Search in sources :

Example 46 with AtlasJsonTestUnrootedMapper

use of io.atlasmap.json.test.AtlasJsonTestUnrootedMapper in project atlasmap by atlasmap.

the class MultidocFlatMappingTest method testProcessJavaJavaFlatFieldMapping.

@Test
public void testProcessJavaJavaFlatFieldMapping() throws Exception {
    AtlasContext context = atlasContextFactory.createContext(new File("src/test/resources/multidoc/atlasmapping-flatprimitive.json").toURI());
    AtlasSession session = context.createSession();
    BaseFlatPrimitiveClass sourceJava = generateFlatPrimitiveClass(SourceFlatPrimitiveClass.class);
    session.setSourceDocument("SourceJava", sourceJava);
    String sourceJson = AtlasTestUtil.loadFileAsString("src/test/resources/multidoc/atlas-json-flatprimitive-unrooted.json");
    session.setSourceDocument("SourceJson", sourceJson);
    String sourceXml = AtlasTestUtil.loadFileAsString("src/test/resources/multidoc/atlas-xml-flatprimitive-attribute.xml");
    session.setSourceDocument("SourceXml", sourceXml);
    context.process(session);
    assertFalse(session.hasErrors(), printAudit(session));
    Object targetJava = session.getTargetDocument("TargetJava");
    assertNotNull(targetJava);
    assertTrue(targetJava instanceof TargetFlatPrimitiveClass);
    validateFlatPrimitiveClassPrimitiveFields((TargetFlatPrimitiveClass) targetJava);
    Object targetJson = session.getTargetDocument("TargetJson");
    assertNotNull(targetJson);
    assertTrue(targetJson instanceof String);
    AtlasJsonTestUnrootedMapper testMapper = new AtlasJsonTestUnrootedMapper();
    TargetFlatPrimitive targetObject = testMapper.readValue((String) targetJson, TargetFlatPrimitive.class);
    AtlasTestUtil.validateJsonFlatPrimitivePrimitiveFields(targetObject);
    Object targetXml = session.getTargetDocument("TargetXml");
    assertNotNull(targetXml);
    assertTrue(targetXml instanceof String);
    assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?><XmlFPA booleanField=\"false\" byteField=\"99\" charField=\"a\" doubleField=\"5.0E7\" floatField=\"4.0E7\" intField=\"2\" longField=\"30000\" shortField=\"1\"/>", targetXml, targetXml.toString());
}
Also used : TargetFlatPrimitive(io.atlasmap.json.test.TargetFlatPrimitive) TargetFlatPrimitiveClass(io.atlasmap.java.test.TargetFlatPrimitiveClass) AtlasContext(io.atlasmap.api.AtlasContext) AtlasJsonTestUnrootedMapper(io.atlasmap.json.test.AtlasJsonTestUnrootedMapper) BaseFlatPrimitiveClass(io.atlasmap.java.test.BaseFlatPrimitiveClass) File(java.io.File) AtlasSession(io.atlasmap.api.AtlasSession) AtlasMappingBaseTest(io.atlasmap.itests.reference.AtlasMappingBaseTest) Test(org.junit.jupiter.api.Test)

Example 47 with AtlasJsonTestUnrootedMapper

use of io.atlasmap.json.test.AtlasJsonTestUnrootedMapper in project atlasmap by atlasmap.

the class MultidocComplexTest method testProcessComplexBasicNullContact.

