use of org.rutebanken.netex.model.ValidBetween in project OpenTripPlanner by opentripplanner.
the class ValidityComparatorTest method testValidityComparator.
@Test
public void testValidityComparator() {
ValidBetween validNull = new ValidBetween();
ValidBetween validNow1 = new ValidBetween();
validNow1.setFromDate(LocalDateTime.now().minusDays(3));
validNow1.setToDate(LocalDateTime.now().plusDays(3));
ValidBetween validPast1 = new ValidBetween();
validPast1.setFromDate(LocalDateTime.now().minusDays(7));
validPast1.setToDate(LocalDateTime.now().minusDays(5));
ValidBetween validFuture1 = new ValidBetween();
validFuture1.setFromDate(LocalDateTime.now().plusDays(5));
validFuture1.setToDate(LocalDateTime.now().plusDays(7));
ValidBetween validNow2 = new ValidBetween();
validNow2.setFromDate(LocalDateTime.now().minusDays(4));
validNow2.setToDate(LocalDateTime.now().plusDays(4));
ValidBetween validPast2 = new ValidBetween();
validPast2.setFromDate(LocalDateTime.now().minusDays(8));
validPast2.setToDate(LocalDateTime.now().minusDays(6));
ValidBetween validFuture2 = new ValidBetween();
validFuture2.setFromDate(LocalDateTime.now().plusDays(6));
validFuture2.setToDate(LocalDateTime.now().plusDays(8));
Assert.equals(0, validityComparator.compare(Collections.singletonList(validNull), Collections.singletonList(validNull)));
Assert.equals(0, validityComparator.compare(Collections.singletonList(validNull), Collections.singletonList(validNow1)));
Assert.equals(0, validityComparator.compare(Collections.singletonList(validNow1), Collections.singletonList(validNow2)));
Assert.equals(-1, validityComparator.compare(Collections.singletonList(validNow1), Collections.singletonList(validPast2)));
Assert.equals(-1, validityComparator.compare(Collections.singletonList(validNow1), Collections.singletonList(validFuture2)));
Assert.equals(0, validityComparator.compare(Collections.singletonList(validPast1), Collections.singletonList(validPast1)));
Assert.equals(1, validityComparator.compare(Collections.singletonList(validPast1), Collections.singletonList(validNow2)));
Assert.equals(-1, validityComparator.compare(Collections.singletonList(validPast1), Collections.singletonList(validPast2)));
Assert.equals(1, validityComparator.compare(Collections.singletonList(validPast1), Collections.singletonList(validFuture2)));
Assert.equals(0, validityComparator.compare(Collections.singletonList(validFuture1), Collections.singletonList(validFuture1)));
Assert.equals(1, validityComparator.compare(Collections.singletonList(validFuture1), Collections.singletonList(validNow2)));
Assert.equals(-1, validityComparator.compare(Collections.singletonList(validFuture1), Collections.singletonList(validPast2)));
Assert.equals(-1, validityComparator.compare(Collections.singletonList(validFuture1), Collections.singletonList(validFuture2)));
}
use of org.rutebanken.netex.model.ValidBetween in project tiamat by entur.
the class ExportResourceTest method exportStopPlacesWithEffectiveChangedInPeriod.
@Test
public void exportStopPlacesWithEffectiveChangedInPeriod() throws Exception {
LocalDateTime validFrom = LocalDateTime.now().minusDays(3);
StopPlace stopPlace1 = new StopPlace().withId("XYZ:Stopplace:1").withVersion("1").withName(new MultilingualString().withValue("Changed stop1")).withValidBetween(new ValidBetween().withFromDate(validFrom)).withCentroid(new SimplePoint_VersionStructure().withLocation(new LocationStructure().withLatitude(new BigDecimal("59.914353")).withLongitude(new BigDecimal("10.806387"))));
StopPlace stopPlace2 = new StopPlace().withId("XYZ:Stopplace:2").withVersion("1").withName(new MultilingualString().withValue("Changed stop2")).withValidBetween(new ValidBetween().withFromDate(validFrom.plusDays(1))).withCentroid(new SimplePoint_VersionStructure().withLocation(new LocationStructure().withLatitude(new BigDecimal("22.914353")).withLongitude(new BigDecimal("11.806387"))));
PublicationDeliveryStructure publicationDelivery = publicationDeliveryTestHelper.createPublicationDeliveryWithStopPlace(stopPlace1, stopPlace2);
publicationDeliveryTestHelper.postAndReturnPublicationDelivery(publicationDelivery);
UriInfo uriInfoMock = Mockito.mock(UriInfo.class);
Mockito.when(uriInfoMock.getAbsolutePathBuilder()).thenReturn(JerseyUriBuilder.fromPath("http://test"));
ChangedStopPlaceSearchDto search = new ChangedStopPlaceSearchDto(null, null, 0, 1);
Response response = exportResource.exportStopPlacesWithEffectiveChangedInPeriod(search, newExportParamsBuilder().build(), uriInfoMock);
List<StopPlace> changedStopPlaces = publicationDeliveryTestHelper.extractStopPlaces(response);
Assert.assertEquals(1, changedStopPlaces.size());
Assert.assertEquals(stopPlace1.getName().getValue(), changedStopPlaces.get(0).getName().getValue());
Link link = response.getLink("next");
Assert.assertNotNull(link);
}
use of org.rutebanken.netex.model.ValidBetween in project tiamat by entur.
the class FareZoneImportTest method publicationDeliveryWithFareZone.
@Test
public void publicationDeliveryWithFareZone() throws Exception {
LocalDateTime validFrom = LocalDateTime.now().minusDays(3);
List<JAXBElement<? extends Zone_VersionStructure>> tariffZones = new ArrayList<>();
FareZone fareZone = new FareZone().withName(new MultilingualString().withValue("V02")).withVersion("1").withValidBetween(new ValidBetween().withFromDate(validFrom)).withId("RUT:FareZone:01");
tariffZones.add(new ObjectFactory().createFareZone(fareZone));
SiteFrame siteFrame = publicationDeliveryTestHelper.siteFrame().withTariffZones(new TariffZonesInFrame_RelStructure().withTariffZone(tariffZones));
PublicationDeliveryStructure publicationDeliveryStructure = publicationDeliveryTestHelper.publicationDelivery(siteFrame);
PublicationDeliveryStructure response = publicationDeliveryTestHelper.postAndReturnPublicationDelivery(publicationDeliveryStructure);
final List<JAXBElement<? extends Zone_VersionStructure>> actualZones = publicationDeliveryTestHelper.findSiteFrame(response).getTariffZones().getTariffZone();
assertThat(actualZones).isNotEmpty();
assertThat(actualZones.get(0).getValue().getName().getValue()).isEqualTo(fareZone.getName().getValue());
}
use of org.rutebanken.netex.model.ValidBetween in project tiamat by entur.
the class FareZoneImportTest method publicationDeliveryWithFareZoneAndStopPlace.
@Test
public void publicationDeliveryWithFareZoneAndStopPlace() throws Exception {
LocalDateTime validFrom = LocalDateTime.now().minusDays(3);
List<JAXBElement<? extends Zone_VersionStructure>> tariffZones = new ArrayList<>();
FareZone fareZone = new FareZone().withName(new MultilingualString().withValue("V02")).withVersion("1").withValidBetween(new ValidBetween().withFromDate(validFrom)).withId("RUT:FareZone:05");
tariffZones.add(new ObjectFactory().createFareZone(fareZone));
StopPlace stopPlace = new StopPlace();
stopPlace.withId("XYZ:StopPlace:32111");
stopPlace.setVersion("1");
stopPlace.setTariffZones(new TariffZoneRefs_RelStructure().withTariffZoneRef(new TariffZoneRef().withVersion(fareZone.getVersion()).withRef(fareZone.getId())));
SiteFrame siteFrame = publicationDeliveryTestHelper.siteFrame().withTariffZones(new TariffZonesInFrame_RelStructure().withTariffZone(tariffZones)).withStopPlaces(new StopPlacesInFrame_RelStructure().withStopPlace(stopPlace));
PublicationDeliveryStructure publicationDeliveryStructure = publicationDeliveryTestHelper.publicationDelivery(siteFrame);
ImportParams importParams = new ImportParams();
importParams.importType = ImportType.INITIAL;
// First
publicationDeliveryTestHelper.postAndReturnPublicationDelivery(publicationDeliveryStructure, importParams);
PublicationDeliveryStructure response = publicationDeliveryTestHelper.postAndReturnPublicationDelivery(publicationDeliveryStructure, importParams);
List<JAXBElement<? extends Zone_VersionStructure>> actualZones = publicationDeliveryTestHelper.findSiteFrame(response).getTariffZones().getTariffZone();
assertThat(actualZones).isNotEmpty();
assertThat(actualZones.get(0).getValue().getName().getValue()).isEqualTo(fareZone.getName().getValue());
// Versions for tariff zones are incremented.
assertThat(actualZones.get(0).getValue().getVersion()).isEqualTo("2");
}
use of org.rutebanken.netex.model.ValidBetween in project tiamat by entur.
the class ImportResourceTest method importStopPlaceWithMultipleValidBetweenPeriodsIgnoresAllButFirst.
@Test
public void importStopPlaceWithMultipleValidBetweenPeriodsIgnoresAllButFirst() throws Exception {
LocalDateTime firstValidFrom = now.plusSeconds(1);
LocalDateTime secondValidFrom = now.plusSeconds(2);
StopPlace stopPlace1 = new StopPlace().withId("XYZ:Stopplace:1").withVersion("1").withName(new MultilingualString().withValue("New stop1")).withValidBetween(new ValidBetween().withFromDate(firstValidFrom).withToDate(secondValidFrom), new ValidBetween().withFromDate(secondValidFrom)).withCentroid(new SimplePoint_VersionStructure().withLocation(new LocationStructure().withLatitude(new BigDecimal("59.914353")).withLongitude(new BigDecimal("10.806387"))));
PublicationDeliveryStructure publicationDelivery = publicationDeliveryTestHelper.createPublicationDeliveryWithStopPlace(stopPlace1);
PublicationDeliveryStructure response = publicationDeliveryTestHelper.postAndReturnPublicationDelivery(publicationDelivery);
List<StopPlace> changedStopPlaces = publicationDeliveryTestHelper.extractStopPlaces(response);
Assert.assertEquals(1, changedStopPlaces.size());
StopPlace stopPlace = changedStopPlaces.get(0);
List<ValidBetween> actualValidBetween = stopPlace.getValidBetween();
assertThat(actualValidBetween).as("Stop Place should have actualValidBetween set").isNotNull().isNotEmpty().hasSize(1);
assertThat(actualValidBetween.get(0).getFromDate()).isEqualTo(firstValidFrom);
}
Aggregations