Search in sources :

Example 1 with DateTimeClass

use of io.atlasmap.java.test.DateTimeClass in project atlasmap by atlasmap.

the class JavaJavaDateTimeMappingTest method doTest.

private void doTest(int offset) throws Exception {
    AtlasMapping atlasMapping = AtlasModelFactory.createAtlasMapping();
    atlasMapping.setName("JavaJavaDateTimeMapping");
    addDataSource(atlasMapping, "atlas:java?className=io.atlasmap.java.test.DateTimeClass", DataSourceType.SOURCE);
    addDataSource(atlasMapping, "atlas:java?className=io.atlasmap.java.test.DateTimeClass", DataSourceType.TARGET);
    List<BaseMapping> mappings = atlasMapping.getMappings().getMapping();
    for (int i = 0; i < DATE_TIME_FIELDS.length; i++) {
        int targetIndex = offset + i < DATE_TIME_FIELDS.length ? offset + i : offset + i - DATE_TIME_FIELDS.length;
        JavaField sourceField = copyJavaField(DATE_TIME_FIELDS[i]);
        JavaField targetField = copyJavaField(DATE_TIME_FIELDS[targetIndex]);
        if (UNSUPPORTED.containsKey(sourceField.getFieldType()) && UNSUPPORTED.get(sourceField.getFieldType()).equals(targetField.getFieldType())) {
            sourceField = copyJavaField(targetField);
        }
        Mapping mfm = AtlasModelFactory.createMapping(MappingType.MAP);
        mfm.getInputField().add(sourceField);
        mfm.getOutputField().add(targetField);
        mappings.add(mfm);
    }
    AtlasContext context = ((DefaultAtlasContextFactory) atlasContextFactory).createContext(atlasMapping);
    AtlasSession session = context.createSession();
    session.setDefaultSourceDocument(createSource());
    context.process(session);
    Object object = session.getDefaultTargetDocument();
    assertNotNull(object);
    assertTrue(object instanceof DateTimeClass);
    validateTarget((DateTimeClass) object);
}
Also used : DefaultAtlasContextFactory(io.atlasmap.core.DefaultAtlasContextFactory) AtlasMapping(io.atlasmap.v2.AtlasMapping) JavaField(io.atlasmap.java.v2.JavaField) DateTimeClass(io.atlasmap.java.test.DateTimeClass) AtlasContext(io.atlasmap.api.AtlasContext) BaseMapping(io.atlasmap.v2.BaseMapping) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping) AtlasSession(io.atlasmap.api.AtlasSession) BaseMapping(io.atlasmap.v2.BaseMapping)

Example 2 with DateTimeClass

use of io.atlasmap.java.test.DateTimeClass in project atlasmap by atlasmap.

the class JavaJavaDateTimeMappingTest method doTest.

private void doTest(int offset) throws Exception {
    AtlasMapping atlasMapping = AtlasModelFactory.createAtlasMapping();
    atlasMapping.setName("JavaJavaDateTimeMapping");
    addDataSource(atlasMapping, "atlas:java?className=io.atlasmap.java.test.DateTimeClass", DataSourceType.SOURCE);
    addDataSource(atlasMapping, "atlas:java?className=io.atlasmap.java.test.DateTimeClass", DataSourceType.TARGET);
    List<BaseMapping> mappings = atlasMapping.getMappings().getMapping();
    for (int i = 0; i < DATE_TIME_FIELDS.length; i++) {
        int targetIndex = offset + i < DATE_TIME_FIELDS.length ? offset + i : offset + i - DATE_TIME_FIELDS.length;
        JavaField sourceField = copyJavaField(DATE_TIME_FIELDS[i]);
        JavaField targetField = copyJavaField(DATE_TIME_FIELDS[targetIndex]);
        if (UNSUPPORTED.containsKey(sourceField.getFieldType()) && UNSUPPORTED.get(sourceField.getFieldType()).equals(targetField.getFieldType())) {
            sourceField = copyJavaField(targetField);
        }
        Mapping mfm = AtlasModelFactory.createMapping(MappingType.MAP);
        mfm.getInputField().add(sourceField);
        mfm.getOutputField().add(targetField);
        mappings.add(mfm);
    }
    AtlasContext context = ((DefaultAtlasContextFactory) atlasContextFactory).createContext(atlasMapping);
    AtlasSession session = context.createSession();
    session.setDefaultSourceDocument(createSource());
    context.process(session);
    Object object = session.getDefaultTargetDocument();
    assertNotNull(object);
    assertTrue(object instanceof DateTimeClass);
    validateTarget((DateTimeClass) object);
}
Also used : DefaultAtlasContextFactory(io.atlasmap.core.DefaultAtlasContextFactory) AtlasMapping(io.atlasmap.v2.AtlasMapping) JavaField(io.atlasmap.java.v2.JavaField) DateTimeClass(io.atlasmap.java.test.DateTimeClass) AtlasContext(io.atlasmap.api.AtlasContext) BaseMapping(io.atlasmap.v2.BaseMapping) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping) AtlasSession(io.atlasmap.api.AtlasSession) BaseMapping(io.atlasmap.v2.BaseMapping)

