in ddm-rrm/src/it/java/com/epam/digital/data/platform/management/CandidateVersionControllerIT.java [57:112]
void getVersionsList() {
final var gerritProps = context.getGerritProps();
final var versionCandidate1 = Map.of(
"_number", 1,
"subject", "John Doe's version candidate with number 1",
"topic", "Implemented new feature",
"change_id", "change_id1",
"owner", Map.of("username", gerritProps.getUser()),
"labels", Map.of()
);
final var versionCandidate2 = Map.of(
"_number", 2,
"subject", "John Doe's version candidate with number 2",
"topic", "Bug fix",
"change_id", "change_id2",
"owner", Map.of("username", gerritProps.getUser()),
"labels", Map.of()
);
final var versionsResponse = List.of(versionCandidate1, versionCandidate2);
final var objectMapper = new ObjectMapper();
context.getGerritMockServer().addStubMapping(stubFor(
WireMock.get(String.format("/a/changes/?q=project:%s+status:open+owner:%s",
gerritProps.getRepository(), gerritProps.getUser()))
.willReturn(aResponse().withStatus(200)
.withBody(objectMapper.writeValueAsString(versionsResponse)))));
context.getGerritMockServer().addStubMapping(stubFor(
WireMock.get(urlPathEqualTo("/a/changes/change_id1"))
.willReturn(aResponse().withStatus(200)
.withBody(objectMapper.writeValueAsString(versionCandidate1)))));
context.getGerritMockServer().addStubMapping(stubFor(
WireMock.get(urlPathEqualTo("/a/changes/change_id1/revisions/current/mergeable"))
.willReturn(aResponse().withStatus(200)
.withBody("{\"mergeable\":true}"))));
context.getGerritMockServer().addStubMapping(stubFor(
WireMock.get(urlPathEqualTo("/a/changes/change_id2"))
.willReturn(aResponse().withStatus(200)
.withBody(objectMapper.writeValueAsString(versionCandidate2)))));
context.getGerritMockServer().addStubMapping(stubFor(
WireMock.get(urlPathEqualTo("/a/changes/change_id2/revisions/current/mergeable"))
.willReturn(aResponse().withStatus(200)
.withBody("{\"mergeable\":false}"))));
mockMvc.perform(get("/versions/candidates")
.accept(MediaType.APPLICATION_JSON_VALUE)
).andExpectAll(
status().isOk(),
content().contentType("application/json"),
jsonPath("$", hasSize(2)),
jsonPath("$[0].id", is("1")),
jsonPath("$[0].name", is("John Doe's version candidate with number 1")),
jsonPath("$[0].description", is("Implemented new feature")),
jsonPath("$[1].id", is("2")),
jsonPath("$[1].name", is("John Doe's version candidate with number 2")),
jsonPath("$[1].description", is("Bug fix"))
);
}