Commit 93e2dd6e authored by Piotr Gawron's avatar Piotr Gawron
Browse files

doc for update overlay API call

parent 471fd112
......@@ -73,7 +73,7 @@ public class OverlayRestImpl extends BaseRestImpl {
return result;
}
private Map<String, Object> overlayToMap(Layout overlay) {
public Map<String, Object> overlayToMap(Layout overlay) {
Map<String, Object> result = new TreeMap<>();
result.put("idObject", overlay.getId());
......
......@@ -480,11 +480,14 @@ abstract public class ControllerIntegrationTest {
UploadedFileEntry file = new UploadedFileEntry();
file.setFileContent(content.getBytes());
file.setLength(content.getBytes().length);
file.setOriginalFileName("test.txt");
Layout overlay = new Layout();
overlay.setColorSchemaType(ColorSchemaType.GENERIC);
overlay.setInputData(file);
overlay.setProject(project);
overlay.setTitle("test title");
overlay.setDescription("test description");
overlay.setCreator(admin);
layoutDao.add(overlay);
return overlay;
......@@ -538,6 +541,10 @@ abstract public class ControllerIntegrationTest {
return getProjectPathParameters().and(parameterWithName("mapId").description("map identifier"));
}
protected PathParametersSnippet getOverlayPathParameters() {
return getProjectPathParameters().and(parameterWithName("overlayId").description("overlay identifier"));
}
protected RequestParametersSnippet getChemicalFilter() {
return requestParameters(
parameterWithName("columns")
......
......@@ -4,14 +4,12 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
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.restdocs.payload.PayloadDocumentation.*;
import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName;
import static org.springframework.restdocs.request.RequestDocumentation.requestParameters;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import java.util.Arrays;
import java.util.List;
import java.util.*;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.message.BasicNameValuePair;
......@@ -32,8 +30,10 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.web.servlet.RequestBuilder;
import org.springframework.transaction.annotation.Transactional;
import com.google.gson.Gson;
import com.google.gson.JsonParser;
import lcsb.mapviewer.api.projects.overlays.OverlayRestImpl;
import lcsb.mapviewer.model.Project;
import lcsb.mapviewer.model.cache.UploadedFileEntry;
import lcsb.mapviewer.model.map.layout.ColorSchemaType;
......@@ -76,6 +76,9 @@ public class OverlayControllerIntegrationTest extends ControllerIntegrationTest
@Autowired
private ProjectSnippets snippets;
@Autowired
private OverlayRestImpl overlayRestImpl;
@Before
public void setup() {
project = createProject(TEST_PROJECT);
......@@ -734,15 +737,25 @@ public class OverlayControllerIntegrationTest extends ControllerIntegrationTest
Layout overlay = createOverlay(user);
String body = "{\"overlay\":{}}";
Map<String, Object> updateOverlay = overlayRestImpl.overlayToMap(overlay);
updateOverlay.remove("deprecatedColumns");
updateOverlay.remove("idObject");
updateOverlay.remove("images");
updateOverlay.remove("inputDataAvailable");
String body = "{\"overlay\":" + new Gson().toJson(updateOverlay) + "}";
MockHttpSession session = createSession(BUILT_IN_TEST_ADMIN_LOGIN, BUILT_IN_TEST_ADMIN_PASSWORD);
RequestBuilder request = patch("/projects/" + TEST_PROJECT + "/overlays/" + overlay.getId())
RequestBuilder request = patch("/projects/{projectId}/overlays/{overlayId}", TEST_PROJECT, overlay.getId())
.content(body)
.session(session);
mockMvc.perform(request)
.andDo(document("projects/project_overlays/update_overlay",
getOverlayPathParameters(),
getUpdateOverlayRequestParameters(),
responseFields(overlayFields())))
.andExpect(status().is2xxSuccessful());
}
......@@ -1332,7 +1345,6 @@ public class OverlayControllerIntegrationTest extends ControllerIntegrationTest
}
private Snippet getCreateOverlayRequestParameters() {
return requestParameters(
parameterWithName("name")
.description("name of the data overlay"),
......@@ -1357,4 +1369,17 @@ public class OverlayControllerIntegrationTest extends ControllerIntegrationTest
"true/false indicating if user agreed to the new Google Maps API license https://cloud.google.com/maps-platform/terms/"));
}
private Snippet getUpdateOverlayRequestParameters() {
List<FieldDescriptor> fields = new ArrayList<>(overlayFields());
List<FieldDescriptor> toRemove = new ArrayList<>();
for (FieldDescriptor fieldDescriptor : fields) {
if (fieldDescriptor.getPath().equals("idObject") || fieldDescriptor.getPath().equals("inputDataAvailable")
|| fieldDescriptor.getPath().equals("images") || fieldDescriptor.getPath().equals("deprecatedColumns")) {
toRemove.add(fieldDescriptor);
}
}
fields.removeAll(toRemove);
return requestFields().andWithPrefix("overlay.", fields);
}
}
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