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.Node;
25 import org.opendaylight.yangtools.yang.model.api.Module;
28 * If more then one data element with equal name exists where container or leaf schema node should be present the
29 * RestconfDocumentedException has to be raised
33 public class MultipleEqualNamesForDataNodesTest {
36 public void multipleEqualNameDataNodeTestForContainerJsonTest() {
37 multipleEqualNameDataNodeTest("/equal-data-node-names/equal-name-data-for-container.json",
38 ErrorType.APPLICATION, ErrorTag.BAD_ELEMENT, JsonToCompositeNodeProvider.INSTANCE);
42 public void multipleEqualNameDataNodeTestForLeafJsonTest() {
43 multipleEqualNameDataNodeTest("/equal-data-node-names/equal-name-data-for-leaf.json", ErrorType.PROTOCOL,
44 ErrorTag.MALFORMED_MESSAGE, JsonToCompositeNodeProvider.INSTANCE);
48 public void multipleEqualNameDataNodeTestForContainerXmlTest() {
49 multipleEqualNameDataNodeTest("/equal-data-node-names/equal-name-data-for-container.xml",
50 ErrorType.APPLICATION, ErrorTag.BAD_ELEMENT, XmlToCompositeNodeProvider.INSTANCE);
54 public void multipleEqualNameDataNodeTestForLeafXmlTest() {
55 multipleEqualNameDataNodeTest("/equal-data-node-names/equal-name-data-for-leaf.xml", ErrorType.APPLICATION,
56 ErrorTag.BAD_ELEMENT, XmlToCompositeNodeProvider.INSTANCE);
59 private void multipleEqualNameDataNodeTest(String path, ErrorType errorType, ErrorTag errorTag,
60 MessageBodyReader<Node<?>> messageBodyReader) {
62 Node<?> node = TestUtils.readInputToCnSn(path, false, messageBodyReader);
65 Set<Module> modules = null;
66 modules = TestUtils.loadModulesFrom("/equal-data-node-names/yang");
67 assertNotNull(modules);
69 TestUtils.normalizeCompositeNode(node, 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());