Search in sources :

Example 6 with SampleFieldKey

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

the class AbstractMapperFactoryTest method testErrorHandlers.

@Test
public void testErrorHandlers() {
    MapperFactory mapperFactory = new MapperFactory();
    FieldMapperErrorHandler<SampleFieldKey> fieldMapperErrorHandler = new FieldMapperErrorHandler<SampleFieldKey>() {

        @Override
        public void errorMappingField(SampleFieldKey key, Object source, Object target, Exception error) throws MappingException {
        }
    };
    MapperBuilderErrorHandler mapperBuilderErrorHandler = new MapperBuilderErrorHandler() {

        @Override
        public void accessorNotFound(String msg) {
        }

        @Override
        public void propertyNotFound(Type target, String property) {
        }

        @Override
        public void customFieldError(FieldKey<?> key, String message) {
        }
    };
    ConsumerErrorHandler consumerErrorHandler = new ConsumerErrorHandler() {

        @Override
        public void handlerError(Throwable error, Object target) {
        }
    };
    mapperFactory.fieldMapperErrorHandler(fieldMapperErrorHandler);
    mapperFactory.mapperBuilderErrorHandler(mapperBuilderErrorHandler);
    mapperFactory.consumerErrorHandler(consumerErrorHandler);
    MapperConfig<SampleFieldKey, FieldMapperColumnDefinition<SampleFieldKey>> mapperConfig = mapperFactory.mapperConfig();
    assertEquals(fieldMapperErrorHandler, mapperConfig.fieldMapperErrorHandler());
    assertEquals(mapperBuilderErrorHandler, mapperConfig.mapperBuilderErrorHandler());
    assertEquals(consumerErrorHandler, mapperConfig.consumerErrorHandler());
    Assert.assertEquals(consumerErrorHandler, mapperFactory.consumerErrorHandler());
    mapperFactory = new MapperFactory();
    assertTrue(mapperFactory.ignorePropertyNotFound().mapperConfig().mapperBuilderErrorHandler() instanceof IgnoreMapperBuilderErrorHandler);
}
Also used : FieldMapperColumnDefinition(org.simpleflatmapper.map.property.FieldMapperColumnDefinition) RethrowMapperBuilderErrorHandler(org.simpleflatmapper.map.error.RethrowMapperBuilderErrorHandler) IgnoreMapperBuilderErrorHandler(org.simpleflatmapper.map.IgnoreMapperBuilderErrorHandler) MapperBuilderErrorHandler(org.simpleflatmapper.map.MapperBuilderErrorHandler) IgnoreMapperBuilderErrorHandler(org.simpleflatmapper.map.IgnoreMapperBuilderErrorHandler) MappingException(org.simpleflatmapper.map.MappingException) Type(java.lang.reflect.Type) RethrowConsumerErrorHandler(org.simpleflatmapper.map.error.RethrowConsumerErrorHandler) ConsumerErrorHandler(org.simpleflatmapper.map.ConsumerErrorHandler) AbstractMapperFactory(org.simpleflatmapper.map.mapper.AbstractMapperFactory) SampleFieldKey(org.simpleflatmapper.test.map.SampleFieldKey) FieldMapperErrorHandler(org.simpleflatmapper.map.FieldMapperErrorHandler) FieldKey(org.simpleflatmapper.map.FieldKey) SampleFieldKey(org.simpleflatmapper.test.map.SampleFieldKey) Test(org.junit.Test)

Example 7 with SampleFieldKey

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

the class AbstractMapperFactoryTest method testAsmSettings.

@Test
public void testAsmSettings() {
    ReflectionService reflectionService = new MapperFactory().useAsm(false).getReflectionService();
    assertFalse(reflectionService.isAsmActivated());
    MapperConfig<SampleFieldKey, FieldMapperColumnDefinition<SampleFieldKey>> mapperConfig = new MapperFactory().asmMapperNbFieldsLimit(33).failOnAsm(true).maxMethodSize(13).mapperConfig();
    assertEquals(33, mapperConfig.asmMapperNbFieldsLimit());
    assertEquals(13, mapperConfig.maxMethodSize());
    assertEquals(true, mapperConfig.failOnAsm());
    reflectionService = new ReflectionService(null);
    assertSame(reflectionService, new MapperFactory().reflectionService(reflectionService).getReflectionService());
}
Also used : FieldMapperColumnDefinition(org.simpleflatmapper.map.property.FieldMapperColumnDefinition) AbstractMapperFactory(org.simpleflatmapper.map.mapper.AbstractMapperFactory) SampleFieldKey(org.simpleflatmapper.test.map.SampleFieldKey) ReflectionService(org.simpleflatmapper.reflect.ReflectionService) Test(org.junit.Test)

Example 8 with SampleFieldKey

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

the class ConstantTargetFieldMapperFactoryImplTest method testGetterNotFound.

