Search in sources :

Example 6 with StopPlace

use of org.rutebanken.netex.model.StopPlace in project tiamat by entur.

the class FareZoneImportTest method mergeFareZonesForStopPlace.

@Test
public void mergeFareZonesForStopPlace() throws Exception {
    SimplePoint_VersionStructure point = new SimplePoint_VersionStructure().withLocation(new LocationStructure().withLatitude(new BigDecimal("77")).withLongitude(new BigDecimal("9.7")));
    List<JAXBElement<? extends Zone_VersionStructure>> tariffZones1 = new ArrayList<>();
    FareZone fareZone1 = new FareZone().withName(new MultilingualString().withValue("V03")).withVersion("1").withId("ATB:FareZone:01");
    tariffZones1.add(new ObjectFactory().createFareZone(fareZone1));
    StopPlace stopPlace = new StopPlace().withId("ATB:StopPlace:322").withName(new MultilingualString().withValue("name")).withCentroid(point).withVersion("1").withStopPlaceType(StopTypeEnumeration.ONSTREET_BUS).withTariffZones(new TariffZoneRefs_RelStructure().withTariffZoneRef(new TariffZoneRef().withVersion(fareZone1.getVersion()).withRef(fareZone1.getId())));
    SiteFrame siteFrame = publicationDeliveryTestHelper.siteFrame().withTariffZones(new TariffZonesInFrame_RelStructure().withTariffZone(tariffZones1)).withStopPlaces(new StopPlacesInFrame_RelStructure().withStopPlace(stopPlace));
    PublicationDeliveryStructure publicationDeliveryStructure = publicationDeliveryTestHelper.publicationDelivery(siteFrame);
    ImportParams importParams = new ImportParams();
    importParams.importType = ImportType.INITIAL;
    // First
    publicationDeliveryTestHelper.postAndReturnPublicationDelivery(publicationDeliveryStructure, importParams);
    List<JAXBElement<? extends Zone_VersionStructure>> tariffZones2 = new ArrayList<>();
    FareZone fareZone2 = new FareZone().withName(new MultilingualString().withValue("X08")).withVersion("1").withId("NTR:FareZone:03");
    tariffZones2.add(new ObjectFactory().createFareZone(fareZone2));
    StopPlace stopPlace2 = new StopPlace().withId("NTR:StopPlace:322").withVersion("2").withStopPlaceType(StopTypeEnumeration.ONSTREET_BUS).withTariffZones(new TariffZoneRefs_RelStructure().withTariffZoneRef(new TariffZoneRef().withVersion(fareZone2.getVersion()).withRef(fareZone2.getId())));
    SiteFrame siteFrame2 = publicationDeliveryTestHelper.siteFrame().withTariffZones(new TariffZonesInFrame_RelStructure().withTariffZone(tariffZones2)).withStopPlaces(new StopPlacesInFrame_RelStructure().withStopPlace(stopPlace2));
    PublicationDeliveryStructure publicationDeliveryStructure2 = publicationDeliveryTestHelper.publicationDelivery(siteFrame2);
    // Second import should match and merge tariffzones
    importParams.importType = ImportType.MATCH;
    PublicationDeliveryStructure matchReponse = publicationDeliveryTestHelper.postAndReturnPublicationDelivery(publicationDeliveryStructure2, importParams);
    List<JAXBElement<? extends Zone_VersionStructure>> actualZones = publicationDeliveryTestHelper.findSiteFrame(matchReponse).getTariffZones().getTariffZone();
    assertThat(actualZones).isNotEmpty();
    assertThat(actualZones).hasSize(2);
    List<StopPlace> actualIdMatchedStopPlaces = publicationDeliveryTestHelper.extractStopPlaces(matchReponse);
    assertThat(actualIdMatchedStopPlaces).hasSize(1);
    assertThat(actualIdMatchedStopPlaces.get(0).getTariffZones().getTariffZoneRef()).as("number of tariff zone refs").hasSize(2);
    importParams.importType = ImportType.ID_MATCH;
    PublicationDeliveryStructure idMatchResponse = publicationDeliveryTestHelper.postAndReturnPublicationDelivery(publicationDeliveryStructure2, importParams);
    actualZones = publicationDeliveryTestHelper.findSiteFrame(idMatchResponse).getTariffZones().getTariffZone();
    assertThat(actualZones).isNotEmpty();
    assertThat(actualZones).hasSize(2);
    actualIdMatchedStopPlaces = publicationDeliveryTestHelper.extractStopPlaces(matchReponse);
    assertThat(actualIdMatchedStopPlaces).hasSize(1);
    assertThat(actualIdMatchedStopPlaces.get(0).getTariffZones().getTariffZoneRef()).as("number of tariff zone refs").hasSize(2);
}
Also used : 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) SimplePoint_VersionStructure(org.rutebanken.netex.model.SimplePoint_VersionStructure) JAXBElement(javax.xml.bind.JAXBElement) FareZone(org.rutebanken.netex.model.FareZone) StopPlacesInFrame_RelStructure(org.rutebanken.netex.model.StopPlacesInFrame_RelStructure) LocationStructure(org.rutebanken.netex.model.LocationStructure) BigDecimal(java.math.BigDecimal) 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 7 with StopPlace

