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 Dec 9, 2024
1 parent fbd1eb8 commit f0a0879
Show file tree
Hide file tree
Showing 19 changed files with 2,272 additions and 2,308 deletions.
1,813 changes: 1,120 additions & 693 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 @@ -10,8 +10,6 @@
import org.entur.netex.index.api.NetexEntitiesIndex;
import org.entur.netex.validation.validator.ValidationReport;
import org.junit.jupiter.api.Test;
import org.rutebanken.netex.model.FlexibleArea;
import org.rutebanken.netex.model.FlexibleStopPlace;

class InvalidFlexibleAreaValidatorTest extends ValidationTest {

Expand All @@ -26,10 +24,11 @@ private ValidationReport runValidation(

@Test
void testDataSetWithoutFlexibleStopPlacesShouldBeIgnoredGracefully() {
NetexEntitiesTestFactory testData = new NetexEntitiesTestFactory();
NetexEntitiesTestFactory netexEntitiesTestFactory =
new NetexEntitiesTestFactory();

ValidationReport validationReport = runValidation(
testData.netexEntitiesIndex().create()
netexEntitiesTestFactory.create()
);

assertTrue(validationReport.getValidationReportEntries().isEmpty());
Expand Down Expand Up @@ -177,30 +176,30 @@ void testMissingCoordinatesShouldFail() {

@Test
void testMissingFlexibleStopAreaShouldIgnoreValidationGracefully() {
NetexEntitiesTestFactory testData = new NetexEntitiesTestFactory();
NetexEntitiesTestFactory netexEntitiesTestFactory =
new NetexEntitiesTestFactory();

FlexibleStopPlace flexibleStopPlace =
new NetexEntitiesTestFactory.CreateFlexibleStopPlace().create();
netexEntitiesTestFactory.createFlexibleStopPlace();

ValidationReport validationReport = runValidation(
testData.netexEntitiesIndex(flexibleStopPlace).create()
netexEntitiesTestFactory.create()
);

assertThat(validationReport.getValidationReportEntries().size(), is(0));
}

@Test
void testMissingPolygonShouldIgnoreValidationGracefully2() {
NetexEntitiesTestFactory testData = new NetexEntitiesTestFactory();
NetexEntitiesTestFactory netexEntitiesTestFactory =
new NetexEntitiesTestFactory();

FlexibleArea flexibleArea = testData.flexibleArea().create();

FlexibleStopPlace flexibleStopPlace = testData
.flexibleStopPlace(flexibleArea.withPolygon(null))
.create();
netexEntitiesTestFactory
.createFlexibleStopPlace()
.flexibleArea(1)
.withNullPolygon(true);

ValidationReport validationReport = runValidation(
testData.netexEntitiesIndex(flexibleStopPlace).create()
netexEntitiesTestFactory.create()
);

assertThat(validationReport.getValidationReportEntries().size(), is(0));
Expand All @@ -209,19 +208,13 @@ void testMissingPolygonShouldIgnoreValidationGracefully2() {
private ValidationReport runTestWithGivenCoordinates(
List<Double> coordinates
) {
NetexEntitiesTestFactory testData = new NetexEntitiesTestFactory();

FlexibleArea flexibleArea = testData
.flexibleArea()
.withCoordinates(coordinates)
.create();

FlexibleStopPlace flexibleStopPlace = testData
.flexibleStopPlace(flexibleArea)
.create();

return runValidation(
testData.netexEntitiesIndex(flexibleStopPlace).create()
);
NetexEntitiesTestFactory netexEntitiesTestFactory =
new NetexEntitiesTestFactory();
netexEntitiesTestFactory
.createFlexibleStopPlace()
.flexibleArea(1)
.withCoordinates(coordinates);

return runValidation(netexEntitiesTestFactory.create());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.Collection;
import java.util.List;
import java.util.stream.IntStream;
import no.entur.antu.netextestdata.NetexEntitiesTestFactory;
import no.entur.antu.validation.ValidationTest;
Expand All @@ -15,9 +14,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.ServiceJourneyInterchange;
import org.rutebanken.netex.model.ScheduledStopPointRefStructure;

class UnexpectedInterchangeDistanceValidatorTest extends ValidationTest {

Expand Down Expand Up @@ -165,57 +163,47 @@ private ValidationReport runTestWithCoordinates(
) {
assert coordinates.length % 2 == 0;

NetexEntitiesTestFactory fragment = new NetexEntitiesTestFactory();
NetexEntitiesTestFactory netexEntitiesTestFactory =
new NetexEntitiesTestFactory();

List<ServiceJourneyInterchange> serviceJourneyInterchanges = IntStream
IntStream
.rangeClosed(1, coordinates.length / 2)
.mapToObj(i -> {
.forEach(i -> {
int idx1 = (i - 1) * 2;
int idx2 = (i - 1) * 2 + 1;

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)
netexEntitiesTestFactory
.createServiceJourneyInterchange(i)
.withFromPointRef(fromPointRef)
.withToPointRef(toPointRef)
.withFromJourneyRef(
ServiceJourneyId.ofValidId("TST:ServiceJourney:" + idx1)
NetexEntitiesTestFactory.createServiceJourneyRef(idx1)
)
.withToJourneyRef(
ServiceJourneyId.ofValidId("TST:ServiceJourney:" + idx2)
)
.create();
})
.toList();

return runValidation(
fragment
.netexEntitiesIndex()
.addInterchanges(
serviceJourneyInterchanges.toArray(ServiceJourneyInterchange[]::new)
)
.create()
);
NetexEntitiesTestFactory.createServiceJourneyRef(idx2)
);
});

return runValidation(netexEntitiesTestFactory.create());
}
}
Loading

0 comments on commit f0a0879

Please sign in to comment.