Skip to content
Snippets Groups Projects
Commit 3d3cbbaa authored by Piotr Gawron's avatar Piotr Gawron
Browse files

proper status code is returned when invalid input file is passed for conversion

parent 728420fe
No related branches found
No related tags found
1 merge request!944Internal server error when parsing SBGN -> Bad request
...@@ -51,9 +51,12 @@ public class ConvertRestImpl extends BaseRestImpl { ...@@ -51,9 +51,12 @@ public class ConvertRestImpl extends BaseRestImpl {
} }
public ByteArrayOutputStream converToImage(String fromFormat, String toFormat, String input) public ByteArrayOutputStream converToImage(String fromFormat, String toFormat, String input)
throws InvalidInputDataExecption, SBMLException, IOException, ConverterException, DrawingException, throws IOException, DrawingException, QueryException {
QueryException { try {
return converToImage(fromFormat, toFormat, input, 0.0, 0.0); 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() { public Map<String, Object> getInformation() {
......
...@@ -9,6 +9,7 @@ import org.junit.runners.Suite.SuiteClasses; ...@@ -9,6 +9,7 @@ import org.junit.runners.Suite.SuiteClasses;
ChemicalControllerIntegrationTest.class, ChemicalControllerIntegrationTest.class,
CommentControllerIntegrationTest.class, CommentControllerIntegrationTest.class,
CommentControllerIntegrationTestWithoutTransaction.class, CommentControllerIntegrationTestWithoutTransaction.class,
ConvertControllerIntegrationTest.class,
DrugControllerIntegrationTest.class, DrugControllerIntegrationTest.class,
EndPointsInputValidationTests.class, EndPointsInputValidationTests.class,
FileControllerIntegrationTest.class, FileControllerIntegrationTest.class,
......
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());
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment