Skip to content

Commit

Permalink
fixing sonar
Browse files Browse the repository at this point in the history
changing jacoco

addressing warnings from sonar
  • Loading branch information
SoLetsDev authored and soletsdev committed Jun 24, 2024
1 parent c1b68b0 commit 0e98302
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 29 deletions.
3 changes: 1 addition & 2 deletions api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.4</version>
<version>0.8.8</version>
</plugin>
<plugin>
<groupId>org.hibernate.orm.tooling</groupId>
Expand Down Expand Up @@ -334,7 +334,6 @@
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.4</version>
<executions>
<execution>
<id>prepare-agent</id>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public void after() {
@Test
public void testReadSaga_GivenInValidID_ShouldReturnStatusNotFound() throws Exception {
this.mockMvc.perform(get(URL.BASE_URL + "/saga/" + UUID.randomUUID().toString())
.with(jwt().jwt((jwt) -> jwt.claim("scope", "MACRO_READ_SAGA")))
.with(jwt().jwt(jwt -> jwt.claim("scope", "MACRO_READ_SAGA")))
.contentType(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON))
.andDo(print()).andExpect(status().isNotFound());
Expand All @@ -104,7 +104,7 @@ public void testReadSaga_GivenValidID_ShouldReturnStatusOK() throws Exception {
var sagaFromDB = sagaService.createSagaRecordInDB(SagaEnum.MACRO_CREATE_SAGA.toString(), "Test", payload, UUID.fromString(macroID));

this.mockMvc.perform(get(URL.BASE_URL + "/saga/" + sagaFromDB.getSagaId().toString())
.with(jwt().jwt((jwt) -> jwt.claim("scope", "MACRO_READ_SAGA")))
.with(jwt().jwt(jwt -> jwt.claim("scope", "MACRO_READ_SAGA")))
.contentType(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON))
.andDo(print()).andExpect(status().isOk())
Expand All @@ -129,7 +129,7 @@ public void testGetSagaPaginated_givenNoSearchCriteria_shouldReturnAllWithStatus
this.repository.saveAll(sagaEntities);
final MvcResult result = this.mockMvc
.perform(get("/api/v1/macro/saga/paginated")
.with(jwt().jwt((jwt) -> jwt.claim("scope", "MACRO_READ_SAGA")))
.with(jwt().jwt(jwt -> jwt.claim("scope", "MACRO_READ_SAGA")))
.contentType(APPLICATION_JSON))
.andReturn();
this.mockMvc.perform(asyncDispatch(result)).andDo(print()).andExpect(status().isOk()).andExpect(jsonPath("$.content", hasSize(3)));
Expand All @@ -140,7 +140,7 @@ public void testGetSagaPaginated_givenNoSearchCriteria_shouldReturnAllWithStatus
public void testGetSagaPaginated_givenNoData_shouldReturnStatusOk() throws Exception {
final MvcResult result = this.mockMvc
.perform(get("/api/v1/macro/saga/paginated")
.with(jwt().jwt((jwt) -> jwt.claim("scope", "MACRO_READ_SAGA")))
.with(jwt().jwt(jwt -> jwt.claim("scope", "MACRO_READ_SAGA")))
.contentType(APPLICATION_JSON))
.andReturn();
this.mockMvc.perform(asyncDispatch(result)).andDo(print()).andExpect(status().isOk()).andExpect(jsonPath("$.content", hasSize(0)));
Expand Down Expand Up @@ -175,7 +175,7 @@ public void testGetSagaPaginated_givenSearchCriteria_shouldReturnStatusOk() thro

final MvcResult result = this.mockMvc
.perform(get("/api/v1/macro/saga/paginated")
.with(jwt().jwt((jwt) -> jwt.claim("scope", "MACRO_READ_SAGA")))
.with(jwt().jwt(jwt -> jwt.claim("scope", "MACRO_READ_SAGA")))
.param("searchCriteriaList", criteriaJSON)
.contentType(APPLICATION_JSON))
.andReturn();
Expand All @@ -186,7 +186,7 @@ public void testGetSagaPaginated_givenSearchCriteria_shouldReturnStatusOk() thro
@SuppressWarnings("java:S100")
public void testReadSagaEvents_givenSagaDoesntExist_shouldReturnStatusNotFound() throws Exception {
this.mockMvc.perform(get("/api/v1/macro/saga/{sagaId}/saga-events", UUID.randomUUID())
.with(jwt().jwt((jwt) -> jwt.claim("scope", "MACRO_READ_SAGA")))
.with(jwt().jwt(jwt -> jwt.claim("scope", "MACRO_READ_SAGA")))
.contentType(APPLICATION_JSON)).andDo(print()).andExpect(status().isNotFound());
}

Expand All @@ -212,22 +212,22 @@ public void testGetSagaEventsBySagaID_whenSagaIDIsValid_shouldReturnStatusOk() t
}
this.sagaEventRepository.saveAll(sagaEvents);
this.mockMvc.perform(get("/api/v1/macro/saga/{sagaId}/saga-events", saga.getSagaId())
.with(jwt().jwt((jwt) -> jwt.claim("scope", "MACRO_READ_SAGA"))))
.with(jwt().jwt(jwt -> jwt.claim("scope", "MACRO_READ_SAGA"))))
.andDo(print()).andExpect(status().isOk()).andExpect(jsonPath("$", hasSize(3)));
}

@Test
public void testUpdateSaga_givenNoBody_shouldReturn400() throws Exception {
this.mockMvc.perform(put("/api/v1/macro/saga/{sagaId}", UUID.randomUUID())
.with(jwt().jwt((jwt) -> jwt.claim("scope", "MACRO_WRITE_SAGA")))
.with(jwt().jwt(jwt -> jwt.claim("scope", "MACRO_WRITE_SAGA")))
.contentType(APPLICATION_JSON)).andDo(print()).andExpect(status().isBadRequest());
}

@Test
public void testUpdateSaga_givenInvalidID_shouldReturn404() throws Exception {
val saga = createMockSaga();
this.mockMvc.perform(put("/api/v1/macro/saga/{sagaId}", UUID.randomUUID()).content(objectMapper.writeValueAsBytes(saga))
.with(jwt().jwt((jwt) -> jwt.claim("scope", "MACRO_WRITE_SAGA")))
.with(jwt().jwt(jwt -> jwt.claim("scope", "MACRO_WRITE_SAGA")))
.contentType(APPLICATION_JSON)).andDo(print()).andExpect(status().isNotFound());
}

Expand All @@ -236,7 +236,7 @@ public void testUpdateSaga_givenPastUpdateDate_shouldReturn409() throws Exceptio
final var sagaFromDB = this.sagaService.createSagaRecordInDB(MACRO_CREATE_SAGA.toString(), "Test", "Test", UUID.fromString(this.macroID));
sagaFromDB.setUpdateDate(LocalDateTime.now());
this.mockMvc.perform(put("/api/v1/macro/saga/{sagaId}", sagaFromDB.getSagaId()).content(objectMapper.writeValueAsBytes(mapper.toStruct(sagaFromDB)))
.with(jwt().jwt((jwt) -> jwt.claim("scope", "MACRO_WRITE_SAGA")))
.with(jwt().jwt(jwt -> jwt.claim("scope", "MACRO_WRITE_SAGA")))
.contentType(APPLICATION_JSON)).andDo(print()).andExpect(status().isConflict());
}

