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