Search in sources :

Example 1 with StopPlaceReference

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

the class GroupOfStopPlacesSaverServiceTest method addMembers.

@Test
public void addMembers() throws Exception {
    StopPlace stopPlace = new StopPlace();
    stopPlaceRepository.save(stopPlace);
    GroupOfStopPlaces groupOfStopPlaces = new GroupOfStopPlaces();
    groupOfStopPlaces.setName(new EmbeddableMultilingualString("name"));
    groupOfStopPlaces.getMembers().add(new StopPlaceReference(stopPlace.getNetexId()));
    GroupOfStopPlaces saved = groupOfStopPlacesSaverService.saveNewVersion(groupOfStopPlaces);
    StopPlace stopPlace2 = new StopPlace();
    stopPlaceRepository.save(stopPlace2);
    GroupOfStopPlaces changed = new GroupOfStopPlaces();
    changed.setNetexId(saved.getNetexId());
    changed.setName(new EmbeddableMultilingualString("name"));
    changed.getMembers().add(new StopPlaceReference(stopPlace.getNetexId()));
    changed.getMembers().add(new StopPlaceReference(stopPlace2.getNetexId()));
    groupOfStopPlacesSaverService.saveNewVersion(changed);
    List<GroupOfStopPlaces> all = groupOfStopPlacesRepository.findAll();
    assertThat(all).hasSize(1);
    GroupOfStopPlaces actual = all.get(0);
    assertThat(actual.getMembers()).hasSize(2).extracting(StopPlaceReference::getRef).contains(stopPlace.getNetexId(), stopPlace2.getNetexId());
}
Also used : StopPlace(org.rutebanken.tiamat.model.StopPlace) GroupOfStopPlaces(org.rutebanken.tiamat.model.GroupOfStopPlaces) StopPlaceReference(org.rutebanken.tiamat.model.StopPlaceReference) EmbeddableMultilingualString(org.rutebanken.tiamat.model.EmbeddableMultilingualString) Test(org.junit.Test) TiamatIntegrationTest(org.rutebanken.tiamat.TiamatIntegrationTest)

Example 2 with StopPlaceReference

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

the class GroupOfStopPlacesSaverServiceTest method saveNewVersionDoesNotAcceptChildStopPlaceRefs.

@Test
public void saveNewVersionDoesNotAcceptChildStopPlaceRefs() throws Exception {
    StopPlace stopPlace = new StopPlace();
    stopPlace.setParentSiteRef(new SiteRefStructure("NSR:StopPlace:99999"));
    stopPlaceRepository.save(stopPlace);
    GroupOfStopPlaces groupOfStopPlaces = new GroupOfStopPlaces();
    groupOfStopPlaces.setName(new EmbeddableMultilingualString("name"));
    groupOfStopPlaces.getMembers().add(new StopPlaceReference(stopPlace.getNetexId()));
    assertThatThrownBy(() -> groupOfStopPlacesSaverService.saveNewVersion(groupOfStopPlaces)).isInstanceOf(IllegalArgumentException.class);
}
Also used : StopPlace(org.rutebanken.tiamat.model.StopPlace) GroupOfStopPlaces(org.rutebanken.tiamat.model.GroupOfStopPlaces) StopPlaceReference(org.rutebanken.tiamat.model.StopPlaceReference) SiteRefStructure(org.rutebanken.tiamat.model.SiteRefStructure) EmbeddableMultilingualString(org.rutebanken.tiamat.model.EmbeddableMultilingualString) Test(org.junit.Test) TiamatIntegrationTest(org.rutebanken.tiamat.TiamatIntegrationTest)

Example 3 with StopPlaceReference

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

the class ExportResourceTest method exportGroupOfStopPlacesToNetex.

