Search in sources :

Example 26 with ValidBetween

use of org.rutebanken.tiamat.model.ValidBetween in project tiamat by entur.

the class StopPlaceVersionedSaverServiceTest method doNotAcceptFromDateBeforePreviousVersionFromDate.

@Test(expected = IllegalArgumentException.class)
public void doNotAcceptFromDateBeforePreviousVersionFromDate() {
    StopPlace previousVersion = new StopPlace();
    previousVersion.setVersion(1L);
    stopPlaceRepository.save(previousVersion);
    Instant now = Instant.now();
    // No to date
    previousVersion.setValidBetween(new ValidBetween(now.minusSeconds(1000), null));
    StopPlace newVersion = new StopPlace();
    newVersion.setVersion(2L);
    newVersion.setValidBetween(new ValidBetween(previousVersion.getValidBetween().getFromDate().minusSeconds(10)));
    newVersion.setNetexId(previousVersion.getNetexId());
    stopPlaceVersionedSaverService.saveNewVersion(previousVersion, newVersion);
}
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 27 with ValidBetween

use of org.rutebanken.tiamat.model.ValidBetween in project tiamat by entur.

the class StopPlaceVersionedSaverServiceTest method terminateStopPlaceValidityVerifyValidity.

@Test
public void terminateStopPlaceValidityVerifyValidity() throws Exception {
    StopPlace stopPlace = new StopPlace(new EmbeddableMultilingualString("About to get terminated"));
    stopPlace.setVersion(1L);
    stopPlace.setValidBetween(new ValidBetween(Instant.EPOCH));
    stopPlace = stopPlaceRepository.save(stopPlace);
    StopPlace newVersion = versionCreator.createCopy(stopPlace, StopPlace.class);
    Instant now = Instant.now();
    Instant terminated = now.plusSeconds(1);
    newVersion.setValidBetween(new ValidBetween(now, terminated));
    newVersion = stopPlaceVersionedSaverService.saveNewVersion(stopPlace, newVersion);
    assertThat(newVersion.getVersion()).isGreaterThan(stopPlace.getVersion());
    assertThat(newVersion.getValidBetween()).isNotNull();
    assertThat(newVersion.getValidBetween().getFromDate()).isEqualTo(now);
    assertThat(newVersion.getValidBetween().getToDate()).isEqualTo(terminated);
}
Also used : StopPlace(org.rutebanken.tiamat.model.StopPlace) Instant(java.time.Instant) ValidBetween(org.rutebanken.tiamat.model.ValidBetween) EmbeddableMultilingualString(org.rutebanken.tiamat.model.EmbeddableMultilingualString) Test(org.junit.Test) TiamatIntegrationTest(org.rutebanken.tiamat.TiamatIntegrationTest)

Example 28 with ValidBetween

use of org.rutebanken.tiamat.model.ValidBetween in project tiamat by entur.

the class StopPlaceVersionedSaverServiceTest method newVersionDefaultFromDateIsSet.

@Test
public void newVersionDefaultFromDateIsSet() throws Exception {
    StopPlace oldVersion = new StopPlace(new EmbeddableMultilingualString("About to get a new version where default from date is set"));
    oldVersion.setVersion(1L);
    oldVersion.setValidBetween(new ValidBetween(Instant.EPOCH));
    oldVersion = stopPlaceRepository.save(oldVersion);
    StopPlace newVersion = versionCreator.createCopy(oldVersion, StopPlace.class);
    newVersion.setValidBetween(new ValidBetween(null));
    newVersion = stopPlaceVersionedSaverService.saveNewVersion(oldVersion, newVersion);
    assertThat(newVersion.getVersion()).isGreaterThan(oldVersion.getVersion());
    assertThat(newVersion.getValidBetween()).isNotNull();
    assertThat(newVersion.getValidBetween().getFromDate()).isNotNull();
    oldVersion = stopPlaceRepository.findFirstByNetexIdAndVersion(oldVersion.getNetexId(), oldVersion.getVersion());
    assertThat(newVersion.getValidBetween().getFromDate().minusMillis(MILLIS_BETWEEN_VERSIONS)).isEqualTo(oldVersion.getValidBetween().getToDate());
}
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)

Example 29 with ValidBetween

use of org.rutebanken.tiamat.model.ValidBetween in project tiamat by entur.

the class TariffZoneSaverServiceTest method updateTariffZoneShouldHaveValidFromDate.