use of org.rutebanken.netex.model.StopPlace in project tiamat by entur.

the class ImportResourceTest method publicationDeliveriesWithDuplicateStopPlace.

/**
 * When sending a stop place with the same ID twice, the same stop place must be returned.
 * When importing multiple stop places and those exists, make sure no Lazy Initialization Exception is thrown.
 */
@Test
public void publicationDeliveriesWithDuplicateStopPlace() throws Exception {
    StopPlace stopPlace = new StopPlace().withId("RUT:StopPlace:123123").withVersion("1").withCentroid(new SimplePoint_VersionStructure().withLocation(new LocationStructure().withLatitude(new BigDecimal("9")).withLongitude(new BigDecimal("71"))));
    StopPlace stopPlace2 = new StopPlace().withId("RUT:StopPlace:123123").withVersion("1").withCentroid(new SimplePoint_VersionStructure().withLocation(new LocationStructure().withLatitude(new BigDecimal("10")).withLongitude(new BigDecimal("72"))));
    PublicationDeliveryStructure publicationDelivery = publicationDeliveryTestHelper.createPublicationDeliveryWithStopPlace(stopPlace);
    publicationDeliveryTestHelper.postAndReturnPublicationDelivery(publicationDelivery);
    PublicationDeliveryStructure publicationDelivery2 = publicationDeliveryTestHelper.createPublicationDeliveryWithStopPlace(stopPlace2);
    PublicationDeliveryStructure response = publicationDeliveryTestHelper.postAndReturnPublicationDelivery(publicationDelivery2);
    List<StopPlace> result = publicationDeliveryTestHelper.extractStopPlaces(response);
    assertThat(result).as("Expecting one stop place in return, as there is no need to return duplicates").hasSize(1);
}
Also used : StopPlace(org.rutebanken.netex.model.StopPlace) PublicationDeliveryStructure(org.rutebanken.netex.model.PublicationDeliveryStructure) SimplePoint_VersionStructure(org.rutebanken.netex.model.SimplePoint_VersionStructure) LocationStructure(org.rutebanken.netex.model.LocationStructure) BigDecimal(java.math.BigDecimal) Test(org.junit.Test) TiamatIntegrationTest(org.rutebanken.tiamat.TiamatIntegrationTest)

Example 8 with StopPlace

use of org.rutebanken.netex.model.StopPlace in project tiamat by entur.

the class ImportResourceTest method computeStopPlaceCentroid.

@Test
public void computeStopPlaceCentroid() throws Exception {
    StopPlace stopPlace = new StopPlace().withId("XYZ:StopPlace:9").withVersion("1").withCentroid(new SimplePoint_VersionStructure().withLocation(new LocationStructure().withLatitude(new BigDecimal("1")).withLongitude(new BigDecimal("2")))).withQuays(new Quays_RelStructure().withQuayRefOrQuay(new Quay().withId("XYZ:Quay:9").withVersion("1").withName(new MultilingualString().withValue("quay number one")).withCentroid(new SimplePoint_VersionStructure().withId("12").withVersion("1").withLocation(new LocationStructure().withLatitude(new BigDecimal("10")).withLongitude(new BigDecimal("20")))), new Quay().withId("XYZ:Quay:133").withVersion("1").withName(new MultilingualString().withValue("quay number two")).withCentroid(new SimplePoint_VersionStructure().withId("30").withVersion("1").withLocation(new LocationStructure().withLatitude(new BigDecimal("10.0002")).withLongitude(new BigDecimal("20.0002"))))));
    PublicationDeliveryStructure publicationDelivery = publicationDeliveryTestHelper.createPublicationDeliveryWithStopPlace(stopPlace);
    PublicationDeliveryStructure firstResponse = publicationDeliveryTestHelper.postAndReturnPublicationDelivery(publicationDelivery);
    StopPlace actualStopPlace = publicationDeliveryTestHelper.findFirstStopPlace(firstResponse);
    assertThat(actualStopPlace.getCentroid().getLocation().getLongitude().doubleValue()).isEqualTo(20.0001);
    assertThat(actualStopPlace.getCentroid().getLocation().getLatitude().doubleValue()).isEqualTo(10.0001);
}
Also used : Quays_RelStructure(org.rutebanken.netex.model.Quays_RelStructure) StopPlace(org.rutebanken.netex.model.StopPlace) PublicationDeliveryStructure(org.rutebanken.netex.model.PublicationDeliveryStructure) SimplePoint_VersionStructure(org.rutebanken.netex.model.SimplePoint_VersionStructure) Quay(org.rutebanken.netex.model.Quay) MultilingualString(org.rutebanken.netex.model.MultilingualString) LocationStructure(org.rutebanken.netex.model.LocationStructure) BigDecimal(java.math.BigDecimal) Test(org.junit.Test) TiamatIntegrationTest(org.rutebanken.tiamat.TiamatIntegrationTest)

