Skip to content

Commit 3f18533

Browse files
Get rid of unnecessary hard code in the tests code
1 parent 5da2c90 commit 3f18533

6 files changed

Lines changed: 11 additions & 21 deletions

File tree

memex/src/test/java/com/johnlpage/memex/cucumber/steps/CucumberSpringContextConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
@CucumberContextConfiguration
1717
@SpringBootTest(classes = CucumberTestsContainersConfig.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
1818
@ActiveProfiles("test")
19-
@EmbeddedKafka(partitions = 1, topics = {"test"})
19+
@EmbeddedKafka
2020
public class CucumberSpringContextConfig {
2121

2222
}

memex/src/test/java/com/johnlpage/memex/cucumber/steps/InspectionsPreConditionSteps.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public void givenVehicleInspectionsExist(DataTable dataTable) throws JsonProcess
4747
List<VehicleInspection> inspections = new ArrayList<>();
4848

4949
for (Map<String, String> row : rows) {
50-
String json = row.get("vehicleinspection");
50+
String json = row.values().iterator().next(); // Assuming each row has a single JSON string value
5151
VehicleInspection inspection = objectMapper.readValue(json, VehicleInspection.class);
5252
inspections.add(inspection);
5353
Long testId = inspection.getTestid();

memex/src/test/java/com/johnlpage/memex/cucumber/steps/KafkaConsumerSteps.java

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ public void init() {
4747
@Autowired
4848
private VehicleInspectionIdRangeValidator idRangeValidator;
4949

50-
@When("I send {int} vehicle inspections starting with id {long} to kafka with:")
51-
public void sendVehicleInspectionsToKafka(int count, long startId, String jsonTemplate) throws JsonProcessingException {
50+
@When("I send {int} vehicle inspections starting with id {long} to kafka {string} topic with:")
51+
public void sendVehicleInspectionsToKafka(int count, long startId, String topicName, String jsonTemplate) throws JsonProcessingException {
5252
idRangeValidator.validate(startId);
5353
long endIdInclusive = startId + count - 1;
5454
idRangeValidator.validate(endIdInclusive);
@@ -59,11 +59,11 @@ public void sendVehicleInspectionsToKafka(int count, long startId, String jsonTe
5959
vehicleInspection.setTestid(testId);
6060

6161
String message = objectMapper.writeValueAsString(vehicleInspection);
62-
kafkaTemplate.send("test", message);
62+
kafkaTemplate.send(topicName, message);
6363
}
6464
}
6565

66-
@Then("verify {int} vehicle inspections starting from id {long} do exist with:")
66+
@Then("{int} vehicle inspections starting from id {long} do exist with:")
6767
public void verifyVehicleInspectionsSaved(int count, long startId, String expectedJson) throws JsonProcessingException {
6868
long endId = startId + count - 1;
6969
idRangeValidator.validateRange(startId, endId);
@@ -115,12 +115,4 @@ private void assertJsonContains(JsonNode expected, JsonNode actual) {
115115
}
116116
}
117117
}
118-
119-
public ResponseEntity<VehicleInspection> makeGetVehicleInspectionByIdRequest(long id) {
120-
return restClient.get()
121-
.uri(apiBaseUrl + "/api/inspections/id/" + id)
122-
.retrieve()
123-
.toEntity(VehicleInspection.class);
124-
}
125-
126118
}

memex/src/test/java/com/johnlpage/memex/cucumber/steps/RestApiSteps.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public void eachItemInTheResponseArrayShouldContain(String key, String value) {
112112
assertFalse(list.isEmpty(), "Response array should not be empty for this check");
113113
for (Map<String, Object> item : list) {
114114
if (key.indexOf('.') > 0) {
115-
// If the value is a vehicle field, we need to check the nested structure
115+
// If the value is an embedded document field, we need to check the nested structure
116116
String[] parts = key.split("\\.");
117117
assertThat(item, hasKey(parts[0]));
118118
Object nestedValue = item.get(parts[0]);

memex/src/test/java/com/johnlpage/memex/cucumber/steps/TimeManagementSteps.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,10 @@ public class TimeManagementSteps {
1313
@Autowired
1414
MacrosRegister macroRegister;
1515

16-
private ZonedDateTime capturedTimestamp;
17-
1816
@Given("I capture the current timestamp to {string} with {string} pattern")
1917
public void iCaptureTheCurrentTimestamp(String macroName, String datePattern) {
20-
this.capturedTimestamp = ZonedDateTime.now();
21-
macroRegister.registerMacro(macroName, this.capturedTimestamp.format(DateTimeFormatter.ofPattern(datePattern)));
18+
ZonedDateTime capturedTimestamp = ZonedDateTime.now();
19+
macroRegister.registerMacro(macroName, capturedTimestamp.format(DateTimeFormatter.ofPattern(datePattern)));
2220
}
2321

2422
@Given("I wait for {int} second(s)")

memex/src/test/resources/features/inspections.kafka.feature

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ Feature: Vehicle Inspection Kafka Integration
77
@kafka @sunny_day
88
Scenario: Vehicle Inspection Kafka consumer listens to sent messages
99
Given the vehicle inspections in range 10000-11000 do not exist
10-
When I send 100 vehicle inspections starting with id 10000 to kafka with:
10+
When I send 100 vehicle inspections starting with id 10000 to kafka "test" topic with:
1111
"""
1212
{"capacity": 60, "vehicle": {"make": "Ford"}}
1313
"""
1414
Then I wait for 2 seconds
15-
And verify 100 vehicle inspections starting from id 10000 do exist with:
15+
And 100 vehicle inspections starting from id 10000 do exist with:
1616
"""
1717
{"capacity": 60, "vehicle": {"make": "Ford"}}
1818
"""

0 commit comments

Comments
 (0)