Skip to content

Commit

Permalink
Rename stubbings to stub
Browse files Browse the repository at this point in the history
  • Loading branch information
mcruzdev committed Mar 17, 2024
1 parent 9831332 commit 6f77edb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class OpenApiWiremockGeneratorWrapper {
private static final Logger LOGGER = LoggerFactory.getLogger(OpenApiWiremockGeneratorWrapper.class);
public static final String MAPPINGS_DIR = "mappings";
private static final String MAPPINGS = "mappings";
private static final String WIREMOCK_OUTPUT_FILE = "wiremock-stubbings.json";
private static final String WIREMOCK_OUTPUT_FILE = "wiremock-stubs.json";
private static final OpenAPIV3Parser OPENAPI_PARSER_INSTANCE = new OpenAPIV3Parser();
public static final ObjectMapper OBJECT_MAPPER_INSTANCE = new ObjectMapper();
private final Path outputDir;
Expand Down Expand Up @@ -62,16 +62,16 @@ private Consumer<Path> generateWiremockStubbingFile(Path mappingsDir) {
return file -> {
OpenAPI openAPI = OPENAPI_PARSER_INSTANCE.read(file.toString());
OpenApi2WiremockMapper openApi2WiremockMapper = new OpenApi2WiremockMapper(openAPI);
List<Stubbing> stubbings = openApi2WiremockMapper.generateWiremockStubs();
List<Stubbing> stubs = openApi2WiremockMapper.generateWiremockStubs();

try {

byte[] json = OBJECT_MAPPER_INSTANCE.writeValueAsBytes(Map.of(MAPPINGS, stubbings));
byte[] json = OBJECT_MAPPER_INSTANCE.writeValueAsBytes(Map.of(MAPPINGS, stubs));

Path wiremockStubbings = Files
Path wiremockStubs = Files
.createFile(mappingsDir.resolve(generateFinalFilename(file)));

Files.write(wiremockStubbings, json);
Files.write(wiremockStubs, json);

} catch (IOException e) {
LOGGER.warn("Failed to generate Wiremock stubs for file " + file.toAbsolutePath(), e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,35 +23,35 @@ void should_map_openapi_path_with_get_ping_to_wiremock_stubbing_correctly() thro
OpenApi2WiremockMapper openApi2WiremockMapper = new OpenApi2WiremockMapper(openAPI);

// when
List<Stubbing> stubbings = openApi2WiremockMapper.generateWiremockStubs();
List<Stubbing> stubs = openApi2WiremockMapper.generateWiremockStubs();

// then
Stubbing stubbing = stubbings.stream().findFirst().orElseThrow();
Stubbing stubbing = stubs.stream().findFirst().orElseThrow();

Assertions.assertEquals(1, stubbings.size());
Assertions.assertEquals(1, stubs.size());
Assertions.assertEquals("/ping", stubbing.urlPath());
Assertions.assertEquals("GET", stubbing.method());
}

@Test
@DisplayName("Should map two paths to two stubbings correctly")
public void should_map_two_paths_to_two_stubbing_correctly() throws URISyntaxException {
@DisplayName("Should map two paths to two stubs correctly")
public void should_map_two_paths_to_two_stubs_correctly() throws URISyntaxException {
// given
OpenAPI openAPI = readOpenAPI("openapi/should_map_two_paths_to_two_stubbing_correctly.yaml");
OpenApi2WiremockMapper openApi2WiremockMapper = new OpenApi2WiremockMapper(openAPI);

// when
List<Stubbing> stubbings = openApi2WiremockMapper.generateWiremockStubs();
List<Stubbing> stubs = openApi2WiremockMapper.generateWiremockStubs();

// then
Assertions.assertEquals(2, stubbings.size());
Assertions.assertEquals(2, stubs.size());

Assertions.assertTrue(
stubbings.stream().anyMatch(stub -> stub.urlPath().equalsIgnoreCase("/users/1")
stubs.stream().anyMatch(stub -> stub.urlPath().equalsIgnoreCase("/users/1")
&& stub.method().equalsIgnoreCase("GET")));

Assertions.assertTrue(
stubbings.stream().anyMatch(stub -> stub.urlPath().equalsIgnoreCase("/users/1")
stubs.stream().anyMatch(stub -> stub.urlPath().equalsIgnoreCase("/users/1")
&& stub.method().equalsIgnoreCase("DELETE")));
}

Expand All @@ -64,8 +64,8 @@ public void should_map_two_paths_to_two_stubbing_correctly() throws URISyntaxExc
OpenApi2WiremockMapper openApi2WiremockMapper = new OpenApi2WiremockMapper(openAPI);

// arrange
List<Stubbing> stubbings = openApi2WiremockMapper.generateWiremockStubs();
Stubbing stubbing = stubbings.stream().findFirst().orElse(null);
List<Stubbing> stubs = openApi2WiremockMapper.generateWiremockStubs();
Stubbing stubbing = stubs.stream().findFirst().orElse(null);

// assert
Assertions.assertNotNull(stubbing);
Expand All @@ -81,8 +81,8 @@ public void should_map_two_paths_to_two_stubbing_correctly() throws URISyntaxExc
OpenApi2WiremockMapper openApi2WiremockMapper = new OpenApi2WiremockMapper(openAPI);

// arrange
List<Stubbing> stubbings = openApi2WiremockMapper.generateWiremockStubs();
Stubbing stubbing = stubbings.stream().findFirst().orElse(null);
List<Stubbing> stubs = openApi2WiremockMapper.generateWiremockStubs();
Stubbing stubbing = stubs.stream().findFirst().orElse(null);

// assert
Assertions.assertNotNull(stubbing);
Expand All @@ -97,8 +97,8 @@ void should_get_the_lowest_status_code_when_there_is_two() throws URISyntaxExcep
OpenApi2WiremockMapper openApi2WiremockMapper = new OpenApi2WiremockMapper(openAPI);

// arrange
List<Stubbing> stubbings = openApi2WiremockMapper.generateWiremockStubs();
Stubbing stubbing = stubbings.stream().findFirst().orElse(null);
List<Stubbing> stubs = openApi2WiremockMapper.generateWiremockStubs();
Stubbing stubbing = stubs.stream().findFirst().orElse(null);

// assert
Assertions.assertNotNull(stubbing);
Expand Down

0 comments on commit 6f77edb

Please sign in to comment.