Search in sources :

Example 1 with ValidBetween

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)));
}
Also used : ValidBetween(org.rutebanken.netex.model.ValidBetween) Test(org.junit.Test)

Example 2 with ValidBetween

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);
}
Also used : LocalDateTime(java.time.LocalDateTime) StopPlace(org.rutebanken.netex.model.StopPlace) PublicationDeliveryStructure(org.rutebanken.netex.model.PublicationDeliveryStructure) SimplePoint_VersionStructure(org.rutebanken.netex.model.SimplePoint_VersionStructure) ValidBetween(org.rutebanken.netex.model.ValidBetween) LocationStructure(org.rutebanken.netex.model.LocationStructure) BigDecimal(java.math.BigDecimal) Response(javax.ws.rs.core.Response) MultilingualString(org.rutebanken.netex.model.MultilingualString) EmbeddableMultilingualString(org.rutebanken.tiamat.model.EmbeddableMultilingualString) ChangedStopPlaceSearchDto(org.rutebanken.tiamat.dtoassembling.dto.ChangedStopPlaceSearchDto) UriInfo(javax.ws.rs.core.UriInfo) Link(javax.ws.rs.core.Link) Test(org.junit.Test) TiamatIntegrationTest(org.rutebanken.tiamat.TiamatIntegrationTest)

Example 3 with ValidBetween

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());
}
Also used : LocalDateTime(java.time.LocalDateTime) SiteFrame(org.rutebanken.netex.model.SiteFrame) TariffZonesInFrame_RelStructure(org.rutebanken.netex.model.TariffZonesInFrame_RelStructure) ObjectFactory(org.rutebanken.netex.model.ObjectFactory) ArrayList(java.util.ArrayList) PublicationDeliveryStructure(org.rutebanken.netex.model.PublicationDeliveryStructure) JAXBElement(javax.xml.bind.JAXBElement) Zone_VersionStructure(org.rutebanken.netex.model.Zone_VersionStructure) FareZone(org.rutebanken.netex.model.FareZone) MultilingualString(org.rutebanken.netex.model.MultilingualString) ValidBetween(org.rutebanken.netex.model.ValidBetween) Test(org.junit.Test) TiamatIntegrationTest(org.rutebanken.tiamat.TiamatIntegrationTest)

Example 4 with ValidBetween

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");
}
Also used : LocalDateTime(java.time.LocalDateTime) TariffZoneRefs_RelStructure(org.rutebanken.netex.model.TariffZoneRefs_RelStructure) StopPlace(org.rutebanken.netex.model.StopPlace) SiteFrame(org.rutebanken.netex.model.SiteFrame) TariffZonesInFrame_RelStructure(org.rutebanken.netex.model.TariffZonesInFrame_RelStructure) ArrayList(java.util.ArrayList) PublicationDeliveryStructure(org.rutebanken.netex.model.PublicationDeliveryStructure) JAXBElement(javax.xml.bind.JAXBElement) FareZone(org.rutebanken.netex.model.FareZone) ValidBetween(org.rutebanken.netex.model.ValidBetween) StopPlacesInFrame_RelStructure(org.rutebanken.netex.model.StopPlacesInFrame_RelStructure) ObjectFactory(org.rutebanken.netex.model.ObjectFactory) ImportParams(org.rutebanken.tiamat.importer.ImportParams) Zone_VersionStructure(org.rutebanken.netex.model.Zone_VersionStructure) MultilingualString(org.rutebanken.netex.model.MultilingualString) TariffZoneRef(org.rutebanken.netex.model.TariffZoneRef) Test(org.junit.Test) TiamatIntegrationTest(org.rutebanken.tiamat.TiamatIntegrationTest)

Example 5 with ValidBetween

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);
}
Also used : LocalDateTime(java.time.LocalDateTime) StopPlace(org.rutebanken.netex.model.StopPlace) PublicationDeliveryStructure(org.rutebanken.netex.model.PublicationDeliveryStructure) SimplePoint_VersionStructure(org.rutebanken.netex.model.SimplePoint_VersionStructure) MultilingualString(org.rutebanken.netex.model.MultilingualString) ValidBetween(org.rutebanken.netex.model.ValidBetween) LocationStructure(org.rutebanken.netex.model.LocationStructure) BigDecimal(java.math.BigDecimal) Test(org.junit.Test) TiamatIntegrationTest(org.rutebanken.tiamat.TiamatIntegrationTest)

Aggregations

ValidBetween (org.rutebanken.netex.model.ValidBetween)12 Test (org.junit.Test)8 MultilingualString (org.rutebanken.netex.model.MultilingualString)8 PublicationDeliveryStructure (org.rutebanken.netex.model.PublicationDeliveryStructure)7 TiamatIntegrationTest (org.rutebanken.tiamat.TiamatIntegrationTest)7 LocalDateTime (java.time.LocalDateTime)6 ObjectFactory (org.rutebanken.netex.model.ObjectFactory)5 StopPlace (org.rutebanken.netex.model.StopPlace)5 ArrayList (java.util.ArrayList)4 JAXBElement (javax.xml.bind.JAXBElement)4 SiteFrame (org.rutebanken.netex.model.SiteFrame)4 TariffZonesInFrame_RelStructure (org.rutebanken.netex.model.TariffZonesInFrame_RelStructure)4 Zone_VersionStructure (org.rutebanken.netex.model.Zone_VersionStructure)4 BigDecimal (java.math.BigDecimal)2 FareZone (org.rutebanken.netex.model.FareZone)2 LocationStructure (org.rutebanken.netex.model.LocationStructure)2 SimplePoint_VersionStructure (org.rutebanken.netex.model.SimplePoint_VersionStructure)2 StopPlacesInFrame_RelStructure (org.rutebanken.netex.model.StopPlacesInFrame_RelStructure)2 TariffZone (org.rutebanken.netex.model.TariffZone)2 TariffZoneRef (org.rutebanken.netex.model.TariffZoneRef)2