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.json.SfstExporterTest.java

private boolean testExportSfstJson(String expectedResultFile, boolean nameOnly) throws IOException {
    ServiceFunctionSchedulerType serviceFunctionSchedulerType;
    String exportedSfstString;//from w  ww  .j  a  v  a2  s. c o  m
    SfstExporterFactory sfstExporterFactory = new SfstExporterFactory();

    if (nameOnly) {
        serviceFunctionSchedulerType = this.buildServiceFunctionSchedulerTypeNameOnly();
        exportedSfstString = sfstExporterFactory.getExporter().exportJsonNameOnly(serviceFunctionSchedulerType);
    } else {
        serviceFunctionSchedulerType = this.buildServiceFunctionSchedulerType();
        exportedSfstString = sfstExporterFactory.getExporter().exportJson(serviceFunctionSchedulerType);
    }

    ObjectMapper objectMapper = new ObjectMapper();
    JsonNode expectedSfstJson = objectMapper
            .readTree(this.gatherServiceFunctionSchedulerTypeJsonStringFromFile(expectedResultFile));
    JsonNode exportedSfstJson = objectMapper.readTree(exportedSfstString);

    return expectedSfstJson.equals(exportedSfstJson);
}

From source file:org.opendaylight.sfc.sbrest.json.RspExporterTest.java

private boolean testExportRspJson(String expectedResultFile, boolean nameOnly) throws IOException {
    RenderedServicePath renderedServicePath;
    String exportedRspString;//from   w w w  .  j av  a2 s.  co m
    RspExporterFactory rspExporterFactory = new RspExporterFactory();

    if (nameOnly) {
        renderedServicePath = this.buildRenderedServicePathNameOnly();
        exportedRspString = rspExporterFactory.getExporter().exportJsonNameOnly(renderedServicePath);
    } else {
        renderedServicePath = this.buildRenderedServicePath();
        exportedRspString = rspExporterFactory.getExporter().exportJson(renderedServicePath);
    }

    ObjectMapper objectMapper = new ObjectMapper();
    JsonNode expectedRspJson = objectMapper
            .readTree(this.gatherRenderedServicePathJsonStringFromFile(expectedResultFile));
    JsonNode exportedRspJson = objectMapper.readTree(exportedRspString);

    return expectedRspJson.equals(exportedRspJson);
}

From source file:com.openplatform.udm.javamodel.CandidateSchemaTest.java

/**
 * Test address schema./*w  w w  . ja  v a  2s .c  o m*/
 *
 * @throws IOException Signals that an I/O exception has occurred.
 */
@Test
public void testAddressSchema() throws IOException {
    //ASSIGN & ACT
    File file = new File(filePathAddress);
    Address addressSchema = Transformer.fromJSON(file, Address.class);
    String outputJson = Transformer.toJSON(addressSchema);
    ObjectMapper diffMapper = new ObjectMapper();
    JsonNode tree1 = diffMapper.readTree(file);
    JsonNode tree2 = diffMapper.readTree(outputJson);

    //ASSERT
    org.junit.Assert.assertTrue(tree1.equals(tree2));
}

From source file:com.openplatform.udm.javamodel.CandidateSchemaTest.java

/**
 * Test person schema.//from   w w  w .  j av  a 2 s.co  m
 *
 * @throws IOException Signals that an I/O exception has occurred.
 */
@Test
public void testPersonSchema() throws IOException {
    //ASSIGN & ACT
    File file = new File(filePathPerson);
    Person personSchema = Transformer.fromJSON(file, Person.class);
    String outputJson = Transformer.toJSON(personSchema);
    ObjectMapper diffMapper = new ObjectMapper();
    JsonNode tree1 = diffMapper.readTree(file);
    JsonNode tree2 = diffMapper.readTree(outputJson);

    //ASSERT
    org.junit.Assert.assertTrue(tree1.equals(tree2));
}

From source file:com.openplatform.udm.javamodel.CandidateSchemaTest.java

/**
 * Creates an ObjectMapper object that reads in sample candidate JSON data and populates
 * the candidate java model with it. The data is then read from the populated java model.
 * The input and output JSON data from the java model (before deserialisation and after 
 * serialisation, respectively) is constructed into JSON trees and tested for equality.
 * This is different from comparing their string representation; object and property order
 * does not affect the validity of the JSON data against the defined schema
 *
 * @throws IOException Signals that an I/O exception has occurred.
 *//*from  w  w  w  . ja  va2 s  .  c  o m*/

@Test
public void testCandidateSchema() throws IOException {
    //ASSIGN & ACT
    File file = new File(filePathCandidate);
    Candidate candidateSchema = Transformer.fromJSON(file, Candidate.class);
    String outputJson = Transformer.toJSON(candidateSchema);
    ObjectMapper diffMapper = new ObjectMapper();
    JsonNode tree1 = diffMapper.readTree(file);
    JsonNode tree2 = diffMapper.readTree(outputJson);

    //ASSERT
    org.junit.Assert.assertTrue(tree1.equals(tree2));
}

From source file:org.opendaylight.sfc.sbrest.json.SfExporterTest.java

