List of usage examples for com.fasterxml.jackson.databind JsonNode size
public int size()
From source file:org.opendaylight.nemo.renderer.openflow.physicalnetwork.PhyConfigLoaderTest.java
@Test public void testBuildHosts() throws Exception { Class<PhyConfigLoader> class1 = PhyConfigLoader.class; Method method = class1.getDeclaredMethod("buildHosts", new Class[] { JsonNode.class }); method.setAccessible(true);/*from w ww. ja va 2 s . co m*/ JsonNode hostsNode = mock(JsonNode.class); JsonNode hosts = mock(JsonNode.class); JsonNode host = mock(JsonNode.class); JsonNode host_temp = mock(JsonNode.class); JsonNode host_temp1 = mock(JsonNode.class); JsonNode ipaddrs = mock(JsonNode.class); JsonNode ipaddr = mock(JsonNode.class); List<PhysicalHost> list; when(hostsNode.path(any(String.class))).thenReturn(hosts); when(hosts.size()).thenReturn(1); when(hosts.get(any(Integer.class))).thenReturn(host); //get into method "buildhost" when(host.get(any(String.class))).thenReturn(host_temp); when(host_temp.asText()).thenReturn(new String("00001111-0000-0000-0000-000011112222")) //HOST_ID .thenReturn(new String("hostName")) //HOST_NAME .thenReturn(new String("00:11:22:33:44:55")) //MAC_ADDRESS .thenReturn(new String("nodeId")) //NODE_ID .thenReturn(new String("connetionId"));//PhysicalPortId when(host.path(any(String.class))).thenReturn(ipaddrs); when(ipaddrs.size()).thenReturn(1); when(ipaddrs.get(any(Integer.class))).thenReturn(ipaddr); when(ipaddr.get(any(String.class))).thenReturn(host_temp1); when(host_temp1.asText()).thenReturn(new String("192.168.1.1"));//ipv4_address list = (List<PhysicalHost>) method.invoke(phyConfigLoader, hostsNode); Assert.assertTrue(list.size() == 1); }
From source file:org.activiti.rest.service.api.runtime.ProcessInstanceCollectionResourceTest.java
/** * Test starting a process instance passing in variables to set. *//*from ww w. j ava2s . c om*/ @Deployment(resources = { "org/activiti/rest/service/api/runtime/ProcessInstanceResourceTest.process-one.bpmn20.xml" }) public void testStartProcessWithVariables() throws Exception { ArrayNode variablesNode = objectMapper.createArrayNode(); // String variable ObjectNode stringVarNode = variablesNode.addObject(); stringVarNode.put("name", "stringVariable"); stringVarNode.put("value", "simple string value"); stringVarNode.put("type", "string"); ObjectNode integerVarNode = variablesNode.addObject(); integerVarNode.put("name", "integerVariable"); integerVarNode.put("value", 1234); integerVarNode.put("type", "integer"); ObjectNode shortVarNode = variablesNode.addObject(); shortVarNode.put("name", "shortVariable"); shortVarNode.put("value", 123); shortVarNode.put("type", "short"); ObjectNode longVarNode = variablesNode.addObject(); longVarNode.put("name", "longVariable"); longVarNode.put("value", 4567890L); longVarNode.put("type", "long"); ObjectNode doubleVarNode = variablesNode.addObject(); doubleVarNode.put("name", "doubleVariable"); doubleVarNode.put("value", 123.456); doubleVarNode.put("type", "double"); ObjectNode booleanVarNode = variablesNode.addObject(); booleanVarNode.put("name", "booleanVariable"); booleanVarNode.put("value", Boolean.TRUE); booleanVarNode.put("type", "boolean"); // Date Calendar varCal = Calendar.getInstance(); String isoString = getISODateString(varCal.getTime()); ObjectNode dateVarNode = variablesNode.addObject(); dateVarNode.put("name", "dateVariable"); dateVarNode.put("value", isoString); dateVarNode.put("type", "date"); ObjectNode requestNode = objectMapper.createObjectNode(); // Start using process definition key, passing in variables requestNode.put("processDefinitionKey", "processOne"); requestNode.put("variables", variablesNode); HttpPost httpPost = new HttpPost( SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_COLLECTION)); httpPost.setEntity(new StringEntity(requestNode.toString())); CloseableHttpResponse response = executeRequest(httpPost, HttpStatus.SC_CREATED); JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent()); closeResponse(response); assertEquals(false, responseNode.get("ended").asBoolean()); JsonNode variablesArrayNode = responseNode.get("variables"); assertEquals(0, variablesArrayNode.size()); ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().singleResult(); assertNotNull(processInstance); // Check if engine has correct variables set Map<String, Object> processVariables = runtimeService.getVariables(processInstance.getId()); assertEquals(7, processVariables.size()); assertEquals("simple string value", processVariables.get("stringVariable")); assertEquals(1234, processVariables.get("integerVariable")); assertEquals((short) 123, processVariables.get("shortVariable")); assertEquals(4567890L, processVariables.get("longVariable")); assertEquals(123.456, processVariables.get("doubleVariable")); assertEquals(Boolean.TRUE, processVariables.get("booleanVariable")); assertEquals(dateFormat.parse(isoString), processVariables.get("dateVariable")); }
From source file:org.flowable.rest.service.api.runtime.ProcessInstanceCollectionResourceTest.java
/** * Test starting a process instance passing in variables to set. *///from w w w . j a v a 2 s . co m @Deployment(resources = { "org/flowable/rest/service/api/runtime/ProcessInstanceResourceTest.process-one.bpmn20.xml" }) public void testStartProcessWithVariables() throws Exception { ArrayNode variablesNode = objectMapper.createArrayNode(); // String variable ObjectNode stringVarNode = variablesNode.addObject(); stringVarNode.put("name", "stringVariable"); stringVarNode.put("value", "simple string value"); stringVarNode.put("type", "string"); ObjectNode integerVarNode = variablesNode.addObject(); integerVarNode.put("name", "integerVariable"); integerVarNode.put("value", 1234); integerVarNode.put("type", "integer"); ObjectNode shortVarNode = variablesNode.addObject(); shortVarNode.put("name", "shortVariable"); shortVarNode.put("value", 123); shortVarNode.put("type", "short"); ObjectNode longVarNode = variablesNode.addObject(); longVarNode.put("name", "longVariable"); longVarNode.put("value", 4567890L); longVarNode.put("type", "long"); ObjectNode doubleVarNode = variablesNode.addObject(); doubleVarNode.put("name", "doubleVariable"); doubleVarNode.put("value", 123.456); doubleVarNode.put("type", "double"); ObjectNode booleanVarNode = variablesNode.addObject(); booleanVarNode.put("name", "booleanVariable"); booleanVarNode.put("value", Boolean.TRUE); booleanVarNode.put("type", "boolean"); // Date Calendar varCal = Calendar.getInstance(); String isoString = getISODateString(varCal.getTime()); ObjectNode dateVarNode = variablesNode.addObject(); dateVarNode.put("name", "dateVariable"); dateVarNode.put("value", isoString); dateVarNode.put("type", "date"); ObjectNode requestNode = objectMapper.createObjectNode(); // Start using process definition key, passing in variables requestNode.put("processDefinitionKey", "processOne"); requestNode.set("variables", variablesNode); HttpPost httpPost = new HttpPost( SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_COLLECTION)); httpPost.setEntity(new StringEntity(requestNode.toString())); CloseableHttpResponse response = executeRequest(httpPost, HttpStatus.SC_CREATED); JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent()); closeResponse(response); assertFalse(responseNode.get("ended").asBoolean()); JsonNode variablesArrayNode = responseNode.get("variables"); assertEquals(0, variablesArrayNode.size()); ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().singleResult(); assertNotNull(processInstance); // Check if engine has correct variables set Map<String, Object> processVariables = runtimeService.getVariables(processInstance.getId()); assertEquals(7, processVariables.size()); assertEquals("simple string value", processVariables.get("stringVariable")); assertEquals(1234, processVariables.get("integerVariable")); assertEquals((short) 123, processVariables.get("shortVariable")); assertEquals(4567890L, processVariables.get("longVariable")); assertEquals(123.456, processVariables.get("doubleVariable")); assertEquals(Boolean.TRUE, processVariables.get("booleanVariable")); assertEquals(dateFormat.parse(isoString), processVariables.get("dateVariable")); }
From source file:com.flipkart.zjsonpatch.ApplyProcessor.java
@Override public void remove(List<String> path) { if (path.isEmpty()) { throw new JsonPatchApplicationException("[Remove Operation] path is empty"); } else {/* w w w.ja v a2 s . co m*/ JsonNode parentNode = getParentNode(path); if (parentNode == null) { throw new JsonPatchApplicationException( "[Remove Operation] noSuchPath in source, path provided : " + path); } else { String fieldToRemove = path.get(path.size() - 1).replaceAll("\"", ""); if (parentNode.isObject()) ((ObjectNode) parentNode).remove(fieldToRemove); else if (parentNode.isArray()) ((ArrayNode) parentNode).remove(arrayIndex(fieldToRemove, parentNode.size() - 1)); else throw new JsonPatchApplicationException( "[Remove Operation] noSuchPath in source, path provided : " + path); } } }
From source file:com.servioticy.api.commons.data.SO.java
/** * @param actuationName/* w w w . ja v a 2 s .c o m*/ * @return the actutation JsonNode */ public JsonNode getActuation(String actuationName) { JsonNode actions = soRoot.path("actions"); if (actions == null) { throw new ServIoTWebApplicationException(Response.Status.INTERNAL_SERVER_ERROR, "Actuation '" + actuationName + "' does not exist for SO: " + soId); } for (int i = 0; i < actions.size(); i++) { if (actions.get(i).path("name").asText().equalsIgnoreCase(actuationName)) return actions.get(i); } throw new ServIoTWebApplicationException(Response.Status.INTERNAL_SERVER_ERROR, "Actuation '" + actuationName + "' does not exist for SO: " + soId); }
From source file:org.activiti.rest.service.api.runtime.ProcessInstanceCollectionResourceTest.java
@Deployment(resources = { "org/activiti/rest/service/api/runtime/ProcessInstanceResourceTest.process-one.bpmn20.xml" }) public void testGetProcessInstancesByBusinessKeyAndIncludeVariables() throws Exception { HashMap<String, Object> variables = new HashMap<String, Object>(); variables.put("myVar1", "myVar1"); ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("processOne", "myBusinessKey", variables);/*from w w w. ja va2s . com*/ String processId = processInstance.getId(); // check that the right process is returned with no variables String url = RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_COLLECTION) + "?businessKey=myBusinessKey"; CloseableHttpResponse response = executeRequest(new HttpGet(SERVER_URL_PREFIX + url), HttpStatus.SC_OK); JsonNode rootNode = objectMapper.readTree(response.getEntity().getContent()); closeResponse(response); assertTrue(rootNode.size() > 0); assertEquals(1, rootNode.get("data").size()); JsonNode dataNode = rootNode.get("data").get(0); assertEquals(processId, dataNode.get("id").asText()); assertEquals(processInstance.getProcessDefinitionId(), dataNode.get("processDefinitionId").asText()); assertTrue( dataNode.get("processDefinitionUrl").asText().contains(processInstance.getProcessDefinitionId())); JsonNode variableNodes = dataNode.get("variables"); assertEquals(0, variableNodes.size()); // check that the right process is returned along with the variables // when includeProcessvariable is set url = RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_COLLECTION) + "?businessKey=myBusinessKey&includeProcessVariables=true"; response = executeRequest(new HttpGet(SERVER_URL_PREFIX + url), HttpStatus.SC_OK); rootNode = objectMapper.readTree(response.getEntity().getContent()); closeResponse(response); assertTrue(rootNode.size() > 0); assertEquals(1, rootNode.get("data").size()); dataNode = rootNode.get("data").get(0); assertEquals(processId, dataNode.get("id").textValue()); assertEquals(processInstance.getProcessDefinitionId(), dataNode.get("processDefinitionId").asText()); assertTrue( dataNode.get("processDefinitionUrl").asText().contains(processInstance.getProcessDefinitionId())); variableNodes = dataNode.get("variables"); assertEquals(1, variableNodes.size()); variableNodes = dataNode.get("variables"); assertEquals(1, variableNodes.size()); assertNotNull(variableNodes.get(0).get("name")); assertNotNull(variableNodes.get(0).get("value")); assertEquals("myVar1", variableNodes.get(0).get("name").asText()); assertEquals("myVar1", variableNodes.get(0).get("value").asText()); }
From source file:org.flowable.rest.service.api.runtime.ProcessInstanceCollectionResourceTest.java
@Deployment(resources = { "org/flowable/rest/service/api/runtime/ProcessInstanceResourceTest.process-one.bpmn20.xml" }) public void testGetProcessInstancesByBusinessKeyAndIncludeVariables() throws Exception { HashMap<String, Object> variables = new HashMap<String, Object>(); variables.put("myVar1", "myVar1"); ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("processOne", "myBusinessKey", variables);//from w w w . j ava 2 s. c om String processId = processInstance.getId(); // check that the right process is returned with no variables String url = RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_COLLECTION) + "?businessKey=myBusinessKey"; CloseableHttpResponse response = executeRequest(new HttpGet(SERVER_URL_PREFIX + url), HttpStatus.SC_OK); JsonNode rootNode = objectMapper.readTree(response.getEntity().getContent()); closeResponse(response); assertTrue(rootNode.size() > 0); assertEquals(1, rootNode.get("data").size()); JsonNode dataNode = rootNode.get("data").get(0); assertEquals(processId, dataNode.get("id").asText()); assertEquals(processInstance.getProcessDefinitionId(), dataNode.get("processDefinitionId").asText()); assertTrue( dataNode.get("processDefinitionUrl").asText().contains(processInstance.getProcessDefinitionId())); JsonNode variableNodes = dataNode.get("variables"); assertEquals(0, variableNodes.size()); // check that the right process is returned along with the variables // when includeProcessvariable is set url = RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_COLLECTION) + "?businessKey=myBusinessKey&includeProcessVariables=true"; response = executeRequest(new HttpGet(SERVER_URL_PREFIX + url), HttpStatus.SC_OK); rootNode = objectMapper.readTree(response.getEntity().getContent()); closeResponse(response); assertTrue(rootNode.size() > 0); assertEquals(1, rootNode.get("data").size()); dataNode = rootNode.get("data").get(0); assertEquals(processId, dataNode.get("id").textValue()); assertEquals(processInstance.getProcessDefinitionId(), dataNode.get("processDefinitionId").asText()); assertTrue( dataNode.get("processDefinitionUrl").asText().contains(processInstance.getProcessDefinitionId())); variableNodes = dataNode.get("variables"); assertEquals(1, variableNodes.size()); variableNodes = dataNode.get("variables"); assertEquals(1, variableNodes.size()); assertNotNull(variableNodes.get(0).get("name")); assertNotNull(variableNodes.get(0).get("value")); assertEquals("myVar1", variableNodes.get(0).get("name").asText()); assertEquals("myVar1", variableNodes.get(0).get("value").asText()); }
From source file:org.teavm.flavour.json.test.SerializerTest.java
@Test public void writesArrayProperty() { ArrayProperty o = new ArrayProperty(); o.setArray(new int[] { 23, 42 }); JsonNode node = JSONRunner.serialize(o); assertTrue("Root node should be JSON object", node.isObject()); assertTrue("Root node should contain `array' property", node.has("array")); JsonNode propertyNode = node.get("array"); assertTrue("Property `array' should be JSON array", propertyNode.isArray()); assertEquals("Length must be 2", 2, propertyNode.size()); JsonNode firstNode = propertyNode.get(0); assertTrue("Item must be numeric", firstNode.isNumber()); assertEquals(23, firstNode.asInt()); }
From source file:org.teavm.flavour.json.test.SerializerTest.java
@Test public void writesArrayOfObjectProperty() { A item = new A(); ArrayOfObjectProperty o = new ArrayOfObjectProperty(); o.setArray(new A[] { item }); JsonNode node = JSONRunner.serialize(o); assertTrue("Root node should be JSON object", node.isObject()); assertTrue("Root node should contain `array' property", node.has("array")); JsonNode propertyNode = node.get("array"); assertTrue("Property `array' should be JSON array", propertyNode.isArray()); assertEquals("Length must be 1", 1, propertyNode.size()); JsonNode itemNode = propertyNode.get(0); assertTrue("Item must be object", itemNode.isObject()); assertTrue(itemNode.has("a")); assertTrue(itemNode.has("b")); }
From source file:com.okta.tools.awscli.java
private static String ProcessPolicyDocument(String policyDoc) { String strRoleToAssume = null; try {/*from w ww .j av a 2s. c o m*/ String policyDocClean = URLDecoder.decode(policyDoc, "UTF-8"); logger.debug("Clean Policy Document: " + policyDocClean); ObjectMapper objectMapper = new ObjectMapper(); try { JsonNode rootNode = objectMapper.readTree(policyDocClean); JsonNode statement = rootNode.path("Statement"); logger.debug("Statement node: " + statement.toString()); JsonNode resource = null; if (statement.isArray()) { logger.debug("Statement is array"); for (int i = 0; i < statement.size(); i++) { String action = statement.get(i).path("Action").textValue(); if (action != null && action.equals("sts:AssumeRole")) { resource = statement.get(i).path("Resource"); logger.debug("Resource node: " + resource.toString()); break; } } } else { logger.debug("Statement is NOT array"); if (statement.get("Action").textValue().equals("sts:AssumeRole")) { resource = statement.path("Resource"); logger.debug("Resource node: " + resource.toString()); } } if (resource != null) { if (resource.isArray()) { //if we're handling a policy with an array of AssumeRole attributes ArrayList<String> lstRoles = new ArrayList<String>(); for (final JsonNode node : resource) { lstRoles.add(node.asText()); } strRoleToAssume = SelectRole(lstRoles); } else { strRoleToAssume = resource.textValue(); logger.debug("Role to assume: " + roleToAssume); } } } catch (IOException ioe) { } } catch (UnsupportedEncodingException uee) { } return strRoleToAssume; }