X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fsal%2Fyang-prototype%2Fcode-generator%2Fyang-model-parser-impl%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fyang%2Fmodel%2Fparser%2Fimpl%2FYangModelParserListenerTest.java;fp=opendaylight%2Fsal%2Fyang-prototype%2Fcode-generator%2Fyang-model-parser-impl%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fyang%2Fmodel%2Fparser%2Fimpl%2FYangModelParserListenerTest.java;h=0000000000000000000000000000000000000000;hb=6e72d221f55cfac71ee6e594b62cb5af9672614a;hp=1f0cb0301260b52eb7d0e6b9449c1b4a4e76f826;hpb=e028e5b6177c47d08f4f2da677759c4665da3f84;p=controller.git diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/yang/model/parser/impl/YangModelParserListenerTest.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/yang/model/parser/impl/YangModelParserListenerTest.java deleted file mode 100644 index 1f0cb03012..0000000000 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/yang/model/parser/impl/YangModelParserListenerTest.java +++ /dev/null @@ -1,271 +0,0 @@ -/* - * Copyright (c) 2013 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.yang.model.parser.impl; - -import static org.junit.Assert.*; - -import java.io.IOException; -import java.io.InputStream; -import java.net.URI; -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Date; -import java.util.List; -import java.util.Set; - -import org.antlr.v4.runtime.ANTLRInputStream; -import org.antlr.v4.runtime.CommonTokenStream; -import org.antlr.v4.runtime.tree.ParseTree; -import org.antlr.v4.runtime.tree.ParseTreeWalker; -import org.junit.Ignore; -import org.junit.Test; -import org.opendaylight.controller.antlrv4.code.gen.YangLexer; -import org.opendaylight.controller.antlrv4.code.gen.YangParser; -import org.opendaylight.controller.yang.common.QName; -import org.opendaylight.controller.yang.model.api.ContainerSchemaNode; -import org.opendaylight.controller.yang.model.api.DataNodeContainer; -import org.opendaylight.controller.yang.model.api.DataSchemaNode; -import org.opendaylight.controller.yang.model.api.LeafSchemaNode; -import org.opendaylight.controller.yang.model.api.ListSchemaNode; -import org.opendaylight.controller.yang.model.api.Module; -import org.opendaylight.controller.yang.model.api.ModuleImport; -import org.opendaylight.controller.yang.model.api.SchemaNode; -import org.opendaylight.controller.yang.model.api.SchemaPath; -import org.opendaylight.controller.yang.model.api.Status; -import org.opendaylight.controller.yang.model.api.TypeDefinition; -import org.opendaylight.controller.yang.model.parser.builder.impl.ModuleBuilder; -import org.opendaylight.controller.yang.model.util.Leafref; -import org.opendaylight.controller.yang.model.util.UnknownType; - -public class YangModelParserListenerTest { - - @Test - public void testParseImport() throws Exception { - Module module = getModule("/abstract-topology.yang"); - - Set imports = module.getImports(); - assertEquals(1, imports.size()); - ModuleImport moduleImport = imports.iterator().next(); - - assertEquals("inet", moduleImport.getPrefix()); - - DateFormat simpleDateFormat = new SimpleDateFormat("yyyy-mm-dd"); - Date expectedDate = simpleDateFormat.parse("2010-09-24"); - assertEquals(expectedDate, moduleImport.getRevision()); - } - - @Test - public void testParseHeaders() throws Exception { - Module module = getModule("/abstract-topology.yang"); - - URI namespace = module.getNamespace(); - URI expectedNS = URI.create(""); - assertEquals(expectedNS, namespace); - - DateFormat simpleDateFormat = new SimpleDateFormat("yyyy-mm-dd"); - Date expectedDate = simpleDateFormat.parse("2013-02-08"); - assertEquals(expectedDate, module.getRevision()); - - String prefix = module.getPrefix(); - String expectedPrefix = "tp"; - assertEquals(expectedPrefix, prefix); - - String expectedDescription = "This module contains the definitions of elements that creates network"; - assertTrue(module.getDescription().contains(expectedDescription)); - - String expectedReference = "~~~ WILL BE DEFINED LATER"; - assertEquals(expectedReference, module.getReference()); - - assertEquals("1", module.getYangVersion()); - } - - @Test - public void testParseLeafref() throws Exception { - Module module = getModule("/abstract-topology.yang"); - - Set> typedefs = module.getTypeDefinitions(); - assertEquals(2, typedefs.size()); - for(TypeDefinition td : typedefs) { - Leafref baseType = (Leafref)td.getBaseType(); - if(td.getQName().getLocalName().equals("node-id-ref")) { - assertEquals("/tp:topology/tp:network-nodes/tp:network-node/tp:node-id", baseType.getPathStatement().toString()); - } else { - assertEquals("/tp:topology/tp:network-links/tp:network-link/tp:link-id", baseType.getPathStatement().toString()); - } - } - } - - @Ignore - @Test - public void testParseModule() throws IOException { - //TODO: fix test - Module module = getModule("/test-model.yang"); - - URI namespace = module.getNamespace(); - Date revision = module.getRevision(); - String prefix = module.getPrefix(); - - String expectedDescription = "module description"; - assertEquals(expectedDescription, module.getDescription()); - - String expectedReference = "module reference"; - assertEquals(expectedReference, module.getReference()); - - Set> typedefs = module.getTypeDefinitions(); - assertEquals(10, typedefs.size()); - - Set childNodes = module.getChildNodes(); - assertEquals(1, childNodes.size()); - - final String containerName = "network"; - final QName containerQName = new QName(namespace, revision, prefix, containerName); - ContainerSchemaNode tested = (ContainerSchemaNode) module.getChildNodes().iterator().next(); - DataSchemaNode container1 = module.getDataChildByName(containerName); - DataSchemaNode container2 = module.getDataChildByName(containerQName); - - assertEquals(tested, container1); - assertEquals(container1, container2); - } - - @Ignore - @Test - public void testParseContainer() throws IOException { - //TODO: fix test - Module module = getModule("/test-model.yang"); - - URI namespace = module.getNamespace(); - Date revision = module.getRevision(); - String prefix = module.getPrefix(); - final QName containerQName = new QName(namespace, revision, prefix, "network"); - - ContainerSchemaNode tested = (ContainerSchemaNode)module.getDataChildByName(containerQName); - - Set containerChildNodes = tested.getChildNodes(); - assertEquals(3, containerChildNodes.size()); - - String expectedDescription = "network-description"; - String expectedReference = "network-reference"; - Status expectedStatus = Status.OBSOLETE; - testDesc_Ref_Status(tested, expectedDescription, expectedReference, expectedStatus); - - List path = new ArrayList(); - path.add(new QName(namespace, revision, prefix, "test-model")); - path.add(containerQName); - SchemaPath expectedSchemaPath = new SchemaPath(path, true); - assertEquals(expectedSchemaPath, tested.getPath()); - - assertTrue(tested.isConfiguration()); - assertTrue(tested.isPresenceContainer()); - } - - @Ignore - @Test - public void testParseList() throws IOException { - //TODO: fix test - Module module = getModule("/test-model.yang"); - - URI namespace = module.getNamespace(); - Date revision = module.getRevision(); - String prefix = module.getPrefix(); - final QName listQName = new QName(namespace, revision, prefix, "topology"); - - DataNodeContainer networkContainer = (DataNodeContainer)module.getDataChildByName("network"); - DataNodeContainer topologiesContainer = (DataNodeContainer)networkContainer.getDataChildByName("topologies"); - ListSchemaNode tested = (ListSchemaNode)topologiesContainer.getDataChildByName(listQName); - assertEquals(listQName, tested.getQName()); - - String expectedDescription = "Test description of list 'topology'."; - String expectedReference = null; - Status expectedStatus = Status.CURRENT; - testDesc_Ref_Status(tested, expectedDescription, expectedReference, expectedStatus); - - List path = new ArrayList(); - path.add(new QName(namespace, revision, prefix, "test-model")); - path.add(new QName(namespace, revision, prefix, "network")); - path.add(new QName(namespace, revision, prefix, "topologies")); - path.add(listQName); - SchemaPath expectedSchemaPath = new SchemaPath(path, true); - assertEquals(expectedSchemaPath, tested.getPath()); - - List expectedKey = new ArrayList(); - expectedKey.add(new QName(namespace, revision, prefix, "topology-id")); - assertEquals(expectedKey, tested.getKeyDefinition()); - - assertEquals(Collections.EMPTY_SET, tested.getTypeDefinitions()); - assertEquals(Collections.EMPTY_SET, tested.getUses()); - assertEquals(Collections.EMPTY_SET, tested.getGroupings()); - - assertTrue(tested.getDataChildByName("topology-id") instanceof LeafSchemaNode); - } - - @Ignore - @Test - public void testParseLeaf() throws IOException { - //TODO: fix test - Module module = getModule("/test-model.yang"); - - URI namespace = module.getNamespace(); - Date revision = module.getRevision(); - String prefix = module.getPrefix(); - final QName leafQName = new QName(namespace, revision, prefix, "topology-id"); - - DataNodeContainer networkContainer = (DataNodeContainer)module.getDataChildByName("network"); - DataNodeContainer topologiesContainer = (DataNodeContainer)networkContainer.getDataChildByName("topologies"); - DataNodeContainer topologyList = (DataNodeContainer)topologiesContainer.getDataChildByName("topology"); - LeafSchemaNode tested = (LeafSchemaNode)topologyList.getDataChildByName(leafQName); - assertEquals(leafQName, tested.getQName()); - - String expectedDescription = "Test description of leaf 'topology-id'"; - String expectedReference = null; - Status expectedStatus = Status.CURRENT; - testDesc_Ref_Status(tested, expectedDescription, expectedReference, expectedStatus); - - List path = new ArrayList(); - path.add(new QName(namespace, revision, prefix, "test-model")); - path.add(new QName(namespace, revision, prefix, "network")); - path.add(new QName(namespace, revision, prefix, "topologies")); - path.add(new QName(namespace, revision, prefix, "topology")); - path.add(leafQName); - SchemaPath expectedSchemaPath = new SchemaPath(path, true); - assertEquals(expectedSchemaPath, tested.getPath()); - - UnknownType.Builder typeBuilder = new UnknownType.Builder(new QName(namespace, revision, prefix, "topology-id"), null, null); - TypeDefinition expectedType = typeBuilder.build(); - assertEquals(expectedType, tested.getType()); - } - - - private void testDesc_Ref_Status(SchemaNode tested, String expectedDescription, String expectedReference, Status expectedStatus) { - assertEquals(expectedDescription, tested.getDescription()); - assertEquals(expectedReference, tested.getReference()); - assertEquals(expectedStatus, tested.getStatus()); - } - - private Module getModule(String testFile) throws IOException { - ModuleBuilder builder = getBuilder(testFile); - return builder.build(); - } - - private ModuleBuilder getBuilder(String fileName) throws IOException { - final InputStream inStream = getClass().getResourceAsStream(fileName); - ANTLRInputStream input = new ANTLRInputStream(inStream); - final YangLexer lexer = new YangLexer(input); - final CommonTokenStream tokens = new CommonTokenStream(lexer); - final YangParser parser = new YangParser(tokens); - - final ParseTree tree = parser.yang(); - final ParseTreeWalker walker = new ParseTreeWalker(); - - final YangModelParserListenerImpl modelParser = new YangModelParserListenerImpl(); - walker.walk(modelParser, tree); - return modelParser.getModuleBuilder(); - } - -}