@Test
public void testGetterNotFound() {
    ConstantTargetFieldMapperFactory<Appendable, SampleFieldKey> factory = ConstantTargetFieldMapperFactoryImpl.<Appendable, SampleFieldKey>newInstance(setterFactory, Appendable.class);
    try {
        PropertyMeta<Object, Object> pm = mock(PropertyMeta.class);
        PropertyMapping<Object, Object, SampleFieldKey, FieldMapperColumnDefinition<SampleFieldKey>> propertyMapping = new PropertyMapping<Object, Object, SampleFieldKey, FieldMapperColumnDefinition<SampleFieldKey>>(pm, new SampleFieldKey("hh", 0), FieldMapperColumnDefinition.<SampleFieldKey>identity());
        factory.newFieldMapper(propertyMapping, null, RethrowMapperBuilderErrorHandler.INSTANCE);
        fail();
    } catch (MapperBuildingException e) {
    }
}
Also used : FieldMapperColumnDefinition(org.simpleflatmapper.map.property.FieldMapperColumnDefinition) PropertyMapping(org.simpleflatmapper.map.mapper.PropertyMapping) MapperBuildingException(org.simpleflatmapper.map.MapperBuildingException) SampleFieldKey(org.simpleflatmapper.test.map.SampleFieldKey) DbObject(org.simpleflatmapper.test.beans.DbObject) ConstantSourceFieldMapperFactoryImplTest(org.simpleflatmapper.test.map.fieldmapper.ConstantSourceFieldMapperFactoryImplTest) Test(org.junit.Test)

Example 9 with SampleFieldKey

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

the class FieldMapperColumnDefinitionProviderImplTest method testProvides.

@Test
public void testProvides() {
    final Object prop1 = "prop1";
    final Object prop2 = "prop2";
    final ConstantUnaryFactory<SampleFieldKey, Object> prop1Fact = ConstantUnaryFactory.<SampleFieldKey, Object>of(prop1);
    final ConstantUnaryFactory<SampleFieldKey, Object> prop2Fact = ConstantUnaryFactory.<SampleFieldKey, Object>of(prop2);
    FieldMapperColumnDefinitionProviderImpl<SampleFieldKey> provider = new FieldMapperColumnDefinitionProviderImpl<SampleFieldKey>();
    final Predicate<SampleFieldKey> prop1Predicate = new Predicate<SampleFieldKey>() {

        @Override
        public boolean test(SampleFieldKey sampleFieldKey) {
            return sampleFieldKey.getIndex() == 0;
        }
    };
    final Predicate<SampleFieldKey> prop2Predicate = new Predicate<SampleFieldKey>() {

        @Override
        public boolean test(SampleFieldKey sampleFieldKey) {
            return sampleFieldKey.getIndex() == 1;
        }
    };
    provider.addColumnProperty(prop1Predicate, prop1Fact);
    provider.addColumnProperty(prop2Predicate, prop2Fact);
    List<AbstractColumnDefinitionProvider.PredicatedColunnPropertyFactory<FieldMapperColumnDefinition<SampleFieldKey>, SampleFieldKey>> properties = provider.getProperties();
    assertEquals(2, properties.size());
    assertEquals(prop1Predicate, properties.get(0).getPredicate());
    assertEquals(prop2Predicate, properties.get(1).getPredicate());
    assertEquals(prop1Fact, properties.get(0).getColumnPropertyFactory());
    assertEquals(prop2Fact, properties.get(1).getColumnPropertyFactory());
    final ArrayList<String> props = new ArrayList<String>();
    provider.addColumnProperty(prop1Predicate, new Object());
    provider.forEach(String.class, new BiConsumer<Predicate<? super SampleFieldKey>, String>() {

        @Override
        public void accept(Predicate<? super SampleFieldKey> predicate, String s) {
            if (s == prop1) {
                assertEquals(predicate, prop1Predicate);
            }
            if (s == prop2) {
                assertEquals(predicate, prop2Predicate);
            }
            props.add(s);
        }
    });
    assertArrayEquals(new String[] { "prop1", "prop2" }, props.toArray(new String[0]));
    assertArrayEquals(new String[] { "prop1" }, provider.getColumnDefinition(new SampleFieldKey("", 0)).lookForAll(String.class));
}
Also used : ArrayList(java.util.ArrayList) Predicate(org.simpleflatmapper.util.Predicate) SampleFieldKey(org.simpleflatmapper.test.map.SampleFieldKey) FieldMapperColumnDefinitionProviderImpl(org.simpleflatmapper.map.mapper.FieldMapperColumnDefinitionProviderImpl) Test(org.junit.Test)

Example 10 with SampleFieldKey

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

the class MappingContextFactoryBuilderTest method testKeysAndSuppliers.

@Test
public void testKeysAndSuppliers() {
    builder.addSupplier(1, new ConstantSupplier<String>("hh"));
    builder.addKey(new SampleFieldKey("k1", 0));
    assertFalse(builder.hasNoKeys());
    MappingContextFactory<Object[]> mappingContextFactory = builder.newFactory();
    assertTrue(mappingContextFactory instanceof BreakDetectorMappingContextFactory);
    assertEquals("hh", mappingContextFactory.newContext().context(1));
    assertNull(mappingContextFactory.newContext().context(0));
}
Also used : BreakDetectorMappingContextFactory(org.simpleflatmapper.map.context.impl.BreakDetectorMappingContextFactory) SampleFieldKey(org.simpleflatmapper.test.map.SampleFieldKey) 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