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 = {
MediaType.APPLICATION_JSON_VALUE })
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;
@RunWith(Suite.class)
@SuiteClasses({ ConfigurationRestImplTest.class })
@SuiteClasses({
ConfigurationControllerTest.class,
ConfigurationRestImplTest.class })
public class AllConfigurationTests {
}
package lcsb.mapviewer.api.configuration;
import static org.junit.Assert.fail;
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 com.google.gson.Gson;
import lcsb.mapviewer.api.QueryException;
import lcsb.mapviewer.api.SpringRestApiTestConfig;
import lcsb.mapviewer.model.user.ConfigurationElementType;
import lcsb.mapviewer.services.interfaces.IUserService;
@ContextConfiguration(classes = SpringRestApiTestConfig.class)
@WebAppConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
public class ConfigurationControllerTest {
@Autowired
ConfigurationController configurationController;
@Autowired
IUserService userService;
@Test
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, ConfigurationElementType.MAX_NUMBER_OF_MAP_LEVELS.name());
fail("Exception expected");
} catch (QueryException e) {
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
}
......@@ -65,6 +65,7 @@ public class ConfigurationService implements IConfigurationService {
}
@Override
@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