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);
}
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);
}
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);
}
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);
}
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");
}
Aggregations