diff --git a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/SessionController1_9.java b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/SessionController1_9.java index b8e065bdc..74858af65 100644 --- a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/SessionController1_9.java +++ b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/SessionController1_9.java @@ -66,11 +66,11 @@ public Object get() { boolean authenticated = Context.isAuthenticated(); SimpleObject session = new SimpleObject(); session.add("authenticated", authenticated); + session.add("locale", Context.getLocale()); + session.add("allowedLocales", Context.getAdministrationService().getAllowedLocales()); if (authenticated) { session.add("user", ConversionUtil.convertToRepresentation(Context.getAuthenticatedUser(), new CustomRepresentation(USER_CUSTOM_REP))); - session.add("locale", Context.getLocale()); - session.add("allowedLocales", Context.getAdministrationService().getAllowedLocales()); session.add("sessionLocation", ConversionUtil.convertToRepresentation(Context.getUserContext().getLocation(), Representation.REF)); session.add("currentProvider", ConversionUtil.convertToRepresentation(getCurrentProvider(), Representation.REF)); } diff --git a/omod-1.9/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/SessionController1_9Test.java b/omod-1.9/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/SessionController1_9Test.java index 5ff929b84..17d420fe2 100644 --- a/omod-1.9/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/SessionController1_9Test.java +++ b/omod-1.9/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/SessionController1_9Test.java @@ -23,10 +23,8 @@ import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.mock.web.MockHttpSession; import org.springframework.mock.web.MockServletContext; -import org.springframework.web.context.request.ServletWebRequest; -import org.springframework.web.context.request.WebRequest; - import javax.servlet.http.HttpServletRequest; +import java.lang.reflect.InvocationTargetException; import java.util.HashMap; import java.util.List; import java.util.Locale; @@ -85,6 +83,22 @@ public void get_shouldReturnTheUserIfTheUserIsAuthenticated() throws Exception { Assert.assertEquals(Context.getAuthenticatedUser().getPerson().getUuid(), PropertyUtils.getProperty(personProp, "uuid")); } + + @Test + public void get_shouldReturnLocaleInfoIfTheUserIsNotAuthenticated() throws InvocationTargetException, IllegalAccessException, NoSuchMethodException { + Assert.assertTrue(Context.isAuthenticated()); + + // log out the current authenticated user + controller.delete(hsr); + Assert.assertFalse(Context.isAuthenticated()); + Assert.assertNull(hsr.getSession(false)); + + // check if the unauthenticated user response has locale and allowedLocales + Object ret = controller.get(); + Assert.assertEquals(Context.getLocale(), PropertyUtils.getProperty(ret, "locale")); + Assert.assertArrayEquals(Context.getAdministrationService().getAllowedLocales().toArray(), + ((List) PropertyUtils.getProperty(ret, "allowedLocales")).toArray()); + } @Test public void get_shouldReturnLocaleInfoIfTheUserIsAuthenticated() throws Exception {