diff --git a/src/test/java/org/rutebanken/netex/model/MarshalUnmarshalTest.java b/src/test/java/org/rutebanken/netex/model/MarshalUnmarshalTest.java index d72c226..e2df73b 100644 --- a/src/test/java/org/rutebanken/netex/model/MarshalUnmarshalTest.java +++ b/src/test/java/org/rutebanken/netex/model/MarshalUnmarshalTest.java @@ -35,6 +35,7 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; +import java.time.Duration; import java.time.LocalDateTime; import java.time.LocalTime; import java.time.temporal.ChronoField; @@ -295,6 +296,119 @@ void unmarshalPublicationDeliveryAndVerifyValidBetween() throws JAXBException, I assertThat(departureTimeOffset).isNotNull().hasToString("08:40"); } + @Test + void networkWithAuthorityRefRoundTrip() throws JAXBException { + Marshaller marshaller = jaxbContext.createMarshaller(); + + Network network = factory.createNetwork() + .withVersion("1").withId("TST:Network:1") + .withName(factory.createMultilingualString().withValue("Test Network")) + .withTransportOrganisationRef(factory.createAuthorityRef( + new AuthorityRef().withRef("TST:Authority:1"))); + + PublicationDeliveryStructure publicationDelivery = new PublicationDeliveryStructure() + .withPublicationTimestamp(LocalDateTime.now().withNano(0)) + .withParticipantRef("test") + .withDataObjects(new PublicationDeliveryStructure.DataObjects() + .withCompositeFrameOrCommonFrame(factory.createCompositeFrame( + factory.createCompositeFrame() + .withVersion("1").withId("TST:CompositeFrame:1") + .withFrames(new Frames_RelStructure() + .withCommonFrame(factory.createServiceFrame( + factory.createServiceFrame() + .withVersion("1").withId("TST:ServiceFrame:1") + .withNetwork(network))))))); + + marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + marshaller.marshal(factory.createPublicationDelivery(publicationDelivery), byteArrayOutputStream); + + String xml = byteArrayOutputStream.toString(); + + Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); + + @SuppressWarnings("unchecked") + JAXBElement jaxbElement = (JAXBElement) unmarshaller + .unmarshal(new ByteArrayInputStream(xml.getBytes())); + + PublicationDeliveryStructure actual = jaxbElement.getValue(); + CompositeFrame compositeFrame = (CompositeFrame) actual.getDataObjects().getCompositeFrameOrCommonFrame().get(0).getValue(); + ServiceFrame serviceFrame = (ServiceFrame) compositeFrame.getFrames().getCommonFrame().get(0).getValue(); + Network actualNetwork = serviceFrame.getNetwork(); + + assertThat(actualNetwork.getName().getValue()).isEqualTo("Test Network"); + assertThat(actualNetwork.getTransportOrganisationRef().getValue().getRef()).isEqualTo("TST:Authority:1"); + } + + @Test + void flexibleLineRoundTrip() throws JAXBException { + Marshaller marshaller = jaxbContext.createMarshaller(); + + FlexibleLine flexibleLine = new FlexibleLine() + .withVersion("1").withId("TST:FlexibleLine:1") + .withName(factory.createMultilingualString().withValue("Flex Route")) + .withTransportMode(AllVehicleModesOfTransportEnumeration.BUS) + .withFlexibleLineType(FlexibleLineTypeEnumeration.FLEXIBLE_AREAS_ONLY) + .withBookingAccess(BookingAccessEnumeration.PUBLIC) + .withBookWhen(PurchaseWhenEnumeration.DAY_OF_TRAVEL_ONLY) + .withLatestBookingTime(LocalTime.of(14, 0)) + .withBookingContact(new ContactStructure().withPhone("+47 11223344").withUrl("https://flex.example.com")); + + marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + marshaller.marshal(factory.createFlexibleLine(flexibleLine), byteArrayOutputStream); + + String xml = byteArrayOutputStream.toString(); + + Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); + + @SuppressWarnings("unchecked") + JAXBElement jaxbElement = (JAXBElement) unmarshaller + .unmarshal(new ByteArrayInputStream(xml.getBytes())); + + FlexibleLine actual = jaxbElement.getValue(); + assertThat(actual.getName().getValue()).isEqualTo("Flex Route"); + assertThat(actual.getTransportMode()).isEqualTo(AllVehicleModesOfTransportEnumeration.BUS); + assertThat(actual.getFlexibleLineType()).isEqualTo(FlexibleLineTypeEnumeration.FLEXIBLE_AREAS_ONLY); + assertThat(actual.getBookingAccess()).isEqualTo(BookingAccessEnumeration.PUBLIC); + assertThat(actual.getBookWhen()).isEqualTo(PurchaseWhenEnumeration.DAY_OF_TRAVEL_ONLY); + assertThat(actual.getLatestBookingTime()).isEqualTo(LocalTime.of(14, 0)); + assertThat(actual.getBookingContact().getPhone()).isEqualTo("+47 11223344"); + assertThat(actual.getBookingContact().getUrl()).isEqualTo("https://flex.example.com"); + } + + @Test + void blockRoundTrip() throws JAXBException { + Marshaller marshaller = jaxbContext.createMarshaller(); + + Block block = new Block() + .withVersion("1").withId("TST:Block:1") + .withName(factory.createMultilingualString().withValue("Test Block")) + .withDescription(factory.createMultilingualString().withValue("Block description")) + .withPrivateCode(new PrivateCodeStructure().withValue("BLK001")) + .withStartTime(LocalTime.of(6, 0)) + .withEndTime(LocalTime.of(14, 30)); + + marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + marshaller.marshal(factory.createBlock(block), byteArrayOutputStream); + + String xml = byteArrayOutputStream.toString(); + + Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); + + @SuppressWarnings("unchecked") + JAXBElement jaxbElement = (JAXBElement) unmarshaller + .unmarshal(new ByteArrayInputStream(xml.getBytes())); + + Block actual = jaxbElement.getValue(); + assertThat(actual.getName().getValue()).isEqualTo("Test Block"); + assertThat(actual.getDescription().getValue()).isEqualTo("Block description"); + assertThat(actual.getPrivateCode().getValue()).isEqualTo("BLK001"); + assertThat(actual.getStartTime()).isEqualTo(LocalTime.of(6, 0)); + assertThat(actual.getEndTime()).isEqualTo(LocalTime.of(14, 30)); + } + @Test void fragmentShouldNotContainNetexNamespace() throws Exception { JAXBContext netexJaxBContext = JAXBContext.newInstance("net.opengis.gml._3:org.rutebanken.netex.model:uk.org.siri.siri"); diff --git a/src/test/java/org/rutebanken/netex/model/UnmarshalResourceFrameExtendedTest.java b/src/test/java/org/rutebanken/netex/model/UnmarshalResourceFrameExtendedTest.java new file mode 100644 index 0000000..2ee3ea2 --- /dev/null +++ b/src/test/java/org/rutebanken/netex/model/UnmarshalResourceFrameExtendedTest.java @@ -0,0 +1,124 @@ +/* + * 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 org.rutebanken.netex.model; + +import jakarta.xml.bind.JAXBElement; +import jakarta.xml.bind.JAXBException; +import jakarta.xml.bind.Unmarshaller; +import org.junit.jupiter.api.Test; + +import java.io.ByteArrayInputStream; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +class UnmarshalResourceFrameExtendedTest extends AbstractUnmarshalFrameTest { + + @Test + void unmarshalAuthorityWithContactDetails() throws JAXBException { + + String xml = "\n" + + "\n" + + " 2023-08-03T00:20:33.505\n" + + " RB\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " Test Authority\n" + + " \n" + + " +47 99887766\n" + + " https://www.testauthority.no\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + ""; + + Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); + + @SuppressWarnings("unchecked") + JAXBElement jaxbElement = (JAXBElement) unmarshaller + .unmarshal(new ByteArrayInputStream(xml.getBytes())); + + PublicationDeliveryStructure publicationDeliveryStructure = jaxbElement.getValue(); + CompositeFrame compositeFrame = (CompositeFrame) publicationDeliveryStructure.getDataObjects().getCompositeFrameOrCommonFrame().get(0).getValue(); + + ResourceFrame resourceFrame = (ResourceFrame) compositeFrame.getFrames().getCommonFrame().get(0).getValue(); + + Authority authority = (Authority) resourceFrame.getOrganisations().getOrganisation_().get(0).getValue(); + assertEquals("Test Authority", authority.getName().getValue()); + assertEquals("+47 99887766", authority.getContactDetails().getPhone()); + assertEquals("https://www.testauthority.no", authority.getContactDetails().getUrl()); + } + + @Test + void unmarshalOperatorWithBrandingRef() throws JAXBException { + + String xml = "\n" + + "\n" + + " 2023-08-03T00:20:33.505\n" + + " RB\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " Test Brand\n" + + " https://www.testbrand.no\n" + + " https://www.testbrand.no/logo.png\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " Test Operator\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + ""; + + Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); + + @SuppressWarnings("unchecked") + JAXBElement jaxbElement = (JAXBElement) unmarshaller + .unmarshal(new ByteArrayInputStream(xml.getBytes())); + + PublicationDeliveryStructure publicationDeliveryStructure = jaxbElement.getValue(); + CompositeFrame compositeFrame = (CompositeFrame) publicationDeliveryStructure.getDataObjects().getCompositeFrameOrCommonFrame().get(0).getValue(); + + ResourceFrame resourceFrame = (ResourceFrame) compositeFrame.getFrames().getCommonFrame().get(0).getValue(); + + Branding branding = (Branding) resourceFrame.getTypesOfValue().getValueSetOrTypeOfValue().get(0).getValue(); + assertEquals("Test Brand", branding.getName().getValue()); + assertEquals("https://www.testbrand.no", branding.getUrl()); + assertEquals("https://www.testbrand.no/logo.png", branding.getImage()); + + Operator operator = (Operator) resourceFrame.getOrganisations().getOrganisation_().get(0).getValue(); + assertEquals("Test Operator", operator.getName().getValue()); + assertNotNull(operator.getBrandingRef()); + assertEquals("TST:Branding:1", operator.getBrandingRef().getRef()); + } +} diff --git a/src/test/java/org/rutebanken/netex/model/UnmarshalServiceFrameChouetteTest.java b/src/test/java/org/rutebanken/netex/model/UnmarshalServiceFrameChouetteTest.java new file mode 100644 index 0000000..3817891 --- /dev/null +++ b/src/test/java/org/rutebanken/netex/model/UnmarshalServiceFrameChouetteTest.java @@ -0,0 +1,503 @@ +/* + * 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 org.rutebanken.netex.model; + +import jakarta.xml.bind.JAXBElement; +import jakarta.xml.bind.JAXBException; +import jakarta.xml.bind.Unmarshaller; +import org.junit.jupiter.api.Test; + +import java.io.ByteArrayInputStream; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +class UnmarshalServiceFrameChouetteTest extends AbstractUnmarshalFrameTest { + + @Test + void unmarshalBookingArrangementsOnStopPointInJourneyPattern() throws JAXBException { + + String xml = "\n" + + "\n" + + " 2023-08-03T00:20:33.337\n" + + " RB\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " public\n" + + " dayOfTravelOnly\n" + + " beforeBoarding\n" + + " callOffice online\n" + + " 14:00:00\n" + + " PT2H\n" + + " \n" + + " +47 55551234\n" + + " https://booking.example.com\n" + + " \n" + + " Call to book\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + ""; + + Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); + + @SuppressWarnings("unchecked") + JAXBElement jaxbElement = (JAXBElement) unmarshaller + .unmarshal(new ByteArrayInputStream(xml.getBytes())); + + PublicationDeliveryStructure publicationDeliveryStructure = jaxbElement.getValue(); + CompositeFrame compositeFrame = (CompositeFrame) publicationDeliveryStructure.getDataObjects().getCompositeFrameOrCommonFrame().get(0).getValue(); + ServiceFrame serviceFrame = (ServiceFrame) compositeFrame.getFrames().getCommonFrame().get(0).getValue(); + + JourneyPattern journeyPattern = (JourneyPattern) serviceFrame.getJourneyPatterns().getJourneyPattern_OrJourneyPatternView().get(0).getValue(); + StopPointInJourneyPattern stopPoint = (StopPointInJourneyPattern) journeyPattern.getPointsInSequence() + .getPointInJourneyPatternOrStopPointInJourneyPatternOrTimingPointInJourneyPattern().get(0); + + BookingArrangementsStructure booking = stopPoint.getBookingArrangements(); + assertNotNull(booking); + assertEquals(BookingAccessEnumeration.PUBLIC, booking.getBookingAccess()); + assertEquals(PurchaseWhenEnumeration.DAY_OF_TRAVEL_ONLY, booking.getBookWhen()); + assertEquals(1, booking.getBuyWhen().size()); + assertEquals(PurchaseMomentEnumeration.BEFORE_BOARDING, booking.getBuyWhen().get(0)); + assertEquals(java.time.LocalTime.of(14, 0), booking.getLatestBookingTime()); + assertEquals(java.time.Duration.ofHours(2), booking.getMinimumBookingPeriod()); + assertEquals("+47 55551234", booking.getBookingContact().getPhone()); + assertEquals("https://booking.example.com", booking.getBookingContact().getUrl()); + assertEquals("Call to book", booking.getBookingNote().getValue()); + assertEquals(2, booking.getBookingMethods().size()); + assertEquals(BookingMethodEnumeration.CALL_OFFICE, booking.getBookingMethods().get(0)); + assertEquals(BookingMethodEnumeration.ONLINE, booking.getBookingMethods().get(1)); + } + + @Test + void unmarshalDestinationDisplayWithVias() throws JAXBException { + + String xml = "\n" + + "\n" + + " 2023-08-03T00:20:33.337\n" + + " RB\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " Bergen\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + ""; + + Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); + + @SuppressWarnings("unchecked") + JAXBElement jaxbElement = (JAXBElement) unmarshaller + .unmarshal(new ByteArrayInputStream(xml.getBytes())); + + PublicationDeliveryStructure publicationDeliveryStructure = jaxbElement.getValue(); + CompositeFrame compositeFrame = (CompositeFrame) publicationDeliveryStructure.getDataObjects().getCompositeFrameOrCommonFrame().get(0).getValue(); + ServiceFrame serviceFrame = (ServiceFrame) compositeFrame.getFrames().getCommonFrame().get(0).getValue(); + + DestinationDisplay dd = serviceFrame.getDestinationDisplays().getDestinationDisplay().get(0); + assertEquals("Bergen", dd.getFrontText().getValue()); + assertNotNull(dd.getVias()); + assertEquals(2, dd.getVias().getVia().size()); + + Via_VersionedChildStructure via1 = dd.getVias().getVia().get(0); + assertEquals("TST:DestinationDisplay:Via1", via1.getDestinationDisplayRef().getRef()); + Via_VersionedChildStructure via2 = dd.getVias().getVia().get(1); + assertEquals("TST:DestinationDisplay:Via2", via2.getDestinationDisplayRef().getRef()); + } + + @Test + void unmarshalDirectionAndRouteDirectionType() throws JAXBException { + + String xml = "\n" + + "\n" + + " 2023-08-03T00:20:33.337\n" + + " RB\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " Outbound\n" + + " outbound\n" + + " \n" + + " \n" + + " Inbound\n" + + " inbound\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " Main Route\n" + + " outbound\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + ""; + + Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); + + @SuppressWarnings("unchecked") + JAXBElement jaxbElement = (JAXBElement) unmarshaller + .unmarshal(new ByteArrayInputStream(xml.getBytes())); + + PublicationDeliveryStructure publicationDeliveryStructure = jaxbElement.getValue(); + CompositeFrame compositeFrame = (CompositeFrame) publicationDeliveryStructure.getDataObjects().getCompositeFrameOrCommonFrame().get(0).getValue(); + ServiceFrame serviceFrame = (ServiceFrame) compositeFrame.getFrames().getCommonFrame().get(0).getValue(); + + assertEquals(2, serviceFrame.getDirections().getDirection().size()); + Direction outbound = serviceFrame.getDirections().getDirection().get(0); + assertEquals("Outbound", outbound.getName().getValue()); + assertEquals(DirectionTypeEnumeration.OUTBOUND, outbound.getDirectionType()); + Direction inbound = serviceFrame.getDirections().getDirection().get(1); + assertEquals(DirectionTypeEnumeration.INBOUND, inbound.getDirectionType()); + + Route route = (Route) serviceFrame.getRoutes().getRoute_().get(0).getValue(); + assertEquals(DirectionTypeEnumeration.OUTBOUND, route.getDirectionType()); + assertEquals("TST:Direction:Outbound", route.getDirectionRef().getRef()); + assertEquals("TST:Route:2", route.getInverseRouteRef().getRef()); + } + + @Test + void unmarshalRoutePointWithProjection() throws JAXBException { + + String xml = "\n" + + "\n" + + " 2023-08-03T00:20:33.337\n" + + " RB\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " true\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + ""; + + Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); + + @SuppressWarnings("unchecked") + JAXBElement jaxbElement = (JAXBElement) unmarshaller + .unmarshal(new ByteArrayInputStream(xml.getBytes())); + + PublicationDeliveryStructure publicationDeliveryStructure = jaxbElement.getValue(); + CompositeFrame compositeFrame = (CompositeFrame) publicationDeliveryStructure.getDataObjects().getCompositeFrameOrCommonFrame().get(0).getValue(); + ServiceFrame serviceFrame = (ServiceFrame) compositeFrame.getFrames().getCommonFrame().get(0).getValue(); + + RoutePoint routePoint = serviceFrame.getRoutePoints().getRoutePoint().get(0); + assertTrue(routePoint.isBorderCrossing()); + + assertNotNull(routePoint.getProjections()); + PointProjection projection = (PointProjection) routePoint.getProjections().getProjectionRefOrProjection().get(0).getValue(); + assertEquals("TST:ScheduledStopPoint:1", projection.getProjectToPointRef().getRef()); + } + + @Test + void unmarshalScheduledStopPointWithTimingPointStatus() throws JAXBException { + + String xml = "\n" + + "\n" + + " 2023-08-03T00:20:33.337\n" + + " RB\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " Timing Stop\n" + + " timingPoint\n" + + " \n" + + " \n" + + " Non-Timing Stop\n" + + " notTimingPoint\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + ""; + + Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); + + @SuppressWarnings("unchecked") + JAXBElement jaxbElement = (JAXBElement) unmarshaller + .unmarshal(new ByteArrayInputStream(xml.getBytes())); + + PublicationDeliveryStructure publicationDeliveryStructure = jaxbElement.getValue(); + CompositeFrame compositeFrame = (CompositeFrame) publicationDeliveryStructure.getDataObjects().getCompositeFrameOrCommonFrame().get(0).getValue(); + ServiceFrame serviceFrame = (ServiceFrame) compositeFrame.getFrames().getCommonFrame().get(0).getValue(); + + ScheduledStopPoint ssp1 = serviceFrame.getScheduledStopPoints().getScheduledStopPoint().get(0); + assertEquals("Timing Stop", ssp1.getName().getValue()); + assertEquals(TimingPointStatusEnumeration.TIMING_POINT, ssp1.getTimingPointStatus()); + + ScheduledStopPoint ssp2 = serviceFrame.getScheduledStopPoints().getScheduledStopPoint().get(1); + assertEquals(TimingPointStatusEnumeration.NOT_TIMING_POINT, ssp2.getTimingPointStatus()); + } + + @Test + void unmarshalLinePresentationAndPrivateCode() throws JAXBException { + + String xml = "\n" + + "\n" + + " 2023-08-03T00:20:33.337\n" + + " RB\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " Line One\n" + + " bus\n" + + " PRIV001\n" + + " \n" + + " 0054A6\n" + + " FFFFFF\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + ""; + + Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); + + @SuppressWarnings("unchecked") + JAXBElement jaxbElement = (JAXBElement) unmarshaller + .unmarshal(new ByteArrayInputStream(xml.getBytes())); + + PublicationDeliveryStructure publicationDeliveryStructure = jaxbElement.getValue(); + CompositeFrame compositeFrame = (CompositeFrame) publicationDeliveryStructure.getDataObjects().getCompositeFrameOrCommonFrame().get(0).getValue(); + ServiceFrame serviceFrame = (ServiceFrame) compositeFrame.getFrames().getCommonFrame().get(0).getValue(); + + Line line = (Line) serviceFrame.getLines().getLine_().get(0).getValue(); + assertEquals("Line One", line.getName().getValue()); + assertEquals("PRIV001", line.getPrivateCode().getValue()); + + PresentationStructure presentation = line.getPresentation(); + assertNotNull(presentation); + assertNotNull(presentation.getColour()); + assertNotNull(presentation.getTextColour()); + } + + @Test + void unmarshalNoticeWithAlternativeTexts() throws JAXBException { + + String xml = "\n" + + "\n" + + " 2023-08-03T00:20:33.337\n" + + " RB\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " Stopper ikke alle holdeplasser\n" + + " A\n" + + " \n" + + " \n" + + " Does not stop at all stops\n" + + " \n" + + " \n" + + " Stannar inte vid alla hallplatser\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + ""; + + Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); + + @SuppressWarnings("unchecked") + JAXBElement jaxbElement = (JAXBElement) unmarshaller + .unmarshal(new ByteArrayInputStream(xml.getBytes())); + + PublicationDeliveryStructure publicationDeliveryStructure = jaxbElement.getValue(); + CompositeFrame compositeFrame = (CompositeFrame) publicationDeliveryStructure.getDataObjects().getCompositeFrameOrCommonFrame().get(0).getValue(); + ServiceFrame serviceFrame = (ServiceFrame) compositeFrame.getFrames().getCommonFrame().get(0).getValue(); + + Notice notice = serviceFrame.getNotices().getNotice().get(0); + assertEquals("Stopper ikke alle holdeplasser", notice.getText().getValue()); + assertEquals("no", notice.getText().getLang()); + + assertNotNull(notice.getAlternativeTexts()); + assertEquals(2, notice.getAlternativeTexts().getAlternativeText().size()); + + AlternativeText alt1 = notice.getAlternativeTexts().getAlternativeText().get(0); + assertEquals("Does not stop at all stops", alt1.getText().getValue()); + assertEquals("en", alt1.getText().getLang()); + + AlternativeText alt2 = notice.getAlternativeTexts().getAlternativeText().get(1); + assertEquals("Stannar inte vid alla hallplatser", alt2.getText().getValue()); + assertEquals("sv", alt2.getText().getLang()); + } + + @Test + void unmarshalServiceLinkWithLinkSequenceProjection() throws JAXBException { + + String xml = "\n" + + "\n" + + " 2023-08-03T00:20:33.337\n" + + " RB\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " 59.91 10.75 59.92 10.76\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + ""; + + Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); + + @SuppressWarnings("unchecked") + JAXBElement jaxbElement = (JAXBElement) unmarshaller + .unmarshal(new ByteArrayInputStream(xml.getBytes())); + + PublicationDeliveryStructure publicationDeliveryStructure = jaxbElement.getValue(); + CompositeFrame compositeFrame = (CompositeFrame) publicationDeliveryStructure.getDataObjects().getCompositeFrameOrCommonFrame().get(0).getValue(); + ServiceFrame serviceFrame = (ServiceFrame) compositeFrame.getFrames().getCommonFrame().get(0).getValue(); + + ServiceLink serviceLink = serviceFrame.getServiceLinks().getServiceLink().get(0); + assertEquals("TST:ScheduledStopPoint:1", serviceLink.getFromPointRef().getRef()); + assertEquals("TST:ScheduledStopPoint:2", serviceLink.getToPointRef().getRef()); + + assertNotNull(serviceLink.getProjections()); + LinkSequenceProjection_VersionStructure projection = (LinkSequenceProjection_VersionStructure) + serviceLink.getProjections().getProjectionRefOrProjection().get(0).getValue(); + assertNotNull(projection.getLineString()); + } + + @Test + void unmarshalCodespace() throws JAXBException { + + String xml = "\n" + + "\n" + + " 2023-08-03T00:20:33.337\n" + + " RB\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " TST\n" + + " http://www.rutebanken.org/ns/tst\n" + + " \n" + + " \n" + + " NSR\n" + + " http://www.rutebanken.org/ns/nsr\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + ""; + + Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); + + @SuppressWarnings("unchecked") + JAXBElement jaxbElement = (JAXBElement) unmarshaller + .unmarshal(new ByteArrayInputStream(xml.getBytes())); + + PublicationDeliveryStructure publicationDeliveryStructure = jaxbElement.getValue(); + CompositeFrame compositeFrame = (CompositeFrame) publicationDeliveryStructure.getDataObjects().getCompositeFrameOrCommonFrame().get(0).getValue(); + + assertEquals(2, compositeFrame.getCodespaces().getCodespaceRefOrCodespace().size()); + Codespace codespace1 = (Codespace) compositeFrame.getCodespaces().getCodespaceRefOrCodespace().get(0); + assertEquals("TST", codespace1.getXmlns()); + assertEquals("http://www.rutebanken.org/ns/tst", codespace1.getXmlnsUrl()); + + Codespace codespace2 = (Codespace) compositeFrame.getCodespaces().getCodespaceRefOrCodespace().get(1); + assertEquals("NSR", codespace2.getXmlns()); + assertEquals("http://www.rutebanken.org/ns/nsr", codespace2.getXmlnsUrl()); + } +} diff --git a/src/test/java/org/rutebanken/netex/model/UnmarshalServiceFrameExtendedTest.java b/src/test/java/org/rutebanken/netex/model/UnmarshalServiceFrameExtendedTest.java new file mode 100644 index 0000000..26dba19 --- /dev/null +++ b/src/test/java/org/rutebanken/netex/model/UnmarshalServiceFrameExtendedTest.java @@ -0,0 +1,266 @@ +/* + * 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 org.rutebanken.netex.model; + +import jakarta.xml.bind.JAXBElement; +import jakarta.xml.bind.JAXBException; +import jakarta.xml.bind.Unmarshaller; +import org.junit.jupiter.api.Test; + +import java.io.ByteArrayInputStream; +import java.math.BigDecimal; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +class UnmarshalServiceFrameExtendedTest extends AbstractUnmarshalFrameTest { + + @Test + void unmarshalNetworkWithAuthorityRef() throws JAXBException { + + String xml = "\n" + + "\n" + + " 2023-08-03T00:20:33.337\n" + + " RB\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " Test Network\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + ""; + + Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); + + @SuppressWarnings("unchecked") + JAXBElement jaxbElement = (JAXBElement) unmarshaller + .unmarshal(new ByteArrayInputStream(xml.getBytes())); + + PublicationDeliveryStructure publicationDeliveryStructure = jaxbElement.getValue(); + CompositeFrame compositeFrame = (CompositeFrame) publicationDeliveryStructure.getDataObjects().getCompositeFrameOrCommonFrame().get(0).getValue(); + + ServiceFrame serviceFrame = (ServiceFrame) compositeFrame.getFrames().getCommonFrame().get(0).getValue(); + Network network = serviceFrame.getNetwork(); + assertNotNull(network); + assertEquals("Test Network", network.getName().getValue()); + assertEquals("TST:Authority:1", network.getTransportOrganisationRef().getValue().getRef()); + } + + @Test + void unmarshalDestinationDisplayAndScheduledStopPoint() throws JAXBException { + + String xml = "\n" + + "\n" + + " 2023-08-03T00:20:33.337\n" + + " RB\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " Oslo S\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " Jernbanetorget\n" + + " \n" + + " \n" + + " Majorstuen\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + ""; + + Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); + + @SuppressWarnings("unchecked") + JAXBElement jaxbElement = (JAXBElement) unmarshaller + .unmarshal(new ByteArrayInputStream(xml.getBytes())); + + PublicationDeliveryStructure publicationDeliveryStructure = jaxbElement.getValue(); + CompositeFrame compositeFrame = (CompositeFrame) publicationDeliveryStructure.getDataObjects().getCompositeFrameOrCommonFrame().get(0).getValue(); + + ServiceFrame serviceFrame = (ServiceFrame) compositeFrame.getFrames().getCommonFrame().get(0).getValue(); + + DestinationDisplay destinationDisplay = serviceFrame.getDestinationDisplays().getDestinationDisplay().get(0); + assertEquals("Oslo S", destinationDisplay.getFrontText().getValue()); + + assertEquals(2, serviceFrame.getScheduledStopPoints().getScheduledStopPoint().size()); + ScheduledStopPoint ssp1 = serviceFrame.getScheduledStopPoints().getScheduledStopPoint().get(0); + assertEquals("Jernbanetorget", ssp1.getName().getValue()); + ScheduledStopPoint ssp2 = serviceFrame.getScheduledStopPoints().getScheduledStopPoint().get(1); + assertEquals("Majorstuen", ssp2.getName().getValue()); + } + + @Test + void unmarshalServiceLink() throws JAXBException { + + String xml = "\n" + + "\n" + + " 2023-08-03T00:20:33.337\n" + + " RB\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " 1234.5\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + ""; + + Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); + + @SuppressWarnings("unchecked") + JAXBElement jaxbElement = (JAXBElement) unmarshaller + .unmarshal(new ByteArrayInputStream(xml.getBytes())); + + PublicationDeliveryStructure publicationDeliveryStructure = jaxbElement.getValue(); + CompositeFrame compositeFrame = (CompositeFrame) publicationDeliveryStructure.getDataObjects().getCompositeFrameOrCommonFrame().get(0).getValue(); + + ServiceFrame serviceFrame = (ServiceFrame) compositeFrame.getFrames().getCommonFrame().get(0).getValue(); + + assertEquals(1, serviceFrame.getServiceLinks().getServiceLink().size()); + ServiceLink serviceLink = serviceFrame.getServiceLinks().getServiceLink().get(0); + assertEquals("TST:ScheduledStopPoint:1", serviceLink.getFromPointRef().getRef()); + assertEquals("TST:ScheduledStopPoint:2", serviceLink.getToPointRef().getRef()); + assertEquals(new BigDecimal("1234.5"), serviceLink.getDistance()); + } + + @Test + void unmarshalFlexibleLineAndGroupOfLines() throws JAXBException { + + String xml = "\n" + + "\n" + + " 2023-08-03T00:20:33.337\n" + + " RB\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " Flex Route 1\n" + + " bus\n" + + " flexibleAreasOnly\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " Line Group A\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + ""; + + Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); + + @SuppressWarnings("unchecked") + JAXBElement jaxbElement = (JAXBElement) unmarshaller + .unmarshal(new ByteArrayInputStream(xml.getBytes())); + + PublicationDeliveryStructure publicationDeliveryStructure = jaxbElement.getValue(); + CompositeFrame compositeFrame = (CompositeFrame) publicationDeliveryStructure.getDataObjects().getCompositeFrameOrCommonFrame().get(0).getValue(); + + ServiceFrame serviceFrame = (ServiceFrame) compositeFrame.getFrames().getCommonFrame().get(0).getValue(); + + FlexibleLine flexibleLine = (FlexibleLine) serviceFrame.getLines().getLine_().get(0).getValue(); + assertEquals("Flex Route 1", flexibleLine.getName().getValue()); + assertEquals(AllVehicleModesOfTransportEnumeration.BUS, flexibleLine.getTransportMode()); + assertEquals(FlexibleLineTypeEnumeration.FLEXIBLE_AREAS_ONLY, flexibleLine.getFlexibleLineType()); + + GroupOfLines groupOfLines = serviceFrame.getGroupsOfLines().getGroupOfLines().get(0); + assertEquals("Line Group A", groupOfLines.getName().getValue()); + assertEquals(2, groupOfLines.getMembers().getLineRef().size()); + assertEquals("TST:Line:1", groupOfLines.getMembers().getLineRef().get(0).getValue().getRef()); + assertEquals("TST:Line:2", groupOfLines.getMembers().getLineRef().get(1).getValue().getRef()); + } + + @Test + void unmarshalNoticeAndNoticeAssignment() throws JAXBException { + + String xml = "\n" + + "\n" + + " 2023-08-03T00:20:33.337\n" + + " RB\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " Does not stop at all stops\n" + + " A\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + ""; + + Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); + + @SuppressWarnings("unchecked") + JAXBElement jaxbElement = (JAXBElement) unmarshaller + .unmarshal(new ByteArrayInputStream(xml.getBytes())); + + PublicationDeliveryStructure publicationDeliveryStructure = jaxbElement.getValue(); + CompositeFrame compositeFrame = (CompositeFrame) publicationDeliveryStructure.getDataObjects().getCompositeFrameOrCommonFrame().get(0).getValue(); + + ServiceFrame serviceFrame = (ServiceFrame) compositeFrame.getFrames().getCommonFrame().get(0).getValue(); + + assertEquals(1, serviceFrame.getNotices().getNotice().size()); + Notice notice = serviceFrame.getNotices().getNotice().get(0); + assertEquals("Does not stop at all stops", notice.getText().getValue()); + assertEquals("A", notice.getPublicCode()); + + NoticeAssignment noticeAssignment = (NoticeAssignment) serviceFrame.getNoticeAssignments().getNoticeAssignment_().get(0).getValue(); + assertEquals("TST:Notice:1", noticeAssignment.getNoticeRef().getRef()); + assertEquals("TST:ServiceJourney:1", noticeAssignment.getNoticedObjectRef().getRef()); + } +} diff --git a/src/test/java/org/rutebanken/netex/model/UnmarshalSiteFrameChouetteTest.java b/src/test/java/org/rutebanken/netex/model/UnmarshalSiteFrameChouetteTest.java new file mode 100644 index 0000000..ee52978 --- /dev/null +++ b/src/test/java/org/rutebanken/netex/model/UnmarshalSiteFrameChouetteTest.java @@ -0,0 +1,67 @@ +/* + * 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 org.rutebanken.netex.model; + +import jakarta.xml.bind.JAXBElement; +import jakarta.xml.bind.JAXBException; +import jakarta.xml.bind.Unmarshaller; +import org.junit.jupiter.api.Test; + +import java.io.ByteArrayInputStream; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +class UnmarshalSiteFrameChouetteTest extends AbstractUnmarshalFrameTest { + + @Test + void unmarshalStopPlaceWithDescriptionAndLandmark() throws JAXBException { + + String xml = "" + + "" + + " 2016-05-18T15:00:00.0+01:00" + + " NHR" + + " " + + " " + + " " + + " " + + " Oslo S" + + " Main train station" + + " Central Station Clock Tower" + + " rail" + + " OSL001" + + " " + + " " + + " " + + " " + + ""; + + Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); + + @SuppressWarnings("unchecked") + JAXBElement jaxbElement = (JAXBElement) unmarshaller + .unmarshal(new ByteArrayInputStream(xml.getBytes())); + + PublicationDeliveryStructure publicationDeliveryStructure = jaxbElement.getValue(); + SiteFrame siteFrame = (SiteFrame) publicationDeliveryStructure.getDataObjects().getCompositeFrameOrCommonFrame().get(0).getValue(); + + StopPlace stopPlace = (StopPlace) siteFrame.getStopPlaces().getStopPlace_().get(0).getValue(); + assertEquals("Oslo S", stopPlace.getName().getValue()); + assertEquals("Main train station", stopPlace.getDescription().getValue()); + assertEquals("Central Station Clock Tower", stopPlace.getLandmark().getValue()); + assertEquals(AllVehicleModesOfTransportEnumeration.RAIL, stopPlace.getTransportMode()); + assertEquals("OSL001", stopPlace.getPrivateCode().getValue()); + } +} diff --git a/src/test/java/org/rutebanken/netex/model/UnmarshalSiteFrameExtendedTest.java b/src/test/java/org/rutebanken/netex/model/UnmarshalSiteFrameExtendedTest.java new file mode 100644 index 0000000..66a4692 --- /dev/null +++ b/src/test/java/org/rutebanken/netex/model/UnmarshalSiteFrameExtendedTest.java @@ -0,0 +1,147 @@ +/* + * 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 org.rutebanken.netex.model; + +import jakarta.xml.bind.JAXBElement; +import jakarta.xml.bind.JAXBException; +import jakarta.xml.bind.Unmarshaller; +import org.junit.jupiter.api.Test; + +import java.io.ByteArrayInputStream; +import java.math.BigInteger; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +class UnmarshalSiteFrameExtendedTest extends AbstractUnmarshalFrameTest { + + @Test + void unmarshalStopPlaceWithAccessibilityAssessment() throws JAXBException { + + String xml = "" + + "" + + " 2016-05-18T15:00:00.0+01:00" + + " NHR" + + " " + + " " + + " " + + " " + + " Accessible Stop" + + " bus" + + " " + + " true" + + " " + + " " + + " true" + + " true" + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + ""; + + Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); + + @SuppressWarnings("unchecked") + JAXBElement jaxbElement = (JAXBElement) unmarshaller + .unmarshal(new ByteArrayInputStream(xml.getBytes())); + + PublicationDeliveryStructure publicationDeliveryStructure = jaxbElement.getValue(); + SiteFrame siteFrame = (SiteFrame) publicationDeliveryStructure.getDataObjects().getCompositeFrameOrCommonFrame().get(0).getValue(); + + StopPlace stopPlace = (StopPlace) siteFrame.getStopPlaces().getStopPlace_().get(0).getValue(); + assertEquals("Accessible Stop", stopPlace.getName().getValue()); + + AccessibilityAssessment assessment = stopPlace.getAccessibilityAssessment(); + assertNotNull(assessment); + assertEquals(LimitationStatusEnumeration.TRUE, assessment.getMobilityImpairedAccess()); + + AccessibilityLimitation limitation = assessment.getLimitations().getAccessibilityLimitation(); + assertEquals(LimitationStatusEnumeration.TRUE, limitation.getWheelchairAccess()); + assertEquals(LimitationStatusEnumeration.TRUE, limitation.getStepFreeAccess()); + } + + @Test + void unmarshalFlexibleStopPlace() throws JAXBException { + + String xml = "" + + "" + + " 2016-05-18T15:00:00.0+01:00" + + " NHR" + + " " + + " " + + " " + + " " + + " Flexible Area North" + + " bus" + + " " + + " " + + " " + + " " + + ""; + + Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); + + @SuppressWarnings("unchecked") + JAXBElement jaxbElement = (JAXBElement) unmarshaller + .unmarshal(new ByteArrayInputStream(xml.getBytes())); + + PublicationDeliveryStructure publicationDeliveryStructure = jaxbElement.getValue(); + SiteFrame siteFrame = (SiteFrame) publicationDeliveryStructure.getDataObjects().getCompositeFrameOrCommonFrame().get(0).getValue(); + + FlexibleStopPlace flexibleStopPlace = siteFrame.getFlexibleStopPlaces().getFlexibleStopPlace().get(0); + assertEquals("Flexible Area North", flexibleStopPlace.getName().getValue()); + assertEquals(AllVehicleModesOfTransportEnumeration.BUS, flexibleStopPlace.getTransportMode()); + } + + @Test + void unmarshalParking() throws JAXBException { + + String xml = "" + + "" + + " 2016-05-18T15:00:00.0+01:00" + + " NHR" + + " " + + " " + + " " + + " " + + " Central Parking" + + " parkAndRide" + + " 250" + + " " + + " " + + " " + + " " + + ""; + + Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); + + @SuppressWarnings("unchecked") + JAXBElement jaxbElement = (JAXBElement) unmarshaller + .unmarshal(new ByteArrayInputStream(xml.getBytes())); + + PublicationDeliveryStructure publicationDeliveryStructure = jaxbElement.getValue(); + SiteFrame siteFrame = (SiteFrame) publicationDeliveryStructure.getDataObjects().getCompositeFrameOrCommonFrame().get(0).getValue(); + + Parking parking = siteFrame.getParkings().getParking().get(0); + assertEquals("Central Parking", parking.getName().getValue()); + assertEquals(ParkingTypeEnumeration.PARK_AND_RIDE, parking.getParkingType()); + assertEquals(BigInteger.valueOf(250), parking.getTotalCapacity()); + } +} diff --git a/src/test/java/org/rutebanken/netex/model/UnmarshalTimetableFrameChouetteTest.java b/src/test/java/org/rutebanken/netex/model/UnmarshalTimetableFrameChouetteTest.java new file mode 100644 index 0000000..45d1c66 --- /dev/null +++ b/src/test/java/org/rutebanken/netex/model/UnmarshalTimetableFrameChouetteTest.java @@ -0,0 +1,157 @@ +/* + * 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 org.rutebanken.netex.model; + +import jakarta.xml.bind.JAXBElement; +import jakarta.xml.bind.JAXBException; +import jakarta.xml.bind.Unmarshaller; +import org.junit.jupiter.api.Test; + +import java.io.ByteArrayInputStream; +import java.time.LocalTime; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +class UnmarshalTimetableFrameChouetteTest extends AbstractUnmarshalFrameTest { + + @Test + void unmarshalDeadRun() throws JAXBException { + + String xml = "\n" + + "\n" + + " 2023-08-03T00:20:33.337\n" + + " RB\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " Dead Run to Depot\n" + + " bus\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " 23:30:00\n" + + " \n" + + " \n" + + " 23:55:00\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + ""; + + Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); + + @SuppressWarnings("unchecked") + JAXBElement jaxbElement = (JAXBElement) unmarshaller + .unmarshal(new ByteArrayInputStream(xml.getBytes())); + + PublicationDeliveryStructure publicationDeliveryStructure = jaxbElement.getValue(); + CompositeFrame compositeFrame = (CompositeFrame) publicationDeliveryStructure.getDataObjects().getCompositeFrameOrCommonFrame().get(0).getValue(); + TimetableFrame timetableFrame = (TimetableFrame) compositeFrame.getFrames().getCommonFrame().get(0).getValue(); + + DeadRun deadRun = (DeadRun) timetableFrame.getVehicleJourneys() + .getVehicleJourneyOrDatedVehicleJourneyOrNormalDatedVehicleJourney().get(0); + assertEquals("Dead Run to Depot", deadRun.getName().getValue()); + assertEquals(AllVehicleModesOfTransportEnumeration.BUS, deadRun.getTransportMode()); + + assertNotNull(deadRun.getDayTypes()); + assertEquals("TST:DayType:Weekday", deadRun.getDayTypes().getDayTypeRef().get(0).getValue().getRef()); + + assertEquals("TST:JourneyPattern:DR1", deadRun.getJourneyPatternRef().getValue().getRef()); + + assertNotNull(deadRun.getPassingTimes()); + assertEquals(2, deadRun.getPassingTimes().getTimetabledPassingTime().size()); + assertEquals(LocalTime.of(23, 30), deadRun.getPassingTimes().getTimetabledPassingTime().get(0).getDepartureTime()); + assertEquals(LocalTime.of(23, 55), deadRun.getPassingTimes().getTimetabledPassingTime().get(1).getArrivalTime()); + } + + @Test + void unmarshalFlexibleServicePropertiesExtended() throws JAXBException { + + String xml = "\n" + + "\n" + + " 2023-08-03T00:20:33.337\n" + + " RB\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " Flex Extended\n" + + " bus\n" + + " \n" + + " dynamicPassingTimes\n" + + " true\n" + + " false\n" + + " public\n" + + " untilPreviousDay\n" + + " beforeBoarding onBoarding\n" + + " Advanced booking required\n" + + " \n" + + " +47 99998888\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + ""; + + Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); + + @SuppressWarnings("unchecked") + JAXBElement jaxbElement = (JAXBElement) unmarshaller + .unmarshal(new ByteArrayInputStream(xml.getBytes())); + + PublicationDeliveryStructure publicationDeliveryStructure = jaxbElement.getValue(); + CompositeFrame compositeFrame = (CompositeFrame) publicationDeliveryStructure.getDataObjects().getCompositeFrameOrCommonFrame().get(0).getValue(); + TimetableFrame timetableFrame = (TimetableFrame) compositeFrame.getFrames().getCommonFrame().get(0).getValue(); + + ServiceJourney sj = (ServiceJourney) timetableFrame.getVehicleJourneys() + .getVehicleJourneyOrDatedVehicleJourneyOrNormalDatedVehicleJourney().get(0); + + FlexibleServiceProperties fsp = sj.getFlexibleServiceProperties(); + assertNotNull(fsp); + assertEquals(FlexibleServiceEnumeration.DYNAMIC_PASSING_TIMES, fsp.getFlexibleServiceType()); + assertTrue(fsp.isCancellationPossible()); + assertFalse(fsp.isChangeOfTimePossible()); + assertEquals(BookingAccessEnumeration.PUBLIC, fsp.getBookingAccess()); + assertEquals(PurchaseWhenEnumeration.UNTIL_PREVIOUS_DAY, fsp.getBookWhen()); + + assertEquals(2, fsp.getBuyWhen().size()); + assertEquals(PurchaseMomentEnumeration.BEFORE_BOARDING, fsp.getBuyWhen().get(0)); + assertEquals(PurchaseMomentEnumeration.ON_BOARDING, fsp.getBuyWhen().get(1)); + + assertEquals("Advanced booking required", fsp.getBookingNote().getValue()); + assertEquals("+47 99998888", fsp.getBookingContact().getPhone()); + } +} diff --git a/src/test/java/org/rutebanken/netex/model/UnmarshalTimetableFrameExtendedTest.java b/src/test/java/org/rutebanken/netex/model/UnmarshalTimetableFrameExtendedTest.java new file mode 100644 index 0000000..b1fe8ac --- /dev/null +++ b/src/test/java/org/rutebanken/netex/model/UnmarshalTimetableFrameExtendedTest.java @@ -0,0 +1,136 @@ +/* + * 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 org.rutebanken.netex.model; + +import jakarta.xml.bind.JAXBElement; +import jakarta.xml.bind.JAXBException; +import jakarta.xml.bind.Unmarshaller; +import org.junit.jupiter.api.Test; + +import java.io.ByteArrayInputStream; +import java.time.Duration; +import java.time.LocalTime; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +class UnmarshalTimetableFrameExtendedTest extends AbstractUnmarshalFrameTest { + + @Test + void unmarshalServiceJourneyInterchange() throws JAXBException { + + String xml = "\n" + + "\n" + + " 2023-08-03T00:20:33.337\n" + + " RB\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " true\n" + + " true\n" + + " PT5M\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + ""; + + Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); + + @SuppressWarnings("unchecked") + JAXBElement jaxbElement = (JAXBElement) unmarshaller + .unmarshal(new ByteArrayInputStream(xml.getBytes())); + + PublicationDeliveryStructure publicationDeliveryStructure = jaxbElement.getValue(); + CompositeFrame compositeFrame = (CompositeFrame) publicationDeliveryStructure.getDataObjects().getCompositeFrameOrCommonFrame().get(0).getValue(); + + TimetableFrame timetableFrame = (TimetableFrame) compositeFrame.getFrames().getCommonFrame().get(0).getValue(); + + ServiceJourneyInterchange interchange = (ServiceJourneyInterchange) timetableFrame.getJourneyInterchanges() + .getServiceJourneyPatternInterchangeOrServiceJourneyInterchange().get(0); + assertEquals("TST:ScheduledStopPoint:1", interchange.getFromPointRef().getRef()); + assertEquals("TST:ScheduledStopPoint:2", interchange.getToPointRef().getRef()); + assertEquals("TST:ServiceJourney:1", interchange.getFromJourneyRef().getRef()); + assertEquals("TST:ServiceJourney:2", interchange.getToJourneyRef().getRef()); + assertTrue(interchange.isStaySeated()); + assertTrue(interchange.isGuaranteed()); + assertEquals(Duration.ofMinutes(5), interchange.getMaximumWaitTime()); + } + + @Test + void unmarshalServiceJourneyWithFlexibleServiceProperties() throws JAXBException { + + String xml = "\n" + + "\n" + + " 2023-08-03T00:20:33.337\n" + + " RB\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " Flex Service\n" + + " bus\n" + + " \n" + + " public\n" + + " dayOfTravelOnly\n" + + " 12:00:00\n" + + " \n" + + " +47 12345678\n" + + " https://booking.example.com\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + ""; + + Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); + + @SuppressWarnings("unchecked") + JAXBElement jaxbElement = (JAXBElement) unmarshaller + .unmarshal(new ByteArrayInputStream(xml.getBytes())); + + PublicationDeliveryStructure publicationDeliveryStructure = jaxbElement.getValue(); + CompositeFrame compositeFrame = (CompositeFrame) publicationDeliveryStructure.getDataObjects().getCompositeFrameOrCommonFrame().get(0).getValue(); + + TimetableFrame timetableFrame = (TimetableFrame) compositeFrame.getFrames().getCommonFrame().get(0).getValue(); + + ServiceJourney serviceJourney = (ServiceJourney) timetableFrame.getVehicleJourneys() + .getVehicleJourneyOrDatedVehicleJourneyOrNormalDatedVehicleJourney().get(0); + assertEquals("Flex Service", serviceJourney.getName().getValue()); + + FlexibleServiceProperties flexProps = serviceJourney.getFlexibleServiceProperties(); + assertEquals(BookingAccessEnumeration.PUBLIC, flexProps.getBookingAccess()); + assertEquals(PurchaseWhenEnumeration.DAY_OF_TRAVEL_ONLY, flexProps.getBookWhen()); + assertEquals(LocalTime.of(12, 0), flexProps.getLatestBookingTime()); + assertEquals("+47 12345678", flexProps.getBookingContact().getPhone()); + assertEquals("https://booking.example.com", flexProps.getBookingContact().getUrl()); + } +} diff --git a/src/test/java/org/rutebanken/netex/model/UnmarshalTransportSubModeTest.java b/src/test/java/org/rutebanken/netex/model/UnmarshalTransportSubModeTest.java new file mode 100644 index 0000000..fc03670 --- /dev/null +++ b/src/test/java/org/rutebanken/netex/model/UnmarshalTransportSubModeTest.java @@ -0,0 +1,285 @@ +/* + * 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 org.rutebanken.netex.model; + +import jakarta.xml.bind.JAXBElement; +import jakarta.xml.bind.JAXBException; +import jakarta.xml.bind.Unmarshaller; +import org.junit.jupiter.api.Test; + +import java.io.ByteArrayInputStream; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +class UnmarshalTransportSubModeTest extends AbstractUnmarshalFrameTest { + + @Test + void unmarshalStopPlaceWithBusSubmode() throws JAXBException { + + String xml = "" + + "" + + " 2016-05-18T15:00:00.0+01:00" + + " NHR" + + " " + + " " + + " " + + " " + + " Bus Stop" + + " bus" + + " expressBus" + + " " + + " " + + " Rail Station" + + " rail" + + " regionalRail" + + " " + + " " + + " Ferry Terminal" + + " water" + + " localCarFerry" + + " " + + " " + + " Tram Stop" + + " tram" + + " cityTram" + + " " + + " " + + " Metro Station" + + " metro" + + " metro" + + " " + + " " + + " " + + " " + + ""; + + Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); + + @SuppressWarnings("unchecked") + JAXBElement jaxbElement = (JAXBElement) unmarshaller + .unmarshal(new ByteArrayInputStream(xml.getBytes())); + + PublicationDeliveryStructure publicationDeliveryStructure = jaxbElement.getValue(); + SiteFrame siteFrame = (SiteFrame) publicationDeliveryStructure.getDataObjects().getCompositeFrameOrCommonFrame().get(0).getValue(); + + StopPlace busStop = (StopPlace) siteFrame.getStopPlaces().getStopPlace_().get(0).getValue(); + assertEquals(AllVehicleModesOfTransportEnumeration.BUS, busStop.getTransportMode()); + assertEquals(BusSubmodeEnumeration.EXPRESS_BUS, busStop.getBusSubmode()); + assertEquals("expressBus", busStop.getBusSubmode().value()); + + StopPlace railStop = (StopPlace) siteFrame.getStopPlaces().getStopPlace_().get(1).getValue(); + assertEquals(AllVehicleModesOfTransportEnumeration.RAIL, railStop.getTransportMode()); + assertEquals(RailSubmodeEnumeration.REGIONAL_RAIL, railStop.getRailSubmode()); + assertEquals("regionalRail", railStop.getRailSubmode().value()); + + StopPlace waterStop = (StopPlace) siteFrame.getStopPlaces().getStopPlace_().get(2).getValue(); + assertEquals(AllVehicleModesOfTransportEnumeration.WATER, waterStop.getTransportMode()); + assertEquals(WaterSubmodeEnumeration.LOCAL_CAR_FERRY, waterStop.getWaterSubmode()); + assertEquals("localCarFerry", waterStop.getWaterSubmode().value()); + + StopPlace tramStop = (StopPlace) siteFrame.getStopPlaces().getStopPlace_().get(3).getValue(); + assertEquals(AllVehicleModesOfTransportEnumeration.TRAM, tramStop.getTransportMode()); + assertEquals(TramSubmodeEnumeration.CITY_TRAM, tramStop.getTramSubmode()); + assertEquals("cityTram", tramStop.getTramSubmode().value()); + + StopPlace metroStop = (StopPlace) siteFrame.getStopPlaces().getStopPlace_().get(4).getValue(); + assertEquals(AllVehicleModesOfTransportEnumeration.METRO, metroStop.getTransportMode()); + assertEquals(MetroSubmodeEnumeration.METRO, metroStop.getMetroSubmode()); + assertEquals("metro", metroStop.getMetroSubmode().value()); + } + + @Test + void unmarshalServiceJourneyWithTransportSubmode() throws JAXBException { + + String xml = "\n" + + "\n" + + " 2023-08-03T00:20:33.337\n" + + " RB\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " Express Bus 100\n" + + " bus\n" + + " \n" + + " expressBus\n" + + " \n" + + " \n" + + " \n" + + " Regional Rail 200\n" + + " rail\n" + + " \n" + + " regionalRail\n" + + " \n" + + " \n" + + " \n" + + " Local Ferry\n" + + " water\n" + + " \n" + + " localPassengerFerry\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + ""; + + Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); + + @SuppressWarnings("unchecked") + JAXBElement jaxbElement = (JAXBElement) unmarshaller + .unmarshal(new ByteArrayInputStream(xml.getBytes())); + + PublicationDeliveryStructure publicationDeliveryStructure = jaxbElement.getValue(); + CompositeFrame compositeFrame = (CompositeFrame) publicationDeliveryStructure.getDataObjects().getCompositeFrameOrCommonFrame().get(0).getValue(); + TimetableFrame timetableFrame = (TimetableFrame) compositeFrame.getFrames().getCommonFrame().get(0).getValue(); + + ServiceJourney busSj = (ServiceJourney) timetableFrame.getVehicleJourneys() + .getVehicleJourneyOrDatedVehicleJourneyOrNormalDatedVehicleJourney().get(0); + assertEquals(AllVehicleModesOfTransportEnumeration.BUS, busSj.getTransportMode()); + assertNotNull(busSj.getTransportSubmode()); + assertEquals(BusSubmodeEnumeration.EXPRESS_BUS, busSj.getTransportSubmode().getBusSubmode()); + assertEquals("expressBus", busSj.getTransportSubmode().getBusSubmode().value()); + + ServiceJourney railSj = (ServiceJourney) timetableFrame.getVehicleJourneys() + .getVehicleJourneyOrDatedVehicleJourneyOrNormalDatedVehicleJourney().get(1); + assertEquals(AllVehicleModesOfTransportEnumeration.RAIL, railSj.getTransportMode()); + assertNotNull(railSj.getTransportSubmode()); + assertEquals(RailSubmodeEnumeration.REGIONAL_RAIL, railSj.getTransportSubmode().getRailSubmode()); + assertEquals("regionalRail", railSj.getTransportSubmode().getRailSubmode().value()); + + ServiceJourney waterSj = (ServiceJourney) timetableFrame.getVehicleJourneys() + .getVehicleJourneyOrDatedVehicleJourneyOrNormalDatedVehicleJourney().get(2); + assertEquals(AllVehicleModesOfTransportEnumeration.WATER, waterSj.getTransportMode()); + assertNotNull(waterSj.getTransportSubmode()); + assertEquals(WaterSubmodeEnumeration.LOCAL_PASSENGER_FERRY, waterSj.getTransportSubmode().getWaterSubmode()); + assertEquals("localPassengerFerry", waterSj.getTransportSubmode().getWaterSubmode().value()); + } + + @Test + void unmarshalRouteWithLineRef() throws JAXBException { + + String xml = "\n" + + "\n" + + " 2023-08-03T00:20:33.337\n" + + " RB\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " Main Route\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + ""; + + Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); + + @SuppressWarnings("unchecked") + JAXBElement jaxbElement = (JAXBElement) unmarshaller + .unmarshal(new ByteArrayInputStream(xml.getBytes())); + + PublicationDeliveryStructure publicationDeliveryStructure = jaxbElement.getValue(); + CompositeFrame compositeFrame = (CompositeFrame) publicationDeliveryStructure.getDataObjects().getCompositeFrameOrCommonFrame().get(0).getValue(); + ServiceFrame serviceFrame = (ServiceFrame) compositeFrame.getFrames().getCommonFrame().get(0).getValue(); + + Route route = (Route) serviceFrame.getRoutes().getRoute_().get(0).getValue(); + assertEquals("Main Route", route.getName().getValue()); + assertNotNull(route.getLineRef()); + assertEquals("TST:Line:100", route.getLineRef().getValue().getRef()); + } + + @Test + void unmarshalStopPlaceWithCoachFunicularAndTelecabinSubmodes() throws JAXBException { + + String xml = "" + + "" + + " 2016-05-18T15:00:00.0+01:00" + + " NHR" + + " " + + " " + + " " + + " " + + " Coach Terminal" + + " coach" + + " internationalCoach" + + " " + + " " + + " Funicular Station" + + " funicular" + + " funicular" + + " " + + " " + + " Cable Car Station" + + " cableway" + + " telecabin" + + " " + + " " + + " Airport" + + " air" + + " domesticFlight" + + " " + + " " + + " " + + " " + + ""; + + Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); + + @SuppressWarnings("unchecked") + JAXBElement jaxbElement = (JAXBElement) unmarshaller + .unmarshal(new ByteArrayInputStream(xml.getBytes())); + + PublicationDeliveryStructure publicationDeliveryStructure = jaxbElement.getValue(); + SiteFrame siteFrame = (SiteFrame) publicationDeliveryStructure.getDataObjects().getCompositeFrameOrCommonFrame().get(0).getValue(); + + StopPlace coachStop = (StopPlace) siteFrame.getStopPlaces().getStopPlace_().get(0).getValue(); + assertEquals(AllVehicleModesOfTransportEnumeration.COACH, coachStop.getTransportMode()); + assertEquals(CoachSubmodeEnumeration.INTERNATIONAL_COACH, coachStop.getCoachSubmode()); + assertEquals("internationalCoach", coachStop.getCoachSubmode().value()); + + StopPlace funicularStop = (StopPlace) siteFrame.getStopPlaces().getStopPlace_().get(1).getValue(); + assertEquals(AllVehicleModesOfTransportEnumeration.FUNICULAR, funicularStop.getTransportMode()); + assertEquals(FunicularSubmodeEnumeration.FUNICULAR, funicularStop.getFunicularSubmode()); + assertEquals("funicular", funicularStop.getFunicularSubmode().value()); + + StopPlace telecabinStop = (StopPlace) siteFrame.getStopPlaces().getStopPlace_().get(2).getValue(); + assertEquals(AllVehicleModesOfTransportEnumeration.CABLEWAY, telecabinStop.getTransportMode()); + assertEquals(TelecabinSubmodeEnumeration.TELECABIN, telecabinStop.getTelecabinSubmode()); + assertEquals("telecabin", telecabinStop.getTelecabinSubmode().value()); + + StopPlace airStop = (StopPlace) siteFrame.getStopPlaces().getStopPlace_().get(3).getValue(); + assertEquals(AllVehicleModesOfTransportEnumeration.AIR, airStop.getTransportMode()); + assertEquals(AirSubmodeEnumeration.DOMESTIC_FLIGHT, airStop.getAirSubmode()); + assertEquals("domesticFlight", airStop.getAirSubmode().value()); + } +} diff --git a/src/test/java/org/rutebanken/netex/model/UnmarshalVehicleScheduleFrameChouetteTest.java b/src/test/java/org/rutebanken/netex/model/UnmarshalVehicleScheduleFrameChouetteTest.java new file mode 100644 index 0000000..ba60d3f --- /dev/null +++ b/src/test/java/org/rutebanken/netex/model/UnmarshalVehicleScheduleFrameChouetteTest.java @@ -0,0 +1,108 @@ +/* + * 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 org.rutebanken.netex.model; + +import jakarta.xml.bind.JAXBElement; +import jakarta.xml.bind.JAXBException; +import jakarta.xml.bind.Unmarshaller; +import org.junit.jupiter.api.Test; + +import java.io.ByteArrayInputStream; +import java.math.BigInteger; +import java.time.LocalTime; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +class UnmarshalVehicleScheduleFrameChouetteTest extends AbstractUnmarshalFrameTest { + + @Test + void unmarshalBlockInVehicleScheduleFrame() throws JAXBException { + + String xml = "\n" + + "\n" + + " 2023-08-03T00:20:33.337\n" + + " RB\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " Morning Block\n" + + " First block of the day\n" + + " BLK001\n" + + " 05:30:00\n" + + " 12:00:00\n" + + " 0\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + ""; + + Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); + + @SuppressWarnings("unchecked") + JAXBElement jaxbElement = (JAXBElement) unmarshaller + .unmarshal(new ByteArrayInputStream(xml.getBytes())); + + PublicationDeliveryStructure publicationDeliveryStructure = jaxbElement.getValue(); + CompositeFrame compositeFrame = (CompositeFrame) publicationDeliveryStructure.getDataObjects().getCompositeFrameOrCommonFrame().get(0).getValue(); + VehicleScheduleFrame vsFrame = (VehicleScheduleFrame) compositeFrame.getFrames().getCommonFrame().get(0).getValue(); + + assertNotNull(vsFrame.getBlocks()); + assertEquals(1, vsFrame.getBlocks().getBlockOrCompoundBlockOrTrainBlock().size()); + + Block block = (Block) vsFrame.getBlocks().getBlockOrCompoundBlockOrTrainBlock().get(0); + assertEquals("Morning Block", block.getName().getValue()); + assertEquals("First block of the day", block.getDescription().getValue()); + assertEquals("BLK001", block.getPrivateCode().getValue()); + assertEquals(LocalTime.of(5, 30), block.getStartTime()); + assertEquals(LocalTime.of(12, 0), block.getEndTime()); + assertEquals(BigInteger.ZERO, block.getEndTimeDayOffset()); + assertEquals("TST:ScheduledStopPoint:Depot", block.getStartPointRef().getRef()); + assertEquals("TST:ScheduledStopPoint:Depot", block.getEndPointRef().getRef()); + + assertNotNull(block.getDayTypes()); + assertEquals("TST:DayType:Weekday", block.getDayTypes().getDayTypeRef().get(0).getValue().getRef()); + + assertNotNull(block.getJourneys()); + assertEquals(4, block.getJourneys().getJourneyRefOrJourneyDesignatorOrServiceDesignator().size()); + + Object firstRef = block.getJourneys().getJourneyRefOrJourneyDesignatorOrServiceDesignator().get(0).getValue(); + assertTrue(firstRef instanceof DeadRunRefStructure); + assertEquals("TST:DeadRun:ToStart", ((DeadRunRefStructure) firstRef).getRef()); + + Object secondRef = block.getJourneys().getJourneyRefOrJourneyDesignatorOrServiceDesignator().get(1).getValue(); + assertTrue(secondRef instanceof VehicleJourneyRefStructure); + assertEquals("TST:ServiceJourney:1", ((VehicleJourneyRefStructure) secondRef).getRef()); + } +}