From 92aeec3acd1ef423221ad6d3933c92af87946b3a Mon Sep 17 00:00:00 2001 From: Peter Nosal Date: Tue, 17 May 2016 15:09:07 +0200 Subject: [PATCH] Removed usage of deprecated YangParserImpl from tests in mdsal project Change-Id: I0e5d5e565c97d1ecdc1f764609382be3dda2ef59 Signed-off-by: Peter Nosal --- .../doc/generator/maven/DocGenTest.java | 16 +- .../maven/{retest => }/RetestUtils.java | 4 +- .../maven/YangModuleInfoCompilationTest.java | 7 +- .../generator/maven/retest/DocGenTest.java | 88 -- .../retest/YangModuleInfoCompilationTest.java | 220 ---- .../wadl/generator/maven/WadlGenTest.java | 17 +- .../generator/maven/retest/WadlGenTest.java | 89 -- .../generator/impl/AbstractTypesTest.java | 2 +- .../impl/AugmentRelativeXPathTest.java | 14 +- .../generator/impl/AugmentedTypeTest.java | 9 +- .../generator/impl/BinaryTypeTest.java | 23 +- .../impl/BindingGeneratorImplTest.java | 37 +- .../impl/BitAndUnionTOEnclosingTest.java | 17 +- .../binding/generator/impl/Bug4145Test.java | 15 +- .../impl/ChoiceCaseGenTypesTest.java | 13 +- .../generator/impl/ControllerTest.java | 7 +- .../generator/impl/ExtendedTypedefTest.java | 10 +- .../generator/impl/GenEnumResolvingTest.java | 23 +- .../generator/impl/GenTypesSubSetTest.java | 13 +- ...InnerClassForBitsAndUnionInLeavesTest.java | 19 +- .../impl/GeneratedTypesBitsTest.java | 17 +- .../impl/GeneratedTypesLeafrefTest.java | 49 +- .../impl/GeneratedTypesStringTest.java | 13 +- .../generator/impl/GeneratedTypesTest.java | 33 +- .../generator/impl/IdentityrefTypeTest.java | 17 +- .../generator/impl/NameTypePattern.java | 2 +- .../binding/generator/impl}/RetestUtils.java | 10 +- .../generator/impl/SupportTestUtil.java | 12 +- .../impl/TypeProviderIntegrationTest.java | 6 +- .../generator/impl/UnionTypeDefTest.java | 7 +- .../sal/binding/generator/impl/UsesTest.java | 62 +- .../stmt/parser/retest/AbstractTypesTest.java | 40 - .../retest/AugmentRelativeXPathTest.java | 130 --- .../stmt/parser/retest/AugmentedTypeTest.java | 182 ---- .../stmt/parser/retest/BinaryTypeTest.java | 57 -- .../retest/BindingGeneratorImplTest.java | 197 ---- .../retest/BitAndUnionTOEnclosingTest.java | 273 ----- .../parser/retest/ChoiceCaseGenTypesTest.java | 175 ---- .../stmt/parser/retest/ControllerTest.java | 37 - .../parser/retest/ExtendedTypedefTest.java | 134 --- .../parser/retest/GenEnumResolvingTest.java | 164 --- .../parser/retest/GenTypesSubSetTest.java | 91 -- ...InnerClassForBitsAndUnionInLeavesTest.java | 143 --- .../parser/retest/GeneratedTypesBitsTest.java | 128 --- .../retest/GeneratedTypesLeafrefTest.java | 238 ----- .../retest/GeneratedTypesStringTest.java | 127 --- .../parser/retest/GeneratedTypesTest.java | 414 -------- .../parser/retest/IdentityrefTypeTest.java | 103 -- .../stmt/parser/retest/NameTypePattern.java | 26 - .../stmt/parser/retest/SupportTestUtil.java | 148 --- .../retest/TypeProviderIntegrationTest.java | 298 ------ .../stmt/parser/retest/UnionTypeDefTest.java | 37 - .../impl/stmt/parser/retest/UsesTest.java | 601 ----------- .../binding/yang/types/BaseYangTypesTest.java | 20 +- .../LeafrefTypeWithNullToStringInXpath.java | 3 +- .../yang/types/LeafrefTypeWithNullXpath.java | 3 +- .../{stmt/parser/retest => }/RetestUtils.java | 10 +- .../yang/types/TestIntegerTypeDefinition.java | 3 +- .../yang/types/TestLeafSchemaNode.java | 3 +- .../yang/types/TypeProviderImplTest.java | 64 +- .../binding/yang/types/TypeProviderModel.java | 15 +- .../binding/yang/types/TypeProviderTest.java | 30 +- .../stmt/parser/retest/BaseYangTypesTest.java | 277 ------ .../LeafrefTypeWithNullToStringInXpath.java | 76 -- .../retest/LeafrefTypeWithNullXpath.java | 63 -- .../retest/TestIntegerTypeDefinition.java | 64 -- .../parser/retest/TestLeafSchemaNode.java | 71 -- .../parser/retest/TypeProviderImplTest.java | 193 ---- .../stmt/parser/retest/TypeProviderModel.java | 48 - .../stmt/parser/retest/TypeProviderTest.java | 938 ------------------ .../util/BindingGeneratorUtilTest.java | 22 +- .../binding/generator/util}/RetestUtils.java | 10 +- .../retest/BindingGeneratorUtilTest.java | 438 -------- ...AugmentToUsesInAugmentCompilationTest.java | 119 --- .../parser/retest/BaseCompilationTest.java | 38 - .../stmt/parser/retest/Bug1276Test.java | 104 -- .../stmt/parser/retest/Bug532Test.java | 119 --- .../retest/CascadeUsesCompilationTest.java | 143 --- .../parser/retest/ClassCodeGeneratorTest.java | 146 --- .../stmt/parser/retest/CompilationTest.java | 705 ------------- .../parser/retest/CompilationTestUtils.java | 428 -------- .../parser/retest/EndodingInJavaDocTest.java | 42 - .../parser/retest/GeneratorJavaFileTest.java | 63 -- .../retest/NestedGroupingCompilationTest.java | 85 -- .../parser/retest/TypedefCompilationTest.java | 349 ------- .../retest/UnionTypedefUnusedImportTest.java | 68 -- .../stmt/parser/retest/package-info.java | 8 - ...AugmentToUsesInAugmentCompilationTest.java | 66 +- .../generator/test/BaseCompilationTest.java | 18 +- .../java/api/generator/test/Bug1276Test.java | 35 +- .../java/api/generator/test/Bug532Test.java | 20 +- .../test/CascadeUsesCompilationTest.java | 4 +- .../test/ClassCodeGeneratorTest.java | 12 +- .../api/generator/test/CompilationTest.java | 371 +++---- .../generator/test/CompilationTestUtils.java | 2 +- .../generator/test/EncodingInJavaDocTest.java | 7 +- .../generator/test/GeneratorJavaFileTest.java | 6 +- .../test/NestedGroupingCompilationTest.java | 4 +- .../parser/retest => test}/RetestUtils.java | 10 +- .../test/TypedefCompilationTest.java | 245 +++-- .../test/UnionTypedefUnusedImportTest.java | 4 +- .../mdsal/dom/broker/test/DOMBrokerTest.java | 2 +- .../broker/test/DOMDataTreeListenerTest.java | 2 +- .../broker/test/DOMTransactionChainTest.java | 2 +- ...rdedDOMDataTreeProducerMultiShardTest.java | 4 +- .../mdsal/dom/broker/test/util/TestModel.java | 19 +- .../dom/store/impl/InMemoryDataStoreTest.java | 3 +- .../md/sal/dom/store/impl/TestModel.java | 29 +- 108 files changed, 757 insertions(+), 9490 deletions(-) rename binding/maven-sal-api-gen-plugin/src/test/java/org/opendaylight/yangtools/yang/unified/doc/generator/maven/{retest => }/RetestUtils.java (97%) delete mode 100644 binding/maven-sal-api-gen-plugin/src/test/java/org/opendaylight/yangtools/yang/unified/doc/generator/maven/retest/DocGenTest.java delete mode 100644 binding/maven-sal-api-gen-plugin/src/test/java/org/opendaylight/yangtools/yang/unified/doc/generator/maven/retest/YangModuleInfoCompilationTest.java delete mode 100644 binding/maven-sal-api-gen-plugin/src/test/java/org/opendaylight/yangtools/yang/wadl/generator/maven/retest/WadlGenTest.java rename binding/{mdsal-binding-generator-util/src/test/java/org/opendaylight/yangtools/binding/generator/util/stmt/parser/retest => mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl}/RetestUtils.java (82%) delete mode 100644 binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/AbstractTypesTest.java delete mode 100644 binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/AugmentRelativeXPathTest.java delete mode 100644 binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/AugmentedTypeTest.java delete mode 100644 binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/BinaryTypeTest.java delete mode 100644 binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/BindingGeneratorImplTest.java delete mode 100644 binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/BitAndUnionTOEnclosingTest.java delete mode 100644 binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/ChoiceCaseGenTypesTest.java delete mode 100644 binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/ControllerTest.java delete mode 100644 binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/ExtendedTypedefTest.java delete mode 100644 binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/GenEnumResolvingTest.java delete mode 100644 binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/GenTypesSubSetTest.java delete mode 100644 binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/GenerateInnerClassForBitsAndUnionInLeavesTest.java delete mode 100644 binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/GeneratedTypesBitsTest.java delete mode 100644 binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/GeneratedTypesLeafrefTest.java delete mode 100644 binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/GeneratedTypesStringTest.java delete mode 100644 binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/GeneratedTypesTest.java delete mode 100644 binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/IdentityrefTypeTest.java delete mode 100644 binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/NameTypePattern.java delete mode 100644 binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/SupportTestUtil.java delete mode 100644 binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/TypeProviderIntegrationTest.java delete mode 100644 binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/UnionTypeDefTest.java delete mode 100644 binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/UsesTest.java rename binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/{stmt/parser/retest => }/RetestUtils.java (85%) delete mode 100644 binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/stmt/parser/retest/BaseYangTypesTest.java delete mode 100644 binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/stmt/parser/retest/LeafrefTypeWithNullToStringInXpath.java delete mode 100644 binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/stmt/parser/retest/LeafrefTypeWithNullXpath.java delete mode 100644 binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/stmt/parser/retest/TestIntegerTypeDefinition.java delete mode 100644 binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/stmt/parser/retest/TestLeafSchemaNode.java delete mode 100644 binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/stmt/parser/retest/TypeProviderImplTest.java delete mode 100644 binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/stmt/parser/retest/TypeProviderModel.java delete mode 100644 binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/stmt/parser/retest/TypeProviderTest.java rename binding/{mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest => mdsal-binding-generator-util/src/test/java/org/opendaylight/yangtools/binding/generator/util}/RetestUtils.java (82%) delete mode 100644 binding/mdsal-binding-generator-util/src/test/java/org/opendaylight/yangtools/binding/generator/util/stmt/parser/retest/BindingGeneratorUtilTest.java delete mode 100644 binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/stmt/parser/retest/AugmentToUsesInAugmentCompilationTest.java delete mode 100644 binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/stmt/parser/retest/BaseCompilationTest.java delete mode 100644 binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/stmt/parser/retest/Bug1276Test.java delete mode 100644 binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/stmt/parser/retest/Bug532Test.java delete mode 100644 binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/stmt/parser/retest/CascadeUsesCompilationTest.java delete mode 100644 binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/stmt/parser/retest/ClassCodeGeneratorTest.java delete mode 100644 binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/stmt/parser/retest/CompilationTest.java delete mode 100644 binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/stmt/parser/retest/CompilationTestUtils.java delete mode 100644 binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/stmt/parser/retest/EndodingInJavaDocTest.java delete mode 100644 binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/stmt/parser/retest/GeneratorJavaFileTest.java delete mode 100644 binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/stmt/parser/retest/NestedGroupingCompilationTest.java delete mode 100644 binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/stmt/parser/retest/TypedefCompilationTest.java delete mode 100644 binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/stmt/parser/retest/UnionTypedefUnusedImportTest.java delete mode 100644 binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/stmt/parser/retest/package-info.java rename binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/{stmt/parser/retest => test}/RetestUtils.java (85%) diff --git a/binding/maven-sal-api-gen-plugin/src/test/java/org/opendaylight/yangtools/yang/unified/doc/generator/maven/DocGenTest.java b/binding/maven-sal-api-gen-plugin/src/test/java/org/opendaylight/yangtools/yang/unified/doc/generator/maven/DocGenTest.java index 1e9ae3586e..a65d8c1bab 100644 --- a/binding/maven-sal-api-gen-plugin/src/test/java/org/opendaylight/yangtools/yang/unified/doc/generator/maven/DocGenTest.java +++ b/binding/maven-sal-api-gen-plugin/src/test/java/org/opendaylight/yangtools/yang/unified/doc/generator/maven/DocGenTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2016 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, @@ -16,18 +16,18 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.List; +import java.util.Set; import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl; import org.opendaylight.yangtools.yang2sources.spi.BasicCodeGenerator; public class DocGenTest { public static final String FS = File.separator; private static final String TEST_PATH = "target" + FS + "test" + FS + "site"; private static final File GENERATOR_OUTPUT_DIR = new File(TEST_PATH); - private YangParserImpl parser; @Before public void init() { @@ -35,7 +35,6 @@ public class DocGenTest { deleteTestDir(GENERATOR_OUTPUT_DIR); } assertTrue(GENERATOR_OUTPUT_DIR.mkdirs()); - parser = new YangParserImpl(); } @After @@ -48,13 +47,14 @@ public class DocGenTest { @Test public void testListGeneration() throws Exception { final List sourceFiles = getSourceFiles("/doc-gen"); - final SchemaContext context = parser.parseFiles(sourceFiles); + final SchemaContext context = RetestUtils.parseYangSources(sourceFiles); + final Set modules = context.getModules(); final BasicCodeGenerator generator = new DocumentationGeneratorImpl(); - Collection generatedFiles = generator.generateSources(context, GENERATOR_OUTPUT_DIR, context.getModules()); + Collection generatedFiles = generator.generateSources(context, GENERATOR_OUTPUT_DIR, modules); assertEquals(4, generatedFiles.size()); } - private static List getSourceFiles(final String path) throws Exception { + private static List getSourceFiles(String path) throws Exception { final URI resPath = DocGenTest.class.getResource(path).toURI(); final File sourcesDir = new File(resPath); if (sourcesDir.exists()) { @@ -70,7 +70,7 @@ public class DocGenTest { } } - private static void deleteTestDir(final File file) { + private static void deleteTestDir(File file) { if (file.isDirectory()) { File[] filesToDelete = file.listFiles(); if (filesToDelete != null) { diff --git a/binding/maven-sal-api-gen-plugin/src/test/java/org/opendaylight/yangtools/yang/unified/doc/generator/maven/retest/RetestUtils.java b/binding/maven-sal-api-gen-plugin/src/test/java/org/opendaylight/yangtools/yang/unified/doc/generator/maven/RetestUtils.java similarity index 97% rename from binding/maven-sal-api-gen-plugin/src/test/java/org/opendaylight/yangtools/yang/unified/doc/generator/maven/retest/RetestUtils.java rename to binding/maven-sal-api-gen-plugin/src/test/java/org/opendaylight/yangtools/yang/unified/doc/generator/maven/RetestUtils.java index d6fcc915d9..b3459071ee 100644 --- a/binding/maven-sal-api-gen-plugin/src/test/java/org/opendaylight/yangtools/yang/unified/doc/generator/maven/retest/RetestUtils.java +++ b/binding/maven-sal-api-gen-plugin/src/test/java/org/opendaylight/yangtools/yang/unified/doc/generator/maven/RetestUtils.java @@ -1,12 +1,12 @@ /* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2016 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.yangtools.yang.unified.doc.generator.maven.retest; +package org.opendaylight.yangtools.yang.unified.doc.generator.maven; import org.opendaylight.yangtools.yang.parser.util.NamedFileInputStream; diff --git a/binding/maven-sal-api-gen-plugin/src/test/java/org/opendaylight/yangtools/yang/unified/doc/generator/maven/YangModuleInfoCompilationTest.java b/binding/maven-sal-api-gen-plugin/src/test/java/org/opendaylight/yangtools/yang/unified/doc/generator/maven/YangModuleInfoCompilationTest.java index ec026beec3..f907d19075 100644 --- a/binding/maven-sal-api-gen-plugin/src/test/java/org/opendaylight/yangtools/yang/unified/doc/generator/maven/YangModuleInfoCompilationTest.java +++ b/binding/maven-sal-api-gen-plugin/src/test/java/org/opendaylight/yangtools/yang/unified/doc/generator/maven/YangModuleInfoCompilationTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2016 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, @@ -30,8 +30,6 @@ import org.junit.Test; import org.opendaylight.yangtools.maven.sal.api.gen.plugin.CodeGeneratorImpl; import org.opendaylight.yangtools.yang.binding.YangModuleInfo; import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.model.parser.api.YangContextParser; -import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl; import org.sonatype.plexus.build.incremental.DefaultBuildContext; /** @@ -133,8 +131,7 @@ public class YangModuleInfoCompilationTest { private static void generateTestSources(final String resourceDirPath, final File sourcesOutputDir) throws Exception { final List sourceFiles = getSourceFiles(resourceDirPath); - YangContextParser parser = new YangParserImpl(); - final SchemaContext context = parser.parseFiles(sourceFiles); + final SchemaContext context = RetestUtils.parseYangSources(sourceFiles); CodeGeneratorImpl codegen = new CodeGeneratorImpl(); codegen.setBuildContext(new DefaultBuildContext()); codegen.generateSources(context, sourcesOutputDir, context.getModules()); diff --git a/binding/maven-sal-api-gen-plugin/src/test/java/org/opendaylight/yangtools/yang/unified/doc/generator/maven/retest/DocGenTest.java b/binding/maven-sal-api-gen-plugin/src/test/java/org/opendaylight/yangtools/yang/unified/doc/generator/maven/retest/DocGenTest.java deleted file mode 100644 index 20fd0ec7a1..0000000000 --- a/binding/maven-sal-api-gen-plugin/src/test/java/org/opendaylight/yangtools/yang/unified/doc/generator/maven/retest/DocGenTest.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright (c) 2015 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.yangtools.yang.unified.doc.generator.maven.retest; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import java.io.File; -import java.io.FileNotFoundException; -import java.net.URI; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; -import java.util.Set; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.opendaylight.yangtools.yang.model.api.Module; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.unified.doc.generator.maven.DocumentationGeneratorImpl; -import org.opendaylight.yangtools.yang2sources.spi.BasicCodeGenerator; - -public class DocGenTest { - public static final String FS = File.separator; - private static final String TEST_PATH = "target" + FS + "test" + FS + "site"; - private static final File GENERATOR_OUTPUT_DIR = new File(TEST_PATH); - - @Before - public void init() { - if (GENERATOR_OUTPUT_DIR.exists()) { - deleteTestDir(GENERATOR_OUTPUT_DIR); - } - assertTrue(GENERATOR_OUTPUT_DIR.mkdirs()); - } - - @After - public void cleanUp() { - if (GENERATOR_OUTPUT_DIR.exists()) { - deleteTestDir(GENERATOR_OUTPUT_DIR); - } - } - - @Test - public void testListGeneration() throws Exception { - final List sourceFiles = getSourceFiles("/doc-gen"); - final SchemaContext context = RetestUtils.parseYangSources(sourceFiles); - final Set modules = context.getModules(); - final BasicCodeGenerator generator = new DocumentationGeneratorImpl(); - Collection generatedFiles = generator.generateSources(context, GENERATOR_OUTPUT_DIR, modules); - assertEquals(4, generatedFiles.size()); - } - - private static List getSourceFiles(String path) throws Exception { - final URI resPath = DocGenTest.class.getResource(path).toURI(); - final File sourcesDir = new File(resPath); - if (sourcesDir.exists()) { - final List sourceFiles = new ArrayList<>(); - final File[] fileArray = sourcesDir.listFiles(); - if (fileArray == null) { - throw new IllegalArgumentException("Unable to locate files in " + sourcesDir); - } - sourceFiles.addAll(Arrays.asList(fileArray)); - return sourceFiles; - } else { - throw new FileNotFoundException("Testing files were not found(" + sourcesDir.getName() + ")"); - } - } - - private static void deleteTestDir(File file) { - if (file.isDirectory()) { - File[] filesToDelete = file.listFiles(); - if (filesToDelete != null) { - for (File f : filesToDelete) { - deleteTestDir(f); - } - } - } - if (!file.delete()) { - throw new RuntimeException("Failed to clean up after test"); - } - } - -} diff --git a/binding/maven-sal-api-gen-plugin/src/test/java/org/opendaylight/yangtools/yang/unified/doc/generator/maven/retest/YangModuleInfoCompilationTest.java b/binding/maven-sal-api-gen-plugin/src/test/java/org/opendaylight/yangtools/yang/unified/doc/generator/maven/retest/YangModuleInfoCompilationTest.java deleted file mode 100644 index 2836f83425..0000000000 --- a/binding/maven-sal-api-gen-plugin/src/test/java/org/opendaylight/yangtools/yang/unified/doc/generator/maven/retest/YangModuleInfoCompilationTest.java +++ /dev/null @@ -1,220 +0,0 @@ -/* - * Copyright (c) 2015 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.yangtools.yang.unified.doc.generator.maven.retest; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import java.io.File; -import java.io.FileNotFoundException; -import java.lang.reflect.Method; -import java.net.URI; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Set; -import javax.tools.JavaCompiler; -import javax.tools.JavaFileObject; -import javax.tools.StandardJavaFileManager; -import javax.tools.ToolProvider; -import org.junit.BeforeClass; -import org.junit.Test; -import org.opendaylight.yangtools.maven.sal.api.gen.plugin.CodeGeneratorImpl; -import org.opendaylight.yangtools.yang.binding.YangModuleInfo; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.sonatype.plexus.build.incremental.DefaultBuildContext; - -/** - * Test correct generation of YangModuleInfo class. - * - */ -// TODO: most of private static methods are copied from -// binding-java-api-generator project - reorganize compilation tests -public class YangModuleInfoCompilationTest { - public static final String FS = File.separator; - private static final String BASE_PKG = "org.opendaylight.yang.gen.v1"; - - private static final String TEST_PATH = "target" + FS + "test"; - private static final File TEST_DIR = new File(TEST_PATH); - - private static final String GENERATOR_OUTPUT_PATH = TEST_PATH + FS + "src"; - private static final File GENERATOR_OUTPUT_DIR = new File(GENERATOR_OUTPUT_PATH); - private static final String COMPILER_OUTPUT_PATH = TEST_PATH + FS + "bin"; - private static final File COMPILER_OUTPUT_DIR = new File(COMPILER_OUTPUT_PATH); - - @BeforeClass - public static void createTestDirs() { - if (TEST_DIR.exists()) { - deleteTestDir(TEST_DIR); - } - assertTrue(GENERATOR_OUTPUT_DIR.mkdirs()); - assertTrue(COMPILER_OUTPUT_DIR.mkdirs()); - } - - @Test - public void compilationTest() throws Exception { - final File sourcesOutputDir = new File(GENERATOR_OUTPUT_PATH + FS + "yang"); - assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdirs()); - final File compiledOutputDir = new File(COMPILER_OUTPUT_PATH + FS + "yang"); - assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdirs()); - - generateTestSources("/yang-module-info", sourcesOutputDir); - - // Test if $YangModuleInfoImpl.java file is generated - final String BASE_PATH = "org" + FS + "opendaylight" + FS + "yang" + FS + "gen" + FS + "v1"; - final String NS_TEST = BASE_PATH + FS + "yang" + FS + "test" + FS + "main" + FS + "rev140630"; - File parent = new File(sourcesOutputDir, NS_TEST); - File keyArgs = new File(parent, "$YangModuleInfoImpl.java"); - assertTrue(keyArgs.exists()); - - // Test if sources are compilable - testCompilation(sourcesOutputDir, compiledOutputDir); - - // Create URLClassLoader - URL[] urls = new URL[2]; - urls[0] = compiledOutputDir.toURI().toURL(); - urls[1] = new File(System.getProperty("user.dir")).toURI().toURL(); - ClassLoader loader = new URLClassLoader(urls); - - // Load class - Class yangModuleInfoClass = Class.forName(BASE_PKG + ".yang.test.main.rev140630.$YangModuleInfoImpl", true, - loader); - - // Test generated $YangModuleInfoImpl class - assertFalse(yangModuleInfoClass.isInterface()); - Method getInstance = assertContainsMethod(yangModuleInfoClass, YangModuleInfo.class, "getInstance"); - Object yangModuleInfo = getInstance.invoke(null); - - // Test getImportedModules method - Method getImportedModules = assertContainsMethod(yangModuleInfoClass, Set.class, "getImportedModules"); - Object importedModules = getImportedModules.invoke(yangModuleInfo); - assertTrue(importedModules instanceof Set); - - YangModuleInfo infoImport = null; - YangModuleInfo infoSub1 = null; - YangModuleInfo infoSub2 = null; - YangModuleInfo infoSub3 = null; - for (Object importedModule : (Set) importedModules) { - assertTrue(importedModule instanceof YangModuleInfo); - YangModuleInfo ymi = (YangModuleInfo) importedModule; - String name = ymi.getName(); - - switch (name) { - case "import-module": - infoImport = ymi; - break; - case "submodule1": - infoSub1 = ymi; - break; - case "submodule2": - infoSub2 = ymi; - break; - case "submodule3": - infoSub3 = ymi; - } - } - assertNotNull(infoImport); - assertNotNull(infoSub1); - assertNotNull(infoSub2); - assertNotNull(infoSub3); - - cleanUp(sourcesOutputDir, compiledOutputDir); - } - - private static void generateTestSources(final String resourceDirPath, final File sourcesOutputDir) throws Exception { - final List sourceFiles = getSourceFiles(resourceDirPath); - final SchemaContext context = RetestUtils.parseYangSources(sourceFiles); - CodeGeneratorImpl codegen = new CodeGeneratorImpl(); - codegen.setBuildContext(new DefaultBuildContext()); - codegen.generateSources(context, sourcesOutputDir, context.getModules()); - } - - private static void testCompilation(final File sourcesOutputDir, final File compiledOutputDir) { - JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); - StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null); - List filesList = getJavaFiles(sourcesOutputDir); - Iterable compilationUnits = fileManager.getJavaFileObjectsFromFiles(filesList); - Iterable options = Arrays.asList("-d", compiledOutputDir.getAbsolutePath()); - boolean compiled = compiler.getTask(null, null, null, options, null, compilationUnits).call(); - assertTrue(compiled); - } - - private static List getJavaFiles(final File directory) { - List result = new ArrayList<>(); - File[] filesToRead = directory.listFiles(); - if (filesToRead != null) { - for (File file : filesToRead) { - if (file.isDirectory()) { - result.addAll(getJavaFiles(file)); - } else { - String absPath = file.getAbsolutePath(); - if (absPath.endsWith(".java")) { - result.add(file); - } - } - } - } - return result; - } - - private static List getSourceFiles(final String path) throws Exception { - final URI resPath = YangModuleInfoCompilationTest.class.getResource(path).toURI(); - final File sourcesDir = new File(resPath); - final URI currentDir = new File(System.getProperty("user.dir")).toURI(); - if (sourcesDir.exists()) { - final List sourceFiles = new ArrayList<>(); - final File[] fileArray = sourcesDir.listFiles(); - if (fileArray == null) { - throw new IllegalArgumentException("Unable to locate files in " + sourcesDir); - } - for (File sourceFile : fileArray) { - sourceFiles.add(new File(currentDir.relativize(sourceFile.toURI()).toString())); - } - return sourceFiles; - } else { - throw new FileNotFoundException("Testing files were not found(" + sourcesDir.getName() + ")"); - } - } - - private static void deleteTestDir(final File file) { - if (file.isDirectory()) { - File[] filesToDelete = file.listFiles(); - if (filesToDelete != null) { - for (File f : filesToDelete) { - deleteTestDir(f); - } - } - } - if (!file.delete()) { - throw new RuntimeException("Failed to clean up after test"); - } - } - - private static Method assertContainsMethod(final Class clazz, final Class returnType, final String name, final Class... args) { - try { - Method m = clazz.getDeclaredMethod(name, args); - assertEquals(returnType, m.getReturnType()); - return m; - } catch (NoSuchMethodException e) { - throw new AssertionError("Method " + name + " with args " + Arrays.toString(args) - + " does not exists in class " + clazz.getSimpleName()); - } - } - - private static void cleanUp(final File... resourceDirs) { - for (File resourceDir : resourceDirs) { - if (resourceDir.exists()) { - deleteTestDir(resourceDir); - } - } - } - -} diff --git a/binding/maven-sal-api-gen-plugin/src/test/java/org/opendaylight/yangtools/yang/wadl/generator/maven/WadlGenTest.java b/binding/maven-sal-api-gen-plugin/src/test/java/org/opendaylight/yangtools/yang/wadl/generator/maven/WadlGenTest.java index 5c8eb4ea7b..b11c264a5e 100644 --- a/binding/maven-sal-api-gen-plugin/src/test/java/org/opendaylight/yangtools/yang/wadl/generator/maven/WadlGenTest.java +++ b/binding/maven-sal-api-gen-plugin/src/test/java/org/opendaylight/yangtools/yang/wadl/generator/maven/WadlGenTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2016 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, @@ -16,18 +16,19 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.List; +import java.util.Set; import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl; +import org.opendaylight.yangtools.yang.unified.doc.generator.maven.RetestUtils; import org.opendaylight.yangtools.yang2sources.spi.BasicCodeGenerator; public class WadlGenTest { public static final String FS = File.separator; private static final String TEST_PATH = "target" + FS + "test" + FS + "site"; private static final File GENERATOR_OUTPUT_DIR = new File(TEST_PATH); - private YangParserImpl parser; @Before public void init() { @@ -35,7 +36,6 @@ public class WadlGenTest { deleteTestDir(GENERATOR_OUTPUT_DIR); } assertTrue(GENERATOR_OUTPUT_DIR.mkdirs()); - parser = new YangParserImpl(); } @After @@ -48,13 +48,14 @@ public class WadlGenTest { @Test public void testListGeneration() throws Exception { final List sourceFiles = getSourceFiles("/wadl-gen"); - final SchemaContext context = parser.parseFiles(sourceFiles); + final SchemaContext context = RetestUtils.parseYangSources(sourceFiles); + final Set modules = context.getModules(); final BasicCodeGenerator generator = new WadlGenerator(); - Collection generatedWadlFiles = generator.generateSources(context, GENERATOR_OUTPUT_DIR, context.getModules()); + Collection generatedWadlFiles = generator.generateSources(context, GENERATOR_OUTPUT_DIR, modules); assertEquals(3, generatedWadlFiles.size()); } - private static List getSourceFiles(final String path) throws Exception { + private static List getSourceFiles(String path) throws Exception { final URI resPath = WadlGenTest.class.getResource(path).toURI(); final File sourcesDir = new File(resPath); if (sourcesDir.exists()) { @@ -70,7 +71,7 @@ public class WadlGenTest { } } - private static void deleteTestDir(final File file) { + private static void deleteTestDir(File file) { if (file.isDirectory()) { File[] filesToDelete = file.listFiles(); if (filesToDelete != null) { diff --git a/binding/maven-sal-api-gen-plugin/src/test/java/org/opendaylight/yangtools/yang/wadl/generator/maven/retest/WadlGenTest.java b/binding/maven-sal-api-gen-plugin/src/test/java/org/opendaylight/yangtools/yang/wadl/generator/maven/retest/WadlGenTest.java deleted file mode 100644 index 7c940b768f..0000000000 --- a/binding/maven-sal-api-gen-plugin/src/test/java/org/opendaylight/yangtools/yang/wadl/generator/maven/retest/WadlGenTest.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (c) 2015 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.yangtools.yang.wadl.generator.maven.retest; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import java.io.File; -import java.io.FileNotFoundException; -import java.net.URI; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; -import java.util.Set; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.opendaylight.yangtools.yang.model.api.Module; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.unified.doc.generator.maven.retest.RetestUtils; -import org.opendaylight.yangtools.yang.wadl.generator.maven.WadlGenerator; -import org.opendaylight.yangtools.yang2sources.spi.BasicCodeGenerator; - -public class WadlGenTest { - public static final String FS = File.separator; - private static final String TEST_PATH = "target" + FS + "test" + FS + "site"; - private static final File GENERATOR_OUTPUT_DIR = new File(TEST_PATH); - - @Before - public void init() { - if (GENERATOR_OUTPUT_DIR.exists()) { - deleteTestDir(GENERATOR_OUTPUT_DIR); - } - assertTrue(GENERATOR_OUTPUT_DIR.mkdirs()); - } - - @After - public void cleanUp() { - if (GENERATOR_OUTPUT_DIR.exists()) { - deleteTestDir(GENERATOR_OUTPUT_DIR); - } - } - - @Test - public void testListGeneration() throws Exception { - final List sourceFiles = getSourceFiles("/wadl-gen"); - final SchemaContext context = RetestUtils.parseYangSources(sourceFiles); - final Set modules = context.getModules(); - final BasicCodeGenerator generator = new WadlGenerator(); - Collection generatedWadlFiles = generator.generateSources(context, GENERATOR_OUTPUT_DIR, modules); - assertEquals(3, generatedWadlFiles.size()); - } - - private static List getSourceFiles(String path) throws Exception { - final URI resPath = WadlGenTest.class.getResource(path).toURI(); - final File sourcesDir = new File(resPath); - if (sourcesDir.exists()) { - final List sourceFiles = new ArrayList<>(); - final File[] fileArray = sourcesDir.listFiles(); - if (fileArray == null) { - throw new IllegalArgumentException("Unable to locate files in " + sourcesDir); - } - sourceFiles.addAll(Arrays.asList(fileArray)); - return sourceFiles; - } else { - throw new FileNotFoundException("Testing files were not found(" + sourcesDir.getName() + ")"); - } - } - - private static void deleteTestDir(File file) { - if (file.isDirectory()) { - File[] filesToDelete = file.listFiles(); - if (filesToDelete != null) { - for (File f : filesToDelete) { - deleteTestDir(f); - } - } - } - if (!file.delete()) { - throw new RuntimeException("Failed to clean up after test"); - } - } - -} diff --git a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/AbstractTypesTest.java b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/AbstractTypesTest.java index 58b5133d15..b3345fd19a 100644 --- a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/AbstractTypesTest.java +++ b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/AbstractTypesTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2016 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, diff --git a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/AugmentRelativeXPathTest.java b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/AugmentRelativeXPathTest.java index 250faf8c28..c7db24fff3 100644 --- a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/AugmentRelativeXPathTest.java +++ b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/AugmentRelativeXPathTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2016 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, @@ -11,9 +11,11 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; +import org.opendaylight.yangtools.yang.parser.spi.source.SourceException; + import java.io.IOException; import java.util.List; - import org.junit.Test; import org.opendaylight.yangtools.sal.binding.generator.api.BindingGenerator; import org.opendaylight.yangtools.sal.binding.model.api.GeneratedProperty; @@ -22,8 +24,6 @@ import org.opendaylight.yangtools.sal.binding.model.api.GeneratedType; import org.opendaylight.yangtools.sal.binding.model.api.MethodSignature; import org.opendaylight.yangtools.sal.binding.model.api.Type; import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.model.parser.api.YangContextParser; -import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl; public class AugmentRelativeXPathTest extends AbstractTypesTest { @@ -32,9 +32,9 @@ public class AugmentRelativeXPathTest extends AbstractTypesTest { } @Test - public void AugmentationWithRelativeXPathTest() throws IOException { - final YangContextParser parser = new YangParserImpl(); - final SchemaContext context = parser.parseFiles(testModels); + public void AugmentationWithRelativeXPathTest() throws IOException, SourceException, ReactorException { + + final SchemaContext context = RetestUtils.parseYangSources(testModels); assertNotNull("context is null", context); final BindingGenerator bindingGen = new BindingGeneratorImpl(true); diff --git a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/AugmentedTypeTest.java b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/AugmentedTypeTest.java index 70c7c6684e..911f69160c 100644 --- a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/AugmentedTypeTest.java +++ b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/AugmentedTypeTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2016 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, @@ -12,9 +12,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import java.io.File; -import java.util.Arrays; import java.util.List; - import org.junit.Test; import org.opendaylight.yangtools.sal.binding.generator.api.BindingGenerator; import org.opendaylight.yangtools.sal.binding.model.api.GeneratedProperty; @@ -23,7 +21,6 @@ import org.opendaylight.yangtools.sal.binding.model.api.GeneratedType; import org.opendaylight.yangtools.sal.binding.model.api.MethodSignature; import org.opendaylight.yangtools.sal.binding.model.api.Type; import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl; public class AugmentedTypeTest { @@ -40,8 +37,8 @@ public class AugmentedTypeTest { File ietfInterfaces = new File(getClass().getResource("/augment-test-models/ietf-interfaces@2012-11-15.yang") .toURI()); - final SchemaContext context = new YangParserImpl().parseFiles(Arrays.asList(abstractTopology, augmentTopology, - augmentNetworkLink, augmentTopologyTunnels, ietfInterfaces)); + final SchemaContext context = RetestUtils.parseYangSources(abstractTopology, augmentTopology, + augmentNetworkLink, augmentTopologyTunnels, ietfInterfaces); assertNotNull("Schema Context is null", context); final BindingGenerator bindingGen = new BindingGeneratorImpl(true); diff --git a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/BinaryTypeTest.java b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/BinaryTypeTest.java index 32b51af193..6baede1bab 100644 --- a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/BinaryTypeTest.java +++ b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/BinaryTypeTest.java @@ -1,29 +1,29 @@ /* -* 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 -*/ + * Copyright (c) 2016 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.yangtools.sal.binding.generator.impl; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; +import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; +import org.opendaylight.yangtools.yang.parser.spi.source.SourceException; + import java.io.File; import java.io.IOException; import java.net.URISyntaxException; import java.net.URL; import java.util.ArrayList; import java.util.List; - import org.junit.BeforeClass; import org.junit.Test; import org.opendaylight.yangtools.sal.binding.generator.api.BindingGenerator; import org.opendaylight.yangtools.sal.binding.model.api.Type; import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.model.parser.api.YangContextParser; -import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl; public class BinaryTypeTest { private final static List yangModels = new ArrayList<>(); @@ -41,9 +41,8 @@ public class BinaryTypeTest { } @Test - public void binaryTypeTest() throws IOException { - final YangContextParser parser = new YangParserImpl(); - final SchemaContext context = parser.parseFiles(yangModels); + public void binaryTypeTest() throws IOException, SourceException, ReactorException { + final SchemaContext context = RetestUtils.parseYangSources(yangModels); assertNotNull("context is null", context); final BindingGenerator bindingGen = new BindingGeneratorImpl(true); diff --git a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/BindingGeneratorImplTest.java b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/BindingGeneratorImplTest.java index 7088949431..5a687ef442 100644 --- a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/BindingGeneratorImplTest.java +++ b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/BindingGeneratorImplTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2016 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, @@ -12,23 +12,22 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; +import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; +import org.opendaylight.yangtools.yang.parser.spi.source.SourceException; +import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor; +import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline; +import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.EffectiveSchemaContext; +import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl; import java.io.File; import java.io.IOException; import java.net.URISyntaxException; import java.util.List; - import org.junit.Test; import org.opendaylight.yangtools.sal.binding.model.api.GeneratedType; import org.opendaylight.yangtools.sal.binding.model.api.ParameterizedType; import org.opendaylight.yangtools.sal.binding.model.api.Type; import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException; -import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl; -import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; -import org.opendaylight.yangtools.yang.parser.spi.source.SourceException; -import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor; -import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline; -import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl; public class BindingGeneratorImplTest { @@ -51,7 +50,7 @@ public class BindingGeneratorImplTest { reactor.addSources(ISIS_20131021, L3_20131021, NETWORK_TOPOLOGY_20131021); - SchemaContext context = reactor.buildEffective(); + EffectiveSchemaContext context = reactor.buildEffective(); assertNotNull(context); List generateTypes = new BindingGeneratorImpl(false) @@ -62,13 +61,11 @@ public class BindingGeneratorImplTest { @Test public void choiceNodeGenerationTest() throws IOException, - YangSyntaxErrorException, URISyntaxException { + YangSyntaxErrorException, URISyntaxException, SourceException, ReactorException { File resourceFile = new File(getClass().getResource( "/binding-generator-impl-test/choice-test.yang").toURI()); - File resourceDir = resourceFile.getParentFile(); - YangParserImpl parser = YangParserImpl.getInstance(); - SchemaContext context = parser.parseFile(resourceFile, resourceDir); + SchemaContext context = RetestUtils.parseYangSources(resourceFile); List generateTypes = new BindingGeneratorImpl(false) .generateTypes(context); @@ -161,15 +158,15 @@ public class BindingGeneratorImplTest { } @Test - public void notificationGenerationTest() throws IOException, YangSyntaxErrorException, URISyntaxException { - File resourceFile = new File(getClass().getResource("/binding-generator-impl-test/notification-test.yang") - .toURI()); - File resourceDir = resourceFile.getParentFile(); + public void notificationGenerationTest() throws IOException, + YangSyntaxErrorException, URISyntaxException, SourceException, ReactorException { + File resourceFile = new File(getClass().getResource( + "/binding-generator-impl-test/notification-test.yang").toURI()); - YangParserImpl parser = YangParserImpl.getInstance(); - SchemaContext context = parser.parseFile(resourceFile, resourceDir); + SchemaContext context = RetestUtils.parseYangSources(resourceFile); - List generateTypes = new BindingGeneratorImpl(false).generateTypes(context); + List generateTypes = new BindingGeneratorImpl(false) + .generateTypes(context); GeneratedType foo = null; for (Type type : generateTypes) { diff --git a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/BitAndUnionTOEnclosingTest.java b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/BitAndUnionTOEnclosingTest.java index 419551a2d7..e55cb7f1f1 100644 --- a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/BitAndUnionTOEnclosingTest.java +++ b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/BitAndUnionTOEnclosingTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2016 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, @@ -9,15 +9,16 @@ package org.opendaylight.yangtools.sal.binding.generator.impl; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import static org.opendaylight.yangtools.sal.binding.generator.impl.SupportTestUtil.containsAttributes; import static org.opendaylight.yangtools.sal.binding.generator.impl.SupportTestUtil.containsMethods; +import static org.opendaylight.yangtools.sal.binding.generator.impl.SupportTestUtil.containsAttributes; +import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; +import org.opendaylight.yangtools.yang.parser.spi.source.SourceException; import java.io.File; import java.io.IOException; import java.net.URISyntaxException; import java.util.ArrayList; import java.util.List; - import org.junit.BeforeClass; import org.junit.Test; import org.opendaylight.yangtools.sal.binding.generator.api.BindingGenerator; @@ -26,8 +27,6 @@ import org.opendaylight.yangtools.sal.binding.model.api.GeneratedTransferObject; import org.opendaylight.yangtools.sal.binding.model.api.GeneratedType; import org.opendaylight.yangtools.sal.binding.model.api.Type; import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.model.parser.api.YangContextParser; -import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl; public class BitAndUnionTOEnclosingTest { @@ -35,9 +34,9 @@ public class BitAndUnionTOEnclosingTest { private static List genTypes = null; private static GeneratedType parentContainer = null; - public static void parseResources() throws IOException { - final YangContextParser parser = new YangParserImpl(); - final SchemaContext context = parser.parseFiles(testModels); + public static void parseResources() throws IOException, SourceException, ReactorException { + + final SchemaContext context = RetestUtils.parseYangSources(testModels); assertNotNull(context); final BindingGenerator bindingGen = new BindingGeneratorImpl(true); @@ -54,7 +53,7 @@ public class BitAndUnionTOEnclosingTest { } @BeforeClass - public static void loadTestResources() throws IOException, URISyntaxException { + public static void loadTestResources() throws IOException, URISyntaxException, SourceException, ReactorException { final File listModelFile = new File(ExtendedTypedefTest.class.getResource("/bit_and_union.yang").toURI()); testModels.add(listModelFile); parseResources(); diff --git a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/Bug4145Test.java b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/Bug4145Test.java index b1c264c6c3..c6ec6c977a 100644 --- a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/Bug4145Test.java +++ b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/Bug4145Test.java @@ -2,25 +2,24 @@ package org.opendaylight.yangtools.sal.binding.generator.impl; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; + +import java.io.File; import java.io.IOException; -import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException; import java.net.URISyntaxException; -import java.io.File; import java.util.List; +import org.junit.Test; import org.opendaylight.yangtools.sal.binding.model.api.Type; import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl; -import org.junit.Test; +import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException; +import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; public class Bug4145Test { @Test - public void bug4145Test() throws URISyntaxException, IOException, YangSyntaxErrorException { + public void bug4145Test() throws URISyntaxException, IOException, YangSyntaxErrorException, ReactorException { File resourceFile = new File(getClass().getResource( "/bug-4145/foo.yang").toURI()); - File resourceDir = resourceFile.getParentFile(); - YangParserImpl parser = YangParserImpl.getInstance(); - SchemaContext context = parser.parseFile(resourceFile, resourceDir); + SchemaContext context = RetestUtils.parseYangSources(resourceFile); List generateTypes = new BindingGeneratorImpl(false) .generateTypes(context); diff --git a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/ChoiceCaseGenTypesTest.java b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/ChoiceCaseGenTypesTest.java index 74b22005d2..7e9ea1821f 100644 --- a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/ChoiceCaseGenTypesTest.java +++ b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/ChoiceCaseGenTypesTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2016 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, @@ -20,8 +20,8 @@ import org.opendaylight.yangtools.sal.binding.model.api.GeneratedTransferObject; import org.opendaylight.yangtools.sal.binding.model.api.GeneratedType; import org.opendaylight.yangtools.sal.binding.model.api.Type; import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.model.parser.api.YangContextParser; -import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl; +import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; +import org.opendaylight.yangtools.yang.parser.spi.source.SourceException; public class ChoiceCaseGenTypesTest extends AbstractTypesTest { @@ -55,9 +55,8 @@ public class ChoiceCaseGenTypesTest extends AbstractTypesTest { } @Test - public void choiceCaseResolvingTypeTest() throws IOException { - final YangContextParser parser = new YangParserImpl(); - final SchemaContext context = parser.parseFiles(testModels); + public void choiceCaseResolvingTypeTest() throws IOException, SourceException, ReactorException { + final SchemaContext context = RetestUtils.parseYangSources(testModels); assertNotNull("context is null", context); final BindingGenerator bindingGen = new BindingGeneratorImpl(true); @@ -73,7 +72,7 @@ public class ChoiceCaseGenTypesTest extends AbstractTypesTest { checkGeneratedType(genTypes, "LockType", pcgPref); // choice genType = checkGeneratedType(genTypes, "GlobalLock", pcgPref + ".lock.type"); // case - containsMethods(genType, new NameTypePattern("getGlobalLock", "GlobalLock")); + SupportTestUtil.containsMethods(genType, new NameTypePattern("getGlobalLock", "GlobalLock")); containsInterface("LockType", genType); genType = checkGeneratedType(genTypes, "PartialLock", pcgPref + ".lock.type"); // case diff --git a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/ControllerTest.java b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/ControllerTest.java index 0fde6324ef..c78b81e26e 100644 --- a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/ControllerTest.java +++ b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/ControllerTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2016 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, @@ -11,14 +11,11 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import java.io.File; -import java.util.Arrays; import java.util.List; - import org.junit.Test; import org.opendaylight.yangtools.sal.binding.generator.api.BindingGenerator; import org.opendaylight.yangtools.sal.binding.model.api.Type; import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl; public class ControllerTest { @@ -28,7 +25,7 @@ public class ControllerTest { File co = new File(getClass().getResource("/controller-models/controller-openflow.yang").toURI()); File ietfInetTypes = new File(getClass().getResource("/ietf/ietf-inet-types.yang").toURI()); - final SchemaContext context = new YangParserImpl().parseFiles(Arrays.asList(cn, co, ietfInetTypes)); + final SchemaContext context = RetestUtils.parseYangSources(cn, co, ietfInetTypes); assertNotNull("Schema Context is null", context); final BindingGenerator bindingGen = new BindingGeneratorImpl(true); diff --git a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/ExtendedTypedefTest.java b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/ExtendedTypedefTest.java index 329934fb30..e247cf80ac 100644 --- a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/ExtendedTypedefTest.java +++ b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/ExtendedTypedefTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2016 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, @@ -11,11 +11,8 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; - import java.io.File; -import java.util.Arrays; import java.util.List; - import org.junit.Test; import org.opendaylight.yangtools.sal.binding.generator.api.BindingGenerator; import org.opendaylight.yangtools.sal.binding.model.api.GeneratedProperty; @@ -23,7 +20,6 @@ import org.opendaylight.yangtools.sal.binding.model.api.GeneratedTransferObject; import org.opendaylight.yangtools.sal.binding.model.api.Type; import org.opendaylight.yangtools.sal.binding.yang.types.BaseYangTypes; import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl; public class ExtendedTypedefTest { @@ -32,7 +28,7 @@ public class ExtendedTypedefTest { File abstractTopology = new File(getClass().getResource("/typedef-of-typedef/typedef_of_typedef.yang").toURI()); File ietfInetTypes = new File(getClass().getResource("/ietf/ietf-inet-types.yang").toURI()); - final SchemaContext context = new YangParserImpl().parseFiles(Arrays.asList(abstractTopology, ietfInetTypes)); + final SchemaContext context = RetestUtils.parseYangSources(abstractTopology, ietfInetTypes); assertNotNull("Schema Context is null", context); final BindingGenerator bindingGen = new BindingGeneratorImpl(true); @@ -97,7 +93,7 @@ public class ExtendedTypedefTest { // extended-typedef-union assertNotNull("ExtendedTypedefUnion object not found", extendedTypedefUnion); properties = extendedTypedefUnion.getProperties(); - assertTrue("ExtendedTypedefUnion shouldn't have any property", properties.isEmpty()); + assertEquals("ExtendedTypedefUnion shouldn't have any property", 0, properties.size()); extendTO = extendedTypedefUnion.getSuperType(); assertEquals("Incorrect extension fo ExtendedTypedefUnion.", "UnionTypedef", extendTO.getName()); diff --git a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/GenEnumResolvingTest.java b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/GenEnumResolvingTest.java index 1227d70e3a..1a2dbadc02 100644 --- a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/GenEnumResolvingTest.java +++ b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/GenEnumResolvingTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2016 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, @@ -10,14 +10,12 @@ package org.opendaylight.yangtools.sal.binding.generator.impl; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; - +import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; +import org.opendaylight.yangtools.yang.parser.spi.source.SourceException; import java.io.File; import java.io.IOException; import java.net.URISyntaxException; -import java.util.Arrays; -import java.util.Collections; import java.util.List; - import org.junit.Test; import org.opendaylight.yangtools.sal.binding.generator.api.BindingGenerator; import org.opendaylight.yangtools.sal.binding.model.api.Enumeration; @@ -25,17 +23,16 @@ import org.opendaylight.yangtools.sal.binding.model.api.GeneratedType; import org.opendaylight.yangtools.sal.binding.model.api.MethodSignature; import org.opendaylight.yangtools.sal.binding.model.api.Type; import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl; public class GenEnumResolvingTest { @Test - public void testLeafEnumResolving() throws URISyntaxException, IOException { + public void testLeafEnumResolving() throws URISyntaxException, IOException, SourceException, ReactorException { File ietfInterfaces = new File(getClass().getResource("/enum-test-models/ietf-interfaces@2012-11-15.yang") .toURI()); File ianaIfTypeModel = new File(getClass().getResource("/ietf/iana-if-type.yang").toURI()); - final SchemaContext context = new YangParserImpl().parseFiles(Arrays.asList(ietfInterfaces, ianaIfTypeModel)); + final SchemaContext context = RetestUtils.parseYangSources(ietfInterfaces, ianaIfTypeModel); assertTrue(context != null); final BindingGenerator bindingGen = new BindingGeneratorImpl(true); @@ -95,9 +92,9 @@ public class GenEnumResolvingTest { } @Test - public void testTypedefEnumResolving() throws URISyntaxException, IOException { + public void testTypedefEnumResolving() throws URISyntaxException, IOException, SourceException, ReactorException { File ianaIfType = new File(getClass().getResource("/ietf/iana-if-type.yang").toURI()); - final SchemaContext context = new YangParserImpl().parseFiles(Collections.singleton(ianaIfType)); + final SchemaContext context = RetestUtils.parseYangSources(ianaIfType); assertTrue(context != null); final BindingGenerator bindingGen = new BindingGeneratorImpl(true); final List genTypes = bindingGen.generateTypes(context); @@ -112,15 +109,15 @@ public class GenEnumResolvingTest { } @Test - public void testLeafrefEnumResolving() throws URISyntaxException, IOException { + public void testLeafrefEnumResolving() throws URISyntaxException, IOException, SourceException, ReactorException { File abstractTopology = new File(getClass().getResource("/enum-test-models/abstract-topology@2013-02-08.yang") .toURI()); File ietfInterfaces = new File(getClass().getResource("/enum-test-models/ietf-interfaces@2012-11-15.yang") .toURI()); File ianaIfType = new File(getClass().getResource("/ietf/iana-if-type.yang").toURI()); - final SchemaContext context = new YangParserImpl().parseFiles(Arrays.asList(abstractTopology, ietfInterfaces, - ianaIfType)); + final SchemaContext context = RetestUtils.parseYangSources(abstractTopology, ietfInterfaces, + ianaIfType); assertNotNull(context); final BindingGenerator bindingGen = new BindingGeneratorImpl(true); final List genTypes = bindingGen.generateTypes(context); diff --git a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/GenTypesSubSetTest.java b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/GenTypesSubSetTest.java index 5f3988a0f6..a32aca52b0 100644 --- a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/GenTypesSubSetTest.java +++ b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/GenTypesSubSetTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2016 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, @@ -12,17 +12,14 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import java.io.File; -import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Set; - import org.junit.Test; import org.opendaylight.yangtools.sal.binding.generator.api.BindingGenerator; import org.opendaylight.yangtools.sal.binding.model.api.Type; import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl; public class GenTypesSubSetTest { @@ -34,8 +31,8 @@ public class GenTypesSubSetTest { File ietfInetTypes = new File(getClass().getResource("/ietf/ietf-inet-types.yang").toURI()); File ietfYangTypes = new File(getClass().getResource("/ietf/ietf-yang-types.yang").toURI()); - final SchemaContext context = new YangParserImpl().parseFiles(Arrays.asList(abstractTopology, ietfInterfaces, - ietfInetTypes, ietfYangTypes)); + final SchemaContext context = RetestUtils.parseYangSources(abstractTopology, ietfInterfaces, + ietfInetTypes, ietfYangTypes); Set modules = context.getModules(); final Set toGenModules = new HashSet<>(); @@ -66,8 +63,8 @@ public class GenTypesSubSetTest { File ietfYangTypes = new File(getClass().getResource("/ietf/ietf-yang-types.yang").toURI()); File ianaIfType = new File(getClass().getResource("/ietf/iana-if-type.yang").toURI()); - final SchemaContext context = new YangParserImpl().parseFiles(Arrays.asList(abstractTopology, ietfInterfaces, - ietfInetTypes, ietfYangTypes, ianaIfType)); + final SchemaContext context = RetestUtils.parseYangSources(abstractTopology, ietfInterfaces, + ietfInetTypes, ietfYangTypes, ianaIfType); assertNotNull("Schema Context is null", context); final Set modules = context.getModules(); diff --git a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/GenerateInnerClassForBitsAndUnionInLeavesTest.java b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/GenerateInnerClassForBitsAndUnionInLeavesTest.java index 7e971d843d..3c3458dfd7 100644 --- a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/GenerateInnerClassForBitsAndUnionInLeavesTest.java +++ b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/GenerateInnerClassForBitsAndUnionInLeavesTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2016 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, @@ -8,9 +8,9 @@ package org.opendaylight.yangtools.sal.binding.generator.impl; import static org.junit.Assert.assertTrue; + import java.io.File; import java.net.URI; -import java.util.ArrayList; import java.util.List; import org.junit.Test; import org.opendaylight.yangtools.sal.binding.generator.api.BindingGenerator; @@ -19,27 +19,14 @@ import org.opendaylight.yangtools.sal.binding.model.api.GeneratedTransferObject; import org.opendaylight.yangtools.sal.binding.model.api.GeneratedType; import org.opendaylight.yangtools.sal.binding.model.api.Type; import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.model.parser.api.YangContextParser; -import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl; public class GenerateInnerClassForBitsAndUnionInLeavesTest { - private static SchemaContext resolveSchemaContextFromFiles(final URI... yangFiles) throws Exception { - final YangContextParser parser = new YangParserImpl(); - - final List inputFiles = new ArrayList(); - for (URI yangFile : yangFiles) { - inputFiles.add(new File(yangFile)); - } - - return parser.parseFiles(inputFiles); - } - @Test public void testInnerClassCreationForBitsAndUnionsInLeafes() throws Exception { final URI yangTypesPath = getClass().getResource("/bit_and_union_in_leaf.yang").toURI(); - final SchemaContext context = resolveSchemaContextFromFiles(yangTypesPath); + final SchemaContext context = RetestUtils.parseYangSources(new File(yangTypesPath)); assertTrue(context != null); final BindingGenerator bindingGen = new BindingGeneratorImpl(true); diff --git a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/GeneratedTypesBitsTest.java b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/GeneratedTypesBitsTest.java index 16abfd7b1c..9d8b6f9d74 100644 --- a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/GeneratedTypesBitsTest.java +++ b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/GeneratedTypesBitsTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2016 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, @@ -11,10 +11,9 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; - +import java.io.File; import java.net.URI; import java.util.List; - import org.junit.Test; import org.opendaylight.yangtools.sal.binding.generator.api.BindingGenerator; import org.opendaylight.yangtools.sal.binding.model.api.GeneratedProperty; @@ -32,7 +31,7 @@ public class GeneratedTypesBitsTest { public void testGeneretedTypesBitsTest() throws Exception { final URI yangTypesPath = getClass().getResource("/simple-bits-demo.yang").toURI(); - final SchemaContext context = SupportTestUtil.resolveSchemaContextFromFiles(yangTypesPath); + final SchemaContext context = RetestUtils.parseYangSources(new File(yangTypesPath)); assertTrue(context != null); final BindingGenerator bindingGen = new BindingGeneratorImpl(true); @@ -109,17 +108,17 @@ public class GeneratedTypesBitsTest { assertTrue(byteTypeFound); - assertEquals(classPropertiesNumb,8); + assertEquals(8, classPropertiesNumb); - assertEquals(toStringPropertiesNum,8); - assertEquals(equalPropertiesNum,8); - assertEquals(hashPropertiesNum,8); + assertEquals(8, toStringPropertiesNum); + assertEquals(8, equalPropertiesNum); + assertEquals(8, hashPropertiesNum); assertTrue(leafParentFound); assertNotNull(methodSignaturesList); assertTrue(getByteLeafMethodFound); - assertEquals(nameReturnParamType,"ByteType"); + assertEquals("ByteType", nameReturnParamType); assertFalse(setByteLeafMethodFound); assertEquals(0, setByteLeafMethodParamNum); diff --git a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/GeneratedTypesLeafrefTest.java b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/GeneratedTypesLeafrefTest.java index f286b3ebbc..0a6d096395 100644 --- a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/GeneratedTypesLeafrefTest.java +++ b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/GeneratedTypesLeafrefTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2016 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, @@ -12,17 +12,12 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import com.google.common.io.ByteSource; + import java.io.File; import java.io.IOException; -import java.io.InputStream; import java.net.URI; import java.net.URISyntaxException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; import java.util.List; -import java.util.Set; import org.junit.Test; import org.opendaylight.yangtools.sal.binding.generator.api.BindingGenerator; import org.opendaylight.yangtools.sal.binding.model.api.GeneratedProperty; @@ -30,44 +25,22 @@ import org.opendaylight.yangtools.sal.binding.model.api.GeneratedTransferObject; import org.opendaylight.yangtools.sal.binding.model.api.GeneratedType; import org.opendaylight.yangtools.sal.binding.model.api.MethodSignature; import org.opendaylight.yangtools.sal.binding.model.api.Type; -import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.model.parser.api.YangContextParser; -import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException; -import org.opendaylight.yangtools.yang.parser.builder.impl.BuilderUtils; -import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl; +import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; +import org.opendaylight.yangtools.yang.parser.spi.source.SourceException; public class GeneratedTypesLeafrefTest { - public static Set loadModules(final Collection input) throws IOException, - YangSyntaxErrorException { - Collection sources = BuilderUtils.streamsToByteSources(input); - final YangContextParser parser = new YangParserImpl(); - SchemaContext ctx = parser.parseSources(sources); - return ctx.getModules(); - } - - private static SchemaContext resolveSchemaContextFromFiles(final URI... yangFiles) throws IOException { - final YangContextParser parser = new YangParserImpl(); - - final List inputFiles = new ArrayList(); - for (URI yangFile : yangFiles) { - inputFiles.add(new File(yangFile)); - } - - return parser.parseFiles(inputFiles); - } - @Test - public void testLeafrefResolving() throws URISyntaxException, IOException { + public void testLeafrefResolving() throws URISyntaxException, IOException, SourceException, ReactorException { File abstractTopology = new File(getClass().getResource( "/leafref-test-models/abstract-topology@2013-02-08.yang").toURI()); File ietfInterfaces = new File(getClass().getResource("/ietf/ietf-interfaces.yang").toURI()); File ietfInetTypes = new File(getClass().getResource("/ietf/ietf-inet-types.yang").toURI()); File ietfYangTypes = new File(getClass().getResource("/ietf/ietf-yang-types.yang").toURI()); - final SchemaContext context = new YangParserImpl().parseFiles(Arrays.asList(abstractTopology, ietfInterfaces, - ietfInetTypes, ietfYangTypes)); + final SchemaContext context = RetestUtils.parseYangSources(abstractTopology, ietfInterfaces, + ietfInetTypes, ietfYangTypes); assertNotNull(context); assertEquals(4, context.getModules().size()); @@ -244,11 +217,11 @@ public class GeneratedTypesLeafrefTest { } @Test - public void testLeafrefInvalidPathResolving() throws URISyntaxException, IOException { + public void testLeafrefInvalidPathResolving() throws URISyntaxException, IOException, SourceException, ReactorException { final URI resource = getClass().getResource("/leafref-test-invalid-model/foo.yang").toURI(); assertNotNull(resource); - final SchemaContext context = resolveSchemaContextFromFiles(resource); + final SchemaContext context = RetestUtils.parseYangSources(new File(resource)); assertNotNull(context); assertEquals(1, context.getModules().size()); @@ -257,8 +230,8 @@ public class GeneratedTypesLeafrefTest { bindingGen.generateTypes(context); fail("Expected IllegalArgumentException caused by invalid leafref path"); } catch (IllegalArgumentException e) { - String expected = "Failed to find leafref target: ../id in module foo (QNameModule{ns=urn:yang.foo, rev=2014-03-10})"; - assertTrue(e.getMessage().startsWith(expected)); + String expected = "Failed to find leafref target"; + assertTrue(e.getMessage().contains(expected)); } } } \ No newline at end of file diff --git a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/GeneratedTypesStringTest.java b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/GeneratedTypesStringTest.java index fa7e0bfc59..f3a4a8256c 100644 --- a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/GeneratedTypesStringTest.java +++ b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/GeneratedTypesStringTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2016 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, @@ -10,12 +10,14 @@ package org.opendaylight.yangtools.sal.binding.generator.impl; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; +import org.opendaylight.yangtools.yang.parser.spi.source.SourceException; + import java.io.File; import java.io.IOException; import java.net.URISyntaxException; import java.util.ArrayList; import java.util.List; - import org.junit.BeforeClass; import org.junit.Test; import org.opendaylight.yangtools.sal.binding.generator.api.BindingGenerator; @@ -24,8 +26,6 @@ import org.opendaylight.yangtools.sal.binding.model.api.GeneratedTransferObject; import org.opendaylight.yangtools.sal.binding.model.api.ParameterizedType; import org.opendaylight.yangtools.sal.binding.model.api.Type; import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.model.parser.api.YangContextParser; -import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl; public class GeneratedTypesStringTest { @@ -39,9 +39,8 @@ public class GeneratedTypesStringTest { } @Test - public void constantGenerationTest() throws IOException { - final YangContextParser parser = new YangParserImpl(); - final SchemaContext context = parser.parseFiles(testModels); + public void constantGenerationTest() throws IOException, SourceException, ReactorException { + final SchemaContext context = RetestUtils.parseYangSources(testModels); assertNotNull(context); final BindingGenerator bindingGen = new BindingGeneratorImpl(true); diff --git a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/GeneratedTypesTest.java b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/GeneratedTypesTest.java index 6ab45367de..b103f18120 100644 --- a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/GeneratedTypesTest.java +++ b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/GeneratedTypesTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2016 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, @@ -9,14 +9,12 @@ package org.opendaylight.yangtools.sal.binding.generator.impl; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; - +import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; +import org.opendaylight.yangtools.yang.parser.spi.source.SourceException; import java.io.File; import java.io.IOException; import java.net.URISyntaxException; -import java.util.Arrays; -import java.util.Collections; import java.util.List; - import org.junit.Test; import org.opendaylight.yangtools.sal.binding.generator.api.BindingGenerator; import org.opendaylight.yangtools.sal.binding.model.api.GeneratedProperty; @@ -25,16 +23,15 @@ import org.opendaylight.yangtools.sal.binding.model.api.GeneratedType; import org.opendaylight.yangtools.sal.binding.model.api.MethodSignature; import org.opendaylight.yangtools.sal.binding.model.api.Type; import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl; public class GeneratedTypesTest { @Test - public void testMultipleModulesResolving() throws URISyntaxException, IOException { + public void testMultipleModulesResolving() throws URISyntaxException, IOException, SourceException, ReactorException { File abstractTopology = new File(getClass().getResource("/abstract-topology.yang").toURI()); File ietfInetTypes = new File(getClass().getResource("/ietf/ietf-inet-types.yang").toURI()); - final SchemaContext context = new YangParserImpl().parseFiles(Arrays.asList(abstractTopology, ietfInetTypes)); + final SchemaContext context = RetestUtils.parseYangSources(abstractTopology, ietfInetTypes); assertNotNull(context); final BindingGenerator bindingGen = new BindingGeneratorImpl(true); @@ -45,9 +42,9 @@ public class GeneratedTypesTest { } @Test - public void testContainerResolving() throws URISyntaxException, IOException { + public void testContainerResolving() throws URISyntaxException, IOException, SourceException, ReactorException { final File testFile = new File(getClass().getResource("/simple-container-demo.yang").toURI()); - final SchemaContext context = new YangParserImpl().parseFiles(Collections.singleton(testFile)); + final SchemaContext context = RetestUtils.parseYangSources(testFile); assertNotNull(context); final BindingGenerator bindingGen = new BindingGeneratorImpl(true); @@ -130,9 +127,9 @@ public class GeneratedTypesTest { } @Test - public void testLeafListResolving() throws URISyntaxException, IOException { + public void testLeafListResolving() throws URISyntaxException, IOException, SourceException, ReactorException { final File testFile = new File(getClass().getResource("/simple-leaf-list-demo.yang").toURI()); - final SchemaContext context = new YangParserImpl().parseFiles(Collections.singleton(testFile)); + final SchemaContext context = RetestUtils.parseYangSources(testFile); assertNotNull(context); final BindingGenerator bindingGen = new BindingGeneratorImpl(true); @@ -214,9 +211,9 @@ public class GeneratedTypesTest { } @Test - public void testListResolving() throws URISyntaxException, IOException { + public void testListResolving() throws URISyntaxException, IOException, SourceException, ReactorException { final File testFile = new File(getClass().getResource("/simple-list-demo.yang").toURI()); - final SchemaContext context = new YangParserImpl().parseFiles(Collections.singleton(testFile)); + final SchemaContext context = RetestUtils.parseYangSources(testFile); assertNotNull(context); final BindingGenerator bindingGen = new BindingGeneratorImpl(true); @@ -337,9 +334,9 @@ public class GeneratedTypesTest { } @Test - public void testListCompositeKeyResolving() throws URISyntaxException, IOException { + public void testListCompositeKeyResolving() throws URISyntaxException, IOException, SourceException, ReactorException { final File testFile = new File(getClass().getResource("/list-composite-key.yang").toURI()); - final SchemaContext context = new YangParserImpl().parseFiles(Collections.singleton(testFile)); + final SchemaContext context = RetestUtils.parseYangSources(testFile); assertNotNull(context); final BindingGenerator bindingGen = new BindingGeneratorImpl(true); @@ -389,9 +386,9 @@ public class GeneratedTypesTest { } @Test - public void testGeneratedTypes() throws URISyntaxException, IOException { + public void testGeneratedTypes() throws URISyntaxException, IOException, SourceException, ReactorException { final File testFile = new File(getClass().getResource("/demo-topology.yang").toURI()); - final SchemaContext context = new YangParserImpl().parseFiles(Collections.singleton(testFile)); + final SchemaContext context = RetestUtils.parseYangSources(testFile); assertNotNull(context); final BindingGenerator bindingGen = new BindingGeneratorImpl(true); diff --git a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/IdentityrefTypeTest.java b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/IdentityrefTypeTest.java index 0b17a86bda..78fbf7014f 100644 --- a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/IdentityrefTypeTest.java +++ b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/IdentityrefTypeTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2016 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, @@ -10,13 +10,15 @@ package org.opendaylight.yangtools.sal.binding.generator.impl; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; +import org.opendaylight.yangtools.yang.parser.spi.source.SourceException; + import java.io.File; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import java.util.ArrayList; import java.util.List; - import org.junit.Before; import org.junit.Test; import org.opendaylight.yangtools.sal.binding.generator.api.BindingGenerator; @@ -26,8 +28,6 @@ import org.opendaylight.yangtools.sal.binding.model.api.ParameterizedType; import org.opendaylight.yangtools.sal.binding.model.api.Type; import org.opendaylight.yangtools.sal.binding.yang.types.TypeProviderImpl; import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.model.parser.api.YangContextParser; -import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl; public class IdentityrefTypeTest { @@ -52,14 +52,15 @@ public class IdentityrefTypeTest { /** * Test mainly for the method - * {@link TypeProviderImpl#provideTypeForIdentityref(IdentityrefTypeDefinition) + * TypeProviderImpl#provideTypeForIdentityref(IdentityrefTypeDefinition) * provideTypeForIdentityref} + * @throws ReactorException Reactor exception + * @throws SourceException Source exception * @throws IOException IOException */ @Test - public void testIdentityrefYangBuiltInType() throws IOException { - final YangContextParser parser = new YangParserImpl(); - final SchemaContext context = parser.parseFiles(testModels); + public void testIdentityrefYangBuiltInType() throws IOException, SourceException, ReactorException { + final SchemaContext context = RetestUtils.parseYangSources(testModels); assertNotNull(context); final BindingGenerator bindingGen = new BindingGeneratorImpl(true); diff --git a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/NameTypePattern.java b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/NameTypePattern.java index acf940e57b..c1b22c6a26 100644 --- a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/NameTypePattern.java +++ b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/NameTypePattern.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2016 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, diff --git a/binding/mdsal-binding-generator-util/src/test/java/org/opendaylight/yangtools/binding/generator/util/stmt/parser/retest/RetestUtils.java b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/RetestUtils.java similarity index 82% rename from binding/mdsal-binding-generator-util/src/test/java/org/opendaylight/yangtools/binding/generator/util/stmt/parser/retest/RetestUtils.java rename to binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/RetestUtils.java index 11317e11d7..ef27c1f568 100644 --- a/binding/mdsal-binding-generator-util/src/test/java/org/opendaylight/yangtools/binding/generator/util/stmt/parser/retest/RetestUtils.java +++ b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/RetestUtils.java @@ -1,4 +1,12 @@ -package org.opendaylight.yangtools.binding.generator.util.stmt.parser.retest; +/* + * Copyright (c) 2016 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.yangtools.sal.binding.generator.impl; import java.util.Collection; diff --git a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/SupportTestUtil.java b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/SupportTestUtil.java index 59a04ff4e6..413f256813 100644 --- a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/SupportTestUtil.java +++ b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/SupportTestUtil.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2016 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, @@ -10,6 +10,9 @@ package org.opendaylight.yangtools.sal.binding.generator.impl; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; +import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; +import org.opendaylight.yangtools.yang.parser.spi.source.SourceException; + import java.io.File; import java.io.IOException; import java.net.URI; @@ -22,20 +25,17 @@ import org.opendaylight.yangtools.sal.binding.model.api.MethodSignature; import org.opendaylight.yangtools.sal.binding.model.api.ParameterizedType; import org.opendaylight.yangtools.sal.binding.model.api.Type; import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.model.parser.api.YangContextParser; -import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl; public class SupportTestUtil { - public static SchemaContext resolveSchemaContextFromFiles(final URI... yangFiles) throws IOException { - final YangContextParser parser = new YangParserImpl(); + public static SchemaContext resolveSchemaContextFromFiles(final URI... yangFiles) throws IOException, SourceException, ReactorException { final List inputFiles = new ArrayList(); for (int i = 0; i < yangFiles.length; ++i) { inputFiles.add(new File(yangFiles[i])); } - return parser.parseFiles(inputFiles); + return RetestUtils.parseYangSources(inputFiles); } public static void containsMethods(final GeneratedType genType, final NameTypePattern... searchedSignsWhat) { diff --git a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/TypeProviderIntegrationTest.java b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/TypeProviderIntegrationTest.java index d34f7c5278..7cc22aa2b2 100644 --- a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/TypeProviderIntegrationTest.java +++ b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/TypeProviderIntegrationTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2016 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, @@ -13,7 +13,6 @@ import static org.junit.Assert.assertNotNull; import java.io.File; import java.text.ParseException; import java.text.SimpleDateFormat; -import java.util.Arrays; import java.util.Set; import org.junit.Before; import org.junit.BeforeClass; @@ -24,7 +23,6 @@ import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode; import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.opendaylight.yangtools.yang.model.api.TypeDefinition; -import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl; public class TypeProviderIntegrationTest { private final String PKG = "org.opendaylight.yang.gen.v1.urn.opendaylight.test.rev131008."; @@ -38,7 +36,7 @@ public class TypeProviderIntegrationTest { .toURI()); File ietfInetTypes = new File(TypeProviderIntegrationTest.class.getResource("/ietf/ietf-inet-types.yang") .toURI()); - context = new YangParserImpl().parseFiles(Arrays.asList(abstractTopology, ietfInetTypes)); + context = RetestUtils.parseYangSources(abstractTopology, ietfInetTypes); assertNotNull(context); } diff --git a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/UnionTypeDefTest.java b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/UnionTypeDefTest.java index ae8a3eb3d4..2280a6da64 100644 --- a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/UnionTypeDefTest.java +++ b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/UnionTypeDefTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2016 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, @@ -11,14 +11,11 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import java.io.File; -import java.util.Arrays; import java.util.List; - import org.junit.Test; import org.opendaylight.yangtools.sal.binding.generator.api.BindingGenerator; import org.opendaylight.yangtools.sal.binding.model.api.Type; import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl; public class UnionTypeDefTest { @@ -26,7 +23,7 @@ public class UnionTypeDefTest { public void unionTypeResolvingTest() throws Exception { File abstractTopology = new File(getClass().getResource("/union-test-models/abstract-topology.yang").toURI()); File ietfInetTypes = new File(getClass().getResource("/ietf/ietf-inet-types.yang").toURI()); - final SchemaContext context = new YangParserImpl().parseFiles(Arrays.asList(abstractTopology, ietfInetTypes)); + final SchemaContext context = RetestUtils.parseYangSources(abstractTopology, ietfInetTypes); assertNotNull("context is null", context); final BindingGenerator bindingGen = new BindingGeneratorImpl(true); diff --git a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/UsesTest.java b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/UsesTest.java index 524ef51962..81bd94216c 100644 --- a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/UsesTest.java +++ b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/UsesTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2016 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, @@ -10,23 +10,22 @@ package org.opendaylight.yangtools.sal.binding.generator.impl; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import static org.opendaylight.yangtools.sal.binding.generator.impl.SupportTestUtil.containsInterface; import static org.opendaylight.yangtools.sal.binding.generator.impl.SupportTestUtil.containsMethods; +import static org.opendaylight.yangtools.sal.binding.generator.impl.SupportTestUtil.containsInterface; +import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; +import org.opendaylight.yangtools.yang.parser.spi.source.SourceException; import java.io.File; import java.io.IOException; import java.net.URISyntaxException; import java.util.ArrayList; import java.util.List; - import org.junit.Test; import org.opendaylight.yangtools.sal.binding.generator.api.BindingGenerator; import org.opendaylight.yangtools.sal.binding.model.api.GeneratedTransferObject; import org.opendaylight.yangtools.sal.binding.model.api.GeneratedType; import org.opendaylight.yangtools.sal.binding.model.api.Type; import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.model.parser.api.YangContextParser; -import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl; public class UsesTest { @@ -42,10 +41,9 @@ public class UsesTest { } @Test - public void usesInGroupingDependenciesTest() throws IOException { + public void usesInGroupingDependenciesTest() throws IOException, SourceException, ReactorException { List testModels = loadTestResources("/uses-of-grouping/uses-of-grouping-dependencies.yang"); - final YangContextParser parser = new YangParserImpl(); - final SchemaContext context = parser.parseFiles(testModels); + final SchemaContext context = RetestUtils.parseYangSources(testModels); assertNotNull(context); final BindingGenerator bindingGen = new BindingGeneratorImpl(true); @@ -97,10 +95,10 @@ public class UsesTest { } @Test - public void usesInCaseTest() throws IOException { + public void usesInCaseTest() throws IOException, SourceException, ReactorException { List testModels = loadTestResources("/uses-of-grouping/uses-of-grouping-case.yang"); - final YangContextParser parser = new YangParserImpl(); - final SchemaContext context = parser.parseFiles(testModels); + + final SchemaContext context = RetestUtils.parseYangSources(testModels); assertNotNull(context); final BindingGenerator bindingGen = new BindingGeneratorImpl(true); @@ -145,10 +143,10 @@ public class UsesTest { } @Test - public void usesInContainerTest() throws IOException { + public void usesInContainerTest() throws IOException, SourceException, ReactorException { List testModels = loadTestResources("/uses-of-grouping/uses-of-grouping-container.yang"); - final YangContextParser parser = new YangParserImpl(); - final SchemaContext context = parser.parseFiles(testModels); + + final SchemaContext context = RetestUtils.parseYangSources(testModels); assertNotNull(context); final BindingGenerator bindingGen = new BindingGeneratorImpl(true); @@ -198,10 +196,10 @@ public class UsesTest { } @Test - public void usesInGroupingTest() throws IOException { + public void usesInGroupingTest() throws IOException, SourceException, ReactorException { List testModels = loadTestResources("/uses-of-grouping/uses-of-grouping-grouping.yang"); - final YangContextParser parser = new YangParserImpl(); - final SchemaContext context = parser.parseFiles(testModels); + + final SchemaContext context = RetestUtils.parseYangSources(testModels); assertNotNull(context); final BindingGenerator bindingGen = new BindingGeneratorImpl(true); @@ -249,10 +247,10 @@ public class UsesTest { } @Test - public void usesInListTest() throws IOException { + public void usesInListTest() throws IOException, SourceException, ReactorException { List testModels = loadTestResources("/uses-of-grouping/uses-of-grouping-list.yang"); - final YangContextParser parser = new YangParserImpl(); - final SchemaContext context = parser.parseFiles(testModels); + + final SchemaContext context = RetestUtils.parseYangSources(testModels); assertNotNull(context); final BindingGenerator bindingGen = new BindingGeneratorImpl(true); @@ -331,10 +329,10 @@ public class UsesTest { } @Test - public void usesInModulTest() throws IOException { + public void usesInModulTest() throws IOException, SourceException, ReactorException { List testModels = loadTestResources("/uses-of-grouping/uses-of-grouping-modul.yang"); - final YangContextParser parser = new YangParserImpl(); - final SchemaContext context = parser.parseFiles(testModels); + + final SchemaContext context = RetestUtils.parseYangSources(testModels); assertNotNull(context); final BindingGenerator bindingGen = new BindingGeneratorImpl(true); @@ -382,10 +380,10 @@ public class UsesTest { } @Test - public void usesInRpcTest() throws IOException { + public void usesInRpcTest() throws IOException, SourceException, ReactorException { List testModels = loadTestResources("/uses-of-grouping/uses-of-grouping-rpc.yang"); - final YangContextParser parser = new YangParserImpl(); - final SchemaContext context = parser.parseFiles(testModels); + + final SchemaContext context = RetestUtils.parseYangSources(testModels); assertNotNull(context); final BindingGenerator bindingGen = new BindingGeneratorImpl(true); @@ -475,10 +473,10 @@ public class UsesTest { } @Test - public void usesInAugmentTest() throws IOException { + public void usesInAugmentTest() throws IOException, SourceException, ReactorException { List testModels = loadTestResources("/uses-of-grouping/uses-of-grouping-augment.yang"); - final YangContextParser parser = new YangParserImpl(); - final SchemaContext context = parser.parseFiles(testModels); + + final SchemaContext context = RetestUtils.parseYangSources(testModels); assertNotNull(context); final BindingGenerator bindingGen = new BindingGeneratorImpl(true); @@ -528,10 +526,10 @@ public class UsesTest { } @Test - public void usesInNotification() throws IOException { + public void usesInNotification() throws IOException, SourceException, ReactorException { List testModels = loadTestResources("/uses-of-grouping/uses-of-grouping-notification.yang"); - final YangContextParser parser = new YangParserImpl(); - final SchemaContext context = parser.parseFiles(testModels); + + final SchemaContext context = RetestUtils.parseYangSources(testModels); assertNotNull(context); final BindingGenerator bindingGen = new BindingGeneratorImpl(true); diff --git a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/AbstractTypesTest.java b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/AbstractTypesTest.java deleted file mode 100644 index 92a3e8fd3b..0000000000 --- a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/AbstractTypesTest.java +++ /dev/null @@ -1,40 +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.yangtools.sal.binding.generator.impl.stmt.parser.retest; - -import com.google.common.base.Preconditions; -import java.io.File; -import java.net.URISyntaxException; -import java.net.URL; -import java.util.HashSet; -import java.util.Set; -import org.junit.Before; - -public abstract class AbstractTypesTest { - - private final URL testSourcesDirUrl; - protected Set testModels; - - AbstractTypesTest(final URL testSourcesDirUrl) { - this.testSourcesDirUrl = testSourcesDirUrl; - } - - @Before - public void loadTestResources() throws URISyntaxException { - File testSourcesDir = new File(testSourcesDirUrl.toURI()); - File[] testFiles = Preconditions.checkNotNull(testSourcesDir.listFiles(), testSourcesDir - + " does not denote a directory"); - testModels = new HashSet<>(); - for (File file : testFiles) { - if (file.isFile()) { - testModels.add(file); - } - } - } - -} diff --git a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/AugmentRelativeXPathTest.java b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/AugmentRelativeXPathTest.java deleted file mode 100644 index 2792a02b3d..0000000000 --- a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/AugmentRelativeXPathTest.java +++ /dev/null @@ -1,130 +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.yangtools.sal.binding.generator.impl.stmt.parser.retest; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; -import org.opendaylight.yangtools.yang.parser.spi.source.SourceException; - -import org.opendaylight.yangtools.sal.binding.generator.impl.BindingGeneratorImpl; -import java.io.IOException; -import java.util.List; -import org.junit.Test; -import org.opendaylight.yangtools.sal.binding.generator.api.BindingGenerator; -import org.opendaylight.yangtools.sal.binding.model.api.GeneratedProperty; -import org.opendaylight.yangtools.sal.binding.model.api.GeneratedTransferObject; -import org.opendaylight.yangtools.sal.binding.model.api.GeneratedType; -import org.opendaylight.yangtools.sal.binding.model.api.MethodSignature; -import org.opendaylight.yangtools.sal.binding.model.api.Type; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; - -public class AugmentRelativeXPathTest extends AbstractTypesTest { - - public AugmentRelativeXPathTest() { - super(AugmentRelativeXPathTest.class.getResource("/augment-relative-xpath-models")); - } - - @Test - public void AugmentationWithRelativeXPathTest() throws IOException, SourceException, ReactorException { - - final SchemaContext context = RetestUtils.parseYangSources(testModels); - - assertNotNull("context is null", context); - final BindingGenerator bindingGen = new BindingGeneratorImpl(true); - final List genTypes = bindingGen.generateTypes(context); - - assertNotNull("genTypes is null", genTypes); - assertFalse("genTypes is empty", genTypes.isEmpty()); - - GeneratedTransferObject gtInterfaceKey = null; - GeneratedType gtInterface = null; - GeneratedType gtTunnel = null; - GeneratedTransferObject gtTunnelKey = null; - - for (final Type type : genTypes) { - if (type.getName().equals("InterfaceKey") && type.getPackageName().contains("augment._abstract.topology")) { - gtInterfaceKey = (GeneratedTransferObject) type; - } else if (type.getName().equals("Interface") - && type.getPackageName().contains("augment._abstract.topology")) { - gtInterface = (GeneratedType) type; - } else if (type.getName().equals("Tunnel") && type.getPackageName().contains("augment._abstract.topology")) { - gtTunnel = (GeneratedType) type; - } else if (type.getName().equals("TunnelKey") - && type.getPackageName().contains("augment._abstract.topology")) { - gtTunnelKey = (GeneratedTransferObject) type; - } - } - - // 'Interface - assertNotNull("Interface is null", gtInterface); - final List gtInterfaceMethods = gtInterface.getMethodDefinitions(); - assertNotNull("Interface methods are null", gtInterfaceMethods); - MethodSignature getIfcKeyMethod = null; - for (final MethodSignature method : gtInterfaceMethods) { - if (method.getName().equals("getKey")) { - getIfcKeyMethod = method; - break; - } - } - assertNotNull("getKey method is null", getIfcKeyMethod); - assertNotNull("getKey method return type is null", getIfcKeyMethod.getReturnType()); - assertTrue("getKey method return type name must be InterfaceKey", getIfcKeyMethod.getReturnType().getName() - .equals("InterfaceKey")); - - // 'InterfaceKey' - assertNotNull("InterfaceKey is null", gtInterfaceKey); - final List properties = gtInterfaceKey.getProperties(); - assertNotNull("InterfaceKey properties are null", properties); - GeneratedProperty gtInterfaceId = null; - for (final GeneratedProperty property : properties) { - if (property.getName().equals("interfaceId")) { - gtInterfaceId = property; - break; - } - } - assertNotNull("interfaceId is null", gtInterfaceId); - assertNotNull("interfaceId return type is null", gtInterfaceId.getReturnType()); - assertTrue("interfaceId return type name must be String", - gtInterfaceId.getReturnType().getName().equals("String")); - - // 'Tunnel' - assertNotNull("Tunnel is null", gtTunnel); - final List tunnelMethods = gtTunnel.getMethodDefinitions(); - assertNotNull("Tunnel methods are null", tunnelMethods); - MethodSignature getTunnelKeyMethod = null; - for (MethodSignature method : tunnelMethods) { - if (method.getName().equals("getKey")) { - getTunnelKeyMethod = method; - break; - } - } - assertNotNull("getKey method is null", getTunnelKeyMethod); - assertNotNull("getKey method return type", getTunnelKeyMethod.getReturnType()); - assertTrue("getKey method return type name must be TunnelKey", getTunnelKeyMethod.getReturnType().getName() - .equals("TunnelKey")); - - // 'TunnelKey' - assertNotNull("TunnelKey is null", gtTunnelKey); - final List tunnelKeyProperties = gtTunnelKey.getProperties(); - assertNotNull("TunnelKey properties are null", tunnelKeyProperties); - - GeneratedProperty gtTunnelId = null; - for (final GeneratedProperty property : tunnelKeyProperties) { - if (property.getName().equals("tunnelId")) { - gtTunnelId = property; - } - } - assertNotNull("tunnelId is null", gtTunnelId); - assertNotNull("tunnelId return type is null", gtTunnelId.getReturnType()); - assertTrue("tunnelId return type name must be Uri", gtTunnelId.getReturnType().getName().equals("Uri")); - } - -} diff --git a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/AugmentedTypeTest.java b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/AugmentedTypeTest.java deleted file mode 100644 index bfc53fc1f9..0000000000 --- a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/AugmentedTypeTest.java +++ /dev/null @@ -1,182 +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.yangtools.sal.binding.generator.impl.stmt.parser.retest; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import org.opendaylight.yangtools.sal.binding.generator.impl.BindingGeneratorImpl; - -import java.io.File; -import java.util.List; -import org.junit.Test; -import org.opendaylight.yangtools.sal.binding.generator.api.BindingGenerator; -import org.opendaylight.yangtools.sal.binding.model.api.GeneratedProperty; -import org.opendaylight.yangtools.sal.binding.model.api.GeneratedTransferObject; -import org.opendaylight.yangtools.sal.binding.model.api.GeneratedType; -import org.opendaylight.yangtools.sal.binding.model.api.MethodSignature; -import org.opendaylight.yangtools.sal.binding.model.api.Type; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; - -public class AugmentedTypeTest { - - @Test - public void augmentedAbstractTopologyTest() throws Exception { - File abstractTopology = new File(getClass().getResource( - "/augment-test-models/abstract-topology@2013-02-08.yang").toURI()); - File augmentTopology = new File(getClass().getResource( - "/augment-test-models/augment-abstract-topology@2013-05-03.yang").toURI()); - File augmentNetworkLink = new File(getClass().getResource( - "/augment-test-models/augment-network-link-attributes@2013-05-03.yang").toURI()); - File augmentTopologyTunnels = new File(getClass().getResource( - "/augment-test-models/augment-topology-tunnels@2013-05-03.yang").toURI()); - File ietfInterfaces = new File(getClass().getResource("/augment-test-models/ietf-interfaces@2012-11-15.yang") - .toURI()); - - final SchemaContext context = RetestUtils.parseYangSources(abstractTopology, augmentTopology, - augmentNetworkLink, augmentTopologyTunnels, ietfInterfaces); - assertNotNull("Schema Context is null", context); - - final BindingGenerator bindingGen = new BindingGeneratorImpl(true); - final List genTypes = bindingGen.generateTypes(context); - - assertNotNull("genTypes is null", genTypes); - assertFalse("genTypes is empty", genTypes.isEmpty()); - - GeneratedTransferObject gtInterfaceKey = null; - GeneratedType gtInterface = null; - GeneratedType gtTunnel = null; - GeneratedTransferObject gtTunnelKey = null; - GeneratedType gtNetworkLink2 = null; - - for (final Type type : genTypes) { - if (type.getName().equals("InterfaceKey") && type.getPackageName().contains("augment._abstract.topology")) { - gtInterfaceKey = (GeneratedTransferObject) type; - } else if (type.getName().equals("Interface") - && type.getPackageName().contains("augment._abstract.topology")) { - gtInterface = (GeneratedType) type; - } else if (type.getName().equals("Tunnel") && type.getPackageName().contains("augment._abstract.topology")) { - gtTunnel = (GeneratedType) type; - } else if (type.getName().equals("TunnelKey") - && type.getPackageName().contains("augment._abstract.topology")) { - gtTunnelKey = (GeneratedTransferObject) type; - } else if (type.getName().equals("NetworkLink2") - && type.getPackageName().contains("augment._abstract.topology")) { - gtNetworkLink2 = (GeneratedType) type; - } - } - - // 'Interface - assertNotNull("gtInterface is null", gtInterface); - final List gtInterfaceMethods = gtInterface.getMethodDefinitions(); - assertNotNull("gtInterfaceMethods is null", gtInterfaceMethods); - MethodSignature getIfcKeyMethod = null; - for (final MethodSignature method : gtInterfaceMethods) { - if (method.getName().equals("getKey")) { - getIfcKeyMethod = method; - break; - } - } - assertNotNull("getIfcKeyMethod is null", getIfcKeyMethod); - assertNotNull("getIfcKeyMethod.getReturnType() is null", getIfcKeyMethod.getReturnType()); - assertFalse("getIfcKeyMethod.getReturnType() should not be Void", - getIfcKeyMethod.getReturnType().equals("java.lang.Void")); - assertTrue("getIfcKeyMethod.getReturnType().getName() must be InterfaceKey", getIfcKeyMethod.getReturnType() - .getName().equals("InterfaceKey")); - - MethodSignature getHigherLayerIfMethod = null; - for (final MethodSignature method : gtInterfaceMethods) { - if (method.getName().equals("getHigherLayerIf")) { - getHigherLayerIfMethod = method; - break; - } - } - assertNotNull("getHigherLayerIf method is null", getHigherLayerIfMethod); - assertNotNull("getHigherLayerIf method return type is null", getHigherLayerIfMethod.getReturnType()); - assertTrue("getHigherLayerIf method return type name must be List", getHigherLayerIfMethod.getReturnType() - .getName().equals("List")); - - // 'InterfaceKey' - assertNotNull("InterfaceKey is null", gtInterfaceKey); - final List properties = gtInterfaceKey.getProperties(); - assertNotNull("properties is null", properties); - GeneratedProperty gtInterfaceId = null; - for (final GeneratedProperty property : properties) { - if (property.getName().equals("interfaceId")) { - gtInterfaceId = property; - break; - } - } - assertNotNull("interfaceId is null", gtInterfaceId); - assertNotNull("interfaceId return type is null", gtInterfaceId.getReturnType()); - assertTrue("interfaceId return type name must be String", - gtInterfaceId.getReturnType().getName().equals("String")); - - // 'Tunnel' - assertNotNull("Tunnel is null", gtTunnel); - final List tunnelMethods = gtTunnel.getMethodDefinitions(); - assertNotNull("Tunnel methods are null", tunnelMethods); - MethodSignature getTunnelKeyMethod = null; - for (MethodSignature method : tunnelMethods) { - if (method.getName().equals("getKey")) { - getTunnelKeyMethod = method; - break; - } - } - assertNotNull("getKey method of Tunnel is null", getTunnelKeyMethod); - assertNotNull("getKey method return type is null", getTunnelKeyMethod.getReturnType()); - assertTrue("getKey method return type name must be TunnelKey", getTunnelKeyMethod.getReturnType().getName() - .equals("TunnelKey")); - - // 'TunnelKey' - assertNotNull("TunnelKey is null", gtTunnelKey); - final List tunnelKeyProperties = gtTunnelKey.getProperties(); - assertNotNull("TunnelKey properties are null", tunnelKeyProperties); - - GeneratedProperty gtTunnelId = null; - for (final GeneratedProperty property : tunnelKeyProperties) { - if (property.getName().equals("tunnelId")) { - gtTunnelId = property; - } - } - assertNotNull("tunnelId is null", gtTunnelId); - assertNotNull("tunnelId return type is null", gtTunnelId.getReturnType()); - assertTrue("tunnelId returnType name must be Integer", gtTunnelId.getReturnType().getName().equals("Integer")); - - // 'NetworkLink2' - assertNotNull("NetworkLink2 is null", gtNetworkLink2); - - final List networkLink2Methods = gtNetworkLink2.getMethodDefinitions(); - assertNotNull("NetworkLink2 methods are null", networkLink2Methods); - - MethodSignature getIfcMethod = null; - for (MethodSignature method : networkLink2Methods) { - if (method.getName().equals("getInterface")) { - getIfcMethod = method; - break; - } - } - - assertNotNull("getInterface method is null", getIfcMethod); - assertNotNull("getInterface method return type is null", getIfcMethod.getReturnType()); - assertTrue("getInterface method return type name must be String", getIfcMethod.getReturnType().getName() - .equals("String")); - } - - @Test - public void augmentedNetworkLinkTest() { - - } - - @Test - public void augmentedTopologyTunnelsTest() { - - } - -} diff --git a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/BinaryTypeTest.java b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/BinaryTypeTest.java deleted file mode 100644 index bdd273e1c8..0000000000 --- a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/BinaryTypeTest.java +++ /dev/null @@ -1,57 +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.yangtools.sal.binding.generator.impl.stmt.parser.retest; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; - -import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; -import org.opendaylight.yangtools.yang.parser.spi.source.SourceException; - -import org.opendaylight.yangtools.sal.binding.generator.impl.BindingGeneratorImpl; -import java.io.File; -import java.io.IOException; -import java.net.URISyntaxException; -import java.net.URL; -import java.util.ArrayList; -import java.util.List; -import org.junit.BeforeClass; -import org.junit.Test; -import org.opendaylight.yangtools.sal.binding.generator.api.BindingGenerator; -import org.opendaylight.yangtools.sal.binding.model.api.Type; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; - -public class BinaryTypeTest { - private final static List yangModels = new ArrayList<>(); - private final static URL yangModelsFolder = AugmentedTypeTest.class - .getResource("/binary-type-test-models"); - - @BeforeClass - public static void loadTestResources() throws URISyntaxException { - final File augFolder = new File(yangModelsFolder.toURI()); - for (final File fileEntry : augFolder.listFiles()) { - if (fileEntry.isFile()) { - yangModels.add(fileEntry); - } - } - } - - @Test - public void binaryTypeTest() throws IOException, SourceException, ReactorException { - final SchemaContext context = RetestUtils.parseYangSources(yangModels); - - assertNotNull("context is null", context); - final BindingGenerator bindingGen = new BindingGeneratorImpl(true); - final List genTypes = bindingGen.generateTypes(context); - - assertNotNull("genTypes is null", genTypes); - assertFalse("genTypes is empty", genTypes.isEmpty()); - - //TODO: implement test - } -} diff --git a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/BindingGeneratorImplTest.java b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/BindingGeneratorImplTest.java deleted file mode 100644 index 79ec3333e7..0000000000 --- a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/BindingGeneratorImplTest.java +++ /dev/null @@ -1,197 +0,0 @@ -/* - * Copyright (c) 2015 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.yangtools.sal.binding.generator.impl.stmt.parser.retest; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import org.opendaylight.yangtools.sal.binding.generator.impl.BindingGeneratorImpl; -import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; -import org.opendaylight.yangtools.yang.parser.spi.source.SourceException; -import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor; -import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline; -import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.EffectiveSchemaContext; -import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl; -import java.io.File; -import java.io.IOException; -import java.net.URISyntaxException; -import java.util.List; -import org.junit.Test; -import org.opendaylight.yangtools.sal.binding.model.api.GeneratedType; -import org.opendaylight.yangtools.sal.binding.model.api.ParameterizedType; -import org.opendaylight.yangtools.sal.binding.model.api.Type; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException; - -public class BindingGeneratorImplTest { - - private static final YangStatementSourceImpl NETWORK_TOPOLOGY_20131021 = new YangStatementSourceImpl( - "/isis-topology/network-topology@2013-10-21.yang", false); - - private static final YangStatementSourceImpl ISIS_20131021 = new YangStatementSourceImpl( - "/isis-topology/isis-topology@2013-10-21.yang", false); - - private static final YangStatementSourceImpl L3_20131021 = new YangStatementSourceImpl( - "/isis-topology/l3-unicast-igp-topology@2013-10-21.yang", false); - - @Test - public void isisTotpologyStatementParserTest() throws IOException, - YangSyntaxErrorException, URISyntaxException, SourceException, - ReactorException { - CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR - .newBuild(); - - reactor.addSources(ISIS_20131021, L3_20131021, - NETWORK_TOPOLOGY_20131021); - - EffectiveSchemaContext context = reactor.buildEffective(); - assertNotNull(context); - - List generateTypes = new BindingGeneratorImpl(false) - .generateTypes(context); - - assertFalse(generateTypes.isEmpty()); - } - - @Test - public void choiceNodeGenerationTest() throws IOException, - YangSyntaxErrorException, URISyntaxException, SourceException, ReactorException { - File resourceFile = new File(getClass().getResource( - "/binding-generator-impl-test/choice-test.yang").toURI()); - - SchemaContext context = RetestUtils.parseYangSources(resourceFile); - - List generateTypes = new BindingGeneratorImpl(false) - .generateTypes(context); - - GeneratedType choiceTestData = null; - GeneratedType myRootContainer = null; - GeneratedType myList = null; - GeneratedType myContainer = null; - GeneratedType myList2 = null; - GeneratedType myContainer2 = null; - - for (Type type : generateTypes) { - switch (type.getName()) { - case "ChoiceTestData": - choiceTestData = (GeneratedType) type; - break; - case "Myrootcontainer": - myRootContainer = (GeneratedType) type; - break; - case "Mylist": - myList = (GeneratedType) type; - break; - case "Mylist2": - myList2 = (GeneratedType) type; - break; - case "Mycontainer": - myContainer = (GeneratedType) type; - break; - case "Mycontainer2": - myContainer2 = (GeneratedType) type; - break; - } - } - - assertNotNull(choiceTestData); - assertNotNull(myRootContainer); - assertNotNull(myList); - assertNotNull(myContainer); - assertNotNull(myList2); - assertNotNull(myContainer2); - - List implements1 = myContainer.getImplements(); - Type childOfParamType = null; - for (Type type : implements1) { - if (type.getName().equals("ChildOf")) { - childOfParamType = ((ParameterizedType) type) - .getActualTypeArguments()[0]; - break; - } - } - assertNotNull(childOfParamType); - assertTrue(childOfParamType.getName().equals("ChoiceTestData")); - - implements1 = myList.getImplements(); - childOfParamType = null; - for (Type type : implements1) { - if (type.getName().equals("ChildOf")) { - childOfParamType = ((ParameterizedType) type) - .getActualTypeArguments()[0]; - break; - } - } - assertNotNull(childOfParamType); - assertTrue(childOfParamType.getName().equals("ChoiceTestData")); - - implements1 = myContainer2.getImplements(); - childOfParamType = null; - for (Type type : implements1) { - if (type.getName().equals("ChildOf")) { - childOfParamType = ((ParameterizedType) type) - .getActualTypeArguments()[0]; - break; - } - } - assertNotNull(childOfParamType); - assertTrue(childOfParamType.getName().equals("Myrootcontainer")); - - implements1 = myList2.getImplements(); - childOfParamType = null; - for (Type type : implements1) { - if (type.getName().equals("ChildOf")) { - childOfParamType = ((ParameterizedType) type) - .getActualTypeArguments()[0]; - break; - } - } - assertNotNull(childOfParamType); - assertTrue(childOfParamType.getName().equals("Myrootcontainer")); - - } - - @Test - public void notificationGenerationTest() throws IOException, - YangSyntaxErrorException, URISyntaxException, SourceException, ReactorException { - File resourceFile = new File(getClass().getResource( - "/binding-generator-impl-test/notification-test.yang").toURI()); - - SchemaContext context = RetestUtils.parseYangSources(resourceFile); - - List generateTypes = new BindingGeneratorImpl(false) - .generateTypes(context); - - GeneratedType foo = null; - for (Type type : generateTypes) { - if (type.getName().equals("Foo")) { - foo = (GeneratedType) type; - break; - } - } - - Type childOf = null; - Type dataObject = null; - List impl = foo.getImplements(); - for (Type type : impl) { - switch (type.getName()) { - case "ChildOf": - childOf = type; - break; - case "DataObject": - dataObject = type; - break; - } - } - - assertNull(childOf); - assertNotNull(dataObject); - } - -} diff --git a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/BitAndUnionTOEnclosingTest.java b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/BitAndUnionTOEnclosingTest.java deleted file mode 100644 index 46ec6f5055..0000000000 --- a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/BitAndUnionTOEnclosingTest.java +++ /dev/null @@ -1,273 +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.yangtools.sal.binding.generator.impl.stmt.parser.retest; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.opendaylight.yangtools.sal.binding.generator.impl.stmt.parser.retest.SupportTestUtil.containsMethods; -import static org.opendaylight.yangtools.sal.binding.generator.impl.stmt.parser.retest.SupportTestUtil.containsAttributes; - -import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; -import org.opendaylight.yangtools.yang.parser.spi.source.SourceException; -import org.opendaylight.yangtools.sal.binding.generator.impl.BindingGeneratorImpl; -import java.io.File; -import java.io.IOException; -import java.net.URISyntaxException; -import java.util.ArrayList; -import java.util.List; -import org.junit.BeforeClass; -import org.junit.Test; -import org.opendaylight.yangtools.sal.binding.generator.api.BindingGenerator; -import org.opendaylight.yangtools.sal.binding.model.api.GeneratedProperty; -import org.opendaylight.yangtools.sal.binding.model.api.GeneratedTransferObject; -import org.opendaylight.yangtools.sal.binding.model.api.GeneratedType; -import org.opendaylight.yangtools.sal.binding.model.api.Type; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; - -public class BitAndUnionTOEnclosingTest { - - private final static List testModels = new ArrayList(); - private static List genTypes = null; - private static GeneratedType parentContainer = null; - - public static void parseResources() throws IOException, SourceException, ReactorException { - - final SchemaContext context = RetestUtils.parseYangSources(testModels); - - assertNotNull(context); - final BindingGenerator bindingGen = new BindingGeneratorImpl(true); - genTypes = bindingGen.generateTypes(context); - - for (Type type : genTypes) { - if (type instanceof GeneratedType) { - GeneratedType genType = (GeneratedType) type; - if (genType.getName().equals("ParentContainer") && !(genType instanceof GeneratedTransferObject)) { - parentContainer = genType; - } - } - } - } - - @BeforeClass - public static void loadTestResources() throws IOException, URISyntaxException, SourceException, ReactorException { - final File listModelFile = new File(ExtendedTypedefTest.class.getResource("/bit_and_union.yang").toURI()); - testModels.add(listModelFile); - parseResources(); - } - - @Test - public void testNestedTypesInLeaf() { - GeneratedTransferObject lfLeaf = null; - int lfLeafCounter = 0; - GeneratedTransferObject lf1Leaf = null; - int lf1LeafCounter = 0; - GeneratedTransferObject lf2Leaf = null; - int lf2LeafCounter = 0; - List enclosedTypes = parentContainer.getEnclosedTypes(); - for (GeneratedType genType : enclosedTypes) { - if (genType instanceof GeneratedTransferObject) { - if (genType.getName().equals("Lf")) { - lfLeaf = (GeneratedTransferObject) genType; - lfLeafCounter++; - } else if (genType.getName().equals("Lf1")) { - lf1Leaf = (GeneratedTransferObject) genType; - lf1LeafCounter++; - } else if (genType.getName().equals("Lf2")) { - lf2Leaf = (GeneratedTransferObject) genType; - lf2LeafCounter++; - } - - } - } - - // nested types in leaf, contains Lf? - assertNotNull("Lf TO wasn't found.", lfLeaf); - assertEquals("Lf TO has incorrect number of occurences.", 1, lfLeafCounter); - assertEquals("Lf has incorrect package name.", - "org.opendaylight.yang.gen.v1.urn.bit.union.in.leaf.rev130626.ParentContainer", - lfLeaf.getPackageName()); - - assertEquals("Lf generated TO has incorrect number of properties", 3, lfLeaf.getProperties().size()); - containsAttributes(lfLeaf, true, true, true, new NameTypePattern("string", "String")); - containsAttributes(lfLeaf, true, false, true, new NameTypePattern("lf1", "Lf1")); - - // nested types in leaf, contains Lf1? - assertNotNull("Lf1 TO wasn't found.", lf1Leaf); - assertEquals("Lf1 TO has incorrect number of occurences.", 1, lf1LeafCounter); - assertEquals("Lf1 has incorrect package name.", - "org.opendaylight.yang.gen.v1.urn.bit.union.in.leaf.rev130626.ParentContainer", - lf1Leaf.getPackageName()); - - assertEquals("Lf generated TO has incorrect number of properties", 4, lf1Leaf.getProperties().size()); - containsAttributes(lf1Leaf, true, true, true, new NameTypePattern("uint32", "Long")); - containsAttributes(lf1Leaf, true, true, true, new NameTypePattern("int8", "Byte")); - containsAttributes(lf1Leaf, true, true, true, new NameTypePattern("string", "String")); - containsAttributes(lf1Leaf, true, false, true, new NameTypePattern("lf2", "Lf2")); - - // nested types in leaf, contains Lf2? - assertNotNull("Lf2 TO wasn't found.", lf2Leaf); - assertEquals("Lf2 TO has incorrect number of occurences.", 1, lf2LeafCounter); - assertEquals("Lf2 has incorrect package name.", - "org.opendaylight.yang.gen.v1.urn.bit.union.in.leaf.rev130626.ParentContainer", - lf2Leaf.getPackageName()); - - assertEquals("Lf generated TO has incorrect number of properties", 2, lf2Leaf.getProperties().size()); - containsAttributes(lf2Leaf, true, true, true, new NameTypePattern("string", "String")); - containsAttributes(lf2Leaf, true, true, true, new NameTypePattern("uint64", "BigInteger")); - } - - @Test - public void testNestedTypesInTypedef() { - - GeneratedTransferObject typeUnionTypedef = null; - int typeUnionTypedefCounter = 0; - - for (Type type : genTypes) { - if (type instanceof GeneratedType) { - GeneratedType genType = (GeneratedType) type; - if (genType.getName().equals("TypeUnion") && (genType instanceof GeneratedTransferObject)) { - typeUnionTypedef = (GeneratedTransferObject) genType; - typeUnionTypedefCounter++; - } - } - } - - assertNotNull("TypeUnion TO wasn't found.", typeUnionTypedef); - assertEquals("TypeUnion TO has incorrect number of occurences.", 1, typeUnionTypedefCounter); - - assertNotNull("TypeUnion TO wasn't found.", typeUnionTypedef); - assertEquals("TypeUnion TO has incorrect number of occurences.", 1, typeUnionTypedefCounter); - assertEquals("TypeUnion has incorrect package name.", - "org.opendaylight.yang.gen.v1.urn.bit.union.in.leaf.rev130626", typeUnionTypedef.getPackageName()); - - assertEquals("TypeUnion generated TO has incorrect number of properties", 3, typeUnionTypedef.getProperties() - .size()); - containsAttributes(typeUnionTypedef, true, true, true, new NameTypePattern("string", "String")); - containsAttributes(typeUnionTypedef, true, false, true, new NameTypePattern("typeUnion1", "TypeUnion1")); - - List nestedUnions = typeUnionTypedef.getEnclosedTypes(); - assertEquals("Incorrect number of nested unions", 2, nestedUnions.size()); - - GeneratedTransferObject typeUnion1 = null; - int typeUnion1Counter = 0; - GeneratedTransferObject typeUnion2 = null; - int typeUnion2Counter = 0; - for (GeneratedType genType : nestedUnions) { - if (genType instanceof GeneratedTransferObject) { - if (genType.getName().equals("TypeUnion1")) { - typeUnion1 = (GeneratedTransferObject) genType; - typeUnion1Counter++; - } else if (genType.getName().equals("TypeUnion2")) { - typeUnion2 = (GeneratedTransferObject) genType; - typeUnion2Counter++; - } - } - } - - assertNotNull("TypeUnion1 TO wasn't found.", typeUnion1); - assertEquals("TypeUnion1 TO has incorrect number of occurences.", 1, typeUnion1Counter); - - assertEquals("TypeUnion1 has incorrect package name.", - "org.opendaylight.yang.gen.v1.urn.bit.union.in.leaf.rev130626", typeUnion1.getPackageName()); - - assertEquals("TypeUnion1 generated TO has incorrect number of properties", 4, typeUnion1.getProperties().size()); - - containsAttributes(typeUnion1, true, true, true, new NameTypePattern("uint32", "Long")); - containsAttributes(typeUnion1, true, true, true, new NameTypePattern("int8", "Byte")); - containsAttributes(typeUnion1, true, true, true, new NameTypePattern("string", "String")); - containsAttributes(typeUnion1, true, false, true, new NameTypePattern("typeUnion2", "TypeUnion2")); - - assertNotNull("TypeUnion2 TO wasn't found.", typeUnion2); - assertEquals("TypeUnion2 TO has incorrect number of occurences.", 1, typeUnion2Counter); - - assertEquals("TypeUnion2 has incorrect package name.", - "org.opendaylight.yang.gen.v1.urn.bit.union.in.leaf.rev130626", typeUnion2.getPackageName()); - - assertEquals("TypeUnion2 generated TO has incorrect number of properties", 2, typeUnion2.getProperties().size()); - containsAttributes(typeUnion2, true, true, true, new NameTypePattern("string", "String")); - containsAttributes(typeUnion2, true, true, true, new NameTypePattern("uint64", "BigInteger")); - - } - - @Test - public void bitAndUnionEnclosingTest() { - - assertNotNull("Parent container object wasn't found.", parentContainer); - containsMethods(parentContainer, new NameTypePattern("getLf", "Lf")); - - GeneratedTransferObject bitLeaf = null; - GeneratedTransferObject unionLeaf = null; - List enclosedTypes = parentContainer.getEnclosedTypes(); - for (GeneratedType genType : enclosedTypes) { - if (genType instanceof GeneratedTransferObject) { - if (genType.getName().equals("BitLeaf")) { - bitLeaf = (GeneratedTransferObject) genType; - } else if (genType.getName().equals("UnionLeaf")) { - unionLeaf = (GeneratedTransferObject) genType; - } - } - } - - assertNotNull("BitLeaf TO wasn't found.", bitLeaf); - assertNotNull("UnionLeaf TO wasn't found.", unionLeaf); - - assertEquals("BitLeaf has incorrect package name.", - "org.opendaylight.yang.gen.v1.urn.bit.union.in.leaf.rev130626.ParentContainer", - bitLeaf.getPackageName()); - assertEquals("UnionLeaf has incorrect package name.", - "org.opendaylight.yang.gen.v1.urn.bit.union.in.leaf.rev130626.ParentContainer", - bitLeaf.getPackageName()); - - List propertiesBitLeaf = bitLeaf.getProperties(); - GeneratedProperty firstBitProperty = null; - GeneratedProperty secondBitProperty = null; - GeneratedProperty thirdBitProperty = null; - - for (GeneratedProperty genProperty : propertiesBitLeaf) { - if (genProperty.getName().equals("firstBit")) { - firstBitProperty = genProperty; - } else if (genProperty.getName().equals("secondBit")) { - secondBitProperty = genProperty; - } else if (genProperty.getName().equals("thirdBit")) { - thirdBitProperty = genProperty; - } - } - - assertNotNull("firstBit property wasn't found", firstBitProperty); - assertNotNull("secondBit property wasn't found", secondBitProperty); - assertNotNull("thirdBit property wasn't found", thirdBitProperty); - - assertEquals("firstBit property has incorrect type", "Boolean", firstBitProperty.getReturnType().getName()); - assertEquals("secondBit property has incorrect type", "Boolean", secondBitProperty.getReturnType().getName()); - assertEquals("thirdBit property has incorrect type", "Boolean", thirdBitProperty.getReturnType().getName()); - - GeneratedProperty uint32Property = null; - GeneratedProperty stringProperty = null; - GeneratedProperty uint8Property = null; - List propertiesUnionLeaf = unionLeaf.getProperties(); - for (GeneratedProperty genProperty : propertiesUnionLeaf) { - if (genProperty.getName().equals("int32")) { - uint32Property = genProperty; - } else if (genProperty.getName().equals("string")) { - stringProperty = genProperty; - } else if (genProperty.getName().equals("uint8")) { - uint8Property = genProperty; - } - } - - assertNotNull("uint32 property wasn't found", uint32Property); - assertNotNull("string property wasn't found", stringProperty); - assertNotNull("uint8 property wasn't found", uint8Property); - - assertEquals("uint32 property has incorrect type", "Integer", uint32Property.getReturnType().getName()); - assertEquals("string property has incorrect type", "String", stringProperty.getReturnType().getName()); - assertEquals("uint8 property has incorrect type", "Short", uint8Property.getReturnType().getName()); - - } - -} diff --git a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/ChoiceCaseGenTypesTest.java b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/ChoiceCaseGenTypesTest.java deleted file mode 100644 index c315d74d9c..0000000000 --- a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/ChoiceCaseGenTypesTest.java +++ /dev/null @@ -1,175 +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.yangtools.sal.binding.generator.impl.stmt.parser.retest; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.opendaylight.yangtools.sal.binding.generator.impl.stmt.parser.retest.SupportTestUtil.containsInterface; -import static org.opendaylight.yangtools.sal.binding.generator.impl.stmt.parser.retest.SupportTestUtil.containsMethods; -import java.io.IOException; -import java.util.List; -import org.junit.Test; -import org.opendaylight.yangtools.sal.binding.generator.api.BindingGenerator; -import org.opendaylight.yangtools.sal.binding.generator.impl.BindingGeneratorImpl; -import org.opendaylight.yangtools.sal.binding.model.api.GeneratedTransferObject; -import org.opendaylight.yangtools.sal.binding.model.api.GeneratedType; -import org.opendaylight.yangtools.sal.binding.model.api.Type; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; -import org.opendaylight.yangtools.yang.parser.spi.source.SourceException; - -public class ChoiceCaseGenTypesTest extends AbstractTypesTest { - - public ChoiceCaseGenTypesTest() { - super(ChoiceCaseGenTypesTest.class.getResource("/choice-case-type-test-models")); - } - - private static GeneratedType checkGeneratedType(final List genTypes, final String genTypeName, - final String packageName, final int occurences) { - GeneratedType searchedGenType = null; - int searchedGenTypeCounter = 0; - for (Type type : genTypes) { - if (type instanceof GeneratedType && !(type instanceof GeneratedTransferObject)) { - GeneratedType genType = (GeneratedType) type; - if (genType.getName().equals(genTypeName) && genType.getPackageName().equals(packageName)) { - searchedGenType = genType; - searchedGenTypeCounter++; - } - } - } - assertNotNull("Generated type " + genTypeName + " wasn't found", searchedGenType); - assertEquals(genTypeName + " generated type has incorrect number of occurences.", occurences, - searchedGenTypeCounter); - return searchedGenType; - - } - - private static GeneratedType checkGeneratedType(final List genTypes, final String genTypeName, - final String packageName) { - return checkGeneratedType(genTypes, genTypeName, packageName, 1); - } - - @Test - public void choiceCaseResolvingTypeTest() throws IOException, SourceException, ReactorException { - final SchemaContext context = RetestUtils.parseYangSources(testModels); - - assertNotNull("context is null", context); - final BindingGenerator bindingGen = new BindingGeneratorImpl(true); - final List genTypes = bindingGen.generateTypes(context); - - assertNotNull("genTypes is null", genTypes); - assertFalse("genTypes is empty", genTypes.isEmpty()); - - // test for file choice-monitoring - String pcgPref = "org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.choice.monitoring.rev130701.netconf.state.datastores.datastore.locks"; - GeneratedType genType = null; - - checkGeneratedType(genTypes, "LockType", pcgPref); // choice - - genType = checkGeneratedType(genTypes, "GlobalLock", pcgPref + ".lock.type"); // case - SupportTestUtil.containsMethods(genType, new NameTypePattern("getGlobalLock", "GlobalLock")); - containsInterface("LockType", genType); - - genType = checkGeneratedType(genTypes, "PartialLock", pcgPref + ".lock.type"); // case - containsMethods(genType, new NameTypePattern("getPartialLock", "List")); - containsInterface("LockType", genType); - - genType = checkGeneratedType(genTypes, "Fingerprint", pcgPref + ".lock.type"); // case - containsMethods(genType, new NameTypePattern("getAlgorithmAndHash", "AlgorithmAndHash")); - containsInterface("LockType", genType); - - genType = checkGeneratedType(genTypes, "AlgorithmAndHash", pcgPref + ".lock.type.fingerprint"); // choice - - genType = checkGeneratedType(genTypes, "Md5", pcgPref + ".lock.type.fingerprint.algorithm.and.hash"); // case - containsMethods(genType, new NameTypePattern("getMd5", "TlsFingerprintType")); - containsInterface("AlgorithmAndHash", genType); - - genType = checkGeneratedType(genTypes, "Sha1", pcgPref + ".lock.type.fingerprint.algorithm.and.hash"); // case - containsMethods(genType, new NameTypePattern("getSha1", "TlsFingerprintType")); - containsInterface("AlgorithmAndHash", genType); - - genType = checkGeneratedType(genTypes, "Sha224", pcgPref + ".lock.type.fingerprint.algorithm.and.hash"); // case - containsMethods(genType, new NameTypePattern("getSha224", "TlsFingerprintType")); - containsInterface("AlgorithmAndHash", genType); - - genType = checkGeneratedType(genTypes, "Sha256", pcgPref + ".lock.type.fingerprint.algorithm.and.hash"); // case - containsMethods(genType, new NameTypePattern("getSha256", "TlsFingerprintType")); - containsInterface("AlgorithmAndHash", genType); - - genType = checkGeneratedType(genTypes, "Sha384", pcgPref + ".lock.type.fingerprint.algorithm.and.hash"); // case - containsMethods(genType, new NameTypePattern("getSha384", "TlsFingerprintType")); - containsInterface("AlgorithmAndHash", genType); - - genType = checkGeneratedType(genTypes, "Sha512", pcgPref + ".lock.type.fingerprint.algorithm.and.hash"); // case - containsMethods(genType, new NameTypePattern("getSha512", "TlsFingerprintType")); - containsInterface("AlgorithmAndHash", genType); - - // test for file augment-monitoring - // augment - // "/nm:netconf-state/nm:datastores/nm:datastore/nm:locks/nm:lock-type" - pcgPref = "org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.augment.monitoring.rev130701"; - genType = null; - - genType = checkGeneratedType(genTypes, "AutonomousLock", pcgPref - + ".netconf.state.datastores.datastore.locks.lock.type"); // choice - containsMethods(genType, new NameTypePattern("getAutonomousDef", "AutonomousDef")); - containsInterface("LockType", genType); - - genType = checkGeneratedType(genTypes, "AnonymousLock", pcgPref - + ".netconf.state.datastores.datastore.locks.lock.type"); // choice - containsMethods(genType, new NameTypePattern("getLockTime", "Long")); - containsInterface("LockType", genType); - - genType = checkGeneratedType(genTypes, "LeafAugCase", pcgPref - + ".netconf.state.datastores.datastore.locks.lock.type"); // choice - containsMethods(genType, new NameTypePattern("getLeafAugCase", "String")); - containsInterface("LockType", genType); - - // augment - // "/nm:netconf-state/nm:datastores/nm:datastore/nm:locks/nm:lock-type/nm:partial-lock" - // { - genType = checkGeneratedType(genTypes, "PartialLock1", pcgPref); // case - containsMethods(genType, new NameTypePattern("getAugCaseByChoice", "AugCaseByChoice")); - containsInterface("Augmentation", genType); - - genType = checkGeneratedType(genTypes, "AugCaseByChoice", pcgPref - + ".netconf.state.datastores.datastore.locks.lock.type.partial.lock"); // choice - - genType = checkGeneratedType(genTypes, "Foo", pcgPref - + ".netconf.state.datastores.datastore.locks.lock.type.partial.lock.aug._case.by.choice"); // case - containsMethods(genType, new NameTypePattern("getFoo", "String")); - containsInterface("AugCaseByChoice", genType); - - genType = checkGeneratedType(genTypes, "Bar", pcgPref - + ".netconf.state.datastores.datastore.locks.lock.type.partial.lock.aug._case.by.choice"); // case - containsMethods(genType, new NameTypePattern("isBar", "Boolean")); - containsInterface("AugCaseByChoice", genType); - - // augment "/nm:netconf-state/nm:datastores/nm:datastore" { - genType = checkGeneratedType(genTypes, "Datastore1", pcgPref); - containsMethods(genType, new NameTypePattern("getStorageFormat", "StorageFormat")); - containsInterface("Augmentation", genType); - - genType = checkGeneratedType(genTypes, "StorageFormat", pcgPref + ".netconf.state.datastores.datastore"); // choice - - genType = checkGeneratedType(genTypes, "UnknownFiles", pcgPref - + ".netconf.state.datastores.datastore.storage.format"); // case - containsMethods(genType, new NameTypePattern("getFiles", "List")); - containsInterface("StorageFormat", genType); - - genType = checkGeneratedType(genTypes, "Xml", pcgPref + ".netconf.state.datastores.datastore.storage.format"); // case - containsMethods(genType, new NameTypePattern("getXmlDef", "XmlDef")); - containsInterface("StorageFormat", genType); - - genType = checkGeneratedType(genTypes, "Yang", pcgPref + ".netconf.state.datastores.datastore.storage.format"); // case - containsMethods(genType, new NameTypePattern("getYangFileName", "String")); - containsInterface("StorageFormat", genType); - - } -} diff --git a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/ControllerTest.java b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/ControllerTest.java deleted file mode 100644 index 370d3567a8..0000000000 --- a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/ControllerTest.java +++ /dev/null @@ -1,37 +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.yangtools.sal.binding.generator.impl.stmt.parser.retest; - -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import org.opendaylight.yangtools.sal.binding.generator.impl.BindingGeneratorImpl; -import java.io.File; -import java.util.List; -import org.junit.Test; -import org.opendaylight.yangtools.sal.binding.generator.api.BindingGenerator; -import org.opendaylight.yangtools.sal.binding.model.api.Type; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; - -public class ControllerTest { - - @Test - public void controllerAugmentationTest() throws Exception { - File cn = new File(getClass().getResource("/controller-models/controller-network.yang").toURI()); - File co = new File(getClass().getResource("/controller-models/controller-openflow.yang").toURI()); - File ietfInetTypes = new File(getClass().getResource("/ietf/ietf-inet-types.yang").toURI()); - - final SchemaContext context = RetestUtils.parseYangSources(cn, co, ietfInetTypes); - assertNotNull("Schema Context is null", context); - - final BindingGenerator bindingGen = new BindingGeneratorImpl(true); - final List genTypes = bindingGen.generateTypes(context); - - assertNotNull(genTypes); - assertTrue(!genTypes.isEmpty()); - } -} diff --git a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/ExtendedTypedefTest.java b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/ExtendedTypedefTest.java deleted file mode 100644 index 745330f327..0000000000 --- a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/ExtendedTypedefTest.java +++ /dev/null @@ -1,134 +0,0 @@ -/* - * 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.yangtools.sal.binding.generator.impl.stmt.parser.retest; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import java.io.File; -import java.util.List; -import org.junit.Test; -import org.opendaylight.yangtools.sal.binding.generator.api.BindingGenerator; -import org.opendaylight.yangtools.sal.binding.generator.impl.BindingGeneratorImpl; -import org.opendaylight.yangtools.sal.binding.model.api.GeneratedProperty; -import org.opendaylight.yangtools.sal.binding.model.api.GeneratedTransferObject; -import org.opendaylight.yangtools.sal.binding.model.api.Type; -import org.opendaylight.yangtools.sal.binding.yang.types.BaseYangTypes; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; - -public class ExtendedTypedefTest { - - @Test - public void constantGenerationTest() throws Exception { - File abstractTopology = new File(getClass().getResource("/typedef-of-typedef/typedef_of_typedef.yang").toURI()); - File ietfInetTypes = new File(getClass().getResource("/ietf/ietf-inet-types.yang").toURI()); - - final SchemaContext context = RetestUtils.parseYangSources(abstractTopology, ietfInetTypes); - assertNotNull("Schema Context is null", context); - - final BindingGenerator bindingGen = new BindingGeneratorImpl(true); - final List genTypes = bindingGen.generateTypes(context); - - GeneratedTransferObject simpleTypedef4 = null; - GeneratedTransferObject extendedTypedefUnion = null; - GeneratedTransferObject unionTypedef = null; - GeneratedTransferObject typedefFromImport = null; - for (final Type type : genTypes) { - if (type instanceof GeneratedTransferObject) { - if (type.getName().equals("SimpleTypedef4")) { - simpleTypedef4 = (GeneratedTransferObject) type; - } else if (type.getName().equals("ExtendedTypedefUnion")) { - extendedTypedefUnion = (GeneratedTransferObject) type; - } else if (type.getName().equals("UnionTypedef")) { - unionTypedef = (GeneratedTransferObject) type; - } else if (type.getName().equals("TypedefFromImport")) { - typedefFromImport = (GeneratedTransferObject) type; - } - } - } - - // typedef-from-import - assertNotNull("TypedefFromImport not found", typedefFromImport); - List properties = typedefFromImport.getProperties(); - assertTrue("Properties of TypedefFromImport should be empty", properties.isEmpty()); - assertEquals("TypedefFromImport should be extended", "Ipv4Address", typedefFromImport.getSuperType().getName()); - - // simple-typedef4 - assertNotNull("SimpleTypedef4 not found", simpleTypedef4); - assertNotNull("ExtendedTypedefUnion not found", extendedTypedefUnion); - assertNotNull("UnionTypedef", unionTypedef); - - properties = simpleTypedef4.getProperties(); - assertTrue("SimpleTypedef4 shouldn't have properties.", properties.isEmpty()); - - GeneratedTransferObject extendTO = simpleTypedef4.getSuperType(); - assertNotNull("SimpleTypedef4 should have extend.", extendTO); - assertEquals("Incorrect extension for SimpleTypedef4.", "SimpleTypedef3", extendTO.getName()); - properties = extendTO.getProperties(); - assertTrue("SimpleTypedef3 shouldn't have properties.", properties.isEmpty()); - - extendTO = extendTO.getSuperType(); - assertNotNull("SimpleTypedef3 should have extend.", extendTO); - assertEquals("Incorrect extension for SimpleTypedef3.", "SimpleTypedef2", extendTO.getName()); - properties = extendTO.getProperties(); - assertTrue("SimpleTypedef2 shouldn't have properties.", properties.isEmpty()); - - extendTO = extendTO.getSuperType(); - assertNotNull("SimpleTypedef2 should have extend.", extendTO); - assertEquals("SimpleTypedef2 should be extended with SimpleTypedef1.", "SimpleTypedef1", extendTO.getName()); - properties = extendTO.getProperties(); - assertEquals("Incorrect number of properties in class SimpleTypedef1.", 1, properties.size()); - - assertEquals("Incorrect property's name", "value", properties.get(0).getName()); - assertEquals("Property's incorrect type", BaseYangTypes.UINT8_TYPE, properties.get(0).getReturnType()); - - extendTO = extendTO.getSuperType(); - assertNull("SimpleTypedef1 shouldn't have extend.", extendTO); - - // extended-typedef-union - assertNotNull("ExtendedTypedefUnion object not found", extendedTypedefUnion); - properties = extendedTypedefUnion.getProperties(); - assertEquals("ExtendedTypedefUnion shouldn't have any property", 0, properties.size()); - - extendTO = extendedTypedefUnion.getSuperType(); - assertEquals("Incorrect extension fo ExtendedTypedefUnion.", "UnionTypedef", extendTO.getName()); - assertNull("UnionTypedef shouldn't be extended", extendTO.getSuperType()); - assertEquals("Incorrect number of properties for UnionTypedef.", 5, extendTO.getProperties().size()); - - GeneratedProperty simpleTypedef4Property = null; - GeneratedProperty simpleTypedef1Property = null; - GeneratedProperty byteTypeProperty = null; - GeneratedProperty typedefEnumFruitProperty = null; - for (GeneratedProperty genProperty : extendTO.getProperties()) { - if (genProperty.getName().equals("simpleTypedef1")) { - simpleTypedef1Property = genProperty; - } else if (genProperty.getName().equals("simpleTypedef4")) { - simpleTypedef4Property = genProperty; - } else if (genProperty.getName().equals("byteType")) { - byteTypeProperty = genProperty; - } else if (genProperty.getName().equals("typedefEnumFruit")) { - typedefEnumFruitProperty = genProperty; - } - } - - assertNotNull("simpleTypedef4 property not found in UnionTypedef", simpleTypedef4Property); - assertNotNull("simpleTypedef1 property not found in UnionTypedef", simpleTypedef1Property); - assertNotNull("byteType property not found in UnionTypedef", byteTypeProperty); - assertNotNull("typedefEnumFruit property not found in UnionTypedef", typedefEnumFruitProperty); - - assertEquals("Incorrect type for property simpleTypedef4.", "SimpleTypedef4", simpleTypedef4Property - .getReturnType().getName()); - assertEquals("Incorrect type for property simpleTypedef1.", "SimpleTypedef1", simpleTypedef1Property - .getReturnType().getName()); - assertEquals("Incorrect type for property byteType.", "ByteType", byteTypeProperty.getReturnType().getName()); - assertEquals("Incorrect type for property typedefEnumFruit.", "TypedefEnumFruit", typedefEnumFruitProperty - .getReturnType().getName()); - } - -} diff --git a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/GenEnumResolvingTest.java b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/GenEnumResolvingTest.java deleted file mode 100644 index 666f063bf8..0000000000 --- a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/GenEnumResolvingTest.java +++ /dev/null @@ -1,164 +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.yangtools.sal.binding.generator.impl.stmt.parser.retest; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; -import org.opendaylight.yangtools.yang.parser.spi.source.SourceException; -import org.opendaylight.yangtools.sal.binding.generator.impl.BindingGeneratorImpl; -import java.io.File; -import java.io.IOException; -import java.net.URISyntaxException; -import java.util.List; -import org.junit.Test; -import org.opendaylight.yangtools.sal.binding.generator.api.BindingGenerator; -import org.opendaylight.yangtools.sal.binding.model.api.Enumeration; -import org.opendaylight.yangtools.sal.binding.model.api.GeneratedType; -import org.opendaylight.yangtools.sal.binding.model.api.MethodSignature; -import org.opendaylight.yangtools.sal.binding.model.api.Type; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; - -public class GenEnumResolvingTest { - - @Test - public void testLeafEnumResolving() throws URISyntaxException, IOException, SourceException, ReactorException { - File ietfInterfaces = new File(getClass().getResource("/enum-test-models/ietf-interfaces@2012-11-15.yang") - .toURI()); - File ianaIfTypeModel = new File(getClass().getResource("/ietf/iana-if-type.yang").toURI()); - - final SchemaContext context = RetestUtils.parseYangSources(ietfInterfaces, ianaIfTypeModel); - assertTrue(context != null); - - final BindingGenerator bindingGen = new BindingGeneratorImpl(true); - final List genTypes = bindingGen.generateTypes(context); - assertTrue(genTypes != null); - - assertEquals("Expected count of all Generated Types", 6, genTypes.size()); - - GeneratedType genInterface = null; - for (final Type type : genTypes) { - if (type instanceof GeneratedType) { - if (type.getName().equals("Interface")) { - genInterface = (GeneratedType) type; - } - } - } - assertNotNull("Generated Type Interface is not present in list of Generated Types", genInterface); - - Enumeration linkUpDownTrapEnable = null; - Enumeration operStatus = null; - final List enums = genInterface.getEnumerations(); - assertNotNull("Generated Type Interface cannot contain NULL reference to Enumeration types!", enums); - assertEquals("Generated Type Interface MUST contain 2 Enumeration Types", 2, enums.size()); - for (final Enumeration e : enums) { - if (e.getName().equals("LinkUpDownTrapEnable")) { - linkUpDownTrapEnable = e; - } else if (e.getName().equals("OperStatus")) { - operStatus = e; - } - } - - assertNotNull("Expected Enum LinkUpDownTrapEnable, but was NULL!", linkUpDownTrapEnable); - assertNotNull("Expected Enum OperStatus, but was NULL!", operStatus); - - assertNotNull("Enum LinkUpDownTrapEnable MUST contain Values definition not NULL reference!", - linkUpDownTrapEnable.getValues()); - assertNotNull("Enum OperStatus MUST contain Values definition not NULL reference!", operStatus.getValues()); - assertEquals("Enum LinkUpDownTrapEnable MUST contain 2 values!", 2, linkUpDownTrapEnable.getValues().size()); - assertEquals("Enum OperStatus MUST contain 7 values!", 7, operStatus.getValues().size()); - - final List methods = genInterface.getMethodDefinitions(); - - assertNotNull("Generated Interface cannot contain NULL reference for Method Signature Definitions!", methods); - - assertEquals("Expected count of method signature definitions is 15", 15, methods.size()); - Enumeration ianaIfType = null; - for (final MethodSignature method : methods) { - if (method.getName().equals("getType")) { - if (method.getReturnType() instanceof Enumeration) { - ianaIfType = (Enumeration) method.getReturnType(); - } - } - } - - assertNotNull("Method getType MUST return Enumeration Type not NULL reference!", ianaIfType); - assertEquals("Enumeration getType MUST contain 272 values!", 272, ianaIfType.getValues().size()); - } - - @Test - public void testTypedefEnumResolving() throws URISyntaxException, IOException, SourceException, ReactorException { - File ianaIfType = new File(getClass().getResource("/ietf/iana-if-type.yang").toURI()); - final SchemaContext context = RetestUtils.parseYangSources(ianaIfType); - assertTrue(context != null); - final BindingGenerator bindingGen = new BindingGeneratorImpl(true); - final List genTypes = bindingGen.generateTypes(context); - assertTrue(genTypes != null); - assertEquals(1, genTypes.size()); - - final Type type = genTypes.get(0); - assertTrue(type instanceof Enumeration); - - final Enumeration enumer = (Enumeration) type; - assertEquals("Enumeration type MUST contain 272 values!", 272, enumer.getValues().size()); - } - - @Test - public void testLeafrefEnumResolving() throws URISyntaxException, IOException, SourceException, ReactorException { - File abstractTopology = new File(getClass().getResource("/enum-test-models/abstract-topology@2013-02-08.yang") - .toURI()); - File ietfInterfaces = new File(getClass().getResource("/enum-test-models/ietf-interfaces@2012-11-15.yang") - .toURI()); - File ianaIfType = new File(getClass().getResource("/ietf/iana-if-type.yang").toURI()); - - final SchemaContext context = RetestUtils.parseYangSources(abstractTopology, ietfInterfaces, - ianaIfType); - assertNotNull(context); - final BindingGenerator bindingGen = new BindingGeneratorImpl(true); - final List genTypes = bindingGen.generateTypes(context); - assertNotNull(genTypes); - assertTrue(!genTypes.isEmpty()); - - GeneratedType genInterface = null; - for (final Type type : genTypes) { - if (type instanceof GeneratedType) { - if (type.getPackageName().equals( - "org.opendaylight.yang.gen.v1.urn.model._abstract.topology.rev130208.topology.interfaces") - && type.getName().equals("Interface")) { - genInterface = (GeneratedType) type; - } - } - } - assertNotNull("Generated Type Interface is not present in list of Generated Types", genInterface); - - Type linkUpDownTrapEnable = null; - Type operStatus = null; - final List methods = genInterface.getMethodDefinitions(); - assertNotNull("Generated Type Interface cannot contain NULL reference to Enumeration types!", methods); - assertEquals("Generated Type Interface MUST contain 5 Methods ", 5, methods.size()); - for (final MethodSignature method : methods) { - if (method.getName().equals("getLinkUpDownTrapEnable")) { - linkUpDownTrapEnable = method.getReturnType(); - } else if (method.getName().equals("getOperStatus")) { - operStatus = method.getReturnType(); - } - } - - assertNotNull("Expected Referenced Enum LinkUpDownTrapEnable, but was NULL!", linkUpDownTrapEnable); - assertTrue("Expected LinkUpDownTrapEnable of type Enumeration", linkUpDownTrapEnable instanceof Enumeration); - assertEquals(linkUpDownTrapEnable.getPackageName(), - "org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev121115.interfaces.Interface"); - - assertNotNull("Expected Referenced Enum OperStatus, but was NULL!", operStatus); - assertTrue("Expected OperStatus of type Enumeration", operStatus instanceof Enumeration); - assertEquals(operStatus.getPackageName(), - "org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev121115.interfaces.Interface"); - } - -} diff --git a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/GenTypesSubSetTest.java b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/GenTypesSubSetTest.java deleted file mode 100644 index 966a15df7f..0000000000 --- a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/GenTypesSubSetTest.java +++ /dev/null @@ -1,91 +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.yangtools.sal.binding.generator.impl.stmt.parser.retest; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; - -import org.opendaylight.yangtools.sal.binding.generator.impl.BindingGeneratorImpl; - -import java.io.File; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import org.junit.Test; -import org.opendaylight.yangtools.sal.binding.generator.api.BindingGenerator; -import org.opendaylight.yangtools.sal.binding.model.api.Type; -import org.opendaylight.yangtools.yang.model.api.Module; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; - -public class GenTypesSubSetTest { - - @Test - public void genTypesFromSubsetOfTwoModulesTest() throws Exception { - File abstractTopology = new File(getClass().getResource( - "/leafref-test-models/abstract-topology@2013-02-08.yang").toURI()); - File ietfInterfaces = new File(getClass().getResource("/ietf/ietf-interfaces.yang").toURI()); - File ietfInetTypes = new File(getClass().getResource("/ietf/ietf-inet-types.yang").toURI()); - File ietfYangTypes = new File(getClass().getResource("/ietf/ietf-yang-types.yang").toURI()); - - final SchemaContext context = RetestUtils.parseYangSources(abstractTopology, ietfInterfaces, - ietfInetTypes, ietfYangTypes); - Set modules = context.getModules(); - - final Set toGenModules = new HashSet<>(); - for (final Module module : modules) { - if (module.getName().equals("abstract-topology")) { - toGenModules.add(module); - } else if (module.getName().equals("ietf-interfaces")) { - toGenModules.add(module); - } - } - - assertEquals("Set of to Generate Modules must contain 2 modules", 2, toGenModules.size()); - assertNotNull("Schema Context is null", context); - final BindingGenerator bindingGen = new BindingGeneratorImpl(true); - final List genTypes = bindingGen.generateTypes(context, toGenModules); - assertNotNull("genTypes is null", genTypes); - assertFalse("genTypes is empty", genTypes.isEmpty()); - assertEquals("Expected Generated Types from provided sub set of " + "modules should be 23!", 23, - genTypes.size()); - } - - @Test - public void genTypesFromSubsetOfThreeModulesTest() throws Exception { - File abstractTopology = new File(getClass().getResource( - "/leafref-test-models/abstract-topology@2013-02-08.yang").toURI()); - File ietfInterfaces = new File(getClass().getResource("/ietf/ietf-interfaces.yang").toURI()); - File ietfInetTypes = new File(getClass().getResource("/ietf/ietf-inet-types.yang").toURI()); - File ietfYangTypes = new File(getClass().getResource("/ietf/ietf-yang-types.yang").toURI()); - File ianaIfType = new File(getClass().getResource("/ietf/iana-if-type.yang").toURI()); - - final SchemaContext context = RetestUtils.parseYangSources(abstractTopology, ietfInterfaces, - ietfInetTypes, ietfYangTypes, ianaIfType); - assertNotNull("Schema Context is null", context); - final Set modules = context.getModules(); - - final Set toGenModules = new HashSet<>(); - for (final Module module : modules) { - if (module.getName().equals("abstract-topology")) { - toGenModules.add(module); - } else if (module.getName().equals("ietf-interfaces")) { - toGenModules.add(module); - } else if (module.getName().equals("iana-if-type")) { - toGenModules.add(module); - } - } - assertEquals("Set of to Generate Modules must contain 3 modules", 3, toGenModules.size()); - - final BindingGenerator bindingGen = new BindingGeneratorImpl(true); - final List genTypes = bindingGen.generateTypes(context, toGenModules); - assertNotNull("genTypes is null", genTypes); - assertFalse("genTypes is empty", genTypes.isEmpty()); - assertEquals("Expected Generated Types", 24, genTypes.size()); - } -} diff --git a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/GenerateInnerClassForBitsAndUnionInLeavesTest.java b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/GenerateInnerClassForBitsAndUnionInLeavesTest.java deleted file mode 100644 index 9ba0696187..0000000000 --- a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/GenerateInnerClassForBitsAndUnionInLeavesTest.java +++ /dev/null @@ -1,143 +0,0 @@ -/* - * 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.yangtools.sal.binding.generator.impl.stmt.parser.retest; - -import static org.junit.Assert.assertTrue; - -import org.opendaylight.yangtools.sal.binding.generator.impl.BindingGeneratorImpl; - -import java.io.File; -import java.net.URI; -import java.util.List; -import org.junit.Test; -import org.opendaylight.yangtools.sal.binding.generator.api.BindingGenerator; -import org.opendaylight.yangtools.sal.binding.model.api.GeneratedProperty; -import org.opendaylight.yangtools.sal.binding.model.api.GeneratedTransferObject; -import org.opendaylight.yangtools.sal.binding.model.api.GeneratedType; -import org.opendaylight.yangtools.sal.binding.model.api.Type; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; - -public class GenerateInnerClassForBitsAndUnionInLeavesTest { - - @Test - public void testInnerClassCreationForBitsAndUnionsInLeafes() throws Exception { - final URI yangTypesPath = getClass().getResource("/bit_and_union_in_leaf.yang").toURI(); - - final SchemaContext context = RetestUtils.parseYangSources(new File(yangTypesPath)); - assertTrue(context != null); - - final BindingGenerator bindingGen = new BindingGeneratorImpl(true); - final List genTypes = bindingGen.generateTypes(context); - assertTrue(genTypes != null); - - boolean parentContainerFound = false; - boolean bitLeafTOFound = false; - boolean unionLeafTOFound = false; - - boolean firstBitPropertyFound = false; - boolean secondBitPropertyFound = false; - boolean thirdBitPropertyFound = false; - - boolean firstBitPropertyTypeOK = false; - boolean secondBitPropertyTypeOK = false; - boolean thirdBitPropertyTypeOK = false; - - boolean int32UnionPropertyFound = false; - boolean int32UnionPropertyTypeOK = false; - boolean stringUnionPropertyFound = false; - boolean stringUnionPropertyTypeOK = false; - boolean uint8UnionPropertyFound = false; - boolean uint8UnionPropertyTypeOK = false; - - for (Type type : genTypes) { - if (type instanceof GeneratedType && !(type instanceof GeneratedTransferObject)) { - if (type.getName().equals("ParentContainer")) { - parentContainerFound = true; - GeneratedType parentContainer = (GeneratedType) type; - List enclosedTypes = parentContainer.getEnclosedTypes(); - for (GeneratedType genType : enclosedTypes) { - if (genType instanceof GeneratedTransferObject) { - if (genType.getName().equals("BitLeaf")) { - bitLeafTOFound = true; - GeneratedTransferObject bitLeafTO = (GeneratedTransferObject) genType; - - List bitLeafProperties = bitLeafTO.getProperties(); - for (GeneratedProperty bitLeafProperty : bitLeafProperties) { - String bitLeafPropertyType = bitLeafProperty.getReturnType().getName(); - if (bitLeafProperty.getName().equals("firstBit")) { - firstBitPropertyFound = true; - if (bitLeafPropertyType.equals("Boolean")) { - firstBitPropertyTypeOK = true; - } - } else if (bitLeafProperty.getName().equals("secondBit")) { - secondBitPropertyFound = true; - if (bitLeafPropertyType.equals("Boolean")) { - secondBitPropertyTypeOK = true; - } - } else if (bitLeafProperty.getName().equals("thirdBit")) { - thirdBitPropertyFound = true; - if (bitLeafPropertyType.equals("Boolean")) { - thirdBitPropertyTypeOK = true; - } - } - - } - - } else if (genType.getName().equals("UnionLeaf")) { - unionLeafTOFound = true; - GeneratedTransferObject unionLeafTO = (GeneratedTransferObject) genType; - - List unionLeafProperties = unionLeafTO.getProperties(); - for (GeneratedProperty unionLeafProperty : unionLeafProperties) { - String unionLeafPropertyType = unionLeafProperty.getReturnType().getName(); - if (unionLeafProperty.getName().equals("int32")) { - int32UnionPropertyFound = true; - if (unionLeafPropertyType.equals("Integer")) { - int32UnionPropertyTypeOK = true; - } - } else if (unionLeafProperty.getName().equals("string")) { - stringUnionPropertyFound = true; - if (unionLeafPropertyType.equals("String")) { - stringUnionPropertyTypeOK = true; - } - } else if (unionLeafProperty.getName().equals("uint8")) { - uint8UnionPropertyFound = true; - if (unionLeafPropertyType.equals("Short")) { - uint8UnionPropertyTypeOK = true; - } - } - - } - - } - } - } - } - } - } - assertTrue(parentContainerFound); - - assertTrue(bitLeafTOFound); - assertTrue(firstBitPropertyFound); - assertTrue(secondBitPropertyFound); - assertTrue(thirdBitPropertyFound); - - assertTrue(firstBitPropertyTypeOK); - assertTrue(secondBitPropertyTypeOK); - assertTrue(thirdBitPropertyTypeOK); - - assertTrue(unionLeafTOFound); - assertTrue(int32UnionPropertyFound); - assertTrue(int32UnionPropertyTypeOK); - assertTrue(stringUnionPropertyFound); - assertTrue(stringUnionPropertyTypeOK); - assertTrue(uint8UnionPropertyFound); - assertTrue(uint8UnionPropertyTypeOK); - - } -} diff --git a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/GeneratedTypesBitsTest.java b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/GeneratedTypesBitsTest.java deleted file mode 100644 index 14beb94c26..0000000000 --- a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/GeneratedTypesBitsTest.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * 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.yangtools.sal.binding.generator.impl.stmt.parser.retest; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import java.io.File; -import java.net.URI; -import java.util.List; -import org.junit.Test; -import org.opendaylight.yangtools.sal.binding.generator.api.BindingGenerator; -import org.opendaylight.yangtools.sal.binding.generator.impl.BindingGeneratorImpl; -import org.opendaylight.yangtools.sal.binding.model.api.GeneratedProperty; -import org.opendaylight.yangtools.sal.binding.model.api.GeneratedTransferObject; -import org.opendaylight.yangtools.sal.binding.model.api.GeneratedType; -import org.opendaylight.yangtools.sal.binding.model.api.MethodSignature; -import org.opendaylight.yangtools.sal.binding.model.api.MethodSignature.Parameter; -import org.opendaylight.yangtools.sal.binding.model.api.Type; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; - -public class GeneratedTypesBitsTest { - - - @Test - public void testGeneretedTypesBitsTest() throws Exception { - final URI yangTypesPath = getClass().getResource("/simple-bits-demo.yang").toURI(); - - final SchemaContext context = RetestUtils.parseYangSources(new File(yangTypesPath)); - assertTrue(context != null); - - final BindingGenerator bindingGen = new BindingGeneratorImpl(true); - final List genTypes = bindingGen.generateTypes(context); - assertTrue(genTypes != null); - - List methodSignaturesList = null; - - boolean leafParentFound = false; - - boolean byteTypeFound = false; - int classPropertiesNumb = 0; - int toStringPropertiesNum = 0; - int equalPropertiesNum = 0; - int hashPropertiesNum = 0; - - String nameReturnParamType = ""; - boolean getByteLeafMethodFound = false; - boolean setByteLeafMethodFound = false; - int setByteLeafMethodParamNum = 0; - - for (final Type type : genTypes) { - if (type instanceof GeneratedTransferObject) { // searching for - // ByteType - final GeneratedTransferObject genTO = (GeneratedTransferObject) type; - if (genTO.getName().equals("ByteType")) { - byteTypeFound = true; - List genProperties = genTO.getProperties(); - classPropertiesNumb = genProperties.size(); - - genProperties = null; - genProperties = genTO.getToStringIdentifiers(); - toStringPropertiesNum = genProperties.size(); - - genProperties = null; - genProperties = genTO.getEqualsIdentifiers(); - equalPropertiesNum = genProperties.size(); - - genProperties = null; - genProperties = genTO.getHashCodeIdentifiers(); - hashPropertiesNum = genProperties.size(); - - } - } else if (type instanceof GeneratedType) { // searching for - // interface - // LeafParameterContainer - final GeneratedType genType = (GeneratedType) type; - if (genType.getName().equals("LeafParentContainer")) { - leafParentFound = true; - // check of methods - methodSignaturesList = genType.getMethodDefinitions(); - if (methodSignaturesList != null) { - for (MethodSignature methodSignature : methodSignaturesList) { // loop - // through - // all - // methods - if (methodSignature.getName().equals("getByteLeaf")) { - getByteLeafMethodFound = true; - - nameReturnParamType = methodSignature.getReturnType().getName(); - } else if (methodSignature.getName().equals("setByteLeaf")) { - setByteLeafMethodFound = true; - - List parameters = methodSignature.getParameters(); - setByteLeafMethodParamNum = parameters.size(); - } - - } - } - } - } - - } - - assertTrue(byteTypeFound); - - assertEquals(8, classPropertiesNumb); - - assertEquals(8, toStringPropertiesNum); - assertEquals(8, equalPropertiesNum); - assertEquals(8, hashPropertiesNum); - assertTrue(leafParentFound); - - assertNotNull(methodSignaturesList); - - assertTrue(getByteLeafMethodFound); - assertEquals("ByteType", nameReturnParamType); - - assertFalse(setByteLeafMethodFound); - assertEquals(0, setByteLeafMethodParamNum); - } - -} diff --git a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/GeneratedTypesLeafrefTest.java b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/GeneratedTypesLeafrefTest.java deleted file mode 100644 index 27201af5aa..0000000000 --- a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/GeneratedTypesLeafrefTest.java +++ /dev/null @@ -1,238 +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.yangtools.sal.binding.generator.impl.stmt.parser.retest; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import java.io.File; -import java.io.IOException; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.List; -import org.junit.Test; -import org.opendaylight.yangtools.sal.binding.generator.api.BindingGenerator; -import org.opendaylight.yangtools.sal.binding.generator.impl.BindingGeneratorImpl; -import org.opendaylight.yangtools.sal.binding.model.api.GeneratedProperty; -import org.opendaylight.yangtools.sal.binding.model.api.GeneratedTransferObject; -import org.opendaylight.yangtools.sal.binding.model.api.GeneratedType; -import org.opendaylight.yangtools.sal.binding.model.api.MethodSignature; -import org.opendaylight.yangtools.sal.binding.model.api.Type; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; -import org.opendaylight.yangtools.yang.parser.spi.source.SourceException; - -public class GeneratedTypesLeafrefTest { - - @Test - public void testLeafrefResolving() throws URISyntaxException, IOException, SourceException, ReactorException { - File abstractTopology = new File(getClass().getResource( - "/leafref-test-models/abstract-topology@2013-02-08.yang").toURI()); - File ietfInterfaces = new File(getClass().getResource("/ietf/ietf-interfaces.yang").toURI()); - File ietfInetTypes = new File(getClass().getResource("/ietf/ietf-inet-types.yang").toURI()); - File ietfYangTypes = new File(getClass().getResource("/ietf/ietf-yang-types.yang").toURI()); - - final SchemaContext context = RetestUtils.parseYangSources(abstractTopology, ietfInterfaces, - ietfInetTypes, ietfYangTypes); - assertNotNull(context); - assertEquals(4, context.getModules().size()); - - final BindingGenerator bindingGen = new BindingGeneratorImpl(true); - final List genTypes = bindingGen.generateTypes(context); - - assertEquals(54, genTypes.size()); - assertNotNull(genTypes); - - GeneratedTransferObject gtIfcKey = null; - GeneratedType gtIfc = null; - GeneratedType gtNetworkLink = null; - GeneratedType gtSource = null; - GeneratedType gtDest = null; - GeneratedType gtTunnel = null; - GeneratedTransferObject gtTunnelKey = null; - GeneratedType gtTopology = null; - for (final Type type : genTypes) { - String name = type.getName(); - if ("InterfaceKey".equals(name)) { - gtIfcKey = (GeneratedTransferObject) type; - } else if ("Interface".equals(name)) { - gtIfc = (GeneratedType) type; - } else if ("NetworkLink".equals(name)) { - gtNetworkLink = (GeneratedType) type; - } else if ("SourceNode".equals(name)) { - gtSource = (GeneratedType) type; - } else if ("DestinationNode".equals(name)) { - gtDest = (GeneratedType) type; - } else if ("Tunnel".equals(name)) { - gtTunnel = (GeneratedType) type; - } else if ("TunnelKey".equals(name)) { - gtTunnelKey = (GeneratedTransferObject) type; - } else if ("Topology".equals(name)) { - gtTopology = (GeneratedType) type; - } - } - - assertNotNull(gtIfcKey); - assertNotNull(gtIfc); - assertNotNull(gtNetworkLink); - assertNotNull(gtSource); - assertNotNull(gtDest); - assertNotNull(gtTunnel); - assertNotNull(gtTunnelKey); - assertNotNull(gtTopology); - - // Topology - final List gtTopoMethods = gtTopology.getMethodDefinitions(); - assertNotNull(gtTopoMethods); - MethodSignature condLeafref = null; - for (final MethodSignature method : gtTopoMethods) { - if (method.getName().equals("getCondLeafref")) { - condLeafref = method; - } - } - assertNotNull(condLeafref); - Type condLeafRT = condLeafref.getReturnType(); - assertNotNull(condLeafRT); - assertEquals("java.lang.Object", condLeafRT.getFullyQualifiedName()); - - // InterfaceId - final List gtIfcKeyProps = gtIfcKey.getProperties(); - assertNotNull(gtIfcKeyProps); - GeneratedProperty ifcIdProp = null; - for (final GeneratedProperty property : gtIfcKeyProps) { - if (property.getName().equals("interfaceId")) { - ifcIdProp = property; - } - } - assertNotNull(ifcIdProp); - Type ifcIdPropType = ifcIdProp.getReturnType(); - assertNotNull(ifcIdPropType); - assertEquals("java.lang.String", ifcIdPropType.getFullyQualifiedName()); - - // Interface - final List gtIfcMethods = gtIfc.getMethodDefinitions(); - assertNotNull(gtIfcMethods); - MethodSignature getIfcKey = null; - MethodSignature getHigherLayerIf = null; - for (final MethodSignature method : gtIfcMethods) { - if (method.getName().equals("getKey")) { - getIfcKey = method; - } else if (method.getName().equals("getHigherLayerIf")) { - getHigherLayerIf = method; - } - } - assertNotNull(getIfcKey); - Type getIfcKeyType = getIfcKey.getReturnType(); - assertNotNull(getIfcKeyType); - assertNotSame("java.lang.Void", getIfcKeyType); - assertEquals("InterfaceKey", getIfcKeyType.getName()); - - assertNotNull(getHigherLayerIf); - Type getHigherLayerIfType = getHigherLayerIf.getReturnType(); - assertNotNull(getHigherLayerIfType); - assertNotSame("java.lang.Void", getHigherLayerIfType); - assertEquals("List", getHigherLayerIfType.getName()); - - // NetworkLink - final List gtNetworkLinkMethods = gtNetworkLink.getMethodDefinitions(); - assertNotNull(gtNetworkLinkMethods); - MethodSignature getIfc = null; - for (MethodSignature method : gtNetworkLinkMethods) { - if (method.getName().equals("getInterface")) { - getIfc = method; - } - } - assertNotNull(getIfc); - Type getIfcType = getIfc.getReturnType(); - assertNotNull(getIfcType); - assertNotSame("java.lang.Void", getIfcType); - assertEquals("String", getIfcType.getName()); - - // SourceNode - final List gtSourceMethods = gtSource.getMethodDefinitions(); - assertNotNull(gtSourceMethods); - MethodSignature getIdSource = null; - for (MethodSignature method : gtSourceMethods) { - if (method.getName().equals("getId")) { - getIdSource = method; - } - } - assertNotNull(getIdSource); - Type getIdType = getIdSource.getReturnType(); - assertNotNull(getIdType); - assertNotSame("java.lang.Void", getIdType); - assertEquals("Uri", getIdType.getName()); - - // DestinationNode - final List gtDestMethods = gtDest.getMethodDefinitions(); - assertNotNull(gtDestMethods); - MethodSignature getIdDest = null; - for (MethodSignature method : gtDestMethods) { - if (method.getName().equals("getId")) { - getIdDest = method; - } - } - assertNotNull(getIdDest); - Type getIdDestType = getIdDest.getReturnType(); - assertNotNull(getIdDestType); - assertNotSame("java.lang.Void", getIdDestType); - assertEquals("Uri", getIdDestType.getName()); - - // Tunnel - final List gtTunnelMethods = gtTunnel.getMethodDefinitions(); - assertNotNull(gtTunnelMethods); - MethodSignature getTunnelKey = null; - for (MethodSignature method : gtTunnelMethods) { - if (method.getName().equals("getKey")) { - getTunnelKey = method; - } - } - assertNotNull(getTunnelKey); - Type getTunnelKeyType = getTunnelKey.getReturnType(); - assertNotNull(getTunnelKeyType); - assertNotSame("java.lang.Void", getTunnelKeyType); - assertEquals("TunnelKey", getTunnelKeyType.getName()); - - // TunnelKey - final List gtTunnelKeyProps = gtTunnelKey.getProperties(); - assertNotNull(gtTunnelKeyProps); - GeneratedProperty tunnelId = null; - for (final GeneratedProperty property : gtTunnelKeyProps) { - if (property.getName().equals("tunnelId")) { - tunnelId = property; - } - } - assertNotNull(tunnelId); - Type tunnelIdType = tunnelId.getReturnType(); - assertNotNull(tunnelIdType); - assertNotSame("java.lang.Void", tunnelIdType); - assertEquals("Uri", tunnelIdType.getName()); - } - - @Test - public void testLeafrefInvalidPathResolving() throws URISyntaxException, IOException, SourceException, ReactorException { - final URI resource = getClass().getResource("/leafref-test-invalid-model/foo.yang").toURI(); - assertNotNull(resource); - - final SchemaContext context = RetestUtils.parseYangSources(new File(resource)); - assertNotNull(context); - assertEquals(1, context.getModules().size()); - - final BindingGenerator bindingGen = new BindingGeneratorImpl(true); - try { - bindingGen.generateTypes(context); - fail("Expected IllegalArgumentException caused by invalid leafref path"); - } catch (IllegalArgumentException e) { - String expected = "Failed to find leafref target"; - assertTrue(e.getMessage().contains(expected)); - } - } -} \ No newline at end of file diff --git a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/GeneratedTypesStringTest.java b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/GeneratedTypesStringTest.java deleted file mode 100644 index 8277ba540d..0000000000 --- a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/GeneratedTypesStringTest.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * 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.yangtools.sal.binding.generator.impl.stmt.parser.retest; - -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; -import org.opendaylight.yangtools.yang.parser.spi.source.SourceException; - -import org.opendaylight.yangtools.sal.binding.generator.impl.BindingGeneratorImpl; -import java.io.File; -import java.io.IOException; -import java.net.URISyntaxException; -import java.util.ArrayList; -import java.util.List; -import org.junit.BeforeClass; -import org.junit.Test; -import org.opendaylight.yangtools.sal.binding.generator.api.BindingGenerator; -import org.opendaylight.yangtools.sal.binding.model.api.Constant; -import org.opendaylight.yangtools.sal.binding.model.api.GeneratedTransferObject; -import org.opendaylight.yangtools.sal.binding.model.api.ParameterizedType; -import org.opendaylight.yangtools.sal.binding.model.api.Type; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; - -public class GeneratedTypesStringTest { - - private final static List testModels = new ArrayList(); - - @BeforeClass - public static void loadTestResources() throws URISyntaxException { - final File listModelFile = new File(GeneratedTypesStringTest.class.getResource("/simple-string-demo.yang") - .toURI()); - testModels.add(listModelFile); - } - - @Test - public void constantGenerationTest() throws IOException, SourceException, ReactorException { - final SchemaContext context = RetestUtils.parseYangSources(testModels); - - assertNotNull(context); - final BindingGenerator bindingGen = new BindingGeneratorImpl(true); - final List genTypes = bindingGen.generateTypes(context); - - boolean typedefStringFound = false; - boolean constantRegExListFound = false; - boolean constantRegExListTypeGeneric = false; - boolean constantRegExListTypeContainer = false; - boolean noStringInReqExListFound = false; - boolean constantRegExListValueOK = false; - boolean constantRegExListTypeOneGeneric = false; - for (final Type type : genTypes) { - if (type instanceof GeneratedTransferObject) { - final GeneratedTransferObject genTO = (GeneratedTransferObject) type; - - if (genTO.getName().equals("TypedefString")) { - typedefStringFound = true; - - List constants = genTO.getConstantDefinitions(); - for (Constant con : constants) { - if (con.getName().equals("PATTERN_CONSTANTS")) { - constantRegExListFound = true; - } else { - break; - } - ParameterizedType pType; - if (con.getType() instanceof ParameterizedType) { - pType = (ParameterizedType) con.getType(); - } else { - break; - } - - Type[] types; - if (pType.getName().equals("List")) { - constantRegExListTypeContainer = true; - types = pType.getActualTypeArguments(); - } else { - break; - } - - if (types.length == 1) { - constantRegExListTypeOneGeneric = true; - } else { - break; - } - - if (types[0].getName().equals("String")) { - constantRegExListTypeGeneric = true; - } else { - break; - } - - if (con.getValue() instanceof List) { - constantRegExListValueOK = true; - } else { - break; - } - - for (Object obj : (List) con.getValue()) { - if (!(obj instanceof String)) { - noStringInReqExListFound = true; - break; - } - } - - } - } - } - - } - - assertTrue("Typedef >>TypedefString<< wasn't found", typedefStringFound); - assertTrue("Constant PATTERN_CONSTANTS is missing in TO", constantRegExListFound); - assertTrue("Constant PATTERN_CONSTANTS doesn't have correct container type", constantRegExListTypeContainer); - assertTrue("Constant PATTERN_CONSTANTS has more than one generic type", constantRegExListTypeOneGeneric); - assertTrue("Constant PATTERN_CONSTANTS doesn't have correct generic type", constantRegExListTypeGeneric); - assertTrue("Constant PATTERN_CONSTANTS doesn't contain List object", constantRegExListValueOK); - assertTrue("In list found other type than String", !noStringInReqExListFound); - - } - -} diff --git a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/GeneratedTypesTest.java b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/GeneratedTypesTest.java deleted file mode 100644 index 31168b8b2f..0000000000 --- a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/GeneratedTypesTest.java +++ /dev/null @@ -1,414 +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.yangtools.sal.binding.generator.impl.stmt.parser.retest; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; -import org.opendaylight.yangtools.yang.parser.spi.source.SourceException; -import org.opendaylight.yangtools.sal.binding.generator.impl.BindingGeneratorImpl; -import java.io.File; -import java.io.IOException; -import java.net.URISyntaxException; -import java.util.List; -import org.junit.Test; -import org.opendaylight.yangtools.sal.binding.generator.api.BindingGenerator; -import org.opendaylight.yangtools.sal.binding.model.api.GeneratedProperty; -import org.opendaylight.yangtools.sal.binding.model.api.GeneratedTransferObject; -import org.opendaylight.yangtools.sal.binding.model.api.GeneratedType; -import org.opendaylight.yangtools.sal.binding.model.api.MethodSignature; -import org.opendaylight.yangtools.sal.binding.model.api.Type; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; - -public class GeneratedTypesTest { - - @Test - public void testMultipleModulesResolving() throws URISyntaxException, IOException, SourceException, ReactorException { - File abstractTopology = new File(getClass().getResource("/abstract-topology.yang").toURI()); - File ietfInetTypes = new File(getClass().getResource("/ietf/ietf-inet-types.yang").toURI()); - - final SchemaContext context = RetestUtils.parseYangSources(abstractTopology, ietfInetTypes); - assertNotNull(context); - - final BindingGenerator bindingGen = new BindingGeneratorImpl(true); - final List genTypes = bindingGen.generateTypes(context); - - assertNotNull(genTypes); - assertEquals(29, genTypes.size()); - } - - @Test - public void testContainerResolving() throws URISyntaxException, IOException, SourceException, ReactorException { - final File testFile = new File(getClass().getResource("/simple-container-demo.yang").toURI()); - final SchemaContext context = RetestUtils.parseYangSources(testFile); - assertNotNull(context); - - final BindingGenerator bindingGen = new BindingGeneratorImpl(true); - final List genTypes = bindingGen.generateTypes(context); - - assertNotNull(genTypes); - assertEquals(3, genTypes.size()); - - GeneratedType simpleContainer = (GeneratedType) genTypes.get(1); - GeneratedType nestedContainer = (GeneratedType) genTypes.get(2); - for (Type t : genTypes) { - if ("SimpleContainer".equals(t.getName())) { - simpleContainer = (GeneratedType) t; - } else if ("NestedContainer".equals(t.getName())) { - nestedContainer = (GeneratedType) t; - } - } - assertNotNull(simpleContainer); - assertNotNull(nestedContainer); - assertEquals(3, simpleContainer.getMethodDefinitions().size()); - assertEquals(2, nestedContainer.getMethodDefinitions().size()); - - int getFooMethodCounter = 0; - int getBarMethodCounter = 0; - int getNestedContainerCounter = 0; - - String getFooMethodReturnTypeName = ""; - String getBarMethodReturnTypeName = ""; - String getNestedContainerReturnTypeName = ""; - for (final MethodSignature method : simpleContainer.getMethodDefinitions()) { - if (method.getName().equals("getFoo")) { - getFooMethodCounter++; - getFooMethodReturnTypeName = method.getReturnType().getName(); - } - - if (method.getName().equals("getBar")) { - getBarMethodCounter++; - getBarMethodReturnTypeName = method.getReturnType().getName(); - } - - if (method.getName().equals("getNestedContainer")) { - getNestedContainerCounter++; - getNestedContainerReturnTypeName = method.getReturnType().getName(); - } - } - - assertEquals(1, getFooMethodCounter); - assertEquals("Integer", getFooMethodReturnTypeName); - - assertEquals(1, getBarMethodCounter); - assertEquals("String", getBarMethodReturnTypeName); - - assertEquals(1, getNestedContainerCounter); - assertEquals("NestedContainer", getNestedContainerReturnTypeName); - - getFooMethodCounter = 0; - getBarMethodCounter = 0; - - getFooMethodReturnTypeName = ""; - getBarMethodReturnTypeName = ""; - - for (final MethodSignature method : nestedContainer.getMethodDefinitions()) { - - if (method.getName().equals("getFoo")) { - getFooMethodCounter++; - getFooMethodReturnTypeName = method.getReturnType().getName(); - } - - if (method.getName().equals("getBar")) { - getBarMethodCounter++; - getBarMethodReturnTypeName = method.getReturnType().getName(); - } - } - - assertEquals(1, getFooMethodCounter); - assertEquals("Short", getFooMethodReturnTypeName); - - assertEquals(1, getBarMethodCounter); - assertEquals("String", getBarMethodReturnTypeName); - } - - @Test - public void testLeafListResolving() throws URISyntaxException, IOException, SourceException, ReactorException { - final File testFile = new File(getClass().getResource("/simple-leaf-list-demo.yang").toURI()); - final SchemaContext context = RetestUtils.parseYangSources(testFile); - assertNotNull(context); - - final BindingGenerator bindingGen = new BindingGeneratorImpl(true); - final List genTypes = bindingGen.generateTypes(context); - - assertNotNull(genTypes); - assertEquals(3, genTypes.size()); - - GeneratedType simpleContainer = (GeneratedType) genTypes.get(1); - GeneratedType nestedContainer = (GeneratedType) genTypes.get(2); - for (Type t : genTypes) { - if ("SimpleContainer".equals(t.getName())) { - simpleContainer = (GeneratedType) t; - } else if ("NestedContainer".equals(t.getName())) { - nestedContainer = (GeneratedType) t; - } - } - assertNotNull(simpleContainer); - assertNotNull(nestedContainer); - assertEquals(3, simpleContainer.getMethodDefinitions().size()); - assertEquals(2, nestedContainer.getMethodDefinitions().size()); - - int getFooMethodCounter = 0; - int getBarMethodCounter = 0; - int getNestedContainerCounter = 0; - - String getFooMethodReturnTypeName = ""; - String getBarMethodReturnTypeName = ""; - String getNestedContainerReturnTypeName = ""; - for (final MethodSignature method : simpleContainer.getMethodDefinitions()) { - if (method.getName().equals("getFoo")) { - getFooMethodCounter++; - getFooMethodReturnTypeName = method.getReturnType().getName(); - } - - if (method.getName().equals("getBar")) { - getBarMethodCounter++; - getBarMethodReturnTypeName = method.getReturnType().getName(); - } - - if (method.getName().equals("getNestedContainer")) { - getNestedContainerCounter++; - getNestedContainerReturnTypeName = method.getReturnType().getName(); - } - } - - assertEquals(1, getFooMethodCounter); - assertEquals("List", getFooMethodReturnTypeName); - - assertEquals(1, getBarMethodCounter); - assertEquals("String", getBarMethodReturnTypeName); - - assertEquals(1, getNestedContainerCounter); - assertEquals("NestedContainer", getNestedContainerReturnTypeName); - - getFooMethodCounter = 0; - getBarMethodCounter = 0; - - getFooMethodReturnTypeName = ""; - getBarMethodReturnTypeName = ""; - - for (final MethodSignature method : nestedContainer.getMethodDefinitions()) { - if (method.getName().equals("getFoo")) { - getFooMethodCounter++; - getFooMethodReturnTypeName = method.getReturnType().getName(); - } - - if (method.getName().equals("getBar")) { - getBarMethodCounter++; - getBarMethodReturnTypeName = method.getReturnType().getName(); - } - } - - assertEquals(1, getFooMethodCounter); - assertEquals("Short", getFooMethodReturnTypeName); - - assertEquals(1, getBarMethodCounter); - assertEquals("List", getBarMethodReturnTypeName); - } - - @Test - public void testListResolving() throws URISyntaxException, IOException, SourceException, ReactorException { - final File testFile = new File(getClass().getResource("/simple-list-demo.yang").toURI()); - final SchemaContext context = RetestUtils.parseYangSources(testFile); - assertNotNull(context); - - final BindingGenerator bindingGen = new BindingGeneratorImpl(true); - final List genTypes = bindingGen.generateTypes(context); - - assertNotNull(genTypes); - assertEquals(5, genTypes.size()); - - int listParentContainerMethodsCount = 0; - int simpleListMethodsCount = 0; - int listChildContainerMethodsCount = 0; - int listKeyClassCount = 0; - - int getSimpleListKeyMethodCount = 0; - int getListChildContainerMethodCount = 0; - int getFooMethodCount = 0; - int setFooMethodCount = 0; - int getSimpleLeafListMethodCount = 0; - int setSimpleLeafListMethodCount = 0; - int getBarMethodCount = 0; - - String getSimpleListKeyMethodReturnTypeName = ""; - String getListChildContainerMethodReturnTypeName = ""; - - int listKeyClassPropertyCount = 0; - String listKeyClassPropertyName = ""; - String listKeyClassPropertyTypeName = ""; - boolean listKeyClassPropertyReadOnly = false; - - int hashMethodParameterCount = 0; - String hashMethodParameterName = ""; - String hashMethodParameterReturnTypeName = ""; - - int equalMethodParameterCount = 0; - String equalMethodParameterName = ""; - String equalMethodParameterReturnTypeName = ""; - - for (final Type type : genTypes) { - if (type instanceof GeneratedType && !(type instanceof GeneratedTransferObject)) { - final GeneratedType genType = (GeneratedType) type; - if (genType.getName().equals("ListParentContainer")) { - listParentContainerMethodsCount = genType.getMethodDefinitions().size(); - } else if (genType.getName().equals("SimpleList")) { - simpleListMethodsCount = genType.getMethodDefinitions().size(); - final List methods = genType.getMethodDefinitions(); - for (final MethodSignature method : methods) { - if (method.getName().equals("getKey")) { - getSimpleListKeyMethodCount++; - getSimpleListKeyMethodReturnTypeName = method.getReturnType().getName(); - } else if (method.getName().equals("getListChildContainer")) { - getListChildContainerMethodCount++; - getListChildContainerMethodReturnTypeName = method.getReturnType().getName(); - } else if (method.getName().equals("getFoo")) { - getFooMethodCount++; - } else if (method.getName().equals("setFoo")) { - setFooMethodCount++; - } else if (method.getName().equals("getSimpleLeafList")) { - getSimpleLeafListMethodCount++; - } else if (method.getName().equals("setSimpleLeafList")) { - setSimpleLeafListMethodCount++; - } else if (method.getName().equals("getBar")) { - getBarMethodCount++; - } - } - } else if (genType.getName().equals("ListChildContainer")) { - listChildContainerMethodsCount = genType.getMethodDefinitions().size(); - } - } else if (type instanceof GeneratedTransferObject) { - final GeneratedTransferObject genTO = (GeneratedTransferObject) type; - final List properties = genTO.getProperties(); - final List hashProps = genTO.getHashCodeIdentifiers(); - final List equalProps = genTO.getEqualsIdentifiers(); - - listKeyClassCount++; - listKeyClassPropertyCount = properties.size(); - listKeyClassPropertyName = properties.get(0).getName(); - listKeyClassPropertyTypeName = properties.get(0).getReturnType().getName(); - listKeyClassPropertyReadOnly = properties.get(0).isReadOnly(); - - hashMethodParameterCount = hashProps.size(); - hashMethodParameterName = hashProps.get(0).getName(); - hashMethodParameterReturnTypeName = hashProps.get(0).getReturnType().getName(); - - equalMethodParameterCount = equalProps.size(); - equalMethodParameterName = equalProps.get(0).getName(); - equalMethodParameterReturnTypeName = equalProps.get(0).getReturnType().getName(); - - } - } - - assertEquals(1, listParentContainerMethodsCount); - assertEquals(1, listChildContainerMethodsCount); - assertEquals(1, getSimpleListKeyMethodCount); - assertEquals(1, listKeyClassCount); - - assertEquals(1, listKeyClassPropertyCount); - assertEquals("listKey", listKeyClassPropertyName); - assertEquals("Byte", listKeyClassPropertyTypeName); - assertEquals(true, listKeyClassPropertyReadOnly); - assertEquals(1, hashMethodParameterCount); - assertEquals("listKey", hashMethodParameterName); - assertEquals("Byte", hashMethodParameterReturnTypeName); - assertEquals(1, equalMethodParameterCount); - assertEquals("listKey", equalMethodParameterName); - assertEquals("Byte", equalMethodParameterReturnTypeName); - - assertEquals("SimpleListKey", getSimpleListKeyMethodReturnTypeName); - - assertEquals(1, getListChildContainerMethodCount); - assertEquals("ListChildContainer", getListChildContainerMethodReturnTypeName); - assertEquals(1, getFooMethodCount); - assertEquals(0, setFooMethodCount); - assertEquals(1, getSimpleLeafListMethodCount); - assertEquals(0, setSimpleLeafListMethodCount); - assertEquals(1, getBarMethodCount); - - assertEquals(6, simpleListMethodsCount); - } - - @Test - public void testListCompositeKeyResolving() throws URISyntaxException, IOException, SourceException, ReactorException { - final File testFile = new File(getClass().getResource("/list-composite-key.yang").toURI()); - final SchemaContext context = RetestUtils.parseYangSources(testFile); - assertNotNull(context); - - final BindingGenerator bindingGen = new BindingGeneratorImpl(true); - final List genTypes = bindingGen.generateTypes(context); - - assertNotNull(genTypes); - assertEquals(7, genTypes.size()); - - int genTypesCount = 0; - int genTOsCount = 0; - - int compositeKeyListKeyPropertyCount = 0; - int compositeKeyListKeyCount = 0; - int innerListKeyPropertyCount = 0; - - for (final Type type : genTypes) { - if (type instanceof GeneratedType && !(type instanceof GeneratedTransferObject)) { - genTypesCount++; - } else if (type instanceof GeneratedTransferObject) { - final GeneratedTransferObject genTO = (GeneratedTransferObject) type; - - if (genTO.getName().equals("CompositeKeyListKey")) { - compositeKeyListKeyCount++; - final List properties = genTO.getProperties(); - for (final GeneratedProperty prop : properties) { - if (prop.getName().equals("key1")) { - compositeKeyListKeyPropertyCount++; - } else if (prop.getName().equals("key2")) { - compositeKeyListKeyPropertyCount++; - } - } - genTOsCount++; - } else if (genTO.getName().equals("InnerListKey")) { - final List properties = genTO.getProperties(); - innerListKeyPropertyCount = properties.size(); - genTOsCount++; - } - } - } - assertEquals(1, compositeKeyListKeyCount); - assertEquals(2, compositeKeyListKeyPropertyCount); - - assertEquals(1, innerListKeyPropertyCount); - - assertEquals(5, genTypesCount); - assertEquals(2, genTOsCount); - } - - @Test - public void testGeneratedTypes() throws URISyntaxException, IOException, SourceException, ReactorException { - final File testFile = new File(getClass().getResource("/demo-topology.yang").toURI()); - final SchemaContext context = RetestUtils.parseYangSources(testFile); - assertNotNull(context); - - final BindingGenerator bindingGen = new BindingGeneratorImpl(true); - final List genTypes = bindingGen.generateTypes(context); - - assertNotNull(genTypes); - assertEquals(14, genTypes.size()); - - int genTypesCount = 0; - int genTOsCount = 0; - for (final Type type : genTypes) { - if (type instanceof GeneratedType && !(type instanceof GeneratedTransferObject)) { - genTypesCount++; - } else if (type instanceof GeneratedTransferObject) { - genTOsCount++; - } - } - - assertEquals(11, genTypesCount); - assertEquals(3, genTOsCount); - } -} diff --git a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/IdentityrefTypeTest.java b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/IdentityrefTypeTest.java deleted file mode 100644 index c88045c36c..0000000000 --- a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/IdentityrefTypeTest.java +++ /dev/null @@ -1,103 +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.yangtools.sal.binding.generator.impl.stmt.parser.retest; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; -import org.opendaylight.yangtools.yang.parser.spi.source.SourceException; - -import org.opendaylight.yangtools.sal.binding.generator.impl.BindingGeneratorImpl; -import java.io.File; -import java.io.IOException; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.ArrayList; -import java.util.List; -import org.junit.Before; -import org.junit.Test; -import org.opendaylight.yangtools.sal.binding.generator.api.BindingGenerator; -import org.opendaylight.yangtools.sal.binding.model.api.GeneratedType; -import org.opendaylight.yangtools.sal.binding.model.api.MethodSignature; -import org.opendaylight.yangtools.sal.binding.model.api.ParameterizedType; -import org.opendaylight.yangtools.sal.binding.model.api.Type; -import org.opendaylight.yangtools.sal.binding.yang.types.TypeProviderImpl; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; - -public class IdentityrefTypeTest { - - private static List testModels = null; - - @Before - public void loadTestResources() throws URISyntaxException { - URI folderPath = IdentityrefTypeTest.class.getResource("/identityref.yang").toURI(); - File folderFile = new File(folderPath); - testModels = new ArrayList(); - - if (folderFile.isFile()) { - testModels.add(folderFile); - } else { - for (File file : folderFile.listFiles()) { - if (file.isFile()) { - testModels.add(file); - } - } - } - } - - /** - * Test mainly for the method - * {@link TypeProviderImpl#provideTypeForIdentityref(IdentityrefTypeDefinition) - * provideTypeForIdentityref} - * @throws ReactorException Reactor exception - * @throws SourceException Source exception - * @throws IOException IOException - */ - @Test - public void testIdentityrefYangBuiltInType() throws IOException, SourceException, ReactorException { - final SchemaContext context = RetestUtils.parseYangSources(testModels); - - assertNotNull(context); - final BindingGenerator bindingGen = new BindingGeneratorImpl(true); - final List genTypes = bindingGen.generateTypes(context); - - GeneratedType moduleGenType = null; - for (Type type : genTypes) { - if (type.getName().equals("ModuleIdentityrefData")) { - if (type instanceof GeneratedType) { - moduleGenType = (GeneratedType) type; - } - } - } - - assertNotNull("Generated type for whole module wasn't found", moduleGenType); - - String typeName = null; - String actualTypeName = ""; - int numOfActualTypes = 0; - List methodSignatures = moduleGenType.getMethodDefinitions(); - for (MethodSignature methodSignature : methodSignatures) { - if (methodSignature.getName().equals("getLf")) { - Type returnType = methodSignature.getReturnType(); - if (returnType instanceof ParameterizedType) { - typeName = returnType.getName(); - Type[] actualTypes = ((ParameterizedType) returnType).getActualTypeArguments(); - numOfActualTypes = actualTypes.length; - actualTypeName = actualTypes[0].getName(); - } - } - } - assertNotNull("The method 'getLf' wasn't found", typeName); - assertEquals("Return type has incorrect name", "Class", typeName); - assertEquals("Incorrect number of type parameters", 1, numOfActualTypes); - assertEquals("Return type has incorrect actual parameter", "SomeIdentity", actualTypeName); - - } - -} diff --git a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/NameTypePattern.java b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/NameTypePattern.java deleted file mode 100644 index 7b9ddee731..0000000000 --- a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/NameTypePattern.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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.yangtools.sal.binding.generator.impl.stmt.parser.retest; - -public class NameTypePattern { - final String name; - final String type; - - public NameTypePattern(String name, String type) { - this.name = name; - this.type = type; - } - - public String getName() { - return this.name; - } - - public String getType() { - return this.type; - } -} diff --git a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/SupportTestUtil.java b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/SupportTestUtil.java deleted file mode 100644 index f41bfef0bd..0000000000 --- a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/SupportTestUtil.java +++ /dev/null @@ -1,148 +0,0 @@ -/* - * 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.yangtools.sal.binding.generator.impl.stmt.parser.retest; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; -import org.opendaylight.yangtools.yang.parser.spi.source.SourceException; - -import java.io.File; -import java.io.IOException; -import java.net.URI; -import java.util.ArrayList; -import java.util.List; -import org.opendaylight.yangtools.sal.binding.model.api.GeneratedProperty; -import org.opendaylight.yangtools.sal.binding.model.api.GeneratedTransferObject; -import org.opendaylight.yangtools.sal.binding.model.api.GeneratedType; -import org.opendaylight.yangtools.sal.binding.model.api.MethodSignature; -import org.opendaylight.yangtools.sal.binding.model.api.ParameterizedType; -import org.opendaylight.yangtools.sal.binding.model.api.Type; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; - -public class SupportTestUtil { - - public static SchemaContext resolveSchemaContextFromFiles(final URI... yangFiles) throws IOException, SourceException, ReactorException { - - final List inputFiles = new ArrayList(); - for (int i = 0; i < yangFiles.length; ++i) { - inputFiles.add(new File(yangFiles[i])); - } - - return RetestUtils.parseYangSources(inputFiles); - } - - public static void containsMethods(final GeneratedType genType, final NameTypePattern... searchedSignsWhat) { - final List searchedSignsIn = genType.getMethodDefinitions(); - containsMethods(searchedSignsIn, searchedSignsWhat); - } - - public static void containsMethods(final List searchedSignsIn, - final NameTypePattern... searchedSignsWhat) { - if (searchedSignsIn == null) { - throw new IllegalArgumentException("List of method signatures in which should be searched can't be null"); - } - if (searchedSignsWhat == null) { - throw new IllegalArgumentException("Array of method signatures which should be searched can't be null"); - } - - for (NameTypePattern searchedSignWhat : searchedSignsWhat) { - boolean nameMatchFound = false; - String typeNameFound = ""; - for (MethodSignature searchedSignIn : searchedSignsIn) { - if (searchedSignWhat.getName().equals(searchedSignIn.getName())) { - nameMatchFound = true; - typeNameFound = resolveFullNameOfReturnType(searchedSignIn.getReturnType()); - if (searchedSignWhat.getType().equals(typeNameFound)) { - break; - } - } - } - assertTrue("Method " + searchedSignWhat.getName() + " wasn't found.", nameMatchFound); - assertEquals("Return type in method " + searchedSignWhat.getName() + " doesn't match expected type ", - searchedSignWhat.getType(), typeNameFound); - - } - } - - public static void containsAttributes(final GeneratedTransferObject genTO, boolean equal, boolean hash, - boolean toString, final NameTypePattern... searchedSignsWhat) { - List searchedPropertiesIn = genTO.getProperties(); - containsAttributes(searchedPropertiesIn, "", searchedSignsWhat); - if (equal) { - searchedPropertiesIn = genTO.getEqualsIdentifiers(); - containsAttributes(searchedPropertiesIn, "equal", searchedSignsWhat); - } - if (hash) { - searchedPropertiesIn = genTO.getHashCodeIdentifiers(); - containsAttributes(searchedPropertiesIn, "hash", searchedSignsWhat); - } - if (toString) { - searchedPropertiesIn = genTO.getToStringIdentifiers(); - containsAttributes(searchedPropertiesIn, "toString", searchedSignsWhat); - } - - } - - public static void containsAttributes(final List searchedPropertiesIn, final String listType, - final NameTypePattern... searchedPropertiesWhat) { - - for (NameTypePattern searchedPropertyWhat : searchedPropertiesWhat) { - boolean nameMatchFound = false; - String typeNameFound = ""; - for (GeneratedProperty searchedPropertyIn : searchedPropertiesIn) { - if (searchedPropertyWhat.getName().equals(searchedPropertyIn.getName())) { - nameMatchFound = true; - typeNameFound = resolveFullNameOfReturnType(searchedPropertyIn.getReturnType()); - if (searchedPropertyWhat.getType().equals(typeNameFound)) { - break; - } - } - } - assertTrue("Property " + searchedPropertyWhat.getName() + " wasn't found in " + listType - + " property list.", nameMatchFound); - assertEquals("The type of property " + searchedPropertyWhat.getName() + " in " + listType - + " property list doesn't match expected type.", searchedPropertyWhat.getType(), typeNameFound); - - } - } - - public static String resolveFullNameOfReturnType(final Type type) { - final StringBuilder nameBuilder = new StringBuilder(); - if (type instanceof ParameterizedType) { - nameBuilder.append(type.getName() + "<"); - ParameterizedType parametrizedTypes = (ParameterizedType) type; - for (Type parametrizedType : parametrizedTypes.getActualTypeArguments()) { - nameBuilder.append(parametrizedType.getName() + ","); - } - if (nameBuilder.charAt(nameBuilder.length() - 1) == ',') { - nameBuilder.deleteCharAt(nameBuilder.length() - 1); - } - nameBuilder.append(">"); - } else { - nameBuilder.append(type.getName()); - } - return nameBuilder.toString(); - } - - public static void containsInterface(String interfaceNameSearched, GeneratedType genType) { - List caseCImplements = genType.getImplements(); - boolean interfaceFound = false; - for (Type caseCImplement : caseCImplements) { - String interfaceName = resolveFullNameOfReturnType(caseCImplement); - if (interfaceName.equals(interfaceNameSearched)) { - interfaceFound = true; - break; - } - } - assertTrue("Generated type " + genType.getName() + " doesn't implement interface " + interfaceNameSearched, - interfaceFound); - } - -} diff --git a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/TypeProviderIntegrationTest.java b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/TypeProviderIntegrationTest.java deleted file mode 100644 index f65882fe4e..0000000000 --- a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/TypeProviderIntegrationTest.java +++ /dev/null @@ -1,298 +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.yangtools.sal.binding.generator.impl.stmt.parser.retest; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import java.io.File; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Set; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.opendaylight.yangtools.sal.binding.yang.types.TypeProviderImpl; -import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode; -import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode; -import org.opendaylight.yangtools.yang.model.api.Module; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.model.api.TypeDefinition; - -public class TypeProviderIntegrationTest { - private final String PKG = "org.opendaylight.yang.gen.v1.urn.opendaylight.test.rev131008."; - private static SchemaContext context; - private TypeProviderImpl provider; - private Module m; - - @BeforeClass - public static void setup() throws Exception { - File abstractTopology = new File(TypeProviderIntegrationTest.class.getResource("/type-provider/test.yang") - .toURI()); - File ietfInetTypes = new File(TypeProviderIntegrationTest.class.getResource("/ietf/ietf-inet-types.yang") - .toURI()); - context = RetestUtils.parseYangSources(abstractTopology, ietfInetTypes); - assertNotNull(context); - } - - @Before - public void init() throws ParseException { - provider = new TypeProviderImpl(context); - m = context.findModuleByName("test", new SimpleDateFormat("yyyy-MM-dd").parse("2013-10-08")); - } - - @Test - public void testGetTypeDefaultConstructionBinary() throws ParseException { - LeafSchemaNode leaf = (LeafSchemaNode) m.getDataChildByName("leaf-binary"); - String actual = provider.getTypeDefaultConstruction(leaf); - assertEquals("new byte[] {77, 97, 110}", actual); - - leaf = (LeafSchemaNode) m.getDataChildByName("ext-binary"); - actual = provider.getTypeDefaultConstruction(leaf); - assertEquals("new " + PKG + "MyBinary(new byte[] {77, 97, 110})", actual); - } - - @Test - public void testGetTypeDefaultConstructionBits() throws ParseException { - LeafSchemaNode leaf = (LeafSchemaNode) m.getDataChildByName("leaf-bits"); - String actual = provider.getTypeDefaultConstruction(leaf); - assertEquals("new " + PKG + "TestData.LeafBits(false, false, true)", actual); - - leaf = (LeafSchemaNode) m.getDataChildByName("ext-bits"); - actual = provider.getTypeDefaultConstruction(leaf); - assertEquals("new " + PKG + "MyBits(false, false, true)", actual); - } - - @Test - public void testGetTypeDefaultConstructionBoolean() throws ParseException { - LeafSchemaNode leaf = (LeafSchemaNode) m.getDataChildByName("leaf-boolean"); - String actual = provider.getTypeDefaultConstruction(leaf); - assertEquals("new java.lang.Boolean(\"true\")", actual); - - leaf = (LeafSchemaNode) m.getDataChildByName("ext-boolean"); - actual = provider.getTypeDefaultConstruction(leaf); - assertEquals("new " + PKG + "MyBoolean(new java.lang.Boolean(\"true\"))", actual); - } - - @Test - public void testGetTypeDefaultConstructionDecimal() throws ParseException { - LeafSchemaNode leaf = (LeafSchemaNode) m.getDataChildByName("leaf-decimal64"); - String actual = provider.getTypeDefaultConstruction(leaf); - assertEquals("new java.math.BigDecimal(\"3.14\")", actual); - - leaf = (LeafSchemaNode) m.getDataChildByName("ext-decimal64"); - actual = provider.getTypeDefaultConstruction(leaf); - assertEquals("new " + PKG + "MyDecimal64(new java.math.BigDecimal(\"3.14\"))", actual); - } - - @Test - public void testGetTypeDefaultConstructionEmpty() throws ParseException { - LeafSchemaNode leaf = (LeafSchemaNode) m.getDataChildByName("leaf-empty"); - String actual = provider.getTypeDefaultConstruction(leaf); - assertEquals("new java.lang.Boolean(\"false\")", actual); - - leaf = (LeafSchemaNode) m.getDataChildByName("ext-empty"); - actual = provider.getTypeDefaultConstruction(leaf); - assertEquals("new " + PKG + "MyEmpty(new java.lang.Boolean(\"false\"))", actual); - } - - @Test - public void testGetTypeDefaultConstructionEnumeration() throws ParseException { - LeafSchemaNode leaf = (LeafSchemaNode) m.getDataChildByName("leaf-enumeration"); - String actual = provider.getTypeDefaultConstruction(leaf); - assertEquals("org.opendaylight.yang.gen.v1.urn.opendaylight.test.rev131008.LeafEnumeration.Seven", actual); - - leaf = (LeafSchemaNode) m.getDataChildByName("ext-enumeration"); - actual = provider.getTypeDefaultConstruction(leaf); - assertEquals(PKG + "MyEnumeration.Seven", actual); - } - - @Test - public void testGetTypeDefaultConstructionInt8() throws ParseException { - LeafSchemaNode leaf = (LeafSchemaNode) m.getDataChildByName("leaf-int8"); - String actual = provider.getTypeDefaultConstruction(leaf); - assertEquals("new java.lang.Byte(\"11\")", actual); - - leaf = (LeafSchemaNode) m.getDataChildByName("ext-int8"); - actual = provider.getTypeDefaultConstruction(leaf); - assertEquals("new " + PKG + "MyInt8(new java.lang.Byte(\"11\"))", actual); - } - - @Test - public void testGetTypeDefaultConstructionInt16() throws ParseException { - LeafSchemaNode leaf = (LeafSchemaNode) m.getDataChildByName("leaf-int16"); - String actual = provider.getTypeDefaultConstruction(leaf); - assertEquals("new java.lang.Short(\"111\")", actual); - - leaf = (LeafSchemaNode) m.getDataChildByName("ext-int16"); - actual = provider.getTypeDefaultConstruction(leaf); - assertEquals("new " + PKG + "MyInt16(new java.lang.Short(\"111\"))", actual); - } - - @Test - public void testGetTypeDefaultConstructionInt32() throws ParseException { - LeafSchemaNode leaf = (LeafSchemaNode) m.getDataChildByName("leaf-int32"); - String actual = provider.getTypeDefaultConstruction(leaf); - assertEquals("new java.lang.Integer(\"1111\")", actual); - - leaf = (LeafSchemaNode) m.getDataChildByName("ext-int32"); - actual = provider.getTypeDefaultConstruction(leaf); - assertEquals("new " + PKG + "MyInt32(new java.lang.Integer(\"1111\"))", actual); - } - - @Test - public void testGetTypeDefaultConstructionInt64() throws ParseException { - LeafSchemaNode leaf = (LeafSchemaNode) m.getDataChildByName("leaf-int64"); - String actual = provider.getTypeDefaultConstruction(leaf); - assertEquals("new java.lang.Long(\"11111\")", actual); - - leaf = (LeafSchemaNode) m.getDataChildByName("ext-int64"); - actual = provider.getTypeDefaultConstruction(leaf); - assertEquals("new " + PKG + "MyInt64(new java.lang.Long(\"11111\"))", actual); - } - - @Test - public void testGetTypeDefaultConstructionLeafref1() throws ParseException { - LeafSchemaNode leaf = (LeafSchemaNode) m.getDataChildByName("leaf-leafref"); - String actual = provider.getTypeDefaultConstruction(leaf); - assertEquals("new java.math.BigDecimal(\"1.234\")", actual); - - leaf = (LeafSchemaNode) m.getDataChildByName("ext-leafref"); - actual = provider.getTypeDefaultConstruction(leaf); - assertEquals("new java.math.BigDecimal(\"1.234\")", actual); - } - - @Test - public void testGetTypeDefaultConstructionLeafref2() throws ParseException { - LeafSchemaNode leaf = (LeafSchemaNode) m.getDataChildByName("leaf-leafref1"); - String actual = provider.getTypeDefaultConstruction(leaf); - assertEquals("new " + PKG + "MyBinary(new byte[] {77, 97, 110})", actual); - - leaf = (LeafSchemaNode) m.getDataChildByName("ext-leafref1"); - actual = provider.getTypeDefaultConstruction(leaf); - assertEquals("new " + PKG + "MyBinary(new byte[] {77, 97, 110})", actual); - } - - @Test - public void testGetTypeDefaultConstructionString() throws ParseException { - LeafSchemaNode leaf = (LeafSchemaNode) m.getDataChildByName("leaf-string"); - String actual = provider.getTypeDefaultConstruction(leaf); - assertEquals("\"name\"", actual); - - leaf = (LeafSchemaNode) m.getDataChildByName("ext-string"); - actual = provider.getTypeDefaultConstruction(leaf); - assertEquals("new " + PKG + "MyString(\"name\")", actual); - } - - @Test - public void testGetTypeDefaultConstructionUint8() throws ParseException { - LeafSchemaNode leaf = (LeafSchemaNode) m.getDataChildByName("leaf-uint8"); - String actual = provider.getTypeDefaultConstruction(leaf); - assertEquals("new java.lang.Short(\"11\")", actual); - - leaf = (LeafSchemaNode) m.getDataChildByName("ext-uint8"); - actual = provider.getTypeDefaultConstruction(leaf); - assertEquals("new " + PKG + "MyUint8(new java.lang.Short(\"11\"))", actual); - } - - @Test - public void testGetTypeDefaultConstructionUint16() throws ParseException { - LeafSchemaNode leaf = (LeafSchemaNode) m.getDataChildByName("leaf-uint16"); - String actual = provider.getTypeDefaultConstruction(leaf); - assertEquals("new java.lang.Integer(\"111\")", actual); - - leaf = (LeafSchemaNode) m.getDataChildByName("ext-uint16"); - actual = provider.getTypeDefaultConstruction(leaf); - assertEquals("new " + PKG + "MyUint16(new java.lang.Integer(\"111\"))", actual); - } - - @Test - public void testGetTypeDefaultConstructionUint32() throws ParseException { - LeafSchemaNode leaf = (LeafSchemaNode) m.getDataChildByName("leaf-uint32"); - String actual = provider.getTypeDefaultConstruction(leaf); - assertEquals("new java.lang.Long(\"1111\")", actual); - - leaf = (LeafSchemaNode) m.getDataChildByName("ext-uint32"); - actual = provider.getTypeDefaultConstruction(leaf); - assertEquals("new " + PKG + "MyUint32(new java.lang.Long(\"1111\"))", actual); - } - - @Test - public void testGetTypeDefaultConstructionUint64() throws ParseException { - LeafSchemaNode leaf = (LeafSchemaNode) m.getDataChildByName("leaf-uint64"); - String actual = provider.getTypeDefaultConstruction(leaf); - assertEquals("new java.math.BigInteger(\"11111\")", actual); - - leaf = (LeafSchemaNode) m.getDataChildByName("ext-uint64"); - actual = provider.getTypeDefaultConstruction(leaf); - assertEquals("new " + PKG + "MyUint64(new java.math.BigInteger(\"11111\"))", actual); - } - - @Test - public void testGetTypeDefaultConstruction() throws ParseException { - LeafSchemaNode leaf = (LeafSchemaNode) m.getDataChildByName("ip-leaf"); - String actual = provider.getTypeDefaultConstruction(leaf); - String exp = "new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address(\"0.0.0.1\")"; - assertEquals(exp, actual); - } - - @Test - public void testGetTypeDefaultConstructionUnion() throws ParseException { - LeafSchemaNode leaf = (LeafSchemaNode) m.getDataChildByName("leaf-union"); - String actual = provider.getTypeDefaultConstruction(leaf); - String expected = "new " + PKG + "TestData.LeafUnion(\"111\".toCharArray())"; - assertEquals(expected, actual); - - leaf = (LeafSchemaNode) m.getDataChildByName("ext-union"); - actual = provider.getTypeDefaultConstruction(leaf); - expected = "new " + PKG + "MyUnion(\"111\".toCharArray())"; - assertEquals(expected, actual); - } - - @Test - public void testGetTypeDefaultConstructionUnionNested() throws ParseException { - ContainerSchemaNode c1 = (ContainerSchemaNode) m.getDataChildByName("c1"); - ContainerSchemaNode c2 = (ContainerSchemaNode) c1.getDataChildByName("c2"); - ContainerSchemaNode c3 = (ContainerSchemaNode) c2.getDataChildByName("c3"); - LeafSchemaNode leaf = (LeafSchemaNode) c3.getDataChildByName("id"); - - String actual = provider.getTypeDefaultConstruction(leaf); - String expected = "new " + PKG + "NestedUnion(\"111\".toCharArray())"; - assertEquals(expected, actual); - } - - @Test - public void testGetParamNameFromType() throws ParseException { - m = context.findModuleByName("ietf-inet-types", new SimpleDateFormat("yyyy-MM-dd").parse("2010-09-24")); - Set> types = m.getTypeDefinitions(); - TypeDefinition ipv4 = null; - TypeDefinition ipv6 = null; - TypeDefinition ipv4Pref = null; - TypeDefinition ipv6Pref = null; - for (TypeDefinition type : types) { - if ("ipv4-address".equals(type.getQName().getLocalName())) { - ipv4 = type; - } else if ("ipv6-address".equals(type.getQName().getLocalName())) { - ipv6 = type; - } else if ("ipv4-prefix".equals(type.getQName().getLocalName())) { - ipv4Pref = type; - } else if ("ipv6-prefix".equals(type.getQName().getLocalName())) { - ipv6Pref = type; - } - } - - assertNotNull(ipv4); - assertNotNull(ipv6); - assertNotNull(ipv4Pref); - assertNotNull(ipv6Pref); - assertEquals("ipv4Address", provider.getParamNameFromType(ipv4)); - assertEquals("ipv6Address", provider.getParamNameFromType(ipv6)); - assertEquals("ipv4Prefix", provider.getParamNameFromType(ipv4Pref)); - assertEquals("ipv6Prefix", provider.getParamNameFromType(ipv6Pref)); - } -} \ No newline at end of file diff --git a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/UnionTypeDefTest.java b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/UnionTypeDefTest.java deleted file mode 100644 index bbe3867ec4..0000000000 --- a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/UnionTypeDefTest.java +++ /dev/null @@ -1,37 +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.yangtools.sal.binding.generator.impl.stmt.parser.retest; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import org.opendaylight.yangtools.sal.binding.generator.impl.BindingGeneratorImpl; -import java.io.File; -import java.util.List; -import org.junit.Test; -import org.opendaylight.yangtools.sal.binding.generator.api.BindingGenerator; -import org.opendaylight.yangtools.sal.binding.model.api.Type; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; - -public class UnionTypeDefTest { - - @Test - public void unionTypeResolvingTest() throws Exception { - File abstractTopology = new File(getClass().getResource("/union-test-models/abstract-topology.yang").toURI()); - File ietfInetTypes = new File(getClass().getResource("/ietf/ietf-inet-types.yang").toURI()); - final SchemaContext context = RetestUtils.parseYangSources(abstractTopology, ietfInetTypes); - - assertNotNull("context is null", context); - final BindingGenerator bindingGen = new BindingGeneratorImpl(true); - final List genTypes = bindingGen.generateTypes(context); - - assertNotNull("genTypes is null", genTypes); - assertFalse("genTypes is empty", genTypes.isEmpty()); - - // TODO: implement test - } -} diff --git a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/UsesTest.java b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/UsesTest.java deleted file mode 100644 index bfddeefcb2..0000000000 --- a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/UsesTest.java +++ /dev/null @@ -1,601 +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.yangtools.sal.binding.generator.impl.stmt.parser.retest; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.opendaylight.yangtools.sal.binding.generator.impl.stmt.parser.retest.SupportTestUtil.containsMethods; -import static org.opendaylight.yangtools.sal.binding.generator.impl.stmt.parser.retest.SupportTestUtil.containsInterface; - -import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; -import org.opendaylight.yangtools.yang.parser.spi.source.SourceException; -import org.opendaylight.yangtools.sal.binding.generator.impl.BindingGeneratorImpl; -import java.io.File; -import java.io.IOException; -import java.net.URISyntaxException; -import java.util.ArrayList; -import java.util.List; -import org.junit.Test; -import org.opendaylight.yangtools.sal.binding.generator.api.BindingGenerator; -import org.opendaylight.yangtools.sal.binding.model.api.GeneratedTransferObject; -import org.opendaylight.yangtools.sal.binding.model.api.GeneratedType; -import org.opendaylight.yangtools.sal.binding.model.api.Type; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; - -public class UsesTest { - - private static List loadTestResources(final String testFile) { - try { - final List testModels = new ArrayList(); - final File listModelFile = new File(UsesTest.class.getResource(testFile).toURI()); - testModels.add(listModelFile); - return testModels; - } catch (URISyntaxException e) { - throw new IllegalStateException(e); - } - } - - @Test - public void usesInGroupingDependenciesTest() throws IOException, SourceException, ReactorException { - List testModels = loadTestResources("/uses-of-grouping/uses-of-grouping-dependencies.yang"); - final SchemaContext context = RetestUtils.parseYangSources(testModels); - - assertNotNull(context); - final BindingGenerator bindingGen = new BindingGeneratorImpl(true); - final List genTypes = bindingGen.generateTypes(context); - GeneratedType groupingU = null; - GeneratedType groupingX = null; - GeneratedType groupingV = null; - - int groupingUCounter = 0; - int groupingXCounter = 0; - int groupingVCounter = 0; - - for (Type type : genTypes) { - if (type instanceof GeneratedType && !(type instanceof GeneratedTransferObject)) { - GeneratedType genType = (GeneratedType) type; - if (genType.getName().equals("GroupingU")) { - groupingU = genType; - groupingUCounter++; - } else if (genType.getName().equals("GroupingV")) { - groupingV = genType; - groupingVCounter++; - } else if (genType.getName().equals("GroupingX")) { - groupingX = genType; - groupingXCounter++; - } - } - } - - assertNotNull("Generated type for grouping-U wasn't generated.", groupingU); - assertEquals("GroupingU interface generated more than one time.", 1, groupingUCounter); - assertEquals("GroupingU is in wrong package.", - "org.opendaylight.yang.gen.v1.urn.grouping.dependencies.rev130718", groupingU.getPackageName()); - - assertNotNull("Generated type for grouping-V wasn't generated.", groupingV); - assertEquals("GroupingV interface generated more than one time.", 1, groupingVCounter); - assertEquals("GroupingV is in wrong package.", - "org.opendaylight.yang.gen.v1.urn.grouping.dependencies.rev130718", groupingV.getPackageName()); - - assertNotNull("Generated type for grouping-X wasn't generated.", groupingX); - assertEquals("GroupingX interface generated more than one time.", 1, groupingXCounter); - assertEquals("GroupingX is in wrong package.", - "org.opendaylight.yang.gen.v1.urn.grouping.dependencies.rev130718", groupingX.getPackageName()); - - containsInterface("GroupingV", groupingU); - containsInterface("GroupingX", groupingU); - containsInterface("GroupingZ", groupingV); - containsInterface("GroupingZZ", groupingV); - containsInterface("GroupingY", groupingX); - } - - @Test - public void usesInCaseTest() throws IOException, SourceException, ReactorException { - List testModels = loadTestResources("/uses-of-grouping/uses-of-grouping-case.yang"); - - final SchemaContext context = RetestUtils.parseYangSources(testModels); - - assertNotNull(context); - final BindingGenerator bindingGen = new BindingGeneratorImpl(true); - final List genTypes = bindingGen.generateTypes(context); - - GeneratedType groupingCaseTest = null; - int groupingCaseTestCounter = 0; - GeneratedType caseC = null; - int caseCCounter = 0; - for (Type type : genTypes) { - if (type instanceof GeneratedType && !(type instanceof GeneratedTransferObject)) { - GeneratedType genType = (GeneratedType) type; - if (genType.getName().equals("C")) { - caseC = genType; - caseCCounter++; - } else if (genType.getName().equals("GroupingCaseTest")) { - groupingCaseTest = genType; - groupingCaseTestCounter++; - } - } - } - - assertNotNull("Generated type for case C wasn't generated.", caseC); - assertEquals("Case C interface generated more than one time.", 1, caseCCounter); - assertEquals( - "Case C is in wrong package.", - "org.opendaylight.yang.gen.v1.urn.grouping.uses._case.rev130718.container.with.choicetest.choice.test", - caseC.getPackageName()); - - assertNotNull("Generated type for grouping-case-test wasn't generated.", groupingCaseTest); - assertEquals("GroupingCaseTest interface generated more than one time.", 1, groupingCaseTestCounter); - assertEquals("GroupingCaseTest is in wrong package.", - "org.opendaylight.yang.gen.v1.urn.grouping.uses._case.rev130718", groupingCaseTest.getPackageName()); - - containsInterface("GroupingCaseTest", caseC); - assertTrue("Case C shouldn't contain any method.", caseC.getMethodDefinitions().isEmpty()); - - assertEquals("Number of method in GroupingCaseTest is incorrect", 1, groupingCaseTest.getMethodDefinitions() - .size()); - containsMethods(groupingCaseTest.getMethodDefinitions(), new NameTypePattern("getLeafGroupingCaseTest1", - "String")); - } - - @Test - public void usesInContainerTest() throws IOException, SourceException, ReactorException { - List testModels = loadTestResources("/uses-of-grouping/uses-of-grouping-container.yang"); - - final SchemaContext context = RetestUtils.parseYangSources(testModels); - - assertNotNull(context); - final BindingGenerator bindingGen = new BindingGeneratorImpl(true); - final List genTypes = bindingGen.generateTypes(context); - - int containerTestCount = 0; - int groupingContainerTestCounter = 0; - GeneratedType containerTest = null; - GeneratedType groupingContainerTest = null; - - for (Type type : genTypes) { - if (type instanceof GeneratedType && !(type instanceof GeneratedTransferObject)) { - GeneratedType genType = (GeneratedType) type; - if (genType.getName().equals("GroupingContainerTest")) { - groupingContainerTest = genType; - groupingContainerTestCounter++; - } else if (genType.getName().equals("ContainerTest")) { - containerTest = genType; - containerTestCount++; - } - } - } - - assertNotNull("Generated type for grouping-container-test wasn't generated", groupingContainerTest); - assertEquals("GroupingContainerTest interface - incorrect number of occurences", 1, - groupingContainerTestCounter); - assertEquals("GroupingContainerTest isn't in correct package", - "org.opendaylight.yang.gen.v1.urn.grouping.uses.container.rev130718", - groupingContainerTest.getPackageName()); - - assertNotNull("Generated type for container-test wasn't generated", containerTest); - assertEquals("ContainerTest interface - incorrect number of occurences", 1, containerTestCount); - assertEquals("ContainerTest isn't in correct package", - "org.opendaylight.yang.gen.v1.urn.grouping.uses.container.rev130718", containerTest.getPackageName()); - - containsInterface("GroupingContainerTest", containerTest); - - assertEquals("Number of method in GroupingContainerTestis incorrect", 2, groupingContainerTest - .getMethodDefinitions().size()); - assertEquals("Number of method in ContainerTest is incorrect", 1, containerTest.getMethodDefinitions().size()); - - containsMethods(groupingContainerTest.getMethodDefinitions(), new NameTypePattern( - "getLeafGroupingContainerTest1", "String"), new NameTypePattern("getLeafGroupingContainerTest2", - "Short")); - - containsMethods(containerTest.getMethodDefinitions(), new NameTypePattern("getContainerLeafTest", "String")); - } - - @Test - public void usesInGroupingTest() throws IOException, SourceException, ReactorException { - List testModels = loadTestResources("/uses-of-grouping/uses-of-grouping-grouping.yang"); - - final SchemaContext context = RetestUtils.parseYangSources(testModels); - - assertNotNull(context); - final BindingGenerator bindingGen = new BindingGeneratorImpl(true); - final List genTypes = bindingGen.generateTypes(context); - - int groupingTestCount = 0; - int groupingGroupingTestCounter = 0; - GeneratedType groupingTest = null; - GeneratedType groupingGroupingTest = null; - - for (Type type : genTypes) { - if (type instanceof GeneratedType && !(type instanceof GeneratedTransferObject)) { - GeneratedType genType = (GeneratedType) type; - if (genType.getName().equals("GroupingGroupingTest")) { - groupingGroupingTest = genType; - groupingGroupingTestCounter++; - } else if (genType.getName().equals("GroupingTest")) { - groupingTest = genType; - groupingTestCount++; - } - } - } - - assertNotNull("Generated type for grouping-grouping-test wasn't generated", groupingGroupingTest); - assertEquals("GroupingGroupingTest interface - incorrect number of occurences", 1, groupingGroupingTestCounter); - assertEquals("GroupingGroupingTest isn't in correct package", - "org.opendaylight.yang.gen.v1.urn.grouping.uses.grouping.rev130718", - groupingGroupingTest.getPackageName()); - - assertNotNull("Generated type for grouping-test wasn't generated", groupingTest); - assertEquals("GroupingTest interface - incorrect number of occurences", 1, groupingTestCount); - assertEquals("GroupingTest isn't in correct package", - "org.opendaylight.yang.gen.v1.urn.grouping.uses.grouping.rev130718", groupingTest.getPackageName()); - - containsInterface("GroupingGroupingTest", groupingTest); - - assertEquals("Number of method in GroupingGroupingTest is incorrect", 1, groupingGroupingTest - .getMethodDefinitions().size()); - assertEquals("Number of method in GroupingTest is incorrect", 1, groupingTest.getMethodDefinitions().size()); - - containsMethods(groupingGroupingTest.getMethodDefinitions(), new NameTypePattern("getLeafGroupingGrouping", - "String")); - - containsMethods(groupingTest.getMethodDefinitions(), new NameTypePattern("getLeafGroupingTest", "Byte")); - } - - @Test - public void usesInListTest() throws IOException, SourceException, ReactorException { - List testModels = loadTestResources("/uses-of-grouping/uses-of-grouping-list.yang"); - - final SchemaContext context = RetestUtils.parseYangSources(testModels); - - assertNotNull(context); - final BindingGenerator bindingGen = new BindingGeneratorImpl(true); - final List genTypes = bindingGen.generateTypes(context); - - int listTestCounter = 0; - int groupingListTestCounter = 0; - int containerGroupingListTestCounter = 0; - int listGroupingListTestCounter = 0; - GeneratedType listTest = null; - GeneratedType groupingListTest = null; - GeneratedType containerGroupingListTest = null; - GeneratedType listGroupingListTest = null; - - for (Type type : genTypes) { - if (type instanceof GeneratedType && !(type instanceof GeneratedTransferObject)) { - GeneratedType genType = (GeneratedType) type; - if (genType.getName().equals("GroupingListTest")) { - groupingListTest = genType; - groupingListTestCounter++; - } else if (genType.getName().equals("ListTest")) { - listTest = genType; - listTestCounter++; - } else if (genType.getName().equals("ContainerGroupingListTest")) { - containerGroupingListTest = genType; - containerGroupingListTestCounter++; - } else if (genType.getName().equals("ListGroupingListTest")) { - listGroupingListTest = genType; - listGroupingListTestCounter++; - } - } - } - - assertNotNull("Generated type for grouping-list-test wasn't generated", groupingListTest); - assertEquals("GroupingListTest interface - incorrect number of occurences", 1, groupingListTestCounter); - assertEquals("GroupingListTest isn't in correct package", - "org.opendaylight.yang.gen.v1.urn.grouping.uses.list.rev130718", groupingListTest.getPackageName()); - - assertNotNull("Generated type for list-test wasn't generated", listTest); - assertEquals("ListTest interface - incorrect number of occurences", 1, listTestCounter); - assertEquals("ListTest isn't in correct package", - "org.opendaylight.yang.gen.v1.urn.grouping.uses.list.rev130718", listTest.getPackageName()); - - assertNotNull("Generated type for container-grouping-list-test wasn't generated", containerGroupingListTest); - assertEquals("ContainerGroupingListTest interface - incorrect number of occurences", 1, - containerGroupingListTestCounter); - assertEquals("ContainerGroupingListTest isn't in correct package", - "org.opendaylight.yang.gen.v1.urn.grouping.uses.list.rev130718.grouping.list.test", - containerGroupingListTest.getPackageName()); - - assertNotNull("Generated type for list-grouping-list-test wasn't generated", listGroupingListTest); - assertEquals("ListGroupingListTest interface - incorrect number of occurences", 1, listGroupingListTestCounter); - assertEquals("ListGroupingListTest isn't in correct package", - "org.opendaylight.yang.gen.v1.urn.grouping.uses.list.rev130718.grouping.list.test", - listGroupingListTest.getPackageName()); - - containsInterface("GroupingListTest", listTest); - - assertEquals("Number of method in GroupingListTest is incorrect", 4, groupingListTest.getMethodDefinitions() - .size()); - assertEquals("Number of method in ListTest is incorrect", 1, listTest.getMethodDefinitions().size()); - assertEquals("Number of method in ContainerGroupingListTest is incorrect", 1, containerGroupingListTest - .getMethodDefinitions().size()); - assertEquals("Number of method in ListGroupingListTest is incorrect", 1, listGroupingListTest - .getMethodDefinitions().size()); - - containsMethods(groupingListTest.getMethodDefinitions(), new NameTypePattern("getContainerGroupingListTest", - "ContainerGroupingListTest"), new NameTypePattern("getLeafGroupingListTest", "String"), - new NameTypePattern("getLeaffllistGroupingListTest", "List"), new NameTypePattern( - "getListGroupingListTest", "List")); - containsMethods(listTest.getMethodDefinitions(), new NameTypePattern("getListLeafTest", "String")); - containsMethods(containerGroupingListTest.getMethodDefinitions(), new NameTypePattern( - "getLeafContainerGroupingListTest", "Short")); - containsMethods(listGroupingListTest.getMethodDefinitions(), new NameTypePattern("getLeafListGroupingListTest", - "Integer")); - } - - @Test - public void usesInModulTest() throws IOException, SourceException, ReactorException { - List testModels = loadTestResources("/uses-of-grouping/uses-of-grouping-modul.yang"); - - final SchemaContext context = RetestUtils.parseYangSources(testModels); - - assertNotNull(context); - final BindingGenerator bindingGen = new BindingGeneratorImpl(true); - final List genTypes = bindingGen.generateTypes(context); - - int groupingModulTestCounter = 0; - int groupingUsesModulDataCounter = 0; - GeneratedType groupingModulTest = null; - GeneratedType groupingUsesModulData = null; - - for (Type type : genTypes) { - if (type instanceof GeneratedType && !(type instanceof GeneratedTransferObject)) { - GeneratedType genType = (GeneratedType) type; - if (genType.getName().equals("GroupingModulTest")) { - groupingModulTest = genType; - groupingModulTestCounter++; - } else if (genType.getName().equals("GroupingUsesModulData")) { - groupingUsesModulData = genType; - groupingUsesModulDataCounter++; - } - } - } - - assertNotNull("Generated type for grouping-list-test wasn't generated", groupingModulTest); - assertEquals("GroupingModulTest interface - incorrect number of occurences", 1, groupingModulTestCounter); - assertEquals("GroupingModulTest isn't in correct package", - "org.opendaylight.yang.gen.v1.urn.grouping.uses.modul.rev130718", groupingModulTest.getPackageName()); - - assertNotNull("Generated type for modul wasn't generated", groupingUsesModulData); - assertEquals("GroupingUsesModulData interface - incorrect number of occurences", 1, - groupingUsesModulDataCounter); - assertEquals("GroupingUsesModulData isn't in correct package", - "org.opendaylight.yang.gen.v1.urn.grouping.uses.modul.rev130718", - groupingUsesModulData.getPackageName()); - - containsInterface("GroupingModulTest", groupingUsesModulData); - - assertEquals("Number of method in GroupingUsesModulData is incorrect", 0, groupingUsesModulData - .getMethodDefinitions().size()); - assertEquals("Number of method in GroupingModulTest is incorrect", 2, groupingModulTest.getMethodDefinitions() - .size()); - - containsMethods(groupingModulTest.getMethodDefinitions(), new NameTypePattern("getLeafGroupingModulTest", - "String"), new NameTypePattern("getLeafGroupingModulTest2", "Short")); - } - - @Test - public void usesInRpcTest() throws IOException, SourceException, ReactorException { - List testModels = loadTestResources("/uses-of-grouping/uses-of-grouping-rpc.yang"); - - final SchemaContext context = RetestUtils.parseYangSources(testModels); - - assertNotNull(context); - final BindingGenerator bindingGen = new BindingGeneratorImpl(true); - final List genTypes = bindingGen.generateTypes(context); - - int rpcTestInputCounter = 0; - int rpcTestOutputCounter = 0; - int groupingRpcInputTestCounter = 0; - int groupingRpcOutputTestCounter = 0; - int containerGroupingRpcInputTestCounter = 0; - GeneratedType rpcTestInput = null; - GeneratedType rpcTestOutput = null; - GeneratedType groupingRpcInputTest = null; - GeneratedType groupingRpcOutputTest = null; - GeneratedType containerGroupingRpcInputTest = null; - - for (Type type : genTypes) { - if (type instanceof GeneratedType && !(type instanceof GeneratedTransferObject)) { - GeneratedType genType = (GeneratedType) type; - if (genType.getName().equals("RpcTestInput")) { - rpcTestInput = genType; - rpcTestInputCounter++; - } else if (genType.getName().equals("RpcTestOutput")) { - rpcTestOutput = genType; - rpcTestOutputCounter++; - } else if (genType.getName().equals("GroupingRpcInputTest")) { - groupingRpcInputTest = genType; - groupingRpcInputTestCounter++; - } else if (genType.getName().equals("GroupingRpcOutputTest")) { - groupingRpcOutputTest = genType; - groupingRpcOutputTestCounter++; - } else if (genType.getName().equals("ContainerGroupingRpcInputTest")) { - containerGroupingRpcInputTest = genType; - containerGroupingRpcInputTestCounter++; - } - - } - } - - assertNotNull("Generated type for RPC test input wasn't generated", rpcTestInput); - assertEquals("RpcTestInput interface - incorrect number of occurences", 1, rpcTestInputCounter); - assertEquals("RpcTestInput isn't in correct package", - "org.opendaylight.yang.gen.v1.urn.grouping.uses.rpc.rev130718", rpcTestInput.getPackageName()); - - assertNotNull("Generated type for RPC test output wasn't generated", rpcTestOutput); - assertEquals("RpcTestOutput interface - incorrect number of occurences", 1, rpcTestOutputCounter); - assertEquals("RpcTestOutput isn't in correct package", - "org.opendaylight.yang.gen.v1.urn.grouping.uses.rpc.rev130718", rpcTestOutput.getPackageName()); - - assertNotNull("Generated type for grouping-rpc-input-test wasn't generated", groupingRpcInputTest); - assertEquals("RpcTestOutput interface - incorrect number of occurences", 1, groupingRpcInputTestCounter); - assertEquals("GroupingRpcInputTest isn't in correct package", - "org.opendaylight.yang.gen.v1.urn.grouping.uses.rpc.rev130718", groupingRpcInputTest.getPackageName()); - - assertNotNull("Generated type for grouping-rpc-output-test wasn't generated", groupingRpcOutputTest); - assertEquals("RpcTestOutput interface - incorrect number of occurences", 1, groupingRpcOutputTestCounter); - assertEquals("GroupingRpcOutputTest isn't in correct package", - "org.opendaylight.yang.gen.v1.urn.grouping.uses.rpc.rev130718", groupingRpcOutputTest.getPackageName()); - - assertNotNull("Generated type for container-grouping-rpc-input-test wasn't generated", - containerGroupingRpcInputTest); - assertEquals("ContainerGroupingRpcInputTest interface - incorrect number of occurences", 1, - containerGroupingRpcInputTestCounter); - assertEquals("ContainerGroupingRpcInputTest isn't in correct package", - "org.opendaylight.yang.gen.v1.urn.grouping.uses.rpc.rev130718.grouping.rpc.input.test", - containerGroupingRpcInputTest.getPackageName()); - - containsInterface("GroupingRpcInputTest", rpcTestInput); - containsInterface("GroupingRpcOutputTest", rpcTestOutput); - - assertEquals("Number of method in RpcTestInput is incorrect", 0, rpcTestInput.getMethodDefinitions().size()); - assertEquals("Number of method in RpcTestOutput is incorrect", 0, rpcTestOutput.getMethodDefinitions().size()); - assertEquals("Number of method in GroupingRpcInputTest is incorrect", 2, groupingRpcInputTest - .getMethodDefinitions().size()); - assertEquals("Number of method in GroupingRpcOutputTest is incorrect", 1, groupingRpcOutputTest - .getMethodDefinitions().size()); - assertEquals("Number of method in ContainerGroupingRpcInputTest is incorrect", 1, containerGroupingRpcInputTest - .getMethodDefinitions().size()); - - containsMethods(groupingRpcInputTest.getMethodDefinitions(), new NameTypePattern( - "getContainerGroupingRpcInputTest", "ContainerGroupingRpcInputTest"), new NameTypePattern( - "getLeaflistGroupingRpcInputTest", "List")); - containsMethods(groupingRpcOutputTest.getMethodDefinitions(), new NameTypePattern( - "getLeafGroupingRpcOutputTest", "Byte")); - containsMethods(containerGroupingRpcInputTest.getMethodDefinitions(), new NameTypePattern( - "getLeafContainerGroupingRpcInputTest", "String")); - } - - @Test - public void usesInAugmentTest() throws IOException, SourceException, ReactorException { - List testModels = loadTestResources("/uses-of-grouping/uses-of-grouping-augment.yang"); - - final SchemaContext context = RetestUtils.parseYangSources(testModels); - - assertNotNull(context); - final BindingGenerator bindingGen = new BindingGeneratorImpl(true); - final List genTypes = bindingGen.generateTypes(context); - - GeneratedType containerAugment1 = null; - GeneratedType groupingAugmentTest = null; - int containerAugment1Counter = 0; - int groupingAugmentTestCounter = 0; - - for (Type type : genTypes) { - if (type instanceof GeneratedType && !(type instanceof GeneratedTransferObject)) { - GeneratedType genType = (GeneratedType) type; - if (genType.getName().equals("ContainerAugment1")) { - containerAugment1 = genType; - containerAugment1Counter++; - } else if (genType.getName().equals("GroupingAugmentTest")) { - groupingAugmentTest = genType; - groupingAugmentTestCounter++; - } - } - } - - assertNotNull("Generated type for augment /container-augment wasn't generated.", containerAugment1); - assertEquals("ContainerAugment1 interface generated more than one time.", 1, containerAugment1Counter); - assertEquals("ContainerAugment1 is in wrong package.", - "org.opendaylight.yang.gen.v1.urn.grouping.uses.augment.rev130718", containerAugment1.getPackageName()); - - assertNotNull("Generated type for grouping-augment-test wasn't generated.", groupingAugmentTest); - assertEquals("GroupingAugmentTest interface generated more than one time.", 1, groupingAugmentTestCounter); - assertEquals("groupingAugmentTest is in wrong package.", - "org.opendaylight.yang.gen.v1.urn.grouping.uses.augment.rev130718", - groupingAugmentTest.getPackageName()); - - containsInterface("GroupingAugmentTest", containerAugment1); - - assertEquals("Number of method in GroupingCaseTest is incorrect", 0, containerAugment1.getMethodDefinitions() - .size()); - - assertEquals("Number of method in ContainerAugment1 is incorrect", 0, containerAugment1.getMethodDefinitions() - .size()); - assertEquals("Number of method in GroupingCaseTest is incorrect", 1, groupingAugmentTest.getMethodDefinitions() - .size()); - - containsMethods(groupingAugmentTest.getMethodDefinitions(), new NameTypePattern("getLeafGroupingAugmentTest", - "String")); - } - - @Test - public void usesInNotification() throws IOException, SourceException, ReactorException { - List testModels = loadTestResources("/uses-of-grouping/uses-of-grouping-notification.yang"); - - final SchemaContext context = RetestUtils.parseYangSources(testModels); - - assertNotNull(context); - final BindingGenerator bindingGen = new BindingGeneratorImpl(true); - final List genTypes = bindingGen.generateTypes(context); - - GeneratedType notificationTest = null; - GeneratedType groupingNotificationTest = null; - GeneratedType containerGroupingNotificationTest = null; - int notificationTestCounter = 0; - int groupingNotificationTestCounter = 0; - int containerGroupingNotificationTestCounter = 0; - - for (Type type : genTypes) { - if (type instanceof GeneratedType && !(type instanceof GeneratedTransferObject)) { - GeneratedType genType = (GeneratedType) type; - if (genType.getName().equals("NotificationTest")) { - notificationTest = genType; - notificationTestCounter++; - } else if (genType.getName().equals("GroupingNotificationTest")) { - groupingNotificationTest = genType; - groupingNotificationTestCounter++; - } else if (genType.getName().equals("ContainerGroupingNotificationTest")) { - containerGroupingNotificationTest = genType; - containerGroupingNotificationTestCounter++; - } - } - } - - assertNotNull("Generated type for notification-test wasn't generated.", notificationTest); - assertEquals("NotificationTest interface generated more than one time.", 1, notificationTestCounter); - assertEquals("NotificationTest is in wrong package.", - "org.opendaylight.yang.gen.v1.urn.grouping.uses.notification.rev130718", - notificationTest.getPackageName()); - - assertNotNull("Generated type for grouping-notification-test wasn't generated.", groupingNotificationTest); - assertEquals("GroupingNotificationTest interface generated more than one time.", 1, - groupingNotificationTestCounter); - assertEquals("groupingNotificationTest is in wrong package.", - "org.opendaylight.yang.gen.v1.urn.grouping.uses.notification.rev130718", - groupingNotificationTest.getPackageName()); - - assertNotNull("Generated type for container-grouping-notification-test wasn't generated.", - containerGroupingNotificationTest); - assertEquals("ContainerGroupingNotificationTest interface generated more than one time.", 1, - containerGroupingNotificationTestCounter); - assertEquals("ContainerGroupingNotificationTest is in wrong package.", - "org.opendaylight.yang.gen.v1.urn.grouping.uses.notification.rev130718.grouping.notification.test", - containerGroupingNotificationTest.getPackageName()); - - containsInterface("GroupingNotificationTest", notificationTest); - - assertEquals("Number of method in NotificationTest is incorrect", 1, notificationTest.getMethodDefinitions() - .size()); - assertEquals("Number of method in GroupingNotificationTest is incorrect", 2, groupingNotificationTest - .getMethodDefinitions().size()); - assertEquals("Number of method in ContainerGroupingNotificationTest is incorrect", 1, - containerGroupingNotificationTest.getMethodDefinitions().size()); - - containsMethods(notificationTest.getMethodDefinitions(), new NameTypePattern("getLeafNotificationTest", - "String")); - containsMethods(groupingNotificationTest.getMethodDefinitions(), new NameTypePattern( - "getContainerGroupingNotificationTest", "ContainerGroupingNotificationTest"), new NameTypePattern( - "getLeaffllistGroupingNotificationTest", "List")); - containsMethods(containerGroupingNotificationTest.getMethodDefinitions(), new NameTypePattern( - "getLeafContainerGroupingNotificationTest", "Long")); - } - -} diff --git a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/BaseYangTypesTest.java b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/BaseYangTypesTest.java index 9a29a6f986..02928a8521 100644 --- a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/BaseYangTypesTest.java +++ b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/BaseYangTypesTest.java @@ -1,10 +1,11 @@ /* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2016 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.yangtools.sal.binding.yang.types; import static org.junit.Assert.assertEquals; @@ -21,7 +22,6 @@ import org.junit.Test; import org.opendaylight.yangtools.binding.generator.util.BindingGeneratorUtil; import org.opendaylight.yangtools.sal.binding.generator.spi.TypeProvider; import org.opendaylight.yangtools.sal.binding.model.api.Type; -import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.opendaylight.yangtools.yang.model.api.TypeDefinition; import org.opendaylight.yangtools.yang.model.api.type.BinaryTypeDefinition; @@ -33,9 +33,8 @@ import org.opendaylight.yangtools.yang.model.api.type.IntegerTypeDefinition; import org.opendaylight.yangtools.yang.model.api.type.StringTypeDefinition; import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition; import org.opendaylight.yangtools.yang.model.api.type.UnsignedIntegerTypeDefinition; -import org.opendaylight.yangtools.yang.model.parser.api.YangContextParser; -import org.opendaylight.yangtools.yang.model.util.ExtendedType; -import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl; +import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; +import org.opendaylight.yangtools.yang.parser.spi.source.SourceException; /** * Test class for testing BaseYangTypes class. @@ -62,15 +61,11 @@ public class BaseYangTypesTest { private static EmptyTypeDefinition empty = null; private static BooleanTypeDefinition bool = null; - @SuppressWarnings("deprecation") @BeforeClass - public static void setup() { + public static void setup() throws SourceException, ReactorException { final List modelsToParse = Collections .singletonList(BaseYangTypesTest.class.getResourceAsStream("/base-yang-types.yang")); - final YangContextParser parser = new YangParserImpl(); - final Set modules = parser.parseYangModelsFromStreams(modelsToParse); - assertTrue(!modules.isEmpty()); - schemaContext = parser.resolveSchemaContext(modules); + schemaContext = RetestUtils.parseYangStreams(modelsToParse); assertNotNull(schemaContext); initTypeDefinitionsFromSchemaContext(); } @@ -81,9 +76,10 @@ public class BaseYangTypesTest { for (final TypeDefinition typedef : typedefs) { assertNotNull(typedef); - assertTrue(typedef instanceof ExtendedType); final TypeDefinition baseType = typedef.getBaseType(); + assertNotNull(baseType); + if (baseType instanceof BinaryTypeDefinition) { binary = (BinaryTypeDefinition) baseType; } else if (baseType instanceof DecimalTypeDefinition) { diff --git a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/LeafrefTypeWithNullToStringInXpath.java b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/LeafrefTypeWithNullToStringInXpath.java index 7ec51a118a..9ca33e321e 100644 --- a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/LeafrefTypeWithNullToStringInXpath.java +++ b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/LeafrefTypeWithNullToStringInXpath.java @@ -1,10 +1,11 @@ /* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2016 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.yangtools.sal.binding.yang.types; import java.util.List; diff --git a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/LeafrefTypeWithNullXpath.java b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/LeafrefTypeWithNullXpath.java index 89a7c6a2b0..3f644f2f01 100644 --- a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/LeafrefTypeWithNullXpath.java +++ b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/LeafrefTypeWithNullXpath.java @@ -1,10 +1,11 @@ /* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2016 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.yangtools.sal.binding.yang.types; import java.util.List; diff --git a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/stmt/parser/retest/RetestUtils.java b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/RetestUtils.java similarity index 85% rename from binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/stmt/parser/retest/RetestUtils.java rename to binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/RetestUtils.java index 2539209bdd..92ba5d898c 100644 --- a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/stmt/parser/retest/RetestUtils.java +++ b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/RetestUtils.java @@ -1,4 +1,12 @@ -package org.opendaylight.yangtools.sal.binding.yang.types.stmt.parser.retest; +/* + * Copyright (c) 2016 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.yangtools.sal.binding.yang.types; import java.util.List; diff --git a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/TestIntegerTypeDefinition.java b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/TestIntegerTypeDefinition.java index a7a14fa7e3..10325d4f24 100644 --- a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/TestIntegerTypeDefinition.java +++ b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/TestIntegerTypeDefinition.java @@ -1,10 +1,11 @@ /* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2016 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.yangtools.sal.binding.yang.types; import java.util.List; diff --git a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/TestLeafSchemaNode.java b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/TestLeafSchemaNode.java index 200e149b4a..928d74c4ef 100644 --- a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/TestLeafSchemaNode.java +++ b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/TestLeafSchemaNode.java @@ -1,10 +1,11 @@ /* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2016 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.yangtools.sal.binding.yang.types; import java.util.List; diff --git a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/TypeProviderImplTest.java b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/TypeProviderImplTest.java index 1742adccee..6e22000f77 100644 --- a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/TypeProviderImplTest.java +++ b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/TypeProviderImplTest.java @@ -1,23 +1,21 @@ /* - * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2016 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.yangtools.sal.binding.yang.types; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; - -import com.google.common.base.Optional; import java.io.File; +import java.io.FileNotFoundException; import java.net.URI; import java.net.URISyntaxException; -import java.util.ArrayList; -import java.util.Arrays; import java.util.NoSuchElementException; import org.junit.Rule; import org.junit.Test; @@ -33,19 +31,20 @@ import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.opendaylight.yangtools.yang.model.api.SchemaPath; import org.opendaylight.yangtools.yang.model.api.TypeDefinition; +import org.opendaylight.yangtools.yang.model.api.type.BinaryTypeDefinition; +import org.opendaylight.yangtools.yang.model.api.type.BooleanTypeDefinition; +import org.opendaylight.yangtools.yang.model.api.type.DecimalTypeDefinition; +import org.opendaylight.yangtools.yang.model.api.type.EmptyTypeDefinition; import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition; -import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition.EnumPair; -import org.opendaylight.yangtools.yang.model.util.BinaryType; -import org.opendaylight.yangtools.yang.model.util.BooleanType; -import org.opendaylight.yangtools.yang.model.util.Decimal64; -import org.opendaylight.yangtools.yang.model.util.EmptyType; -import org.opendaylight.yangtools.yang.model.util.EnumerationType; -import org.opendaylight.yangtools.yang.model.util.IdentityrefType; -import org.opendaylight.yangtools.yang.model.util.StringType; +import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition; +import org.opendaylight.yangtools.yang.model.api.type.StringTypeDefinition; +import org.opendaylight.yangtools.yang.model.util.type.BaseTypes; +import org.opendaylight.yangtools.yang.model.util.type.IdentityrefTypeBuilder; import org.opendaylight.yangtools.yang.parser.builder.impl.IdentitySchemaNodeBuilder; import org.opendaylight.yangtools.yang.parser.builder.impl.LeafSchemaNodeBuilder; import org.opendaylight.yangtools.yang.parser.builder.impl.ModuleBuilder; -import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl; +import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; +import org.opendaylight.yangtools.yang.parser.spi.source.SourceException; import org.opendaylight.yangtools.yang.parser.util.YangValidationException; public class TypeProviderImplTest { @@ -57,8 +56,7 @@ public class TypeProviderImplTest { public void testLeafRefRelativeSelfReference() throws Exception { File relative = new File(getClass().getResource("/leafref/leafref-relative-invalid.yang").toURI()); - final YangParserImpl yangParser = new YangParserImpl(); - final SchemaContext schemaContext = yangParser.parseFiles(Arrays.asList(relative)); + final SchemaContext schemaContext = RetestUtils.parseYangSources(relative); final Module moduleRelative = schemaContext.findModuleByNamespace(new URI("urn:xml:ns:yang:lrr")).iterator().next(); final TypeProviderImpl typeProvider = new TypeProviderImpl(schemaContext); @@ -72,8 +70,7 @@ public class TypeProviderImplTest { public void testLeafRefAbsoluteSelfReference() throws Exception { File relative = new File(getClass().getResource("/leafref/leafref-absolute-invalid.yang").toURI()); - final YangParserImpl yangParser = new YangParserImpl(); - final SchemaContext schemaContext = yangParser.parseFiles(Arrays.asList(relative)); + final SchemaContext schemaContext = RetestUtils.parseYangSources(relative); final Module moduleRelative = schemaContext.findModuleByNamespace(new URI("urn:xml:ns:yang:lra")).iterator().next(); final TypeProviderImpl typeProvider = new TypeProviderImpl(schemaContext); @@ -84,11 +81,10 @@ public class TypeProviderImplTest { } @Test - public void testLeafRefRelativeAndAbsoluteValidReference() throws URISyntaxException { + public void testLeafRefRelativeAndAbsoluteValidReference() throws URISyntaxException, SourceException, FileNotFoundException, ReactorException { File valid = new File(getClass().getResource("/leafref/leafref-valid.yang").toURI()); - final YangParserImpl yangParser = new YangParserImpl(); - final SchemaContext schemaContext = yangParser.parseFiles(Arrays.asList(valid)); + final SchemaContext schemaContext = RetestUtils.parseYangSources(valid); final Module moduleValid = schemaContext.findModuleByNamespace(new URI("urn:xml:ns:yang:lrv")).iterator().next(); final TypeProviderImpl typeProvider = new TypeProviderImpl(schemaContext); @@ -108,17 +104,18 @@ public class TypeProviderImplTest { } @Test - public void testMethodsOfTypeProviderImpl() throws URISyntaxException { - final YangParserImpl yangParser = new YangParserImpl(); - final File abstractTopology = new File(BaseYangTypes.class.getResource("/base-yang-types.yang") + public void testMethodsOfTypeProviderImpl() throws URISyntaxException, SourceException, FileNotFoundException, ReactorException { + final File abstractTopology = new File(getClass().getResource("/base-yang-types.yang") .toURI()); - final SchemaContext schemaContext = yangParser.parseFiles(Arrays.asList(abstractTopology)); + + final SchemaContext schemaContext = RetestUtils.parseYangSources(abstractTopology); + final TypeProviderImpl typeProvider = new TypeProviderImpl(schemaContext); final SchemaPath refTypePath = SchemaPath.create(true, QName.create("cont1"), QName.create("list1")); final GeneratedTypeBuilderImpl refType = new GeneratedTypeBuilderImpl("org.opendaylight.yangtools.test", "TestType"); typeProvider.putReferencedType(refTypePath, refType); - final StringType stringType = StringType.getInstance(); + final StringTypeDefinition stringType = BaseTypes.stringType(); LeafSchemaNodeBuilder leafSchemaNodeBuilder = new LeafSchemaNodeBuilder("test-module", 111, QName.create("Cont1"), SchemaPath.ROOT); leafSchemaNodeBuilder.setType(stringType); LeafSchemaNode leafSchemaNode = leafSchemaNodeBuilder.build(); @@ -140,28 +137,28 @@ public class TypeProviderImplTest { assertEquals("\"default value\"", typeProvider.getTypeDefaultConstruction(leafSchemaNode, "default value")); // binary type - final BinaryType binaryType = BinaryType.getInstance(); + final BinaryTypeDefinition binaryType = BaseTypes.binaryType(); leafSchemaNodeBuilder = new LeafSchemaNodeBuilder("test-module", 111, QName.create("Cont1"), SchemaPath.ROOT); leafSchemaNodeBuilder.setType(binaryType); leafSchemaNode = leafSchemaNodeBuilder.build(); assertEquals("new byte[] {-45}", typeProvider.getTypeDefaultConstruction(leafSchemaNode, "01")); // boolean type - final BooleanType booleanType = BooleanType.getInstance(); + final BooleanTypeDefinition booleanType = BaseTypes.booleanType(); leafSchemaNodeBuilder = new LeafSchemaNodeBuilder("test-module", 111, QName.create("Cont1"), SchemaPath.ROOT); leafSchemaNodeBuilder.setType(booleanType); leafSchemaNode = leafSchemaNodeBuilder.build(); assertEquals("new java.lang.Boolean(\"false\")", typeProvider.getTypeDefaultConstruction(leafSchemaNode, "false")); // decimal type - final Decimal64 decimalType = Decimal64.create(refTypePath, 4); + final DecimalTypeDefinition decimalType = BaseTypes.decimalTypeBuilder(refTypePath).setFractionDigits(4).build(); leafSchemaNodeBuilder = new LeafSchemaNodeBuilder("test-module", 111, QName.create("Cont1"), SchemaPath.ROOT); leafSchemaNodeBuilder.setType(decimalType); leafSchemaNode = leafSchemaNodeBuilder.build(); assertEquals("new java.math.BigDecimal(\"111\")", typeProvider.getTypeDefaultConstruction(leafSchemaNode, "111")); // empty type - final EmptyType emptyType = EmptyType.getInstance(); + final EmptyTypeDefinition emptyType = BaseTypes.emptyType(); leafSchemaNodeBuilder = new LeafSchemaNodeBuilder("test-module", 111, QName.create("Cont1"), SchemaPath.ROOT); leafSchemaNodeBuilder.setType(emptyType); leafSchemaNode = leafSchemaNodeBuilder.build(); @@ -169,7 +166,7 @@ public class TypeProviderImplTest { // enum type expException.expect(NoSuchElementException.class); - final EnumerationType enumType = EnumerationType.create(refTypePath, new ArrayList(), Optional. absent()); + final EnumTypeDefinition enumType = BaseTypes.enumerationTypeBuilder(refTypePath).build(); leafSchemaNodeBuilder = new LeafSchemaNodeBuilder("test-module", 111, QName.create("Cont1"), SchemaPath.ROOT); leafSchemaNodeBuilder.setType(enumType); leafSchemaNode = leafSchemaNodeBuilder.build(); @@ -182,7 +179,10 @@ public class TypeProviderImplTest { final ModuleBuilder testModBuilder = new ModuleBuilder("test-module", "/test"); final IdentitySchemaNodeBuilder identityNodeBuilder = testModBuilder.addIdentity(QName.create("IdentityRefTest"), 111, SchemaPath.ROOT); final IdentitySchemaNode identitySchemaNode = identityNodeBuilder.build(); - final IdentityrefType identityRef = IdentityrefType.create(refTypePath, identitySchemaNode); + + final IdentityrefTypeBuilder identityRefBuilder = BaseTypes.identityrefTypeBuilder(refTypePath); + identityRefBuilder.setIdentity(identitySchemaNode); + final IdentityrefTypeDefinition identityRef = identityRefBuilder.build(); leafSchemaNodeBuilder = new LeafSchemaNodeBuilder("test-module", 111, QName.create("Cont1"), SchemaPath.ROOT); leafSchemaNodeBuilder.setType(identityRef); diff --git a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/TypeProviderModel.java b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/TypeProviderModel.java index 4b8377deae..a2938d73cb 100644 --- a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/TypeProviderModel.java +++ b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/TypeProviderModel.java @@ -1,19 +1,20 @@ /* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2016 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.yangtools.sal.binding.yang.types; +import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; +import org.opendaylight.yangtools.yang.parser.spi.source.SourceException; + import java.io.InputStream; import java.util.ArrayList; import java.util.List; -import java.util.Set; -import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl; /** * Test Model Provider designated to load test resources and provide Schema Context @@ -42,9 +43,7 @@ final class TypeProviderModel { return arrayList; } - public static SchemaContext createTestContext() { - YangParserImpl parser = new YangParserImpl(); - Set modules = parser.parseYangModelsFromStreams(provideTestModelStreams()); - return parser.resolveSchemaContext(modules); + public static SchemaContext createTestContext() throws SourceException, ReactorException { + return RetestUtils.parseYangStreams(provideTestModelStreams()); } } diff --git a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/TypeProviderTest.java b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/TypeProviderTest.java index 004b007969..d39103bfd6 100644 --- a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/TypeProviderTest.java +++ b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/TypeProviderTest.java @@ -1,17 +1,17 @@ -/** - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. +/* + * Copyright (c) 2016 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.yangtools.sal.binding.yang.types; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import java.math.BigInteger; import java.util.List; import java.util.Set; import org.junit.Before; @@ -25,7 +25,6 @@ import org.opendaylight.yangtools.binding.generator.util.BindingGeneratorUtil; import org.opendaylight.yangtools.binding.generator.util.ReferencedTypeImpl; import org.opendaylight.yangtools.binding.generator.util.generated.type.builder.GeneratedTOBuilderImpl; import org.opendaylight.yangtools.sal.binding.generator.spi.TypeProvider; -import org.opendaylight.yangtools.sal.binding.model.api.BaseTypeWithRestrictions; import org.opendaylight.yangtools.sal.binding.model.api.ConcreteType; import org.opendaylight.yangtools.sal.binding.model.api.Enumeration; import org.opendaylight.yangtools.sal.binding.model.api.GeneratedTransferObject; @@ -45,6 +44,8 @@ import org.opendaylight.yangtools.yang.model.api.TypeDefinition; import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition; import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint; import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition; +import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; +import org.opendaylight.yangtools.yang.parser.spi.source.SourceException; /** * Test suite for testing public methods in TypeProviderImpl class @@ -67,7 +68,7 @@ public class TypeProviderTest { private SchemaNode schemaNode; @Before - public void setUp() { + public void setUp() throws SourceException, ReactorException { MockitoAnnotations.initMocks(this); schemaContext = TypeProviderModel.createTestContext(); assertNotNull(schemaContext); @@ -191,8 +192,8 @@ public class TypeProviderTest { assertTrue(!rangeConstraints.isEmpty()); final RangeConstraint constraint = rangeConstraints.get(0); - assertEquals(BigInteger.ONE, constraint.getMin()); - assertEquals(BigInteger.valueOf(100), constraint.getMax()); + assertEquals(1, constraint.getMin().intValue()); + assertEquals(100, constraint.getMax().intValue()); } @Test @@ -225,6 +226,10 @@ public class TypeProviderTest { return result; } + /** + * FIXME: Remove @Ignore annotation once the bug https://bugs.opendaylight.org/show_bug.cgi?id=1862 is fixed + */ + @Ignore @Test public void bug1862RestrictedTypedefTransformationTest() { final TypeProvider provider = new TypeProviderImpl(schemaContext); @@ -234,7 +239,8 @@ public class TypeProviderTest { final Restrictions restrictions = BindingGeneratorUtil.getRestrictions(leafType); final Type result = provider.javaTypeForSchemaDefinitionType(leafType, leaf, restrictions); assertNotNull(result); - assertTrue(result instanceof BaseTypeWithRestrictions); + assertTrue(result instanceof GeneratedTransferObject); + //TODO: complete test after bug 1862 is fixed } @Test @@ -312,7 +318,7 @@ public class TypeProviderTest { assertTrue(leafrefResolvedType2 instanceof ParameterizedType); } - private void setReferencedTypeForTypeProvider(TypeProvider provider) { + private void setReferencedTypeForTypeProvider(final TypeProvider provider) { final LeafSchemaNode enumLeafNode = provideLeafNodeFromTopLevelContainer(testTypeProviderModule, "foo", "resolve-direct-use-of-enum"); final TypeDefinition enumLeafTypedef = enumLeafNode.getType(); @@ -684,15 +690,15 @@ public class TypeProviderTest { GeneratedTOBuilder builder = new GeneratedTOBuilderImpl("test.package", "TestBuilder"); - provider.addUnitsToGenTO(builder, null); + TypeProviderImpl.addUnitsToGenTO(builder, null); GeneratedTransferObject genTO = builder.toInstance(); assertTrue(genTO.getConstantDefinitions().isEmpty()); - provider.addUnitsToGenTO(builder, ""); + TypeProviderImpl.addUnitsToGenTO(builder, ""); genTO = builder.toInstance(); assertTrue(genTO.getConstantDefinitions().isEmpty()); - provider.addUnitsToGenTO(builder, "125"); + TypeProviderImpl.addUnitsToGenTO(builder, "125"); genTO = builder.toInstance(); assertTrue(!genTO.getConstantDefinitions().isEmpty()); assertEquals(1, genTO.getConstantDefinitions().size()); diff --git a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/stmt/parser/retest/BaseYangTypesTest.java b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/stmt/parser/retest/BaseYangTypesTest.java deleted file mode 100644 index 858d810560..0000000000 --- a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/stmt/parser/retest/BaseYangTypesTest.java +++ /dev/null @@ -1,277 +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.yangtools.sal.binding.yang.types.stmt.parser.retest; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import java.io.InputStream; -import java.math.BigDecimal; -import java.math.BigInteger; -import java.util.Collections; -import java.util.List; -import java.util.Set; -import org.junit.BeforeClass; -import org.junit.Test; -import org.opendaylight.yangtools.binding.generator.util.BindingGeneratorUtil; -import org.opendaylight.yangtools.sal.binding.generator.spi.TypeProvider; -import org.opendaylight.yangtools.sal.binding.model.api.Type; -import org.opendaylight.yangtools.sal.binding.yang.types.BaseYangTypes; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.model.api.TypeDefinition; -import org.opendaylight.yangtools.yang.model.api.type.BinaryTypeDefinition; -import org.opendaylight.yangtools.yang.model.api.type.BooleanTypeDefinition; -import org.opendaylight.yangtools.yang.model.api.type.DecimalTypeDefinition; -import org.opendaylight.yangtools.yang.model.api.type.EmptyTypeDefinition; -import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition; -import org.opendaylight.yangtools.yang.model.api.type.IntegerTypeDefinition; -import org.opendaylight.yangtools.yang.model.api.type.StringTypeDefinition; -import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition; -import org.opendaylight.yangtools.yang.model.api.type.UnsignedIntegerTypeDefinition; -import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; -import org.opendaylight.yangtools.yang.parser.spi.source.SourceException; - -/** - * Test class for testing BaseYangTypes class. - * - * @author Lukas Sedlak <lsedlak@cisco.com> - */ -public class BaseYangTypesTest { - - private static SchemaContext schemaContext; - - private static BinaryTypeDefinition binary = null; - private static DecimalTypeDefinition decimal64 = null; - private static EnumTypeDefinition enumeration = null; - private static IntegerTypeDefinition int8 = null; - private static IntegerTypeDefinition int16 = null; - private static IntegerTypeDefinition int32 = null; - private static IntegerTypeDefinition int64 = null; - private static StringTypeDefinition string = null; - private static UnsignedIntegerTypeDefinition uint8 = null; - private static UnsignedIntegerTypeDefinition uint16 = null; - private static UnsignedIntegerTypeDefinition uint32 = null; - private static UnsignedIntegerTypeDefinition uint64 = null; - private static UnionTypeDefinition union = null; - private static EmptyTypeDefinition empty = null; - private static BooleanTypeDefinition bool = null; - - @BeforeClass - public static void setup() throws SourceException, ReactorException { - final List modelsToParse = Collections - .singletonList(BaseYangTypesTest.class.getResourceAsStream("/base-yang-types.yang")); - schemaContext = RetestUtils.parseYangStreams(modelsToParse); - assertNotNull(schemaContext); - initTypeDefinitionsFromSchemaContext(); - } - - private static void initTypeDefinitionsFromSchemaContext() { - Set> typedefs = schemaContext.getTypeDefinitions(); - assertTrue(!typedefs.isEmpty()); - - for (final TypeDefinition typedef : typedefs) { - assertNotNull(typedef); - - final TypeDefinition baseType = typedef.getBaseType(); - assertNotNull(baseType); - - if (baseType instanceof BinaryTypeDefinition) { - binary = (BinaryTypeDefinition) baseType; - } else if (baseType instanceof DecimalTypeDefinition) { - decimal64 = (DecimalTypeDefinition) baseType; - } else if (baseType instanceof EnumTypeDefinition) { - enumeration = (EnumTypeDefinition) baseType; - } else if (baseType instanceof IntegerTypeDefinition) { - String typeName = baseType.getQName().getLocalName(); - switch (typeName) { - case "int8": - int8 = (IntegerTypeDefinition) baseType; - break; - case "int16": - int16 = (IntegerTypeDefinition) baseType; - break; - case "int32": - int32 = (IntegerTypeDefinition) baseType; - break; - case "int64": - int64 = (IntegerTypeDefinition) baseType; - break; - } - } else if (baseType instanceof StringTypeDefinition) { - string = (StringTypeDefinition) baseType; - } else if (baseType instanceof UnsignedIntegerTypeDefinition) { - String typeName = baseType.getQName().getLocalName(); - switch (typeName) { - case "uint8": - uint8 = (UnsignedIntegerTypeDefinition) baseType; - break; - case "uint16": - uint16 = (UnsignedIntegerTypeDefinition) baseType; - break; - case "uint32": - uint32 = (UnsignedIntegerTypeDefinition) baseType; - break; - case "uint64": - uint64 = (UnsignedIntegerTypeDefinition) baseType; - break; - } - } else if (baseType instanceof UnionTypeDefinition) { - union = (UnionTypeDefinition) baseType; - } else if (baseType instanceof EmptyTypeDefinition) { - empty = (EmptyTypeDefinition) baseType; - } else if (baseType instanceof BooleanTypeDefinition) { - bool = (BooleanTypeDefinition) baseType; - } - } - assertNotNull(binary); - assertNotNull(decimal64); - assertNotNull(enumeration); - assertNotNull(int8); - assertNotNull(int16); - assertNotNull(int32); - assertNotNull(int64); - assertNotNull(string); - assertNotNull(uint8); - assertNotNull(uint16); - assertNotNull(uint32); - assertNotNull(uint64); - assertNotNull(union); - assertNotNull(empty); - assertNotNull(bool); - } - - @Test - public void javaTypeForSchemaDefinitionTypeTest() { - final TypeProvider typeProvider = BaseYangTypes.BASE_YANG_TYPES_PROVIDER; - - Type javaType = typeProvider.javaTypeForSchemaDefinitionType(binary, binary); - assertNotNull(javaType); - assertEquals("byte[]", javaType.getFullyQualifiedName()); - - javaType = typeProvider.javaTypeForSchemaDefinitionType(decimal64, decimal64); - assertNotNull(javaType); - assertEquals(BigDecimal.class.getCanonicalName(), javaType.getFullyQualifiedName()); - - javaType = typeProvider.javaTypeForSchemaDefinitionType(enumeration, enumeration); - assertNotNull(javaType); - assertEquals(Enum.class.getCanonicalName(), javaType.getFullyQualifiedName()); - - javaType = typeProvider.javaTypeForSchemaDefinitionType(int8, int8); - assertNotNull(javaType); - assertEquals(Byte.class.getCanonicalName(), javaType.getFullyQualifiedName()); - - javaType = typeProvider.javaTypeForSchemaDefinitionType(int16, int16); - assertNotNull(javaType); - assertEquals(Short.class.getCanonicalName(), javaType.getFullyQualifiedName()); - - javaType = typeProvider.javaTypeForSchemaDefinitionType(int32, int32); - assertNotNull(javaType); - assertEquals(Integer.class.getCanonicalName(), javaType.getFullyQualifiedName()); - - javaType = typeProvider.javaTypeForSchemaDefinitionType(int64, int64); - assertNotNull(javaType); - assertEquals(Long.class.getCanonicalName(), javaType.getFullyQualifiedName()); - - javaType = typeProvider.javaTypeForSchemaDefinitionType(string, string); - assertNotNull(javaType); - assertEquals(String.class.getCanonicalName(), javaType.getFullyQualifiedName()); - - javaType = typeProvider.javaTypeForSchemaDefinitionType(uint8, uint8); - assertNotNull(javaType); - assertEquals(Short.class.getCanonicalName(), javaType.getFullyQualifiedName()); - - javaType = typeProvider.javaTypeForSchemaDefinitionType(uint16, uint16); - assertNotNull(javaType); - assertEquals(Integer.class.getCanonicalName(), javaType.getFullyQualifiedName()); - - javaType = typeProvider.javaTypeForSchemaDefinitionType(uint32, uint32); - assertNotNull(javaType); - assertEquals(Long.class.getCanonicalName(), javaType.getFullyQualifiedName()); - - javaType = typeProvider.javaTypeForSchemaDefinitionType(uint64, uint64); - assertNotNull(javaType); - assertEquals(BigInteger.class.getCanonicalName(), javaType.getFullyQualifiedName()); - - javaType = typeProvider.javaTypeForSchemaDefinitionType(union, union); - assertNotNull(javaType); - assertEquals("Union", javaType.getFullyQualifiedName()); - - javaType = typeProvider.javaTypeForSchemaDefinitionType(empty, empty); - assertNotNull(javaType); - assertEquals(Boolean.class.getCanonicalName(), javaType.getFullyQualifiedName()); - - javaType = typeProvider.javaTypeForSchemaDefinitionType(bool, bool); - assertNotNull(javaType); - assertEquals(Boolean.class.getCanonicalName(), javaType.getFullyQualifiedName()); - } - - @Test - public void javaTypeForRestrictedSchemaDefinitionTypeTest() { - final TypeProvider typeProvider = BaseYangTypes.BASE_YANG_TYPES_PROVIDER; - - Type javaType = typeProvider.javaTypeForSchemaDefinitionType(binary, binary, BindingGeneratorUtil.getRestrictions(binary)); - assertNotNull(javaType); - assertEquals("byte[]", javaType.getFullyQualifiedName()); - - javaType = typeProvider.javaTypeForSchemaDefinitionType(decimal64, decimal64, BindingGeneratorUtil.getRestrictions(decimal64)); - assertNotNull(javaType); - assertEquals(BigDecimal.class.getCanonicalName(), javaType.getFullyQualifiedName()); - - javaType = typeProvider.javaTypeForSchemaDefinitionType(enumeration, enumeration, BindingGeneratorUtil.getRestrictions(enumeration)); - assertNotNull(javaType); - assertEquals(Enum.class.getCanonicalName(), javaType.getFullyQualifiedName()); - - javaType = typeProvider.javaTypeForSchemaDefinitionType(int8, int8, BindingGeneratorUtil.getRestrictions(int8)); - assertNotNull(javaType); - assertEquals(Byte.class.getCanonicalName(), javaType.getFullyQualifiedName()); - - javaType = typeProvider.javaTypeForSchemaDefinitionType(int16, int16, BindingGeneratorUtil.getRestrictions(int16)); - assertNotNull(javaType); - assertEquals(Short.class.getCanonicalName(), javaType.getFullyQualifiedName()); - - javaType = typeProvider.javaTypeForSchemaDefinitionType(int32, int32, BindingGeneratorUtil.getRestrictions(int32)); - assertNotNull(javaType); - assertEquals(Integer.class.getCanonicalName(), javaType.getFullyQualifiedName()); - - javaType = typeProvider.javaTypeForSchemaDefinitionType(int64, int64, BindingGeneratorUtil.getRestrictions(int64)); - assertNotNull(javaType); - assertEquals(Long.class.getCanonicalName(), javaType.getFullyQualifiedName()); - - javaType = typeProvider.javaTypeForSchemaDefinitionType(string, string, BindingGeneratorUtil.getRestrictions(string)); - assertNotNull(javaType); - assertEquals(String.class.getCanonicalName(), javaType.getFullyQualifiedName()); - - javaType = typeProvider.javaTypeForSchemaDefinitionType(uint8, uint8, BindingGeneratorUtil.getRestrictions(uint8)); - assertNotNull(javaType); - assertEquals(Short.class.getCanonicalName(), javaType.getFullyQualifiedName()); - - javaType = typeProvider.javaTypeForSchemaDefinitionType(uint16, uint16, BindingGeneratorUtil.getRestrictions(uint16)); - assertNotNull(javaType); - assertEquals(Integer.class.getCanonicalName(), javaType.getFullyQualifiedName()); - - javaType = typeProvider.javaTypeForSchemaDefinitionType(uint32, uint32, BindingGeneratorUtil.getRestrictions(uint32)); - assertNotNull(javaType); - assertEquals(Long.class.getCanonicalName(), javaType.getFullyQualifiedName()); - - javaType = typeProvider.javaTypeForSchemaDefinitionType(uint64, uint64, BindingGeneratorUtil.getRestrictions(uint64)); - assertNotNull(javaType); - assertEquals(BigInteger.class.getCanonicalName(), javaType.getFullyQualifiedName()); - - javaType = typeProvider.javaTypeForSchemaDefinitionType(union, union, BindingGeneratorUtil.getRestrictions(union)); - assertNotNull(javaType); - assertEquals("Union", javaType.getFullyQualifiedName()); - - javaType = typeProvider.javaTypeForSchemaDefinitionType(empty, empty, BindingGeneratorUtil.getRestrictions(empty)); - assertNotNull(javaType); - assertEquals(Boolean.class.getCanonicalName(), javaType.getFullyQualifiedName()); - - javaType = typeProvider.javaTypeForSchemaDefinitionType(bool, bool, BindingGeneratorUtil.getRestrictions(bool)); - assertNotNull(javaType); - assertEquals(Boolean.class.getCanonicalName(), javaType.getFullyQualifiedName()); - } -} diff --git a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/stmt/parser/retest/LeafrefTypeWithNullToStringInXpath.java b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/stmt/parser/retest/LeafrefTypeWithNullToStringInXpath.java deleted file mode 100644 index 561454bd55..0000000000 --- a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/stmt/parser/retest/LeafrefTypeWithNullToStringInXpath.java +++ /dev/null @@ -1,76 +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.yangtools.sal.binding.yang.types.stmt.parser.retest; - -import java.util.List; -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath; -import org.opendaylight.yangtools.yang.model.api.SchemaPath; -import org.opendaylight.yangtools.yang.model.api.Status; -import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode; -import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition; - -/** - * Mock LeafrefDypeDefinition implementation with non-null referenced RevisionAwareXPath. - * - * Although RevisionAwareXPath has implemented Override for toString to return null value to reach specific branch - * in TypeProviderImpl#provideTypeForLeafref method. - * - * Created by lukas on 9/17/14. - */ -public class LeafrefTypeWithNullToStringInXpath implements LeafrefTypeDefinition { - @Override public RevisionAwareXPath getPathStatement() { - return new RevisionAwareXPath() { - @Override - public boolean isAbsolute() { - return false; - } - - @Override - public String toString() { - return null; - } - }; - } - - @Override public LeafrefTypeDefinition getBaseType() { - return null; - } - - @Override public String getUnits() { - return null; - } - - @Override public Object getDefaultValue() { - return null; - } - - @Override public QName getQName() { - return null; - } - - @Override public SchemaPath getPath() { - return null; - } - - @Override public List getUnknownSchemaNodes() { - return null; - } - - @Override public String getDescription() { - return null; - } - - @Override public String getReference() { - return null; - } - - @Override public Status getStatus() { - return null; - } -} diff --git a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/stmt/parser/retest/LeafrefTypeWithNullXpath.java b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/stmt/parser/retest/LeafrefTypeWithNullXpath.java deleted file mode 100644 index 241ff18b12..0000000000 --- a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/stmt/parser/retest/LeafrefTypeWithNullXpath.java +++ /dev/null @@ -1,63 +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.yangtools.sal.binding.yang.types.stmt.parser.retest; - -import java.util.List; -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath; -import org.opendaylight.yangtools.yang.model.api.SchemaPath; -import org.opendaylight.yangtools.yang.model.api.Status; -import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode; -import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition; - -/** - * Mock LeafrefDypeDefinition implementation with RevisionAwareXPath null reference - * - * @author Lukas Sedlak <lsedlak@cisco.com> - */ -public class LeafrefTypeWithNullXpath implements LeafrefTypeDefinition { - @Override public RevisionAwareXPath getPathStatement() { - return null; - } - - @Override public LeafrefTypeDefinition getBaseType() { - return null; - } - - @Override public String getUnits() { - return null; - } - - @Override public Object getDefaultValue() { - return null; - } - - @Override public QName getQName() { - return null; - } - - @Override public SchemaPath getPath() { - return null; - } - - @Override public List getUnknownSchemaNodes() { - return null; - } - - @Override public String getDescription() { - return null; - } - - @Override public String getReference() { - return null; - } - - @Override public Status getStatus() { - return null; - } -} diff --git a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/stmt/parser/retest/TestIntegerTypeDefinition.java b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/stmt/parser/retest/TestIntegerTypeDefinition.java deleted file mode 100644 index 9277a431f2..0000000000 --- a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/stmt/parser/retest/TestIntegerTypeDefinition.java +++ /dev/null @@ -1,64 +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.yangtools.sal.binding.yang.types.stmt.parser.retest; - -import java.util.List; -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.model.api.SchemaPath; -import org.opendaylight.yangtools.yang.model.api.Status; -import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode; -import org.opendaylight.yangtools.yang.model.api.type.IntegerTypeDefinition; -import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint; - -/** - * Mock Integer Type Definition designated to increase branch coverage in test cases. - * - * @author Lukas Sedlak <lsedlak@cisco.com> - */ -final class TestIntegerTypeDefinition implements IntegerTypeDefinition { - - @Override public List getRangeConstraints() { - return null; - } - - @Override public IntegerTypeDefinition getBaseType() { - return null; - } - - @Override public String getUnits() { - return null; - } - - @Override public Object getDefaultValue() { - return null; - } - - @Override public QName getQName() { - return null; - } - - @Override public SchemaPath getPath() { - return null; - } - - @Override public List getUnknownSchemaNodes() { - return null; - } - - @Override public String getDescription() { - return null; - } - - @Override public String getReference() { - return null; - } - - @Override public Status getStatus() { - return null; - } -} diff --git a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/stmt/parser/retest/TestLeafSchemaNode.java b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/stmt/parser/retest/TestLeafSchemaNode.java deleted file mode 100644 index 0f6d451b1c..0000000000 --- a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/stmt/parser/retest/TestLeafSchemaNode.java +++ /dev/null @@ -1,71 +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.yangtools.sal.binding.yang.types.stmt.parser.retest; - -import java.util.List; -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.model.api.*; - -/** - * Mock Leaf Schema Node designated to increase branch coverage in test cases. - * - * @author Lukas Sedlak <lsedlak@cisco.com> - */ -public class TestLeafSchemaNode implements LeafSchemaNode { - @Override public TypeDefinition getType() { - return null; - } - - @Override public String getDefault() { - return null; - } - - @Override public String getUnits() { - return null; - } - - @Override public boolean isAugmenting() { - return false; - } - - @Override public boolean isAddedByUses() { - return false; - } - - @Override public boolean isConfiguration() { - return false; - } - - @Override public ConstraintDefinition getConstraints() { - return null; - } - - @Override public QName getQName() { - return null; - } - - @Override public SchemaPath getPath() { - return null; - } - - @Override public List getUnknownSchemaNodes() { - return null; - } - - @Override public String getDescription() { - return null; - } - - @Override public String getReference() { - return null; - } - - @Override public Status getStatus() { - return null; - } -} diff --git a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/stmt/parser/retest/TypeProviderImplTest.java b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/stmt/parser/retest/TypeProviderImplTest.java deleted file mode 100644 index ae765478b2..0000000000 --- a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/stmt/parser/retest/TypeProviderImplTest.java +++ /dev/null @@ -1,193 +0,0 @@ -/* - * 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.yangtools.sal.binding.yang.types.stmt.parser.retest; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import java.io.File; -import java.io.FileNotFoundException; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.NoSuchElementException; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.opendaylight.yangtools.binding.generator.util.generated.type.builder.GeneratedTypeBuilderImpl; -import org.opendaylight.yangtools.sal.binding.model.api.Type; -import org.opendaylight.yangtools.sal.binding.yang.types.TypeProviderImpl; -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; -import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode; -import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode; -import org.opendaylight.yangtools.yang.model.api.ListSchemaNode; -import org.opendaylight.yangtools.yang.model.api.Module; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.model.api.SchemaPath; -import org.opendaylight.yangtools.yang.model.api.TypeDefinition; -import org.opendaylight.yangtools.yang.model.api.type.BinaryTypeDefinition; -import org.opendaylight.yangtools.yang.model.api.type.BooleanTypeDefinition; -import org.opendaylight.yangtools.yang.model.api.type.DecimalTypeDefinition; -import org.opendaylight.yangtools.yang.model.api.type.EmptyTypeDefinition; -import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition; -import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition; -import org.opendaylight.yangtools.yang.model.api.type.StringTypeDefinition; -import org.opendaylight.yangtools.yang.model.util.type.BaseTypes; -import org.opendaylight.yangtools.yang.model.util.type.IdentityrefTypeBuilder; -import org.opendaylight.yangtools.yang.parser.builder.impl.IdentitySchemaNodeBuilder; -import org.opendaylight.yangtools.yang.parser.builder.impl.LeafSchemaNodeBuilder; -import org.opendaylight.yangtools.yang.parser.builder.impl.ModuleBuilder; -import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; -import org.opendaylight.yangtools.yang.parser.spi.source.SourceException; -import org.opendaylight.yangtools.yang.parser.util.YangValidationException; - -public class TypeProviderImplTest { - - @Rule - public ExpectedException expException = ExpectedException.none(); - - @Test (expected = YangValidationException.class) - public void testLeafRefRelativeSelfReference() throws Exception { - File relative = new File(getClass().getResource("/leafref/leafref-relative-invalid.yang").toURI()); - - final SchemaContext schemaContext = RetestUtils.parseYangSources(relative); - final Module moduleRelative = schemaContext.findModuleByNamespace(new URI("urn:xml:ns:yang:lrr")).iterator().next(); - final TypeProviderImpl typeProvider = new TypeProviderImpl(schemaContext); - - DataSchemaNode leafref = ((ListSchemaNode) moduleRelative.getDataChildByName("neighbor")).getDataChildByName("neighbor-id"); - LeafSchemaNode leaf = (LeafSchemaNode) leafref; - TypeDefinition leafType = leaf.getType(); - Type leafrefResolvedType = typeProvider.javaTypeForSchemaDefinitionType(leafType, leaf); - } - - @Test (expected = YangValidationException.class) - public void testLeafRefAbsoluteSelfReference() throws Exception { - File relative = new File(getClass().getResource("/leafref/leafref-absolute-invalid.yang").toURI()); - - final SchemaContext schemaContext = RetestUtils.parseYangSources(relative); - final Module moduleRelative = schemaContext.findModuleByNamespace(new URI("urn:xml:ns:yang:lra")).iterator().next(); - final TypeProviderImpl typeProvider = new TypeProviderImpl(schemaContext); - - DataSchemaNode leafref = ((ListSchemaNode) moduleRelative.getDataChildByName("neighbor")).getDataChildByName("neighbor-id"); - LeafSchemaNode leaf = (LeafSchemaNode) leafref; - TypeDefinition leafType = leaf.getType(); - Type leafrefResolvedType = typeProvider.javaTypeForSchemaDefinitionType(leafType, leaf); - } - - @Test - public void testLeafRefRelativeAndAbsoluteValidReference() throws URISyntaxException, SourceException, FileNotFoundException, ReactorException { - File valid = new File(getClass().getResource("/leafref/leafref-valid.yang").toURI()); - - final SchemaContext schemaContext = RetestUtils.parseYangSources(valid); - final Module moduleValid = schemaContext.findModuleByNamespace(new URI("urn:xml:ns:yang:lrv")).iterator().next(); - final TypeProviderImpl typeProvider = new TypeProviderImpl(schemaContext); - - DataSchemaNode leafrefRel = ((ListSchemaNode) moduleValid.getDataChildByName("neighbor")).getDataChildByName - ("neighbor-id"); - LeafSchemaNode leafRel = (LeafSchemaNode) leafrefRel; - TypeDefinition leafTypeRel = leafRel.getType(); - Type leafrefRelResolvedType = typeProvider.javaTypeForSchemaDefinitionType(leafTypeRel, leafRel); - assertNotNull(leafrefRelResolvedType); - - DataSchemaNode leafrefAbs = ((ListSchemaNode) moduleValid.getDataChildByName("neighbor")).getDataChildByName - ("neighbor2-id"); - LeafSchemaNode leafAbs = (LeafSchemaNode) leafrefAbs; - TypeDefinition leafTypeAbs = leafAbs.getType(); - Type leafrefAbsResolvedType = typeProvider.javaTypeForSchemaDefinitionType(leafTypeAbs, leafAbs); - assertNotNull(leafrefAbsResolvedType); - } - - @Test - public void testMethodsOfTypeProviderImpl() throws URISyntaxException, SourceException, FileNotFoundException, ReactorException { - final File abstractTopology = new File(getClass().getResource("/base-yang-types.yang") - .toURI()); - - final SchemaContext schemaContext = RetestUtils.parseYangSources(abstractTopology); - - final TypeProviderImpl typeProvider = new TypeProviderImpl(schemaContext); - - final SchemaPath refTypePath = SchemaPath.create(true, QName.create("cont1"), QName.create("list1")); - final GeneratedTypeBuilderImpl refType = new GeneratedTypeBuilderImpl("org.opendaylight.yangtools.test", "TestType"); - typeProvider.putReferencedType(refTypePath, refType); - final StringTypeDefinition stringType = BaseTypes.stringType(); - LeafSchemaNodeBuilder leafSchemaNodeBuilder = new LeafSchemaNodeBuilder("test-module", 111, QName.create("Cont1"), SchemaPath.ROOT); - leafSchemaNodeBuilder.setType(stringType); - LeafSchemaNode leafSchemaNode = leafSchemaNodeBuilder.build(); - - // test constructor - assertNotNull(typeProvider); - - // test getAdditionalTypes() method - assertFalse(typeProvider.getAdditionalTypes().isEmpty()); - - // test getConstructorPropertyName() method - assertTrue(typeProvider.getConstructorPropertyName(null).isEmpty()); - assertEquals("value", typeProvider.getConstructorPropertyName(stringType)); - - // test getParamNameFromType() method - assertEquals("string", typeProvider.getParamNameFromType(stringType)); - - // test getTypeDefaultConstruction() method for string type - assertEquals("\"default value\"", typeProvider.getTypeDefaultConstruction(leafSchemaNode, "default value")); - - // binary type - final BinaryTypeDefinition binaryType = BaseTypes.binaryType(); - leafSchemaNodeBuilder = new LeafSchemaNodeBuilder("test-module", 111, QName.create("Cont1"), SchemaPath.ROOT); - leafSchemaNodeBuilder.setType(binaryType); - leafSchemaNode = leafSchemaNodeBuilder.build(); - assertEquals("new byte[] {-45}", typeProvider.getTypeDefaultConstruction(leafSchemaNode, "01")); - - // boolean type - final BooleanTypeDefinition booleanType = BaseTypes.booleanType(); - leafSchemaNodeBuilder = new LeafSchemaNodeBuilder("test-module", 111, QName.create("Cont1"), SchemaPath.ROOT); - leafSchemaNodeBuilder.setType(booleanType); - leafSchemaNode = leafSchemaNodeBuilder.build(); - assertEquals("new java.lang.Boolean(\"false\")", typeProvider.getTypeDefaultConstruction(leafSchemaNode, "false")); - - // decimal type - final DecimalTypeDefinition decimalType = BaseTypes.decimalTypeBuilder(refTypePath).setFractionDigits(4).build(); - leafSchemaNodeBuilder = new LeafSchemaNodeBuilder("test-module", 111, QName.create("Cont1"), SchemaPath.ROOT); - leafSchemaNodeBuilder.setType(decimalType); - leafSchemaNode = leafSchemaNodeBuilder.build(); - assertEquals("new java.math.BigDecimal(\"111\")", typeProvider.getTypeDefaultConstruction(leafSchemaNode, "111")); - - // empty type - final EmptyTypeDefinition emptyType = BaseTypes.emptyType(); - leafSchemaNodeBuilder = new LeafSchemaNodeBuilder("test-module", 111, QName.create("Cont1"), SchemaPath.ROOT); - leafSchemaNodeBuilder.setType(emptyType); - leafSchemaNode = leafSchemaNodeBuilder.build(); - assertEquals("new java.lang.Boolean(\"default value\")", typeProvider.getTypeDefaultConstruction(leafSchemaNode, "default value")); - - // enum type - expException.expect(NoSuchElementException.class); - final EnumTypeDefinition enumType = BaseTypes.enumerationTypeBuilder(refTypePath).build(); - leafSchemaNodeBuilder = new LeafSchemaNodeBuilder("test-module", 111, QName.create("Cont1"), SchemaPath.ROOT); - leafSchemaNodeBuilder.setType(enumType); - leafSchemaNode = leafSchemaNodeBuilder.build(); - assertEquals("\"default value\"", typeProvider.getTypeDefaultConstruction(leafSchemaNode, "default value")); - - // identityref type - expException.expect(UnsupportedOperationException.class); - expException.expectMessage("Cannot get default construction for identityref type"); - - final ModuleBuilder testModBuilder = new ModuleBuilder("test-module", "/test"); - final IdentitySchemaNodeBuilder identityNodeBuilder = testModBuilder.addIdentity(QName.create("IdentityRefTest"), 111, SchemaPath.ROOT); - final IdentitySchemaNode identitySchemaNode = identityNodeBuilder.build(); - - final IdentityrefTypeBuilder identityRefBuilder = BaseTypes.identityrefTypeBuilder(refTypePath); - identityRefBuilder.setIdentity(identitySchemaNode); - final IdentityrefTypeDefinition identityRef = identityRefBuilder.build(); - leafSchemaNodeBuilder = new LeafSchemaNodeBuilder("test-module", 111, QName.create("Cont1"), SchemaPath.ROOT); - leafSchemaNodeBuilder.setType(identityRef); - - leafSchemaNodeBuilder.setParent(identityNodeBuilder); - leafSchemaNode = leafSchemaNodeBuilder.build(); - assertEquals("\"default value\"", typeProvider.getTypeDefaultConstruction(leafSchemaNode, "default value")); - } -} diff --git a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/stmt/parser/retest/TypeProviderModel.java b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/stmt/parser/retest/TypeProviderModel.java deleted file mode 100644 index 61ebc106f4..0000000000 --- a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/stmt/parser/retest/TypeProviderModel.java +++ /dev/null @@ -1,48 +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.yangtools.sal.binding.yang.types.stmt.parser.retest; - -import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; -import org.opendaylight.yangtools.yang.parser.spi.source.SourceException; - -import java.io.InputStream; -import java.util.ArrayList; -import java.util.List; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; - -/** - * Test Model Provider designated to load test resources and provide Schema Context - * for testing of TypeProviderImpl - * - * @author Lukas Sedlak <lsedlak@cisco.com> - */ -final class TypeProviderModel { - - public static final String TEST_TYPE_PROVIDER_MODULE_NAME = "test-type-provider"; - - private static final String BASE_YANG_TYPES_PATH = "/base-yang-types.yang"; - private static final String TEST_TYPE_PROVIDER_PATH = "/"+TEST_TYPE_PROVIDER_MODULE_NAME+".yang"; - private static final String TEST_TYPE_PROVIDER_B_PATH = "/test-type-provider-b.yang"; - - private static InputStream getInputStream(final String resourceName) { - return TypeProviderModel.class.getResourceAsStream(resourceName); - } - - private static List provideTestModelStreams() { - final List arrayList = new ArrayList<>(); - - arrayList.add(getInputStream(BASE_YANG_TYPES_PATH)); - arrayList.add(getInputStream(TEST_TYPE_PROVIDER_PATH)); - arrayList.add(getInputStream(TEST_TYPE_PROVIDER_B_PATH)); - return arrayList; - } - - public static SchemaContext createTestContext() throws SourceException, ReactorException { - return RetestUtils.parseYangStreams(provideTestModelStreams()); - } -} diff --git a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/stmt/parser/retest/TypeProviderTest.java b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/stmt/parser/retest/TypeProviderTest.java deleted file mode 100644 index 0e5b9522dd..0000000000 --- a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/stmt/parser/retest/TypeProviderTest.java +++ /dev/null @@ -1,938 +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.yangtools.sal.binding.yang.types.stmt.parser.retest; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import java.util.List; -import java.util.Set; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.opendaylight.yangtools.binding.generator.util.BindingGeneratorUtil; -import org.opendaylight.yangtools.binding.generator.util.ReferencedTypeImpl; -import org.opendaylight.yangtools.binding.generator.util.generated.type.builder.GeneratedTOBuilderImpl; -import org.opendaylight.yangtools.sal.binding.generator.spi.TypeProvider; -import org.opendaylight.yangtools.sal.binding.model.api.ConcreteType; -import org.opendaylight.yangtools.sal.binding.model.api.Enumeration; -import org.opendaylight.yangtools.sal.binding.model.api.GeneratedTransferObject; -import org.opendaylight.yangtools.sal.binding.model.api.ParameterizedType; -import org.opendaylight.yangtools.sal.binding.model.api.Restrictions; -import org.opendaylight.yangtools.sal.binding.model.api.Type; -import org.opendaylight.yangtools.sal.binding.model.api.type.builder.GeneratedTOBuilder; -import org.opendaylight.yangtools.sal.binding.yang.types.TypeProviderImpl; -import org.opendaylight.yangtools.yang.model.api.DataNodeContainer; -import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; -import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode; -import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode; -import org.opendaylight.yangtools.yang.model.api.Module; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.model.api.SchemaNode; -import org.opendaylight.yangtools.yang.model.api.SchemaPath; -import org.opendaylight.yangtools.yang.model.api.TypeDefinition; -import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition; -import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint; -import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition; -import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; -import org.opendaylight.yangtools.yang.parser.spi.source.SourceException; - -/** - * Test suite for testing public methods in TypeProviderImpl class - * - * @see org.opendaylight.yangtools.sal.binding.yang.types.TypeProviderImpl - * - * @author Lukas Sedlak <lsedlak@cisco.com> - */ -@RunWith(JUnit4.class) -public class TypeProviderTest { - - private SchemaContext schemaContext; - private Set schemaModules; - private Module testTypeProviderModule; - - @Mock - private SchemaPath schemaPath; - - @Mock - private SchemaNode schemaNode; - - @Before - public void setUp() throws SourceException, ReactorException { - MockitoAnnotations.initMocks(this); - schemaContext = TypeProviderModel.createTestContext(); - assertNotNull(schemaContext); - schemaModules = schemaContext.getModules(); - assertNotNull(schemaModules); - testTypeProviderModule = resolveModule(TypeProviderModel.TEST_TYPE_PROVIDER_MODULE_NAME); - assertNotNull(testTypeProviderModule); - } - - private Module resolveModule(final String moduleName) { - assertNotNull(moduleName); - for (Module m : schemaModules) { - if (moduleName.equals(m.getName())) { - return m; - } - } - assertTrue("Unable to resolve module " + moduleName + ". No module present within Schema Context!" , false); - return null; - } - - @Test(expected = IllegalArgumentException.class) - public void typeProviderInstanceWithNullSchemaContextTest() { - final TypeProvider provider = new TypeProviderImpl(null); - } - - @Test(expected = IllegalArgumentException.class) - public void putReferencedTypeWithNullSchemaPathParamTest() { - final TypeProvider provider = new TypeProviderImpl(schemaContext); - - ((TypeProviderImpl) provider).putReferencedType(null, null); - ((TypeProviderImpl) provider).putReferencedType(schemaPath, null); - } - - @Test(expected = IllegalArgumentException.class) - public void putReferencedTypeWithNullRefTypeParamTest() { - final TypeProvider provider = new TypeProviderImpl(schemaContext); - - ((TypeProviderImpl) provider).putReferencedType(schemaPath, null); - } - - @Test - public void getAdditionalTypesTest() { - final TypeProvider provider = new TypeProviderImpl(schemaContext); - - assertNotNull(((TypeProviderImpl) provider).getAdditionalTypes()); - } - - @Test(expected = IllegalArgumentException.class) - public void javaTypeForSchemaDefinitionTypeNullTypedefTest() { - final TypeProvider provider = new TypeProviderImpl(schemaContext); - - provider.javaTypeForSchemaDefinitionType(null, null, null); - } - - @Test(expected = IllegalArgumentException.class) - public void javaTypeForSchemaDefinitionTypeTypedefNullQNameTest() { - final TypeProvider provider = new TypeProviderImpl(schemaContext); - - TestIntegerTypeDefinition testTypedef = new TestIntegerTypeDefinition(); - provider.javaTypeForSchemaDefinitionType(testTypedef, null, null); - } - - private static LeafSchemaNode provideLeafNodeFromTopLevelContainer(final Module module, final String containerName, final String leafNodeName) { - final DataSchemaNode rootNode = module.getDataChildByName(containerName); - assertNotNull("Container foo is not present in root of module "+ module.getName(), rootNode); - assertTrue(rootNode instanceof DataNodeContainer); - - final DataNodeContainer rootContainer = (DataNodeContainer) rootNode; - final DataSchemaNode node = rootContainer.getDataChildByName(leafNodeName); - assertNotNull(node); - assertTrue(node instanceof LeafSchemaNode); - return (LeafSchemaNode) node; - } - - private static LeafListSchemaNode provideLeafListNodeFromTopLevelContainer(final Module module, final String containerName, final String leafListNodeName) { - final DataSchemaNode rootNode = module.getDataChildByName(containerName); - assertNotNull("Container foo is not present in root of module " + module.getName(), rootNode); - assertTrue(rootNode instanceof DataNodeContainer); - - final DataNodeContainer rootContainer = (DataNodeContainer) rootNode; - final DataSchemaNode node = rootContainer.getDataChildByName(leafListNodeName); - assertNotNull(node); - assertTrue(node instanceof LeafListSchemaNode); - return (LeafListSchemaNode) node; - } - - @Test - public void javaTypeForSchemaDefinitionExtTypeTest() { - final TypeProvider provider = new TypeProviderImpl(schemaContext); - final LeafSchemaNode leaf = provideLeafNodeFromTopLevelContainer(testTypeProviderModule, "foo", "yang-int8-type"); - - final TypeDefinition leafType = leaf.getType(); - final Type result = provider.javaTypeForSchemaDefinitionType(leafType, leaf); - assertNotNull(result); - assertTrue(result instanceof GeneratedTransferObject); - - final GeneratedTransferObject genTO = (GeneratedTransferObject) result; - assertEquals("base-yang-types", genTO.getModuleName()); - assertEquals("org.opendaylight.yang.gen.v1.urn.opendaylight.org.test.base.yang.types.rev140914", genTO.getPackageName()); - assertEquals("YangInt8", genTO.getName()); - assertTrue(genTO.getProperties().size() == 1); - } - - @Test - public void javaTypeForSchemaDefinitionRestrictedExtTypeTest() { - final TypeProvider provider = new TypeProviderImpl(schemaContext); - final LeafSchemaNode leaf = provideLeafNodeFromTopLevelContainer(testTypeProviderModule, "foo", "restricted-int8-type"); - - final TypeDefinition leafType = leaf.getType(); - final Restrictions restrictions = BindingGeneratorUtil.getRestrictions(leafType); - - final Type result = provider.javaTypeForSchemaDefinitionType(leafType, leaf, restrictions); - assertNotNull(result); - assertTrue(result instanceof GeneratedTransferObject); - - final GeneratedTransferObject genTO = (GeneratedTransferObject) result; - assertEquals("org.opendaylight.yang.gen.v1.urn.opendaylight.org.test.base.yang.types.rev140914", genTO.getPackageName()); - assertEquals("YangInt8Restricted", genTO.getName()); - assertTrue(genTO.getProperties().size() == 1); - final List rangeConstraints = genTO.getRestrictions().getRangeConstraints(); - - assertTrue(!rangeConstraints.isEmpty()); - final RangeConstraint constraint = rangeConstraints.get(0); - assertEquals(1, constraint.getMin().intValue()); - assertEquals(100, constraint.getMax().intValue()); - } - - @Test - public void javaTypeForSchemaDefinitionEmptyStringPatternTypeTest() { - final TypeProviderImpl provider = new TypeProviderImpl(schemaContext); - - final Module testTypeProvider = resolveModule("test-type-provider"); - final TypeDefinition emptyPatternString = resolveTypeDefinitionFromModule(testTypeProvider, "empty-pattern-string"); - - assertNotNull(emptyPatternString); - final Restrictions restrictions = BindingGeneratorUtil.getRestrictions(emptyPatternString); - - Type result = provider.javaTypeForSchemaDefinitionType(emptyPatternString, emptyPatternString, restrictions); - assertNotNull(result); - assertTrue(result instanceof GeneratedTransferObject); - - result = provider.generatedTypeForExtendedDefinitionType(emptyPatternString, emptyPatternString); - assertNotNull(result); - assertTrue(result instanceof GeneratedTransferObject); - } - - private static TypeDefinition resolveTypeDefinitionFromModule(final Module module, final String typedefName) { - TypeDefinition result = null; - final Set> typeDefs = module.getTypeDefinitions(); - for (final TypeDefinition typedef : typeDefs) { - if (typedef.getQName().getLocalName().equals(typedefName)) { - result = typedef; - } - } - return result; - } - - /** - * FIXME: Remove @Ignore annotation once the bug https://bugs.opendaylight.org/show_bug.cgi?id=1862 is fixed - */ - @Ignore - @Test - public void bug1862RestrictedTypedefTransformationTest() { - final TypeProvider provider = new TypeProviderImpl(schemaContext); - final LeafSchemaNode leaf = provideLeafNodeFromTopLevelContainer(testTypeProviderModule, "foo", "bug-1862-restricted-typedef"); - - final TypeDefinition leafType = leaf.getType(); - final Restrictions restrictions = BindingGeneratorUtil.getRestrictions(leafType); - final Type result = provider.javaTypeForSchemaDefinitionType(leafType, leaf, restrictions); - assertNotNull(result); - assertTrue(result instanceof GeneratedTransferObject); - //TODO: complete test after bug 1862 is fixed - } - - @Test - public void javaTypeForSchemaDefinitionEnumExtTypeTest() { - final TypeProvider provider = new TypeProviderImpl(schemaContext); - LeafSchemaNode leaf = provideLeafNodeFromTopLevelContainer(testTypeProviderModule, "foo", "resolve-enum-leaf"); - TypeDefinition leafType = leaf.getType(); - Type result = provider.javaTypeForSchemaDefinitionType(leafType, leaf); - assertNotNull(result); - assertTrue(result instanceof Enumeration); - - final Enumeration enumType = (Enumeration) result; - final List enumValues = enumType.getValues(); - assertTrue(!enumValues.isEmpty()); - assertEquals("A", enumValues.get(0).getName()); - assertEquals("B", enumValues.get(1).getName()); - - leaf = provideLeafNodeFromTopLevelContainer(testTypeProviderModule, "foo", "resolve-direct-use-of-enum"); - leafType = leaf.getType(); - result = provider.javaTypeForSchemaDefinitionType(leafType, leaf); - assertNotNull(result); - assertTrue(result instanceof ConcreteType); - - assertEquals("java.lang", result.getPackageName()); - assertEquals("Enum", result.getName()); - } - - @Test - public void javaTypeForSchemaDefinitionLeafrefExtTypeTest() { - final TypeProvider provider = new TypeProviderImpl(schemaContext); - LeafSchemaNode leaf = provideLeafNodeFromTopLevelContainer(testTypeProviderModule, "bar", "leafref-value"); - TypeDefinition leafType = leaf.getType(); - final Type leafrefResolvedType1 = provider.javaTypeForSchemaDefinitionType(leafType, leaf); - assertNotNull(leafrefResolvedType1); - assertTrue(leafrefResolvedType1 instanceof GeneratedTransferObject); - - final Module module = resolveModule("test-type-provider-b"); - final DataSchemaNode rootNode = module.getDataChildByName("id"); - assertNotNull("leaf id is not present in root of module "+ module.getName(), rootNode); - assertTrue(rootNode instanceof LeafSchemaNode); - leaf = (LeafSchemaNode) rootNode; - leafType = leaf.getType(); - - final Type leafrefResolvedType2 = provider.javaTypeForSchemaDefinitionType(leafType, leaf); - assertNotNull(leafrefResolvedType2); - assertTrue(leafrefResolvedType2 instanceof GeneratedTransferObject); - } - - @Test - public void javaTypeForSchemaDefinitionLeafrefToEnumTypeTest() { - final TypeProvider provider = new TypeProviderImpl(schemaContext); - - setReferencedTypeForTypeProvider(provider); - - final Module module = resolveModule("test-type-provider-b"); - - final DataSchemaNode enumNode = module.getDataChildByName("enum"); - assertNotNull("leaf enum is not present in root of module " + module.getName(), enumNode); - assertTrue(enumNode instanceof LeafSchemaNode); - LeafSchemaNode leaf = (LeafSchemaNode) enumNode; - final TypeDefinition leafType = leaf.getType(); - - final Type leafrefResolvedType1 = provider.javaTypeForSchemaDefinitionType(leafType, leaf); - assertNotNull(leafrefResolvedType1); - assertTrue(leafrefResolvedType1 instanceof ReferencedTypeImpl); - - final DataSchemaNode enumListNode = module.getDataChildByName("enums"); - assertNotNull("leaf-list enums is not present in root of module "+ module.getName(), enumNode); - assertTrue(enumListNode instanceof LeafListSchemaNode); - LeafListSchemaNode leafList = (LeafListSchemaNode) enumListNode; - TypeDefinition leafListType = leafList.getType(); - - final Type leafrefResolvedType2 = provider.javaTypeForSchemaDefinitionType(leafListType, leafList); - assertNotNull(leafrefResolvedType2); - assertTrue(leafrefResolvedType2 instanceof ParameterizedType); - } - - private void setReferencedTypeForTypeProvider(final TypeProvider provider) { - final LeafSchemaNode enumLeafNode = provideLeafNodeFromTopLevelContainer(testTypeProviderModule, "foo", - "resolve-direct-use-of-enum"); - final TypeDefinition enumLeafTypedef = enumLeafNode.getType(); - Type enumType = provider.javaTypeForSchemaDefinitionType(enumLeafTypedef, enumLeafNode); - - Type refType = new ReferencedTypeImpl(enumType.getPackageName(), enumType.getName()); - ((TypeProviderImpl) provider).putReferencedType(enumLeafNode.getPath(), refType); - - final LeafListSchemaNode enumListNode = provideLeafListNodeFromTopLevelContainer(testTypeProviderModule, "foo", - "list-of-enums"); - final TypeDefinition enumLeafListTypedef = enumListNode.getType(); - enumType = provider.javaTypeForSchemaDefinitionType(enumLeafListTypedef, enumListNode); - - refType = new ReferencedTypeImpl(enumType.getPackageName(), enumType.getPackageName()); - ((TypeProviderImpl) provider).putReferencedType(enumListNode.getPath(), refType); - } - - @Test - public void javaTypeForSchemaDefinitionConditionalLeafrefTest() { - final TypeProvider provider = new TypeProviderImpl(schemaContext); - final Module module = resolveModule("test-type-provider-b"); - - final DataSchemaNode condLeaf = module.getDataChildByName("conditional-leafref"); - assertNotNull("leaf conditional-leafref is not present in root of module "+ module.getName(), condLeaf); - assertTrue(condLeaf instanceof LeafSchemaNode); - LeafSchemaNode leaf = (LeafSchemaNode) condLeaf; - final TypeDefinition leafType = leaf.getType(); - - final Type resultType = provider.javaTypeForSchemaDefinitionType(leafType, leaf); - assertNotNull(resultType); - assertTrue(resultType instanceof ConcreteType); - assertEquals("java.lang", resultType.getPackageName()); - assertEquals("Object", resultType.getName()); - } - - @Test(expected = IllegalArgumentException.class) - public void javaTypeForSchemaDefinitionInvalidLeafrefPathTest() { - final TypeProvider provider = new TypeProviderImpl(schemaContext); - final Module module = resolveModule("test-type-provider-b"); - - final DataSchemaNode condLeaf = module.getDataChildByName("unreslovable-leafref"); - assertNotNull("leaf unreslovable-leafref is not present in root of module "+ module.getName(), condLeaf); - assertTrue(condLeaf instanceof LeafSchemaNode); - LeafSchemaNode leaf = (LeafSchemaNode) condLeaf; - final TypeDefinition leafType = leaf.getType(); - - provider.javaTypeForSchemaDefinitionType(leafType, leaf); - } - - @Test(expected = IllegalArgumentException.class) - public void provideTypeForLeafrefWithNullLeafrefTypeTest() { - final TypeProviderImpl provider = new TypeProviderImpl(schemaContext); - - provider.provideTypeForLeafref(null, null); - } - - @Test(expected = IllegalArgumentException.class) - public void provideTypeForLeafrefWithNullLeafrefTypePathStatementTest() { - final TypeProviderImpl provider = new TypeProviderImpl(schemaContext); - - final LeafrefTypeWithNullXpath leafrePath = new LeafrefTypeWithNullXpath(); - provider.provideTypeForLeafref(leafrePath, schemaNode); - } - - @Test(expected = IllegalStateException.class) - public void provideTypeForLeafrefWithNullParentModuleTest() { - final TypeProviderImpl provider = new TypeProviderImpl(schemaContext); - LeafSchemaNode leaf = provideLeafNodeFromTopLevelContainer(testTypeProviderModule, "bar", "leafref-value"); - TypeDefinition leafType = leaf.getType(); - assertTrue(leafType instanceof LeafrefTypeDefinition); - provider.provideTypeForLeafref((LeafrefTypeDefinition) leafType, schemaNode); - } - - @Test - public void javaTypeForSchemaDefinitionIdentityrefExtTypeTest() { - final TypeProvider provider = new TypeProviderImpl(schemaContext); - final LeafSchemaNode leaf = provideLeafNodeFromTopLevelContainer(testTypeProviderModule, "foo", "crypto"); - final TypeDefinition leafType = leaf.getType(); - - final Type result = provider.javaTypeForSchemaDefinitionType(leafType, leaf); - assertNotNull(result); - assertTrue(result instanceof ParameterizedType); - } - - @Test - public void javaTypeForSchemaDefinitionForExtUnionWithSimpleTypesTest() { - final TypeProvider provider = new TypeProviderImpl(schemaContext); - final LeafSchemaNode leaf = provideLeafNodeFromTopLevelContainer(testTypeProviderModule, "use-of-unions", "simple-int-types-union"); - final TypeDefinition leafType = leaf.getType(); - - final Type result = provider.javaTypeForSchemaDefinitionType(leafType, leaf); - assertNotNull(result); - assertTrue(result instanceof GeneratedTransferObject); - assertEquals("YangUnion", result.getName()); - //TODO: write additional asserts to compare whole GeneratedTrasnferObject against yang union definition - } - - @Test - public void javaTypeForSchemaDefinitionForExtComplexUnionWithInnerUnionTypesTest() { - final TypeProvider provider = new TypeProviderImpl(schemaContext); - final LeafSchemaNode leaf = provideLeafNodeFromTopLevelContainer(testTypeProviderModule, "use-of-unions", "complex-union"); - final TypeDefinition leafType = leaf.getType(); - - final Type result = provider.javaTypeForSchemaDefinitionType(leafType, leaf); - assertNotNull(result); - assertTrue(result instanceof GeneratedTransferObject); - assertEquals("ComplexUnion", result.getName()); - //TODO: write additional asserts to compare whole GeneratedTrasnferObject against yang union definition - } - - @Test - public void javaTypeForSchemaDefinitionForExtUnionWithInnerUnionAndSimpleTypeTest() { - final TypeProvider provider = new TypeProviderImpl(schemaContext); - final LeafSchemaNode leaf = provideLeafNodeFromTopLevelContainer(testTypeProviderModule, "use-of-unions", "complex-string-int-union"); - final TypeDefinition leafType = leaf.getType(); - - final Type result = provider.javaTypeForSchemaDefinitionType(leafType, leaf); - assertNotNull(result); - assertTrue(result instanceof GeneratedTransferObject); - assertEquals("ComplexStringIntUnion", result.getName()); - //TODO: write additional asserts to compare whole GeneratedTrasnferObject against yang union definition - } - - @Test - public void provideGeneratedTOBuilderForUnionTypeDefWithInnerUnionTypesTest() { - final TypeProviderImpl provider = new TypeProviderImpl(schemaContext); - - final Module testTypeProvider = resolveModule("test-type-provider"); - final TypeDefinition unionTypeDef = resolveTypeDefinitionFromModule(testTypeProvider, "complex-union"); - - assertNotNull(unionTypeDef); - assertTrue(unionTypeDef.getBaseType() instanceof UnionTypeDefinition); - GeneratedTOBuilder unionTypeBuilder = provider.provideGeneratedTOBuilderForUnionTypeDef("test.package.name", - (UnionTypeDefinition)unionTypeDef.getBaseType(), "ComplexUnionType", unionTypeDef); - - assertNotNull(unionTypeBuilder); - - GeneratedTransferObject unionType = unionTypeBuilder.toInstance(); - assertEquals("ComplexUnionType", unionType.getName()); - - unionTypeBuilder = provider.provideGeneratedTOBuilderForUnionTypeDef("test.package.name", - (UnionTypeDefinition)unionTypeDef.getBaseType(), "", unionTypeDef); - - assertNotNull(unionTypeBuilder); - - unionType = unionTypeBuilder.toInstance(); - assertEquals("Union", unionType.getName()); - - unionTypeBuilder = provider.provideGeneratedTOBuilderForUnionTypeDef("test.package.name", - (UnionTypeDefinition)unionTypeDef.getBaseType(), null, unionTypeDef); - - assertNotNull(unionTypeBuilder); - - unionType = unionTypeBuilder.toInstance(); - assertEquals("Union", unionType.getName()); - } - - @Test - public void provideGeneratedTOBuilderForUnionTypeDefWithInnerUnionAndSimpleTypeTest() { - final TypeProviderImpl provider = new TypeProviderImpl(schemaContext); - - final Module testTypeProvider = resolveModule("test-type-provider"); - final TypeDefinition unionTypeDef = resolveTypeDefinitionFromModule(testTypeProvider, "complex-string-int-union"); - - assertNotNull(unionTypeDef); - assertTrue(unionTypeDef.getBaseType() instanceof UnionTypeDefinition); - final GeneratedTOBuilder unionTypeBuilder = provider.provideGeneratedTOBuilderForUnionTypeDef("test.package.name", - (UnionTypeDefinition)unionTypeDef.getBaseType(), "ComplexStringIntUnionType", unionTypeDef); - - assertNotNull(unionTypeBuilder); - - GeneratedTransferObject unionType = unionTypeBuilder.toInstance(); - assertEquals("ComplexStringIntUnionType", unionType.getName()); - } - - @Test - public void generatedTypeForExtendedDefinitionTypeTest() { - final TypeProviderImpl provider = new TypeProviderImpl(schemaContext); - - final Module baseYangTypes = resolveModule("base-yang-types"); - final Set> typeDefs = baseYangTypes.getTypeDefinitions(); - - Type yangBoolean = null; - Type yangEmpty = null; - Type yangEnumeration = null; - Type yangInt8 = null; - Type yangInt8Restricted = null; - Type yangInt16 = null; - Type yangInt32 = null; - Type yangInt64 = null; - Type yangString = null; - Type yangDecimal = null; - Type yangUint8 = null; - Type yangUint16 = null; - Type yangUint32 = null; - Type yangUint64 = null; - Type yangUnion = null; - Type yangBinary = null; - Type yangBits = null; - Type yangInstanceIdentifier = null; - - for (TypeDefinition typedef : typeDefs) { - Type type = provider.generatedTypeForExtendedDefinitionType(typedef, typedef); - if (type instanceof GeneratedTransferObject) { - if (type.getName().equals("YangBoolean")) { - yangBoolean = type; - } else if (type.getName().equals("YangEmpty")) { - yangEmpty = type; - } else if (type.getName().equals("YangInt8")) { - yangInt8 = type; - } else if (type.getName().equals("YangInt8Restricted")) { - yangInt8Restricted = type; - } else if (type.getName().equals("YangInt16")) { - yangInt16 = type; - } else if (type.getName().equals("YangInt32")) { - yangInt32 = type; - } else if (type.getName().equals("YangInt64")) { - yangInt64 = type; - } else if (type.getName().equals("YangString")) { - yangString = type; - } else if (type.getName().equals("YangDecimal64")) { - yangDecimal = type; - } else if (type.getName().equals("YangUint8")) { - yangUint8 = type; - } else if (type.getName().equals("YangUint16")) { - yangUint16 = type; - } else if (type.getName().equals("YangUint32")) { - yangUint32 = type; - } else if (type.getName().equals("YangUint64")) { - yangUint64 = type; - } else if (type.getName().equals("YangUnion")) { - yangUnion = type; - } else if (type.getName().equals("YangBinary")) { - yangBinary = type; - } else if (type.getName().equals("YangInstanceIdentifier")) { - yangInstanceIdentifier = type; - } else if (type.getName().equals("YangBits")) { - yangBits = type; - } - } else if (type instanceof Enumeration) { - if (type.getName().equals("YangEnumeration")) { - yangEnumeration = type; - } - } - } - - assertNotNull(yangBoolean); - assertNotNull(yangEmpty); - assertNotNull(yangEnumeration); - assertNotNull(yangInt8); - assertNotNull(yangInt8Restricted); - assertNotNull(yangInt16); - assertNotNull(yangInt32); - assertNotNull(yangInt64); - assertNotNull(yangString); - assertNotNull(yangDecimal); - assertNotNull(yangUint8); - assertNotNull(yangUint16); - assertNotNull(yangUint32); - assertNotNull(yangUint64); - assertNotNull(yangUnion); - assertNotNull(yangBinary); - assertNotNull(yangBits); - assertNotNull(yangInstanceIdentifier); - } - - @Test(expected = IllegalArgumentException.class) - public void generatedTypeForExtendedDefinitionTypeWithTypedefNullTest() { - final TypeProviderImpl provider = new TypeProviderImpl(schemaContext); - provider.generatedTypeForExtendedDefinitionType(null, null); - } - - @Test(expected = IllegalArgumentException.class) - public void generatedTypeForExtendedDefinitionTypeWithTypedefQNameNullTest() { - final TypeProviderImpl provider = new TypeProviderImpl(schemaContext); - TestIntegerTypeDefinition testInt = new TestIntegerTypeDefinition(); - provider.generatedTypeForExtendedDefinitionType(testInt, testInt); - } - - @Test - public void generatedTypeForExtendedDefinitionTypeWithInnerExtendedTypeTest() { - final TypeProviderImpl provider = new TypeProviderImpl(schemaContext); - - final Module baseYangTypes = resolveModule("test-type-provider"); - TypeDefinition extYangInt8Typedef = resolveTypeDefinitionFromModule(baseYangTypes, "extended-yang-int8"); - assertNotNull(extYangInt8Typedef); - Type extType = provider.generatedTypeForExtendedDefinitionType(extYangInt8Typedef, extYangInt8Typedef); - assertNotNull(extType); - assertTrue(extType instanceof GeneratedTransferObject); - } - - @Test - public void generatedTypeForExtendedDefinitionTypeWithLeafrefBaseTypeTest() { - final TypeProviderImpl provider = new TypeProviderImpl(schemaContext); - - final Module baseYangTypes = resolveModule("test-type-provider"); - TypeDefinition barItemLeafrefId = resolveTypeDefinitionFromModule(baseYangTypes, "bar-item-leafref-id"); - assertNotNull(barItemLeafrefId); - Type extType = provider.generatedTypeForExtendedDefinitionType(barItemLeafrefId, barItemLeafrefId); - assertEquals(null, extType); - } - - @Test - public void generatedTypeForExtendedDefinitionTypeWithIdentityrefBaseTypeTest() { - final TypeProviderImpl provider = new TypeProviderImpl(schemaContext); - - final Module baseYangTypes = resolveModule("test-type-provider"); - - TypeDefinition aesIdentityrefType = resolveTypeDefinitionFromModule(baseYangTypes, "aes-identityref-type"); - - assertNotNull(aesIdentityrefType); - Type extType = provider.generatedTypeForExtendedDefinitionType(aesIdentityrefType, aesIdentityrefType); - assertEquals(null, extType); - } - - @Test(expected = IllegalArgumentException.class) - public void provideGeneratedTOBuilderForBitsTypeDefinitionWithNullTypedefTest() { - final TypeProviderImpl provider = new TypeProviderImpl(schemaContext); - provider.provideGeneratedTOBuilderForBitsTypeDefinition("", null, "", ""); - } - - @Test(expected = IllegalArgumentException.class) - public void provideGeneratedTOBuilderForBitsTypeDefinitionWithBasePackageNullTest() { - final TypeProviderImpl provider = new TypeProviderImpl(schemaContext); - final LeafSchemaNode leaf = provideLeafNodeFromTopLevelContainer(testTypeProviderModule, "foo", "yang-int8-type"); - final TypeDefinition leafType = leaf.getType(); - provider.provideGeneratedTOBuilderForBitsTypeDefinition(null, leafType, "", ""); - } - - @Test - public void provideGeneratedTOBuilderForBitsTypeDefinitionWithNonBitsTypedefTest() { - final TypeProviderImpl provider = new TypeProviderImpl(schemaContext); - - final LeafSchemaNode leaf = provideLeafNodeFromTopLevelContainer(testTypeProviderModule, "foo", "yang-int8-type"); - final TypeDefinition leafType = leaf.getType(); - Type type = provider.provideGeneratedTOBuilderForBitsTypeDefinition("", leafType, "", ""); - - assertEquals(null, type); - } - - @Test - public void getConstructorPropertyNameTest() { - final TypeProvider provider = new TypeProviderImpl(schemaContext); - - final LeafSchemaNode leaf = provideLeafNodeFromTopLevelContainer(testTypeProviderModule, "foo", "yang-int8-type"); - final TypeDefinition leafType = leaf.getType(); - - final String ctorPropertyName = provider.getConstructorPropertyName(leafType); - assertEquals("value", ctorPropertyName); - - final String emptyStringName = provider.getConstructorPropertyName(leaf); - assertTrue(emptyStringName.isEmpty()); - } - - @Test - public void getParamNameFromTypeTest() { - final TypeProvider provider = new TypeProviderImpl(schemaContext); - - final LeafSchemaNode leaf = provideLeafNodeFromTopLevelContainer(testTypeProviderModule, "foo", "yang-int8-type"); - final TypeDefinition leafType = leaf.getType(); - - final String paramName = provider.getParamNameFromType(leafType); - assertEquals("yangInt8", paramName); - } - - @Test - public void addUnitsToGenTOTest() { - final TypeProviderImpl provider = new TypeProviderImpl(schemaContext); - - GeneratedTOBuilder builder = new GeneratedTOBuilderImpl("test.package", "TestBuilder"); - - TypeProviderImpl.addUnitsToGenTO(builder, null); - GeneratedTransferObject genTO = builder.toInstance(); - assertTrue(genTO.getConstantDefinitions().isEmpty()); - - TypeProviderImpl.addUnitsToGenTO(builder, ""); - genTO = builder.toInstance(); - assertTrue(genTO.getConstantDefinitions().isEmpty()); - - TypeProviderImpl.addUnitsToGenTO(builder, "125"); - genTO = builder.toInstance(); - assertTrue(!genTO.getConstantDefinitions().isEmpty()); - assertEquals(1, genTO.getConstantDefinitions().size()); - assertEquals("_UNITS", genTO.getConstantDefinitions().get(0).getName()); - assertEquals(genTO.getConstantDefinitions().get(0).getValue(), "\"125\""); - } - - @Test(expected = NullPointerException.class) - public void getTypeDefaultConstructionLeafTypeNullTest() { - final TypeProviderImpl provider = new TypeProviderImpl(schemaContext); - TestLeafSchemaNode leafSchemaNode = new TestLeafSchemaNode(); - provider.getTypeDefaultConstruction(leafSchemaNode, null); - } - - @Test(expected = NullPointerException.class) - public void getTypeDefaultConstructionDefaultValueNullTest() { - final TypeProviderImpl provider = new TypeProviderImpl(schemaContext); - final LeafSchemaNode leaf = provideLeafForGetDefaultConstructionTestCase("yang-boolean"); - provider.getTypeDefaultConstruction(leaf, null); - } - - private LeafSchemaNode provideLeafForGetDefaultConstructionTestCase(final String leafName) { - return provideLeafNodeFromTopLevelContainer(testTypeProviderModule, "construction-type-test", - leafName); - } - - @Test(expected = UnsupportedOperationException.class) - public void getTypeDefaultConstructionDefaultValueForInstanceIdentifierTest() { - final TypeProviderImpl provider = new TypeProviderImpl(schemaContext); - LeafSchemaNode leaf = provideLeafForGetDefaultConstructionTestCase("foo-container-id"); - provider.getTypeDefaultConstruction(leaf, "NAN"); - } - - @Test(expected = UnsupportedOperationException.class) - public void getTypeDefaultConstructionDefaultValueForIdentityrefTest() { - final TypeProviderImpl provider = new TypeProviderImpl(schemaContext); - LeafSchemaNode leaf = provideLeafForGetDefaultConstructionTestCase("aes-identityref-type"); - provider.getTypeDefaultConstruction(leaf, "NAN"); - } - - @Test - public void getTypeDefaultConstructionDefaultValueTest() { - final TypeProviderImpl provider = new TypeProviderImpl(schemaContext); - - LeafSchemaNode leaf = provideLeafForGetDefaultConstructionTestCase("yang-boolean"); - String result = provider.getTypeDefaultConstruction(leaf, "true"); - assertNotNull(result); - assertTrue(!result.isEmpty()); - assertEquals("new org.opendaylight.yang.gen.v1.urn.opendaylight.org.test.base.yang.types.rev140914.YangBoolean(new java.lang.Boolean(\"true\"))", - result); - - leaf = provideLeafForGetDefaultConstructionTestCase("yang-empty"); - result = provider.getTypeDefaultConstruction(leaf, "true"); - assertNotNull(result); - assertTrue(!result.isEmpty()); - assertEquals("new org.opendaylight.yang.gen.v1.urn.opendaylight.org.test.base.yang.types.rev140914.YangEmpty(new java.lang.Boolean(\"true\"))", - result); - - leaf = provideLeafForGetDefaultConstructionTestCase("yang-enumeration"); - result = provider.getTypeDefaultConstruction(leaf, "a"); - assertNotNull(result); - assertTrue(!result.isEmpty()); - assertEquals("org.opendaylight.yang.gen.v1.urn.opendaylight.org.test.base.yang.types.rev140914.YangEnumeration.A", - result); - - leaf = provideLeafForGetDefaultConstructionTestCase("direct-use-of-enum"); - result = provider.getTypeDefaultConstruction(leaf, "y"); - assertNotNull(result); - assertTrue(!result.isEmpty()); - assertEquals("org.opendaylight.yang.gen.v1.urn.opendaylight.org.test.type.provider.model.rev140912.construction.type.test.DirectUseOfEnum.Y", - result); - - leaf = provideLeafForGetDefaultConstructionTestCase("yang-int8"); - result = provider.getTypeDefaultConstruction(leaf, "17"); - assertNotNull(result); - assertTrue(!result.isEmpty()); - assertEquals("new org.opendaylight.yang.gen.v1.urn.opendaylight.org.test.base.yang.types.rev140914.YangInt8(new java.lang.Byte(\"17\"))", - result); - - leaf = provideLeafForGetDefaultConstructionTestCase("yang-int8-restricted"); - result = provider.getTypeDefaultConstruction(leaf, "99"); - assertNotNull(result); - assertTrue(!result.isEmpty()); - assertEquals("new org.opendaylight.yang.gen.v1.urn.opendaylight.org.test.base.yang.types.rev140914.YangInt8Restricted(new java.lang.Byte(\"99\"))", - result); - - leaf = provideLeafForGetDefaultConstructionTestCase("yang-int16"); - result = provider.getTypeDefaultConstruction(leaf, "1024"); - assertNotNull(result); - assertTrue(!result.isEmpty()); - assertEquals("new org.opendaylight.yang.gen.v1.urn.opendaylight.org.test.base.yang.types.rev140914.YangInt16(new java.lang.Short(\"1024\"))", - result); - - leaf = provideLeafForGetDefaultConstructionTestCase("yang-int32"); - result = provider.getTypeDefaultConstruction(leaf, "1048576"); - assertNotNull(result); - assertTrue(!result.isEmpty()); - assertEquals("new org.opendaylight.yang.gen.v1.urn.opendaylight.org.test.base.yang.types.rev140914.YangInt32(new java.lang.Integer(\"1048576\"))", - result); - - leaf = provideLeafForGetDefaultConstructionTestCase("yang-int64"); - result = provider.getTypeDefaultConstruction(leaf, "1099511627776"); - assertNotNull(result); - assertTrue(!result.isEmpty()); - assertEquals("new org.opendaylight.yang.gen.v1.urn.opendaylight.org.test.base.yang.types.rev140914.YangInt64(new java.lang.Long(\"1099511627776\"))", - result); - - leaf = provideLeafForGetDefaultConstructionTestCase("yang-string"); - result = provider.getTypeDefaultConstruction(leaf, "TEST"); - assertNotNull(result); - assertTrue(!result.isEmpty()); - assertEquals("new org.opendaylight.yang.gen.v1.urn.opendaylight.org.test.base.yang.types.rev140914.YangString(\"TEST\")", - result); - - leaf = provideLeafForGetDefaultConstructionTestCase("yang-decimal64"); - result = provider.getTypeDefaultConstruction(leaf, "1274.25"); - assertNotNull(result); - assertTrue(!result.isEmpty()); - assertEquals("new org.opendaylight.yang.gen.v1.urn.opendaylight.org.test.base.yang.types.rev140914.YangDecimal64(new java.math.BigDecimal(\"1274.25\"))", - result); - - leaf = provideLeafForGetDefaultConstructionTestCase("yang-uint8"); - result = provider.getTypeDefaultConstruction(leaf, "128"); - assertNotNull(result); - assertTrue(!result.isEmpty()); - assertEquals("new org.opendaylight.yang.gen.v1.urn.opendaylight.org.test.base.yang.types.rev140914.YangUint8(new java.lang.Short(\"128\"))", - result); - - leaf = provideLeafForGetDefaultConstructionTestCase("yang-uint16"); - result = provider.getTypeDefaultConstruction(leaf, "1048576"); - assertNotNull(result); - assertTrue(!result.isEmpty()); - assertEquals("new org.opendaylight.yang.gen.v1.urn.opendaylight.org.test.base.yang.types.rev140914.YangUint16(new java.lang.Integer(\"1048576\"))", - result); - - leaf = provideLeafForGetDefaultConstructionTestCase("yang-uint32"); - result = provider.getTypeDefaultConstruction(leaf, "1099511627776"); - assertNotNull(result); - assertTrue(!result.isEmpty()); - assertEquals("new org.opendaylight.yang.gen.v1.urn.opendaylight.org.test.base.yang.types.rev140914.YangUint32(new java.lang.Long(\"1099511627776\"))", - result); - - leaf = provideLeafForGetDefaultConstructionTestCase("yang-uint64"); - result = provider.getTypeDefaultConstruction(leaf, "1208925819614629174706176"); - assertNotNull(result); - assertTrue(!result.isEmpty()); - assertEquals("new org.opendaylight.yang.gen.v1.urn.opendaylight.org.test.base.yang.types.rev140914.YangUint64(new java.math.BigInteger(\"1208925819614629174706176\"))", - result); - - //FIXME: Is this correct scenario and correct result? - leaf = provideLeafForGetDefaultConstructionTestCase("complex-union"); - result = provider.getTypeDefaultConstruction(leaf, "75"); - assertNotNull(result); - assertTrue(!result.isEmpty()); - assertEquals("new org.opendaylight.yang.gen.v1.urn.opendaylight.org.test.type.provider.model.rev140912.ComplexUnion(\"null\".toCharArray())", - result); - - //FIXME: Is this correct scenario and correct result? - leaf = provideLeafForGetDefaultConstructionTestCase("complex-string-int-union"); - result = provider.getTypeDefaultConstruction(leaf, "TEST_UNION_STRING_DEFAULT"); - assertNotNull(result); - assertTrue(!result.isEmpty()); - assertEquals("new org.opendaylight.yang.gen.v1.urn.opendaylight.org.test.type.provider.model.rev140912.ComplexStringIntUnion(\"null\".toCharArray())", - result); - - leaf = provideLeafForGetDefaultConstructionTestCase("simple-int-types-union"); - result = provider.getTypeDefaultConstruction(leaf, "2048"); - assertNotNull(result); - assertTrue(!result.isEmpty()); - assertEquals("new org.opendaylight.yang.gen.v1.urn.opendaylight.org.test.base.yang.types.rev140914.YangUnion(\"null\".toCharArray())", - result); - - - leaf = provideLeafForGetDefaultConstructionTestCase("direct-union-leaf"); - result = provider.getTypeDefaultConstruction(leaf); - assertNotNull(result); - assertTrue(!result.isEmpty()); - assertEquals("new org.opendaylight.yang.gen.v1.urn.opendaylight.org.test.type.provider.model.rev140912.DirectUnionLeaf(\"128\".toCharArray())", - result); - - final Module module = resolveModule("test-type-provider"); - DataSchemaNode rootNode = module.getDataChildByName("root-union-leaf"); - assertNotNull("leaf root-union-leaf is not present in root of module "+ module.getName(), rootNode); - assertTrue(rootNode instanceof LeafSchemaNode); - leaf = (LeafSchemaNode) rootNode; - result = provider.getTypeDefaultConstruction(leaf); - assertNotNull(result); - assertTrue(!result.isEmpty()); - assertEquals("new org.opendaylight.yang.gen.v1.urn.opendaylight.org.test.type.provider.model.rev140912.TestTypeProviderData.RootUnionLeaf(\"256\".toCharArray())", - result); - - leaf = provideLeafForGetDefaultConstructionTestCase("yang-binary"); - result = provider.getTypeDefaultConstruction(leaf, "0xffffff"); - assertNotNull(result); - assertTrue(!result.isEmpty()); - assertEquals("new org.opendaylight.yang.gen.v1.urn.opendaylight.org.test.base.yang.types.rev140914.YangBinary(new byte[] {-45, 23, -33, 125, -9, -33})", - result); - - rootNode = module.getDataChildByName("root-bits-leaf"); - assertNotNull("leaf bits-leaf is not present in root of module "+ module.getName(), rootNode); - assertTrue(rootNode instanceof LeafSchemaNode); - leaf = (LeafSchemaNode) rootNode; - result = provider.getTypeDefaultConstruction(leaf); - assertNotNull(result); - assertTrue(!result.isEmpty()); - assertEquals("new org.opendaylight.yang.gen.v1.urn.opendaylight.org.test.type.provider.model.rev140912.TestTypeProviderData.RootBitsLeaf(false, true, false)", - result); - - leaf = provideLeafForGetDefaultConstructionTestCase("yang-bits"); - result = provider.getTypeDefaultConstruction(leaf, "10-Mb-only"); - assertNotNull(result); - assertTrue(!result.isEmpty()); - assertEquals("new org.opendaylight.yang.gen.v1.urn.opendaylight.org.test.base.yang.types.rev140914.YangBits(true, false, false)", - result); - - leaf = provideLeafForGetDefaultConstructionTestCase("bar-id"); - result = provider.getTypeDefaultConstruction(leaf, "128"); - assertNotNull(result); - assertTrue(!result.isEmpty()); - assertEquals("new org.opendaylight.yang.gen.v1.urn.opendaylight.org.test.base.yang.types.rev140914.YangInt16(new java.lang.Short(\"128\"))", - result); - - leaf = provideLeafForGetDefaultConstructionTestCase("foo-leafref-value"); - result = provider.getTypeDefaultConstruction(leaf, "32"); - assertNotNull(result); - assertTrue(!result.isEmpty()); - assertEquals("new org.opendaylight.yang.gen.v1.urn.opendaylight.org.test.base.yang.types.rev140914.YangInt8(new java.lang.Byte(\"32\"))", - result); - - leaf = provideLeafForGetDefaultConstructionTestCase("foo-cond-bar-item"); - result = provider.getTypeDefaultConstruction(leaf, "10"); - assertNotNull(result); - assertTrue(!result.isEmpty()); - assertEquals("new java.lang.Object()", - result); - } -} diff --git a/binding/mdsal-binding-generator-util/src/test/java/org/opendaylight/yangtools/binding/generator/util/BindingGeneratorUtilTest.java b/binding/mdsal-binding-generator-util/src/test/java/org/opendaylight/yangtools/binding/generator/util/BindingGeneratorUtilTest.java index c2df71de33..5a3581b0e7 100644 --- a/binding/mdsal-binding-generator-util/src/test/java/org/opendaylight/yangtools/binding/generator/util/BindingGeneratorUtilTest.java +++ b/binding/mdsal-binding-generator-util/src/test/java/org/opendaylight/yangtools/binding/generator/util/BindingGeneratorUtilTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2016 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, @@ -13,7 +13,12 @@ import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; + +import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; +import org.opendaylight.yangtools.yang.parser.spi.source.SourceException; + import com.google.common.base.Optional; + import java.io.File; import java.io.IOException; import java.io.Serializable; @@ -22,6 +27,7 @@ import java.net.URISyntaxException; import java.util.ArrayList; import java.util.List; import java.util.Set; + import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; @@ -42,7 +48,6 @@ import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint; import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint; import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint; import org.opendaylight.yangtools.yang.model.api.type.UnsignedIntegerTypeDefinition; -import org.opendaylight.yangtools.yang.model.parser.api.YangContextParser; import org.opendaylight.yangtools.yang.model.util.BaseConstraints; import org.opendaylight.yangtools.yang.model.util.DataNodeIterator; import org.opendaylight.yangtools.yang.model.util.Decimal64; @@ -52,14 +57,13 @@ import org.opendaylight.yangtools.yang.model.util.Int16; import org.opendaylight.yangtools.yang.model.util.StringType; import org.opendaylight.yangtools.yang.model.util.Uint16; import org.opendaylight.yangtools.yang.parser.builder.impl.ModuleBuilder; -import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl; public class BindingGeneratorUtilTest { @Rule public ExpectedException expectedEx = ExpectedException.none(); - private static List loadTestResources(final String testFile) { + private static List loadTestResources(String testFile) { final List testModels = new ArrayList(); File listModelFile; try { @@ -81,14 +85,14 @@ public class BindingGeneratorUtilTest { * </ul> * <li>packageNameForTypeDefinition</li> <li>moduleNamespaceToPackageName</li> * - without revision </ul> - * - * @throws IOException IOException + * @throws ReactorException Reactor exception + * @throws SourceException Source exception */ @Test - public void testBindingGeneratorUtilMethods() throws IOException { + public void testBindingGeneratorUtilMethods() throws IOException, SourceException, ReactorException { List testModels = loadTestResources("/module.yang"); - final YangContextParser parser = new YangParserImpl(); - final Set modules = parser.parseFiles(testModels).getModules(); + + final Set modules = RetestUtils.parseYangSources(testModels).getModules(); String packageName = ""; Module module = null; for (Module m : modules) { diff --git a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/RetestUtils.java b/binding/mdsal-binding-generator-util/src/test/java/org/opendaylight/yangtools/binding/generator/util/RetestUtils.java similarity index 82% rename from binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/RetestUtils.java rename to binding/mdsal-binding-generator-util/src/test/java/org/opendaylight/yangtools/binding/generator/util/RetestUtils.java index 82fb15d7b8..e9c8f79825 100644 --- a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/stmt/parser/retest/RetestUtils.java +++ b/binding/mdsal-binding-generator-util/src/test/java/org/opendaylight/yangtools/binding/generator/util/RetestUtils.java @@ -1,4 +1,12 @@ -package org.opendaylight.yangtools.sal.binding.generator.impl.stmt.parser.retest; +/* + * Copyright (c) 2016 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.yangtools.binding.generator.util; import java.util.Collection; diff --git a/binding/mdsal-binding-generator-util/src/test/java/org/opendaylight/yangtools/binding/generator/util/stmt/parser/retest/BindingGeneratorUtilTest.java b/binding/mdsal-binding-generator-util/src/test/java/org/opendaylight/yangtools/binding/generator/util/stmt/parser/retest/BindingGeneratorUtilTest.java deleted file mode 100644 index f136051654..0000000000 --- a/binding/mdsal-binding-generator-util/src/test/java/org/opendaylight/yangtools/binding/generator/util/stmt/parser/retest/BindingGeneratorUtilTest.java +++ /dev/null @@ -1,438 +0,0 @@ -/* - * 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.yangtools.binding.generator.util.stmt.parser.retest; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - -import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; -import org.opendaylight.yangtools.yang.parser.spi.source.SourceException; -import org.opendaylight.yangtools.binding.generator.util.Types; -import org.opendaylight.yangtools.binding.generator.util.BindingGeneratorUtil; - -import com.google.common.base.Optional; - -import java.io.File; -import java.io.IOException; -import java.io.Serializable; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.ArrayList; -import java.util.List; -import java.util.Set; - -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.opendaylight.yangtools.binding.generator.util.generated.type.builder.GeneratedTypeBuilderImpl; -import org.opendaylight.yangtools.sal.binding.model.api.AccessModifier; -import org.opendaylight.yangtools.sal.binding.model.api.Restrictions; -import org.opendaylight.yangtools.sal.binding.model.api.type.builder.GeneratedTypeBuilder; -import org.opendaylight.yangtools.sal.binding.model.api.type.builder.MethodSignatureBuilder; -import org.opendaylight.yangtools.yang.binding.BindingMapping; -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode; -import org.opendaylight.yangtools.yang.model.api.Module; -import org.opendaylight.yangtools.yang.model.api.SchemaPath; -import org.opendaylight.yangtools.yang.model.api.TypeDefinition; -import org.opendaylight.yangtools.yang.model.api.type.DecimalTypeDefinition; -import org.opendaylight.yangtools.yang.model.api.type.IntegerTypeDefinition; -import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint; -import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint; -import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint; -import org.opendaylight.yangtools.yang.model.api.type.UnsignedIntegerTypeDefinition; -import org.opendaylight.yangtools.yang.model.util.BaseConstraints; -import org.opendaylight.yangtools.yang.model.util.DataNodeIterator; -import org.opendaylight.yangtools.yang.model.util.Decimal64; -import org.opendaylight.yangtools.yang.model.util.ExtendedType; -import org.opendaylight.yangtools.yang.model.util.ExtendedType.Builder; -import org.opendaylight.yangtools.yang.model.util.Int16; -import org.opendaylight.yangtools.yang.model.util.StringType; -import org.opendaylight.yangtools.yang.model.util.Uint16; -import org.opendaylight.yangtools.yang.parser.builder.impl.ModuleBuilder; - -public class BindingGeneratorUtilTest { - - @Rule - public ExpectedException expectedEx = ExpectedException.none(); - - private static List loadTestResources(String testFile) { - final List testModels = new ArrayList(); - File listModelFile; - try { - listModelFile = new File(BindingGeneratorUtilTest.class.getResource(testFile).toURI()); - } catch (URISyntaxException e) { - throw new IllegalArgumentException("Failed to load sources from " + testFile); - } - testModels.add(listModelFile); - return testModels; - } - - /** - * Tests methods: - * <ul> - * <li>moduleNamespaceToPackageName</li> - with revision - * <li>packageNameForGeneratedType</li> - * <ul> - * <li>validateJavaPackage</li> - * </ul> - * <li>packageNameForTypeDefinition</li> <li>moduleNamespaceToPackageName</li> - * - without revision </ul> - * @throws ReactorException Reactor exception - * @throws SourceException Source exception - */ - @Test - public void testBindingGeneratorUtilMethods() throws IOException, SourceException, ReactorException { - List testModels = loadTestResources("/module.yang"); - - final Set modules = RetestUtils.parseYangSources(testModels).getModules(); - String packageName = ""; - Module module = null; - for (Module m : modules) { - module = m; - break; - } - assertNotNull("Module can't be null", module); - - // test of the method moduleNamespaceToPackageName() - packageName = BindingGeneratorUtil.moduleNamespaceToPackageName(module); - assertEquals("Generated package name is incorrect.", - "org.opendaylight.yang.gen.v1.urn.m.o.d.u.l.e.n.a.m.e.t.e.s.t._case._1digit.rev130910", packageName); - - // test of the method packageNameForGeneratedType() - DataNodeIterator it = new DataNodeIterator(module); - List schemaContainers = it.allContainers(); - String subPackageNameForDataNode = ""; - for (ContainerSchemaNode containerSchemaNode : schemaContainers) { - if (containerSchemaNode.getQName().getLocalName().equals("cont-inner")) { - subPackageNameForDataNode = BindingGeneratorUtil.packageNameForGeneratedType(packageName, - containerSchemaNode.getPath()); - break; - } - } - assertEquals("The name of the subpackage is incorrect.", - "org.opendaylight.yang.gen.v1.urn.m.o.d.u.l.e.n.a.m.e.t.e.s.t._case._1digit.rev130910.cont.outter", - subPackageNameForDataNode); - - // test of the method packageNameForTypeDefinition - Set> typeDefinitions = module.getTypeDefinitions(); - String subPackageNameForTypeDefinition = ""; - TypeDefinition firstTypeDef = null; - - for (TypeDefinition tpDef : typeDefinitions) { - if (tpDef.getQName().getLocalName().equals("tpdf")) { - subPackageNameForTypeDefinition = BindingGeneratorUtil.packageNameForTypeDefinition(packageName, tpDef); - firstTypeDef = tpDef; - break; - } - } - assertEquals("The name of the subpackage is incorrect.", - "org.opendaylight.yang.gen.v1.urn.m.o.d.u.l.e.n.a.m.e.t.e.s.t._case._1digit.rev130910", - subPackageNameForTypeDefinition); - - // test method getRestrictions - Restrictions restriction = BindingGeneratorUtil.getRestrictions(firstTypeDef); - assertNotNull(restriction); - - // test method computeDefaultSUID - GeneratedTypeBuilder genTypeBuilder = new GeneratedTypeBuilderImpl("org.opendaylight.yangtools.test", "TestType"); - genTypeBuilder.addMethod("testMethod"); - genTypeBuilder.addAnnotation("org.opendaylight.yangtools.test.annotation", "AnnotationTest"); - genTypeBuilder.addEnclosingTransferObject("testObject"); - genTypeBuilder.addProperty("newProp"); - GeneratedTypeBuilder genType = new GeneratedTypeBuilderImpl("org.opendaylight.yangtools.test", "Type2"); - genTypeBuilder.addImplementsType(genType); - long computedSUID = BindingGeneratorUtil.computeDefaultSUID(genTypeBuilder); - - GeneratedTypeBuilder genTypeBuilder2 = new GeneratedTypeBuilderImpl("org.opendaylight.yangtools.test2", "TestType2"); - long computedSUID2 = BindingGeneratorUtil.computeDefaultSUID(genTypeBuilder2); - assertNotEquals(computedSUID, computedSUID2); - - // test of exception part of the method moduleNamespaceToPackageName() - ModuleBuilder moduleBuilder = new ModuleBuilder("module-withut-revision", null); - moduleBuilder.setSource(""); - Module moduleWithoutRevision = moduleBuilder.build(); - boolean passedSuccesfully = false; - try { - BindingGeneratorUtil.moduleNamespaceToPackageName(moduleWithoutRevision); - passedSuccesfully = true; - } catch (IllegalArgumentException e) { - } - assertFalse("Exception 'IllegalArgumentException' wasn't raised", passedSuccesfully); - - } - - /** - * Test for the method - * <ul> - * <li>{@link BindingGeneratorUtil#packageNameForTypeDefinition(String, TypeDefinition) - * packageNameForTypeDefinition(String, TypeDefinition)}</li> - * </ul> - */ - @Test - @Deprecated - public void testPackageNameForTypeDefinitionNullBasePackageName() { - expectedEx.expect(IllegalArgumentException.class); - expectedEx.expectMessage("Base Package Name cannot be NULL!"); - BindingGeneratorUtil.packageNameForTypeDefinition(null, null); - } - - /** - * Test for the method - * <ul> - * <li>{@link BindingGeneratorUtil#packageNameForTypeDefinition(String, TypeDefinition) - * packageNameForTypeDefinition(String, TypeDefinition)}</li> - * </ul> - */ - @Test - @Deprecated - public void testPackageNameForTypeDefinitionNullTypeDefinition() { - expectedEx.expect(IllegalArgumentException.class); - expectedEx.expectMessage("Type Definition reference cannot be NULL!"); - BindingGeneratorUtil.packageNameForTypeDefinition("test.package", null); - } - - /** - * Test for the method - * <ul> - * <li>{@link BindingGeneratorUtil#packageNameForGeneratedType(String, SchemaPath) - * packageNameForGeneratedType(String, SchemaPath)}</li> - * </ul> - */ - @Test - public void testPackageNameForGeneratedTypeNullBasePackageName() { - expectedEx.expect(NullPointerException.class); - BindingGeneratorUtil.packageNameForGeneratedType(null, null); - } - - /** - * Test for the method - * <ul> - * <li>{@link BindingGeneratorUtil#packageNameForGeneratedType(String, SchemaPath) - * packageNameForGeneratedType(String, SchemaPath)}</li> - * </ul> - */ - @Test - public void testPackageNameForGeneratedTypeNullSchemaPath() { - expectedEx.expect(NullPointerException.class); - BindingGeneratorUtil.packageNameForGeneratedType("test.package", null); - } - - /** - * Test for the method - * <ul> - * <li>{@link BindingGeneratorUtil#parseToClassName(String) - * parseToClassName(String)}</li> - * </ul> - */ - @Test - public void testParseToClassNameNullValue() { - String className = BindingGeneratorUtil.parseToClassName("test-class-name"); - assertEquals("TestClassName", className); - - expectedEx.expect(IllegalArgumentException.class); - expectedEx.expectMessage("Name can not be null"); - className = BindingGeneratorUtil.parseToClassName(null); - } - - /** - * Test for the method - * <ul> - * <li>{@link BindingGeneratorUtil#parseToClassName(String) - * parseToClassName(String)}</li> - * </ul> - */ - @Test - public void testParseToClassNameEmptyValue() { - String className = BindingGeneratorUtil.parseToClassName("test-class-name"); - assertEquals("TestClassName", className); - - expectedEx.expect(IllegalArgumentException.class); - expectedEx.expectMessage("Name can not be empty"); - className = BindingGeneratorUtil.parseToClassName(""); - } - - /** - * Test for the method - * <ul> - * <li>{@link BindingGeneratorUtil#resolveJavaReservedWordEquivalency(String) - * resolveJavaReservedWordEquivalency(String)}</li> - * <ul> - */ - @Test - public void testValidateParameterName() { - assertNull("Return value is incorrect.", BindingGeneratorUtil.resolveJavaReservedWordEquivalency(null)); - assertEquals("Return value is incorrect.", "whatever", - BindingGeneratorUtil.resolveJavaReservedWordEquivalency("whatever")); - assertEquals("Return value is incorrect.", "_case", - BindingGeneratorUtil.resolveJavaReservedWordEquivalency("case")); - } - - /** - * Tests the methods: - * <ul> - * <li>parseToClassName</li> - * <ul> - * <li>parseToCamelCase</li> - * <ul> - * <li>replaceWithCamelCase</li> - * </ul> - * </ul> <li>parseToValidParamName</li> - * <ul> - * <li>parseToCamelCase</li> - * <ul> - * <li>replaceWithCamelCase</li> - * </ul> - * </ul> - * <ul> - */ - @Test - public void testParsingMethods() { - // parseToClassName method testing - assertEquals("Class name has incorrect format", "SomeTestingClassName", - BindingMapping.getClassName(" some-testing_class name ")); - assertEquals("Class name has incorrect format", "_0SomeTestingClassName", - BindingMapping.getClassName(" 0 some-testing_class name ")); - - // parseToValidParamName - assertEquals("Parameter name has incorrect format", "someTestingParameterName", - BindingGeneratorUtil.parseToValidParamName(" some-testing_parameter name ")); - assertEquals("Parameter name has incorrect format", "_0someTestingParameterName", - BindingGeneratorUtil.parseToValidParamName(" 0some-testing_parameter name ")); - } - - @Test - public void computeDefaultSUIDTest() { - GeneratedTypeBuilderImpl generatedTypeBuilder = new GeneratedTypeBuilderImpl("my.package", "MyName"); - - MethodSignatureBuilder method = generatedTypeBuilder.addMethod("myMethodName"); - method.setAccessModifier(AccessModifier.PUBLIC); - generatedTypeBuilder.addProperty("myProperty"); - generatedTypeBuilder.addImplementsType(Types.typeForClass(Serializable.class)); - - assertEquals(6788238694991761868L, BindingGeneratorUtil.computeDefaultSUID(generatedTypeBuilder)); - - } - - @Test - public void getRestrictionsTest() { - - Optional absent = Optional.absent(); - - Builder extTypeBuilder = ExtendedType.builder(new QName(URI.create("namespace"), "localName"), - Int16.getInstance(), absent, absent, SchemaPath.create(true, QName.create("/root"))); - - ArrayList lenght = new ArrayList(); - ArrayList range = new ArrayList(); - ArrayList pattern = new ArrayList(); - - lenght.add(BaseConstraints.newLengthConstraint(1, 2, absent, absent)); - range.add(BaseConstraints.newRangeConstraint(1, 2, absent, absent)); - pattern.add(BaseConstraints.newPatternConstraint(".*", absent, absent)); - - extTypeBuilder.lengths(lenght); - extTypeBuilder.ranges(range); - extTypeBuilder.patterns(pattern); - - Restrictions restrictions = BindingGeneratorUtil.getRestrictions(extTypeBuilder.build()); - - assertNotNull(restrictions); - - assertEquals(1, restrictions.getLengthConstraints().size()); - assertEquals(1, restrictions.getRangeConstraints().size()); - assertEquals(1, restrictions.getPatternConstraints().size()); - - assertFalse(restrictions.isEmpty()); - assertTrue(restrictions.getLengthConstraints().contains( - BaseConstraints.newLengthConstraint(1, 2, absent, absent))); - assertTrue(restrictions.getRangeConstraints() - .contains(BaseConstraints.newRangeConstraint(1, 2, absent, absent))); - assertTrue(restrictions.getPatternConstraints().contains( - BaseConstraints.newPatternConstraint(".*", absent, absent))); - } - - @Test - public void getEmptyRestrictionsTest() { - - Optional absent = Optional.absent(); - - Builder extTypeBuilder = ExtendedType.builder(new QName(URI.create("namespace"), "localName"), - StringType.getInstance(), absent, absent, SchemaPath.create(true, QName.create("/root"))); - - Restrictions restrictions = BindingGeneratorUtil.getRestrictions(extTypeBuilder.build()); - - assertNotNull(restrictions); - assertTrue(restrictions.isEmpty()); - - } - - @Test - public void getDefaultIntegerRestrictionsTest() { - - Optional absent = Optional.absent(); - - Builder extTypeBuilder = ExtendedType.builder(new QName(URI.create("namespace"), "localName"), - Int16.getInstance(), absent, absent, SchemaPath.create(true, QName.create("/root"))); - - ExtendedType extType = extTypeBuilder.build(); - Restrictions restrictions = BindingGeneratorUtil.getRestrictions(extType); - - assertNotNull(restrictions); - assertFalse(restrictions.isEmpty()); - assertEquals(((IntegerTypeDefinition) extType.getBaseType()).getRangeConstraints(), - restrictions.getRangeConstraints()); - assertTrue(restrictions.getLengthConstraints().isEmpty()); - assertTrue(restrictions.getPatternConstraints().isEmpty()); - - } - - @Test - public void getDefaultUnsignedIntegerRestrictionsTest() { - - Optional absent = Optional.absent(); - - Builder extTypeBuilder = ExtendedType.builder(new QName(URI.create("namespace"), "localName"), - Uint16.getInstance(), absent, absent, SchemaPath.create(true, QName.create("/root"))); - - ExtendedType extType = extTypeBuilder.build(); - Restrictions restrictions = BindingGeneratorUtil.getRestrictions(extType); - - assertNotNull(restrictions); - assertFalse(restrictions.isEmpty()); - assertEquals(((UnsignedIntegerTypeDefinition) extType.getBaseType()).getRangeConstraints(), - restrictions.getRangeConstraints()); - assertTrue(restrictions.getLengthConstraints().isEmpty()); - assertTrue(restrictions.getPatternConstraints().isEmpty()); - } - - @Test - public void getDefaultDecimalRestrictionsTest() { - - Optional absent = Optional.absent(); - SchemaPath path = SchemaPath.create(true, QName.create("/root")); - - Builder extTypeBuilder = ExtendedType.builder(new QName(URI.create("namespace"), "localName"), - Decimal64.create(path, 10), absent, absent, path); - - ExtendedType extType = extTypeBuilder.build(); - Restrictions restrictions = BindingGeneratorUtil.getRestrictions(extType); - - assertNotNull(restrictions); - assertFalse(restrictions.isEmpty()); - assertEquals(((DecimalTypeDefinition) extType.getBaseType()).getRangeConstraints(), - restrictions.getRangeConstraints()); - assertTrue(restrictions.getLengthConstraints().isEmpty()); - assertTrue(restrictions.getPatternConstraints().isEmpty()); - - } - -} diff --git a/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/stmt/parser/retest/AugmentToUsesInAugmentCompilationTest.java b/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/stmt/parser/retest/AugmentToUsesInAugmentCompilationTest.java deleted file mode 100644 index 2435bb90b3..0000000000 --- a/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/stmt/parser/retest/AugmentToUsesInAugmentCompilationTest.java +++ /dev/null @@ -1,119 +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.yangtools.sal.java.api.generator.stmt.parser.retest; - -import static org.junit.Assert.assertTrue; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.BASE_PKG; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.COMPILER_OUTPUT_PATH; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.FS; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.GENERATOR_OUTPUT_PATH; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.NS_BAR; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.NS_BAZ; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.NS_FOO; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.assertFilesCount; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.assertImplementsIfc; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.cleanUp; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.getSourceFiles; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.testAugmentation; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.testCompilation; -import com.google.common.collect.ImmutableSet; -import java.io.File; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.List; -import org.junit.Test; -import org.opendaylight.yangtools.sal.binding.model.api.Type; -import org.opendaylight.yangtools.sal.java.api.generator.GeneratorJavaFile; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; - -public class AugmentToUsesInAugmentCompilationTest extends BaseCompilationTest { - - @Test - public void testAugmentToUsesInAugment() throws Exception { - final File sourcesOutputDir = new File(GENERATOR_OUTPUT_PATH + FS + "augment-uses-to-augment"); - assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir()); - final File compiledOutputDir = new File(COMPILER_OUTPUT_PATH + FS + "augment-uses-to-augment"); - assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir()); - - final List sourceFiles = getSourceFiles("/compilation/augment-uses-to-augment"); - final SchemaContext context = RetestUtils.parseYangSources(sourceFiles); - final List types = bindingGenerator.generateTypes(context); - final GeneratorJavaFile generator = new GeneratorJavaFile(ImmutableSet.copyOf(types)); - generator.generateToFile(sourcesOutputDir); - - // Test if all sources are generated from 'module foo' - File fooParent = new File(sourcesOutputDir, NS_FOO); - assertFilesCount(fooParent, 4); - assertTrue(new File(fooParent, "IgpLinkAttributes.java").exists()); - assertTrue(new File(fooParent, "Link1.java").exists()); - assertTrue(new File(fooParent, "Link1Builder.java").exists()); - - // Test if all sources are generated from 'module bar' - File barParent = new File(sourcesOutputDir, NS_BAR); - assertFilesCount(barParent, 7); - assertTrue(new File(barParent, "BarData.java").exists()); - assertTrue(new File(barParent, "NetworkTopology.java").exists()); - assertTrue(new File(barParent, "NetworkTopologyBuilder.java").exists()); - assertTrue(new File(barParent, "Link.java").exists()); - assertTrue(new File(barParent, "LinkAttributes.java").exists()); - - File networkParent = new File(barParent, "network"); - assertFilesCount(networkParent, 1); - File topologyParent = new File(networkParent, "topology"); - assertFilesCount(topologyParent, 3); - assertTrue(new File(topologyParent, "Topology.java").exists()); - assertTrue(new File(topologyParent, "TopologyBuilder.java").exists()); - assertTrue(new File(topologyParent, "TopologyKey.java").exists()); - - File linkParent = new File(barParent, "link"); - assertFilesCount(linkParent, 3); - assertTrue(new File(linkParent, "Link.java").exists()); - assertTrue(new File(linkParent, "LinkBuilder.java").exists()); - assertTrue(new File(linkParent, "LinkKey.java").exists()); - - // Test if all sources are generated from 'module baz' - File bazParent = new File(sourcesOutputDir, NS_BAZ); - assertFilesCount(bazParent, 4); - assertTrue(new File(bazParent, "IgpLinkAttributes1.java").exists()); - assertTrue(new File(bazParent, "IgpLinkAttributes1Builder.java").exists()); - assertTrue(new File(bazParent, "LinkAttributes.java").exists()); - - // Test if sources are compilable - testCompilation(sourcesOutputDir, compiledOutputDir); - - ClassLoader loader = new URLClassLoader(new URL[] { compiledOutputDir.toURI().toURL() }); - - try { - Class link1Class = Class.forName(BASE_PKG + ".urn.opendaylight.foo.rev131008.Link1", true, loader); - String augmentableNode = BASE_PKG + ".urn.opendaylight.bar.rev131008.link.Link"; - testAugmentation(link1Class, augmentableNode); - - Class igpLinkAttributesClass = Class.forName(BASE_PKG - + ".urn.opendaylight.foo.rev131008.IgpLinkAttributes", true, loader); - assertImplementsIfc(link1Class, igpLinkAttributesClass); - } catch (ClassNotFoundException e) { - throw new AssertionError("Class for augment wasn't generated"); - } - - try { - Class igpLinkAttributes1Class = Class.forName(BASE_PKG - + ".urn.opendaylight.baz.rev131008.IgpLinkAttributes1", true, loader); - String augmentableNode = BASE_PKG + ".urn.opendaylight.foo.rev131008.igp.link.attributes.IgpLinkAttributes"; - testAugmentation(igpLinkAttributes1Class, augmentableNode); - - Class linkAttributesClass = Class.forName(BASE_PKG + ".urn.opendaylight.baz.rev131008.LinkAttributes", - true, loader); - assertImplementsIfc(igpLinkAttributes1Class, linkAttributesClass); - } catch (ClassNotFoundException e) { - throw new AssertionError("Class for augment wasn't generated"); - } - - cleanUp(sourcesOutputDir, compiledOutputDir); - } - -} diff --git a/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/stmt/parser/retest/BaseCompilationTest.java b/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/stmt/parser/retest/BaseCompilationTest.java deleted file mode 100644 index 8c1e94df9f..0000000000 --- a/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/stmt/parser/retest/BaseCompilationTest.java +++ /dev/null @@ -1,38 +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.yangtools.sal.java.api.generator.stmt.parser.retest; - -import static org.junit.Assert.assertTrue; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.COMPILER_OUTPUT_DIR; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.GENERATOR_OUTPUT_DIR; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.TEST_DIR; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.deleteTestDir; -import org.junit.Before; -import org.junit.BeforeClass; -import org.opendaylight.yangtools.sal.binding.generator.api.BindingGenerator; -import org.opendaylight.yangtools.sal.binding.generator.impl.BindingGeneratorImpl; - -public abstract class BaseCompilationTest { - - protected BindingGenerator bindingGenerator; - - @BeforeClass - public static void createTestDirs() { - if (TEST_DIR.exists()) { - deleteTestDir(TEST_DIR); - } - assertTrue(GENERATOR_OUTPUT_DIR.mkdirs()); - assertTrue(COMPILER_OUTPUT_DIR.mkdirs()); - } - - @Before - public void init() { - bindingGenerator = new BindingGeneratorImpl(true); - } - -} diff --git a/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/stmt/parser/retest/Bug1276Test.java b/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/stmt/parser/retest/Bug1276Test.java deleted file mode 100644 index 0cbefe8795..0000000000 --- a/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/stmt/parser/retest/Bug1276Test.java +++ /dev/null @@ -1,104 +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.yangtools.sal.java.api.generator.stmt.parser.retest; - -import static org.junit.Assert.assertTrue; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.BASE_PKG; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.COMPILER_OUTPUT_PATH; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.FS; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.GENERATOR_OUTPUT_PATH; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.assertContainsConstructor; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.cleanUp; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.getSourceFiles; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.testCompilation; -import com.google.common.collect.ImmutableSet; -import java.io.File; -import java.lang.reflect.Constructor; -import java.lang.reflect.Method; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.Arrays; -import java.util.List; -import org.junit.Test; -import org.opendaylight.yangtools.sal.binding.model.api.Type; -import org.opendaylight.yangtools.sal.java.api.generator.GeneratorJavaFile; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; - -/** - * Previous construction of union constructor - * - * - * public IpAddress(Arg1 _arg1) { - * super(); - * this._arg1 = _arg1; - * this._arg2 = null; - * this._value = null; - * } - * - * - * was incorrect and setting - * - * this._value == null - * - * was replaced with setting _value to correct value, for example: - * - * this._value = arg1.getValue() or - * this._value = _arg1.getValue().toString().toCharArray() - * - */ -public class Bug1276Test extends BaseCompilationTest { - - @Test - public void test() throws Exception { - final File sourcesOutputDir = new File(GENERATOR_OUTPUT_PATH + FS + "bug1276"); - assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir()); - final File compiledOutputDir = new File(COMPILER_OUTPUT_PATH + FS + "bug1276"); - assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir()); - - generateTestSources("/compilation/bug1276", sourcesOutputDir); - - // Test if sources are compilable - testCompilation(sourcesOutputDir, compiledOutputDir); - - ClassLoader loader = new URLClassLoader(new URL[] { compiledOutputDir.toURI().toURL() }); - Class ipAddressClass = Class.forName(BASE_PKG + ".test.yang.union.rev140715.IpAddress", true, loader); - Class ipv4AddressClass = Class.forName(BASE_PKG + ".test.yang.union.rev140715.Ipv4Address", true, loader); - Class hostClass = Class.forName(BASE_PKG + ".test.yang.union.rev140715.Host", true, loader); - - Constructor ipAddressConstructor = assertContainsConstructor(ipAddressClass, ipv4AddressClass); - Constructor ipv4addressConstructor = assertContainsConstructor(ipv4AddressClass, String.class); - Constructor hostConstructor = assertContainsConstructor(hostClass, ipAddressClass); - - // test IpAddress with Ipv4Address argument - Object ipv4address = ipv4addressConstructor.newInstance("192.168.0.1"); - Object ipAddress = ipAddressConstructor.newInstance(ipv4address); - Method getValue = ipAddressClass.getDeclaredMethod("getValue"); - char[] expected = "192.168.0.1".toCharArray(); - Object actual = getValue.invoke(ipAddress); - assertTrue(actual instanceof char[]); - assertTrue(Arrays.equals(expected, (char[]) actual)); - - // test Host with IpAddress argument - Object host = hostConstructor.newInstance(ipAddress); - getValue = hostClass.getDeclaredMethod("getValue"); - actual = getValue.invoke(host); - assertTrue(actual instanceof char[]); - assertTrue(Arrays.equals(expected, (char[]) actual)); - - cleanUp(sourcesOutputDir, compiledOutputDir); - } - - private void generateTestSources(final String resourceDirPath, final File sourcesOutputDir) throws Exception { - final List sourceFiles = getSourceFiles(resourceDirPath); - final SchemaContext context = RetestUtils.parseYangSources(sourceFiles); - final List types = bindingGenerator.generateTypes(context); - final GeneratorJavaFile generator = new GeneratorJavaFile(ImmutableSet.copyOf(types)); - generator.generateToFile(sourcesOutputDir); - } - -} diff --git a/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/stmt/parser/retest/Bug532Test.java b/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/stmt/parser/retest/Bug532Test.java deleted file mode 100644 index ddd169799e..0000000000 --- a/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/stmt/parser/retest/Bug532Test.java +++ /dev/null @@ -1,119 +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.yangtools.sal.java.api.generator.stmt.parser.retest; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.BASE_PKG; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.COMPILER_OUTPUT_PATH; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.FS; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.GENERATOR_OUTPUT_PATH; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.cleanUp; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.getSourceFiles; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.testCompilation; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Lists; -import java.io.File; -import java.lang.reflect.Constructor; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.List; -import org.junit.Test; -import org.mockito.Mockito; -import org.opendaylight.yangtools.sal.binding.model.api.Type; -import org.opendaylight.yangtools.sal.java.api.generator.GeneratorJavaFile; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; - -/** - * Test correct functionality of copy constructor of generated builder classes. - */ -public class Bug532Test extends BaseCompilationTest { - - @Test - public void test() throws Exception { - final File sourcesOutputDir = new File(GENERATOR_OUTPUT_PATH + FS + "bug532"); - assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir()); - final File compiledOutputDir = new File(COMPILER_OUTPUT_PATH + FS + "bug532"); - assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir()); - - generateTestSources("/compilation/list-gen-retest", sourcesOutputDir); - - // Test if sources are compilable - testCompilation(sourcesOutputDir, compiledOutputDir); - - ClassLoader loader = new URLClassLoader(new URL[] { compiledOutputDir.toURI().toURL() }); - Class linksKeyClass = Class.forName(BASE_PKG + ".urn.opendaylight.retest.rev131008.LinksKey", true, loader); - Class linksClass = Class.forName(BASE_PKG + ".urn.opendaylight.retest.rev131008.Links", true, loader); - Class linksBuilderClass = Class.forName(BASE_PKG + ".urn.opendaylight.retest.rev131008.LinksBuilder", true, - loader); - Class levelClass = Class.forName(BASE_PKG + ".urn.opendaylight.retest.rev131008.links.Level", true, loader); - Class nodeClass = Class.forName(BASE_PKG + ".urn.opendaylight.retest.rev131008.links.Node", true, loader); - Class nodeListClass = Class.forName(BASE_PKG + ".urn.opendaylight.retest.rev131008.links.NodeList", true, - loader); - - // init default values - Byte expectedId = Byte.valueOf("5"); - String expectedName = "test-link"; - Integer expectedSize = Integer.valueOf(10); - - - Object expectedLevel = Mockito.mock(levelClass); - Integer expectedLinksId = Integer.valueOf(11); - Object expectedNode = Mockito.mock(nodeClass); - List expectedNodeList = Lists.newArrayList(Mockito.mock(nodeListClass), Mockito.mock(nodeListClass)); - Constructor keyConstructor = linksKeyClass.getDeclaredConstructor(Byte.class, String.class, Integer.class); - Object expectedKey = keyConstructor.newInstance(expectedId, expectedName, expectedSize); - - // create Links object - Object linksBuilder = linksBuilderClass.newInstance(); - linksBuilderClass.getDeclaredMethod("setKey", linksKeyClass).invoke(linksBuilder, expectedKey); - linksBuilderClass.getDeclaredMethod("setLevel", levelClass).invoke(linksBuilder, expectedLevel); - linksBuilderClass.getDeclaredMethod("setLinksId", Integer.class).invoke(linksBuilder, expectedLinksId); - linksBuilderClass.getDeclaredMethod("setNode", nodeClass).invoke(linksBuilder, expectedNode); - linksBuilderClass.getDeclaredMethod("setNodeList", List.class).invoke(linksBuilder, expectedNodeList); - Object links = linksBuilderClass.getDeclaredMethod("build").invoke(linksBuilder); - - // create LinksBuilder object with constructor with Links object - // argument - Constructor linksBuilderConstructor = linksBuilderClass.getDeclaredConstructor(linksClass); - assertNotNull(linksBuilderConstructor); - Object linksBuilderTested = linksBuilderConstructor.newInstance(links); - - // get values from LinksBuilder - Object actualKey = linksBuilderClass.getDeclaredMethod("getKey").invoke(linksBuilderTested); - Object actualId = linksBuilderClass.getDeclaredMethod("getId").invoke(linksBuilderTested); - Object actualName = linksBuilderClass.getDeclaredMethod("getName").invoke(linksBuilderTested); - Object actualSize = linksBuilderClass.getDeclaredMethod("getSize").invoke(linksBuilderTested); - Object actualLevel = linksBuilderClass.getDeclaredMethod("getLevel").invoke(linksBuilderTested); - Object actualLinksId = linksBuilderClass.getDeclaredMethod("getLinksId").invoke(linksBuilderTested); - Object actualNode = linksBuilderClass.getDeclaredMethod("getNode").invoke(linksBuilderTested); - Object actualNodeList = linksBuilderClass.getDeclaredMethod("getNodeList").invoke(linksBuilderTested); - - // test - assertEquals(expectedKey, actualKey); - assertEquals(expectedId, actualId); - assertEquals(expectedName, actualName); - assertEquals(expectedSize, actualSize); - assertEquals(expectedLevel, actualLevel); - assertEquals(expectedLinksId, actualLinksId); - assertEquals(expectedNode, actualNode); - assertEquals(expectedNodeList, actualNodeList); - - cleanUp(sourcesOutputDir, compiledOutputDir); - } - - private void generateTestSources(final String resourceDirPath, final File sourcesOutputDir) throws Exception { - final List sourceFiles = getSourceFiles(resourceDirPath); - final SchemaContext context = RetestUtils.parseYangSources(sourceFiles); - final List types = bindingGenerator.generateTypes(context); - final GeneratorJavaFile generator = new GeneratorJavaFile(ImmutableSet.copyOf(types)); - generator.generateToFile(sourcesOutputDir); - } - -} diff --git a/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/stmt/parser/retest/CascadeUsesCompilationTest.java b/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/stmt/parser/retest/CascadeUsesCompilationTest.java deleted file mode 100644 index 8ac68512c5..0000000000 --- a/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/stmt/parser/retest/CascadeUsesCompilationTest.java +++ /dev/null @@ -1,143 +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.yangtools.sal.java.api.generator.stmt.parser.retest; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.BASE_PKG; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.COMPILER_OUTPUT_PATH; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.FS; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.GENERATOR_OUTPUT_PATH; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.NS_BAR; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.NS_BAZ; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.NS_FOO; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.assertFilesCount; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.assertImplementsIfc; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.cleanUp; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.getSourceFiles; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.testCompilation; -import com.google.common.collect.ImmutableSet; -import java.io.File; -import java.lang.reflect.Constructor; -import java.lang.reflect.Method; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.List; -import org.junit.Test; -import org.opendaylight.yangtools.sal.binding.model.api.Type; -import org.opendaylight.yangtools.sal.java.api.generator.GeneratorJavaFile; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; - -public class CascadeUsesCompilationTest extends BaseCompilationTest { - - @Test - public void testCascadeUsesCompilation() throws Exception { - final File sourcesOutputDir = new File(GENERATOR_OUTPUT_PATH + FS + "cascade-uses"); - assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir()); - final File compiledOutputDir = new File(COMPILER_OUTPUT_PATH + FS + "cascade-uses"); - assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir()); - - final List sourceFiles = getSourceFiles("/compilation/cascade-uses"); - final SchemaContext context = RetestUtils.parseYangSources(sourceFiles); - final List types = bindingGenerator.generateTypes(context); - final GeneratorJavaFile generator = new GeneratorJavaFile(ImmutableSet.copyOf(types)); - generator.generateToFile(sourcesOutputDir); - - // Test if all sources are generated from module foo - File parent = new File(sourcesOutputDir, NS_FOO); - assertFilesCount(parent, 5); - File fooData = new File(parent, "FooData.java"); - File foo_gr1 = new File(parent, "FooGr1.java"); - File nodes = new File(parent, "Nodes.java"); - File nodesBuilder = new File(parent, "NodesBuilder.java"); - assertTrue(fooData.exists()); - assertTrue(foo_gr1.exists()); - assertTrue(nodes.exists()); - assertTrue(nodesBuilder.exists()); - - // Test if all sources are generated from module bar - parent = new File(sourcesOutputDir, NS_BAR); - assertFilesCount(parent, 2); - File barGr1 = new File(parent, "BarGr1.java"); - File barGr2 = new File(parent, "BarGr2.java"); - assertTrue(barGr1.exists()); - assertTrue(barGr2.exists()); - - // Test if all sources are generated from module baz - parent = new File(sourcesOutputDir, NS_BAZ); - assertFilesCount(parent, 1); - File bazGr1 = new File(parent, "BazGr1.java"); - assertTrue(bazGr1.exists()); - - // Test if sources are compilable - testCompilation(sourcesOutputDir, compiledOutputDir); - - ClassLoader loader = new URLClassLoader(new URL[] { compiledOutputDir.toURI().toURL() }); - Class nodesClass = Class.forName(BASE_PKG + ".urn.opendaylight.foo.rev131008.Nodes", true, - loader); - Class nodesBuilderClass = Class.forName(BASE_PKG + ".urn.opendaylight.foo.rev131008.NodesBuilder", true, - loader); - Class fooGr1Class = Class.forName(BASE_PKG + ".urn.opendaylight.foo.rev131008.FooGr1", true, loader); - Class barGr2Class = Class.forName(BASE_PKG + ".urn.opendaylight.bar.rev131008.BarGr2", true, loader); - Class barGr1Class = Class.forName(BASE_PKG + ".urn.opendaylight.bar.rev131008.BarGr1", true, loader); - Class bazGr1Class = Class.forName(BASE_PKG + ".urn.opendaylight.baz.rev131008.BazGr1", true, loader); - - // test generated interface from 'container nodes' - assertImplementsIfc(nodesClass, fooGr1Class); - assertImplementsIfc(nodesClass, barGr2Class); - - // test generated builder for 'container nodes' - assertFalse(nodesBuilderClass.isInterface()); - Constructor[] nodesBuilderConstructors = nodesBuilderClass.getConstructors(); - assertEquals(6, nodesBuilderConstructors.length); - - // test generation of builder constructors from uses in 'container nodes' - Constructor defaultConstructor = null; - Constructor usesFooGr1 = null; - Constructor usesBarGr2 = null; - Constructor usesBarGr1 = null; - Constructor usesBazGr1 = null; - for (Constructor c : nodesBuilderConstructors) { - Class[] params = c.getParameterTypes(); - if (params.length == 0) { - defaultConstructor = c; - } else { - assertEquals(1, params.length); - if (params[0].equals(fooGr1Class)) { - usesFooGr1 = c; - } else if (params[0].equals(barGr2Class)) { - usesBarGr2 = c; - } else if (params[0].equals(barGr1Class)) { - usesBarGr1 = c; - } else if (params[0].equals(bazGr1Class)) { - usesBazGr1 = c; - } - } - } - assertNotNull(defaultConstructor); - assertNotNull(usesFooGr1); - assertNotNull(usesBarGr2); - assertNotNull(usesBarGr1); - assertNotNull(usesBazGr1); - - Method fieldsFromMethod = null; - for (Method m : nodesBuilderClass.getDeclaredMethods()) { - String methodName = m.getName(); - if ("fieldsFrom".equals(methodName)) { - fieldsFromMethod = m; - } - } - assertNotNull(fieldsFromMethod); - assertEquals(1, fieldsFromMethod.getParameterTypes().length); - - cleanUp(sourcesOutputDir, compiledOutputDir); - } - -} diff --git a/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/stmt/parser/retest/ClassCodeGeneratorTest.java b/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/stmt/parser/retest/ClassCodeGeneratorTest.java deleted file mode 100644 index d351fdc750..0000000000 --- a/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/stmt/parser/retest/ClassCodeGeneratorTest.java +++ /dev/null @@ -1,146 +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.yangtools.sal.java.api.generator.stmt.parser.retest; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import java.io.File; -import java.io.IOException; -import java.net.URISyntaxException; -import java.util.ArrayList; -import java.util.List; -import org.junit.BeforeClass; -import org.junit.Test; -import org.opendaylight.yangtools.binding.generator.util.Types; -import org.opendaylight.yangtools.binding.generator.util.generated.type.builder.GeneratedTOBuilderImpl; -import org.opendaylight.yangtools.sal.binding.generator.api.BindingGenerator; -import org.opendaylight.yangtools.sal.binding.generator.impl.BindingGeneratorImpl; -import org.opendaylight.yangtools.sal.binding.model.api.GeneratedProperty; -import org.opendaylight.yangtools.sal.binding.model.api.GeneratedTransferObject; -import org.opendaylight.yangtools.sal.binding.model.api.GeneratedType; -import org.opendaylight.yangtools.sal.binding.model.api.Type; -import org.opendaylight.yangtools.sal.binding.model.api.type.builder.GeneratedPropertyBuilder; -import org.opendaylight.yangtools.sal.binding.model.api.type.builder.GeneratedTOBuilder; -import org.opendaylight.yangtools.sal.java.api.generator.TOGenerator; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; -import org.opendaylight.yangtools.yang.parser.spi.source.SourceException; - -public class ClassCodeGeneratorTest { - - private final static List testModels = new ArrayList(); - - @BeforeClass - public static void loadTestResources() throws URISyntaxException { - final File listModelFile = new File(ClassCodeGeneratorTest.class - .getResource("/list-composite-key.yang").toURI()); - testModels.add(listModelFile); - } - - @Test - public void compositeKeyClassTest() throws IOException, SourceException, ReactorException { - - final SchemaContext context = RetestUtils.parseYangSources(testModels); - - assertNotNull(context); - final BindingGenerator bindingGen = new BindingGeneratorImpl(true); - final List genTypes = bindingGen.generateTypes(context); - - assertTrue(genTypes != null); - assertEquals(7, genTypes.size()); - - int genTypesCount = 0; - int genTOsCount = 0; - for (final Type type : genTypes) { - if (type instanceof GeneratedType - && !(type instanceof GeneratedTransferObject)) { - genTypesCount++; - } else if (type instanceof GeneratedTransferObject) { - final GeneratedTransferObject genTO = (GeneratedTransferObject) type; - - if (genTO.getName().equals("CompositeKeyListKey")) { - final List properties = genTO - .getProperties(); - int propertyCount = 0; - for (final GeneratedProperty prop : properties) { - if (prop.getName().equals("key1")) { - propertyCount++; - } else if (prop.getName().equals("key2")) { - propertyCount++; - } - } - - final TOGenerator clsGen = new TOGenerator(); - final String outputStr = clsGen.generate(genTO); - - assertNotNull(outputStr); - assertTrue(outputStr.contains("public CompositeKeyListKey(java.lang.Byte _key1, java.lang.String _key2)")); - - assertEquals(2, propertyCount); - genTOsCount++; - } else if (genTO.getName().equals("InnerListKey")) { - final List properties = genTO - .getProperties(); - assertEquals(1, properties.size()); - genTOsCount++; - } - } - } - - assertEquals(5, genTypesCount); - assertEquals(2, genTOsCount); - } - - /** - * Test for testing of false scenario. - * - * Test tests value types. Value types are not allowed to have default constructor. - */ - @Test - public void defaultConstructorNotPresentInValueTypeTest() { - final GeneratedTOBuilder toBuilder = new GeneratedTOBuilderImpl( - "simple.pack", "DefCtor"); - - GeneratedPropertyBuilder propBuilder = toBuilder.addProperty("foo"); - propBuilder.setReturnType(Types.typeForClass(String.class)); - propBuilder.setReadOnly(false); - - propBuilder = toBuilder.addProperty("bar"); - propBuilder.setReturnType(Types.typeForClass(Integer.class)); - propBuilder.setReadOnly(false); - - final GeneratedTransferObject genTO = toBuilder.toInstance(); - - final TOGenerator clsGen = new TOGenerator(); - final String outputStr = clsGen.generate(genTO); - - assertNotNull(outputStr); - assertFalse(outputStr.contains("public DefCtor()")); - } - - @Test - public void toStringTest() { - final GeneratedTOBuilder toBuilder = new GeneratedTOBuilderImpl( - "simple.pack", "DefCtor"); - - GeneratedPropertyBuilder propBuilder = toBuilder.addProperty("foo"); - propBuilder.setReturnType(Types.typeForClass(String.class)); - propBuilder.setReadOnly(false); - toBuilder.addToStringProperty(propBuilder); - - propBuilder = toBuilder.addProperty("bar"); - propBuilder.setReturnType(Types.typeForClass(Integer.class)); - propBuilder.setReadOnly(false); - toBuilder.addToStringProperty(propBuilder); - final GeneratedTransferObject genTO = toBuilder.toInstance(); - final TOGenerator clsGen = new TOGenerator(); - assertNotNull(clsGen.generate(genTO)); - } -} diff --git a/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/stmt/parser/retest/CompilationTest.java b/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/stmt/parser/retest/CompilationTest.java deleted file mode 100644 index c12718b1cb..0000000000 --- a/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/stmt/parser/retest/CompilationTest.java +++ /dev/null @@ -1,705 +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.yangtools.sal.java.api.generator.stmt.parser.retest; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.BASE_PKG; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.COMPILER_OUTPUT_PATH; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.FS; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.GENERATOR_OUTPUT_PATH; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.NS_BAR; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.NS_BAZ; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.NS_FOO; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.NS_TEST; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.assertContainsConstructor; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.assertContainsField; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.assertContainsMethod; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.assertContainsRestrictionCheck; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.assertFilesCount; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.assertImplementsIfc; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.assertImplementsParameterizedIfc; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.cleanUp; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.getSourceFiles; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.testCompilation; - -import com.google.common.base.Predicate; -import com.google.common.collect.Collections2; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Range; -import java.io.File; -import java.lang.annotation.Annotation; -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import java.lang.reflect.ParameterizedType; -import java.lang.reflect.WildcardType; -import java.math.BigDecimal; -import java.math.BigInteger; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Comparator; -import java.util.List; -import org.junit.Test; -import org.opendaylight.yangtools.sal.binding.model.api.Type; -import org.opendaylight.yangtools.sal.java.api.generator.GeneratorJavaFile; -import org.opendaylight.yangtools.yang.binding.ChildOf; -import org.opendaylight.yangtools.yang.binding.annotations.RoutingContext; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; - -/** - * Test correct code generation. - * - */ -public class CompilationTest extends BaseCompilationTest { - - /* - * Java 8 allows JaCoCo to hook onto interfaces, as well as - * generating a default implementation. We only want to check - * abstract methods. - */ - private static Collection abstractMethods(final Class clazz) { - // Filter out - return Collections2.filter(Arrays.asList(clazz.getDeclaredMethods()), new Predicate() { - @Override - public boolean apply(final Method input) { - return Modifier.isAbstract(input.getModifiers()); - } - }); - } - - @Test - public void testListGeneration() throws Exception { - final File sourcesOutputDir = new File(GENERATOR_OUTPUT_PATH + FS + "list-gen"); - assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir()); - final File compiledOutputDir = new File(COMPILER_OUTPUT_PATH + FS + "list-gen"); - assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir()); - - generateTestSources("/compilation/list-gen", sourcesOutputDir); - - // Test if all sources are generated - File parent = new File(sourcesOutputDir, NS_TEST); - final File keyArgs = new File(parent, "KeyArgs.java"); - final File links = new File(parent, "Links.java"); - final File linksBuilder = new File(parent, "LinksBuilder.java"); - final File linksKey = new File(parent, "LinksKey.java"); - final File testData = new File(parent, "TestData.java"); - assertTrue(keyArgs.exists()); - assertTrue(links.exists()); - assertTrue(linksBuilder.exists()); - assertTrue(linksKey.exists()); - assertTrue(testData.exists()); - assertFilesCount(parent, 6); - - parent = new File(sourcesOutputDir, NS_TEST + FS + "links"); - final File level = new File(parent, "Level.java"); - final File linkGroup = new File(parent, "LinkGroup.java"); - final File node = new File(parent, "Node.java"); - final File nodeBuilder = new File(parent, "NodeBuilder.java"); - final File nodeList = new File(parent, "NodeList.java"); - final File nodeListBuilder = new File(parent, "NodeListBuilder.java"); - final File nodesType = new File(parent, "NodesType.java"); - assertTrue(level.exists()); - assertTrue(linkGroup.exists()); - assertTrue(node.exists()); - assertTrue(nodeBuilder.exists()); - assertTrue(nodeList.exists()); - assertTrue(nodeListBuilder.exists()); - assertTrue(nodesType.exists()); - assertFilesCount(parent, 7); - - // Test if sources are compilable - testCompilation(sourcesOutputDir, compiledOutputDir); - - final ClassLoader loader = new URLClassLoader(new URL[] { compiledOutputDir.toURI().toURL() }); - final Class keyArgsClass = Class.forName(BASE_PKG + ".urn.opendaylight.test.rev131008.KeyArgs", true, loader); - final Class linksClass = Class.forName(BASE_PKG + ".urn.opendaylight.test.rev131008.Links", true, loader); - final Class linksKeyClass = Class.forName(BASE_PKG + ".urn.opendaylight.test.rev131008.LinksKey", true, loader); - - // Test generated 'grouping key-args' - assertTrue(keyArgsClass.isInterface()); - assertContainsMethod(keyArgsClass, String.class, "getName"); - assertContainsMethod(keyArgsClass, Integer.class, "getSize"); - assertEquals(2, abstractMethods(keyArgsClass).size()); - - // Test generated 'list links' - assertTrue(linksClass.isInterface()); - assertImplementsIfc(linksClass, keyArgsClass); - // TODO: anyxml - assertEquals(6, abstractMethods(linksClass).size()); - - // Test list key constructor arguments ordering - assertContainsConstructor(linksKeyClass, Byte.class, String.class, Integer.class); - // Test serialVersionUID generation - final Field suid = assertContainsField(linksKeyClass, "serialVersionUID", Long.TYPE); - suid.setAccessible(true); - assertEquals(-8829501012356283881L, suid.getLong(null)); - - cleanUp(sourcesOutputDir, compiledOutputDir); - } - - @Test - public void testAugmentUnderUsesGeneration() throws Exception { - final File sourcesOutputDir = new File(GENERATOR_OUTPUT_PATH + FS + "augment-under-uses"); - assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir()); - final File compiledOutputDir = new File(COMPILER_OUTPUT_PATH + FS + "augment-under-uses"); - assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir()); - - generateTestSources("/compilation/augment-under-uses", sourcesOutputDir); - - // Test if all sources were generated from 'module foo' - File parent = new File(sourcesOutputDir, NS_FOO); - assertTrue(new File(parent, "Object.java").exists()); - assertTrue(new File(parent, "ClosedObject.java").exists()); - assertTrue(new File(parent, "OpenObject.java").exists()); - assertTrue(new File(parent, "ExplicitRouteObject.java").exists()); - assertTrue(new File(parent, "PathKeySubobject.java").exists()); - assertFilesCount(parent, 9); - - parent = new File(parent, "object"); - assertTrue(new File(parent, "Nodes.java").exists()); - assertTrue(new File(parent, "NodesBuilder.java").exists()); - assertFilesCount(parent, 2); - - parent = new File(sourcesOutputDir, NS_FOO + FS + "closed"); - assertFilesCount(parent, 1); - - parent = new File(parent, "object"); - assertTrue(new File(parent, "Link1.java").exists()); - assertTrue(new File(parent, "Link1Builder.java").exists()); - assertFilesCount(parent, 2); - - parent = new File(sourcesOutputDir, NS_FOO + FS + "open"); - assertFilesCount(parent, 1); - - parent = new File(parent, "object"); - assertTrue(new File(parent, "Nodes1.java").exists()); - assertTrue(new File(parent, "Nodes1Builder.java").exists()); - assertFilesCount(parent, 3); - - parent = new File(parent, "nodes"); - assertTrue(new File(parent, "Links.java").exists()); - assertTrue(new File(parent, "LinksBuilder.java").exists()); - assertFilesCount(parent, 2); - - parent = new File(sourcesOutputDir, NS_FOO + FS + "explicit"); - assertFilesCount(parent, 1); - parent = new File(parent, "route"); - assertFilesCount(parent, 1); - parent = new File(parent, "object"); - assertTrue(new File(parent, "Subobjects.java").exists()); - assertTrue(new File(parent, "SubobjectsBuilder.java").exists()); - assertFilesCount(parent, 3); - - parent = new File(parent, "subobjects"); - assertFilesCount(parent, 1); - parent = new File(parent, "subobject"); - assertFilesCount(parent, 1); - parent = new File(parent, "type"); - assertTrue(new File(parent, "PathKey.java").exists()); - assertTrue(new File(parent, "PathKeyBuilder.java").exists()); - assertFilesCount(parent, 3); - - parent = new File(parent, "path"); - assertFilesCount(parent, 1); - parent = new File(parent, "key"); - assertTrue(new File(parent, "PathKey.java").exists()); - assertTrue(new File(parent, "PathKeyBuilder.java").exists()); - assertFilesCount(parent, 2); - - // Test if all sources were generated from 'module bar' - parent = new File(sourcesOutputDir, NS_BAR); - assertTrue(new File(parent, "BasicExplicitRouteSubobjects.java").exists()); - assertTrue(new File(parent, "ExplicitRouteSubobjects.java").exists()); - assertTrue(new File(parent, "RouteSubobjects.java").exists()); - assertFilesCount(parent, 5); - - parent = new File(parent, "route"); - assertFilesCount(parent, 1); - parent = new File(new File(sourcesOutputDir, NS_BAR), "basic"); - assertFilesCount(parent, 1); - parent = new File(parent, "explicit"); - assertFilesCount(parent, 1); - parent = new File(parent, "route"); - assertFilesCount(parent, 1); - - parent = new File(parent, "subobjects"); - assertFilesCount(parent, 2); - assertTrue(new File(parent, "SubobjectType.java").exists()); - - parent = new File(parent, "subobject"); - assertFilesCount(parent, 1); - - parent = new File(parent, "type"); - assertTrue(new File(parent, "IpPrefix.java").exists()); - assertTrue(new File(parent, "IpPrefixBuilder.java").exists()); - assertTrue(new File(parent, "Label.java").exists()); - assertTrue(new File(parent, "LabelBuilder.java").exists()); - assertFilesCount(parent, 4); - - // Test if sources are compilable - testCompilation(sourcesOutputDir, compiledOutputDir); - - cleanUp(sourcesOutputDir, compiledOutputDir); - } - - @Test - public void testAugmentOfAugmentGeneration() throws Exception { - final File sourcesOutputDir = new File(GENERATOR_OUTPUT_PATH + FS + "aug-of-aug"); - assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir()); - final File compiledOutputDir = new File(COMPILER_OUTPUT_PATH + FS + "aug-of-aug"); - assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir()); - - generateTestSources("/compilation/augment-of-augment", sourcesOutputDir); - - // Test if all sources were generated from 'module foo' - File parent = new File(sourcesOutputDir, NS_FOO); - final File fooListener = new File(parent, "FooListener.java"); - File pathAttributes = new File(parent, "PathAttributes.java"); - final File update = new File(parent, "Update.java"); - final File updateBuilder = new File(parent, "UpdateBuilder.java"); - assertTrue(fooListener.exists()); - assertTrue(pathAttributes.exists()); - assertTrue(update.exists()); - assertTrue(updateBuilder.exists()); - assertFilesCount(parent, 6); - - parent = new File(sourcesOutputDir, NS_FOO + FS + "path"); - assertFilesCount(parent, 1); - parent = new File(parent, "attributes"); - assertFilesCount(parent, 2); - final File origin = new File(parent, "Origin.java"); - final File originBuilder = new File(parent, "OriginBuilder.java"); - assertTrue(origin.exists()); - assertTrue(originBuilder.exists()); - - parent = new File(sourcesOutputDir, NS_FOO + FS + "update"); - assertFilesCount(parent, 2); - pathAttributes = new File(parent, "PathAttributes.java"); - final File pathAttributesBuilder = new File(parent, "PathAttributesBuilder.java"); - assertTrue(pathAttributes.exists()); - assertTrue(pathAttributesBuilder.exists()); - - // Test if all sources were generated from 'module bar' - parent = new File(sourcesOutputDir, NS_BAR); - final File destination = new File(parent, "Destination.java"); - final File pathAttributes1 = new File(parent, "PathAttributes1.java"); - final File pathAttributes1Builder = new File(parent, "PathAttributes1Builder.java"); - assertTrue(destination.exists()); - assertTrue(pathAttributes1.exists()); - assertTrue(pathAttributes1Builder.exists()); - assertFilesCount(parent, 5); - - parent = new File(sourcesOutputDir, NS_BAR + FS + "destination"); - assertFilesCount(parent, 2); - final File destinationType = new File(parent, "DestinationType.java"); - assertTrue(destinationType.exists()); - - parent = new File(parent, "destination"); - assertFilesCount(parent, 1); - parent = new File(parent, "type"); - assertFilesCount(parent, 2); - final File destinationIpv4 = new File(parent, "DestinationIp.java"); - final File destinationIpv4Builder = new File(parent, "DestinationIpBuilder.java"); - assertTrue(destinationIpv4.exists()); - assertTrue(destinationIpv4Builder.exists()); - - parent = new File(sourcesOutputDir, NS_BAR + FS + "update"); - assertFilesCount(parent, 1); - parent = new File(parent, "path"); - assertFilesCount(parent, 1); - parent = new File(parent, "attributes"); - final File mpUnreachNlri = new File(parent, "MpUnreachNlri.java"); - final File mpUnreachNlriBuilder = new File(parent, "MpUnreachNlriBuilder.java"); - assertTrue(mpUnreachNlri.exists()); - assertTrue(mpUnreachNlriBuilder.exists()); - assertFilesCount(parent, 3); - - parent = new File(parent, "mp"); - assertFilesCount(parent, 1); - parent = new File(parent, "unreach"); - assertFilesCount(parent, 1); - parent = new File(parent, "nlri"); - final File withdrawnRoutes = new File(parent, "WithdrawnRoutes.java"); - final File withdrawnRoutesBuilder = new File(parent, "WithdrawnRoutesBuilder.java"); - assertTrue(withdrawnRoutes.exists()); - assertTrue(withdrawnRoutesBuilder.exists()); - assertFilesCount(parent, 2); - - // Test if all sources were generated from 'module baz' - parent = new File(sourcesOutputDir, NS_BAZ); - assertFilesCount(parent, 2); - final File linkstateDestination = new File(parent, "LinkstateDestination.java"); - assertTrue(linkstateDestination.exists()); - - parent = new File(sourcesOutputDir, NS_BAZ + FS + "update"); - assertFilesCount(parent, 1); - parent = new File(parent, "path"); - assertFilesCount(parent, 1); - parent = new File(parent, "attributes"); - assertFilesCount(parent, 1); - parent = new File(parent, "mp"); - assertFilesCount(parent, 1); - parent = new File(parent, "unreach"); - assertFilesCount(parent, 1); - parent = new File(parent, "nlri"); - assertFilesCount(parent, 1); - parent = new File(parent, "withdrawn"); - assertFilesCount(parent, 1); - parent = new File(parent, "routes"); - assertFilesCount(parent, 1); - parent = new File(parent, "destination"); - assertFilesCount(parent, 1); - parent = new File(parent, "type"); - final File destinationLinkstate = new File(parent, "DestinationLinkstate.java"); - final File destinationLinkstateBuilder = new File(parent, "DestinationLinkstateBuilder.java"); - assertTrue(destinationLinkstate.exists()); - assertTrue(destinationLinkstateBuilder.exists()); - assertFilesCount(parent, 3); - parent = new File(parent, "destination"); - assertFilesCount(parent, 1); - parent = new File(parent, "linkstate"); - final File links = new File(parent, "Links.java"); - final File linksBuilder = new File(parent, "LinksBuilder.java"); - assertTrue(links.exists()); - assertTrue(linksBuilder.exists()); - assertFilesCount(parent, 3); - parent = new File(parent, "links"); - final File source = new File(parent, "Source.java"); - final File sourceBuilder = new File(parent, "SourceBuilder.java"); - assertTrue(source.exists()); - assertTrue(sourceBuilder.exists()); - assertFilesCount(parent, 3); - parent = new File(parent, "source"); - final File address = new File(parent, "Address.java"); - final File addressBuilder = new File(parent, "AddressBuilder.java"); - assertTrue(address.exists()); - assertTrue(addressBuilder.exists()); - assertFilesCount(parent, 2); - - // Test if sources are compilable - testCompilation(sourcesOutputDir, compiledOutputDir); - - cleanUp(sourcesOutputDir, compiledOutputDir); - } - - @Test - public void testLeafReturnTypes() throws Exception { - final File sourcesOutputDir = new File(GENERATOR_OUTPUT_PATH + FS + "leaf-return-types"); - assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir()); - final File compiledOutputDir = new File(COMPILER_OUTPUT_PATH + FS + "leaf-return-types"); - assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir()); - - generateTestSources("/compilation/leaf-return-types", sourcesOutputDir); - - final File parent = new File(sourcesOutputDir, NS_TEST); - assertTrue(new File(parent, "TestData.java").exists()); - assertTrue(new File(parent, "Nodes.java").exists()); - assertTrue(new File(parent, "NodesBuilder.java").exists()); - assertTrue(new File(parent, "Alg.java").exists()); - assertTrue(new File(parent, "NodesIdUnionBuilder.java").exists()); - assertFilesCount(parent, 5); - - // Test if sources are compilable - testCompilation(sourcesOutputDir, compiledOutputDir); - - final String pkg = BASE_PKG + ".urn.opendaylight.test.rev131008"; - final ClassLoader loader = new URLClassLoader(new URL[] { compiledOutputDir.toURI().toURL() }); - final Class nodesClass = Class.forName(pkg + ".Nodes", true, loader); - final Class builderClass = Class.forName(pkg + ".NodesBuilder", true, loader); - - // Test methods return type - final byte[] b = new byte[] {}; - assertContainsMethod(nodesClass, b.getClass(), "getIdBinary"); - assertContainsMethod(nodesClass, pkg + ".Nodes$IdBits", "getIdBits", loader); - assertContainsMethod(nodesClass, Boolean.class, "isIdBoolean"); - assertContainsMethod(nodesClass, BigDecimal.class, "getIdDecimal64"); - assertContainsMethod(nodesClass, Boolean.class, "isIdEmpty"); - assertContainsMethod(nodesClass, pkg + ".Nodes$IdEnumeration", "getIdEnumeration", loader); - testReturnTypeIdentityref(nodesClass, "getIdIdentityref", pkg + ".Alg"); - testReturnTypeInstanceIdentitifer(loader, nodesClass, "getIdInstanceIdentifier"); - assertContainsMethod(nodesClass, Byte.class, "getId8"); - assertContainsMethod(nodesClass, Short.class, "getId16"); - assertContainsMethod(nodesClass, Integer.class, "getId32"); - assertContainsMethod(nodesClass, Long.class, "getId64"); - assertContainsMethod(nodesClass, Long.class, "getIdLeafref"); - assertContainsMethod(nodesClass, String.class, "getIdString"); - assertContainsMethod(nodesClass, Short.class, "getIdU8"); - assertContainsMethod(nodesClass, Integer.class, "getIdU16"); - assertContainsMethod(nodesClass, Long.class, "getIdU32"); - assertContainsMethod(nodesClass, BigInteger.class, "getIdU64"); - assertContainsMethod(nodesClass, pkg + ".Nodes$IdUnion", "getIdUnion", loader); - - final Object builderObj = builderClass.newInstance(); - - Method m = assertContainsMethod(builderClass, builderClass, "setIdBinary", b.getClass()); - final List> lengthConstraints = new ArrayList<>(); - lengthConstraints.add(Range.closed(1, 10)); - byte[] arg = new byte[] {}; - String expectedMsg = String.format("Invalid length: %s, expected: %s.", Arrays.toString(arg), lengthConstraints); - assertContainsRestrictionCheck(builderObj, m, expectedMsg, arg); - - m = assertContainsMethod(builderClass, builderClass, "setIdDecimal64", BigDecimal.class); - final List> rangeConstraints = new ArrayList<>(); - rangeConstraints.add(Range.closed(new BigDecimal("1.5"), new BigDecimal("5.5"))); - Object arg1 = new BigDecimal("1.4"); - expectedMsg = String.format("Invalid range: %s, expected: %s.", arg1, rangeConstraints); - assertContainsRestrictionCheck(builderObj, m, expectedMsg, arg1); - - cleanUp(sourcesOutputDir, compiledOutputDir); - } - - @Test - public void testGenerationContextReferenceExtension() throws Exception { - final File sourcesOutputDir = new File(GENERATOR_OUTPUT_PATH + FS + "context-reference"); - assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir()); - final File compiledOutputDir = new File(COMPILER_OUTPUT_PATH + FS + "context-reference"); - assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir()); - - generateTestSources("/compilation/context-reference", sourcesOutputDir); - - // Test if all sources are generated - final File fooParent = new File(sourcesOutputDir, NS_FOO); - assertFilesCount(fooParent, 3); - assertTrue(new File(fooParent, "FooData.java").exists()); - assertTrue(new File(fooParent, "Nodes.java").exists()); - assertTrue(new File(fooParent, "NodesBuilder.java").exists()); - - final File barParent = new File(sourcesOutputDir, NS_BAR); - assertFilesCount(barParent, 1); - assertTrue(new File(barParent, "IdentityClass.java").exists()); - - // Test if sources are compilable - testCompilation(sourcesOutputDir, compiledOutputDir); - - final ClassLoader loader = new URLClassLoader(new URL[] { compiledOutputDir.toURI().toURL() }); - final Class nodesClass = Class.forName(BASE_PKG + ".urn.opendaylight.foo.rev131008.Nodes", true, loader); - final Class identityClass = Class - .forName(BASE_PKG + ".urn.opendaylight.bar.rev131008.IdentityClass", true, loader); - - // test identity - try { - identityClass.getConstructor(); - final Class baseIdentity = Class.forName("org.opendaylight.yangtools.yang.binding.BaseIdentity", true, loader); - assertEquals(baseIdentity, identityClass.getSuperclass()); - } catch (final NoSuchMethodException e) { - throw new AssertionError("IdentityClass must have no-arg constructor"); - } - - // Test annotation - try { - final Method getId = nodesClass.getMethod("getId"); - final Annotation[] annotations = getId.getAnnotations(); - assertEquals(1, annotations.length); - final Annotation routingContext = annotations[0]; - assertEquals(RoutingContext.class, routingContext.annotationType()); - } catch (final NoSuchMethodException e) { - throw new AssertionError("Method getId() not found"); - } - - cleanUp(sourcesOutputDir, compiledOutputDir); - } - - @Test - public void compilationTest() throws Exception { - final File sourcesOutputDir = new File(GENERATOR_OUTPUT_PATH + FS + "yang"); - assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir()); - final File compiledOutputDir = new File(COMPILER_OUTPUT_PATH + FS + "yang"); - assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir()); - - generateTestSources("/yang", sourcesOutputDir); - - // Test if sources are compilable - testCompilation(sourcesOutputDir, compiledOutputDir); - - cleanUp(sourcesOutputDir, compiledOutputDir); - } - - @Test - public void testBug586() throws Exception { - final File sourcesOutputDir = new File(GENERATOR_OUTPUT_PATH + FS + "bug586"); - assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir()); - final File compiledOutputDir = new File(COMPILER_OUTPUT_PATH + FS + "bug586"); - assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir()); - - generateTestSources("/compilation/bug586", sourcesOutputDir); - - // Test if sources are compilable - testCompilation(sourcesOutputDir, compiledOutputDir); - - cleanUp(sourcesOutputDir, compiledOutputDir); - } - - @Test - public void testBug4760() throws Exception { - final File sourcesOutputDir = new File(GENERATOR_OUTPUT_PATH + FS + "bug4760"); - assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir()); - final File compiledOutputDir = new File(COMPILER_OUTPUT_PATH + FS + "bug4760"); - assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir()); - - generateTestSources("/compilation/bug4760", sourcesOutputDir); - - // Test if sources are compilable - testCompilation(sourcesOutputDir, compiledOutputDir); - - cleanUp(sourcesOutputDir, compiledOutputDir); - } - - /** - * Test handling nested uses-augmentations. - * - * @throws Exception - */ - @Test - public void testBug1172() throws Exception { - final File sourcesOutputDir = new File(GENERATOR_OUTPUT_PATH + FS + "bug1172"); - assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir()); - final File compiledOutputDir = new File(COMPILER_OUTPUT_PATH + FS + "bug1172"); - assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir()); - - generateTestSources("/compilation/bug1172", sourcesOutputDir); - - // Test if sources are compilable - testCompilation(sourcesOutputDir, compiledOutputDir); - - cleanUp(sourcesOutputDir, compiledOutputDir); - } - - @Test - public void testBug5461() throws Exception { - final File sourcesOutputDir = new File(GENERATOR_OUTPUT_PATH + FS + "bug5461"); - assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir()); - final File compiledOutputDir = new File(COMPILER_OUTPUT_PATH + FS + "bug5461"); - assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir()); - - generateTestSources("/compilation/bug5461", sourcesOutputDir); - - // Test if sources are compilable - testCompilation(sourcesOutputDir, compiledOutputDir); - - cleanUp(sourcesOutputDir, compiledOutputDir); - } - - @Test - public void testBug5788() throws Exception { - final File sourcesOutputDir = new File(GENERATOR_OUTPUT_PATH + FS + "bug5788"); - assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir()); - final File compiledOutputDir = new File(COMPILER_OUTPUT_PATH + FS + "bug5788"); - assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir()); - - generateTestSources("/compilation/bug5788", sourcesOutputDir); - - // Test if sources are compilable - testCompilation(sourcesOutputDir, compiledOutputDir); - - cleanUp(sourcesOutputDir, compiledOutputDir); - } - - /** - * Test if class generated for node from grouping implements ChildOf. - * - * @throws Exception - */ - @Test - public void testBug1377() throws Exception { - final File sourcesOutputDir = new File(GENERATOR_OUTPUT_PATH + FS + "bug1377"); - assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir()); - final File compiledOutputDir = new File(COMPILER_OUTPUT_PATH + FS + "bug1377"); - assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir()); - - generateTestSources("/compilation/bug1377", sourcesOutputDir); - - // Test if sources are compilable - testCompilation(sourcesOutputDir, compiledOutputDir); - - final ClassLoader loader = new URLClassLoader(new URL[] { compiledOutputDir.toURI().toURL() }); - final Class outputActionClass = Class.forName(BASE_PKG - + ".urn.test.foo.rev140717.action.action.output.action._case.OutputAction", true, loader); - final Class actionClass = Class.forName(BASE_PKG + ".urn.test.foo.rev140717.Action", true, loader); - - // Test generated 'container output-action' - assertTrue(outputActionClass.isInterface()); - assertImplementsParameterizedIfc(outputActionClass, ChildOf.class.toString(), actionClass.getCanonicalName()); - - cleanUp(sourcesOutputDir, compiledOutputDir); - } - - @Test - public void classNamesColisionTest() throws Exception { - final File sourcesOutputDir = new File(GENERATOR_OUTPUT_PATH + FS + "class-name-collision"); - assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir()); - final File compiledOutputDir = new File(COMPILER_OUTPUT_PATH + FS + "class-name-collision"); - assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir()); - - generateTestSources("/compilation/class-name-collision", sourcesOutputDir); - testCompilation(sourcesOutputDir, compiledOutputDir); - cleanUp(sourcesOutputDir, compiledOutputDir); - } - - private void generateTestSources(final String resourceDirPath, final File sourcesOutputDir) throws Exception { - final List sourceFiles = getSourceFiles(resourceDirPath); - final SchemaContext context = RetestUtils.parseYangSources(sourceFiles); - final List types = bindingGenerator.generateTypes(context); - Collections.sort(types, new Comparator() { - @Override - public int compare(final Type o1, final Type o2) { - return o2.getName().compareTo(o1.getName()); - } - }); - final GeneratorJavaFile generator = new GeneratorJavaFile(ImmutableSet.copyOf(types)); - generator.generateToFile(sourcesOutputDir); - } - - private static void testReturnTypeIdentityref(final Class clazz, final String methodName, final String returnTypeStr) throws Exception { - Method method; - java.lang.reflect.Type returnType; - try { - method = clazz.getMethod(methodName); - assertEquals(java.lang.Class.class, method.getReturnType()); - returnType = method.getGenericReturnType(); - assertTrue(returnType instanceof ParameterizedType); - final ParameterizedType pt = (ParameterizedType) returnType; - final java.lang.reflect.Type[] parameters = pt.getActualTypeArguments(); - assertEquals(1, parameters.length); - final java.lang.reflect.Type parameter = parameters[0]; - assertTrue(parameter instanceof WildcardType); - final WildcardType wildcardType = (WildcardType) parameter; - assertEquals("? extends " + returnTypeStr, wildcardType.toString()); - } catch (final NoSuchMethodException e) { - throw new AssertionError("Method '" + methodName + "' not found"); - } - } - - private static void testReturnTypeInstanceIdentitifer(final ClassLoader loader, final Class clazz, final String methodName) - throws Exception { - Method method; - Class rawReturnType; - java.lang.reflect.Type returnType; - try { - method = clazz.getMethod(methodName); - rawReturnType = Class.forName("org.opendaylight.yangtools.yang.binding.InstanceIdentifier", true, loader); - assertEquals(rawReturnType, method.getReturnType()); - returnType = method.getGenericReturnType(); - assertTrue(returnType instanceof ParameterizedType); - final ParameterizedType pt = (ParameterizedType) returnType; - final java.lang.reflect.Type[] parameters = pt.getActualTypeArguments(); - assertEquals(1, parameters.length); - final java.lang.reflect.Type parameter = parameters[0]; - assertTrue(parameter instanceof WildcardType); - final WildcardType wildcardType = (WildcardType) parameter; - assertEquals("?", wildcardType.toString()); - } catch (final NoSuchMethodException e) { - throw new AssertionError("Method '" + methodName + "' not found"); - } - } - -} diff --git a/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/stmt/parser/retest/CompilationTestUtils.java b/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/stmt/parser/retest/CompilationTestUtils.java deleted file mode 100644 index 14859bc22d..0000000000 --- a/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/stmt/parser/retest/CompilationTestUtils.java +++ /dev/null @@ -1,428 +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.yangtools.sal.java.api.generator.stmt.parser.retest; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import java.io.File; -import java.io.FileNotFoundException; -import java.lang.reflect.Constructor; -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import java.lang.reflect.ParameterizedType; -import java.net.URI; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import javax.tools.JavaCompiler; -import javax.tools.JavaFileObject; -import javax.tools.StandardJavaFileManager; -import javax.tools.ToolProvider; - -public class CompilationTestUtils { - public static final String FS = File.separator; - static final String BASE_PKG = "org.opendaylight.yang.gen.v1"; - - static final String TEST_PATH = "target" + FS + "test"; - static final File TEST_DIR = new File(TEST_PATH); - - static final String GENERATOR_OUTPUT_PATH = TEST_PATH + FS + "src"; - static final File GENERATOR_OUTPUT_DIR = new File(GENERATOR_OUTPUT_PATH); - static final String COMPILER_OUTPUT_PATH = TEST_PATH + FS + "bin"; - static final File COMPILER_OUTPUT_DIR = new File(COMPILER_OUTPUT_PATH); - - static final String AUGMENTATION = "interface org.opendaylight.yangtools.yang.binding.Augmentation"; - - static final String BASE_PATH = "org" + FS + "opendaylight" + FS + "yang" + FS + "gen" + FS + "v1"; - static final String NS_TEST = BASE_PATH + FS + "urn" + FS + "opendaylight" + FS + "test" + FS + "rev131008"; - static final String NS_FOO = BASE_PATH + FS + "urn" + FS + "opendaylight" + FS + "foo" + FS + "rev131008"; - static final String NS_BAR = BASE_PATH + FS + "urn" + FS + "opendaylight" + FS + "bar" + FS + "rev131008"; - static final String NS_BAZ = BASE_PATH + FS + "urn" + FS + "opendaylight" + FS + "baz" + FS + "rev131008"; - - /** - * Method to clean resources. It is manually called at the end of each test - * instead of marking it with @After annotation to prevent removing - * generated code if test fails. - */ - static void cleanUp(final File... resourceDirs) { - for (File resourceDir : resourceDirs) { - if (resourceDir.exists()) { - deleteTestDir(resourceDir); - } - } - } - - /** - * Asserts that class contains field with fiven name and type. - * - * @param clazz - * class to test - * @param name - * field name - * @param type - * field type - * @return field with given name if present in class - */ - static Field assertContainsField(final Class clazz, final String name, final Class type) { - try { - Field f = clazz.getDeclaredField(name); - assertEquals(type, f.getType()); - return f; - } catch (NoSuchFieldException e) { - throw new AssertionError("Field " + name + " does not exist in class " + clazz.getSimpleName()); - } - } - - /** - * Asserts that class contains field with given name and value. Method tries - * to create new instance of class and get value of field. If class - * constructor contains any arguments, class is instantiated with null - * values. - * - * @param clazz - * class to test - * @param name - * name of field - * @param returnType - * return type of field - * @param expectedValue - * expected value of field - * @param constructorArgs - * constructor arguments of class to test - */ - static void assertContainsFieldWithValue(final Class clazz, final String name, final Class returnType, final Object expectedValue, - final Class... constructorArgs) { - Object[] initargs = null; - if (constructorArgs != null && constructorArgs.length > 0) { - initargs = new Object[constructorArgs.length]; - for (int i = 0; i < constructorArgs.length; i++) { - initargs[i] = null; - } - } - assertContainsFieldWithValue(clazz, name, returnType, expectedValue, constructorArgs, initargs); - } - - /** - * Asserts that class contains field with given name, return type and value. - * - * @param clazz - * class to test - * @param name - * name of field - * @param returnType - * return type of field - * @param expectedValue - * expected value of field - * @param constructorArgs - * array of constructor arguments classes - * @param initargs - * array of constructor values - */ - static void assertContainsFieldWithValue(final Class clazz, final String name, final Class returnType, final Object expectedValue, - final Class[] constructorArgs, final Object... initargs) { - Field f = assertContainsField(clazz, name, returnType); - f.setAccessible(true); - - final Object obj; - if ((f.getModifiers() & Modifier.STATIC) == 0) { - try { - Constructor c = clazz.getDeclaredConstructor(constructorArgs); - obj = c.newInstance(initargs); - } catch (Exception e) { - throw new AssertionError("Failed to instantiate object for " + clazz, e); - } - } else { - obj = null; - } - - try { - assertEquals(expectedValue, f.get(obj)); - } catch (IllegalArgumentException | IllegalAccessException e) { - throw new AssertionError("Failed to get field " + name + " of class " + clazz, e); - } - } - - /** - * Asserts that class contains constructor with parameter types. - * - * @param clazz - * class to test - * @param args - * array of argument classes - */ - static Constructor assertContainsConstructor(final Class clazz, final Class... args) { - try { - return clazz.getDeclaredConstructor(args); - } catch (NoSuchMethodException e) { - throw new AssertionError("Constructor with args " + Arrays.toString(args) + " does not exists in class " - + clazz.getSimpleName()); - } - } - - /** - * Asserts that class contains method with given name, return type and - * parameter types. - * - * @param clazz - * class to test - * @param returnType - * method return type - * @param name - * method name - * @param args - * array of parameter type classes - * @return method with given name, return type and parameter types - */ - static Method assertContainsMethod(final Class clazz, final Class returnType, final String name, final Class... args) { - try { - Method m = clazz.getDeclaredMethod(name, args); - assertEquals(returnType, m.getReturnType()); - return m; - } catch (NoSuchMethodException e) { - throw new AssertionError("Method " + name + " with args " + Arrays.toString(args) - + " does not exists in class " + clazz.getSimpleName()); - } - } - - /** - * Asserts that class contains method with given name and return type. - * - * @param clazz - * class to test - * @param returnTypeStr - * name of method return type - * @param name - * method name - * @param loader - * current class loader - */ - static void assertContainsMethod(final Class clazz, final String returnTypeStr, final String name, final ClassLoader loader) { - Class returnType; - try { - returnType = Class.forName(returnTypeStr, true, loader); - Method method = clazz.getMethod(name); - assertEquals(returnType, method.getReturnType()); - } catch (ClassNotFoundException e) { - throw new AssertionError("Return type of method '" + name + "' not found"); - } catch (NoSuchMethodException e) { - throw new AssertionError("Method " + name + " does not exists in class " + clazz.getSimpleName()); - } - } - - /** - * Asserts that class contains hashCode, equals and toString methods. - * - * @param clazz - * class to test - */ - static void assertContainsDefaultMethods(final Class clazz) { - assertContainsMethod(clazz, Integer.TYPE, "hashCode"); - assertContainsMethod(clazz, Boolean.TYPE, "equals", Object.class); - assertContainsMethod(clazz, String.class, "toString"); - } - - /** - * Asserts that constructor contains check for illegal argument. - * - * @param constructor - * constructor to invoke - * @param errorMsg - * expected error message - * @param args - * constructor arguments - * @throws Exception - */ - static void assertContainsRestrictionCheck(final Constructor constructor, final String errorMsg, final Object... args) - throws Exception { - try { - constructor.newInstance(args); - fail("constructor invocation should fail"); - } catch (InvocationTargetException e) { - Throwable cause = e.getCause(); - assertTrue(cause instanceof IllegalArgumentException); - assertEquals(errorMsg, cause.getMessage()); - } - } - - /** - * Asserts that method contains check for illegal argument. - * - * @param obj - * object to test (can be null, if method is static) - * @param method - * method to invoke - * @param errorMsg - * expected error message - * @param args - * constructor arguments - * @throws Exception - */ - static void assertContainsRestrictionCheck(final Object obj, final Method method, final String errorMsg, final Object... args) - throws Exception { - try { - method.invoke(obj, args); - fail("method invocation should fail"); - } catch (InvocationTargetException e) { - Throwable cause = e.getCause(); - assertTrue(cause instanceof IllegalArgumentException); - assertEquals(errorMsg, cause.getMessage()); - } - } - - /** - * Asserts that class implements given interface. - * - * @param clazz - * source to test - * @param ifc - * expected interface - */ - static void assertImplementsIfc(final Class clazz, final Class ifc) { - Class[] interfaces = clazz.getInterfaces(); - List> ifcsList = Arrays.asList(interfaces); - if (!ifcsList.contains(ifc)) { - throw new AssertionError(clazz + " should implement " + ifc); - } - } - - /** - * Test if interface generated from augment extends Augmentation interface - * with correct generic type. - * - * @param clazz - * interface generated from augment - * @param genericTypeName - * fully qualified name of expected parameter type - */ - static void testAugmentation(final Class clazz, final String genericTypeName) { - assertImplementsParameterizedIfc(clazz, AUGMENTATION, genericTypeName); - } - - /** - * Asserts that class implements interface with given name and generic type - * parameter. - * - * @param clazz - * class to test - * @param ifcName - * name of interface - * @param genericTypeName - * name of generic type - */ - static void assertImplementsParameterizedIfc(final Class clazz, final String ifcName, final String genericTypeName) { - ParameterizedType ifcType = null; - for (java.lang.reflect.Type ifc : clazz.getGenericInterfaces()) { - if (ifc instanceof ParameterizedType) { - ParameterizedType pt = (ParameterizedType) ifc; - if (ifcName.equals(pt.getRawType().toString())) { - ifcType = pt; - } - } - } - assertNotNull(ifcType); - - java.lang.reflect.Type[] typeArguments = ifcType.getActualTypeArguments(); - assertEquals(1, typeArguments.length); - assertEquals("interface " + genericTypeName, typeArguments[0].toString()); - } - - /** - * Test if source code is compilable. - * - * @param sourcesOutputDir - * directory containing source files - * @param compiledOutputDir - * compiler output directory - */ - static void testCompilation(final File sourcesOutputDir, final File compiledOutputDir) { - JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); - StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null); - List filesList = getJavaFiles(sourcesOutputDir); - Iterable compilationUnits = fileManager.getJavaFileObjectsFromFiles(filesList); - Iterable options = Arrays.asList("-d", compiledOutputDir.getAbsolutePath()); - boolean compiled = compiler.getTask(null, null, null, options, null, compilationUnits).call(); - assertTrue("Compilation failed", compiled); - } - - /** - * Asserts that directory contains exactly given count of files. - * - * @param dir - * directory to test - * @param count - * expected count of files in directory - */ - static void assertFilesCount(final File dir, final int count) { - File[] dirContent = dir.listFiles(); - if (dirContent == null) { - throw new AssertionError("File " + dir + " doesn't exists or it's not a directory"); - } else { - assertEquals("Unexpected count of generated files", count, dirContent.length); - } - } - - /** - * Search recursively given directory for *.java files. - * - * @param directory - * directory to search - * @return List of java files found - */ - private static List getJavaFiles(final File directory) { - List result = new ArrayList<>(); - File[] filesToRead = directory.listFiles(); - if (filesToRead != null) { - for (File file : filesToRead) { - if (file.isDirectory()) { - result.addAll(getJavaFiles(file)); - } else { - String absPath = file.getAbsolutePath(); - if (absPath.endsWith(".java")) { - result.add(file); - } - } - } - } - return result; - } - - static List getSourceFiles(final String path) throws Exception { - final URI resPath = BaseCompilationTest.class.getResource(path).toURI(); - final File sourcesDir = new File(resPath); - if (sourcesDir.exists()) { - final List sourceFiles = new ArrayList<>(); - final File[] fileArray = sourcesDir.listFiles(); - if (fileArray == null) { - throw new IllegalArgumentException("Unable to locate files in " + sourcesDir); - } - sourceFiles.addAll(Arrays.asList(fileArray)); - return sourceFiles; - } else { - throw new FileNotFoundException("Testing files were not found(" + sourcesDir.getName() + ")"); - } - } - - static void deleteTestDir(final File file) { - if (file.isDirectory()) { - File[] filesToDelete = file.listFiles(); - if (filesToDelete != null) { - for (File f : filesToDelete) { - deleteTestDir(f); - } - } - } - if (!file.delete()) { - throw new RuntimeException("Failed to clean up after test"); - } - } - -} diff --git a/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/stmt/parser/retest/EndodingInJavaDocTest.java b/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/stmt/parser/retest/EndodingInJavaDocTest.java deleted file mode 100644 index a43c2545f1..0000000000 --- a/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/stmt/parser/retest/EndodingInJavaDocTest.java +++ /dev/null @@ -1,42 +0,0 @@ -package org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest; - -import static org.junit.Assert.assertTrue; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.COMPILER_OUTPUT_PATH; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.FS; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.GENERATOR_OUTPUT_PATH; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.cleanUp; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.getSourceFiles; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.testCompilation; -import com.google.common.collect.ImmutableSet; -import java.io.File; -import java.util.List; -import org.junit.Test; -import org.opendaylight.yangtools.sal.binding.model.api.Type; -import org.opendaylight.yangtools.sal.java.api.generator.GeneratorJavaFile; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; - -/** - * Test if generated classes from yang file is compilable, generated javadoc comments contains - * symbols as javadoc comment tag, which caused of compilation problem. - */ -public class EndodingInJavaDocTest extends BaseCompilationTest { - - @Test - public void testAugmentToUsesInAugment() throws Exception { - final File sourcesOutputDir = new File(GENERATOR_OUTPUT_PATH + FS + "encoding-javadoc"); - assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir()); - final File compiledOutputDir = new File(COMPILER_OUTPUT_PATH + FS + "encoding-javadoc"); - assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir()); - - final List sourceFiles = getSourceFiles("/compilation/encoding-javadoc"); - final SchemaContext context = RetestUtils.parseYangSources(sourceFiles); - final List types = bindingGenerator.generateTypes(context); - final GeneratorJavaFile generator = new GeneratorJavaFile(ImmutableSet.copyOf(types)); - generator.generateToFile(sourcesOutputDir); - - // Test if sources are compilable - testCompilation(sourcesOutputDir, compiledOutputDir); - cleanUp(sourcesOutputDir, compiledOutputDir); - } - -} diff --git a/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/stmt/parser/retest/GeneratorJavaFileTest.java b/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/stmt/parser/retest/GeneratorJavaFileTest.java deleted file mode 100644 index 90b548a9d0..0000000000 --- a/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/stmt/parser/retest/GeneratorJavaFileTest.java +++ /dev/null @@ -1,63 +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.yangtools.sal.java.api.generator.stmt.parser.retest; - -import static org.junit.Assert.assertTrue; - -import java.io.File; -import java.io.IOException; -import java.util.Arrays; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import org.junit.Test; -import org.opendaylight.yangtools.binding.generator.util.BindingTypes; -import org.opendaylight.yangtools.binding.generator.util.Types; -import org.opendaylight.yangtools.binding.generator.util.generated.type.builder.GeneratedTypeBuilderImpl; -import org.opendaylight.yangtools.sal.binding.model.api.GeneratedType; -import org.opendaylight.yangtools.sal.binding.model.api.type.builder.GeneratedTypeBuilder; -import org.opendaylight.yangtools.sal.java.api.generator.GeneratorJavaFile; - -public class GeneratorJavaFileTest { - private static final String FS = File.separator; - private static final String PATH = "target/test/test-dir"; - - @Test - public void test() throws IOException { - final Set types = new HashSet(); - GeneratedType t1 = createGeneratedType("org.opendaylight.controller.gen", "Type1"); - GeneratedType t2 = createGeneratedType("org.opendaylight.controller.gen", "Type2"); - GeneratedType t3 = createGeneratedType("org.opendaylight.controller.gen", "Type3"); - types.add(t1); - types.add(t2); - types.add(t3); - GeneratedTypeBuilder gtb = new GeneratedTypeBuilderImpl("org.opendaylight.controller.gen", "Type4"); - gtb.addImplementsType(Types.augmentableTypeFor(gtb)); - types.add(gtb.toInstance()); - GeneratorJavaFile generator = new GeneratorJavaFile(types); - generator.generateToFile(new File(PATH)); - - String[] files = new File(PATH + FS + "org" + FS + "opendaylight" + FS + "controller" + FS + "gen").list(); - List filesList = Arrays.asList(files); - - // assertEquals(5, files.length); - assertTrue(filesList.contains("Type1.java")); - assertTrue(filesList.contains("Type2.java")); - assertTrue(filesList.contains("Type3.java")); - assertTrue(filesList.contains("Type4.java")); - assertTrue(filesList.contains("Type4Builder.java")); - } - - private static GeneratedType createGeneratedType(String pkgName, String name) { - GeneratedTypeBuilder builder = new GeneratedTypeBuilderImpl(pkgName, name); - builder.addImplementsType(BindingTypes.DATA_OBJECT); - return builder.toInstance(); - } - -} diff --git a/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/stmt/parser/retest/NestedGroupingCompilationTest.java b/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/stmt/parser/retest/NestedGroupingCompilationTest.java deleted file mode 100644 index 25f503f5b0..0000000000 --- a/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/stmt/parser/retest/NestedGroupingCompilationTest.java +++ /dev/null @@ -1,85 +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.yangtools.sal.java.api.generator.stmt.parser.retest; - -import static org.junit.Assert.assertTrue; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.BASE_PKG; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.COMPILER_OUTPUT_PATH; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.FS; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.GENERATOR_OUTPUT_PATH; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.NS_TEST; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.assertFilesCount; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.assertImplementsIfc; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.cleanUp; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.getSourceFiles; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.testCompilation; -import com.google.common.collect.ImmutableSet; -import java.io.File; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.List; -import org.junit.Test; -import org.opendaylight.yangtools.sal.binding.model.api.Type; -import org.opendaylight.yangtools.sal.java.api.generator.GeneratorJavaFile; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; - -/** - * Test correct code generation. - * - */ -public class NestedGroupingCompilationTest extends BaseCompilationTest { - - @Test - public void testListGeneration() throws Exception { - final File sourcesOutputDir = new File(GENERATOR_OUTPUT_PATH + FS + "nested-grouping"); - assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir()); - final File compiledOutputDir = new File(COMPILER_OUTPUT_PATH + FS + "nested-grouping"); - assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir()); - - generateTestSources("/compilation/nested-grouping", sourcesOutputDir); - - // Test if all sources are generated - File parent = new File(sourcesOutputDir, NS_TEST); - File foo = new File(parent, "Foo.java"); - File fooBuilder = new File(parent, "FooBuilder.java"); - File testData = new File(parent, "TestData.java"); - File fooDir = new File(parent, "foo"); - assertTrue(foo.exists()); - assertTrue(fooBuilder.exists()); - assertTrue(testData.exists()); - assertTrue(fooDir.exists()); - assertFilesCount(parent, 4); - - parent = new File(parent, "foo"); - File bar = new File(parent, "Bar.java"); - assertTrue(bar.exists()); - assertFilesCount(parent, 1); - - // Test if sources are compilable - testCompilation(sourcesOutputDir, compiledOutputDir); - - ClassLoader loader = new URLClassLoader(new URL[] { compiledOutputDir.toURI().toURL() }); - Class fooClass = Class.forName(BASE_PKG + ".urn.opendaylight.test.rev131008.Foo", true, loader); - Class barClass = Class.forName(BASE_PKG + ".urn.opendaylight.test.rev131008.foo.Bar", true, loader); - - // Test generated 'foo' - assertTrue(fooClass.isInterface()); - assertImplementsIfc(fooClass, barClass); - - cleanUp(sourcesOutputDir, compiledOutputDir); - } - - private void generateTestSources(final String resourceDirPath, final File sourcesOutputDir) throws Exception { - final List sourceFiles = getSourceFiles(resourceDirPath); - final SchemaContext context = RetestUtils.parseYangSources(sourceFiles); - final List types = bindingGenerator.generateTypes(context); - final GeneratorJavaFile generator = new GeneratorJavaFile(ImmutableSet.copyOf(types)); - generator.generateToFile(sourcesOutputDir); - } - -} diff --git a/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/stmt/parser/retest/TypedefCompilationTest.java b/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/stmt/parser/retest/TypedefCompilationTest.java deleted file mode 100644 index 89766fb706..0000000000 --- a/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/stmt/parser/retest/TypedefCompilationTest.java +++ /dev/null @@ -1,349 +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.yangtools.sal.java.api.generator.stmt.parser.retest; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.BASE_PKG; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.COMPILER_OUTPUT_PATH; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.FS; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.GENERATOR_OUTPUT_PATH; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.NS_FOO; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.assertContainsConstructor; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.assertContainsDefaultMethods; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.assertContainsField; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.assertContainsFieldWithValue; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.assertContainsMethod; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.assertContainsRestrictionCheck; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.assertFilesCount; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.cleanUp; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.getSourceFiles; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.testCompilation; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Range; -import java.io.File; -import java.lang.reflect.Constructor; -import java.lang.reflect.Method; -import java.math.BigDecimal; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.ArrayList; -import java.util.List; -import java.util.regex.Pattern; -import org.junit.Test; -import org.opendaylight.yangtools.sal.binding.model.api.Type; -import org.opendaylight.yangtools.sal.java.api.generator.GeneratorJavaFile; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; - -/** - * Test correct code generation. - * - */ -public class TypedefCompilationTest extends BaseCompilationTest { - private static final String VAL = "_value"; - private static final String GET_VAL = "getValue"; - private static final String UNITS = "_UNITS"; - - @Test - public void test() throws Exception { - final File sourcesOutputDir = new File(GENERATOR_OUTPUT_PATH + FS + "typedef"); - assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir()); - final File compiledOutputDir = new File(COMPILER_OUTPUT_PATH + FS + "typedef"); - assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir()); - - final List sourceFiles = getSourceFiles("/compilation/typedef"); - final SchemaContext context = RetestUtils.parseYangSources(sourceFiles); - final List types = bindingGenerator.generateTypes(context); - final GeneratorJavaFile generator = new GeneratorJavaFile(ImmutableSet.copyOf(types)); - generator.generateToFile(sourcesOutputDir); - - File parent = new File(sourcesOutputDir, NS_FOO); - File bitsExt = new File(parent, "BitsExt.java"); - File int32Ext0 = new File(parent, "Int32Ext0.java"); - File int32Ext1 = new File(parent, "Int32Ext1.java"); - File int32Ext2 = new File(parent, "Int32Ext2.java"); - File myDecimalType = new File(parent, "MyDecimalType.java"); - File stringExt1 = new File(parent, "StringExt1.java"); - File stringExt2 = new File(parent, "StringExt2.java"); - File stringExt3 = new File(parent, "StringExt3.java"); - File unionExt1 = new File(parent, "UnionExt1.java"); - File unionExt2 = new File(parent, "UnionExt2.java"); - File unionExt3 = new File(parent, "UnionExt3.java"); - File unionExt4 = new File(parent, "UnionExt4.java"); - assertTrue(bitsExt.exists()); - assertTrue(int32Ext0.exists()); - assertTrue(int32Ext1.exists()); - assertTrue(int32Ext2.exists()); - assertTrue(myDecimalType.exists()); - assertTrue(stringExt1.exists()); - assertTrue(stringExt2.exists()); - assertTrue(stringExt3.exists()); - assertTrue(unionExt1.exists()); - assertTrue(unionExt2.exists()); - assertTrue(unionExt3.exists()); - assertTrue(unionExt4.exists()); - assertFilesCount(parent, 33); - - // Test if sources are compilable - testCompilation(sourcesOutputDir, compiledOutputDir); - - String pkg = BASE_PKG + ".urn.opendaylight.foo.rev131008"; - ClassLoader loader = new URLClassLoader(new URL[] { compiledOutputDir.toURI().toURL() }); - Class bitsExtClass = Class.forName(pkg + ".BitsExt", true, loader); - Class int32Ext1Class = Class.forName(pkg + ".Int32Ext1", true, loader); - Class int32Ext2Class = Class.forName(pkg + ".Int32Ext2", true, loader); - Class myDecimalTypeClass = Class.forName(pkg + ".MyDecimalType", true, loader); - Class myDecimalType2Class = Class.forName(pkg + ".MyDecimalType2", true, loader); - Class stringExt1Class = Class.forName(pkg + ".StringExt1", true, loader); - Class stringExt2Class = Class.forName(pkg + ".StringExt2", true, loader); - Class stringExt3Class = Class.forName(pkg + ".StringExt3", true, loader); - Class unionExt1Class = Class.forName(pkg + ".UnionExt1", true, loader); - Class unionExt2Class = Class.forName(pkg + ".UnionExt2", true, loader); - Class unionExt3Class = Class.forName(pkg + ".UnionExt3", true, loader); - Class unionExt4Class = Class.forName(pkg + ".UnionExt4", true, loader); - - // typedef bits-ext - assertFalse(bitsExtClass.isInterface()); - assertContainsField(bitsExtClass, "_pc", Boolean.class); - assertContainsField(bitsExtClass, "_bpc", Boolean.class); - assertContainsField(bitsExtClass, "_dpc", Boolean.class); - assertContainsField(bitsExtClass, "_lbpc", Boolean.class); - assertContainsField(bitsExtClass, "_spc", Boolean.class); - assertContainsField(bitsExtClass, "_sfmof", Boolean.class); - assertContainsField(bitsExtClass, "_sfapc", Boolean.class); - assertContainsFieldWithValue(bitsExtClass, "serialVersionUID", Long.TYPE, -2922917845344851623L, Boolean.class, - Boolean.class, Boolean.class, Boolean.class, Boolean.class, Boolean.class, Boolean.class); - - // assertEquals(8, bitsExtClass.getDeclaredFields()); - Constructor expectedConstructor = assertContainsConstructor(bitsExtClass, Boolean.class, Boolean.class, - Boolean.class, Boolean.class, Boolean.class, Boolean.class, Boolean.class); - assertContainsConstructor(bitsExtClass, bitsExtClass); - assertEquals(2, bitsExtClass.getConstructors().length); - Method defInst = assertContainsMethod(bitsExtClass, bitsExtClass, "getDefaultInstance", String.class); - assertContainsDefaultMethods(bitsExtClass); - // assertEquals(11, bitsExtClass.getDeclaredMethods().length); - - Object obj = expectedConstructor.newInstance(null, null, null, null, null, new Boolean("true"), null); - assertEquals(obj, defInst.invoke(null, "sfmof")); - - // typedef int32-ext1 - assertFalse(int32Ext1Class.isInterface()); - assertContainsField(int32Ext1Class, VAL, Integer.class); - assertContainsFieldWithValue(int32Ext1Class, "serialVersionUID", Long.TYPE, 5351634010010233292L, Integer.class); - // assertEquals(3, int32Ext1Class.getDeclaredFields().length); - - expectedConstructor = assertContainsConstructor(int32Ext1Class, Integer.class); - assertContainsConstructor(int32Ext1Class, int32Ext1Class); - assertEquals(2, int32Ext1Class.getConstructors().length); - assertContainsDefaultMethods(int32Ext1Class); - assertContainsMethod(int32Ext1Class, Integer.class, GET_VAL); - defInst = assertContainsMethod(int32Ext1Class, int32Ext1Class, "getDefaultInstance", String.class); - // assertEquals(6, int32Ext1Class.getDeclaredMethods().length); - - List> rangeConstraints = new ArrayList<>(); - rangeConstraints.add(Range.closed(new Integer("2"), new Integer("2147483647"))); - Object arg = new Integer("1"); - String expectedMsg = String.format("Invalid range: %s, expected: %s.", arg, rangeConstraints); - assertContainsRestrictionCheck(expectedConstructor, expectedMsg, arg); - obj = expectedConstructor.newInstance(new Integer("159")); - assertEquals(obj, defInst.invoke(null, "159")); - - // typedef int32-ext2 - assertFalse(int32Ext2Class.isInterface()); - assertContainsFieldWithValue(int32Ext2Class, UNITS, String.class, "mile", Integer.class); - assertContainsFieldWithValue(int32Ext2Class, "serialVersionUID", Long.TYPE, 317831889060130988L, Integer.class); - // assertEquals(3, int32Ext2Class.getDeclaredFields().length); - expectedConstructor = assertContainsConstructor(int32Ext2Class, Integer.class); - assertContainsConstructor(int32Ext2Class, int32Ext2Class); - assertContainsConstructor(int32Ext2Class, int32Ext1Class); - assertEquals(3, int32Ext2Class.getDeclaredConstructors().length); - assertContainsMethod(int32Ext2Class, String.class, "toString"); - defInst = assertContainsMethod(int32Ext2Class, int32Ext2Class, "getDefaultInstance", String.class); - // assertEquals(3, int32Ext2Class.getDeclaredMethods().length); - - rangeConstraints.clear(); - rangeConstraints.add(Range.closed(new Integer("3"), new Integer("9"))); - rangeConstraints.add(Range.closed(new Integer("11"), new Integer("2147483647"))); - arg = new Integer("10"); - expectedMsg = String.format("Invalid range: %s, expected: %s.", arg, rangeConstraints); - assertContainsRestrictionCheck(expectedConstructor, expectedMsg, arg); - obj = expectedConstructor.newInstance(new Integer("2147483647")); - assertEquals(obj, defInst.invoke(null, "2147483647")); - - // typedef string-ext1 - assertFalse(stringExt1Class.isInterface()); - assertContainsField(stringExt1Class, VAL, String.class); - assertContainsField(stringExt1Class, "patterns", Pattern[].class); - assertContainsField(stringExt1Class, "PATTERN_CONSTANTS", List.class); - assertContainsFieldWithValue(stringExt1Class, "serialVersionUID", Long.TYPE, 6943827552297110991L, String.class); - // assertEquals(5, stringExt1Class.getDeclaredFields().length); - expectedConstructor = assertContainsConstructor(stringExt1Class, String.class); - assertContainsConstructor(stringExt1Class, stringExt1Class); - assertEquals(2, stringExt1Class.getDeclaredConstructors().length); - assertContainsMethod(stringExt1Class, String.class, GET_VAL); - defInst = assertContainsMethod(stringExt1Class, stringExt1Class, "getDefaultInstance", String.class); - assertContainsDefaultMethods(stringExt1Class); - // assertEquals(6, stringExt1Class.getDeclaredMethods().length); - - List> lengthConstraints = new ArrayList<>(); - lengthConstraints.add(Range.closed(5, 11)); - arg = "abcd"; - expectedMsg = String.format("Invalid length: %s, expected: %s.", arg, lengthConstraints); - assertContainsRestrictionCheck(expectedConstructor, expectedMsg, arg); - - obj = expectedConstructor.newInstance("abcde"); - assertEquals(obj, defInst.invoke(null, "abcde")); - - // typedef string-ext2 - assertFalse(stringExt2Class.isInterface()); - assertContainsFieldWithValue(stringExt2Class, "serialVersionUID", Long.TYPE, 8100233177432072092L, String.class); - // assertEquals(2, stringExt2Class.getDeclaredFields().length); - expectedConstructor = assertContainsConstructor(stringExt2Class, String.class); - assertContainsConstructor(stringExt2Class, stringExt2Class); - assertContainsConstructor(stringExt2Class, stringExt1Class); - assertEquals(3, stringExt2Class.getDeclaredConstructors().length); - defInst = assertContainsMethod(stringExt2Class, stringExt2Class, "getDefaultInstance", String.class); - // assertEquals(2, stringExt2Class.getDeclaredMethods().length); - - lengthConstraints.clear(); - lengthConstraints.add(Range.closed(6, 10)); - arg = "abcde"; - expectedMsg = String.format("Invalid length: %s, expected: %s.", arg, lengthConstraints); - assertContainsRestrictionCheck(expectedConstructor, expectedMsg, arg); - obj = expectedConstructor.newInstance("abcdef"); - assertEquals(obj, defInst.invoke(null, "abcdef")); - - // typedef string-ext3 - assertFalse(stringExt3Class.isInterface()); - assertContainsFieldWithValue(stringExt3Class, "serialVersionUID", Long.TYPE, -2751063130555484180L, - String.class); - // assertEquals(1, stringExt3Class.getDeclaredFields().length); - expectedConstructor = assertContainsConstructor(stringExt3Class, String.class); - assertContainsConstructor(stringExt3Class, stringExt3Class); - assertContainsConstructor(stringExt3Class, stringExt2Class); - assertEquals(3, stringExt3Class.getDeclaredConstructors().length); - defInst = assertContainsMethod(stringExt3Class, stringExt3Class, "getDefaultInstance", String.class); - // assertEquals(1, stringExt3Class.getDeclaredMethods().length); - - obj = expectedConstructor.newInstance("bbbbbb"); - assertEquals(obj, defInst.invoke(null, "bbbbbb")); - - // typedef my-decimal-type - assertFalse(myDecimalTypeClass.isInterface()); - assertContainsField(myDecimalTypeClass, VAL, BigDecimal.class); - assertContainsFieldWithValue(myDecimalTypeClass, "serialVersionUID", Long.TYPE, 3143735729419861095L, - BigDecimal.class); - // assertEquals(3, myDecimalTypeClass.getDeclaredFields().length); - assertContainsMethod(myDecimalTypeClass, BigDecimal.class, "getValue"); - expectedConstructor = assertContainsConstructor(myDecimalTypeClass, BigDecimal.class); - assertContainsConstructor(myDecimalTypeClass, myDecimalTypeClass); - assertEquals(2, myDecimalTypeClass.getDeclaredConstructors().length); - assertContainsMethod(myDecimalTypeClass, BigDecimal.class, GET_VAL); - assertContainsDefaultMethods(myDecimalTypeClass); - defInst = assertContainsMethod(myDecimalTypeClass, myDecimalTypeClass, "getDefaultInstance", String.class); - // assertEquals(6, myDecimalTypeClass.getDeclaredMethods().length); - - List> decimalRangeConstraints = new ArrayList<>(); - decimalRangeConstraints.add(Range.closed(new BigDecimal("1.5"), new BigDecimal("5.5"))); - arg = new BigDecimal("1.4"); - expectedMsg = String.format("Invalid range: %s, expected: %s.", arg, decimalRangeConstraints); - assertContainsRestrictionCheck(expectedConstructor, expectedMsg, arg); - obj = expectedConstructor.newInstance(new BigDecimal("3.14")); - assertEquals(obj, defInst.invoke(null, "3.14")); - - // typedef my-decimal-type2 - assertFalse(myDecimalType2Class.isInterface()); - assertContainsField(myDecimalType2Class, VAL, BigDecimal.class); - assertContainsFieldWithValue(myDecimalType2Class, "serialVersionUID", Long.TYPE, -672265764962082714L, BigDecimal.class); - // assertEquals(3, myDecimalType2Class.getDeclaredFields().length); - assertContainsMethod(myDecimalType2Class, BigDecimal.class, "getValue"); - expectedConstructor = assertContainsConstructor(myDecimalType2Class, BigDecimal.class); - assertContainsConstructor(myDecimalType2Class, myDecimalType2Class); - assertEquals(2, myDecimalType2Class.getDeclaredConstructors().length); - assertContainsMethod(myDecimalType2Class, BigDecimal.class, GET_VAL); - assertContainsDefaultMethods(myDecimalType2Class); - defInst = assertContainsMethod(myDecimalType2Class, myDecimalType2Class, "getDefaultInstance", String.class); - // assertEquals(6, myDecimalType2Class.getDeclaredMethods().length); - - List> decimal2RangeConstraints = new ArrayList<>(); - decimal2RangeConstraints.add(Range.closed(new BigDecimal("0"), new BigDecimal("1"))); - arg = new BigDecimal("1.4"); - expectedMsg = String.format("Invalid range: %s, expected: %s.", arg, decimal2RangeConstraints); - assertContainsRestrictionCheck(expectedConstructor, expectedMsg, arg); - obj = expectedConstructor.newInstance(new BigDecimal("0.14")); - assertEquals(obj, defInst.invoke(null, "0.14")); - - // typedef union-ext1 - assertFalse(unionExt1Class.isInterface()); - assertContainsField(unionExt1Class, "_int16", Short.class); - assertContainsField(unionExt1Class, "_int32", Integer.class); - assertContainsFieldWithValue(unionExt1Class, "serialVersionUID", Long.TYPE, -5610530488718168882L, - new Class[] { Short.class }, Short.valueOf("1")); - // assertEquals(4, unionExt1Class.getDeclaredFields().length); - assertContainsMethod(unionExt1Class, Short.class, "getInt16"); - assertContainsMethod(unionExt1Class, Integer.class, "getInt32"); - assertContainsConstructor(unionExt1Class, Short.class); - assertContainsConstructor(unionExt1Class, Integer.class); - assertContainsConstructor(unionExt1Class, unionExt1Class); - assertEquals(4, unionExt1Class.getDeclaredConstructors().length); - assertContainsDefaultMethods(unionExt1Class); - - // typedef union-ext2 - assertFalse(unionExt2Class.isInterface()); - assertContainsFieldWithValue(unionExt2Class, "serialVersionUID", Long.TYPE, -8833407459073585206L, - new Class[] { Short.class }, Short.valueOf("1")); - // assertEquals(1, unionExt2Class.getDeclaredFields().length); - // assertEquals(0, unionExt2Class.getDeclaredMethods().length); - assertContainsConstructor(unionExt2Class, Short.class); - assertContainsConstructor(unionExt2Class, Integer.class); - assertContainsConstructor(unionExt2Class, unionExt2Class); - assertContainsConstructor(unionExt2Class, unionExt1Class); - assertEquals(5, unionExt2Class.getDeclaredConstructors().length); - - // typedef union-ext3 - assertFalse(unionExt3Class.isInterface()); - assertContainsField(unionExt3Class, "_string", String.class); - assertContainsField(unionExt3Class, "_unionExt2", unionExt2Class); - assertContainsFieldWithValue(unionExt3Class, UNITS, String.class, "object id", new Class[] { String.class }, - ""); - assertContainsFieldWithValue(unionExt3Class, "serialVersionUID", Long.TYPE, 4347887914884631036L, - new Class[] { String.class }, ""); - // assertEquals(5, unionExt3Class.getDeclaredFields().length); - assertContainsMethod(unionExt3Class, String.class, "getString"); - assertContainsMethod(unionExt3Class, unionExt2Class, "getUnionExt2"); - assertContainsConstructor(unionExt3Class, String.class); - assertContainsConstructor(unionExt3Class, unionExt2Class); - assertContainsConstructor(unionExt3Class, unionExt3Class); - assertEquals(4, unionExt3Class.getDeclaredConstructors().length); - assertContainsDefaultMethods(unionExt3Class); - - // typedef union-ext4 - assertFalse(unionExt4Class.isInterface()); - assertContainsField(unionExt4Class, "_unionExt3", unionExt3Class); - assertContainsField(unionExt4Class, "_int32Ext2", int32Ext2Class); - assertContainsField(unionExt4Class, "_empty", Boolean.class); - assertContainsField(unionExt4Class, "_myDecimalType", myDecimalTypeClass); - assertContainsFieldWithValue(unionExt4Class, "serialVersionUID", Long.TYPE, 4299836385615211130L, - new Class[] { Boolean.class }, false); - // assertEquals(6, unionExt4Class.getDeclaredFields().length); - assertContainsMethod(unionExt4Class, unionExt3Class, "getUnionExt3"); - assertContainsMethod(unionExt4Class, int32Ext2Class, "getInt32Ext2"); - assertContainsMethod(unionExt4Class, Boolean.class, "isEmpty"); - assertContainsMethod(unionExt4Class, myDecimalTypeClass, "getMyDecimalType"); - assertContainsConstructor(unionExt4Class, unionExt3Class); - assertContainsConstructor(unionExt4Class, int32Ext2Class); - assertContainsConstructor(unionExt4Class, Boolean.class); - assertContainsConstructor(unionExt4Class, myDecimalTypeClass); - assertContainsConstructor(unionExt4Class, unionExt4Class); - assertEquals(6, unionExt4Class.getDeclaredConstructors().length); - assertContainsDefaultMethods(unionExt4Class); - - cleanUp(sourcesOutputDir, compiledOutputDir); - } -} diff --git a/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/stmt/parser/retest/UnionTypedefUnusedImportTest.java b/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/stmt/parser/retest/UnionTypedefUnusedImportTest.java deleted file mode 100644 index b4ec7a7510..0000000000 --- a/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/stmt/parser/retest/UnionTypedefUnusedImportTest.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * 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.yangtools.sal.java.api.generator.stmt.parser.retest; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.COMPILER_OUTPUT_PATH; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.FS; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.GENERATOR_OUTPUT_PATH; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.cleanUp; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.getSourceFiles; -import static org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.CompilationTestUtils.testCompilation; -import java.io.File; -import java.io.IOException; -import java.net.URISyntaxException; -import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.HashSet; -import java.util.List; -import org.junit.Test; -import org.opendaylight.yangtools.sal.binding.model.api.Type; -import org.opendaylight.yangtools.sal.java.api.generator.GeneratorJavaFile; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; - -public class UnionTypedefUnusedImportTest extends BaseCompilationTest { - - @Test - public void testUnionTypedefUnusedImport() throws Exception { - final File sourcesOutputDir = new File(GENERATOR_OUTPUT_PATH + FS + "union-typedef"); - assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir()); - final File compiledOutputDir = new File(COMPILER_OUTPUT_PATH + FS + "union-typedef"); - assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir()); - - final List sourceFiles = getSourceFiles("/compilation/union-typedef"); - final SchemaContext context = RetestUtils.parseYangSources(sourceFiles); - final List types = bindingGenerator.generateTypes(context); - final GeneratorJavaFile generator = new GeneratorJavaFile(new HashSet<>(types)); - generator.generateToFile(sourcesOutputDir); - final boolean isUsedImport = containsImport("org.opendaylight.yang.gen.v1.org.opendaylight.yangtools.union.typedef.rev130208.TypedefUnion"); - assertFalse(String.format("Class shouldn't contain import for this type '%s'", types.get(1).getName()), - isUsedImport); - - testCompilation(sourcesOutputDir, compiledOutputDir); - cleanUp(sourcesOutputDir, compiledOutputDir); - } - - private static String readFile(final String path, final Charset encoding) throws IOException { - byte[] encoded = Files.readAllBytes(Paths.get(path)); - return new String(encoded, encoding); - } - - private static boolean containsImport(final String fullImport) throws URISyntaxException, IOException { - final String filePath = GENERATOR_OUTPUT_PATH + FS + "union-typedef" + FS + "org" + FS + "opendaylight" + FS + "yang" + FS + "gen" + FS + "v1" + FS + "org" + FS + "opendaylight" + FS + "yangtools" + FS + "union" + FS + "typedef" + FS + "rev141124" + FS + "TypedefUnionBuilder.java"; - final String fileContent = readFile(filePath, StandardCharsets.UTF_8); - - if (fileContent.contains(fullImport)) { - return true; - } - return false; - } -} diff --git a/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/stmt/parser/retest/package-info.java b/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/stmt/parser/retest/package-info.java deleted file mode 100644 index e025ff445f..0000000000 --- a/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/stmt/parser/retest/package-info.java +++ /dev/null @@ -1,8 +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.yangtools.sal.java.api.generator.stmt.parser.retest; \ No newline at end of file diff --git a/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/test/AugmentToUsesInAugmentCompilationTest.java b/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/test/AugmentToUsesInAugmentCompilationTest.java index 41521a73e7..9797c42407 100644 --- a/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/test/AugmentToUsesInAugmentCompilationTest.java +++ b/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/test/AugmentToUsesInAugmentCompilationTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2016 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, @@ -8,19 +8,7 @@ package org.opendaylight.yangtools.sal.java.api.generator.test; import static org.junit.Assert.assertTrue; -import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.BASE_PKG; -import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.COMPILER_OUTPUT_PATH; -import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.FS; -import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.GENERATOR_OUTPUT_PATH; -import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.NS_BAR; -import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.NS_BAZ; -import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.NS_FOO; -import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.assertFilesCount; -import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.assertImplementsIfc; -import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.cleanUp; -import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.getSourceFiles; -import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.testAugmentation; -import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.testCompilation; + import com.google.common.collect.ImmutableSet; import java.io.File; import java.net.URL; @@ -35,27 +23,27 @@ public class AugmentToUsesInAugmentCompilationTest extends BaseCompilationTest { @Test public void testAugmentToUsesInAugment() throws Exception { - final File sourcesOutputDir = new File(GENERATOR_OUTPUT_PATH + FS + "augment-uses-to-augment"); + final File sourcesOutputDir = new File(CompilationTestUtils.GENERATOR_OUTPUT_PATH + CompilationTestUtils.FS + "augment-uses-to-augment"); assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir()); - final File compiledOutputDir = new File(COMPILER_OUTPUT_PATH + FS + "augment-uses-to-augment"); + final File compiledOutputDir = new File(CompilationTestUtils.COMPILER_OUTPUT_PATH + CompilationTestUtils.FS + "augment-uses-to-augment"); assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir()); - final List sourceFiles = getSourceFiles("/compilation/augment-uses-to-augment"); - final SchemaContext context = parser.parseFiles(sourceFiles); + final List sourceFiles = CompilationTestUtils.getSourceFiles("/compilation/augment-uses-to-augment"); + final SchemaContext context = RetestUtils.parseYangSources(sourceFiles); final List types = bindingGenerator.generateTypes(context); final GeneratorJavaFile generator = new GeneratorJavaFile(ImmutableSet.copyOf(types)); generator.generateToFile(sourcesOutputDir); // Test if all sources are generated from 'module foo' - File fooParent = new File(sourcesOutputDir, NS_FOO); - assertFilesCount(fooParent, 4); + File fooParent = new File(sourcesOutputDir, CompilationTestUtils.NS_FOO); + CompilationTestUtils.assertFilesCount(fooParent, 4); assertTrue(new File(fooParent, "IgpLinkAttributes.java").exists()); assertTrue(new File(fooParent, "Link1.java").exists()); assertTrue(new File(fooParent, "Link1Builder.java").exists()); // Test if all sources are generated from 'module bar' - File barParent = new File(sourcesOutputDir, NS_BAR); - assertFilesCount(barParent, 7); + File barParent = new File(sourcesOutputDir, CompilationTestUtils.NS_BAR); + CompilationTestUtils.assertFilesCount(barParent, 7); assertTrue(new File(barParent, "BarData.java").exists()); assertTrue(new File(barParent, "NetworkTopology.java").exists()); assertTrue(new File(barParent, "NetworkTopologyBuilder.java").exists()); @@ -63,57 +51,57 @@ public class AugmentToUsesInAugmentCompilationTest extends BaseCompilationTest { assertTrue(new File(barParent, "LinkAttributes.java").exists()); File networkParent = new File(barParent, "network"); - assertFilesCount(networkParent, 1); + CompilationTestUtils.assertFilesCount(networkParent, 1); File topologyParent = new File(networkParent, "topology"); - assertFilesCount(topologyParent, 3); + CompilationTestUtils.assertFilesCount(topologyParent, 3); assertTrue(new File(topologyParent, "Topology.java").exists()); assertTrue(new File(topologyParent, "TopologyBuilder.java").exists()); assertTrue(new File(topologyParent, "TopologyKey.java").exists()); File linkParent = new File(barParent, "link"); - assertFilesCount(linkParent, 3); + CompilationTestUtils.assertFilesCount(linkParent, 3); assertTrue(new File(linkParent, "Link.java").exists()); assertTrue(new File(linkParent, "LinkBuilder.java").exists()); assertTrue(new File(linkParent, "LinkKey.java").exists()); // Test if all sources are generated from 'module baz' - File bazParent = new File(sourcesOutputDir, NS_BAZ); - assertFilesCount(bazParent, 4); + File bazParent = new File(sourcesOutputDir, CompilationTestUtils.NS_BAZ); + CompilationTestUtils.assertFilesCount(bazParent, 4); assertTrue(new File(bazParent, "IgpLinkAttributes1.java").exists()); assertTrue(new File(bazParent, "IgpLinkAttributes1Builder.java").exists()); assertTrue(new File(bazParent, "LinkAttributes.java").exists()); // Test if sources are compilable - testCompilation(sourcesOutputDir, compiledOutputDir); + CompilationTestUtils.testCompilation(sourcesOutputDir, compiledOutputDir); ClassLoader loader = new URLClassLoader(new URL[] { compiledOutputDir.toURI().toURL() }); try { - Class link1Class = Class.forName(BASE_PKG + ".urn.opendaylight.foo.rev131008.Link1", true, loader); - String augmentableNode = BASE_PKG + ".urn.opendaylight.bar.rev131008.link.Link"; - testAugmentation(link1Class, augmentableNode); + Class link1Class = Class.forName(CompilationTestUtils.BASE_PKG + ".urn.opendaylight.foo.rev131008.Link1", true, loader); + String augmentableNode = CompilationTestUtils.BASE_PKG + ".urn.opendaylight.bar.rev131008.link.Link"; + CompilationTestUtils.testAugmentation(link1Class, augmentableNode); - Class igpLinkAttributesClass = Class.forName(BASE_PKG + Class igpLinkAttributesClass = Class.forName(CompilationTestUtils.BASE_PKG + ".urn.opendaylight.foo.rev131008.IgpLinkAttributes", true, loader); - assertImplementsIfc(link1Class, igpLinkAttributesClass); + CompilationTestUtils.assertImplementsIfc(link1Class, igpLinkAttributesClass); } catch (ClassNotFoundException e) { throw new AssertionError("Class for augment wasn't generated"); } try { - Class igpLinkAttributes1Class = Class.forName(BASE_PKG + Class igpLinkAttributes1Class = Class.forName(CompilationTestUtils.BASE_PKG + ".urn.opendaylight.baz.rev131008.IgpLinkAttributes1", true, loader); - String augmentableNode = BASE_PKG + ".urn.opendaylight.foo.rev131008.igp.link.attributes.IgpLinkAttributes"; - testAugmentation(igpLinkAttributes1Class, augmentableNode); + String augmentableNode = CompilationTestUtils.BASE_PKG + ".urn.opendaylight.foo.rev131008.igp.link.attributes.IgpLinkAttributes"; + CompilationTestUtils.testAugmentation(igpLinkAttributes1Class, augmentableNode); - Class linkAttributesClass = Class.forName(BASE_PKG + ".urn.opendaylight.baz.rev131008.LinkAttributes", + Class linkAttributesClass = Class.forName(CompilationTestUtils.BASE_PKG + ".urn.opendaylight.baz.rev131008.LinkAttributes", true, loader); - assertImplementsIfc(igpLinkAttributes1Class, linkAttributesClass); + CompilationTestUtils.assertImplementsIfc(igpLinkAttributes1Class, linkAttributesClass); } catch (ClassNotFoundException e) { throw new AssertionError("Class for augment wasn't generated"); } - cleanUp(sourcesOutputDir, compiledOutputDir); + CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir); } } diff --git a/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/test/BaseCompilationTest.java b/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/test/BaseCompilationTest.java index 2d95469304..465ff0c016 100644 --- a/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/test/BaseCompilationTest.java +++ b/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/test/BaseCompilationTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2016 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, @@ -8,33 +8,27 @@ package org.opendaylight.yangtools.sal.java.api.generator.test; import static org.junit.Assert.assertTrue; -import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.COMPILER_OUTPUT_DIR; -import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.GENERATOR_OUTPUT_DIR; -import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.TEST_DIR; -import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.deleteTestDir; + import org.junit.Before; import org.junit.BeforeClass; import org.opendaylight.yangtools.sal.binding.generator.api.BindingGenerator; import org.opendaylight.yangtools.sal.binding.generator.impl.BindingGeneratorImpl; -import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl; public abstract class BaseCompilationTest { - protected YangParserImpl parser; protected BindingGenerator bindingGenerator; @BeforeClass public static void createTestDirs() { - if (TEST_DIR.exists()) { - deleteTestDir(TEST_DIR); + if (CompilationTestUtils.TEST_DIR.exists()) { + CompilationTestUtils.deleteTestDir(CompilationTestUtils.TEST_DIR); } - assertTrue(GENERATOR_OUTPUT_DIR.mkdirs()); - assertTrue(COMPILER_OUTPUT_DIR.mkdirs()); + assertTrue(CompilationTestUtils.GENERATOR_OUTPUT_DIR.mkdirs()); + assertTrue(CompilationTestUtils.COMPILER_OUTPUT_DIR.mkdirs()); } @Before public void init() { - parser = new YangParserImpl(); bindingGenerator = new BindingGeneratorImpl(true); } diff --git a/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/test/Bug1276Test.java b/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/test/Bug1276Test.java index 9e2bfb610d..0a24d2d838 100644 --- a/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/test/Bug1276Test.java +++ b/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/test/Bug1276Test.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2016 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, @@ -8,14 +8,7 @@ package org.opendaylight.yangtools.sal.java.api.generator.test; import static org.junit.Assert.assertTrue; -import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.BASE_PKG; -import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.COMPILER_OUTPUT_PATH; -import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.FS; -import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.GENERATOR_OUTPUT_PATH; -import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.assertContainsConstructor; -import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.cleanUp; -import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.getSourceFiles; -import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.testCompilation; + import com.google.common.collect.ImmutableSet; import java.io.File; import java.lang.reflect.Constructor; @@ -55,24 +48,24 @@ public class Bug1276Test extends BaseCompilationTest { @Test public void test() throws Exception { - final File sourcesOutputDir = new File(GENERATOR_OUTPUT_PATH + FS + "bug1276"); + final File sourcesOutputDir = new File(CompilationTestUtils.GENERATOR_OUTPUT_PATH + CompilationTestUtils.FS + "bug1276"); assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir()); - final File compiledOutputDir = new File(COMPILER_OUTPUT_PATH + FS + "bug1276"); + final File compiledOutputDir = new File(CompilationTestUtils.COMPILER_OUTPUT_PATH + CompilationTestUtils.FS + "bug1276"); assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir()); generateTestSources("/compilation/bug1276", sourcesOutputDir); // Test if sources are compilable - testCompilation(sourcesOutputDir, compiledOutputDir); + CompilationTestUtils.testCompilation(sourcesOutputDir, compiledOutputDir); ClassLoader loader = new URLClassLoader(new URL[] { compiledOutputDir.toURI().toURL() }); - Class ipAddressClass = Class.forName(BASE_PKG + ".test.yang.union.rev140715.IpAddress", true, loader); - Class ipv4AddressClass = Class.forName(BASE_PKG + ".test.yang.union.rev140715.Ipv4Address", true, loader); - Class hostClass = Class.forName(BASE_PKG + ".test.yang.union.rev140715.Host", true, loader); + Class ipAddressClass = Class.forName(CompilationTestUtils.BASE_PKG + ".test.yang.union.rev140715.IpAddress", true, loader); + Class ipv4AddressClass = Class.forName(CompilationTestUtils.BASE_PKG + ".test.yang.union.rev140715.Ipv4Address", true, loader); + Class hostClass = Class.forName(CompilationTestUtils.BASE_PKG + ".test.yang.union.rev140715.Host", true, loader); - Constructor ipAddressConstructor = assertContainsConstructor(ipAddressClass, ipv4AddressClass); - Constructor ipv4addressConstructor = assertContainsConstructor(ipv4AddressClass, String.class); - Constructor hostConstructor = assertContainsConstructor(hostClass, ipAddressClass); + Constructor ipAddressConstructor = CompilationTestUtils.assertContainsConstructor(ipAddressClass, ipv4AddressClass); + Constructor ipv4addressConstructor = CompilationTestUtils.assertContainsConstructor(ipv4AddressClass, String.class); + Constructor hostConstructor = CompilationTestUtils.assertContainsConstructor(hostClass, ipAddressClass); // test IpAddress with Ipv4Address argument Object ipv4address = ipv4addressConstructor.newInstance("192.168.0.1"); @@ -90,12 +83,12 @@ public class Bug1276Test extends BaseCompilationTest { assertTrue(actual instanceof char[]); assertTrue(Arrays.equals(expected, (char[]) actual)); - cleanUp(sourcesOutputDir, compiledOutputDir); + CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir); } private void generateTestSources(final String resourceDirPath, final File sourcesOutputDir) throws Exception { - final List sourceFiles = getSourceFiles(resourceDirPath); - final SchemaContext context = parser.parseFiles(sourceFiles); + final List sourceFiles = CompilationTestUtils.getSourceFiles(resourceDirPath); + final SchemaContext context = RetestUtils.parseYangSources(sourceFiles); final List types = bindingGenerator.generateTypes(context); final GeneratorJavaFile generator = new GeneratorJavaFile(ImmutableSet.copyOf(types)); generator.generateToFile(sourcesOutputDir); diff --git a/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/test/Bug532Test.java b/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/test/Bug532Test.java index df865df7d3..592d328308 100644 --- a/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/test/Bug532Test.java +++ b/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/test/Bug532Test.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2016 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, @@ -42,25 +42,27 @@ public class Bug532Test extends BaseCompilationTest { final File compiledOutputDir = new File(COMPILER_OUTPUT_PATH + FS + "bug532"); assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir()); - generateTestSources("/compilation/list-gen", sourcesOutputDir); + generateTestSources("/compilation/list-gen-retest", sourcesOutputDir); // Test if sources are compilable testCompilation(sourcesOutputDir, compiledOutputDir); ClassLoader loader = new URLClassLoader(new URL[] { compiledOutputDir.toURI().toURL() }); - Class linksKeyClass = Class.forName(BASE_PKG + ".urn.opendaylight.test.rev131008.LinksKey", true, loader); - Class linksClass = Class.forName(BASE_PKG + ".urn.opendaylight.test.rev131008.Links", true, loader); - Class linksBuilderClass = Class.forName(BASE_PKG + ".urn.opendaylight.test.rev131008.LinksBuilder", true, + Class linksKeyClass = Class.forName(BASE_PKG + ".urn.opendaylight.retest.rev131008.LinksKey", true, loader); + Class linksClass = Class.forName(BASE_PKG + ".urn.opendaylight.retest.rev131008.Links", true, loader); + Class linksBuilderClass = Class.forName(BASE_PKG + ".urn.opendaylight.retest.rev131008.LinksBuilder", true, loader); - Class levelClass = Class.forName(BASE_PKG + ".urn.opendaylight.test.rev131008.links.Level", true, loader); - Class nodeClass = Class.forName(BASE_PKG + ".urn.opendaylight.test.rev131008.links.Node", true, loader); - Class nodeListClass = Class.forName(BASE_PKG + ".urn.opendaylight.test.rev131008.links.NodeList", true, + Class levelClass = Class.forName(BASE_PKG + ".urn.opendaylight.retest.rev131008.links.Level", true, loader); + Class nodeClass = Class.forName(BASE_PKG + ".urn.opendaylight.retest.rev131008.links.Node", true, loader); + Class nodeListClass = Class.forName(BASE_PKG + ".urn.opendaylight.retest.rev131008.links.NodeList", true, loader); // init default values Byte expectedId = Byte.valueOf("5"); String expectedName = "test-link"; Integer expectedSize = Integer.valueOf(10); + + Object expectedLevel = Mockito.mock(levelClass); Integer expectedLinksId = Integer.valueOf(11); Object expectedNode = Mockito.mock(nodeClass); @@ -108,7 +110,7 @@ public class Bug532Test extends BaseCompilationTest { private void generateTestSources(final String resourceDirPath, final File sourcesOutputDir) throws Exception { final List sourceFiles = getSourceFiles(resourceDirPath); - final SchemaContext context = parser.parseFiles(sourceFiles); + final SchemaContext context = RetestUtils.parseYangSources(sourceFiles); final List types = bindingGenerator.generateTypes(context); final GeneratorJavaFile generator = new GeneratorJavaFile(ImmutableSet.copyOf(types)); generator.generateToFile(sourcesOutputDir); diff --git a/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/test/CascadeUsesCompilationTest.java b/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/test/CascadeUsesCompilationTest.java index 004bfc7473..1993f569ae 100644 --- a/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/test/CascadeUsesCompilationTest.java +++ b/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/test/CascadeUsesCompilationTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2016 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, @@ -45,7 +45,7 @@ public class CascadeUsesCompilationTest extends BaseCompilationTest { assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir()); final List sourceFiles = getSourceFiles("/compilation/cascade-uses"); - final SchemaContext context = parser.parseFiles(sourceFiles); + final SchemaContext context = RetestUtils.parseYangSources(sourceFiles); final List types = bindingGenerator.generateTypes(context); final GeneratorJavaFile generator = new GeneratorJavaFile(ImmutableSet.copyOf(types)); generator.generateToFile(sourcesOutputDir); diff --git a/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/test/ClassCodeGeneratorTest.java b/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/test/ClassCodeGeneratorTest.java index ca2854fdff..2cf19eb468 100644 --- a/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/test/ClassCodeGeneratorTest.java +++ b/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/test/ClassCodeGeneratorTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2016 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, @@ -30,8 +30,8 @@ import org.opendaylight.yangtools.sal.binding.model.api.type.builder.GeneratedPr import org.opendaylight.yangtools.sal.binding.model.api.type.builder.GeneratedTOBuilder; import org.opendaylight.yangtools.sal.java.api.generator.TOGenerator; import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.model.parser.api.YangContextParser; -import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl; +import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; +import org.opendaylight.yangtools.yang.parser.spi.source.SourceException; public class ClassCodeGeneratorTest { @@ -45,9 +45,9 @@ public class ClassCodeGeneratorTest { } @Test - public void compositeKeyClassTest() throws IOException { - final YangContextParser parser = new YangParserImpl(); - final SchemaContext context = parser.parseFiles(testModels); + public void compositeKeyClassTest() throws IOException, SourceException, ReactorException { + + final SchemaContext context = RetestUtils.parseYangSources(testModels); assertNotNull(context); final BindingGenerator bindingGen = new BindingGeneratorImpl(true); diff --git a/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/test/CompilationTest.java b/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/test/CompilationTest.java index d8701b5ef4..74cd9019ef 100644 --- a/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/test/CompilationTest.java +++ b/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/test/CompilationTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2016 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, @@ -9,24 +9,6 @@ package org.opendaylight.yangtools.sal.java.api.generator.test; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.BASE_PKG; -import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.COMPILER_OUTPUT_PATH; -import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.FS; -import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.GENERATOR_OUTPUT_PATH; -import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.NS_BAR; -import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.NS_BAZ; -import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.NS_FOO; -import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.NS_TEST; -import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.assertContainsConstructor; -import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.assertContainsField; -import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.assertContainsMethod; -import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.assertContainsRestrictionCheck; -import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.assertFilesCount; -import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.assertImplementsIfc; -import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.assertImplementsParameterizedIfc; -import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.cleanUp; -import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.getSourceFiles; -import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.testCompilation; import com.google.common.base.Predicate; import com.google.common.collect.Collections2; @@ -79,15 +61,15 @@ public class CompilationTest extends BaseCompilationTest { @Test public void testListGeneration() throws Exception { - final File sourcesOutputDir = new File(GENERATOR_OUTPUT_PATH + FS + "list-gen"); + final File sourcesOutputDir = new File(CompilationTestUtils.GENERATOR_OUTPUT_PATH + CompilationTestUtils.FS + "list-gen"); assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir()); - final File compiledOutputDir = new File(COMPILER_OUTPUT_PATH + FS + "list-gen"); + final File compiledOutputDir = new File(CompilationTestUtils.COMPILER_OUTPUT_PATH + CompilationTestUtils.FS + "list-gen"); assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir()); generateTestSources("/compilation/list-gen", sourcesOutputDir); // Test if all sources are generated - File parent = new File(sourcesOutputDir, NS_TEST); + File parent = new File(sourcesOutputDir, CompilationTestUtils.NS_TEST); final File keyArgs = new File(parent, "KeyArgs.java"); final File links = new File(parent, "Links.java"); final File linksBuilder = new File(parent, "LinksBuilder.java"); @@ -98,9 +80,9 @@ public class CompilationTest extends BaseCompilationTest { assertTrue(linksBuilder.exists()); assertTrue(linksKey.exists()); assertTrue(testData.exists()); - assertFilesCount(parent, 6); + CompilationTestUtils.assertFilesCount(parent, 6); - parent = new File(sourcesOutputDir, NS_TEST + FS + "links"); + parent = new File(sourcesOutputDir, CompilationTestUtils.NS_TEST + CompilationTestUtils.FS + "links"); final File level = new File(parent, "Level.java"); final File linkGroup = new File(parent, "LinkGroup.java"); final File node = new File(parent, "Node.java"); @@ -115,154 +97,154 @@ public class CompilationTest extends BaseCompilationTest { assertTrue(nodeList.exists()); assertTrue(nodeListBuilder.exists()); assertTrue(nodesType.exists()); - assertFilesCount(parent, 7); + CompilationTestUtils.assertFilesCount(parent, 7); // Test if sources are compilable - testCompilation(sourcesOutputDir, compiledOutputDir); + CompilationTestUtils.testCompilation(sourcesOutputDir, compiledOutputDir); final ClassLoader loader = new URLClassLoader(new URL[] { compiledOutputDir.toURI().toURL() }); - final Class keyArgsClass = Class.forName(BASE_PKG + ".urn.opendaylight.test.rev131008.KeyArgs", true, loader); - final Class linksClass = Class.forName(BASE_PKG + ".urn.opendaylight.test.rev131008.Links", true, loader); - final Class linksKeyClass = Class.forName(BASE_PKG + ".urn.opendaylight.test.rev131008.LinksKey", true, loader); + final Class keyArgsClass = Class.forName(CompilationTestUtils.BASE_PKG + ".urn.opendaylight.test.rev131008.KeyArgs", true, loader); + final Class linksClass = Class.forName(CompilationTestUtils.BASE_PKG + ".urn.opendaylight.test.rev131008.Links", true, loader); + final Class linksKeyClass = Class.forName(CompilationTestUtils.BASE_PKG + ".urn.opendaylight.test.rev131008.LinksKey", true, loader); // Test generated 'grouping key-args' assertTrue(keyArgsClass.isInterface()); - assertContainsMethod(keyArgsClass, String.class, "getName"); - assertContainsMethod(keyArgsClass, Integer.class, "getSize"); + CompilationTestUtils.assertContainsMethod(keyArgsClass, String.class, "getName"); + CompilationTestUtils.assertContainsMethod(keyArgsClass, Integer.class, "getSize"); assertEquals(2, abstractMethods(keyArgsClass).size()); // Test generated 'list links' assertTrue(linksClass.isInterface()); - assertImplementsIfc(linksClass, keyArgsClass); + CompilationTestUtils.assertImplementsIfc(linksClass, keyArgsClass); // TODO: anyxml assertEquals(6, abstractMethods(linksClass).size()); // Test list key constructor arguments ordering - assertContainsConstructor(linksKeyClass, Byte.class, String.class, Integer.class); + CompilationTestUtils.assertContainsConstructor(linksKeyClass, Byte.class, String.class, Integer.class); // Test serialVersionUID generation - final Field suid = assertContainsField(linksKeyClass, "serialVersionUID", Long.TYPE); + final Field suid = CompilationTestUtils.assertContainsField(linksKeyClass, "serialVersionUID", Long.TYPE); suid.setAccessible(true); assertEquals(-8829501012356283881L, suid.getLong(null)); - cleanUp(sourcesOutputDir, compiledOutputDir); + CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir); } @Test public void testAugmentUnderUsesGeneration() throws Exception { - final File sourcesOutputDir = new File(GENERATOR_OUTPUT_PATH + FS + "augment-under-uses"); + final File sourcesOutputDir = new File(CompilationTestUtils.GENERATOR_OUTPUT_PATH + CompilationTestUtils.FS + "augment-under-uses"); assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir()); - final File compiledOutputDir = new File(COMPILER_OUTPUT_PATH + FS + "augment-under-uses"); + final File compiledOutputDir = new File(CompilationTestUtils.COMPILER_OUTPUT_PATH + CompilationTestUtils.FS + "augment-under-uses"); assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir()); generateTestSources("/compilation/augment-under-uses", sourcesOutputDir); // Test if all sources were generated from 'module foo' - File parent = new File(sourcesOutputDir, NS_FOO); + File parent = new File(sourcesOutputDir, CompilationTestUtils.NS_FOO); assertTrue(new File(parent, "Object.java").exists()); assertTrue(new File(parent, "ClosedObject.java").exists()); assertTrue(new File(parent, "OpenObject.java").exists()); assertTrue(new File(parent, "ExplicitRouteObject.java").exists()); assertTrue(new File(parent, "PathKeySubobject.java").exists()); - assertFilesCount(parent, 9); + CompilationTestUtils.assertFilesCount(parent, 9); parent = new File(parent, "object"); assertTrue(new File(parent, "Nodes.java").exists()); assertTrue(new File(parent, "NodesBuilder.java").exists()); - assertFilesCount(parent, 2); + CompilationTestUtils.assertFilesCount(parent, 2); - parent = new File(sourcesOutputDir, NS_FOO + FS + "closed"); - assertFilesCount(parent, 1); + parent = new File(sourcesOutputDir, CompilationTestUtils.NS_FOO + CompilationTestUtils.FS + "closed"); + CompilationTestUtils.assertFilesCount(parent, 1); parent = new File(parent, "object"); assertTrue(new File(parent, "Link1.java").exists()); assertTrue(new File(parent, "Link1Builder.java").exists()); - assertFilesCount(parent, 2); + CompilationTestUtils.assertFilesCount(parent, 2); - parent = new File(sourcesOutputDir, NS_FOO + FS + "open"); - assertFilesCount(parent, 1); + parent = new File(sourcesOutputDir, CompilationTestUtils.NS_FOO + CompilationTestUtils.FS + "open"); + CompilationTestUtils.assertFilesCount(parent, 1); parent = new File(parent, "object"); assertTrue(new File(parent, "Nodes1.java").exists()); assertTrue(new File(parent, "Nodes1Builder.java").exists()); - assertFilesCount(parent, 3); + CompilationTestUtils.assertFilesCount(parent, 3); parent = new File(parent, "nodes"); assertTrue(new File(parent, "Links.java").exists()); assertTrue(new File(parent, "LinksBuilder.java").exists()); - assertFilesCount(parent, 2); + CompilationTestUtils.assertFilesCount(parent, 2); - parent = new File(sourcesOutputDir, NS_FOO + FS + "explicit"); - assertFilesCount(parent, 1); + parent = new File(sourcesOutputDir, CompilationTestUtils.NS_FOO + CompilationTestUtils.FS + "explicit"); + CompilationTestUtils.assertFilesCount(parent, 1); parent = new File(parent, "route"); - assertFilesCount(parent, 1); + CompilationTestUtils.assertFilesCount(parent, 1); parent = new File(parent, "object"); assertTrue(new File(parent, "Subobjects.java").exists()); assertTrue(new File(parent, "SubobjectsBuilder.java").exists()); - assertFilesCount(parent, 3); + CompilationTestUtils.assertFilesCount(parent, 3); parent = new File(parent, "subobjects"); - assertFilesCount(parent, 1); + CompilationTestUtils.assertFilesCount(parent, 1); parent = new File(parent, "subobject"); - assertFilesCount(parent, 1); + CompilationTestUtils.assertFilesCount(parent, 1); parent = new File(parent, "type"); assertTrue(new File(parent, "PathKey.java").exists()); assertTrue(new File(parent, "PathKeyBuilder.java").exists()); - assertFilesCount(parent, 3); + CompilationTestUtils.assertFilesCount(parent, 3); parent = new File(parent, "path"); - assertFilesCount(parent, 1); + CompilationTestUtils.assertFilesCount(parent, 1); parent = new File(parent, "key"); assertTrue(new File(parent, "PathKey.java").exists()); assertTrue(new File(parent, "PathKeyBuilder.java").exists()); - assertFilesCount(parent, 2); + CompilationTestUtils.assertFilesCount(parent, 2); // Test if all sources were generated from 'module bar' - parent = new File(sourcesOutputDir, NS_BAR); + parent = new File(sourcesOutputDir, CompilationTestUtils.NS_BAR); assertTrue(new File(parent, "BasicExplicitRouteSubobjects.java").exists()); assertTrue(new File(parent, "ExplicitRouteSubobjects.java").exists()); assertTrue(new File(parent, "RouteSubobjects.java").exists()); - assertFilesCount(parent, 5); + CompilationTestUtils.assertFilesCount(parent, 5); parent = new File(parent, "route"); - assertFilesCount(parent, 1); - parent = new File(new File(sourcesOutputDir, NS_BAR), "basic"); - assertFilesCount(parent, 1); + CompilationTestUtils.assertFilesCount(parent, 1); + parent = new File(new File(sourcesOutputDir, CompilationTestUtils.NS_BAR), "basic"); + CompilationTestUtils.assertFilesCount(parent, 1); parent = new File(parent, "explicit"); - assertFilesCount(parent, 1); + CompilationTestUtils.assertFilesCount(parent, 1); parent = new File(parent, "route"); - assertFilesCount(parent, 1); + CompilationTestUtils.assertFilesCount(parent, 1); parent = new File(parent, "subobjects"); - assertFilesCount(parent, 2); + CompilationTestUtils.assertFilesCount(parent, 2); assertTrue(new File(parent, "SubobjectType.java").exists()); parent = new File(parent, "subobject"); - assertFilesCount(parent, 1); + CompilationTestUtils.assertFilesCount(parent, 1); parent = new File(parent, "type"); assertTrue(new File(parent, "IpPrefix.java").exists()); assertTrue(new File(parent, "IpPrefixBuilder.java").exists()); assertTrue(new File(parent, "Label.java").exists()); assertTrue(new File(parent, "LabelBuilder.java").exists()); - assertFilesCount(parent, 4); + CompilationTestUtils.assertFilesCount(parent, 4); // Test if sources are compilable - testCompilation(sourcesOutputDir, compiledOutputDir); + CompilationTestUtils.testCompilation(sourcesOutputDir, compiledOutputDir); - cleanUp(sourcesOutputDir, compiledOutputDir); + CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir); } @Test public void testAugmentOfAugmentGeneration() throws Exception { - final File sourcesOutputDir = new File(GENERATOR_OUTPUT_PATH + FS + "aug-of-aug"); + final File sourcesOutputDir = new File(CompilationTestUtils.GENERATOR_OUTPUT_PATH + CompilationTestUtils.FS + "aug-of-aug"); assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir()); - final File compiledOutputDir = new File(COMPILER_OUTPUT_PATH + FS + "aug-of-aug"); + final File compiledOutputDir = new File(CompilationTestUtils.COMPILER_OUTPUT_PATH + CompilationTestUtils.FS + "aug-of-aug"); assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir()); generateTestSources("/compilation/augment-of-augment", sourcesOutputDir); // Test if all sources were generated from 'module foo' - File parent = new File(sourcesOutputDir, NS_FOO); + File parent = new File(sourcesOutputDir, CompilationTestUtils.NS_FOO); final File fooListener = new File(parent, "FooListener.java"); File pathAttributes = new File(parent, "PathAttributes.java"); final File update = new File(parent, "Update.java"); @@ -271,220 +253,220 @@ public class CompilationTest extends BaseCompilationTest { assertTrue(pathAttributes.exists()); assertTrue(update.exists()); assertTrue(updateBuilder.exists()); - assertFilesCount(parent, 6); + CompilationTestUtils.assertFilesCount(parent, 6); - parent = new File(sourcesOutputDir, NS_FOO + FS + "path"); - assertFilesCount(parent, 1); + parent = new File(sourcesOutputDir, CompilationTestUtils.NS_FOO + CompilationTestUtils.FS + "path"); + CompilationTestUtils.assertFilesCount(parent, 1); parent = new File(parent, "attributes"); - assertFilesCount(parent, 2); + CompilationTestUtils.assertFilesCount(parent, 2); final File origin = new File(parent, "Origin.java"); final File originBuilder = new File(parent, "OriginBuilder.java"); assertTrue(origin.exists()); assertTrue(originBuilder.exists()); - parent = new File(sourcesOutputDir, NS_FOO + FS + "update"); - assertFilesCount(parent, 2); + parent = new File(sourcesOutputDir, CompilationTestUtils.NS_FOO + CompilationTestUtils.FS + "update"); + CompilationTestUtils.assertFilesCount(parent, 2); pathAttributes = new File(parent, "PathAttributes.java"); final File pathAttributesBuilder = new File(parent, "PathAttributesBuilder.java"); assertTrue(pathAttributes.exists()); assertTrue(pathAttributesBuilder.exists()); // Test if all sources were generated from 'module bar' - parent = new File(sourcesOutputDir, NS_BAR); + parent = new File(sourcesOutputDir, CompilationTestUtils.NS_BAR); final File destination = new File(parent, "Destination.java"); final File pathAttributes1 = new File(parent, "PathAttributes1.java"); final File pathAttributes1Builder = new File(parent, "PathAttributes1Builder.java"); assertTrue(destination.exists()); assertTrue(pathAttributes1.exists()); assertTrue(pathAttributes1Builder.exists()); - assertFilesCount(parent, 5); + CompilationTestUtils.assertFilesCount(parent, 5); - parent = new File(sourcesOutputDir, NS_BAR + FS + "destination"); - assertFilesCount(parent, 2); + parent = new File(sourcesOutputDir, CompilationTestUtils.NS_BAR + CompilationTestUtils.FS + "destination"); + CompilationTestUtils.assertFilesCount(parent, 2); final File destinationType = new File(parent, "DestinationType.java"); assertTrue(destinationType.exists()); parent = new File(parent, "destination"); - assertFilesCount(parent, 1); + CompilationTestUtils.assertFilesCount(parent, 1); parent = new File(parent, "type"); - assertFilesCount(parent, 2); + CompilationTestUtils.assertFilesCount(parent, 2); final File destinationIpv4 = new File(parent, "DestinationIp.java"); final File destinationIpv4Builder = new File(parent, "DestinationIpBuilder.java"); assertTrue(destinationIpv4.exists()); assertTrue(destinationIpv4Builder.exists()); - parent = new File(sourcesOutputDir, NS_BAR + FS + "update"); - assertFilesCount(parent, 1); + parent = new File(sourcesOutputDir, CompilationTestUtils.NS_BAR + CompilationTestUtils.FS + "update"); + CompilationTestUtils.assertFilesCount(parent, 1); parent = new File(parent, "path"); - assertFilesCount(parent, 1); + CompilationTestUtils.assertFilesCount(parent, 1); parent = new File(parent, "attributes"); final File mpUnreachNlri = new File(parent, "MpUnreachNlri.java"); final File mpUnreachNlriBuilder = new File(parent, "MpUnreachNlriBuilder.java"); assertTrue(mpUnreachNlri.exists()); assertTrue(mpUnreachNlriBuilder.exists()); - assertFilesCount(parent, 3); + CompilationTestUtils.assertFilesCount(parent, 3); parent = new File(parent, "mp"); - assertFilesCount(parent, 1); + CompilationTestUtils.assertFilesCount(parent, 1); parent = new File(parent, "unreach"); - assertFilesCount(parent, 1); + CompilationTestUtils.assertFilesCount(parent, 1); parent = new File(parent, "nlri"); final File withdrawnRoutes = new File(parent, "WithdrawnRoutes.java"); final File withdrawnRoutesBuilder = new File(parent, "WithdrawnRoutesBuilder.java"); assertTrue(withdrawnRoutes.exists()); assertTrue(withdrawnRoutesBuilder.exists()); - assertFilesCount(parent, 2); + CompilationTestUtils.assertFilesCount(parent, 2); // Test if all sources were generated from 'module baz' - parent = new File(sourcesOutputDir, NS_BAZ); - assertFilesCount(parent, 2); + parent = new File(sourcesOutputDir, CompilationTestUtils.NS_BAZ); + CompilationTestUtils.assertFilesCount(parent, 2); final File linkstateDestination = new File(parent, "LinkstateDestination.java"); assertTrue(linkstateDestination.exists()); - parent = new File(sourcesOutputDir, NS_BAZ + FS + "update"); - assertFilesCount(parent, 1); + parent = new File(sourcesOutputDir, CompilationTestUtils.NS_BAZ + CompilationTestUtils.FS + "update"); + CompilationTestUtils.assertFilesCount(parent, 1); parent = new File(parent, "path"); - assertFilesCount(parent, 1); + CompilationTestUtils.assertFilesCount(parent, 1); parent = new File(parent, "attributes"); - assertFilesCount(parent, 1); + CompilationTestUtils.assertFilesCount(parent, 1); parent = new File(parent, "mp"); - assertFilesCount(parent, 1); + CompilationTestUtils.assertFilesCount(parent, 1); parent = new File(parent, "unreach"); - assertFilesCount(parent, 1); + CompilationTestUtils.assertFilesCount(parent, 1); parent = new File(parent, "nlri"); - assertFilesCount(parent, 1); + CompilationTestUtils.assertFilesCount(parent, 1); parent = new File(parent, "withdrawn"); - assertFilesCount(parent, 1); + CompilationTestUtils.assertFilesCount(parent, 1); parent = new File(parent, "routes"); - assertFilesCount(parent, 1); + CompilationTestUtils.assertFilesCount(parent, 1); parent = new File(parent, "destination"); - assertFilesCount(parent, 1); + CompilationTestUtils.assertFilesCount(parent, 1); parent = new File(parent, "type"); final File destinationLinkstate = new File(parent, "DestinationLinkstate.java"); final File destinationLinkstateBuilder = new File(parent, "DestinationLinkstateBuilder.java"); assertTrue(destinationLinkstate.exists()); assertTrue(destinationLinkstateBuilder.exists()); - assertFilesCount(parent, 3); + CompilationTestUtils.assertFilesCount(parent, 3); parent = new File(parent, "destination"); - assertFilesCount(parent, 1); + CompilationTestUtils.assertFilesCount(parent, 1); parent = new File(parent, "linkstate"); final File links = new File(parent, "Links.java"); final File linksBuilder = new File(parent, "LinksBuilder.java"); assertTrue(links.exists()); assertTrue(linksBuilder.exists()); - assertFilesCount(parent, 3); + CompilationTestUtils.assertFilesCount(parent, 3); parent = new File(parent, "links"); final File source = new File(parent, "Source.java"); final File sourceBuilder = new File(parent, "SourceBuilder.java"); assertTrue(source.exists()); assertTrue(sourceBuilder.exists()); - assertFilesCount(parent, 3); + CompilationTestUtils.assertFilesCount(parent, 3); parent = new File(parent, "source"); final File address = new File(parent, "Address.java"); final File addressBuilder = new File(parent, "AddressBuilder.java"); assertTrue(address.exists()); assertTrue(addressBuilder.exists()); - assertFilesCount(parent, 2); + CompilationTestUtils.assertFilesCount(parent, 2); // Test if sources are compilable - testCompilation(sourcesOutputDir, compiledOutputDir); + CompilationTestUtils.testCompilation(sourcesOutputDir, compiledOutputDir); - cleanUp(sourcesOutputDir, compiledOutputDir); + CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir); } @Test public void testLeafReturnTypes() throws Exception { - final File sourcesOutputDir = new File(GENERATOR_OUTPUT_PATH + FS + "leaf-return-types"); + final File sourcesOutputDir = new File(CompilationTestUtils.GENERATOR_OUTPUT_PATH + CompilationTestUtils.FS + "leaf-return-types"); assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir()); - final File compiledOutputDir = new File(COMPILER_OUTPUT_PATH + FS + "leaf-return-types"); + final File compiledOutputDir = new File(CompilationTestUtils.COMPILER_OUTPUT_PATH + CompilationTestUtils.FS + "leaf-return-types"); assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir()); generateTestSources("/compilation/leaf-return-types", sourcesOutputDir); - final File parent = new File(sourcesOutputDir, NS_TEST); + final File parent = new File(sourcesOutputDir, CompilationTestUtils.NS_TEST); assertTrue(new File(parent, "TestData.java").exists()); assertTrue(new File(parent, "Nodes.java").exists()); assertTrue(new File(parent, "NodesBuilder.java").exists()); assertTrue(new File(parent, "Alg.java").exists()); assertTrue(new File(parent, "NodesIdUnionBuilder.java").exists()); - assertFilesCount(parent, 5); + CompilationTestUtils.assertFilesCount(parent, 5); // Test if sources are compilable - testCompilation(sourcesOutputDir, compiledOutputDir); + CompilationTestUtils.testCompilation(sourcesOutputDir, compiledOutputDir); - final String pkg = BASE_PKG + ".urn.opendaylight.test.rev131008"; + final String pkg = CompilationTestUtils.BASE_PKG + ".urn.opendaylight.test.rev131008"; final ClassLoader loader = new URLClassLoader(new URL[] { compiledOutputDir.toURI().toURL() }); final Class nodesClass = Class.forName(pkg + ".Nodes", true, loader); final Class builderClass = Class.forName(pkg + ".NodesBuilder", true, loader); // Test methods return type final byte[] b = new byte[] {}; - assertContainsMethod(nodesClass, b.getClass(), "getIdBinary"); - assertContainsMethod(nodesClass, pkg + ".Nodes$IdBits", "getIdBits", loader); - assertContainsMethod(nodesClass, Boolean.class, "isIdBoolean"); - assertContainsMethod(nodesClass, BigDecimal.class, "getIdDecimal64"); - assertContainsMethod(nodesClass, Boolean.class, "isIdEmpty"); - assertContainsMethod(nodesClass, pkg + ".Nodes$IdEnumeration", "getIdEnumeration", loader); + CompilationTestUtils.assertContainsMethod(nodesClass, b.getClass(), "getIdBinary"); + CompilationTestUtils.assertContainsMethod(nodesClass, pkg + ".Nodes$IdBits", "getIdBits", loader); + CompilationTestUtils.assertContainsMethod(nodesClass, Boolean.class, "isIdBoolean"); + CompilationTestUtils.assertContainsMethod(nodesClass, BigDecimal.class, "getIdDecimal64"); + CompilationTestUtils.assertContainsMethod(nodesClass, Boolean.class, "isIdEmpty"); + CompilationTestUtils.assertContainsMethod(nodesClass, pkg + ".Nodes$IdEnumeration", "getIdEnumeration", loader); testReturnTypeIdentityref(nodesClass, "getIdIdentityref", pkg + ".Alg"); testReturnTypeInstanceIdentitifer(loader, nodesClass, "getIdInstanceIdentifier"); - assertContainsMethod(nodesClass, Byte.class, "getId8"); - assertContainsMethod(nodesClass, Short.class, "getId16"); - assertContainsMethod(nodesClass, Integer.class, "getId32"); - assertContainsMethod(nodesClass, Long.class, "getId64"); - assertContainsMethod(nodesClass, Long.class, "getIdLeafref"); - assertContainsMethod(nodesClass, String.class, "getIdString"); - assertContainsMethod(nodesClass, Short.class, "getIdU8"); - assertContainsMethod(nodesClass, Integer.class, "getIdU16"); - assertContainsMethod(nodesClass, Long.class, "getIdU32"); - assertContainsMethod(nodesClass, BigInteger.class, "getIdU64"); - assertContainsMethod(nodesClass, pkg + ".Nodes$IdUnion", "getIdUnion", loader); + CompilationTestUtils.assertContainsMethod(nodesClass, Byte.class, "getId8"); + CompilationTestUtils.assertContainsMethod(nodesClass, Short.class, "getId16"); + CompilationTestUtils.assertContainsMethod(nodesClass, Integer.class, "getId32"); + CompilationTestUtils.assertContainsMethod(nodesClass, Long.class, "getId64"); + CompilationTestUtils.assertContainsMethod(nodesClass, Long.class, "getIdLeafref"); + CompilationTestUtils.assertContainsMethod(nodesClass, String.class, "getIdString"); + CompilationTestUtils.assertContainsMethod(nodesClass, Short.class, "getIdU8"); + CompilationTestUtils.assertContainsMethod(nodesClass, Integer.class, "getIdU16"); + CompilationTestUtils.assertContainsMethod(nodesClass, Long.class, "getIdU32"); + CompilationTestUtils.assertContainsMethod(nodesClass, BigInteger.class, "getIdU64"); + CompilationTestUtils.assertContainsMethod(nodesClass, pkg + ".Nodes$IdUnion", "getIdUnion", loader); final Object builderObj = builderClass.newInstance(); - Method m = assertContainsMethod(builderClass, builderClass, "setIdBinary", b.getClass()); + Method m = CompilationTestUtils.assertContainsMethod(builderClass, builderClass, "setIdBinary", b.getClass()); final List> lengthConstraints = new ArrayList<>(); lengthConstraints.add(Range.closed(1, 10)); byte[] arg = new byte[] {}; String expectedMsg = String.format("Invalid length: %s, expected: %s.", Arrays.toString(arg), lengthConstraints); - assertContainsRestrictionCheck(builderObj, m, expectedMsg, arg); + CompilationTestUtils.assertContainsRestrictionCheck(builderObj, m, expectedMsg, arg); - m = assertContainsMethod(builderClass, builderClass, "setIdDecimal64", BigDecimal.class); + m = CompilationTestUtils.assertContainsMethod(builderClass, builderClass, "setIdDecimal64", BigDecimal.class); final List> rangeConstraints = new ArrayList<>(); rangeConstraints.add(Range.closed(new BigDecimal("1.5"), new BigDecimal("5.5"))); Object arg1 = new BigDecimal("1.4"); expectedMsg = String.format("Invalid range: %s, expected: %s.", arg1, rangeConstraints); - assertContainsRestrictionCheck(builderObj, m, expectedMsg, arg1); + CompilationTestUtils.assertContainsRestrictionCheck(builderObj, m, expectedMsg, arg1); - cleanUp(sourcesOutputDir, compiledOutputDir); + CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir); } @Test public void testGenerationContextReferenceExtension() throws Exception { - final File sourcesOutputDir = new File(GENERATOR_OUTPUT_PATH + FS + "context-reference"); + final File sourcesOutputDir = new File(CompilationTestUtils.GENERATOR_OUTPUT_PATH + CompilationTestUtils.FS + "context-reference"); assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir()); - final File compiledOutputDir = new File(COMPILER_OUTPUT_PATH + FS + "context-reference"); + final File compiledOutputDir = new File(CompilationTestUtils.COMPILER_OUTPUT_PATH + CompilationTestUtils.FS + "context-reference"); assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir()); generateTestSources("/compilation/context-reference", sourcesOutputDir); // Test if all sources are generated - final File fooParent = new File(sourcesOutputDir, NS_FOO); - assertFilesCount(fooParent, 3); + final File fooParent = new File(sourcesOutputDir, CompilationTestUtils.NS_FOO); + CompilationTestUtils.assertFilesCount(fooParent, 3); assertTrue(new File(fooParent, "FooData.java").exists()); assertTrue(new File(fooParent, "Nodes.java").exists()); assertTrue(new File(fooParent, "NodesBuilder.java").exists()); - final File barParent = new File(sourcesOutputDir, NS_BAR); - assertFilesCount(barParent, 1); + final File barParent = new File(sourcesOutputDir, CompilationTestUtils.NS_BAR); + CompilationTestUtils.assertFilesCount(barParent, 1); assertTrue(new File(barParent, "IdentityClass.java").exists()); // Test if sources are compilable - testCompilation(sourcesOutputDir, compiledOutputDir); + CompilationTestUtils.testCompilation(sourcesOutputDir, compiledOutputDir); final ClassLoader loader = new URLClassLoader(new URL[] { compiledOutputDir.toURI().toURL() }); - final Class nodesClass = Class.forName(BASE_PKG + ".urn.opendaylight.foo.rev131008.Nodes", true, loader); + final Class nodesClass = Class.forName(CompilationTestUtils.BASE_PKG + ".urn.opendaylight.foo.rev131008.Nodes", true, loader); final Class identityClass = Class - .forName(BASE_PKG + ".urn.opendaylight.bar.rev131008.IdentityClass", true, loader); + .forName(CompilationTestUtils.BASE_PKG + ".urn.opendaylight.bar.rev131008.IdentityClass", true, loader); // test identity try { @@ -506,37 +488,52 @@ public class CompilationTest extends BaseCompilationTest { throw new AssertionError("Method getId() not found"); } - cleanUp(sourcesOutputDir, compiledOutputDir); + CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir); } @Test public void compilationTest() throws Exception { - final File sourcesOutputDir = new File(GENERATOR_OUTPUT_PATH + FS + "yang"); + final File sourcesOutputDir = new File(CompilationTestUtils.GENERATOR_OUTPUT_PATH + CompilationTestUtils.FS + "yang"); assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir()); - final File compiledOutputDir = new File(COMPILER_OUTPUT_PATH + FS + "yang"); + final File compiledOutputDir = new File(CompilationTestUtils.COMPILER_OUTPUT_PATH + CompilationTestUtils.FS + "yang"); assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir()); generateTestSources("/yang", sourcesOutputDir); // Test if sources are compilable - testCompilation(sourcesOutputDir, compiledOutputDir); + CompilationTestUtils.testCompilation(sourcesOutputDir, compiledOutputDir); - cleanUp(sourcesOutputDir, compiledOutputDir); + CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir); } @Test public void testBug586() throws Exception { - final File sourcesOutputDir = new File(GENERATOR_OUTPUT_PATH + FS + "bug586"); + final File sourcesOutputDir = new File(CompilationTestUtils.GENERATOR_OUTPUT_PATH + CompilationTestUtils.FS + "bug586"); assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir()); - final File compiledOutputDir = new File(COMPILER_OUTPUT_PATH + FS + "bug586"); + final File compiledOutputDir = new File(CompilationTestUtils.COMPILER_OUTPUT_PATH + CompilationTestUtils.FS + "bug586"); assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir()); generateTestSources("/compilation/bug586", sourcesOutputDir); // Test if sources are compilable - testCompilation(sourcesOutputDir, compiledOutputDir); + CompilationTestUtils.testCompilation(sourcesOutputDir, compiledOutputDir); - cleanUp(sourcesOutputDir, compiledOutputDir); + CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir); + } + + @Test + public void testBug4760() throws Exception { + final File sourcesOutputDir = new File(CompilationTestUtils.GENERATOR_OUTPUT_PATH + CompilationTestUtils.FS + "bug4760"); + assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir()); + final File compiledOutputDir = new File(CompilationTestUtils.COMPILER_OUTPUT_PATH + CompilationTestUtils.FS + "bug4760"); + assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir()); + + generateTestSources("/compilation/bug4760", sourcesOutputDir); + + // Test if sources are compilable + CompilationTestUtils.testCompilation(sourcesOutputDir, compiledOutputDir); + + CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir); } /** @@ -546,17 +543,47 @@ public class CompilationTest extends BaseCompilationTest { */ @Test public void testBug1172() throws Exception { - final File sourcesOutputDir = new File(GENERATOR_OUTPUT_PATH + FS + "bug1172"); + final File sourcesOutputDir = new File(CompilationTestUtils.GENERATOR_OUTPUT_PATH + CompilationTestUtils.FS + "bug1172"); assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir()); - final File compiledOutputDir = new File(COMPILER_OUTPUT_PATH + FS + "bug1172"); + final File compiledOutputDir = new File(CompilationTestUtils.COMPILER_OUTPUT_PATH + CompilationTestUtils.FS + "bug1172"); assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir()); generateTestSources("/compilation/bug1172", sourcesOutputDir); // Test if sources are compilable - testCompilation(sourcesOutputDir, compiledOutputDir); + CompilationTestUtils.testCompilation(sourcesOutputDir, compiledOutputDir); + + CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir); + } + + @Test + public void testBug5461() throws Exception { + final File sourcesOutputDir = new File(CompilationTestUtils.GENERATOR_OUTPUT_PATH + CompilationTestUtils.FS + "bug5461"); + assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir()); + final File compiledOutputDir = new File(CompilationTestUtils.COMPILER_OUTPUT_PATH + CompilationTestUtils.FS + "bug5461"); + assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir()); + + generateTestSources("/compilation/bug5461", sourcesOutputDir); + + // Test if sources are compilable + CompilationTestUtils.testCompilation(sourcesOutputDir, compiledOutputDir); + + CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir); + } + + @Test + public void testBug5788() throws Exception { + final File sourcesOutputDir = new File(CompilationTestUtils.GENERATOR_OUTPUT_PATH + CompilationTestUtils.FS + "bug5788"); + assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir()); + final File compiledOutputDir = new File(CompilationTestUtils.COMPILER_OUTPUT_PATH + CompilationTestUtils.FS + "bug5788"); + assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir()); + + generateTestSources("/compilation/bug5788", sourcesOutputDir); + + // Test if sources are compilable + CompilationTestUtils.testCompilation(sourcesOutputDir, compiledOutputDir); - cleanUp(sourcesOutputDir, compiledOutputDir); + CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir); } /** @@ -566,43 +593,43 @@ public class CompilationTest extends BaseCompilationTest { */ @Test public void testBug1377() throws Exception { - final File sourcesOutputDir = new File(GENERATOR_OUTPUT_PATH + FS + "bug1377"); + final File sourcesOutputDir = new File(CompilationTestUtils.GENERATOR_OUTPUT_PATH + CompilationTestUtils.FS + "bug1377"); assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir()); - final File compiledOutputDir = new File(COMPILER_OUTPUT_PATH + FS + "bug1377"); + final File compiledOutputDir = new File(CompilationTestUtils.COMPILER_OUTPUT_PATH + CompilationTestUtils.FS + "bug1377"); assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir()); generateTestSources("/compilation/bug1377", sourcesOutputDir); // Test if sources are compilable - testCompilation(sourcesOutputDir, compiledOutputDir); + CompilationTestUtils.testCompilation(sourcesOutputDir, compiledOutputDir); final ClassLoader loader = new URLClassLoader(new URL[] { compiledOutputDir.toURI().toURL() }); - final Class outputActionClass = Class.forName(BASE_PKG + final Class outputActionClass = Class.forName(CompilationTestUtils.BASE_PKG + ".urn.test.foo.rev140717.action.action.output.action._case.OutputAction", true, loader); - final Class actionClass = Class.forName(BASE_PKG + ".urn.test.foo.rev140717.Action", true, loader); + final Class actionClass = Class.forName(CompilationTestUtils.BASE_PKG + ".urn.test.foo.rev140717.Action", true, loader); // Test generated 'container output-action' assertTrue(outputActionClass.isInterface()); - assertImplementsParameterizedIfc(outputActionClass, ChildOf.class.toString(), actionClass.getCanonicalName()); + CompilationTestUtils.assertImplementsParameterizedIfc(outputActionClass, ChildOf.class.toString(), actionClass.getCanonicalName()); - cleanUp(sourcesOutputDir, compiledOutputDir); + CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir); } @Test public void classNamesColisionTest() throws Exception { - final File sourcesOutputDir = new File(GENERATOR_OUTPUT_PATH + FS + "class-name-collision"); + final File sourcesOutputDir = new File(CompilationTestUtils.GENERATOR_OUTPUT_PATH + CompilationTestUtils.FS + "class-name-collision"); assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir()); - final File compiledOutputDir = new File(COMPILER_OUTPUT_PATH + FS + "class-name-collision"); + final File compiledOutputDir = new File(CompilationTestUtils.COMPILER_OUTPUT_PATH + CompilationTestUtils.FS + "class-name-collision"); assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir()); generateTestSources("/compilation/class-name-collision", sourcesOutputDir); - testCompilation(sourcesOutputDir, compiledOutputDir); - cleanUp(sourcesOutputDir, compiledOutputDir); + CompilationTestUtils.testCompilation(sourcesOutputDir, compiledOutputDir); + CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir); } private void generateTestSources(final String resourceDirPath, final File sourcesOutputDir) throws Exception { - final List sourceFiles = getSourceFiles(resourceDirPath); - final SchemaContext context = parser.parseFiles(sourceFiles); + final List sourceFiles = CompilationTestUtils.getSourceFiles(resourceDirPath); + final SchemaContext context = RetestUtils.parseYangSources(sourceFiles); final List types = bindingGenerator.generateTypes(context); Collections.sort(types, new Comparator() { @Override diff --git a/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/test/CompilationTestUtils.java b/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/test/CompilationTestUtils.java index 118fa94b1e..a442b23026 100644 --- a/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/test/CompilationTestUtils.java +++ b/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/test/CompilationTestUtils.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2016 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, diff --git a/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/test/EncodingInJavaDocTest.java b/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/test/EncodingInJavaDocTest.java index c30c121d68..dc31d7a9f1 100644 --- a/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/test/EncodingInJavaDocTest.java +++ b/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/test/EncodingInJavaDocTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2016 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, @@ -14,7 +14,6 @@ import static org.opendaylight.yangtools.sal.java.api.generator.test.Compilation import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.cleanUp; import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.getSourceFiles; import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.testCompilation; - import com.google.common.collect.ImmutableSet; import java.io.File; import java.util.List; @@ -30,14 +29,14 @@ import org.opendaylight.yangtools.yang.model.api.SchemaContext; public class EncodingInJavaDocTest extends BaseCompilationTest { @Test - public void testJavadocEncodingCompilation() throws Exception { + public void testAugmentToUsesInAugment() throws Exception { final File sourcesOutputDir = new File(GENERATOR_OUTPUT_PATH + FS + "encoding-javadoc"); assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir()); final File compiledOutputDir = new File(COMPILER_OUTPUT_PATH + FS + "encoding-javadoc"); assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir()); final List sourceFiles = getSourceFiles("/compilation/encoding-javadoc"); - final SchemaContext context = parser.parseFiles(sourceFiles); + final SchemaContext context = RetestUtils.parseYangSources(sourceFiles); final List types = bindingGenerator.generateTypes(context); final GeneratorJavaFile generator = new GeneratorJavaFile(ImmutableSet.copyOf(types)); generator.generateToFile(sourcesOutputDir); diff --git a/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/test/GeneratorJavaFileTest.java b/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/test/GeneratorJavaFileTest.java index 8105ea110f..90c48eadee 100644 --- a/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/test/GeneratorJavaFileTest.java +++ b/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/test/GeneratorJavaFileTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2016 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, @@ -8,12 +8,14 @@ package org.opendaylight.yangtools.sal.java.api.generator.test; import static org.junit.Assert.assertTrue; + import java.io.File; import java.io.IOException; import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Set; + import org.junit.Test; import org.opendaylight.yangtools.binding.generator.util.BindingTypes; import org.opendaylight.yangtools.binding.generator.util.Types; @@ -52,7 +54,7 @@ public class GeneratorJavaFileTest { assertTrue(filesList.contains("Type4Builder.java")); } - private static GeneratedType createGeneratedType(final String pkgName, final String name) { + private static GeneratedType createGeneratedType(String pkgName, String name) { GeneratedTypeBuilder builder = new GeneratedTypeBuilderImpl(pkgName, name); builder.addImplementsType(BindingTypes.DATA_OBJECT); return builder.toInstance(); diff --git a/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/test/NestedGroupingCompilationTest.java b/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/test/NestedGroupingCompilationTest.java index d2fb5a8d50..6829d5a200 100644 --- a/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/test/NestedGroupingCompilationTest.java +++ b/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/test/NestedGroupingCompilationTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2016 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, @@ -76,7 +76,7 @@ public class NestedGroupingCompilationTest extends BaseCompilationTest { private void generateTestSources(final String resourceDirPath, final File sourcesOutputDir) throws Exception { final List sourceFiles = getSourceFiles(resourceDirPath); - final SchemaContext context = parser.parseFiles(sourceFiles); + final SchemaContext context = RetestUtils.parseYangSources(sourceFiles); final List types = bindingGenerator.generateTypes(context); final GeneratorJavaFile generator = new GeneratorJavaFile(ImmutableSet.copyOf(types)); generator.generateToFile(sourcesOutputDir); diff --git a/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/stmt/parser/retest/RetestUtils.java b/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/test/RetestUtils.java similarity index 85% rename from binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/stmt/parser/retest/RetestUtils.java rename to binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/test/RetestUtils.java index 1fd86c07cd..4d0b68b3c4 100644 --- a/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/stmt/parser/retest/RetestUtils.java +++ b/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/test/RetestUtils.java @@ -1,4 +1,12 @@ -package org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest; +/* + * Copyright (c) 2016 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.yangtools.sal.java.api.generator.test; import java.util.List; diff --git a/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/test/TypedefCompilationTest.java b/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/test/TypedefCompilationTest.java index 57e94f4fba..5fdcc027cf 100644 --- a/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/test/TypedefCompilationTest.java +++ b/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/test/TypedefCompilationTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2016 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, @@ -10,21 +10,10 @@ package org.opendaylight.yangtools.sal.java.api.generator.test; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.BASE_PKG; -import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.COMPILER_OUTPUT_PATH; -import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.FS; -import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.GENERATOR_OUTPUT_PATH; -import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.NS_FOO; -import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.assertContainsConstructor; -import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.assertContainsDefaultMethods; -import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.assertContainsField; import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.assertContainsFieldWithValue; import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.assertContainsMethod; import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.assertContainsRestrictionCheck; -import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.assertFilesCount; -import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.cleanUp; -import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.getSourceFiles; -import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.testCompilation; + import com.google.common.collect.ImmutableSet; import com.google.common.collect.Range; import java.io.File; @@ -52,18 +41,18 @@ public class TypedefCompilationTest extends BaseCompilationTest { @Test public void test() throws Exception { - final File sourcesOutputDir = new File(GENERATOR_OUTPUT_PATH + FS + "typedef"); + final File sourcesOutputDir = new File(CompilationTestUtils.GENERATOR_OUTPUT_PATH + CompilationTestUtils.FS + "typedef"); assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir()); - final File compiledOutputDir = new File(COMPILER_OUTPUT_PATH + FS + "typedef"); + final File compiledOutputDir = new File(CompilationTestUtils.COMPILER_OUTPUT_PATH + CompilationTestUtils.FS + "typedef"); assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir()); - final List sourceFiles = getSourceFiles("/compilation/typedef"); - final SchemaContext context = parser.parseFiles(sourceFiles); + final List sourceFiles = CompilationTestUtils.getSourceFiles("/compilation/typedef"); + final SchemaContext context = RetestUtils.parseYangSources(sourceFiles); final List types = bindingGenerator.generateTypes(context); final GeneratorJavaFile generator = new GeneratorJavaFile(ImmutableSet.copyOf(types)); generator.generateToFile(sourcesOutputDir); - File parent = new File(sourcesOutputDir, NS_FOO); + File parent = new File(sourcesOutputDir, CompilationTestUtils.NS_FOO); File bitsExt = new File(parent, "BitsExt.java"); File int32Ext0 = new File(parent, "Int32Ext0.java"); File int32Ext1 = new File(parent, "Int32Ext1.java"); @@ -88,12 +77,12 @@ public class TypedefCompilationTest extends BaseCompilationTest { assertTrue(unionExt2.exists()); assertTrue(unionExt3.exists()); assertTrue(unionExt4.exists()); - assertFilesCount(parent, 33); + CompilationTestUtils.assertFilesCount(parent, 33); // Test if sources are compilable - testCompilation(sourcesOutputDir, compiledOutputDir); + CompilationTestUtils.testCompilation(sourcesOutputDir, compiledOutputDir); - String pkg = BASE_PKG + ".urn.opendaylight.foo.rev131008"; + String pkg = CompilationTestUtils.BASE_PKG + ".urn.opendaylight.foo.rev131008"; ClassLoader loader = new URLClassLoader(new URL[] { compiledOutputDir.toURI().toURL() }); Class bitsExtClass = Class.forName(pkg + ".BitsExt", true, loader); Class int32Ext1Class = Class.forName(pkg + ".Int32Ext1", true, loader); @@ -110,23 +99,23 @@ public class TypedefCompilationTest extends BaseCompilationTest { // typedef bits-ext assertFalse(bitsExtClass.isInterface()); - assertContainsField(bitsExtClass, "_pc", Boolean.class); - assertContainsField(bitsExtClass, "_bpc", Boolean.class); - assertContainsField(bitsExtClass, "_dpc", Boolean.class); - assertContainsField(bitsExtClass, "_lbpc", Boolean.class); - assertContainsField(bitsExtClass, "_spc", Boolean.class); - assertContainsField(bitsExtClass, "_sfmof", Boolean.class); - assertContainsField(bitsExtClass, "_sfapc", Boolean.class); - assertContainsFieldWithValue(bitsExtClass, "serialVersionUID", Long.TYPE, -2922917845344851623L, Boolean.class, + CompilationTestUtils.assertContainsField(bitsExtClass, "_pc", Boolean.class); + CompilationTestUtils.assertContainsField(bitsExtClass, "_bpc", Boolean.class); + CompilationTestUtils.assertContainsField(bitsExtClass, "_dpc", Boolean.class); + CompilationTestUtils.assertContainsField(bitsExtClass, "_lbpc", Boolean.class); + CompilationTestUtils.assertContainsField(bitsExtClass, "_spc", Boolean.class); + CompilationTestUtils.assertContainsField(bitsExtClass, "_sfmof", Boolean.class); + CompilationTestUtils.assertContainsField(bitsExtClass, "_sfapc", Boolean.class); + CompilationTestUtils.assertContainsFieldWithValue(bitsExtClass, "serialVersionUID", Long.TYPE, -2922917845344851623L, Boolean.class, Boolean.class, Boolean.class, Boolean.class, Boolean.class, Boolean.class, Boolean.class); // assertEquals(8, bitsExtClass.getDeclaredFields()); - Constructor expectedConstructor = assertContainsConstructor(bitsExtClass, Boolean.class, Boolean.class, + Constructor expectedConstructor = CompilationTestUtils.assertContainsConstructor(bitsExtClass, Boolean.class, Boolean.class, Boolean.class, Boolean.class, Boolean.class, Boolean.class, Boolean.class); - assertContainsConstructor(bitsExtClass, bitsExtClass); + CompilationTestUtils.assertContainsConstructor(bitsExtClass, bitsExtClass); assertEquals(2, bitsExtClass.getConstructors().length); - Method defInst = assertContainsMethod(bitsExtClass, bitsExtClass, "getDefaultInstance", String.class); - assertContainsDefaultMethods(bitsExtClass); + Method defInst = CompilationTestUtils.assertContainsMethod(bitsExtClass, bitsExtClass, "getDefaultInstance", String.class); + CompilationTestUtils.assertContainsDefaultMethods(bitsExtClass); // assertEquals(11, bitsExtClass.getDeclaredMethods().length); Object obj = expectedConstructor.newInstance(null, null, null, null, null, new Boolean("true"), null); @@ -134,37 +123,37 @@ public class TypedefCompilationTest extends BaseCompilationTest { // typedef int32-ext1 assertFalse(int32Ext1Class.isInterface()); - assertContainsField(int32Ext1Class, VAL, Integer.class); - assertContainsFieldWithValue(int32Ext1Class, "serialVersionUID", Long.TYPE, 5351634010010233292L, Integer.class); + CompilationTestUtils.assertContainsField(int32Ext1Class, VAL, Integer.class); + CompilationTestUtils.assertContainsFieldWithValue(int32Ext1Class, "serialVersionUID", Long.TYPE, 5351634010010233292L, Integer.class); // assertEquals(3, int32Ext1Class.getDeclaredFields().length); - expectedConstructor = assertContainsConstructor(int32Ext1Class, Integer.class); - assertContainsConstructor(int32Ext1Class, int32Ext1Class); + expectedConstructor = CompilationTestUtils.assertContainsConstructor(int32Ext1Class, Integer.class); + CompilationTestUtils.assertContainsConstructor(int32Ext1Class, int32Ext1Class); assertEquals(2, int32Ext1Class.getConstructors().length); - assertContainsDefaultMethods(int32Ext1Class); - assertContainsMethod(int32Ext1Class, Integer.class, GET_VAL); - defInst = assertContainsMethod(int32Ext1Class, int32Ext1Class, "getDefaultInstance", String.class); + CompilationTestUtils.assertContainsDefaultMethods(int32Ext1Class); + CompilationTestUtils.assertContainsMethod(int32Ext1Class, Integer.class, GET_VAL); + defInst = CompilationTestUtils.assertContainsMethod(int32Ext1Class, int32Ext1Class, "getDefaultInstance", String.class); // assertEquals(6, int32Ext1Class.getDeclaredMethods().length); List> rangeConstraints = new ArrayList<>(); rangeConstraints.add(Range.closed(new Integer("2"), new Integer("2147483647"))); Object arg = new Integer("1"); String expectedMsg = String.format("Invalid range: %s, expected: %s.", arg, rangeConstraints); - assertContainsRestrictionCheck(expectedConstructor, expectedMsg, arg); + CompilationTestUtils.assertContainsRestrictionCheck(expectedConstructor, expectedMsg, arg); obj = expectedConstructor.newInstance(new Integer("159")); assertEquals(obj, defInst.invoke(null, "159")); // typedef int32-ext2 assertFalse(int32Ext2Class.isInterface()); - assertContainsFieldWithValue(int32Ext2Class, UNITS, String.class, "mile", Integer.class); - assertContainsFieldWithValue(int32Ext2Class, "serialVersionUID", Long.TYPE, 317831889060130988L, Integer.class); + CompilationTestUtils.assertContainsFieldWithValue(int32Ext2Class, UNITS, String.class, "mile", Integer.class); + CompilationTestUtils.assertContainsFieldWithValue(int32Ext2Class, "serialVersionUID", Long.TYPE, 317831889060130988L, Integer.class); // assertEquals(3, int32Ext2Class.getDeclaredFields().length); - expectedConstructor = assertContainsConstructor(int32Ext2Class, Integer.class); - assertContainsConstructor(int32Ext2Class, int32Ext2Class); - assertContainsConstructor(int32Ext2Class, int32Ext1Class); + expectedConstructor = CompilationTestUtils.assertContainsConstructor(int32Ext2Class, Integer.class); + CompilationTestUtils.assertContainsConstructor(int32Ext2Class, int32Ext2Class); + CompilationTestUtils.assertContainsConstructor(int32Ext2Class, int32Ext1Class); assertEquals(3, int32Ext2Class.getDeclaredConstructors().length); - assertContainsMethod(int32Ext2Class, String.class, "toString"); - defInst = assertContainsMethod(int32Ext2Class, int32Ext2Class, "getDefaultInstance", String.class); + CompilationTestUtils.assertContainsMethod(int32Ext2Class, String.class, "toString"); + defInst = CompilationTestUtils.assertContainsMethod(int32Ext2Class, int32Ext2Class, "getDefaultInstance", String.class); // assertEquals(3, int32Ext2Class.getDeclaredMethods().length); rangeConstraints.clear(); @@ -172,63 +161,63 @@ public class TypedefCompilationTest extends BaseCompilationTest { rangeConstraints.add(Range.closed(new Integer("11"), new Integer("2147483647"))); arg = new Integer("10"); expectedMsg = String.format("Invalid range: %s, expected: %s.", arg, rangeConstraints); - assertContainsRestrictionCheck(expectedConstructor, expectedMsg, arg); + CompilationTestUtils.assertContainsRestrictionCheck(expectedConstructor, expectedMsg, arg); obj = expectedConstructor.newInstance(new Integer("2147483647")); assertEquals(obj, defInst.invoke(null, "2147483647")); // typedef string-ext1 assertFalse(stringExt1Class.isInterface()); - assertContainsField(stringExt1Class, VAL, String.class); - assertContainsField(stringExt1Class, "patterns", Pattern[].class); - assertContainsField(stringExt1Class, "PATTERN_CONSTANTS", List.class); - assertContainsFieldWithValue(stringExt1Class, "serialVersionUID", Long.TYPE, 6943827552297110991L, String.class); + CompilationTestUtils.assertContainsField(stringExt1Class, VAL, String.class); + CompilationTestUtils.assertContainsField(stringExt1Class, "patterns", Pattern[].class); + CompilationTestUtils.assertContainsField(stringExt1Class, "PATTERN_CONSTANTS", List.class); + CompilationTestUtils.assertContainsFieldWithValue(stringExt1Class, "serialVersionUID", Long.TYPE, 6943827552297110991L, String.class); // assertEquals(5, stringExt1Class.getDeclaredFields().length); - expectedConstructor = assertContainsConstructor(stringExt1Class, String.class); - assertContainsConstructor(stringExt1Class, stringExt1Class); + expectedConstructor = CompilationTestUtils.assertContainsConstructor(stringExt1Class, String.class); + CompilationTestUtils.assertContainsConstructor(stringExt1Class, stringExt1Class); assertEquals(2, stringExt1Class.getDeclaredConstructors().length); - assertContainsMethod(stringExt1Class, String.class, GET_VAL); - defInst = assertContainsMethod(stringExt1Class, stringExt1Class, "getDefaultInstance", String.class); - assertContainsDefaultMethods(stringExt1Class); + CompilationTestUtils.assertContainsMethod(stringExt1Class, String.class, GET_VAL); + defInst = CompilationTestUtils.assertContainsMethod(stringExt1Class, stringExt1Class, "getDefaultInstance", String.class); + CompilationTestUtils.assertContainsDefaultMethods(stringExt1Class); // assertEquals(6, stringExt1Class.getDeclaredMethods().length); List> lengthConstraints = new ArrayList<>(); lengthConstraints.add(Range.closed(5, 11)); arg = "abcd"; expectedMsg = String.format("Invalid length: %s, expected: %s.", arg, lengthConstraints); - assertContainsRestrictionCheck(expectedConstructor, expectedMsg, arg); + CompilationTestUtils.assertContainsRestrictionCheck(expectedConstructor, expectedMsg, arg); obj = expectedConstructor.newInstance("abcde"); assertEquals(obj, defInst.invoke(null, "abcde")); // typedef string-ext2 assertFalse(stringExt2Class.isInterface()); - assertContainsFieldWithValue(stringExt2Class, "serialVersionUID", Long.TYPE, 8100233177432072092L, String.class); + CompilationTestUtils.assertContainsFieldWithValue(stringExt2Class, "serialVersionUID", Long.TYPE, 8100233177432072092L, String.class); // assertEquals(2, stringExt2Class.getDeclaredFields().length); - expectedConstructor = assertContainsConstructor(stringExt2Class, String.class); - assertContainsConstructor(stringExt2Class, stringExt2Class); - assertContainsConstructor(stringExt2Class, stringExt1Class); + expectedConstructor = CompilationTestUtils.assertContainsConstructor(stringExt2Class, String.class); + CompilationTestUtils.assertContainsConstructor(stringExt2Class, stringExt2Class); + CompilationTestUtils.assertContainsConstructor(stringExt2Class, stringExt1Class); assertEquals(3, stringExt2Class.getDeclaredConstructors().length); - defInst = assertContainsMethod(stringExt2Class, stringExt2Class, "getDefaultInstance", String.class); + defInst = CompilationTestUtils.assertContainsMethod(stringExt2Class, stringExt2Class, "getDefaultInstance", String.class); // assertEquals(2, stringExt2Class.getDeclaredMethods().length); lengthConstraints.clear(); lengthConstraints.add(Range.closed(6, 10)); arg = "abcde"; expectedMsg = String.format("Invalid length: %s, expected: %s.", arg, lengthConstraints); - assertContainsRestrictionCheck(expectedConstructor, expectedMsg, arg); + CompilationTestUtils.assertContainsRestrictionCheck(expectedConstructor, expectedMsg, arg); obj = expectedConstructor.newInstance("abcdef"); assertEquals(obj, defInst.invoke(null, "abcdef")); // typedef string-ext3 assertFalse(stringExt3Class.isInterface()); - assertContainsFieldWithValue(stringExt3Class, "serialVersionUID", Long.TYPE, -2751063130555484180L, + CompilationTestUtils.assertContainsFieldWithValue(stringExt3Class, "serialVersionUID", Long.TYPE, -2751063130555484180L, String.class); // assertEquals(1, stringExt3Class.getDeclaredFields().length); - expectedConstructor = assertContainsConstructor(stringExt3Class, String.class); - assertContainsConstructor(stringExt3Class, stringExt3Class); - assertContainsConstructor(stringExt3Class, stringExt2Class); + expectedConstructor = CompilationTestUtils.assertContainsConstructor(stringExt3Class, String.class); + CompilationTestUtils.assertContainsConstructor(stringExt3Class, stringExt3Class); + CompilationTestUtils.assertContainsConstructor(stringExt3Class, stringExt2Class); assertEquals(3, stringExt3Class.getDeclaredConstructors().length); - defInst = assertContainsMethod(stringExt3Class, stringExt3Class, "getDefaultInstance", String.class); + defInst = CompilationTestUtils.assertContainsMethod(stringExt3Class, stringExt3Class, "getDefaultInstance", String.class); // assertEquals(1, stringExt3Class.getDeclaredMethods().length); obj = expectedConstructor.newInstance("bbbbbb"); @@ -236,114 +225,114 @@ public class TypedefCompilationTest extends BaseCompilationTest { // typedef my-decimal-type assertFalse(myDecimalTypeClass.isInterface()); - assertContainsField(myDecimalTypeClass, VAL, BigDecimal.class); - assertContainsFieldWithValue(myDecimalTypeClass, "serialVersionUID", Long.TYPE, 3143735729419861095L, + CompilationTestUtils.assertContainsField(myDecimalTypeClass, VAL, BigDecimal.class); + CompilationTestUtils.assertContainsFieldWithValue(myDecimalTypeClass, "serialVersionUID", Long.TYPE, 3143735729419861095L, BigDecimal.class); // assertEquals(3, myDecimalTypeClass.getDeclaredFields().length); - assertContainsMethod(myDecimalTypeClass, BigDecimal.class, "getValue"); - expectedConstructor = assertContainsConstructor(myDecimalTypeClass, BigDecimal.class); - assertContainsConstructor(myDecimalTypeClass, myDecimalTypeClass); + CompilationTestUtils.assertContainsMethod(myDecimalTypeClass, BigDecimal.class, "getValue"); + expectedConstructor = CompilationTestUtils.assertContainsConstructor(myDecimalTypeClass, BigDecimal.class); + CompilationTestUtils.assertContainsConstructor(myDecimalTypeClass, myDecimalTypeClass); assertEquals(2, myDecimalTypeClass.getDeclaredConstructors().length); - assertContainsMethod(myDecimalTypeClass, BigDecimal.class, GET_VAL); - assertContainsDefaultMethods(myDecimalTypeClass); - defInst = assertContainsMethod(myDecimalTypeClass, myDecimalTypeClass, "getDefaultInstance", String.class); + CompilationTestUtils.assertContainsMethod(myDecimalTypeClass, BigDecimal.class, GET_VAL); + CompilationTestUtils.assertContainsDefaultMethods(myDecimalTypeClass); + defInst = CompilationTestUtils.assertContainsMethod(myDecimalTypeClass, myDecimalTypeClass, "getDefaultInstance", String.class); // assertEquals(6, myDecimalTypeClass.getDeclaredMethods().length); List> decimalRangeConstraints = new ArrayList<>(); decimalRangeConstraints.add(Range.closed(new BigDecimal("1.5"), new BigDecimal("5.5"))); arg = new BigDecimal("1.4"); expectedMsg = String.format("Invalid range: %s, expected: %s.", arg, decimalRangeConstraints); - assertContainsRestrictionCheck(expectedConstructor, expectedMsg, arg); + CompilationTestUtils.assertContainsRestrictionCheck(expectedConstructor, expectedMsg, arg); obj = expectedConstructor.newInstance(new BigDecimal("3.14")); assertEquals(obj, defInst.invoke(null, "3.14")); // typedef my-decimal-type2 assertFalse(myDecimalType2Class.isInterface()); - assertContainsField(myDecimalType2Class, VAL, BigDecimal.class); - assertContainsFieldWithValue(myDecimalType2Class, "serialVersionUID", Long.TYPE, -672265764962082714L, BigDecimal.class); + CompilationTestUtils.assertContainsField(myDecimalType2Class, VAL, BigDecimal.class); + CompilationTestUtils.assertContainsFieldWithValue(myDecimalType2Class, "serialVersionUID", Long.TYPE, -672265764962082714L, BigDecimal.class); // assertEquals(3, myDecimalType2Class.getDeclaredFields().length); - assertContainsMethod(myDecimalType2Class, BigDecimal.class, "getValue"); - expectedConstructor = assertContainsConstructor(myDecimalType2Class, BigDecimal.class); - assertContainsConstructor(myDecimalType2Class, myDecimalType2Class); + CompilationTestUtils.assertContainsMethod(myDecimalType2Class, BigDecimal.class, "getValue"); + expectedConstructor = CompilationTestUtils.assertContainsConstructor(myDecimalType2Class, BigDecimal.class); + CompilationTestUtils.assertContainsConstructor(myDecimalType2Class, myDecimalType2Class); assertEquals(2, myDecimalType2Class.getDeclaredConstructors().length); - assertContainsMethod(myDecimalType2Class, BigDecimal.class, GET_VAL); - assertContainsDefaultMethods(myDecimalType2Class); - defInst = assertContainsMethod(myDecimalType2Class, myDecimalType2Class, "getDefaultInstance", String.class); + CompilationTestUtils.assertContainsMethod(myDecimalType2Class, BigDecimal.class, GET_VAL); + CompilationTestUtils.assertContainsDefaultMethods(myDecimalType2Class); + defInst = CompilationTestUtils.assertContainsMethod(myDecimalType2Class, myDecimalType2Class, "getDefaultInstance", String.class); // assertEquals(6, myDecimalType2Class.getDeclaredMethods().length); List> decimal2RangeConstraints = new ArrayList<>(); decimal2RangeConstraints.add(Range.closed(new BigDecimal("0"), new BigDecimal("1"))); arg = new BigDecimal("1.4"); expectedMsg = String.format("Invalid range: %s, expected: %s.", arg, decimal2RangeConstraints); - assertContainsRestrictionCheck(expectedConstructor, expectedMsg, arg); + CompilationTestUtils.assertContainsRestrictionCheck(expectedConstructor, expectedMsg, arg); obj = expectedConstructor.newInstance(new BigDecimal("0.14")); assertEquals(obj, defInst.invoke(null, "0.14")); // typedef union-ext1 assertFalse(unionExt1Class.isInterface()); - assertContainsField(unionExt1Class, "_int16", Short.class); - assertContainsField(unionExt1Class, "_int32", Integer.class); - assertContainsFieldWithValue(unionExt1Class, "serialVersionUID", Long.TYPE, -5610530488718168882L, + CompilationTestUtils.assertContainsField(unionExt1Class, "_int16", Short.class); + CompilationTestUtils.assertContainsField(unionExt1Class, "_int32", Integer.class); + CompilationTestUtils.assertContainsFieldWithValue(unionExt1Class, "serialVersionUID", Long.TYPE, -5610530488718168882L, new Class[] { Short.class }, Short.valueOf("1")); // assertEquals(4, unionExt1Class.getDeclaredFields().length); - assertContainsMethod(unionExt1Class, Short.class, "getInt16"); - assertContainsMethod(unionExt1Class, Integer.class, "getInt32"); - assertContainsConstructor(unionExt1Class, Short.class); - assertContainsConstructor(unionExt1Class, Integer.class); - assertContainsConstructor(unionExt1Class, unionExt1Class); + CompilationTestUtils.assertContainsMethod(unionExt1Class, Short.class, "getInt16"); + CompilationTestUtils.assertContainsMethod(unionExt1Class, Integer.class, "getInt32"); + CompilationTestUtils.assertContainsConstructor(unionExt1Class, Short.class); + CompilationTestUtils.assertContainsConstructor(unionExt1Class, Integer.class); + CompilationTestUtils.assertContainsConstructor(unionExt1Class, unionExt1Class); assertEquals(4, unionExt1Class.getDeclaredConstructors().length); - assertContainsDefaultMethods(unionExt1Class); + CompilationTestUtils.assertContainsDefaultMethods(unionExt1Class); // typedef union-ext2 assertFalse(unionExt2Class.isInterface()); - assertContainsFieldWithValue(unionExt2Class, "serialVersionUID", Long.TYPE, -8833407459073585206L, + CompilationTestUtils.assertContainsFieldWithValue(unionExt2Class, "serialVersionUID", Long.TYPE, -8833407459073585206L, new Class[] { Short.class }, Short.valueOf("1")); // assertEquals(1, unionExt2Class.getDeclaredFields().length); // assertEquals(0, unionExt2Class.getDeclaredMethods().length); - assertContainsConstructor(unionExt2Class, Short.class); - assertContainsConstructor(unionExt2Class, Integer.class); - assertContainsConstructor(unionExt2Class, unionExt2Class); - assertContainsConstructor(unionExt2Class, unionExt1Class); + CompilationTestUtils.assertContainsConstructor(unionExt2Class, Short.class); + CompilationTestUtils.assertContainsConstructor(unionExt2Class, Integer.class); + CompilationTestUtils.assertContainsConstructor(unionExt2Class, unionExt2Class); + CompilationTestUtils.assertContainsConstructor(unionExt2Class, unionExt1Class); assertEquals(5, unionExt2Class.getDeclaredConstructors().length); // typedef union-ext3 assertFalse(unionExt3Class.isInterface()); - assertContainsField(unionExt3Class, "_string", String.class); - assertContainsField(unionExt3Class, "_unionExt2", unionExt2Class); - assertContainsFieldWithValue(unionExt3Class, UNITS, String.class, "object id", new Class[] { String.class }, + CompilationTestUtils.assertContainsField(unionExt3Class, "_string", String.class); + CompilationTestUtils.assertContainsField(unionExt3Class, "_unionExt2", unionExt2Class); + CompilationTestUtils.assertContainsFieldWithValue(unionExt3Class, UNITS, String.class, "object id", new Class[] { String.class }, ""); - assertContainsFieldWithValue(unionExt3Class, "serialVersionUID", Long.TYPE, 4347887914884631036L, + CompilationTestUtils.assertContainsFieldWithValue(unionExt3Class, "serialVersionUID", Long.TYPE, 4347887914884631036L, new Class[] { String.class }, ""); // assertEquals(5, unionExt3Class.getDeclaredFields().length); - assertContainsMethod(unionExt3Class, String.class, "getString"); - assertContainsMethod(unionExt3Class, unionExt2Class, "getUnionExt2"); - assertContainsConstructor(unionExt3Class, String.class); - assertContainsConstructor(unionExt3Class, unionExt2Class); - assertContainsConstructor(unionExt3Class, unionExt3Class); + CompilationTestUtils.assertContainsMethod(unionExt3Class, String.class, "getString"); + CompilationTestUtils.assertContainsMethod(unionExt3Class, unionExt2Class, "getUnionExt2"); + CompilationTestUtils.assertContainsConstructor(unionExt3Class, String.class); + CompilationTestUtils.assertContainsConstructor(unionExt3Class, unionExt2Class); + CompilationTestUtils.assertContainsConstructor(unionExt3Class, unionExt3Class); assertEquals(4, unionExt3Class.getDeclaredConstructors().length); - assertContainsDefaultMethods(unionExt3Class); + CompilationTestUtils.assertContainsDefaultMethods(unionExt3Class); // typedef union-ext4 assertFalse(unionExt4Class.isInterface()); - assertContainsField(unionExt4Class, "_unionExt3", unionExt3Class); - assertContainsField(unionExt4Class, "_int32Ext2", int32Ext2Class); - assertContainsField(unionExt4Class, "_empty", Boolean.class); - assertContainsField(unionExt4Class, "_myDecimalType", myDecimalTypeClass); - assertContainsFieldWithValue(unionExt4Class, "serialVersionUID", Long.TYPE, 4299836385615211130L, + CompilationTestUtils.assertContainsField(unionExt4Class, "_unionExt3", unionExt3Class); + CompilationTestUtils.assertContainsField(unionExt4Class, "_int32Ext2", int32Ext2Class); + CompilationTestUtils.assertContainsField(unionExt4Class, "_empty", Boolean.class); + CompilationTestUtils.assertContainsField(unionExt4Class, "_myDecimalType", myDecimalTypeClass); + CompilationTestUtils.assertContainsFieldWithValue(unionExt4Class, "serialVersionUID", Long.TYPE, 4299836385615211130L, new Class[] { Boolean.class }, false); // assertEquals(6, unionExt4Class.getDeclaredFields().length); - assertContainsMethod(unionExt4Class, unionExt3Class, "getUnionExt3"); - assertContainsMethod(unionExt4Class, int32Ext2Class, "getInt32Ext2"); - assertContainsMethod(unionExt4Class, Boolean.class, "isEmpty"); - assertContainsMethod(unionExt4Class, myDecimalTypeClass, "getMyDecimalType"); - assertContainsConstructor(unionExt4Class, unionExt3Class); - assertContainsConstructor(unionExt4Class, int32Ext2Class); - assertContainsConstructor(unionExt4Class, Boolean.class); - assertContainsConstructor(unionExt4Class, myDecimalTypeClass); - assertContainsConstructor(unionExt4Class, unionExt4Class); + CompilationTestUtils.assertContainsMethod(unionExt4Class, unionExt3Class, "getUnionExt3"); + CompilationTestUtils.assertContainsMethod(unionExt4Class, int32Ext2Class, "getInt32Ext2"); + CompilationTestUtils.assertContainsMethod(unionExt4Class, Boolean.class, "isEmpty"); + CompilationTestUtils.assertContainsMethod(unionExt4Class, myDecimalTypeClass, "getMyDecimalType"); + CompilationTestUtils.assertContainsConstructor(unionExt4Class, unionExt3Class); + CompilationTestUtils.assertContainsConstructor(unionExt4Class, int32Ext2Class); + CompilationTestUtils.assertContainsConstructor(unionExt4Class, Boolean.class); + CompilationTestUtils.assertContainsConstructor(unionExt4Class, myDecimalTypeClass); + CompilationTestUtils.assertContainsConstructor(unionExt4Class, unionExt4Class); assertEquals(6, unionExt4Class.getDeclaredConstructors().length); - assertContainsDefaultMethods(unionExt4Class); + CompilationTestUtils.assertContainsDefaultMethods(unionExt4Class); - cleanUp(sourcesOutputDir, compiledOutputDir); + CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir); } } diff --git a/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/test/UnionTypedefUnusedImportTest.java b/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/test/UnionTypedefUnusedImportTest.java index ffe2c80fba..4b15c2209a 100644 --- a/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/test/UnionTypedefUnusedImportTest.java +++ b/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/test/UnionTypedefUnusedImportTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2016 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, @@ -39,7 +39,7 @@ public class UnionTypedefUnusedImportTest extends BaseCompilationTest { assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir()); final List sourceFiles = getSourceFiles("/compilation/union-typedef"); - final SchemaContext context = parser.parseFiles(sourceFiles); + final SchemaContext context = RetestUtils.parseYangSources(sourceFiles); final List types = bindingGenerator.generateTypes(context); final GeneratorJavaFile generator = new GeneratorJavaFile(new HashSet<>(types)); generator.generateToFile(sourcesOutputDir); diff --git a/dom/mdsal-dom-broker/src/test/java/org/opendaylight/mdsal/dom/broker/test/DOMBrokerTest.java b/dom/mdsal-dom-broker/src/test/java/org/opendaylight/mdsal/dom/broker/test/DOMBrokerTest.java index eb70b7ec61..9ed475c51a 100644 --- a/dom/mdsal-dom-broker/src/test/java/org/opendaylight/mdsal/dom/broker/test/DOMBrokerTest.java +++ b/dom/mdsal-dom-broker/src/test/java/org/opendaylight/mdsal/dom/broker/test/DOMBrokerTest.java @@ -58,7 +58,7 @@ public class DOMBrokerTest { private CommitExecutorService commitExecutor; @Before - public void setupStore() { + public void setupStore() throws Exception{ InMemoryDOMDataStore operStore = new InMemoryDOMDataStore("OPER", MoreExecutors.newDirectExecutorService()); diff --git a/dom/mdsal-dom-broker/src/test/java/org/opendaylight/mdsal/dom/broker/test/DOMDataTreeListenerTest.java b/dom/mdsal-dom-broker/src/test/java/org/opendaylight/mdsal/dom/broker/test/DOMDataTreeListenerTest.java index ef57b2fd16..71575ef5d7 100644 --- a/dom/mdsal-dom-broker/src/test/java/org/opendaylight/mdsal/dom/broker/test/DOMDataTreeListenerTest.java +++ b/dom/mdsal-dom-broker/src/test/java/org/opendaylight/mdsal/dom/broker/test/DOMDataTreeListenerTest.java @@ -91,7 +91,7 @@ public class DOMDataTreeListenerTest { LogicalDatastoreType.CONFIGURATION, TestModel.OUTER_LIST_PATH); @Before - public void setupStore() { + public void setupStore() throws Exception{ InMemoryDOMDataStore operStore = new InMemoryDOMDataStore("OPER", MoreExecutors.newDirectExecutorService()); InMemoryDOMDataStore configStore = new InMemoryDOMDataStore("CFG", diff --git a/dom/mdsal-dom-broker/src/test/java/org/opendaylight/mdsal/dom/broker/test/DOMTransactionChainTest.java b/dom/mdsal-dom-broker/src/test/java/org/opendaylight/mdsal/dom/broker/test/DOMTransactionChainTest.java index d13285ee25..87465addb9 100644 --- a/dom/mdsal-dom-broker/src/test/java/org/opendaylight/mdsal/dom/broker/test/DOMTransactionChainTest.java +++ b/dom/mdsal-dom-broker/src/test/java/org/opendaylight/mdsal/dom/broker/test/DOMTransactionChainTest.java @@ -46,7 +46,7 @@ public class DOMTransactionChainTest { private AbstractDOMDataBroker domBroker; @Before - public void setupStore() { + public void setupStore() throws Exception{ InMemoryDOMDataStore operStore = new InMemoryDOMDataStore("OPER", MoreExecutors.newDirectExecutorService()); InMemoryDOMDataStore configStore = new InMemoryDOMDataStore("CFG", MoreExecutors.newDirectExecutorService()); schemaContext = TestModel.createTestContext(); diff --git a/dom/mdsal-dom-broker/src/test/java/org/opendaylight/mdsal/dom/broker/test/ShardedDOMDataTreeProducerMultiShardTest.java b/dom/mdsal-dom-broker/src/test/java/org/opendaylight/mdsal/dom/broker/test/ShardedDOMDataTreeProducerMultiShardTest.java index bd18ac0f84..f8d4b249d1 100644 --- a/dom/mdsal-dom-broker/src/test/java/org/opendaylight/mdsal/dom/broker/test/ShardedDOMDataTreeProducerMultiShardTest.java +++ b/dom/mdsal-dom-broker/src/test/java/org/opendaylight/mdsal/dom/broker/test/ShardedDOMDataTreeProducerMultiShardTest.java @@ -31,10 +31,11 @@ import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContaine import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder; import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafNodeBuilder; import org.opendaylight.yangtools.yang.model.api.SchemaContext; +import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; public class ShardedDOMDataTreeProducerMultiShardTest { - private final SchemaContext schemaContext = TestModel.createTestContext(); + private SchemaContext schemaContext; private static final DOMDataTreeIdentifier ROOT_ID = new DOMDataTreeIdentifier(LogicalDatastoreType.OPERATIONAL, YangInstanceIdentifier.EMPTY); @@ -58,6 +59,7 @@ public class ShardedDOMDataTreeProducerMultiShardTest { @Before public void setUp() throws Exception { + schemaContext = TestModel.createTestContext(); rootShard = InMemoryDOMDataTreeShard.create(ROOT_ID); rootShard.onGlobalContextUpdated(schemaContext); diff --git a/dom/mdsal-dom-broker/src/test/java/org/opendaylight/mdsal/dom/broker/test/util/TestModel.java b/dom/mdsal-dom-broker/src/test/java/org/opendaylight/mdsal/dom/broker/test/util/TestModel.java index 182c0fd06c..ced72a18a1 100644 --- a/dom/mdsal-dom-broker/src/test/java/org/opendaylight/mdsal/dom/broker/test/util/TestModel.java +++ b/dom/mdsal-dom-broker/src/test/java/org/opendaylight/mdsal/dom/broker/test/util/TestModel.java @@ -9,12 +9,17 @@ package org.opendaylight.mdsal.dom.broker.test.util; import java.io.InputStream; import java.util.Collections; +import java.util.List; import java.util.Set; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl; +import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; +import org.opendaylight.yangtools.yang.parser.spi.source.SourceException; +import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor; +import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline; public class TestModel { @@ -55,9 +60,15 @@ public class TestModel { return TestModel.class.getResourceAsStream(DATASTORE_TEST_YANG); } - public static SchemaContext createTestContext() { - YangParserImpl parser = new YangParserImpl(); - Set modules = parser.parseYangModelsFromStreams(Collections.singletonList(getDatastoreTestInputStream())); - return parser.resolveSchemaContext(modules); + public static SchemaContext createTestContext() throws ReactorException { + return parseYangStreams(Collections.singletonList(getDatastoreTestInputStream())); + } + + private static SchemaContext parseYangStreams(List streams) + throws SourceException, ReactorException { + + CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR + .newBuild(); + return reactor.buildEffective(streams); } } diff --git a/dom/mdsal-dom-inmemory-datastore/src/test/java/org/opendaylight/controller/md/sal/dom/store/impl/InMemoryDataStoreTest.java b/dom/mdsal-dom-inmemory-datastore/src/test/java/org/opendaylight/controller/md/sal/dom/store/impl/InMemoryDataStoreTest.java index 753fdfa5a4..53bb7aca26 100644 --- a/dom/mdsal-dom-inmemory-datastore/src/test/java/org/opendaylight/controller/md/sal/dom/store/impl/InMemoryDataStoreTest.java +++ b/dom/mdsal-dom-inmemory-datastore/src/test/java/org/opendaylight/controller/md/sal/dom/store/impl/InMemoryDataStoreTest.java @@ -42,6 +42,7 @@ import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes; import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder; import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException; +import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; public class InMemoryDataStoreTest { @@ -49,7 +50,7 @@ public class InMemoryDataStoreTest { private InMemoryDOMDataStore domStore; @Before - public void setupStore() throws IOException, YangSyntaxErrorException { + public void setupStore() throws IOException, YangSyntaxErrorException, ReactorException { domStore = new InMemoryDOMDataStore("TEST", MoreExecutors.newDirectExecutorService()); schemaContext = TestModel.createTestContext(); domStore.onGlobalContextUpdated(schemaContext); diff --git a/dom/mdsal-dom-inmemory-datastore/src/test/java/org/opendaylight/controller/md/sal/dom/store/impl/TestModel.java b/dom/mdsal-dom-inmemory-datastore/src/test/java/org/opendaylight/controller/md/sal/dom/store/impl/TestModel.java index 6d868ee50d..097c519560 100644 --- a/dom/mdsal-dom-inmemory-datastore/src/test/java/org/opendaylight/controller/md/sal/dom/store/impl/TestModel.java +++ b/dom/mdsal-dom-inmemory-datastore/src/test/java/org/opendaylight/controller/md/sal/dom/store/impl/TestModel.java @@ -10,12 +10,18 @@ package org.opendaylight.controller.md.sal.dom.store.impl; import com.google.common.io.ByteSource; import com.google.common.io.Resources; import java.io.IOException; +import java.io.InputStream; import java.util.Collections; +import java.util.List; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException; import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl; +import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; +import org.opendaylight.yangtools.yang.parser.spi.source.SourceException; +import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor; +import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline; public class TestModel { @@ -34,12 +40,25 @@ public class TestModel { public static final QName TWO_QNAME = QName.create(TEST_QNAME, "two"); public static final QName THREE_QNAME = QName.create(TEST_QNAME, "three"); - private static ByteSource getInputStream() { - return Resources.asByteSource(TestModel.class.getResource(DATASTORE_TEST_YANG)); + // private static ByteSource getInputStream() { + // return Resources.asByteSource(TestModel.class.getResource(DATASTORE_TEST_YANG)); + // } + + private static InputStream getInputStream() { + return TestModel.class.getResourceAsStream(DATASTORE_TEST_YANG); + } + + public static SchemaContext createTestContext() throws IOException, YangSyntaxErrorException, ReactorException { + //YangParserImpl parser = new YangParserImpl(); + //return parser.parseSources(Collections.singletonList(getInputStream())); + return parseYangStreams(Collections.singletonList(getInputStream())); } - public static SchemaContext createTestContext() throws IOException, YangSyntaxErrorException { - YangParserImpl parser = new YangParserImpl(); - return parser.parseSources(Collections.singletonList(getInputStream())); + private static SchemaContext parseYangStreams(List streams) + throws SourceException, ReactorException { + + CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR + .newBuild(); + return reactor.buildEffective(streams); } } -- 2.36.6