2 * Copyright (c) 2014, 2015 Brocade Communication Systems, Inc., Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.controller.sal.restconf.impl.test;
11 import static org.junit.Assert.assertTrue;
12 import java.io.FileNotFoundException;
13 import javax.ws.rs.client.Entity;
14 import javax.ws.rs.core.Application;
15 import javax.ws.rs.core.MediaType;
16 import javax.ws.rs.core.Response;
17 import org.glassfish.jersey.server.ResourceConfig;
18 import org.glassfish.jersey.test.JerseyTest;
19 import org.junit.BeforeClass;
20 import org.junit.Ignore;
21 import org.junit.Test;
22 import org.opendaylight.netconf.sal.rest.impl.JsonNormalizedNodeBodyReader;
23 import org.opendaylight.netconf.sal.rest.impl.NormalizedNodeJsonBodyWriter;
24 import org.opendaylight.netconf.sal.rest.impl.NormalizedNodeXmlBodyWriter;
25 import org.opendaylight.netconf.sal.rest.impl.RestconfDocumentedExceptionMapper;
26 import org.opendaylight.netconf.sal.rest.impl.XmlNormalizedNodeBodyReader;
27 import org.opendaylight.netconf.sal.restconf.impl.ControllerContext;
28 import org.opendaylight.netconf.sal.restconf.impl.RestconfImpl;
29 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
31 public class CodecsExceptionsCatchingTest extends JerseyTest {
33 private static RestconfImpl restConf;
34 private static ControllerContext controllerContext = ControllerContext.getInstance();
37 public static void init() throws FileNotFoundException {
38 restConf = RestconfImpl.getInstance();
39 controllerContext = ControllerContext.getInstance();
40 final SchemaContext schemaContext = TestUtils.loadSchemaContext("/decoding-exception/yang");
41 controllerContext.setGlobalSchema(schemaContext);
42 restConf.setControllerContext(controllerContext);
46 protected Application configure() {
47 /* enable/disable Jersey logs to console */
48 // enable(TestProperties.LOG_TRAFFIC);
49 // enable(TestProperties.DUMP_ENTITY);
50 // enable(TestProperties.RECORD_LOG_LEVEL);
51 // set(TestProperties.RECORD_LOG_LEVEL, Level.ALL.intValue());
52 ResourceConfig resourceConfig = new ResourceConfig();
53 resourceConfig = resourceConfig.registerInstances(restConf, new NormalizedNodeJsonBodyWriter(),
54 new NormalizedNodeXmlBodyWriter(), new XmlNormalizedNodeBodyReader(), new JsonNormalizedNodeBodyReader());
55 resourceConfig.registerClasses(RestconfDocumentedExceptionMapper.class);
56 return resourceConfig;
60 @Ignore // TODO RestconfDocumentedExceptionMapper needs be fixed before
61 public void StringToNumberConversionError() {
62 final Response response = target("/config/number:cont").request(MediaType.APPLICATION_XML).put(
63 Entity.entity("<cont xmlns=\"number\"><lf>3f</lf></cont>", MediaType.APPLICATION_XML));
64 final String exceptionMessage = response.readEntity(String.class);
65 assertTrue(exceptionMessage.contains("invalid-value"));