Example usage for com.fasterxml.jackson.databind JsonNode equals

List of usage examples for com.fasterxml.jackson.databind JsonNode equals

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind JsonNode equals.

Prototype

public abstract boolean equals(Object paramObject);

Source Link

Usage

From source file:org.opendaylight.sfc.sbrest.provider.task.SbRestAclTaskTest.java

@Test
public void testSbRestAclTask1() throws IOException {
    SbRestAclTask sbRestAclTask = new SbRestAclTask(RestOperation.DELETE, this.buildAccessList(),
            executorService);/*from   w w w . j  a  v a  2 s  . com*/

    JsonNode jsonObject = mapper.readTree(sbRestAclTask.jsonObject);
    assertTrue(jsonObject.equals(this.buildAccessListObjectNode()));
    assertTrue(sbRestAclTask.restUriList.get(0).contains(REST_URI));
}

From source file:org.opendaylight.sfc.sbrest.provider.task.SbRestAclTaskTest.java

@Test
public void testSbRestAclTaskAclObjectForwarderList() throws IOException {
    SbRestAclTask sbRestAclTask = new SbRestAclTask(RestOperation.PUT, this.buildAccessList(),
            this.buildServiceFunctionClassifier().getSclServiceFunctionForwarder(), executorService);

    JsonNode jsonObject = mapper.readTree(sbRestAclTask.jsonObject);
    assertTrue(jsonObject.equals(this.buildAccessListObjectNode()));
    assertTrue(sbRestAclTask.restUriList.get(0).contains(REST_URI));
}

From source file:org.opendaylight.sfc.sbrest.provider.task.SbRestAclTaskTest.java

@Test
public void testSbRestAclTaskEmpty() throws IOException {
    PowerMockito.mockStatic(SfcProviderServiceForwarderAPI.class);
    Mockito.when(SfcProviderServiceForwarderAPI.readServiceFunctionForwarder(SFF_NAME))
            .thenReturn(new ServiceFunctionForwarderBuilder().build());

    SbRestAclTask sbRestAclTask = new SbRestAclTask(RestOperation.PUT, this.buildAccessList(), executorService);

    JsonNode jsonObject = mapper.readTree(sbRestAclTask.jsonObject);
    assertTrue(jsonObject.equals(this.buildAccessListObjectNode()));
    assertNull(sbRestAclTask.restUriList);
}

From source file:org.opendaylight.sfc.sbrest.provider.task.SbRestAclTaskTest.java

@Test
public void testSbRestAclTaskForwarderListEmpty() throws IOException {
    SclServiceFunctionForwarderBuilder sclServiceFunctionForwarderBuilder = new SclServiceFunctionForwarderBuilder();
    sclServiceFunctionForwarderBuilder.setName(SFF_NAME.getValue());

    List<SclServiceFunctionForwarder> sclServiceFunctionForwarderList = new ArrayList<>();
    sclServiceFunctionForwarderList.add(sclServiceFunctionForwarderBuilder.build());

    SbRestAclTask sbRestAclTask = new SbRestAclTask(RestOperation.PUT, this.buildAccessList(),
            sclServiceFunctionForwarderList, executorService);

    JsonNode jsonObject = mapper.readTree(sbRestAclTask.jsonObject);
    assertTrue(jsonObject.equals(this.buildAccessListObjectNode()));
    assertTrue(sbRestAclTask.restUriList.get(0).contains(REST_URI));
}

From source file:de.jlo.talendcomp.json.JsonComparator.java

/**
 * Collects the values for the both arrays have in common 
 * @param array1//from   w  ww.  j a  v a 2s.com
 * @param array2
 * @return an array which contains all values both arrays have in common
 */
public ArrayNode intersect(ArrayNode array1, ArrayNode array2) {
    ArrayNode result = objectMapper.createArrayNode();
    for (int i1 = 0, n1 = array1.size(); i1 < n1; i1++) {
        JsonNode node1 = array1.get(i1);
        for (int i2 = 0, n2 = array2.size(); i2 < n2; i2++) {
            JsonNode node2 = array2.get(i2);
            if (node1.equals(node2)) {
                result.add(node2);
            }
        }
    }
    return result;
}

From source file:com.auditbucket.test.unit.TestJson.java

