Commit 566cf0f3 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

invalid file id returns 400 not 500

parent 76ea198f
......@@ -349,7 +349,7 @@ public class ProjectRestImpl extends BaseRestImpl {
if (fileId == null) {
throw new QueryException("file-id is obligatory");
}
UploadedFileEntry file = uploadedFileEntryDao.getById(Integer.valueOf(fileId));
UploadedFileEntry file = uploadedFileEntryDao.getById(super.parseInteger(fileId, "fileId"));
if (file == null) {
throw new QueryException("Invalid file id: " + fileId);
}
......
......@@ -4,6 +4,11 @@ import static org.junit.Assert.*;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import java.util.Arrays;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.Before;
......@@ -25,7 +30,7 @@ import lcsb.mapviewer.model.security.PrivilegeType;
import lcsb.mapviewer.model.user.User;
import lcsb.mapviewer.persist.dao.ProjectDao;
import lcsb.mapviewer.services.interfaces.IUserService;
@RunWith(SpringJUnit4ClassRunner.class)
@Transactional
@Rollback
......@@ -321,4 +326,21 @@ public class ProjectControllerIntegrationTest extends ControllerIntegrationTest
.andExpect(status().isNotFound());
}
@Test(timeout = 10000)
public void addProjectWithInvalidFileId() 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("file-id", String.valueOf("")),
new BasicNameValuePair("mapCanvasType", "OPEN_LAYERS"),
new BasicNameValuePair("parser",
"lcsb.mapviewer.converter.model.celldesigner.CellDesignerXmlParser"))));
RequestBuilder request = post("/projects/projectId")
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
.content(body)
.session(session);
mockMvc.perform(request).andExpect(status().is4xxClientError());
}
}
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