From 0938ae1e06dc5ebcac92dc67ad910a27efba5f12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=20Erik=20St=C3=B8wer?= Date: Mon, 13 May 2024 22:02:51 +0200 Subject: [PATCH 01/50] Move mummu integration to entur sandbox --- .../entur/stopplace}/NetexHttpMessageConverterTest.java | 2 +- .../ext/entur/stopplace/EnturMummuStopPlaceRegistry.java} | 8 ++++---- .../ext/entur/stopplace}/NetexHttpMessageConverter.java | 2 +- .../netex/producer/line/JourneyPatternProducer.java | 2 +- .../entur/uttu/graphql/fetchers/QuayRefSearchFetcher.java | 2 +- .../uttu/graphql/mappers/FlexibleStopPlaceMapper.java | 2 +- .../graphql/mappers/StopPointInJourneyPatternMapper.java | 2 +- .../entur/uttu/stopplace/{ => spi}/StopPlaceRegistry.java | 2 +- src/test/java/no/entur/uttu/UttuTestApp.java | 5 ++--- .../java/no/entur/uttu/stubs/StopPlaceRegistryStub.java | 4 ++-- 10 files changed, 15 insertions(+), 16 deletions(-) rename src/{test/java/no/entur/uttu/config => ext-test/java/no/entur/uttu/ext/entur/stopplace}/NetexHttpMessageConverterTest.java (95%) rename src/{main/java/no/entur/uttu/stopplace/DefaultStopPlaceRegistry.java => ext/java/no/entur/uttu/ext/entur/stopplace/EnturMummuStopPlaceRegistry.java} (94%) rename src/{main/java/no/entur/uttu/config => ext/java/no/entur/uttu/ext/entur/stopplace}/NetexHttpMessageConverter.java (98%) rename src/main/java/no/entur/uttu/stopplace/{ => spi}/StopPlaceRegistry.java (95%) diff --git a/src/test/java/no/entur/uttu/config/NetexHttpMessageConverterTest.java b/src/ext-test/java/no/entur/uttu/ext/entur/stopplace/NetexHttpMessageConverterTest.java similarity index 95% rename from src/test/java/no/entur/uttu/config/NetexHttpMessageConverterTest.java rename to src/ext-test/java/no/entur/uttu/ext/entur/stopplace/NetexHttpMessageConverterTest.java index 2dc6e915..a149a5c4 100644 --- a/src/test/java/no/entur/uttu/config/NetexHttpMessageConverterTest.java +++ b/src/ext-test/java/no/entur/uttu/ext/entur/stopplace/NetexHttpMessageConverterTest.java @@ -1,4 +1,4 @@ -package no.entur.uttu.config; +package no.entur.uttu.ext.entur.stopplace; import jakarta.xml.bind.JAXBException; import org.junit.Test; diff --git a/src/main/java/no/entur/uttu/stopplace/DefaultStopPlaceRegistry.java b/src/ext/java/no/entur/uttu/ext/entur/stopplace/EnturMummuStopPlaceRegistry.java similarity index 94% rename from src/main/java/no/entur/uttu/stopplace/DefaultStopPlaceRegistry.java rename to src/ext/java/no/entur/uttu/ext/entur/stopplace/EnturMummuStopPlaceRegistry.java index 5fcce9c2..2635faf3 100644 --- a/src/main/java/no/entur/uttu/stopplace/DefaultStopPlaceRegistry.java +++ b/src/ext/java/no/entur/uttu/ext/entur/stopplace/EnturMummuStopPlaceRegistry.java @@ -13,7 +13,7 @@ * limitations under the Licence. */ -package no.entur.uttu.stopplace; +package no.entur.uttu.ext.entur.stopplace; import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; @@ -23,7 +23,7 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import javax.annotation.PostConstruct; -import no.entur.uttu.config.NetexHttpMessageConverter; +import no.entur.uttu.stopplace.spi.StopPlaceRegistry; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; @@ -39,10 +39,10 @@ * to retrieve a stop place given the ID of one of its quays. */ @Component -public class DefaultStopPlaceRegistry implements StopPlaceRegistry { +public class EnturMummuStopPlaceRegistry implements StopPlaceRegistry { private static final Logger logger = LoggerFactory.getLogger( - DefaultStopPlaceRegistry.class + EnturMummuStopPlaceRegistry.class ); private RestTemplate restTemplate = new RestTemplate(); diff --git a/src/main/java/no/entur/uttu/config/NetexHttpMessageConverter.java b/src/ext/java/no/entur/uttu/ext/entur/stopplace/NetexHttpMessageConverter.java similarity index 98% rename from src/main/java/no/entur/uttu/config/NetexHttpMessageConverter.java rename to src/ext/java/no/entur/uttu/ext/entur/stopplace/NetexHttpMessageConverter.java index 1eb64948..f27125e9 100644 --- a/src/main/java/no/entur/uttu/config/NetexHttpMessageConverter.java +++ b/src/ext/java/no/entur/uttu/ext/entur/stopplace/NetexHttpMessageConverter.java @@ -1,4 +1,4 @@ -package no.entur.uttu.config; +package no.entur.uttu.ext.entur.stopplace; import static jakarta.xml.bind.JAXBContext.newInstance; diff --git a/src/main/java/no/entur/uttu/export/netex/producer/line/JourneyPatternProducer.java b/src/main/java/no/entur/uttu/export/netex/producer/line/JourneyPatternProducer.java index f6b9095d..82ec1188 100644 --- a/src/main/java/no/entur/uttu/export/netex/producer/line/JourneyPatternProducer.java +++ b/src/main/java/no/entur/uttu/export/netex/producer/line/JourneyPatternProducer.java @@ -29,7 +29,7 @@ import no.entur.uttu.model.Ref; import no.entur.uttu.model.StopPointInJourneyPattern; import no.entur.uttu.model.job.SeverityEnumeration; -import no.entur.uttu.stopplace.StopPlaceRegistry; +import no.entur.uttu.stopplace.spi.StopPlaceRegistry; import org.rutebanken.netex.model.BookingAccessEnumeration; import org.rutebanken.netex.model.BookingArrangementsStructure; import org.rutebanken.netex.model.BookingMethodEnumeration; diff --git a/src/main/java/no/entur/uttu/graphql/fetchers/QuayRefSearchFetcher.java b/src/main/java/no/entur/uttu/graphql/fetchers/QuayRefSearchFetcher.java index 9181124b..340d859f 100644 --- a/src/main/java/no/entur/uttu/graphql/fetchers/QuayRefSearchFetcher.java +++ b/src/main/java/no/entur/uttu/graphql/fetchers/QuayRefSearchFetcher.java @@ -6,7 +6,7 @@ import graphql.schema.DataFetchingEnvironment; import java.util.stream.Collectors; import no.entur.uttu.model.TimetabledPassingTime; -import no.entur.uttu.stopplace.StopPlaceRegistry; +import no.entur.uttu.stopplace.spi.StopPlaceRegistry; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; diff --git a/src/main/java/no/entur/uttu/graphql/mappers/FlexibleStopPlaceMapper.java b/src/main/java/no/entur/uttu/graphql/mappers/FlexibleStopPlaceMapper.java index ddfe9760..6aab70f6 100644 --- a/src/main/java/no/entur/uttu/graphql/mappers/FlexibleStopPlaceMapper.java +++ b/src/main/java/no/entur/uttu/graphql/mappers/FlexibleStopPlaceMapper.java @@ -36,7 +36,7 @@ import no.entur.uttu.model.Value; import no.entur.uttu.repository.ProviderRepository; import no.entur.uttu.repository.generic.ProviderEntityRepository; -import no.entur.uttu.stopplace.StopPlaceRegistry; +import no.entur.uttu.stopplace.spi.StopPlaceRegistry; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; diff --git a/src/main/java/no/entur/uttu/graphql/mappers/StopPointInJourneyPatternMapper.java b/src/main/java/no/entur/uttu/graphql/mappers/StopPointInJourneyPatternMapper.java index 8a7b06fc..8d5d4ada 100644 --- a/src/main/java/no/entur/uttu/graphql/mappers/StopPointInJourneyPatternMapper.java +++ b/src/main/java/no/entur/uttu/graphql/mappers/StopPointInJourneyPatternMapper.java @@ -28,7 +28,7 @@ import no.entur.uttu.repository.FlexibleStopPlaceRepository; import no.entur.uttu.repository.ProviderRepository; import no.entur.uttu.repository.generic.ProviderEntityRepository; -import no.entur.uttu.stopplace.StopPlaceRegistry; +import no.entur.uttu.stopplace.spi.StopPlaceRegistry; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; diff --git a/src/main/java/no/entur/uttu/stopplace/StopPlaceRegistry.java b/src/main/java/no/entur/uttu/stopplace/spi/StopPlaceRegistry.java similarity index 95% rename from src/main/java/no/entur/uttu/stopplace/StopPlaceRegistry.java rename to src/main/java/no/entur/uttu/stopplace/spi/StopPlaceRegistry.java index a389e833..03a959f4 100644 --- a/src/main/java/no/entur/uttu/stopplace/StopPlaceRegistry.java +++ b/src/main/java/no/entur/uttu/stopplace/spi/StopPlaceRegistry.java @@ -13,7 +13,7 @@ * limitations under the Licence. */ -package no.entur.uttu.stopplace; +package no.entur.uttu.stopplace.spi; import java.util.Optional; diff --git a/src/test/java/no/entur/uttu/UttuTestApp.java b/src/test/java/no/entur/uttu/UttuTestApp.java index 22f2873c..5b65a87a 100644 --- a/src/test/java/no/entur/uttu/UttuTestApp.java +++ b/src/test/java/no/entur/uttu/UttuTestApp.java @@ -15,10 +15,9 @@ package no.entur.uttu; -import no.entur.uttu.ext.entur.organisation.EnturLegacyOrganisationRegistry; +import no.entur.uttu.ext.entur.stopplace.EnturMummuStopPlaceRegistry; import no.entur.uttu.repository.generic.ProviderEntityRepositoryImpl; import no.entur.uttu.security.UttuSecurityConfiguration; -import no.entur.uttu.stopplace.DefaultStopPlaceRegistry; import org.entur.pubsub.base.config.GooglePubSubConfig; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @@ -42,7 +41,7 @@ @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = App.class), @ComponentScan.Filter( type = FilterType.ASSIGNABLE_TYPE, - value = DefaultStopPlaceRegistry.class + value = EnturMummuStopPlaceRegistry.class ), } ) diff --git a/src/test/java/no/entur/uttu/stubs/StopPlaceRegistryStub.java b/src/test/java/no/entur/uttu/stubs/StopPlaceRegistryStub.java index a4bc1454..ca36dbf0 100644 --- a/src/test/java/no/entur/uttu/stubs/StopPlaceRegistryStub.java +++ b/src/test/java/no/entur/uttu/stubs/StopPlaceRegistryStub.java @@ -19,8 +19,8 @@ import java.io.IOException; import java.io.InputStream; import java.util.Optional; -import no.entur.uttu.config.NetexHttpMessageConverter; -import no.entur.uttu.stopplace.StopPlaceRegistry; +import no.entur.uttu.ext.entur.stopplace.NetexHttpMessageConverter; +import no.entur.uttu.stopplace.spi.StopPlaceRegistry; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpInputMessage; import org.springframework.stereotype.Component; From 43cda585887f5b865d3d4ecb4c54355c8406c23b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=20Erik=20St=C3=B8wer?= Date: Mon, 13 May 2024 23:08:18 +0200 Subject: [PATCH 02/50] Add new default implementation --- .../EnturMummuStopPlaceRegistry.java | 2 + ...ationDeliveryFileOrganisationRegistry.java | 12 +- ...licationDeliveryFileStopPlaceRegistry.java | 119 ++++++++++++++++++ src/test/java/no/entur/uttu/UttuTestApp.java | 4 - 4 files changed, 126 insertions(+), 11 deletions(-) create mode 100644 src/main/java/no/entur/uttu/stopplace/NetexPublicationDeliveryFileStopPlaceRegistry.java diff --git a/src/ext/java/no/entur/uttu/ext/entur/stopplace/EnturMummuStopPlaceRegistry.java b/src/ext/java/no/entur/uttu/ext/entur/stopplace/EnturMummuStopPlaceRegistry.java index 2635faf3..56dcc1ef 100644 --- a/src/ext/java/no/entur/uttu/ext/entur/stopplace/EnturMummuStopPlaceRegistry.java +++ b/src/ext/java/no/entur/uttu/ext/entur/stopplace/EnturMummuStopPlaceRegistry.java @@ -27,6 +27,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Profile; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; @@ -39,6 +40,7 @@ * to retrieve a stop place given the ID of one of its quays. */ @Component +@Profile("entur-mummu-stop-place-registry") public class EnturMummuStopPlaceRegistry implements StopPlaceRegistry { private static final Logger logger = LoggerFactory.getLogger( diff --git a/src/main/java/no/entur/uttu/organisation/NetexPublicationDeliveryFileOrganisationRegistry.java b/src/main/java/no/entur/uttu/organisation/NetexPublicationDeliveryFileOrganisationRegistry.java index 297c2b86..6629c83c 100644 --- a/src/main/java/no/entur/uttu/organisation/NetexPublicationDeliveryFileOrganisationRegistry.java +++ b/src/main/java/no/entur/uttu/organisation/NetexPublicationDeliveryFileOrganisationRegistry.java @@ -34,14 +34,12 @@ public class NetexPublicationDeliveryFileOrganisationRegistry implements OrganisationRegistry { - private final Logger logger = LoggerFactory.getLogger(this.getClass()); - - private List organisations = List.of(); - - private static final Logger log = LoggerFactory.getLogger( + private static final Logger logger = LoggerFactory.getLogger( NetexPublicationDeliveryFileOrganisationRegistry.class ); + private List organisations = List.of(); + private static final JAXBContext publicationDeliveryContext = createContext( PublicationDeliveryStructure.class, Organisation.class @@ -130,11 +128,11 @@ private Unmarshaller getUnmarshaller() throws JAXBException { private static JAXBContext createContext(Class... clazz) { try { JAXBContext jaxbContext = newInstance(clazz); - log.info("Created context {}", jaxbContext.getClass()); + logger.info("Created context {}", jaxbContext.getClass()); return jaxbContext; } catch (JAXBException e) { String message = "Could not create instance of jaxb context for class " + clazz; - log.warn(message, e); + logger.warn(message, e); throw new RuntimeException( "Could not create instance of jaxb context for class " + clazz, e diff --git a/src/main/java/no/entur/uttu/stopplace/NetexPublicationDeliveryFileStopPlaceRegistry.java b/src/main/java/no/entur/uttu/stopplace/NetexPublicationDeliveryFileStopPlaceRegistry.java new file mode 100644 index 00000000..7d0b5596 --- /dev/null +++ b/src/main/java/no/entur/uttu/stopplace/NetexPublicationDeliveryFileStopPlaceRegistry.java @@ -0,0 +1,119 @@ +package no.entur.uttu.stopplace; + +import static jakarta.xml.bind.JAXBContext.newInstance; + +import jakarta.xml.bind.JAXBContext; +import jakarta.xml.bind.JAXBElement; +import jakarta.xml.bind.JAXBException; +import jakarta.xml.bind.Unmarshaller; +import java.io.File; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.concurrent.ConcurrentHashMap; +import javax.annotation.PostConstruct; +import javax.xml.transform.Source; +import javax.xml.transform.stream.StreamSource; +import no.entur.uttu.organisation.NetexPublicationDeliveryFileOrganisationRegistry; +import no.entur.uttu.stopplace.spi.StopPlaceRegistry; +import org.rutebanken.netex.model.GeneralOrganisation; +import org.rutebanken.netex.model.Organisation; +import org.rutebanken.netex.model.PublicationDeliveryStructure; +import org.rutebanken.netex.model.Quay; +import org.rutebanken.netex.model.ResourceFrame; +import org.rutebanken.netex.model.SiteFrame; +import org.rutebanken.netex.model.StopPlace; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.stereotype.Component; + +@Component +@ConditionalOnMissingBean( + value = StopPlaceRegistry.class, + ignored = NetexPublicationDeliveryFileStopPlaceRegistry.class +) +public class NetexPublicationDeliveryFileStopPlaceRegistry implements StopPlaceRegistry { + + private static final Logger logger = LoggerFactory.getLogger( + NetexPublicationDeliveryFileOrganisationRegistry.class + ); + + private static final JAXBContext publicationDeliveryContext = createContext( + PublicationDeliveryStructure.class, + Organisation.class + ); + + private Map stopPlaceByQuayRefIndex = new ConcurrentHashMap<>(); + + @Value("${uttu.stopplace.netex-file-uri}") + String netexFileUri; + + @PostConstruct + public void init() { + try { + PublicationDeliveryStructure publicationDeliveryStructure = readFromSource( + new StreamSource(new File(netexFileUri)) + ); + publicationDeliveryStructure + .getDataObjects() + .getCompositeFrameOrCommonFrame() + .forEach(frame -> { + var frameValue = frame.getValue(); + if (frameValue instanceof SiteFrame siteFrame) { + List stopPlaces = siteFrame + .getStopPlaces() + .getStopPlace_() + .stream() + .map(stopPlace -> (StopPlace) stopPlace.getValue()) + .toList(); + + stopPlaces.forEach(stopPlace -> { + stopPlace + .getQuays() + .getQuayRefOrQuay() + .stream() + .forEach(quayRefOrQuay -> { + Quay quay = (Quay) quayRefOrQuay.getValue(); + stopPlaceByQuayRefIndex.put(quay.getId(), stopPlace); + }); + }); + } + }); + } catch (JAXBException e) { + logger.warn( + "Unable to unmarshal stop places xml, stop place registry will be an empty list" + ); + } + } + + @Override + public Optional getStopPlaceByQuayRef(String quayRef) { + return Optional.ofNullable(stopPlaceByQuayRefIndex.get(quayRef)); + } + + private T readFromSource(Source source) throws JAXBException { + JAXBElement element = (JAXBElement) getUnmarshaller().unmarshal(source); + return element.getValue(); + } + + private Unmarshaller getUnmarshaller() throws JAXBException { + return publicationDeliveryContext.createUnmarshaller(); + } + + private static JAXBContext createContext(Class... clazz) { + try { + JAXBContext jaxbContext = newInstance(clazz); + logger.info("Created context {}", jaxbContext.getClass()); + return jaxbContext; + } catch (JAXBException e) { + String message = "Could not create instance of jaxb context for class " + clazz; + logger.warn(message, e); + throw new RuntimeException( + "Could not create instance of jaxb context for class " + clazz, + e + ); + } + } +} diff --git a/src/test/java/no/entur/uttu/UttuTestApp.java b/src/test/java/no/entur/uttu/UttuTestApp.java index 5b65a87a..5db2ecfd 100644 --- a/src/test/java/no/entur/uttu/UttuTestApp.java +++ b/src/test/java/no/entur/uttu/UttuTestApp.java @@ -39,10 +39,6 @@ value = UttuSecurityConfiguration.class ), @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = App.class), - @ComponentScan.Filter( - type = FilterType.ASSIGNABLE_TYPE, - value = EnturMummuStopPlaceRegistry.class - ), } ) public class UttuTestApp { From ff7f38801e5140807118b35c4b1fe15b63162fed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=20Erik=20St=C3=B8wer?= Date: Tue, 14 May 2024 12:08:19 +0200 Subject: [PATCH 03/50] Remove stop place registry stub in favor of new implementation --- ...licationDeliveryFileStopPlaceRegistry.java | 21 +- ...actFixedLinesGraphQLIntegrationTest.groovy | 4 +- ...FlexibleLinesGraphQLIntegrationTest.groovy | 6 +- .../FixedLineGraphQLIntegrationTest.groovy | 4 +- ...ibleStopPlaceGraphQLIntegrationTest.groovy | 4 +- ...opPlaceByQuayGraphQLIntegrationTest.groovy | 11 +- .../uttu/stubs/StopPlaceRegistryStub.java | 58 -- .../resources/application-test.properties | 1 + src/test/resources/fixtures/stopplaces.xml | 780 ++++++++++++++++++ src/test/resources/stopPlaceFixture.xml | 649 --------------- 10 files changed, 809 insertions(+), 729 deletions(-) delete mode 100644 src/test/java/no/entur/uttu/stubs/StopPlaceRegistryStub.java create mode 100644 src/test/resources/fixtures/stopplaces.xml delete mode 100644 src/test/resources/stopPlaceFixture.xml diff --git a/src/main/java/no/entur/uttu/stopplace/NetexPublicationDeliveryFileStopPlaceRegistry.java b/src/main/java/no/entur/uttu/stopplace/NetexPublicationDeliveryFileStopPlaceRegistry.java index 7d0b5596..22646450 100644 --- a/src/main/java/no/entur/uttu/stopplace/NetexPublicationDeliveryFileStopPlaceRegistry.java +++ b/src/main/java/no/entur/uttu/stopplace/NetexPublicationDeliveryFileStopPlaceRegistry.java @@ -70,14 +70,19 @@ public void init() { .toList(); stopPlaces.forEach(stopPlace -> { - stopPlace - .getQuays() - .getQuayRefOrQuay() - .stream() - .forEach(quayRefOrQuay -> { - Quay quay = (Quay) quayRefOrQuay.getValue(); - stopPlaceByQuayRefIndex.put(quay.getId(), stopPlace); - }); + Optional + .ofNullable(stopPlace.getQuays()) + .ifPresentOrElse( + quays -> { + quays + .getQuayRefOrQuay() + .forEach(quayRefOrQuay -> { + Quay quay = (Quay) quayRefOrQuay.getValue(); + stopPlaceByQuayRefIndex.put(quay.getId(), stopPlace); + }); + }, + () -> {} + ); }); } }); diff --git a/src/test/groovy/no/entur/uttu/graphql/AbstractFixedLinesGraphQLIntegrationTest.groovy b/src/test/groovy/no/entur/uttu/graphql/AbstractFixedLinesGraphQLIntegrationTest.groovy index 804dca4a..57efdafa 100644 --- a/src/test/groovy/no/entur/uttu/graphql/AbstractFixedLinesGraphQLIntegrationTest.groovy +++ b/src/test/groovy/no/entur/uttu/graphql/AbstractFixedLinesGraphQLIntegrationTest.groovy @@ -117,13 +117,13 @@ abstract class AbstractFixedLinesGraphQLIntegrationTest extends AbstractGraphQLR { "pointsInSequence": [ { - "quayRef": "NSR:Quay:69", + "quayRef": "NSR:Quay:494", "destinationDisplay": { "frontText": "Første stopp" } }, { - "quayRef": "NSR:Quay:70" + "quayRef": "NSR:Quay:563" } ], "serviceJourneys": [ diff --git a/src/test/groovy/no/entur/uttu/graphql/AbstractFlexibleLinesGraphQLIntegrationTest.groovy b/src/test/groovy/no/entur/uttu/graphql/AbstractFlexibleLinesGraphQLIntegrationTest.groovy index ce1fe141..87508ea4 100644 --- a/src/test/groovy/no/entur/uttu/graphql/AbstractFlexibleLinesGraphQLIntegrationTest.groovy +++ b/src/test/groovy/no/entur/uttu/graphql/AbstractFlexibleLinesGraphQLIntegrationTest.groovy @@ -191,7 +191,7 @@ abstract class AbstractFlexibleLinesGraphQLIntegrationTest extends AbstractGraph "key": "foo", "values": ["bar", "baz"] }], - "hailAndRideArea": {"startQuayRef": "NSR:Quay:start","endQuayRef": "NSR:Quay:end"} + "hailAndRideArea": {"startQuayRef": "NSR:Quay:565","endQuayRef": "NSR:Quay:494"} } }""" @@ -268,7 +268,7 @@ abstract class AbstractFlexibleLinesGraphQLIntegrationTest extends AbstractGraph "flexibleStopPlaceRef": "$flexAreaStopPlaceId" }, { - "quayRef": "NSR:Quay:3513" + "quayRef": "NSR:Quay:563" } ], "serviceJourneys": [ @@ -306,7 +306,7 @@ abstract class AbstractFlexibleLinesGraphQLIntegrationTest extends AbstractGraph , { - "quayRef": "NSR:Quay:3513" + "quayRef": "NSR:Quay:494" } ], "serviceJourneys": [ diff --git a/src/test/groovy/no/entur/uttu/graphql/FixedLineGraphQLIntegrationTest.groovy b/src/test/groovy/no/entur/uttu/graphql/FixedLineGraphQLIntegrationTest.groovy index 9dfa763a..afa82664 100644 --- a/src/test/groovy/no/entur/uttu/graphql/FixedLineGraphQLIntegrationTest.groovy +++ b/src/test/groovy/no/entur/uttu/graphql/FixedLineGraphQLIntegrationTest.groovy @@ -29,7 +29,7 @@ class FixedLineGraphQLIntegrationTest extends AbstractFixedLinesGraphQLIntegrati createFixedLine(testFixedLineName) .body("data.mutateFixedLine.id", startsWith("TST:Line")) .body("data.mutateFixedLine.name", equalTo(testFixedLineName)) - .body("data.mutateFixedLine.journeyPatterns[0].pointsInSequence[0].quayRef", equalTo("NSR:Quay:69")) + .body("data.mutateFixedLine.journeyPatterns[0].pointsInSequence[0].quayRef", equalTo("NSR:Quay:494")) .body("data.mutateFixedLine.journeyPatterns[0].serviceJourneys[0].passingTimes[0].departureTime", equalTo("07:00:00")) } -} \ No newline at end of file +} diff --git a/src/test/groovy/no/entur/uttu/graphql/FlexibleStopPlaceGraphQLIntegrationTest.groovy b/src/test/groovy/no/entur/uttu/graphql/FlexibleStopPlaceGraphQLIntegrationTest.groovy index c9bb8e66..d89e6847 100644 --- a/src/test/groovy/no/entur/uttu/graphql/FlexibleStopPlaceGraphQLIntegrationTest.groovy +++ b/src/test/groovy/no/entur/uttu/graphql/FlexibleStopPlaceGraphQLIntegrationTest.groovy @@ -72,8 +72,8 @@ mutation deleteFlexibleStopPlace(\$id: ID!) { createFlexibleStopPlaceWithHailAndRideArea(hailAndRideTest) .body("data.mutateFlexibleStopPlace.id", startsWith("TST:FlexibleStopPlace")) .body("data.mutateFlexibleStopPlace.name", equalTo(hailAndRideTest)) - .body("data.mutateFlexibleStopPlace.hailAndRideArea.startQuayRef", equalTo("NSR:Quay:start")) - .body("data.mutateFlexibleStopPlace.hailAndRideArea.endQuayRef", equalTo("NSR:Quay:end")) + .body("data.mutateFlexibleStopPlace.hailAndRideArea.startQuayRef", equalTo("NSR:Quay:565")) + .body("data.mutateFlexibleStopPlace.hailAndRideArea.endQuayRef", equalTo("NSR:Quay:494")) } @Test diff --git a/src/test/groovy/no/entur/uttu/graphql/StopPlaceByQuayGraphQLIntegrationTest.groovy b/src/test/groovy/no/entur/uttu/graphql/StopPlaceByQuayGraphQLIntegrationTest.groovy index 08144e14..bd3b3add 100644 --- a/src/test/groovy/no/entur/uttu/graphql/StopPlaceByQuayGraphQLIntegrationTest.groovy +++ b/src/test/groovy/no/entur/uttu/graphql/StopPlaceByQuayGraphQLIntegrationTest.groovy @@ -9,13 +9,14 @@ class StopPlaceByQuayGraphQLIntegrationTest extends AbstractFlexibleLinesGraphQL @Test void getStopPlaceByQuayRefTest() { - String id = "NSR:StopPlace:337" - String query = """ { stopPlaceByQuayRef(id:"$id") { id, name { lang value }, quays { id publicCode }}}""" - assertResponse(executeGraphqQLQueryOnly(query), "stopPlaceByQuayRef") + String quayId = "NSR:Quay:494"; + String expectedStopPlaceId = "NSR:StopPlace:301" + String query = """ { stopPlaceByQuayRef(id:"$quayId") { id, name { lang value }, quays { id publicCode }}}""" + assertResponse(executeGraphqQLQueryOnly(query), "stopPlaceByQuayRef", expectedStopPlaceId) } - void assertResponse(ValidatableResponse rsp, String path) { - rsp.body("data. "+path+".id", equalTo("NSR:StopPlace:337")) + void assertResponse(ValidatableResponse rsp, String path, String expectedId) { + rsp.body("data. "+path+".id", equalTo(expectedId)) } } diff --git a/src/test/java/no/entur/uttu/stubs/StopPlaceRegistryStub.java b/src/test/java/no/entur/uttu/stubs/StopPlaceRegistryStub.java deleted file mode 100644 index ca36dbf0..00000000 --- a/src/test/java/no/entur/uttu/stubs/StopPlaceRegistryStub.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Licensed under the EUPL, Version 1.2 or – as soon they will be approved by - * the European Commission - subsequent versions of the EUPL (the "Licence"); - * You may not use this work except in compliance with the Licence. - * You may obtain a copy of the Licence at: - * - * https://joinup.ec.europa.eu/software/page/eupl - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the Licence is distributed on an "AS IS" basis, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Licence for the specific language governing permissions and - * limitations under the Licence. - */ - -package no.entur.uttu.stubs; - -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.Optional; -import no.entur.uttu.ext.entur.stopplace.NetexHttpMessageConverter; -import no.entur.uttu.stopplace.spi.StopPlaceRegistry; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpInputMessage; -import org.springframework.stereotype.Component; - -@Component -public class StopPlaceRegistryStub implements StopPlaceRegistry { - - @Override - public Optional getStopPlaceByQuayRef( - String quayRef - ) { - NetexHttpMessageConverter converter = new NetexHttpMessageConverter(); - - try { - org.rutebanken.netex.model.StopPlace stopPlace = - (org.rutebanken.netex.model.StopPlace) converter.read( - org.rutebanken.netex.model.StopPlace.class, - new HttpInputMessage() { - @Override - public InputStream getBody() throws IOException { - return new FileInputStream("src/test/resources/stopPlaceFixture.xml"); - } - - @Override - public HttpHeaders getHeaders() { - return HttpHeaders.EMPTY; - } - } - ); - return Optional.of(stopPlace); - } catch (IOException e) { - return Optional.empty(); - } - } -} diff --git a/src/test/resources/application-test.properties b/src/test/resources/application-test.properties index b0707aee..3deb23f6 100644 --- a/src/test/resources/application-test.properties +++ b/src/test/resources/application-test.properties @@ -64,3 +64,4 @@ management.endpoints.web.exposure.exclude=* management.endpoints.jmx.exposure.exclude=* uttu.organisations.netex-file-uri=src/test/resources/fixtures/organisations.xml +uttu.stopplace.netex-file-uri=src/test/resources/fixtures/stopplaces.xml diff --git a/src/test/resources/fixtures/stopplaces.xml b/src/test/resources/fixtures/stopplaces.xml new file mode 100644 index 00000000..dde2b32b --- /dev/null +++ b/src/test/resources/fixtures/stopplaces.xml @@ -0,0 +1,780 @@ + + + + + + + Oslo S + + + + 10.753276 + 59.910925 + + + + unknown + + + true + true + unknown + unknown + unknown + + + + + + + + both + + + + + true + true + + + + + true + 17 + + false + + + + + + rail + + + + + + + + + railStation + preferredInterchange + + + + + grails-platformId + 6170 + + + uicCode + 7600100 + + + imported-id + NSB:Quay:760010015,LIN:Quay:007600100 + + + tpsiId + 760010015 + + + 15 + + + 10.754734 + 59.910123 + + + + 15 + + + + + grails-platformId + 6157 + + + uicCode + 7600100 + + + imported-id + NSB:Quay:0076001002 + + + tpsiId + 760010002 + + + 2 + + + 10.755594 + 59.911022 + + + + 2 + + + + + grails-platformId + 6160 + + + uicCode + 7600100 + + + imported-id + NSB:Quay:0076001005 + + + tpsiId + 760010005 + + + 5 + + + 10.755399 + 59.910818 + + + + 5 + + + + + grails-platformId + 6162 + + + uicCode + 7600100 + + + imported-id + NSB:Quay:0076001007 + + + tpsiId + 760010007 + + + 7 + + + 10.755264 + 59.910677 + + + + 7 + + + + + grails-platformId + 6161 + + + uicCode + 7600100 + + + imported-id + NSB:Quay:0076001006 + + + tpsiId + 760010006 + + + 6 + + + 10.755326 + 59.910741 + + + + 6 + + + + + grails-platformId + 6166 + + + uicCode + 7600100 + + + imported-id + NSB:Quay:00760010011 + + + tpsiId + 760010011 + + + 11 + + + 10.754999 + 59.910400 + + + + 11 + + + + + grails-platformId + 6171 + + + uicCode + 7600100 + + + imported-id + NSB:Quay:00760010016 + + + tpsiId + 760010016 + + + 16 + + + 10.754663 + 59.910049 + + + + 16 + + + + + grails-platformId + 6168 + + + uicCode + 7600100 + + + imported-id + NSB:Quay:00760010013 + + + tpsiId + 760010013 + + + 13 + + + 10.754866 + 59.910261 + + + + 13 + + + + + grails-platformId + 6169 + + + uicCode + 7600100 + + + imported-id + NSB:Quay:00760010014 + + + tpsiId + 760010014 + + + 14 + + + 10.754798 + 59.910189 + + + + 14 + + + + + grails-platformId + 6164 + + + uicCode + 7600100 + + + imported-id + NSB:Quay:0076001009 + + + tpsiId + 760010009 + + + 9 + + + 10.755133 + 59.910540 + + + + 9 + + + + + grails-platformId + 6163 + + + uicCode + 7600100 + + + imported-id + NSB:Quay:0076001008 + + + tpsiId + 760010008 + + + 8 + + + 10.755195 + 59.910605 + + + + 8 + + + + + grails-platformId + 6159 + + + uicCode + 7600100 + + + imported-id + NSB:Quay:0076001004 + + + tpsiId + 760010004 + + + 4 + + + 10.755461 + 59.910882 + + + + 4 + + + + + grails-platformId + 6174 + + + uicCode + 7600100 + + + imported-id + NSB:Quay:00760010019 + + + tpsiId + 760010019 + + + 19 + + + 10.754467 + 59.909844 + + + + 19 + + + + + grails-platformId + 6172 + + + uicCode + 7600100 + + + imported-id + NSB:Quay:00760010017 + + + tpsiId + 760010017 + + + 17 + + + 10.754599 + 59.909982 + + + + 17 + + + + + grails-platformId + 6167 + + + uicCode + 7600100 + + + imported-id + NSB:Quay:00760010012 + + + tpsiId + 760010012 + + + 12 + + + 10.754926 + 59.910324 + + + + 12 + + + + + grails-platformId + 6158 + + + uicCode + 7600100 + + + imported-id + NSB:Quay:0076001003 + + + tpsiId + 760010003 + + + 3 + + + 10.755531 + 59.910956 + + + + 3 + + + + + grails-platformId + 6173 + + + uicCode + 7600100 + + + imported-id + NSB:Quay:00760010018 + + + tpsiId + 760010018 + + + 18 + + + 10.754527 + 59.909906 + + + + 18 + + + + + grails-platformId + 6165 + + + uicCode + 7600100 + + + imported-id + NSB:Quay:00760010010 + + + tpsiId + 760010010 + + + 10 + + + 10.755060 + 59.910464 + + + + 10 + + + + + grails-platformId + 6156 + + + uicCode + 7600100 + + + TPSI-Kode + 760010001 + + + imported-id + FLT:Quay:007600100,NSB:Quay:0076001001,NSB:Quay:076001001,NSB:Quay:007600100,FLT:Quay:7600100 + + + tpsiId + 760010001 + + + 1 + + + 10.755664 + 59.911095 + + + + 1 + + + + +