Skip to content

Commit

Permalink
feat: Add deleteAll() endpoint to AnalyticsJobController
Browse files Browse the repository at this point in the history
  • Loading branch information
flonix8 committed Dec 18, 2023
1 parent 871644e commit f9f7a04
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,10 @@ public ResponseEntity<String> deleteJob(@PathVariable Long id) {
analyticsJobService.deleteById(id);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}

@DeleteMapping("/all")
public ResponseEntity<String> clearJobs() {
analyticsJobService.deleteAll();
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,16 @@ protected MockHttpServletResponse retrieveById(Long id) throws Exception {
return response;
}

protected MockHttpServletResponse retrieveAll() throws Exception {
MockHttpServletResponse response = mvc.perform(
get(getRestPath() + "/all")
.contentType(MediaType.APPLICATION_JSON))
.andReturn().getResponse();

LOG.info(response.getContentAsString());
return response;
}

protected MockHttpServletResponse delete(Long id) throws Exception {
MockHttpServletResponse response = mvc.perform(
MockMvcRequestBuilders.delete(getRestPath() + "/" + id)
Expand All @@ -161,4 +171,15 @@ protected MockHttpServletResponse delete(Long id) throws Exception {
LOG.info(response.getContentAsString());
return response;
}

protected MockHttpServletResponse deleteAll() throws Exception {
MockHttpServletResponse response = mvc.perform(
MockMvcRequestBuilders.delete(getRestPath() + "/all")
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().is2xxSuccessful())
.andReturn().getResponse();

LOG.info(response.getContentAsString());
return response;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -125,5 +125,23 @@ public void canDelete() throws Exception {
MockHttpServletResponse checkResponse = retrieveById(responseEntity.getId());
assertThat(checkResponse.getStatus()).isEqualTo(HttpStatus.NOT_FOUND.value());
}

@Test
public void canDeleteAll() throws Exception {
// given
AnalyticsJobEntity entity = readFromFile(data + "job1.json");
MockHttpServletResponse response1 = create(entity);
MockHttpServletResponse response2 = create(entity);

// when
MockHttpServletResponse deleteResponse = deleteAll();

assertThat(deleteResponse.getStatus()).isEqualTo(HttpStatus.NO_CONTENT.value());

MockHttpServletResponse checkResponse = retrieveAll();
assertThat(checkResponse.getStatus()).isEqualTo(HttpStatus.OK.value());
AnalyticsJobEntity[] entities = mapper.readValue(checkResponse.getContentAsString(), AnalyticsJobEntity[].class);
assertThat(entities.length).isEqualTo(0);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,8 @@ public AnalyticsJobEntity update(Long id, AnalyticsJobEntity jobUpdate) {
public void deleteById(Long id) {
analyticsJobRepository.deleteById(id);
}

public void deleteAll() {
analyticsJobRepository.deleteAll();
}
}

0 comments on commit f9f7a04

Please sign in to comment.