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;
13 import java.io.FileNotFoundException;
14 import javax.ws.rs.client.Entity;
15 import javax.ws.rs.core.Application;
16 import javax.ws.rs.core.MediaType;
17 import javax.ws.rs.core.Response;
18 import org.glassfish.jersey.server.ResourceConfig;
19 import org.glassfish.jersey.test.JerseyTest;
20 import org.junit.Before;
21 import org.junit.Ignore;
22 import org.junit.Test;
23 import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils;
24 import org.opendaylight.netconf.sal.rest.impl.JsonNormalizedNodeBodyReader;
25 import org.opendaylight.netconf.sal.rest.impl.NormalizedNodeJsonBodyWriter;
26 import org.opendaylight.netconf.sal.rest.impl.NormalizedNodeXmlBodyWriter;
27 import org.opendaylight.netconf.sal.rest.impl.RestconfDocumentedExceptionMapper;
28 import org.opendaylight.netconf.sal.rest.impl.XmlNormalizedNodeBodyReader;
29 import org.opendaylight.netconf.sal.restconf.impl.ControllerContext;
30 import org.opendaylight.netconf.sal.restconf.impl.RestconfImpl;
31 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
32 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
34 public class CodecsExceptionsCatchingTest extends JerseyTest {
36 private RestconfImpl restConf;
37 private ControllerContext controllerContext;
40 public void init() throws FileNotFoundException, ReactorException {
41 restConf = RestconfImpl.getInstance();
42 final SchemaContext schemaContext = TestUtils.loadSchemaContext("/decoding-exception/yang");
43 controllerContext = TestRestconfUtils.newControllerContext(schemaContext);
44 restConf.setControllerContext(controllerContext);
48 protected Application configure() {
49 /* enable/disable Jersey logs to console */
50 // enable(TestProperties.LOG_TRAFFIC);
51 // enable(TestProperties.DUMP_ENTITY);
52 // enable(TestProperties.RECORD_LOG_LEVEL);
53 // set(TestProperties.RECORD_LOG_LEVEL, Level.ALL.intValue());
54 ResourceConfig resourceConfig = new ResourceConfig();
55 resourceConfig = resourceConfig.registerInstances(restConf, new NormalizedNodeJsonBodyWriter(),
56 new NormalizedNodeXmlBodyWriter(), new XmlNormalizedNodeBodyReader(controllerContext),
57 new JsonNormalizedNodeBodyReader(controllerContext));
58 resourceConfig.registerClasses(RestconfDocumentedExceptionMapper.class);
59 return resourceConfig;
63 @Ignore // TODO RestconfDocumentedExceptionMapper needs be fixed before
64 public void stringToNumberConversionError() {
65 final Response response = target("/config/number:cont").request(MediaType.APPLICATION_XML).put(
66 Entity.entity("<cont xmlns=\"number\"><lf>3f</lf></cont>", MediaType.APPLICATION_XML));
67 final String exceptionMessage = response.readEntity(String.class);
68 assertTrue(exceptionMessage.contains("invalid-value"));