Search in sources :

Example 11 with SampleFieldKey

use of org.simpleflatmapper.test.map.SampleFieldKey in project SimpleFlatMapper by arnaudroger.

the class MappingContextFactoryBuilderTest method testKeys.

@Test
public void testKeys() throws Exception {
    builder.addKey(new SampleFieldKey("k1", 0));
    assertFalse(builder.hasNoKeys());
    MappingContextFactory<Object[]> mappingContextFactory = builder.newFactory();
    assertTrue(mappingContextFactory instanceof BreakDetectorMappingContextFactory);
    assertNull(mappingContextFactory.newContext().context(0));
    assertTrue(builder.nullChecker().test(new Object[] { null }));
    assertFalse(builder.nullChecker().test(new Object[] { 123 }));
}
Also used : BreakDetectorMappingContextFactory(org.simpleflatmapper.map.context.impl.BreakDetectorMappingContextFactory) SampleFieldKey(org.simpleflatmapper.test.map.SampleFieldKey) Test(org.junit.Test)

Example 12 with SampleFieldKey

use of org.simpleflatmapper.test.map.SampleFieldKey in project SimpleFlatMapper by arnaudroger.

the class MappingContextFactoryBuilderTest method testKeysWithSubBuilder.

@Test
public void testKeysWithSubBuilder() {
    builder.addKey(new SampleFieldKey("k1", 0));
    MappingContextFactoryBuilder<Object[], SampleFieldKey> subBuilder = builder.newBuilder(Arrays.asList(new SampleFieldKey("k2", 3)), null);
    subBuilder.newBuilder(Arrays.asList(new SampleFieldKey("k3", 6)), null);
    MappingContextFactory<Object[]> mappingContextFactory = builder.newFactory();
    MappingContext<Object[]> mappingContext = mappingContextFactory.newContext();
}
Also used : SampleFieldKey(org.simpleflatmapper.test.map.SampleFieldKey) Test(org.junit.Test)

Example 13 with SampleFieldKey

use of org.simpleflatmapper.test.map.SampleFieldKey in project SimpleFlatMapper by arnaudroger.

the class Issue365Test method mapperConfig.

private MapperConfig<SampleFieldKey, FieldMapperColumnDefinition<SampleFieldKey>> mapperConfig() {
    FieldMapperColumnDefinitionProviderImpl<SampleFieldKey> provider = new FieldMapperColumnDefinitionProviderImpl<SampleFieldKey>();
    provider.addColumnDefinition("benchmark", FieldMapperColumnDefinition.<SampleFieldKey>identity().add(new SetterProperty(SETTER)).add(new GetterProperty(GETTER)));
    return MapperConfig.<SampleFieldKey>fieldMapperConfig().columnDefinitions(provider);
}
Also used : SetterProperty(org.simpleflatmapper.map.property.SetterProperty) SampleFieldKey(org.simpleflatmapper.test.map.SampleFieldKey) FieldMapperColumnDefinitionProviderImpl(org.simpleflatmapper.map.mapper.FieldMapperColumnDefinitionProviderImpl) GetterProperty(org.simpleflatmapper.map.property.GetterProperty)

Example 14 with SampleFieldKey

use of org.simpleflatmapper.test.map.SampleFieldKey in project SimpleFlatMapper by arnaudroger.

the class ConstantSourceFieldMapperFactoryImplTest method createPropertyMapping.

public static <T, P> PropertyMapping<T, P, SampleFieldKey, FieldMapperColumnDefinition<SampleFieldKey>> createPropertyMapping(Class<T> target, String property) {
    ClassMeta<T> classMeta = REFLECTION_SERVICE.getClassMeta(target);
    PropertyMeta<T, P> propertyMeta = classMeta.newPropertyFinder(ConstantPredicate.<PropertyMeta<?, ?>>truePredicate()).findProperty(DefaultPropertyNameMatcher.of(property), new Object[0]);
    PropertyMapping<T, P, SampleFieldKey, FieldMapperColumnDefinition<SampleFieldKey>> pm = new PropertyMapping<T, P, SampleFieldKey, FieldMapperColumnDefinition<SampleFieldKey>>(propertyMeta, new SampleFieldKey(property, 0), FieldMapperColumnDefinition.<SampleFieldKey>identity());
    return pm;
}
Also used : FieldMapperColumnDefinition(org.simpleflatmapper.map.property.FieldMapperColumnDefinition) PropertyMapping(org.simpleflatmapper.map.mapper.PropertyMapping) PropertyMeta(org.simpleflatmapper.reflect.meta.PropertyMeta) SampleFieldKey(org.simpleflatmapper.test.map.SampleFieldKey)

