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.JsonToCompositeNodeProvider;
15 import org.opendaylight.controller.sal.rest.impl.RestconfDocumentedExceptionMapper;
16 import org.opendaylight.controller.sal.rest.impl.StructuredDataToJsonProvider;
17 import org.opendaylight.controller.sal.rest.impl.StructuredDataToXmlProvider;
18 import org.opendaylight.controller.sal.rest.impl.XmlToCompositeNodeProvider;
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, StructuredDataToXmlProvider.INSTANCE,
46 StructuredDataToJsonProvider.INSTANCE, XmlToCompositeNodeProvider.INSTANCE,
47 JsonToCompositeNodeProvider.INSTANCE);
48 resourceConfig.registerClasses(RestconfDocumentedExceptionMapper.class);
49 return resourceConfig;
53 @Ignore // TODO RestconfDocumentedExceptionMapper needs be fixed before
54 public void StringToNumberConversionError() {
55 final Response response = target("/config/number:cont").request(MediaType.APPLICATION_XML).put(
56 Entity.entity("<cont xmlns=\"number\"><lf>3f</lf></cont>", MediaType.APPLICATION_XML));
57 final String exceptionMessage = response.readEntity(String.class);
58 assertTrue(exceptionMessage.contains("invalid-value"));