Skip to content

Commit

Permalink
Extract input generators
Browse files Browse the repository at this point in the history
  • Loading branch information
testower committed Jan 31, 2025
1 parent 7cee0dd commit 7ea9ae3
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 78 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package no.entur.uttu.integration;

import io.restassured.response.ValidatableResponse;
import java.util.Map;
import no.entur.uttu.UttuIntegrationTest;
import no.entur.uttu.stubs.UserContextServiceStub;
import org.junit.Before;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.graphql.test.tester.GraphQlTester;
import org.springframework.graphql.test.tester.HttpGraphQlTester;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.web.reactive.server.WebTestClient;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package no.entur.uttu.integration;

import java.util.List;
import java.util.Map;
import org.jetbrains.annotations.NotNull;
import org.junit.Test;
import org.springframework.graphql.test.tester.GraphQlTester;

Expand Down Expand Up @@ -32,7 +30,7 @@ public void testDayTypeLifeCycle() {
public void testUnableToDeleteDayTypeUsedByServiceJourney() {
var response = createDayType();
String dayTypeRef = response.path("mutateDayType.id").entity(String.class).get();
String networkId = createNetworkWithName("TestNetworkForDayTypes")
String networkId = createNetworkWithName()
.path("mutateNetwork.id")
.entity(String.class)
.get();
Expand All @@ -55,89 +53,28 @@ public void testUnableToDeleteDayTypeUsedByServiceJourney() {
}

private GraphQlTester.Response createDayType() {
var input = generateDayTypeInput();
var input = InputGenerators.generateDayTypeInput();

return graphQlTester.documentName("mutateDayType").variable("input", input).execute();
}

private static @NotNull Map<String, Object> generateDayTypeInput() {
return Map.of(
"daysOfWeek",
List.of("monday", "tuesday", "wednesday", "thursday", "friday"),
"dayTypeAssignments",
Map.of(
"operatingPeriod",
Map.of("fromDate", "2020-04-01", "toDate", "2020-05-01"),
"isAvailable",
true
)
);
}

private void createFixedLineWithDayTypeRef(
String name,
String networkId,
String dayTypeRef
) {
var input = generateFixedLineInput(name, networkId, dayTypeRef);
var input = InputGenerators.generateFixedLineInput(name, networkId, dayTypeRef);

graphQlTester.documentName("mutateFixedLine").variable("input", input).execute();
}

private static @NotNull Map<String, Object> generateFixedLineInput(
String name,
String networkId,
String dayTypeRef
) {
return Map.of(
"name",
name,
"publicCode",
"TestFixedLine",
"transportMode",
"bus",
"transportSubmode",
"localBus",
"networkRef",
networkId,
"operatorRef",
"NOG:Operator:1",
"journeyPatterns",
List.of(
Map.of(
"pointsInSequence",
List.of(
Map.of(
"quayRef",
"NSR:Quay:494",
"destinationDisplay",
Map.of("frontText", "Første stopp")
),
Map.of("quayRef", "NSR:Quay:563")
),
"serviceJourneys",
List.of(
Map.of(
"name",
"Hverdager3-" + System.currentTimeMillis(),
"dayTypesRefs",
List.of(dayTypeRef),
"passingTimes",
List.of(
Map.of("departureTime", "07:00:00"),
Map.of("arrivalTime", "07:15:00")
)
)
)
)
)
);
}

private GraphQlTester.Response createNetworkWithName(String name) {
private GraphQlTester.Response createNetworkWithName() {
return graphQlTester
.documentName("mutateNetwork")
.variable("network", Map.of("name", name, "authorityRef", "NOG:Authority:1"))
.variable(
"network",
InputGenerators.generateNetworkInput("TestNetworkForDayTypes", "NOG:Authority:1")
)
.execute();
}
}
79 changes: 79 additions & 0 deletions src/test/java/no/entur/uttu/integration/InputGenerators.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package no.entur.uttu.integration;

import java.util.List;
import java.util.Map;
import org.jetbrains.annotations.NotNull;

public class InputGenerators {

static @NotNull Map<String, Object> generateDayTypeInput() {
return Map.of(
"daysOfWeek",
List.of("monday", "tuesday", "wednesday", "thursday", "friday"),
"dayTypeAssignments",
Map.of(
"operatingPeriod",
Map.of("fromDate", "2020-04-01", "toDate", "2020-05-01"),
"isAvailable",
true
)
);
}

static @NotNull Map<String, Object> generateFixedLineInput(
String name,
String networkId,
String dayTypeRef
) {
return Map.of(
"name",
name,
"publicCode",
"TestFixedLine",
"transportMode",
"bus",
"transportSubmode",
"localBus",
"networkRef",
networkId,
"operatorRef",
"NOG:Operator:1",
"journeyPatterns",
List.of(
Map.of(
"pointsInSequence",
List.of(
Map.of(
"quayRef",
"NSR:Quay:494",
"destinationDisplay",
Map.of("frontText", "Første stopp")
),
Map.of("quayRef", "NSR:Quay:563")
),
"serviceJourneys",
List.of(
Map.of(
"name",
"Hverdager3-" + System.currentTimeMillis(),
"dayTypesRefs",
List.of(dayTypeRef),
"passingTimes",
List.of(
Map.of("departureTime", "07:00:00"),
Map.of("arrivalTime", "07:15:00")
)
)
)
)
)
);
}

static @NotNull Map<String, String> generateNetworkInput(
String name,
String authorityRef
) {
return Map.of("name", name, "authorityRef", authorityRef);
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
package no.entur.uttu.integration;

import java.util.HashMap;
import org.junit.Test;
import org.springframework.graphql.test.tester.GraphQlTester;

public class NetworkGraphQLIntegrationTest extends AbstractGraphQLIntegrationTest {

@Test
public void testCreateNetwork() {
var input = new HashMap<>();
input.put("name", "TestNetwork");
input.put("authorityRef", "NOG:Authority:1");
var input = InputGenerators.generateNetworkInput("TestNetwork", "NOG:Authority:1");

GraphQlTester.Response response = graphQlTester
.documentName("mutateNetwork")
.variable("network", input)
Expand Down

0 comments on commit 7ea9ae3

Please sign in to comment.