Example 15 with SampleFieldKey

use of org.simpleflatmapper.test.map.SampleFieldKey in project SimpleFlatMapper by arnaudroger.

the class ConstantSourceMapperBuilderTest method testAnonymousParameterWithDifferentType.

@Test
public void testAnonymousParameterWithDifferentType() throws Exception {
    ConstantSourceMapperBuilder<Object, MyObjectWithInner, SampleFieldKey> constantSourceMapperBuilder = new ConstantSourceMapperBuilder<Object, MyObjectWithInner, SampleFieldKey>(mapperSource, classMeta, MapperConfig.config(new IdentityFieldMapperColumnDefinitionProvider<SampleFieldKey>()), new MappingContextFactoryBuilder<Object, SampleFieldKey>(null), SampleFieldKey.KEY_FACTORY);
    constantSourceMapperBuilder.addMapping(new SampleFieldKey("prop", 0, Date.class), FieldMapperColumnDefinition.<SampleFieldKey>identity());
    Mapper<Object, MyObjectWithInner> mapper = constantSourceMapperBuilder.mapper();
    MyObjectWithInner o = mapper.map(null);
    assertEquals(DATE, o.prop.date);
    assertNull(o.prop.str);
}
Also used : IdentityFieldMapperColumnDefinitionProvider(org.simpleflatmapper.map.impl.IdentityFieldMapperColumnDefinitionProvider) SampleFieldKey(org.simpleflatmapper.test.map.SampleFieldKey) ConstantSourceMapperBuilder(org.simpleflatmapper.map.mapper.ConstantSourceMapperBuilder) Date(java.util.Date) Test(org.junit.Test)

Aggregations

SampleFieldKey (org.simpleflatmapper.test.map.SampleFieldKey)21 Test (org.junit.Test)19 AbstractMapperFactory (org.simpleflatmapper.map.mapper.AbstractMapperFactory)7 FieldMapperColumnDefinition (org.simpleflatmapper.map.property.FieldMapperColumnDefinition)6 DbObject (org.simpleflatmapper.test.beans.DbObject)4 ConstantSourceMapperBuilder (org.simpleflatmapper.map.mapper.ConstantSourceMapperBuilder)3 DbFinal1DeepObject (org.simpleflatmapper.test.beans.DbFinal1DeepObject)3 DbFinalObject (org.simpleflatmapper.test.beans.DbFinalObject)3 DbListObject (org.simpleflatmapper.test.beans.DbListObject)3 DbPartialFinalObject (org.simpleflatmapper.test.beans.DbPartialFinalObject)3 Type (java.lang.reflect.Type)2 ArrayList (java.util.ArrayList)2 FieldMapperErrorHandler (org.simpleflatmapper.map.FieldMapperErrorHandler)2 MapperBuildingException (org.simpleflatmapper.map.MapperBuildingException)2 MappingException (org.simpleflatmapper.map.MappingException)2 BreakDetectorMappingContextFactory (org.simpleflatmapper.map.context.impl.BreakDetectorMappingContextFactory)2 RethrowConsumerErrorHandler (org.simpleflatmapper.map.error.RethrowConsumerErrorHandler)2 RethrowMapperBuilderErrorHandler (org.simpleflatmapper.map.error.RethrowMapperBuilderErrorHandler)2 IdentityFieldMapperColumnDefinitionProvider (org.simpleflatmapper.map.impl.IdentityFieldMapperColumnDefinitionProvider)2 FieldMapperColumnDefinitionProviderImpl (org.simpleflatmapper.map.mapper.FieldMapperColumnDefinitionProviderImpl)2