generated from Health-Education-England/tis-microservice-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #240 from Health-Education-England/feat-endpoint-f…
…or-exceptions Feat endpoint for exceptions
- Loading branch information
Showing
12 changed files
with
212 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/main/java/uk/nhs/hee/tis/revalidation/connection/controller/ExceptionLogController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package uk.nhs.hee.tis.revalidation.connection.controller; | ||
|
||
import java.util.List; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import uk.nhs.hee.tis.revalidation.connection.dto.ExceptionLogDto; | ||
import uk.nhs.hee.tis.revalidation.connection.service.ExceptionService; | ||
|
||
@Slf4j | ||
@RestController | ||
@RequestMapping("/api/exceptionLog") | ||
public class ExceptionLogController { | ||
private ExceptionService exceptionService; | ||
|
||
public ExceptionLogController(ExceptionService exceptionService) { | ||
this.exceptionService = exceptionService; | ||
} | ||
|
||
private static final String ADMIN = "admin"; | ||
|
||
/** | ||
* GET /exceptions/today : get list of exceptions from today for an admin. | ||
* | ||
* @return the list of ExceptionLogDto | ||
*/ | ||
@GetMapping("/today") | ||
public ResponseEntity<List<ExceptionLogDto>> getListOfConnectionExceptionsFromToday( | ||
@RequestParam(name = ADMIN) final String admin) { | ||
|
||
log.info("Received request to fetch exceptions for admin: {}", admin); | ||
final var exceptions = exceptionService.getConnectionExceptionLogsFromToday(admin); | ||
return ResponseEntity.ok().body(exceptions); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/main/java/uk/nhs/hee/tis/revalidation/connection/mapper/ExceptionLogMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package uk.nhs.hee.tis.revalidation.connection.mapper; | ||
|
||
import java.util.List; | ||
import org.mapstruct.Mapper; | ||
import org.mapstruct.Mapping; | ||
import uk.nhs.hee.tis.revalidation.connection.dto.ExceptionLogDto; | ||
import uk.nhs.hee.tis.revalidation.connection.entity.ExceptionLog; | ||
|
||
@Mapper(componentModel = "spring") | ||
public interface ExceptionLogMapper { | ||
|
||
@Mapping(target = "id", ignore = true) | ||
List<ExceptionLogDto> exceptionLogsToExceptionLogDtos(List<ExceptionLog> exceptionLog); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
...st/java/uk/nhs/hee/tis/revalidation/connection/controller/ExceptionLogControllerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package uk.nhs.hee.tis.revalidation.connection.controller; | ||
|
||
import static java.util.List.of; | ||
import static org.hamcrest.Matchers.hasItem; | ||
import static org.mockito.Mockito.when; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
||
import com.github.javafaker.Faker; | ||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.InjectMocks; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; | ||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
import uk.nhs.hee.tis.revalidation.connection.dto.ExceptionLogDto; | ||
import uk.nhs.hee.tis.revalidation.connection.service.ExceptionService; | ||
|
||
@WebMvcTest(ExceptionLogController.class) | ||
class ExceptionLogControllerTest { | ||
|
||
private final Faker faker = new Faker(); | ||
private String admin; | ||
private LocalDateTime today; | ||
private String gmcId1; | ||
private String gmcId2; | ||
private String exceptionReason1; | ||
private String exceptionReason2; | ||
@Autowired | ||
private MockMvc mockMvc; | ||
@MockBean | ||
private ExceptionService exceptionService; | ||
@InjectMocks | ||
private ExceptionLogController exceptionLogController; | ||
|
||
@BeforeEach | ||
public void setup() { | ||
|
||
admin = faker.internet().emailAddress(); | ||
today = LocalDateTime.now(); | ||
gmcId1 = faker.number().digits(8); | ||
gmcId2 = faker.number().digits(8); | ||
exceptionReason1 = faker.lorem().characters(20); | ||
exceptionReason2 = faker.lorem().characters(20); | ||
} | ||
|
||
@Test | ||
void shouldReturnAllExceptionsFromTodayForAnAdmin() throws Exception { | ||
final var exceptionRecordDtoList = buildExceptionRecordDtoList(); | ||
|
||
when(exceptionService.getConnectionExceptionLogsFromToday(admin)).thenReturn( | ||
exceptionRecordDtoList); | ||
|
||
mockMvc.perform(get("/api/exceptionLog/today") | ||
.param("admin", admin)) | ||
.andExpect(status().isOk()) | ||
.andExpect(jsonPath("$.[*].gmcId").value(hasItem(gmcId1))) | ||
.andExpect(jsonPath("$.[*].errorMessage").value(hasItem(exceptionReason1))) | ||
.andExpect(jsonPath("$.[*].admin").value(hasItem(admin))) | ||
.andExpect(jsonPath("$.[*].gmcId").value(hasItem(gmcId2))) | ||
.andExpect(jsonPath("$.[*].errorMessage").value(hasItem(exceptionReason2))) | ||
.andExpect(jsonPath("$.[*].admin").value(hasItem(admin))); | ||
|
||
} | ||
|
||
private List<ExceptionLogDto> buildExceptionRecordDtoList() { | ||
final var record1 = ExceptionLogDto.builder() | ||
.gmcId(gmcId1).errorMessage(exceptionReason1) | ||
.timestamp(today).admin(admin) | ||
.build(); | ||
final var record2 = ExceptionLogDto.builder() | ||
.gmcId(gmcId2).errorMessage(exceptionReason2) | ||
.timestamp(today).admin(admin) | ||
.build(); | ||
return of(record1, record2); | ||
} | ||
} |
Oops, something went wrong.