List of usage examples for com.fasterxml.jackson.databind JsonNode equals
public abstract boolean equals(Object paramObject);
From source file:org.opendaylight.sfc.sbrest.provider.task.SbRestSfstateTaskTest.java
@Test public void testSbRestSfstateTaskEmpty() throws IOException { SbRestSfstateTask sbRestSfstateTask = new SbRestSfstateTask(RestOperation.PUT, new ServiceFunctionStateBuilder().build(), executorService); PowerMockito.mockStatic(SfcProviderServiceFunctionAPI.class); Mockito.when(SfcProviderServiceFunctionAPI.readServiceFunction(SFSTATE_NAME)) .thenReturn(new ServiceFunctionBuilder().build()); JsonNode jsonObject = mapper.readTree(sbRestSfstateTask.jsonObject); assertTrue("Must be true", jsonObject.equals(this.buildServiceFunctionStateTopNode())); assertNull("Must be null", sbRestSfstateTask.restUriList); }
From source file:com.crushpaper.DbJsonBackupForUserTest.java
@Test public void test4() throws IOException { final TestEntrySet before = new TestEntrySet(new TestEntry[] { new TestEntry("1", new TestEntry[] { new TestEntry("2", 2), new TestEntry("3", 3) }) }); final ObjectMapper mapper = new ObjectMapper(); final JsonNode node1 = mapper .readTree("{\n" + "\"note\": \"3\",\n" + "\"modTime\": 3,\n" + "\"createTime\": 3,\n" + "\"id\": \"S5\",\n" + "\"type\": \"note\",\n" + "\"parentId\": \"S3\"\n" + "}"); final JsonNode node2 = mapper.readTree("{\n" + "\"note\": \"2\",\n" + "\"modTime\": 2,\n" + "\"createTime\": 2,\n" + "\"id\": \"S4\",\n" + "\"type\": \"note\",\n" + "\"parentId\": \"S3\",\n" + "\"nextSiblingId\": \"S5\"\n" + "}"); final JsonNode node3 = mapper.readTree("{\n" + "\"note\": \"1\",\n" + "\"modTime\": 1,\n" + "\"createTime\": 1,\n" + "\"id\": \"S3\",\n" + "\"type\": \"root\"\n" + "}\n"); final Errors errors = new Errors(); try {/*from www . ja va 2s . c o m*/ final User user = dbLogic.getOrCreateUser("user"); assertTrue(dbLogic.addEntries(before, user, createTime, errors)); dbLogic.commit(); final StringBuilder result = new StringBuilder(); dbLogic.backupJsonForUser(user, result); final JsonNode resultNode = mapper.readTree(result.toString()); assertTrue(resultNode.isObject()); final JsonNode entriesNodes = resultNode.get("entries"); assertTrue(entriesNodes.isArray()); assertEquals(3, entriesNodes.size()); boolean matched1 = false, matched2 = false, matched3 = false; for (int i = 0; i < 3; ++i) { final JsonNode obj = entriesNodes.get(i); if (obj.equals(node1)) { matched1 = true; } else if (obj.equals(node2)) { matched2 = true; } else if (obj.equals(node3)) { matched3 = true; } } assertTrue(matched1); assertTrue(matched2); assertTrue(matched3); } catch (final IOException e) { assertTrue(false); } }
From source file:com.pros.jsontransform.examples.expressions.ExpressionsTest.java
@Test public void testFieldRenaming() throws IOException, ObjectTransformerException { jsonSource = JunitTools.readFile(pathToJson + "/" + fileNamePrefix + "Source.json"); jsonTransform = JunitTools.readFile(pathToJson + "/" + fileNamePrefix + "Map.json"); jsonTarget = JunitTools.readFile(pathToJson + "/" + fileNamePrefix + "Target.json"); ObjectTransformer transformer = new ObjectTransformer(mapper); String result = transformer.transform(jsonSource, jsonTransform); System.out.println(result);// w ww .j a v a2 s . co m // need to adjust UUID as it never repeats JsonNode resultNode = mapper.readTree(result); ObjectNode target = (ObjectNode) mapper.readTree(jsonTarget); target.replace("id", resultNode.get("id")); assertTrue(resultNode.equals(target)); }
From source file:org.opendaylight.sfc.sbrest.provider.task.SbRestRspTaskTest.java
@Test public void testSbRestRspTask() throws IOException { SbRestRspTask sbRestRspTask = new SbRestRspTask(RestOperation.PUT, this.buildRenderedServicePath(), executorService);//from www . jav a 2 s . c o m JsonNode jsonObject = mapper.readTree(sbRestRspTask.jsonObject); assertTrue("Must be true", jsonObject.equals(this.buildRenderedServicePathObjectNode())); assertTrue("Must be true", sbRestRspTask.restUriList.get(0).contains(REST_URI)); }
From source file:org.opendaylight.sfc.sbrest.provider.task.SbRestRspTaskTest.java
@Test public void testSbRestRspTask1() throws IOException { SbRestRspTask sbRestRspTask = new SbRestRspTask(RestOperation.DELETE, this.buildRenderedServicePath(), executorService);/* www . j av a 2 s .co m*/ JsonNode jsonObject = mapper.readTree(sbRestRspTask.jsonObject); assertTrue("Must be true", jsonObject.equals(this.buildRenderedServicePathObjectNode1())); assertTrue("Must be true", sbRestRspTask.restUriList.get(0).contains(REST_URI)); }
From source file:de.jlo.talendcomp.json.JsonComparator.java
/** * Checks if the array contains the given value * @param array the array which perhaps contains the value * @param value the value to search for/* ww w.j a v a2 s .co m*/ * @return true or false * @throws Exception */ public boolean contains(ArrayNode array, JsonNode value, String jsonPath) throws Exception { if (jsonPath == null || jsonPath.trim().isEmpty()) { return contains(array, value); } else { JsonDocument doc = new JsonDocument(array); for (int i = 0, n = array.size(); i < n; i++) { JsonNode nodeInArray = array.get(i); JsonNode child1 = doc.getNode(nodeInArray, jsonPath); JsonNode child2 = doc.getNode(value, jsonPath); if (child1.equals(child2)) { return true; } } return false; } }
From source file:org.opendaylight.sfc.sbrest.provider.task.SbRestRspTaskTest.java
@Test public void testSbRestRspTaskEmpty() throws IOException { PowerMockito.mockStatic(SfcProviderServiceForwarderAPI.class); Mockito.when(SfcProviderServiceForwarderAPI.readServiceFunctionForwarder(SFF_NAME)) .thenReturn(new ServiceFunctionForwarderBuilder().build()); SbRestRspTask sbRestRspTask = new SbRestRspTask(RestOperation.PUT, new RenderedServicePathBuilder().build(), executorService);/* www.j av a2 s. c om*/ JsonNode jsonObject = mapper.readTree(sbRestRspTask.jsonObject); assertTrue("Must be true", jsonObject.equals(this.buildRenderedServicePathTopNode())); assertNull("Must be null", sbRestRspTask.restUriList); }
From source file:org.opendaylight.sfc.sbrest.provider.task.SbRestSfgTaskTest.java
@Test public void testSbRestSfgTask1() throws IOException { SbRestSfgTask sbRestSfgTask = new SbRestSfgTask(RestOperation.DELETE, this.buildServiceFunctionGroup1(), executorService);/*from w w w . j a va2 s . c om*/ JsonNode jsonObject = mapper.readTree(sbRestSfgTask.jsonObject); assertNull("Must be null", sbRestSfgTask.restUriList); assertTrue("Must be true", jsonObject.equals(buildServiceFunctionGroupObjectNode1())); }
From source file:org.opendaylight.sfc.sbrest.provider.task.SbRestSfgTaskTest.java
@Test // SbRestAbstractClass creates string jsonObject from dataObject (service function group) & set // Rest uri list//from ww w . j a v a 2s. com // contain of jsonObject also depends on rest operation // this jsonObject is then compared with object node created in this class public void testSbRestSfgTask() throws IOException { SbRestSfgTask sbRestSfgTask = new SbRestSfgTask(RestOperation.PUT, this.buildServiceFunctionGroup(), executorService); JsonNode jsonObject = mapper.readTree(sbRestSfgTask.jsonObject); assertNotNull("Must not be null", sbRestSfgTask.restUriList); assertTrue("Must be true", jsonObject.equals(this.buildServiceFunctionGroupObjectNode())); assertTrue("Must be true", sbRestSfgTask.restUriList.get(0).contains(REST_URI)); }
From source file:org.opendaylight.sfc.sbrest.provider.task.SbRestAclTaskTest.java
@Test public void testSbRestAclTask() throws IOException { SbRestAclTask sbRestAclTask = new SbRestAclTask(RestOperation.PUT, this.buildAccessList(), executorService); JsonNode jsonObject = mapper.readTree(sbRestAclTask.jsonObject); assertTrue(jsonObject.equals(this.buildAccessListObjectNode())); assertTrue(sbRestAclTask.restUriList.get(0).contains(REST_URI)); }