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.StructuredDataToJsonProvider;
18 import org.opendaylight.controller.sal.rest.impl.StructuredDataToXmlProvider;
19 import org.opendaylight.controller.sal.rest.impl.XmlToCompositeNodeProvider;
20 import org.opendaylight.controller.sal.restconf.impl.ControllerContext;
21 import org.opendaylight.controller.sal.restconf.impl.RestconfImpl;
22 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
24 public class CodecsExceptionsCatchingTest extends JerseyTest {
26 private static RestconfImpl restConf;
27 private static ControllerContext controllerContext = ControllerContext.getInstance();
30 public static void init() throws FileNotFoundException {
31 restConf = RestconfImpl.getInstance();
32 controllerContext = ControllerContext.getInstance();
33 SchemaContext schemaContext = TestUtils.loadSchemaContext("/decoding-exception/yang");
34 controllerContext.setGlobalSchema(schemaContext);
35 restConf.setControllerContext(controllerContext);
39 protected Application configure() {
40 /* enable/disable Jersey logs to console */
41 // enable(TestProperties.LOG_TRAFFIC);
42 // enable(TestProperties.DUMP_ENTITY);
43 // enable(TestProperties.RECORD_LOG_LEVEL);
44 // set(TestProperties.RECORD_LOG_LEVEL, Level.ALL.intValue());
45 ResourceConfig resourceConfig = new ResourceConfig();
46 resourceConfig = resourceConfig.registerInstances(restConf, StructuredDataToXmlProvider.INSTANCE,
47 StructuredDataToJsonProvider.INSTANCE, XmlToCompositeNodeProvider.INSTANCE,
48 JsonToCompositeNodeProvider.INSTANCE);
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("Incorrect lexical representation of Integer value: 3f"));