Example 3 with DateTimeClass

use of io.atlasmap.java.test.DateTimeClass in project atlasmap by atlasmap.

the class JavaJavaDateTimeMappingTest method createSource.

private DateTimeClass createSource() {
    DateTimeClass sourceClass = new DateTimeClass();
    sourceClass.setCalendarField(Calendar.getInstance());
    sourceClass.setDateField(Date.from(Instant.now()));
    sourceClass.setGregorianCalendarField((GregorianCalendar) GregorianCalendar.getInstance());
    sourceClass.setLocalDateField(LocalDate.now());
    sourceClass.setLocalDateTimeField(LocalDateTime.now());
    sourceClass.setLocalTimeField(LocalTime.now());
    sourceClass.setMonthDayField(MonthDay.now());
    sourceClass.setSqlDateField(new java.sql.Date(Instant.now().toEpochMilli()));
    sourceClass.setSqlTimeField(new java.sql.Time(Instant.now().toEpochMilli()));
    sourceClass.setSqlTimestampField(new java.sql.Timestamp(Instant.now().toEpochMilli()));
    sourceClass.setYearField(Year.now());
    sourceClass.setYearMonthField(YearMonth.now());
    sourceClass.setZonedDateTimeField(ZonedDateTime.now());
    return sourceClass;
}
Also used : DateTimeClass(io.atlasmap.java.test.DateTimeClass)

Example 4 with DateTimeClass

use of io.atlasmap.java.test.DateTimeClass in project atlasmap by atlasmap.

the class JavaJavaDateTimeMappingTest method createSource.

private DateTimeClass createSource() {
    DateTimeClass sourceClass = new DateTimeClass();
    sourceClass.setCalendarField(Calendar.getInstance());
    sourceClass.setDateField(Date.from(Instant.now()));
    sourceClass.setGregorianCalendarField((GregorianCalendar) GregorianCalendar.getInstance());
    sourceClass.setLocalDateField(LocalDate.now());
    sourceClass.setLocalDateTimeField(LocalDateTime.now());
    sourceClass.setLocalTimeField(LocalTime.now());
    sourceClass.setMonthDayField(MonthDay.now());
    sourceClass.setSqlDateField(new java.sql.Date(Instant.now().toEpochMilli()));
    sourceClass.setSqlTimeField(new java.sql.Time(Instant.now().toEpochMilli()));
    sourceClass.setSqlTimestampField(new java.sql.Timestamp(Instant.now().toEpochMilli()));
    sourceClass.setYearField(Year.now());
    sourceClass.setYearMonthField(YearMonth.now());
    sourceClass.setZonedDateTimeField(ZonedDateTime.now());
    return sourceClass;
}
Also used : DateTimeClass(io.atlasmap.java.test.DateTimeClass)

Aggregations

DateTimeClass (io.atlasmap.java.test.DateTimeClass)4 AtlasContext (io.atlasmap.api.AtlasContext)2 AtlasSession (io.atlasmap.api.AtlasSession)2 DefaultAtlasContextFactory (io.atlasmap.core.DefaultAtlasContextFactory)2 JavaField (io.atlasmap.java.v2.JavaField)2 AtlasMapping (io.atlasmap.v2.AtlasMapping)2 BaseMapping (io.atlasmap.v2.BaseMapping)2 Mapping (io.atlasmap.v2.Mapping)2