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
......@@ -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() {
......
......@@ -9,6 +9,7 @@ import org.junit.runners.Suite.SuiteClasses;
ChemicalControllerIntegrationTest.class,
CommentControllerIntegrationTest.class,
CommentControllerIntegrationTestWithoutTransaction.class,
ConvertControllerIntegrationTest.class,
DrugControllerIntegrationTest.class,
EndPointsInputValidationTests.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());
}
}
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