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);
}
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);
}
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());
}
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);
}
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());
}
Aggregations