use of org.rutebanken.tiamat.model.ValidBetween in project tiamat by entur.
the class StopPlaceRepositoryImplTest method findStopsWithEffectiveChangesInPeriodWithParent.
@Test
public void findStopsWithEffectiveChangesInPeriodWithParent() {
String importedIdPosix = "321";
String importedId = "XXX:StopPlace:" + importedIdPosix;
StopPlace childStop = new StopPlace();
childStop.setVersion(1L);
Quay quay = new Quay();
quay.getOrCreateValues(ORIGINAL_ID_KEY).add(importedId);
quayRepository.save(quay);
childStop.getQuays().add(quay);
StopPlace parentStop = new StopPlace();
parentStop.setParentStopPlace(true);
parentStop.setVersion(2L);
// Valid between only set on parent
parentStop.setValidBetween(new ValidBetween(now.minusSeconds(10)));
parentStop.getChildren().add(childStop);
stopPlaceRepository.save(parentStop);
childStop.setParentSiteRef(new SiteRefStructure(parentStop.getNetexId(), String.valueOf(parentStop.getVersion())));
stopPlaceRepository.save(childStop);
ChangedStopPlaceSearch changedStopPlaceSearch = new ChangedStopPlaceSearch(now.minusSeconds(20), now.plusSeconds(20), PageRequest.of(0, 10));
Page<StopPlace> result = stopPlaceRepository.findStopPlacesWithEffectiveChangeInPeriod(changedStopPlaceSearch);
assertThat(result.getContent()).extracting(StopPlace::getNetexId).contains(parentStop.getNetexId());
assertThat(result.getContent()).extracting(StopPlace::getNetexId).doesNotContain(childStop.getNetexId());
}
use of org.rutebanken.tiamat.model.ValidBetween in project tiamat by entur.
the class StopPlaceRepositoryImplTest method findStopPlacesDefaultsToVersionValidityCurrent.
@Test
public void findStopPlacesDefaultsToVersionValidityCurrent() {
Instant yesterday = now.minus(1, ChronoUnit.DAYS);
StopPlace v1 = new StopPlace(new EmbeddableMultilingualString("stop"));
v1.setStopPlaceType(StopTypeEnumeration.BUS_STATION);
v1.setVersion(1L);
v1.setValidBetween(new ValidBetween(Instant.EPOCH, yesterday));
stopPlaceRepository.save(v1);
StopPlace v2 = new StopPlace(new EmbeddableMultilingualString("v2"));
v2.setVersion(2L);
v2.setNetexId(v1.getNetexId());
v2.setStopPlaceType(StopTypeEnumeration.BUS_STATION);
v2.setValidBetween(new ValidBetween(yesterday));
stopPlaceRepository.save(v2);
stopPlaceRepository.flush();
ExportParams exportParams = newExportParamsBuilder().setStopPlaceSearch(newStopPlaceSearchBuilder().setQuery(v2.getNetexId()).setStopTypeEnumerations(Arrays.asList(StopTypeEnumeration.BUS_STATION)).build()).build();
List<StopPlace> content = stopPlaceRepository.findStopPlace(exportParams).getContent();
assertThat(content).isNotEmpty();
assertThat(content).hasSize(1);
assertThat(content.get(0).getVersion()).isEqualTo(2L);
}
use of org.rutebanken.tiamat.model.ValidBetween in project tiamat by entur.
the class StopPlaceRepositoryImplTest method findStopPlacesWithinMaxVersion.
@Test
public void findStopPlacesWithinMaxVersion() throws Exception {
double southEastLatitude = 59.875649;
double southEastLongitude = 10.500340;
double northWestLatitude = 59.875924;
double northWestLongitude = 10.500699;
StopPlace version1 = createStopPlace(59.875679, 10.500430);
version1.setVersion(1L);
version1.setNetexId("NSR:StopPlace:977777");
version1.setValidBetween(new ValidBetween(Instant.EPOCH, now.minusMillis(1000000)));
StopPlace version2 = createStopPlace(59.875679, 10.500430);
version2.setVersion(2L);
version2.setNetexId(version1.getNetexId());
version2.setValidBetween(new ValidBetween(now.minusMillis(1000001), now.plusMillis(1000000)));
stopPlaceRepository.save(version1);
stopPlaceRepository.save(version2);
Pageable pageable = PageRequest.of(0, 10);
Page<StopPlace> result = stopPlaceRepository.findStopPlacesWithin(southEastLongitude, southEastLatitude, northWestLongitude, northWestLatitude, null, pageable);
assertThat(result).hasSize(1);
assertThat(result.getContent().get(0).getVersion()).isEqualTo(version2.getVersion());
}
use of org.rutebanken.tiamat.model.ValidBetween in project tiamat by entur.
the class StopPlaceRepositoryImplTest method findByTagParam.
@Test
public void findByTagParam() {
StopPlace stopPlace = new StopPlace();
stopPlace.setVersion(2L);
stopPlace.setValidBetween(new ValidBetween(now.minusSeconds(10)));
stopPlaceRepository.save(stopPlace);
Tag tag = new Tag();
tag.setName("tagname");
tag.setIdreference(stopPlace.getNetexId());
tag = tagRepository.save(tag);
StopPlaceSearch stopPlaceSearch = StopPlaceSearch.newStopPlaceSearchBuilder().setQuery("#" + tag.getName()).build();
Page<StopPlace> searchResult = stopPlaceRepository.findStopPlace(ExportParams.newExportParamsBuilder().setStopPlaceSearch(stopPlaceSearch).build());
assertThat(searchResult.getContent()).extracting(s -> s.getNetexId()).contains(stopPlace.getNetexId());
}
use of org.rutebanken.tiamat.model.ValidBetween in project tiamat by entur.
the class StopPlaceRepositoryTest method findCurrentlyValidStopPlaceWithoutEndDate.
@Test
public void findCurrentlyValidStopPlaceWithoutEndDate() {
StopPlace currentlyValid = new StopPlace();
currentlyValid.setVersion(1L);
currentlyValid.setValidBetween(new ValidBetween(now.minus(1, DAYS)));
stopPlaceRepository.save(currentlyValid);
StopPlaceSearch stopPlaceSearch = StopPlaceSearch.newStopPlaceSearchBuilder().setVersionValidity(ExportParams.VersionValidity.ALL).build();
Page<StopPlace> results = stopPlaceRepository.findStopPlace(ExportParams.newExportParamsBuilder().setStopPlaceSearch(stopPlaceSearch).build());
assertThat(results).hasSize(1);
assertThat(results).contains(currentlyValid);
}
Aggregations