@Test
public void simpleTextRemainsUncompressed() throws Exception {
    String json = "{\"colname\": \"tinytext.......................\"}";
    System.out.println("Before Comppression" + json.getBytes().length);

    CompressionResult result = CompressionHelper.compress(json);
    Assert.assertEquals(CompressionResult.Method.NONE, result.getMethod());
    System.out.println("Compressed " + result.length());

    String uncompressed = CompressionHelper.decompress(result);

    ObjectMapper mapper = new ObjectMapper();
    JsonNode compareTo = mapper.readTree(json);
    JsonNode other = mapper.readTree(uncompressed);
    Assert.assertTrue(compareTo.equals(other));

}

From source file:com.auditbucket.test.unit.TestJson.java

@Test
public void compressLotsOfBytes() throws Exception {
    String json = getBigJsonText(99);
    System.out.println("Pretty JSON          - " + json.getBytes().length);
    LogInputBean log = new LogInputBean("", "", null, json);
    System.out.println("JSON Node (unpretty) - " + log.getWhat().getBytes().length);

    CompressionResult result = CompressionHelper.compress(json);
    System.out.println("Compress Pretty      - " + result.length());
    result = CompressionHelper.compress(log.getWhat());
    System.out.println("Compressed JSON      - " + result.length());

    Assert.assertEquals(CompressionResult.Method.GZIP, result.getMethod());

    json = getBigJsonText(99);/*from   w w  w .j  a v a2  s. c om*/
    String uncompressed = CompressionHelper.decompress(result);

    ObjectMapper mapper = new ObjectMapper();
    JsonNode compareTo = mapper.readTree(json);
    JsonNode other = mapper.readTree(uncompressed);
    Assert.assertTrue(compareTo.equals(other));
}

From source file:com.github.fge.jsonpatch.JsonPatchTestSuite.java

@Test(dataProvider = "getTests")
public void testsFromTestSuitePass(final JsonNode source, final JsonPatch patch, final JsonNode expected,
        final boolean valid) {
    try {// ww  w  . ja va 2s .  c  om
        final JsonNode actual = patch.apply(source);
        if (!valid)
            fail("Test was expected to fail!!");
        // Have to do that... TestNG tries to be too smart with regards
        // to iterable collections...
        assertTrue(actual.equals(expected));
    } catch (JsonPatchException ignored) {
        if (valid)
            fail("Test was expected to succeed!!");
    }
}

From source file:com.redhat.lightblue.eval.FieldAccessRoleEvaluator.java

private boolean different(KeyValueCursor<Path, JsonNode> c1, KeyValueCursor<Path, JsonNode> c2) {
    while (c1.hasNext()) {
        if (c2.hasNext()) {
            c1.next();/*from  w  w w.ja v a  2 s .co m*/
            c2.next();
            JsonNode v1 = c1.getCurrentValue();
            JsonNode v2 = c2.getCurrentValue();
            if (!v1.equals(v2)) {
                return true;
            }
        } else {
            return true;
        }
    }
    return c2.hasNext();
}

From source file:de.jlo.talendcomp.json.JsonComparator.java

/**
 * Collects the differences between the both arrays 
 * @param array1//w  w w  . ja v a  2s.c  o m
 * @param array2
 * @return an array which contains the difference between both arrays
 */
public ArrayNode difference(ArrayNode array1, ArrayNode array2) {
    ArrayNode result = objectMapper.createArrayNode();
    for (int i1 = 0, n1 = array1.size(); i1 < n1; i1++) {
        JsonNode node1 = array1.get(i1);
        boolean found = false;
        for (int i2 = 0, n2 = array2.size(); i2 < n2; i2++) {
            JsonNode node2 = array2.get(i2);
            if (node1.equals(node2)) {
                found = true;
                break;
            }
        }
        if (found == false) {
            result.add(node1);
        }
    }
    // exchange the arrays
    ArrayNode x = array1;
    array1 = array2;
    array2 = x;
    for (int i1 = 0, n1 = array1.size(); i1 < n1; i1++) {
        JsonNode node1 = array1.get(i1);
        boolean found = false;
        for (int i2 = 0, n2 = array2.size(); i2 < n2; i2++) {
            JsonNode node2 = array2.get(i2);
            if (node1.equals(node2)) {
                found = true;
                break;
            }
        }
        if (found == false) {
            result.add(node1);
        }
    }
    return result;
}