@Test(expected = IllegalArgumentException.class)
public void updateTariffZoneShouldHaveValidFromDate() {
    TariffZone existingTariffZone = new TariffZone();
    existingTariffZone.setNetexId(randomizedTestNetexIdGenerator.generateRandomizedNetexId(existingTariffZone));
    Geometry geometry = geometryFactory.createPoint(new Coordinate(9.84, 59.26)).buffer(20);
    LinearRing linearRing = new LinearRing(new CoordinateArraySequence(geometry.getCoordinates()), geometryFactory);
    existingTariffZone.setPolygon(geometryFactory.createPolygon(linearRing, null));
    existingTariffZone.setVersion(2L);
    var zonedDateTime = ZonedDateTime.of(2020, 12, 01, 00, 00, 00, 000, ZoneId.systemDefault());
    Instant existingTariffZoneFromDate = zonedDateTime.toInstant();
    existingTariffZone.setValidBetween(new ValidBetween(existingTariffZoneFromDate, null));
    tariffZoneRepository.save(existingTariffZone);
    TariffZone newTariffZone = new TariffZone();
    newTariffZone.setNetexId(existingTariffZone.getNetexId());
    newTariffZone.setName(new EmbeddableMultilingualString("name"));
    newTariffZone.setPolygon(null);
    Instant newTariffZoneFromDate = zonedDateTime.minusDays(1L).toInstant();
    newTariffZone.setValidBetween(new ValidBetween(newTariffZoneFromDate, null));
    tariffZoneSaverService.saveNewVersion(newTariffZone);
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) TariffZone(org.rutebanken.tiamat.model.TariffZone) Coordinate(org.locationtech.jts.geom.Coordinate) Instant(java.time.Instant) ValidBetween(org.rutebanken.tiamat.model.ValidBetween) LinearRing(org.locationtech.jts.geom.LinearRing) EmbeddableMultilingualString(org.rutebanken.tiamat.model.EmbeddableMultilingualString) CoordinateArraySequence(org.locationtech.jts.geom.impl.CoordinateArraySequence) Test(org.junit.Test) TiamatIntegrationTest(org.rutebanken.tiamat.TiamatIntegrationTest)

Example 30 with ValidBetween

use of org.rutebanken.tiamat.model.ValidBetween in project tiamat by entur.

the class TariffZoneSaverServiceTest method saveExistingTariffZone.

@Test
public void saveExistingTariffZone() {
    TariffZone existingTariffZone = new TariffZone();
    existingTariffZone.setNetexId(randomizedTestNetexIdGenerator.generateRandomizedNetexId(existingTariffZone));
    Geometry geometry = geometryFactory.createPoint(new Coordinate(9.84, 59.26)).buffer(20);
    LinearRing linearRing = new LinearRing(new CoordinateArraySequence(geometry.getCoordinates()), geometryFactory);
    existingTariffZone.setPolygon(geometryFactory.createPolygon(linearRing, null));
    existingTariffZone.setVersion(2L);
    var zonedDateTime = ZonedDateTime.of(2020, 12, 01, 00, 00, 00, 000, ZoneId.systemDefault());
    Instant fromDate = zonedDateTime.toInstant();
    existingTariffZone.setValidBetween(new ValidBetween(fromDate, null));
    tariffZoneRepository.save(existingTariffZone);
    TariffZone newTariffZone = new TariffZone();
    newTariffZone.setNetexId(existingTariffZone.getNetexId());
    newTariffZone.setName(new EmbeddableMultilingualString("name"));
    newTariffZone.setPolygon(null);
    TariffZone actual = tariffZoneSaverService.saveNewVersion(newTariffZone);
    assertThat(actual.getPolygon()).isNull();
    assertThat(actual.getVersion()).isEqualTo(3L);
    assertThat(actual.getName().getValue()).isEqualTo(newTariffZone.getName().getValue());
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) TariffZone(org.rutebanken.tiamat.model.TariffZone) Coordinate(org.locationtech.jts.geom.Coordinate) Instant(java.time.Instant) ValidBetween(org.rutebanken.tiamat.model.ValidBetween) LinearRing(org.locationtech.jts.geom.LinearRing) EmbeddableMultilingualString(org.rutebanken.tiamat.model.EmbeddableMultilingualString) CoordinateArraySequence(org.locationtech.jts.geom.impl.CoordinateArraySequence) 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