diff --git a/rest-api/src/main/java/lcsb/mapviewer/api/convert/ConvertRestImpl.java b/rest-api/src/main/java/lcsb/mapviewer/api/convert/ConvertRestImpl.java index d763144b8709c1202ab0e5542aa09581406c5045..6e42cc705f643865e6eb67f7e82e144ec49c15e9 100644 --- a/rest-api/src/main/java/lcsb/mapviewer/api/convert/ConvertRestImpl.java +++ b/rest-api/src/main/java/lcsb/mapviewer/api/convert/ConvertRestImpl.java @@ -51,9 +51,12 @@ public class ConvertRestImpl extends BaseRestImpl { } public ByteArrayOutputStream converToImage(String fromFormat, String toFormat, String input) - throws InvalidInputDataExecption, SBMLException, IOException, ConverterException, DrawingException, - QueryException { - return converToImage(fromFormat, toFormat, input, 0.0, 0.0); + throws IOException, DrawingException, QueryException { + try { + return converToImage(fromFormat, toFormat, input, 0.0, 0.0); + } catch (InvalidInputDataExecption | ConverterException e) { + throw new QueryException("Input file is invalid", e); + } } public Map<String, Object> getInformation() { diff --git a/web/src/test/java/lcsb/mapviewer/web/AllIntegrationTests.java b/web/src/test/java/lcsb/mapviewer/web/AllIntegrationTests.java index ffb65322d3c03825bcdfa667a2cb09972428f7e5..d54b136d005749c05573233d4278a9f6f07539ff 100644 --- a/web/src/test/java/lcsb/mapviewer/web/AllIntegrationTests.java +++ b/web/src/test/java/lcsb/mapviewer/web/AllIntegrationTests.java @@ -9,6 +9,7 @@ import org.junit.runners.Suite.SuiteClasses; ChemicalControllerIntegrationTest.class, CommentControllerIntegrationTest.class, CommentControllerIntegrationTestWithoutTransaction.class, + ConvertControllerIntegrationTest.class, DrugControllerIntegrationTest.class, EndPointsInputValidationTests.class, FileControllerIntegrationTest.class, diff --git a/web/src/test/java/lcsb/mapviewer/web/ConvertControllerIntegrationTest.java b/web/src/test/java/lcsb/mapviewer/web/ConvertControllerIntegrationTest.java new file mode 100644 index 0000000000000000000000000000000000000000..01b4928513721285b57934123533d8a42d0b24c9 --- /dev/null +++ b/web/src/test/java/lcsb/mapviewer/web/ConvertControllerIntegrationTest.java @@ -0,0 +1,37 @@ +package lcsb.mapviewer.web; + +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.http.MediaType; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.web.servlet.RequestBuilder; + +@RunWith(SpringJUnit4ClassRunner.class) +public class ConvertControllerIntegrationTest extends ControllerIntegrationTest { + + @Test + public void testConvertInvalidFile() throws Exception { + String body = "invalid content"; + RequestBuilder request = post("/convert/image/SBGN-ML:svg") + .contentType(MediaType.APPLICATION_FORM_URLENCODED) + .content(body); + + mockMvc.perform(request) + .andExpect(status().isBadRequest()); + } + + @Test + public void testConvertInvalidMapFormat() throws Exception { + String body = "invalid content"; + RequestBuilder request = post("/convert/image/unknown:svg") + .contentType(MediaType.APPLICATION_FORM_URLENCODED) + .content(body); + + mockMvc.perform(request) + .andExpect(status().isBadRequest()); + } + +}