Search in sources :

Example 1 with ValidBetween

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();
}
Also used : StopPlace(org.rutebanken.tiamat.model.StopPlace) ValidBetween(org.rutebanken.tiamat.model.ValidBetween) EmbeddableMultilingualString(org.rutebanken.tiamat.model.EmbeddableMultilingualString) Test(org.junit.Test) TiamatIntegrationTest(org.rutebanken.tiamat.TiamatIntegrationTest) Transactional(javax.transaction.Transactional)

Example 2 with ValidBetween

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);
}
Also used : StopPlace(org.rutebanken.tiamat.model.StopPlace) Instant(java.time.Instant) EmbeddableMultilingualString(org.rutebanken.tiamat.model.EmbeddableMultilingualString) ValidBetween(org.rutebanken.tiamat.model.ValidBetween) PlaceEquipment(org.rutebanken.tiamat.model.PlaceEquipment) EmbeddableMultilingualString(org.rutebanken.tiamat.model.EmbeddableMultilingualString) GeneralSign(org.rutebanken.tiamat.model.GeneralSign) Coordinate(org.locationtech.jts.geom.Coordinate) PrivateCodeStructure(org.rutebanken.tiamat.model.PrivateCodeStructure) Value(org.rutebanken.tiamat.model.Value) Quay(org.rutebanken.tiamat.model.Quay) InstalledEquipment_VersionStructure(org.rutebanken.tiamat.model.InstalledEquipment_VersionStructure) Test(org.junit.Test) TiamatIntegrationTest(org.rutebanken.tiamat.TiamatIntegrationTest) Transactional(javax.transaction.Transactional)

Example 3 with ValidBetween

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);
}
Also used : StopPlace(org.rutebanken.tiamat.model.StopPlace) Instant(java.time.Instant) ValidBetween(org.rutebanken.tiamat.model.ValidBetween) EmbeddableMultilingualString(org.rutebanken.tiamat.model.EmbeddableMultilingualString) EmbeddableMultilingualString(org.rutebanken.tiamat.model.EmbeddableMultilingualString) Test(org.junit.Test) TiamatIntegrationTest(org.rutebanken.tiamat.TiamatIntegrationTest) Transactional(javax.transaction.Transactional)

Example 4 with ValidBetween

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);
}
Also used : StopPlace(org.rutebanken.tiamat.model.StopPlace) Instant(java.time.Instant) ValidBetween(org.rutebanken.tiamat.model.ValidBetween) Test(org.junit.Test) TiamatIntegrationTest(org.rutebanken.tiamat.TiamatIntegrationTest)

Example 5 with ValidBetween

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);
}
Also used : StopPlace(org.rutebanken.tiamat.model.StopPlace) ValidBetween(org.rutebanken.tiamat.model.ValidBetween) Test(org.junit.Test) TiamatIntegrationTest(org.rutebanken.tiamat.TiamatIntegrationTest)

Aggregations

ValidBetween (org.rutebanken.tiamat.model.ValidBetween)66 StopPlace (org.rutebanken.tiamat.model.StopPlace)57 Test (org.junit.Test)56 TiamatIntegrationTest (org.rutebanken.tiamat.TiamatIntegrationTest)56 EmbeddableMultilingualString (org.rutebanken.tiamat.model.EmbeddableMultilingualString)38 Instant (java.time.Instant)33 StopPlaceSearch (org.rutebanken.tiamat.exporter.params.StopPlaceSearch)17 SiteRefStructure (org.rutebanken.tiamat.model.SiteRefStructure)14 ChangedStopPlaceSearch (org.rutebanken.tiamat.repository.search.ChangedStopPlaceSearch)12 ExportParams (org.rutebanken.tiamat.exporter.params.ExportParams)11 Quay (org.rutebanken.tiamat.model.Quay)11 List (java.util.List)9 Coordinate (org.locationtech.jts.geom.Coordinate)9 TopographicPlace (org.rutebanken.tiamat.model.TopographicPlace)9 Pageable (org.springframework.data.domain.Pageable)9 Autowired (org.springframework.beans.factory.annotation.Autowired)8 Arrays (java.util.Arrays)7 Set (java.util.Set)7 IdMappingDto (org.rutebanken.tiamat.dtoassembling.dto.IdMappingDto)7 Value (org.rutebanken.tiamat.model.Value)7