use of org.joda.time.LocalTime in project jsonschema2pojo by joelittlejohn.
the class JodaDatesIT method useJodaLocalTimesCausesLocalTimeDefaultValues.
@Test
public void useJodaLocalTimesCausesLocalTimeDefaultValues() throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, SecurityException, InvocationTargetException {
ClassLoader classLoader = schemaRule.generateAndCompile("/schema/default/default.json", "com.example", config("useJodaLocalTimes", true));
Class<?> classWithDefaults = classLoader.loadClass("com.example.Default");
Object instance = classWithDefaults.newInstance();
Method getter = classWithDefaults.getMethod("getTimeAsStringWithDefault");
assertThat((LocalTime) getter.invoke(instance), is(equalTo(new LocalTime("16:15:00"))));
}
use of org.joda.time.LocalTime in project uPortal by Jasig.
the class PortalEventDimensionPopulatorImpl method doPopulateTimeDimensions.
/**
* Populate the time dimensions
*/
final void doPopulateTimeDimensions() {
final List<TimeDimension> timeDimensions = this.timeDimensionDao.getTimeDimensions();
if (timeDimensions.isEmpty()) {
logger.info("No TimeDimensions exist, creating them");
} else if (timeDimensions.size() != (24 * 60)) {
this.logger.info("There are only " + timeDimensions.size() + " time dimensions in the database, there should be " + (24 * 60) + " creating missing dimensions");
} else {
this.logger.debug("Found expected " + timeDimensions.size() + " time dimensions");
return;
}
LocalTime nextTime = new LocalTime(0, 0);
final LocalTime lastTime = new LocalTime(23, 59);
for (final TimeDimension timeDimension : timeDimensions) {
LocalTime dimensionTime = timeDimension.getTime();
if (nextTime.isBefore(dimensionTime)) {
do {
checkShutdown();
this.timeDimensionDao.createTimeDimension(nextTime);
nextTime = nextTime.plusMinutes(1);
} while (nextTime.isBefore(dimensionTime));
} else if (nextTime.isAfter(dimensionTime)) {
do {
checkShutdown();
this.timeDimensionDao.createTimeDimension(dimensionTime);
dimensionTime = dimensionTime.plusMinutes(1);
} while (nextTime.isAfter(dimensionTime));
}
nextTime = dimensionTime.plusMinutes(1);
}
// Add any missing times from the tail
while (nextTime.isBefore(lastTime) || nextTime.equals(lastTime)) {
checkShutdown();
this.timeDimensionDao.createTimeDimension(nextTime);
if (nextTime.equals(lastTime)) {
break;
}
nextTime = nextTime.plusMinutes(1);
}
}
use of org.joda.time.LocalTime in project uPortal by Jasig.
the class PortalEventDimensionPopulatorImplTest method populateSomeTimeDimensions.
@Test
public void populateSomeTimeDimensions() {
final Builder<Object> existingTimeDimensionBuilder = ImmutableList.builder();
TimeDimension td = mock(TimeDimension.class);
when(td.getTime()).thenReturn(new LocalTime(0, 1));
existingTimeDimensionBuilder.add(td);
final List<TimeDimension> existingTimeDimensions = ImmutableList.of(createMockTimeDimension(new LocalTime(0, 1)), createMockTimeDimension(new LocalTime(0, 2)), createMockTimeDimension(new LocalTime(0, 3)), createMockTimeDimension(new LocalTime(0, 4)), createMockTimeDimension(new LocalTime(0, 7)), createMockTimeDimension(new LocalTime(0, 8)), createMockTimeDimension(new LocalTime(0, 9)), createMockTimeDimension(new LocalTime(1, 23)), createMockTimeDimension(new LocalTime(23, 58)));
when(timeDimensionDao.getTimeDimensions()).thenReturn(existingTimeDimensions);
this.portalEventDimensionPopulator.doPopulateTimeDimensions();
verify(timeDimensionDao).getTimeDimensions();
verify(timeDimensionDao, times((60 * 24) - existingTimeDimensions.size())).createTimeDimension(ArgumentMatchers.<LocalTime>any());
verifyNoMoreInteractions(timeDimensionDao, dateDimensionDao);
}
use of org.joda.time.LocalTime in project cayenne by apache.
the class LocalTimeTypeTest method testMaterializeObjectTimestamp.
public void testMaterializeObjectTimestamp() throws Exception {
Object o = type.materializeObject(resultSet(new Timestamp(0)), 1, Types.TIMESTAMP);
assertEquals(new LocalTime(0), o);
}
use of org.joda.time.LocalTime in project cayenne by apache.
the class LocalTimeTypeTest method testSetJdbcObject.
public void testSetJdbcObject() throws Exception {
PreparedStatement statement = new MockPreparedStatement(new MockConnection(), "update t set c = ?");
LocalTime date = new LocalTime(0);
type.setJdbcObject(statement, date, 1, Types.TIME, 0);
Object object = ((MockPreparedStatement) statement).getParameter(1);
assertEquals(Time.class, object.getClass());
assertEquals(new LocalDate(0, DateTimeZone.UTC).toDateTime(date).getMillis(), ((Time) object).getTime());
type.setJdbcObject(statement, date, 1, Types.TIMESTAMP, 0);
object = ((MockPreparedStatement) statement).getParameter(1);
assertEquals(Timestamp.class, object.getClass());
assertEquals(new LocalDate(0, DateTimeZone.UTC).toDateTime(date).getMillis(), ((Timestamp) object).getTime());
type.setJdbcObject(statement, null, 1, Types.TIMESTAMP, 0);
object = ((MockPreparedStatement) statement).getParameter(1);
assertNull(object);
}
Aggregations