use of org.rutebanken.tiamat.model.ValidBetween in project tiamat by entur.
the class StopPlaceMergerTest method testMergeStopPlacesShouldIgnoreValidBetween.
@Test
@Transactional
public void testMergeStopPlacesShouldIgnoreValidBetween() {
StopPlace fromStopPlace = new StopPlace();
fromStopPlace.setName(new EmbeddableMultilingualString("Name"));
ValidBetween fromValidBetween = new ValidBetween(now.minusSeconds(3600));
fromStopPlace.setValidBetween(fromValidBetween);
StopPlace toStopPlace = new StopPlace();
toStopPlace.setName(new EmbeddableMultilingualString("Name 2"));
ValidBetween toValidBetween = new ValidBetween(now.minusSeconds(1800));
toStopPlace.setValidBetween(toValidBetween);
stopPlaceVersionedSaverService.saveNewVersion(fromStopPlace);
stopPlaceVersionedSaverService.saveNewVersion(toStopPlace);
StopPlace mergedStopPlace = stopPlaceMerger.mergeStopPlaces(fromStopPlace.getNetexId(), toStopPlace.getNetexId(), null, null, false);
assertThat(mergedStopPlace.getValidBetween()).isNotNull();
assertThat(mergedStopPlace.getValidBetween().getFromDate()).isNotNull();
assertThat(mergedStopPlace.getValidBetween().getToDate()).isNull();
}
use of org.rutebanken.tiamat.model.ValidBetween in project tiamat by entur.
the class StopPlaceMergerTest method testMergeStopPlaces.
@Test
@Transactional
public void testMergeStopPlaces() {
Instant atTestStart = now;
StopPlace fromStopPlace = new StopPlace();
fromStopPlace.setName(new EmbeddableMultilingualString("Name"));
fromStopPlace.setCentroid(geometryFactory.createPoint(new Coordinate(11.1, 60.1)));
fromStopPlace.getOriginalIds().add("TEST:StopPlace:1234");
fromStopPlace.getOriginalIds().add("TEST:StopPlace:5678");
fromStopPlace.setStopPlaceType(StopTypeEnumeration.AIRPORT);
PlaceEquipment fromPlaceEquipment = new PlaceEquipment();
GeneralSign generalSign = new GeneralSign();
generalSign.setSignContentType(SignContentEnumeration.TRANSPORT_MODE);
generalSign.setPublicCode(new PrivateCodeStructure("111", "111111"));
fromPlaceEquipment.getInstalledEquipment().add(generalSign);
fromStopPlace.setPlaceEquipments(fromPlaceEquipment);
String testKey = "testKey";
String testValue = "testValue";
fromStopPlace.getKeyValues().put(testKey, new Value(testValue));
Quay fromQuay = new Quay();
fromQuay.setCompassBearing(new Float(90));
fromQuay.setCentroid(geometryFactory.createPoint(new Coordinate(11.2, 60.2)));
fromQuay.getOriginalIds().add("TEST:Quay:123401");
fromQuay.getOriginalIds().add("TEST:Quay:567801");
fromStopPlace.getQuays().add(fromQuay);
String oldVersionComment = "Old version deleted";
fromStopPlace.setVersionComment(oldVersionComment);
fromStopPlace.setTransportMode(VehicleModeEnumeration.WATER);
stopPlaceVersionedSaverService.saveNewVersion(fromStopPlace);
StopPlace toStopPlace = new StopPlace();
toStopPlace.setName(new EmbeddableMultilingualString("Name 2"));
toStopPlace.setCentroid(geometryFactory.createPoint(new Coordinate(11.11, 60.11)));
toStopPlace.getOriginalIds().add("TEST:StopPlace:4321");
toStopPlace.getOriginalIds().add("TEST:StopPlace:8765");
toStopPlace.setStopPlaceType(StopTypeEnumeration.BUS_STATION);
toStopPlace.setTransportMode(VehicleModeEnumeration.BUS);
// Old version of toStopPlace
Instant toStopPlaceOriginalFromDate = Instant.EPOCH;
toStopPlace.setValidBetween(new ValidBetween(toStopPlaceOriginalFromDate));
Quay toQuay = new Quay();
toQuay.setCompassBearing(new Float(90));
toQuay.setCentroid(geometryFactory.createPoint(new Coordinate(11.21, 60.21)));
toQuay.getOriginalIds().add("TEST:Quay:432101");
toQuay.getOriginalIds().add("TEST:Quay:876501");
toStopPlace.getQuays().add(toQuay);
stopPlaceVersionedSaverService.saveNewVersion(toStopPlace);
// Act
StopPlace mergedStopPlace = stopPlaceMerger.mergeStopPlaces(fromStopPlace.getNetexId(), toStopPlace.getNetexId(), null, null, false);
assertThat(mergedStopPlace).isNotNull();
assertThat(fromStopPlace.getOriginalIds()).isNotEmpty();
assertThat(toStopPlace.getOriginalIds()).isNotEmpty();
assertThat(mergedStopPlace.getOriginalIds()).hasSize(fromStopPlace.getOriginalIds().size() + toStopPlace.getOriginalIds().size());
assertThat(mergedStopPlace.getOriginalIds().containsAll(fromStopPlace.getOriginalIds()));
assertThat(mergedStopPlace.getKeyValues().get(testKey)).isNotNull();
assertThat(mergedStopPlace.getKeyValues().get(testKey).getItems()).hasSize(1);
assertThat(mergedStopPlace.getKeyValues().get(testKey).getItems()).contains(testValue);
assertThat(mergedStopPlace.getName().getValue()).matches(toStopPlace.getName().getValue());
assertThat(mergedStopPlace.getVersionComment()).isNull();
assertThat(mergedStopPlace.getTransportMode()).isEqualTo(VehicleModeEnumeration.BUS);
assertThat(mergedStopPlace.getStopPlaceType()).isEqualTo(StopTypeEnumeration.BUS_STATION);
// Equipment
PlaceEquipment placeEquipment = mergedStopPlace.getPlaceEquipments();
assertThat(placeEquipment).isNotNull();
List<InstalledEquipment_VersionStructure> equipment = placeEquipment.getInstalledEquipment();
assertThat(equipment).hasSize(1);
// Result from merge does not contain same object
assertThat(equipment).doesNotContain(generalSign);
assertThat(equipment.get(0)).isInstanceOf(GeneralSign.class);
assertThat(((GeneralSign) equipment.get(0)).getSignContentType()).isEqualTo(SignContentEnumeration.TRANSPORT_MODE);
// assertQuays
assertThat(mergedStopPlace.getQuays()).hasSize(2);
mergedStopPlace.getQuays().forEach(quay -> {
if (quay.getNetexId().equals(fromQuay.getNetexId())) {
// The from-Quay has increased its version twice - once for terminating 'from', once for adding to 'to'
assertThat(quay.getVersion()).isEqualTo(1 + fromQuay.getVersion());
assertThat(quay.equals(fromQuay));
} else if (quay.getNetexId().equals(toQuay.getNetexId())) {
assertThat(quay.getVersion()).isEqualTo(1 + toQuay.getVersion());
assertThat(quay.equals(toQuay));
} else {
fail("Unknown Quay has been added");
}
});
StopPlace stopPlaceBeforeMerging = stopPlaceRepository.findFirstByNetexIdAndVersion(toStopPlace.getNetexId(), toStopPlace.getVersion());
assertThat(mergedStopPlace.getValidBetween().getFromDate()).as("merged stop place from date").isEqualTo(stopPlaceBeforeMerging.getValidBetween().getToDate().plusMillis(MILLIS_BETWEEN_VERSIONS)).as("merged stop place from date should have version from date after test started").isAfterOrEqualTo(atTestStart);
assertThat(stopPlaceBeforeMerging.getValidBetween().getFromDate()).as("old version of to-stopplace should not have changed from date").isEqualTo(toStopPlaceOriginalFromDate);
assertThat(stopPlaceBeforeMerging.getValidBetween().getToDate()).as("old version of to-stopplace should have its to date updated").isAfterOrEqualTo(atTestStart);
}
use of org.rutebanken.tiamat.model.ValidBetween in project tiamat by entur.
the class StopPlaceTerminatorTest method testDeactivateStopPlaceWithFromDate.
/**
* When attempting to deactivate stop place that is already deactivate, expect exception.
*/
@Transactional
@Test(expected = IllegalArgumentException.class)
public void testDeactivateStopPlaceWithFromDate() {
Instant now = Instant.now();
StopPlace savedStopPlace = stopPlaceVersionedSaverService.saveNewVersion(new StopPlace(new EmbeddableMultilingualString("LIAB")));
stopPlaceRepository.save(savedStopPlace);
savedStopPlace.setValidBetween(new ValidBetween(now, now.plusSeconds(10)));
String stopPlaceNetexId = savedStopPlace.getNetexId();
Instant terminateDate = now.plusSeconds(20);
stopPlaceTerminator.terminateStopPlace(stopPlaceNetexId, terminateDate, "Deactivating Stop", null);
}
use of org.rutebanken.tiamat.model.ValidBetween in project tiamat by entur.
the class ValidityUpdaterTest method useValidBetweenFromDateIfAlreadySet.
@Test
public void useValidBetweenFromDateIfAlreadySet() {
StopPlace stopPlace = new StopPlace();
stopPlace.setVersion(1L);
Instant now = Instant.now();
stopPlace.setValidBetween(new ValidBetween(now));
Instant actual = validityUpdater.updateValidBetween(stopPlace, now);
assertThat(stopPlace.getValidBetween()).isNotNull();
assertThat(stopPlace.getValidBetween().getFromDate()).as("from date").isEqualTo(now);
assertThat(stopPlace.getValidBetween().getToDate()).as("to date").isNull();
assertThat(actual).as("new version valid from").isEqualTo(now);
}
use of org.rutebanken.tiamat.model.ValidBetween in project tiamat by entur.
the class ValidityUpdaterTest method doNotSetEndDateOnPreviousVersionIfAlreadySet.
@Test
public void doNotSetEndDateOnPreviousVersionIfAlreadySet() {
StopPlace oldVersion = new StopPlace();
oldVersion.setVersion(1L);
oldVersion.setValidBetween(new ValidBetween(Instant.EPOCH, Instant.EPOCH));
validityUpdater.terminateVersion(oldVersion, Instant.now());
assertThat(oldVersion.getValidBetween().getToDate()).isEqualTo(Instant.EPOCH);
}
Aggregations