Skip to content

Commit

Permalink
Refactor NetexEntitiesTestFactory and unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
mansoor-sajjad committed Nov 30, 2024
1 parent eb4b9e9 commit a084fda
Show file tree
Hide file tree
Showing 18 changed files with 1,089 additions and 839 deletions.
725 changes: 397 additions & 328 deletions src/test/java/no/entur/antu/netextestdata/NetexEntitiesTestFactory.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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(
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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();
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -196,50 +193,34 @@ private List<ServiceJourneyInterchange> createServiceJourneyInterchanges(

int maxStartIndex = Math.max(startIndex, 0);

List<ServiceJourney> serviceJourneys = fragment.createServiceJourneys(
fragment.journeyPattern().create(),
(numberOfServiceJourneyInterchanges + maxStartIndex) * 2
);
List<NetexEntitiesTestFactory.CreateServiceJourney> serviceJourneys =
fragment.serviceJourneys(
fragment.journeyPattern(1),
(numberOfServiceJourneyInterchanges + maxStartIndex) * 2
);

List<Integer> duplicateIndexesList = Arrays
.stream(duplicateIndexes)
.boxed()
.toList();

List<NetexEntitiesTestFactory.CreateServiceJourneyInterchange> 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();
}
}
Loading

0 comments on commit a084fda

Please sign in to comment.