Search in sources :

Example 1 with MapperBuilderErrorHandler

use of org.simpleflatmapper.map.MapperBuilderErrorHandler in project SimpleFlatMapper by arnaudroger.

the class CsvWriterTest method testWriterWithCustomMapperConfig.

@Test
public void testWriterWithCustomMapperConfig() throws Exception {
    CsvWriter.CsvWriterDSL<DbObject> from = CsvWriter.from(DbObject.class);
    from = from.mapperConfig(from.mapperConfig().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) {
        }
    }));
    from.columns("nonexistent");
}
Also used : Type(java.lang.reflect.Type) MapperBuilderErrorHandler(org.simpleflatmapper.map.MapperBuilderErrorHandler) CsvWriter(org.simpleflatmapper.csv.CsvWriter) DbObject(org.simpleflatmapper.test.beans.DbObject) Test(org.junit.Test)

Example 2 with MapperBuilderErrorHandler

use of org.simpleflatmapper.map.MapperBuilderErrorHandler 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 3 with MapperBuilderErrorHandler

use of org.simpleflatmapper.map.MapperBuilderErrorHandler in project SimpleFlatMapper by arnaudroger.

the class PropertyMappingsBuilderTest method testSelfPropertyInvalidation.

@Test
public void testSelfPropertyInvalidation() {
    final ClassMeta<DbObject> classMeta = ReflectionService.newInstance().getClassMeta(DbObject.class);
    MapperBuilderErrorHandler errorHandler = mock(MapperBuilderErrorHandler.class);
    PropertyMappingsBuilder<DbObject, SampleFieldKey, FieldMapperColumnDefinition<SampleFieldKey>> builder = PropertyMappingsBuilder.of(classMeta, MapperConfig.<SampleFieldKey>fieldMapperConfig().mapperBuilderErrorHandler(errorHandler), ConstantPredicate.<PropertyMeta<?, ?>>truePredicate());
    builder.addProperty(new SampleFieldKey("self", 0), FieldMapperColumnDefinition.<SampleFieldKey>identity());
    verify(errorHandler, never()).customFieldError(any(FieldKey.class), any(String.class));
    verify(errorHandler, never()).accessorNotFound(any(String.class));
    verify(errorHandler, never()).propertyNotFound(any(Type.class), any(String.class));
    builder.addProperty(new SampleFieldKey("id", 1), FieldMapperColumnDefinition.<SampleFieldKey>identity());
    verify(errorHandler).propertyNotFound(DbObject.class, "self");
}
Also used : FieldMapperColumnDefinition(org.simpleflatmapper.map.property.FieldMapperColumnDefinition) Type(java.lang.reflect.Type) IgnoreMapperBuilderErrorHandler(org.simpleflatmapper.map.IgnoreMapperBuilderErrorHandler) MapperBuilderErrorHandler(org.simpleflatmapper.map.MapperBuilderErrorHandler) DbObject(org.simpleflatmapper.test.beans.DbObject) FieldKey(org.simpleflatmapper.map.FieldKey) Test(org.junit.Test)

Example 4 with MapperBuilderErrorHandler

use of org.simpleflatmapper.map.MapperBuilderErrorHandler in project SimpleFlatMapper by arnaudroger.

the class JdbcMapperErrorTest method testHandleMapperErrorSetterNotFound.

@Test
public void testHandleMapperErrorSetterNotFound() throws NoSuchMethodException, SecurityException, IOException {
    MapperBuilderErrorHandler errorHandler = mock(MapperBuilderErrorHandler.class);
    JdbcMapperBuilder<DbObject> builder = JdbcMapperFactoryHelper.asm().mapperBuilderErrorHandler(errorHandler).newBuilder(DbObject.class);
    builder.addMapping("id", 1);
    builder.addMapping("notthere1", 2);
    verify(errorHandler).propertyNotFound(DbObject.class, "notthere1");
    builder.addMapping("notthere3");
    verify(errorHandler).propertyNotFound(DbObject.class, "notthere3");
}
Also used : MapperBuilderErrorHandler(org.simpleflatmapper.map.MapperBuilderErrorHandler) DbObject(org.simpleflatmapper.test.beans.DbObject) Test(org.junit.Test)

Example 5 with MapperBuilderErrorHandler

use of org.simpleflatmapper.map.MapperBuilderErrorHandler in project SimpleFlatMapper by arnaudroger.

the class CsvMapperBuilderTest method testMapDbObjectWrongName.

@Test
public void testMapDbObjectWrongName() throws Exception {
    MapperBuilderErrorHandler mapperBuilderErrorHandler = mock(MapperBuilderErrorHandler.class);
    CsvMapperBuilder<DbFinalObject> builder = csvMapperFactory.mapperBuilderErrorHandler(mapperBuilderErrorHandler).newBuilder(DbFinalObject.class);
    builder.addMapping("id");
    builder.addMapping("No_prop");
    verify(mapperBuilderErrorHandler).propertyNotFound(DbFinalObject.class, "No_prop");
}
Also used : DbFinalObject(org.simpleflatmapper.test.beans.DbFinalObject) MapperBuilderErrorHandler(org.simpleflatmapper.map.MapperBuilderErrorHandler) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)6 MapperBuilderErrorHandler (org.simpleflatmapper.map.MapperBuilderErrorHandler)6 Type (java.lang.reflect.Type)3 DbObject (org.simpleflatmapper.test.beans.DbObject)3 FieldKey (org.simpleflatmapper.map.FieldKey)2 IgnoreMapperBuilderErrorHandler (org.simpleflatmapper.map.IgnoreMapperBuilderErrorHandler)2 FieldMapperColumnDefinition (org.simpleflatmapper.map.property.FieldMapperColumnDefinition)2 CsvWriter (org.simpleflatmapper.csv.CsvWriter)1 ConsumerErrorHandler (org.simpleflatmapper.map.ConsumerErrorHandler)1 FieldMapperErrorHandler (org.simpleflatmapper.map.FieldMapperErrorHandler)1 MappingException (org.simpleflatmapper.map.MappingException)1 RethrowConsumerErrorHandler (org.simpleflatmapper.map.error.RethrowConsumerErrorHandler)1 RethrowMapperBuilderErrorHandler (org.simpleflatmapper.map.error.RethrowMapperBuilderErrorHandler)1 AbstractMapperFactory (org.simpleflatmapper.map.mapper.AbstractMapperFactory)1 DbFinalObject (org.simpleflatmapper.test.beans.DbFinalObject)1 SampleFieldKey (org.simpleflatmapper.test.map.SampleFieldKey)1