Skip to content

Commit

Permalink
add logging when starting task and when task executes successfully
Browse files Browse the repository at this point in the history
  • Loading branch information
etan-sb committed Dec 5, 2024
1 parent 07092c1 commit 986b034
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,10 @@ public ResponseEntity<String> deleteCmsId(
HttpServletRequest request,
@PathVariable String measureId,
@RequestParam(name = "cmsId") Integer cmsId,
@Value("${admin-api-key}") String apiKey) {
@Value("${admin-api-key}") String apiKey,
Principal principal) {
log.info("User [{}] - Started admin task [deleteCmsId] and is attempting to delete " +
"CMS id [{}] from measure with measure id [{}]", principal.getName(), cmsId, measureId);
return ResponseEntity.status(HttpStatus.OK)
.body(measureSetService.deleteCmsId(measureId, cmsId));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ public String deleteCmsId(String measureId, Integer cmsId) {
measureSet.setCmsId(null);
measureSetRepository.save(measureSet);

log.info("With the measure id of [{}], successfully queried " +
"for its measure set with measure set id of [{}] and deleted CMS id " +
"of [{}] from the measure set", measureId, measureSetId, cmsId);

return String.format("CMS id of %s was deleted successfully from " +
"measure set with measure set id of %s", cmsId, measureSetId);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.mock.web.MockHttpServletRequest;

import java.io.UnsupportedEncodingException;
import java.security.Principal;
Expand Down Expand Up @@ -264,6 +265,9 @@ void createCmsId() {

@Test
void deleteCmsId() {
Principal principal = mock(Principal.class);
MockHttpServletRequest mockHttpServletRequest = new MockHttpServletRequest();

String measureId = "measureId";

final MeasureSet measureSet =
Expand All @@ -279,7 +283,7 @@ void deleteCmsId() {

when(measureSetService.deleteCmsId(anyString(), anyInt())).thenReturn(expectedBody);

ResponseEntity<String> response = controller.deleteCmsId(null, measureId, measureSet.getCmsId(), "apiKey");
ResponseEntity<String> response = controller.deleteCmsId(mockHttpServletRequest, measureId, measureSet.getCmsId(), "apiKey", principal);

assertThat(response.getBody(), is(notNullValue()));
assertEquals(expectedBody, response.getBody());
Expand Down

0 comments on commit 986b034

Please sign in to comment.