private boolean testExportSfJson(String expectedResultFile, boolean nameOnly) throws IOException {
    ServiceFunction serviceFunction;/* w  ww  .java2 s. co m*/
    String exportedSfString;
    SfExporterFactory sfExporterFactory = new SfExporterFactory();

    if (nameOnly) {
        serviceFunction = this.buildServiceFunctionNameOnly();
        exportedSfString = sfExporterFactory.getExporter().exportJsonNameOnly(serviceFunction);
    } else {
        serviceFunction = this.buildServiceFunction();
        exportedSfString = sfExporterFactory.getExporter().exportJson(serviceFunction);
    }

    ObjectMapper objectMapper = new ObjectMapper();
    JsonNode expectedSfJson = objectMapper
            .readTree(this.gatherServiceFunctionJsonStringFromFile(expectedResultFile));
    JsonNode exportedSfJson = objectMapper.readTree(exportedSfString);

    return expectedSfJson.equals(exportedSfJson);
}

From source file:com.jaspersoft.studio.data.querydesigner.json.JsonDataManager.java

private List<JsonSupportNode> getChildrenJsonNodes(JsonNode jsonNode) {
    List<JsonSupportNode> children = new ArrayList<JsonSupportNode>();
    if (jsonNode.isArray() && jsonNode.equals(jsonRoot)) {
        // Assumption: consider the first element as a template
        jsonNode = jsonNode.get(0);/*from w ww  .ja v a2 s  .  c  o  m*/
    }
    Iterator<String> fieldNames = jsonNode.fieldNames();
    while (fieldNames.hasNext()) {
        String name = fieldNames.next();
        JsonNode tmpNode = jsonNode.get(name);
        if (tmpNode.isObject()) {
            JsonSupportNode child = new JsonSupportNode();
            child.setNodeText(name);
            List<JsonSupportNode> innerChildren = getChildrenJsonNodes(tmpNode);
            for (JsonSupportNode innerChild : innerChildren) {
                innerChild.setParent(child, -1);
            }
            getJsonNodesMap().put(child, tmpNode);
            children.add(child);
        } else if (tmpNode.isArray()) {
            Iterator<JsonNode> elements = tmpNode.elements();
            while (elements.hasNext()) {
                JsonNode el = elements.next();
                JsonSupportNode child = new JsonSupportNode();
                child.setNodeText(name);
                List<JsonSupportNode> innerChildren = getChildrenJsonNodes(el);
                for (JsonSupportNode innerChild : innerChildren) {
                    innerChild.setParent(child, -1);
                }
                getJsonNodesMap().put(child, el);
                children.add(child);
            }
        } else if (tmpNode.isValueNode()) {
            JsonSupportNode child = new JsonSupportNode();
            child.setNodeText(name);
            getJsonNodesMap().put(child, tmpNode);
            children.add(child);
        }
    }
    return children;
}

From source file:org.opendaylight.sfc.sbrest.json.ExporterUtilTest.java

private boolean testExportUtilLocatorJson(String locatorTypeName, String expectedResultFile)
        throws IOException {
    DataPlaneLocator dataPlaneLocator = this.buildDataPlaneLocator(locatorTypeName);

    ObjectMapper objectMapper = new ObjectMapper();

    JsonNode expectedLocatorJson = objectMapper.readTree(this.gatherUtilJsonStringFromFile(expectedResultFile));
    JsonNode exportedLocatorJson = ExporterUtil.getDataPlaneLocatorObjectNode(dataPlaneLocator);

    return expectedLocatorJson.equals(exportedLocatorJson);
}

From source file:org.opendaylight.sfc.sbrest.json.ExporterUtilTest.java

private boolean testExportUtilTransportJson(String transportTypeName, String expectedResultFile)
        throws IOException {
    DataPlaneLocator dataPlaneLocator = this.buildDataPlaneLocatorTransport(transportTypeName);

    ObjectMapper objectMapper = new ObjectMapper();

    JsonNode expectedLocatorJson = objectMapper.readTree(this.gatherUtilJsonStringFromFile(expectedResultFile));
    JsonNode exportedLocatorJson = ExporterUtil.getDataPlaneLocatorObjectNode(dataPlaneLocator);

    return expectedLocatorJson.equals(exportedLocatorJson);
}

From source file:org.opendaylight.sfc.sbrest.json.AclExporterTest.java

private boolean testExportAclJson(String accessListType, String expectedResultFile, boolean nameOnly)
        throws IOException {
    Acl accessList;//w  w  w. jav a 2 s  .  c o  m
    String exportedAclString;
    AclExporterFactory aclExporterFactory = new AclExporterFactory();

    if (nameOnly) {
        accessList = this.buildAccessListNameOnly();
        exportedAclString = aclExporterFactory.getExporter().exportJsonNameOnly(accessList);
    } else {
        accessList = this.buildAccessList(accessListType);
        exportedAclString = aclExporterFactory.getExporter().exportJson(accessList);
    }

    ObjectMapper objectMapper = new ObjectMapper();
    JsonNode expectedAclJson = objectMapper
            .readTree(this.gatherAccessListJsonStringFromFile(expectedResultFile));
    JsonNode exportedAclJson = objectMapper.readTree(exportedAclString);

    return expectedAclJson.equals(exportedAclJson);
}