1 package org.opendaylight.controller.sal.restconf.impl.test;
3 import static org.junit.Assert.assertTrue;
5 import java.io.FileNotFoundException;
6 import javax.ws.rs.client.Entity;
7 import javax.ws.rs.core.Application;
8 import javax.ws.rs.core.MediaType;
9 import javax.ws.rs.core.Response;
10 import org.glassfish.jersey.server.ResourceConfig;
11 import org.glassfish.jersey.test.JerseyTest;
12 import org.junit.BeforeClass;
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 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 public void StringToNumberConversionError() {
54 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 String exceptionMessage = response.readEntity(String.class);
57 assertTrue(exceptionMessage.contains("invalid-value"));