use of org.rutebanken.tiamat.model.TariffZone in project tiamat by entur.
the class StopPlaceMergerTest method testMergeStopPlacesWithAlternativeNames.
@Test
@Transactional
public void testMergeStopPlacesWithAlternativeNames() {
StopPlace fromStopPlace = new StopPlace();
fromStopPlace.setName(new EmbeddableMultilingualString("Name"));
TariffZone tariffZone1 = new TariffZone();
tariffZone1.setNetexId("NSR:TariffZone:1");
tariffZone1.setVersion(1L);
tariffZoneRepository.save(tariffZone1);
Set<TariffZoneRef> fromTzSet = new HashSet<>();
TariffZoneRef fromTz = new TariffZoneRef();
fromTz.setRef(tariffZone1.getNetexId());
fromTz.setVersion(String.valueOf(tariffZone1.getVersion()));
fromTzSet.add(fromTz);
fromStopPlace.setTariffZones(fromTzSet);
AlternativeName fromAlternativeName = new AlternativeName();
fromAlternativeName.setName(new EmbeddableMultilingualString("FROM-alternative"));
fromStopPlace.getAlternativeNames().add(fromAlternativeName);
StopPlace toStopPlace = new StopPlace();
toStopPlace.setName(new EmbeddableMultilingualString("Name 2"));
TariffZone tariffZone2 = new TariffZone();
tariffZone2.setNetexId("NSR:TariffZone:2");
tariffZone2.setVersion(2L);
tariffZoneRepository.save(tariffZone2);
Set<TariffZoneRef> toTzSet = new HashSet<>();
TariffZoneRef toTz = new TariffZoneRef();
toTz.setRef(tariffZone2.getNetexId());
toTz.setVersion(String.valueOf(tariffZone2.getVersion()));
toTzSet.add(toTz);
toStopPlace.setTariffZones(toTzSet);
AlternativeName toAlternativeName = new AlternativeName();
toAlternativeName.setName(new EmbeddableMultilingualString("TO-alternative"));
toStopPlace.getAlternativeNames().add(toAlternativeName);
stopPlaceVersionedSaverService.saveNewVersion(fromStopPlace);
stopPlaceVersionedSaverService.saveNewVersion(toStopPlace);
StopPlace mergedStopPlace = stopPlaceMerger.mergeStopPlaces(fromStopPlace.getNetexId(), toStopPlace.getNetexId(), null, null, false);
// AlternativeName
assertThat(mergedStopPlace.getAlternativeNames()).isNotNull();
assertThat(mergedStopPlace.getAlternativeNames()).hasSize(2);
}
use of org.rutebanken.tiamat.model.TariffZone in project tiamat by entur.
the class TariffZoneRepositoryImplTest method getTariffZonesFromStopPlaceIds.
@Test
public void getTariffZonesFromStopPlaceIds() throws Exception {
String tariffZoneNetexId = "CRI:TariffZone:1";
TariffZone v1 = new TariffZone();
v1.setVersion(1L);
v1.setNetexId(tariffZoneNetexId);
var zonedDateTime = ZonedDateTime.of(2020, 12, 01, 00, 00, 00, 000, ZoneId.systemDefault());
Instant fromDate = zonedDateTime.toInstant();
v1.setValidBetween(new ValidBetween(fromDate, null));
tariffZoneRepository.save(v1);
TariffZone v2 = new TariffZone();
v2.setVersion(2L);
v2.setNetexId(tariffZoneNetexId);
var zonedDateTime2 = zonedDateTime.plusDays(10L);
var fromDate2 = zonedDateTime2.toInstant();
v2.setValidBetween(new ValidBetween(fromDate2, null));
tariffZoneRepository.save(v2);
StopPlace stopPlace = new StopPlace();
stopPlace.getTariffZones().add(new TariffZoneRef(tariffZoneNetexId));
stopPlaceRepository.save(stopPlace);
List<TariffZone> tariffZones = tariffZoneRepository.getTariffZonesFromStopPlaceIds(Sets.newHashSet(stopPlace.getId()));
assertThat(tariffZones).hasSize(1);
assertThat(tariffZones.get(0).getVersion()).isEqualTo(v2.getVersion());
}
use of org.rutebanken.tiamat.model.TariffZone in project tiamat by entur.
the class TariffZoneRepositoryImplTest method findTariffZonesByIdSuffix.
@Test
public void findTariffZonesByIdSuffix() throws Exception {
TariffZone tariffZone2V = new TariffZone();
tariffZone2V.setName(new EmbeddableMultilingualString("2V"));
tariffZone2V.setNetexId("RUT:TariffZone:2V");
TariffZone tariffZone412 = new TariffZone();
tariffZone412.setNetexId("BRA:TariffZone:412");
tariffZone412.setName(new EmbeddableMultilingualString("Kongsberg"));
tariffZoneRepository.save(tariffZone2V);
tariffZoneRepository.save(tariffZone412);
TariffZoneSearch search = TariffZoneSearch.newTariffZoneSearchBuilder().query(tariffZone2V.getName().getValue()).build();
List<TariffZone> tariffZoneList = tariffZoneRepository.findTariffZones(search);
assertThat(tariffZoneList).hasSize(1).extracting(TariffZone::getNetexId).containsOnly(tariffZone2V.getNetexId());
}
use of org.rutebanken.tiamat.model.TariffZone in project tiamat by entur.
the class TariffZonesLookupServiceTest method getTariffZones.
@Test
public void getTariffZones() {
TariffZone firstVersion = new TariffZone();
firstVersion.setNetexId("NSR:TariffZone:1");
firstVersion.setVersion(1L);
Point point = geometryFactory.createPoint(new Coordinate(9.84, 59.26));
Geometry geometry = point.buffer(20);
LinearRing linearRing = new LinearRing(new CoordinateArraySequence(geometry.getCoordinates()), geometryFactory);
firstVersion.setPolygon(geometryFactory.createPolygon(linearRing, null));
TariffZone secondVersion = new TariffZone();
secondVersion.setNetexId("NSR:TariffZone:1");
secondVersion.setVersion(2L);
secondVersion.setPolygon(geometryFactory.createPolygon(linearRing, null));
TariffZone anotherOne = new TariffZone();
anotherOne.setNetexId("NSR:TariffZone:2");
anotherOne.setVersion(3L);
anotherOne.setPolygon(geometryFactory.createPolygon(linearRing, null));
when(tariffZoneRepository.findAllValidTariffZones()).thenReturn(Arrays.asList(firstVersion, secondVersion, anotherOne));
java.util.function.Supplier<List<Pair<String, Polygon>>> actual = tariffZonesLookupService.getTariffZones();
assertThat(actual.get()).hasSize(2);
}
use of org.rutebanken.tiamat.model.TariffZone in project tiamat by entur.
the class StopPlaceMergerTest method testMergeStopPlacesWithTariffZones.
@Test
@Transactional
public void testMergeStopPlacesWithTariffZones() {
StopPlace fromStopPlace = new StopPlace();
fromStopPlace.setName(new EmbeddableMultilingualString("Name"));
TariffZone tariffZone1 = new TariffZone();
tariffZone1.setNetexId("NSR:TariffZone:1");
tariffZone1.setVersion(1L);
tariffZoneRepository.save(tariffZone1);
Set<TariffZoneRef> fromTzSet = new HashSet<>();
TariffZoneRef fromTz = new TariffZoneRef();
fromTz.setRef(tariffZone1.getNetexId());
fromTz.setVersion(String.valueOf(tariffZone1.getVersion()));
fromTzSet.add(fromTz);
fromStopPlace.setTariffZones(fromTzSet);
StopPlace toStopPlace = new StopPlace();
toStopPlace.setName(new EmbeddableMultilingualString("Name 2"));
TariffZone tariffZone2 = new TariffZone();
tariffZone2.setNetexId("NSR:TariffZone:2");
tariffZone2.setVersion(2L);
tariffZoneRepository.save(tariffZone2);
Set<TariffZoneRef> toTzSet = new HashSet<>();
TariffZoneRef toTz = new TariffZoneRef();
toTz.setRef(tariffZone2.getNetexId());
toTz.setVersion(String.valueOf(tariffZone2.getVersion()));
toTzSet.add(toTz);
toStopPlace.setTariffZones(toTzSet);
stopPlaceVersionedSaverService.saveNewVersion(fromStopPlace);
stopPlaceVersionedSaverService.saveNewVersion(toStopPlace);
StopPlace mergedStopPlace = stopPlaceMerger.mergeStopPlaces(fromStopPlace.getNetexId(), toStopPlace.getNetexId(), null, null, false);
assertThat(mergedStopPlace.getTariffZones()).hasSize(2);
}
Aggregations