1 package org.opendaylight.controller.sal.restconf.impl.test;
3 import static org.junit.Assert.assertTrue;
4 import java.io.FileNotFoundException;
5 import javax.ws.rs.client.Entity;
6 import javax.ws.rs.core.Application;
7 import javax.ws.rs.core.MediaType;
8 import javax.ws.rs.core.Response;
9 import org.glassfish.jersey.server.ResourceConfig;
10 import org.glassfish.jersey.test.JerseyTest;
11 import org.junit.BeforeClass;
12 import org.junit.Ignore;
13 import org.junit.Test;
14 import org.opendaylight.controller.sal.rest.impl.JsonNormalizedNodeBodyReader;
15 import org.opendaylight.controller.sal.rest.impl.NormalizedNodeJsonBodyWriter;
16 import org.opendaylight.controller.sal.rest.impl.NormalizedNodeXmlBodyWriter;
17 import org.opendaylight.controller.sal.rest.impl.RestconfDocumentedExceptionMapper;
18 import org.opendaylight.controller.sal.rest.impl.XmlNormalizedNodeBodyReader;
19 import org.opendaylight.controller.sal.restconf.impl.ControllerContext;
20 import org.opendaylight.controller.sal.restconf.impl.RestconfImpl;
21 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
23 public class CodecsExceptionsCatchingTest extends JerseyTest {
25 private static RestconfImpl restConf;
26 private static ControllerContext controllerContext = ControllerContext.getInstance();
29 public static void init() throws FileNotFoundException {
30 restConf = RestconfImpl.getInstance();
31 controllerContext = ControllerContext.getInstance();
32 final SchemaContext schemaContext = TestUtils.loadSchemaContext("/decoding-exception/yang");
33 controllerContext.setGlobalSchema(schemaContext);
34 restConf.setControllerContext(controllerContext);
38 protected Application configure() {
39 /* enable/disable Jersey logs to console */
40 // enable(TestProperties.LOG_TRAFFIC);
41 // enable(TestProperties.DUMP_ENTITY);
42 // enable(TestProperties.RECORD_LOG_LEVEL);
43 // set(TestProperties.RECORD_LOG_LEVEL, Level.ALL.intValue());
44 ResourceConfig resourceConfig = new ResourceConfig();
45 resourceConfig = resourceConfig.registerInstances(restConf, new NormalizedNodeJsonBodyWriter(),
46 new NormalizedNodeXmlBodyWriter(), new XmlNormalizedNodeBodyReader(), new JsonNormalizedNodeBodyReader());
47 resourceConfig.registerClasses(RestconfDocumentedExceptionMapper.class);
48 return resourceConfig;
52 @Ignore // TODO RestconfDocumentedExceptionMapper needs be fixed before
53 public void StringToNumberConversionError() {
54 final Response response = target("/config/number:cont").request(MediaType.APPLICATION_XML).put(
55 Entity.entity("<cont xmlns=\"number\"><lf>3f</lf></cont>", MediaType.APPLICATION_XML));
56 final String exceptionMessage = response.readEntity(String.class);
57 assertTrue(exceptionMessage.contains("invalid-value"));