Refine search
@Test public void shouldRangeSeekInOrderAscendingLocalDateTimeArray() throws Exception { Object o0 = new LocalDateTime[]{LocalDateTime.of( 10, 10, 10, 10, 10, 10, 0 )}; Object o1 = new LocalDateTime[]{LocalDateTime.of( 10, 10, 10, 10, 10, 10, 1 )}; Object o2 = new LocalDateTime[]{LocalDateTime.of( 10, 10, 10, 10, 10, 10, 2 )}; Object o3 = new LocalDateTime[]{LocalDateTime.of( 10, 10, 10, 10, 10, 10, 3 )}; Object o4 = new LocalDateTime[]{LocalDateTime.of( 10, 10, 10, 10, 10, 10, 4 )}; Object o5 = new LocalDateTime[]{LocalDateTime.of( 10, 10, 10, 10, 10, 10, 5 )}; shouldRangeSeekInOrder( IndexOrder.ASCENDING, o0, o1, o2, o3, o4, o5 ); }
@Test public void shouldRangeSeekInOrderAscendingLocalDateTimeArray() throws Exception { Object o0 = new LocalDateTime[]{LocalDateTime.of( 10, 10, 10, 10, 10, 10, 0 )}; Object o1 = new LocalDateTime[]{LocalDateTime.of( 10, 10, 10, 10, 10, 10, 1 )}; Object o2 = new LocalDateTime[]{LocalDateTime.of( 10, 10, 10, 10, 10, 10, 2 )}; Object o3 = new LocalDateTime[]{LocalDateTime.of( 10, 10, 10, 10, 10, 10, 3 )}; Object o4 = new LocalDateTime[]{LocalDateTime.of( 10, 10, 10, 10, 10, 10, 4 )}; Object o5 = new LocalDateTime[]{LocalDateTime.of( 10, 10, 10, 10, 10, 10, 5 )}; shouldSeekInOrderExactWithRange( IndexOrder.ASCENDING, o0, o1, o2, o3, o4, o5 ); }
@Test public void shouldRangeSeekInOrderDescendingLocalDateTimeArray() throws Exception { Object o0 = new LocalDateTime[]{LocalDateTime.of( 10, 10, 10, 10, 10, 10, 0 )}; Object o1 = new LocalDateTime[]{LocalDateTime.of( 10, 10, 10, 10, 10, 10, 1 )}; Object o2 = new LocalDateTime[]{LocalDateTime.of( 10, 10, 10, 10, 10, 10, 2 )}; Object o3 = new LocalDateTime[]{LocalDateTime.of( 10, 10, 10, 10, 10, 10, 3 )}; Object o4 = new LocalDateTime[]{LocalDateTime.of( 10, 10, 10, 10, 10, 10, 4 )}; Object o5 = new LocalDateTime[]{LocalDateTime.of( 10, 10, 10, 10, 10, 10, 5 )}; shouldSeekInOrderExactWithRange( IndexOrder.DESCENDING, o0, o1, o2, o3, o4, o5 ); }
@Test public void shouldRangeSeekInOrderDescendingLocalDateTimeArray() throws Exception { Object o0 = new LocalDateTime[]{LocalDateTime.of( 10, 10, 10, 10, 10, 10, 0 )}; Object o1 = new LocalDateTime[]{LocalDateTime.of( 10, 10, 10, 10, 10, 10, 1 )}; Object o2 = new LocalDateTime[]{LocalDateTime.of( 10, 10, 10, 10, 10, 10, 2 )}; Object o3 = new LocalDateTime[]{LocalDateTime.of( 10, 10, 10, 10, 10, 10, 3 )}; Object o4 = new LocalDateTime[]{LocalDateTime.of( 10, 10, 10, 10, 10, 10, 4 )}; Object o5 = new LocalDateTime[]{LocalDateTime.of( 10, 10, 10, 10, 10, 10, 5 )}; shouldRangeSeekInOrder( IndexOrder.DESCENDING, o0, o1, o2, o3, o4, o5 ); }
@Test public void createRandomIteratorForLocalDateTime() { Random workingRandom = mock(Random.class); LocalDateTime fromTime = LocalDateTime.of(2016, 7, 1, 4, 5, 12); LocalDateTime toTime = LocalDateTime.of(2016, 7, 3, 12, 15, 12); when(workingRandom.nextInt(anyInt())).thenReturn(3, 0); assertElementsOfIterator(new TemporalValueRange<>(fromTime, toTime, 10, ChronoUnit.MINUTES).createRandomIterator(workingRandom), LocalDateTime.of(2016, 7, 1, 4, 35, 12)); }
@Test public void testConversion() throws ParseException { Calendar cal = Calendar.getInstance(); cal.set(2016, Calendar.MAY, 1, 12, 30, 45); cal.set(Calendar.MILLISECOND, 718); assertFormat(LocalDateTime.of(2016, 5, 1, 12, 30, 45, 718004350), cal.getTime()); compare(LocalDateTime.class, LocalDateTime.now()); compare(LocalDateTime.class, LocalDateTime.of(12016, 3, 11, 3, 30)); }
@Test public void testBindLocalDateTime() { MutablePropertyValues propertyValues = new MutablePropertyValues(); propertyValues.add("localDateTime", LocalDateTime.of(2009, 10, 31, 12, 0)); binder.bind(propertyValues); assertEquals(0, binder.getBindingResult().getErrorCount()); String value = binder.getBindingResult().getFieldValue("localDateTime").toString(); assertTrue(value.startsWith("10/31/09")); assertTrue(value.endsWith("12:00 PM")); }
@Test public void testBindLocalDateTimeAnnotated() { MutablePropertyValues propertyValues = new MutablePropertyValues(); propertyValues.add("localDateTimeAnnotated", LocalDateTime.of(2009, 10, 31, 12, 0)); binder.bind(propertyValues); assertEquals(0, binder.getBindingResult().getErrorCount()); String value = binder.getBindingResult().getFieldValue("localDateTimeAnnotated").toString(); assertTrue(value.startsWith("Oct 31, 2009")); assertTrue(value.endsWith("12:00:00 PM")); }
@Test public void testJPACallback() { Long personId = 1L; doInJPA( this::entityManagerFactory, entityManager -> { Person person = new Person(); person.id = personId; person.name = "John Doe"; person.dateOfBirth = Timestamp.valueOf(LocalDateTime.of( 2000, 1, 1, 0, 0, 0 )); entityManager.persist( person ); } ); doInJPA( this::entityManagerFactory, entityManager -> { Person person = entityManager.find( Person.class, personId ); assertTrue(person.age > 0); } ); }
@Test public void shouldPackLocalDateTimeWithTimeZoneId() { LocalDateTime localDateTime = LocalDateTime.of( 1999, 12, 30, 9, 49, 20, 999999999 ); ZoneId zoneId = ZoneId.of( "Europe/Stockholm" ); ZonedDateTime zonedDateTime = ZonedDateTime.of( localDateTime, zoneId ); PackedOutputArray packedOutput = pack( datetime( zonedDateTime ) ); ByteBuffer buffer = ByteBuffer.wrap( packedOutput.bytes() ); buffer.getShort(); // skip struct header assertEquals( INT_32, buffer.get() ); assertEquals( localDateTime.toEpochSecond( UTC ), buffer.getInt() ); assertEquals( INT_32, buffer.get() ); assertEquals( localDateTime.getNano(), buffer.getInt() ); buffer.getShort(); // skip zoneId string header byte[] zoneIdBytes = new byte[zoneId.getId().getBytes( UTF_8 ).length]; buffer.get( zoneIdBytes ); assertEquals( zoneId.getId(), new String( zoneIdBytes, UTF_8 ) ); }
@Test public void shouldPackLocalDateTimeWithTimeZoneOffset() { LocalDateTime localDateTime = LocalDateTime.of( 2015, 3, 23, 19, 15, 59, 10 ); ZoneOffset offset = ZoneOffset.ofHoursMinutes( -5, -15 ); ZonedDateTime zonedDateTime = ZonedDateTime.of( localDateTime, offset ); PackedOutputArray packedOutput = pack( datetime( zonedDateTime ) ); ByteBuffer buffer = ByteBuffer.wrap( packedOutput.bytes() ); buffer.getShort(); // skip struct header assertEquals( INT_32, buffer.get() ); assertEquals( localDateTime.toEpochSecond( UTC ), buffer.getInt() ); assertEquals( localDateTime.getNano(), buffer.get() ); assertEquals( INT_16, buffer.get() ); assertEquals( offset.getTotalSeconds(), buffer.getShort() ); }
@Test public void testBindDateTimeWithSpecificStyle() { DateTimeFormatterRegistrar registrar = new DateTimeFormatterRegistrar(); registrar.setDateTimeStyle(FormatStyle.MEDIUM); setup(registrar); MutablePropertyValues propertyValues = new MutablePropertyValues(); propertyValues.add("localDateTime", LocalDateTime.of(2009, 10, 31, 12, 0)); binder.bind(propertyValues); assertEquals(0, binder.getBindingResult().getErrorCount()); String value = binder.getBindingResult().getFieldValue("localDateTime").toString(); assertTrue(value.startsWith("Oct 31, 2009")); assertTrue(value.endsWith("12:00:00 PM")); }
@Test public void shouldDeserializeTimeMillisToBigint() { shouldDeserializeTypeCorrectly( LogicalTypes.timeMillis().addToSchema( org.apache.avro.SchemaBuilder.builder().intType()), ChronoUnit.MILLIS.between( LocalDateTime.of(LocalDate.now(), LocalTime.MIDNIGHT), LocalDateTime.now()), Schema.OPTIONAL_INT64_SCHEMA ); }
@Test public void shouldDeserializeTimeMicrosToBigint() { shouldDeserializeTypeCorrectly( LogicalTypes.timeMicros().addToSchema( org.apache.avro.SchemaBuilder.builder().longType()), ChronoUnit.MICROS.between( LocalDateTime.of(LocalDate.now(), LocalTime.MIDNIGHT), LocalDateTime.now()), Schema.OPTIONAL_INT64_SCHEMA ); }