/* * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ package org.opendaylight.controller.sal.restconf.impl.test; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.fail; import java.util.List; import java.util.Set; import javax.ws.rs.ext.MessageBodyReader; import org.junit.Test; import org.opendaylight.controller.sal.rest.impl.JsonToCompositeNodeProvider; import org.opendaylight.controller.sal.rest.impl.XmlToCompositeNodeProvider; import org.opendaylight.controller.sal.restconf.impl.RestconfDocumentedException; import org.opendaylight.controller.sal.restconf.impl.RestconfError; import org.opendaylight.controller.sal.restconf.impl.RestconfError.ErrorTag; import org.opendaylight.controller.sal.restconf.impl.RestconfError.ErrorType; import org.opendaylight.yangtools.yang.data.api.CompositeNode; import org.opendaylight.yangtools.yang.model.api.Module; /** * If more then one data element with equal name exists where container or leaf schema node should be present the * RestconfDocumentedException has to be raised * * Tests for BUG 1204 */ public class MultipleEqualNamesForDataNodesTest { @Test public void multipleEqualNameDataNodeTestForContainerJsonTest() { multipleEqualNameDataNodeTest("/equal-data-node-names/equal-name-data-for-container.json", ErrorType.APPLICATION, ErrorTag.BAD_ELEMENT, JsonToCompositeNodeProvider.INSTANCE); } @Test public void multipleEqualNameDataNodeTestForLeafJsonTest() { multipleEqualNameDataNodeTest("/equal-data-node-names/equal-name-data-for-leaf.json", ErrorType.PROTOCOL, ErrorTag.MALFORMED_MESSAGE, JsonToCompositeNodeProvider.INSTANCE); } @Test public void multipleEqualNameDataNodeTestForContainerXmlTest() { multipleEqualNameDataNodeTest("/equal-data-node-names/equal-name-data-for-container.xml", ErrorType.APPLICATION, ErrorTag.BAD_ELEMENT, XmlToCompositeNodeProvider.INSTANCE); } @Test public void multipleEqualNameDataNodeTestForLeafXmlTest() { multipleEqualNameDataNodeTest("/equal-data-node-names/equal-name-data-for-leaf.xml", ErrorType.APPLICATION, ErrorTag.BAD_ELEMENT, XmlToCompositeNodeProvider.INSTANCE); } private void multipleEqualNameDataNodeTest(String path, ErrorType errorType, ErrorTag errorTag, MessageBodyReader messageBodyReader) { try { CompositeNode compositeNode = TestUtils.readInputToCnSn(path, false, messageBodyReader); assertNotNull(compositeNode); Set modules = null; modules = TestUtils.loadModulesFrom("/equal-data-node-names/yang"); assertNotNull(modules); TestUtils.normalizeCompositeNode(compositeNode, modules, "equal-data-node-names" + ":" + "cont"); fail("Exception RestconfDocumentedException should be raised"); } catch (RestconfDocumentedException e) { List errors = e.getErrors(); assertNotNull(errors); assertEquals(1, errors.size()); RestconfError restconfError = errors.get(0); assertEquals(errorType, restconfError.getErrorType()); assertEquals(errorTag, restconfError.getErrorTag()); } } }