@Test
public void exportGroupOfStopPlacesToNetex() throws Exception {
    org.rutebanken.tiamat.model.StopPlace stopPlace = new org.rutebanken.tiamat.model.StopPlace();
    stopPlace.setName(new EmbeddableMultilingualString("stopPlace"));
    stopPlace.setCentroid(point(60.000, 10.78));
    stopPlaceVersionedSaverService.saveNewVersion(stopPlace);
    org.rutebanken.tiamat.model.StopPlace stopPlace2 = new org.rutebanken.tiamat.model.StopPlace();
    stopPlace2.setName(new EmbeddableMultilingualString("stopPlace 2"));
    stopPlace2.setCentroid(point(61.000, 11.78));
    stopPlaceVersionedSaverService.saveNewVersion(stopPlace2);
    org.rutebanken.tiamat.model.GroupOfStopPlaces groupOfStopPlaces = new org.rutebanken.tiamat.model.GroupOfStopPlaces();
    groupOfStopPlaces.getMembers().add(new StopPlaceReference(stopPlace.getNetexId()));
    groupOfStopPlaces.getMembers().add(new StopPlaceReference(stopPlace2.getNetexId()));
    groupOfStopPlaces.setChangedBy("mr. Solem");
    groupOfStopPlaces.setCreated(Instant.now());
    groupOfStopPlaces.setChanged(Instant.now());
    groupOfStopPlaces.setName(new EmbeddableMultilingualString("oh my gosp"));
    org.rutebanken.tiamat.model.AlternativeName alternativeName = new org.rutebanken.tiamat.model.AlternativeName();
    alternativeName.setName(new EmbeddableMultilingualString("alternative name alias"));
    alternativeName.setNameType(org.rutebanken.tiamat.model.NameTypeEnumeration.ALIAS);
    groupOfStopPlaces.getAlternativeNames().add(alternativeName);
    groupOfStopPlacesSaverService.saveNewVersion(groupOfStopPlaces);
    stopPlaceRepository.flush();
    groupOfStopPlacesRepository.flush();
    ExportParams exportParams = ExportParams.newExportParamsBuilder().setStopPlaceSearch(StopPlaceSearch.newStopPlaceSearchBuilder().build()).setGroupOfStopPlacesExportMode(ExportParams.ExportMode.RELEVANT).build();
    Response response = exportResource.exportStopPlaces(exportParams);
    PublicationDeliveryStructure publicationDeliveryStructure = publicationDeliveryTestHelper.fromResponse(response);
    SiteFrame siteFrame = publicationDeliveryTestHelper.findSiteFrame(publicationDeliveryStructure);
    List<StopPlace> stopPlaces = publicationDeliveryTestHelper.extractStopPlaces(siteFrame);
    Assert.assertEquals(2, stopPlaces.size());
    GroupOfStopPlaces netexGroupOfStopPlaces = publicationDeliveryTestHelper.extractGroupOfStopPlaces(siteFrame).get(0);
    assertThat(netexGroupOfStopPlaces).isNotNull();
    assertThat(netexGroupOfStopPlaces.getName().getValue()).as("name.value").isEqualTo(groupOfStopPlaces.getName().getValue());
    assertThat(netexGroupOfStopPlaces.getAlternativeNames()).as("alternativeNames").isNotNull();
    assertThat(netexGroupOfStopPlaces.getMembers()).as("members").isNotNull();
    assertThat(netexGroupOfStopPlaces.getMembers().getStopPlaceRef()).as("stop place ref list").isNotNull().isNotEmpty().extracting(StopPlaceRefStructure::getRef).as("reference to stop place id").containsOnly(stopPlace.getNetexId(), stopPlace2.getNetexId());
    assertThat(netexGroupOfStopPlaces.getCentroid()).as("centroid").isNotNull();
    assertThat(netexGroupOfStopPlaces.getChanged()).as("changed").isNotNull();
    assertThat(netexGroupOfStopPlaces.getVersion()).as("version").isEqualTo(String.valueOf(groupOfStopPlaces.getVersion()));
}
Also used : StopPlace(org.rutebanken.netex.model.StopPlace) SiteFrame(org.rutebanken.netex.model.SiteFrame) GroupOfStopPlaces(org.rutebanken.netex.model.GroupOfStopPlaces) StopPlaceReference(org.rutebanken.tiamat.model.StopPlaceReference) PublicationDeliveryStructure(org.rutebanken.netex.model.PublicationDeliveryStructure) StopPlaceRefStructure(org.rutebanken.netex.model.StopPlaceRefStructure) EmbeddableMultilingualString(org.rutebanken.tiamat.model.EmbeddableMultilingualString) Response(javax.ws.rs.core.Response) ExportParams(org.rutebanken.tiamat.exporter.params.ExportParams) Test(org.junit.Test) TiamatIntegrationTest(org.rutebanken.tiamat.TiamatIntegrationTest)

Example 4 with StopPlaceReference

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

the class NetexMapperTest method mapGroupOfStopPlacesToNetex.