@Test
public void testProcessComplexBasicNullContact() throws Exception {
    AtlasContext context = atlasContextFactory.createContext(new File("src/test/resources/multidoc/atlasmapping-complex-simple.json").toURI());
    AtlasSession session = context.createSession();
    BaseOrder javaSourceOrder = AtlasTestUtil.generateOrderClass(SourceOrder.class, SourceAddress.class, SourceContact.class);
    javaSourceOrder.setContact(null);
    session.setSourceDocument("JavaSourceOrder", javaSourceOrder);
    String jsonSourceOrder = AtlasTestUtil.loadFileAsString("src/test/resources/multidoc/atlas-json-complex-order-autodetect-unrooted.json");
    session.setSourceDocument("JsonSourceOrder", jsonSourceOrder);
    String xmlOrderAttribute = AtlasTestUtil.loadFileAsString("src/test/resources/multidoc/atlas-xml-complex-order-autodetect-attribute-ns.xml");
    session.setSourceDocument("XmlOrderAttribute", xmlOrderAttribute);
    context.process(session);
    assertFalse(session.hasErrors(), printAudit(session));
    TargetTestClass targetTestClass = (TargetTestClass) session.getTargetDocument("JavaTargetTestClass");
    assertEquals(TargetTestClass.class.getName(), targetTestClass.getClass().getName());
    assertEquals(TargetContact.class.getName(), targetTestClass.getContact().getClass().getName());
    assertEquals(Integer.valueOf(8765309), targetTestClass.getOrder().getOrderId());
    assertEquals("Ozzie", targetTestClass.getContact().getFirstName());
    assertEquals("Smith", targetTestClass.getContact().getLastName());
    Object jsonTargetOrder = session.getTargetDocument("JsonTargetOrder");
    assertTrue(jsonTargetOrder instanceof String);
    AtlasJsonTestUnrootedMapper testMapper = new AtlasJsonTestUnrootedMapper();
    io.atlasmap.json.test.TargetOrder jsonTargetOrderObject = testMapper.readValue((String) jsonTargetOrder, io.atlasmap.json.test.TargetOrder.class);
    assertEquals(Integer.valueOf(8765309), jsonTargetOrderObject.getOrderId());
    assertEquals("Ozzie", jsonTargetOrderObject.getContact().getFirstName());
    assertNull(jsonTargetOrderObject.getContact().getLastName());
    Object xmlOrderElement = session.getTargetDocument("XmlOrderElement");
    assertNotNull(xmlOrderElement);
    assertTrue(xmlOrderElement instanceof String);
    HashMap<String, String> ns = new HashMap<>();
    ns.put("ns", "http://atlasmap.io/xml/test/v2");
    assertThat(xmlOrderElement).withNamespaceContext(ns).valueByXPath("/ns:XmlOE/ns:orderId").isEqualTo("8765309");
    assertThat(xmlOrderElement).withNamespaceContext(ns).valueByXPath("/ns:XmlOE/ns:Contact/ns:lastName").isNullOrEmpty();
}
Also used : HashMap(java.util.HashMap) TargetContact(io.atlasmap.java.test.TargetContact) AtlasJsonTestUnrootedMapper(io.atlasmap.json.test.AtlasJsonTestUnrootedMapper) BaseOrder(io.atlasmap.java.test.BaseOrder) AtlasContext(io.atlasmap.api.AtlasContext) TargetTestClass(io.atlasmap.java.test.TargetTestClass) File(java.io.File) AtlasSession(io.atlasmap.api.AtlasSession) AtlasMappingBaseTest(io.atlasmap.itests.reference.AtlasMappingBaseTest) Test(org.junit.jupiter.api.Test)

Example 48 with AtlasJsonTestUnrootedMapper

use of io.atlasmap.json.test.AtlasJsonTestUnrootedMapper in project atlasmap by atlasmap.

the class JavaJsonCombineTest method testProcessCombineOutOfOrder.

@Test
public void testProcessCombineOutOfOrder() throws Exception {
    AtlasContext context = atlasContextFactory.createContext(new File("src/test/resources/javaToJson/atlasmapping-combine-outoforder.json").toURI());
    AtlasSession session = context.createSession();
    BaseContact sourceContact = AtlasTestUtil.generateContact(SourceContact.class);
    session.setDefaultSourceDocument(sourceContact);
    context.process(session);
    Object object = session.getDefaultTargetDocument();
    assertNotNull(object);
    assertTrue(object instanceof String);
    AtlasJsonTestUnrootedMapper mapper = new AtlasJsonTestUnrootedMapper();
    io.atlasmap.json.test.TargetContact targetContact = mapper.readValue((String) object, io.atlasmap.json.test.TargetContact.class);
    assertEquals("Ozzie Smith 5551212 81111", targetContact.getFirstName());
    assertNull(targetContact.getLastName());
    assertNull(targetContact.getPhoneNumber());
    assertNull(targetContact.getZipCode());
    assertFalse(session.hasErrors());
}
Also used : BaseContact(io.atlasmap.java.test.BaseContact) AtlasContext(io.atlasmap.api.AtlasContext) AtlasJsonTestUnrootedMapper(io.atlasmap.json.test.AtlasJsonTestUnrootedMapper) File(java.io.File) AtlasSession(io.atlasmap.api.AtlasSession) AtlasMappingBaseTest(io.atlasmap.itests.reference.AtlasMappingBaseTest) Test(org.junit.jupiter.api.Test)

Example 49 with AtlasJsonTestUnrootedMapper

use of io.atlasmap.json.test.AtlasJsonTestUnrootedMapper in project atlasmap by atlasmap.

the class JavaJsonCombineTest method testProcessCombineNullInput.

