Commit 89c511ed authored by Piotr Gawron's avatar Piotr Gawron
Browse files

documentation for downloading map API call

parent 3d9b463e
......@@ -66,3 +66,21 @@ include::{snippets}/projects/project_maps/get_connections/curl-request.adoc[]
=== Sample Response
include::{snippets}/projects/project_maps/get_connections/response-body.adoc[]
== Download map
Download map in a standard format.
=== Path Parameters
include::{snippets}/projects/project_maps/download_model_simple/path-parameters.adoc[]
=== Request Parameters
include::{snippets}/projects/project_maps/download_model_simple/request-parameters.adoc[]
=== CURL sample 1
include::{snippets}/projects/project_maps/download_model_simple/curl-request.adoc[]
=== CURL sample 2
include::{snippets}/projects/project_maps/download_from_polygon/curl-request.adoc[]
=== CURL sample 3
include::{snippets}/projects/project_maps/download_with_element_list/curl-request.adoc[]
......@@ -6,8 +6,7 @@ import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.docu
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get;
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.patch;
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.restdocs.request.RequestDocumentation.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import org.apache.logging.log4j.LogManager;
......@@ -18,6 +17,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.mock.web.MockHttpSession;
import org.springframework.restdocs.payload.ResponseFieldsSnippet;
import org.springframework.restdocs.request.RequestParametersSnippet;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.web.servlet.MvcResult;
......@@ -58,6 +58,9 @@ public class MapControllerIntegrationTest extends ControllerIntegrationTest {
private Project project;
private ModelData map;
@Autowired
ProjectSnippets snippets;
@Before
public void setup() {
project = createProject(TEST_PROJECT);
......@@ -319,7 +322,7 @@ public class MapControllerIntegrationTest extends ControllerIntegrationTest {
MockHttpSession session = createSession(ControllerIntegrationTest.BUILT_IN_TEST_ADMIN_LOGIN,
ControllerIntegrationTest.BUILT_IN_TEST_ADMIN_PASSWORD);
String content = "{}";
String content = "{\"model\":{}}";
RequestBuilder request = patch("/projects/*/models/" + map.getId())
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
......@@ -363,11 +366,63 @@ public class MapControllerIntegrationTest extends ControllerIntegrationTest {
MockHttpSession session = createSession(ControllerIntegrationTest.BUILT_IN_TEST_ADMIN_LOGIN,
ControllerIntegrationTest.BUILT_IN_TEST_ADMIN_PASSWORD);
RequestBuilder request = get("/projects/" + TEST_PROJECT + "/models/" + map.getId() + ":downloadModel?" +
"handlerClass=" + CellDesignerXmlParser.class.getCanonicalName())
RequestBuilder request = get("/projects/{projectId}/models/{mapId}:downloadModel?" +
"handlerClass=" + CellDesignerXmlParser.class.getCanonicalName(), TEST_PROJECT, map.getId())
.session(session);
mockMvc.perform(request)
.andDo(document("projects/project_maps/download_model_simple",
downloadModelRequestParameters(),
pathParameters(parameterWithName("projectId").description("project identifier"),
parameterWithName("mapId").description("map identifier"))))
.andExpect(status().is2xxSuccessful());
}
private RequestParametersSnippet downloadModelRequestParameters() {
return requestParameters(
parameterWithName("handlerClass").description("class preparing model file. Available options: " +
snippets.getParsers()),
parameterWithName("polygonString").description("polygon defining part of the model to be downloaded")
.optional(),
parameterWithName("elementIds").description("list of element ids that should be included in the output")
.optional(),
parameterWithName("reactionIds").description("list of reaction ids that should be included in the output")
.optional());
}
@Test
public void testDownloadModelByPolygon() throws Exception {
MockHttpSession session = createSession(ControllerIntegrationTest.BUILT_IN_TEST_ADMIN_LOGIN,
ControllerIntegrationTest.BUILT_IN_TEST_ADMIN_PASSWORD);
RequestBuilder request = get("/projects/{projectId}/models/{mapId}:downloadModel?" +
"handlerClass=" + CellDesignerXmlParser.class.getCanonicalName() +
"&polygonString=0,0;100,0;0,100", TEST_PROJECT, map.getId())
.session(session);
mockMvc.perform(request)
.andDo(document("projects/project_maps/download_from_polygon",
downloadModelRequestParameters(),
pathParameters(parameterWithName("projectId").description("project identifier"),
parameterWithName("mapId").description("map identifier"))))
.andExpect(status().is2xxSuccessful());
}
@Test
public void testDownloadModelByElementList() throws Exception {
MockHttpSession session = createSession(ControllerIntegrationTest.BUILT_IN_TEST_ADMIN_LOGIN,
ControllerIntegrationTest.BUILT_IN_TEST_ADMIN_PASSWORD);
RequestBuilder request = get("/projects/{projectId}/models/{mapId}:downloadModel?" +
"handlerClass=" + CellDesignerXmlParser.class.getCanonicalName() +
"&elementIds=" + map.getElements().iterator().next().getId(), TEST_PROJECT, map.getId())
.session(session);
mockMvc.perform(request)
.andDo(document("projects/project_maps/download_with_element_list",
downloadModelRequestParameters(),
pathParameters(parameterWithName("projectId").description("project identifier"),
parameterWithName("mapId").description("map identifier"))))
.andExpect(status().is2xxSuccessful());
}
......
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