Commit 7f39039f authored by Piotr Gawron's avatar Piotr Gawron
Browse files

document for get user and create user API calls

parent 362e603a
......@@ -14,4 +14,34 @@ include::{snippets}/user/list_users/response-fields.adoc[]
=== Sample Response
include::{snippets}/user/list_users/response-body.adoc[]
== Get specific user data
=== CURL sample
include::{snippets}/user/get_user/curl-request.adoc[]
=== Path Parameters
include::{snippets}/user/get_user/path-parameters.adoc[]
=== Response Fields
include::{snippets}/user/get_user/response-fields.adoc[]
=== Sample Response
include::{snippets}/user/get_user/response-body.adoc[]
== Create user
=== CURL sample
include::{snippets}/user/create_user/curl-request.adoc[]
=== Path Parameters
include::{snippets}/user/create_user/path-parameters.adoc[]
=== Request Parameters
include::{snippets}/user/create_user/request-parameters.adoc[]
=== Response Fields
include::{snippets}/user/create_user/response-fields.adoc[]
=== Sample Response
include::{snippets}/user/create_user/response-body.adoc[]
......@@ -2,9 +2,10 @@ package lcsb.mapviewer.web;
import static org.junit.Assert.*;
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.*;
import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath;
import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.restdocs.request.RequestDocumentation.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import java.util.*;
......@@ -21,6 +22,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.mock.web.MockHttpSession;
import org.springframework.restdocs.payload.FieldDescriptor;
import org.springframework.restdocs.request.ParameterDescriptor;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
......@@ -91,7 +93,6 @@ public class UserControllerIntegrationTest extends ControllerIntegrationTest {
String body = "{\"privileges\":{\"IS_ADMIN\":true}}";
RequestBuilder request = patch("/users/" + TEST_USER_LOGIN + ":updatePrivileges")
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
.content(body)
.session(session);
......@@ -108,7 +109,6 @@ public class UserControllerIntegrationTest extends ControllerIntegrationTest {
String body = "{\"privileges\":{\"IS_ADMIN\":true}}";
RequestBuilder request = patch("/users/unkown_login:updatePrivileges")
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
.content(body)
.session(session);
......@@ -127,7 +127,6 @@ public class UserControllerIntegrationTest extends ControllerIntegrationTest {
String body = "{\"privileges\":{\"IS_ADMIN\":false}}";
RequestBuilder request = patch("/users/" + TEST_USER_LOGIN + ":updatePrivileges")
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
.content(body)
.session(session);
......@@ -148,7 +147,6 @@ public class UserControllerIntegrationTest extends ControllerIntegrationTest {
String body = "{\"privileges\":{\"READ_PROJECT:" + project.getId() + "\":true}}";
RequestBuilder request = patch("/users/" + TEST_USER_LOGIN + ":updatePrivileges")
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
.content(body)
.session(session);
......@@ -165,7 +163,6 @@ public class UserControllerIntegrationTest extends ControllerIntegrationTest {
String body = "{\"privileges\":{\"XYZ\":true}}";
RequestBuilder request = patch("/users/" + TEST_USER_LOGIN + ":updatePrivileges")
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
.content(body)
.session(session);
......@@ -180,7 +177,6 @@ public class UserControllerIntegrationTest extends ControllerIntegrationTest {
String body = "{\"privileges\":{\"READ_PROJECT:-5:-1\":true}}";
RequestBuilder request = patch("/users/" + TEST_USER_LOGIN + ":updatePrivileges")
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
.content(body)
.session(session);
......@@ -195,7 +191,6 @@ public class UserControllerIntegrationTest extends ControllerIntegrationTest {
String body = "{\"privileges\":{\"IS_ADMIN\":\"surprise\"}}";
RequestBuilder request = patch("/users/" + TEST_USER_LOGIN + ":updatePrivileges")
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
.content(body)
.session(session);
......@@ -215,11 +210,9 @@ public class UserControllerIntegrationTest extends ControllerIntegrationTest {
String revokeBody = "{\"privileges\":{\"READ_PROJECT:" + project.getId() + "\":false}}";
RequestBuilder grantRequest = patch("/users/" + TEST_USER_LOGIN + ":updatePrivileges")
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
.content(grantBody)
.session(session);
RequestBuilder revokeRequest = patch("/users/" + TEST_USER_LOGIN + ":updatePrivileges")
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
.content(revokeBody)
.session(session);
......@@ -234,11 +227,12 @@ public class UserControllerIntegrationTest extends ControllerIntegrationTest {
public void fetchUserPrivilege() throws Exception {
MockHttpSession session = createSession(BUILT_IN_TEST_ADMIN_LOGIN, BUILT_IN_TEST_ADMIN_PASSWORD);
RequestBuilder request = get("/users/" + TEST_USER_LOGIN)
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
RequestBuilder request = get("/users/{login}", TEST_USER_LOGIN)
.session(session);
String response = mockMvc.perform(request)
.andDo(document("user/get_user",
responseFields(getUserResponseFields())))
.andExpect(status().is2xxSuccessful())
.andReturn().getResponse().getContentAsString();
......@@ -257,7 +251,6 @@ public class UserControllerIntegrationTest extends ControllerIntegrationTest {
MockHttpSession session = createSession(BUILT_IN_TEST_ADMIN_LOGIN, BUILT_IN_TEST_ADMIN_PASSWORD);
RequestBuilder grantRequest = get("/users/?columns=login")
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
.session(session);
String response = mockMvc.perform(grantRequest)
......@@ -279,7 +272,6 @@ public class UserControllerIntegrationTest extends ControllerIntegrationTest {
MockHttpSession session = createSession(BUILT_IN_TEST_ADMIN_LOGIN, BUILT_IN_TEST_ADMIN_PASSWORD);
RequestBuilder grantRequest = get("/users/?columns=login,ldapAccountAvailable,connectedToLdap")
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
.session(session);
String response = mockMvc.perform(grantRequest)
......@@ -300,7 +292,6 @@ public class UserControllerIntegrationTest extends ControllerIntegrationTest {
MockHttpSession session = createSession(BUILT_IN_TEST_ADMIN_LOGIN, BUILT_IN_TEST_ADMIN_PASSWORD);
RequestBuilder grantRequest = get("/users/admin/?columns=login,ldapAccountAvailable,connectedToLdap")
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
.session(session);
String response = mockMvc.perform(grantRequest)
......@@ -323,12 +314,16 @@ public class UserControllerIntegrationTest extends ControllerIntegrationTest {
new BasicNameValuePair("name", "FirstName"),
new BasicNameValuePair("password", "FirstName"))));
RequestBuilder grantRequest = post("/users/" + testLogin)
RequestBuilder grantRequest = post("/users/{login}", testLogin)
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
.content(body)
.session(session);
mockMvc.perform(grantRequest)
.andDo(document("user/create_user",
pathParameters(parameterWithName("login").description("user login")),
requestParameters(getUserRequestFieldsWithoutLogin()),
responseFields(getUserResponseFields())))
.andExpect(status().is2xxSuccessful());
assertNotNull(userService.getUserByLogin(testLogin));
......@@ -435,7 +430,6 @@ public class UserControllerIntegrationTest extends ControllerIntegrationTest {
String body = "{\"user\":{\"password\":\"" + newPassword + "\"}}";
RequestBuilder grantRequest = patch("/users/" + TEST_USER_LOGIN)
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
.content(body)
.session(session);
......@@ -453,7 +447,6 @@ public class UserControllerIntegrationTest extends ControllerIntegrationTest {
String body = "{\"user\":{\"connectedtoldap\":false}}";
RequestBuilder grantRequest = patch("/users/" + TEST_USER_LOGIN)
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
.content(body)
.session(session);
......@@ -690,7 +683,7 @@ public class UserControllerIntegrationTest extends ControllerIntegrationTest {
private List<FieldDescriptor> getUserResponseFields() {
return Arrays.asList(
fieldWithPath("login")
.description("user name")
.description("user login")
.type("String"),
fieldWithPath("connectedToLdap")
.description("is user account connected to ldap")
......@@ -738,7 +731,42 @@ public class UserControllerIntegrationTest extends ControllerIntegrationTest {
fieldWithPath("privileges[].privilegeType")
.description(
"type of privilege, available values: " + projectSnippets.getOptionsAsString(PrivilegeType.class))
.optional()
.type("String"));
}
private List<ParameterDescriptor> getUserRequestFieldsWithoutLogin() {
return Arrays.asList(
parameterWithName("password")
.optional()
.description("user password"),
parameterWithName("connectedToLdap")
.optional()
.description("is user account connected to ldap"),
parameterWithName("ldapAccountAvailable")
.optional()
.description("does is account exist in ldap"),
parameterWithName("email")
.optional()
.description("email address"),
parameterWithName("maxColor")
.optional()
.description("color used for drawing data overlays with max value"),
parameterWithName("minColor")
.optional()
.description("color used for drawing data overlays with min value"),
parameterWithName("neutralColor")
.optional()
.description("color used for drawing data overlays with 0 value"),
parameterWithName("simpleColor")
.optional()
.description("color used for drawing data overlays without value"),
parameterWithName("name")
.optional()
.description("first name"),
parameterWithName("surname")
.optional()
.description("last name"));
}
}
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