Commit 9e0da04c authored by Piotr Gawron's avatar Piotr Gawron
Browse files

document create data overlay API call

parent 0eb60cbd
......@@ -11,6 +11,7 @@ import static org.springframework.restdocs.request.RequestDocumentation.requestP
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import java.util.Arrays;
import java.util.List;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.message.BasicNameValuePair;
......@@ -22,8 +23,10 @@ import org.junit.runner.RunWith;
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.payload.ResponseFieldsSnippet;
import org.springframework.restdocs.request.RequestParametersSnippet;
import org.springframework.restdocs.snippet.Snippet;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.web.servlet.RequestBuilder;
......@@ -33,6 +36,7 @@ import com.google.gson.JsonParser;
import lcsb.mapviewer.model.Project;
import lcsb.mapviewer.model.cache.UploadedFileEntry;
import lcsb.mapviewer.model.map.layout.ColorSchemaType;
import lcsb.mapviewer.model.map.layout.Layout;
import lcsb.mapviewer.model.map.model.ModelData;
import lcsb.mapviewer.model.map.reaction.Reaction;
......@@ -69,6 +73,9 @@ public class OverlayControllerIntegrationTest extends ControllerIntegrationTest
private Reaction reaction;
private Element element;
@Autowired
private ProjectSnippets snippets;
@Before
public void setup() {
project = createProject(TEST_PROJECT);
......@@ -508,12 +515,43 @@ public class OverlayControllerIntegrationTest extends ControllerIntegrationTest
new BasicNameValuePair("googleLicenseConsent", "overlay name"),
new BasicNameValuePair("type", "GENERIC"))));
RequestBuilder request = post("/projects/" + TEST_PROJECT + "/overlays/")
RequestBuilder request = post("/projects/{projectId}/overlays/", TEST_PROJECT)
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
.content(body)
.session(session);
mockMvc.perform(request)
.andDo(document("projects/project_overlays/create_from_file",
getProjectPathParameters(),
getCreateOverlayRequestParameters(),
responseFields(overlayFields())))
.andExpect(status().is2xxSuccessful());
assertEquals(1, layoutDao.getLayoutsByProject(project).size());
}
@Test
public void testAdminCreateOverlayFromContent() throws Exception {
MockHttpSession session = createSession(BUILT_IN_TEST_ADMIN_LOGIN, BUILT_IN_TEST_ADMIN_PASSWORD);
String body = EntityUtils.toString(new UrlEncodedFormEntity(Arrays.asList(
new BasicNameValuePair("content", "elementIdentifier\tvalue\n\t-1"),
new BasicNameValuePair("name", "overlay name"),
new BasicNameValuePair("description", "overlay name"),
new BasicNameValuePair("filename", "overlay name"),
new BasicNameValuePair("googleLicenseConsent", "overlay name"),
new BasicNameValuePair("type", "GENERIC"))));
RequestBuilder request = post("/projects/{projectId}/overlays/", TEST_PROJECT)
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
.content(body)
.session(session);
mockMvc.perform(request)
.andDo(document("projects/project_overlays/create_from_content",
getProjectPathParameters(),
getCreateOverlayRequestParameters(),
responseFields(overlayFields())))
.andExpect(status().is2xxSuccessful());
assertEquals(1, layoutDao.getLayoutsByProject(project).size());
......@@ -1251,42 +1289,72 @@ public class OverlayControllerIntegrationTest extends ControllerIntegrationTest
}
private ResponseFieldsSnippet listOfOverlayFields() {
return responseFields(
fieldWithPath("[].name")
return responseFields().andWithPrefix("[].", overlayFields());
}
private List<FieldDescriptor> overlayFields() {
return Arrays.asList(
fieldWithPath("name")
.description("name")
.type("string"),
fieldWithPath("[].description")
fieldWithPath("description")
.description("description")
.type("string"),
fieldWithPath("[].defaultOverlay")
fieldWithPath("defaultOverlay")
.description("should the overlay be used as default (at most one per project should be marked with true)")
.type("boolean"),
fieldWithPath("[].idObject")
fieldWithPath("idObject")
.description("identifier")
.type("number"),
fieldWithPath("[].inputDataAvailable")
fieldWithPath("inputDataAvailable")
.description("is the source data for the overlay available")
.type("string"),
fieldWithPath("[].publicOverlay")
fieldWithPath("publicOverlay")
.description("is the data overlay publicaly available to all users")
.type("boolean"),
fieldWithPath("[].googleLicenseConsent")
fieldWithPath("googleLicenseConsent")
.description("did creator accepted license required by Google Maps API")
.type("boolean"),
fieldWithPath("[].images")
fieldWithPath("images")
.description(
"in case the data overlay is a background data overlay this object contains map between submaps and folders where background images are stored")
.type("string"),
fieldWithPath("[].deprecatedColumns")
fieldWithPath("deprecatedColumns")
.description("list of columns in the input datasource that are deprecated and should be avoided")
.type("Array<String>"),
fieldWithPath("[].order")
fieldWithPath("order")
.description("sort order")
.type("number"),
fieldWithPath("[].creator")
fieldWithPath("creator")
.description("login of the user who uploaded data overlay")
.type("string")
.optional());
}
private Snippet getCreateOverlayRequestParameters() {
return requestParameters(
parameterWithName("name")
.description("name of the data overlay"),
parameterWithName("content")
.description(
"content of the file that is uploaded with definition what should be visible where (alternative to fileId)")
.optional(),
parameterWithName("fileId")
.description(
"uploaded file id that should be used as data overlay content content (alternative to content)")
.optional(),
parameterWithName("description")
.description("short description of the data overlay"),
parameterWithName("filename")
.description("name of the file that should be used when downloading the source"),
parameterWithName("type")
.description("type of the data overlay (default: " + ColorSchemaType.GENERIC + "). Available options: "
+ snippets.getOptionsAsString(ColorSchemaType.class))
.optional(),
parameterWithName("googleLicenseConsent")
.description(
"true/false indicating if user agreed to the new Google Maps API license https://cloud.google.com/maps-platform/terms/"));
}
}
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