Skip to content

Commit

Permalink
RESTWS-919: POST request to /session endpoint should return current s…
Browse files Browse the repository at this point in the history
…ession (#588)
  • Loading branch information
ManojLL authored Sep 12, 2023
1 parent 19e37de commit e4ae0d7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public Object get() {
@RequestMapping(method = RequestMethod.POST)
@ResponseBody
@ResponseStatus(value = HttpStatus.OK)
public void post(HttpServletRequest request, @RequestBody Map<String, String> body) {
public Object post(HttpServletRequest request, @RequestBody Map<String, String> body) {
String localeStr = body.get("locale");
if (localeStr != null) {
Locale locale = null;
Expand Down Expand Up @@ -108,6 +108,7 @@ public void post(HttpServletRequest request, @RequestBody Map<String, String> bo
request.getSession().setAttribute("emrContext.sessionLocationId", location.getId());
}
}
return get();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,26 @@ public void get_shouldReturnCurrentProviderIfTheUserIsAuthenticated() throws Exc
Assert.assertNotNull(currentProvider);
Assert.assertTrue(currentProvider.toString().contains("Super User"));
}

@Test
public void post_shouldReturnTheCurrentSession() throws Exception{
String content = "{}";
Object ret = controller.post(hsr,new ObjectMapper().readValue(content, HashMap.class));
Object currentProvider = PropertyUtils.getProperty(ret, "currentProvider");
Assert.assertNotNull(currentProvider);
Assert.assertTrue(currentProvider.toString().contains("Super User"));
}

@Test
public void post_shouldSetTheUserLocale() throws Exception {
Locale newLocale = new Locale("sp");
String content = "{\"locale\":\"" + newLocale.toString() + "\"}";
Assert.assertNotEquals(newLocale, Context.getLocale());
controller.post(hsr, new ObjectMapper().readValue(content, HashMap.class));
Object ret = controller.post(hsr, new ObjectMapper().readValue(content, HashMap.class));
Assert.assertEquals(newLocale, Context.getLocale());
Assert.assertEquals(Context.getLocale(), PropertyUtils.getProperty(ret, "locale"));
Assert.assertArrayEquals(Context.getAdministrationService().getAllowedLocales().toArray(),
((List<Locale>) PropertyUtils.getProperty(ret, "allowedLocales")).toArray());
}

@Test(expected = APIException.class)
Expand All @@ -145,14 +157,16 @@ public void post_shouldSetTheSessionLocation() throws Exception {
String content = "{\"sessionLocation\":\"" + XANADU_UUID + "\"}";
Location loc = Context.getLocationService().getLocationByUuid(XANADU_UUID);
Assert.assertNotEquals(loc, Context.getUserContext().getLocation());
controller.post(hsr, new ObjectMapper().readValue(content, HashMap.class));
Object ret = controller.post(hsr, new ObjectMapper().readValue(content, HashMap.class));
Assert.assertEquals(loc, Context.getUserContext().getLocation());
Object responseLoc = PropertyUtils.getProperty(ret, "sessionLocation");
Assert.assertTrue(responseLoc.toString() + " should contain 'display=Xanadu'",
responseLoc.toString().contains("display=Xanadu"));
}

@Test(expected = APIException.class)
public void post_shouldFailWhenSettingNonexistantLocation() throws Exception {
String content = "{\"sessionLocation\":\"fake-nonexistant-uuid\"}";
controller.post(hsr, new ObjectMapper().readValue(content, HashMap.class));
}

}

0 comments on commit e4ae0d7

Please sign in to comment.