@Test
public void mapGroupOfStopPlacesToNetex() throws Exception {
    StopPlace stopPlace = new StopPlace();
    stopPlace.setNetexId("NSR:StopPlace:1");
    stopPlace.setName(new EmbeddableMultilingualString("stopPlace"));
    GroupOfStopPlaces groupOfStopPlaces = new GroupOfStopPlaces();
    groupOfStopPlaces.setNetexId("NSR:GroupOfStopPlaces:1");
    groupOfStopPlaces.getMembers().add(new StopPlaceReference(stopPlace.getNetexId()));
    groupOfStopPlaces.setChangedBy("Solem");
    groupOfStopPlaces.setVersion(2L);
    groupOfStopPlaces.setCreated(Instant.now());
    groupOfStopPlaces.setChanged(Instant.now());
    groupOfStopPlaces.setName(new EmbeddableMultilingualString("oh my gosp"));
    groupOfStopPlaces.setCentroid(geometryFactory.createPoint(new Coordinate(16, 17)));
    AlternativeName alternativeName = new AlternativeName();
    alternativeName.setName(new EmbeddableMultilingualString("alternative name alias"));
    alternativeName.setNameType(NameTypeEnumeration.ALIAS);
    groupOfStopPlaces.getAlternativeNames().add(alternativeName);
    org.rutebanken.netex.model.GroupOfStopPlaces netexGroupOfStopPlaces = netexMapper.getFacade().map(groupOfStopPlaces, org.rutebanken.netex.model.GroupOfStopPlaces.class);
    assertThat(netexGroupOfStopPlaces).isNotNull();
    assertThat(netexGroupOfStopPlaces.getName().getValue()).as("name.value").isEqualTo(groupOfStopPlaces.getName().getValue());
    assertThat(netexGroupOfStopPlaces.getAlternativeNames()).as("alternativeNames").isNotNull();
    assertThat(netexGroupOfStopPlaces.getMembers()).as("members").isNotNull();
    assertThat(netexGroupOfStopPlaces.getMembers().getStopPlaceRef()).as("stop place ref list").isNotNull().isNotEmpty().extracting(StopPlaceRefStructure::getRef).as("reference to stop place id").containsOnly(stopPlace.getNetexId());
    assertThat(netexGroupOfStopPlaces.getChanged()).as("changed").isNotNull();
    assertThat(netexGroupOfStopPlaces.getVersion()).as("version").isEqualTo(String.valueOf(groupOfStopPlaces.getVersion()));
}
Also used : StopPlace(org.rutebanken.tiamat.model.StopPlace) GroupOfStopPlaces(org.rutebanken.tiamat.model.GroupOfStopPlaces) Coordinate(org.locationtech.jts.geom.Coordinate) StopPlaceReference(org.rutebanken.tiamat.model.StopPlaceReference) StopPlaceRefStructure(org.rutebanken.netex.model.StopPlaceRefStructure) EmbeddableMultilingualString(org.rutebanken.tiamat.model.EmbeddableMultilingualString) AlternativeName(org.rutebanken.tiamat.model.AlternativeName) Test(org.junit.Test) TiamatIntegrationTest(org.rutebanken.tiamat.TiamatIntegrationTest)

Example 5 with StopPlaceReference

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

the class GroupOfStopPlacesCentroidComputerTest method compute.

@Test
public void compute() {
    StopPlace stopPlace = new StopPlace();
    stopPlace.setCentroid(point(60.000, 10.78));
    StopPlace stopPlace2 = new StopPlace();
    stopPlace2.setCentroid(point(60.000, 10.78));
    stopPlaceRepository.save(stopPlace);
    stopPlaceRepository.save(stopPlace2);
    GroupOfStopPlaces groupOfStopPlaces = new GroupOfStopPlaces();
    groupOfStopPlaces.getMembers().add(new StopPlaceReference(stopPlace.getNetexId()));
    groupOfStopPlaces.getMembers().add(new StopPlaceReference(stopPlace2.getNetexId()));
    groupOfStopPlacesSaverService.saveNewVersion(groupOfStopPlaces);
    Optional<Point> computedPoint = groupOfStopPlacesCentroidComputer.compute(groupOfStopPlaces);
    assertThat(computedPoint).isPresent();
    assertThat(computedPoint.get()).isEqualTo(stopPlace2.getCentroid());
}
Also used : StopPlace(org.rutebanken.tiamat.model.StopPlace) GroupOfStopPlaces(org.rutebanken.tiamat.model.GroupOfStopPlaces) StopPlaceReference(org.rutebanken.tiamat.model.StopPlaceReference) Point(org.locationtech.jts.geom.Point) Test(org.junit.Test) TiamatIntegrationTest(org.rutebanken.tiamat.TiamatIntegrationTest)

Aggregations

StopPlaceReference (org.rutebanken.tiamat.model.StopPlaceReference)11 Test (org.junit.Test)9 TiamatIntegrationTest (org.rutebanken.tiamat.TiamatIntegrationTest)9 EmbeddableMultilingualString (org.rutebanken.tiamat.model.EmbeddableMultilingualString)8 GroupOfStopPlaces (org.rutebanken.tiamat.model.GroupOfStopPlaces)8 StopPlace (org.rutebanken.tiamat.model.StopPlace)8 ExportParams (org.rutebanken.tiamat.exporter.params.ExportParams)3 TariffZoneRef (org.rutebanken.tiamat.model.TariffZoneRef)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 List (java.util.List)2 PublicationDeliveryStructure (org.rutebanken.netex.model.PublicationDeliveryStructure)2 StopPlaceRefStructure (org.rutebanken.netex.model.StopPlaceRefStructure)2 TariffZone (org.rutebanken.tiamat.model.TariffZone)2 TopographicPlace (org.rutebanken.tiamat.model.TopographicPlace)2 Instant (java.time.Instant)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Set (java.util.Set)1