Skip to content

Commit

Permalink
path change
Browse files Browse the repository at this point in the history
  • Loading branch information
ramueSVA committed Nov 14, 2024
1 parent dc11742 commit 420b52d
Showing 1 changed file with 16 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.springframework.http.MediaType;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MvcResult;

import java.nio.charset.StandardCharsets;

Expand All @@ -28,46 +29,49 @@
""")
public class ManagerControllerIT extends IntegrationTest {

private static final String MANAGER_PATH = "/manager";

@Autowired
public MockMvc mockMvc;

private static final String PATH = "/manager/execute/query";

@Autowired
private ObjectMapper mapper;

@Test
@SneakyThrows
@WithMockNumUser(roles = {"MANAGER"})
public void execute() {
var query = "SELECT *";
public void executeQuery() {
String query = "SELECT *";
QueryDto queryDto = new QueryDto();
queryDto.setAql(query);
QueryResponseData queryResponseData = new QueryResponseData();
var expectedResult = mapper.writeValueAsString(queryResponseData);

ehrClient
.when(HttpRequest.request().withMethod("POST").withPath("/ehrbase/rest/openehr/v1/query/aql/").withBody(StringBody.subString(query, StandardCharsets.UTF_8)))
.when(HttpRequest.request().withMethod("POST").withHeaders(AUTH_HEADER).withPath("/ehrbase/rest/openehr/v1/query/aql/").withBody(StringBody.subString(query, StandardCharsets.UTF_8)))
.respond(HttpResponse.response().withStatusCode(HttpStatusCode.OK_200.code()).withBody(expectedResult, org.mockserver.model.MediaType.JSON_UTF_8));

var result = mockMvc.perform(post(PATH).with(csrf())
.contentType(MediaType.APPLICATION_JSON)
.content(mapper.writeValueAsString(queryDto))
).andExpect(status().isOk())
.andReturn();
MvcResult result =
mockMvc
.perform(
post(MANAGER_PATH + "/execute/query").with(csrf())
.contentType(MediaType.APPLICATION_JSON)
.content(mapper.writeValueAsString(queryDto)))
.andExpect(status().isOk())
.andReturn();

assertThat(result.getResponse().getContentAsString(), equalTo(expectedResult));
}

@Test
@SneakyThrows
@WithMockNumUser()
public void executeAsNonAuthorizedUser() {
public void executeQueryAsNonAuthorizedUser() {
var query = "SELECT *";
QueryDto queryDto = new QueryDto();
queryDto.setAql(query);

mockMvc.perform(post(PATH).with(csrf())
mockMvc.perform(post(MANAGER_PATH + "/execute/query").with(csrf())
.contentType(MediaType.APPLICATION_JSON)
.content(mapper.writeValueAsString(queryDto))
).andExpect(status().isForbidden());
Expand Down

0 comments on commit 420b52d

Please sign in to comment.