X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-rest-connector%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Frestconf%2Fimpl%2Ftest%2FCodecsExceptionsCatchingTest.java;fp=opendaylight%2Fmd-sal%2Fsal-rest-connector%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Frestconf%2Fimpl%2Ftest%2FCodecsExceptionsCatchingTest.java;h=767aaf36c149a9a61763d71f9e7722f997e9a595;hp=0000000000000000000000000000000000000000;hb=70c7f86d4f89fbc48ad2d896732982e42db67fd5;hpb=386d8f0ac5fa09ee5514d48284f1a4012f408b52 diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/CodecsExceptionsCatchingTest.java b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/CodecsExceptionsCatchingTest.java new file mode 100644 index 0000000000..767aaf36c1 --- /dev/null +++ b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/CodecsExceptionsCatchingTest.java @@ -0,0 +1,59 @@ +package org.opendaylight.controller.sal.restconf.impl.test; + +import static org.junit.Assert.assertTrue; + +import java.io.FileNotFoundException; + +import javax.ws.rs.client.Entity; +import javax.ws.rs.core.Application; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import org.glassfish.jersey.server.ResourceConfig; +import org.glassfish.jersey.test.JerseyTest; +import org.junit.BeforeClass; +import org.junit.Test; +import org.opendaylight.controller.sal.rest.impl.JsonToCompositeNodeProvider; +import org.opendaylight.controller.sal.rest.impl.StructuredDataToJsonProvider; +import org.opendaylight.controller.sal.rest.impl.StructuredDataToXmlProvider; +import org.opendaylight.controller.sal.rest.impl.XmlToCompositeNodeProvider; +import org.opendaylight.controller.sal.restconf.impl.ControllerContext; +import org.opendaylight.controller.sal.restconf.impl.RestconfImpl; +import org.opendaylight.yangtools.yang.model.api.SchemaContext; + +public class CodecsExceptionsCatchingTest extends JerseyTest { + + private static RestconfImpl restConf; + private static ControllerContext controllerContext = ControllerContext.getInstance(); + + @BeforeClass + public static void init() throws FileNotFoundException { + restConf = RestconfImpl.getInstance(); + controllerContext = ControllerContext.getInstance(); + SchemaContext schemaContext = TestUtils.loadSchemaContext("/decoding-exception/yang"); + controllerContext.setGlobalSchema(schemaContext); + restConf.setControllerContext(controllerContext); + } + + @Override + protected Application configure() { + /* enable/disable Jersey logs to console */ + // enable(TestProperties.LOG_TRAFFIC); + // enable(TestProperties.DUMP_ENTITY); + // enable(TestProperties.RECORD_LOG_LEVEL); + // set(TestProperties.RECORD_LOG_LEVEL, Level.ALL.intValue()); + ResourceConfig resourceConfig = new ResourceConfig(); + resourceConfig = resourceConfig.registerInstances(restConf, StructuredDataToXmlProvider.INSTANCE, + StructuredDataToJsonProvider.INSTANCE, XmlToCompositeNodeProvider.INSTANCE, + JsonToCompositeNodeProvider.INSTANCE); + return resourceConfig; + } + + @Test + public void StringToNumberConversionError() { + Response response = target("/config/number:cont").request(MediaType.APPLICATION_XML).put( + Entity.entity("3f", MediaType.APPLICATION_XML)); + String exceptionMessage = response.readEntity(String.class); + assertTrue(exceptionMessage.contains("Incorrect lexical representation of Integer value: 3f")); + } +} \ No newline at end of file