use of org.rutebanken.netex.model.TariffZoneRef 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.TariffZoneRef 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.TariffZoneRef in project tiamat by entur.
the class TariffZoneImportTest method publicationDeliveryWithTariffZoneAndStopPlace.
@Test
public void publicationDeliveryWithTariffZoneAndStopPlace() throws Exception {
LocalDateTime validFrom = LocalDateTime.now().minusDays(3);
List<JAXBElement<? extends Zone_VersionStructure>> tariffZones = new ArrayList<>();
TariffZone tariffZone = new TariffZone().withName(new MultilingualString().withValue("V02")).withVersion("1").withValidBetween(new ValidBetween().withFromDate(validFrom)).withId("RUT:TariffZone:05");
tariffZones.add(new ObjectFactory().createTariffZone(tariffZone));
StopPlace stopPlace = new StopPlace();
stopPlace.withId("XYZ:StopPlace:32111");
stopPlace.setVersion("1");
stopPlace.setTariffZones(new TariffZoneRefs_RelStructure().withTariffZoneRef(new TariffZoneRef().withVersion(tariffZone.getVersion()).withRef(tariffZone.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(tariffZone.getName().getValue());
// Versions for tariff zones are incremented.
assertThat(actualZones.get(0).getValue().getVersion()).isEqualTo("2");
}
use of org.rutebanken.netex.model.TariffZoneRef in project tiamat by entur.
the class FareZonesFromStopsExporterTest method handleUnresolvableTariffZoneRef.
@Test
public void handleUnresolvableTariffZoneRef() {
FareZone fareZone = new FareZone();
fareZone.setNetexId("VKT:FareZone:201");
fareZone.setVersion(1L);
fareZoneRepository.save(fareZone);
StopPlace netexStopPlace = new StopPlace();
netexStopPlace.setId("NSR:StopPlace:1");
netexStopPlace.withTariffZones(new TariffZoneRefs_RelStructure().withTariffZoneRef(new TariffZoneRef().withRef("NSR:FareZone:1")));
SiteFrame siteFrame = new SiteFrame();
tariffZonesFromStopsExporter.resolveTariffZones(Arrays.asList(netexStopPlace), siteFrame);
assertThat(siteFrame.getTariffZones()).as("Number of tariffzones returned").isNull();
}
use of org.rutebanken.netex.model.TariffZoneRef in project tiamat by entur.
the class FareZonesFromStopsExporterTest method keepExistingFareZones.
@Test
public void keepExistingFareZones() {
FareZone fareZone = new FareZone();
fareZone.setNetexId("VKT:FareZone:201");
fareZone.setVersion(1L);
fareZoneRepository.save(fareZone);
org.rutebanken.netex.model.FareZone alreadyAddedFareZone = new org.rutebanken.netex.model.FareZone().withId("VKT:FareZone:123").withVersion("2");
StopPlace netexStopPlace = new StopPlace();
netexStopPlace.setId("NSR:StopPlace:1");
netexStopPlace.withTariffZones(new TariffZoneRefs_RelStructure().withTariffZoneRef(new TariffZoneRef().withRef(fareZone.getNetexId()).withVersion("1")));
SiteFrame siteFrame = new SiteFrame();
siteFrame.withTariffZones(new TariffZonesInFrame_RelStructure().withTariffZone(new ObjectFactory().createFareZone(alreadyAddedFareZone)));
tariffZonesFromStopsExporter.resolveTariffZones(Arrays.asList(netexStopPlace), siteFrame);
assertThat(siteFrame.getTariffZones().getTariffZone()).as("Number of tariffzones returned").hasSize(2);
}
Aggregations