Skip to content

Commit a6cc1dc

Browse files
authored
DMP-5257 Create new endpoint GET /admin/reports (#3079)
1 parent a7afc49 commit a6cc1dc

File tree

6 files changed

+189
-0
lines changed

6 files changed

+189
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package uk.gov.hmcts.darts.reports.controller;
2+
3+
import org.junit.jupiter.params.ParameterizedTest;
4+
import org.junit.jupiter.params.provider.EnumSource;
5+
import org.skyscreamer.jsonassert.JSONAssert;
6+
import org.skyscreamer.jsonassert.JSONCompareMode;
7+
import org.springframework.beans.factory.annotation.Autowired;
8+
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
9+
import org.springframework.test.web.servlet.MockMvc;
10+
import org.springframework.test.web.servlet.MvcResult;
11+
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
12+
import uk.gov.hmcts.darts.common.enums.SecurityRoleEnum;
13+
import uk.gov.hmcts.darts.testutils.GivenBuilder;
14+
import uk.gov.hmcts.darts.testutils.IntegrationBase;
15+
16+
import static org.junit.jupiter.params.provider.EnumSource.Mode.EXCLUDE;
17+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
18+
19+
@AutoConfigureMockMvc
20+
class ReportsControllerGetAdminReportsIntTest extends IntegrationBase {
21+
22+
private static final String ENDPOINT_URL = "/admin/reports";
23+
24+
@Autowired
25+
private transient MockMvc mockMvc;
26+
@Autowired
27+
private GivenBuilder given;
28+
29+
@ParameterizedTest
30+
@EnumSource(value = SecurityRoleEnum.class, names = {"SUPER_ADMIN", "SUPER_USER"}, mode = EnumSource.Mode.INCLUDE)
31+
void getReportsAdmin_shouldReturn501Error_NotYetImplemented(SecurityRoleEnum role) throws Exception {
32+
33+
given.anAuthenticatedUserWithGlobalAccessAndRole(role);
34+
35+
mockMvc.perform(MockMvcRequestBuilders.get(ENDPOINT_URL))
36+
.andExpect(status().isNotImplemented())
37+
.andReturn();
38+
39+
}
40+
41+
@ParameterizedTest
42+
@EnumSource(value = SecurityRoleEnum.class, names = {"SUPER_ADMIN", "SUPER_USER"}, mode = EXCLUDE)
43+
void getReportsAdmin_shouldReturnForbidden_ForNotAuthorisedUsers(SecurityRoleEnum role) throws Exception {
44+
given.anAuthenticatedUserWithGlobalAccessAndRole(role);
45+
46+
MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.get(ENDPOINT_URL))
47+
.andExpect(status().isForbidden())
48+
.andReturn();
49+
50+
var jsonString = mvcResult.getResponse().getContentAsString();
51+
JSONAssert.assertEquals(
52+
"""
53+
{
54+
"type": "AUTHORISATION_109",
55+
"title": "User is not authorised for this endpoint",
56+
"status": 403
57+
}
58+
""", jsonString, JSONCompareMode.STRICT);
59+
}
60+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package uk.gov.hmcts.darts.reports.controller;
2+
3+
4+
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
5+
import lombok.RequiredArgsConstructor;
6+
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
7+
import org.springframework.http.HttpStatus;
8+
import org.springframework.http.ResponseEntity;
9+
import org.springframework.web.bind.annotation.RestController;
10+
import uk.gov.hmcts.darts.authorisation.annotation.Authorisation;
11+
import uk.gov.hmcts.darts.reports.http.api.ReportsApi;
12+
import uk.gov.hmcts.darts.reports.model.AdminReportsResponseItem;
13+
import uk.gov.hmcts.darts.reports.service.ReportsAdminService;
14+
15+
import static uk.gov.hmcts.darts.authorisation.constants.AuthorisationConstants.SECURITY_SCHEMES_BEARER_AUTH;
16+
import static uk.gov.hmcts.darts.authorisation.enums.ContextIdEnum.ANY_ENTITY_ID;
17+
import static uk.gov.hmcts.darts.common.enums.SecurityRoleEnum.SUPER_ADMIN;
18+
import static uk.gov.hmcts.darts.common.enums.SecurityRoleEnum.SUPER_USER;
19+
20+
@RestController
21+
@RequiredArgsConstructor
22+
@ConditionalOnProperty(prefix = "darts", name = "api-pod", havingValue = "true")
23+
public class ReportsController implements ReportsApi {
24+
25+
private final ReportsAdminService reportsAdminService;
26+
27+
@Override
28+
@SecurityRequirement(name = SECURITY_SCHEMES_BEARER_AUTH)
29+
@Authorisation(contextId = ANY_ENTITY_ID,
30+
globalAccessSecurityRoles = {SUPER_ADMIN, SUPER_USER})
31+
public ResponseEntity<AdminReportsResponseItem> getAdminReports() {
32+
reportsAdminService.getAdminReports();
33+
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
34+
}
35+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package uk.gov.hmcts.darts.reports.service;
2+
3+
import uk.gov.hmcts.darts.reports.model.AdminReportsResponseItem;
4+
5+
@FunctionalInterface
6+
public interface ReportsAdminService {
7+
8+
AdminReportsResponseItem getAdminReports();
9+
10+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package uk.gov.hmcts.darts.reports.service.impl;
2+
3+
import lombok.RequiredArgsConstructor;
4+
import lombok.extern.slf4j.Slf4j;
5+
import org.springframework.stereotype.Service;
6+
import uk.gov.hmcts.darts.reports.model.AdminReportsResponseItem;
7+
import uk.gov.hmcts.darts.reports.service.ReportsAdminService;
8+
9+
@Service
10+
@RequiredArgsConstructor
11+
@Slf4j
12+
public class ReportsAdminServiceImpl implements ReportsAdminService {
13+
14+
@Override
15+
public AdminReportsResponseItem getAdminReports() {
16+
return null;
17+
}
18+
19+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
openapi: 3.0.1
2+
3+
info:
4+
5+
version: ${version}
6+
title: Modernised DARTS
7+
description: |-
8+
Modernised DARTS (Digital Audio Recording and Transcription Service).
9+
10+
servers:
11+
- url: http://localhost:4550/
12+
13+
paths:
14+
/admin/reports:
15+
get:
16+
tags:
17+
- Reports
18+
summary: Get admin reports
19+
operationId: getAdminReports
20+
responses:
21+
'200':
22+
description: OK
23+
content:
24+
application/json:
25+
schema:
26+
$ref: '#/components/schemas/AdminReportsResponseItem'
27+
'403':
28+
description: Forbidden Error
29+
content:
30+
application/json+problem:
31+
schema:
32+
$ref: './problem.yaml'
33+
34+
components:
35+
schemas:
36+
37+
AdminReportsResponseItem:
38+
type: object
39+
properties:
40+
reports:
41+
type: array
42+
items:
43+
$ref: '#/components/schemas/Report'
44+
45+
Report:
46+
type: object
47+
properties:
48+
reportName:
49+
type: string
50+
example: "Monthly Report"
51+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package uk.gov.hmcts.darts.reports.service.impl;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import static org.junit.jupiter.api.Assertions.assertNull;
6+
7+
class ReportsAdminServiceImplTest {
8+
9+
@Test
10+
void getAdminReports() {
11+
ReportsAdminServiceImpl reportsAdminService = new ReportsAdminServiceImpl();
12+
assertNull(reportsAdminService.getAdminReports());
13+
}
14+
}

0 commit comments

Comments
 (0)