Commit 26e4bc2b authored by Piotr Gawron's avatar Piotr Gawron
Browse files

project name cannot be change to too long name

parent fc8f43d3
......@@ -377,6 +377,9 @@ public class ProjectRestImpl extends BaseRestImpl {
params.projectFile(file);
params.projectId(projectId);
params.projectName(getFirstValue(data.get("name")));
if (params.getProjectName() != null && params.getProjectName().length() > 255) {
throw new QueryException("name is too long");
}
params.projectOrganism(getFirstValue(data.get("organism")));
params.sbgnFormat(getFirstValue(data.get("sbgn")));
params.semanticZoomContainsMultipleLayouts(getFirstValue(data.get("semantic-zoom-contains-multiple-layouts")));
......
......@@ -305,6 +305,12 @@ abstract public class ControllerIntegrationTest {
});
}
protected Project createProjectInSeparateThread(String projectId) throws Exception {
return callInSeparateThread(() -> {
return createProject(projectId);
});
}
protected Layout createOverlay(Project project, User admin) {
return createOverlay(project, admin, "elementIdentifier\tvalue\n\t-1");
}
......
......@@ -194,13 +194,6 @@ public class ProjectControllerIntegrationTestForAsyncCalls extends ControllerInt
}
}
private Project createProjectInSeparateThread(String projectId) throws Exception {
return callInSeparateThread(() -> {
return createProject(projectId);
});
}
private void grantPrivilegeInSeparateThread(User user, String string) throws Exception {
callInSeparateThread(() -> {
userService.grantUserPrivilege(user, PrivilegeType.valueOf(string.split(":")[0]), string.split(":")[1]);
......
package lcsb.mapviewer.web;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
......@@ -101,4 +102,52 @@ public class ProjectControllerIntegrationTestWithoutTransaction extends Controll
}
}
@Test
public void addProjectWithTooLongName() throws Exception {
User admin = userService.getUserByLogin(BUILT_IN_ADMIN_LOGIN);
UploadedFileEntry fileEntry = createFileInSeparateThread(
new String(Files.readAllBytes(Paths.get("./src/test/resources/generic.xml")), "UTF-8"),
admin);
try {
String invalidName = "aaaaaaaaxvncnbvscbnmcnbmccbnsbnsdsnbmdsvbnmsdvnbmsdbmnbndvmsbnmsvdnbmnmbdsvnbmdsvxncbmbnmscbnzdnbnabnsbnamsdbmnsadbmnasdbnmnbmsadbnmasdnbasdbnmsadnbnbmsadbnmadsnbmadsnbnbsadnbmadsbnndsabnbmdasbnmdsajqwrhgjrwhjghgjwerghjwreghwewnjnnbbbnbnbmbnbnzcmnnbmzcnmbcsbnmcsnbcnbzmnbczxnbmczxnbmcxznbcnxbmznbmxzcnbzcxnnbcxznbmzcnbczxnbmnbzcxnbmcznnczbnbzcnbmzcbnmbncznbcznbcz";
String body = EntityUtils.toString(new UrlEncodedFormEntity(Arrays.asList(
new BasicNameValuePair("file-id", String.valueOf(fileEntry.getId())),
new BasicNameValuePair("mapCanvasType", "OPEN_LAYERS"),
new BasicNameValuePair("name", invalidName),
new BasicNameValuePair("parser",
"lcsb.mapviewer.converter.model.celldesigner.CellDesignerXmlParser"))));
RequestBuilder request = post("/projects/" + TEST_PROJECT)
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
.content(body)
.session(createSession(BUILT_IN_ADMIN_LOGIN, BUILT_IN_ADMIN_PASSWORD));
mockMvc.perform(request).andExpect(status().isBadRequest());
} finally {
removeFileInSeparateThread(fileEntry);
}
}
@Test
public void modifyProjectWithTooLongName() throws Exception {
createProjectInSeparateThread(TEST_PROJECT);
try {
String invalidName = "aaaaaaaaxvncnbvscbnmcnbmccbnsbnsdsnbmdsvbnmsdvnbmsdbmnbndvmsbnmsvdnbmnmbdsvnbmdsvxncbmbnmscbnzdnbnabnsbnamsdbmnsadbmnasdbnmnbmsadbnmasdnbasdbnmsadnbnbmsadbnmadsnbmadsnbnbsadnbmadsbnndsabnbmdasbnmdsajqwrhgjrwhjghgjwerghjwreghwewnjnnbbbnbnbmbnbnzcmnnbmzcnmbcsbnmcsnbcnbzmnbczxnbmczxnbmcxznbcnxbmznbmxzcnbzcxnnbcxznbmzcnbczxnbmnbzcxnbmcznnczbnbzcnbmzcbnmbncznbcznbcz";
String content = "{\"project\":{\"name\":\"" + invalidName + "\"}}";
RequestBuilder request = patch("/projects/" + TEST_PROJECT + "/")
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
.content(content)
.session(createSession(BUILT_IN_ADMIN_LOGIN, BUILT_IN_ADMIN_PASSWORD));
mockMvc.perform(request).andExpect(status().isBadRequest());
} finally {
removeProjectInSeparateThread(TEST_PROJECT);
}
}
}
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