Expand All @@ -245,7 +245,7 @@ public void testUpdateSaga_givenValidData_shouldReturnOk() throws Exception {
final var sagaFromDB = this.sagaService.createSagaRecordInDB(MACRO_CREATE_SAGA.toString(), "Test", "Test", UUID.fromString(this.macroID));
sagaFromDB.setUpdateDate(sagaFromDB.getUpdateDate().withNano((int)Math.round(sagaFromDB.getUpdateDate().getNano()/1000.00)*1000)); //db limits precision, so need to adjust
this.mockMvc.perform(put("/api/v1/macro/saga/{sagaId}", sagaFromDB.getSagaId()).content(objectMapper.writeValueAsBytes(mapper.toStruct(sagaFromDB)))
.with(jwt().jwt((jwt) -> jwt.claim("scope", "MACRO_WRITE_SAGA")))
.with(jwt().jwt(jwt -> jwt.claim("scope", "MACRO_WRITE_SAGA")))
.contentType(APPLICATION_JSON)).andDo(print()).andExpect(status().isOk());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,30 +82,30 @@ public void after() {
@Test
public void testRetrievePenMacros_ShouldReturnStatusOK() throws Exception {
this.mockMvc.perform(MockMvcRequestBuilders.get(URL.BASE_URL + URL.PEN_MACRO)
.with(jwt().jwt((jwt) -> jwt.claim("scope", "READ_PEN_MACRO"))))
.with(jwt().jwt(jwt -> jwt.claim("scope", "READ_PEN_MACRO"))))
.andDo(print()).andExpect(status().isOk());
}

@Test
public void testRetrievePenMacros_GivenInvalidMacroID_ShouldReturnStatusNotFound() throws Exception {
this.mockMvc.perform(MockMvcRequestBuilders.get(URL.BASE_URL + URL.PEN_MACRO + URL.MACRO_ID,UUID.randomUUID().toString())
.with(jwt().jwt((jwt) -> jwt.claim("scope", "READ_PEN_MACRO"))))
.with(jwt().jwt(jwt -> jwt.claim("scope", "READ_PEN_MACRO"))))
.andDo(print()).andExpect(status().isNotFound());
}

