From e463c926bfde211a620aa07fc3064d61409c31b3 Mon Sep 17 00:00:00 2001 From: Mansoor Sajjad Date: Wed, 27 Nov 2024 14:41:16 +0100 Subject: [PATCH] Refactor NetexEntitiesTestFactory and unit tests. --- pom.xml | 2 +- .../NetexEntitiesTestFactory.java | 566 ++++++++++-------- .../InvalidFlexibleAreaValidatorTest.java | 10 +- ...ectedInterchangeDistanceValidatorTest.java | 3 +- .../DuplicateInterchangesValidatorTest.java | 57 +- .../MandatoryFieldsValidatorTest.java | 32 +- ...opPointsInVehicleJourneyValidatorTest.java | 4 +- ...istanceBetweenStopPointsValidatorTest.java | 9 +- .../IdenticalStopPointsValidatorTest.java | 68 ++- .../samequayref/SameQuayRefValidatorTest.java | 29 +- .../SameStopPointsValidatorTest.java | 218 ++++--- .../StopPointsCountValidatorTest.java | 32 +- ...gPassengerStopAssignmentValidatorTest.java | 68 ++- ...ingTimetabledPassingTimeValidatorTest.java | 84 ++- ...InvalidServiceAlterationValidatorTest.java | 114 ++-- .../MissingReplacementValidatorTest.java | 55 +- .../speed/UnexpectedSpeedValidatorTest.java | 45 +- ...tedDistanceInServiceLinkValidatorTest.java | 4 +- .../MismatchedStopPointsValidatorTest.java | 69 ++- 19 files changed, 825 insertions(+), 644 deletions(-) diff --git a/pom.xml b/pom.xml index 2b1e6a9e..dadf189e 100644 --- a/pom.xml +++ b/pom.xml @@ -27,7 +27,7 @@ false 4.4.4 3.0 - 6.0.2 + 6.0.4-SNAPSHOT 3.1.29 2.11.0 1.17 diff --git a/src/test/java/no/entur/antu/netextestdata/NetexEntitiesTestFactory.java b/src/test/java/no/entur/antu/netextestdata/NetexEntitiesTestFactory.java index abeb2eea..94cd4810 100644 --- a/src/test/java/no/entur/antu/netextestdata/NetexEntitiesTestFactory.java +++ b/src/test/java/no/entur/antu/netextestdata/NetexEntitiesTestFactory.java @@ -4,6 +4,8 @@ import static no.entur.antu.netextestdata.MappingSupport.createWrappedRef; import jakarta.xml.bind.JAXBElement; +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; import java.math.BigInteger; import java.time.Duration; import java.time.LocalDate; @@ -13,6 +15,7 @@ import java.util.Collection; import java.util.Collections; import java.util.List; +import java.util.Optional; import java.util.stream.IntStream; import net.opengis.gml._3.AbstractRingPropertyType; import net.opengis.gml._3.DirectPositionListType; @@ -33,113 +36,143 @@ public class NetexEntitiesTestFactory { .withId("EVERYDAY") .withName(new MultilingualString().withValue("everyday")); - public CreateLine line() { - return new CreateLine(); + public CreateLine line(int id) { + return new CreateLine(id); } - public CreateRoute route() { - return new CreateRoute(); + public CreateRoute route(int id) { + return new CreateRoute(id); } - public CreateJourneyPattern journeyPattern() { - return new CreateJourneyPattern(); + public CreateJourneyPattern journeyPattern(int id) { + return new CreateJourneyPattern(id); } public CreateServiceJourney serviceJourney( - Line line, - JourneyPattern journeyPattern + int id, + CreateLine line, + CreateJourneyPattern journeyPattern ) { - return new CreateServiceJourney(line, journeyPattern); + return new CreateServiceJourney(id, line, journeyPattern); } - public CreateServiceJourney serviceJourney(JourneyPattern journeyPattern) { - return serviceJourney(new CreateLine().create(), journeyPattern); + public CreateServiceJourney serviceJourney( + int id, + CreateJourneyPattern journeyPattern + ) { + return serviceJourney(id, new CreateLine(1), journeyPattern); } public CreateTimetabledPassingTimes timetabledPassingTimes() { return new CreateTimetabledPassingTimes(); } - public CreateDeadRun deadRun(Line line, JourneyPattern journeyPattern) { - return new CreateDeadRun(line, journeyPattern); + public CreateDeadRun deadRun( + int id, + CreateLine createLine, + CreateJourneyPattern createJourneyPattern + ) { + return new CreateDeadRun(id, createLine, createJourneyPattern); } - public CreateDeadRun deadRun(JourneyPattern journeyPattern) { - return deadRun(new CreateLine().create(), journeyPattern); + public CreateDeadRun deadRun( + int id, + CreateJourneyPattern createJourneyPattern + ) { + return deadRun(id, new CreateLine(1), createJourneyPattern); } public CreateDatedServiceJourney datedServiceJourney( - int serviceJourneyRefId + int id, + CreateServiceJourney serviceJourneyRef, + CreateOperatingDay operatingDayRef ) { - return new CreateDatedServiceJourney(serviceJourneyRefId); + return new CreateDatedServiceJourney( + id, + serviceJourneyRef, + operatingDayRef + ); } - public List createJourneyPatterns( + public List journeyPatterns( int numberOfJourneyPatterns ) { return IntStream .rangeClosed(1, numberOfJourneyPatterns) - .mapToObj(index -> new CreateJourneyPattern().withId(index).create()) + .mapToObj(CreateJourneyPattern::new) .toList(); } - public List createServiceJourneys( - Line line, - JourneyPattern journeyPattern, + public List serviceJourneys( + CreateLine createLine, + CreateJourneyPattern createJourneyPattern, int numberOfServiceJourneys ) { return IntStream .rangeClosed(1, numberOfServiceJourneys) .mapToObj(index -> - new CreateServiceJourney(line, journeyPattern).withId(index).create() + new CreateServiceJourney(index, createLine, createJourneyPattern) + .create() ) .toList(); } - public List createServiceJourneys( - JourneyPattern journeyPattern, + public List serviceJourneys( + CreateJourneyPattern createJourneyPattern, int numberOfServiceJourneys ) { - return createServiceJourneys( - new CreateLine().create(), - journeyPattern, + return serviceJourneys( + new CreateLine(1), + createJourneyPattern, numberOfServiceJourneys ); } - public CreateServiceJourneyInterchange serviceJourneyInterchange() { - return new CreateServiceJourneyInterchange(); + public CreateServiceJourneyInterchange serviceJourneyInterchange(int id) { + return new CreateServiceJourneyInterchange(id); } public CreateServiceLink serviceLink( + int id, String fromScheduledStopPointRef, String toScheduledStopPointRef ) { - return new CreateServiceLink() + return new CreateServiceLink(id) .withFromScheduledStopPointRef(fromScheduledStopPointRef) .withToScheduledStopPointRef(toScheduledStopPointRef); } - public CreateFlexibleArea flexibleArea() { - return new CreateFlexibleArea(); + public CreateFlexibleArea flexibleArea(int id) { + return new CreateFlexibleArea(id); } - public CreateFlexibleStopPlace flexibleStopPlace(FlexibleArea flexibleArea) { - return new CreateFlexibleStopPlace().withFlexibleArea(flexibleArea); + public CreateFlexibleStopPlace flexibleStopPlace( + int id, + FlexibleArea flexibleArea + ) { + return new CreateFlexibleStopPlace(id).withFlexibleArea(flexibleArea); } public CreateStopPointInJourneyPattern stopPointInJourneyPattern( - int journeyPatternId + int id, + CreateJourneyPattern journeyPatternRef ) { - return new CreateStopPointInJourneyPattern(journeyPatternId); + return new CreateStopPointInJourneyPattern(id, journeyPatternRef); } - public CreateLinkInJourneyPattern linkInJourneyPattern(int journeyPatternId) { - return new CreateLinkInJourneyPattern(journeyPatternId); + public CreateLinkInJourneyPattern linkInJourneyPattern( + int id, + CreateJourneyPattern journeyPatternRef + ) { + return new CreateLinkInJourneyPattern(id, journeyPatternRef); } - public CreatePassengerStopAssignment passengerStopAssignment() { - return new CreatePassengerStopAssignment(); + public CreatePassengerStopAssignment passengerStopAssignment(int id) { + return new CreatePassengerStopAssignment(id); + } + + public CreateOperatingDay operatingDay(int id, LocalDate date) { + return new CreateOperatingDay(id, date); } public CreateNetexEntitiesIndex netexEntitiesIndex() { @@ -166,15 +199,44 @@ public CreateNetexEntitiesIndex netexEntitiesIndex( .addFlexibleStopPlace(flexibleStopPlace); } - public static class CreateFlexibleArea { + public CreateDayType dayType(int dayTypeId) { + return new CreateDayType(dayTypeId); + } + + public CreateDayTypeAssignment dayTypeAssignment(int id) { + return new CreateDayTypeAssignment(id); + } + + public abstract static class CreateEntity { + + protected final String id; + + public CreateEntity(int id) { + this.id = String.valueOf(id); + } - private int id = 1; + public CreateEntity(String id) { + this.id = String.valueOf(id); + } + + // TODO: no final + public final String ref() { + Type type = + ( + (ParameterizedType) getClass().getGenericSuperclass() + ).getActualTypeArguments()[0]; + return "TST:" + ((Class) type).getSimpleName() + ":" + id; + } + + public abstract T create(); + } + + public static class CreateFlexibleArea extends CreateEntity { private List coordinates; - public CreateFlexibleArea withId(int id) { - this.id = id; - return this; + public CreateFlexibleArea(int id) { + super(id); } public CreateFlexibleArea withCoordinates(List coordinates) { @@ -189,7 +251,7 @@ public FlexibleArea create() { linearRing.withPosList(positionList); return new FlexibleArea() - .withId("RUT:FlexibleArea:" + id) + .withId(ref()) .withName(new MultilingualString().withValue("FlexibleArea " + id)) .withPolygon( new PolygonType() @@ -203,15 +265,13 @@ public FlexibleArea create() { } } - public static class CreateFlexibleStopPlace { - - private int id = 1; + public static class CreateFlexibleStopPlace + extends CreateEntity { private FlexibleArea flexibleArea; - public CreateFlexibleStopPlace withId(int id) { - this.id = id; - return this; + public CreateFlexibleStopPlace(int id) { + super(id); } public CreateFlexibleStopPlace withFlexibleArea(FlexibleArea flexibleArea) { @@ -221,7 +281,7 @@ public CreateFlexibleStopPlace withFlexibleArea(FlexibleArea flexibleArea) { public FlexibleStopPlace create() { return new FlexibleStopPlace() - .withId("RUT:FlexibleStopPlace:" + id) + .withId(ref()) .withName(new MultilingualString().withValue("FlexibleStopPlace " + id)) .withAreas( new FlexibleStopPlace_VersionStructure.Areas() @@ -230,9 +290,8 @@ public FlexibleStopPlace create() { } } - public static class CreatePassengerStopAssignment { - - private int id; + public static class CreatePassengerStopAssignment + extends CreateEntity { private String scheduleStopPointRef; @@ -240,9 +299,8 @@ public static class CreatePassengerStopAssignment { private String quayRef; - public CreatePassengerStopAssignment withId(int id) { - this.id = id; - return this; + public CreatePassengerStopAssignment(int id) { + super(id); } public CreatePassengerStopAssignment withScheduleStopPointId( @@ -265,7 +323,7 @@ public CreatePassengerStopAssignment withQuayId(int quayId) { public PassengerStopAssignment create() { return new PassengerStopAssignment() - .withId("TST:PassengerStopAssignment:" + id) + .withId(ref()) .withScheduledStopPointRef( createWrappedRef( scheduleStopPointRef, @@ -279,30 +337,22 @@ public PassengerStopAssignment create() { } } - public static class CreateDatedServiceJourney { + public static class CreateDatedServiceJourney + extends CreateEntity { - private int id = 1; - private int operatingDayRefId = -1; - private final int serviceJourneyRefId; + private final CreateOperatingDay operatingDayRef; + private final CreateServiceJourney serviceJourneyRef; + private CreateDatedServiceJourney datedServiceJourneyRef; private ServiceAlterationEnumeration serviceAlteration; - private int datedServiceJourneyRefId = -1; - - public CreateDatedServiceJourney(int serviceJourneyRefId) { - assert serviceJourneyRefId > 0; - this.serviceJourneyRefId = serviceJourneyRefId; - } - - public CreateDatedServiceJourney withId(int id) { - this.id = id; - return this; - } - public CreateDatedServiceJourney withOperatingDayRefId( - int operatingDayRefId + public CreateDatedServiceJourney( + int id, + CreateServiceJourney serviceJourneyRef, + CreateOperatingDay operatingDayRef ) { - assert operatingDayRefId > 0; - this.operatingDayRefId = operatingDayRefId; - return this; + super(id); + this.serviceJourneyRef = serviceJourneyRef; + this.operatingDayRef = operatingDayRef; } public CreateDatedServiceJourney withServiceAlteration( @@ -313,79 +363,143 @@ public CreateDatedServiceJourney withServiceAlteration( } public CreateDatedServiceJourney withDatedServiceJourneyRef( - int datedServiceJourneyRefId + CreateDatedServiceJourney datedServiceJourneyRef ) { - assert datedServiceJourneyRefId > 0; - this.datedServiceJourneyRefId = datedServiceJourneyRefId; + this.datedServiceJourneyRef = datedServiceJourneyRef; return this; } public DatedServiceJourney create() { DatedServiceJourney datedServiceJourney = new DatedServiceJourney() - .withId("TST:DatedServiceJourney:" + id); + .withId(ref()); Collection> journeyRefs = new ArrayList<>(); journeyRefs.add( createJaxbElement( - new ServiceJourneyRefStructure() - .withRef("TST:ServiceJourney:" + serviceJourneyRefId) + new ServiceJourneyRefStructure().withRef(serviceJourneyRef.ref()) ) ); - if (datedServiceJourneyRefId > 0) { + if (datedServiceJourneyRef != null) { journeyRefs.add( createJaxbElement( new DatedServiceJourneyRefStructure() - .withRef("TST:DatedServiceJourney:" + datedServiceJourneyRefId) + .withRef(datedServiceJourneyRef.ref()) ) ); } - if (operatingDayRefId > 0) { - datedServiceJourney.withOperatingDayRef( - new OperatingDayRefStructure() - .withRef("TST:OperatingDay:" + operatingDayRefId) - ); - } - return datedServiceJourney .withJourneyRef(journeyRefs) + .withOperatingDayRef( + new OperatingDayRefStructure().withRef(operatingDayRef.ref()) + ) .withServiceAlteration(serviceAlteration); } } - public static class CreateOperatingDay { + public static class CreateOperatingDay extends CreateEntity { - private int id = 1; private final LocalDate calendarDate; - public CreateOperatingDay(LocalDate calendarDate) { + public CreateOperatingDay(int id, LocalDate calendarDate) { + super(id); this.calendarDate = calendarDate; } - public CreateOperatingDay withId(int id) { - this.id = id; - return this; - } - public OperatingDay create() { return new OperatingDay() - .withId("TST:OperatingDay:" + id) + .withId(ref()) // .withId(calendarDate.format(DATE_FORMATTER)) .withCalendarDate(calendarDate.atStartOfDay()); } } - public static class CreateLine { + public static class CreateDayType extends CreateEntity { - private int id = 1; - private AllVehicleModesOfTransportEnumeration transportMode; + public CreateDayType(int id) { + super(id); + } + + public DayType create() { + return new DayType().withId(ref()); + } + } + + public static class CreateDayTypeAssignment + extends CreateEntity { + + private CreateDayType DayTypeRef; + private LocalDate date; + private CreateOperatingDay operatingDayRef; + // TODO: create CreateOperatingPeriod + private String operatingPeriodRef; + + public CreateDayTypeAssignment(int id) { + super(id); + } - public CreateLine withId(int id) { - this.id = id; + public CreateDayTypeAssignment withDate(LocalDate date) { + this.date = date; + this.operatingDayRef = null; + this.operatingPeriodRef = null; return this; } + public CreateDayTypeAssignment withOperatingDayRef( + CreateOperatingDay operatingDayRef + ) { + this.operatingDayRef = operatingDayRef; + this.date = null; + this.operatingPeriodRef = null; + return this; + } + + public CreateDayTypeAssignment withOperatingPeriodRef( + String operatingPeriodRef + ) { + this.operatingPeriodRef = operatingPeriodRef; + this.date = null; + this.operatingDayRef = null; + return this; + } + + public DayTypeAssignment create() { + DayTypeAssignment dayTypeAssignment = new DayTypeAssignment() + .withId(ref()); + + Optional + .ofNullable(date) + .ifPresent(d -> dayTypeAssignment.withDate(d.atStartOfDay())); + + Optional + .ofNullable(operatingDayRef) + .ifPresent(ref -> + dayTypeAssignment.withOperatingDayRef( + new OperatingDayRefStructure().withRef(ref.ref()) + ) + ); + + Optional + .ofNullable(operatingPeriodRef) + .ifPresent(ref -> + dayTypeAssignment.withOperatingPeriodRef( + createJaxbElement(new OperatingPeriodRefStructure().withRef(ref)) + ) + ); + + return dayTypeAssignment; + } + } + + public static class CreateLine extends CreateEntity { + + private AllVehicleModesOfTransportEnumeration transportMode; + + public CreateLine(int id) { + super(id); + } + public CreateLine withTransportMode( AllVehicleModesOfTransportEnumeration transportMode ) { @@ -395,20 +509,18 @@ public CreateLine withTransportMode( public Line create() { return new Line() - .withId("TST:Line:" + id) + .withId(ref()) .withName(new MultilingualString().withValue("Line " + id)) .withTransportMode(transportMode); } } - public static class CreateRoute { + public static class CreateRoute extends CreateEntity { - private int id = 1; private Line line; - public CreateRoute withId(int id) { - this.id = id; - return this; + public CreateRoute(int id) { + super(id); } public CreateRoute withLine(Line line) { @@ -418,17 +530,17 @@ public CreateRoute withLine(Line line) { public Route create() { return new Route() + .withId(ref()) .withLineRef( createJaxbElement(new LineRefStructure().withRef(line.getId())) - ) - .withId("TST:Route:" + id); + ); } } - public static class CreateJourneyPattern { + public static class CreateJourneyPattern + extends CreateEntity { private Route route; - private int id = 1; private int numberOfStopPointInJourneyPattern = 4; private int numberOfServiceLinksInJourneyPattern = 3; @@ -439,9 +551,8 @@ public static class CreateJourneyPattern { List linkInSequence = new ArrayList<>(); - public CreateJourneyPattern withId(int id) { - this.id = id; - return this; + public CreateJourneyPattern(int id) { + super(id); } public CreateJourneyPattern withRoute(Route route) { @@ -487,13 +598,8 @@ public CreateJourneyPattern withServiceLinksInJourneyPattern( return this; } - public int id() { - return id; - } - public JourneyPattern create() { - JourneyPattern journeyPattern = new JourneyPattern() - .withId("TST:JourneyPattern:" + id); + JourneyPattern journeyPattern = new JourneyPattern().withId(ref()); if (route != null) { journeyPattern.withRouteRef( @@ -539,8 +645,7 @@ private List createPointsInLinkSequ .range(0, numberOfStopPointInJourneyPattern) .mapToObj(index -> { CreateStopPointInJourneyPattern createStopPointInJourneyPattern = - new CreateStopPointInJourneyPattern(id) - .withId(index + 1) + new CreateStopPointInJourneyPattern(index + 1, this) .withOrder(index + 1) .withScheduledStopPointId(index + 1); @@ -562,8 +667,7 @@ private List createLinksInLinkSequen .range(0, numberOfStopPointInJourneyPattern) .mapToObj(index -> { CreateLinkInJourneyPattern createLinkInJourneyPattern = - new CreateLinkInJourneyPattern(id) - .withId(index + 1) + new CreateLinkInJourneyPattern(index + 1, this) .withOrder(index + 1) .withServiceLinkId(index + 1); @@ -574,10 +678,9 @@ private List createLinksInLinkSequen } } - public static class CreateStopPointInJourneyPattern { + public static class CreateStopPointInJourneyPattern + extends CreateEntity { - private final int journeyPatternId; - private int id = 1; private int order = 1; private int scheduledStopPointId = 1; private int destinationDisplayId = -1; @@ -585,18 +688,10 @@ public static class CreateStopPointInJourneyPattern { private boolean forBoarding = false; public CreateStopPointInJourneyPattern( - CreateJourneyPattern journeyPattern + int id, + CreateJourneyPattern journeyPatternRef ) { - this.journeyPatternId = journeyPattern.id; - } - - public CreateStopPointInJourneyPattern(int journeyPatternId) { - this.journeyPatternId = journeyPatternId; - } - - public CreateStopPointInJourneyPattern withId(int id) { - this.id = id; - return this; + super(journeyPatternRef.ref() + "_" + id); } public CreateStopPointInJourneyPattern withOrder(int order) { @@ -635,19 +730,19 @@ public CreateStopPointInJourneyPattern withForBoarding( public StopPointInJourneyPattern create() { StopPointInJourneyPattern stopPointInJourneyPattern = new StopPointInJourneyPattern() - .withId( - "TST:StopPointInJourneyPattern:" + journeyPatternId + "_" + id - ) + .withId(ref()) .withOrder(BigInteger.valueOf(order)) .withScheduledStopPointRef( - createScheduledStopPointRef( - "TST:ScheduledStopPoint:" + scheduledStopPointId + createJaxbElement( + new ScheduledStopPointRefStructure() + .withRef("TST:ScheduledStopPoint:" + scheduledStopPointId) ) ); if (destinationDisplayId > 0) { stopPointInJourneyPattern.setDestinationDisplayRef( - createDestinationDisplayRef( - "TST:DestinationDisplay:" + destinationDisplayId + createJaxbElement( + new DestinationDisplayRefStructure() + .withRef("TST:DestinationDisplay:" + destinationDisplayId) ) .getValue() ); @@ -660,20 +755,17 @@ public StopPointInJourneyPattern create() { } } - public static class CreateLinkInJourneyPattern { + public static class CreateLinkInJourneyPattern + extends CreateEntity { - private final int journeyPatternId; - private int id = 1; private int order = 1; private int serviceLinkId; - public CreateLinkInJourneyPattern(int journeyPatternId) { - this.journeyPatternId = journeyPatternId; - } - - public CreateLinkInJourneyPattern withId(int id) { - this.id = id; - return this; + public CreateLinkInJourneyPattern( + int id, + CreateJourneyPattern journeyPatternRef + ) { + super(journeyPatternRef.ref() + "_" + id); } public CreateLinkInJourneyPattern withOrder(int order) { @@ -688,7 +780,7 @@ public CreateLinkInJourneyPattern withServiceLinkId(int serviceLinkId) { public LinkInJourneyPattern create() { return new LinkInJourneyPattern() - .withId("TST:LinkInJourneyPattern:" + journeyPatternId + "_" + id) + .withId(ref()) .withOrder(BigInteger.valueOf(order)) .withServiceLinkRef( new ServiceLinkRefStructure() @@ -697,25 +789,24 @@ public LinkInJourneyPattern create() { } } - public static class CreateDeadRun { + public static class CreateDeadRun extends CreateEntity { - private int id = 1; - private final Line line; - private final JourneyPattern journeyPattern; + private final CreateLine createLine; + private final CreateJourneyPattern createJourneyPattern; private CreateTimetabledPassingTimes createTimetabledPassingTimes; - public CreateDeadRun(Line line, JourneyPattern journeyPattern) { - this.line = line; - this.journeyPattern = journeyPattern; + public CreateDeadRun( + int id, + CreateLine createLine, + CreateJourneyPattern createJourneyPattern + ) { + super(id); + this.createLine = createLine; + this.createJourneyPattern = createJourneyPattern; this.createTimetabledPassingTimes = new CreateTimetabledPassingTimes(); } - public CreateDeadRun withId(int id) { - this.id = id; - return this; - } - public CreateDeadRun withCreateTimetabledPassingTimes( CreateTimetabledPassingTimes createTimetabledPassingTimes ) { @@ -725,37 +816,43 @@ public CreateDeadRun withCreateTimetabledPassingTimes( public DeadRun create() { return new DeadRun() - .withId("TST:DeadRun:" + id) - .withLineRef(createLineRef(line.getId())) + .withId(ref()) + .withLineRef( + createJaxbElement(new LineRefStructure().withRef(createLine.ref())) + ) .withDayTypes(createEveryDayRefs()) - .withJourneyPatternRef(createJourneyPatternRef(journeyPattern.getId())) + .withJourneyPatternRef( + createJaxbElement( + new JourneyPatternRefStructure().withRef(createJourneyPattern.ref()) + ) + ) .withPassingTimes( new TimetabledPassingTimes_RelStructure() .withTimetabledPassingTime( - createTimetabledPassingTimes.create(journeyPattern) + createTimetabledPassingTimes.create(createJourneyPattern.create()) ) ); } } - public static class CreateServiceJourney { + public static class CreateServiceJourney + extends CreateEntity { - private int id = 1; - private final Line line; - private final JourneyPattern journeyPattern; + private final CreateLine line; + private final CreateJourneyPattern journeyPattern; private CreateTimetabledPassingTimes createTimetabledPassingTimes; - public CreateServiceJourney(Line line, JourneyPattern journeyPattern) { + public CreateServiceJourney( + int id, + CreateLine line, + CreateJourneyPattern journeyPattern + ) { + super(id); this.line = line; this.journeyPattern = journeyPattern; this.createTimetabledPassingTimes = new CreateTimetabledPassingTimes(); } - public CreateServiceJourney withId(int id) { - this.id = id; - return this; - } - public CreateServiceJourney withCreateTimetabledPassingTimes( CreateTimetabledPassingTimes createTimetabledPassingTimes ) { @@ -765,22 +862,28 @@ public CreateServiceJourney withCreateTimetabledPassingTimes( public ServiceJourney create() { return new ServiceJourney() - .withId("TST:ServiceJourney:" + id) - .withLineRef(createLineRef(line.getId())) + .withId(ref()) + .withLineRef( + createJaxbElement(new LineRefStructure().withRef(line.ref())) + ) .withDayTypes(createEveryDayRefs()) - .withJourneyPatternRef(createJourneyPatternRef(journeyPattern.getId())) + .withJourneyPatternRef( + createJaxbElement( + new JourneyPatternRefStructure().withRef(journeyPattern.ref()) + ) + ) .withPassingTimes( new TimetabledPassingTimes_RelStructure() .withTimetabledPassingTime( - createTimetabledPassingTimes.create(journeyPattern) + createTimetabledPassingTimes.create(journeyPattern.create()) ) ); } } - public static class CreateServiceJourneyInterchange { + public static class CreateServiceJourneyInterchange + extends CreateEntity { - private int id = 1; private boolean guaranteed = true; private Duration maximumWaitTime; private ScheduledStopPointId fromPointRef; @@ -788,9 +891,8 @@ public static class CreateServiceJourneyInterchange { private ServiceJourneyId fromJourneyRef; private ServiceJourneyId toJourneyRef; - public CreateServiceJourneyInterchange withId(int id) { - this.id = id; - return this; + public CreateServiceJourneyInterchange(int id) { + super(id); } public CreateServiceJourneyInterchange withGuaranteed(boolean guaranteed) { @@ -836,7 +938,7 @@ public CreateServiceJourneyInterchange withToJourneyRef( public ServiceJourneyInterchange create() { ServiceJourneyInterchange serviceJourneyInterchange = new ServiceJourneyInterchange() - .withId("TST:ServiceJourneyInterchange:" + id) + .withId(ref()) .withGuaranteed(guaranteed) .withMaximumWaitTime(maximumWaitTime); @@ -894,26 +996,27 @@ private List createTimetabledPassingTimes( .range(0, pointsInLink.size()) .mapToObj(index -> new TimetabledPassingTime() - .withId("TTPT-" + (index + 1)) + .withId("TST:TimetabledPassingTime" + (index + 1)) .withDepartureTime(LocalTime.of(5, index * departureTimeOffset)) .withPointInJourneyPatternRef( - createStopPointRef(pointsInLink.get(index).getId()) + createJaxbElement( + new PointInJourneyPatternRefStructure() + .withRef(pointsInLink.get(index).getId()) + ) ) ) .toList(); } } - public static class CreateServiceLink { + public static class CreateServiceLink extends CreateEntity { - private int id = 1; private ScheduledStopPointRefStructure fromScheduledStopPointRef; private ScheduledStopPointRefStructure toScheduledStopPointRef; - private LinkSequenceProjection_VersionStructure linkSequenceProjectionVersionStructure; + private LinkSequenceProjection_VersionStructure linkSequenceProjection_VersionStructure; - public CreateServiceLink withId(int id) { - this.id = id; - return this; + public CreateServiceLink(int id) { + super(id); } public CreateServiceLink withFromScheduledStopPointRef( @@ -935,7 +1038,7 @@ public CreateServiceLink withToScheduledStopPointRef( public CreateServiceLink withLineStringList( List lineStringPositions ) { - this.linkSequenceProjectionVersionStructure = + this.linkSequenceProjection_VersionStructure = new LinkSequenceProjection_VersionStructure() .withId("TST:ServiceLinkProjection:" + id) .withLineString( @@ -950,7 +1053,7 @@ public CreateServiceLink withLineStringList( public CreateServiceLink withLineStringPositions( List lineStringPositions ) { - this.linkSequenceProjectionVersionStructure = + this.linkSequenceProjection_VersionStructure = new LinkSequenceProjection_VersionStructure() .withId("TST:ServiceLinkProjection:" + id) .withLineString( @@ -964,15 +1067,13 @@ public CreateServiceLink withLineStringPositions( public ServiceLink create() { return new ServiceLink() - .withId("TST:ServiceLink:" + id) + .withId(ref()) .withFromPointRef(fromScheduledStopPointRef) .withToPointRef(toScheduledStopPointRef) .withProjections( new Projections_RelStructure() .withProjectionRefOrProjection( - createLinkSequenceProjection_VersionStructureElement( - linkSequenceProjectionVersionStructure - ) + createJaxbElement(linkSequenceProjection_VersionStructure) ) ); } @@ -1164,41 +1265,6 @@ private static DayTypeRefs_RelStructure createEveryDayRefs() { .withDayTypeRef(Collections.singleton(createEveryDayRef())); } - /* private static utility methods */ - private static JAXBElement createLinkSequenceProjection_VersionStructureElement( - LinkSequenceProjection_VersionStructure value - ) { - return createJaxbElement(value); - } - - private static JAXBElement createScheduledStopPointRef( - String id - ) { - return createWrappedRef(id, ScheduledStopPointRefStructure.class); - } - - private static JAXBElement createStopPointRef( - String id - ) { - return createWrappedRef(id, StopPointInJourneyPatternRefStructure.class); - } - - private static JAXBElement createJourneyPatternRef( - String id - ) { - return createWrappedRef(id, JourneyPatternRefStructure.class); - } - - private static JAXBElement createLineRef(String id) { - return createWrappedRef(id, LineRefStructure.class); - } - - private static JAXBElement createDestinationDisplayRef( - String id - ) { - return createWrappedRef(id, DestinationDisplayRefStructure.class); - } - private static JAXBElement createEveryDayRef() { return createJaxbElement( new DayTypeRefStructure().withRef(EVERYDAY.getId()) diff --git a/src/test/java/no/entur/antu/validation/flex/validator/flexiblearea/InvalidFlexibleAreaValidatorTest.java b/src/test/java/no/entur/antu/validation/flex/validator/flexiblearea/InvalidFlexibleAreaValidatorTest.java index f2f3fd02..f3dc3999 100644 --- a/src/test/java/no/entur/antu/validation/flex/validator/flexiblearea/InvalidFlexibleAreaValidatorTest.java +++ b/src/test/java/no/entur/antu/validation/flex/validator/flexiblearea/InvalidFlexibleAreaValidatorTest.java @@ -180,7 +180,7 @@ void testMissingFlexibleStopAreaShouldIgnoreValidationGracefully() { NetexEntitiesTestFactory testData = new NetexEntitiesTestFactory(); FlexibleStopPlace flexibleStopPlace = - new NetexEntitiesTestFactory.CreateFlexibleStopPlace().create(); + new NetexEntitiesTestFactory.CreateFlexibleStopPlace(1).create(); ValidationReport validationReport = runValidation( testData.netexEntitiesIndex(flexibleStopPlace).create() @@ -193,10 +193,10 @@ void testMissingFlexibleStopAreaShouldIgnoreValidationGracefully() { void testMissingPolygonShouldIgnoreValidationGracefully2() { NetexEntitiesTestFactory testData = new NetexEntitiesTestFactory(); - FlexibleArea flexibleArea = testData.flexibleArea().create(); + FlexibleArea flexibleArea = testData.flexibleArea(1).create(); FlexibleStopPlace flexibleStopPlace = testData - .flexibleStopPlace(flexibleArea.withPolygon(null)) + .flexibleStopPlace(1, flexibleArea.withPolygon(null)) .create(); ValidationReport validationReport = runValidation( @@ -212,12 +212,12 @@ private ValidationReport runTestWithGivenCoordinates( NetexEntitiesTestFactory testData = new NetexEntitiesTestFactory(); FlexibleArea flexibleArea = testData - .flexibleArea() + .flexibleArea(1) .withCoordinates(coordinates) .create(); FlexibleStopPlace flexibleStopPlace = testData - .flexibleStopPlace(flexibleArea) + .flexibleStopPlace(1, flexibleArea) .create(); return runValidation( diff --git a/src/test/java/no/entur/antu/validation/validator/interchange/distance/UnexpectedInterchangeDistanceValidatorTest.java b/src/test/java/no/entur/antu/validation/validator/interchange/distance/UnexpectedInterchangeDistanceValidatorTest.java index 7ca99fd5..a310f6d5 100644 --- a/src/test/java/no/entur/antu/validation/validator/interchange/distance/UnexpectedInterchangeDistanceValidatorTest.java +++ b/src/test/java/no/entur/antu/validation/validator/interchange/distance/UnexpectedInterchangeDistanceValidatorTest.java @@ -199,8 +199,7 @@ private ValidationReport runTestWithCoordinates( ); return fragment - .serviceJourneyInterchange() - .withId(i) + .serviceJourneyInterchange(i) .withFromPointRef(fromPointRef) .withToPointRef(toPointRef) .withFromJourneyRef( diff --git a/src/test/java/no/entur/antu/validation/validator/interchange/duplicate/DuplicateInterchangesValidatorTest.java b/src/test/java/no/entur/antu/validation/validator/interchange/duplicate/DuplicateInterchangesValidatorTest.java index 43e6cb4f..b52ddbe7 100644 --- a/src/test/java/no/entur/antu/validation/validator/interchange/duplicate/DuplicateInterchangesValidatorTest.java +++ b/src/test/java/no/entur/antu/validation/validator/interchange/duplicate/DuplicateInterchangesValidatorTest.java @@ -197,8 +197,8 @@ private List createServiceJourneyInterchanges( int maxStartIndex = Math.max(startIndex, 0); - List serviceJourneys = fragment.createServiceJourneys( - fragment.journeyPattern().create(), + List serviceJourneys = fragment.serviceJourneys( + fragment.journeyPattern(1), (numberOfServiceJourneyInterchanges + maxStartIndex) * 2 ); @@ -207,40 +207,27 @@ private List createServiceJourneyInterchanges( .boxed() .toList(); - List createServiceJourneyInterchanges = - IntStream - .range( - maxStartIndex, - numberOfServiceJourneyInterchanges + maxStartIndex - ) - .map(index -> - duplicateIndexesList.contains(index) ? maxStartIndex : index - ) - .mapToObj(index -> - new NetexEntitiesTestFactory.CreateServiceJourneyInterchange() - .withFromJourneyRef( - ServiceJourneyId.ofValidId(serviceJourneys.get(index * 2)) - ) - .withToJourneyRef( - ServiceJourneyId.ofValidId(serviceJourneys.get((index * 2) + 1)) - ) - .withFromPointRef( - new ScheduledStopPointId("TST:ScheduledStopPoint:" + (index + 1)) - ) - .withToPointRef( - new ScheduledStopPointId("TST:ScheduledStopPoint:" + (index + 2)) - ) - ) - .toList(); - return IntStream - .range(0, createServiceJourneyInterchanges.size()) - .mapToObj(index -> - createServiceJourneyInterchanges - .get(index) - .withId(maxStartIndex + index) - .create() - ) + .range(maxStartIndex, numberOfServiceJourneyInterchanges + maxStartIndex) + .mapToObj(index -> { + int id = duplicateIndexesList.contains(index) ? maxStartIndex : index; + return new NetexEntitiesTestFactory.CreateServiceJourneyInterchange( + index + ) + .withFromJourneyRef( + ServiceJourneyId.ofValidId(serviceJourneys.get(id * 2)) + ) + .withToJourneyRef( + ServiceJourneyId.ofValidId(serviceJourneys.get((id * 2) + 1)) + ) + .withFromPointRef( + new ScheduledStopPointId("TST:ScheduledStopPoint:" + (id + 1)) + ) + .withToPointRef( + new ScheduledStopPointId("TST:ScheduledStopPoint:" + (id + 2)) + ) + .create(); + }) .toList(); } } diff --git a/src/test/java/no/entur/antu/validation/validator/interchange/mandatoryfields/MandatoryFieldsValidatorTest.java b/src/test/java/no/entur/antu/validation/validator/interchange/mandatoryfields/MandatoryFieldsValidatorTest.java index 84b7f4be..be52b8db 100644 --- a/src/test/java/no/entur/antu/validation/validator/interchange/mandatoryfields/MandatoryFieldsValidatorTest.java +++ b/src/test/java/no/entur/antu/validation/validator/interchange/mandatoryfields/MandatoryFieldsValidatorTest.java @@ -38,15 +38,13 @@ void testAllMandatoryFieldArePresent() { NetexEntitiesTestFactory netexEntitiesFactory = new NetexEntitiesTestFactory(); - List serviceJourneys = - netexEntitiesFactory.createServiceJourneys( - netexEntitiesFactory.journeyPattern().create(), - 2 - ); + List serviceJourneys = netexEntitiesFactory.serviceJourneys( + netexEntitiesFactory.journeyPattern(1), + 2 + ); ServiceJourneyInterchange serviceJourneyInterchange = netexEntitiesFactory - .serviceJourneyInterchange() - .withId(1) + .serviceJourneyInterchange(1) .withFromJourneyRef(ServiceJourneyId.ofValidId(serviceJourneys.get(0))) .withToJourneyRef(ServiceJourneyId.ofValidId(serviceJourneys.get(1))) .withFromPointRef(scheduledStopPointId1) @@ -84,12 +82,11 @@ void testFromServiceJourneyRefMissing() { new NetexEntitiesTestFactory(); ServiceJourney serviceJourney = netexEntitiesFactory - .serviceJourney(netexEntitiesFactory.journeyPattern().create()) + .serviceJourney(1, netexEntitiesFactory.journeyPattern(1)) .create(); ServiceJourneyInterchange serviceJourneyInterchange = netexEntitiesFactory - .serviceJourneyInterchange() - .withId(1) + .serviceJourneyInterchange(1) .withToJourneyRef(ServiceJourneyId.ofValidId(serviceJourney)) .withFromPointRef(scheduledStopPointId1) .withToPointRef(scheduledStopPointId2) @@ -134,12 +131,11 @@ void testToServiceJourneyRefMissing() { new NetexEntitiesTestFactory(); ServiceJourney serviceJourney = netexEntitiesFactory - .serviceJourney(netexEntitiesFactory.journeyPattern().create()) + .serviceJourney(1, netexEntitiesFactory.journeyPattern(1)) .create(); ServiceJourneyInterchange serviceJourneyInterchange = netexEntitiesFactory - .serviceJourneyInterchange() - .withId(1) + .serviceJourneyInterchange(1) .withFromJourneyRef(ServiceJourneyId.ofValidId(serviceJourney)) .withFromPointRef(scheduledStopPointId1) .withToPointRef(scheduledStopPointId2) @@ -184,12 +180,11 @@ void testFromPointRefMissing() { new NetexEntitiesTestFactory(); ServiceJourney serviceJourney = netexEntitiesFactory - .serviceJourney(netexEntitiesFactory.journeyPattern().create()) + .serviceJourney(1, netexEntitiesFactory.journeyPattern(1)) .create(); ServiceJourneyInterchange serviceJourneyInterchange = netexEntitiesFactory - .serviceJourneyInterchange() - .withId(1) + .serviceJourneyInterchange(1) .withFromJourneyRef(ServiceJourneyId.ofValidId(serviceJourney)) .withToJourneyRef(ServiceJourneyId.ofValidId(serviceJourney)) .withToPointRef(scheduledStopPointId) @@ -229,12 +224,11 @@ void testToPointRefMissing() { new NetexEntitiesTestFactory(); ServiceJourney serviceJourney = netexEntitiesFactory - .serviceJourney(netexEntitiesFactory.journeyPattern().create()) + .serviceJourney(1, netexEntitiesFactory.journeyPattern(1)) .create(); ServiceJourneyInterchange serviceJourneyInterchange = netexEntitiesFactory - .serviceJourneyInterchange() - .withId(1) + .serviceJourneyInterchange(1) .withFromJourneyRef(ServiceJourneyId.ofValidId(serviceJourney)) .withToJourneyRef(ServiceJourneyId.ofValidId(serviceJourney)) .withFromPointRef(scheduledStopPointId) diff --git a/src/test/java/no/entur/antu/validation/validator/interchange/stoppoints/StopPointsInVehicleJourneyValidatorTest.java b/src/test/java/no/entur/antu/validation/validator/interchange/stoppoints/StopPointsInVehicleJourneyValidatorTest.java index 1f8afa1d..c5422e61 100644 --- a/src/test/java/no/entur/antu/validation/validator/interchange/stoppoints/StopPointsInVehicleJourneyValidatorTest.java +++ b/src/test/java/no/entur/antu/validation/validator/interchange/stoppoints/StopPointsInVehicleJourneyValidatorTest.java @@ -99,7 +99,7 @@ void noInterchangeNoEffect() { void interchangeWithMissingAttributes() { NetexEntitiesTestFactory fragment = new NetexEntitiesTestFactory(); ServiceJourneyInterchange serviceJourneyInterchange = fragment - .serviceJourneyInterchange() + .serviceJourneyInterchange(1) .create(); mockGetServiceJourneyInterchangeInfo( @@ -174,7 +174,7 @@ private ValidationReport runTestFor( ); ServiceJourneyInterchange serviceJourneyInterchange = fragment - .serviceJourneyInterchange() + .serviceJourneyInterchange(1) .withFromPointRef(fromPointRef) .withToPointRef(toPointRef) .withFromJourneyRef(fromServiceJourneyRef) diff --git a/src/test/java/no/entur/antu/validation/validator/journeypattern/stoppoint/distance/UnexpectedDistanceBetweenStopPointsValidatorTest.java b/src/test/java/no/entur/antu/validation/validator/journeypattern/stoppoint/distance/UnexpectedDistanceBetweenStopPointsValidatorTest.java index 9ceaf69b..59ce3360 100644 --- a/src/test/java/no/entur/antu/validation/validator/journeypattern/stoppoint/distance/UnexpectedDistanceBetweenStopPointsValidatorTest.java +++ b/src/test/java/no/entur/antu/validation/validator/journeypattern/stoppoint/distance/UnexpectedDistanceBetweenStopPointsValidatorTest.java @@ -169,12 +169,12 @@ private ValidationReport runWithQuayCoordinates( ) { NetexEntitiesTestFactory testFragment = new NetexEntitiesTestFactory(); - Line line = testFragment.line().withTransportMode(transportMode).create(); + Line line = testFragment.line(1).withTransportMode(transportMode).create(); - Route route = testFragment.route().withLine(line).create(); + Route route = testFragment.route(1).withLine(line).create(); NetexEntitiesTestFactory.CreateJourneyPattern createJourneyPattern = - testFragment.journeyPattern().withId(123).withRoute(route); + testFragment.journeyPattern(123).withRoute(route); if (coordinates.isEmpty()) { createJourneyPattern.withNumberOfStopPointInJourneyPattern(0); @@ -184,8 +184,7 @@ private ValidationReport runWithQuayCoordinates( .rangeClosed(1, coordinates.size()) .mapToObj(i -> testFragment - .stopPointInJourneyPattern(123) - .withId(i) + .stopPointInJourneyPattern(i, createJourneyPattern) .withScheduledStopPointId(i) .create() ) diff --git a/src/test/java/no/entur/antu/validation/validator/journeypattern/stoppoint/identicalstoppoints/IdenticalStopPointsValidatorTest.java b/src/test/java/no/entur/antu/validation/validator/journeypattern/stoppoint/identicalstoppoints/IdenticalStopPointsValidatorTest.java index e8aaaef7..b7956383 100644 --- a/src/test/java/no/entur/antu/validation/validator/journeypattern/stoppoint/identicalstoppoints/IdenticalStopPointsValidatorTest.java +++ b/src/test/java/no/entur/antu/validation/validator/journeypattern/stoppoint/identicalstoppoints/IdenticalStopPointsValidatorTest.java @@ -67,14 +67,14 @@ void testDifferentDestinationDisplays() { ValidationReport validationReport = getValidationReport( numberOfJourneyPatterns, numberOfStopPoints, - create -> { - if (create.journeyPatternId() == 1 && create.stopPointId() == 1) { - create.createStopPointInJourneyPattern().withDestinationDisplayId(1); + context -> { + if (context.journeyPatternId() == 1 && context.stopPointId() == 1) { + context.createStopPointInJourneyPattern().withDestinationDisplayId(1); } - if (create.journeyPatternId() == 2 && create.stopPointId() == 1) { - create.createStopPointInJourneyPattern().withDestinationDisplayId(2); + if (context.journeyPatternId() == 2 && context.stopPointId() == 1) { + context.createStopPointInJourneyPattern().withDestinationDisplayId(2); } - return create; + return context; } ); @@ -148,36 +148,40 @@ private ValidationReport getValidationReport( List createJourneyPatterns = IntStream .rangeClosed(1, numberOfJourneyPatterns) - .mapToObj(journeyPatternId -> - testFragment.journeyPattern().withId(journeyPatternId) - ) + .mapToObj(testFragment::journeyPattern) .toList(); if (numberOfStopPoints > 0) { - createJourneyPatterns.forEach(createJourneyPattern -> - createJourneyPattern.withStopPointsInJourneyPattern( - IntStream - .rangeClosed(1, numberOfStopPoints) - .mapToObj(stopPointId -> - new CreateStopPointInJourneyPatternContext( - stopPointId, - createJourneyPattern.id(), - new CreateStopPointInJourneyPattern(createJourneyPattern) - .withId(stopPointId) - .withScheduledStopPointId(stopPointId) - .withDestinationDisplayId(stopPointId) - .withForBoarding(stopPointId == 1) // first stop point - .withForAlighting(stopPointId == numberOfStopPoints) // last stop point + IntStream + .rangeClosed(1, numberOfJourneyPatterns) + .forEach(journeyPatternIndex -> { + NetexEntitiesTestFactory.CreateJourneyPattern createJourneyPattern = + createJourneyPatterns.get(journeyPatternIndex - 1); + createJourneyPattern.withStopPointsInJourneyPattern( + IntStream + .rangeClosed(1, numberOfStopPoints) + .mapToObj(stopPointIndex -> + new CreateStopPointInJourneyPatternContext( + stopPointIndex, + journeyPatternIndex, + new CreateStopPointInJourneyPattern( + stopPointIndex, + createJourneyPattern + ) + .withScheduledStopPointId(stopPointIndex) + .withDestinationDisplayId(stopPointIndex) + .withForBoarding(stopPointIndex == 1) // first stop point + .withForAlighting(stopPointIndex == numberOfStopPoints) // last stop point + ) ) - ) - .map(customizeStopPoint) - .map( - CreateStopPointInJourneyPatternContext::createStopPointInJourneyPattern - ) - .map(CreateStopPointInJourneyPattern::create) - .toList() - ) - ); + .map(customizeStopPoint) + .map( + CreateStopPointInJourneyPatternContext::createStopPointInJourneyPattern + ) + .map(CreateStopPointInJourneyPattern::create) + .toList() + ); + }); } else { createJourneyPatterns.forEach(createJourneyPattern -> createJourneyPattern.withNumberOfStopPointInJourneyPattern(0) diff --git a/src/test/java/no/entur/antu/validation/validator/journeypattern/stoppoint/samequayref/SameQuayRefValidatorTest.java b/src/test/java/no/entur/antu/validation/validator/journeypattern/stoppoint/samequayref/SameQuayRefValidatorTest.java index d2b087f4..84dbb908 100644 --- a/src/test/java/no/entur/antu/validation/validator/journeypattern/stoppoint/samequayref/SameQuayRefValidatorTest.java +++ b/src/test/java/no/entur/antu/validation/validator/journeypattern/stoppoint/samequayref/SameQuayRefValidatorTest.java @@ -29,8 +29,7 @@ void testNoStopPointsInJourneyPattern() { NetexEntitiesTestFactory testFragment = new NetexEntitiesTestFactory(); JourneyPattern journeyPattern = testFragment - .journeyPattern() - .withId(1) + .journeyPattern(1) .withNumberOfStopPointInJourneyPattern(0) .create(); @@ -48,19 +47,18 @@ void testNoStopPointsInJourneyPattern() { void testNoSameQuayRefOnStopPoints() { NetexEntitiesTestFactory testFragment = new NetexEntitiesTestFactory(); - JourneyPattern journeyPattern = testFragment - .journeyPattern() - .withId(1) + NetexEntitiesTestFactory.CreateJourneyPattern createJourneyPattern = + testFragment.journeyPattern(1); + + JourneyPattern journeyPattern = createJourneyPattern .withStopPointsInJourneyPattern( List.of( testFragment - .stopPointInJourneyPattern(1) - .withId(1) + .stopPointInJourneyPattern(1, createJourneyPattern) .withScheduledStopPointId(1) .create(), testFragment - .stopPointInJourneyPattern(1) - .withId(2) + .stopPointInJourneyPattern(2, createJourneyPattern) .withScheduledStopPointId(2) .create() ) @@ -91,19 +89,18 @@ void testNoSameQuayRefOnStopPoints() { void testSameQuayRefOnStopPoints() { NetexEntitiesTestFactory testFragment = new NetexEntitiesTestFactory(); - JourneyPattern journeyPattern = testFragment - .journeyPattern() - .withId(1) + NetexEntitiesTestFactory.CreateJourneyPattern createJourneyPattern = + testFragment.journeyPattern(1); + + JourneyPattern journeyPattern = createJourneyPattern .withStopPointsInJourneyPattern( List.of( testFragment - .stopPointInJourneyPattern(1) - .withId(1) + .stopPointInJourneyPattern(1, createJourneyPattern) .withScheduledStopPointId(1) .create(), testFragment - .stopPointInJourneyPattern(1) - .withId(2) + .stopPointInJourneyPattern(2, createJourneyPattern) .withScheduledStopPointId(2) .create() ) diff --git a/src/test/java/no/entur/antu/validation/validator/journeypattern/stoppoint/samestoppoints/SameStopPointsValidatorTest.java b/src/test/java/no/entur/antu/validation/validator/journeypattern/stoppoint/samestoppoints/SameStopPointsValidatorTest.java index b97bac93..7d8bd516 100644 --- a/src/test/java/no/entur/antu/validation/validator/journeypattern/stoppoint/samestoppoints/SameStopPointsValidatorTest.java +++ b/src/test/java/no/entur/antu/validation/validator/journeypattern/stoppoint/samestoppoints/SameStopPointsValidatorTest.java @@ -32,19 +32,21 @@ void testAllJourneyPatternsHaveDifferentStopPoints() { IntStream .rangeClosed(1, 8) - .forEach(i -> + .forEach(i -> { + NetexEntitiesTestFactory.CreateJourneyPattern createJourneyPattern = + testFragment.journeyPattern(i); createNetexEntitiesIndex.addJourneyPatterns( - testFragment - .journeyPattern() - .withId(i) + createJourneyPattern .withStopPointsInJourneyPattern( List.of( - testFragment.stopPointInJourneyPattern(i).withId(i).create() + testFragment + .stopPointInJourneyPattern(i, createJourneyPattern) + .create() ) ) .create() - ) - ); + ); + }); ValidationReport validationReport = runValidation( createNetexEntitiesIndex.create() @@ -61,18 +63,33 @@ void testAllJourneyPatternsHaveSameStopPoints() { NetexEntitiesTestFactory.CreateNetexEntitiesIndex createNetexEntitiesIndex = testFragment.netexEntitiesIndex(); + NetexEntitiesTestFactory.CreateJourneyPattern createJourneyPattern1 = + testFragment.journeyPattern(1); + createNetexEntitiesIndex.addJourneyPatterns( + createJourneyPattern1 + .withStopPointsInJourneyPattern( + List.of( + testFragment + .stopPointInJourneyPattern(sameStopPointId, createJourneyPattern1) + .create() + ) + ) + .create() + ); + IntStream - .rangeClosed(1, 8) + .rangeClosed(2, 8) .forEach(i -> createNetexEntitiesIndex.addJourneyPatterns( testFragment - .journeyPattern() - .withId(i) + .journeyPattern(i) .withStopPointsInJourneyPattern( List.of( testFragment - .stopPointInJourneyPattern(1) - .withId(sameStopPointId) + .stopPointInJourneyPattern( + sameStopPointId, + createJourneyPattern1 + ) .create() ) ) @@ -93,53 +110,65 @@ void testMultiplePairsOfJourneyPatternsHaveSameStopPoints() { int sameStopPointId1 = 987; int sameStopPointId2 = 988; - JourneyPattern journeyPatternWithSameStopPoints1_1 = testFragment - .journeyPattern() - .withId(123) + NetexEntitiesTestFactory.CreateJourneyPattern createJourneyPattern123 = + testFragment.journeyPattern(123); + + JourneyPattern journeyPatternWithSameStopPoints1_1 = createJourneyPattern123 .withStopPointsInJourneyPattern( List.of( testFragment - .stopPointInJourneyPattern(123) - .withId(sameStopPointId1) + .stopPointInJourneyPattern( + sameStopPointId1, + createJourneyPattern123 + ) .create() ) ) .create(); - JourneyPattern journeyPatternWithSameStopPoints1_2 = testFragment - .journeyPattern() - .withId(345) + NetexEntitiesTestFactory.CreateJourneyPattern createJourneyPattern345 = + testFragment.journeyPattern(345); + + JourneyPattern journeyPatternWithSameStopPoints1_2 = createJourneyPattern345 .withStopPointsInJourneyPattern( List.of( testFragment - .stopPointInJourneyPattern(123) - .withId(sameStopPointId1) + .stopPointInJourneyPattern( + sameStopPointId1, + createJourneyPattern123 + ) .create() ) ) .create(); - JourneyPattern journeyPatternWithSameStopPoints2_1 = testFragment - .journeyPattern() - .withId(567) + NetexEntitiesTestFactory.CreateJourneyPattern createJourneyPattern567 = + testFragment.journeyPattern(567); + + JourneyPattern journeyPatternWithSameStopPoints2_1 = createJourneyPattern567 .withStopPointsInJourneyPattern( List.of( testFragment - .stopPointInJourneyPattern(567) - .withId(sameStopPointId2) + .stopPointInJourneyPattern( + sameStopPointId2, + createJourneyPattern567 + ) .create() ) ) .create(); - JourneyPattern journeyPatternWithSameStopPoints2_2 = testFragment - .journeyPattern() - .withId(789) + NetexEntitiesTestFactory.CreateJourneyPattern createJourneyPattern789 = + testFragment.journeyPattern(789); + + JourneyPattern journeyPatternWithSameStopPoints2_2 = createJourneyPattern789 .withStopPointsInJourneyPattern( List.of( testFragment - .stopPointInJourneyPattern(567) - .withId(sameStopPointId2) + .stopPointInJourneyPattern( + sameStopPointId2, + createJourneyPattern567 + ) .create() ) ) @@ -164,32 +193,38 @@ void testMultiplePairsOfJourneyPatternsHaveSameStopPoints() { void testAllJourneyPatternsWithMultipleStopPointsHaveSameStopPoints() { NetexEntitiesTestFactory testFragment = new NetexEntitiesTestFactory(); int stopPointInJourneyPatternId = 987; - JourneyPattern journeyPattern1 = testFragment - .journeyPattern() - .withId(123) + NetexEntitiesTestFactory.CreateJourneyPattern createJourneyPattern123 = + testFragment.journeyPattern(123); + + JourneyPattern journeyPattern1 = createJourneyPattern123 .withStopPointsInJourneyPattern( IntStream .rangeClosed(1, 10) .mapToObj(i -> testFragment - .stopPointInJourneyPattern(123) - .withId(stopPointInJourneyPatternId + 1) + .stopPointInJourneyPattern( + stopPointInJourneyPatternId + 1, + createJourneyPattern123 + ) .create() ) .toList() ) .create(); - JourneyPattern journeyPattern2 = testFragment - .journeyPattern() - .withId(345) + NetexEntitiesTestFactory.CreateJourneyPattern createJourneyPattern345 = + testFragment.journeyPattern(345); + + JourneyPattern journeyPattern2 = createJourneyPattern345 .withStopPointsInJourneyPattern( IntStream .rangeClosed(1, 10) .mapToObj(i -> testFragment - .stopPointInJourneyPattern(123) - .withId(stopPointInJourneyPatternId + 1) + .stopPointInJourneyPattern( + stopPointInJourneyPatternId + 1, + createJourneyPattern123 + ) .create() ) .toList() @@ -211,54 +246,63 @@ void testTwoJourneyPatternsOutOfTenHaveSameStopPoints() { NetexEntitiesTestFactory testFragment = new NetexEntitiesTestFactory(); int stopPointInJourneyPatternId = 987; - NetexEntitiesTestFactory.CreateNetexEntitiesIndex createNetexEntitiesIndex = - testFragment.netexEntitiesIndex(); + NetexEntitiesTestFactory.CreateJourneyPattern createJourneyPattern123 = + testFragment.journeyPattern(123); - IntStream - .rangeClosed(1, 8) - .forEach(i -> - createNetexEntitiesIndex.addJourneyPatterns( - testFragment - .journeyPattern() - .withId(i) - .withStopPointsInJourneyPattern( - List.of( - testFragment - .stopPointInJourneyPattern(123) - .withId(stopPointInJourneyPatternId + i) - .create() - ) - ) - .create() - ) - ); - - JourneyPattern journeyPatternWithSameStopPoints1 = testFragment - .journeyPattern() - .withId(123) + JourneyPattern journeyPatternWithSameStopPoints1 = createJourneyPattern123 .withStopPointsInJourneyPattern( List.of( testFragment - .stopPointInJourneyPattern(123) - .withId(stopPointInJourneyPatternId) + .stopPointInJourneyPattern( + stopPointInJourneyPatternId, + createJourneyPattern123 + ) .create() ) ) .create(); - JourneyPattern journeyPatternWithSameStopPoints2 = testFragment - .journeyPattern() - .withId(345) + NetexEntitiesTestFactory.CreateJourneyPattern createJourneyPattern345 = + testFragment.journeyPattern(345); + + JourneyPattern journeyPatternWithSameStopPoints2 = createJourneyPattern345 .withStopPointsInJourneyPattern( List.of( testFragment - .stopPointInJourneyPattern(123) - .withId(stopPointInJourneyPatternId) + .stopPointInJourneyPattern( + stopPointInJourneyPatternId, + createJourneyPattern123 + ) .create() ) ) .create(); + NetexEntitiesTestFactory.CreateNetexEntitiesIndex createNetexEntitiesIndex = + testFragment.netexEntitiesIndex(); + + IntStream + .rangeClosed(1, 8) + .forEach(i -> { + NetexEntitiesTestFactory.CreateJourneyPattern createJourneyPattern = + testFragment.journeyPattern(i); + + createNetexEntitiesIndex.addJourneyPatterns( + createJourneyPattern + .withStopPointsInJourneyPattern( + List.of( + testFragment + .stopPointInJourneyPattern( + stopPointInJourneyPatternId + i, + createJourneyPattern123 + ) + .create() + ) + ) + .create() + ); + }); + createNetexEntitiesIndex.addJourneyPatterns( journeyPatternWithSameStopPoints1, journeyPatternWithSameStopPoints2 @@ -278,16 +322,19 @@ void testJourneyPatternsWithUnSortedSameStopPoints() { List stopPointsOrder1 = List.of(8, 3, 5, 2, 4, 10, 9, 1, 7, 6); - JourneyPattern journeyPattern1 = testFragment - .journeyPattern() - .withId(123) + NetexEntitiesTestFactory.CreateJourneyPattern createJourneyPattern123 = + testFragment.journeyPattern(123); + + JourneyPattern journeyPattern123 = createJourneyPattern123 .withStopPointsInJourneyPattern( IntStream .rangeClosed(1, 10) .mapToObj(i -> testFragment - .stopPointInJourneyPattern(123) - .withId(stopPointInJourneyPatternId + 1) + .stopPointInJourneyPattern( + stopPointInJourneyPatternId + 1, + createJourneyPattern123 + ) .withOrder(stopPointsOrder1.get(i - 1)) // not in order, as appeared in the xml .create() ) @@ -295,16 +342,19 @@ void testJourneyPatternsWithUnSortedSameStopPoints() { ) .create(); - JourneyPattern journeyPattern2 = testFragment - .journeyPattern() - .withId(345) + NetexEntitiesTestFactory.CreateJourneyPattern createJourneyPattern345 = + testFragment.journeyPattern(345); + + JourneyPattern journeyPattern345 = createJourneyPattern345 .withStopPointsInJourneyPattern( IntStream .rangeClosed(1, 10) .mapToObj(i -> testFragment - .stopPointInJourneyPattern(123) - .withId(stopPointInJourneyPatternId + 1) + .stopPointInJourneyPattern( + stopPointInJourneyPatternId + 1, + createJourneyPattern123 + ) .withOrder(i) // In correct order, also as appeared in xml .create() ) @@ -315,7 +365,7 @@ void testJourneyPatternsWithUnSortedSameStopPoints() { ValidationReport validationReport = runValidation( testFragment .netexEntitiesIndex() - .addJourneyPatterns(journeyPattern1, journeyPattern2) + .addJourneyPatterns(journeyPattern123, journeyPattern345) .create() ); diff --git a/src/test/java/no/entur/antu/validation/validator/journeypattern/stoppoint/stoppointscount/StopPointsCountValidatorTest.java b/src/test/java/no/entur/antu/validation/validator/journeypattern/stoppoint/stoppointscount/StopPointsCountValidatorTest.java index a09e7a30..0053899d 100644 --- a/src/test/java/no/entur/antu/validation/validator/journeypattern/stoppoint/stoppointscount/StopPointsCountValidatorTest.java +++ b/src/test/java/no/entur/antu/validation/validator/journeypattern/stoppoint/stoppointscount/StopPointsCountValidatorTest.java @@ -47,16 +47,19 @@ void testJourneyPatternWithNoServiceLinks() { NetexEntitiesTestFactory testFragment = new NetexEntitiesTestFactory(); int stopPointInJourneyPatternIdOffset = 123; - JourneyPattern journeyPattern = testFragment - .journeyPattern() - .withId(123) + NetexEntitiesTestFactory.CreateJourneyPattern createJourneyPattern123 = + testFragment.journeyPattern(123); + + JourneyPattern journeyPattern = createJourneyPattern123 .withStopPointsInJourneyPattern( IntStream .rangeClosed(1, 10) .mapToObj(i -> testFragment - .stopPointInJourneyPattern(123) - .withId(stopPointInJourneyPatternIdOffset + 1) + .stopPointInJourneyPattern( + stopPointInJourneyPatternIdOffset + 1, + createJourneyPattern123 + ) .create() ) .toList() @@ -79,16 +82,19 @@ private ValidationReport runWith10StopPoints(int numberOfServiceLinks) { int stopPointInJourneyPatternIdOffset = 123; int linksInJourneyPatternIdOffset = 234; - JourneyPattern journeyPattern = testFragment - .journeyPattern() - .withId(123) + NetexEntitiesTestFactory.CreateJourneyPattern createJourneyPattern123 = + testFragment.journeyPattern(123); + + JourneyPattern journeyPattern = createJourneyPattern123 .withStopPointsInJourneyPattern( IntStream .rangeClosed(1, 10) .mapToObj(i -> testFragment - .stopPointInJourneyPattern(123) - .withId(stopPointInJourneyPatternIdOffset + 1) + .stopPointInJourneyPattern( + stopPointInJourneyPatternIdOffset + 1, + createJourneyPattern123 + ) .create() ) .toList() @@ -98,8 +104,10 @@ private ValidationReport runWith10StopPoints(int numberOfServiceLinks) { .rangeClosed(1, numberOfServiceLinks) .mapToObj(i -> testFragment - .linkInJourneyPattern(123) - .withId(linksInJourneyPatternIdOffset + 1) + .linkInJourneyPattern( + linksInJourneyPatternIdOffset + 1, + createJourneyPattern123 + ) .create() ) .toList() diff --git a/src/test/java/no/entur/antu/validation/validator/passengerstopassignemnt/MissingPassengerStopAssignmentValidatorTest.java b/src/test/java/no/entur/antu/validation/validator/passengerstopassignemnt/MissingPassengerStopAssignmentValidatorTest.java index 62ca1d57..fbfe97ef 100644 --- a/src/test/java/no/entur/antu/validation/validator/passengerstopassignemnt/MissingPassengerStopAssignmentValidatorTest.java +++ b/src/test/java/no/entur/antu/validation/validator/passengerstopassignemnt/MissingPassengerStopAssignmentValidatorTest.java @@ -16,7 +16,6 @@ import org.junit.jupiter.api.Test; import org.rutebanken.netex.model.DeadRun; import org.rutebanken.netex.model.JourneyPattern; -import org.rutebanken.netex.model.Line; import org.rutebanken.netex.model.PassengerStopAssignment; import org.rutebanken.netex.model.ServiceJourney; @@ -34,11 +33,14 @@ private ValidationReport runValidation( @Test void testAllStopPlaceAssignmentsExists() { NetexEntitiesTestFactory testData = new NetexEntitiesTestFactory(); - JourneyPattern journeyPattern = testData.journeyPattern().create(); + NetexEntitiesTestFactory.CreateJourneyPattern createJourneyPattern = + testData.journeyPattern(1); ServiceJourney serviceJourney = testData - .serviceJourney(journeyPattern) + .serviceJourney(1, createJourneyPattern) .create(); + JourneyPattern journeyPattern = createJourneyPattern.create(); + NetexEntitiesIndex netexEntitiesIndex = testData .netexEntitiesIndex(journeyPattern, serviceJourney) .create(); @@ -66,11 +68,13 @@ void testAllStopPlaceAssignmentsExists() { @Test void testMissingStopPlaceAssignmentsButServiceJourneyExists() { NetexEntitiesTestFactory testData = new NetexEntitiesTestFactory(); - JourneyPattern journeyPattern = testData.journeyPattern().create(); + NetexEntitiesTestFactory.CreateJourneyPattern createJourneyPattern = + testData.journeyPattern(1); ServiceJourney serviceJourney = testData - .serviceJourney(journeyPattern) + .serviceJourney(1, createJourneyPattern) .create(); + JourneyPattern journeyPattern = createJourneyPattern.create(); NetexEntitiesIndex netexEntitiesIndex = testData .netexEntitiesIndex(journeyPattern, serviceJourney) .create(); @@ -102,18 +106,25 @@ void testMissingStopPlaceAssignmentsButServiceJourneyExists() { */ void testMissingSingleStopPlaceAssignmentsUsedInMultipleJourneyPatternsButServiceJourneyExists() { NetexEntitiesTestFactory testData = new NetexEntitiesTestFactory(); - List journeyPatterns = testData.createJourneyPatterns(4); - Line line = testData.line().create(); + List journeyPatterns = + testData.journeyPatterns(4); List serviceJourneys = journeyPatterns .stream() - .map(journeyPattern -> testData.serviceJourney(line, journeyPattern)) + .map(journeyPattern -> + testData.serviceJourney(1, testData.line(1), journeyPattern) + ) .map(NetexEntitiesTestFactory.CreateServiceJourney::create) .map(ServiceJourney.class::cast) .toList(); NetexEntitiesIndex netexEntitiesIndex = testData .netexEntitiesIndex() - .addJourneyPatterns(journeyPatterns.toArray(JourneyPattern[]::new)) + .addJourneyPatterns( + journeyPatterns + .stream() + .map(NetexEntitiesTestFactory.CreateJourneyPattern::create) + .toArray(JourneyPattern[]::new) + ) .addServiceJourneys(serviceJourneys.toArray(ServiceJourney[]::new)) .create(); @@ -128,12 +139,13 @@ void testMissingSingleStopPlaceAssignmentsUsedInMultipleJourneyPatternsButServic */ void testMissingStopPlaceAssignmentsAndNoServiceJourneyExists() { NetexEntitiesTestFactory testData = new NetexEntitiesTestFactory(); - JourneyPattern journeyPattern = testData.journeyPattern().create(); + NetexEntitiesTestFactory.CreateJourneyPattern createJourneyPattern = + testData.journeyPattern(1); NetexEntitiesIndex netexEntitiesIndex = new NetexEntitiesIndexImpl(); netexEntitiesIndex .getJourneyPatternIndex() - .put(journeyPattern.getId(), journeyPattern); + .put(createJourneyPattern.ref(), createJourneyPattern.create()); ValidationReport validationReport = runValidation(netexEntitiesIndex); @@ -146,12 +158,13 @@ void testMissingStopPlaceAssignmentsAndNoServiceJourneyExists() { */ void testMissingStopPlaceAssignmentsAndDeadRunExists() { NetexEntitiesTestFactory testData = new NetexEntitiesTestFactory(); - JourneyPattern journeyPattern = testData.journeyPattern().create(); - DeadRun deadRun = testData.deadRun(journeyPattern).create(); + NetexEntitiesTestFactory.CreateJourneyPattern createJourneyPattern = + testData.journeyPattern(1); + DeadRun deadRun = testData.deadRun(1, createJourneyPattern).create(); NetexEntitiesIndex netexEntitiesIndex = testData .netexEntitiesIndex() - .addJourneyPatterns(journeyPattern) + .addJourneyPatterns(createJourneyPattern.create()) .addDeadRuns(deadRun) .create(); @@ -166,16 +179,19 @@ void testMissingStopPlaceAssignmentsAndDeadRunExists() { */ void testMissingStopPlaceAssignmentsAndBothDeadRunAndServiceJourneyExists() { NetexEntitiesTestFactory testData = new NetexEntitiesTestFactory(); - JourneyPattern journeyPattern = testData.journeyPattern().create(); - Line line = testData.line().create(); - DeadRun deadRun = testData.deadRun(line, journeyPattern).create(); + NetexEntitiesTestFactory.CreateJourneyPattern createJourneyPattern = + testData.journeyPattern(1); + NetexEntitiesTestFactory.CreateLine createLine = testData.line(1); + DeadRun deadRun = testData + .deadRun(1, createLine, createJourneyPattern) + .create(); ServiceJourney serviceJourney = testData - .serviceJourney(line, journeyPattern) + .serviceJourney(1, createLine, createJourneyPattern) .create(); NetexEntitiesIndex netexEntitiesIndex = testData .netexEntitiesIndex() - .addJourneyPatterns(journeyPattern) + .addJourneyPatterns(createJourneyPattern.create()) .addServiceJourneys(serviceJourney) .addDeadRuns(deadRun) .create(); @@ -188,11 +204,13 @@ void testMissingStopPlaceAssignmentsAndBothDeadRunAndServiceJourneyExists() { @Test void testMissingMultipleStopPlaceAssignmentsButServiceJourneyExists() { NetexEntitiesTestFactory testData = new NetexEntitiesTestFactory(); - JourneyPattern journeyPattern = testData.journeyPattern().create(); + NetexEntitiesTestFactory.CreateJourneyPattern createJourneyPattern = + testData.journeyPattern(1); ServiceJourney serviceJourney = testData - .serviceJourney(journeyPattern) + .serviceJourney(1, createJourneyPattern) .create(); + JourneyPattern journeyPattern = createJourneyPattern.create(); NetexEntitiesIndex netexEntitiesIndex = testData .netexEntitiesIndex(journeyPattern, serviceJourney) .create(); @@ -221,11 +239,13 @@ void testMissingMultipleStopPlaceAssignmentsButServiceJourneyExists() { @Test void testPassengerStopAssignmentsInLineFileAndNotOnCommonFileShouldBeOk() { NetexEntitiesTestFactory testData = new NetexEntitiesTestFactory(); - JourneyPattern journeyPattern = testData.journeyPattern().create(); + NetexEntitiesTestFactory.CreateJourneyPattern createJourneyPattern = + testData.journeyPattern(1); ServiceJourney serviceJourney = testData - .serviceJourney(journeyPattern) + .serviceJourney(1, createJourneyPattern) .create(); + JourneyPattern journeyPattern = createJourneyPattern.create(); NetexEntitiesTestFactory.CreateNetexEntitiesIndex createNetexEntitiesIndex = testData.netexEntitiesIndex(journeyPattern, serviceJourney); @@ -239,7 +259,7 @@ void testPassengerStopAssignmentsInLineFileAndNotOnCommonFileShouldBeOk() { ) .forEach(index -> { PassengerStopAssignment passengerStopAssignment = testData - .passengerStopAssignment() + .passengerStopAssignment(1) .withScheduleStopPointId(index + 1) .withStopPlaceId(index + 1) .withQuayId(index + 1) diff --git a/src/test/java/no/entur/antu/validation/validator/servicejourney/passingtime/NonIncreasingTimetabledPassingTimeValidatorTest.java b/src/test/java/no/entur/antu/validation/validator/servicejourney/passingtime/NonIncreasingTimetabledPassingTimeValidatorTest.java index 26485d3f..bb13fee0 100644 --- a/src/test/java/no/entur/antu/validation/validator/servicejourney/passingtime/NonIncreasingTimetabledPassingTimeValidatorTest.java +++ b/src/test/java/no/entur/antu/validation/validator/servicejourney/passingtime/NonIncreasingTimetabledPassingTimeValidatorTest.java @@ -31,11 +31,13 @@ private ValidationReport runValidation( @Test void testValidateServiceJourneyWithRegularStop() { NetexEntitiesTestFactory testData = new NetexEntitiesTestFactory(); - JourneyPattern journeyPattern = testData.journeyPattern().create(); + NetexEntitiesTestFactory.CreateJourneyPattern createJourneyPattern = + testData.journeyPattern(1); ServiceJourney serviceJourney = testData - .serviceJourney(journeyPattern) + .serviceJourney(1, createJourneyPattern) .create(); + JourneyPattern journeyPattern = createJourneyPattern.create(); ValidationReport validationReport = runValidation( testData.netexEntitiesIndex(journeyPattern, serviceJourney).create() ); @@ -46,11 +48,13 @@ void testValidateServiceJourneyWithRegularStop() { @Test void testValidateServiceJourneyWithRegularStopMissingTime() { NetexEntitiesTestFactory testData = new NetexEntitiesTestFactory(); - JourneyPattern journeyPattern = testData.journeyPattern().create(); + NetexEntitiesTestFactory.CreateJourneyPattern createJourneyPattern = + testData.journeyPattern(1); ServiceJourney serviceJourney = testData - .serviceJourney(journeyPattern) + .serviceJourney(1, createJourneyPattern) .create(); + JourneyPattern journeyPattern = createJourneyPattern.create(); // remove arrival time and departure time TimetabledPassingTime timetabledPassingTime = getFirstPassingTime( serviceJourney @@ -76,11 +80,13 @@ void testValidateServiceJourneyWithRegularStopMissingTime() { @Test void testValidateServiceJourneyWithRegularStopInconsistentTime() { NetexEntitiesTestFactory testData = new NetexEntitiesTestFactory(); - JourneyPattern journeyPattern = testData.journeyPattern().create(); + NetexEntitiesTestFactory.CreateJourneyPattern createJourneyPattern = + testData.journeyPattern(1); ServiceJourney serviceJourney = testData - .serviceJourney(journeyPattern) + .serviceJourney(1, createJourneyPattern) .create(); + JourneyPattern journeyPattern = createJourneyPattern.create(); // set arrival time after departure time TimetabledPassingTime timetabledPassingTime = getFirstPassingTime( serviceJourney @@ -108,11 +114,13 @@ void testValidateServiceJourneyWithRegularStopInconsistentTime() { @Test void testValidateServiceJourneyWithAreaStop() { NetexEntitiesTestFactory testData = new NetexEntitiesTestFactory(); - JourneyPattern journeyPattern = testData.journeyPattern().create(); + NetexEntitiesTestFactory.CreateJourneyPattern createJourneyPattern = + testData.journeyPattern(1); ServiceJourney serviceJourney = testData - .serviceJourney(journeyPattern) + .serviceJourney(1, createJourneyPattern) .create(); + JourneyPattern journeyPattern = createJourneyPattern.create(); // remove arrival time and departure time and add flex window getFirstPassingTime(serviceJourney) .withArrivalTime(null) @@ -136,9 +144,10 @@ void testValidateServiceJourneyWithAreaStop() { @Test void testValidateServiceJourneyWithAreaStopMissingTimeWindow() { NetexEntitiesTestFactory testData = new NetexEntitiesTestFactory(); - JourneyPattern journeyPattern = testData.journeyPattern().create(); + NetexEntitiesTestFactory.CreateJourneyPattern createJourneyPattern = + testData.journeyPattern(1); ServiceJourney serviceJourney = testData - .serviceJourney(journeyPattern) + .serviceJourney(1, createJourneyPattern) .create(); // remove arrival time and departure time and add flex window @@ -146,6 +155,7 @@ void testValidateServiceJourneyWithAreaStopMissingTimeWindow() { .withArrivalTime(null) .withDepartureTime(null); + JourneyPattern journeyPattern = createJourneyPattern.create(); NetexEntitiesIndex netexEntitiesIndex = testData .netexEntitiesIndex(journeyPattern, serviceJourney) .create(); @@ -171,9 +181,10 @@ void testValidateServiceJourneyWithAreaStopMissingTimeWindow() { @Test void testValidateServiceJourneyWithAreaStopInconsistentTimeWindow() { NetexEntitiesTestFactory testData = new NetexEntitiesTestFactory(); - JourneyPattern journeyPattern = testData.journeyPattern().create(); + NetexEntitiesTestFactory.CreateJourneyPattern createJourneyPattern = + testData.journeyPattern(1); ServiceJourney serviceJourney = testData - .serviceJourney(journeyPattern) + .serviceJourney(1, createJourneyPattern) .create(); // remove arrival time and departure time and add flex window @@ -183,6 +194,7 @@ void testValidateServiceJourneyWithAreaStopInconsistentTimeWindow() { .withEarliestDepartureTime(LocalTime.MIDNIGHT.plusMinutes(1)) .withLatestArrivalTime(LocalTime.MIDNIGHT); + JourneyPattern journeyPattern = createJourneyPattern.create(); NetexEntitiesIndex netexEntitiesIndex = testData .netexEntitiesIndex(journeyPattern, serviceJourney) .create(); @@ -211,9 +223,10 @@ void testValidateServiceJourneyWithAreaStopInconsistentTimeWindow() { @Test void testValidateServiceJourneyWithRegularStopFollowedByRegularStopNonIncreasingTime() { NetexEntitiesTestFactory testData = new NetexEntitiesTestFactory(); - JourneyPattern journeyPattern = testData.journeyPattern().create(); + NetexEntitiesTestFactory.CreateJourneyPattern createJourneyPattern = + testData.journeyPattern(1); ServiceJourney serviceJourney = testData - .serviceJourney(journeyPattern) + .serviceJourney(1, createJourneyPattern) .create(); // remove arrival time and departure time and add flex window on second stop @@ -227,6 +240,7 @@ void testValidateServiceJourneyWithRegularStopFollowedByRegularStopNonIncreasing firstPassingTime.getDepartureTime().minusMinutes(1) ); + JourneyPattern journeyPattern = createJourneyPattern.create(); NetexEntitiesIndex netexEntitiesIndex = testData .netexEntitiesIndex(journeyPattern, serviceJourney) .create(); @@ -252,9 +266,10 @@ void testValidateServiceJourneyWithRegularStopFollowedByRegularStopNonIncreasing @Test void testValidateWithRegularStopFollowedByRegularStopWithMissingTime() { NetexEntitiesTestFactory testData = new NetexEntitiesTestFactory(); - JourneyPattern journeyPattern = testData.journeyPattern().create(); + NetexEntitiesTestFactory.CreateJourneyPattern createJourneyPattern = + testData.journeyPattern(1); ServiceJourney serviceJourney = testData - .serviceJourney(journeyPattern) + .serviceJourney(1, createJourneyPattern) .create(); // Set arrivalTime AFTER departure time (not valid) @@ -262,6 +277,7 @@ void testValidateWithRegularStopFollowedByRegularStopWithMissingTime() { .withDepartureTime(null) .withArrivalTime(null); + JourneyPattern journeyPattern = createJourneyPattern.create(); NetexEntitiesIndex netexEntitiesIndex = testData .netexEntitiesIndex(journeyPattern, serviceJourney) .create(); @@ -283,9 +299,10 @@ void testValidateWithRegularStopFollowedByRegularStopWithMissingTime() { @Test void testValidateServiceJourneyWithRegularStopFollowedByStopArea() { NetexEntitiesTestFactory testData = new NetexEntitiesTestFactory(); - JourneyPattern journeyPattern = testData.journeyPattern().create(); + NetexEntitiesTestFactory.CreateJourneyPattern createJourneyPattern = + testData.journeyPattern(1); ServiceJourney serviceJourney = testData - .serviceJourney(journeyPattern) + .serviceJourney(1, createJourneyPattern) .create(); // remove arrival time and departure time and add flex window on second stop @@ -300,6 +317,7 @@ void testValidateServiceJourneyWithRegularStopFollowedByStopArea() { .withArrivalTime(null) .withDepartureTime(null); + JourneyPattern journeyPattern = createJourneyPattern.create(); NetexEntitiesIndex netexEntitiesIndex = testData .netexEntitiesIndex(journeyPattern, serviceJourney) .create(); @@ -316,9 +334,10 @@ void testValidateServiceJourneyWithRegularStopFollowedByStopArea() { @Test void testValidateServiceJourneyWithRegularStopFollowedByStopAreaNonIncreasingTime() { NetexEntitiesTestFactory testData = new NetexEntitiesTestFactory(); - JourneyPattern journeyPattern = testData.journeyPattern().create(); + NetexEntitiesTestFactory.CreateJourneyPattern createJourneyPattern = + testData.journeyPattern(1); ServiceJourney serviceJourney = testData - .serviceJourney(journeyPattern) + .serviceJourney(1, createJourneyPattern) .create(); // remove arrival time and departure time and add flex window with decreasing time on second stop @@ -335,6 +354,7 @@ void testValidateServiceJourneyWithRegularStopFollowedByStopAreaNonIncreasingTim .withArrivalTime(null) .withDepartureTime(null); + JourneyPattern journeyPattern = createJourneyPattern.create(); NetexEntitiesIndex netexEntitiesIndex = testData .netexEntitiesIndex(journeyPattern, serviceJourney) .create(); @@ -363,9 +383,10 @@ void testValidateServiceJourneyWithRegularStopFollowedByStopAreaNonIncreasingTim @Test void testValidateServiceJourneyWithStopAreaFollowedByRegularStop() { NetexEntitiesTestFactory testData = new NetexEntitiesTestFactory(); - JourneyPattern journeyPattern = testData.journeyPattern().create(); + NetexEntitiesTestFactory.CreateJourneyPattern createJourneyPattern = + testData.journeyPattern(1); ServiceJourney serviceJourney = testData - .serviceJourney(journeyPattern) + .serviceJourney(1, createJourneyPattern) .create(); // remove arrival time and departure time and add flex window on first stop @@ -378,6 +399,7 @@ void testValidateServiceJourneyWithStopAreaFollowedByRegularStop() { .withArrivalTime(null) .withDepartureTime(null); + JourneyPattern journeyPattern = createJourneyPattern.create(); NetexEntitiesIndex netexEntitiesIndex = testData .netexEntitiesIndex(journeyPattern, serviceJourney) .create(); @@ -394,9 +416,10 @@ void testValidateServiceJourneyWithStopAreaFollowedByRegularStop() { @Test void testValidateServiceJourneyWithStopAreaFollowedByStopArea() { NetexEntitiesTestFactory testData = new NetexEntitiesTestFactory(); - JourneyPattern journeyPattern = testData.journeyPattern().create(); + NetexEntitiesTestFactory.CreateJourneyPattern createJourneyPattern = + testData.journeyPattern(1); ServiceJourney serviceJourney = testData - .serviceJourney(journeyPattern) + .serviceJourney(1, createJourneyPattern) .create(); // remove arrival time and departure time and add flex window on first stop @@ -420,6 +443,7 @@ void testValidateServiceJourneyWithStopAreaFollowedByStopArea() { .withArrivalTime(null) .withDepartureTime(null); + JourneyPattern journeyPattern = createJourneyPattern.create(); NetexEntitiesIndex netexEntitiesIndex = testData .netexEntitiesIndex(journeyPattern, serviceJourney) .create(); @@ -440,9 +464,10 @@ void testValidateServiceJourneyWithStopAreaFollowedByStopArea() { @Test void testValidateServiceJourneyWithStopAreaFollowedByStopAreaNonIncreasingTime() { NetexEntitiesTestFactory testData = new NetexEntitiesTestFactory(); - JourneyPattern journeyPattern = testData.journeyPattern().create(); + NetexEntitiesTestFactory.CreateJourneyPattern createJourneyPattern = + testData.journeyPattern(1); ServiceJourney serviceJourney = testData - .serviceJourney(journeyPattern) + .serviceJourney(1, createJourneyPattern) .create(); // remove arrival time and departure time and add flex window on first stop and second stop @@ -475,6 +500,7 @@ void testValidateServiceJourneyWithStopAreaFollowedByStopAreaNonIncreasingTime() .withArrivalTime(null) .withDepartureTime(null); + JourneyPattern journeyPattern = createJourneyPattern.create(); NetexEntitiesIndex netexEntitiesIndex = testData .netexEntitiesIndex(journeyPattern, serviceJourney) .create(); @@ -503,9 +529,10 @@ void testValidateServiceJourneyWithStopAreaFollowedByStopAreaNonIncreasingTime() @Test void testValidateServiceJourneyWithStopAreaFollowedByRegularStopNonIncreasingTime() { NetexEntitiesTestFactory testData = new NetexEntitiesTestFactory(); - JourneyPattern journeyPattern = testData.journeyPattern().create(); + NetexEntitiesTestFactory.CreateJourneyPattern createJourneyPattern = + testData.journeyPattern(1); ServiceJourney serviceJourney = testData - .serviceJourney(journeyPattern) + .serviceJourney(1, createJourneyPattern) .create(); // remove arrival time and departure time and add flex window on first stop @@ -526,6 +553,7 @@ void testValidateServiceJourneyWithStopAreaFollowedByRegularStopNonIncreasingTim .withArrivalTime(firstPassingTime.getLatestArrivalTime().minusMinutes(1)) .withDepartureTime(null); + JourneyPattern journeyPattern = createJourneyPattern.create(); NetexEntitiesIndex netexEntitiesIndex = testData .netexEntitiesIndex(journeyPattern, serviceJourney) .create(); diff --git a/src/test/java/no/entur/antu/validation/validator/servicejourney/servicealteration/InvalidServiceAlterationValidatorTest.java b/src/test/java/no/entur/antu/validation/validator/servicejourney/servicealteration/InvalidServiceAlterationValidatorTest.java index b8b68e23..a0997dd8 100644 --- a/src/test/java/no/entur/antu/validation/validator/servicejourney/servicealteration/InvalidServiceAlterationValidatorTest.java +++ b/src/test/java/no/entur/antu/validation/validator/servicejourney/servicealteration/InvalidServiceAlterationValidatorTest.java @@ -4,6 +4,8 @@ import static org.hamcrest.Matchers.is; import static org.junit.jupiter.api.Assertions.assertTrue; +import java.time.LocalDate; +import java.util.List; import java.util.stream.IntStream; import no.entur.antu.netextestdata.NetexEntitiesTestFactory; import no.entur.antu.validation.ValidationTest; @@ -25,20 +27,33 @@ private ValidationReport runValidation( ); } + private NetexEntitiesTestFactory.CreateDatedServiceJourney datedServiceJourneyDraft( + int id, + NetexEntitiesTestFactory testData + ) { + return testData.datedServiceJourney( + id, + testData.serviceJourney(id, testData.journeyPattern(id)), + testData.operatingDay(id, LocalDate.of(2024, 12, 1)) + ); + } + @Test void testCorrectServiceAlterationExists() { NetexEntitiesTestFactory testData = new NetexEntitiesTestFactory(); - DatedServiceJourney datedServiceJourneyReplaced = testData - .datedServiceJourney(1) - .withId(1) + DatedServiceJourney datedServiceJourneyReplaced = datedServiceJourneyDraft( + 1, + testData + ) .withServiceAlteration(ServiceAlterationEnumeration.REPLACED) .create(); - DatedServiceJourney datedServiceJourneyNew = testData - .datedServiceJourney(2) - .withId(2) - .withDatedServiceJourneyRef(1) // Reference to replaced + DatedServiceJourney datedServiceJourneyNew = datedServiceJourneyDraft( + 2, + testData + ) + .withDatedServiceJourneyRef(testData.datedServiceJourney(1, null, null)) // Reference to replaced .create(); ValidationReport validationReport = runValidation( @@ -61,24 +76,25 @@ void testCorrectServiceAlterationExistsForMultipleDSJs() { NetexEntitiesTestFactory.CreateNetexEntitiesIndex createNetexEntitiesIndex = testData.netexEntitiesIndex(); - IntStream - .of(1, 2, 3) - .mapToObj(i -> - testData - .datedServiceJourney(i) - .withId(i) - .withServiceAlteration(ServiceAlterationEnumeration.REPLACED) - .create() - ) + List replacedDatedServiceJourneys = + IntStream + .of(1, 2, 3) + .mapToObj(i -> + datedServiceJourneyDraft(i, testData) + .withServiceAlteration(ServiceAlterationEnumeration.REPLACED) + ) + .toList(); + + replacedDatedServiceJourneys + .stream() + .map(NetexEntitiesTestFactory.CreateDatedServiceJourney::create) .forEach(createNetexEntitiesIndex::addDatedServiceJourneys); IntStream .of(1, 2, 3) .mapToObj(i -> - testData - .datedServiceJourney(i + 3) - .withId(i + 3) - .withDatedServiceJourneyRef(i) // Reference to replaced + datedServiceJourneyDraft(i + 3, testData) + .withDatedServiceJourneyRef(replacedDatedServiceJourneys.get(i - 1)) // Reference to replaced .create() ) .forEach(createNetexEntitiesIndex::addDatedServiceJourneys); @@ -94,23 +110,19 @@ void testCorrectServiceAlterationExistsForMultipleDSJs() { void testServiceAlterationMissing() { NetexEntitiesTestFactory testData = new NetexEntitiesTestFactory(); - DatedServiceJourney datedServiceJourneyReplaced = testData - .datedServiceJourney(1) - .withId(1) - .create(); + NetexEntitiesTestFactory.CreateDatedServiceJourney datedServiceJourneyReplaced = + datedServiceJourneyDraft(1, testData); - DatedServiceJourney datedServiceJourneyNew = testData - .datedServiceJourney(2) - .withId(2) - .withDatedServiceJourneyRef(1) // Reference to replaced - .create(); + NetexEntitiesTestFactory.CreateDatedServiceJourney datedServiceJourneyNew = + datedServiceJourneyDraft(2, testData) + .withDatedServiceJourneyRef(datedServiceJourneyReplaced); // Reference to replaced ValidationReport validationReport = runValidation( testData .netexEntitiesIndex() .addDatedServiceJourneys( - datedServiceJourneyReplaced, - datedServiceJourneyNew + datedServiceJourneyReplaced.create(), + datedServiceJourneyNew.create() ) .create() ); @@ -134,18 +146,24 @@ void testServiceAlterationMissingForMultipleDSJs() { NetexEntitiesTestFactory.CreateNetexEntitiesIndex createNetexEntitiesIndex = testData.netexEntitiesIndex(); - IntStream - .of(1, 2, 3) - .mapToObj(i -> testData.datedServiceJourney(i).withId(i).create()) + List datedServiceJourneysWithNoServiceAlteration = + IntStream + .of(1, 2, 3) + .mapToObj(i -> datedServiceJourneyDraft(i, testData)) + .toList(); + + datedServiceJourneysWithNoServiceAlteration + .stream() + .map(NetexEntitiesTestFactory.CreateDatedServiceJourney::create) .forEach(createNetexEntitiesIndex::addDatedServiceJourneys); IntStream .of(1, 2, 3) .mapToObj(i -> - testData - .datedServiceJourney(i + 3) - .withId(i + 3) - .withDatedServiceJourneyRef(i) // Reference to replaced + datedServiceJourneyDraft(i + 3, testData) + .withDatedServiceJourneyRef( + datedServiceJourneysWithNoServiceAlteration.get(i - 1) + ) // Reference to replaced .create() ) .forEach(createNetexEntitiesIndex::addDatedServiceJourneys); @@ -170,24 +188,20 @@ void testServiceAlterationMissingForMultipleDSJs() { void testUnexpectedServiceAlteration() { NetexEntitiesTestFactory testData = new NetexEntitiesTestFactory(); - DatedServiceJourney datedServiceJourneyReplaced = testData - .datedServiceJourney(1) - .withId(1) - .withServiceAlteration(ServiceAlterationEnumeration.CANCELLATION) - .create(); + NetexEntitiesTestFactory.CreateDatedServiceJourney cancelledDatedServiceJourney = + datedServiceJourneyDraft(1, testData) + .withServiceAlteration(ServiceAlterationEnumeration.CANCELLATION); - DatedServiceJourney datedServiceJourneyNew = testData - .datedServiceJourney(2) - .withId(2) - .withDatedServiceJourneyRef(1) // Reference to replaced - .create(); + NetexEntitiesTestFactory.CreateDatedServiceJourney newDatedServiceJourney = + datedServiceJourneyDraft(2, testData) + .withDatedServiceJourneyRef(cancelledDatedServiceJourney); // Reference to cancelled ValidationReport validationReport = runValidation( testData .netexEntitiesIndex() .addDatedServiceJourneys( - datedServiceJourneyReplaced, - datedServiceJourneyNew + cancelledDatedServiceJourney.create(), + newDatedServiceJourney.create() ) .create() ); diff --git a/src/test/java/no/entur/antu/validation/validator/servicejourney/servicealteration/MissingReplacementValidatorTest.java b/src/test/java/no/entur/antu/validation/validator/servicejourney/servicealteration/MissingReplacementValidatorTest.java index 22e99e9e..4cdb3a71 100644 --- a/src/test/java/no/entur/antu/validation/validator/servicejourney/servicealteration/MissingReplacementValidatorTest.java +++ b/src/test/java/no/entur/antu/validation/validator/servicejourney/servicealteration/MissingReplacementValidatorTest.java @@ -4,6 +4,7 @@ import static org.hamcrest.Matchers.is; import static org.junit.jupiter.api.Assertions.assertTrue; +import java.time.LocalDate; import java.util.stream.IntStream; import no.entur.antu.netextestdata.NetexEntitiesTestFactory; import no.entur.antu.validation.ValidationTest; @@ -11,7 +12,6 @@ import org.entur.netex.validation.validator.ValidationReport; import org.entur.netex.validation.validator.ValidationReportEntry; import org.junit.jupiter.api.Test; -import org.rutebanken.netex.model.DatedServiceJourney; import org.rutebanken.netex.model.ServiceAlterationEnumeration; class MissingReplacementValidatorTest extends ValidationTest { @@ -25,28 +25,35 @@ private ValidationReport runValidation( ); } + private NetexEntitiesTestFactory.CreateDatedServiceJourney datedServiceJourneyDraft( + int id, + NetexEntitiesTestFactory testData + ) { + return testData.datedServiceJourney( + id, + testData.serviceJourney(id, testData.journeyPattern(id)), + testData.operatingDay(id, LocalDate.parse("2024-12-01")) + ); + } + @Test void testCorrectReplacementExists() { NetexEntitiesTestFactory testData = new NetexEntitiesTestFactory(); - DatedServiceJourney datedServiceJourneyReplaced = testData - .datedServiceJourney(1) - .withId(1) - .withServiceAlteration(ServiceAlterationEnumeration.REPLACED) - .create(); + NetexEntitiesTestFactory.CreateDatedServiceJourney datedServiceJourneyReplaced = + datedServiceJourneyDraft(1, testData) + .withServiceAlteration(ServiceAlterationEnumeration.REPLACED); - DatedServiceJourney datedServiceJourneyNew = testData - .datedServiceJourney(2) - .withId(2) - .withDatedServiceJourneyRef(1) // Reference to replaced - .create(); + NetexEntitiesTestFactory.CreateDatedServiceJourney datedServiceJourneyNew = + datedServiceJourneyDraft(2, testData) + .withDatedServiceJourneyRef(datedServiceJourneyReplaced); // Reference to replaced ValidationReport validationReport = runValidation( testData .netexEntitiesIndex() .addDatedServiceJourneys( - datedServiceJourneyReplaced, - datedServiceJourneyNew + datedServiceJourneyReplaced.create(), + datedServiceJourneyNew.create() ) .create() ); @@ -58,23 +65,19 @@ void testCorrectReplacementExists() { void testReplacementDoesNotExists() { NetexEntitiesTestFactory testData = new NetexEntitiesTestFactory(); - DatedServiceJourney datedServiceJourneyReplaced = testData - .datedServiceJourney(1) - .withId(1) - .withServiceAlteration(ServiceAlterationEnumeration.REPLACED) - .create(); + NetexEntitiesTestFactory.CreateDatedServiceJourney datedServiceJourneyReplaced = + datedServiceJourneyDraft(1, testData) + .withServiceAlteration(ServiceAlterationEnumeration.REPLACED); - DatedServiceJourney datedServiceJourneyNew = testData - .datedServiceJourney(2) - .withId(2) - .create(); + NetexEntitiesTestFactory.CreateDatedServiceJourney datedServiceJourneyNew = + datedServiceJourneyDraft(2, testData); ValidationReport validationReport = runValidation( testData .netexEntitiesIndex() .addDatedServiceJourneys( - datedServiceJourneyReplaced, - datedServiceJourneyNew + datedServiceJourneyReplaced.create(), + datedServiceJourneyNew.create() ) .create() ); @@ -101,9 +104,7 @@ void testReplacementMissingForMultipleDSJs() { IntStream .of(1, 2, 3) .mapToObj(i -> - testData - .datedServiceJourney(i) - .withId(i) + datedServiceJourneyDraft(i, testData) .withServiceAlteration(ServiceAlterationEnumeration.REPLACED) .create() ) diff --git a/src/test/java/no/entur/antu/validation/validator/servicejourney/speed/UnexpectedSpeedValidatorTest.java b/src/test/java/no/entur/antu/validation/validator/servicejourney/speed/UnexpectedSpeedValidatorTest.java index 7f887592..2b4c2d3d 100644 --- a/src/test/java/no/entur/antu/validation/validator/servicejourney/speed/UnexpectedSpeedValidatorTest.java +++ b/src/test/java/no/entur/antu/validation/validator/servicejourney/speed/UnexpectedSpeedValidatorTest.java @@ -14,7 +14,6 @@ import org.entur.netex.validation.validator.model.ScheduledStopPointId; import org.junit.jupiter.api.Test; import org.rutebanken.netex.model.AllVehicleModesOfTransportEnumeration; -import org.rutebanken.netex.model.JourneyPattern; import org.rutebanken.netex.model.PassengerStopAssignment; import org.rutebanken.netex.model.ServiceJourney; @@ -142,14 +141,13 @@ void multipleSpeedViolationShouldBeDetected() { @Test void testSameDepartureArrivalTimeErrorThrown() { NetexEntitiesTestFactory testData = new NetexEntitiesTestFactory(); - JourneyPattern journeyPattern = testData - .journeyPattern() - .withNumberOfStopPointInJourneyPattern(2) - .create(); + NetexEntitiesTestFactory.CreateJourneyPattern journeyPattern = testData + .journeyPattern(1) + .withNumberOfStopPointInJourneyPattern(2); // Setting departureTimeOffset to 0, for making the departure time same for both passingTimes. ServiceJourney serviceJourney = testData - .serviceJourney(journeyPattern) + .serviceJourney(1, journeyPattern) .withCreateTimetabledPassingTimes( testData.timetabledPassingTimes().withDepartureTimeOffset(0) ) @@ -162,7 +160,9 @@ void testSameDepartureArrivalTimeErrorThrown() { new QuayCoordinates(6.622312, 60.481548), new QuayCoordinates(6.632312, 60.491548) ), - testData.netexEntitiesIndex(journeyPattern, serviceJourney).create() + testData + .netexEntitiesIndex(journeyPattern.create(), serviceJourney) + .create() ); assertThat(validationReport.getValidationReportEntries().size(), is(1)); @@ -190,14 +190,18 @@ void testPassengerStopAssignmentsInLineFileAndNotOnCommonFileShouldBeOk() { ); NetexEntitiesTestFactory testData = new NetexEntitiesTestFactory(); - JourneyPattern journeyPattern = testData.journeyPattern().create(); + NetexEntitiesTestFactory.CreateJourneyPattern createJourneyPattern = + testData.journeyPattern(1); ServiceJourney serviceJourney = testData - .serviceJourney(journeyPattern) + .serviceJourney(1, createJourneyPattern) .create(); serviceJourney.withTransportMode(AllVehicleModesOfTransportEnumeration.BUS); NetexEntitiesTestFactory.CreateNetexEntitiesIndex createNetexEntitiesIndex = - testData.netexEntitiesIndex(journeyPattern, serviceJourney); + testData.netexEntitiesIndex( + createJourneyPattern.create(), + serviceJourney + ); mockNoQuayIdsInNetexDataRepository(); @@ -208,7 +212,7 @@ void testPassengerStopAssignmentsInLineFileAndNotOnCommonFileShouldBeOk() { ); PassengerStopAssignment passengerStopAssignment = testData - .passengerStopAssignment() + .passengerStopAssignment(i + 1) .withScheduleStopPointId(i + 1) .withStopPlaceId(i + 1) .withQuayId(i + 1) @@ -229,14 +233,18 @@ void testPassengerStopAssignmentsInLineFileAndNotOnCommonFileShouldBeOk() { @Test void testNoPassengerStopAssignmentsFoundShouldIgnoreValidationGracefully() { NetexEntitiesTestFactory testData = new NetexEntitiesTestFactory(); - JourneyPattern journeyPattern = testData.journeyPattern().create(); + NetexEntitiesTestFactory.CreateJourneyPattern createJourneyPattern = + testData.journeyPattern(1); ServiceJourney serviceJourney = testData - .serviceJourney(journeyPattern) + .serviceJourney(1, createJourneyPattern) .create(); serviceJourney.withTransportMode(AllVehicleModesOfTransportEnumeration.BUS); NetexEntitiesTestFactory.CreateNetexEntitiesIndex createNetexEntitiesIndex = - testData.netexEntitiesIndex(journeyPattern, serviceJourney); + testData.netexEntitiesIndex( + createJourneyPattern.create(), + serviceJourney + ); mockNoQuayIdsInNetexDataRepository(); @@ -251,15 +259,18 @@ private ValidationReport runTestWithQuayCoordinates( List quayCoordinates ) { NetexEntitiesTestFactory testData = new NetexEntitiesTestFactory(); - JourneyPattern journeyPattern = testData.journeyPattern().create(); + NetexEntitiesTestFactory.CreateJourneyPattern createJourneyPattern = + testData.journeyPattern(1); ServiceJourney serviceJourney = testData - .serviceJourney(journeyPattern) + .serviceJourney(1, createJourneyPattern) .create(); serviceJourney.withTransportMode(AllVehicleModesOfTransportEnumeration.BUS); return runTestWith( quayCoordinates, - testData.netexEntitiesIndex(journeyPattern, serviceJourney).create() + testData + .netexEntitiesIndex(createJourneyPattern.create(), serviceJourney) + .create() ); } diff --git a/src/test/java/no/entur/antu/validation/validator/servicelink/distance/UnexpectedDistanceInServiceLinkValidatorTest.java b/src/test/java/no/entur/antu/validation/validator/servicelink/distance/UnexpectedDistanceInServiceLinkValidatorTest.java index f410c041..67ef670c 100644 --- a/src/test/java/no/entur/antu/validation/validator/servicelink/distance/UnexpectedDistanceInServiceLinkValidatorTest.java +++ b/src/test/java/no/entur/antu/validation/validator/servicelink/distance/UnexpectedDistanceInServiceLinkValidatorTest.java @@ -386,7 +386,7 @@ private ValidationReport runTestWithDirectPositionType( NetexEntitiesTestFactory testData = new NetexEntitiesTestFactory(); ServiceLink serviceLink = testData - .serviceLink(fromStopPointId.id(), toStopPointId.id()) + .serviceLink(1, fromStopPointId.id(), toStopPointId.id()) .withLineStringPositions(lineStringCoordinates) .create(); @@ -418,7 +418,7 @@ private ValidationReport runTestWith( NetexEntitiesTestFactory testData = new NetexEntitiesTestFactory(); ServiceLink serviceLink = testData - .serviceLink(fromStopPointId.id(), toStopPointId.id()) + .serviceLink(1, fromStopPointId.id(), toStopPointId.id()) .withLineStringList(lineStringCoordinates) .create(); diff --git a/src/test/java/no/entur/antu/validation/validator/servicelink/stoppoints/MismatchedStopPointsValidatorTest.java b/src/test/java/no/entur/antu/validation/validator/servicelink/stoppoints/MismatchedStopPointsValidatorTest.java index 1d15af97..b3e872b8 100644 --- a/src/test/java/no/entur/antu/validation/validator/servicelink/stoppoints/MismatchedStopPointsValidatorTest.java +++ b/src/test/java/no/entur/antu/validation/validator/servicelink/stoppoints/MismatchedStopPointsValidatorTest.java @@ -108,32 +108,33 @@ void testServiceLinkMissing() { void testFromStopPointInServiceLinkDoesNotMatchesJourneyPattern() { NetexEntitiesTestFactory fragment = new NetexEntitiesTestFactory(); + NetexEntitiesTestFactory.CreateJourneyPattern createJourneyPattern = + fragment.journeyPattern(1); + int journeyPatternId = 1; StopPointInJourneyPattern fromStopPointInJourneyPattern = fragment - .stopPointInJourneyPattern(journeyPatternId) + .stopPointInJourneyPattern(1, createJourneyPattern) .withScheduledStopPointId(1) .create(); StopPointInJourneyPattern fromStopPointInServiceLink = fragment - .stopPointInJourneyPattern(journeyPatternId) + .stopPointInJourneyPattern(3, createJourneyPattern) .withScheduledStopPointId(3) .create(); StopPointInJourneyPattern toStopPoint = fragment - .stopPointInJourneyPattern(journeyPatternId) + .stopPointInJourneyPattern(2, createJourneyPattern) .withScheduledStopPointId(2) .create(); - JourneyPattern journeyPattern = fragment - .journeyPattern() - .withId(journeyPatternId) + JourneyPattern journeyPattern = createJourneyPattern .withStopPointsInJourneyPattern( List.of(fromStopPointInJourneyPattern, toStopPoint) ) .withServiceLinksInJourneyPattern( List.of( fragment - .linkInJourneyPattern(journeyPatternId) + .linkInJourneyPattern(1, createJourneyPattern) .withServiceLinkId(1) .create() ) @@ -171,32 +172,32 @@ void testFromStopPointInServiceLinkDoesNotMatchesJourneyPattern() { void testToStopPointInServiceLinkDoesNotMatchesJourneyPattern() { NetexEntitiesTestFactory fragment = new NetexEntitiesTestFactory(); - int journeyPatternId = 1; + NetexEntitiesTestFactory.CreateJourneyPattern createJourneyPattern = + fragment.journeyPattern(1); + StopPointInJourneyPattern fromStopPoint = fragment - .stopPointInJourneyPattern(journeyPatternId) + .stopPointInJourneyPattern(1, createJourneyPattern) .withScheduledStopPointId(1) .create(); StopPointInJourneyPattern toStopPointInJourneyPattern = fragment - .stopPointInJourneyPattern(journeyPatternId) + .stopPointInJourneyPattern(2, createJourneyPattern) .withScheduledStopPointId(2) .create(); StopPointInJourneyPattern toStopPointInServiceLink = fragment - .stopPointInJourneyPattern(journeyPatternId) + .stopPointInJourneyPattern(3, createJourneyPattern) .withScheduledStopPointId(3) .create(); - JourneyPattern journeyPattern = fragment - .journeyPattern() - .withId(journeyPatternId) + JourneyPattern journeyPattern = createJourneyPattern .withStopPointsInJourneyPattern( List.of(fromStopPoint, toStopPointInJourneyPattern) ) .withServiceLinksInJourneyPattern( List.of( fragment - .linkInJourneyPattern(journeyPatternId) + .linkInJourneyPattern(1, createJourneyPattern) .withServiceLinkId(1) .create() ) @@ -276,28 +277,30 @@ private List createJourneyPatterns( ) { NetexEntitiesTestFactory fragment = new NetexEntitiesTestFactory(); - BiFunction stopPoint = ( - journeyPatternId, - stoPointId - ) -> - fragment - .stopPointInJourneyPattern(journeyPatternId) - .withScheduledStopPointId( - Integer.parseInt(journeyPatternId + "" + stoPointId) - ) - .create(); + BiFunction stopPoint = + (stopPointId, journeyPatternRef) -> + fragment + .stopPointInJourneyPattern(stopPointId, journeyPatternRef) + .withScheduledStopPointId(stopPointId) + .create(); return IntStream .rangeClosed(1, numberOfJourneyPatterns) - .mapToObj(journeyPatternId -> - fragment - .journeyPattern() - .withId(journeyPatternId) + .mapToObj(journeyPatternId -> { + NetexEntitiesTestFactory.CreateJourneyPattern createJourneyPattern = + fragment.journeyPattern(journeyPatternId); + + return createJourneyPattern .withStopPointsInJourneyPattern( IntStream .rangeClosed(1, numberOfStopPointsInJourneyPattern) .mapToObj(stopPointInJourneyPatternId -> - stopPoint.apply(journeyPatternId, stopPointInJourneyPatternId) + stopPoint.apply( + Integer.parseInt( + journeyPatternId + "" + stopPointInJourneyPatternId + ), + createJourneyPattern + ) ) .toList() ) @@ -307,7 +310,7 @@ private List createJourneyPatterns( .rangeClosed(1, numberOfStopPointsInJourneyPattern - 1) .mapToObj(serviceLinkId -> fragment - .linkInJourneyPattern(journeyPatternId) + .linkInJourneyPattern(1, createJourneyPattern) .withServiceLinkId( Integer.parseInt(journeyPatternId + "" + serviceLinkId) ) @@ -315,8 +318,8 @@ private List createJourneyPatterns( ) .toList() ) - .create() - ) + .create(); + }) .toList(); } }