@Test
public void testProcessCombineNullInput() throws Exception {
    AtlasContext context = atlasContextFactory.createContext(new File("src/test/resources/javaToJson/atlasmapping-combine-inputnull.json").toURI());
    AtlasSession session = context.createSession();
    BaseContact sourceContact = AtlasTestUtil.generateContact(SourceContact.class);
    sourceContact.setLastName(null);
    session.setDefaultSourceDocument(sourceContact);
    context.process(session);
    Object object = session.getDefaultTargetDocument();
    assertNotNull(object);
    assertTrue(object instanceof String);
    AtlasJsonTestUnrootedMapper mapper = new AtlasJsonTestUnrootedMapper();
    io.atlasmap.json.test.TargetContact targetContact = mapper.readValue((String) object, io.atlasmap.json.test.TargetContact.class);
    assertNotNull(targetContact);
    assertEquals("Ozzie  5551212 81111", targetContact.getFirstName());
    assertFalse(session.hasErrors());
}
Also used : BaseContact(io.atlasmap.java.test.BaseContact) AtlasContext(io.atlasmap.api.AtlasContext) AtlasJsonTestUnrootedMapper(io.atlasmap.json.test.AtlasJsonTestUnrootedMapper) File(java.io.File) AtlasSession(io.atlasmap.api.AtlasSession) AtlasMappingBaseTest(io.atlasmap.itests.reference.AtlasMappingBaseTest) Test(org.junit.jupiter.api.Test)

Example 50 with AtlasJsonTestUnrootedMapper

use of io.atlasmap.json.test.AtlasJsonTestUnrootedMapper in project atlasmap by atlasmap.

the class JavaJsonFlatMappingTest method testProcessJavaJsonFlatPrimitiveUnrooted.

@Test
public void testProcessJavaJsonFlatPrimitiveUnrooted() throws Exception {
    AtlasContext context = atlasContextFactory.createContext(new File("src/test/resources/javaToJson/atlasmapping-flatprimitive-unrooted.json"));
    AtlasSession session = context.createSession();
    session.setDefaultSourceDocument(generateFlatPrimitiveClass(SourceFlatPrimitiveClass.class));
    context.process(session);
    Object object = session.getDefaultTargetDocument();
    assertNotNull(object);
    assertTrue(object instanceof String);
    AtlasJsonTestUnrootedMapper testMapper = new AtlasJsonTestUnrootedMapper();
    TargetFlatPrimitive targetObject = testMapper.readValue((String) object, TargetFlatPrimitive.class);
    AtlasTestUtil.validateJsonFlatPrimitivePrimitiveFields(targetObject);
}
Also used : TargetFlatPrimitive(io.atlasmap.json.test.TargetFlatPrimitive) AtlasContext(io.atlasmap.api.AtlasContext) AtlasJsonTestUnrootedMapper(io.atlasmap.json.test.AtlasJsonTestUnrootedMapper) SourceFlatPrimitiveClass(io.atlasmap.java.test.SourceFlatPrimitiveClass) File(java.io.File) AtlasSession(io.atlasmap.api.AtlasSession) AtlasMappingBaseTest(io.atlasmap.itests.reference.AtlasMappingBaseTest) Test(org.junit.jupiter.api.Test)

Aggregations

AtlasContext (io.atlasmap.api.AtlasContext)50 AtlasSession (io.atlasmap.api.AtlasSession)50 AtlasJsonTestUnrootedMapper (io.atlasmap.json.test.AtlasJsonTestUnrootedMapper)50 File (java.io.File)50 AtlasMappingBaseTest (io.atlasmap.itests.reference.AtlasMappingBaseTest)20 AtlasMappingBaseTest (io.atlasmap.reference.AtlasMappingBaseTest)20 Test (org.junit.Test)20 Test (org.junit.jupiter.api.Test)20 BaseContact (io.atlasmap.java.test.BaseContact)18 TargetFlatPrimitive (io.atlasmap.json.test.TargetFlatPrimitive)16 BaseOrder (io.atlasmap.java.test.BaseOrder)6 TargetOrder (io.atlasmap.json.test.TargetOrder)6 BaseFlatPrimitiveClass (io.atlasmap.java.test.BaseFlatPrimitiveClass)4 SourceFlatPrimitiveClass (io.atlasmap.java.test.SourceFlatPrimitiveClass)4 TargetTestClass (io.atlasmap.java.test.TargetTestClass)4 TargetContact (io.atlasmap.java.test.TargetContact)2 TargetFlatPrimitiveClass (io.atlasmap.java.test.TargetFlatPrimitiveClass)2 AtlasJsonTestRootedMapper (io.atlasmap.json.test.AtlasJsonTestRootedMapper)2 TargetContact (io.atlasmap.json.test.TargetContact)2 XmlOrderElement (io.atlasmap.xml.test.v2.XmlOrderElement)2