use of io.atlasmap.java.test.TargetContact in project atlasmap by atlasmap.
the class JavaJavaSeparateTest method testProcessSeparateNullSource.
@Test
public void testProcessSeparateNullSource() throws Exception {
AtlasContext context = atlasContextFactory.createContext(new File("src/test/resources/javaToJava/atlasmapping-separate-inputnull.xml").toURI());
AtlasSession session = context.createSession();
BaseContact sourceContact = AtlasTestUtil.generateContact(SourceContact.class);
sourceContact.setFirstName(null);
sourceContact.setLastName(null);
session.setDefaultSourceDocument(sourceContact);
context.process(session);
Object object = session.getDefaultTargetDocument();
assertNotNull(object);
assertEquals(TargetContact.class.getName(), object.getClass().getName());
TargetContact targetContact = (TargetContact) object;
assertNotNull(targetContact);
assertEquals(null, targetContact.getFirstName());
assertEquals(null, targetContact.getLastName());
assertEquals("5551212", targetContact.getPhoneNumber());
assertEquals("81111", targetContact.getZipCode());
assertFalse(session.hasErrors());
}
use of io.atlasmap.java.test.TargetContact in project atlasmap by atlasmap.
the class JavaJavaSeparateTest method testProcessSeparateSimple.
@Test
public void testProcessSeparateSimple() throws Exception {
AtlasContext context = atlasContextFactory.createContext(new File("src/test/resources/javaToJava/atlasmapping-separate-simple.xml").toURI());
AtlasSession session = context.createSession();
BaseContact sourceContact = AtlasTestUtil.generateContact(SourceContact.class);
sourceContact.setFirstName("Ozzie Smith");
sourceContact.setLastName(null);
session.setDefaultSourceDocument(sourceContact);
context.process(session);
Object object = session.getDefaultTargetDocument();
assertNotNull(object);
assertEquals(TargetContact.class.getName(), object.getClass().getName());
TargetContact targetContact = (TargetContact) object;
AtlasTestUtil.validateContact(targetContact);
assertFalse(session.hasErrors());
}
use of io.atlasmap.java.test.TargetContact in project atlasmap by atlasmap.
the class JsonJavaCombineTest method testProcessCombineNullInput.
@Test
public void testProcessCombineNullInput() throws Exception {
AtlasSession session = processCombineMapping("src/test/resources/jsonToJava/atlasmapping-combine-inputnull.xml", new String(Files.readAllBytes(Paths.get("src/test/resources/jsonToJava/atlas-json-combine-null-lastName.json"))));
TargetContact targetContact = (TargetContact) session.getDefaultTargetDocument();
assertNotNull(targetContact);
assertEquals("Ozzie 5551212 81111", targetContact.getFirstName());
assertFalse(session.hasErrors());
}
use of io.atlasmap.java.test.TargetContact in project atlasmap by atlasmap.
the class JsonJavaCombineTest method testProcessCombineOutOfOrder.
@Test
public void testProcessCombineOutOfOrder() throws Exception {
AtlasSession session = processCombineMapping("src/test/resources/jsonToJava/atlasmapping-combine-outoforder.xml", new String(Files.readAllBytes(Paths.get("src/test/resources/jsonToJava/atlas-json-combine.json"))));
TargetContact targetContact = (TargetContact) session.getDefaultTargetDocument();
assertEquals("Ozzie Smith 5551212 81111", targetContact.getFirstName());
assertNull(targetContact.getLastName());
assertNull(targetContact.getPhoneNumber());
assertNull(targetContact.getZipCode());
assertFalse(session.hasErrors());
}
use of io.atlasmap.java.test.TargetContact in project atlasmap by atlasmap.
the class JavaWriterUtilMock method setObjectOnParent.
/**
* Set the given object within the parentObject.
*
* @param field
* - provided if we need it, I don't think we will since we already
* have the value in hand?
* @param segmentContext
* - current segment for the field's path, this will be the last
* segment in the path.
* @param parentObject
* - the object we're setting the value in
* @param childObject
* - the childObject to set
*/
@SuppressWarnings({ "unchecked" })
@Override
public void setObjectOnParent(Field field, SegmentContext segmentContext, Object parentObject, Object childObject) throws AtlasException {
String segment = segmentContext.getSegment();
if (LOG.isDebugEnabled()) {
LOG.debug("Setting object '" + segmentContext.getSegmentPath() + "'.\n\tchildObject: " + childObject + "\n\tparentObject: " + parentObject);
}
// now the cleanedSegment is a cleaned name such as "addressLine1"
String cleanedSegment = AtlasPath.cleanPathSegment(segment);
if ("addressLine1".equals(cleanedSegment) && parentObject instanceof TargetAddress) {
((TargetAddress) parentObject).setAddressLine1((String) childObject);
} else if ("addressLine1".equals(cleanedSegment) && parentObject instanceof TargetAddress) {
((TargetAddress) parentObject).setAddressLine1((String) childObject);
} else if ("addressLine2".equals(cleanedSegment) && parentObject instanceof TargetAddress) {
((TargetAddress) parentObject).setAddressLine2((String) childObject);
} else if ("city".equals(cleanedSegment) && parentObject instanceof TargetAddress) {
((TargetAddress) parentObject).setCity((String) childObject);
} else if ("state".equals(cleanedSegment) && parentObject instanceof TargetAddress) {
((TargetAddress) parentObject).setState((String) childObject);
} else if ("zipCode".equals(cleanedSegment) && parentObject instanceof TargetAddress) {
((TargetAddress) parentObject).setZipCode((String) childObject);
} else if ("orders".equals(cleanedSegment) && parentObject instanceof TestListOrders) {
((TestListOrders) parentObject).setOrders((List<BaseOrder>) childObject);
} else if ("orders".equals(cleanedSegment) && parentObject instanceof TargetOrderArray) {
((TargetOrderArray) parentObject).setOrders((TargetOrder[]) childObject);
} else if ("address".equals(cleanedSegment) && parentObject instanceof TargetOrder) {
((TargetOrder) parentObject).setAddress((TargetAddress) childObject);
} else if ("name".equals(cleanedSegment) && parentObject instanceof TargetTestClass) {
((TargetTestClass) parentObject).setName((String) childObject);
} else if ("address".equals(cleanedSegment) && parentObject instanceof TargetTestClass) {
((TargetTestClass) parentObject).setAddress((TargetAddress) childObject);
} else if ("listOrders".equals(cleanedSegment) && parentObject instanceof TargetTestClass) {
((TargetTestClass) parentObject).setListOrders((TestListOrders) childObject);
} else if ("orderId".equals(cleanedSegment) && parentObject instanceof TargetOrder) {
((TargetOrder) parentObject).setOrderId((Integer) childObject);
} else if ("orderArray".equals(cleanedSegment) && parentObject instanceof TargetTestClass) {
((TargetTestClass) parentObject).setOrderArray((TargetOrderArray) childObject);
} else if ("numberOrders".equals(cleanedSegment) && parentObject instanceof TargetOrderArray) {
((TargetOrderArray) parentObject).setNumberOrders((Integer) childObject);
} else if ("contact".equals(cleanedSegment) && parentObject instanceof TargetOrder) {
((TargetOrder) parentObject).setContact((TargetContact) childObject);
} else if ("firstName".equals(cleanedSegment) && parentObject instanceof TargetContact) {
((TargetContact) parentObject).setFirstName((String) childObject);
} else if ("lastName".equals(cleanedSegment) && parentObject instanceof TargetContact) {
((TargetContact) parentObject).setLastName((String) childObject);
} else if ("primitives".equals(cleanedSegment) && parentObject instanceof TargetTestClass) {
((TargetTestClass) parentObject).setPrimitives((TargetFlatPrimitiveClass) childObject);
} else if ("intArrayField".equals(cleanedSegment) && parentObject instanceof TargetFlatPrimitiveClass) {
((TargetFlatPrimitiveClass) parentObject).setIntArrayField((int[]) childObject);
} else if ("boxedStringArrayField".equals(cleanedSegment) && parentObject instanceof TargetFlatPrimitiveClass) {
((TargetFlatPrimitiveClass) parentObject).setBoxedStringArrayField((String[]) childObject);
} else if ("statesLong".equals(cleanedSegment) && parentObject instanceof TargetTestClass) {
((TargetTestClass) parentObject).setStatesLong((StateEnumClassLong) childObject);
} else {
String clz = parentObject.getClass().getSimpleName();
String clz2 = childObject.getClass().getSimpleName();
String setter = "set" + cleanedSegment.substring(0, 1).toUpperCase() + cleanedSegment.substring(1);
String fix = "} else if (\"" + cleanedSegment + "\".equals(cleanedSegment) && parentObject instanceof " + clz + ") {\n " + "((" + clz + ") parentObject)." + setter + "((" + clz2 + ")childObject);";
LOG.error(fix);
throw new AtlasException("FIX: " + fix);
}
if (LOG.isDebugEnabled()) {
LOG.debug("Object after value written: " + parentObject);
}
}
Aggregations