Commit 43f33220 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

proper status code is returned when trying to update configuration option with invalid data

parent 503d2b67
......@@ -73,7 +73,7 @@ public class ConfigurationController extends BaseController {
@RequestMapping(value = "/configuration/options/{option}", method = { RequestMethod.PATCH }, produces = {
public Map<String, Object> getOption(
public Map<String, Object> updateOption(
@RequestBody String body,
@CookieValue(value = Configuration.AUTH_TOKEN) String token,
@PathVariable(value = "option") String option
......@@ -5,7 +5,9 @@ import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
@SuiteClasses({ ConfigurationRestImplTest.class })
ConfigurationRestImplTest.class })
public class AllConfigurationTests {
package lcsb.mapviewer.api.configuration;
import static;
import java.util.HashMap;
import java.util.Map;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import lcsb.mapviewer.api.QueryException;
import lcsb.mapviewer.api.SpringRestApiTestConfig;
import lcsb.mapviewer.model.user.ConfigurationElementType;
@ContextConfiguration(classes = SpringRestApiTestConfig.class)
public class ConfigurationControllerTest {
ConfigurationController configurationController;
IUserService userService;
public void testSetSmtpPortToInvalid() throws Exception {
try {
// assume that we have admin account with all the privileges
String adminToken = userService.login("admin", "admin");
Map<String, Object> option= new HashMap<>();
option.put("value", "not a number");
option.put("type", "not a number");
Map<String, Object> data= new HashMap<>();
data.put("option", option);
String body = new Gson().toJson(data);
configurationController.updateOption(body, adminToken,;
fail("Exception expected");
} catch (QueryException e) {
} catch (Exception e) {
throw e;
......@@ -65,6 +65,7 @@ public class ConfigurationService implements IConfigurationService {
@Transactional(noRollbackFor = InvalidArgumentException.class)
public void setConfigurationValue(ConfigurationElementType type, String value) {
if (value == null) {
throw new InvalidArgumentException("null is not a proper value");
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