Commit 6066c24e authored by Piotr Gawron's avatar Piotr Gawron
Browse files

documentation for API calls get project and list projects

parent 18293e0c
......@@ -28,11 +28,10 @@ import org.springframework.web.context.WebApplicationContext;
import lcsb.mapviewer.common.MinervaLoggerAppender;
import lcsb.mapviewer.common.UnitTestFailedWatcher;
import lcsb.mapviewer.model.Project;
import lcsb.mapviewer.model.ProjectStatus;
import lcsb.mapviewer.model.*;
import lcsb.mapviewer.model.cache.UploadedFileEntry;
import lcsb.mapviewer.model.graphics.PolylineData;
import lcsb.mapviewer.model.map.Comment;
import lcsb.mapviewer.model.map.*;
import lcsb.mapviewer.model.map.layout.ColorSchemaType;
import lcsb.mapviewer.model.map.layout.Layout;
import lcsb.mapviewer.model.map.model.ModelData;
......@@ -204,7 +203,26 @@ abstract public class ControllerIntegrationTest {
protected Project createProject(String projectId) {
Project project = new Project(projectId);
project.setOwner(userService.getUserByLogin(BUILT_IN_TEST_ADMIN_LOGIN));
project.setVersion("1.0");
project.setDisease(new MiriamData(MiriamType.MESH_2012, "D010300"));
project.setOrganism(new MiriamData(MiriamType.TAXONOMY, "9606"));
project.setDirectory("289b78b436176091ad900020c933c544");
project.setNotifyEmail("minerva@uni.lu");
OverviewImage image = new OverviewImage();
image.setFilename("image.png");
image.setHeight(100);
image.setWidth(200);
project.addOverviewImage(image);
project.setName("Test Disease");
ProjectLogEntry entry = new ProjectLogEntry();
entry.setMapName("map_name");
entry.setSeverity("WARNING");
entry.setType(ProjectLogEntryType.OTHER);
entry.setContent("This is warning message");
project.addLogEntry(entry);
ModelData map = new ModelData();
map.setName("map_name");
map.setTileSize(256);
map.setWidth(100);
map.setHeight(100);
......
package lcsb.mapviewer.web;
import static org.junit.Assert.*;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.*;
import static org.springframework.restdocs.payload.PayloadDocumentation.*;
import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName;
import static org.springframework.restdocs.request.RequestDocumentation.pathParameters;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import java.util.Arrays;
import java.util.*;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
......@@ -25,6 +30,8 @@ import org.springframework.transaction.annotation.Transactional;
import com.google.gson.JsonParser;
import lcsb.mapviewer.model.Project;
import lcsb.mapviewer.model.ProjectStatus;
import lcsb.mapviewer.model.graphics.MapCanvasType;
import lcsb.mapviewer.model.security.Privilege;
import lcsb.mapviewer.model.security.PrivilegeType;
import lcsb.mapviewer.model.user.User;
......@@ -56,14 +63,15 @@ public class ProjectControllerIntegrationTest extends ControllerIntegrationTest
@Test
public void testGetAllProjectsAsAdmin() throws Exception {
MockHttpSession session = createSession(BUILT_IN_TEST_ADMIN_LOGIN, BUILT_IN_TEST_ADMIN_PASSWORD);
createProject(TEST_PROJECT);
RequestBuilder request = get("/projects/")
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
.session(session);
String response = mockMvc.perform(request)
.andExpect(status().is2xxSuccessful())
.andDo(document("projects/project_data/list",
responseFields(
subsectionWithPath("[]")
.description("list of projects").type("Array<Project>"))))
.andReturn().getResponse().getContentAsString();
int projects = new JsonParser()
......@@ -103,17 +111,84 @@ public class ProjectControllerIntegrationTest extends ControllerIntegrationTest
public void testUserPrivilegesChangeDuringActiveSession() throws Exception {
MockHttpSession session = createSession(CURATOR_LOGIN, CURATOR_PASSWORD);
Project project = new Project(TEST_PROJECT);
project.setOwner(userService.getUserByLogin(BUILT_IN_TEST_ADMIN_LOGIN));
projectDao.add(project);
Project project = createProject(TEST_PROJECT);
userService.grantUserPrivilege(curator, PrivilegeType.READ_PROJECT, project.getProjectId());
RequestBuilder request = get("/projects/" + TEST_PROJECT + "/")
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
RequestBuilder request = get("/projects/{projectId}/", TEST_PROJECT)
.session(session);
List<String> projectStatuses = new ArrayList<>();
for (ProjectStatus status : ProjectStatus.values()) {
projectStatuses.add(status.name());
}
Collections.sort(projectStatuses);
List<String> mapCanvasTypes = new ArrayList<>();
for (MapCanvasType status : MapCanvasType.values()) {
mapCanvasTypes.add(status.name());
}
Collections.sort(mapCanvasTypes);
mockMvc.perform(request)
.andDo(document("projects/project_data/get_project",
pathParameters(parameterWithName("projectId").description("project identifier")),
responseFields(
fieldWithPath("projectId")
.description("project identifier")
.type("String"),
fieldWithPath("name")
.description("name")
.type("String"),
fieldWithPath("version")
.description("version")
.type("String"),
fieldWithPath("owner")
.description("login of the project creator")
.type("String"),
fieldWithPath("creationDate")
.description("when project was uploaded")
.type("String"),
subsectionWithPath("disease")
.description("identifier of the disease")
.type("MiriamAnnotation")
.optional(),
subsectionWithPath("organism")
.description("identifier of the organism")
.type("MiriamAnnotation")
.optional(),
fieldWithPath("idObject")
.ignored(),
fieldWithPath("directory")
.description(
"directory where files related to the project are located. "
+ "Whole path looks like: /minerva/map_images/{directory}")
.type("String"),
fieldWithPath("status")
.description(
"status of the uploaded project; possible values: " + StringUtils.join(projectStatuses, ", "))
.type("String"),
fieldWithPath("progress")
.description("how much current stage progressed in percent")
.type("Double"),
fieldWithPath("notifyEmail")
.description("email address connected to the project")
.type("String"),
fieldWithPath("mapCanvasType")
.description(
"type of the engine that should be used for project rendering; possible values: "
+ StringUtils.join(mapCanvasTypes, ", "))
.type("String"),
fieldWithPath("logEntries")
.description("flag indicating that there are log entries attached to the project")
.type("boolean"),
subsectionWithPath("overviewImageViews")
.description("list of overview images")
.type("Array<OverviewImage>")
.optional(),
subsectionWithPath("topOverviewImage")
.description("overview image that should be used as top level image")
.type("OverviewImage")
.optional())))
.andExpect(status().is2xxSuccessful());
}
......
Supports Markdown
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