@Test
public void testRetrievePenMacros_GivenMacroIDWithInvalidBusinessUseTypeCode_ShouldReturnStatusNotFound() throws Exception {
MacroEntity savedEntity = createMacroEntities("OTHER");
this.mockMvc.perform(MockMvcRequestBuilders.get(URL.BASE_URL + URL.PEN_MACRO + URL.MACRO_ID,savedEntity.getMacroId().toString())
.with(jwt().jwt((jwt) -> jwt.claim("scope", "READ_PEN_MACRO"))))
.with(jwt().jwt(jwt -> jwt.claim("scope", "READ_PEN_MACRO"))))
.andDo(print()).andExpect(status().isNotFound());
}

@Test
public void testRetrievePenMacros_GivenValidMacroID_ShouldReturnStatusOK() throws Exception {
MacroEntity savedEntity = createMacroEntities("GMP");
final var result = this.mockMvc.perform(MockMvcRequestBuilders.get(URL.BASE_URL + URL.PEN_MACRO + URL.MACRO_ID, savedEntity.getMacroId().toString())
.with(jwt().jwt((jwt) -> jwt.claim("scope", "READ_PEN_MACRO"))))
.with(jwt().jwt(jwt -> jwt.claim("scope", "READ_PEN_MACRO"))))
.andDo(print()).andExpect(jsonPath("$.macroId").value(savedEntity.getMacroId().toString())).andExpect(status().isOk()).andReturn();
assertThat(result).isNotNull();
}
Expand All @@ -114,7 +114,7 @@ public void testRetrievePenMacros_GivenValidMacroID_ShouldReturnStatusOK() throw
public void testRetrievePenMacros_GivenValidBusinessUseTypeCode_ShouldReturnStatusOK() throws Exception {
MacroEntity savedEntity = createMacroEntities("GMP");
final var result = this.mockMvc.perform(MockMvcRequestBuilders.get(URL.BASE_URL + URL.PEN_MACRO +"?businessUseTypeCode=" + savedEntity.getBusinessUseTypeCode())
.with(jwt().jwt((jwt) -> jwt.claim("scope", "READ_PEN_MACRO"))))
.with(jwt().jwt(jwt -> jwt.claim("scope", "READ_PEN_MACRO"))))
.andDo(print()).andExpect(status().isOk()).andExpect(jsonPath("$", hasSize(1)));
assertThat(result).isNotNull();
}
Expand All @@ -123,7 +123,7 @@ public void testRetrievePenMacros_GivenValidBusinessUseTypeCode_ShouldReturnStat
public void testRetrievePenMacros_GivenInvalidBusinessUseTypeCode_ShouldReturnStatusOK() throws Exception {
MacroEntity savedEntity = createMacroEntities("OTHER");
final var result = this.mockMvc.perform(MockMvcRequestBuilders.get(URL.BASE_URL + URL.PEN_MACRO +"?businessUseTypeCode=" + savedEntity.getBusinessUseTypeCode())
.with(jwt().jwt((jwt) -> jwt.claim("scope", "READ_PEN_MACRO"))))
.with(jwt().jwt(jwt -> jwt.claim("scope", "READ_PEN_MACRO"))))
.andDo(print()).andExpect(status().isOk()).andExpect(jsonPath("$", hasSize(0)));
assertThat(result).isNotNull();
}
Expand All @@ -132,7 +132,7 @@ public void testRetrievePenMacros_GivenInvalidBusinessUseTypeCode_ShouldReturnSt
public void testRetrievePenMacros_GivenValidBusinessUseTypeCodeAndMacroTypeCode_ShouldReturnStatusOK() throws Exception {
MacroEntity savedEntity = createMacroEntities("GMP");
final var result = this.mockMvc.perform(MockMvcRequestBuilders.get(URL.BASE_URL + URL.PEN_MACRO +"?businessUseTypeCode=" + savedEntity.getBusinessUseTypeCode() + "&macroTypeCode=" + savedEntity.getMacroTypeCode())
.with(jwt().jwt((jwt) -> jwt.claim("scope", "READ_PEN_MACRO"))))
.with(jwt().jwt(jwt -> jwt.claim("scope", "READ_PEN_MACRO"))))
.andDo(print()).andExpect(status().isOk()).andExpect(jsonPath("$", hasSize(1)));
assertThat(result).isNotNull();
}
Expand All @@ -141,7 +141,7 @@ public void testRetrievePenMacros_GivenValidBusinessUseTypeCodeAndMacroTypeCode_
public void testRetrievePenMacros_GivenInvalidBusinessUseTypeCodeAndMacroTypeCode_ShouldReturnStatusOK() throws Exception {
MacroEntity savedEntity = createMacroEntities("OTHER");
final var result = this.mockMvc.perform(MockMvcRequestBuilders.get(URL.BASE_URL + URL.PEN_MACRO +"?businessUseTypeCode=" + savedEntity.getBusinessUseTypeCode() + "&macroTypeCode=" + savedEntity.getMacroTypeCode())
.with(jwt().jwt((jwt) -> jwt.claim("scope", "READ_PEN_MACRO"))))
.with(jwt().jwt(jwt -> jwt.claim("scope", "READ_PEN_MACRO"))))
.andDo(print()).andExpect(status().isOk()).andExpect(jsonPath("$", hasSize(0)));
assertThat(result).isNotNull();
}
Expand All @@ -150,7 +150,7 @@ public void testRetrievePenMacros_GivenInvalidBusinessUseTypeCodeAndMacroTypeCod
@Test
public void testCreateMacro_GivenInvalidPayload_ShouldReturnStatusBadRequest() throws Exception {
this.mockMvc.perform(MockMvcRequestBuilders.post(URL.BASE_URL + URL.PEN_MACRO + "/create-macro")
.with(jwt().jwt((jwt) -> jwt.claim("scope", "WRITE_PEN_MACRO")))
.with(jwt().jwt(jwt -> jwt.claim("scope", "WRITE_PEN_MACRO")))
.contentType(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON)
.content(placeholderInvalidSagaData()))
Expand All @@ -160,7 +160,7 @@ public void testCreateMacro_GivenInvalidPayload_ShouldReturnStatusBadRequest() t
@Test
public void testCreateMacro_GivenPayloadWithMacroId_ShouldReturnStatusBadRequest() throws Exception {
this.mockMvc.perform(MockMvcRequestBuilders.post(URL.BASE_URL + URL.PEN_MACRO + "/create-macro")
.with(jwt().jwt((jwt) -> jwt.claim("scope", "WRITE_PEN_MACRO")))
.with(jwt().jwt(jwt -> jwt.claim("scope", "WRITE_PEN_MACRO")))
.contentType(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON)
.content(dummyMacroJsonWithId("PENREG")))
Expand All @@ -170,7 +170,7 @@ public void testCreateMacro_GivenPayloadWithMacroId_ShouldReturnStatusBadRequest
@Test
public void testCreateMacro_GivenPayloadWithInvalidBusinessUseTypeCode_ShouldReturnStatusBadRequest() throws Exception {
this.mockMvc.perform(MockMvcRequestBuilders.post(URL.BASE_URL + URL.PEN_MACRO + "/create-macro")
.with(jwt().jwt((jwt) -> jwt.claim("scope", "WRITE_PEN_MACRO")))
.with(jwt().jwt(jwt -> jwt.claim("scope", "WRITE_PEN_MACRO")))
.contentType(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON)
.content(dummyMacroJson("OTHER")))
Expand All @@ -180,7 +180,7 @@ public void testCreateMacro_GivenPayloadWithInvalidBusinessUseTypeCode_ShouldRet
@Test
public void testCreateMacro_GivenValidPayload_ShouldReturnStatusOk() throws Exception {
this.mockMvc.perform(MockMvcRequestBuilders.post(URL.BASE_URL + URL.PEN_MACRO + "/create-macro")
.with(jwt().jwt((jwt) -> jwt.claim("scope", "WRITE_PEN_MACRO")))
.with(jwt().jwt(jwt -> jwt.claim("scope", "WRITE_PEN_MACRO")))
.contentType(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON)
.content(dummyMacroJson("PENREG")))
Expand All @@ -193,7 +193,7 @@ public void testCreateMacro_GivenDuplicateMacroPayload_ShouldReturnStatusBadRequ
this.macroRepository.save(macroEntity);

this.mockMvc.perform(MockMvcRequestBuilders.post(URL.BASE_URL + URL.PEN_MACRO + "/create-macro")
.with(jwt().jwt((jwt) -> jwt.claim("scope", "WRITE_PEN_MACRO")))
.with(jwt().jwt(jwt -> jwt.claim("scope", "WRITE_PEN_MACRO")))
.contentType(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON)
.content(dummyMacroJson("PENREG")))
Expand All @@ -204,7 +204,7 @@ public void testCreateMacro_GivenDuplicateMacroPayload_ShouldReturnStatusBadRequ
@Test
public void testUpdateMacro_GivenInvalidPayload_ShouldReturnStatusBadRequest() throws Exception {
this.mockMvc.perform(MockMvcRequestBuilders.post(URL.BASE_URL + URL.PEN_MACRO + "/update-macro")
.with(jwt().jwt((jwt) -> jwt.claim("scope", "WRITE_PEN_MACRO")))
.with(jwt().jwt(jwt -> jwt.claim("scope", "WRITE_PEN_MACRO")))
.contentType(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON)
.content(placeholderInvalidSagaData()))
Expand All @@ -214,7 +214,7 @@ public void testUpdateMacro_GivenInvalidPayload_ShouldReturnStatusBadRequest() t
@Test
public void testUpdateMacro_GivenValidPayload_ShouldReturnStatusOk() throws Exception {
this.mockMvc.perform(MockMvcRequestBuilders.post(URL.BASE_URL + URL.PEN_MACRO + "/update-macro")
.with(jwt().jwt((jwt) -> jwt.claim("scope", "WRITE_PEN_MACRO")))
.with(jwt().jwt(jwt -> jwt.claim("scope", "WRITE_PEN_MACRO")))
.contentType(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON)
.content(dummyMacroJsonWithId("PENREG")))
Expand All @@ -226,7 +226,7 @@ public void testUpdateMacro_GivenValidPayload_and_SagaWithSameMacroIdStarted_Sho
var payload = dummyMacroJsonWithId("PENREG");
sagaService.createSagaRecordInDB(SagaEnum.MACRO_UPDATE_SAGA.toString(), "Test", payload, UUID.fromString(this.macroID));
this.mockMvc.perform(MockMvcRequestBuilders.post(URL.BASE_URL + URL.PEN_MACRO + "/update-macro")
.with(jwt().jwt((jwt) -> jwt.claim("scope", "WRITE_PEN_MACRO")))
.with(jwt().jwt(jwt -> jwt.claim("scope", "WRITE_PEN_MACRO")))
.contentType(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON)
.content(payload))
Expand Down

0 comments on commit 0e98302

Please sign in to comment.