2 * Copyright (c) 2014 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
8 package org.opendaylight.controller.sal.restconf.impl.test;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.fail;
14 import java.util.List;
16 import javax.ws.rs.ext.MessageBodyReader;
17 import org.junit.Test;
18 import org.opendaylight.controller.sal.rest.impl.JsonToCompositeNodeProvider;
19 import org.opendaylight.controller.sal.rest.impl.XmlToCompositeNodeProvider;
20 import org.opendaylight.controller.sal.restconf.impl.RestconfDocumentedException;
21 import org.opendaylight.controller.sal.restconf.impl.RestconfError;
22 import org.opendaylight.controller.sal.restconf.impl.RestconfError.ErrorTag;
23 import org.opendaylight.controller.sal.restconf.impl.RestconfError.ErrorType;
24 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
25 import org.opendaylight.yangtools.yang.model.api.Module;
28 * If more then one data element with equal name exists where container or
29 * leaf schema node should be present the RestconfDocumentedException has to
34 public class MultipleEqualNamesForDataNodesTest {
37 public void multipleEqualNameDataNodeTestForContainerJsonTest() {
38 multipleEqualNameDataNodeTest("/equal-data-node-names/equal-name-data-for-container.json", ErrorType.APPLICATION,
39 ErrorTag.BAD_ELEMENT,JsonToCompositeNodeProvider.INSTANCE);
43 public void multipleEqualNameDataNodeTestForLeafJsonTest() {
44 multipleEqualNameDataNodeTest("/equal-data-node-names/equal-name-data-for-leaf.json", ErrorType.PROTOCOL,
45 ErrorTag.MALFORMED_MESSAGE,JsonToCompositeNodeProvider.INSTANCE);
49 public void multipleEqualNameDataNodeTestForContainerXmlTest() {
50 multipleEqualNameDataNodeTest("/equal-data-node-names/equal-name-data-for-container.xml", ErrorType.APPLICATION,
51 ErrorTag.BAD_ELEMENT,XmlToCompositeNodeProvider.INSTANCE);
55 public void multipleEqualNameDataNodeTestForLeafXmlTest() {
56 multipleEqualNameDataNodeTest("/equal-data-node-names/equal-name-data-for-leaf.xml", ErrorType.APPLICATION,
57 ErrorTag.BAD_ELEMENT,XmlToCompositeNodeProvider.INSTANCE);
60 private void multipleEqualNameDataNodeTest(String path, ErrorType errorType, ErrorTag errorTag,MessageBodyReader<CompositeNode> messageBodyReader) {
62 CompositeNode compositeNode = TestUtils.readInputToCnSn(path, false,messageBodyReader);
63 assertNotNull(compositeNode);
65 Set<Module> modules = null;
66 modules = TestUtils.loadModulesFrom("/equal-data-node-names/yang");
67 assertNotNull(modules);
69 TestUtils.normalizeCompositeNode(compositeNode, modules, "equal-data-node-names" + ":" + "cont");
70 fail("Exception RestconfDocumentedException should be raised");
71 } catch (RestconfDocumentedException e) {
72 List<RestconfError> errors = e.getErrors();
73 assertNotNull(errors);
75 assertEquals(1, errors.size());
77 RestconfError restconfError = errors.get(0);
79 assertEquals(errorType, restconfError.getErrorType());
80 assertEquals(errorTag, restconfError.getErrorTag());