Skip to content

Commit

Permalink
fix: sonar issues (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrejpetras authored Jul 18, 2024
1 parent 85c908e commit 9e2cd3b
Showing 1 changed file with 15 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ class AnnouncementRestControllerTest extends AbstractTest {
@InjectMockServerClient
MockServerClient mockServerClient;

static final String mockId = "MOCK";
static final String MOCK_ID = "MOCK";

@BeforeEach
void resetExpectation() {
try {
mockServerClient.clear(mockId);
mockServerClient.clear(MOCK_ID);
} catch (Exception ex) {
// mockId not existing
// MOCK_ID not existing
}
}

Expand All @@ -66,7 +66,7 @@ void createAnnouncement_shouldReturnAnnouncement() {
mockServerClient
.when(request().withPath(ANNOUNCEMENT_SVC_INTERNAL_API_BASE_PATH)
.withMethod(HttpMethod.POST))
.withId(mockId)
.withId(MOCK_ID)
.respond(httpRequest -> response().withStatusCode(Response.Status.OK.getStatusCode())
.withContentType(MediaType.APPLICATION_JSON)
.withBody(JsonBody.json(data)));
Expand Down Expand Up @@ -127,7 +127,7 @@ void getAnnouncements_shouldReturnAnnouncementPageResults() {
mockServerClient
.when(request().withPath(ANNOUNCEMENT_SVC_INTERNAL_API_BASE_PATH + "/search")
.withMethod(HttpMethod.POST))
.withId(mockId)
.withId(MOCK_ID)
.respond(httpRequest -> response().withStatusCode(Response.Status.OK.getStatusCode())
.withContentType(MediaType.APPLICATION_JSON)
.withBody(JsonBody.json(data)));
Expand Down Expand Up @@ -167,7 +167,7 @@ void getAnnouncementById_shouldReturnAnnouncement() {
.when(request()
.withPath(ANNOUNCEMENT_SVC_INTERNAL_API_BASE_PATH + "/1")
.withMethod(HttpMethod.GET))
.withId(mockId)
.withId(MOCK_ID)
.respond(
httpRequest -> response()
.withStatusCode(Response.Status.OK.getStatusCode())
Expand Down Expand Up @@ -205,7 +205,7 @@ void getAllAppsWithAnnouncements_shouldReturnAnnouncementApps() {
.when(request()
.withPath(ANNOUNCEMENT_SVC_INTERNAL_API_BASE_PATH + "/products")
.withMethod(HttpMethod.GET))
.withId(mockId)
.withId(MOCK_ID)
.respond(
httpRequest -> response()
.withStatusCode(Response.Status.OK.getStatusCode())
Expand Down Expand Up @@ -245,7 +245,7 @@ void getAnnouncementById_shouldReturnNotFound() {
.when(request()
.withPath(ANNOUNCEMENT_SVC_INTERNAL_API_BASE_PATH + "/" + idNotFound)
.withMethod(HttpMethod.GET))
.withId(mockId)
.withId(MOCK_ID)
.respond(
httpRequest -> response()
.withStatusCode(Response.Status.NOT_FOUND.getStatusCode())
Expand All @@ -272,7 +272,7 @@ void deleteAnnouncementById() {
.when(request()
.withPath(ANNOUNCEMENT_SVC_INTERNAL_API_BASE_PATH + "/" + deleteId)
.withMethod(HttpMethod.DELETE))
.withId(mockId)
.withId(MOCK_ID)
.respond(
httpRequest -> response()
.withStatusCode(Response.Status.NO_CONTENT.getStatusCode()));
Expand Down Expand Up @@ -303,7 +303,7 @@ void updateAnnouncementById() {
.when(request()
.withPath(ANNOUNCEMENT_SVC_INTERNAL_API_BASE_PATH + "/" + updateId)
.withMethod(HttpMethod.PUT))
.withId(mockId)
.withId(MOCK_ID)
.respond(
httpRequest -> response()
.withStatusCode(Response.Status.OK.getStatusCode())
Expand Down Expand Up @@ -336,12 +336,11 @@ void updateAnnouncementById_shouldReturnBadRequest() {
.when(request()
.withPath(ANNOUNCEMENT_SVC_INTERNAL_API_BASE_PATH + "/" + updateId)
.withMethod(HttpMethod.PUT))
.withId(mockId)
.withId(MOCK_ID)
.respond(
httpRequest -> response()
.withStatusCode(Response.Status.BAD_REQUEST.getStatusCode())
.withBody(JsonBody.json(problemDetailResponse)));
;

UpdateAnnouncementRequestDTO input = new UpdateAnnouncementRequestDTO();
// bff call
Expand Down Expand Up @@ -374,7 +373,7 @@ void createAnnouncement_shouldReturnBadRequest_whenRunningIntoValidationConstrai
data.setInvalidParams(list);

mockServerClient.when(request().withPath(ANNOUNCEMENT_SVC_INTERNAL_API_BASE_PATH).withMethod(HttpMethod.POST))
.withId(mockId)
.withId(MOCK_ID)
.respond(httpRequest -> response().withStatusCode(Response.Status.BAD_REQUEST.getStatusCode())
.withContentType(MediaType.APPLICATION_JSON)
.withBody(JsonBody.json(data)));
Expand Down Expand Up @@ -477,7 +476,7 @@ void searchActiveAnnouncements_shouldReturnAnnouncementPageResults() {
.when(request().withPath(ANNOUNCEMENT_SVC_INTERNAL_API_BASE_PATH + "/search")
.withBody(JsonBody.json(criteria1))
.withMethod(HttpMethod.POST))
.withId(mockId)
.withId(MOCK_ID)
.respond(httpRequest -> response().withStatusCode(Response.Status.OK.getStatusCode())
.withContentType(MediaType.APPLICATION_JSON)
.withBody(JsonBody.json(data)));
Expand Down Expand Up @@ -524,7 +523,7 @@ void getAllProductsTest() {
.withMethod(HttpMethod.POST)
.withBody(JsonBody.json(criteria)))
.withPriority(100)
.withId(mockId)
.withId(MOCK_ID)
.respond(httpRequest -> response().withStatusCode(Response.Status.OK.getStatusCode())
.withContentType(MediaType.APPLICATION_JSON)
.withBody(JsonBody.json(result)));
Expand All @@ -549,6 +548,6 @@ void getAllProductsTest() {
Assertions.assertEquals("Product1", response.getStream().get(0).getDisplayName());
Assertions.assertEquals("P2", response.getStream().get(1).getName());
Assertions.assertEquals("Product2", response.getStream().get(1).getDisplayName());
mockServerClient.clear(mockId);
mockServerClient.clear(MOCK_ID);
}
}

0 comments on commit 9e2cd3b

Please sign in to comment.