Commit 557180a3 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

user did not always had preferences defined

parent 2c649f66
......@@ -109,6 +109,9 @@ public class UserController extends BaseController {
if (user == null) {
throw new ObjectNotFoundException("User doesn't exist");
}
if (user.getAnnotationSchema() == null) {
user.setAnnotationSchema(projectService.prepareUserAnnotationSchema(user, true));
}
Boolean ldapAvailable = false;
if (columnSet.contains("ldapAccountAvailable")) {
List<User> userList = new ArrayList<>();
......
package lcsb.mapviewer.web;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.post;
import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath;
import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields;
import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName;
import static org.springframework.restdocs.request.RequestDocumentation.requestParameters;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import java.util.Map;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.Before;
......@@ -21,7 +26,7 @@ import org.springframework.mock.web.MockHttpSession;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.web.servlet.RequestBuilder;
import com.google.gson.JsonParser;
import com.fasterxml.jackson.core.type.TypeReference;
import lcsb.mapviewer.common.Configuration;
import lcsb.mapviewer.model.security.PrivilegeType;
......@@ -112,12 +117,10 @@ public class UserControllerAnonymousIntegrationTest extends ControllerIntegratio
.description("user login of the session owner"))))
.andReturn().getResponse().getContentAsString();
String login = new JsonParser()
.parse(response)
.getAsJsonObject()
.get("login")
.getAsString();
assertEquals(BUILT_IN_TEST_ADMIN_LOGIN, login);
Map<String, Object> result = objectMapper.readValue(response, new TypeReference<Map<String, Object>>() {
});
assertEquals(BUILT_IN_TEST_ADMIN_LOGIN, result.get("login"));
}
@Test
......@@ -163,4 +166,18 @@ public class UserControllerAnonymousIntegrationTest extends ControllerIntegratio
.andExpect(status().is2xxSuccessful());
}
@Test
public void getAnonymousPreferences() throws Exception {
RequestBuilder request = get("/api/users/{login}?columns=preferences", Configuration.ANONYMOUS_LOGIN);
String content = mockMvc.perform(request)
.andExpect(status().is2xxSuccessful())
.andReturn().getResponse().getContentAsString();
Map<String, Object> result = objectMapper.readValue(content, new TypeReference<Map<String, Object>>() {
});
logger.debug(result);
assertNotNull(result.get("preferences"));
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment