Search in sources :

Example 1 with DbEnumObject

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

the class JdbcMapperEnumTest method testIndexedEnumUndefined.

@Test
public void testIndexedEnumUndefined() throws Exception {
    JdbcMapperBuilder<DbEnumObject> builder = JdbcMapperFactoryHelper.asm().newBuilder(DbEnumObject.class);
    builder.addMapping("val", 1);
    JdbcMapper<DbEnumObject> mapper = builder.mapper();
    ResultSet rs = mock(ResultSet.class);
    when(rs.getObject(1)).thenReturn(Integer.valueOf(2));
    assertEquals(DbObject.Type.type3, mapper.map(rs).getVal());
    when(rs.getObject(1)).thenReturn("type2");
    assertEquals(DbObject.Type.type2, mapper.map(rs).getVal());
}
Also used : ResultSet(java.sql.ResultSet) DbEnumObject(org.simpleflatmapper.test.beans.DbEnumObject) Test(org.junit.Test)

Example 2 with DbEnumObject

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

the class JdbcMapperEnumTest method testIndexedEnumString.

@Test
public void testIndexedEnumString() throws Exception {
    JdbcMapperBuilder<DbEnumObject> builder = JdbcMapperFactoryHelper.asm().newBuilder(DbEnumObject.class);
    builder.addMapping("val", 1, Types.VARCHAR);
    JdbcMapper<DbEnumObject> mapper = builder.mapper();
    ResultSet rs = mock(ResultSet.class);
    when(rs.getString(1)).thenReturn("type2");
    assertEquals(DbObject.Type.type2, mapper.map(rs).getVal());
}
Also used : ResultSet(java.sql.ResultSet) DbEnumObject(org.simpleflatmapper.test.beans.DbEnumObject) Test(org.junit.Test)

Example 3 with DbEnumObject

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

the class JdbcMapperEnumTest method testIndexedEnumOrdinal.

@Test
public void testIndexedEnumOrdinal() throws Exception {
    JdbcMapperBuilder<DbEnumObject> builder = JdbcMapperFactoryHelper.asm().newBuilder(DbEnumObject.class);
    builder.addMapping("val", 1, Types.INTEGER);
    JdbcMapper<DbEnumObject> mapper = builder.mapper();
    ResultSet rs = mock(ResultSet.class);
    when(rs.getInt(1)).thenReturn(2);
    assertEquals(DbObject.Type.type3, mapper.map(rs).getVal());
}
Also used : ResultSet(java.sql.ResultSet) DbEnumObject(org.simpleflatmapper.test.beans.DbEnumObject) Test(org.junit.Test)

Example 4 with DbEnumObject

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

the class JdbcMapperEnumTest method testIndexedEnumFactoryMethod.

@Test
public void testIndexedEnumFactoryMethod() throws Exception {
    JdbcMapperBuilder<DbEnumObject> builder = JdbcMapperFactoryHelper.asm().newBuilder(DbEnumObject.class);
    builder.addMapping("val", 1, Types.VARCHAR, new Object[] { ConverterProperty.of(new ContextualConverter<String, DbObject.Type>() {

        @Override
        public DbObject.Type convert(String s, Context context) throws Exception {
            return DbObject.Type.shortForm(s);
        }
    }) });
    JdbcMapper<DbEnumObject> mapper = builder.mapper();
    ResultSet rs = mock(ResultSet.class);
    when(rs.getString(1)).thenReturn("t2");
    assertEquals(DbObject.Type.type2, mapper.map(rs).getVal());
}
Also used : Context(org.simpleflatmapper.converter.Context) DbObject(org.simpleflatmapper.test.beans.DbObject) ResultSet(java.sql.ResultSet) DbEnumObject(org.simpleflatmapper.test.beans.DbEnumObject) ContextualConverter(org.simpleflatmapper.converter.ContextualConverter) Test(org.junit.Test)

Aggregations

ResultSet (java.sql.ResultSet)4 Test (org.junit.Test)4 DbEnumObject (org.simpleflatmapper.test.beans.DbEnumObject)4 Context (org.simpleflatmapper.converter.Context)1 ContextualConverter (org.simpleflatmapper.converter.ContextualConverter)1 DbObject (org.simpleflatmapper.test.beans.DbObject)1