Example 9 with StopPlace

use of org.rutebanken.netex.model.StopPlace 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)

Example 10 with StopPlace

use of org.rutebanken.netex.model.StopPlace in project tiamat by entur.

the class ImportResourceTest method importStopWithoutCoordinatesWithQuays1.

/**
 * Import stop place StopPlace{name=Skaret (no), quays=
 * [Quay{name=Skaret (no), centroid=POINT (7.328336965528884 62.799557598196465), keyValues={imported-id=Value{id=0, items=[MOR:StopArea:1548612801]}}},
 * Quay{name=Skaret (no), keyValues={imported-id=Value{id=0, items=[MOR:StopArea:1548575301]}}}],
 * keyValues={imported-id=Value{id=0, items=[MOR:StopArea:15485753]}}}
 */
@Test
public void importStopWithoutCoordinatesWithQuays1() throws Exception {
    StopPlace stopPlace = new StopPlace().withId("MOR:StopArea:15485753").withVersion("1").withName(new MultilingualString().withValue("Skaret").withLang("no")).withQuays(new Quays_RelStructure().withQuayRefOrQuay(new Quay().withVersion("1").withId("MOR:StopArea:1548612801").withName(new MultilingualString().withValue("Skaret").withLang("no")).withCentroid(new SimplePoint_VersionStructure().withLocation(new LocationStructure().withLatitude(new BigDecimal("62.799557598196465")).withLongitude(new BigDecimal("7.328336965528884")))), new Quay().withId("MOR:StopArea:1548575301").withVersion("1").withName(new MultilingualString().withValue("Skaret").withLang("no"))));
    PublicationDeliveryStructure publicationDelivery = publicationDeliveryTestHelper.createPublicationDeliveryWithStopPlace(stopPlace);
    PublicationDeliveryStructure response = publicationDeliveryTestHelper.postAndReturnPublicationDelivery(publicationDelivery);
    // Exception should not have been thrown
    StopPlace actualStopPlace = publicationDeliveryTestHelper.findFirstStopPlace(response);
    List<Quay> actualQuays = publicationDeliveryTestHelper.extractQuays(actualStopPlace);
    assertThat(actualQuays).isNotNull().as("quays should not be null");
}
Also used : Quays_RelStructure(org.rutebanken.netex.model.Quays_RelStructure) StopPlace(org.rutebanken.netex.model.StopPlace) PublicationDeliveryStructure(org.rutebanken.netex.model.PublicationDeliveryStructure) Quay(org.rutebanken.netex.model.Quay) SimplePoint_VersionStructure(org.rutebanken.netex.model.SimplePoint_VersionStructure) MultilingualString(org.rutebanken.netex.model.MultilingualString) LocationStructure(org.rutebanken.netex.model.LocationStructure) BigDecimal(java.math.BigDecimal) Test(org.junit.Test) TiamatIntegrationTest(org.rutebanken.tiamat.TiamatIntegrationTest)

Aggregations

StopPlace (org.rutebanken.netex.model.StopPlace)84 Test (org.junit.Test)69 TiamatIntegrationTest (org.rutebanken.tiamat.TiamatIntegrationTest)58 PublicationDeliveryStructure (org.rutebanken.netex.model.PublicationDeliveryStructure)54 BigDecimal (java.math.BigDecimal)36 LocationStructure (org.rutebanken.netex.model.LocationStructure)36 MultilingualString (org.rutebanken.netex.model.MultilingualString)36 SimplePoint_VersionStructure (org.rutebanken.netex.model.SimplePoint_VersionStructure)36 ImportParams (org.rutebanken.tiamat.importer.ImportParams)31 Quay (org.rutebanken.netex.model.Quay)28 Quays_RelStructure (org.rutebanken.netex.model.Quays_RelStructure)23 ArrayList (java.util.ArrayList)15 TariffZoneRef (org.rutebanken.netex.model.TariffZoneRef)15 TariffZoneRefs_RelStructure (org.rutebanken.netex.model.TariffZoneRefs_RelStructure)15 SiteFrame (org.rutebanken.netex.model.SiteFrame)13 LocalDateTime (java.time.LocalDateTime)11 ValidBetween (org.rutebanken.netex.model.ValidBetween)11 Response (javax.ws.rs.core.Response)10 ObjectFactory (org.rutebanken.netex.model.ObjectFactory)9 List (java.util.List)8