Finish porting tests

This commit is contained in:
Travis Burtrum 2018-05-07 23:49:56 -04:00
parent 9f00f4924f
commit 1c561181ff
3 changed files with 187 additions and 25 deletions

View File

@ -10,6 +10,7 @@ import java.util.Map;
//IFJAVA8_START //IFJAVA8_START
import java.util.stream.Stream; import java.util.stream.Stream;
import java.time.*;
//IFJAVA8_END //IFJAVA8_END
@JdbcMapper.Mapper( @JdbcMapper.Mapper(
@ -46,6 +47,10 @@ public interface QmDao extends JdbcMapper {
String bobTomMap = "SELECT 'bob' as bob, 'tom' as tom FROM person WHERE person_no = 1"; String bobTomMap = "SELECT 'bob' as bob, 'tom' as tom FROM person WHERE person_no = 1";
String selectThreePeople = "SELECT person_no, first_name, last_name, birth_date from person WHERE person_no IN ({personNo1}, {personNo2}, {personNo3}) ORDER BY person_no"; String selectThreePeople = "SELECT person_no, first_name, last_name, birth_date from person WHERE person_no IN ({personNo1}, {personNo2}, {personNo3}) ORDER BY person_no";
String selectBirthDate = "SELECT birth_date FROM person WHERE person_no = {personNo}";
String selectNumVal = "SELECT num_val FROM val WHERE val_no = {valNo}";
String selectStrVal = "SELECT str_val FROM val WHERE val_no = {valNo}";
@JdbcMapper.SQL(personRegular) @JdbcMapper.SQL(personRegular)
FieldPerson getFieldRegularPerson(long personNo) throws SQLException; FieldPerson getFieldRegularPerson(long personNo) throws SQLException;
@ -167,4 +172,62 @@ public interface QmDao extends JdbcMapper {
Stream<FieldPerson> getThreePeopleStream(long personNo1, long personNo2, long personNo3) throws SQLException; Stream<FieldPerson> getThreePeopleStream(long personNo1, long personNo2, long personNo3) throws SQLException;
//IFJAVA8_END //IFJAVA8_END
@SQL("SELECT first_name, last_name FROM person WHERE person_no = {personNo}")
EnumPerson getEnumPerson(long personNo) throws SQLException;
@SQL("SELECT first_name FROM person WHERE person_no = {personNo}")
EnumPerson getEnumPersonConstructor(long personNo) throws SQLException;
@SQL("SELECT first_name FROM person WHERE person_no = {personNo}")
FirstName getFirstName(long personNo) throws SQLException;
@SQL("SELECT str_val as first_name, str_val as last_name FROM val WHERE val_no = 4")
EnumPerson getEnumPersonNull() throws SQLException;
@SQL("SELECT str_val FROM val WHERE val_no = 4")
FirstName getFirstNameNull() throws SQLException;
@SQL("SELECT first_name AS M_PERSON_FIRST_NAME FROM person WHERE person_no = {personNo}")
CaseSensitivePerson getCaseSensitivePerson(long personNo) throws SQLException;
//IFJAVA8_START
@SQL(selectBirthDate)
Instant getBirthdateInstant(long personNo) throws SQLException;
@SQL(selectBirthDate)
LocalDateTime getBirthdateLocalDateTime(long personNo) throws SQLException;
@SQL(selectBirthDate)
LocalDate getBirthdateLocalDate(long personNo) throws SQLException;
@SQL(selectBirthDate)
LocalTime getBirthdateLocalTime(long personNo) throws SQLException;
@SQL(selectBirthDate)
ZonedDateTime getBirthdateZonedDateTime(long personNo) throws SQLException;
@SQL(selectBirthDate)
OffsetDateTime getBirthdateOffsetDateTime(long personNo) throws SQLException;
@SQL(selectBirthDate)
OffsetTime getBirthdateOffsetTime(long personNo) throws SQLException;
@SQL(selectNumVal)
Year getYearInt(long valNo) throws SQLException;
@SQL(selectStrVal)
Year getYearString(long valNo) throws SQLException;
@SQL(selectStrVal)
ZoneId getZoneId(long valNo) throws SQLException;
@SQL(selectStrVal)
ZoneOffset getZoneOffsetInt(long valNo) throws SQLException;
@SQL(selectStrVal)
ZoneOffset getZoneOffsetString(long valNo) throws SQLException;
//IFJAVA8_END
} }

View File

@ -14,6 +14,7 @@ import java.util.Map;
//IFJAVA8_START //IFJAVA8_START
import java.util.stream.Stream; import java.util.stream.Stream;
import java.time.*;
//IFJAVA8_END //IFJAVA8_END
import static com.moparisthebest.jdbc.TryClose.tryClose; import static com.moparisthebest.jdbc.TryClose.tryClose;
@ -40,6 +41,10 @@ public class QueryMapperQmDao implements QmDao {
public static final String selectPersonNo = "SELECT person_no FROM person WHERE person_no = ?"; public static final String selectPersonNo = "SELECT person_no FROM person WHERE person_no = ?";
public static final String selectThreePeople = "SELECT * from person WHERE person_no IN (?,?,?) ORDER BY person_no"; public static final String selectThreePeople = "SELECT * from person WHERE person_no IN (?,?,?) ORDER BY person_no";
public static final String selectBirthDate = "SELECT birth_date FROM person WHERE person_no = ?";
public static final String selectNumVal = "SELECT num_val FROM val WHERE val_no = ?";
public static final String selectStrVal = "SELECT str_val FROM val WHERE val_no = ?";
private final QueryMapper qm; private final QueryMapper qm;
public QueryMapperQmDao(final Connection conn, final ResultSetMapper rsm) { public QueryMapperQmDao(final Connection conn, final ResultSetMapper rsm) {
@ -255,10 +260,104 @@ public class QueryMapperQmDao implements QmDao {
//IFJAVA8_START //IFJAVA8_START
@Override @Override
public java.util.stream.Stream<FieldPerson> getThreePeopleStream(final long personNo1, final long personNo2, final long personNo3) throws SQLException { public Stream<FieldPerson> getThreePeopleStream(final long personNo1, final long personNo2, final long personNo3) throws SQLException {
return qm.toStream(selectThreePeople, return qm.toStream(selectThreePeople,
FieldPerson.class, personNo1, personNo2, personNo3); FieldPerson.class, personNo1, personNo2, personNo3);
} }
//IFJAVA8_END //IFJAVA8_END
@Override
public EnumPerson getEnumPerson(long personNo) throws SQLException {
return qm.toObject("SELECT first_name, last_name FROM person WHERE person_no = ?", EnumPerson.class, personNo);
}
@Override
public EnumPerson getEnumPersonConstructor(long personNo) throws SQLException {
return qm.toObject("SELECT first_name FROM person WHERE person_no = ?", EnumPerson.class, personNo);
}
@Override
public FirstName getFirstName(long personNo) throws SQLException {
return qm.toObject("SELECT first_name FROM person WHERE person_no = ?", FirstName.class, personNo);
}
@Override
public EnumPerson getEnumPersonNull() throws SQLException {
return qm.toObject("SELECT str_val as first_name, str_val as last_name FROM val WHERE val_no = 4", EnumPerson.class);
}
@Override
public FirstName getFirstNameNull() throws SQLException {
return qm.toObject("SELECT str_val FROM val WHERE val_no = 4", FirstName.class);
}
@Override
public CaseSensitivePerson getCaseSensitivePerson(long personNo) throws SQLException {
return qm.toObject("SELECT first_name AS M_PERSON_FIRST_NAME FROM person WHERE person_no = ?", CaseSensitivePerson.class, personNo);
}
//IFJAVA8_START
@Override
public Instant getBirthdateInstant(long personNo) throws SQLException {
return qm.toObject(selectBirthDate, Instant.class, personNo);
}
@Override
public LocalDateTime getBirthdateLocalDateTime(long personNo) throws SQLException {
return qm.toObject(selectBirthDate, LocalDateTime.class, personNo);
}
@Override
public LocalDate getBirthdateLocalDate(long personNo) throws SQLException {
return qm.toObject(selectBirthDate, LocalDate.class, personNo);
}
@Override
public LocalTime getBirthdateLocalTime(long personNo) throws SQLException {
return qm.toObject(selectBirthDate, LocalTime.class, personNo);
}
@Override
public ZonedDateTime getBirthdateZonedDateTime(long personNo) throws SQLException {
return qm.toObject(selectBirthDate, ZonedDateTime.class, personNo);
}
@Override
public OffsetDateTime getBirthdateOffsetDateTime(long personNo) throws SQLException {
return qm.toObject(selectBirthDate, OffsetDateTime.class, personNo);
}
@Override
public OffsetTime getBirthdateOffsetTime(long personNo) throws SQLException {
return qm.toObject(selectBirthDate, OffsetTime.class, personNo);
}
@Override
public Year getYearInt(long valNo) throws SQLException {
return qm.toObject(selectNumVal, Year.class, valNo);
}
@Override
public Year getYearString(long valNo) throws SQLException {
return qm.toObject(selectStrVal, Year.class, valNo);
}
@Override
public ZoneId getZoneId(long valNo) throws SQLException {
return qm.toObject(selectStrVal, ZoneId.class, valNo);
}
@Override
public ZoneOffset getZoneOffsetInt(long valNo) throws SQLException {
return qm.toObject(selectNumVal, ZoneOffset.class, valNo);
}
@Override
public ZoneOffset getZoneOffsetString(long valNo) throws SQLException {
return qm.toObject(selectStrVal, ZoneOffset.class, valNo);
}
//IFJAVA8_END
} }

View File

@ -14,6 +14,7 @@ import java.sql.DriverManager;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.*; import java.util.*;
//IFJAVA8_START //IFJAVA8_START
import java.time.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
//IFJAVA8_END //IFJAVA8_END
@ -467,88 +468,88 @@ public class QueryMapperTest {
//IFJAVA8_END //IFJAVA8_END
/*
@Test @Test
public void testEnumPerson() throws SQLException { public void testEnumPerson() throws SQLException {
assertEquals(new EnumPerson(FirstName.First), qm.toObject("SELECT first_name, last_name FROM person WHERE person_no = ?", EnumPerson.class, fieldPerson1.getPersonNo())); assertEquals(new EnumPerson(FirstName.First), qm.getEnumPerson(fieldPerson1.getPersonNo()));
} }
@Test @Test
public void testEnumPersonConstructor() throws SQLException { public void testEnumPersonConstructor() throws SQLException {
assertEquals(new EnumPerson(FirstName.First), qm.toObject("SELECT first_name FROM person WHERE person_no = ?", EnumPerson.class, fieldPerson1.getPersonNo())); assertEquals(new EnumPerson(FirstName.First), qm.getEnumPersonConstructor(fieldPerson1.getPersonNo()));
} }
@Test @Test
public void testEnum() throws SQLException { public void testEnum() throws SQLException {
assertEquals(FirstName.First, qm.toObject("SELECT first_name FROM person WHERE person_no = ?", FirstName.class, fieldPerson1.getPersonNo())); assertEquals(FirstName.First, qm.getFirstName(fieldPerson1.getPersonNo()));
} }
@Test @Test
public void testEnumPersonNull() throws SQLException { public void testEnumPersonNull() throws SQLException {
assertEquals(new EnumPerson(null), qm.toObject("SELECT str_val as first_name, str_val as last_name FROM val WHERE val_no = 4", EnumPerson.class)); assertEquals(new EnumPerson(null), qm.getEnumPersonNull());
} }
@Test @Test
public void testEnumNull() throws SQLException { public void testEnumNull() throws SQLException {
assertEquals(null, qm.toObject("SELECT str_val FROM val WHERE val_no = 4", FirstName.class)); assertNull(qm.getFirstNameNull());
} }
@Test @Test
public void testCaseInsensitiveMethods() throws SQLException { public void testCaseInsensitiveMethods() throws SQLException {
final CaseSensitivePerson expected = new CaseSensitivePerson(); final CaseSensitivePerson expected = new CaseSensitivePerson();
expected.setmPersonFirstName(fieldPerson1.getFirstName()); expected.setmPersonFirstName(fieldPerson1.getFirstName());
assertEquals(expected, qm.toObject("SELECT first_name AS M_PERSON_FIRST_NAME FROM person WHERE person_no = ?", CaseSensitivePerson.class, fieldPerson1.getPersonNo())); assertEquals(expected, qm.getCaseSensitivePerson(fieldPerson1.getPersonNo()));
} }
//IFJAVA 8_START //IFJAVA8_START
@Test @Test
public void testInstant() throws SQLException { public void testInstant() throws SQLException {
assertEquals(fieldPerson1.getBirthDate().toInstant(), assertEquals(fieldPerson1.getBirthDate().toInstant(),
qm.toObject("SELECT birth_date FROM person WHERE person_no = ?", Instant.class, fieldPerson1.getPersonNo())); qm.getBirthdateInstant(fieldPerson1.getPersonNo()));
} }
@Test @Test
public void testLocalDateTime() throws SQLException { public void testLocalDateTime() throws SQLException {
assertEquals(fieldPerson1.getBirthDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime(), assertEquals(fieldPerson1.getBirthDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime(),
qm.toObject("SELECT birth_date FROM person WHERE person_no = ?", LocalDateTime.class, fieldPerson1.getPersonNo())); qm.getBirthdateLocalDateTime(fieldPerson1.getPersonNo()));
} }
@Test @Test
public void testLocalDate() throws SQLException { public void testLocalDate() throws SQLException {
assertEquals(fieldPerson1.getBirthDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDate(), assertEquals(fieldPerson1.getBirthDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDate(),
qm.toObject("SELECT birth_date FROM person WHERE person_no = ?", LocalDate.class, fieldPerson1.getPersonNo())); qm.getBirthdateLocalDate(fieldPerson1.getPersonNo()));
} }
@Test @Test
public void testLocalTime() throws SQLException { public void testLocalTime() throws SQLException {
assertEquals(fieldPerson1.getBirthDate().toInstant().atZone(ZoneId.systemDefault()).toLocalTime(), assertEquals(fieldPerson1.getBirthDate().toInstant().atZone(ZoneId.systemDefault()).toLocalTime(),
qm.toObject("SELECT birth_date FROM person WHERE person_no = ?", LocalTime.class, fieldPerson1.getPersonNo())); qm.getBirthdateLocalTime(fieldPerson1.getPersonNo()));
} }
@Test @Test
public void testZonedDateTime() throws SQLException { public void testZonedDateTime() throws SQLException {
assertEquals(fieldPerson1.getBirthDate().toInstant().atZone(ZoneId.systemDefault()), assertEquals(fieldPerson1.getBirthDate().toInstant().atZone(ZoneId.systemDefault()),
qm.toObject("SELECT birth_date FROM person WHERE person_no = ?", ZonedDateTime.class, fieldPerson1.getPersonNo())); qm.getBirthdateZonedDateTime(fieldPerson1.getPersonNo()));
} }
@Test @Test
public void testOffsetDateTime() throws SQLException { public void testOffsetDateTime() throws SQLException {
assertEquals(fieldPerson1.getBirthDate().toInstant().atZone(ZoneId.systemDefault()).toOffsetDateTime(), assertEquals(fieldPerson1.getBirthDate().toInstant().atZone(ZoneId.systemDefault()).toOffsetDateTime(),
qm.toObject("SELECT birth_date FROM person WHERE person_no = ?", OffsetDateTime.class, fieldPerson1.getPersonNo())); qm.getBirthdateOffsetDateTime(fieldPerson1.getPersonNo()));
} }
@Test @Test
public void testZonedOffsetTime() throws SQLException { public void testZonedOffsetTime() throws SQLException {
assertEquals(fieldPerson1.getBirthDate().toInstant().atZone(ZoneId.systemDefault()).toOffsetDateTime().toOffsetTime(), assertEquals(fieldPerson1.getBirthDate().toInstant().atZone(ZoneId.systemDefault()).toOffsetDateTime().toOffsetTime(),
qm.toObject("SELECT birth_date FROM person WHERE person_no = ?", OffsetTime.class, fieldPerson1.getPersonNo())); qm.getBirthdateOffsetTime(fieldPerson1.getPersonNo()));
} }
@Test @Test
public void testYearInt() throws SQLException { public void testYearInt() throws SQLException {
final Val val = vals[0]; final Val val = vals[0];
assertEquals(Year.of((int)val.numVal), assertEquals(Year.of((int)val.numVal),
qm.toObject("SELECT num_val FROM val WHERE val_no = ?", Year.class, val.valNo) qm.getYearInt(val.valNo)
); );
} }
@ -556,7 +557,7 @@ public class QueryMapperTest {
public void testYearString() throws SQLException { public void testYearString() throws SQLException {
final Val val = vals[0]; final Val val = vals[0];
assertEquals(Year.parse(val.strVal), assertEquals(Year.parse(val.strVal),
qm.toObject("SELECT str_val FROM val WHERE val_no = ?", Year.class, val.valNo) qm.getYearString(val.valNo)
); );
} }
@ -564,26 +565,25 @@ public class QueryMapperTest {
public void testZoneId() throws SQLException { public void testZoneId() throws SQLException {
final Val val = vals[1]; final Val val = vals[1];
assertEquals(ZoneId.of(val.strVal), assertEquals(ZoneId.of(val.strVal),
qm.toObject("SELECT str_val FROM val WHERE val_no = ?", ZoneId.class, val.valNo) qm.getZoneId(val.valNo)
); );
} }
@Test @Test
public void testZoneOffsetInt() throws SQLException { public void testZoneOffsetInt() throws SQLException {
final Val val = vals[2]; final Val val = vals[2];
assertEquals(ZoneOffset.of(val.strVal), assertEquals(ZoneOffset.ofHours((int)val.numVal),
qm.toObject("SELECT str_val FROM val WHERE val_no = ?", ZoneOffset.class, val.valNo) qm.getZoneOffsetInt(val.valNo)
); );
} }
@Test @Test
public void testZoneOffsetStr() throws SQLException { public void testZoneOffsetStr() throws SQLException {
final Val val = vals[2]; final Val val = vals[2];
assertEquals(ZoneOffset.ofHours((int)val.numVal), assertEquals(ZoneOffset.of(val.strVal),
qm.toObject("SELECT num_val FROM val WHERE val_no = ?", ZoneOffset.class, val.valNo) qm.getZoneOffsetString(val.valNo)
); );
} }
//IFJAVA 8_END //IFJAVA8_END
*/
} }