Search in sources :

Example 6 with DbObject

use of org.simpleflatmapper.test.beans.DbObject in project SimpleFlatMapper by arnaudroger.

the class AbstractConstantTargetMapperBuilderTest method testConstantValue.

@Test
public void testConstantValue() throws Exception {
    ClassMeta<DbObject> classMeta = ReflectionService.newInstance().<DbObject>getClassMeta(DbObject.class);
    Writerbuilder<DbObject> builder = new Writerbuilder<DbObject>(classMeta);
    builder.addColumn("id");
    builder.addColumn("blop", new ConstantValueProperty<String>("blop", String.class));
    DbObject dbObject = DbObject.newInstance();
    List<Object> list = builder.mapper().map(dbObject);
    assertEquals(list.get(0), dbObject.getId());
    assertEquals("blop", list.get(1));
}
Also used : DbObject(org.simpleflatmapper.test.beans.DbObject) DbObject(org.simpleflatmapper.test.beans.DbObject) Test(org.junit.Test)

Example 7 with DbObject

use of org.simpleflatmapper.test.beans.DbObject in project SimpleFlatMapper by arnaudroger.

the class AbstractMapperBuilderTest method testDefaultValue.

@Test
public void testDefaultValue() throws Exception {
    ClassMeta<DbObject> classMeta = ReflectionService.newInstance().<DbObject>getClassMeta(DbObject.class);
    FieldMapperColumnDefinitionProviderImpl<SampleFieldKey> definitionProvider = new FieldMapperColumnDefinitionProviderImpl<SampleFieldKey>();
    definitionProvider.addColumnProperty("type_name", new DefaultValueProperty<DbObject.Type>(DbObject.Type.type4));
    MapperConfig<SampleFieldKey, FieldMapperColumnDefinition<SampleFieldKey>> mapperConfig = MapperConfig.<SampleFieldKey>fieldMapperConfig().columnDefinitions(definitionProvider);
    Mapper<Object[], DbObject> mapper = new SampleMapperBuilder<DbObject>(classMeta, mapperConfig).addMapping("id").mapper();
    Object[] data = new Object[] { 3l };
    DbObject dbObject = mapper.map(data);
    assertEquals(3l, dbObject.getId());
    assertEquals(DbObject.Type.type4, dbObject.getTypeName());
}
Also used : FieldMapperColumnDefinition(org.simpleflatmapper.map.property.FieldMapperColumnDefinition) DbObject(org.simpleflatmapper.test.beans.DbObject) Type(java.lang.reflect.Type) SampleFieldKey(org.simpleflatmapper.test.map.SampleFieldKey) DbListObject(org.simpleflatmapper.test.beans.DbListObject) DbObject(org.simpleflatmapper.test.beans.DbObject) DbFinal1DeepObject(org.simpleflatmapper.test.beans.DbFinal1DeepObject) DbPartialFinalObject(org.simpleflatmapper.test.beans.DbPartialFinalObject) DbFinalObject(org.simpleflatmapper.test.beans.DbFinalObject) Test(org.junit.Test)

Example 8 with DbObject

use of org.simpleflatmapper.test.beans.DbObject in project SimpleFlatMapper by arnaudroger.

the class AbstractMapperBuilderTest method testSetDbObject.

@Test
public void testSetDbObject() {
    ClassMeta<Set<DbObject>> classMeta = ReflectionService.disableAsm().<Set<DbObject>>getClassMeta(new TypeReference<Set<DbObject>>() {
    }.getType());
    Mapper<Object[], Set<DbObject>> mapper = new SampleMapperBuilder<Set<DbObject>>(classMeta).addMapping("1_id").addMapping("1_name").addMapping("2_id").addMapping("2_name").mapper();
    Set<DbObject> map = mapper.map(new Object[] { 1l, "name1", 2l, "name2" });
    assertEquals(2, map.size());
    Iterator<DbObject> it = map.iterator();
    DbObject o = it.next();
    if (o.getId() == 1l) {
        assertEquals("name1", o.getName());
        o = it.next();
        assertEquals(2l, o.getId());
        assertEquals("name2", o.getName());
    } else {
        assertEquals("name2", o.getName());
        o = it.next();
        assertEquals(1l, o.getId());
        assertEquals("name1", o.getName());
    }
}
Also used : Set(java.util.Set) DbObject(org.simpleflatmapper.test.beans.DbObject) TypeReference(org.simpleflatmapper.util.TypeReference) Test(org.junit.Test)

Example 9 with DbObject

use of org.simpleflatmapper.test.beans.DbObject 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 10 with DbObject

use of org.simpleflatmapper.test.beans.DbObject in project SimpleFlatMapper by arnaudroger.

the class SetRowMapperTest method checkSetRowMapperIdNameEmail.

private void checkSetRowMapperIdNameEmail(SetRowMapper<Object[], Object[][], DbObject, RuntimeException> staticSetRowMapper) throws Exception {
    checkIdNameEmailResult(staticSetRowMapper.forEach(ID_NAME_EMAIL_DATA, new ListCollector<DbObject>()).getList());
    checkIdNameEmailResult(staticSetRowMapper.iterator(ID_NAME_EMAIL_DATA));
    // IFJAVA8_START
    checkIdNameEmailResult(staticSetRowMapper.stream(ID_NAME_EMAIL_DATA).collect(Collectors.<DbObject>toList()));
    // IFJAVA8_END
    checkIdNameEmailRow(1l, staticSetRowMapper.map(ID_NAME_EMAIL_DATA[0]));
    checkIdNameEmailRow(1l, staticSetRowMapper.map(ID_NAME_EMAIL_DATA[0], null));
    DbObject d = new DbObject();
    staticSetRowMapper.mapTo(ID_NAME_EMAIL_DATA[0], d, null);
    checkIdNameEmailRow(1l, d);
}
Also used : DbObject(org.simpleflatmapper.test.beans.DbObject)

Aggregations

DbObject (org.simpleflatmapper.test.beans.DbObject)83 Test (org.junit.Test)75 Connection (java.sql.Connection)27 PreparedStatement (java.sql.PreparedStatement)16 ResultSet (java.sql.ResultSet)14 SQLException (java.sql.SQLException)10 CheckedConsumer (org.simpleflatmapper.util.CheckedConsumer)10 ArrayList (java.util.ArrayList)9 MappingException (org.simpleflatmapper.map.MappingException)6 DbFinalObject (org.simpleflatmapper.test.beans.DbFinalObject)6 Type (java.lang.reflect.Type)5 ParseException (java.text.ParseException)5 JdbcMapperFactory (org.simpleflatmapper.jdbc.JdbcMapperFactory)5 StringReader (java.io.StringReader)4 JdbcColumnKey (org.simpleflatmapper.jdbc.JdbcColumnKey)4 DbPartialFinalObject (org.simpleflatmapper.test.beans.DbPartialFinalObject)4 Statement (java.sql.Statement)3 MapperBuilderErrorHandler (org.simpleflatmapper.map.MapperBuilderErrorHandler)3 FieldMapperColumnDefinition (org.simpleflatmapper.map.property.FieldMapperColumnDefinition)3 ListCollector (org.simpleflatmapper.util.ListCollector)3