1 package org.opendaylight.controller.sal.restconf.impl.test;
3 import static org.junit.Assert.assertTrue;
5 import java.io.FileNotFoundException;
7 import javax.ws.rs.client.Entity;
8 import javax.ws.rs.core.Application;
9 import javax.ws.rs.core.MediaType;
10 import javax.ws.rs.core.Response;
12 import org.glassfish.jersey.server.ResourceConfig;
13 import org.glassfish.jersey.test.JerseyTest;
14 import org.junit.BeforeClass;
15 import org.junit.Test;
16 import org.opendaylight.controller.sal.rest.impl.JsonToCompositeNodeProvider;
17 import org.opendaylight.controller.sal.rest.impl.RestconfDocumentedExceptionMapper;
18 import org.opendaylight.controller.sal.rest.impl.StructuredDataToJsonProvider;
19 import org.opendaylight.controller.sal.rest.impl.StructuredDataToXmlProvider;
20 import org.opendaylight.controller.sal.rest.impl.XmlToCompositeNodeProvider;
21 import org.opendaylight.controller.sal.restconf.impl.ControllerContext;
22 import org.opendaylight.controller.sal.restconf.impl.RestconfImpl;
23 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
25 public class CodecsExceptionsCatchingTest extends JerseyTest {
27 private static RestconfImpl restConf;
28 private static ControllerContext controllerContext = ControllerContext.getInstance();
31 public static void init() throws FileNotFoundException {
32 restConf = RestconfImpl.getInstance();
33 controllerContext = ControllerContext.getInstance();
34 SchemaContext schemaContext = TestUtils.loadSchemaContext("/decoding-exception/yang");
35 controllerContext.setGlobalSchema(schemaContext);
36 restConf.setControllerContext(controllerContext);
40 protected Application configure() {
41 /* enable/disable Jersey logs to console */
42 // enable(TestProperties.LOG_TRAFFIC);
43 // enable(TestProperties.DUMP_ENTITY);
44 // enable(TestProperties.RECORD_LOG_LEVEL);
45 // set(TestProperties.RECORD_LOG_LEVEL, Level.ALL.intValue());
46 ResourceConfig resourceConfig = new ResourceConfig();
47 resourceConfig = resourceConfig.registerInstances(restConf, StructuredDataToXmlProvider.INSTANCE,
48 StructuredDataToJsonProvider.INSTANCE, XmlToCompositeNodeProvider.INSTANCE,
49 JsonToCompositeNodeProvider.INSTANCE);
50 resourceConfig.registerClasses( RestconfDocumentedExceptionMapper.class );
51 return resourceConfig;
55 public void StringToNumberConversionError() {
56 Response response = target("/config/number:cont").request(MediaType.APPLICATION_XML).put(
57 Entity.entity("<cont xmlns=\"number\"><lf>3f</lf></cont>", MediaType.APPLICATION_XML));
58 String exceptionMessage = response.readEntity(String.class);
59 assertTrue(exceptionMessage.contains("invalid-value"));