Skip to content

Commit

Permalink
added current session details after updating session properties
Browse files Browse the repository at this point in the history
added unit tests for session controller

updated unit tests for session controller
  • Loading branch information
ManojLL committed Sep 11, 2023
1 parent cbcf07f commit 3f1b82d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 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 @@ -122,8 +122,11 @@ 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,8 +148,11 @@ 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)
Expand All @@ -155,4 +161,13 @@ public void post_shouldFailWhenSettingNonexistantLocation() throws Exception {
controller.post(hsr, new ObjectMapper().readValue(content, HashMap.class));
}

@Test
public void post_shouldSetTheCurrentSession() 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"));
}

}

0 comments on commit 3f1b82d

Please sign in to comment.