diff --git a/src/test/java/no/entur/antu/netextestdata/NetexEntitiesTestFactory.java b/src/test/java/no/entur/antu/netextestdata/NetexEntitiesTestFactory.java index abeb2eea..d1b610e5 100644 --- a/src/test/java/no/entur/antu/netextestdata/NetexEntitiesTestFactory.java +++ b/src/test/java/no/entur/antu/netextestdata/NetexEntitiesTestFactory.java @@ -1,9 +1,10 @@ package no.entur.antu.netextestdata; import static no.entur.antu.netextestdata.MappingSupport.createJaxbElement; -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 +14,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; @@ -23,8 +25,6 @@ import net.opengis.gml._3.PolygonType; import org.entur.netex.index.api.NetexEntitiesIndex; import org.entur.netex.index.impl.NetexEntitiesIndexImpl; -import org.entur.netex.validation.validator.model.ScheduledStopPointId; -import org.entur.netex.validation.validator.model.ServiceJourneyId; import org.rutebanken.netex.model.*; public class NetexEntitiesTestFactory { @@ -33,113 +33,138 @@ 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 CreateTimetabledPassingTimes timetabledPassingTimes() { - return new CreateTimetabledPassingTimes(); + public CreateServiceJourney serviceJourney( + int id, + CreateJourneyPattern journeyPattern + ) { + return serviceJourney(id, new CreateLine(1), journeyPattern); } - 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) ) .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 +191,70 @@ public CreateNetexEntitiesIndex netexEntitiesIndex( .addFlexibleStopPlace(flexibleStopPlace); } - public static class CreateFlexibleArea { + public static ScheduledStopPointRefStructure createScheduledStopPointRef( + int id + ) { + return new ScheduledStopPointRefStructure() + .withRef("TST:ScheduledStopPoint:" + id); + } - private int id = 1; + public static QuayRefStructure createQuayRef(int id) { + return new QuayRefStructure().withRef("TST:Quay:" + id); + } - private List coordinates; + public static StopPlaceRefStructure createStopPointRef(int id) { + return new StopPlaceRefStructure().withRef("TST:StopPoint:" + id); + } - public CreateFlexibleArea withId(int id) { + public static ServiceLinkRefStructure createServiceLinkRef(int id) { + return new ServiceLinkRefStructure().withRef("TST:ServiceLink:" + id); + } + + public static VehicleJourneyRefStructure createServiceJourneyRef(int id) { + return new VehicleJourneyRefStructure().withRef("TST:ServiceJourney:" + id); + } + + public static DestinationDisplayRefStructure createDestinationDisplayRef( + int id + ) { + return new DestinationDisplayRefStructure() + .withRef("TST:DestinationDisplay:" + id); + } + + public interface createRef { + R refObject(); + } + + /** + * Abstract class for automatic handling of entity reference. + * It creates the reference using reflection, based on the integer id provided + * in the constructor + */ + public abstract static class CreateEntity { + + protected final int id; + + public CreateEntity(int id) { this.id = id; - return this; + } + + 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(int id) { + super(id); } public CreateFlexibleArea withCoordinates(List coordinates) { @@ -189,7 +269,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 +283,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 +299,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,79 +308,63 @@ public FlexibleStopPlace create() { } } - public static class CreatePassengerStopAssignment { - - private int id; + public static class CreatePassengerStopAssignment + extends CreateEntity { - private String scheduleStopPointRef; + private ScheduledStopPointRefStructure scheduleStopPointRef; - private String stopPlaceRef; + private StopPlaceRefStructure stopPlaceRef; - private String quayRef; + private QuayRefStructure quayRef; - public CreatePassengerStopAssignment withId(int id) { - this.id = id; - return this; + public CreatePassengerStopAssignment(int id) { + super(id); } - public CreatePassengerStopAssignment withScheduleStopPointId( - int scheduleStopPointId + public CreatePassengerStopAssignment withScheduledStopPointRef( + ScheduledStopPointRefStructure scheduledStopPointRef ) { - this.scheduleStopPointRef = - "TST:ScheduledStopPoint:" + scheduleStopPointId; + this.scheduleStopPointRef = scheduledStopPointRef; return this; } - public CreatePassengerStopAssignment withStopPlaceId(int stopPlaceId) { - this.stopPlaceRef = "TST:StopPlace:" + stopPlaceId; + public CreatePassengerStopAssignment withStopPlaceRef( + StopPlaceRefStructure stopPlaceRef + ) { + this.stopPlaceRef = stopPlaceRef; return this; } - public CreatePassengerStopAssignment withQuayId(int quayId) { - this.quayRef = "TST:Quay:" + quayId; + public CreatePassengerStopAssignment withQuayRef(QuayRefStructure QuayRef) { + this.quayRef = QuayRef; return this; } public PassengerStopAssignment create() { return new PassengerStopAssignment() - .withId("TST:PassengerStopAssignment:" + id) - .withScheduledStopPointRef( - createWrappedRef( - scheduleStopPointRef, - ScheduledStopPointRefStructure.class - ) - ) - .withQuayRef(createWrappedRef(quayRef, QuayRefStructure.class)) - .withStopPlaceRef( - createWrappedRef(stopPlaceRef, StopPlaceRefStructure.class) - ); + .withId(ref()) + .withScheduledStopPointRef(createJaxbElement(scheduleStopPointRef)) + .withQuayRef(createJaxbElement(quayRef)) + .withStopPlaceRef(createJaxbElement(stopPlaceRef)); } } - 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 +375,142 @@ 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(calendarDate.format(DATE_FORMATTER)) + .withId(ref()) .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 CreateLine withId(int id) { - this.id = 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 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,40 +520,38 @@ 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; + private CreateLine lineRef; - public CreateRoute withId(int id) { - this.id = id; - return this; + public CreateRoute(int id) { + super(id); } - public CreateRoute withLine(Line line) { - this.line = line; + public CreateRoute withLine(CreateLine lineRef) { + this.lineRef = lineRef; return this; } public Route create() { return new Route() + .withId(ref()) .withLineRef( - createJaxbElement(new LineRefStructure().withRef(line.getId())) - ) - .withId("TST:Route:" + id); + createJaxbElement(new LineRefStructure().withRef(lineRef.ref())) + ); } } - public static class CreateJourneyPattern { + public static class CreateJourneyPattern + extends CreateEntity { - private Route route; - private int id = 1; + private CreateRoute routeRef; private int numberOfStopPointInJourneyPattern = 4; private int numberOfServiceLinksInJourneyPattern = 3; @@ -439,13 +562,12 @@ 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) { - this.route = route; + public CreateJourneyPattern withRoute(CreateRoute routeRef) { + this.routeRef = routeRef; return this; } @@ -487,17 +609,12 @@ 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) { + if (routeRef != null) { journeyPattern.withRouteRef( - new RouteRefStructure().withRef(route.getId()) + new RouteRefStructure().withRef(routeRef.ref()) ); } @@ -539,14 +656,17 @@ 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); + .withScheduledStopPointRef( + createScheduledStopPointRef(index + 1) + ); // Setting destination display id for first and last stop point if (index == 0 || index == numberOfStopPointInJourneyPattern - 1) { - createStopPointInJourneyPattern.withDestinationDisplayId(index + 1); + createStopPointInJourneyPattern.withDestinationDisplayId( + createDestinationDisplayRef(index + 1) + ); } return createStopPointInJourneyPattern.create(); @@ -562,10 +682,9 @@ 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); + .withServiceLinkRef(createServiceLinkRef(index + 1)); return createLinkInJourneyPattern.create(); }) @@ -574,29 +693,20 @@ 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; + private ScheduledStopPointRefStructure scheduledStopPointRef; + private DestinationDisplayRefStructure destinationDisplayRef; private boolean forAlighting = false; 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(Integer.parseInt(journeyPatternRef.id + "" + id)); } public CreateStopPointInJourneyPattern withOrder(int order) { @@ -604,17 +714,17 @@ public CreateStopPointInJourneyPattern withOrder(int order) { return this; } - public CreateStopPointInJourneyPattern withScheduledStopPointId( - int scheduledStopPointId + public CreateStopPointInJourneyPattern withScheduledStopPointRef( + ScheduledStopPointRefStructure scheduledStopPointRef ) { - this.scheduledStopPointId = scheduledStopPointId; + this.scheduledStopPointRef = scheduledStopPointRef; return this; } public CreateStopPointInJourneyPattern withDestinationDisplayId( - int destinationDisplayId + DestinationDisplayRefStructure destinationDisplayRef ) { - this.destinationDisplayId = destinationDisplayId; + this.destinationDisplayRef = destinationDisplayRef; return this; } @@ -635,21 +745,13 @@ 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 - ) - ); - if (destinationDisplayId > 0) { + .withScheduledStopPointRef(createJaxbElement(scheduledStopPointRef)); + + if (destinationDisplayRef != null) { stopPointInJourneyPattern.setDestinationDisplayRef( - createDestinationDisplayRef( - "TST:DestinationDisplay:" + destinationDisplayId - ) - .getValue() + createJaxbElement(destinationDisplayRef).getValue() ); } @@ -660,20 +762,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; + private ServiceLinkRefStructure serviceLinkRef; - public CreateLinkInJourneyPattern(int journeyPatternId) { - this.journeyPatternId = journeyPatternId; - } - - public CreateLinkInJourneyPattern withId(int id) { - this.id = id; - return this; + public CreateLinkInJourneyPattern( + int id, + CreateJourneyPattern journeyPatternRef + ) { + super(Integer.parseInt(journeyPatternRef.id + "" + id)); } public CreateLinkInJourneyPattern withOrder(int order) { @@ -681,41 +780,39 @@ public CreateLinkInJourneyPattern withOrder(int order) { return this; } - public CreateLinkInJourneyPattern withServiceLinkId(int serviceLinkId) { - this.serviceLinkId = serviceLinkId; + public CreateLinkInJourneyPattern withServiceLinkRef( + ServiceLinkRefStructure serviceLinkRef + ) { + this.serviceLinkRef = serviceLinkRef; return this; } public LinkInJourneyPattern create() { return new LinkInJourneyPattern() - .withId("TST:LinkInJourneyPattern:" + journeyPatternId + "_" + id) + .withId(ref()) .withOrder(BigInteger.valueOf(order)) - .withServiceLinkRef( - new ServiceLinkRefStructure() - .withRef("TST:ServiceLink:" + serviceLinkId) - ); + .withServiceLinkRef(serviceLinkRef); } } - 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 lineRef; + private final CreateJourneyPattern journeyPattern; private CreateTimetabledPassingTimes createTimetabledPassingTimes; - public CreateDeadRun(Line line, JourneyPattern journeyPattern) { - this.line = line; + public CreateDeadRun( + int id, + CreateLine lineRef, + CreateJourneyPattern journeyPattern + ) { + super(id); + this.lineRef = lineRef; this.journeyPattern = journeyPattern; this.createTimetabledPassingTimes = new CreateTimetabledPassingTimes(); } - public CreateDeadRun withId(int id) { - this.id = id; - return this; - } - public CreateDeadRun withCreateTimetabledPassingTimes( CreateTimetabledPassingTimes createTimetabledPassingTimes ) { @@ -725,35 +822,46 @@ public CreateDeadRun withCreateTimetabledPassingTimes( public DeadRun create() { return new DeadRun() - .withId("TST:DeadRun:" + id) - .withLineRef(createLineRef(line.getId())) + .withId(ref()) + .withLineRef( + createJaxbElement(new LineRefStructure().withRef(lineRef.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 CreateServiceJourney { + public static class CreateServiceJourney + extends CreateEntity + implements createRef { - 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 VehicleJourneyRefStructure refObject() { + return NetexEntitiesTestFactory.createServiceJourneyRef(id); } public CreateServiceJourney withCreateTimetabledPassingTimes( @@ -765,32 +873,37 @@ 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; - private ScheduledStopPointId toPointRef; - private ServiceJourneyId fromJourneyRef; - private ServiceJourneyId toJourneyRef; + private ScheduledStopPointRefStructure fromPointRef; + private ScheduledStopPointRefStructure toPointRef; + private VehicleJourneyRefStructure fromJourneyRef; + private VehicleJourneyRefStructure toJourneyRef; - public CreateServiceJourneyInterchange withId(int id) { - this.id = id; - return this; + public CreateServiceJourneyInterchange(int id) { + super(id); } public CreateServiceJourneyInterchange withGuaranteed(boolean guaranteed) { @@ -806,28 +919,28 @@ public CreateServiceJourneyInterchange withMaximumWaitTime( } public CreateServiceJourneyInterchange withFromPointRef( - ScheduledStopPointId fromPointRef + ScheduledStopPointRefStructure fromPointRef ) { this.fromPointRef = fromPointRef; return this; } public CreateServiceJourneyInterchange withToPointRef( - ScheduledStopPointId toPointRef + ScheduledStopPointRefStructure toPointRef ) { this.toPointRef = toPointRef; return this; } public CreateServiceJourneyInterchange withFromJourneyRef( - ServiceJourneyId fromJourneyRef + VehicleJourneyRefStructure fromJourneyRef ) { this.fromJourneyRef = fromJourneyRef; return this; } public CreateServiceJourneyInterchange withToJourneyRef( - ServiceJourneyId toJourneyRef + VehicleJourneyRefStructure toJourneyRef ) { this.toJourneyRef = toJourneyRef; return this; @@ -836,32 +949,24 @@ public CreateServiceJourneyInterchange withToJourneyRef( public ServiceJourneyInterchange create() { ServiceJourneyInterchange serviceJourneyInterchange = new ServiceJourneyInterchange() - .withId("TST:ServiceJourneyInterchange:" + id) + .withId(ref()) .withGuaranteed(guaranteed) .withMaximumWaitTime(maximumWaitTime); if (fromPointRef != null) { - serviceJourneyInterchange.withFromPointRef( - new ScheduledStopPointRefStructure().withRef(fromPointRef.id()) - ); + serviceJourneyInterchange.withFromPointRef(fromPointRef); } if (toPointRef != null) { - serviceJourneyInterchange.withToPointRef( - new ScheduledStopPointRefStructure().withRef(toPointRef.id()) - ); + serviceJourneyInterchange.withToPointRef(toPointRef); } if (fromJourneyRef != null) { - serviceJourneyInterchange.withFromJourneyRef( - new VehicleJourneyRefStructure().withRef(fromJourneyRef.id()) - ); + serviceJourneyInterchange.withFromJourneyRef(fromJourneyRef); } if (toJourneyRef != null) { - serviceJourneyInterchange.withToJourneyRef( - new VehicleJourneyRefStructure().withRef(toJourneyRef.id()) - ); + serviceJourneyInterchange.withToJourneyRef(toJourneyRef); } return serviceJourneyInterchange; @@ -894,26 +999,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 StopPointInJourneyPatternRefStructure() + .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 +1041,7 @@ public CreateServiceLink withToScheduledStopPointRef( public CreateServiceLink withLineStringList( List lineStringPositions ) { - this.linkSequenceProjectionVersionStructure = + this.linkSequenceProjection_VersionStructure = new LinkSequenceProjection_VersionStructure() .withId("TST:ServiceLinkProjection:" + id) .withLineString( @@ -950,7 +1056,7 @@ public CreateServiceLink withLineStringList( public CreateServiceLink withLineStringPositions( List lineStringPositions ) { - this.linkSequenceProjectionVersionStructure = + this.linkSequenceProjection_VersionStructure = new LinkSequenceProjection_VersionStructure() .withId("TST:ServiceLinkProjection:" + id) .withLineString( @@ -964,15 +1070,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 +1268,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 13020d68..6c78368f 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 @@ -15,8 +15,8 @@ import org.entur.netex.validation.validator.model.QuayCoordinates; import org.entur.netex.validation.validator.model.QuayId; import org.entur.netex.validation.validator.model.ScheduledStopPointId; -import org.entur.netex.validation.validator.model.ServiceJourneyId; import org.junit.jupiter.api.Test; +import org.rutebanken.netex.model.ScheduledStopPointRefStructure; import org.rutebanken.netex.model.ServiceJourneyInterchange; class UnexpectedInterchangeDistanceValidatorTest extends ValidationTest { @@ -176,34 +176,32 @@ private ValidationReport runTestWithCoordinates( QuayCoordinates fromCoordinates = coordinates[idx1]; QuayCoordinates toCoordinates = coordinates[idx2]; - ScheduledStopPointId fromPointRef = new ScheduledStopPointId( - "TST:ScheduledStopPoint:" + idx1 - ); - ScheduledStopPointId toPointRef = new ScheduledStopPointId( - "TST:ScheduledStopPoint:" + idx2 - ); + ScheduledStopPointRefStructure fromPointRef = + NetexEntitiesTestFactory.createScheduledStopPointRef(idx1); + ScheduledStopPointRefStructure toPointRef = + NetexEntitiesTestFactory.createScheduledStopPointRef(idx2); mockGetCoordinates( - fromPointRef, + ScheduledStopPointId.of(fromPointRef), new QuayId("TST:Quay:" + idx1), fromCoordinates ); + mockGetCoordinates( - toPointRef, + ScheduledStopPointId.of(toPointRef), new QuayId("TST:Quay:" + idx2), toCoordinates ); return fragment - .serviceJourneyInterchange() - .withId(i) + .serviceJourneyInterchange(i) .withFromPointRef(fromPointRef) .withToPointRef(toPointRef) .withFromJourneyRef( - ServiceJourneyId.ofValidId("TST:ServiceJourney:" + idx1) + NetexEntitiesTestFactory.createServiceJourneyRef(idx1) ) .withToJourneyRef( - ServiceJourneyId.ofValidId("TST:ServiceJourney:" + idx2) + NetexEntitiesTestFactory.createServiceJourneyRef(idx2) ) .create(); }) 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 c3ebd330..c384cf01 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 @@ -17,11 +17,8 @@ import org.entur.netex.index.api.NetexEntitiesIndex; import org.entur.netex.validation.validator.ValidationReport; import org.entur.netex.validation.validator.ValidationReportEntry; -import org.entur.netex.validation.validator.model.ScheduledStopPointId; -import org.entur.netex.validation.validator.model.ServiceJourneyId; import org.hamcrest.CoreMatchers; import org.junit.jupiter.api.Test; -import org.rutebanken.netex.model.ServiceJourney; import org.rutebanken.netex.model.ServiceJourneyInterchange; class DuplicateInterchangesValidatorTest extends ValidationTest { @@ -196,50 +193,34 @@ private List createServiceJourneyInterchanges( int maxStartIndex = Math.max(startIndex, 0); - List serviceJourneys = fragment.createServiceJourneys( - fragment.journeyPattern().create(), - (numberOfServiceJourneyInterchanges + maxStartIndex) * 2 - ); + List serviceJourneys = + fragment.serviceJourneys( + fragment.journeyPattern(1), + (numberOfServiceJourneyInterchanges + maxStartIndex) * 2 + ); List duplicateIndexesList = Arrays .stream(duplicateIndexes) .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(serviceJourneys.get(id * 2).refObject()) + .withToJourneyRef(serviceJourneys.get((id * 2) + 1).refObject()) + .withFromPointRef( + NetexEntitiesTestFactory.createScheduledStopPointRef(id + 1) + ) + .withToPointRef( + NetexEntitiesTestFactory.createScheduledStopPointRef(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 93a0411f..b562063f 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 @@ -11,8 +11,8 @@ import org.entur.netex.validation.validator.ValidationReportEntry; import org.entur.netex.validation.validator.model.QuayId; import org.entur.netex.validation.validator.model.ScheduledStopPointId; -import org.entur.netex.validation.validator.model.ServiceJourneyId; import org.junit.jupiter.api.Test; +import org.rutebanken.netex.model.ScheduledStopPointRefStructure; import org.rutebanken.netex.model.ServiceJourney; import org.rutebanken.netex.model.ServiceJourneyInterchange; @@ -29,41 +29,46 @@ private ValidationReport runValidation( @Test void testAllMandatoryFieldArePresent() { - ScheduledStopPointId scheduledStopPointId1 = new ScheduledStopPointId( - "TST:ScheduledStopPoint:1" - ); - ScheduledStopPointId scheduledStopPointId2 = new ScheduledStopPointId( - "TST:ScheduledStopPoint:2" - ); + ScheduledStopPointRefStructure scheduledStopPointId1 = + NetexEntitiesTestFactory.createScheduledStopPointRef(1); + ScheduledStopPointRefStructure scheduledStopPointId2 = + NetexEntitiesTestFactory.createScheduledStopPointRef(2); NetexEntitiesTestFactory netexEntitiesFactory = new NetexEntitiesTestFactory(); - List serviceJourneys = - netexEntitiesFactory.createServiceJourneys( - netexEntitiesFactory.journeyPattern().create(), + List serviceJourneys = + netexEntitiesFactory.serviceJourneys( + netexEntitiesFactory.journeyPattern(1), 2 ); ServiceJourneyInterchange serviceJourneyInterchange = netexEntitiesFactory - .serviceJourneyInterchange() - .withId(1) - .withFromJourneyRef(ServiceJourneyId.ofValidId(serviceJourneys.get(0))) - .withToJourneyRef(ServiceJourneyId.ofValidId(serviceJourneys.get(1))) + .serviceJourneyInterchange(1) + .withFromJourneyRef(serviceJourneys.get(0).refObject()) + .withToJourneyRef(serviceJourneys.get(1).refObject()) .withFromPointRef(scheduledStopPointId1) .withToPointRef(scheduledStopPointId2) .create(); mockGetQuayId( - new ScheduledStopPointId(scheduledStopPointId1.id()), + ScheduledStopPointId.of(scheduledStopPointId1), new QuayId("TST:Quay:1") ); - mockGetQuayId(scheduledStopPointId2, new QuayId("TST:Quay:2")); + mockGetQuayId( + ScheduledStopPointId.of(scheduledStopPointId2), + new QuayId("TST:Quay:2") + ); ValidationReport validationReport = runValidation( netexEntitiesFactory .netexEntitiesIndex() - .addServiceJourneys(serviceJourneys.toArray(ServiceJourney[]::new)) + .addServiceJourneys( + serviceJourneys + .stream() + .map(NetexEntitiesTestFactory.CreateServiceJourney::create) + .toArray(ServiceJourney[]::new) + ) .addInterchanges(serviceJourneyInterchange) .create() ); @@ -73,36 +78,41 @@ void testAllMandatoryFieldArePresent() { @Test void testFromServiceJourneyRefMissing() { - ScheduledStopPointId scheduledStopPointId1 = new ScheduledStopPointId( - "TST:ScheduledStopPoint:1" - ); - ScheduledStopPointId scheduledStopPointId2 = new ScheduledStopPointId( - "TST:ScheduledStopPoint:2" - ); + ScheduledStopPointRefStructure scheduledStopPointId1 = + NetexEntitiesTestFactory.createScheduledStopPointRef(1); + ScheduledStopPointRefStructure scheduledStopPointId2 = + NetexEntitiesTestFactory.createScheduledStopPointRef(2); NetexEntitiesTestFactory netexEntitiesFactory = new NetexEntitiesTestFactory(); - ServiceJourney serviceJourney = netexEntitiesFactory - .serviceJourney(netexEntitiesFactory.journeyPattern().create()) - .create(); + NetexEntitiesTestFactory.CreateServiceJourney serviceJourney = + netexEntitiesFactory.serviceJourney( + 1, + netexEntitiesFactory.journeyPattern(1) + ); ServiceJourneyInterchange serviceJourneyInterchange = netexEntitiesFactory - .serviceJourneyInterchange() - .withId(1) - .withToJourneyRef(ServiceJourneyId.ofValidId(serviceJourney)) + .serviceJourneyInterchange(1) + .withToJourneyRef(serviceJourney.refObject()) .withFromPointRef(scheduledStopPointId1) .withToPointRef(scheduledStopPointId2) .create(); - mockGetQuayId(scheduledStopPointId1, new QuayId("TST:Quay:1")); + mockGetQuayId( + ScheduledStopPointId.of(scheduledStopPointId1), + new QuayId("TST:Quay:1") + ); - mockGetQuayId(scheduledStopPointId2, new QuayId("TST:Quay:2")); + mockGetQuayId( + ScheduledStopPointId.of(scheduledStopPointId2), + new QuayId("TST:Quay:2") + ); ValidationReport validationReport = runValidation( netexEntitiesFactory .netexEntitiesIndex() - .addServiceJourneys(serviceJourney) + .addServiceJourneys(serviceJourney.create()) .addInterchanges(serviceJourneyInterchange) .create() ); @@ -123,39 +133,41 @@ void testFromServiceJourneyRefMissing() { @Test void testToServiceJourneyRefMissing() { - ScheduledStopPointId scheduledStopPointId1 = new ScheduledStopPointId( - "TST:ScheduledStopPoint:1" - ); - ScheduledStopPointId scheduledStopPointId2 = new ScheduledStopPointId( - "TST:ScheduledStopPoint:2" - ); + ScheduledStopPointRefStructure scheduledStopPointId1 = + NetexEntitiesTestFactory.createScheduledStopPointRef(1); + ScheduledStopPointRefStructure scheduledStopPointId2 = + NetexEntitiesTestFactory.createScheduledStopPointRef(2); NetexEntitiesTestFactory netexEntitiesFactory = new NetexEntitiesTestFactory(); - ServiceJourney serviceJourney = netexEntitiesFactory - .serviceJourney(netexEntitiesFactory.journeyPattern().create()) - .create(); + NetexEntitiesTestFactory.CreateServiceJourney serviceJourney = + netexEntitiesFactory.serviceJourney( + 1, + netexEntitiesFactory.journeyPattern(1) + ); ServiceJourneyInterchange serviceJourneyInterchange = netexEntitiesFactory - .serviceJourneyInterchange() - .withId(1) - .withFromJourneyRef(ServiceJourneyId.ofValidId(serviceJourney)) + .serviceJourneyInterchange(1) + .withFromJourneyRef(serviceJourney.refObject()) .withFromPointRef(scheduledStopPointId1) .withToPointRef(scheduledStopPointId2) .create(); - mockGetQuayId(scheduledStopPointId1, new QuayId("TST:Quay:1")); + mockGetQuayId( + ScheduledStopPointId.of(scheduledStopPointId1), + new QuayId("TST:Quay:1") + ); mockGetQuayId( - new ScheduledStopPointId(scheduledStopPointId2.id()), + ScheduledStopPointId.of(scheduledStopPointId2), new QuayId("TST:Quay:2") ); ValidationReport validationReport = runValidation( netexEntitiesFactory .netexEntitiesIndex() - .addServiceJourneys(serviceJourney) + .addServiceJourneys(serviceJourney.create()) .addInterchanges(serviceJourneyInterchange) .create() ); @@ -176,31 +188,34 @@ void testToServiceJourneyRefMissing() { @Test void testFromPointRefMissing() { - ScheduledStopPointId scheduledStopPointId = new ScheduledStopPointId( - "TST:ScheduledStopPoint:1" - ); + ScheduledStopPointRefStructure scheduledStopPointId = + NetexEntitiesTestFactory.createScheduledStopPointRef(1); NetexEntitiesTestFactory netexEntitiesFactory = new NetexEntitiesTestFactory(); - ServiceJourney serviceJourney = netexEntitiesFactory - .serviceJourney(netexEntitiesFactory.journeyPattern().create()) - .create(); + NetexEntitiesTestFactory.CreateServiceJourney serviceJourney = + netexEntitiesFactory.serviceJourney( + 1, + netexEntitiesFactory.journeyPattern(1) + ); ServiceJourneyInterchange serviceJourneyInterchange = netexEntitiesFactory - .serviceJourneyInterchange() - .withId(1) - .withFromJourneyRef(ServiceJourneyId.ofValidId(serviceJourney)) - .withToJourneyRef(ServiceJourneyId.ofValidId(serviceJourney)) + .serviceJourneyInterchange(1) + .withFromJourneyRef(serviceJourney.refObject()) + .withToJourneyRef(serviceJourney.refObject()) .withToPointRef(scheduledStopPointId) .create(); - mockGetQuayId(scheduledStopPointId, new QuayId("TST:Quay:1")); + mockGetQuayId( + ScheduledStopPointId.of(scheduledStopPointId), + new QuayId("TST:Quay:1") + ); ValidationReport validationReport = runValidation( netexEntitiesFactory .netexEntitiesIndex() - .addServiceJourneys(serviceJourney) + .addServiceJourneys(serviceJourney.create()) .addInterchanges(serviceJourneyInterchange) .create() ); @@ -221,31 +236,34 @@ void testFromPointRefMissing() { @Test void testToPointRefMissing() { - ScheduledStopPointId scheduledStopPointId = new ScheduledStopPointId( - "TST:ScheduledStopPoint:1" - ); + ScheduledStopPointRefStructure scheduledStopPointId = + NetexEntitiesTestFactory.createScheduledStopPointRef(1); NetexEntitiesTestFactory netexEntitiesFactory = new NetexEntitiesTestFactory(); - ServiceJourney serviceJourney = netexEntitiesFactory - .serviceJourney(netexEntitiesFactory.journeyPattern().create()) - .create(); + NetexEntitiesTestFactory.CreateServiceJourney serviceJourney = + netexEntitiesFactory.serviceJourney( + 1, + netexEntitiesFactory.journeyPattern(1) + ); ServiceJourneyInterchange serviceJourneyInterchange = netexEntitiesFactory - .serviceJourneyInterchange() - .withId(1) - .withFromJourneyRef(ServiceJourneyId.ofValidId(serviceJourney)) - .withToJourneyRef(ServiceJourneyId.ofValidId(serviceJourney)) + .serviceJourneyInterchange(1) + .withFromJourneyRef(serviceJourney.refObject()) + .withToJourneyRef(serviceJourney.refObject()) .withFromPointRef(scheduledStopPointId) .create(); - mockGetQuayId(scheduledStopPointId, new QuayId("TST:Quay:1")); + mockGetQuayId( + ScheduledStopPointId.of(scheduledStopPointId), + new QuayId("TST:Quay:1") + ); ValidationReport validationReport = runValidation( netexEntitiesFactory .netexEntitiesIndex() - .addServiceJourneys(serviceJourney) + .addServiceJourneys(serviceJourney.create()) .addInterchanges(serviceJourneyInterchange) .create() ); 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 d95ebf5d..54a9426c 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( @@ -159,26 +159,20 @@ private ValidationReport runTestFor( NetexEntitiesTestFactory fragment = new NetexEntitiesTestFactory(); - ScheduledStopPointId fromPointRef = new ScheduledStopPointId( - "TST:ScheduledStopPoint:" + fromPointRefId - ); - ScheduledStopPointId toPointRef = new ScheduledStopPointId( - "TST:ScheduledStopPoint:" + toPointRefId - ); - - ServiceJourneyId fromServiceJourneyRef = new ServiceJourneyId( - "TST:ServiceJourney:" + fromServiceJourneyId - ); - ServiceJourneyId toServiceJourneyRef = new ServiceJourneyId( - "TST:ServiceJourney:" + toServiceJourneyId - ); - ServiceJourneyInterchange serviceJourneyInterchange = fragment - .serviceJourneyInterchange() - .withFromPointRef(fromPointRef) - .withToPointRef(toPointRef) - .withFromJourneyRef(fromServiceJourneyRef) - .withToJourneyRef(toServiceJourneyRef) + .serviceJourneyInterchange(1) + .withFromPointRef( + NetexEntitiesTestFactory.createScheduledStopPointRef(fromPointRefId) + ) + .withToPointRef( + NetexEntitiesTestFactory.createScheduledStopPointRef(toPointRefId) + ) + .withFromJourneyRef( + NetexEntitiesTestFactory.createServiceJourneyRef(fromServiceJourneyId) + ) + .withToJourneyRef( + NetexEntitiesTestFactory.createServiceJourneyRef(toServiceJourneyId) + ) .create(); mockGetServiceJourneyInterchangeInfo( 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 5d69b792..4b9a309c 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 @@ -18,8 +18,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.Line; -import org.rutebanken.netex.model.Route; class UnexpectedDistanceBetweenStopPointsValidatorTest extends ValidationTest { @@ -169,12 +167,16 @@ private ValidationReport runWithQuayCoordinates( ) { NetexEntitiesTestFactory testFragment = new NetexEntitiesTestFactory(); - Line line = testFragment.line().withTransportMode(transportMode).create(); + NetexEntitiesTestFactory.CreateLine line = testFragment + .line(1) + .withTransportMode(transportMode); - Route route = testFragment.route().withLine(line).create(); + NetexEntitiesTestFactory.CreateRoute route = testFragment + .route(1) + .withLine(line); NetexEntitiesTestFactory.CreateJourneyPattern createJourneyPattern = - testFragment.journeyPattern().withId(123).withRoute(route); + testFragment.journeyPattern(123).withRoute(route); if (coordinates.isEmpty()) { createJourneyPattern.withNumberOfStopPointInJourneyPattern(0); @@ -184,9 +186,10 @@ private ValidationReport runWithQuayCoordinates( .rangeClosed(1, coordinates.size()) .mapToObj(i -> testFragment - .stopPointInJourneyPattern(123) - .withId(i) - .withScheduledStopPointId(i) + .stopPointInJourneyPattern(i, createJourneyPattern) + .withScheduledStopPointRef( + NetexEntitiesTestFactory.createScheduledStopPointRef(i) + ) .create() ) .toList() @@ -196,8 +199,8 @@ private ValidationReport runWithQuayCoordinates( NetexEntitiesIndex netexEntitiesIndex = testFragment .netexEntitiesIndex() .addJourneyPatterns(createJourneyPattern.create()) - .addLine(line) - .addRoute(route) + .addLine(line.create()) + .addRoute(route.create()) .create(); return runTestWith(coordinates, netexEntitiesIndex); 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..532cff09 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,22 @@ 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( + NetexEntitiesTestFactory.createDestinationDisplayRef(1) + ); } - if (create.journeyPatternId() == 2 && create.stopPointId() == 1) { - create.createStopPointInJourneyPattern().withDestinationDisplayId(2); + if (context.journeyPatternId() == 2 && context.stopPointId() == 1) { + context + .createStopPointInJourneyPattern() + .withDestinationDisplayId( + NetexEntitiesTestFactory.createDestinationDisplayRef(2) + ); } - return create; + return context; } ); @@ -94,10 +102,18 @@ void testDifferentScheduledStopPoints() { numberOfStopPoints, create -> { if (create.journeyPatternId() == 1 && create.stopPointId() == 1) { - create.createStopPointInJourneyPattern().withScheduledStopPointId(1); + create + .createStopPointInJourneyPattern() + .withScheduledStopPointRef( + NetexEntitiesTestFactory.createScheduledStopPointRef(1) + ); } if (create.journeyPatternId() == 2 && create.stopPointId() == 1) { - create.createStopPointInJourneyPattern().withScheduledStopPointId(2); + create + .createStopPointInJourneyPattern() + .withScheduledStopPointRef( + NetexEntitiesTestFactory.createScheduledStopPointRef(2) + ); } return create; } @@ -148,36 +164,48 @@ 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 + ) + .withScheduledStopPointRef( + NetexEntitiesTestFactory.createScheduledStopPointRef( + stopPointIndex + ) + ) + .withDestinationDisplayId( + NetexEntitiesTestFactory.createDestinationDisplayRef( + 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..b2de16bf 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 @@ -12,6 +12,7 @@ import org.entur.netex.validation.validator.model.ScheduledStopPointId; import org.junit.jupiter.api.Test; import org.rutebanken.netex.model.JourneyPattern; +import org.rutebanken.netex.model.ScheduledStopPointRefStructure; class SameQuayRefValidatorTest extends ValidationTest { @@ -29,8 +30,7 @@ void testNoStopPointsInJourneyPattern() { NetexEntitiesTestFactory testFragment = new NetexEntitiesTestFactory(); JourneyPattern journeyPattern = testFragment - .journeyPattern() - .withId(1) + .journeyPattern(1) .withNumberOfStopPointInJourneyPattern(0) .create(); @@ -48,32 +48,35 @@ void testNoStopPointsInJourneyPattern() { void testNoSameQuayRefOnStopPoints() { NetexEntitiesTestFactory testFragment = new NetexEntitiesTestFactory(); - JourneyPattern journeyPattern = testFragment - .journeyPattern() - .withId(1) + NetexEntitiesTestFactory.CreateJourneyPattern createJourneyPattern = + testFragment.journeyPattern(1); + + ScheduledStopPointRefStructure scheduledStopPointRef1 = + NetexEntitiesTestFactory.createScheduledStopPointRef(1); + ScheduledStopPointRefStructure scheduledStopPointRef2 = + NetexEntitiesTestFactory.createScheduledStopPointRef(2); + JourneyPattern journeyPattern = createJourneyPattern .withStopPointsInJourneyPattern( List.of( testFragment - .stopPointInJourneyPattern(1) - .withId(1) - .withScheduledStopPointId(1) + .stopPointInJourneyPattern(1, createJourneyPattern) + .withScheduledStopPointRef(scheduledStopPointRef1) .create(), testFragment - .stopPointInJourneyPattern(1) - .withId(2) - .withScheduledStopPointId(2) + .stopPointInJourneyPattern(2, createJourneyPattern) + .withScheduledStopPointRef(scheduledStopPointRef2) .create() ) ) .create(); mockGetQuayId( - new ScheduledStopPointId("TST:ScheduledStopPoint:1"), + ScheduledStopPointId.of(scheduledStopPointRef1), new QuayId("TST:Quay:1") ); mockGetQuayId( - new ScheduledStopPointId("TST:ScheduledStopPoint:2"), + ScheduledStopPointId.of(scheduledStopPointRef2), new QuayId("TST:Quay:2") ); @@ -91,20 +94,23 @@ void testNoSameQuayRefOnStopPoints() { void testSameQuayRefOnStopPoints() { NetexEntitiesTestFactory testFragment = new NetexEntitiesTestFactory(); - JourneyPattern journeyPattern = testFragment - .journeyPattern() - .withId(1) + NetexEntitiesTestFactory.CreateJourneyPattern createJourneyPattern = + testFragment.journeyPattern(1); + + ScheduledStopPointRefStructure scheduledStopPointRef1 = + NetexEntitiesTestFactory.createScheduledStopPointRef(1); + ScheduledStopPointRefStructure scheduledStopPointRef2 = + NetexEntitiesTestFactory.createScheduledStopPointRef(2); + JourneyPattern journeyPattern = createJourneyPattern .withStopPointsInJourneyPattern( List.of( testFragment - .stopPointInJourneyPattern(1) - .withId(1) - .withScheduledStopPointId(1) + .stopPointInJourneyPattern(1, createJourneyPattern) + .withScheduledStopPointRef(scheduledStopPointRef1) .create(), testFragment - .stopPointInJourneyPattern(1) - .withId(2) - .withScheduledStopPointId(2) + .stopPointInJourneyPattern(2, createJourneyPattern) + .withScheduledStopPointRef(scheduledStopPointRef2) .create() ) ) @@ -112,14 +118,8 @@ void testSameQuayRefOnStopPoints() { QuayId testQuayId1 = new QuayId("TST:Quay:1"); - mockGetQuayId( - new ScheduledStopPointId("TST:ScheduledStopPoint:1"), - testQuayId1 - ); - mockGetQuayId( - new ScheduledStopPointId("TST:ScheduledStopPoint:2"), - testQuayId1 - ); + mockGetQuayId(ScheduledStopPointId.of(scheduledStopPointRef1), testQuayId1); + mockGetQuayId(ScheduledStopPointId.of(scheduledStopPointRef2), testQuayId1); ValidationReport validationReport = runValidation( testFragment 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..c52cc2c2 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,10 +259,14 @@ void testPassengerStopAssignmentsInLineFileAndNotOnCommonFileShouldBeOk() { ) .forEach(index -> { PassengerStopAssignment passengerStopAssignment = testData - .passengerStopAssignment() - .withScheduleStopPointId(index + 1) - .withStopPlaceId(index + 1) - .withQuayId(index + 1) + .passengerStopAssignment(1) + .withScheduledStopPointRef( + NetexEntitiesTestFactory.createScheduledStopPointRef(index + 1) + ) + .withStopPlaceRef( + NetexEntitiesTestFactory.createStopPointRef(index + 1) + ) + .withQuayRef(NetexEntitiesTestFactory.createQuayRef(index + 1)) .create(); createNetexEntitiesIndex.addPassengerStopAssignment( 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 b119068c..8487772b 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 @@ -30,11 +30,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() ); @@ -45,11 +47,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 @@ -75,11 +79,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 @@ -107,11 +113,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) @@ -135,9 +143,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 @@ -145,6 +154,7 @@ void testValidateServiceJourneyWithAreaStopMissingTimeWindow() { .withArrivalTime(null) .withDepartureTime(null); + JourneyPattern journeyPattern = createJourneyPattern.create(); NetexEntitiesIndex netexEntitiesIndex = testData .netexEntitiesIndex(journeyPattern, serviceJourney) .create(); @@ -170,9 +180,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 @@ -182,6 +193,7 @@ void testValidateServiceJourneyWithAreaStopInconsistentTimeWindow() { .withEarliestDepartureTime(LocalTime.MIDNIGHT.plusMinutes(1)) .withLatestArrivalTime(LocalTime.MIDNIGHT); + JourneyPattern journeyPattern = createJourneyPattern.create(); NetexEntitiesIndex netexEntitiesIndex = testData .netexEntitiesIndex(journeyPattern, serviceJourney) .create(); @@ -210,9 +222,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 @@ -226,6 +239,7 @@ void testValidateServiceJourneyWithRegularStopFollowedByRegularStopNonIncreasing firstPassingTime.getDepartureTime().minusMinutes(1) ); + JourneyPattern journeyPattern = createJourneyPattern.create(); NetexEntitiesIndex netexEntitiesIndex = testData .netexEntitiesIndex(journeyPattern, serviceJourney) .create(); @@ -251,9 +265,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) @@ -261,6 +276,7 @@ void testValidateWithRegularStopFollowedByRegularStopWithMissingTime() { .withDepartureTime(null) .withArrivalTime(null); + JourneyPattern journeyPattern = createJourneyPattern.create(); NetexEntitiesIndex netexEntitiesIndex = testData .netexEntitiesIndex(journeyPattern, serviceJourney) .create(); @@ -282,9 +298,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 @@ -299,6 +316,7 @@ void testValidateServiceJourneyWithRegularStopFollowedByStopArea() { .withArrivalTime(null) .withDepartureTime(null); + JourneyPattern journeyPattern = createJourneyPattern.create(); NetexEntitiesIndex netexEntitiesIndex = testData .netexEntitiesIndex(journeyPattern, serviceJourney) .create(); @@ -315,9 +333,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 @@ -334,6 +353,7 @@ void testValidateServiceJourneyWithRegularStopFollowedByStopAreaNonIncreasingTim .withArrivalTime(null) .withDepartureTime(null); + JourneyPattern journeyPattern = createJourneyPattern.create(); NetexEntitiesIndex netexEntitiesIndex = testData .netexEntitiesIndex(journeyPattern, serviceJourney) .create(); @@ -362,9 +382,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 @@ -377,6 +398,7 @@ void testValidateServiceJourneyWithStopAreaFollowedByRegularStop() { .withArrivalTime(null) .withDepartureTime(null); + JourneyPattern journeyPattern = createJourneyPattern.create(); NetexEntitiesIndex netexEntitiesIndex = testData .netexEntitiesIndex(journeyPattern, serviceJourney) .create(); @@ -393,9 +415,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 @@ -419,6 +442,7 @@ void testValidateServiceJourneyWithStopAreaFollowedByStopArea() { .withArrivalTime(null) .withDepartureTime(null); + JourneyPattern journeyPattern = createJourneyPattern.create(); NetexEntitiesIndex netexEntitiesIndex = testData .netexEntitiesIndex(journeyPattern, serviceJourney) .create(); @@ -439,9 +463,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 @@ -474,6 +499,7 @@ void testValidateServiceJourneyWithStopAreaFollowedByStopAreaNonIncreasingTime() .withArrivalTime(null) .withDepartureTime(null); + JourneyPattern journeyPattern = createJourneyPattern.create(); NetexEntitiesIndex netexEntitiesIndex = testData .netexEntitiesIndex(journeyPattern, serviceJourney) .create(); @@ -502,9 +528,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 @@ -525,6 +552,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 2c7a8adc..9c8b54cd 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() ); @@ -132,18 +144,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); @@ -166,24 +184,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 7bbda4b1..65a29473 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() ); @@ -99,9 +102,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 1c52e6a1..06ed006b 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; @@ -149,14 +148,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(); @@ -167,10 +170,12 @@ void testPassengerStopAssignmentsInLineFileAndNotOnCommonFileShouldBeOk() { ); PassengerStopAssignment passengerStopAssignment = testData - .passengerStopAssignment() - .withScheduleStopPointId(i + 1) - .withStopPlaceId(i + 1) - .withQuayId(i + 1) + .passengerStopAssignment(i + 1) + .withScheduledStopPointRef( + NetexEntitiesTestFactory.createScheduledStopPointRef(i + 1) + ) + .withStopPlaceRef(NetexEntitiesTestFactory.createStopPointRef(i + 1)) + .withQuayRef(NetexEntitiesTestFactory.createQuayRef(i + 1)) .create(); createNetexEntitiesIndex.addPassengerStopAssignment( @@ -188,14 +193,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(); @@ -210,15 +219,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 b595f85c..bd3457a1 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 c48bb959..3d3c8e17 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,33 +108,41 @@ void testServiceLinkMissing() { void testFromStopPointInServiceLinkDoesNotMatchesJourneyPattern() { NetexEntitiesTestFactory fragment = new NetexEntitiesTestFactory(); - int journeyPatternId = 1; + NetexEntitiesTestFactory.CreateJourneyPattern createJourneyPattern = + fragment.journeyPattern(1); + StopPointInJourneyPattern fromStopPointInJourneyPattern = fragment - .stopPointInJourneyPattern(journeyPatternId) - .withScheduledStopPointId(1) + .stopPointInJourneyPattern(1, createJourneyPattern) + .withScheduledStopPointRef( + NetexEntitiesTestFactory.createScheduledStopPointRef(1) + ) .create(); StopPointInJourneyPattern fromStopPointInServiceLink = fragment - .stopPointInJourneyPattern(journeyPatternId) - .withScheduledStopPointId(3) + .stopPointInJourneyPattern(3, createJourneyPattern) + .withScheduledStopPointRef( + NetexEntitiesTestFactory.createScheduledStopPointRef(3) + ) .create(); StopPointInJourneyPattern toStopPoint = fragment - .stopPointInJourneyPattern(journeyPatternId) - .withScheduledStopPointId(2) + .stopPointInJourneyPattern(2, createJourneyPattern) + .withScheduledStopPointRef( + NetexEntitiesTestFactory.createScheduledStopPointRef(2) + ) .create(); - JourneyPattern journeyPattern = fragment - .journeyPattern() - .withId(journeyPatternId) + JourneyPattern journeyPattern = createJourneyPattern .withStopPointsInJourneyPattern( List.of(fromStopPointInJourneyPattern, toStopPoint) ) .withServiceLinksInJourneyPattern( List.of( fragment - .linkInJourneyPattern(journeyPatternId) - .withServiceLinkId(1) + .linkInJourneyPattern(1, createJourneyPattern) + .withServiceLinkRef( + NetexEntitiesTestFactory.createServiceLinkRef(1) + ) .create() ) ) @@ -168,33 +176,41 @@ void testFromStopPointInServiceLinkDoesNotMatchesJourneyPattern() { void testToStopPointInServiceLinkDoesNotMatchesJourneyPattern() { NetexEntitiesTestFactory fragment = new NetexEntitiesTestFactory(); - int journeyPatternId = 1; + NetexEntitiesTestFactory.CreateJourneyPattern createJourneyPattern = + fragment.journeyPattern(1); + StopPointInJourneyPattern fromStopPoint = fragment - .stopPointInJourneyPattern(journeyPatternId) - .withScheduledStopPointId(1) + .stopPointInJourneyPattern(1, createJourneyPattern) + .withScheduledStopPointRef( + NetexEntitiesTestFactory.createScheduledStopPointRef(1) + ) .create(); StopPointInJourneyPattern toStopPointInJourneyPattern = fragment - .stopPointInJourneyPattern(journeyPatternId) - .withScheduledStopPointId(2) + .stopPointInJourneyPattern(2, createJourneyPattern) + .withScheduledStopPointRef( + NetexEntitiesTestFactory.createScheduledStopPointRef(2) + ) .create(); StopPointInJourneyPattern toStopPointInServiceLink = fragment - .stopPointInJourneyPattern(journeyPatternId) - .withScheduledStopPointId(3) + .stopPointInJourneyPattern(3, createJourneyPattern) + .withScheduledStopPointRef( + NetexEntitiesTestFactory.createScheduledStopPointRef(3) + ) .create(); - JourneyPattern journeyPattern = fragment - .journeyPattern() - .withId(journeyPatternId) + JourneyPattern journeyPattern = createJourneyPattern .withStopPointsInJourneyPattern( List.of(fromStopPoint, toStopPointInJourneyPattern) ) .withServiceLinksInJourneyPattern( List.of( fragment - .linkInJourneyPattern(journeyPatternId) - .withServiceLinkId(1) + .linkInJourneyPattern(1, createJourneyPattern) + .withServiceLinkRef( + NetexEntitiesTestFactory.createServiceLinkRef(1) + ) .create() ) ) @@ -270,28 +286,32 @@ 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) + .withScheduledStopPointRef( + NetexEntitiesTestFactory.createScheduledStopPointRef(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() ) @@ -301,16 +321,18 @@ private List createJourneyPatterns( .rangeClosed(1, numberOfStopPointsInJourneyPattern - 1) .mapToObj(serviceLinkId -> fragment - .linkInJourneyPattern(journeyPatternId) - .withServiceLinkId( - Integer.parseInt(journeyPatternId + "" + serviceLinkId) + .linkInJourneyPattern(1, createJourneyPattern) + .withServiceLinkRef( + NetexEntitiesTestFactory.createServiceLinkRef( + Integer.parseInt(journeyPatternId + "" + serviceLinkId) + ) ) .create() ) .toList() ) - .create() - ) + .create(); + }) .toList(); } }