From c3ff09884178e03dc325b75b0944fd8239319058 Mon Sep 17 00:00:00 2001 From: Igor Foltin Date: Thu, 5 May 2016 15:49:26 +0200 Subject: [PATCH] Bug 5085: Clean-up test and retest JUnit tests Migrated unit tests which used old yang parser to new yang parser. Change-Id: Ib3dae51fc083734e9b27692f12b6f5528975f4bb Signed-off-by: Igor Foltin --- .../codec/gson/{retest => }/Bug4501Test.java | 9 +- .../codec/gson/{retest => }/Bug4969Test.java | 29 +- .../gson/JsonStreamToNormalizedNodeTest.java | 5 +- .../gson/NormalizedNodeToJsonStreamTest.java | 54 +- .../gson/StreamToNormalizedNodeTest.java | 11 +- .../yang/data/codec/gson/TestUtils.java | 61 +- ...estingNormalizedNodeStructuresCreator.java | 2 +- .../YangModeledAnyXmlSupportTest.java | 12 +- .../JsonStreamToNormalizedNodeTest.java | 296 ------ .../NormalizedNodeToJsonStreamTest.java | 425 -------- .../data/codec/gson/retest/RetestUtils.java | 65 -- .../retest/StreamToNormalizedNodeTest.java | 126 --- .../data/codec/gson/retest/TestUtils.java | 106 -- ...estingNormalizedNodeStructuresCreator.java | 297 ------ .../impl/{RetestUtils.java => TestUtils.java} | 4 +- .../yang/data/impl/codec/xml/Bug2964Test.java | 52 +- .../InstanceIdentifierForXmlCodecTest.java | 4 +- .../impl/codec/xml/XmlDocumentUtilsTest.java | 4 +- .../impl/codec/xml/XmlStreamUtilsTest.java | 42 +- .../impl/codec/xml/retest/Bug2964Test.java | 101 -- .../codec/xml/retest/RandomPrefixTest.java | 90 -- .../xml/retest/XmlDocumentUtilsTest.java | 74 -- .../codec/xml/retest/XmlStreamUtilsTest.java | 223 ---- .../codecs/BinaryCodecStringTest.java | 6 +- .../codecs/BitsCodecStringTest.java | 14 +- .../codecs/BooleanCodecStringTest.java | 15 +- .../codecs/DecimalCodecStringTest.java | 17 +- .../codecs/EmptyCodecStringTest.java | 12 +- .../codecs/EnumCodecStringTest.java | 10 +- .../codecs/Int16CodecStringTest.java | 8 +- .../codecs/Int32CodecStringTest.java | 16 +- .../codecs/Int64CodecStringTest.java | 8 +- .../codecs/Int8CodecStringTest.java | 16 +- .../codecs/StringCodecStringTest.java | 9 +- .../StringPatternCheckingCodecTest.java | 8 +- .../TypeDefinitionAwareCodecTestHelper.java | 4 +- .../codecs/Uint16CodecStringTest.java | 8 +- .../codecs/Uint32CodecStringTest.java | 8 +- .../codecs/Uint64CodecStringTest.java | 16 +- .../codecs/Uint8CodecStringTest.java | 8 +- .../codecs/UnionCodecStringTest.java | 12 +- .../DataTreeCandidateValidatorTest.java | 8 +- .../DataTreeCandidateValidatorTest2.java | 8 +- .../DataTreeCandidateValidatorTest3.java | 8 +- .../{test/retest => }/LeafRefContextTest.java | 8 +- .../LeafRefContextTreeBuilderTest.java | 10 +- .../test/DataTreeCandidateValidatorTest.java | 815 --------------- .../test/DataTreeCandidateValidatorTest2.java | 361 ------- .../test/DataTreeCandidateValidatorTest3.java | 462 --------- .../context/test/LeafRefContextTest.java | 112 -- .../test/LeafRefContextTreeBuilderTest.java | 281 ----- .../impl/schema/{test => }/BuilderTest.java | 8 +- .../impl/schema/InstanceIdToNodesTest.java | 226 ++-- .../schema/NormalizedDataBuilderTest.java | 73 +- .../{test => }/NormalizedNodeUtilsTest.java | 10 +- .../schema/retest/InstanceIdToNodesTest.java | 206 ---- .../retest/NormalizedDataBuilderTest.java | 231 ----- .../DomToNormalizedNodeParserFactoryTest.java | 4 +- .../transform/dom/serializer/Bug5396.java | 4 +- .../serializer/DomSerializerTestUtils.java | 4 +- .../NormalizedNodeXmlTranslationTest.java | 218 ++-- .../YangModeledAnyXMLDeserializationTest.java | 8 +- .../YangModeledAnyXMLSerializationTest.java | 8 +- .../NormalizedNodeXmlTranslationTest.java | 401 -------- .../data/impl/schema/tree/Bug2690FixTest.java | 95 -- ...etest_Bug2690Fix.java => Bug2690Test.java} | 6 +- .../data/impl/schema/tree/Bug3674Test.java | 5 +- .../data/impl/schema/tree/Bug4295Test.java | 4 +- .../impl/schema/tree/CaseExclusionTest.java | 2 +- .../tree/ConcurrentTreeModificationTest.java | 11 +- .../tree/ConfigStatementValidationTest.java | 81 +- .../schema/tree/DataTreeTransactionTest.java | 3 +- .../impl/schema/tree/ErrorReportingTest.java | 6 +- ...on.java => ListConstraintsValidation.java} | 8 +- .../tree/ListConstraintsValidationTest.java | 301 ------ .../impl/schema/tree/MandatoryLeafTest.java | 2 +- .../tree/ModificationMetadataTreeTest.java | 5 +- .../impl/schema/tree/OrderedListTest.java | 4 +- .../data/impl/schema/tree/RetestModel.java | 50 - .../impl/schema/tree/Retest_Bug3674Test.java | 52 - ...Retest_ConcurrentTreeModificationTest.java | 636 ------------ .../Retest_ConfigStatementValidationTest.java | 168 --- .../tree/Retest_ErrorReportingTest.java | 75 -- .../Retest_ModificationMetadataTreeTest.java | 250 ----- .../tree/Retest_StoreTreeNodesTest.java | 202 ---- .../impl/schema/tree/StoreTreeNodesTest.java | 7 +- .../yang/data/impl/schema/tree/TestModel.java | 38 +- .../yangtools/yang/data/jaxen/JaxenTest.java | 7 +- .../yangtools/yang/data/jaxen/TestUtils.java | 50 +- .../builder/impl/AbstractBuilderTest.java | 87 -- .../parser/builder/impl/BuilderUtilsTest.java | 497 --------- .../parser/builder/impl/CopyUtilsTest.java | 482 --------- .../impl/LeafListSchemaNodeBuilderTest.java | 136 --- .../builder/impl/ModuleBuilderTest.java | 814 --------------- .../parser/builder/impl/RefineUtilsTest.java | 254 ----- .../impl/RpcDefinitionBuilderTest.java | 106 -- .../impl/TypeDefinitionBuilderImplTest.java | 73 -- .../yang/parser/impl/AugmentTest.java | 457 --------- .../parser/impl/AugmentToExtensionTest.java | 70 -- .../AugmentationSchemaBuilderImplTest.java | 66 -- .../yang/parser/impl/Bug1412Test.java | 90 -- .../yang/parser/impl/Bug1413Test.java | 42 - .../yang/parser/impl/Bug2291Test.java | 26 - .../yang/parser/impl/Bug3799Test.java | 58 -- .../yang/parser/impl/Bug394Test.java | 48 - .../yang/parser/impl/Bug4079Test.java | 170 ---- .../yang/parser/impl/GroupingTest.java | 585 ----------- .../yang/parser/impl/ListKeysTest.java | 60 -- .../yang/parser/impl/OrderingTest.java | 129 --- .../impl/ParsingExtensionValueTest.java | 40 - .../parser/impl/SameQNamesInChoiceTest.java | 57 -- .../yang/parser/impl/SchemaContextTest.java | 81 -- .../yangtools/yang/parser/impl/TestUtils.java | 238 ----- .../yang/parser/impl/TwoRevisionsTest.java | 24 - .../yang/parser/impl/TypesResolutionTest.java | 357 ------- .../yang/parser/impl/UsesAugmentTest.java | 651 ------------ .../impl/YangModelValidationListTest.java | 110 -- .../impl/YangModelValidationModuleTest.java | 177 ---- .../YangModelValidationSubModuleTest.java | 85 -- .../parser/impl/YangModelValidationTest.java | 272 ----- .../parser/impl/YangParserIdentityTest.java | 54 - .../parser/impl/YangParserNegativeTest.java | 258 ----- .../parser/impl/YangParserSimpleTest.java | 211 ---- .../yang/parser/impl/YangParserTest.java | 963 ------------------ .../impl/YangParserWithContextTest.java | 400 -------- .../parser/util/SchemaContextUtilTest.java | 77 +- ...t.java => AugmentArgumentParsingTest.java} | 6 +- .../stmt/{test => }/AugmentProcessTest.java | 4 +- .../stmt/{test => }/AugmentSimplestTest.java | 4 +- .../yang/stmt/{retest => }/AugmentTest.java | 4 +- .../{retest => }/AugmentToExtensionTest.java | 12 +- .../yang/stmt/{retest => }/Bug1412Test.java | 4 +- .../yang/stmt/{retest => }/Bug1413Test.java | 4 +- .../{parser/impl => stmt}/Bug2219Test.java | 4 +- .../yang/stmt/{retest => }/Bug2291Test.java | 4 +- .../yang/stmt/{test => }/Bug3799Test.java | 10 +- .../{parser/impl => stmt}/Bug3859Test.java | 4 +- .../stmt/{test => }/Bug3874ExtensionTest.java | 4 +- .../yang/stmt/{retest => }/Bug394Test.java | 4 +- .../yang/stmt/{retest => }/Bug4079Test.java | 2 +- .../{parser/impl => stmt}/Bug4231Test.java | 29 +- .../yang/stmt/{test => }/Bug4410Test.java | 4 +- .../yang/stmt/{test => }/Bug4456Test.java | 4 +- .../yang/stmt/{test => }/Bug4459Test.java | 4 +- .../yang/stmt/{test => }/Bug4610Test.java | 4 +- .../{parser/impl => stmt}/Bug4623Test.java | 75 +- .../yang/stmt/{test => }/Bug4933Test.java | 4 +- .../yang/stmt/{test => }/Bug5059.java | 4 +- .../yang/stmt/{test => }/Bug5101.java | 4 +- .../yang/stmt/{test => }/Bug5335.java | 3 +- .../yang/stmt/{test => }/Bug5396.java | 3 +- .../yang/stmt/{test => }/Bug5437.java | 4 +- .../yang/stmt/{test => }/Bug5481.java | 3 +- .../yang/stmt/{test => }/Bug5550.java | 4 +- .../yang/stmt/{retest => }/Bug5693Test.java | 3 +- .../yang/stmt/{test => }/CaseStmtTest.java | 4 +- .../yang/stmt/{test => }/ChoiceStmtTest.java | 4 +- .../{test => }/ControllerStmtParserTest.java | 4 +- .../{test => }/DeclaredStatementsTest.java | 2 +- .../build/test => }/EffectiveBuildTest.java | 10 +- .../test => }/EffectiveIdentityTest.java | 11 +- .../build/test => }/EffectiveModuleTest.java | 10 +- .../EffectiveModulesAndSubmodulesTest.java | 11 +- .../test => }/EffectiveStatementTypeTest.java | 4 +- ...EffectiveUsesRefineAndConstraintsTest.java | 11 +- .../stmt/{test => }/ExtensionStmtTest.java | 4 +- .../{test => }/GroupingAndUsesStmtTest.java | 4 +- .../yang/stmt/{retest => }/GroupingTest.java | 4 +- .../stmt/{test => }/IdentityStmtTest.java | 4 +- .../{test => }/ImportResolutionBasicTest.java | 4 +- .../stmt/{test => }/ImportRevisionsTest.java | 4 +- .../{test => }/IncludeResolutionTest.java | 10 +- .../stmt/{test => }/IncludeRevisionsTest.java | 10 +- .../stmt/{test => }/IncludedStmtsTest.java | 4 +- .../yang/stmt/{test => }/KeyTest.java | 4 +- .../yang/stmt/{retest => }/ListKeysTest.java | 4 +- .../yang/stmt/{test => }/ListTest.java | 4 +- .../test => }/MappedEffectiveBuildTest.java | 10 +- .../impl => stmt}/ModuleIdentifierTest.java | 4 +- .../stmt/{test => }/MoreRevisionsTest.java | 4 +- .../stmt/{test => }/MustAndWhenStmtTest.java | 4 +- .../stmt/{test => }/NotificationStmtTest.java | 4 +- .../yang/stmt/{retest => }/OrderingTest.java | 4 +- .../ParsingExtensionValueTest.java | 4 +- .../yang/stmt/{test => }/RpcStmtTest.java | 4 +- .../stmt/{retest => }/SchemaContextTest.java | 4 +- .../{retest => }/SchemaContextUtilTest.java | 4 +- .../yang/stmt/{test => }/StmtTestUtils.java | 4 +- .../{test => }/SubstatementValidatorTest.java | 6 +- .../yang/stmt/{retest => }/TestUtils.java | 5 +- .../stmt/{retest => }/TwoRevisionsTest.java | 4 +- .../{test => }/TypedefConstraintsTest.java | 10 +- .../stmt/{test => }/TypedefSubStmtsTest.java | 4 +- .../{retest => }/TypesResolutionTest.java | 87 +- .../stmt/{retest => }/UsesAugmentTest.java | 4 +- .../stmt/{test => }/YangFileStmtTest.java | 4 +- .../YangModelValidationListTest.java | 4 +- .../YangModelValidationModuleTest.java | 4 +- .../YangModelValidationSubModuleTest.java | 4 +- .../{retest => }/YangModelValidationTest.java | 4 +- .../{retest => }/YangParserIdentityTest.java | 5 +- .../{retest => }/YangParserNegativeTest.java | 35 +- .../{retest => }/YangParserSimpleTest.java | 4 +- .../stmt/{retest => }/YangParserTest.java | 106 +- .../YangParserWithContextTest.java | 32 +- .../stmt/{test => }/YangTypes2StmtTest.java | 4 +- .../stmt/{test => }/YangTypesStmtTest.java | 4 +- .../AugmentationSchemaBuilderImplTest.java | 66 -- .../yang/stmt/retest/Bug2219Test.java | 49 - .../stmt/retest/ModuleIdentifierTest.java | 82 -- .../stmt/retest/SameQNamesInChoiceTest.java | 58 -- .../yang/stmt/retest/package-info.java | 13 - .../yin/YinFileAugmentStmtTest.java | 6 +- .../{test => }/yin/YinFileChoiceStmtTest.java | 6 +- .../yin/YinFileExtensionStmtTest.java | 6 +- .../yin/YinFileFeatureStmtTest.java | 6 +- .../yin/YinFileGroupingStmtTest.java | 6 +- .../yin/YinFileHeaderStmtsTest.java | 6 +- .../yin/YinFileIdentityStmtTest.java | 6 +- .../{test => }/yin/YinFileImportStmtTest.java | 6 +- .../yin/YinFileIncludeStmtTest.java | 6 +- .../yin/YinFileLeafListStmtTest.java | 6 +- .../{test => }/yin/YinFileListStmtTest.java | 6 +- .../{test => }/yin/YinFileMetaStmtsTest.java | 6 +- .../{test => }/yin/YinFileRpcStmtTest.java | 6 +- .../stmt/{test => }/yin/YinFileStmtTest.java | 6 +- .../yin/YinFileTypeDefStmtTest.java | 6 +- .../{test => }/yin/YinFileUsesStmtTest.java | 6 +- 228 files changed, 1119 insertions(+), 16112 deletions(-) rename yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/{retest => }/Bug4501Test.java (90%) rename yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/{retest => }/Bug4969Test.java (80%) rename yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/{retest => }/YangModeledAnyXmlSupportTest.java (90%) delete mode 100644 yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/retest/JsonStreamToNormalizedNodeTest.java delete mode 100644 yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/retest/NormalizedNodeToJsonStreamTest.java delete mode 100644 yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/retest/RetestUtils.java delete mode 100644 yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/retest/StreamToNormalizedNodeTest.java delete mode 100644 yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/retest/TestUtils.java delete mode 100644 yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/retest/TestingNormalizedNodeStructuresCreator.java rename yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/{RetestUtils.java => TestUtils.java} (97%) delete mode 100644 yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/xml/retest/Bug2964Test.java delete mode 100644 yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/xml/retest/RandomPrefixTest.java delete mode 100644 yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/xml/retest/XmlDocumentUtilsTest.java delete mode 100644 yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/xml/retest/XmlStreamUtilsTest.java rename yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/{test => }/codecs/BinaryCodecStringTest.java (83%) rename yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/{test => }/codecs/BitsCodecStringTest.java (64%) rename yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/{test => }/codecs/BooleanCodecStringTest.java (65%) rename yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/{test => }/codecs/DecimalCodecStringTest.java (57%) rename yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/{test => }/codecs/EmptyCodecStringTest.java (58%) rename yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/{test => }/codecs/EnumCodecStringTest.java (69%) rename yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/{test => }/codecs/Int16CodecStringTest.java (82%) rename yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/{test => }/codecs/Int32CodecStringTest.java (69%) rename yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/{test => }/codecs/Int64CodecStringTest.java (83%) rename yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/{test => }/codecs/Int8CodecStringTest.java (68%) rename yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/{test => }/codecs/StringCodecStringTest.java (71%) rename yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/{test => }/codecs/StringPatternCheckingCodecTest.java (90%) rename yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/{test => }/codecs/TypeDefinitionAwareCodecTestHelper.java (95%) rename yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/{test => }/codecs/Uint16CodecStringTest.java (79%) rename yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/{test => }/codecs/Uint32CodecStringTest.java (79%) rename yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/{test => }/codecs/Uint64CodecStringTest.java (63%) rename yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/{test => }/codecs/Uint8CodecStringTest.java (80%) rename yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/{test => }/codecs/UnionCodecStringTest.java (80%) rename yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/{test/retest => }/DataTreeCandidateValidatorTest.java (99%) rename yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/{test/retest => }/DataTreeCandidateValidatorTest2.java (98%) rename yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/{test/retest => }/DataTreeCandidateValidatorTest3.java (98%) rename yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/{test/retest => }/LeafRefContextTest.java (94%) rename yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/{test/retest => }/LeafRefContextTreeBuilderTest.java (97%) delete mode 100644 yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/test/DataTreeCandidateValidatorTest.java delete mode 100644 yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/test/DataTreeCandidateValidatorTest2.java delete mode 100644 yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/test/DataTreeCandidateValidatorTest3.java delete mode 100644 yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/test/LeafRefContextTest.java delete mode 100644 yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/test/LeafRefContextTreeBuilderTest.java rename yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/{test => }/BuilderTest.java (98%) rename yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/{test => }/NormalizedNodeUtilsTest.java (92%) delete mode 100644 yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/retest/InstanceIdToNodesTest.java delete mode 100644 yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/retest/NormalizedDataBuilderTest.java rename yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/transform/dom/serializer/{retest => }/YangModeledAnyXMLDeserializationTest.java (97%) rename yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/transform/dom/serializer/{retest => }/YangModeledAnyXMLSerializationTest.java (97%) delete mode 100644 yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/transform/dom/serializer/retest/NormalizedNodeXmlTranslationTest.java delete mode 100644 yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/Bug2690FixTest.java rename yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/{Retest_Bug2690Fix.java => Bug2690Test.java} (95%) rename yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/{Retest_ListConstraintsValidation.java => ListConstraintsValidation.java} (98%) delete mode 100644 yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/ListConstraintsValidationTest.java delete mode 100644 yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/RetestModel.java delete mode 100644 yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/Retest_Bug3674Test.java delete mode 100644 yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/Retest_ConcurrentTreeModificationTest.java delete mode 100644 yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/Retest_ConfigStatementValidationTest.java delete mode 100644 yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/Retest_ErrorReportingTest.java delete mode 100644 yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/Retest_ModificationMetadataTreeTest.java delete mode 100644 yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/Retest_StoreTreeNodesTest.java delete mode 100644 yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/builder/impl/AbstractBuilderTest.java delete mode 100644 yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/builder/impl/BuilderUtilsTest.java delete mode 100644 yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/builder/impl/CopyUtilsTest.java delete mode 100644 yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/builder/impl/LeafListSchemaNodeBuilderTest.java delete mode 100644 yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/builder/impl/ModuleBuilderTest.java delete mode 100644 yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/builder/impl/RefineUtilsTest.java delete mode 100644 yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/builder/impl/RpcDefinitionBuilderTest.java delete mode 100644 yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/builder/impl/TypeDefinitionBuilderImplTest.java delete mode 100644 yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/AugmentTest.java delete mode 100644 yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/AugmentToExtensionTest.java delete mode 100644 yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/AugmentationSchemaBuilderImplTest.java delete mode 100644 yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/Bug1412Test.java delete mode 100644 yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/Bug1413Test.java delete mode 100644 yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/Bug2291Test.java delete mode 100644 yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/Bug3799Test.java delete mode 100644 yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/Bug394Test.java delete mode 100644 yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/Bug4079Test.java delete mode 100644 yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/GroupingTest.java delete mode 100644 yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/ListKeysTest.java delete mode 100644 yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/OrderingTest.java delete mode 100644 yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/ParsingExtensionValueTest.java delete mode 100644 yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/SameQNamesInChoiceTest.java delete mode 100644 yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/SchemaContextTest.java delete mode 100644 yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/TestUtils.java delete mode 100644 yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/TwoRevisionsTest.java delete mode 100644 yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/TypesResolutionTest.java delete mode 100644 yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/UsesAugmentTest.java delete mode 100644 yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/YangModelValidationListTest.java delete mode 100644 yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/YangModelValidationModuleTest.java delete mode 100644 yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/YangModelValidationSubModuleTest.java delete mode 100644 yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/YangModelValidationTest.java delete mode 100644 yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/YangParserIdentityTest.java delete mode 100644 yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/YangParserNegativeTest.java delete mode 100644 yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/YangParserSimpleTest.java delete mode 100644 yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/YangParserTest.java delete mode 100644 yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/YangParserWithContextTest.java rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{test/AugmentTest.java => AugmentArgumentParsingTest.java} (97%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{test => }/AugmentProcessTest.java (98%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{test => }/AugmentSimplestTest.java (93%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{retest => }/AugmentTest.java (99%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{retest => }/AugmentToExtensionTest.java (89%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{retest => }/Bug1412Test.java (96%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{retest => }/Bug1413Test.java (91%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/{parser/impl => stmt}/Bug2219Test.java (94%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{retest => }/Bug2291Test.java (88%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{test => }/Bug3799Test.java (85%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/{parser/impl => stmt}/Bug3859Test.java (85%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{test => }/Bug3874ExtensionTest.java (96%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{retest => }/Bug394Test.java (93%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{retest => }/Bug4079Test.java (99%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/{parser/impl => stmt}/Bug4231Test.java (81%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{test => }/Bug4410Test.java (92%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{test => }/Bug4456Test.java (96%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{test => }/Bug4459Test.java (94%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{test => }/Bug4610Test.java (96%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/{parser/impl => stmt}/Bug4623Test.java (65%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{test => }/Bug4933Test.java (93%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{test => }/Bug5059.java (88%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{test => }/Bug5101.java (96%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{test => }/Bug5335.java (99%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{test => }/Bug5396.java (98%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{test => }/Bug5437.java (96%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{test => }/Bug5481.java (98%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{test => }/Bug5550.java (93%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{retest => }/Bug5693Test.java (97%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{test => }/CaseStmtTest.java (99%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{test => }/ChoiceStmtTest.java (96%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{test => }/ControllerStmtParserTest.java (98%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{test => }/DeclaredStatementsTest.java (99%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{effective/build/test => }/EffectiveBuildTest.java (94%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{effective/build/test => }/EffectiveIdentityTest.java (92%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{effective/build/test => }/EffectiveModuleTest.java (95%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{effective/build/test => }/EffectiveModulesAndSubmodulesTest.java (95%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{effective/build/test => }/EffectiveStatementTypeTest.java (99%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{effective/build/test => }/EffectiveUsesRefineAndConstraintsTest.java (96%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{test => }/ExtensionStmtTest.java (97%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{test => }/GroupingAndUsesStmtTest.java (98%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{retest => }/GroupingTest.java (99%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{test => }/IdentityStmtTest.java (98%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{test => }/ImportResolutionBasicTest.java (97%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{test => }/ImportRevisionsTest.java (97%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{test => }/IncludeResolutionTest.java (92%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{test => }/IncludeRevisionsTest.java (94%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{test => }/IncludedStmtsTest.java (97%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{test => }/KeyTest.java (95%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{retest => }/ListKeysTest.java (97%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{test => }/ListTest.java (97%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{effective/build/test => }/MappedEffectiveBuildTest.java (81%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/{parser/impl => stmt}/ModuleIdentifierTest.java (95%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{test => }/MoreRevisionsTest.java (99%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{test => }/MustAndWhenStmtTest.java (97%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{test => }/NotificationStmtTest.java (95%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{retest => }/OrderingTest.java (98%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{retest => }/ParsingExtensionValueTest.java (88%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{test => }/RpcStmtTest.java (95%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{retest => }/SchemaContextTest.java (95%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{retest => }/SchemaContextUtilTest.java (99%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{test => }/StmtTestUtils.java (97%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{test => }/SubstatementValidatorTest.java (94%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{retest => }/TestUtils.java (98%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{retest => }/TwoRevisionsTest.java (86%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{test => }/TypedefConstraintsTest.java (88%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{test => }/TypedefSubStmtsTest.java (94%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{retest => }/TypesResolutionTest.java (83%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{retest => }/UsesAugmentTest.java (99%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{test => }/YangFileStmtTest.java (97%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{retest => }/YangModelValidationListTest.java (97%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{retest => }/YangModelValidationModuleTest.java (98%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{retest => }/YangModelValidationSubModuleTest.java (96%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{retest => }/YangModelValidationTest.java (98%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{retest => }/YangParserIdentityTest.java (93%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{retest => }/YangParserNegativeTest.java (88%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{retest => }/YangParserSimpleTest.java (98%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{retest => }/YangParserTest.java (88%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{retest => }/YangParserWithContextTest.java (94%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{test => }/YangTypes2StmtTest.java (98%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{test => }/YangTypesStmtTest.java (95%) delete mode 100644 yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/AugmentationSchemaBuilderImplTest.java delete mode 100644 yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/Bug2219Test.java delete mode 100644 yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/ModuleIdentifierTest.java delete mode 100644 yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/SameQNamesInChoiceTest.java delete mode 100644 yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/package-info.java rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{test => }/yin/YinFileAugmentStmtTest.java (92%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{test => }/yin/YinFileChoiceStmtTest.java (94%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{test => }/yin/YinFileExtensionStmtTest.java (96%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{test => }/yin/YinFileFeatureStmtTest.java (90%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{test => }/yin/YinFileGroupingStmtTest.java (93%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{test => }/yin/YinFileHeaderStmtsTest.java (87%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{test => }/yin/YinFileIdentityStmtTest.java (91%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{test => }/yin/YinFileImportStmtTest.java (91%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{test => }/yin/YinFileIncludeStmtTest.java (89%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{test => }/yin/YinFileLeafListStmtTest.java (91%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{test => }/yin/YinFileListStmtTest.java (94%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{test => }/yin/YinFileMetaStmtsTest.java (93%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{test => }/yin/YinFileRpcStmtTest.java (92%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{test => }/yin/YinFileStmtTest.java (95%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{test => }/yin/YinFileTypeDefStmtTest.java (90%) rename yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/{test => }/yin/YinFileUsesStmtTest.java (92%) diff --git a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/retest/Bug4501Test.java b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/Bug4501Test.java similarity index 90% rename from yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/retest/Bug4501Test.java rename to yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/Bug4501Test.java index 0e9ff9b95b..b95f5cc736 100644 --- a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/retest/Bug4501Test.java +++ b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/Bug4501Test.java @@ -1,17 +1,17 @@ /* - * 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.data.codec.gson.retest; +package org.opendaylight.yangtools.yang.data.codec.gson; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.fail; -import static org.opendaylight.yangtools.yang.data.codec.gson.retest.TestUtils.loadModules; -import static org.opendaylight.yangtools.yang.data.codec.gson.retest.TestUtils.loadTextFile; +import static org.opendaylight.yangtools.yang.data.codec.gson.TestUtils.loadModules; +import static org.opendaylight.yangtools.yang.data.codec.gson.TestUtils.loadTextFile; import com.google.common.base.Optional; import com.google.common.collect.ImmutableSet; @@ -28,7 +28,6 @@ import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode; import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter; -import org.opendaylight.yangtools.yang.data.codec.gson.JsonParserStream; import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNormalizedNodeStreamWriter; import org.opendaylight.yangtools.yang.data.impl.schema.NormalizedNodeResult; import org.opendaylight.yangtools.yang.model.api.SchemaContext; diff --git a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/retest/Bug4969Test.java b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/Bug4969Test.java similarity index 80% rename from yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/retest/Bug4969Test.java rename to yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/Bug4969Test.java index babd4fb51f..2a3a1d5a22 100644 --- a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/retest/Bug4969Test.java +++ b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/Bug4969Test.java @@ -1,11 +1,11 @@ /* - * 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.data.codec.gson.retest; +package org.opendaylight.yangtools.yang.data.codec.gson; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -16,7 +16,6 @@ import java.io.File; import java.io.IOException; import java.io.StringReader; import java.net.URISyntaxException; -import java.util.Arrays; import java.util.Set; import org.junit.Test; import org.opendaylight.yangtools.yang.common.QName; @@ -26,11 +25,9 @@ import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode; import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter; -import org.opendaylight.yangtools.yang.data.codec.gson.JsonParserStream; import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNormalizedNodeStreamWriter; import org.opendaylight.yangtools.yang.data.impl.schema.NormalizedNodeResult; 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; @@ -39,16 +36,7 @@ public class Bug4969Test { @Test public void newParserLeafRefTest() throws SourceException, ReactorException, URISyntaxException, IOException { File sourceDir = new File(Bug4969Test.class.getResource("/bug-4969/yang").toURI()); - SchemaContext context = RetestUtils.parseYangSources(sourceDir.listFiles()); - assertNotNull(context); - - verifyNormalizedNodeResult(context); - } - - @Test - public void oldParserLeafRefTest() throws SourceException, ReactorException, URISyntaxException, IOException { - File sourceDir = new File(Bug4969Test.class.getResource("/bug-4969/yang").toURI()); - SchemaContext context = YangParserImpl.getInstance().parseFiles(Arrays.asList(sourceDir.listFiles())); + SchemaContext context = TestUtils.parseYangSources(sourceDir.listFiles()); assertNotNull(context); verifyNormalizedNodeResult(context); @@ -107,16 +95,7 @@ public class Bug4969Test { @Test public void newParserLeafRefTest2() throws SourceException, ReactorException, URISyntaxException, IOException { File sourceDir = new File(Bug4969Test.class.getResource("/leafref/yang").toURI()); - SchemaContext context = RetestUtils.parseYangSources(sourceDir.listFiles()); - assertNotNull(context); - - parseJsonToNormalizedNodes(context); - } - - @Test - public void oldParserLeafRefTest2() throws SourceException, ReactorException, URISyntaxException, IOException { - File sourceDir = new File(Bug4969Test.class.getResource("/leafref/yang").toURI()); - SchemaContext context = YangParserImpl.getInstance().parseFiles(Arrays.asList(sourceDir.listFiles())); + SchemaContext context = TestUtils.parseYangSources(sourceDir.listFiles()); assertNotNull(context); parseJsonToNormalizedNodes(context); diff --git a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/JsonStreamToNormalizedNodeTest.java b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/JsonStreamToNormalizedNodeTest.java index 5582d508c4..c7e574d812 100644 --- a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/JsonStreamToNormalizedNodeTest.java +++ b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/JsonStreamToNormalizedNodeTest.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, @@ -34,6 +34,7 @@ import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNormalizedNodeS import org.opendaylight.yangtools.yang.data.impl.schema.NormalizedNodeResult; import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.opendaylight.yangtools.yang.model.api.SchemaNode; +import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; /** * @@ -46,7 +47,7 @@ public class JsonStreamToNormalizedNodeTest { private static SchemaContext schemaContext; @BeforeClass - public static void initialization() throws IOException, URISyntaxException { + public static void initialization() throws IOException, URISyntaxException, ReactorException { schemaContext = loadModules("/complexjson/yang"); } diff --git a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/NormalizedNodeToJsonStreamTest.java b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/NormalizedNodeToJsonStreamTest.java index 62f1d6e6c5..51ed99fe08 100644 --- a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/NormalizedNodeToJsonStreamTest.java +++ b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/NormalizedNodeToJsonStreamTest.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, @@ -40,6 +40,7 @@ import org.opendaylight.yangtools.yang.data.impl.schema.Builders; import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes; import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.opendaylight.yangtools.yang.model.api.SchemaPath; +import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; /** * Each test tests whether json output obtained after transformation contains is corect. The transformation takes @@ -50,15 +51,15 @@ import org.opendaylight.yangtools.yang.model.api.SchemaPath; public class NormalizedNodeToJsonStreamTest { private static final QName CONT_1 = QName.create("ns:complex:json", "2014-08-11", "cont1"); - private static final QName EMPTY_LEAF = QName.create(CONT_1,"empty"); + private static final QName EMPTY_LEAF = QName.create(CONT_1, "empty"); private static SchemaContext schemaContext; public interface JsonValidator { void validate(final String jsonOutput); - } + } @BeforeClass - public static void initialization() throws IOException, URISyntaxException { + public static void initialization() throws IOException, URISyntaxException, ReactorException { schemaContext = loadModules("/complexjson/yang"); } @@ -106,7 +107,8 @@ public class NormalizedNodeToJsonStreamTest { @Test public void leafListNodeInContainerMultiline() throws IOException, URISyntaxException { final Writer writer = new StringWriter(); - final NormalizedNode leafListNodeInContainer = TestingNormalizedNodeStructuresCreator.leafListNodeInContainerMultiline(); + final NormalizedNode leafListNodeInContainer = TestingNormalizedNodeStructuresCreator + .leafListNodeInContainerMultiline(); final String jsonOutput = normalizedNodeToJsonStreamTransformation(writer, leafListNodeInContainer); new JsonValidator() { @@ -123,7 +125,8 @@ public class NormalizedNodeToJsonStreamTest { lflst11Values.add(((JsonPrimitive) jsonElement).getAsString()); } - assertEquals(Sets.newHashSet("lflst11 value2\r\nanother line 2", "lflst11 value1\nanother line 1"), lflst11Values); + assertEquals(Sets.newHashSet("lflst11 value2\r\nanother line 2", "lflst11 value1\nanother line 1"), + lflst11Values); } }.validate(jsonOutput); @@ -154,7 +157,8 @@ public class NormalizedNodeToJsonStreamTest { @Test public void leafListNodeInContainer() throws IOException, URISyntaxException { final Writer writer = new StringWriter(); - final NormalizedNode leafListNodeInContainer = TestingNormalizedNodeStructuresCreator.leafListNodeInContainer(); + final NormalizedNode leafListNodeInContainer = TestingNormalizedNodeStructuresCreator + .leafListNodeInContainer(); final String jsonOutput = normalizedNodeToJsonStreamTransformation(writer, leafListNodeInContainer); new JsonValidator() { @@ -218,7 +222,8 @@ public class NormalizedNodeToJsonStreamTest { @Test public void choiceNodeInContainer() throws IOException, URISyntaxException { final Writer writer = new StringWriter(); - final NormalizedNode choiceNodeInContainer = TestingNormalizedNodeStructuresCreator.choiceNodeInContainer(); + final NormalizedNode choiceNodeInContainer = TestingNormalizedNodeStructuresCreator + .choiceNodeInContainer(); final String jsonOutput = normalizedNodeToJsonStreamTransformation(writer, choiceNodeInContainer); new JsonValidator() { @@ -244,13 +249,14 @@ public class NormalizedNodeToJsonStreamTest { * [ChoiceNodeImpl[qname=(ns:complex:json?revision=2014-08-11)choc11]] * */ -// @Ignore + // @Ignore @Test public void caseNodeAugmentationInChoiceInContainer() throws IOException, URISyntaxException { final Writer writer = new StringWriter(); final NormalizedNode caseNodeAugmentationInChoiceInContainer = TestingNormalizedNodeStructuresCreator .caseNodeAugmentationInChoiceInContainer(); - final String jsonOutput = normalizedNodeToJsonStreamTransformation(writer, caseNodeAugmentationInChoiceInContainer); + final String jsonOutput = normalizedNodeToJsonStreamTransformation(writer, + caseNodeAugmentationInChoiceInContainer); new JsonValidator() { @Override @@ -286,7 +292,7 @@ public class NormalizedNodeToJsonStreamTest { * [ChoiceNodeImpl[qname=(ns:complex:json?revision=2014-08-11)choc11]] * */ -// @Ignore + // @Ignore @Test public void caseNodeExternalAugmentationInChoiceInContainer() throws IOException, URISyntaxException { final Writer writer = new StringWriter(); @@ -331,14 +337,13 @@ public class NormalizedNodeToJsonStreamTest { * [ChoiceNodeImpl[qname=(ns:complex:json?revision=2014-08-11)choc11]] * */ -// @Ignore + // @Ignore @Test public void choiceNodeAugmentationInContainer() throws IOException, URISyntaxException { final Writer writer = new StringWriter(); final NormalizedNode choiceNodeAugmentationInContainer = TestingNormalizedNodeStructuresCreator .choiceNodeAugmentationInContainer(); - final String jsonOutput = normalizedNodeToJsonStreamTransformation(writer, - choiceNodeAugmentationInContainer); + final String jsonOutput = normalizedNodeToJsonStreamTransformation(writer, choiceNodeAugmentationInContainer); new JsonValidator() { @Override @@ -346,9 +351,9 @@ public class NormalizedNodeToJsonStreamTest { final JsonObject cont1 = resolveCont1(jsonOutput); assertNotNull(cont1); - final JsonPrimitive lf17 = childPrimitive(cont1, "complexjson:lf17","lf17"); + final JsonPrimitive lf17 = childPrimitive(cont1, "complexjson:lf17", "lf17"); assertNotNull(lf17); - assertEquals("lf17 value",lf17.getAsString()); + assertEquals("lf17 value", lf17.getAsString()); } }.validate(jsonOutput); } @@ -358,8 +363,7 @@ public class NormalizedNodeToJsonStreamTest { final Writer writer = new StringWriter(); final NormalizedNode unkeyedNodeInContainer = TestingNormalizedNodeStructuresCreator .unkeyedNodeInContainer(); - final String jsonOutput = normalizedNodeToJsonStreamTransformation(writer, - unkeyedNodeInContainer); + final String jsonOutput = normalizedNodeToJsonStreamTransformation(writer, unkeyedNodeInContainer); new JsonValidator() { @Override @@ -367,7 +371,7 @@ public class NormalizedNodeToJsonStreamTest { final JsonObject cont1 = resolveCont1(jsonOutput); assertNotNull(cont1); - final JsonArray lst12 = childArray(cont1, "complexjson:lst12","lst12"); + final JsonArray lst12 = childArray(cont1, "complexjson:lst12", "lst12"); assertNotNull(lst12); final Iterator iterator = lst12.iterator(); @@ -376,11 +380,11 @@ public class NormalizedNodeToJsonStreamTest { assertFalse(iterator.hasNext()); assertTrue(lst12Entry1Raw instanceof JsonObject); - final JsonObject lst12Entry1 = (JsonObject)lst12Entry1Raw; + final JsonObject lst12Entry1 = (JsonObject) lst12Entry1Raw; final JsonPrimitive lf121 = childPrimitive(lst12Entry1, "complexjson:lf121", "lf121"); assertNotNull(lf121); - assertEquals("lf121 value",lf121.getAsString()); + assertEquals("lf121 value", lf121.getAsString()); } }.validate(jsonOutput); @@ -392,15 +396,13 @@ public class NormalizedNodeToJsonStreamTest { final StringWriter writer = new StringWriter(); final ContainerNode emptyStructure = Builders.containerBuilder() .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(CONT_1)) - .addChild(ImmutableNodes.leafNode(EMPTY_LEAF, null)) - .build(); - final String jsonOutput = normalizedNodeToJsonStreamTransformation(writer, - emptyStructure); + .addChild(ImmutableNodes.leafNode(EMPTY_LEAF, null)).build(); + final String jsonOutput = normalizedNodeToJsonStreamTransformation(writer, emptyStructure); final JsonObject cont1 = resolveCont1(jsonOutput); final JsonElement emptyObj = cont1.get("empty"); assertNotNull(emptyObj); assertTrue(emptyObj instanceof JsonArray); - assertEquals(1,emptyObj.getAsJsonArray().size()); + assertEquals(1, emptyObj.getAsJsonArray().size()); assertTrue(emptyObj.getAsJsonArray().get(0) instanceof JsonNull); } diff --git a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/StreamToNormalizedNodeTest.java b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/StreamToNormalizedNodeTest.java index 3f21878681..28db132ffe 100644 --- a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/StreamToNormalizedNodeTest.java +++ b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/StreamToNormalizedNodeTest.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, @@ -9,6 +9,9 @@ package org.opendaylight.yangtools.yang.data.codec.gson; import static org.opendaylight.yangtools.yang.data.codec.gson.TestUtils.loadModules; import static org.opendaylight.yangtools.yang.data.codec.gson.TestUtils.loadTextFile; + +import org.opendaylight.yangtools.yang.model.api.SchemaPath; + import com.google.gson.stream.JsonReader; import java.io.File; import java.io.IOException; @@ -27,7 +30,7 @@ import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeWrit import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNormalizedNodeStreamWriter; import org.opendaylight.yangtools.yang.data.impl.schema.NormalizedNodeResult; import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.model.api.SchemaPath; +import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -37,7 +40,7 @@ public class StreamToNormalizedNodeTest { private static String streamAsString; @BeforeClass - public static void initialization() throws IOException, URISyntaxException { + public static void initialization() throws IOException, URISyntaxException, ReactorException { schemaContext = loadModules("/complexjson/yang"); streamAsString = loadTextFile(new File(StreamToNormalizedNodeTest.class.getResource( "/complexjson/complex-json.json").toURI())); @@ -100,10 +103,12 @@ public class StreamToNormalizedNodeTest { // String holder final StringWriter writer = new StringWriter(); + // StreamWriter which outputs JSON strings // StreamWriter which outputs JSON strings final NormalizedNodeStreamWriter jsonStream = JSONNormalizedNodeStreamWriter. createExclusiveWriter(JSONCodecFactory.create(schemaContext), SchemaPath.ROOT, null, JsonWriterFactory.createJsonWriter(writer, 2)); + // NormalizedNode -> StreamWriter final NormalizedNodeWriter nodeWriter = NormalizedNodeWriter.forStreamWriter(jsonStream); diff --git a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/TestUtils.java b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/TestUtils.java index c5b6d80c2e..0e13ecbbfe 100644 --- a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/TestUtils.java +++ b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/TestUtils.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,7 +8,6 @@ package org.opendaylight.yangtools.yang.data.codec.gson; import static org.junit.Assert.assertTrue; - import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; @@ -16,24 +15,31 @@ import com.google.gson.JsonParser; import com.google.gson.JsonPrimitive; import java.io.BufferedReader; import java.io.File; +import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; +import java.io.InputStream; import java.net.URI; import java.net.URISyntaxException; import java.util.ArrayList; +import java.util.Collection; import java.util.List; 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; +import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource; +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 TestUtils { private TestUtils() { } - static SchemaContext loadModules(final String resourceDirectory) throws IOException, URISyntaxException { - YangContextParser parser = new YangParserImpl(); + static SchemaContext loadModules(final String resourceDirectory) throws IOException, URISyntaxException, + ReactorException { URI path = StreamToNormalizedNodeTest.class.getResource(resourceDirectory).toURI(); final File testDir = new File(path); final String[] fileList = testDir.list(); @@ -46,7 +52,41 @@ public class TestUtils { testFiles.add(new File(testDir, fileName)); } } - return parser.parseFiles(testFiles); + return parseYangSources(testFiles); + } + + public static SchemaContext parseYangSources(StatementStreamSource... sources) + throws SourceException, ReactorException { + + CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR + .newBuild(); + reactor.addSources(sources); + + return reactor.buildEffective(); + } + + public static SchemaContext parseYangSources(File... files) throws SourceException, ReactorException, FileNotFoundException { + + StatementStreamSource[] sources = new StatementStreamSource[files.length]; + + for(int i = 0; i files) throws SourceException, ReactorException, FileNotFoundException { + return parseYangSources(files.toArray(new File[files.size()])); + } + + + public static SchemaContext parseYangStreams(List streams) + throws SourceException, ReactorException { + + CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR + .newBuild(); + return reactor.buildEffective(streams); } static String loadTextFile(final File file) throws IOException { @@ -66,7 +106,7 @@ public class TestUtils { return loadTextFile(new File(TestUtils.class.getResource(relativePath).toURI())); } - static JsonObject childObject(final JsonObject jsonObject,final String ... names) { + static JsonObject childObject(final JsonObject jsonObject, final String... names) { for (String name : names) { JsonObject childJsonObject = jsonObject.getAsJsonObject(name); if (childJsonObject != null) { @@ -76,7 +116,7 @@ public class TestUtils { return null; } - static JsonPrimitive childPrimitive(final JsonObject jsonObject,final String ... names) { + static JsonPrimitive childPrimitive(final JsonObject jsonObject, final String... names) { for (String name : names) { JsonPrimitive childJsonPrimitive = jsonObject.getAsJsonPrimitive(name); if (childJsonPrimitive != null) { @@ -86,7 +126,7 @@ public class TestUtils { return null; } - static JsonArray childArray(final JsonObject jsonObject,final String ... names) { + static JsonArray childArray(final JsonObject jsonObject, final String... names) { for (String name : names) { JsonArray childJsonArray = jsonObject.getAsJsonArray(name); if (childJsonArray != null) { @@ -105,5 +145,4 @@ public class TestUtils { return cont1; } - } diff --git a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/TestingNormalizedNodeStructuresCreator.java b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/TestingNormalizedNodeStructuresCreator.java index 0001a05aad..db4814c982 100644 --- a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/TestingNormalizedNodeStructuresCreator.java +++ b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/TestingNormalizedNodeStructuresCreator.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/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/retest/YangModeledAnyXmlSupportTest.java b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/YangModeledAnyXmlSupportTest.java similarity index 90% rename from yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/retest/YangModeledAnyXmlSupportTest.java rename to yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/YangModeledAnyXmlSupportTest.java index 220bb7193b..9033049a2d 100644 --- a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/retest/YangModeledAnyXmlSupportTest.java +++ b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/YangModeledAnyXmlSupportTest.java @@ -1,15 +1,15 @@ /* - * 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.data.codec.gson.retest; +package org.opendaylight.yangtools.yang.data.codec.gson; import static org.junit.Assert.assertEquals; -import static org.opendaylight.yangtools.yang.data.codec.gson.retest.TestUtils.loadModules; -import static org.opendaylight.yangtools.yang.data.codec.gson.retest.TestUtils.loadTextFile; +import static org.opendaylight.yangtools.yang.data.codec.gson.TestUtils.loadModules; +import static org.opendaylight.yangtools.yang.data.codec.gson.TestUtils.loadTextFile; import com.google.common.base.Preconditions; import com.google.gson.JsonElement; import com.google.gson.JsonParser; @@ -35,10 +35,6 @@ import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter; import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeWriter; -import org.opendaylight.yangtools.yang.data.codec.gson.JSONCodecFactory; -import org.opendaylight.yangtools.yang.data.codec.gson.JSONNormalizedNodeStreamWriter; -import org.opendaylight.yangtools.yang.data.codec.gson.JsonParserStream; -import org.opendaylight.yangtools.yang.data.codec.gson.JsonWriterFactory; import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNormalizedNodeStreamWriter; import org.opendaylight.yangtools.yang.data.impl.schema.NormalizedNodeResult; import org.opendaylight.yangtools.yang.data.impl.schema.transform.dom.DomUtils; diff --git a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/retest/JsonStreamToNormalizedNodeTest.java b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/retest/JsonStreamToNormalizedNodeTest.java deleted file mode 100644 index 682e6508ef..0000000000 --- a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/retest/JsonStreamToNormalizedNodeTest.java +++ /dev/null @@ -1,296 +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.data.codec.gson.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 static org.opendaylight.yangtools.yang.data.codec.gson.retest.TestUtils.loadModules; -import static org.opendaylight.yangtools.yang.data.codec.gson.retest.TestUtils.loadTextFile; -import static org.opendaylight.yangtools.yang.data.impl.schema.Builders.augmentationBuilder; -import static org.opendaylight.yangtools.yang.data.impl.schema.Builders.choiceBuilder; -import static org.opendaylight.yangtools.yang.data.impl.schema.Builders.containerBuilder; -import static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.leafNode; -import com.google.common.collect.Sets; -import com.google.gson.stream.JsonReader; -import java.io.IOException; -import java.io.StringReader; -import java.net.URISyntaxException; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; -import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode; -import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; -import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter; -import org.opendaylight.yangtools.yang.data.codec.gson.JsonParserStream; -import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNormalizedNodeStreamWriter; -import org.opendaylight.yangtools.yang.data.impl.schema.NormalizedNodeResult; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.model.api.SchemaNode; -import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; - -/** - * - * Each test tests whether json input is correctly transformed to normalized node structure - */ -public class JsonStreamToNormalizedNodeTest { - - private static final QName CONT_1 = QName.create("ns:complex:json", "2014-08-11", "cont1"); - private static final QName EMPTY_LEAF = QName.create(CONT_1,"empty"); - private static SchemaContext schemaContext; - - @BeforeClass - public static void initialization() throws IOException, URISyntaxException, ReactorException { - schemaContext = loadModules("/complexjson/yang"); - } - - /** - * case when anyxml contains simple value will be implemented when anyxml normalized node reprezentation will be - * specified - */ - @Ignore - @Test - public void anyXmlNodeWithSimpleValueInContainer() throws IOException, URISyntaxException { - - } - - /** - * case when anyxml contains complex xml will be implemented when anyxml normalized node reprezentation will be - * specified - */ - @Ignore - @Test - public void anyXmlNodeWithCompositeValueInContainer() throws IOException, URISyntaxException { - - } - - @Test - public void leafNodeInContainer() throws IOException, URISyntaxException { - final String inputJson = loadTextFile("/complexjson/leaf-node-in-container.json"); - verifyTransformationToNormalizedNode(inputJson, TestingNormalizedNodeStructuresCreator.leafNodeInContainer()); - } - - @Test - public void leafNodeViaAugmentationInContainer() throws IOException, URISyntaxException { - final String inputJson = loadTextFile("/complexjson/leaf-node-via-augmentation-in-container.json"); - verifyTransformationToNormalizedNode(inputJson, - TestingNormalizedNodeStructuresCreator.leafNodeViaAugmentationInContainer()); - } - - @Test - public void leafListNodeInContainer() throws IOException, URISyntaxException { - final String inputJson = loadTextFile("/complexjson/leaflist-node-in-container.json"); - verifyTransformationToNormalizedNode(inputJson, - TestingNormalizedNodeStructuresCreator.leafListNodeInContainer()); - } - - @Test - public void keyedListNodeInContainer() throws IOException, URISyntaxException { - final String inputJson = loadTextFile("/complexjson/keyed-list-node-in-container.json"); - verifyTransformationToNormalizedNode(inputJson, - TestingNormalizedNodeStructuresCreator.keyedListNodeInContainer()); - } - - @Test - public void choiceNodeInContainer() throws IOException, URISyntaxException { - final String inputJson = loadTextFile("/complexjson/choice-node-in-container.json"); - verifyTransformationToNormalizedNode(inputJson, TestingNormalizedNodeStructuresCreator.choiceNodeInContainer()); - } - - /** - * Test of translating internal augmentations to normalized nodes structure - * - * 2 nodes are added via internal augmentation A, 1 node via internal augmentation B and one node is originally - * member of case. - * - */ - @Test - public void caseNodeAugmentationInChoiceInContainer() throws IOException, URISyntaxException { - final String inputJson = loadTextFile("/complexjson/case-node-augmentation-in-choice-in-container.json"); - verifyTransformationToNormalizedNode(inputJson, - TestingNormalizedNodeStructuresCreator.caseNodeAugmentationInChoiceInContainer()); - } - - /** - * also test using of namesakes (equal local names with different - * - * @throws IOException - * @throws URISyntaxException - */ - @Test - public void caseNodeExternalAugmentationInChoiceInContainer() throws IOException, URISyntaxException { - final String inputJson = loadTextFile("/complexjson/case-node-external-augmentation-in-choice-in-container.json"); - verifyTransformationToNormalizedNode(inputJson, - TestingNormalizedNodeStructuresCreator.caseNodeExternalAugmentationInChoiceInContainer()); - } - - /** - * augmentation of choice - adding new case - */ - @Test - public void choiceNodeAugmentationInContainer() throws IOException, URISyntaxException { - final String inputJson = loadTextFile("/complexjson/choice-node-augmentation-in-container.json"); - verifyTransformationToNormalizedNode(inputJson, - TestingNormalizedNodeStructuresCreator.choiceNodeAugmentationInContainer()); - } - - @Test - public void unkeyedNodeInContainer() throws IOException, URISyntaxException { - final String inputJson = loadTextFile("/complexjson/unkeyed-node-in-container.json"); - verifyTransformationToNormalizedNode(inputJson, TestingNormalizedNodeStructuresCreator.unkeyedNodeInContainer()); - } - - /** - * Top level JSON element contains no information about module name. - * - * It should be possible to find out potential module name from available schema context. - * - */ - @Test - public void missingModuleInfoInTopLevelElement() throws IOException, URISyntaxException { - final String inputJson = loadTextFile("/complexjson/missing-module-in-top-level.json"); - verifyTransformationToNormalizedNode(inputJson, TestingNormalizedNodeStructuresCreator.topLevelContainer()); - } - - /** - * - * Exception expected. - * - * It tests case when several elements with the same name and various namespaces exists and are in JSON specified - * without module name prefix. - */ - @Test - public void leafNamesakes() throws IOException, URISyntaxException { - final String inputJson = loadTextFile("/complexjson/namesakes.json"); - try { - //second parameter isn't necessary because error will be raised before it is used. - verifyTransformationToNormalizedNode(inputJson, null); - fail("Expected exception not raised"); - } catch (final IllegalStateException e) { - final String errorMessage = e.getMessage(); - assertTrue(errorMessage.contains("Choose suitable module name for element lf11-namesake:")); - assertTrue(errorMessage.contains("complexjson-augmentation")); - assertTrue(errorMessage.contains("complexjson-augmentation-namesake")); - } - } - - @Test - public void emptyTypeTest() throws IOException, URISyntaxException { - final String inputJson = loadTextFile("/complexjson/type-empty.json"); - final ContainerNode awaitedStructure = containerBuilder() - .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(CONT_1)) - .addChild(leafNode(EMPTY_LEAF, null)) - .build(); - - verifyTransformationToNormalizedNode(inputJson, awaitedStructure); - } - - /** - * - * Exception expected. - * - * Json input contains element which doesn't exist in YANG schema - */ - @Test - public void parsingNotExistingElement() throws IOException, URISyntaxException { - final String inputJson = loadTextFile("/complexjson/not-existing-element.json"); - try { - //second parameter isn't necessary because error will be raised before it is used. - verifyTransformationToNormalizedNode(inputJson, null); - } catch (final IllegalStateException e) { - assertTrue(e.getMessage().contains("Schema node with name dummy-element wasn't found")); - } - } - - - @Test - public void listItemWithoutArray() throws IOException, URISyntaxException { - final String inputJson = loadTextFile("/complexjson/keyed-list-restconf-behaviour.json"); - - final NormalizedNodeResult result = new NormalizedNodeResult(); - final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result); - final SchemaNode parentNode = schemaContext.getDataChildByName("cont1"); - final JsonParserStream jsonParser = JsonParserStream.create(streamWriter, schemaContext, parentNode); - jsonParser.parse(new JsonReader(new StringReader(inputJson))); - final NormalizedNode transformedInput = result.getResult(); - assertNotNull(transformedInput); - } - - @Test - public void listItemWithArray() throws IOException, URISyntaxException { - final String inputJson = loadTextFile("/complexjson/keyed-list-yang-json-behaviour.json"); - - final NormalizedNodeResult result = new NormalizedNodeResult(); - final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result); - final SchemaNode parentNode = schemaContext.getDataChildByName("cont1"); - final JsonParserStream jsonParser = JsonParserStream.create(streamWriter, schemaContext, parentNode); - jsonParser.parse(new JsonReader(new StringReader(inputJson))); - final NormalizedNode transformedInput = result.getResult(); - assertNotNull(transformedInput); - } - - @Test - public void multipleChoiceAugmentation() throws IOException, URISyntaxException { - final String inputJson = loadTextFile("/complexjson/multiple-choice-augmentation-in-container.json"); - - final NormalizedNodeResult result = new NormalizedNodeResult(); - final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result); - final SchemaNode parentNode = schemaContext.getDataChildByName("cont1"); - - QName augmentChoice1QName = QName.create(parentNode.getQName(), "augment-choice1"); - QName augmentChoice2QName = QName.create(augmentChoice1QName, "augment-choice2"); - final QName containerQName = QName.create(augmentChoice1QName, "case11-choice-case-container"); - final QName leafQName = QName.create(augmentChoice1QName, "case11-choice-case-leaf"); - - final YangInstanceIdentifier.AugmentationIdentifier aug1Id = - new YangInstanceIdentifier.AugmentationIdentifier(Sets.newHashSet(augmentChoice1QName)); - final YangInstanceIdentifier.AugmentationIdentifier aug2Id = - new YangInstanceIdentifier.AugmentationIdentifier(Sets.newHashSet(augmentChoice2QName)); - final YangInstanceIdentifier.NodeIdentifier augmentChoice1Id = - new YangInstanceIdentifier.NodeIdentifier(augmentChoice1QName); - final YangInstanceIdentifier.NodeIdentifier augmentChoice2Id = - new YangInstanceIdentifier.NodeIdentifier(augmentChoice2QName); - final YangInstanceIdentifier.NodeIdentifier containerId = - new YangInstanceIdentifier.NodeIdentifier(containerQName); - - final NormalizedNode cont1Normalized = - containerBuilder().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(parentNode.getQName())) - .withChild(augmentationBuilder().withNodeIdentifier(aug1Id) - .withChild(choiceBuilder().withNodeIdentifier(augmentChoice1Id) - .withChild(augmentationBuilder().withNodeIdentifier(aug2Id) - .withChild(choiceBuilder().withNodeIdentifier(augmentChoice2Id) - .withChild(containerBuilder().withNodeIdentifier(containerId) - .withChild(leafNode(leafQName, "leaf-value")) - .build()) - .build()) - .build()) - .build()) - .build()).build(); - - final JsonParserStream jsonParser = JsonParserStream.create(streamWriter, schemaContext); - jsonParser.parse(new JsonReader(new StringReader(inputJson))); - final NormalizedNode transformedInput = result.getResult(); - assertNotNull(transformedInput); - assertEquals(cont1Normalized, transformedInput); - } - - private static void verifyTransformationToNormalizedNode(final String inputJson, - final NormalizedNode awaitedStructure) { - final NormalizedNodeResult result = new NormalizedNodeResult(); - final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result); - final JsonParserStream jsonParser = JsonParserStream.create(streamWriter, schemaContext); - jsonParser.parse(new JsonReader(new StringReader(inputJson))); - final NormalizedNode transformedInput = result.getResult(); - assertEquals("Transformation of json input to normalized node wasn't successful.", awaitedStructure, - transformedInput); - } - -} diff --git a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/retest/NormalizedNodeToJsonStreamTest.java b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/retest/NormalizedNodeToJsonStreamTest.java deleted file mode 100644 index 58480a731a..0000000000 --- a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/retest/NormalizedNodeToJsonStreamTest.java +++ /dev/null @@ -1,425 +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.data.codec.gson.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.yang.data.codec.gson.retest.TestUtils.childArray; -import static org.opendaylight.yangtools.yang.data.codec.gson.retest.TestUtils.childPrimitive; -import static org.opendaylight.yangtools.yang.data.codec.gson.retest.TestUtils.loadModules; -import static org.opendaylight.yangtools.yang.data.codec.gson.retest.TestUtils.resolveCont1; -import com.google.common.collect.Sets; -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonNull; -import com.google.gson.JsonObject; -import com.google.gson.JsonPrimitive; -import java.io.IOException; -import java.io.StringWriter; -import java.io.Writer; -import java.net.URISyntaxException; -import java.util.HashSet; -import java.util.Iterator; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; -import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode; -import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; -import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter; -import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeWriter; -import org.opendaylight.yangtools.yang.data.codec.gson.JSONCodecFactory; -import org.opendaylight.yangtools.yang.data.codec.gson.JSONNormalizedNodeStreamWriter; -import org.opendaylight.yangtools.yang.data.codec.gson.JsonWriterFactory; -import org.opendaylight.yangtools.yang.data.impl.schema.Builders; -import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.model.api.SchemaPath; -import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; - -/** - * Each test tests whether json output obtained after transformation contains is corect. The transformation takes - * normalized node data structure and transform it to json output. To make it easier validate json output it is loaded - * via gson as structure of json elements which are walked and compared with awaited values. - * - */ -public class NormalizedNodeToJsonStreamTest { - - private static final QName CONT_1 = QName.create("ns:complex:json", "2014-08-11", "cont1"); - private static final QName EMPTY_LEAF = QName.create(CONT_1, "empty"); - private static SchemaContext schemaContext; - - public interface JsonValidator { - void validate(final String jsonOutput); - } - - @BeforeClass - public static void initialization() throws IOException, URISyntaxException, ReactorException { - schemaContext = loadModules("/complexjson/yang"); - } - - /** - * case when anyxml contains simple value will be implemented when anyxml normalized node reprezentation will be - * specified - */ - @Ignore - @Test - public void anyXmlNodeWithSimpleValueInContainer() throws IOException, URISyntaxException { - - } - - /** - * case when anyxml contains complex xml will be implemented when anyxml normalized node reprezentation will be - * specified - */ - @Ignore - @Test - public void anyXmlNodeWithCompositeValueInContainer() throws IOException, URISyntaxException { - - } - - @Test - public void leafNodeInContainer() throws IOException, URISyntaxException { - final Writer writer = new StringWriter(); - final NormalizedNode leafNodeInContainer = TestingNormalizedNodeStructuresCreator.leafNodeInContainer(); - final String jsonOutput = normalizedNodeToJsonStreamTransformation(writer, leafNodeInContainer); - new JsonValidator() { - - @Override - public void validate(final String jsonOutput) { - final JsonObject cont1 = resolveCont1(jsonOutput); - assertNotNull(cont1); - - final JsonPrimitive lf11 = childPrimitive(cont1, "complexjson:lf11", "lf11"); - assertNotNull(lf11); - final int asInt = lf11.getAsInt(); - assertEquals(453, asInt); - } - }.validate(jsonOutput); - - } - - @Test - public void leafListNodeInContainerMultiline() throws IOException, URISyntaxException { - final Writer writer = new StringWriter(); - final NormalizedNode leafListNodeInContainer = TestingNormalizedNodeStructuresCreator - .leafListNodeInContainerMultiline(); - final String jsonOutput = normalizedNodeToJsonStreamTransformation(writer, leafListNodeInContainer); - new JsonValidator() { - - @Override - public void validate(final String jsonOutput) { - final JsonObject cont1 = resolveCont1(jsonOutput); - assertNotNull(cont1); - final JsonArray lflst11 = childArray(cont1, "complexjson:lflst11", "lflst11"); - assertNotNull(lflst11); - - final HashSet lflst11Values = Sets.newHashSet(); - for (final JsonElement jsonElement : lflst11) { - assertTrue(jsonElement instanceof JsonPrimitive); - lflst11Values.add(((JsonPrimitive) jsonElement).getAsString()); - } - - assertEquals(Sets.newHashSet("lflst11 value2\r\nanother line 2", "lflst11 value1\nanother line 1"), - lflst11Values); - } - }.validate(jsonOutput); - - } - - @Test - public void leafNodeViaAugmentationInContainer() throws IOException, URISyntaxException { - final Writer writer = new StringWriter(); - final NormalizedNode leafNodeViaAugmentationInContainer = TestingNormalizedNodeStructuresCreator - .leafNodeViaAugmentationInContainer(); - final String jsonOutput = normalizedNodeToJsonStreamTransformation(writer, leafNodeViaAugmentationInContainer); - new JsonValidator() { - - @Override - public void validate(final String jsonOutput) { - final JsonObject cont1 = resolveCont1(jsonOutput); - assertNotNull(cont1); - - final JsonPrimitive lf12_1 = childPrimitive(cont1, "complexjson:lf12_1", "lf12_1"); - assertNotNull(lf12_1); - final String asString = lf12_1.getAsString(); - assertEquals("lf12 value", asString); - } - }.validate(jsonOutput); - - } - - @Test - public void leafListNodeInContainer() throws IOException, URISyntaxException { - final Writer writer = new StringWriter(); - final NormalizedNode leafListNodeInContainer = TestingNormalizedNodeStructuresCreator - .leafListNodeInContainer(); - final String jsonOutput = normalizedNodeToJsonStreamTransformation(writer, leafListNodeInContainer); - new JsonValidator() { - - @Override - public void validate(final String jsonOutput) { - final JsonObject cont1 = resolveCont1(jsonOutput); - assertNotNull(cont1); - final JsonArray lflst11 = childArray(cont1, "complexjson:lflst11", "lflst11"); - assertNotNull(lflst11); - - final HashSet lflst11Values = Sets.newHashSet(); - for (final JsonElement jsonElement : lflst11) { - assertTrue(jsonElement instanceof JsonPrimitive); - lflst11Values.add(((JsonPrimitive) jsonElement).getAsString()); - } - - assertEquals(Sets.newHashSet("lflst11 value2", "lflst11 value1"), lflst11Values); - } - }.validate(jsonOutput); - } - - @Test - public void keyedListNodeInContainer() throws IOException, URISyntaxException { - final Writer writer = new StringWriter(); - final NormalizedNode keyedListNodeInContainer = TestingNormalizedNodeStructuresCreator - .keyedListNodeInContainer(); - final String jsonOutput = normalizedNodeToJsonStreamTransformation(writer, keyedListNodeInContainer); - new JsonValidator() { - - @Override - public void validate(final String jsonOutput) { - final JsonObject cont1 = resolveCont1(jsonOutput); - assertNotNull(cont1); - final JsonArray lst11 = childArray(cont1, "complexjson:lst11", "lst11"); - assertNotNull(lst11); - - final Iterator iterator = lst11.iterator(); - assertTrue(iterator.hasNext()); - final JsonElement lst11Entry1Raw = iterator.next(); - assertFalse(iterator.hasNext()); - assertTrue(lst11Entry1Raw instanceof JsonObject); - final JsonObject lst11Entry1 = (JsonObject) lst11Entry1Raw; - - final JsonPrimitive key111 = childPrimitive(lst11Entry1, "complexjson:key111", "key111"); - assertNotNull(key111); - final JsonPrimitive lf112 = childPrimitive(lst11Entry1, "complexjson:lf112", "lf112"); - assertNotNull(lf112); - final JsonPrimitive lf113 = childPrimitive(lst11Entry1, "complexjson:lf113", "lf113"); - assertNotNull(lf113); - final JsonPrimitive lf111 = childPrimitive(lst11Entry1, "complexjson:lf111", "lf111"); - assertNotNull(lf111); - - assertEquals("key111 value", key111.getAsString()); - assertEquals("/complexjson:cont1/complexjson:lflst11[.='foo']", lf112.getAsString()); - assertEquals("lf113 value", lf113.getAsString()); - assertEquals("lf111 value", lf111.getAsString()); - } - }.validate(jsonOutput); - } - - @Test - public void choiceNodeInContainer() throws IOException, URISyntaxException { - final Writer writer = new StringWriter(); - final NormalizedNode choiceNodeInContainer = TestingNormalizedNodeStructuresCreator - .choiceNodeInContainer(); - final String jsonOutput = normalizedNodeToJsonStreamTransformation(writer, choiceNodeInContainer); - new JsonValidator() { - - @Override - public void validate(final String jsonOutput) { - final JsonObject cont1 = resolveCont1(jsonOutput); - assertNotNull(cont1); - final JsonPrimitive lf13 = childPrimitive(cont1, "complexjson:lf13", "lf13"); - assertNotNull(lf13); - - assertEquals("lf13 value", lf13.getAsString()); - } - }.validate(jsonOutput); - } - - /** - * tested case when case c11A in choice choc11 is augmented (two leaves (augment A) and one leaf (augment B) are - * added) - * - * after running this test following exception is raised - * - * java.lang.IllegalArgumentException: Augmentation allowed only in DataNodeContainer - * [ChoiceNodeImpl[qname=(ns:complex:json?revision=2014-08-11)choc11]] - * - */ - // @Ignore - @Test - public void caseNodeAugmentationInChoiceInContainer() throws IOException, URISyntaxException { - final Writer writer = new StringWriter(); - final NormalizedNode caseNodeAugmentationInChoiceInContainer = TestingNormalizedNodeStructuresCreator - .caseNodeAugmentationInChoiceInContainer(); - final String jsonOutput = normalizedNodeToJsonStreamTransformation(writer, - caseNodeAugmentationInChoiceInContainer); - new JsonValidator() { - - @Override - public void validate(final String jsonOutput) { - final JsonObject cont1 = resolveCont1(jsonOutput); - assertNotNull(cont1); - - final JsonPrimitive lf15_21 = childPrimitive(cont1, "complexjson:lf15_21", "lf15_21"); - assertNotNull(lf15_21); - final JsonPrimitive lf13 = childPrimitive(cont1, "complexjson:lf13", "lf13"); - assertNotNull(lf13); - final JsonPrimitive lf15_11 = childPrimitive(cont1, "complexjson:lf15_11", "lf15_11"); - assertNotNull(lf15_11); - final JsonPrimitive lf15_12 = childPrimitive(cont1, "complexjson:lf15_12", "lf15_12"); - assertNotNull(lf15_12); - - assertEquals("lf15_21 value", lf15_21.getAsString()); - assertEquals("lf13 value", lf13.getAsString()); - assertTrue("one two".equals(lf15_11.getAsString()) || "two one".equals(lf15_11.getAsString())); - assertEquals("complexjson:lf11", lf15_12.getAsString()); - - } - }.validate(jsonOutput); - } - - /** - * tested case when case c11A in choice choc11 is augmented (two leaves (augment A) internally and one two leaves - * with the same names externally (augment B) are added) - * - * after running this test following exception is raised - * - * java.lang.IllegalArgumentException: Augmentation allowed only in DataNodeContainer - * [ChoiceNodeImpl[qname=(ns:complex:json?revision=2014-08-11)choc11]] - * - */ - // @Ignore - @Test - public void caseNodeExternalAugmentationInChoiceInContainer() throws IOException, URISyntaxException { - final Writer writer = new StringWriter(); - final NormalizedNode caseNodeExternalAugmentationInChoiceInContainer = TestingNormalizedNodeStructuresCreator - .caseNodeExternalAugmentationInChoiceInContainer(); - final String jsonOutput = normalizedNodeToJsonStreamTransformation(writer, - caseNodeExternalAugmentationInChoiceInContainer); - new JsonValidator() { - - @Override - public void validate(final String jsonOutput) { - final JsonObject cont1 = resolveCont1(jsonOutput); - assertNotNull(cont1); - - final JsonPrimitive lf15_11Augment = childPrimitive(cont1, "complexjson-augmentation:lf15_11"); - assertNotNull(lf15_11Augment); - final JsonPrimitive lf15_12Augment = childPrimitive(cont1, "complexjson-augmentation:lf15_12"); - assertNotNull(lf15_12Augment); - final JsonPrimitive lf13 = childPrimitive(cont1, "complexjson:lf13", "lf13"); - assertNotNull(lf13); - final JsonPrimitive lf15_11 = childPrimitive(cont1, "complexjson:lf15_11", "lf15_11"); - assertNotNull(lf15_11); - final JsonPrimitive lf15_12 = childPrimitive(cont1, "complexjson:lf15_12", "lf15_12"); - assertNotNull(lf15_12); - - assertEquals("lf15_11 value from augmentation", lf15_11Augment.getAsString()); - assertEquals("lf15_12 value from augmentation", lf15_12Augment.getAsString()); - assertEquals("lf13 value", lf13.getAsString()); - assertTrue("one two".equals(lf15_11.getAsString()) || "two one".equals(lf15_11.getAsString())); - assertEquals("complexjson:lf11", lf15_12.getAsString()); - - } - }.validate(jsonOutput); - } - - /** - * augmentation of choice - adding new case - * - * after running this test following exception is raised - * - * java.lang.IllegalArgumentException: Augmentation allowed only in DataNodeContainer - * [ChoiceNodeImpl[qname=(ns:complex:json?revision=2014-08-11)choc11]] - * - */ - // @Ignore - @Test - public void choiceNodeAugmentationInContainer() throws IOException, URISyntaxException { - final Writer writer = new StringWriter(); - final NormalizedNode choiceNodeAugmentationInContainer = TestingNormalizedNodeStructuresCreator - .choiceNodeAugmentationInContainer(); - final String jsonOutput = normalizedNodeToJsonStreamTransformation(writer, choiceNodeAugmentationInContainer); - new JsonValidator() { - - @Override - public void validate(final String jsonOutput) { - final JsonObject cont1 = resolveCont1(jsonOutput); - assertNotNull(cont1); - - final JsonPrimitive lf17 = childPrimitive(cont1, "complexjson:lf17", "lf17"); - assertNotNull(lf17); - assertEquals("lf17 value", lf17.getAsString()); - } - }.validate(jsonOutput); - } - - @Test - public void unkeyedNodeInContainer() throws IOException, URISyntaxException { - final Writer writer = new StringWriter(); - final NormalizedNode unkeyedNodeInContainer = TestingNormalizedNodeStructuresCreator - .unkeyedNodeInContainer(); - final String jsonOutput = normalizedNodeToJsonStreamTransformation(writer, unkeyedNodeInContainer); - new JsonValidator() { - - @Override - public void validate(final String jsonOutput) { - final JsonObject cont1 = resolveCont1(jsonOutput); - assertNotNull(cont1); - - final JsonArray lst12 = childArray(cont1, "complexjson:lst12", "lst12"); - assertNotNull(lst12); - - final Iterator iterator = lst12.iterator(); - assertTrue(iterator.hasNext()); - final JsonElement lst12Entry1Raw = iterator.next(); - assertFalse(iterator.hasNext()); - - assertTrue(lst12Entry1Raw instanceof JsonObject); - final JsonObject lst12Entry1 = (JsonObject) lst12Entry1Raw; - final JsonPrimitive lf121 = childPrimitive(lst12Entry1, "complexjson:lf121", "lf121"); - assertNotNull(lf121); - - assertEquals("lf121 value", lf121.getAsString()); - - } - }.validate(jsonOutput); - - } - - @Test - public void emptyTypeTest() throws IOException, URISyntaxException { - final StringWriter writer = new StringWriter(); - final ContainerNode emptyStructure = Builders.containerBuilder() - .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(CONT_1)) - .addChild(ImmutableNodes.leafNode(EMPTY_LEAF, null)).build(); - final String jsonOutput = normalizedNodeToJsonStreamTransformation(writer, emptyStructure); - final JsonObject cont1 = resolveCont1(jsonOutput); - final JsonElement emptyObj = cont1.get("empty"); - assertNotNull(emptyObj); - assertTrue(emptyObj instanceof JsonArray); - assertEquals(1, emptyObj.getAsJsonArray().size()); - assertTrue(emptyObj.getAsJsonArray().get(0) instanceof JsonNull); - } - - private static String normalizedNodeToJsonStreamTransformation(final Writer writer, - final NormalizedNode inputStructure) throws IOException { - - final NormalizedNodeStreamWriter jsonStream = JSONNormalizedNodeStreamWriter. - createExclusiveWriter(JSONCodecFactory.create(schemaContext), SchemaPath.ROOT, null, - JsonWriterFactory.createJsonWriter(writer, 2)); - final NormalizedNodeWriter nodeWriter = NormalizedNodeWriter.forStreamWriter(jsonStream); - nodeWriter.write(inputStructure); - - nodeWriter.close(); - return writer.toString(); - } - -} diff --git a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/retest/RetestUtils.java b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/retest/RetestUtils.java deleted file mode 100644 index 92e20a2bdc..0000000000 --- a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/retest/RetestUtils.java +++ /dev/null @@ -1,65 +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.data.codec.gson.retest; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.InputStream; -import java.util.Collection; -import java.util.List; - -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; -import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource; -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 RetestUtils { - - private RetestUtils() { - throw new UnsupportedOperationException("Utility class"); - } - - public static SchemaContext parseYangSources(StatementStreamSource... sources) - throws SourceException, ReactorException { - - CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR - .newBuild(); - reactor.addSources(sources); - - return reactor.buildEffective(); - } - - public static SchemaContext parseYangSources(File... files) throws SourceException, ReactorException, FileNotFoundException { - - StatementStreamSource[] sources = new StatementStreamSource[files.length]; - - for(int i = 0; i files) throws SourceException, ReactorException, FileNotFoundException { - return parseYangSources(files.toArray(new File[files.size()])); - } - - - public static SchemaContext parseYangStreams(List streams) - throws SourceException, ReactorException { - - CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR - .newBuild(); - return reactor.buildEffective(streams); - } -} diff --git a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/retest/StreamToNormalizedNodeTest.java b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/retest/StreamToNormalizedNodeTest.java deleted file mode 100644 index d19c7aab5c..0000000000 --- a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/retest/StreamToNormalizedNodeTest.java +++ /dev/null @@ -1,126 +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.data.codec.gson.retest; - -import static org.opendaylight.yangtools.yang.data.codec.gson.retest.TestUtils.loadModules; -import static org.opendaylight.yangtools.yang.data.codec.gson.retest.TestUtils.loadTextFile; - -import org.opendaylight.yangtools.yang.data.codec.gson.JSONCodecFactory; -import org.opendaylight.yangtools.yang.data.codec.gson.JsonWriterFactory; -import org.opendaylight.yangtools.yang.model.api.SchemaPath; - -import com.google.gson.stream.JsonReader; -import java.io.File; -import java.io.IOException; -import java.io.StringReader; -import java.io.StringWriter; -import java.net.URISyntaxException; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; -import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument; -import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild; -import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; -import org.opendaylight.yangtools.yang.data.api.schema.stream.LoggingNormalizedNodeStreamWriter; -import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter; -import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeWriter; -import org.opendaylight.yangtools.yang.data.codec.gson.JSONNormalizedNodeStreamWriter; -import org.opendaylight.yangtools.yang.data.codec.gson.JsonParserStream; -import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNormalizedNodeStreamWriter; -import org.opendaylight.yangtools.yang.data.impl.schema.NormalizedNodeResult; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class StreamToNormalizedNodeTest { - private static final Logger LOG = LoggerFactory.getLogger(StreamToNormalizedNodeTest.class); - private static SchemaContext schemaContext; - private static String streamAsString; - - @BeforeClass - public static void initialization() throws IOException, URISyntaxException, ReactorException { - schemaContext = loadModules("/complexjson/yang"); - streamAsString = loadTextFile(new File(StreamToNormalizedNodeTest.class.getResource( - "/complexjson/complex-json.json").toURI())); - } - - /** - * Demonstrates how to log events produced by a {@link JsonReader}. - * - * @throws IOException - */ - @Test - public void ownStreamWriterImplementationDemonstration() throws IOException { - // GSON's JsonReader reading from the loaded string (our event source) - final JsonReader reader = new JsonReader(new StringReader(streamAsString)); - - // StreamWriter which outputs SLF4J events - final LoggingNormalizedNodeStreamWriter logWriter = new LoggingNormalizedNodeStreamWriter(); - - // JSON -> StreamWriter parser - try (final JsonParserStream jsonHandler = JsonParserStream.create(logWriter, schemaContext)) { - // Process multiple readers, flush()/close() as needed - jsonHandler.parse(reader); - } - } - - /** - * Demonstrates how to create an immutable NormalizedNode tree from a {@link JsonReader} and - * then writes the data back into string representation. - * - * @throws IOException - */ - @Ignore - @Test - public void immutableNormalizedNodeStreamWriterDemonstration() throws IOException { - /* - * This is the parsing part - */ - // This is where we will output the nodes - NormalizedNodeResult result = new NormalizedNodeResult(); - - // StreamWriter which attaches NormalizedNode under parent - final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result); - - // JSON -> StreamWriter parser - try (JsonParserStream handler = JsonParserStream.create(streamWriter, schemaContext)) { - handler.parse(new JsonReader(new StringReader(streamAsString))); - } - - // Finally build the node - final NormalizedNode parsedData = result.getResult(); - LOG.debug("Parsed NormalizedNodes: {}", parsedData); - - /* - * This is the serialization part. - */ - // We want to write the first child out - final DataContainerChild firstChild = (DataContainerChild) parsedData; - LOG.debug("Serializing first child: {}", firstChild); - - // String holder - final StringWriter writer = new StringWriter(); - - // StreamWriter which outputs JSON strings - // StreamWriter which outputs JSON strings - final NormalizedNodeStreamWriter jsonStream = JSONNormalizedNodeStreamWriter. - createExclusiveWriter(JSONCodecFactory.create(schemaContext), SchemaPath.ROOT, null, - JsonWriterFactory.createJsonWriter(writer, 2)); - - // NormalizedNode -> StreamWriter - final NormalizedNodeWriter nodeWriter = NormalizedNodeWriter.forStreamWriter(jsonStream); - - // Write multiple NormalizedNodes fluently, flush()/close() as needed - nodeWriter.write(firstChild).close(); - - // Just to put it somewhere - LOG.debug("Serialized JSON: {}", writer.toString()); - } - -} diff --git a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/retest/TestUtils.java b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/retest/TestUtils.java deleted file mode 100644 index ed539d785a..0000000000 --- a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/retest/TestUtils.java +++ /dev/null @@ -1,106 +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.data.codec.gson.retest; - -import static org.junit.Assert.assertTrue; -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; -import com.google.gson.JsonPrimitive; -import java.io.BufferedReader; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileReader; -import java.io.IOException; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.ArrayList; -import java.util.List; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; - -public class TestUtils { - - private TestUtils() { - } - - static SchemaContext loadModules(final String resourceDirectory) throws IOException, URISyntaxException, - ReactorException { - URI path = StreamToNormalizedNodeTest.class.getResource(resourceDirectory).toURI(); - final File testDir = new File(path); - final String[] fileList = testDir.list(); - final List testFiles = new ArrayList<>(); - if (fileList == null) { - throw new FileNotFoundException(resourceDirectory); - } - for (String fileName : fileList) { - if (!new File(testDir, fileName).isDirectory()) { - testFiles.add(new File(testDir, fileName)); - } - } - return RetestUtils.parseYangSources(testFiles); - } - - static String loadTextFile(final File file) throws IOException { - FileReader fileReader = new FileReader(file); - BufferedReader bufReader = new BufferedReader(fileReader); - - String line = null; - StringBuilder result = new StringBuilder(); - while ((line = bufReader.readLine()) != null) { - result.append(line); - } - bufReader.close(); - return result.toString(); - } - - static String loadTextFile(final String relativePath) throws IOException, URISyntaxException { - return loadTextFile(new File(TestUtils.class.getResource(relativePath).toURI())); - } - - static JsonObject childObject(final JsonObject jsonObject, final String... names) { - for (String name : names) { - JsonObject childJsonObject = jsonObject.getAsJsonObject(name); - if (childJsonObject != null) { - return childJsonObject; - } - } - return null; - } - - static JsonPrimitive childPrimitive(final JsonObject jsonObject, final String... names) { - for (String name : names) { - JsonPrimitive childJsonPrimitive = jsonObject.getAsJsonPrimitive(name); - if (childJsonPrimitive != null) { - return childJsonPrimitive; - } - } - return null; - } - - static JsonArray childArray(final JsonObject jsonObject, final String... names) { - for (String name : names) { - JsonArray childJsonArray = jsonObject.getAsJsonArray(name); - if (childJsonArray != null) { - return childJsonArray; - } - } - return null; - } - - static JsonObject resolveCont1(String jsonOutput) { - JsonParser parser = new JsonParser(); - JsonElement rootElement = parser.parse(jsonOutput); - assertTrue(rootElement.isJsonObject()); - JsonObject rootObject = rootElement.getAsJsonObject(); - JsonObject cont1 = childObject(rootObject, "complexjson:cont1", "cont1"); - return cont1; - } - -} diff --git a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/retest/TestingNormalizedNodeStructuresCreator.java b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/retest/TestingNormalizedNodeStructuresCreator.java deleted file mode 100644 index 52f7bd7a84..0000000000 --- a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/retest/TestingNormalizedNodeStructuresCreator.java +++ /dev/null @@ -1,297 +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.data.codec.gson.retest; - -import com.google.common.collect.Lists; -import com.google.common.collect.Sets; -import java.util.HashMap; -import java.util.Map; -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; -import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier; -import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier; -import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates; -import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue; -import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument; -import org.opendaylight.yangtools.yang.data.api.schema.AugmentationNode; -import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode; -import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode; -import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild; -import org.opendaylight.yangtools.yang.data.api.schema.LeafNode; -import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode; -import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode; -import org.opendaylight.yangtools.yang.data.api.schema.MapNode; -import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; -import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode; -import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode; -import org.opendaylight.yangtools.yang.data.impl.schema.Builders; -import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.CollectionNodeBuilder; -import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeAttrBuilder; -import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder; -import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.ListNodeBuilder; - -public class TestingNormalizedNodeStructuresCreator { - - @SafeVarargs - static NormalizedNode cont1Node( - final DataContainerChild... children) { - DataContainerNodeAttrBuilder cont1 = Builders.containerBuilder(); - cont1.withNodeIdentifier(new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "cont1"))); - - cont1.withValue(Lists.newArrayList(children)); - return cont1.build(); - } - - private static DataContainerChild lst12Node() { - CollectionNodeBuilder lst12Builder = Builders.unkeyedListBuilder() - .withNodeIdentifier(new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "lst12"))); - lst12Builder.withChild(lst12Entry1Node()); - return lst12Builder.build(); - } - - private static UnkeyedListEntryNode lst12Entry1Node() { - DataContainerNodeAttrBuilder lst12Entry1Builder = Builders - .unkeyedListEntryBuilder(); - lst12Entry1Builder - .withNodeIdentifier(new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "lst12"))); - lst12Entry1Builder.withChild(Builders.leafBuilder() - .withNodeIdentifier(new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "lf121"))) - .withValue("lf121 value").build()); - return lst12Entry1Builder.build(); - } - - private static DataContainerChild choc12Node() { - DataContainerNodeBuilder choc12Builder = Builders.choiceBuilder() - .withNodeIdentifier(new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "choc12"))); - - choc12Builder.withChild(lf17Node()); - return choc12Builder.build(); - } - - protected static LeafNode lf17Node() { - return Builders.leafBuilder() - .withNodeIdentifier(new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "lf17"))) - .withValue("lf17 value").build(); - } - - private static DataContainerChild externalAugmentC11AWithLf15_11AndLf15_12Node() { - DataContainerNodeBuilder augmentationBuilder = Builders - .augmentationBuilder(); - augmentationBuilder.withNodeIdentifier(new AugmentationIdentifier(Sets.newHashSet( - QName.create("ns:complex:json:augmentation", "2014-08-14", "lf15_11"), - QName.create("ns:complex:json:augmentation", "2014-08-14", "lf15_12")))); - augmentationBuilder.withChild(lf15_11NodeExternal()); - augmentationBuilder.withChild(lf15_12NodeExternal()); - return augmentationBuilder.build(); - } - - private static LeafNode lf15_12NodeExternal() { - return Builders - .leafBuilder() - .withNodeIdentifier( - new NodeIdentifier(QName.create("ns:complex:json:augmentation", "2014-08-14", "lf15_12"))) - .withValue("lf15_12 value from augmentation").build(); - } - - private static LeafNode lf15_11NodeExternal() { - return Builders - .leafBuilder() - .withNodeIdentifier( - new NodeIdentifier(QName.create("ns:complex:json:augmentation", "2014-08-14", "lf15_11"))) - .withValue("lf15_11 value from augmentation").build(); - } - - @SafeVarargs - private static DataContainerChild choc11Node( - final DataContainerChild... children) { - DataContainerNodeBuilder choc11Builder = Builders.choiceBuilder() - .withNodeIdentifier(new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "choc11"))); - choc11Builder.withValue(Lists.newArrayList(children)); - // choc11Builder.addChild(lf13Node()); - // choc11Builder.addChild(augmentChoc11_c11A_lf1511AndLf1512Children()); - // choc11Builder.addChild(augmentChoc11_c11_lf1521Children()); - return choc11Builder.build(); - } - - private static LeafNode lf13Node() { - return Builders.leafBuilder() - .withNodeIdentifier(new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "lf13"))) - .withValue("lf13 value").build(); - } - - private static DataContainerChild augmentC11AWithLf15_21Node() { - DataContainerNodeBuilder choc11_c11AugmentBuilder = Builders - .augmentationBuilder(); - choc11_c11AugmentBuilder.withNodeIdentifier(new AugmentationIdentifier(Sets.newHashSet(QName.create( - "ns:complex:json", "2014-08-11", "lf15_21")))); - - choc11_c11AugmentBuilder.withChild(lf15_21Node()); - return choc11_c11AugmentBuilder.build(); - } - - private static LeafNode lf15_21Node() { - return Builders.leafBuilder() - .withNodeIdentifier(new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "lf15_21"))) - .withValue("lf15_21 value").build(); - } - - private static DataContainerChild augmentC11AWithLf15_11AndLf15_12Node() { - DataContainerNodeBuilder choc11_c11AugmentBuilder = Builders - .augmentationBuilder(); - choc11_c11AugmentBuilder.withNodeIdentifier(new AugmentationIdentifier(Sets.newHashSet( - QName.create("ns:complex:json", "2014-08-11", "lf15_11"), - QName.create("ns:complex:json", "2014-08-11", "lf15_12")))); - choc11_c11AugmentBuilder.withChild(lf15_11Node()); - choc11_c11AugmentBuilder.withChild(lf15_12Node()); - return choc11_c11AugmentBuilder.build(); - } - - private static LeafNode lf15_12Node() { - return Builders.leafBuilder() - .withNodeIdentifier(new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "lf15_12"))) - .withValue(QName.create("ns:complex:json", "2014-08-11", "lf11")).build(); - } - - private static LeafNode lf15_11Node() { - return Builders.leafBuilder() - .withNodeIdentifier(new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "lf15_11"))) - .withValue(Sets.newHashSet("one", "two")).build(); - } - - private static DataContainerChild lf12_1Node() { - DataContainerNodeBuilder augmentBuilder = Builders - .augmentationBuilder().withNodeIdentifier( - new AugmentationIdentifier(Sets.newHashSet( - QName.create("ns:complex:json", "2014-08-11", "lf12_1"), - QName.create("ns:complex:json", "2014-08-11", "lf12_2")))); - augmentBuilder.withChild(Builders.leafBuilder() - .withNodeIdentifier(new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "lf12_1"))) - .withValue("lf12 value").build()); - return augmentBuilder.build(); - } - - private static DataContainerChild childLst11() { - CollectionNodeBuilder lst11 = Builders.mapBuilder().withNodeIdentifier( - new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "lst11"))); - - DataContainerNodeAttrBuilder lst11Entry1Builder = Builders - .mapEntryBuilder(); - - Map key = new HashMap<>(); - key.put(QName.create("ns:complex:json", "2014-08-11", "key111"), "key111 value"); - key.put(QName.create("ns:complex:json", "2014-08-11", "lf111"), "lf111 value"); - - lst11Entry1Builder.withNodeIdentifier(new NodeIdentifierWithPredicates(QName.create("ns:complex:json", - "2014-08-11", "lst11"), key)); - lst11Entry1Builder.withChild(Builders.leafBuilder() - .withNodeIdentifier(new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "key111"))) - .withValue("key111 value").build()); - lst11Entry1Builder.withChild(Builders.leafBuilder() - .withNodeIdentifier(new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "lf112"))) - .withValue(lf112Value()).build()); - lst11Entry1Builder.withChild(Builders.leafBuilder() - .withNodeIdentifier(new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "lf113"))) - .withValue("lf113 value").build()); - lst11Entry1Builder.withChild(Builders.leafBuilder() - .withNodeIdentifier(new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "lf111"))) - .withValue("lf111 value").build()); - lst11.withChild(lst11Entry1Builder.build()); - return lst11.build(); - } - - private static Object lf112Value() { - return YangInstanceIdentifier.create( - new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "cont1")), - new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "lflst11")), - new NodeWithValue<>(QName.create("ns:complex:json", "2014-08-11", "lflst11"),"foo") - ); - } - - private static DataContainerChild childLflst11() { - ListNodeBuilder> lflst11 = Builders.leafSetBuilder().withNodeIdentifier( - new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "lflst11"))); - lflst11.withChild(Builders - .leafSetEntryBuilder() - .withNodeIdentifier( - new NodeWithValue<>(QName.create("ns:complex:json", "2014-08-11", "lflst11"), "lflst11 value1")) - .withValue("lflst11 value1").build()); - lflst11.withChild(Builders - .leafSetEntryBuilder() - .withNodeIdentifier( - new NodeWithValue<>(QName.create("ns:complex:json", "2014-08-11", "lflst11"), "lflst11 value2")) - .withValue("lflst11 value2").build()); - return lflst11.build(); - } - - private static DataContainerChild childLflst11Multiline() { - ListNodeBuilder> lflst11 = Builders.leafSetBuilder().withNodeIdentifier( - new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "lflst11"))); - lflst11.withChild(Builders - .leafSetEntryBuilder() - .withNodeIdentifier( - new NodeWithValue<>(QName.create("ns:complex:json", "2014-08-11", "lflst11"), "lflst11 value1\nanother line 1")) - .withValue("lflst11 value1\nanother line 1").build()); - lflst11.withChild(Builders - .leafSetEntryBuilder() - .withNodeIdentifier( - new NodeWithValue<>(QName.create("ns:complex:json", "2014-08-11", "lflst11"), "lflst11 value2\r\nanother line 2")) - .withValue("lflst11 value2\r\nanother line 2").build()); - return lflst11.build(); - } - - public static NormalizedNode leafNodeInContainer() { - LeafNode lf11 = Builders.leafBuilder() - .withNodeIdentifier(new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "lf11"))) - .withValue(453).build(); - return cont1Node(lf11); - } - - public static NormalizedNode leafListNodeInContainer() { - return cont1Node(childLflst11()); - } - public static NormalizedNode leafListNodeInContainerMultiline() { - return cont1Node(childLflst11Multiline()); - } - - public static NormalizedNode keyedListNodeInContainer() { - return cont1Node(childLst11()); - } - - public static NormalizedNode leafNodeViaAugmentationInContainer() { - return cont1Node(lf12_1Node()); - } - - public static NormalizedNode choiceNodeInContainer() { - return cont1Node(choc11Node(lf13Node())); - } - - /** - * choc11 contains lf13, lf15_11 and lf15_12 are added via external augmentation - * - * @return - */ - public static NormalizedNode caseNodeAugmentationInChoiceInContainer() { - return cont1Node(choc11Node(augmentC11AWithLf15_11AndLf15_12Node(), lf13Node(), augmentC11AWithLf15_21Node())); - } - - public static NormalizedNode caseNodeExternalAugmentationInChoiceInContainer() { - return cont1Node(choc11Node(lf13Node(), augmentC11AWithLf15_11AndLf15_12Node(), externalAugmentC11AWithLf15_11AndLf15_12Node())); - } - - public static NormalizedNode choiceNodeAugmentationInContainer() { - return cont1Node(choc12Node()); - } - - public static NormalizedNode unkeyedNodeInContainer() { - return cont1Node(lst12Node()); - } - - public static NormalizedNode topLevelContainer() { - return cont1Node(); - } -} diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/RetestUtils.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/TestUtils.java similarity index 97% rename from yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/RetestUtils.java rename to yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/TestUtils.java index 9e68b4e997..a09f17d4a2 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/RetestUtils.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/TestUtils.java @@ -22,9 +22,9 @@ import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementR import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline; import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl; -public class RetestUtils { +public class TestUtils { - private RetestUtils() { + private TestUtils() { throw new UnsupportedOperationException("Utility class"); } diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/xml/Bug2964Test.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/xml/Bug2964Test.java index 3cf1b9b6a1..3ab0ecc038 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/xml/Bug2964Test.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/xml/Bug2964Test.java @@ -1,39 +1,43 @@ +/* + * 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.data.impl.codec.xml; +import static org.hamcrest.CoreMatchers.instanceOf; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThat; import com.google.common.base.Charsets; -import com.google.common.collect.Lists; -import com.google.common.io.ByteSource; +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; import org.junit.Before; import org.junit.Test; import org.opendaylight.yangtools.yang.common.QName; +import org.opendaylight.yangtools.yang.data.impl.TestUtils; import org.opendaylight.yangtools.yang.data.impl.schema.transform.dom.DomUtils; import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode; import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; 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.parser.impl.YangParserImpl; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.xml.sax.SAXException; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.net.URI; - -import static org.hamcrest.CoreMatchers.instanceOf; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; - public class Bug2964Test { - public static final String XML_CONTENT = "\n" + - "test-identity\n" + - ""; + public static final String XML_CONTENT = "\n" + + "test-identity\n" + ""; private static final DocumentBuilderFactory BUILDERFACTORY; @@ -55,13 +59,8 @@ public class Bug2964Test { @Before public void setUp() throws Exception { - final ByteSource byteSource = new ByteSource() { - @Override - public InputStream openStream() throws IOException { - return Bug2964Test.this.getClass().getResourceAsStream("/leafref-test.yang"); - } - }; - schema = new YangParserImpl().parseSources(Lists.newArrayList(byteSource)); + File leafRefTestYang = new File(getClass().getResource("/leafref-test.yang").toURI()); + schema = TestUtils.parseYangSources(leafRefTestYang); } public static Document readXmlToDocument(final String xmlContent) throws SAXException, IOException { @@ -75,8 +74,7 @@ public class Bug2964Test { final Document document = readXmlToDocument(XML_CONTENT); final Element identityLeafRefElement = (Element) document.getDocumentElement().getFirstChild().getNextSibling(); - final Module leafrefModule = schema.findModuleByNamespaceAndRevision( - namespaceUri, null); + final Module leafrefModule = schema.findModuleByNamespaceAndRevision(namespaceUri, null); final ContainerSchemaNode cont2 = (ContainerSchemaNode) leafrefModule.getDataChildByName(CONT_2); final DataSchemaNode identityLeafRefSchema = cont2.getDataChildByName(IDENTITY_LEAFREF); final Object parsedValue = DomUtils.parseXmlValue(identityLeafRefElement, DomUtils.defaultValueCodecProvider(), diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/xml/InstanceIdentifierForXmlCodecTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/xml/InstanceIdentifierForXmlCodecTest.java index d6e412d4f3..935947f9f6 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/xml/InstanceIdentifierForXmlCodecTest.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/xml/InstanceIdentifierForXmlCodecTest.java @@ -19,7 +19,7 @@ import org.mockito.runners.MockitoJUnitRunner; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; -import org.opendaylight.yangtools.yang.data.impl.RetestUtils; +import org.opendaylight.yangtools.yang.data.impl.TestUtils; import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes; import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.w3c.dom.Document; @@ -40,7 +40,7 @@ public class InstanceIdentifierForXmlCodecTest { @Before public void setup() throws Exception { final File rpcTestYang = new File(getClass().getResource("iid-test.yang").toURI()); - this.schemaContext = RetestUtils.parseYangSources(rpcTestYang); + this.schemaContext = TestUtils.parseYangSources(rpcTestYang); final YangInstanceIdentifier.NodeIdentifier container = new YangInstanceIdentifier.NodeIdentifier( QName.create(InstanceIdentifierForXmlCodecTest.NS, InstanceIdentifierForXmlCodecTest.REVISION, "cont")); diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/xml/XmlDocumentUtilsTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/xml/XmlDocumentUtilsTest.java index 99a32465a1..dc86f82ea7 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/xml/XmlDocumentUtilsTest.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/xml/XmlDocumentUtilsTest.java @@ -33,7 +33,7 @@ import org.opendaylight.yangtools.yang.data.api.ModifyAction; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; -import org.opendaylight.yangtools.yang.data.impl.RetestUtils; +import org.opendaylight.yangtools.yang.data.impl.TestUtils; import org.opendaylight.yangtools.yang.data.impl.codec.TypeDefinitionAwareCodec; import org.opendaylight.yangtools.yang.data.impl.schema.Builders; import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes; @@ -80,7 +80,7 @@ public class XmlDocumentUtilsTest { final File rpcTestYang1 = new File(getClass().getResource("xml-doc-test.yang").toURI()); final File rpcTestYang2 = new File(getClass().getResource("xml-doc-test2.yang").toURI()); - this.schema = RetestUtils.parseYangSources(rpcTestYang1, rpcTestYang2); + this.schema = TestUtils.parseYangSources(rpcTestYang1, rpcTestYang2); } public static Document readXmlToDocument(final String xmlContent) throws SAXException, IOException { diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/xml/XmlStreamUtilsTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/xml/XmlStreamUtilsTest.java index 50dab8e3a2..a27595b32e 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/xml/XmlStreamUtilsTest.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/xml/XmlStreamUtilsTest.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, @@ -17,10 +17,10 @@ import com.google.common.base.Optional; import com.google.common.collect.Maps; import java.io.ByteArrayOutputStream; import java.io.File; +import java.io.FileNotFoundException; import java.net.URI; import java.net.URISyntaxException; import java.util.AbstractMap; -import java.util.Collections; import java.util.Date; import java.util.Map; import java.util.regex.Matcher; @@ -34,6 +34,7 @@ import org.junit.Ignore; import org.junit.Test; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.common.QNameModule; +import org.opendaylight.yangtools.yang.data.impl.TestUtils; import org.opendaylight.yangtools.yang.model.api.DataNodeContainer; import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode; @@ -44,7 +45,7 @@ import org.opendaylight.yangtools.yang.model.api.type.InstanceIdentifierTypeDefi import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition; import org.opendaylight.yangtools.yang.model.api.type.StringTypeDefinition; import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil; -import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl; +import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; import org.w3c.dom.Document; public class XmlStreamUtilsTest { @@ -55,21 +56,19 @@ public class XmlStreamUtilsTest { private static Module leafRefModule; @BeforeClass - public static void initialize() throws URISyntaxException { - final YangParserImpl yangParser = new YangParserImpl(); - final File file = new File(XmlStreamUtils.class.getResource("/leafref-test.yang").toURI()); - schemaContext = yangParser.parseFiles(Collections.singletonList(file)); + public static void initialize() throws URISyntaxException, FileNotFoundException, ReactorException { + final File file = new File(org.opendaylight.yangtools.yang.data.impl.codec.xml.retest.XmlStreamUtils.class.getResource("/leafref-test.yang").toURI()); + schemaContext = TestUtils.parseYangSources(file); assertNotNull(schemaContext); - assertEquals(1,schemaContext.getModules().size()); + assertEquals(1, schemaContext.getModules().size()); leafRefModule = schemaContext.getModules().iterator().next(); assertNotNull(leafRefModule); } - @Test public void testWriteAttribute() throws Exception { final ByteArrayOutputStream out = new ByteArrayOutputStream(); - final XMLStreamWriter writer = XML_OUTPUT_FACTORY.createXMLStreamWriter(out); + final XMLStreamWriter writer = XML_OUTPUT_FACTORY.createXMLStreamWriter(out); writer.writeStartElement("element"); QName name = getAttrQName("namespace", "2012-12-12", "attr", Optional.of("prefix")); @@ -92,7 +91,8 @@ public class XmlStreamUtilsTest { assertEquals(2, mappedPrefixes.size()); final String randomPrefixValue = mappedPrefixes.get("namespace2"); - final String expectedXmlAsString = ""; + final String expectedXmlAsString = ""; XMLUnit.setIgnoreAttributeOrder(true); final Document control = XMLUnit.buildControlDocument(expectedXmlAsString); @@ -106,7 +106,7 @@ public class XmlStreamUtilsTest { @Test public void testWriteIdentityRef() throws Exception { final ByteArrayOutputStream out = new ByteArrayOutputStream(); - final XMLStreamWriter writer = XML_OUTPUT_FACTORY.createXMLStreamWriter(out); + final XMLStreamWriter writer = XML_OUTPUT_FACTORY.createXMLStreamWriter(out); writer.writeStartElement("element"); final QNameModule parent = QNameModule.create(URI.create("parent:uri"), new Date()); @@ -149,7 +149,8 @@ public class XmlStreamUtilsTest { /** * Tests relative path with double point inside path (e. g. "../../lf:interface/../lf:cont2/lf:stringleaf") */ - @Ignore //ignored because this isn't implemented + @Ignore + // ignored because this isn't implemented @Test public void testLeafRefWithDoublePointInPath() { getTargetNodeForLeafRef("lf-with-double-point-inside", StringTypeDefinition.class); @@ -169,7 +170,8 @@ public class XmlStreamUtilsTest { assertNotNull(schemaNode); final LeafrefTypeDefinition leafrefTypedef = findLeafrefType(schemaNode); assertNotNull(leafrefTypedef); - final TypeDefinition targetBaseType = SchemaContextUtil.getBaseTypeForLeafRef(leafrefTypedef, schemaContext, schemaNode); + final TypeDefinition targetBaseType = SchemaContextUtil.getBaseTypeForLeafRef(leafrefTypedef, schemaContext, + schemaNode); assertTrue("Wrong class found.", clas.isInstance(targetBaseType)); return targetBaseType; } @@ -182,7 +184,8 @@ public class XmlStreamUtilsTest { return mappedPrefixes; } - private static QName getAttrQName(final String namespace, final String revision, final String localName, final Optional prefix) { + private static QName getAttrQName(final String namespace, final String revision, final String localName, + final Optional prefix) { if (prefix.isPresent()) { final QName moduleQName = QName.create(namespace, revision, "module"); final QNameModule module = QNameModule.create(moduleQName.getNamespace(), moduleQName.getRevision()); @@ -195,14 +198,15 @@ public class XmlStreamUtilsTest { private LeafSchemaNode findSchemaNodeWithLeafrefType(final DataNodeContainer module, final String nodeName) { for (final DataSchemaNode childNode : module.getChildNodes()) { if (childNode instanceof DataNodeContainer) { - LeafSchemaNode leafrefFromRecursion = findSchemaNodeWithLeafrefType((DataNodeContainer)childNode, nodeName); + LeafSchemaNode leafrefFromRecursion = findSchemaNodeWithLeafrefType((DataNodeContainer) childNode, + nodeName); if (leafrefFromRecursion != null) { return leafrefFromRecursion; } } else if (childNode.getQName().getLocalName().equals(nodeName) && childNode instanceof LeafSchemaNode) { - final TypeDefinition leafSchemaNodeType = ((LeafSchemaNode)childNode).getType(); + final TypeDefinition leafSchemaNodeType = ((LeafSchemaNode) childNode).getType(); if (leafSchemaNodeType instanceof LeafrefTypeDefinition) { - return (LeafSchemaNode)childNode; + return (LeafSchemaNode) childNode; } } } @@ -212,7 +216,7 @@ public class XmlStreamUtilsTest { private static LeafrefTypeDefinition findLeafrefType(final LeafSchemaNode schemaNode) { final TypeDefinition type = schemaNode.getType(); if (type instanceof LeafrefTypeDefinition) { - return (LeafrefTypeDefinition)type; + return (LeafrefTypeDefinition) type; } return null; } diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/xml/retest/Bug2964Test.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/xml/retest/Bug2964Test.java deleted file mode 100644 index 329ac4e9f7..0000000000 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/xml/retest/Bug2964Test.java +++ /dev/null @@ -1,101 +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.data.impl.codec.xml.retest; - -import static org.hamcrest.CoreMatchers.instanceOf; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; -import com.google.common.base.Charsets; -import java.io.ByteArrayInputStream; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.net.URI; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; -import org.junit.Before; -import org.junit.Test; -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.data.impl.RetestUtils; -import org.opendaylight.yangtools.yang.data.impl.schema.transform.dom.DomUtils; -import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode; -import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; -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.w3c.dom.Document; -import org.w3c.dom.Element; -import org.xml.sax.SAXException; - -public class Bug2964Test { - - public static final String XML_CONTENT = "\n" - + "test-identity\n" + ""; - - private static final DocumentBuilderFactory BUILDERFACTORY; - - private static final String NAMESPACE = "urn:opendaylight:yangtools:leafref:test"; - private static final String TEST_IDENTITY = "test-identity"; - private static final String CONT_2 = "cont2"; - private static final String IDENTITY_LEAFREF = "point-to-identityrefleaf"; - - static { - final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - factory.setNamespaceAware(true); - factory.setCoalescing(true); - factory.setIgnoringElementContentWhitespace(true); - factory.setIgnoringComments(true); - BUILDERFACTORY = factory; - } - - private SchemaContext schema; - - @Before - public void setUp() throws Exception { - File leafRefTestYang = new File(getClass().getResource("/leafref-test.yang").toURI()); - schema = RetestUtils.parseYangSources(leafRefTestYang); - } - - public static Document readXmlToDocument(final String xmlContent) throws SAXException, IOException { - return readXmlToDocument(new ByteArrayInputStream(xmlContent.getBytes(Charsets.UTF_8))); - } - - @Test - public void testLeafrefIdentityRefDeserialization() throws Exception { - final URI namespaceUri = new URI(NAMESPACE); - - final Document document = readXmlToDocument(XML_CONTENT); - final Element identityLeafRefElement = (Element) document.getDocumentElement().getFirstChild().getNextSibling(); - - final Module leafrefModule = schema.findModuleByNamespaceAndRevision(namespaceUri, null); - final ContainerSchemaNode cont2 = (ContainerSchemaNode) leafrefModule.getDataChildByName(CONT_2); - final DataSchemaNode identityLeafRefSchema = cont2.getDataChildByName(IDENTITY_LEAFREF); - final Object parsedValue = DomUtils.parseXmlValue(identityLeafRefElement, DomUtils.defaultValueCodecProvider(), - identityLeafRefSchema, ((LeafSchemaNode) identityLeafRefSchema).getType(), schema); - - assertThat(parsedValue, instanceOf(QName.class)); - final QName parsedQName = (QName) parsedValue; - assertEquals(namespaceUri, parsedQName.getNamespace()); - assertEquals(TEST_IDENTITY, parsedQName.getLocalName()); - } - - public static Document readXmlToDocument(final InputStream xmlContent) throws SAXException, IOException { - final DocumentBuilder dBuilder; - try { - dBuilder = BUILDERFACTORY.newDocumentBuilder(); - } catch (final ParserConfigurationException e) { - throw new IllegalStateException("Failed to parse XML document", e); - } - final Document doc = dBuilder.parse(xmlContent); - - doc.getDocumentElement().normalize(); - return doc; - } -} diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/xml/retest/RandomPrefixTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/xml/retest/RandomPrefixTest.java deleted file mode 100644 index 257a954350..0000000000 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/xml/retest/RandomPrefixTest.java +++ /dev/null @@ -1,90 +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.data.impl.codec.xml.retest; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; -import com.google.common.collect.Iterables; -import com.google.common.collect.Lists; -import com.google.common.collect.Sets; -import java.net.URI; -import java.util.Date; -import java.util.List; -import org.hamcrest.CoreMatchers; -import org.junit.Test; -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.common.QNameModule; - -public class RandomPrefixTest { - static final int MAX_COUNTER = 4000; - - @Test - public void testEncodeDecode() throws Exception { - - final List allGenerated = Lists.newArrayList(); - for (int i = 0; i < MAX_COUNTER; i++) { - final String encoded = RandomPrefix.encode(i); - assertEquals(RandomPrefix.decode(encoded), i); - allGenerated.add(encoded); - } - - assertEquals(allGenerated.size(), MAX_COUNTER); - assertEquals("dPT", allGenerated.get(MAX_COUNTER - 1)); - assertEquals("a", allGenerated.get(0)); - assertEquals(allGenerated.size(), Sets.newHashSet(allGenerated).size()); - } - - @Test - public void testQNameWithPrefix() throws Exception { - final RandomPrefix a = new RandomPrefix(); - - final List allGenerated = Lists.newArrayList(); - for (int i = 0; i < MAX_COUNTER; i++) { - final String prefix = RandomPrefix.encode(i); - final URI uri = new URI("localhost:" + prefix); - final QName qName = QName.create(QNameModule.create(uri, new Date()), "local-name"); - allGenerated.add(a.encodePrefix(qName.getNamespace())); - } - - assertEquals(MAX_COUNTER, allGenerated.size()); - // We are generating MAX_COUNTER_VALUE + 27 prefixes total, so we should encounter a reset in prefix a start - // from 0 at some point - // At the end, there should be only 27 values in RandomPrefix cache - assertEquals(MAX_COUNTER, Iterables.size(a.getPrefixes())); - assertThat(allGenerated, CoreMatchers.not(CoreMatchers.hasItem("xml"))); - assertThat(allGenerated, CoreMatchers.not(CoreMatchers.hasItem("xmla"))); - assertThat(allGenerated, CoreMatchers.not(CoreMatchers.hasItem("xmlz"))); - - assertEquals(1, Iterables.frequency(allGenerated, "a")); - } - - @Test - public void test2QNames1Namespace() throws Exception { - final RandomPrefix a = new RandomPrefix(); - - final URI uri = URI.create("localhost"); - final QName qName = QName.create(QNameModule.create(uri, new Date()), "local-name"); - final QName qName2 = QName.create(QNameModule.create(uri, new Date()), "local-name"); - - assertEquals(a.encodePrefix(qName.getNamespace()), a.encodePrefix(qName2.getNamespace())); - } - - @Test - public void testQNameNoPrefix() throws Exception { - final RandomPrefix a = new RandomPrefix(); - - final URI uri = URI.create("localhost"); - QName qName = QName.create(uri, new Date(), "local-name"); - assertEquals("a", a.encodePrefix(qName.getNamespace())); - qName = QName.create(QNameModule.create(uri, new Date()), "local-name"); - assertEquals("a", a.encodePrefix(qName.getNamespace())); - qName = QName.create(QNameModule.create(URI.create("second"), new Date()), "local-name"); - assertEquals("b", a.encodePrefix(qName.getNamespace())); - - } -} diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/xml/retest/XmlDocumentUtilsTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/xml/retest/XmlDocumentUtilsTest.java deleted file mode 100644 index 319b4bcfa0..0000000000 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/xml/retest/XmlDocumentUtilsTest.java +++ /dev/null @@ -1,74 +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.data.impl.codec.xml.retest; - -import com.google.common.base.Charsets; -import java.io.ByteArrayInputStream; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; -import org.junit.Before; -import org.opendaylight.yangtools.yang.data.impl.RetestUtils; -import org.opendaylight.yangtools.yang.model.api.Module; -import org.opendaylight.yangtools.yang.model.api.RpcDefinition; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.w3c.dom.Document; -import org.xml.sax.SAXException; - -public class XmlDocumentUtilsTest { - - private static final DocumentBuilderFactory BUILDERFACTORY; - - static { - final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - factory.setNamespaceAware(true); - factory.setCoalescing(true); - factory.setIgnoringElementContentWhitespace(true); - factory.setIgnoringComments(true); - BUILDERFACTORY = factory; - } - - public static final String XML_CONTENT = "\n" - + "value\n" + "" - + "/ltha:cont/ltha:l[ ltha:id='id/foo/bar' ]" + "\n" + ""; - - public static final String RPC_REPLY = "\n" - + " \n" + ""; - - private SchemaContext schema; - private RpcDefinition testRpc; - - @Before - public void setUp() throws Exception { - File rpcTestYang = new File(getClass().getResource("/rpc-test.yang").toURI()); - schema = RetestUtils.parseYangSources(rpcTestYang); - final Module rpcTestModule = schema.getModules().iterator().next(); - testRpc = rpcTestModule.getRpcs().iterator().next(); - } - - public static Document readXmlToDocument(final String xmlContent) throws SAXException, IOException { - return readXmlToDocument(new ByteArrayInputStream(xmlContent.getBytes(Charsets.UTF_8))); - } - - public static Document readXmlToDocument(final InputStream xmlContent) throws SAXException, IOException { - final DocumentBuilder dBuilder; - try { - dBuilder = BUILDERFACTORY.newDocumentBuilder(); - } catch (final ParserConfigurationException e) { - throw new IllegalStateException("Failed to parse XML document", e); - } - final Document doc = dBuilder.parse(xmlContent); - - doc.getDocumentElement().normalize(); - return doc; - } -} diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/xml/retest/XmlStreamUtilsTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/xml/retest/XmlStreamUtilsTest.java deleted file mode 100644 index 457ea4315d..0000000000 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/xml/retest/XmlStreamUtilsTest.java +++ /dev/null @@ -1,223 +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.data.impl.codec.xml.retest; - -import static org.hamcrest.CoreMatchers.containsString; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; -import com.google.common.base.Optional; -import com.google.common.collect.Maps; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.FileNotFoundException; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.AbstractMap; -import java.util.Date; -import java.util.Map; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import javax.xml.stream.XMLOutputFactory; -import javax.xml.stream.XMLStreamWriter; -import org.custommonkey.xmlunit.Diff; -import org.custommonkey.xmlunit.XMLUnit; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.common.QNameModule; -import org.opendaylight.yangtools.yang.data.impl.RetestUtils; -import org.opendaylight.yangtools.yang.model.api.DataNodeContainer; -import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; -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.model.api.type.InstanceIdentifierTypeDefinition; -import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition; -import org.opendaylight.yangtools.yang.model.api.type.StringTypeDefinition; -import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil; -import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; -import org.w3c.dom.Document; - -public class XmlStreamUtilsTest { - - public static final XMLOutputFactory XML_OUTPUT_FACTORY = XMLOutputFactory.newFactory(); - - private static SchemaContext schemaContext; - private static Module leafRefModule; - - @BeforeClass - public static void initialize() throws URISyntaxException, FileNotFoundException, ReactorException { - final File file = new File(XmlStreamUtils.class.getResource("/leafref-test.yang").toURI()); - schemaContext = RetestUtils.parseYangSources(file); - assertNotNull(schemaContext); - assertEquals(1, schemaContext.getModules().size()); - leafRefModule = schemaContext.getModules().iterator().next(); - assertNotNull(leafRefModule); - } - - @Test - public void testWriteAttribute() throws Exception { - final ByteArrayOutputStream out = new ByteArrayOutputStream(); - final XMLStreamWriter writer = XML_OUTPUT_FACTORY.createXMLStreamWriter(out); - writer.writeStartElement("element"); - - QName name = getAttrQName("namespace", "2012-12-12", "attr", Optional.of("prefix")); - final Map.Entry attributeEntry = new AbstractMap.SimpleEntry<>(name, "value"); - - name = getAttrQName("namespace2", "2012-12-12", "attr", Optional.absent()); - final Map.Entry attributeEntryNoPrefix = new AbstractMap.SimpleEntry<>(name, "value"); - - final RandomPrefix randomPrefix = new RandomPrefix(); - XmlStreamUtils.writeAttribute(writer, attributeEntry, randomPrefix); - XmlStreamUtils.writeAttribute(writer, attributeEntryNoPrefix, randomPrefix); - - writer.writeEndElement(); - writer.close(); - out.close(); - - final String xmlAsString = new String(out.toByteArray()); - - final Map mappedPrefixes = mapPrefixed(randomPrefix.getPrefixes()); - assertEquals(2, mappedPrefixes.size()); - final String randomPrefixValue = mappedPrefixes.get("namespace2"); - - final String expectedXmlAsString = ""; - - XMLUnit.setIgnoreAttributeOrder(true); - final Document control = XMLUnit.buildControlDocument(expectedXmlAsString); - final Document test = XMLUnit.buildTestDocument(xmlAsString); - final Diff diff = XMLUnit.compareXML(control, test); - - final boolean identical = diff.identical(); - assertTrue("Xml differs: " + diff.toString(), identical); - } - - @Test - public void testWriteIdentityRef() throws Exception { - final ByteArrayOutputStream out = new ByteArrayOutputStream(); - final XMLStreamWriter writer = XML_OUTPUT_FACTORY.createXMLStreamWriter(out); - - writer.writeStartElement("element"); - final QNameModule parent = QNameModule.create(URI.create("parent:uri"), new Date()); - XmlStreamUtils.write(writer, null, QName.create(parent, "identity"), Optional.of(parent)); - writer.writeEndElement(); - - writer.writeStartElement("elementDifferent"); - XmlStreamUtils.write(writer, null, QName.create("different:namespace", "identity"), Optional.of(parent)); - writer.writeEndElement(); - - writer.close(); - out.close(); - - final String xmlAsString = new String(out.toByteArray()).replaceAll("\\s*", ""); - assertThat(xmlAsString, containsString("element>identity")); - - final Pattern prefixedIdentityPattern = Pattern.compile(".*\"different:namespace\">(.*):identity.*"); - final Matcher matcher = prefixedIdentityPattern.matcher(xmlAsString); - assertTrue("Xml: " + xmlAsString + " should match: " + prefixedIdentityPattern, matcher.matches()); - } - - /** - * One leafref reference to other leafref via relative references - */ - @Test - public void testLeafRefRelativeChaining() { - getTargetNodeForLeafRef("leafname3", StringTypeDefinition.class); - } - - @Test - public void testLeafRefRelative() { - getTargetNodeForLeafRef("pointToStringLeaf", StringTypeDefinition.class); - } - - @Test - public void testLeafRefAbsoluteWithSameTarget() { - getTargetNodeForLeafRef("absname", InstanceIdentifierTypeDefinition.class); - } - - /** - * Tests relative path with double point inside path (e. g. "../../lf:interface/../lf:cont2/lf:stringleaf") - */ - @Ignore - // ignored because this isn't implemented - @Test - public void testLeafRefWithDoublePointInPath() { - getTargetNodeForLeafRef("lf-with-double-point-inside", StringTypeDefinition.class); - } - - @Test - public void testLeafRefRelativeAndAbsoluteWithSameTarget() { - final TypeDefinition targetNodeForAbsname = getTargetNodeForLeafRef("absname", - InstanceIdentifierTypeDefinition.class); - final TypeDefinition targetNodeForRelname = getTargetNodeForLeafRef("relname", - InstanceIdentifierTypeDefinition.class); - assertEquals(targetNodeForAbsname, targetNodeForRelname); - } - - private TypeDefinition getTargetNodeForLeafRef(final String nodeName, final Class clas) { - final LeafSchemaNode schemaNode = findSchemaNodeWithLeafrefType(leafRefModule, nodeName); - assertNotNull(schemaNode); - final LeafrefTypeDefinition leafrefTypedef = findLeafrefType(schemaNode); - assertNotNull(leafrefTypedef); - final TypeDefinition targetBaseType = SchemaContextUtil.getBaseTypeForLeafRef(leafrefTypedef, schemaContext, - schemaNode); - assertTrue("Wrong class found.", clas.isInstance(targetBaseType)); - return targetBaseType; - } - - private static Map mapPrefixed(final Iterable> prefixes) { - final Map mappedPrefixes = Maps.newHashMap(); - for (final Map.Entry prefix : prefixes) { - mappedPrefixes.put(prefix.getKey().toString(), prefix.getValue()); - } - return mappedPrefixes; - } - - private static QName getAttrQName(final String namespace, final String revision, final String localName, - final Optional prefix) { - if (prefix.isPresent()) { - final QName moduleQName = QName.create(namespace, revision, "module"); - final QNameModule module = QNameModule.create(moduleQName.getNamespace(), moduleQName.getRevision()); - return QName.create(module, localName); - } else { - return QName.create(namespace, revision, localName); - } - } - - private LeafSchemaNode findSchemaNodeWithLeafrefType(final DataNodeContainer module, final String nodeName) { - for (final DataSchemaNode childNode : module.getChildNodes()) { - if (childNode instanceof DataNodeContainer) { - LeafSchemaNode leafrefFromRecursion = findSchemaNodeWithLeafrefType((DataNodeContainer) childNode, - nodeName); - if (leafrefFromRecursion != null) { - return leafrefFromRecursion; - } - } else if (childNode.getQName().getLocalName().equals(nodeName) && childNode instanceof LeafSchemaNode) { - final TypeDefinition leafSchemaNodeType = ((LeafSchemaNode) childNode).getType(); - if (leafSchemaNodeType instanceof LeafrefTypeDefinition) { - return (LeafSchemaNode) childNode; - } - } - } - return null; - } - - private static LeafrefTypeDefinition findLeafrefType(final LeafSchemaNode schemaNode) { - final TypeDefinition type = schemaNode.getType(); - if (type instanceof LeafrefTypeDefinition) { - return (LeafrefTypeDefinition) type; - } - return null; - } -} diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/test/codecs/BinaryCodecStringTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codecs/BinaryCodecStringTest.java similarity index 83% rename from yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/test/codecs/BinaryCodecStringTest.java rename to yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codecs/BinaryCodecStringTest.java index 74b65ba1fb..c5e4e9a4d4 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/test/codecs/BinaryCodecStringTest.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codecs/BinaryCodecStringTest.java @@ -1,17 +1,17 @@ /* - * Copyright (c) 2014 Brocade Communications 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.data.impl.test.codecs; +package org.opendaylight.yangtools.yang.data.impl.codecs; import static org.junit.Assert.*; import org.junit.Test; -import static org.opendaylight.yangtools.yang.data.impl.test.codecs.TypeDefinitionAwareCodecTestHelper.getCodec; +import static org.opendaylight.yangtools.yang.data.impl.codecs.TypeDefinitionAwareCodecTestHelper.getCodec; import org.opendaylight.yangtools.yang.data.api.codec.BinaryCodec; import org.opendaylight.yangtools.yang.model.util.BinaryType; diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/test/codecs/BitsCodecStringTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codecs/BitsCodecStringTest.java similarity index 64% rename from yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/test/codecs/BitsCodecStringTest.java rename to yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codecs/BitsCodecStringTest.java index fe1b029aeb..d39226729a 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/test/codecs/BitsCodecStringTest.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codecs/BitsCodecStringTest.java @@ -1,21 +1,17 @@ /* - * Copyright (c) 2014 Brocade Communications 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.data.impl.test.codecs; +package org.opendaylight.yangtools.yang.data.impl.codecs; import static org.junit.Assert.*; import java.util.Collections; import org.junit.Test; -import static org.opendaylight.yangtools.yang.data.impl.test.codecs.TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx; -import static org.opendaylight.yangtools.yang.data.impl.test.codecs.TypeDefinitionAwareCodecTestHelper.toBitsTypeDefinition; -import static org.opendaylight.yangtools.yang.data.impl.test.codecs.TypeDefinitionAwareCodecTestHelper.getCodec; - import org.opendaylight.yangtools.yang.data.api.codec.BitsCodec; import com.google.common.collect.ImmutableSet; @@ -31,7 +27,7 @@ public class BitsCodecStringTest { @Test public void testSerialize() { - BitsCodec codec = getCodec( toBitsTypeDefinition( "foo" ), BitsCodec.class ); + BitsCodec codec = TypeDefinitionAwareCodecTestHelper.getCodec( TypeDefinitionAwareCodecTestHelper.toBitsTypeDefinition( "foo" ), BitsCodec.class ); ImmutableSet toSerialize = ImmutableSet.of("foo", "bar"); @@ -49,13 +45,13 @@ public class BitsCodecStringTest { @Test public void testDeserialize() { - BitsCodec codec = getCodec( toBitsTypeDefinition( "bit1", "bit2" ), BitsCodec.class ); + BitsCodec codec = TypeDefinitionAwareCodecTestHelper.getCodec( TypeDefinitionAwareCodecTestHelper.toBitsTypeDefinition( "bit1", "bit2" ), BitsCodec.class ); assertEquals("deserialize", ImmutableSet.of("bit1", "bit2"), codec.deserialize(" bit1 bit2 ")); assertEquals("deserialize", Collections.emptySet(), codec.deserialize("")); assertEquals("deserialize", Collections.emptySet(), codec.deserialize(null)); - deserializeWithExpectedIllegalArgEx(codec, "bit1 bit3"); + TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx(codec, "bit1 bit3"); } } diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/test/codecs/BooleanCodecStringTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codecs/BooleanCodecStringTest.java similarity index 65% rename from yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/test/codecs/BooleanCodecStringTest.java rename to yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codecs/BooleanCodecStringTest.java index 7bcde74390..143052ddf3 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/test/codecs/BooleanCodecStringTest.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codecs/BooleanCodecStringTest.java @@ -1,20 +1,17 @@ /* - * Copyright (c) 2014 Brocade Communications 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.data.impl.test.codecs; +package org.opendaylight.yangtools.yang.data.impl.codecs; import static org.junit.Assert.*; import org.junit.Test; -import static org.opendaylight.yangtools.yang.data.impl.test.codecs.TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx; -import static org.opendaylight.yangtools.yang.data.impl.test.codecs.TypeDefinitionAwareCodecTestHelper.getCodec; - import org.opendaylight.yangtools.yang.data.api.codec.BooleanCodec; import org.opendaylight.yangtools.yang.model.util.BooleanType; @@ -28,7 +25,7 @@ public class BooleanCodecStringTest { @SuppressWarnings("unchecked") @Test public void testSerialize() { - BooleanCodec codec = getCodec( BooleanType.getInstance(), BooleanCodec.class); + BooleanCodec codec = TypeDefinitionAwareCodecTestHelper.getCodec( BooleanType.getInstance(), BooleanCodec.class); assertEquals( "serialize", "", codec.serialize( null ) ); assertEquals( "serialize", "true", codec.serialize( true ) ); @@ -38,14 +35,14 @@ public class BooleanCodecStringTest { @SuppressWarnings("unchecked") @Test public void testDeserialize() { - BooleanCodec codec = getCodec( BooleanType.getInstance(), BooleanCodec.class); + BooleanCodec codec = TypeDefinitionAwareCodecTestHelper.getCodec( BooleanType.getInstance(), BooleanCodec.class); assertEquals( "deserialize", Boolean.TRUE, codec.deserialize( "true" ) ); assertEquals( "deserialize", Boolean.TRUE, codec.deserialize( "TRUE" ) ); assertEquals( "deserialize", Boolean.FALSE, codec.deserialize( "FALSE" ) ); assertEquals( "deserialize", Boolean.FALSE, codec.deserialize( "false" ) ); assertEquals( "deserialize", null, codec.deserialize( null ) ); - deserializeWithExpectedIllegalArgEx(codec, "foo"); - deserializeWithExpectedIllegalArgEx(codec, ""); + TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx(codec, "foo"); + TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx(codec, ""); } } diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/test/codecs/DecimalCodecStringTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codecs/DecimalCodecStringTest.java similarity index 57% rename from yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/test/codecs/DecimalCodecStringTest.java rename to yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codecs/DecimalCodecStringTest.java index bc962d5c3e..7c26c798af 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/test/codecs/DecimalCodecStringTest.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codecs/DecimalCodecStringTest.java @@ -1,12 +1,12 @@ /* - * Copyright (c) 2014 Brocade Communications 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.data.impl.test.codecs; +package org.opendaylight.yangtools.yang.data.impl.codecs; import static org.junit.Assert.*; import static org.mockito.Mockito.mock; @@ -15,9 +15,6 @@ import java.math.BigDecimal; import org.junit.Test; -import static org.opendaylight.yangtools.yang.data.impl.test.codecs.TypeDefinitionAwareCodecTestHelper.getCodec; -import static org.opendaylight.yangtools.yang.data.impl.test.codecs.TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx; - import org.opendaylight.yangtools.yang.data.api.codec.DecimalCodec; import org.opendaylight.yangtools.yang.model.api.SchemaPath; import org.opendaylight.yangtools.yang.model.util.Decimal64; @@ -32,7 +29,7 @@ public class DecimalCodecStringTest { @SuppressWarnings("unchecked") @Test public void testSerialize() { - DecimalCodec codec = getCodec( Decimal64.create( mock( SchemaPath.class ), 2 ), DecimalCodec.class ); + DecimalCodec codec = TypeDefinitionAwareCodecTestHelper.getCodec( Decimal64.create( mock( SchemaPath.class ), 2 ), DecimalCodec.class ); assertEquals( "serialize", "123.456", codec.serialize( new BigDecimal( "123.456" ) ) ); assertEquals( "serialize", "", codec.serialize( null ) ); @@ -41,12 +38,12 @@ public class DecimalCodecStringTest { @SuppressWarnings("unchecked") @Test public void testDeserialize() { - DecimalCodec codec = getCodec( Decimal64.create( mock( SchemaPath.class ), 2 ), DecimalCodec.class ); + DecimalCodec codec = TypeDefinitionAwareCodecTestHelper.getCodec( Decimal64.create( mock( SchemaPath.class ), 2 ), DecimalCodec.class ); assertEquals( "deserialize", new BigDecimal( "123.456" ), codec.deserialize( "123.456" ) ); - deserializeWithExpectedIllegalArgEx( codec, "12o.3" ); - deserializeWithExpectedIllegalArgEx( codec, "" ); - deserializeWithExpectedIllegalArgEx( codec, null ); + TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx( codec, "12o.3" ); + TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx( codec, "" ); + TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx( codec, null ); } } diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/test/codecs/EmptyCodecStringTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codecs/EmptyCodecStringTest.java similarity index 58% rename from yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/test/codecs/EmptyCodecStringTest.java rename to yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codecs/EmptyCodecStringTest.java index 98d9bc0fcb..5816266806 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/test/codecs/EmptyCodecStringTest.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codecs/EmptyCodecStringTest.java @@ -1,18 +1,16 @@ /* - * Copyright (c) 2014 Brocade Communications 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.data.impl.test.codecs; +package org.opendaylight.yangtools.yang.data.impl.codecs; import static org.junit.Assert.*; import org.junit.Test; -import static org.opendaylight.yangtools.yang.data.impl.test.codecs.TypeDefinitionAwareCodecTestHelper.getCodec; -import static org.opendaylight.yangtools.yang.data.impl.test.codecs.TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx; import org.opendaylight.yangtools.yang.data.api.codec.EmptyCodec; import org.opendaylight.yangtools.yang.model.util.EmptyType; @@ -26,7 +24,7 @@ public class EmptyCodecStringTest { @SuppressWarnings("unchecked") @Test public void testSerialize() { - EmptyCodec codec = getCodec( EmptyType.getInstance(), EmptyCodec.class); + EmptyCodec codec = TypeDefinitionAwareCodecTestHelper.getCodec( EmptyType.getInstance(), EmptyCodec.class); assertEquals( "serialize", "", codec.serialize( null ) ); } @@ -34,12 +32,12 @@ public class EmptyCodecStringTest { @SuppressWarnings("unchecked") @Test public void testDeserialize() { - EmptyCodec codec = getCodec( EmptyType.getInstance(), EmptyCodec.class); + EmptyCodec codec = TypeDefinitionAwareCodecTestHelper.getCodec( EmptyType.getInstance(), EmptyCodec.class); assertEquals( "deserialize", null, codec.deserialize( "" ) ); assertEquals( "deserialize", null, codec.deserialize( null ) ); - deserializeWithExpectedIllegalArgEx( codec, "foo" ); + TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx( codec, "foo" ); } } diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/test/codecs/EnumCodecStringTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codecs/EnumCodecStringTest.java similarity index 69% rename from yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/test/codecs/EnumCodecStringTest.java rename to yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codecs/EnumCodecStringTest.java index 146d762cc1..6be2ddc88c 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/test/codecs/EnumCodecStringTest.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codecs/EnumCodecStringTest.java @@ -1,20 +1,20 @@ /* - * Copyright (c) 2014 Brocade Communications 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.data.impl.test.codecs; +package org.opendaylight.yangtools.yang.data.impl.codecs; import static org.junit.Assert.*; import org.junit.Test; import org.opendaylight.yangtools.yang.data.api.codec.EnumCodec; -import static org.opendaylight.yangtools.yang.data.impl.test.codecs.TypeDefinitionAwareCodecTestHelper.getCodec; -import static org.opendaylight.yangtools.yang.data.impl.test.codecs.TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx; -import static org.opendaylight.yangtools.yang.data.impl.test.codecs.TypeDefinitionAwareCodecTestHelper.toEnumTypeDefinition; +import static org.opendaylight.yangtools.yang.data.impl.codecs.TypeDefinitionAwareCodecTestHelper.getCodec; +import static org.opendaylight.yangtools.yang.data.impl.codecs.TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx; +import static org.opendaylight.yangtools.yang.data.impl.codecs.TypeDefinitionAwareCodecTestHelper.toEnumTypeDefinition; /** * Unit tests for EnumCodecString. diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/test/codecs/Int16CodecStringTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codecs/Int16CodecStringTest.java similarity index 82% rename from yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/test/codecs/Int16CodecStringTest.java rename to yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codecs/Int16CodecStringTest.java index 9d468596d7..d1e94ab0fa 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/test/codecs/Int16CodecStringTest.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codecs/Int16CodecStringTest.java @@ -1,16 +1,16 @@ /* - * Copyright (c) 2014 Brocade Communications 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.data.impl.test.codecs; +package org.opendaylight.yangtools.yang.data.impl.codecs; import static org.junit.Assert.*; -import static org.opendaylight.yangtools.yang.data.impl.test.codecs.TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx; -import static org.opendaylight.yangtools.yang.data.impl.test.codecs.TypeDefinitionAwareCodecTestHelper.getCodec; +import static org.opendaylight.yangtools.yang.data.impl.codecs.TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx; +import static org.opendaylight.yangtools.yang.data.impl.codecs.TypeDefinitionAwareCodecTestHelper.getCodec; import org.junit.Test; import org.opendaylight.yangtools.yang.data.api.codec.Int16Codec; diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/test/codecs/Int32CodecStringTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codecs/Int32CodecStringTest.java similarity index 69% rename from yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/test/codecs/Int32CodecStringTest.java rename to yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codecs/Int32CodecStringTest.java index a3b2975e88..ab7255d0a7 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/test/codecs/Int32CodecStringTest.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codecs/Int32CodecStringTest.java @@ -1,16 +1,14 @@ /* - * Copyright (c) 2014 Brocade Communications 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.data.impl.test.codecs; +package org.opendaylight.yangtools.yang.data.impl.codecs; import static org.junit.Assert.*; -import static org.opendaylight.yangtools.yang.data.impl.test.codecs.TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx; -import static org.opendaylight.yangtools.yang.data.impl.test.codecs.TypeDefinitionAwareCodecTestHelper.getCodec; import org.junit.Test; import org.opendaylight.yangtools.yang.data.api.codec.Int32Codec; @@ -26,7 +24,7 @@ public class Int32CodecStringTest { @SuppressWarnings("unchecked") @Test public void testSerialize() { - Int32Codec codec = getCodec(Int32.getInstance(), Int32Codec.class); + Int32Codec codec = TypeDefinitionAwareCodecTestHelper.getCodec(Int32.getInstance(), Int32Codec.class); assertEquals("serialize", "10", codec.serialize(Integer.valueOf( 10 ))); assertEquals("serialize", "", codec.serialize(null)); @@ -42,7 +40,7 @@ public class Int32CodecStringTest { final String integer = "1174404318"; final String negInteger = "-1174404318"; - Int32Codec codec = getCodec(Int32.getInstance(), Int32Codec.class); + Int32Codec codec = TypeDefinitionAwareCodecTestHelper.getCodec(Int32.getInstance(), Int32Codec.class); assertEquals("deserialize", codec.deserialize(hexa), Integer.valueOf("+045FFFCDE", 16)); assertEquals("deserialize", codec.deserialize(negHexa), Integer.valueOf("-045FFFCDE", 16)); @@ -51,8 +49,8 @@ public class Int32CodecStringTest { assertEquals("deserialize", codec.deserialize(integer), Integer.valueOf(integer, 10)); assertEquals("deserialize", codec.deserialize(negInteger), Integer.valueOf(negInteger, 10)); - deserializeWithExpectedIllegalArgEx(codec, "1o"); - deserializeWithExpectedIllegalArgEx(codec, ""); - deserializeWithExpectedIllegalArgEx(codec, null); + TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx(codec, "1o"); + TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx(codec, ""); + TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx(codec, null); } } diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/test/codecs/Int64CodecStringTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codecs/Int64CodecStringTest.java similarity index 83% rename from yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/test/codecs/Int64CodecStringTest.java rename to yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codecs/Int64CodecStringTest.java index aa93f95a16..bf784afe04 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/test/codecs/Int64CodecStringTest.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codecs/Int64CodecStringTest.java @@ -1,16 +1,16 @@ /* - * Copyright (c) 2014 Brocade Communications 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.data.impl.test.codecs; +package org.opendaylight.yangtools.yang.data.impl.codecs; import static org.junit.Assert.*; -import static org.opendaylight.yangtools.yang.data.impl.test.codecs.TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx; -import static org.opendaylight.yangtools.yang.data.impl.test.codecs.TypeDefinitionAwareCodecTestHelper.getCodec; +import static org.opendaylight.yangtools.yang.data.impl.codecs.TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx; +import static org.opendaylight.yangtools.yang.data.impl.codecs.TypeDefinitionAwareCodecTestHelper.getCodec; import org.junit.Test; import org.opendaylight.yangtools.yang.data.api.codec.Int64Codec; diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/test/codecs/Int8CodecStringTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codecs/Int8CodecStringTest.java similarity index 68% rename from yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/test/codecs/Int8CodecStringTest.java rename to yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codecs/Int8CodecStringTest.java index b699b502fd..4ee8492f19 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/test/codecs/Int8CodecStringTest.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codecs/Int8CodecStringTest.java @@ -1,16 +1,14 @@ /* - * Copyright (c) 2014 Brocade Communications 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.data.impl.test.codecs; +package org.opendaylight.yangtools.yang.data.impl.codecs; import static org.junit.Assert.*; -import static org.opendaylight.yangtools.yang.data.impl.test.codecs.TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx; -import static org.opendaylight.yangtools.yang.data.impl.test.codecs.TypeDefinitionAwareCodecTestHelper.getCodec; import org.junit.Test; import org.opendaylight.yangtools.yang.data.api.codec.Int8Codec; @@ -26,7 +24,7 @@ public class Int8CodecStringTest { @SuppressWarnings("unchecked") @Test public void testSerialize() { - Int8Codec codec = getCodec(Int8.getInstance(), Int8Codec.class); + Int8Codec codec = TypeDefinitionAwareCodecTestHelper.getCodec(Int8.getInstance(), Int8Codec.class); assertEquals("serialize", "10", codec.serialize(Byte.valueOf( (byte) 10 ))); assertEquals("serialize", "", codec.serialize(null)); @@ -42,7 +40,7 @@ public class Int8CodecStringTest { final String integer = "64"; final String negInteger = "-64"; - Int8Codec codec = getCodec(Int8.getInstance(), Int8Codec.class); + Int8Codec codec = TypeDefinitionAwareCodecTestHelper.getCodec(Int8.getInstance(), Int8Codec.class); assertEquals("deserialize", codec.deserialize(hexa), Byte.valueOf("040", 16)); assertEquals("deserialize", codec.deserialize(negHexa), Byte.valueOf("-040", 16)); @@ -51,8 +49,8 @@ public class Int8CodecStringTest { assertEquals("deserialize", codec.deserialize(integer), Byte.valueOf(integer, 10)); assertEquals("deserialize", codec.deserialize(negInteger), Byte.valueOf(negInteger, 10)); - deserializeWithExpectedIllegalArgEx(codec, "1o"); - deserializeWithExpectedIllegalArgEx(codec, ""); - deserializeWithExpectedIllegalArgEx(codec, null); + TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx(codec, "1o"); + TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx(codec, ""); + TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx(codec, null); } } diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/test/codecs/StringCodecStringTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codecs/StringCodecStringTest.java similarity index 71% rename from yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/test/codecs/StringCodecStringTest.java rename to yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codecs/StringCodecStringTest.java index 42e461660e..7810e6c0e4 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/test/codecs/StringCodecStringTest.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codecs/StringCodecStringTest.java @@ -1,17 +1,16 @@ /* - * Copyright (c) 2014 Brocade Communications 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.data.impl.test.codecs; +package org.opendaylight.yangtools.yang.data.impl.codecs; import static org.junit.Assert.*; import org.junit.Test; -import static org.opendaylight.yangtools.yang.data.impl.test.codecs.TypeDefinitionAwareCodecTestHelper.getCodec; import org.opendaylight.yangtools.yang.data.api.codec.StringCodec; import org.opendaylight.yangtools.yang.model.util.StringType; @@ -25,7 +24,7 @@ public class StringCodecStringTest { @SuppressWarnings("unchecked") @Test public void testSerialize() { - StringCodec codec = getCodec( StringType.getInstance(), StringCodec.class); + StringCodec codec = TypeDefinitionAwareCodecTestHelper.getCodec( StringType.getInstance(), StringCodec.class); assertEquals( "serialize", "foo", codec.serialize( "foo" ) ); assertEquals( "serialize", "", codec.serialize( "" ) ); @@ -35,7 +34,7 @@ public class StringCodecStringTest { @SuppressWarnings("unchecked") @Test public void testDeserialize() { - StringCodec codec = getCodec( StringType.getInstance(), StringCodec.class); + StringCodec codec = TypeDefinitionAwareCodecTestHelper.getCodec( StringType.getInstance(), StringCodec.class); assertEquals( "deserialize", "bar", codec.deserialize( "bar" ) ); assertEquals( "deserialize", "", codec.deserialize( "" ) ); diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/test/codecs/StringPatternCheckingCodecTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codecs/StringPatternCheckingCodecTest.java similarity index 90% rename from yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/test/codecs/StringPatternCheckingCodecTest.java rename to yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codecs/StringPatternCheckingCodecTest.java index 9be9ea482f..cfbd0fd35d 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/test/codecs/StringPatternCheckingCodecTest.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codecs/StringPatternCheckingCodecTest.java @@ -6,13 +6,13 @@ * and is available at http://www.eclipse.org/legal/epl-v10.html */ -package org.opendaylight.yangtools.yang.data.impl.test.codecs; +package org.opendaylight.yangtools.yang.data.impl.codecs; 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 static org.opendaylight.yangtools.yang.data.impl.test.codecs.TypeDefinitionAwareCodecTestHelper.getCodec; +import static org.opendaylight.yangtools.yang.data.impl.codecs.TypeDefinitionAwareCodecTestHelper.getCodec; import java.net.URI; import java.net.URISyntaxException; @@ -21,7 +21,7 @@ import org.junit.Test; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.common.QNameModule; import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil; -import org.opendaylight.yangtools.yang.data.impl.RetestUtils; +import org.opendaylight.yangtools.yang.data.impl.TestUtils; import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode; import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode; import org.opendaylight.yangtools.yang.model.api.Module; @@ -40,7 +40,7 @@ public class StringPatternCheckingCodecTest { @Test public void testStringPatternCheckingCodec() throws ReactorException, ParseException, URISyntaxException { - SchemaContext schemaContext = RetestUtils.parseYangSources(TEST_MODULE); + SchemaContext schemaContext = TestUtils.parseYangSources(TEST_MODULE); assertNotNull(schemaContext); QNameModule testModuleQName = QNameModule.create(new URI("string-pattern-checking-codec-test"), diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/test/codecs/TypeDefinitionAwareCodecTestHelper.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codecs/TypeDefinitionAwareCodecTestHelper.java similarity index 95% rename from yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/test/codecs/TypeDefinitionAwareCodecTestHelper.java rename to yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codecs/TypeDefinitionAwareCodecTestHelper.java index 15d90515e8..61562ce778 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/test/codecs/TypeDefinitionAwareCodecTestHelper.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codecs/TypeDefinitionAwareCodecTestHelper.java @@ -1,12 +1,12 @@ /* - * Copyright (c) 2014 Brocade Communications 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.data.impl.test.codecs; +package org.opendaylight.yangtools.yang.data.impl.codecs; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/test/codecs/Uint16CodecStringTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codecs/Uint16CodecStringTest.java similarity index 79% rename from yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/test/codecs/Uint16CodecStringTest.java rename to yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codecs/Uint16CodecStringTest.java index ffd275b95b..4985519d8c 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/test/codecs/Uint16CodecStringTest.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codecs/Uint16CodecStringTest.java @@ -1,16 +1,16 @@ /* - * Copyright (c) 2014 Brocade Communications 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.data.impl.test.codecs; +package org.opendaylight.yangtools.yang.data.impl.codecs; import static org.junit.Assert.*; -import static org.opendaylight.yangtools.yang.data.impl.test.codecs.TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx; -import static org.opendaylight.yangtools.yang.data.impl.test.codecs.TypeDefinitionAwareCodecTestHelper.getCodec; +import static org.opendaylight.yangtools.yang.data.impl.codecs.TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx; +import static org.opendaylight.yangtools.yang.data.impl.codecs.TypeDefinitionAwareCodecTestHelper.getCodec; import org.junit.Test; import org.opendaylight.yangtools.yang.data.api.codec.Uint16Codec; diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/test/codecs/Uint32CodecStringTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codecs/Uint32CodecStringTest.java similarity index 79% rename from yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/test/codecs/Uint32CodecStringTest.java rename to yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codecs/Uint32CodecStringTest.java index bf427b6657..12ad8a62da 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/test/codecs/Uint32CodecStringTest.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codecs/Uint32CodecStringTest.java @@ -1,16 +1,16 @@ /* - * Copyright (c) 2014 Brocade Communications 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.data.impl.test.codecs; +package org.opendaylight.yangtools.yang.data.impl.codecs; import static org.junit.Assert.*; -import static org.opendaylight.yangtools.yang.data.impl.test.codecs.TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx; -import static org.opendaylight.yangtools.yang.data.impl.test.codecs.TypeDefinitionAwareCodecTestHelper.getCodec; +import static org.opendaylight.yangtools.yang.data.impl.codecs.TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx; +import static org.opendaylight.yangtools.yang.data.impl.codecs.TypeDefinitionAwareCodecTestHelper.getCodec; import org.junit.Test; import org.opendaylight.yangtools.yang.data.api.codec.Uint32Codec; diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/test/codecs/Uint64CodecStringTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codecs/Uint64CodecStringTest.java similarity index 63% rename from yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/test/codecs/Uint64CodecStringTest.java rename to yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codecs/Uint64CodecStringTest.java index d5f83c1bcd..c59bfa314a 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/test/codecs/Uint64CodecStringTest.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codecs/Uint64CodecStringTest.java @@ -1,16 +1,14 @@ /* - * Copyright (c) 2014 Brocade Communications 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.data.impl.test.codecs; +package org.opendaylight.yangtools.yang.data.impl.codecs; import static org.junit.Assert.*; -import static org.opendaylight.yangtools.yang.data.impl.test.codecs.TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx; -import static org.opendaylight.yangtools.yang.data.impl.test.codecs.TypeDefinitionAwareCodecTestHelper.getCodec; import java.math.BigInteger; @@ -28,7 +26,7 @@ public class Uint64CodecStringTest { @SuppressWarnings("unchecked") @Test public void testSerialize() { - Uint64Codec codec = getCodec(Uint64.getInstance(), Uint64Codec.class); + Uint64Codec codec = TypeDefinitionAwareCodecTestHelper.getCodec(Uint64.getInstance(), Uint64Codec.class); assertEquals("serialize", "123456789", codec.serialize(BigInteger.valueOf( 123456789 ))); assertEquals("serialize", "", codec.serialize(null)); @@ -41,14 +39,14 @@ public class Uint64CodecStringTest { final String octal = "03536670743556272"; final String integer = "129664115727546"; - Uint64Codec codec = getCodec(Uint64.getInstance(), Uint64Codec.class); + Uint64Codec codec = TypeDefinitionAwareCodecTestHelper.getCodec(Uint64.getInstance(), Uint64Codec.class); assertEquals("deserialize", codec.deserialize(hexa), new BigInteger("75EDC78edCBA", 16)); assertEquals("deserialize", codec.deserialize(octal), new BigInteger(octal, 8)); assertEquals("deserialize", codec.deserialize(integer), new BigInteger(integer, 10)); - deserializeWithExpectedIllegalArgEx(codec, "12345o"); - deserializeWithExpectedIllegalArgEx(codec, ""); - deserializeWithExpectedIllegalArgEx(codec, null); + TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx(codec, "12345o"); + TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx(codec, ""); + TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx(codec, null); } } diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/test/codecs/Uint8CodecStringTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codecs/Uint8CodecStringTest.java similarity index 80% rename from yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/test/codecs/Uint8CodecStringTest.java rename to yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codecs/Uint8CodecStringTest.java index 43d7b50457..9bde6e5624 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/test/codecs/Uint8CodecStringTest.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codecs/Uint8CodecStringTest.java @@ -1,16 +1,16 @@ /* - * Copyright (c) 2014 Brocade Communications 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.data.impl.test.codecs; +package org.opendaylight.yangtools.yang.data.impl.codecs; import static org.junit.Assert.*; -import static org.opendaylight.yangtools.yang.data.impl.test.codecs.TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx; -import static org.opendaylight.yangtools.yang.data.impl.test.codecs.TypeDefinitionAwareCodecTestHelper.getCodec; +import static org.opendaylight.yangtools.yang.data.impl.codecs.TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx; +import static org.opendaylight.yangtools.yang.data.impl.codecs.TypeDefinitionAwareCodecTestHelper.getCodec; import org.junit.Test; import org.opendaylight.yangtools.yang.data.api.codec.Uint8Codec; diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/test/codecs/UnionCodecStringTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codecs/UnionCodecStringTest.java similarity index 80% rename from yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/test/codecs/UnionCodecStringTest.java rename to yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codecs/UnionCodecStringTest.java index 1e01e76415..48fd57bd1e 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/test/codecs/UnionCodecStringTest.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codecs/UnionCodecStringTest.java @@ -1,18 +1,18 @@ /* - * Copyright (c) 2014 Brocade Communications 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.data.impl.test.codecs; +package org.opendaylight.yangtools.yang.data.impl.codecs; import static org.junit.Assert.assertEquals; -import static org.opendaylight.yangtools.yang.data.impl.test.codecs.TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx; -import static org.opendaylight.yangtools.yang.data.impl.test.codecs.TypeDefinitionAwareCodecTestHelper.getCodec; -import static org.opendaylight.yangtools.yang.data.impl.test.codecs.TypeDefinitionAwareCodecTestHelper.toEnumTypeDefinition; -import static org.opendaylight.yangtools.yang.data.impl.test.codecs.TypeDefinitionAwareCodecTestHelper.toUnionTypeDefinition; +import static org.opendaylight.yangtools.yang.data.impl.codecs.TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx; +import static org.opendaylight.yangtools.yang.data.impl.codecs.TypeDefinitionAwareCodecTestHelper.getCodec; +import static org.opendaylight.yangtools.yang.data.impl.codecs.TypeDefinitionAwareCodecTestHelper.toEnumTypeDefinition; +import static org.opendaylight.yangtools.yang.data.impl.codecs.TypeDefinitionAwareCodecTestHelper.toUnionTypeDefinition; import org.junit.Test; import org.opendaylight.yangtools.yang.data.api.codec.UnionCodec; diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/test/retest/DataTreeCandidateValidatorTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/DataTreeCandidateValidatorTest.java similarity index 99% rename from yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/test/retest/DataTreeCandidateValidatorTest.java rename to yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/DataTreeCandidateValidatorTest.java index c8368cafdf..e9e08bf398 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/test/retest/DataTreeCandidateValidatorTest.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/DataTreeCandidateValidatorTest.java @@ -1,11 +1,11 @@ /* - * 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.data.impl.leafref.context.test.retest; +package org.opendaylight.yangtools.yang.data.impl.leafref.context; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -36,7 +36,7 @@ import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate; import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification; import org.opendaylight.yangtools.yang.data.api.schema.tree.TipProducingDataTree; import org.opendaylight.yangtools.yang.data.api.schema.tree.TreeType; -import org.opendaylight.yangtools.yang.data.impl.RetestUtils; +import org.opendaylight.yangtools.yang.data.impl.TestUtils; import org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefContext; import org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefDataValidationFailedException; import org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefValidatation; @@ -122,7 +122,7 @@ public class DataTreeCandidateValidatorTest { .toURI()); final File resourceDir = resourceFile.getParentFile(); - context = RetestUtils.parseYangSources(Arrays.asList(resourceDir + context = TestUtils.parseYangSources(Arrays.asList(resourceDir .listFiles())); final Set modules = context.getModules(); diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/test/retest/DataTreeCandidateValidatorTest2.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/DataTreeCandidateValidatorTest2.java similarity index 98% rename from yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/test/retest/DataTreeCandidateValidatorTest2.java rename to yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/DataTreeCandidateValidatorTest2.java index fd465383b0..60d47246df 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/test/retest/DataTreeCandidateValidatorTest2.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/DataTreeCandidateValidatorTest2.java @@ -1,11 +1,11 @@ /* - * 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.data.impl.leafref.context.test.retest; +package org.opendaylight.yangtools.yang.data.impl.leafref.context; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -30,7 +30,7 @@ import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate; import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification; import org.opendaylight.yangtools.yang.data.api.schema.tree.TipProducingDataTree; import org.opendaylight.yangtools.yang.data.api.schema.tree.TreeType; -import org.opendaylight.yangtools.yang.data.impl.RetestUtils; +import org.opendaylight.yangtools.yang.data.impl.TestUtils; import org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefContext; import org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefDataValidationFailedException; import org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefValidatation; @@ -159,7 +159,7 @@ public class DataTreeCandidateValidatorTest2 { "/leafref-validation/leafref-validation2.yang").toURI()); final File resourceDir = resourceFile.getParentFile(); - context = RetestUtils.parseYangSources(Arrays.asList(resourceDir.listFiles())); + context = TestUtils.parseYangSources(Arrays.asList(resourceDir.listFiles())); final Set modules = context.getModules(); for (final Module module : modules) { diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/test/retest/DataTreeCandidateValidatorTest3.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/DataTreeCandidateValidatorTest3.java similarity index 98% rename from yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/test/retest/DataTreeCandidateValidatorTest3.java rename to yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/DataTreeCandidateValidatorTest3.java index 22022332f9..82906f2568 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/test/retest/DataTreeCandidateValidatorTest3.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/DataTreeCandidateValidatorTest3.java @@ -1,11 +1,11 @@ /* - * 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.data.impl.leafref.context.test.retest; +package org.opendaylight.yangtools.yang.data.impl.leafref.context; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -30,7 +30,7 @@ import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate; import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification; import org.opendaylight.yangtools.yang.data.api.schema.tree.TipProducingDataTree; import org.opendaylight.yangtools.yang.data.api.schema.tree.TreeType; -import org.opendaylight.yangtools.yang.data.impl.RetestUtils; +import org.opendaylight.yangtools.yang.data.impl.TestUtils; import org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefContext; import org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefDataValidationFailedException; import org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefValidatation; @@ -206,7 +206,7 @@ public class DataTreeCandidateValidatorTest3 { "/leafref-validation/leafref-validation3.yang").toURI()); final File resourceDir = resourceFile.getParentFile(); - context = RetestUtils.parseYangSources(Arrays.asList(resourceDir.listFiles())); + context = TestUtils.parseYangSources(Arrays.asList(resourceDir.listFiles())); final Set modules = context.getModules(); for (final Module module : modules) { diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/test/retest/LeafRefContextTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/LeafRefContextTest.java similarity index 94% rename from yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/test/retest/LeafRefContextTest.java rename to yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/LeafRefContextTest.java index c4463efa28..097fa671f5 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/test/retest/LeafRefContextTest.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/LeafRefContextTest.java @@ -1,11 +1,11 @@ /* - * 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.data.impl.leafref.context.test.retest; +package org.opendaylight.yangtools.yang.data.impl.leafref.context; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -20,7 +20,7 @@ import org.junit.BeforeClass; import org.junit.Test; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.common.QNameModule; -import org.opendaylight.yangtools.yang.data.impl.RetestUtils; +import org.opendaylight.yangtools.yang.data.impl.TestUtils; import org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefContext; import org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefContextUtils; import org.opendaylight.yangtools.yang.model.api.DataNodeContainer; @@ -44,7 +44,7 @@ public class LeafRefContextTest { final File resourceDir = resourceFile.getParentFile(); - context = RetestUtils.parseYangSources(Arrays.asList(resourceDir.listFiles())); + context = TestUtils.parseYangSources(Arrays.asList(resourceDir.listFiles())); final Set modules = context.getModules(); for (final Module module : modules) { diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/test/retest/LeafRefContextTreeBuilderTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/LeafRefContextTreeBuilderTest.java similarity index 97% rename from yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/test/retest/LeafRefContextTreeBuilderTest.java rename to yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/LeafRefContextTreeBuilderTest.java index 64baa60f88..c377a68e91 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/test/retest/LeafRefContextTreeBuilderTest.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/LeafRefContextTreeBuilderTest.java @@ -1,11 +1,11 @@ /* - * 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.data.impl.leafref.context.test.retest; +package org.opendaylight.yangtools.yang.data.impl.leafref.context; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -23,7 +23,7 @@ import org.junit.Ignore; import org.junit.Test; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.common.QNameModule; -import org.opendaylight.yangtools.yang.data.impl.RetestUtils; +import org.opendaylight.yangtools.yang.data.impl.TestUtils; import org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefContext; import org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefContextUtils; import org.opendaylight.yangtools.yang.model.api.DataNodeContainer; @@ -47,7 +47,7 @@ public class LeafRefContextTreeBuilderTest { "/leafref-context-test/correct-modules/leafref-test.yang").toURI()); final File resourceDir = resourceFile.getParentFile(); - context = RetestUtils.parseYangSources(Arrays.asList(resourceDir.listFiles())); + context = TestUtils.parseYangSources(Arrays.asList(resourceDir.listFiles())); final Set modules = context.getModules(); for (final Module module : modules) { @@ -244,7 +244,7 @@ public class LeafRefContextTreeBuilderTest { "/leafref-context-test/incorrect-modules/leafref-test.yang").toURI()); final File resourceDir = resourceFile.getParentFile(); - final SchemaContext context = RetestUtils.parseYangSources(Arrays.asList(resourceDir.listFiles())); + final SchemaContext context = TestUtils.parseYangSources(Arrays.asList(resourceDir.listFiles())); LeafRefContext.create(context); diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/test/DataTreeCandidateValidatorTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/test/DataTreeCandidateValidatorTest.java deleted file mode 100644 index e508096511..0000000000 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/test/DataTreeCandidateValidatorTest.java +++ /dev/null @@ -1,815 +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.data.impl.leafref.context.test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import java.io.File; -import java.io.IOException; -import java.net.URISyntaxException; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; -import org.apache.log4j.BasicConfigurator; -import org.junit.BeforeClass; -import org.junit.Test; -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.common.QNameModule; -import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; -import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier; -import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates; -import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue; -import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode; -import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode; -import org.opendaylight.yangtools.yang.data.api.schema.LeafNode; -import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode; -import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode; -import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode; -import org.opendaylight.yangtools.yang.data.api.schema.MapNode; -import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate; -import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification; -import org.opendaylight.yangtools.yang.data.api.schema.tree.TipProducingDataTree; -import org.opendaylight.yangtools.yang.data.api.schema.tree.TreeType; -import org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefContext; -import org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefDataValidationFailedException; -import org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefValidatation; -import org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefYangSyntaxErrorException; -import org.opendaylight.yangtools.yang.data.impl.schema.Builders; -import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes; -import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.CollectionNodeBuilder; -import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeAttrBuilder; -import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder; -import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.ListNodeBuilder; -import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeAttrBuilder; -import org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory; -import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode; -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.parser.api.YangSyntaxErrorException; -import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class DataTreeCandidateValidatorTest { - - private static SchemaContext context; - private static Module valModule; - private static QNameModule valModuleQname; - private static LeafRefContext rootLeafRefContext; - public static TipProducingDataTree inMemoryDataTree; - - private static QName odl; - private static QName project; - private static QName name; - private static QName desc; - private static QName lead; - private static QName owner; - private static QName odlContributor; - private static QName contributor; - private static QName odlProjectName; - private static QName odlProjectDesc; - private static QName login; - private static QName contributorName; - private static QName l1; - private static QName l2; - private static QName con1; - private static QName ch1; - private static QName ch2; - private static QName leafrefInChoice; - private static QName listInChoice; - - private static QName leafrefInChoiceToChoice; - private static QName con3; - private static QName list3InChoice; - private static QName l3; - private static QName choiceInCon3; - - private static QName listInChoiceKey; - private static QName k; - - private static QName leafrefLeafList; - - private static final Logger LOG = LoggerFactory.getLogger(DataTreeCandidateValidatorTest.class); - private static final String NEW_LINE = System.getProperty("line.separator"); - - static { - BasicConfigurator.configure(); - } - - @BeforeClass - public static void init() throws URISyntaxException, IOException, - YangSyntaxErrorException, LeafRefYangSyntaxErrorException { - initSchemaContext(); - - initLeafRefContext(); - - initQnames(); - - initDataTree(); - - } - - private static void initSchemaContext() throws URISyntaxException, - IOException, YangSyntaxErrorException { - final File resourceFile = new File(DataTreeCandidateValidatorTest.class - .getResource("/leafref-validation/leafref-validation.yang") - .toURI()); - final File resourceDir = resourceFile.getParentFile(); - - final YangParserImpl parser = YangParserImpl.getInstance(); - context = parser.parseFile(resourceFile, resourceDir); - - final Set modules = context.getModules(); - for (final Module module : modules) { - if (module.getName().equals("leafref-validation")) { - valModule = module; - } - } - - valModuleQname = valModule.getQNameModule(); - } - - private static void initLeafRefContext() throws IOException, - LeafRefYangSyntaxErrorException { - rootLeafRefContext = LeafRefContext.create(context); - } - - private static void initQnames() { - odl = QName.create(valModuleQname, "odl-project"); - project = QName.create(valModuleQname, "project"); - name = QName.create(valModuleQname, "name"); - desc = QName.create(valModuleQname, "desc"); - lead = QName.create(valModuleQname, "project-lead"); - owner = QName.create(valModuleQname, "project-owner"); - - odlContributor = QName.create(valModuleQname, "odl-contributor"); - contributor = QName.create(valModuleQname, "contributor"); - odlProjectName = QName.create(valModuleQname, "odl-project-name"); - login = QName.create(valModuleQname, "login"); - contributorName = QName.create(valModuleQname, "contributor-name"); - - con1 = QName.create(valModuleQname, "con1"); - l1 = QName.create(valModuleQname, "l1"); - l2 = QName.create(valModuleQname, "l2"); - odlProjectDesc = QName.create(valModuleQname, "odl-project-desc"); - - ch1 = QName.create(valModuleQname, "ch1"); - ch2 = QName.create(valModuleQname, "ch2"); - leafrefInChoice = QName.create(valModuleQname, "leafref-in-choice"); - listInChoice = QName.create(valModuleQname, "list-in-choice"); - - leafrefInChoiceToChoice = QName.create(valModuleQname, - "leafref-in-choice-to-choice"); - con3 = QName.create(valModuleQname, "con3"); - list3InChoice = QName.create(valModuleQname, "list3-in-choice"); - l3 = QName.create(valModuleQname, "l3"); - choiceInCon3 = QName.create(valModuleQname, "choice-in-con3"); - - listInChoiceKey = QName.create(valModuleQname, "list-in-choice-key"); - k = QName.create(valModuleQname, "k"); - - leafrefLeafList = QName.create(valModuleQname, "leafref-leaf-list"); - - } - - private static void initDataTree() { - inMemoryDataTree = InMemoryDataTreeFactory.getInstance().create(TreeType.OPERATIONAL); - inMemoryDataTree.setSchemaContext(context); - - final DataTreeModification initialDataTreeModification = inMemoryDataTree - .takeSnapshot().newModification(); - - final ContainerSchemaNode odlProjContSchemaNode = (ContainerSchemaNode) valModule - .getDataChildByName(odl); - - final ContainerNode odlProjectContainer = createOdlContainer(odlProjContSchemaNode); - - final YangInstanceIdentifier path = YangInstanceIdentifier.of(odl); - initialDataTreeModification.write(path, odlProjectContainer); - initialDataTreeModification.ready(); - - final DataTreeCandidate writeContributorsCandidate = inMemoryDataTree - .prepare(initialDataTreeModification); - inMemoryDataTree.commit(writeContributorsCandidate); - - } - - @Test - public void dataTreeCanditateValidationTest() { - write(); - - write2(); - - delete(); - - writeContributors(); - - writeMapEntry(); - - writeIntoMapEntry(); - } - - private static void writeContributors() { - - final ContainerSchemaNode contributorContSchemaNode = (ContainerSchemaNode) valModule - .getDataChildByName(odlContributor); - - final ContainerNode contributorContainer = createBasicContributorContainer(contributorContSchemaNode); - - final YangInstanceIdentifier contributorPath = YangInstanceIdentifier - .of(odlContributor); - final DataTreeModification writeModification = inMemoryDataTree - .takeSnapshot().newModification(); - writeModification.write(contributorPath, contributorContainer); - writeModification.ready(); - - final DataTreeCandidate writeContributorsCandidate = inMemoryDataTree - .prepare(writeModification); - - LOG.debug("*************************"); - LOG.debug("Before write of contributors: "); - LOG.debug("*************************"); - LOG.debug(inMemoryDataTree.toString()); - - boolean exception = false; - try { - LeafRefValidatation.validate(writeContributorsCandidate, rootLeafRefContext); - } catch (final LeafRefDataValidationFailedException e) { - LOG.debug("All validation errors:" + NEW_LINE + e.getMessage()); - assertEquals(3, e.getValidationsErrorsCount()); - exception = true; - } - - inMemoryDataTree.commit(writeContributorsCandidate); - - LOG.debug("*************************"); - LOG.debug("After write of contributors: "); - LOG.debug("*************************"); - LOG.debug(inMemoryDataTree.toString()); - - assertTrue(exception); - - } - - private static void writeIntoMapEntry() { - - final Map keys = new HashMap<>(); - keys.put(name, "New Project"); - final NodeIdentifierWithPredicates mapEntryPath = new NodeIdentifierWithPredicates( - project, keys); - - final YangInstanceIdentifier leaderPath = YangInstanceIdentifier.of(odl) - .node(project).node(mapEntryPath).node(lead); - - final LeafNode leader = ImmutableNodes.leafNode(lead, - "Updated leader"); - - final DataTreeModification writeModification = inMemoryDataTree - .takeSnapshot().newModification(); - writeModification.write(leaderPath, leader); - writeModification.ready(); - - final DataTreeCandidate writeContributorsCandidate = inMemoryDataTree - .prepare(writeModification); - - LOG.debug("*************************"); - LOG.debug("Before write into map entry (update of leader name): "); - LOG.debug("*************************"); - LOG.debug(inMemoryDataTree.toString()); - - boolean exception = false; - try { - LeafRefValidatation.validate(writeContributorsCandidate, rootLeafRefContext); - } catch (final LeafRefDataValidationFailedException e) { - LOG.debug("All validation errors:" + NEW_LINE + e.getMessage()); - assertEquals(1, e.getValidationsErrorsCount()); - exception = true; - } - - inMemoryDataTree.commit(writeContributorsCandidate); - - LOG.debug("*************************"); - LOG.debug("After write into map entry (update of leader name): "); - LOG.debug("*************************"); - LOG.debug(inMemoryDataTree.toString()); - - assertTrue(exception); - - } - - private static void writeMapEntry() { - - final Map keys = new HashMap<>(); - keys.put(name, "New Project"); - final NodeIdentifierWithPredicates mapEntryPath = new NodeIdentifierWithPredicates( - project, keys); - - final YangInstanceIdentifier newOdlProjectMapEntryPath = YangInstanceIdentifier - .of(odl).node(project).node(mapEntryPath); - - final ContainerSchemaNode odlProjContSchemaNode = (ContainerSchemaNode) valModule - .getDataChildByName(odl); - final ListSchemaNode projListSchemaNode = (ListSchemaNode) odlProjContSchemaNode - .getDataChildByName(project); - final MapEntryNode newProjectMapEntry = createProjectListEntry("New Project", - "New Project description ...", "Leader of New Project", - "Owner of New Project", projListSchemaNode); - - final DataTreeModification writeModification = inMemoryDataTree - .takeSnapshot().newModification(); - writeModification.write(newOdlProjectMapEntryPath, newProjectMapEntry); - writeModification.ready(); - - final DataTreeCandidate writeContributorsCandidate = inMemoryDataTree - .prepare(writeModification); - - LOG.debug("*************************"); - LOG.debug("Before map entry write: "); - LOG.debug("*************************"); - LOG.debug(inMemoryDataTree.toString()); - - boolean exception = false; - try { - LeafRefValidatation.validate(writeContributorsCandidate, rootLeafRefContext); - } catch (final LeafRefDataValidationFailedException e) { - LOG.debug("All validation errors:" + NEW_LINE + e.getMessage()); - assertEquals(2, e.getValidationsErrorsCount()); - exception = true; - } - - inMemoryDataTree.commit(writeContributorsCandidate); - - LOG.debug("*************************"); - LOG.debug("After map entry write: "); - LOG.debug("*************************"); - LOG.debug(inMemoryDataTree.toString()); - - assertTrue(exception); - - } - - private static void write() { - - final ContainerSchemaNode contributorContSchemaNode = (ContainerSchemaNode) valModule - .getDataChildByName(odlContributor); - - final ContainerNode contributorContainer = createContributorContainer(contributorContSchemaNode); - - final YangInstanceIdentifier contributorPath = YangInstanceIdentifier - .of(odlContributor); - final DataTreeModification writeModification = inMemoryDataTree - .takeSnapshot().newModification(); - writeModification.write(contributorPath, contributorContainer); - - writeModification.write(YangInstanceIdentifier.of(l1), - ImmutableNodes.leafNode(l1, "Leafref l1 under the root")); - writeModification - .write(YangInstanceIdentifier.of(l2), ImmutableNodes.leafNode( - l2, "Leafref target l2 under the root")); - - writeModification.ready(); - final DataTreeCandidate writeContributorsCandidate = inMemoryDataTree - .prepare(writeModification); - - LOG.debug("*************************"); - LOG.debug("Before write: "); - LOG.debug("*************************"); - LOG.debug(inMemoryDataTree.toString()); - - boolean exception = false; - try { - LeafRefValidatation.validate(writeContributorsCandidate, rootLeafRefContext); - } catch (final LeafRefDataValidationFailedException e) { - LOG.debug("All validation errors:" + NEW_LINE + e.getMessage()); - assertEquals(12, e.getValidationsErrorsCount()); - exception = true; - } - - inMemoryDataTree.commit(writeContributorsCandidate); - - LOG.debug("*************************"); - LOG.debug("After write: "); - LOG.debug("*************************"); - LOG.debug(inMemoryDataTree.toString()); - - assertTrue(exception); - } - - private static void write2() { - - final ContainerSchemaNode odlCon = (ContainerSchemaNode) valModule - .getDataChildByName(odl); - final ContainerSchemaNode con1Con = (ContainerSchemaNode) odlCon - .getDataChildByName(con1); - final LeafNode l1Leaf = ImmutableNodes.leafNode(l1, "l1 value"); - final DataContainerNodeAttrBuilder containerBuilder = Builders - .containerBuilder(con1Con); - containerBuilder.addChild(l1Leaf); - final ContainerNode con1Node = containerBuilder.build(); - - final YangInstanceIdentifier con1Path = YangInstanceIdentifier.of(odl).node( - con1); - final DataTreeModification writeModification = inMemoryDataTree - .takeSnapshot().newModification(); - writeModification.write(con1Path, con1Node); - - final ChoiceNode choiceNode = createChoiceNode(); - final YangInstanceIdentifier choicePath = YangInstanceIdentifier.of(odl) - .node(ch1); - writeModification.write(choicePath, choiceNode); - - final ContainerNode con3Node = createCon3Node(); - final YangInstanceIdentifier con3Path = YangInstanceIdentifier.of(odl).node( - con3); - writeModification.write(con3Path, con3Node); - - final LeafSetNode leafListNode = createLeafRefLeafListNode(); - final YangInstanceIdentifier leafListPath = YangInstanceIdentifier.of(odl) - .node(leafrefLeafList); - writeModification.write(leafListPath, leafListNode); - writeModification.ready(); - - final DataTreeCandidate writeContributorsCandidate = inMemoryDataTree - .prepare(writeModification); - - LOG.debug("*************************"); - LOG.debug("Before write2: "); - LOG.debug("*************************"); - LOG.debug(inMemoryDataTree.toString()); - - boolean exception = false; - try { - LeafRefValidatation.validate(writeContributorsCandidate, rootLeafRefContext); - } catch (final LeafRefDataValidationFailedException e) { - LOG.debug("All validation errors:" + NEW_LINE + e.getMessage()); - assertEquals(6, e.getValidationsErrorsCount()); - exception = true; - } - - assertTrue(exception); - - inMemoryDataTree.commit(writeContributorsCandidate); - - LOG.debug("*************************"); - LOG.debug("After write2: "); - LOG.debug("*************************"); - LOG.debug(inMemoryDataTree.toString()); - - } - - private static LeafSetNode createLeafRefLeafListNode() { - - final ListNodeBuilder> leafSetBuilder = Builders - .leafSetBuilder(); - leafSetBuilder.withNodeIdentifier(new NodeIdentifier(leafrefLeafList)); - - leafSetBuilder.addChild(createLeafSetEntry(leafrefLeafList, "k1")); - leafSetBuilder.addChild(createLeafSetEntry(leafrefLeafList, "k2")); - leafSetBuilder.addChild(createLeafSetEntry(leafrefLeafList, "k3")); - - return leafSetBuilder.build(); - } - - private static ContainerNode createCon3Node() { - - final CollectionNodeBuilder mapBuilder = Builders - .mapBuilder(); - mapBuilder.withNodeIdentifier(new NodeIdentifier(list3InChoice)); - - mapBuilder.addChild(createList3Entry("k1", "val1", "valA", "valX")); - mapBuilder.addChild(createList3Entry("k2", "val2", "valB", "valY")); - - final DataContainerNodeBuilder choiceBuilder = Builders - .choiceBuilder(); - choiceBuilder.withNodeIdentifier(new NodeIdentifier(choiceInCon3)); - - choiceBuilder.addChild(mapBuilder.build()); - - final DataContainerNodeAttrBuilder containerBuilder = Builders - .containerBuilder(); - containerBuilder.withNodeIdentifier(new NodeIdentifier(con3)); - - containerBuilder.addChild(choiceBuilder.build()); - - return containerBuilder.build(); - } - - private static MapEntryNode createList3Entry(final String kVal, final String l3Val1, - final String l3Val2, final String l3Val3) { - final DataContainerNodeAttrBuilder mapEntryBuilder = Builders - .mapEntryBuilder(); - mapEntryBuilder.withNodeIdentifier(new NodeIdentifierWithPredicates( - list3InChoice, k, kVal)); - - final ListNodeBuilder> leafSetBuilder = Builders - .leafSetBuilder(); - leafSetBuilder.withNodeIdentifier(new NodeIdentifier(l3)); - - leafSetBuilder.addChild(createLeafSetEntry(l3, l3Val1)); - leafSetBuilder.addChild(createLeafSetEntry(l3, l3Val2)); - leafSetBuilder.addChild(createLeafSetEntry(l3, l3Val3)); - - mapEntryBuilder.addChild(ImmutableNodes.leafNode(k, kVal)); - mapEntryBuilder.addChild(leafSetBuilder.build()); - - return mapEntryBuilder.build(); - } - - private static LeafSetEntryNode createLeafSetEntry(final QName qname, final String val) { - final NormalizedNodeAttrBuilder> leafSetEntryBuilder = Builders - .leafSetEntryBuilder(); - leafSetEntryBuilder.withNodeIdentifier(new NodeWithValue<>(qname, val)); - leafSetEntryBuilder.withValue(val); - return leafSetEntryBuilder.build(); - } - - private static ChoiceNode createChoiceNode() { - - final CollectionNodeBuilder listInChoiceBuilder = Builders - .mapBuilder(); - listInChoiceBuilder - .withNodeIdentifier(new NodeIdentifier(listInChoice)); - - listInChoiceBuilder.addChild(createListInChoiceEntry("key1", - "leafref-in-choice value", "val1")); - listInChoiceBuilder.addChild(createListInChoiceEntry("key2", - "l1 value", "val2")); - listInChoiceBuilder.addChild(createListInChoiceEntry("key3", - "l1 value", "val3")); - - final DataContainerNodeBuilder choice2Builder = Builders - .choiceBuilder(); - choice2Builder.withNodeIdentifier(new NodeIdentifier(ch2)); - - choice2Builder.addChild(listInChoiceBuilder.build()); - - final DataContainerNodeBuilder choiceBuilder = Builders - .choiceBuilder(); - choiceBuilder.withNodeIdentifier(new NodeIdentifier(ch1)); - choiceBuilder.addChild(choice2Builder.build()); - - return choiceBuilder.build(); - } - - private static MapEntryNode createListInChoiceEntry(final String keyVal, - final String leafrefInChoiceVal, final String leafrefInChoiceToChoiceVal) { - - final DataContainerNodeAttrBuilder mapEntryBuilder = Builders - .mapEntryBuilder(); - - mapEntryBuilder.withNodeIdentifier(new NodeIdentifierWithPredicates( - listInChoice, listInChoiceKey, keyVal)); - - mapEntryBuilder.addChild(ImmutableNodes.leafNode(listInChoiceKey, - keyVal)); - mapEntryBuilder.addChild(ImmutableNodes.leafNode(leafrefInChoice, - leafrefInChoiceVal)); - mapEntryBuilder.addChild(ImmutableNodes.leafNode( - leafrefInChoiceToChoice, leafrefInChoiceToChoiceVal)); - - return mapEntryBuilder.build(); - } - - private static void delete() { - - final YangInstanceIdentifier contributorPath = YangInstanceIdentifier - .of(odlContributor); - final DataTreeModification delete = inMemoryDataTree.takeSnapshot() - .newModification(); - delete.delete(contributorPath); - delete.ready(); - - final DataTreeCandidate deleteContributorsCanditate = inMemoryDataTree - .prepare(delete); - - LOG.debug("*************************"); - LOG.debug("Before delete: "); - LOG.debug("*************************"); - LOG.debug(inMemoryDataTree.toString()); - - boolean exception = false; - try { - LeafRefValidatation.validate(deleteContributorsCanditate, rootLeafRefContext); - } catch (final LeafRefDataValidationFailedException e) { - LOG.debug("All validation errors:" + NEW_LINE + e.getMessage()); - assertEquals(6, e.getValidationsErrorsCount()); - exception = true; - } - - assertTrue(exception); - - inMemoryDataTree.commit(deleteContributorsCanditate); - - LOG.debug("*************************"); - LOG.debug("After delete: "); - LOG.debug("*************************"); - LOG.debug(inMemoryDataTree.toString()); - - } - - private static ContainerNode createContributorContainer( - final ContainerSchemaNode contributorContSchemaNode) { - - final ListSchemaNode contributorListSchemaNode = (ListSchemaNode) contributorContSchemaNode - .getDataChildByName(contributor); - - final DataContainerNodeAttrBuilder contributorContainerBldr = Builders - .containerBuilder(contributorContSchemaNode); - - final MapNode contributorMap = createContributorList(contributorListSchemaNode); - contributorContainerBldr.addChild(contributorMap); - - final ContainerNode contributorContainer = contributorContainerBldr.build(); - - return contributorContainer; - - } - - private static MapNode createContributorList( - final ListSchemaNode contributorListSchemaNode) { - - final CollectionNodeBuilder contributorMapBldr = Builders - .mapBuilder(contributorListSchemaNode); - - final MapEntryNode contributorMapEntry1 = createContributorListEntry( - "Leader of Yangtools", "Yangtools Leader name", "Yangtools", - "Yangtools description ...", contributorListSchemaNode); - final MapEntryNode contributorMapEntry2 = createContributorListEntry( - "Leader of MD-SAL", "MD-SAL Leader name", "MD-SAL", - "MD-SAL description ...", contributorListSchemaNode); - final MapEntryNode contributorMapEntry3 = createContributorListEntry( - "Leader of Controller", "Controller Leader name", "Controller", - "Controller description ...", contributorListSchemaNode); - - final MapEntryNode contributorMapEntry4 = createContributorListEntry("jdoe", - "John Doe", "MD-SAL", "Yangtools description ...", - contributorListSchemaNode); - - final MapEntryNode contributorMapEntry5 = createContributorListEntry("foo", - "foo name", "Controller", "MD-SAL description ...", - contributorListSchemaNode); - - final MapEntryNode contributorMapEntry6 = createContributorListEntry("bar", - "bar name", "Yangtools", "Controller description ...", - contributorListSchemaNode); - - final MapEntryNode contributorMapEntry7 = createContributorListEntry("baz", - "baz name", "Unknown Project", - "Unknown Project description ...", contributorListSchemaNode); - - final MapEntryNode contributorMapEntry8 = createContributorListEntry("pk", - "pk name", "Unknown Project 2", "Controller description ...", - contributorListSchemaNode); - - contributorMapBldr.addChild(contributorMapEntry1); - contributorMapBldr.addChild(contributorMapEntry2); - contributorMapBldr.addChild(contributorMapEntry3); - contributorMapBldr.addChild(contributorMapEntry4); - contributorMapBldr.addChild(contributorMapEntry5); - contributorMapBldr.addChild(contributorMapEntry6); - contributorMapBldr.addChild(contributorMapEntry7); - contributorMapBldr.addChild(contributorMapEntry8); - - final MapNode contributorMap = contributorMapBldr.build(); - - return contributorMap; - - } - - private static MapEntryNode createContributorListEntry(final String loginVal, - final String contributorNameVal, final String odlProjectNameVal, - final String odlProjectDescVal, final ListSchemaNode contributorListSchemaNode) { - - final LeafNode loginLeaf = ImmutableNodes.leafNode(login, loginVal); - final LeafNode contributorNameLeaf = ImmutableNodes.leafNode( - contributorName, contributorNameVal); - final LeafNode odlProjectNameLeafRef = ImmutableNodes.leafNode( - odlProjectName, odlProjectNameVal); - final LeafNode odlProjectDescLeafRef = ImmutableNodes.leafNode( - odlProjectDesc, odlProjectDescVal); - - final DataContainerNodeAttrBuilder contributorMapEntryBldr = Builders - .mapEntryBuilder(contributorListSchemaNode); - - contributorMapEntryBldr.addChild(loginLeaf); - contributorMapEntryBldr.addChild(contributorNameLeaf); - contributorMapEntryBldr.addChild(odlProjectNameLeafRef); - contributorMapEntryBldr.addChild(odlProjectDescLeafRef); - - final MapEntryNode contributorMapEntry = contributorMapEntryBldr.build(); - - return contributorMapEntry; - } - - private static ContainerNode createOdlContainer( - final ContainerSchemaNode container) { - - final ListSchemaNode projListSchemaNode = (ListSchemaNode) container - .getDataChildByName(project); - - final DataContainerNodeAttrBuilder odlProjectContainerBldr = Builders - .containerBuilder(container); - - final MapNode projectMap = createProjectList(projListSchemaNode); - odlProjectContainerBldr.addChild(projectMap); - - final ContainerNode odlProjectContainer = odlProjectContainerBldr.build(); - - return odlProjectContainer; - } - - private static MapNode createProjectList(final ListSchemaNode projListSchemaNode) { - - final CollectionNodeBuilder projectMapBldr = Builders - .mapBuilder(projListSchemaNode); - - final MapEntryNode projMapEntry1 = createProjectListEntry("Yangtools", - "Yangtools description ...", "Leader of Yangtools", - "Owner of Yangtools", projListSchemaNode); - final MapEntryNode projMapEntry2 = createProjectListEntry("MD-SAL", - "MD-SAL description ...", "Leader of MD-SAL", - "Owner of MD-SAL", projListSchemaNode); - final MapEntryNode projMapEntry3 = createProjectListEntry("Controller", - "Controller description ...", "Leader of Controller", - "Owner of Controller", projListSchemaNode); - - projectMapBldr.addChild(projMapEntry1); - projectMapBldr.addChild(projMapEntry2); - projectMapBldr.addChild(projMapEntry3); - - final MapNode projectMap = projectMapBldr.build(); - - return projectMap; - } - - private static MapEntryNode createProjectListEntry(final String nameVal, - final String descVal, final String leadVal, final String ownerVal, - final ListSchemaNode projListSchemaNode) { - - final LeafNode nameLeaf = ImmutableNodes.leafNode(name, nameVal); - final LeafNode descLeaf = ImmutableNodes.leafNode(desc, descVal); - final LeafNode leadLeafRef = ImmutableNodes.leafNode(lead, leadVal); - final LeafNode ownerLeafRef = ImmutableNodes - .leafNode(owner, ownerVal); - - final DataContainerNodeAttrBuilder projMapEntryBldr = Builders - .mapEntryBuilder(projListSchemaNode); - - projMapEntryBldr.addChild(nameLeaf); - projMapEntryBldr.addChild(descLeaf); - projMapEntryBldr.addChild(leadLeafRef); - projMapEntryBldr.addChild(ownerLeafRef); - final MapEntryNode projMapEntry = projMapEntryBldr.build(); - - return projMapEntry; - } - - private static ContainerNode createBasicContributorContainer( - final ContainerSchemaNode contributorContSchemaNode) { - - final ListSchemaNode contributorListSchemaNode = (ListSchemaNode) contributorContSchemaNode - .getDataChildByName(contributor); - - final DataContainerNodeAttrBuilder contributorContainerBldr = Builders - .containerBuilder(contributorContSchemaNode); - - final MapNode contributorMap = createBasicContributorList(contributorListSchemaNode); - contributorContainerBldr.addChild(contributorMap); - - final ContainerNode contributorContainer = contributorContainerBldr.build(); - - return contributorContainer; - - } - - private static MapNode createBasicContributorList( - final ListSchemaNode contributorListSchemaNode) { - - final CollectionNodeBuilder contributorMapBldr = Builders - .mapBuilder(contributorListSchemaNode); - - final MapEntryNode contributorMapEntry1 = createContributorListEntry( - "Leader of Yangtools", "Yangtools Leader name", "Yangtools", - "Yangtools description ...", contributorListSchemaNode); - final MapEntryNode contributorMapEntry2 = createContributorListEntry( - "Leader of MD-SAL", "MD-SAL Leader name", "MD-SAL", - "MD-SAL description ...", contributorListSchemaNode); - final MapEntryNode contributorMapEntry3 = createContributorListEntry( - "Leader of Controller", "Controller Leader name", "Controller", - "Controller description ...", contributorListSchemaNode); - - contributorMapBldr.addChild(contributorMapEntry1); - contributorMapBldr.addChild(contributorMapEntry2); - contributorMapBldr.addChild(contributorMapEntry3); - - final MapNode contributorMap = contributorMapBldr.build(); - - return contributorMap; - } -} diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/test/DataTreeCandidateValidatorTest2.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/test/DataTreeCandidateValidatorTest2.java deleted file mode 100644 index eb5e7bcca6..0000000000 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/test/DataTreeCandidateValidatorTest2.java +++ /dev/null @@ -1,361 +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.data.impl.leafref.context.test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import java.io.File; -import java.io.IOException; -import java.net.URISyntaxException; -import java.util.Set; -import org.apache.log4j.BasicConfigurator; -import org.junit.BeforeClass; -import org.junit.Test; -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.common.QNameModule; -import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; -import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier; -import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates; -import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode; -import org.opendaylight.yangtools.yang.data.api.schema.LeafNode; -import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode; -import org.opendaylight.yangtools.yang.data.api.schema.MapNode; -import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate; -import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification; -import org.opendaylight.yangtools.yang.data.api.schema.tree.TipProducingDataTree; -import org.opendaylight.yangtools.yang.data.api.schema.tree.TreeType; -import org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefContext; -import org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefDataValidationFailedException; -import org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefValidatation; -import org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefYangSyntaxErrorException; -import org.opendaylight.yangtools.yang.data.impl.schema.Builders; -import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes; -import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.CollectionNodeBuilder; -import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeAttrBuilder; -import org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory; -import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode; -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.parser.api.YangSyntaxErrorException; -import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class DataTreeCandidateValidatorTest2 { - - private static SchemaContext context; - private static Module mainModule; - private static QNameModule rootModuleQname; - private static LeafRefContext rootLeafRefContext; - public static TipProducingDataTree inMemoryDataTree; - - private static QName chips; - private static QName chip; - private static QName devType; - private static QName chipDesc; - - private static QName devices; - private static QName device; - private static QName typeChoice; - private static QName typeText; - private static QName devDesc; - private static QName sn; - private static QName defaultIp; - - private static QName deviceTypeStr; - private static QName deviceType; - private static QName type; - private static QName desc; - - private static final Logger LOG = LoggerFactory.getLogger(DataTreeCandidateValidatorTest2.class); - private static final String NEW_LINE = System.getProperty("line.separator"); - - static { - BasicConfigurator.configure(); - } - - @BeforeClass - public static void init() throws URISyntaxException, IOException, - YangSyntaxErrorException, LeafRefYangSyntaxErrorException { - - initSchemaContext(); - initLeafRefContext(); - initQnames(); - initDataTree(); - } - - @Test - public void dataTreeCanditateValidationTest2() { - - writeDevices(); - } - - private static void writeDevices() { - - final ContainerSchemaNode devicesContSchemaNode = (ContainerSchemaNode) mainModule - .getDataChildByName(devices); - - final ContainerNode devicesContainer = createDevicesContainer(devicesContSchemaNode); - - final YangInstanceIdentifier devicesPath = YangInstanceIdentifier.of(devices); - final DataTreeModification writeModification = inMemoryDataTree - .takeSnapshot().newModification(); - writeModification.write(devicesPath, devicesContainer); - - writeModification.ready(); - final DataTreeCandidate writeDevicesCandidate = inMemoryDataTree - .prepare(writeModification); - - LOG.debug("*************************"); - LOG.debug("Before writeDevices: "); - LOG.debug("*************************"); - LOG.debug(inMemoryDataTree.toString()); - - boolean exception = false; - try { - LeafRefValidatation.validate(writeDevicesCandidate, rootLeafRefContext); - } catch (final LeafRefDataValidationFailedException e) { - LOG.debug("All validation errors:" + NEW_LINE + e.getMessage()); - - assertEquals(4, e.getValidationsErrorsCount()); - exception = true; - } - - assertTrue(exception); - - inMemoryDataTree.commit(writeDevicesCandidate); - - LOG.debug("*************************"); - LOG.debug("After write: "); - LOG.debug("*************************"); - LOG.debug(inMemoryDataTree.toString()); - } - - private static void initQnames() { - - chips = QName.create(rootModuleQname, "chips"); - chip = QName.create(rootModuleQname, "chip"); - devType = QName.create(rootModuleQname, "dev_type"); - chipDesc = QName.create(rootModuleQname, "chip_desc"); - - devices = QName.create(rootModuleQname, "devices"); - device = QName.create(rootModuleQname, "device"); - typeText = QName.create(rootModuleQname, "type_text"); - devDesc = QName.create(rootModuleQname, "dev_desc"); - sn = QName.create(rootModuleQname, "sn"); - defaultIp = QName.create(rootModuleQname, "default_ip"); - - deviceTypeStr = QName.create(rootModuleQname, "device_types"); - deviceType = QName.create(rootModuleQname, "device_type"); - type = QName.create(rootModuleQname, "type"); - desc = QName.create(rootModuleQname, "desc"); - } - - private static void initSchemaContext() throws URISyntaxException, - IOException, YangSyntaxErrorException { - - final File resourceFile = new File(DataTreeCandidateValidatorTest.class - .getResource("/leafref-validation/leafref-validation2.yang") - .toURI()); - final File resourceDir = resourceFile.getParentFile(); - - final YangParserImpl parser = YangParserImpl.getInstance(); - context = parser.parseFile(resourceFile, resourceDir); - - final Set modules = context.getModules(); - for (final Module module : modules) { - if (module.getName().equals("leafref-validation2")) { - mainModule = module; - } - } - - rootModuleQname = mainModule.getQNameModule(); - } - - private static void initDataTree() { - - inMemoryDataTree = InMemoryDataTreeFactory.getInstance().create(TreeType.OPERATIONAL); - inMemoryDataTree.setSchemaContext(context); - - final DataTreeModification initialDataTreeModification = inMemoryDataTree - .takeSnapshot().newModification(); - - final ContainerSchemaNode chipsListContSchemaNode = (ContainerSchemaNode) mainModule - .getDataChildByName(chips); - final ContainerNode chipsContainer = createChipsContainer(chipsListContSchemaNode); - final YangInstanceIdentifier path1 = YangInstanceIdentifier.of(chips); - initialDataTreeModification.write(path1, chipsContainer); - - final ContainerSchemaNode devTypesListContSchemaNode = (ContainerSchemaNode) mainModule - .getDataChildByName(deviceTypeStr); - final ContainerNode deviceTypesContainer = createDevTypeStrContainer(devTypesListContSchemaNode); - final YangInstanceIdentifier path2 = YangInstanceIdentifier.of(deviceTypeStr); - initialDataTreeModification.write(path2, deviceTypesContainer); - - initialDataTreeModification.ready(); - final DataTreeCandidate writeChipsCandidate = inMemoryDataTree - .prepare(initialDataTreeModification); - - inMemoryDataTree.commit(writeChipsCandidate); - - System.out.println(inMemoryDataTree.toString()); - } - - private static void initLeafRefContext() throws IOException, - LeafRefYangSyntaxErrorException { - rootLeafRefContext = LeafRefContext.create(context); - } - - private static ContainerNode createDevTypeStrContainer( - final ContainerSchemaNode container) { - - final ListSchemaNode devTypeListSchemaNode = (ListSchemaNode) container - .getDataChildByName(deviceType); - - final DataContainerNodeAttrBuilder devTypeContainerBldr = Builders - .containerBuilder(container); - - final MapNode devTypeMap = createDevTypeList(devTypeListSchemaNode); - devTypeContainerBldr.addChild(devTypeMap); - - return devTypeContainerBldr.build(); - } - - private static MapNode createDevTypeList( - final ListSchemaNode devTypeListSchemaNode) { - - final CollectionNodeBuilder devTypeMapBldr = Builders - .mapBuilder(devTypeListSchemaNode); - - devTypeMapBldr.addChild(createDevTypeListEntry("dev_type_1", - "typedesc1", devTypeListSchemaNode)); - devTypeMapBldr.addChild(createDevTypeListEntry("dev_type_2", - "typedesc2", devTypeListSchemaNode)); - devTypeMapBldr.addChild(createDevTypeListEntry("dev_type_3", - "typedesc3", devTypeListSchemaNode)); - - return devTypeMapBldr.build(); - } - - private static MapEntryNode createDevTypeListEntry(final String typeVal, - final String descVal, final ListSchemaNode devTypeListSchemaNode) { - - final LeafNode typeLeaf = ImmutableNodes.leafNode(type, typeVal); - final LeafNode descLeaf = ImmutableNodes.leafNode(desc, descVal); - - final DataContainerNodeAttrBuilder devTypeMapEntryBldr = Builders - .mapEntryBuilder(devTypeListSchemaNode); - - devTypeMapEntryBldr.addChild(typeLeaf); - devTypeMapEntryBldr.addChild(descLeaf); - - return devTypeMapEntryBldr.build(); - } - - private static ContainerNode createChipsContainer( - final ContainerSchemaNode container) { - - final ListSchemaNode chipsListSchemaNode = (ListSchemaNode) container - .getDataChildByName(chip); - - final DataContainerNodeAttrBuilder chipsContainerBldr = Builders - .containerBuilder(container); - - final MapNode chipsMap = createChipsList(chipsListSchemaNode); - chipsContainerBldr.addChild(chipsMap); - - return chipsContainerBldr.build(); - } - - private static MapNode createChipsList(final ListSchemaNode chipsListSchemaNode) { - - final CollectionNodeBuilder chipsMapBldr = Builders - .mapBuilder(chipsListSchemaNode); - - chipsMapBldr.addChild(createChipsListEntry("dev_type_1", "desc1", - chipsListSchemaNode)); - chipsMapBldr.addChild(createChipsListEntry("dev_type_2", "desc2", - chipsListSchemaNode)); - - return chipsMapBldr.build(); - } - - private static MapEntryNode createChipsListEntry(final String devTypeVal, - final String chipDescVal, final ListSchemaNode chipsListSchemaNode) { - - final LeafNode devTypeLeaf = ImmutableNodes.leafNode(devType, - devTypeVal); - final LeafNode chipDescLeaf = ImmutableNodes.leafNode(chipDesc, - chipDescVal); - - final DataContainerNodeAttrBuilder chipsMapEntryBldr = Builders - .mapEntryBuilder(chipsListSchemaNode); - - chipsMapEntryBldr.addChild(devTypeLeaf); - chipsMapEntryBldr.addChild(chipDescLeaf); - - return chipsMapEntryBldr.build(); - } - - private static ContainerNode createDevicesContainer( - final ContainerSchemaNode container) { - - final ListSchemaNode devicesListSchemaNode = (ListSchemaNode) container - .getDataChildByName(device); - - final DataContainerNodeAttrBuilder devicesContainerBldr = Builders - .containerBuilder(container); - - final MapNode devicesMap = createDeviceList(devicesListSchemaNode); - devicesContainerBldr.addChild(devicesMap); - - return devicesContainerBldr.build(); - } - - private static MapNode createDeviceList(final ListSchemaNode deviceListSchemaNode) { - - final CollectionNodeBuilder devicesMapBldr = Builders - .mapBuilder(deviceListSchemaNode); - - devicesMapBldr.addChild(createDeviceListEntry("dev_type_1", - "typedesc1", 123456, "192.168.0.1", deviceListSchemaNode)); - devicesMapBldr.addChild(createDeviceListEntry("dev_type_2", - "typedesc2", 123457, "192.168.0.1", deviceListSchemaNode)); - devicesMapBldr.addChild(createDeviceListEntry("dev_type_2", - "typedesc3", 123457, "192.168.0.1", deviceListSchemaNode)); - devicesMapBldr.addChild(createDeviceListEntry("dev_type_1", - "typedesc2", 123458, "192.168.0.1", deviceListSchemaNode)); - devicesMapBldr.addChild(createDeviceListEntry("unknown", "unknown", - 123457, "192.168.0.1", deviceListSchemaNode)); - - return devicesMapBldr.build(); - } - - private static MapEntryNode createDeviceListEntry(final String typeTextVal, - final String descVal, final int snVal, final String defaultIpVal, - final ListSchemaNode devicesListSchemaNode) { - - final LeafNode typeTextLeaf = ImmutableNodes.leafNode(typeText, - typeTextVal); - final LeafNode descLeaf = ImmutableNodes.leafNode(devDesc, descVal); - final LeafNode snValLeaf = ImmutableNodes.leafNode(sn, snVal); - final LeafNode defaultIpLeaf = ImmutableNodes.leafNode(defaultIp, - defaultIpVal); - - final DataContainerNodeAttrBuilder devicesMapEntryBldr = Builders - .mapEntryBuilder(devicesListSchemaNode); - - devicesMapEntryBldr.addChild(typeTextLeaf); - devicesMapEntryBldr.addChild(descLeaf); - devicesMapEntryBldr.addChild(snValLeaf); - devicesMapEntryBldr.addChild(defaultIpLeaf); - - return devicesMapEntryBldr.build(); - } -} \ No newline at end of file diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/test/DataTreeCandidateValidatorTest3.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/test/DataTreeCandidateValidatorTest3.java deleted file mode 100644 index fb57f9b660..0000000000 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/test/DataTreeCandidateValidatorTest3.java +++ /dev/null @@ -1,462 +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.data.impl.leafref.context.test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import java.io.File; -import java.io.IOException; -import java.net.URISyntaxException; -import java.util.Set; -import org.apache.log4j.BasicConfigurator; -import org.junit.BeforeClass; -import org.junit.Test; -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.common.QNameModule; -import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; -import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier; -import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates; -import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode; -import org.opendaylight.yangtools.yang.data.api.schema.LeafNode; -import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode; -import org.opendaylight.yangtools.yang.data.api.schema.MapNode; -import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate; -import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification; -import org.opendaylight.yangtools.yang.data.api.schema.tree.TipProducingDataTree; -import org.opendaylight.yangtools.yang.data.api.schema.tree.TreeType; -import org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefContext; -import org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefDataValidationFailedException; -import org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefValidatation; -import org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefYangSyntaxErrorException; -import org.opendaylight.yangtools.yang.data.impl.schema.Builders; -import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes; -import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.CollectionNodeBuilder; -import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeAttrBuilder; -import org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory; -import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode; -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.parser.api.YangSyntaxErrorException; -import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class DataTreeCandidateValidatorTest3 { - - private static SchemaContext context; - private static Module mainModule; - private static QNameModule rootModuleQname; - private static LeafRefContext rootLeafRefContext; - public static TipProducingDataTree inMemoryDataTree; - - private static QName chips; - private static QName chip; - private static QName devType; - private static QName chipDesc; - - private static QName devices; - private static QName device; - private static QName typeText1; - private static QName typeText2; - private static QName typeText3; - private static QName devDesc; - private static QName sn; - private static QName defaultIp; - - private static QName deviceTypeStr; - private static QName deviceType; - private static QName type1; - private static QName type2; - private static QName type3; - private static QName desc; - - private static final Logger LOG = LoggerFactory.getLogger(DataTreeCandidateValidatorTest3.class); - private static final String NEW_LINE = System.getProperty("line.separator"); - - static { - BasicConfigurator.configure(); - } - - @BeforeClass - public static void init() throws URISyntaxException, IOException, - YangSyntaxErrorException, LeafRefYangSyntaxErrorException { - - initSchemaContext(); - initLeafRefContext(); - initQnames(); - initDataTree(); - } - - @Test - public void dataTreeCanditateValidationTest2() { - - writeDevices(); - - mergeDevices(); - } - - private static void writeDevices() { - - final ContainerSchemaNode devicesContSchemaNode = (ContainerSchemaNode) mainModule - .getDataChildByName(devices); - - final ContainerNode devicesContainer = createDevicesContainer(devicesContSchemaNode); - - final YangInstanceIdentifier devicesPath = YangInstanceIdentifier.of(devices); - final DataTreeModification writeModification = inMemoryDataTree - .takeSnapshot().newModification(); - writeModification.write(devicesPath, devicesContainer); - - writeModification.ready(); - final DataTreeCandidate writeDevicesCandidate = inMemoryDataTree - .prepare(writeModification); - - LOG.debug("*************************"); - LOG.debug("Before writeDevices: "); - LOG.debug("*************************"); - LOG.debug(inMemoryDataTree.toString()); - - boolean exception = false; - try { - LeafRefValidatation.validate(writeDevicesCandidate, rootLeafRefContext); - } catch (final LeafRefDataValidationFailedException e) { - LOG.debug("All validation errors:" + NEW_LINE + e.getMessage()); - assertEquals(6, e.getValidationsErrorsCount()); - exception = true; - } - - assertTrue(exception); - - inMemoryDataTree.commit(writeDevicesCandidate); - - LOG.debug("*************************"); - LOG.debug("After writeDevices: "); - LOG.debug("*************************"); - LOG.debug(inMemoryDataTree.toString()); - } - - private static void mergeDevices() { - - final ContainerSchemaNode devicesContSchemaNode = (ContainerSchemaNode) mainModule - .getDataChildByName(devices); - - final ContainerNode devicesContainer = createDevices2Container(devicesContSchemaNode); - - final YangInstanceIdentifier devicesPath = YangInstanceIdentifier.of(devices); - final DataTreeModification mergeModification = inMemoryDataTree - .takeSnapshot().newModification(); - mergeModification.write(devicesPath, devicesContainer); - mergeModification.merge(devicesPath, devicesContainer); - - mergeModification.ready(); - final DataTreeCandidate mergeDevicesCandidate = inMemoryDataTree - .prepare(mergeModification); - - LOG.debug("*************************"); - LOG.debug("Before mergeDevices: "); - LOG.debug("*************************"); - LOG.debug(inMemoryDataTree.toString()); - - boolean exception = false; - try { - LeafRefValidatation.validate(mergeDevicesCandidate, rootLeafRefContext); - } catch (final LeafRefDataValidationFailedException e) { - LOG.debug("All validation errors:" + NEW_LINE + e.getMessage()); - // :TODO verify errors count gz - assertEquals(6, e.getValidationsErrorsCount()); - exception = true; - } - - inMemoryDataTree.commit(mergeDevicesCandidate); - - LOG.debug("*************************"); - LOG.debug("After mergeDevices: "); - LOG.debug("*************************"); - LOG.debug(inMemoryDataTree.toString()); - - assertTrue(exception); - } - - private static void initQnames() { - - chips = QName.create(rootModuleQname, "chips"); - chip = QName.create(rootModuleQname, "chip"); - devType = QName.create(rootModuleQname, "dev_type"); - chipDesc = QName.create(rootModuleQname, "chip_desc"); - - devices = QName.create(rootModuleQname, "devices"); - device = QName.create(rootModuleQname, "device"); - typeText1 = QName.create(rootModuleQname, "type_text1"); - typeText2 = QName.create(rootModuleQname, "type_text2"); - typeText3 = QName.create(rootModuleQname, "type_text3"); - devDesc = QName.create(rootModuleQname, "dev_desc"); - sn = QName.create(rootModuleQname, "sn"); - defaultIp = QName.create(rootModuleQname, "default_ip"); - - deviceTypeStr = QName.create(rootModuleQname, "device_types"); - deviceType = QName.create(rootModuleQname, "device_type"); - type1 = QName.create(rootModuleQname, "type1"); - type2 = QName.create(rootModuleQname, "type2"); - type3 = QName.create(rootModuleQname, "type3"); - desc = QName.create(rootModuleQname, "desc"); - } - - private static void initSchemaContext() throws URISyntaxException, - IOException, YangSyntaxErrorException { - - final File resourceFile = new File(DataTreeCandidateValidatorTest.class - .getResource("/leafref-validation/leafref-validation3.yang") - .toURI()); - final File resourceDir = resourceFile.getParentFile(); - - final YangParserImpl parser = YangParserImpl.getInstance(); - context = parser.parseFile(resourceFile, resourceDir); - - final Set modules = context.getModules(); - for (final Module module : modules) { - if (module.getName().equals("leafref-validation3")) { - mainModule = module; - } - } - - rootModuleQname = mainModule.getQNameModule(); - } - - private static void initDataTree() { - - inMemoryDataTree = InMemoryDataTreeFactory.getInstance().create(TreeType.OPERATIONAL); - inMemoryDataTree.setSchemaContext(context); - - final DataTreeModification initialDataTreeModification = inMemoryDataTree - .takeSnapshot().newModification(); - - final ContainerSchemaNode chipsListContSchemaNode = (ContainerSchemaNode) mainModule - .getDataChildByName(chips); - final ContainerNode chipsContainer = createChipsContainer(chipsListContSchemaNode); - final YangInstanceIdentifier path1 = YangInstanceIdentifier.of(chips); - initialDataTreeModification.write(path1, chipsContainer); - - final ContainerSchemaNode devTypesListContSchemaNode = (ContainerSchemaNode) mainModule - .getDataChildByName(deviceTypeStr); - final ContainerNode deviceTypesContainer = createDevTypeStrContainer(devTypesListContSchemaNode); - final YangInstanceIdentifier path2 = YangInstanceIdentifier.of(deviceTypeStr); - initialDataTreeModification.write(path2, deviceTypesContainer); - - initialDataTreeModification.ready(); - final DataTreeCandidate writeChipsCandidate = inMemoryDataTree - .prepare(initialDataTreeModification); - - inMemoryDataTree.commit(writeChipsCandidate); - - System.out.println(inMemoryDataTree.toString()); - } - - private static void initLeafRefContext() throws IOException, - LeafRefYangSyntaxErrorException { - rootLeafRefContext = LeafRefContext.create(context); - } - - private static ContainerNode createDevTypeStrContainer( - final ContainerSchemaNode container) { - - final ListSchemaNode devTypeListSchemaNode = (ListSchemaNode) container - .getDataChildByName(deviceType); - - final DataContainerNodeAttrBuilder devTypeContainerBldr = Builders - .containerBuilder(container); - - final MapNode devTypeMap = createDevTypeList(devTypeListSchemaNode); - devTypeContainerBldr.addChild(devTypeMap); - - return devTypeContainerBldr.build(); - } - - private static MapNode createDevTypeList( - final ListSchemaNode devTypeListSchemaNode) { - - final CollectionNodeBuilder devTypeMapBldr = Builders - .mapBuilder(devTypeListSchemaNode); - - devTypeMapBldr.addChild(createDevTypeListEntry("dev_type1_1", - "dev_type2_1", "dev_type3_1", "typedesc1", - devTypeListSchemaNode)); - devTypeMapBldr.addChild(createDevTypeListEntry("dev_type1_2", - "dev_type2_2", "dev_type3_2", "typedesc2", - devTypeListSchemaNode)); - devTypeMapBldr.addChild(createDevTypeListEntry("dev_type1_3", - "dev_type2_3", "dev_type3_3", "typedesc3", - devTypeListSchemaNode)); - - return devTypeMapBldr.build(); - } - - private static MapEntryNode createDevTypeListEntry(final String type1Val, - final String type2Val, final String type3Val, final String descVal, - final ListSchemaNode devTypeListSchemaNode) { - - final LeafNode type1Leaf = ImmutableNodes.leafNode(type1, type1Val); - final LeafNode type2Leaf = ImmutableNodes.leafNode(type2, type2Val); - final LeafNode type3Leaf = ImmutableNodes.leafNode(type3, type3Val); - final LeafNode descLeaf = ImmutableNodes.leafNode(desc, descVal); - - final DataContainerNodeAttrBuilder devTypeMapEntryBldr = Builders - .mapEntryBuilder(devTypeListSchemaNode); - - devTypeMapEntryBldr.addChild(type1Leaf); - devTypeMapEntryBldr.addChild(type2Leaf); - devTypeMapEntryBldr.addChild(type3Leaf); - devTypeMapEntryBldr.addChild(descLeaf); - - return devTypeMapEntryBldr.build(); - } - - private static ContainerNode createChipsContainer( - final ContainerSchemaNode container) { - - final ListSchemaNode chipsListSchemaNode = (ListSchemaNode) container - .getDataChildByName(chip); - - final DataContainerNodeAttrBuilder chipsContainerBldr = Builders - .containerBuilder(container); - - final MapNode chipsMap = createChipsList(chipsListSchemaNode); - chipsContainerBldr.addChild(chipsMap); - - return chipsContainerBldr.build(); - } - - private static MapNode createChipsList(final ListSchemaNode chipsListSchemaNode) { - - final CollectionNodeBuilder chipsMapBldr = Builders - .mapBuilder(chipsListSchemaNode); - - chipsMapBldr.addChild(createChipsListEntry("dev_type_1", "desc1", - chipsListSchemaNode)); - chipsMapBldr.addChild(createChipsListEntry("dev_type_2", "desc2", - chipsListSchemaNode)); - - return chipsMapBldr.build(); - } - - private static MapEntryNode createChipsListEntry(final String devTypeVal, - final String chipDescVal, final ListSchemaNode chipsListSchemaNode) { - - final LeafNode devTypeLeaf = ImmutableNodes.leafNode(devType, - devTypeVal); - final LeafNode chipDescLeaf = ImmutableNodes.leafNode(chipDesc, - chipDescVal); - - final DataContainerNodeAttrBuilder chipsMapEntryBldr = Builders - .mapEntryBuilder(chipsListSchemaNode); - - chipsMapEntryBldr.addChild(devTypeLeaf); - chipsMapEntryBldr.addChild(chipDescLeaf); - - return chipsMapEntryBldr.build(); - } - - private static ContainerNode createDevicesContainer( - final ContainerSchemaNode container) { - - final ListSchemaNode devicesListSchemaNode = (ListSchemaNode) container - .getDataChildByName(device); - - final DataContainerNodeAttrBuilder devicesContainerBldr = Builders - .containerBuilder(container); - - final MapNode devicesMap = createDeviceList(devicesListSchemaNode); - devicesContainerBldr.addChild(devicesMap); - - return devicesContainerBldr.build(); - } - - private static MapNode createDeviceList(final ListSchemaNode deviceListSchemaNode) { - - final CollectionNodeBuilder devicesMapBldr = Builders - .mapBuilder(deviceListSchemaNode); - - devicesMapBldr.addChild(createDeviceListEntry("dev_type1_1", - "dev_type2_1", "dev_type3_1", "typedesc1", 123456, - "192.168.0.1", deviceListSchemaNode)); - devicesMapBldr.addChild(createDeviceListEntry("dev_type1_2", - "dev_type2_2", "dev_type3_2", "typedesc1", 123457, - "192.168.0.1", deviceListSchemaNode)); - devicesMapBldr.addChild(createDeviceListEntry("dev_type1_1", - "dev_type2_2", "dev_type3_3", "typedesc2", 123458, - "192.168.0.1", deviceListSchemaNode)); - devicesMapBldr.addChild(createDeviceListEntry("unk11", "unk22", - "unk33", "unk_desc2", 123457, "192.168.0.1", - deviceListSchemaNode)); - - return devicesMapBldr.build(); - } - - private static ContainerNode createDevices2Container( - final ContainerSchemaNode container) { - - final ListSchemaNode devicesListSchemaNode = (ListSchemaNode) container - .getDataChildByName(device); - - final DataContainerNodeAttrBuilder devicesContainerBldr = Builders - .containerBuilder(container); - - final MapNode devicesMap = createDevice2List(devicesListSchemaNode); - devicesContainerBldr.addChild(devicesMap); - - return devicesContainerBldr.build(); - } - - private static MapNode createDevice2List(final ListSchemaNode deviceListSchemaNode) { - - final CollectionNodeBuilder devicesMapBldr = Builders - .mapBuilder(deviceListSchemaNode); - - devicesMapBldr.addChild(createDeviceListEntry("dev_type1_3", - "dev_type2_3", "dev_type3_3", "typedesc3", 123459, - "192.168.0.1", deviceListSchemaNode)); - devicesMapBldr.addChild(createDeviceListEntry("dev_type1_3", - "dev_type2_3", "dev_type3_3", "typedesc2", 123460, - "192.168.0.1", deviceListSchemaNode)); - devicesMapBldr.addChild(createDeviceListEntry("dev_type1_3", - "dev_type2_2", "dev_type3_1", "typedesc1", 123461, - "192.168.0.1", deviceListSchemaNode)); - devicesMapBldr.addChild(createDeviceListEntry("unk1", "unk2", "unk3", - "unk_desc", 123462, "192.168.0.1", deviceListSchemaNode)); - - return devicesMapBldr.build(); - } - - private static MapEntryNode createDeviceListEntry(final String type1TextVal, - final String type2TextVal, final String type3TextVal, final String descVal, - final int snVal, final String defaultIpVal, final ListSchemaNode devicesListSchemaNode) { - - final LeafNode typeText1Leaf = ImmutableNodes.leafNode(typeText1, - type1TextVal); - final LeafNode typeText2Leaf = ImmutableNodes.leafNode(typeText2, - type2TextVal); - final LeafNode typeText3Leaf = ImmutableNodes.leafNode(typeText3, - type3TextVal); - final LeafNode descLeaf = ImmutableNodes.leafNode(devDesc, descVal); - final LeafNode snValLeaf = ImmutableNodes.leafNode(sn, snVal); - final LeafNode defaultIpLeaf = ImmutableNodes.leafNode(defaultIp, - defaultIpVal); - - final DataContainerNodeAttrBuilder devicesMapEntryBldr = Builders - .mapEntryBuilder(devicesListSchemaNode); - - devicesMapEntryBldr.addChild(typeText1Leaf); - devicesMapEntryBldr.addChild(typeText2Leaf); - devicesMapEntryBldr.addChild(typeText3Leaf); - devicesMapEntryBldr.addChild(descLeaf); - devicesMapEntryBldr.addChild(snValLeaf); - devicesMapEntryBldr.addChild(defaultIpLeaf); - - return devicesMapEntryBldr.build(); - } -} \ No newline at end of file diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/test/LeafRefContextTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/test/LeafRefContextTest.java deleted file mode 100644 index eb3143dd71..0000000000 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/test/LeafRefContextTest.java +++ /dev/null @@ -1,112 +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.data.impl.leafref.context.test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import java.io.File; -import java.io.IOException; -import java.net.URISyntaxException; -import java.util.Map; -import java.util.Set; -import org.junit.BeforeClass; -import org.junit.Test; -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.common.QNameModule; -import org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefContext; -import org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefContextUtils; -import org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefYangSyntaxErrorException; -import org.opendaylight.yangtools.yang.model.api.DataNodeContainer; -import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; -import org.opendaylight.yangtools.yang.model.api.Module; -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; - -public class LeafRefContextTest { - - private static SchemaContext context; - private static Module rootMod; - private static QNameModule root; - private static LeafRefContext rootLeafRefContext; - - @BeforeClass - public static void init() throws URISyntaxException, IOException, - YangSyntaxErrorException, LeafRefYangSyntaxErrorException { - - final File resourceFile = new File( - LeafRefContextTreeBuilderTest.class - .getResource( - "/leafref-context-test/correct-modules/leafref-test2.yang") - .toURI()); - - final File resourceDir = resourceFile.getParentFile(); - - final YangParserImpl parser = YangParserImpl.getInstance(); - context = parser.parseFile(resourceFile, resourceDir); - - final Set modules = context.getModules(); - for (final Module module : modules) { - if (module.getName().equals("leafref-test2")) { - rootMod = module; - } - } - - root = rootMod.getQNameModule(); - rootLeafRefContext = LeafRefContext.create(context); - } - - @Test - public void test() { - - final QName q1 = QName.create(root, "ref1"); - final QName q2 = QName.create(root, "leaf1"); - final QName q3 = QName.create(root, "cont1"); - final QName q4 = QName.create(root, "cont2"); - final QName q5 = QName.create(root, "list1"); - final QName q6 = QName.create(root, "name"); - - final DataSchemaNode leafRefNode = rootMod.getDataChildByName(q1); - final DataSchemaNode targetNode = rootMod.getDataChildByName(q2); - final DataSchemaNode cont1Node = rootMod.getDataChildByName(q3); - final DataSchemaNode cont2Node = rootMod.getDataChildByName(q4); - final DataSchemaNode name1Node = ((DataNodeContainer) ((DataNodeContainer) rootMod - .getDataChildByName(q3)).getDataChildByName(q5)) - .getDataChildByName(q6); - - assertTrue(LeafRefContextUtils.isLeafRef(leafRefNode, - rootLeafRefContext)); - assertFalse(LeafRefContextUtils.isLeafRef(targetNode, - rootLeafRefContext)); - - assertTrue(LeafRefContextUtils.hasLeafRefChild(cont1Node, - rootLeafRefContext)); - assertFalse(LeafRefContextUtils.hasLeafRefChild(leafRefNode, - rootLeafRefContext)); - - assertTrue(LeafRefContextUtils.isReferencedByLeafRef(targetNode, - rootLeafRefContext)); - assertFalse(LeafRefContextUtils.isReferencedByLeafRef(leafRefNode, - rootLeafRefContext)); - - assertTrue(LeafRefContextUtils.hasChildReferencedByLeafRef(cont2Node, - rootLeafRefContext)); - assertFalse(LeafRefContextUtils.hasChildReferencedByLeafRef( - leafRefNode, rootLeafRefContext)); - - Map leafRefs = LeafRefContextUtils - .getAllLeafRefsReferencingThisNode(name1Node, - rootLeafRefContext); - assertEquals(4, leafRefs.size()); - leafRefs = LeafRefContextUtils.getAllLeafRefsReferencingThisNode( - leafRefNode, rootLeafRefContext); - assertTrue(leafRefs.isEmpty()); - } -} diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/test/LeafRefContextTreeBuilderTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/test/LeafRefContextTreeBuilderTest.java deleted file mode 100644 index 110f246d70..0000000000 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/test/LeafRefContextTreeBuilderTest.java +++ /dev/null @@ -1,281 +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.data.impl.leafref.context.test; - -import static org.junit.Assert.assertEquals; -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 java.io.File; -import java.io.IOException; -import java.net.URISyntaxException; -import java.util.List; -import java.util.Set; -import org.junit.BeforeClass; -import org.junit.Test; -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.common.QNameModule; -import org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefContext; -import org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefContextUtils; -import org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefYangSyntaxErrorException; -import org.opendaylight.yangtools.yang.model.api.DataNodeContainer; -import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; -import org.opendaylight.yangtools.yang.model.api.Module; -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; - -public class LeafRefContextTreeBuilderTest { - - private static SchemaContext context; - private static Module impMod; - private static Module tstMod; - private static QNameModule imp; - private static QNameModule tst; - private static LeafRefContext rootLeafRefContext; - - @BeforeClass - public static void init() throws URISyntaxException, IOException, - YangSyntaxErrorException, LeafRefYangSyntaxErrorException { - final File resourceFile = new File( - LeafRefContextTreeBuilderTest.class - .getResource( - "/leafref-context-test/correct-modules/leafref-test.yang") - .toURI()); - final File resourceDir = resourceFile.getParentFile(); - - final YangParserImpl parser = YangParserImpl.getInstance(); - context = parser.parseFile(resourceFile, resourceDir); - - final Set modules = context.getModules(); - for (final Module module : modules) { - if (module.getName().equals("import-mod")) { - impMod = module; - } - if (module.getName().equals("leafref-test")) { - tstMod = module; - } - } - - imp = impMod.getQNameModule(); - tst = tstMod.getQNameModule(); - - rootLeafRefContext = LeafRefContext.create(context); - } - - @Test - public void buildLeafRefContextTreeTest1() { - - final QName q1 = QName.create(tst, "odl-project"); - final QName q2 = QName.create(tst, "project"); - final QName q3 = QName.create(tst, "project-lead"); - - final LeafRefContext leafRefCtx = rootLeafRefContext - .getReferencingChildByName(q1).getReferencingChildByName(q2) - .getReferencingChildByName(q3); - - assertTrue(leafRefCtx.isReferencing()); - assertNotNull(leafRefCtx.getLeafRefTargetPath()); - assertFalse(leafRefCtx.getLeafRefTargetPath().isAbsolute()); - assertNotNull(leafRefCtx.getAbsoluteLeafRefTargetPath()); - assertTrue(leafRefCtx.getAbsoluteLeafRefTargetPath().isAbsolute()); - - System.out.println(); - System.out.println("******* Test 1 ************"); - System.out.println("Original definition string:"); - System.out.println(leafRefCtx.getLeafRefTargetPathString()); - System.out.println("Parsed leafref path:"); - System.out.println(leafRefCtx.getLeafRefTargetPath().toString()); - System.out.println("Absolute leafref path:"); - System.out - .println(leafRefCtx.getAbsoluteLeafRefTargetPath().toString()); - } - - @Test - public void buildLeafRefContextTreeTest2() { - - final QName q1 = QName.create(tst, "odl-project"); - final QName q2 = QName.create(tst, "project"); - final QName q4 = QName.create(tst, "project-lead2"); - - final LeafRefContext leafRefCtx2 = rootLeafRefContext - .getReferencingChildByName(q1).getReferencingChildByName(q2) - .getReferencingChildByName(q4); - - assertTrue(leafRefCtx2.isReferencing()); - assertNotNull(leafRefCtx2.getLeafRefTargetPath()); - assertTrue(leafRefCtx2.getLeafRefTargetPath().isAbsolute()); - assertNotNull(leafRefCtx2.getAbsoluteLeafRefTargetPath()); - assertTrue(leafRefCtx2.getAbsoluteLeafRefTargetPath().isAbsolute()); - - System.out.println(); - System.out.println("******* Test 2 ************"); - System.out.println("Original definition string2:"); - System.out.println(leafRefCtx2.getLeafRefTargetPathString()); - System.out.println("Parsed leafref path2:"); - System.out.println(leafRefCtx2.getLeafRefTargetPath().toString()); - System.out.println("Absolute leafref path2:"); - System.out.println(leafRefCtx2.getAbsoluteLeafRefTargetPath() - .toString()); - System.out.println(); - - } - - @Test - public void buildLeafRefContextTreeXPathTest() { - final QName q1 = QName.create(tst, "odl-project"); - final QName q2 = QName.create(tst, "project"); - final QName q5 = QName.create(tst, "ch1"); - final QName q6 = QName.create(tst, "c1"); - final QName q7 = QName.create(tst, "ch2"); - final QName q8 = QName.create(tst, "l1"); - final LeafRefContext leafRefCtx3 = rootLeafRefContext - .getReferencingChildByName(q1).getReferencingChildByName(q2) - .getReferencingChildByName(q5).getReferencingChildByName(q6) - .getReferencingChildByName(q7).getReferencingChildByName(q6) - .getReferencingChildByName(q8); - - assertTrue(leafRefCtx3.isReferencing()); - assertNotNull(leafRefCtx3.getLeafRefTargetPath()); - assertFalse(leafRefCtx3.getLeafRefTargetPath().isAbsolute()); - assertNotNull(leafRefCtx3.getAbsoluteLeafRefTargetPath()); - assertTrue(leafRefCtx3.getAbsoluteLeafRefTargetPath().isAbsolute()); - - System.out.println(); - System.out.println("******* Test 3 ************"); - System.out.println("Original definition string2:"); - System.out.println(leafRefCtx3.getLeafRefTargetPathString()); - System.out.println("Parsed leafref path2:"); - System.out.println(leafRefCtx3.getLeafRefTargetPath().toString()); - System.out.println("Absolute leafref path2:"); - System.out.println(leafRefCtx3.getAbsoluteLeafRefTargetPath() - .toString()); - System.out.println(); - } - - @Test - public void buildLeafRefContextTreeTest4() { - final QName q9 = QName.create(tst, "odl-project"); - final QName q10 = QName.create(tst, "project"); - final QName q11 = QName.create(tst, "name"); - - final LeafRefContext leafRefCtx4 = rootLeafRefContext - .getReferencedChildByName(q9).getReferencedChildByName(q10) - .getReferencedChildByName(q11); - - assertNotNull(leafRefCtx4); - assertTrue(leafRefCtx4.isReferenced()); - assertEquals(6, leafRefCtx4.getAllReferencedByLeafRefCtxs().size()); - - } - - @Test - public void leafRefContextUtilsTest() { - final QName q1 = QName.create(tst, "odl-contributor"); - final QName q2 = QName.create(tst, "contributor"); - final QName q3 = QName.create(tst, "odl-project-name"); - - final LeafRefContext odlContrProjNameCtx = rootLeafRefContext - .getReferencingChildByName(q1).getReferencingChildByName(q2) - .getReferencingChildByName(q3); - - final DataSchemaNode odlContrProjNameNode = ((DataNodeContainer) ((DataNodeContainer) tstMod - .getDataChildByName(q1)).getDataChildByName(q2)) - .getDataChildByName(q3); - - final LeafRefContext foundOdlContrProjNameCtx = LeafRefContextUtils - .getLeafRefReferencingContext(odlContrProjNameNode, - rootLeafRefContext); - - assertNotNull(foundOdlContrProjNameCtx); - assertTrue(foundOdlContrProjNameCtx.isReferencing()); - assertNotNull(foundOdlContrProjNameCtx.getLeafRefTargetPath()); - assertEquals(odlContrProjNameCtx, foundOdlContrProjNameCtx); - } - - @Test - public void leafRefContextUtilsTest2() { - final QName q1 = QName.create(tst, "odl-project"); - final QName q2 = QName.create(tst, "project"); - final QName q3 = QName.create(tst, "name"); - - final LeafRefContext leafRefCtx = rootLeafRefContext - .getReferencedChildByName(q1).getReferencedChildByName(q2) - .getReferencedChildByName(q3); - - final DataSchemaNode odlProjNameNode = ((DataNodeContainer) ((DataNodeContainer) tstMod - .getDataChildByName(q1)).getDataChildByName(q2)) - .getDataChildByName(q3); - - LeafRefContext foundOdlProjNameCtx = LeafRefContextUtils - .getLeafRefReferencingContext(odlProjNameNode, - rootLeafRefContext); - - assertNull(foundOdlProjNameCtx); - - foundOdlProjNameCtx = LeafRefContextUtils - .getLeafRefReferencedByContext(odlProjNameNode, - rootLeafRefContext); - - assertNotNull(foundOdlProjNameCtx); - assertTrue(foundOdlProjNameCtx.isReferenced()); - assertFalse(foundOdlProjNameCtx.getAllReferencedByLeafRefCtxs() - .isEmpty()); - assertEquals(6, foundOdlProjNameCtx.getAllReferencedByLeafRefCtxs() - .size()); - assertEquals(leafRefCtx, foundOdlProjNameCtx); - } - - @Test - public void leafRefContextUtilsTest3() { - final QName q16 = QName.create(tst, "con1"); - final DataSchemaNode con1 = tstMod.getDataChildByName(q16); - final List allLeafRefChilds = LeafRefContextUtils - .findAllLeafRefChilds(con1, rootLeafRefContext); - - assertNotNull(allLeafRefChilds); - assertFalse(allLeafRefChilds.isEmpty()); - assertEquals(4, allLeafRefChilds.size()); - - final QName q17 = QName.create(tst, "odl-contributor"); - final DataSchemaNode odlContributorNode = tstMod.getDataChildByName(q17); - List allChildsReferencedByLeafRef = LeafRefContextUtils - .findAllChildsReferencedByLeafRef(odlContributorNode, - rootLeafRefContext); - - assertNotNull(allChildsReferencedByLeafRef); - assertFalse(allChildsReferencedByLeafRef.isEmpty()); - assertEquals(1, allChildsReferencedByLeafRef.size()); - - allChildsReferencedByLeafRef = LeafRefContextUtils - .findAllChildsReferencedByLeafRef(con1, rootLeafRefContext); - - assertNotNull(allChildsReferencedByLeafRef); - assertTrue(allChildsReferencedByLeafRef.isEmpty()); - - } - - @Test(expected = RuntimeException.class) - public void incorrectLeafRefPathTest() throws URISyntaxException, - IOException, YangSyntaxErrorException, - LeafRefYangSyntaxErrorException { - final File resourceFile = new File(getClass().getResource( - "/leafref-context-test/incorrect-modules/leafref-test.yang") - .toURI()); - final File resourceDir = resourceFile.getParentFile(); - - final YangParserImpl parser = YangParserImpl.getInstance(); - final SchemaContext context = parser.parseFile(resourceFile, resourceDir); - - LeafRefContext.create(context); - - } - -} diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/test/BuilderTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/BuilderTest.java similarity index 98% rename from yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/test/BuilderTest.java rename to yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/BuilderTest.java index 76e7189d05..10bf9a2380 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/test/BuilderTest.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/BuilderTest.java @@ -6,7 +6,7 @@ * and is available at http://www.eclipse.org/legal/epl-v10.html */ -package org.opendaylight.yangtools.yang.data.impl.schema.test; +package org.opendaylight.yangtools.yang.data.impl.schema; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -34,9 +34,7 @@ import org.opendaylight.yangtools.yang.data.api.schema.OrderedLeafSetNode; import org.opendaylight.yangtools.yang.data.api.schema.OrderedMapNode; import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode; import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode; -import org.opendaylight.yangtools.yang.data.impl.RetestUtils; -import org.opendaylight.yangtools.yang.data.impl.schema.Builders; -import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes; +import org.opendaylight.yangtools.yang.data.impl.TestUtils; import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.CollectionNodeBuilder; import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.ListNodeBuilder; import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableAugmentationNodeBuilder; @@ -95,7 +93,7 @@ public class BuilderTest { public void setup() throws FileNotFoundException, ReactorException, URISyntaxException { final File leafRefTestYang = new File(getClass().getResource("/builder-test/immutable-ordered-map-node.yang") .toURI()); - final SchemaContext schema = RetestUtils.parseYangSources(leafRefTestYang); + final SchemaContext schema = TestUtils.parseYangSources(leafRefTestYang); final Module module = schema.getModules().iterator().next(); final DataSchemaNode root = module.getDataChildByName(ROOT_CONTAINER); list = (ListSchemaNode)((ContainerEffectiveStatementImpl) root).getDataChildByName(LIST_MAIN); diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/InstanceIdToNodesTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/InstanceIdToNodesTest.java index 5b1fdf3cd7..d25c7d0f1d 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/InstanceIdToNodesTest.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/InstanceIdToNodesTest.java @@ -1,20 +1,18 @@ /* - * 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. + * and is available at http://www.eclipse.org/legal/epl-v10.html */ package org.opendaylight.yangtools.yang.data.impl.schema; import static org.junit.Assert.assertEquals; -import com.google.common.base.Function; -import com.google.common.collect.Collections2; -import com.google.common.io.ByteSource; -import java.io.IOException; -import java.io.InputStream; +import java.io.File; +import java.io.FileNotFoundException; +import java.net.URISyntaxException; import java.util.Collections; -import org.junit.Before; +import org.junit.BeforeClass; import org.junit.Test; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; @@ -27,144 +25,180 @@ import org.opendaylight.yangtools.yang.data.api.schema.LeafNode; import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode; import org.opendaylight.yangtools.yang.data.api.schema.MapNode; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; +import org.opendaylight.yangtools.yang.data.impl.TestUtils; 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; public class InstanceIdToNodesTest { private static final String NS = "urn:opendaylight:params:xml:ns:yang:controller:md:sal:normalization:test"; private static final String REVISION = "2014-03-13"; private static final QName ID = QName.create(NS, REVISION, "id"); - private SchemaContext ctx; + private static SchemaContext ctx; private final NodeIdentifier rootContainer = new NodeIdentifier(QName.create(NS, REVISION, "test")); private final NodeIdentifier outerContainer = new NodeIdentifier(QName.create(NS, REVISION, "outer-container")); private final NodeIdentifier augmentedLeaf = new NodeIdentifier(QName.create(NS, REVISION, "augmented-leaf")); - private final AugmentationIdentifier augmentation = new AugmentationIdentifier(Collections.singleton(augmentedLeaf.getNodeType())); + private final AugmentationIdentifier augmentation = new AugmentationIdentifier( + Collections.singleton(augmentedLeaf.getNodeType())); - private final NodeIdentifier outerList = new NodeIdentifier(QName.create(NS, REVISION, "outer-list")); - private final NodeIdentifierWithPredicates outerListWithKey = new NodeIdentifierWithPredicates(QName.create(NS, REVISION, "outer-list"), ID, 1); + private final NodeIdentifier outerList = new NodeIdentifier( + QName.create(NS, REVISION, "outer-list")); + private final NodeIdentifierWithPredicates outerListWithKey = new NodeIdentifierWithPredicates( + QName.create(NS, REVISION, "outer-list"), ID, 1); private final NodeIdentifier choice = new NodeIdentifier(QName.create(NS, REVISION, "outer-choice")); private final NodeIdentifier leafFromCase = new NodeIdentifier(QName.create(NS, REVISION, "one")); private final NodeIdentifier leafList = new NodeIdentifier(QName.create(NS, REVISION, "ordered-leaf-list")); - private final NodeWithValue leafListWithValue = new NodeWithValue<>(leafList.getNodeType(), "abcd"); - - static SchemaContext createTestContext() throws IOException, YangSyntaxErrorException { - final YangParserImpl parser = new YangParserImpl(); - return parser.parseSources(Collections2.transform(Collections.singletonList("/filter-test.yang"), new Function() { - @Override - public ByteSource apply(final String input) { - return new ByteSource() { - @Override - public InputStream openStream() throws IOException { - return InstanceIdToNodesTest.class.getResourceAsStream(input); - } - }; - } - })); + private final NodeWithValue leafListWithValue = new NodeWithValue<>( + leafList.getNodeType(), "abcd"); + + static SchemaContext createTestContext() throws URISyntaxException, FileNotFoundException, ReactorException { + final File resourceFile = new File(InstanceIdToNodesTest.class.getResource("/filter-test.yang").toURI()); + return TestUtils.parseYangSources(resourceFile); } - @Before - public void setUp() throws Exception { + @BeforeClass + public static void setUp() throws Exception { ctx = createTestContext(); } @Test public void testInAugment() throws Exception { - final ContainerNode expectedFilter = Builders.containerBuilder().withNodeIdentifier(rootContainer).withChild( - Builders.containerBuilder().withNodeIdentifier(outerContainer).withChild( - Builders.augmentationBuilder().withNodeIdentifier(augmentation).withChild( - Builders.leafBuilder().withNodeIdentifier(augmentedLeaf).build() - ).build() - ).build() - ).build(); - - final NormalizedNode filter = ImmutableNodes.fromInstanceId(ctx, YangInstanceIdentifier.create(rootContainer, outerContainer, augmentation, augmentedLeaf)); + final ContainerNode expectedFilter = Builders + .containerBuilder() + .withNodeIdentifier(rootContainer) + .withChild( + Builders.containerBuilder() + .withNodeIdentifier(outerContainer) + .withChild( + Builders.augmentationBuilder() + .withNodeIdentifier(augmentation) + .withChild( + Builders.leafBuilder().withNodeIdentifier(augmentedLeaf) + .build()).build()).build()).build(); + + final NormalizedNode filter = ImmutableNodes.fromInstanceId(ctx, + YangInstanceIdentifier.create(rootContainer, outerContainer, augmentation, augmentedLeaf)); assertEquals(expectedFilter, filter); } @Test public void testInAugmentLeafOverride() throws Exception { - final LeafNode lastLeaf = Builders.leafBuilder().withNodeIdentifier(augmentedLeaf).withValue("randomValue").build(); - - final ContainerNode expectedFilter = Builders.containerBuilder().withNodeIdentifier(rootContainer).withChild( - Builders.containerBuilder().withNodeIdentifier(outerContainer).withChild( - Builders.augmentationBuilder().withNodeIdentifier(augmentation).withChild( - lastLeaf - ).build() - ).build() - ).build(); - - final NormalizedNode filter = ImmutableNodes.fromInstanceId(ctx, YangInstanceIdentifier.create(rootContainer, outerContainer, augmentation, augmentedLeaf), lastLeaf); + final LeafNode lastLeaf = Builders.leafBuilder().withNodeIdentifier(augmentedLeaf) + .withValue("randomValue").build(); + + final ContainerNode expectedFilter = Builders + .containerBuilder() + .withNodeIdentifier(rootContainer) + .withChild( + Builders.containerBuilder() + .withNodeIdentifier(outerContainer) + .withChild( + Builders.augmentationBuilder().withNodeIdentifier(augmentation) + .withChild(lastLeaf).build()).build()).build(); + + final NormalizedNode filter = ImmutableNodes.fromInstanceId(ctx, + YangInstanceIdentifier.create(rootContainer, outerContainer, augmentation, augmentedLeaf), lastLeaf); assertEquals(expectedFilter, filter); } @Test public void testListChoice() throws Exception { - final ContainerNode expectedFilter = Builders.containerBuilder().withNodeIdentifier(rootContainer).withChild( - Builders.mapBuilder().withNodeIdentifier(outerList).withChild( - Builders.mapEntryBuilder().withNodeIdentifier(outerListWithKey).withChild( - Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(ID)).withValue(1).build() - ).withChild( - Builders.choiceBuilder().withNodeIdentifier(choice).withChild( - Builders.leafBuilder().withNodeIdentifier(leafFromCase).build() - ).build() - ).build() - ).build() - ).build(); - - final NormalizedNode filter = ImmutableNodes.fromInstanceId(ctx, YangInstanceIdentifier.create(rootContainer, outerList, outerListWithKey, choice, leafFromCase)); + final ContainerNode expectedFilter = Builders + .containerBuilder() + .withNodeIdentifier(rootContainer) + .withChild( + Builders.mapBuilder() + .withNodeIdentifier(outerList) + .withChild( + Builders.mapEntryBuilder() + .withNodeIdentifier(outerListWithKey) + .withChild( + Builders.leafBuilder() + .withNodeIdentifier( + new NodeIdentifier(ID)) + .withValue(1).build()) + .withChild( + Builders.choiceBuilder() + .withNodeIdentifier(choice) + .withChild( + Builders.leafBuilder() + .withNodeIdentifier(leafFromCase) + .build()).build()).build()).build()) + .build(); + + final NormalizedNode filter = ImmutableNodes.fromInstanceId(ctx, + YangInstanceIdentifier.create(rootContainer, outerList, outerListWithKey, choice, leafFromCase)); assertEquals(expectedFilter, filter); } @Test public void testTopContainerLastChildOverride() throws Exception { - final ContainerNode expectedStructure = Builders.containerBuilder().withNodeIdentifier(rootContainer).withChild( - Builders.mapBuilder().withNodeIdentifier(outerList).withChild( - Builders.mapEntryBuilder().withNodeIdentifier(outerListWithKey).withChild( - Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(ID)).withValue(1).build() - ).withChild( - Builders.choiceBuilder().withNodeIdentifier(choice).withChild( - Builders.leafBuilder().withNodeIdentifier(leafFromCase).build() - ).build() - ).build() - ).build() - ).build(); - - final NormalizedNode filter = ImmutableNodes.fromInstanceId(ctx, YangInstanceIdentifier.create(rootContainer), expectedStructure); + final ContainerNode expectedStructure = Builders + .containerBuilder() + .withNodeIdentifier(rootContainer) + .withChild( + Builders.mapBuilder() + .withNodeIdentifier(outerList) + .withChild( + Builders.mapEntryBuilder() + .withNodeIdentifier(outerListWithKey) + .withChild( + Builders.leafBuilder() + .withNodeIdentifier( + new NodeIdentifier(ID)) + .withValue(1).build()) + .withChild( + Builders.choiceBuilder() + .withNodeIdentifier(choice) + .withChild( + Builders.leafBuilder() + .withNodeIdentifier(leafFromCase) + .build()).build()).build()).build()) + .build(); + + final NormalizedNode filter = ImmutableNodes.fromInstanceId(ctx, + YangInstanceIdentifier.create(rootContainer), expectedStructure); assertEquals(expectedStructure, filter); } @Test public void testListLastChildOverride() throws Exception { - final MapEntryNode outerListEntry = Builders.mapEntryBuilder().withNodeIdentifier(outerListWithKey).withChild( - Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(ID)).withValue(1).build() - ).build(); - final MapNode lastChild = Builders.mapBuilder().withNodeIdentifier(this.outerList).withChild( - outerListEntry - ).build(); - final ContainerNode expectedStructure = Builders.containerBuilder().withNodeIdentifier(rootContainer).withChild( - lastChild - ).build(); - - NormalizedNode filter = ImmutableNodes.fromInstanceId(ctx, YangInstanceIdentifier.create(rootContainer, outerList, outerListWithKey), outerListEntry); + final MapEntryNode outerListEntry = Builders + .mapEntryBuilder() + .withNodeIdentifier(outerListWithKey) + .withChild( + Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(ID)) + .withValue(1).build()).build(); + final MapNode lastChild = Builders.mapBuilder().withNodeIdentifier(this.outerList).withChild(outerListEntry) + .build(); + final ContainerNode expectedStructure = Builders.containerBuilder().withNodeIdentifier(rootContainer) + .withChild(lastChild).build(); + + NormalizedNode filter = ImmutableNodes.fromInstanceId(ctx, + YangInstanceIdentifier.create(rootContainer, outerList, outerListWithKey), outerListEntry); assertEquals(expectedStructure, filter); - filter = ImmutableNodes.fromInstanceId(ctx, YangInstanceIdentifier.create(rootContainer, outerList, outerListWithKey)); + filter = ImmutableNodes.fromInstanceId(ctx, + YangInstanceIdentifier.create(rootContainer, outerList, outerListWithKey)); assertEquals(expectedStructure, filter); } @Test public void testLeafList() throws Exception { - final ContainerNode expectedFilter = Builders.containerBuilder().withNodeIdentifier(rootContainer).withChild( - Builders.orderedLeafSetBuilder().withNodeIdentifier(leafList).withChild( - Builders.leafSetEntryBuilder().withNodeIdentifier(leafListWithValue).withValue(leafListWithValue.getValue()).build() - ).build() - ).build(); - - final NormalizedNode filter = ImmutableNodes.fromInstanceId(ctx, YangInstanceIdentifier.create(rootContainer, leafList, leafListWithValue)); + final ContainerNode expectedFilter = Builders + .containerBuilder() + .withNodeIdentifier(rootContainer) + .withChild( + Builders.orderedLeafSetBuilder() + .withNodeIdentifier(leafList) + .withChild( + Builders.leafSetEntryBuilder().withNodeIdentifier(leafListWithValue) + .withValue(leafListWithValue.getValue()).build()).build()).build(); + + final NormalizedNode filter = ImmutableNodes.fromInstanceId(ctx, + YangInstanceIdentifier.create(rootContainer, leafList, leafListWithValue)); assertEquals(expectedFilter, filter); } } \ No newline at end of file diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/NormalizedDataBuilderTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/NormalizedDataBuilderTest.java index 8fd5e28a85..c4ba341711 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/NormalizedDataBuilderTest.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/NormalizedDataBuilderTest.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, @@ -7,15 +7,13 @@ */ package org.opendaylight.yangtools.yang.data.impl.schema; -import com.google.common.base.Function; import com.google.common.base.Preconditions; -import com.google.common.collect.Collections2; import com.google.common.collect.Lists; import com.google.common.collect.Sets; -import com.google.common.io.ByteSource; -import com.google.common.io.Resources; -import java.io.IOException; +import java.io.File; +import java.io.FileNotFoundException; import java.net.URI; +import java.net.URISyntaxException; import java.util.Collections; import java.util.List; import org.junit.Before; @@ -32,6 +30,7 @@ import org.opendaylight.yangtools.yang.data.api.schema.LeafNode; import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode; import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode; import org.opendaylight.yangtools.yang.data.api.schema.MapNode; +import org.opendaylight.yangtools.yang.data.impl.TestUtils; import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder; import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableChoiceNodeSchemaAwareBuilder; import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableMapNodeSchemaAwareBuilder; @@ -45,40 +44,23 @@ 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.parser.api.YangSyntaxErrorException; -import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl; +import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; public class NormalizedDataBuilderTest { private ContainerSchemaNode containerNode; private SchemaContext schema; - SchemaContext parseTestSchema(final String... yangPath) throws IOException, YangSyntaxErrorException { - YangParserImpl yangParserImpl = new YangParserImpl(); - return yangParserImpl.parseSources(getTestYangs(yangPath)); - } - - List getTestYangs(final String... yangPaths) { - - return Lists.newArrayList(Collections2.transform(Lists.newArrayList(yangPaths), - new Function() { - @Override - public ByteSource apply(final String input) { - ByteSource resourceAsStream = Resources.asByteSource(getClass().getResource(input)); - Preconditions.checkNotNull(resourceAsStream, "File %s was null", resourceAsStream); - return resourceAsStream; - } - })); - } - @Before - public void setUp() throws Exception { - schema = parseTestSchema("test.yang"); + public void setUp() throws URISyntaxException, FileNotFoundException, ReactorException { + final File resourceFile = new File(getClass().getResource( + "test.yang").toURI()); + schema = TestUtils.parseYangSources(resourceFile); containerNode = (ContainerSchemaNode) getSchemaNode(schema, "test", "container"); } @Test - public void testSchemaUnaware() throws Exception { + public void testSchemaUnaware() { // Container DataContainerNodeBuilder builder = Builders .containerBuilder().withNodeIdentifier(getNodeIdentifier("container")); @@ -95,8 +77,8 @@ public class NormalizedDataBuilderTest { .withChildValue(1) .withChild( Builders. leafSetEntryBuilder() - .withNodeIdentifier(getNodeWithValueIdentifier("leaf", 3)).withValue(3).build()) - .build(); + .withNodeIdentifier(getNodeWithValueIdentifier("leaf", 3)).withValue(3).build()) + .build(); builder.withChild(leafList); // list @@ -104,12 +86,12 @@ public class NormalizedDataBuilderTest { .mapEntryBuilder() .withChild( Builders. leafBuilder().withNodeIdentifier(getNodeIdentifier("uint32InList")) - .withValue(1).build()) - .withChild(Builders.containerBuilder().withNodeIdentifier(getNodeIdentifier("containerInList")).build()) - .withNodeIdentifier( - new NodeIdentifierWithPredicates(getNodeIdentifier("list").getNodeType(), - Collections.singletonMap(getNodeIdentifier("uint32InList").getNodeType(), (Object) 1))) - .build(); + .withValue(1).build()) + .withChild(Builders.containerBuilder().withNodeIdentifier(getNodeIdentifier("containerInList")).build()) + .withNodeIdentifier( + new NodeIdentifierWithPredicates( + getNodeIdentifier("list").getNodeType(), Collections.singletonMap( + getNodeIdentifier("uint32InList").getNodeType(), (Object) 1))).build(); MapNode list = Builders.mapBuilder().withChild(listChild1).withNodeIdentifier(getNodeIdentifier("list")) .build(); @@ -119,8 +101,8 @@ public class NormalizedDataBuilderTest { .augmentationBuilder() .withNodeIdentifier( new AugmentationIdentifier(Sets.newHashSet(getQName("augmentUint32")))) - .withChild( - Builders. leafBuilder().withNodeIdentifier(getNodeIdentifier("augmentUint32")) + .withChild( + Builders.leafBuilder().withNodeIdentifier(getNodeIdentifier("augmentUint32")) .withValue(11).build()).build(); builder.withChild(augmentation); @@ -132,7 +114,7 @@ public class NormalizedDataBuilderTest { } @Test - public void testSchemaAware() throws Exception { + public void testSchemaAware() { DataContainerNodeBuilder builder = Builders .containerBuilder(containerNode); @@ -162,7 +144,7 @@ public class NormalizedDataBuilderTest { augmentUint32SchemaNode.getQName()); AugmentationNode augmentation = Builders.augmentationBuilder(augmentationSchema) - .withChild(Builders.leafBuilder(augmentUint32SchemaNode).withValue(11).build()).build(); + .withChild(Builders. leafBuilder(augmentUint32SchemaNode).withValue(11).build()).build(); builder.withChild(augmentation); @@ -173,8 +155,7 @@ public class NormalizedDataBuilderTest { LeafSchemaNode augumentString2SchemaNode = (LeafSchemaNode) getSchemaNode(schema, "test", "augmentString2"); ChoiceSchemaNode choice1SchemaNode = (ChoiceSchemaNode) getSchemaNode(schema, "test", "choice"); - ChoiceNode choice = ImmutableChoiceNodeSchemaAwareBuilder - .create(choice1SchemaNode) + ChoiceNode choice = ImmutableChoiceNodeSchemaAwareBuilder.create(choice1SchemaNode) .withChild(Builders. leafBuilder(augumentString1SchemaNode).withValue("case1").build()) // This should fail, since child node belongs to different case // .withChild(Builders.leafBuilder(augumentString2SchemaNode).withValue("case2") @@ -188,7 +169,8 @@ public class NormalizedDataBuilderTest { // .build()); } - private static AugmentationSchema getAugmentationSchemaForChild(final ContainerSchemaNode containerNode, final QName qName) { + private static AugmentationSchema getAugmentationSchemaForChild(final ContainerSchemaNode containerNode, + final QName qName) { for (AugmentationSchema augmentationSchema : containerNode.getAvailableAugmentations()) { if (augmentationSchema.getDataChildByName(qName) != null) { return augmentationSchema; @@ -210,7 +192,8 @@ public class NormalizedDataBuilderTest { return new NodeIdentifier(getQName(localName)); } - public static DataSchemaNode getSchemaNode(final SchemaContext context, final String moduleName, final String childNodeName) { + public static DataSchemaNode getSchemaNode(final SchemaContext context, final String moduleName, + final String childNodeName) { for (Module module : context.getModules()) { if (module.getName().equals(moduleName)) { DataSchemaNode found = findChildNode(module.getChildNodes(), childNodeName); diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/test/NormalizedNodeUtilsTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/NormalizedNodeUtilsTest.java similarity index 92% rename from yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/test/NormalizedNodeUtilsTest.java rename to yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/NormalizedNodeUtilsTest.java index 08044f9a84..7df8959ffd 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/test/NormalizedNodeUtilsTest.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/NormalizedNodeUtilsTest.java @@ -1,4 +1,12 @@ -package org.opendaylight.yangtools.yang.data.impl.schema.test; +/* + * 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.data.impl.schema; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/retest/InstanceIdToNodesTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/retest/InstanceIdToNodesTest.java deleted file mode 100644 index 5aabff3c33..0000000000 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/retest/InstanceIdToNodesTest.java +++ /dev/null @@ -1,206 +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.data.impl.schema.retest; - -import static org.junit.Assert.assertEquals; -import java.io.File; -import java.io.FileNotFoundException; -import java.net.URISyntaxException; -import java.util.Collections; -import org.junit.BeforeClass; -import org.junit.Test; -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; -import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier; -import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier; -import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates; -import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue; -import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode; -import org.opendaylight.yangtools.yang.data.api.schema.LeafNode; -import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode; -import org.opendaylight.yangtools.yang.data.api.schema.MapNode; -import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; -import org.opendaylight.yangtools.yang.data.impl.RetestUtils; -import org.opendaylight.yangtools.yang.data.impl.schema.Builders; -import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; - -public class InstanceIdToNodesTest { - - private static final String NS = "urn:opendaylight:params:xml:ns:yang:controller:md:sal:normalization:test"; - private static final String REVISION = "2014-03-13"; - private static final QName ID = QName.create(NS, REVISION, "id"); - private static SchemaContext ctx; - - private final NodeIdentifier rootContainer = new NodeIdentifier(QName.create(NS, REVISION, "test")); - private final NodeIdentifier outerContainer = new NodeIdentifier(QName.create(NS, REVISION, "outer-container")); - private final NodeIdentifier augmentedLeaf = new NodeIdentifier(QName.create(NS, REVISION, "augmented-leaf")); - private final AugmentationIdentifier augmentation = new AugmentationIdentifier( - Collections.singleton(augmentedLeaf.getNodeType())); - - private final NodeIdentifier outerList = new NodeIdentifier( - QName.create(NS, REVISION, "outer-list")); - private final NodeIdentifierWithPredicates outerListWithKey = new NodeIdentifierWithPredicates( - QName.create(NS, REVISION, "outer-list"), ID, 1); - private final NodeIdentifier choice = new NodeIdentifier(QName.create(NS, REVISION, "outer-choice")); - private final NodeIdentifier leafFromCase = new NodeIdentifier(QName.create(NS, REVISION, "one")); - - private final NodeIdentifier leafList = new NodeIdentifier(QName.create(NS, REVISION, "ordered-leaf-list")); - private final NodeWithValue leafListWithValue = new NodeWithValue<>( - leafList.getNodeType(), "abcd"); - - static SchemaContext createTestContext() throws URISyntaxException, FileNotFoundException, ReactorException { - final File resourceFile = new File(InstanceIdToNodesTest.class.getResource("/filter-test.yang").toURI()); - return RetestUtils.parseYangSources(resourceFile); - } - - @BeforeClass - public static void setUp() throws Exception { - ctx = createTestContext(); - - } - - @Test - public void testInAugment() throws Exception { - final ContainerNode expectedFilter = Builders - .containerBuilder() - .withNodeIdentifier(rootContainer) - .withChild( - Builders.containerBuilder() - .withNodeIdentifier(outerContainer) - .withChild( - Builders.augmentationBuilder() - .withNodeIdentifier(augmentation) - .withChild( - Builders.leafBuilder().withNodeIdentifier(augmentedLeaf) - .build()).build()).build()).build(); - - final NormalizedNode filter = ImmutableNodes.fromInstanceId(ctx, - YangInstanceIdentifier.create(rootContainer, outerContainer, augmentation, augmentedLeaf)); - assertEquals(expectedFilter, filter); - } - - @Test - public void testInAugmentLeafOverride() throws Exception { - final LeafNode lastLeaf = Builders.leafBuilder().withNodeIdentifier(augmentedLeaf) - .withValue("randomValue").build(); - - final ContainerNode expectedFilter = Builders - .containerBuilder() - .withNodeIdentifier(rootContainer) - .withChild( - Builders.containerBuilder() - .withNodeIdentifier(outerContainer) - .withChild( - Builders.augmentationBuilder().withNodeIdentifier(augmentation) - .withChild(lastLeaf).build()).build()).build(); - - final NormalizedNode filter = ImmutableNodes.fromInstanceId(ctx, - YangInstanceIdentifier.create(rootContainer, outerContainer, augmentation, augmentedLeaf), lastLeaf); - assertEquals(expectedFilter, filter); - } - - @Test - public void testListChoice() throws Exception { - final ContainerNode expectedFilter = Builders - .containerBuilder() - .withNodeIdentifier(rootContainer) - .withChild( - Builders.mapBuilder() - .withNodeIdentifier(outerList) - .withChild( - Builders.mapEntryBuilder() - .withNodeIdentifier(outerListWithKey) - .withChild( - Builders.leafBuilder() - .withNodeIdentifier( - new NodeIdentifier(ID)) - .withValue(1).build()) - .withChild( - Builders.choiceBuilder() - .withNodeIdentifier(choice) - .withChild( - Builders.leafBuilder() - .withNodeIdentifier(leafFromCase) - .build()).build()).build()).build()) - .build(); - - final NormalizedNode filter = ImmutableNodes.fromInstanceId(ctx, - YangInstanceIdentifier.create(rootContainer, outerList, outerListWithKey, choice, leafFromCase)); - assertEquals(expectedFilter, filter); - } - - @Test - public void testTopContainerLastChildOverride() throws Exception { - final ContainerNode expectedStructure = Builders - .containerBuilder() - .withNodeIdentifier(rootContainer) - .withChild( - Builders.mapBuilder() - .withNodeIdentifier(outerList) - .withChild( - Builders.mapEntryBuilder() - .withNodeIdentifier(outerListWithKey) - .withChild( - Builders.leafBuilder() - .withNodeIdentifier( - new NodeIdentifier(ID)) - .withValue(1).build()) - .withChild( - Builders.choiceBuilder() - .withNodeIdentifier(choice) - .withChild( - Builders.leafBuilder() - .withNodeIdentifier(leafFromCase) - .build()).build()).build()).build()) - .build(); - - final NormalizedNode filter = ImmutableNodes.fromInstanceId(ctx, - YangInstanceIdentifier.create(rootContainer), expectedStructure); - assertEquals(expectedStructure, filter); - } - - @Test - public void testListLastChildOverride() throws Exception { - final MapEntryNode outerListEntry = Builders - .mapEntryBuilder() - .withNodeIdentifier(outerListWithKey) - .withChild( - Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(ID)) - .withValue(1).build()).build(); - final MapNode lastChild = Builders.mapBuilder().withNodeIdentifier(this.outerList).withChild(outerListEntry) - .build(); - final ContainerNode expectedStructure = Builders.containerBuilder().withNodeIdentifier(rootContainer) - .withChild(lastChild).build(); - - NormalizedNode filter = ImmutableNodes.fromInstanceId(ctx, - YangInstanceIdentifier.create(rootContainer, outerList, outerListWithKey), outerListEntry); - assertEquals(expectedStructure, filter); - filter = ImmutableNodes.fromInstanceId(ctx, - YangInstanceIdentifier.create(rootContainer, outerList, outerListWithKey)); - assertEquals(expectedStructure, filter); - } - - @Test - public void testLeafList() throws Exception { - final ContainerNode expectedFilter = Builders - .containerBuilder() - .withNodeIdentifier(rootContainer) - .withChild( - Builders.orderedLeafSetBuilder() - .withNodeIdentifier(leafList) - .withChild( - Builders.leafSetEntryBuilder().withNodeIdentifier(leafListWithValue) - .withValue(leafListWithValue.getValue()).build()).build()).build(); - - final NormalizedNode filter = ImmutableNodes.fromInstanceId(ctx, - YangInstanceIdentifier.create(rootContainer, leafList, leafListWithValue)); - assertEquals(expectedFilter, filter); - } -} \ No newline at end of file diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/retest/NormalizedDataBuilderTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/retest/NormalizedDataBuilderTest.java deleted file mode 100644 index 20c413d8af..0000000000 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/retest/NormalizedDataBuilderTest.java +++ /dev/null @@ -1,231 +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.data.impl.schema.retest; - -import com.google.common.base.Preconditions; -import com.google.common.collect.Lists; -import com.google.common.collect.Sets; -import java.io.File; -import java.io.FileNotFoundException; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.Collections; -import java.util.List; -import org.junit.Before; -import org.junit.Test; -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier; -import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier; -import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates; -import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue; -import org.opendaylight.yangtools.yang.data.api.schema.AugmentationNode; -import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode; -import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode; -import org.opendaylight.yangtools.yang.data.api.schema.LeafNode; -import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode; -import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode; -import org.opendaylight.yangtools.yang.data.api.schema.MapNode; -import org.opendaylight.yangtools.yang.data.impl.RetestUtils; -import org.opendaylight.yangtools.yang.data.impl.schema.Builders; -import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder; -import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableChoiceNodeSchemaAwareBuilder; -import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableMapNodeSchemaAwareBuilder; -import org.opendaylight.yangtools.yang.model.api.AugmentationSchema; -import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode; -import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode; -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.ListSchemaNode; -import org.opendaylight.yangtools.yang.model.api.Module; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; - -public class NormalizedDataBuilderTest { - - private ContainerSchemaNode containerNode; - private SchemaContext schema; - - @Before - public void setUp() throws URISyntaxException, FileNotFoundException, ReactorException { - final File resourceFile = new File(getClass().getResource( - "../test.yang").toURI()); - schema = RetestUtils.parseYangSources(resourceFile); - containerNode = (ContainerSchemaNode) getSchemaNode(schema, "test", "container"); - } - - @Test - public void testSchemaUnaware() { - // Container - DataContainerNodeBuilder builder = Builders - .containerBuilder().withNodeIdentifier(getNodeIdentifier("container")); - - // leaf - LeafNode leafChild = Builders. leafBuilder().withNodeIdentifier(getNodeIdentifier("leaf")) - .withValue("String").build(); - builder.withChild(leafChild); - - // leafList - LeafSetNode leafList = Builders - . leafSetBuilder() - .withNodeIdentifier(getNodeIdentifier("leaf")) - .withChildValue(1) - .withChild( - Builders. leafSetEntryBuilder() - .withNodeIdentifier(getNodeWithValueIdentifier("leaf", 3)).withValue(3).build()) - .build(); - builder.withChild(leafList); - - // list - MapEntryNode listChild1 = Builders - .mapEntryBuilder() - .withChild( - Builders. leafBuilder().withNodeIdentifier(getNodeIdentifier("uint32InList")) - .withValue(1).build()) - .withChild(Builders.containerBuilder().withNodeIdentifier(getNodeIdentifier("containerInList")).build()) - .withNodeIdentifier( - new NodeIdentifierWithPredicates( - getNodeIdentifier("list").getNodeType(), Collections.singletonMap( - getNodeIdentifier("uint32InList").getNodeType(), (Object) 1))).build(); - - MapNode list = Builders.mapBuilder().withChild(listChild1).withNodeIdentifier(getNodeIdentifier("list")) - .build(); - builder.withChild(list); - - AugmentationNode augmentation = Builders - .augmentationBuilder() - .withNodeIdentifier( - new AugmentationIdentifier(Sets.newHashSet(getQName("augmentUint32")))) - .withChild( - Builders.leafBuilder().withNodeIdentifier(getNodeIdentifier("augmentUint32")) - .withValue(11).build()).build(); - - builder.withChild(augmentation); - - // This works without schema (adding child from augment as a direct - // child) - builder.withChild(Builders. leafBuilder().withNodeIdentifier(getNodeIdentifier("augmentUint32")) - .withValue(11).build()); - } - - @Test - public void testSchemaAware() { - DataContainerNodeBuilder builder = Builders - .containerBuilder(containerNode); - - LeafSchemaNode schemaNode = (LeafSchemaNode) getSchemaNode(schema, "test", "uint32"); - LeafNode leafChild = Builders. leafBuilder(schemaNode).withValue("String").build(); - builder.withChild(leafChild); - - LeafListSchemaNode leafListSchemaNode = (LeafListSchemaNode) getSchemaNode(schema, "test", "leafList"); - LeafSetNode leafList = Builders. leafSetBuilder(leafListSchemaNode).withChildValue(1) - .withChild(Builders. leafSetEntryBuilder(leafListSchemaNode).withValue(3).build()).build(); - builder.withChild(leafList); - - ListSchemaNode listSchema = (ListSchemaNode) getSchemaNode(schema, "test", "list"); - LeafSchemaNode uint32InListSchemaNode = (LeafSchemaNode) getSchemaNode(schema, "test", "uint32InList"); - ContainerSchemaNode containerInListSchemaNode = (ContainerSchemaNode) getSchemaNode(schema, "test", - "containerInList"); - - MapEntryNode listChild1 = Builders.mapEntryBuilder(listSchema) - .withChild(Builders. leafBuilder(uint32InListSchemaNode).withValue(1).build()) - .withChild(Builders.containerBuilder(containerInListSchemaNode).build()).build(); - - MapNode list = ImmutableMapNodeSchemaAwareBuilder.create(listSchema).withChild(listChild1).build(); - builder.withChild(list); - - LeafSchemaNode augmentUint32SchemaNode = (LeafSchemaNode) getSchemaNode(schema, "test", "augmentUint32"); - AugmentationSchema augmentationSchema = getAugmentationSchemaForChild(containerNode, - augmentUint32SchemaNode.getQName()); - - AugmentationNode augmentation = Builders.augmentationBuilder(augmentationSchema) - .withChild(Builders. leafBuilder(augmentUint32SchemaNode).withValue(11).build()).build(); - - builder.withChild(augmentation); - - // This should fail with schema, since the leaf comes from augmentation - // builder.withChild(ImmutableLeafNodeSchemaAwareBuilder.get(augmentUint32SchemaNode).withValue(11).build()); - - LeafSchemaNode augumentString1SchemaNode = (LeafSchemaNode) getSchemaNode(schema, "test", "augmentString1"); - LeafSchemaNode augumentString2SchemaNode = (LeafSchemaNode) getSchemaNode(schema, "test", "augmentString2"); - - ChoiceSchemaNode choice1SchemaNode = (ChoiceSchemaNode) getSchemaNode(schema, "test", "choice"); - ChoiceNode choice = ImmutableChoiceNodeSchemaAwareBuilder.create(choice1SchemaNode) - .withChild(Builders. leafBuilder(augumentString1SchemaNode).withValue("case1").build()) - // This should fail, since child node belongs to different case - // .withChild(Builders.leafBuilder(augumentString2SchemaNode).withValue("case2") - // .build()) - .build(); - - builder.withChild(choice); - - // This should fail, child from case - // builder.withChild(Builders.leafBuilder(augumentString1SchemaNode).withValue("case1") - // .build()); - } - - private static AugmentationSchema getAugmentationSchemaForChild(final ContainerSchemaNode containerNode, - final QName qName) { - for (AugmentationSchema augmentationSchema : containerNode.getAvailableAugmentations()) { - if (augmentationSchema.getDataChildByName(qName) != null) { - return augmentationSchema; - } - } - throw new IllegalStateException("Unable to find child augmentation in " + containerNode); - } - - private static NodeWithValue getNodeWithValueIdentifier(final String localName, final T value) { - return new NodeWithValue<>(getQName(localName), value); - } - - private static QName getQName(final String localName) { - String namespace = "namespace"; - return new QName(URI.create(namespace), localName); - } - - private static NodeIdentifier getNodeIdentifier(final String localName) { - return new NodeIdentifier(getQName(localName)); - } - - public static DataSchemaNode getSchemaNode(final SchemaContext context, final String moduleName, - final String childNodeName) { - for (Module module : context.getModules()) { - if (module.getName().equals(moduleName)) { - DataSchemaNode found = findChildNode(module.getChildNodes(), childNodeName); - Preconditions.checkState(found != null, "Unable to find %s", childNodeName); - return found; - } - } - throw new IllegalStateException("Unable to find child node " + childNodeName); - } - - private static DataSchemaNode findChildNode(final Iterable children, final String name) { - List containers = Lists.newArrayList(); - - for (DataSchemaNode dataSchemaNode : children) { - if (dataSchemaNode.getQName().getLocalName().equals(name)) { - return dataSchemaNode; - } - if (dataSchemaNode instanceof DataNodeContainer) { - containers.add((DataNodeContainer) dataSchemaNode); - } else if (dataSchemaNode instanceof ChoiceSchemaNode) { - containers.addAll(((ChoiceSchemaNode) dataSchemaNode).getCases()); - } - } - - for (DataNodeContainer container : containers) { - DataSchemaNode retVal = findChildNode(container.getChildNodes(), name); - if (retVal != null) { - return retVal; - } - } - - return null; - } -} diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/transform/dom/parser/DomToNormalizedNodeParserFactoryTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/transform/dom/parser/DomToNormalizedNodeParserFactoryTest.java index fac21edc0d..ef63edcc85 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/transform/dom/parser/DomToNormalizedNodeParserFactoryTest.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/transform/dom/parser/DomToNormalizedNodeParserFactoryTest.java @@ -15,7 +15,7 @@ import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode; import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode; import org.opendaylight.yangtools.yang.data.api.schema.OrderedMapNode; import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode; -import org.opendaylight.yangtools.yang.data.impl.RetestUtils; +import org.opendaylight.yangtools.yang.data.impl.TestUtils; import org.opendaylight.yangtools.yang.data.impl.schema.transform.ToNormalizedNodeParser; import org.opendaylight.yangtools.yang.data.impl.schema.transform.dom.DomUtils; import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode; @@ -31,7 +31,7 @@ public class DomToNormalizedNodeParserFactoryTest { public void testFactoryInstantiation() throws ReactorException { YangStatementSourceImpl foo = new YangStatementSourceImpl("/foo.yang", false); - SchemaContext schemaContext = RetestUtils.parseYangSources(foo); + SchemaContext schemaContext = TestUtils.parseYangSources(foo); DomToNormalizedNodeParserFactory factory = DomToNormalizedNodeParserFactory.getInstance( DomUtils.defaultValueCodecProvider(), schemaContext, diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/transform/dom/serializer/Bug5396.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/transform/dom/serializer/Bug5396.java index b7ba1f3b75..103adb2aa5 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/transform/dom/serializer/Bug5396.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/transform/dom/serializer/Bug5396.java @@ -33,7 +33,7 @@ import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgum import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode; import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild; import org.opendaylight.yangtools.yang.data.api.schema.LeafNode; -import org.opendaylight.yangtools.yang.data.impl.RetestUtils; +import org.opendaylight.yangtools.yang.data.impl.TestUtils; import org.opendaylight.yangtools.yang.data.impl.schema.transform.dom.DomUtils; import org.opendaylight.yangtools.yang.data.impl.schema.transform.dom.parser.DomToNormalizedNodeParserFactory; import org.opendaylight.yangtools.yang.model.api.SchemaContext; @@ -64,7 +64,7 @@ public class Bug5396 { fooModuleQName = QNameModule.create(new URI("foo"), SimpleDateFormatUtil.getRevisionFormat() .parse("2016-03-22")); root = QName.create(fooModuleQName, "root"); - schemaContext = RetestUtils + schemaContext = TestUtils .parseYangSources(new File(getClass().getResource("/bug5396/yang/foo.yang").toURI())); } diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/transform/dom/serializer/DomSerializerTestUtils.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/transform/dom/serializer/DomSerializerTestUtils.java index 1b16fcaaa8..6ef48d97f4 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/transform/dom/serializer/DomSerializerTestUtils.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/transform/dom/serializer/DomSerializerTestUtils.java @@ -24,7 +24,7 @@ import javax.xml.transform.stream.StreamResult; import org.mockito.Mockito; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; -import org.opendaylight.yangtools.yang.data.impl.RetestUtils; +import org.opendaylight.yangtools.yang.data.impl.TestUtils; import org.opendaylight.yangtools.yang.data.impl.codec.TypeDefinitionAwareCodec; import org.opendaylight.yangtools.yang.data.impl.codec.xml.XmlCodecProvider; import org.opendaylight.yangtools.yang.data.impl.codec.xml.XmlDocumentUtils; @@ -56,7 +56,7 @@ public class DomSerializerTestUtils { public static SchemaContext getSchemaContext() throws ReactorException, IOException, YangSyntaxErrorException { final StatementStreamSource source = new YangStatementSourceImpl("/dom-serializer-test/serializer-test.yang", false); - final SchemaContext schemaContext = RetestUtils.parseYangSources(source); + final SchemaContext schemaContext = TestUtils.parseYangSources(source); assertNotNull("Schema context must not be null.", schemaContext); return schemaContext; diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/transform/dom/serializer/NormalizedNodeXmlTranslationTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/transform/dom/serializer/NormalizedNodeXmlTranslationTest.java index fa953eff4b..e1f02a76a9 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/transform/dom/serializer/NormalizedNodeXmlTranslationTest.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/transform/dom/serializer/NormalizedNodeXmlTranslationTest.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, @@ -17,8 +17,6 @@ import com.google.common.collect.Collections2; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.common.collect.Sets; -import com.google.common.io.ByteSource; -import com.google.common.io.Resources; import java.io.IOException; import java.io.InputStream; import java.io.StringWriter; @@ -52,10 +50,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier; -import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier; -import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates; -import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode; import org.opendaylight.yangtools.yang.data.api.schema.LeafNode; import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode; @@ -64,6 +59,7 @@ import org.opendaylight.yangtools.yang.data.api.schema.MapNode; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter; import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeWriter; +import org.opendaylight.yangtools.yang.data.impl.TestUtils; import org.opendaylight.yangtools.yang.data.impl.codec.xml.XMLStreamNormalizedNodeStreamWriter; import org.opendaylight.yangtools.yang.data.impl.codec.xml.XmlDocumentUtils; import org.opendaylight.yangtools.yang.data.impl.schema.Builders; @@ -77,8 +73,7 @@ import org.opendaylight.yangtools.yang.data.impl.schema.transform.dom.parser.Dom import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode; import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.opendaylight.yangtools.yang.model.api.SchemaPath; -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.slf4j.Logger; import org.slf4j.LoggerFactory; import org.w3c.dom.Document; @@ -92,14 +87,13 @@ public class NormalizedNodeXmlTranslationTest { @Parameterized.Parameters() public static Collection data() { - return Arrays.asList(new Object[][]{ - {"augment_choice_hell.yang", "augment_choice_hell_ok.xml", augmentChoiceHell()}, - {"augment_choice_hell.yang", "augment_choice_hell_ok2.xml", null}, - {"augment_choice_hell.yang", "augment_choice_hell_ok3.xml", augmentChoiceHell2()}, - {"test.yang", "simple.xml", null}, - {"test.yang", "simple2.xml", null}, + return Arrays.asList(new Object[][] { + { "augment_choice_hell.yang", "augment_choice_hell_ok.xml", augmentChoiceHell() }, + { "augment_choice_hell.yang", "augment_choice_hell_ok2.xml", null }, + { "augment_choice_hell.yang", "augment_choice_hell_ok3.xml", augmentChoiceHell2() }, + { "test.yang", "simple.xml", null }, { "test.yang", "simple2.xml", null }, // TODO check attributes - {"test.yang", "simple_xml_with_attributes.xml", withAttributes()} + { "test.yang", "simple_xml_with_attributes.xml", withAttributes() } }); } @@ -114,18 +108,22 @@ public class NormalizedNodeXmlTranslationTest { } private static ContainerNode augmentChoiceHell2() { - final NodeIdentifier container = getNodeIdentifier("container"); + final YangInstanceIdentifier.NodeIdentifier container = getNodeIdentifier("container"); QName augmentChoice1QName = QName.create(container.getNodeType(), "augment-choice1"); QName augmentChoice2QName = QName.create(augmentChoice1QName, "augment-choice2"); final QName containerQName = QName.create(augmentChoice1QName, "case11-choice-case-container"); final QName leafQName = QName.create(augmentChoice1QName, "case11-choice-case-leaf"); - final AugmentationIdentifier aug1Id = new AugmentationIdentifier(Sets.newHashSet(augmentChoice1QName)); - final AugmentationIdentifier aug2Id = new AugmentationIdentifier(Sets.newHashSet(augmentChoice2QName)); - final NodeIdentifier augmentChoice1Id = new NodeIdentifier(augmentChoice1QName); - final NodeIdentifier augmentChoice2Id = new NodeIdentifier(augmentChoice2QName); - final NodeIdentifier containerId = new NodeIdentifier(containerQName); - + final YangInstanceIdentifier.AugmentationIdentifier aug1Id = new YangInstanceIdentifier.AugmentationIdentifier( + Sets.newHashSet(augmentChoice1QName)); + final YangInstanceIdentifier.AugmentationIdentifier aug2Id = new YangInstanceIdentifier.AugmentationIdentifier( + Sets.newHashSet(augmentChoice2QName)); + final YangInstanceIdentifier.NodeIdentifier augmentChoice1Id = new YangInstanceIdentifier.NodeIdentifier( + augmentChoice1QName); + final YangInstanceIdentifier.NodeIdentifier augmentChoice2Id = new YangInstanceIdentifier.NodeIdentifier( + augmentChoice2QName); + final YangInstanceIdentifier.NodeIdentifier containerId = new YangInstanceIdentifier.NodeIdentifier( + containerQName); return containerBuilder().withNodeIdentifier(container) .withChild(augmentationBuilder().withNodeIdentifier(aug1Id) @@ -142,7 +140,7 @@ public class NormalizedNodeXmlTranslationTest { } private static ContainerNode withAttributes() { - final DataContainerNodeBuilder b = containerBuilder(); + final DataContainerNodeBuilder b = containerBuilder(); b.withNodeIdentifier(getNodeIdentifier("container")); final CollectionNodeBuilder listBuilder = Builders.mapBuilder().withNodeIdentifier( @@ -151,28 +149,29 @@ public class NormalizedNodeXmlTranslationTest { final Map predicates = Maps.newHashMap(); predicates.put(getNodeIdentifier("uint32InList").getNodeType(), 3L); - final DataContainerNodeBuilder list1Builder = Builders + final DataContainerNodeBuilder list1Builder = Builders .mapEntryBuilder().withNodeIdentifier( - new NodeIdentifierWithPredicates(getNodeIdentifier("list").getNodeType(), - predicates)); - final NormalizedNodeBuilder> uint32InListBuilder - = Builders.leafBuilder().withNodeIdentifier(getNodeIdentifier("uint32InList")); + new YangInstanceIdentifier.NodeIdentifierWithPredicates( + getNodeIdentifier("list").getNodeType(), predicates)); + final NormalizedNodeBuilder> uint32InListBuilder = Builders + .leafBuilder().withNodeIdentifier(getNodeIdentifier("uint32InList")); list1Builder.withChild(uint32InListBuilder.withValue(3L).build()); listBuilder.withChild(list1Builder.build()); b.withChild(listBuilder.build()); - final NormalizedNodeBuilder> booleanBuilder - = Builders.leafBuilder().withNodeIdentifier(getNodeIdentifier("boolean")); + final NormalizedNodeBuilder> booleanBuilder = Builders + .leafBuilder().withNodeIdentifier(getNodeIdentifier("boolean")); booleanBuilder.withValue(false); b.withChild(booleanBuilder.build()); - final ListNodeBuilder> leafListBuilder - = Builders.leafSetBuilder().withNodeIdentifier(getNodeIdentifier("leafList")); + final ListNodeBuilder> leafListBuilder = Builders.leafSetBuilder() + .withNodeIdentifier(getNodeIdentifier("leafList")); - final NormalizedNodeBuilder> leafList1Builder - = Builders.leafSetEntryBuilder().withNodeIdentifier(new NodeWithValue<>(getNodeIdentifier("leafList").getNodeType(), "a")); + final NormalizedNodeBuilder> leafList1Builder = Builders + .leafSetEntryBuilder().withNodeIdentifier( + new YangInstanceIdentifier.NodeWithValue(getNodeIdentifier("leafList").getNodeType(), "a")); leafList1Builder.withValue("a"); @@ -184,66 +183,79 @@ public class NormalizedNodeXmlTranslationTest { private static ContainerNode augmentChoiceHell() { - final DataContainerNodeBuilder b = containerBuilder(); + final DataContainerNodeBuilder b = containerBuilder(); b.withNodeIdentifier(getNodeIdentifier("container")); - b.withChild( - choiceBuilder().withNodeIdentifier(getNodeIdentifier("ch2")) - .withChild(Builders.leafBuilder().withNodeIdentifier(getNodeIdentifier("c2Leaf")).withValue("2").build()) + b.withChild(choiceBuilder() + .withNodeIdentifier(getNodeIdentifier("ch2")) + .withChild( + Builders.leafBuilder().withNodeIdentifier(getNodeIdentifier("c2Leaf")).withValue("2").build()) + .withChild( + choiceBuilder() + .withNodeIdentifier(getNodeIdentifier("c2DeepChoice")) + .withChild( + Builders.leafBuilder() + .withNodeIdentifier(getNodeIdentifier("c2DeepChoiceCase1Leaf2")) + .withValue("2").build()).build()).build()); + + b.withChild(choiceBuilder() + .withNodeIdentifier(getNodeIdentifier("ch3")) .withChild( - choiceBuilder().withNodeIdentifier(getNodeIdentifier("c2DeepChoice")) - .withChild(Builders.leafBuilder().withNodeIdentifier(getNodeIdentifier("c2DeepChoiceCase1Leaf2")).withValue("2").build()) - .build() - ) - .build() - ); - - b.withChild( - choiceBuilder().withNodeIdentifier(getNodeIdentifier("ch3")).withChild( Builders.leafBuilder().withNodeIdentifier(getNodeIdentifier("c3Leaf")).withValue("3").build()) - .build()); - - b.withChild( - augmentationBuilder().withNodeIdentifier(getAugmentIdentifier("augLeaf")).withChild( - Builders.leafBuilder().withNodeIdentifier(getNodeIdentifier("augLeaf")).withValue("augment").build()) - .build()); - - b.withChild( - augmentationBuilder().withNodeIdentifier(getAugmentIdentifier("ch")).withChild( - choiceBuilder().withNodeIdentifier(getNodeIdentifier("ch")) - .withChild( - Builders.leafBuilder().withNodeIdentifier(getNodeIdentifier("c1Leaf")).withValue("1").build()) + .build()); + + b.withChild(augmentationBuilder() + .withNodeIdentifier(getAugmentIdentifier("augLeaf")) + .withChild( + Builders.leafBuilder().withNodeIdentifier(getNodeIdentifier("augLeaf")).withValue("augment") + .build()).build()); + + b.withChild(augmentationBuilder() + .withNodeIdentifier(getAugmentIdentifier("ch")) + .withChild( + choiceBuilder() + .withNodeIdentifier(getNodeIdentifier("ch")) + .withChild( + Builders.leafBuilder().withNodeIdentifier(getNodeIdentifier("c1Leaf")) + .withValue("1").build()) .withChild( - augmentationBuilder().withNodeIdentifier(getAugmentIdentifier("c1Leaf_AnotherAugment", "deepChoice")) - .withChild( - Builders.leafBuilder().withNodeIdentifier(getNodeIdentifier("c1Leaf_AnotherAugment")).withValue("1").build()) + augmentationBuilder() + .withNodeIdentifier( + getAugmentIdentifier("c1Leaf_AnotherAugment", "deepChoice")) .withChild( - choiceBuilder().withNodeIdentifier(getNodeIdentifier("deepChoice")) - .withChild( - Builders.leafBuilder().withNodeIdentifier(getNodeIdentifier("deepLeafc1")).withValue("1").build() - ).build() - ).build() - ).build() - ).build()); + Builders.leafBuilder() + .withNodeIdentifier( + getNodeIdentifier("c1Leaf_AnotherAugment")) + .withValue("1").build()) + .withChild( + choiceBuilder() + .withNodeIdentifier(getNodeIdentifier("deepChoice")) + .withChild( + Builders.leafBuilder() + .withNodeIdentifier( + getNodeIdentifier("deepLeafc1")) + .withValue("1").build()).build()) + .build()).build()).build()); return b.build(); } - private static NodeIdentifier getNodeIdentifier(final String localName) { - return new NodeIdentifier(QName.create(URI.create(NAMESPACE), revision, localName)); + private static YangInstanceIdentifier.NodeIdentifier getNodeIdentifier(final String localName) { + return new YangInstanceIdentifier.NodeIdentifier(QName.create(URI.create(NAMESPACE), revision, localName)); } - public static AugmentationIdentifier getAugmentIdentifier(final String... childNames) { + public static YangInstanceIdentifier.AugmentationIdentifier getAugmentIdentifier(final String... childNames) { final Set qn = Sets.newHashSet(); for (final String childName : childNames) { qn.add(getNodeIdentifier(childName).getNodeType()); } - return new AugmentationIdentifier(qn); + return new YangInstanceIdentifier.AugmentationIdentifier(qn); } - public NormalizedNodeXmlTranslationTest(final String yangPath, final String xmlPath, final ContainerNode expectedNode) throws IOException, YangSyntaxErrorException { + public NormalizedNodeXmlTranslationTest(final String yangPath, final String xmlPath, + final ContainerNode expectedNode) throws ReactorException { schema = parseTestSchema(yangPath); this.xmlPath = xmlPath; this.containerNode = (ContainerSchemaNode) NormalizedDataBuilderTest.getSchemaNode(schema, "test", "container"); @@ -254,33 +266,30 @@ public class NormalizedNodeXmlTranslationTest { private final ContainerSchemaNode containerNode; private final String xmlPath; - - SchemaContext parseTestSchema(final String... yangPath) throws IOException, YangSyntaxErrorException { - final YangParserImpl yangParserImpl = new YangParserImpl(); - return yangParserImpl.parseSources(getTestYangs(yangPath)); + SchemaContext parseTestSchema(final String... yangPath) throws ReactorException { + return TestUtils.parseYangStreams(getTestYangs(yangPath)); } - List getTestYangs(final String... yangPaths) { + List getTestYangs(final String... yangPaths) { return Lists.newArrayList(Collections2.transform(Lists.newArrayList(yangPaths), - new Function() { - @Override - public ByteSource apply(final String input) { - final ByteSource source = Resources.asByteSource( - NormalizedDataBuilderTest.class.getResource(input)); - Preconditions.checkNotNull(source, "File %s was null", source); - return source; - } - })); + new Function() { + @Override + public InputStream apply(final String input) { + final InputStream resourceAsStream = NormalizedDataBuilderTest.class.getResourceAsStream(input); + Preconditions.checkNotNull(resourceAsStream, "File %s was null", resourceAsStream); + return resourceAsStream; + } + })); } @Test public void testTranslation() throws Exception { final Document doc = loadDocument(xmlPath); - final ContainerNode built = - DomToNormalizedNodeParserFactory.getInstance(DomUtils.defaultValueCodecProvider(), schema).getContainerNodeParser().parse( - Collections.singletonList(doc.getDocumentElement()), containerNode); + final ContainerNode built = DomToNormalizedNodeParserFactory + .getInstance(DomUtils.defaultValueCodecProvider(), schema).getContainerNodeParser() + .parse(Collections.singletonList(doc.getDocumentElement()), containerNode); if (expectedNode != null) { org.junit.Assert.assertEquals(expectedNode, built); @@ -289,7 +298,8 @@ public class NormalizedNodeXmlTranslationTest { System.err.println(built); logger.info("{}", built); - final Element elementNS = XmlDocumentUtils.getDocument().createElementNS(containerNode.getQName().getNamespace().toString(), containerNode.getQName().getLocalName()); + final Element elementNS = XmlDocumentUtils.getDocument().createElementNS( + containerNode.getQName().getNamespace().toString(), containerNode.getQName().getLocalName()); writeNormalizedNode(built, new DOMResult(elementNS), SchemaPath.create(true), schema); XMLUnit.setIgnoreWhitespace(true); @@ -297,27 +307,27 @@ public class NormalizedNodeXmlTranslationTest { XMLUnit.setIgnoreAttributeOrder(true); XMLUnit.setNormalize(true); - System.err.println(toString(doc.getDocumentElement())); System.err.println(toString(elementNS)); - final Diff diff = new Diff(XMLUnit.buildControlDocument(toString(doc.getDocumentElement())), XMLUnit.buildTestDocument(toString(elementNS))); + final Diff diff = new Diff(XMLUnit.buildControlDocument(toString(doc.getDocumentElement())), + XMLUnit.buildTestDocument(toString(elementNS))); - // FIXME the comparison cannot be performed, since the qualifiers supplied by XMlUnit do not work correctly in this case + // FIXME the comparison cannot be performed, since the qualifiers supplied by XMlUnit do not work correctly in + // this case // We need to implement custom qualifier so that the element ordering does not mess the DIFF -// dd.overrideElementQualifier(new MultiLevelElementNameAndTextQualifier(100, true)); -// assertTrue(dd.toString(), dd.similar()); + // dd.overrideElementQualifier(new MultiLevelElementNameAndTextQualifier(100, true)); + // assertTrue(dd.toString(), dd.similar()); } - static final XMLOutputFactory XML_FACTORY; static { XML_FACTORY = XMLOutputFactory.newFactory(); XML_FACTORY.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, false); } - private static void writeNormalizedNode(final NormalizedNode normalized, final DOMResult result, final SchemaPath schemaPath, final SchemaContext context) - throws IOException, XMLStreamException { + private static void writeNormalizedNode(final NormalizedNode normalized, final DOMResult result, + final SchemaPath schemaPath, final SchemaContext context) throws IOException, XMLStreamException { NormalizedNodeWriter normalizedNodeWriter = null; NormalizedNodeStreamWriter normalizedNodeStreamWriter = null; XMLStreamWriter writer = null; @@ -330,13 +340,13 @@ public class NormalizedNodeXmlTranslationTest { normalizedNodeWriter.flush(); } finally { - if(normalizedNodeWriter != null) { + if (normalizedNodeWriter != null) { normalizedNodeWriter.close(); } - if(normalizedNodeStreamWriter != null) { + if (normalizedNodeStreamWriter != null) { normalizedNodeStreamWriter.close(); } - if(writer != null) { + if (writer != null) { writer.close(); } } diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/transform/dom/serializer/retest/YangModeledAnyXMLDeserializationTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/transform/dom/serializer/YangModeledAnyXMLDeserializationTest.java similarity index 97% rename from yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/transform/dom/serializer/retest/YangModeledAnyXMLDeserializationTest.java rename to yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/transform/dom/serializer/YangModeledAnyXMLDeserializationTest.java index c41e74fe12..36e6b08486 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/transform/dom/serializer/retest/YangModeledAnyXMLDeserializationTest.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/transform/dom/serializer/YangModeledAnyXMLDeserializationTest.java @@ -1,11 +1,11 @@ /* - * 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.data.impl.schema.transform.dom.serializer.retest; +package org.opendaylight.yangtools.yang.data.impl.schema.transform.dom.serializer; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -35,7 +35,7 @@ import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode; import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild; import org.opendaylight.yangtools.yang.data.api.schema.LeafNode; import org.opendaylight.yangtools.yang.data.api.schema.YangModeledAnyXmlNode; -import org.opendaylight.yangtools.yang.data.impl.RetestUtils; +import org.opendaylight.yangtools.yang.data.impl.TestUtils; import org.opendaylight.yangtools.yang.data.impl.schema.transform.dom.DomUtils; import org.opendaylight.yangtools.yang.data.impl.schema.transform.dom.parser.DomToNormalizedNodeParserFactory; import org.opendaylight.yangtools.yang.model.api.ConstraintDefinition; @@ -91,7 +91,7 @@ public class YangModeledAnyXMLDeserializationTest { myLeaf3 = QName.create(fooModuleQName, "my-leaf-3"); myLeaf2 = QName.create(fooModuleQName, "my-leaf-2"); myAnyXMLDataFoo = QName.create(fooModuleQName, "my-anyxml-data"); - schemaContext = RetestUtils.parseYangSources(new File(getClass().getResource("/anyxml-support/yang/foo.yang") + schemaContext = TestUtils.parseYangSources(new File(getClass().getResource("/anyxml-support/yang/foo.yang") .toURI()), new File(getClass().getResource("/anyxml-support/yang/bar.yang").toURI()), new File(getClass().getResource("/anyxml-support/yang/yang-ext.yang").toURI())); } diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/transform/dom/serializer/retest/YangModeledAnyXMLSerializationTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/transform/dom/serializer/YangModeledAnyXMLSerializationTest.java similarity index 97% rename from yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/transform/dom/serializer/retest/YangModeledAnyXMLSerializationTest.java rename to yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/transform/dom/serializer/YangModeledAnyXMLSerializationTest.java index a69e45df2f..c51c845de9 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/transform/dom/serializer/retest/YangModeledAnyXMLSerializationTest.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/transform/dom/serializer/YangModeledAnyXMLSerializationTest.java @@ -1,11 +1,11 @@ /* - * 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.data.impl.schema.transform.dom.serializer.retest; +package org.opendaylight.yangtools.yang.data.impl.schema.transform.dom.serializer; import com.google.common.base.Optional; import com.google.common.base.Preconditions; @@ -43,7 +43,7 @@ import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; import org.opendaylight.yangtools.yang.data.api.schema.YangModeledAnyXmlNode; import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter; import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeWriter; -import org.opendaylight.yangtools.yang.data.impl.RetestUtils; +import org.opendaylight.yangtools.yang.data.impl.TestUtils; import org.opendaylight.yangtools.yang.data.impl.codec.xml.XMLStreamNormalizedNodeStreamWriter; import org.opendaylight.yangtools.yang.data.impl.codec.xml.XmlDocumentUtils; import org.opendaylight.yangtools.yang.data.impl.schema.transform.dom.DomUtils; @@ -86,7 +86,7 @@ public class YangModeledAnyXMLSerializationTest extends XMLTestCase { myContainer2QName = QName.create(bazModuleQName, "my-container-2"); myAnyXMLDataBaz = QName.create(bazModuleQName, "my-anyxml-data"); - schemaContext = RetestUtils.parseYangSources( + schemaContext = TestUtils.parseYangSources( new File(getClass().getResource("/anyxml-support/serialization/baz.yang").toURI()), new File(getClass() .getResource("/anyxml-support/serialization/yang-ext.yang").toURI())); } diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/transform/dom/serializer/retest/NormalizedNodeXmlTranslationTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/transform/dom/serializer/retest/NormalizedNodeXmlTranslationTest.java deleted file mode 100644 index 8674f920a7..0000000000 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/transform/dom/serializer/retest/NormalizedNodeXmlTranslationTest.java +++ /dev/null @@ -1,401 +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.data.impl.schema.transform.dom.serializer.retest; - -import static org.opendaylight.yangtools.yang.data.impl.schema.Builders.augmentationBuilder; -import static org.opendaylight.yangtools.yang.data.impl.schema.Builders.choiceBuilder; -import static org.opendaylight.yangtools.yang.data.impl.schema.Builders.containerBuilder; -import static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.leafNode; -import com.google.common.base.Function; -import com.google.common.base.Preconditions; -import com.google.common.collect.Collections2; -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; -import com.google.common.collect.Sets; -import java.io.IOException; -import java.io.InputStream; -import java.io.StringWriter; -import java.net.URI; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Date; -import java.util.List; -import java.util.Map; -import java.util.Set; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.stream.XMLOutputFactory; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamWriter; -import javax.xml.transform.OutputKeys; -import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerException; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.TransformerFactoryConfigurationError; -import javax.xml.transform.dom.DOMResult; -import javax.xml.transform.dom.DOMSource; -import javax.xml.transform.stream.StreamResult; -import org.custommonkey.xmlunit.Diff; -import org.custommonkey.xmlunit.XMLUnit; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; -import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode; -import org.opendaylight.yangtools.yang.data.api.schema.LeafNode; -import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode; -import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode; -import org.opendaylight.yangtools.yang.data.api.schema.MapNode; -import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; -import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter; -import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeWriter; -import org.opendaylight.yangtools.yang.data.impl.RetestUtils; -import org.opendaylight.yangtools.yang.data.impl.codec.xml.XMLStreamNormalizedNodeStreamWriter; -import org.opendaylight.yangtools.yang.data.impl.codec.xml.XmlDocumentUtils; -import org.opendaylight.yangtools.yang.data.impl.schema.Builders; -import org.opendaylight.yangtools.yang.data.impl.schema.NormalizedDataBuilderTest; -import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.CollectionNodeBuilder; -import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder; -import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.ListNodeBuilder; -import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeBuilder; -import org.opendaylight.yangtools.yang.data.impl.schema.transform.dom.DomUtils; -import org.opendaylight.yangtools.yang.data.impl.schema.transform.dom.parser.DomToNormalizedNodeParserFactory; -import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.model.api.SchemaPath; -import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.xml.sax.SAXException; - -@RunWith(Parameterized.class) -public class NormalizedNodeXmlTranslationTest { - private static final Logger logger = LoggerFactory.getLogger(NormalizedNodeXmlTranslationTest.class); - private final SchemaContext schema; - - @Parameterized.Parameters() - public static Collection data() { - return Arrays.asList(new Object[][] { - { "augment_choice_hell.yang", "augment_choice_hell_ok.xml", augmentChoiceHell() }, - { "augment_choice_hell.yang", "augment_choice_hell_ok2.xml", null }, - { "augment_choice_hell.yang", "augment_choice_hell_ok3.xml", augmentChoiceHell2() }, - { "test.yang", "simple.xml", null }, { "test.yang", "simple2.xml", null }, - // TODO check attributes - { "test.yang", "simple_xml_with_attributes.xml", withAttributes() } - }); - } - - public static final String NAMESPACE = "urn:opendaylight:params:xml:ns:yang:controller:test"; - private static Date revision; - static { - try { - revision = new SimpleDateFormat("yyyy-MM-dd").parse("2014-03-13"); - } catch (final ParseException e) { - throw new RuntimeException(e); - } - } - - private static ContainerNode augmentChoiceHell2() { - final YangInstanceIdentifier.NodeIdentifier container = getNodeIdentifier("container"); - QName augmentChoice1QName = QName.create(container.getNodeType(), "augment-choice1"); - QName augmentChoice2QName = QName.create(augmentChoice1QName, "augment-choice2"); - final QName containerQName = QName.create(augmentChoice1QName, "case11-choice-case-container"); - final QName leafQName = QName.create(augmentChoice1QName, "case11-choice-case-leaf"); - - final YangInstanceIdentifier.AugmentationIdentifier aug1Id = new YangInstanceIdentifier.AugmentationIdentifier( - Sets.newHashSet(augmentChoice1QName)); - final YangInstanceIdentifier.AugmentationIdentifier aug2Id = new YangInstanceIdentifier.AugmentationIdentifier( - Sets.newHashSet(augmentChoice2QName)); - final YangInstanceIdentifier.NodeIdentifier augmentChoice1Id = new YangInstanceIdentifier.NodeIdentifier( - augmentChoice1QName); - final YangInstanceIdentifier.NodeIdentifier augmentChoice2Id = new YangInstanceIdentifier.NodeIdentifier( - augmentChoice2QName); - final YangInstanceIdentifier.NodeIdentifier containerId = new YangInstanceIdentifier.NodeIdentifier( - containerQName); - - return containerBuilder().withNodeIdentifier(container) - .withChild(augmentationBuilder().withNodeIdentifier(aug1Id) - .withChild(choiceBuilder().withNodeIdentifier(augmentChoice1Id) - .withChild(augmentationBuilder().withNodeIdentifier(aug2Id) - .withChild(choiceBuilder().withNodeIdentifier(augmentChoice2Id) - .withChild(containerBuilder().withNodeIdentifier(containerId) - .withChild(leafNode(leafQName, "leaf-value")) - .build()) - .build()) - .build()) - .build()) - .build()).build(); - } - - private static ContainerNode withAttributes() { - final DataContainerNodeBuilder b = containerBuilder(); - b.withNodeIdentifier(getNodeIdentifier("container")); - - final CollectionNodeBuilder listBuilder = Builders.mapBuilder().withNodeIdentifier( - getNodeIdentifier("list")); - - final Map predicates = Maps.newHashMap(); - predicates.put(getNodeIdentifier("uint32InList").getNodeType(), 3L); - - final DataContainerNodeBuilder list1Builder = Builders - .mapEntryBuilder().withNodeIdentifier( - new YangInstanceIdentifier.NodeIdentifierWithPredicates( - getNodeIdentifier("list").getNodeType(), predicates)); - final NormalizedNodeBuilder> uint32InListBuilder = Builders - .leafBuilder().withNodeIdentifier(getNodeIdentifier("uint32InList")); - - list1Builder.withChild(uint32InListBuilder.withValue(3L).build()); - - listBuilder.withChild(list1Builder.build()); - b.withChild(listBuilder.build()); - - final NormalizedNodeBuilder> booleanBuilder = Builders - .leafBuilder().withNodeIdentifier(getNodeIdentifier("boolean")); - booleanBuilder.withValue(false); - b.withChild(booleanBuilder.build()); - - final ListNodeBuilder> leafListBuilder = Builders.leafSetBuilder() - .withNodeIdentifier(getNodeIdentifier("leafList")); - - final NormalizedNodeBuilder> leafList1Builder = Builders - .leafSetEntryBuilder().withNodeIdentifier( - new YangInstanceIdentifier.NodeWithValue(getNodeIdentifier("leafList").getNodeType(), "a")); - - leafList1Builder.withValue("a"); - - leafListBuilder.withChild(leafList1Builder.build()); - b.withChild(leafListBuilder.build()); - - return b.build(); - } - - private static ContainerNode augmentChoiceHell() { - - final DataContainerNodeBuilder b = containerBuilder(); - b.withNodeIdentifier(getNodeIdentifier("container")); - - b.withChild(choiceBuilder() - .withNodeIdentifier(getNodeIdentifier("ch2")) - .withChild( - Builders.leafBuilder().withNodeIdentifier(getNodeIdentifier("c2Leaf")).withValue("2").build()) - .withChild( - choiceBuilder() - .withNodeIdentifier(getNodeIdentifier("c2DeepChoice")) - .withChild( - Builders.leafBuilder() - .withNodeIdentifier(getNodeIdentifier("c2DeepChoiceCase1Leaf2")) - .withValue("2").build()).build()).build()); - - b.withChild(choiceBuilder() - .withNodeIdentifier(getNodeIdentifier("ch3")) - .withChild( - Builders.leafBuilder().withNodeIdentifier(getNodeIdentifier("c3Leaf")).withValue("3").build()) - .build()); - - b.withChild(augmentationBuilder() - .withNodeIdentifier(getAugmentIdentifier("augLeaf")) - .withChild( - Builders.leafBuilder().withNodeIdentifier(getNodeIdentifier("augLeaf")).withValue("augment") - .build()).build()); - - b.withChild(augmentationBuilder() - .withNodeIdentifier(getAugmentIdentifier("ch")) - .withChild( - choiceBuilder() - .withNodeIdentifier(getNodeIdentifier("ch")) - .withChild( - Builders.leafBuilder().withNodeIdentifier(getNodeIdentifier("c1Leaf")) - .withValue("1").build()) - .withChild( - augmentationBuilder() - .withNodeIdentifier( - getAugmentIdentifier("c1Leaf_AnotherAugment", "deepChoice")) - .withChild( - Builders.leafBuilder() - .withNodeIdentifier( - getNodeIdentifier("c1Leaf_AnotherAugment")) - .withValue("1").build()) - .withChild( - choiceBuilder() - .withNodeIdentifier(getNodeIdentifier("deepChoice")) - .withChild( - Builders.leafBuilder() - .withNodeIdentifier( - getNodeIdentifier("deepLeafc1")) - .withValue("1").build()).build()) - .build()).build()).build()); - - return b.build(); - } - - private static YangInstanceIdentifier.NodeIdentifier getNodeIdentifier(final String localName) { - return new YangInstanceIdentifier.NodeIdentifier(QName.create(URI.create(NAMESPACE), revision, localName)); - } - - public static YangInstanceIdentifier.AugmentationIdentifier getAugmentIdentifier(final String... childNames) { - final Set qn = Sets.newHashSet(); - - for (final String childName : childNames) { - qn.add(getNodeIdentifier(childName).getNodeType()); - } - - return new YangInstanceIdentifier.AugmentationIdentifier(qn); - } - - public NormalizedNodeXmlTranslationTest(final String yangPath, final String xmlPath, - final ContainerNode expectedNode) throws ReactorException { - schema = parseTestSchema(yangPath); - this.xmlPath = xmlPath; - this.containerNode = (ContainerSchemaNode) NormalizedDataBuilderTest.getSchemaNode(schema, "test", "container"); - this.expectedNode = expectedNode; - } - - private final ContainerNode expectedNode; - private final ContainerSchemaNode containerNode; - private final String xmlPath; - - SchemaContext parseTestSchema(final String... yangPath) throws ReactorException { - return RetestUtils.parseYangStreams(getTestYangs(yangPath)); - } - - List getTestYangs(final String... yangPaths) { - - return Lists.newArrayList(Collections2.transform(Lists.newArrayList(yangPaths), - new Function() { - @Override - public InputStream apply(final String input) { - final InputStream resourceAsStream = NormalizedDataBuilderTest.class.getResourceAsStream(input); - Preconditions.checkNotNull(resourceAsStream, "File %s was null", resourceAsStream); - return resourceAsStream; - } - })); - } - - @Test - public void testTranslation() throws Exception { - final Document doc = loadDocument(xmlPath); - - final ContainerNode built = DomToNormalizedNodeParserFactory - .getInstance(DomUtils.defaultValueCodecProvider(), schema).getContainerNodeParser() - .parse(Collections.singletonList(doc.getDocumentElement()), containerNode); - - if (expectedNode != null) { - org.junit.Assert.assertEquals(expectedNode, built); - } - - System.err.println(built); - logger.info("{}", built); - - final Element elementNS = XmlDocumentUtils.getDocument().createElementNS( - containerNode.getQName().getNamespace().toString(), containerNode.getQName().getLocalName()); - writeNormalizedNode(built, new DOMResult(elementNS), SchemaPath.create(true), schema); - - XMLUnit.setIgnoreWhitespace(true); - XMLUnit.setIgnoreComments(true); - XMLUnit.setIgnoreAttributeOrder(true); - XMLUnit.setNormalize(true); - - System.err.println(toString(doc.getDocumentElement())); - System.err.println(toString(elementNS)); - - final Diff diff = new Diff(XMLUnit.buildControlDocument(toString(doc.getDocumentElement())), - XMLUnit.buildTestDocument(toString(elementNS))); - - // FIXME the comparison cannot be performed, since the qualifiers supplied by XMlUnit do not work correctly in - // this case - // We need to implement custom qualifier so that the element ordering does not mess the DIFF - // dd.overrideElementQualifier(new MultiLevelElementNameAndTextQualifier(100, true)); - // assertTrue(dd.toString(), dd.similar()); - } - - static final XMLOutputFactory XML_FACTORY; - static { - XML_FACTORY = XMLOutputFactory.newFactory(); - XML_FACTORY.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, false); - } - - private static void writeNormalizedNode(final NormalizedNode normalized, final DOMResult result, - final SchemaPath schemaPath, final SchemaContext context) throws IOException, XMLStreamException { - NormalizedNodeWriter normalizedNodeWriter = null; - NormalizedNodeStreamWriter normalizedNodeStreamWriter = null; - XMLStreamWriter writer = null; - try { - writer = XML_FACTORY.createXMLStreamWriter(result); - normalizedNodeStreamWriter = XMLStreamNormalizedNodeStreamWriter.create(writer, context, schemaPath); - normalizedNodeWriter = NormalizedNodeWriter.forStreamWriter(normalizedNodeStreamWriter); - - normalizedNodeWriter.write(normalized); - - normalizedNodeWriter.flush(); - } finally { - if (normalizedNodeWriter != null) { - normalizedNodeWriter.close(); - } - if (normalizedNodeStreamWriter != null) { - normalizedNodeStreamWriter.close(); - } - if (writer != null) { - writer.close(); - } - } - } - - private static Document loadDocument(final String xmlPath) throws IOException, SAXException { - final InputStream resourceAsStream = NormalizedDataBuilderTest.class.getResourceAsStream(xmlPath); - - final Document currentConfigElement = readXmlToDocument(resourceAsStream); - Preconditions.checkNotNull(currentConfigElement); - return currentConfigElement; - } - - private static final DocumentBuilderFactory BUILDERFACTORY; - - static { - final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - factory.setNamespaceAware(true); - factory.setCoalescing(true); - factory.setIgnoringElementContentWhitespace(true); - factory.setIgnoringComments(true); - BUILDERFACTORY = factory; - } - - private static Document readXmlToDocument(final InputStream xmlContent) throws IOException, SAXException { - final DocumentBuilder dBuilder; - try { - dBuilder = BUILDERFACTORY.newDocumentBuilder(); - } catch (final ParserConfigurationException e) { - throw new RuntimeException("Failed to parse XML document", e); - } - final Document doc = dBuilder.parse(xmlContent); - - doc.getDocumentElement().normalize(); - return doc; - } - - public static String toString(final Element xml) { - try { - final Transformer transformer = TransformerFactory.newInstance().newTransformer(); - transformer.setOutputProperty(OutputKeys.INDENT, "yes"); - - final StreamResult result = new StreamResult(new StringWriter()); - final DOMSource source = new DOMSource(xml); - transformer.transform(source, result); - - return result.getWriter().toString(); - } catch (IllegalArgumentException | TransformerFactoryConfigurationError | TransformerException e) { - throw new RuntimeException("Unable to serialize xml element " + xml, e); - } - } -} diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/Bug2690FixTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/Bug2690FixTest.java deleted file mode 100644 index c39e319067..0000000000 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/Bug2690FixTest.java +++ /dev/null @@ -1,95 +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.data.impl.schema.tree; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import com.google.common.base.Optional; -import com.google.common.io.ByteSource; -import com.google.common.io.Resources; -import java.io.IOException; -import java.util.Collections; -import org.junit.Before; -import org.junit.Test; -import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; -import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode; -import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode; -import org.opendaylight.yangtools.yang.data.api.schema.MapNode; -import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; -import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodeContainer; -import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate; -import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException; -import org.opendaylight.yangtools.yang.data.api.schema.tree.TreeType; -import org.opendaylight.yangtools.yang.data.impl.schema.Builders; -import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes; -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; - -public class Bug2690FixTest { - private static final String ODL_DATASTORE_TEST_YANG = "/odl-datastore-test.yang"; - private SchemaContext schemaContext; - - private InMemoryDataTree inMemoryDataTree; - - @Before - public void prepare() throws IOException, YangSyntaxErrorException { - schemaContext = createTestContext(); - assertNotNull("Schema context must not be null.", schemaContext); - inMemoryDataTree = (InMemoryDataTree) InMemoryDataTreeFactory.getInstance().create(TreeType.OPERATIONAL); - inMemoryDataTree.setSchemaContext(schemaContext); - } - - private static ByteSource getInputStream() { - return Resources.asByteSource(TestModel.class.getResource(ODL_DATASTORE_TEST_YANG)); - } - - public static SchemaContext createTestContext() throws IOException, YangSyntaxErrorException { - final YangParserImpl parser = new YangParserImpl(); - return parser.parseSources(Collections.singletonList(getInputStream())); - } - - @Test - public void testWriteMerge1() throws DataValidationFailedException { - final MapEntryNode fooEntryNode = ImmutableNodes.mapEntry(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1); - final MapEntryNode barEntryNode = ImmutableNodes.mapEntry(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 2); - final MapNode mapNode1 = ImmutableNodes.mapNodeBuilder() - .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.OUTER_LIST_QNAME)) - .withChild(fooEntryNode).build(); - final MapNode mapNode2 = ImmutableNodes.mapNodeBuilder() - .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.OUTER_LIST_QNAME)) - .withChild(barEntryNode).build(); - - final ContainerNode cont1 = Builders.containerBuilder() - .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME)) - .withChild(mapNode1).build(); - - final ContainerNode cont2 = Builders.containerBuilder() - .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME)) - .withChild(mapNode2).build(); - - final InMemoryDataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification(); - modificationTree.write(TestModel.TEST_PATH, cont1); - modificationTree.merge(TestModel.TEST_PATH, cont2); - modificationTree.ready(); - - inMemoryDataTree.validate(modificationTree); - final DataTreeCandidate prepare = inMemoryDataTree.prepare(modificationTree); - inMemoryDataTree.commit(prepare); - - final InMemoryDataTreeSnapshot snapshotAfterTx = inMemoryDataTree.takeSnapshot(); - final InMemoryDataTreeModification modificationAfterTx = snapshotAfterTx.newModification(); - final Optional> readNode = modificationAfterTx.readNode(TestModel.OUTER_LIST_PATH); - assertTrue(readNode.isPresent()); - assertEquals(2, ((NormalizedNodeContainer)readNode.get()).getValue().size()); - - } - - -} diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/Retest_Bug2690Fix.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/Bug2690Test.java similarity index 95% rename from yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/Retest_Bug2690Fix.java rename to yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/Bug2690Test.java index 933017534c..f0dc617e28 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/Retest_Bug2690Fix.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/Bug2690Test.java @@ -25,13 +25,13 @@ import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodeContainer; import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate; import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException; import org.opendaylight.yangtools.yang.data.api.schema.tree.TreeType; -import org.opendaylight.yangtools.yang.data.impl.RetestUtils; +import org.opendaylight.yangtools.yang.data.impl.TestUtils; import org.opendaylight.yangtools.yang.data.impl.schema.Builders; import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes; import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; -public class Retest_Bug2690Fix { +public class Bug2690Test { private static final String ODL_DATASTORE_TEST_YANG = "/odl-datastore-test.yang"; private SchemaContext schemaContext; private InMemoryDataTree inMemoryDataTree; @@ -53,7 +53,7 @@ public class Retest_Bug2690Fix { } public static SchemaContext createTestContext() throws ReactorException { - return RetestUtils.parseYangStreams(Collections.singletonList(getDatastoreTestInputStream())); + return TestUtils.parseYangStreams(Collections.singletonList(getDatastoreTestInputStream())); } @Test diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/Bug3674Test.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/Bug3674Test.java index c5f59e68e6..479f7658f3 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/Bug3674Test.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/Bug3674Test.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. + * 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, @@ -17,6 +17,7 @@ import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification import org.opendaylight.yangtools.yang.data.api.schema.tree.ModificationType; import org.opendaylight.yangtools.yang.data.api.schema.tree.TreeType; import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes; +import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; /** * BUG-3674: issuing a delete on a non-existent entry must be preserved in @@ -27,7 +28,7 @@ public class Bug3674Test { private DataTree tree; @Before - public void setUp() { + public void setUp() throws ReactorException { tree = InMemoryDataTreeFactory.getInstance().create(TreeType.OPERATIONAL); tree.setSchemaContext(TestModel.createTestContext()); diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/Bug4295Test.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/Bug4295Test.java index 9ac489c01b..8d36915d11 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/Bug4295Test.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/Bug4295Test.java @@ -26,7 +26,7 @@ import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException; import org.opendaylight.yangtools.yang.data.api.schema.tree.TipProducingDataTree; import org.opendaylight.yangtools.yang.data.api.schema.tree.TreeType; -import org.opendaylight.yangtools.yang.data.impl.RetestUtils; +import org.opendaylight.yangtools.yang.data.impl.TestUtils; import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes; import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.CollectionNodeBuilder; import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeAttrBuilder; @@ -51,7 +51,7 @@ public class Bug4295Test { public void init() throws Exception { final File resourceFile = new File(Bug4295Test.class.getResource("/bug-4295/foo.yang") .toURI()); - context = RetestUtils.parseYangSources(resourceFile); + context = TestUtils.parseYangSources(resourceFile); foo = QNameModule.create(new URI("foo"), SimpleDateFormatUtil.getRevisionFormat().parse("1970-01-01")); root = QName.create(foo, "root"); subRoot = QName.create(foo, "sub-root"); diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/CaseExclusionTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/CaseExclusionTest.java index cec5bbbc43..781f0d129c 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/CaseExclusionTest.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/CaseExclusionTest.java @@ -31,7 +31,7 @@ public class CaseExclusionTest { @Before public void prepare() throws ReactorException { - schemaContext = RetestModel.createTestContext("/case-exclusion-test.yang"); + schemaContext = TestModel.createTestContext("/case-exclusion-test.yang"); assertNotNull("Schema context must not be null.", schemaContext); } diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/ConcurrentTreeModificationTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/ConcurrentTreeModificationTest.java index 8e7ef3f868..28ee0686ab 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/ConcurrentTreeModificationTest.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/ConcurrentTreeModificationTest.java @@ -1,3 +1,11 @@ +/* + * 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.data.impl.schema.tree; import static org.junit.Assert.assertFalse; @@ -21,6 +29,7 @@ import org.opendaylight.yangtools.yang.data.api.schema.tree.TreeType; 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.parser.spi.meta.ReactorException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -52,7 +61,7 @@ public class ConcurrentTreeModificationTest { private InMemoryDataTree inMemoryDataTree; @Before - public void prepare() { + public void prepare() throws ReactorException { schemaContext = TestModel.createTestContext(); assertNotNull("Schema context must not be null.", schemaContext); inMemoryDataTree = (InMemoryDataTree) InMemoryDataTreeFactory.getInstance().create(TreeType.OPERATIONAL); diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/ConfigStatementValidationTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/ConfigStatementValidationTest.java index f35ad36e1a..5322b9887b 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/ConfigStatementValidationTest.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/ConfigStatementValidationTest.java @@ -5,6 +5,7 @@ * 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.data.impl.schema.tree; import static org.junit.Assert.assertNotNull; @@ -27,6 +28,7 @@ import org.opendaylight.yangtools.yang.data.impl.schema.Builders; 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.parser.spi.meta.ReactorException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -37,20 +39,20 @@ public class ConfigStatementValidationTest { private static final Short ONE_ID = 1; private static final Short TWO_ID = 2; - private static final YangInstanceIdentifier OUTER_LIST_1_PATH = YangInstanceIdentifier.builder(TestModel.OUTER_LIST_PATH) - .nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, ONE_ID) // + private static final YangInstanceIdentifier OUTER_LIST_1_PATH = YangInstanceIdentifier + .builder(TestModel.OUTER_LIST_PATH).nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, ONE_ID) // .build(); - private static final YangInstanceIdentifier OUTER_LIST_2_PATH = YangInstanceIdentifier.builder(TestModel.OUTER_LIST_PATH) - .nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, TWO_ID) // + private static final YangInstanceIdentifier OUTER_LIST_2_PATH = YangInstanceIdentifier + .builder(TestModel.OUTER_LIST_PATH).nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, TWO_ID) // .build(); - private static final MapEntryNode INNER_FOO_ENTRY_NODE = - ImmutableNodes.mapEntry(TestModel.INNER_LIST_QNAME, TestModel.NAME_QNAME, "foo"); + private static final MapEntryNode INNER_FOO_ENTRY_NODE = ImmutableNodes.mapEntry(TestModel.INNER_LIST_QNAME, + TestModel.NAME_QNAME, "foo"); - private static final MapEntryNode INNER_BAR_ENTRY_NODE = - ImmutableNodes.mapEntryBuilder(QName.create(TestModel.TEST_QNAME, "inner-list2"), TestModel.NAME_QNAME, "foo") - .withChild(ImmutableNodes.leafNode(TestModel.VALUE_QNAME, "value")).build(); + private static final MapEntryNode INNER_BAR_ENTRY_NODE = ImmutableNodes + .mapEntryBuilder(QName.create(TestModel.TEST_QNAME, "inner-list2"), TestModel.NAME_QNAME, "foo") + .withChild(ImmutableNodes.leafNode(TestModel.VALUE_QNAME, "value")).build(); private static final MapEntryNode FOO_NODE = mapEntryBuilder(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, ONE_ID) // .withChild(mapNodeBuilder(TestModel.INNER_LIST_QNAME).withChild(INNER_FOO_ENTRY_NODE) // @@ -65,37 +67,32 @@ public class ConfigStatementValidationTest { private SchemaContext schemaContext; private static ContainerNode createFooTestContainerNode() { - return ImmutableContainerNodeBuilder - .create() + return ImmutableContainerNodeBuilder.create() .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME)) - .withChild( - mapNodeBuilder(TestModel.OUTER_LIST_QNAME) - .withChild(FOO_NODE).build()).build(); + .withChild(mapNodeBuilder(TestModel.OUTER_LIST_QNAME).withChild(FOO_NODE).build()).build(); } private static ContainerNode createBarTestContainerNode() { - return ImmutableContainerNodeBuilder - .create() + return ImmutableContainerNodeBuilder.create() .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME)) - .withChild( - mapNodeBuilder(TestModel.OUTER_LIST_QNAME) - .withChild(BAR_NODE).build()).build(); + .withChild(mapNodeBuilder(TestModel.OUTER_LIST_QNAME).withChild(BAR_NODE).build()).build(); } @Before - public void prepare() { + public void prepare() throws ReactorException { schemaContext = TestModel.createTestContext(); assertNotNull("Schema context must not be null.", schemaContext); } - @Test(expected=SchemaValidationFailedException.class) + @Test(expected = SchemaValidationFailedException.class) public void testOnPathFail() throws DataValidationFailedException { - final InMemoryDataTree inMemoryDataTree = - (InMemoryDataTree) InMemoryDataTreeFactory.getInstance().create(TreeType.CONFIGURATION); + final InMemoryDataTree inMemoryDataTree = (InMemoryDataTree) InMemoryDataTreeFactory.getInstance().create( + TreeType.CONFIGURATION); inMemoryDataTree.setSchemaContext(schemaContext); final InMemoryDataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification(); - final YangInstanceIdentifier ii = OUTER_LIST_1_PATH.node(new YangInstanceIdentifier.NodeIdentifier(TestModel.INNER_LIST_QNAME)) - .node(INNER_FOO_ENTRY_NODE.getIdentifier()); + final YangInstanceIdentifier ii = OUTER_LIST_1_PATH.node( + new YangInstanceIdentifier.NodeIdentifier(TestModel.INNER_LIST_QNAME)).node( + INNER_FOO_ENTRY_NODE.getIdentifier()); modificationTree.write(ii, INNER_FOO_ENTRY_NODE); inMemoryDataTree.validate(modificationTree); @@ -103,10 +100,10 @@ public class ConfigStatementValidationTest { inMemoryDataTree.commit(prepare); } - @Test(expected=SchemaValidationFailedException.class) + @Test(expected = SchemaValidationFailedException.class) public void testOnDataFail() throws DataValidationFailedException { - final InMemoryDataTree inMemoryDataTree = - (InMemoryDataTree) InMemoryDataTreeFactory.getInstance().create(TreeType.CONFIGURATION); + final InMemoryDataTree inMemoryDataTree = (InMemoryDataTree) InMemoryDataTreeFactory.getInstance().create( + TreeType.CONFIGURATION); inMemoryDataTree.setSchemaContext(schemaContext); final InMemoryDataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification(); modificationTree.write(TestModel.TEST_PATH, createFooTestContainerNode()); @@ -116,10 +113,10 @@ public class ConfigStatementValidationTest { inMemoryDataTree.commit(prepare); } - @Test(expected=SchemaValidationFailedException.class) + @Test(expected = SchemaValidationFailedException.class) public void testOnDataLeafFail() throws DataValidationFailedException { - final InMemoryDataTree inMemoryDataTree = - (InMemoryDataTree) InMemoryDataTreeFactory.getInstance().create(TreeType.CONFIGURATION); + final InMemoryDataTree inMemoryDataTree = (InMemoryDataTree) InMemoryDataTreeFactory.getInstance().create( + TreeType.CONFIGURATION); inMemoryDataTree.setSchemaContext(schemaContext); final InMemoryDataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification(); modificationTree.write(TestModel.TEST_PATH, createBarTestContainerNode()); @@ -129,13 +126,13 @@ public class ConfigStatementValidationTest { inMemoryDataTree.commit(prepare); } - @Test(expected=SchemaValidationFailedException.class) + @Test(expected = SchemaValidationFailedException.class) public void testOnPathCaseLeafFail() throws DataValidationFailedException { - final InMemoryDataTree inMemoryDataTree = - (InMemoryDataTree) InMemoryDataTreeFactory.getInstance().create(TreeType.CONFIGURATION); + final InMemoryDataTree inMemoryDataTree = (InMemoryDataTree) InMemoryDataTreeFactory.getInstance().create( + TreeType.CONFIGURATION); inMemoryDataTree.setSchemaContext(schemaContext); - final YangInstanceIdentifier.NodeIdentifier choice1Id = new YangInstanceIdentifier.NodeIdentifier( - QName.create(TestModel.TEST_QNAME, "choice1")); + final YangInstanceIdentifier.NodeIdentifier choice1Id = new YangInstanceIdentifier.NodeIdentifier(QName.create( + TestModel.TEST_QNAME, "choice1")); final YangInstanceIdentifier.NodeIdentifier case2ContId = new YangInstanceIdentifier.NodeIdentifier( QName.create(TestModel.TEST_QNAME, "case2-cont")); final YangInstanceIdentifier ii = TestModel.TEST_PATH.node(choice1Id).node(case2ContId); @@ -144,19 +141,19 @@ public class ConfigStatementValidationTest { final InMemoryDataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification(); modificationTree.write(ii, case2Cont); - + modificationTree.ready(); inMemoryDataTree.validate(modificationTree); final DataTreeCandidate prepare = inMemoryDataTree.prepare(modificationTree); inMemoryDataTree.commit(prepare); } - @Test(expected=VerifyException.class) + @Test(expected = VerifyException.class) public void testOnDataCaseLeafFail() throws DataValidationFailedException { - final InMemoryDataTree inMemoryDataTree = - (InMemoryDataTree) InMemoryDataTreeFactory.getInstance().create(TreeType.CONFIGURATION); + final InMemoryDataTree inMemoryDataTree = (InMemoryDataTree) InMemoryDataTreeFactory.getInstance().create( + TreeType.CONFIGURATION); inMemoryDataTree.setSchemaContext(schemaContext); - final YangInstanceIdentifier.NodeIdentifier choice1Id = new YangInstanceIdentifier.NodeIdentifier( - QName.create(TestModel.TEST_QNAME, "choice1")); + final YangInstanceIdentifier.NodeIdentifier choice1Id = new YangInstanceIdentifier.NodeIdentifier(QName.create( + TestModel.TEST_QNAME, "choice1")); final YangInstanceIdentifier ii = TestModel.TEST_PATH.node(choice1Id); final ChoiceNode choice1 = Builders.choiceBuilder().withNodeIdentifier(choice1Id) .withChild(leafNode(QName.create(TestModel.TEST_QNAME, "case1-leaf1"), "leaf-value")).build(); diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/DataTreeTransactionTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/DataTreeTransactionTest.java index 60691a8978..ceabb7a9bf 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/DataTreeTransactionTest.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/DataTreeTransactionTest.java @@ -13,12 +13,13 @@ import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree; import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification; import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException; import org.opendaylight.yangtools.yang.data.api.schema.tree.TreeType; +import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; public class DataTreeTransactionTest { private DataTree tree; @Before - public void setUp() { + public void setUp() throws ReactorException { tree = InMemoryDataTreeFactory.getInstance().create(TreeType.OPERATIONAL); tree.setSchemaContext(TestModel.createTestContext()); } diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/ErrorReportingTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/ErrorReportingTest.java index bc14e4b320..c495f035d9 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/ErrorReportingTest.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/ErrorReportingTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. + * 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, @@ -16,13 +16,14 @@ import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailed import org.opendaylight.yangtools.yang.data.api.schema.tree.ModifiedNodeDoesNotExistException; import org.opendaylight.yangtools.yang.data.api.schema.tree.TreeType; import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes; +import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; public class ErrorReportingTest { private InMemoryDataTree tree; @Before - public void setup() { + public void setup() throws ReactorException { tree = (InMemoryDataTree) InMemoryDataTreeFactory.getInstance().create(TreeType.OPERATIONAL); tree.setSchemaContext(TestModel.createTestContext()); } @@ -71,5 +72,4 @@ public class ErrorReportingTest { } } - } diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/Retest_ListConstraintsValidation.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/ListConstraintsValidation.java similarity index 98% rename from yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/Retest_ListConstraintsValidation.java rename to yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/ListConstraintsValidation.java index fc21395e3b..404be92bfe 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/Retest_ListConstraintsValidation.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/ListConstraintsValidation.java @@ -32,7 +32,7 @@ import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate; import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification; import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException; import org.opendaylight.yangtools.yang.data.api.schema.tree.TreeType; -import org.opendaylight.yangtools.yang.data.impl.RetestUtils; +import org.opendaylight.yangtools.yang.data.impl.TestUtils; import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes; import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafSetEntryNodeBuilder; import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafSetNodeBuilder; @@ -43,8 +43,8 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class Retest_ListConstraintsValidation { - private static final Logger LOG = LoggerFactory.getLogger(Retest_ListConstraintsValidation.class); +public class ListConstraintsValidation { + private static final Logger LOG = LoggerFactory.getLogger(ListConstraintsValidation.class); private static final String CONSTRAINTS_VALIDATION_TEST_YANG = "/list-constraints-validation-test-model.yang"; private SchemaContext schemaContext; @@ -99,7 +99,7 @@ public class Retest_ListConstraintsValidation { } public static SchemaContext createTestContext() throws ReactorException { - return RetestUtils.parseYangStreams(Collections.singletonList(getDatastoreTestInputStream())); + return TestUtils.parseYangStreams(Collections.singletonList(getDatastoreTestInputStream())); } @Test diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/ListConstraintsValidationTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/ListConstraintsValidationTest.java deleted file mode 100644 index 675de0e86a..0000000000 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/ListConstraintsValidationTest.java +++ /dev/null @@ -1,301 +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.yang.data.impl.schema.tree; - -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import com.google.common.base.Optional; -import com.google.common.io.ByteSource; -import com.google.common.io.Resources; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import org.junit.Before; -import org.junit.Test; -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; -import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier; -import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue; -import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode; -import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode; -import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode; -import org.opendaylight.yangtools.yang.data.api.schema.MapNode; -import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; -import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodeContainer; -import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode; -import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode; -import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate; -import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification; -import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException; -import org.opendaylight.yangtools.yang.data.api.schema.tree.TreeType; -import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes; -import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafSetEntryNodeBuilder; -import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafSetNodeBuilder; -import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableUnkeyedListEntryNodeBuilder; -import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableUnkeyedListNodeBuilder; -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.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class ListConstraintsValidationTest { - private static final Logger LOG = LoggerFactory.getLogger(ListConstraintsValidationTest.class); - - private static final String CONSTRAINTS_VALIDATION_TEST_YANG = "/list-constraints-validation-test-model.yang"; - private SchemaContext schemaContext; - - private InMemoryDataTree inMemoryDataTree; - - private static final QName MASTER_CONTAINER_QNAME = QName.create("urn:opendaylight:params:xml:ns:yang:list-constraints-validation-test-model", "2015-02-02", - "master-container"); - private static final QName MIN_MAX_LIST_QNAME = QName.create(MASTER_CONTAINER_QNAME, "min-max-list"); - private static final QName MIN_MAX_KEY_LEAF_QNAME = QName.create(MASTER_CONTAINER_QNAME, "min-max-key-leaf"); - private static final QName UNBOUNDED_LIST_QNAME = QName.create(MASTER_CONTAINER_QNAME, "unbounded-list"); - private static final QName UNBOUNDED_KEY_LEAF_QNAME = QName.create(MASTER_CONTAINER_QNAME, "unbounded-key-leaf"); - private static final QName MIN_MAX_LEAF_LIST_QNAME = QName.create(MASTER_CONTAINER_QNAME, "min-max-leaf-list"); - private static final QName UNBOUNDED_LEAF_LIST_QNAME = QName.create(MASTER_CONTAINER_QNAME, "unbounded-leaf-list"); - private static final QName UNKEYED_LIST_QNAME = QName.create(MASTER_CONTAINER_QNAME, "unkeyed-list"); - private static final QName UNKEYED_LEAF_QNAME = QName.create(MASTER_CONTAINER_QNAME, "unkeyed-leaf"); - - private static final YangInstanceIdentifier MASTER_CONTAINER_PATH = YangInstanceIdentifier.of(MASTER_CONTAINER_QNAME); - private static final YangInstanceIdentifier MIN_MAX_LIST_PATH = YangInstanceIdentifier.builder(MASTER_CONTAINER_PATH) - .node(MIN_MAX_LIST_QNAME).build(); - private static final YangInstanceIdentifier UNBOUNDED_LIST_PATH = YangInstanceIdentifier.builder(MASTER_CONTAINER_PATH) - .node(UNBOUNDED_LIST_QNAME).build(); - private static final YangInstanceIdentifier MIN_MAX_LEAF_LIST_PATH = YangInstanceIdentifier.builder(MASTER_CONTAINER_PATH) - .node(MIN_MAX_LEAF_LIST_QNAME).build(); - private static final YangInstanceIdentifier UNBOUNDED_LEAF_LIST_PATH = YangInstanceIdentifier.builder(MASTER_CONTAINER_PATH) - .node(UNBOUNDED_LEAF_LIST_QNAME).build(); - private static final YangInstanceIdentifier UNKEYED_LIST_PATH = YangInstanceIdentifier.builder(MASTER_CONTAINER_PATH) - .node(UNKEYED_LIST_QNAME).build(); - - @Before - public void prepare() throws IOException, YangSyntaxErrorException { - schemaContext = createTestContext(); - assertNotNull("Schema context must not be null.", schemaContext); - inMemoryDataTree = (InMemoryDataTree) InMemoryDataTreeFactory.getInstance().create(TreeType.OPERATIONAL); - inMemoryDataTree.setSchemaContext(schemaContext); - final InMemoryDataTreeSnapshot initialDataTreeSnapshot = inMemoryDataTree.takeSnapshot(); - final DataTreeModification modificationTree = initialDataTreeSnapshot.newModification(); - - modificationTree.write(MASTER_CONTAINER_PATH, ImmutableNodes.containerNode(MASTER_CONTAINER_QNAME)); - modificationTree.ready(); - inMemoryDataTree.commit(inMemoryDataTree.prepare(modificationTree)); - - } - - private static ByteSource getInputStream() { - return Resources.asByteSource(TestModel.class.getResource(CONSTRAINTS_VALIDATION_TEST_YANG)); - } - - public static SchemaContext createTestContext() throws IOException, YangSyntaxErrorException { - final YangParserImpl parser = new YangParserImpl(); - return parser.parseSources(Collections.singletonList(getInputStream())); - } - - @Test - public void minMaxListTestPass() throws DataValidationFailedException { - - final MapEntryNode fooEntryNode = ImmutableNodes.mapEntry(MIN_MAX_LIST_QNAME, MIN_MAX_KEY_LEAF_QNAME, "foo"); - final MapEntryNode barEntryNode = ImmutableNodes.mapEntry(MIN_MAX_LIST_QNAME, MIN_MAX_KEY_LEAF_QNAME, "bar"); - final MapNode mapNode1 = ImmutableNodes.mapNodeBuilder() - .withNodeIdentifier(new NodeIdentifier(MIN_MAX_LIST_QNAME)) - .withChild(fooEntryNode).build(); - final MapNode mapNode2 = ImmutableNodes.mapNodeBuilder() - .withNodeIdentifier(new NodeIdentifier(MIN_MAX_LIST_QNAME)) - .withChild(barEntryNode).build(); - - final InMemoryDataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification(); - modificationTree.write(MIN_MAX_LIST_PATH, mapNode1); - modificationTree.merge(MIN_MAX_LIST_PATH, mapNode2); - // TODO: check why write and then merge on list commits only "bar" child - modificationTree.ready(); - - inMemoryDataTree.validate(modificationTree); - final DataTreeCandidate prepare = inMemoryDataTree.prepare(modificationTree); - inMemoryDataTree.commit(prepare); - - final InMemoryDataTreeSnapshot snapshotAfterCommit = inMemoryDataTree.takeSnapshot(); - final Optional> minMaxListRead = snapshotAfterCommit.readNode(MIN_MAX_LIST_PATH); - assertTrue(minMaxListRead.isPresent()); - assertTrue(((NormalizedNodeContainer) minMaxListRead.get()).getValue().size() == 2); - } - - @Test(expected=DataValidationFailedException.class) - public void minMaxListFail() throws DataValidationFailedException { - InMemoryDataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification(); - - final MapEntryNode fooEntryNode = ImmutableNodes.mapEntry(MIN_MAX_LIST_QNAME, MIN_MAX_KEY_LEAF_QNAME, "foo"); - final MapEntryNode barEntryNode = ImmutableNodes.mapEntry(MIN_MAX_LIST_QNAME, MIN_MAX_KEY_LEAF_QNAME, "bar"); - final MapEntryNode gooEntryNode = ImmutableNodes.mapEntry(MIN_MAX_LIST_QNAME, MIN_MAX_KEY_LEAF_QNAME, "goo"); - final MapNode mapNode = ImmutableNodes.mapNodeBuilder() - .withNodeIdentifier(new NodeIdentifier(MIN_MAX_LIST_QNAME)) - .withChild(fooEntryNode).build(); - - final YangInstanceIdentifier fooPath = MIN_MAX_LIST_PATH.node(fooEntryNode.getIdentifier()); - final YangInstanceIdentifier barPath = MIN_MAX_LIST_PATH.node(barEntryNode.getIdentifier()); - final YangInstanceIdentifier gooPath = MIN_MAX_LIST_PATH.node(gooEntryNode.getIdentifier()); - - modificationTree.write(MIN_MAX_LIST_PATH, mapNode); - modificationTree.merge(barPath, barEntryNode); - modificationTree.write(gooPath, gooEntryNode); - modificationTree.delete(gooPath); - modificationTree.ready(); - - inMemoryDataTree.validate(modificationTree); - DataTreeCandidate prepare1 = inMemoryDataTree.prepare(modificationTree); - inMemoryDataTree.commit(prepare1); - - InMemoryDataTreeSnapshot snapshotAfterCommit = inMemoryDataTree.takeSnapshot(); - Optional> minMaxListRead = snapshotAfterCommit.readNode(MIN_MAX_LIST_PATH); - assertTrue(minMaxListRead.isPresent()); - assertTrue(((NormalizedNodeContainer) minMaxListRead.get()).getValue().size() == 2); - - modificationTree = inMemoryDataTree.takeSnapshot().newModification(); - modificationTree.write(gooPath, gooEntryNode); - modificationTree.ready(); - - inMemoryDataTree.validate(modificationTree); - prepare1 = inMemoryDataTree.prepare(modificationTree); - inMemoryDataTree.commit(prepare1); - - snapshotAfterCommit = inMemoryDataTree.takeSnapshot(); - minMaxListRead = snapshotAfterCommit.readNode(MIN_MAX_LIST_PATH); - assertTrue(minMaxListRead.isPresent()); - assertTrue(((NormalizedNodeContainer) minMaxListRead.get()).getValue().size() == 3); - - modificationTree = inMemoryDataTree.takeSnapshot().newModification(); - - modificationTree.delete(gooPath); - modificationTree.delete(fooPath); - modificationTree.ready(); - - inMemoryDataTree.validate(modificationTree); - } - - @Test - public void minMaxLeafListPass() throws DataValidationFailedException { - final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification(); - - final NodeWithValue barPath = new NodeWithValue<>(MIN_MAX_LIST_QNAME, "bar"); - final NodeWithValue gooPath = new NodeWithValue<>(MIN_MAX_LIST_QNAME, "goo"); - - final LeafSetEntryNode barLeafSetEntry = ImmutableLeafSetEntryNodeBuilder.create() - .withNodeIdentifier(barPath) - .withValue("bar").build(); - final LeafSetEntryNode gooLeafSetEntry = ImmutableLeafSetEntryNodeBuilder.create() - .withNodeIdentifier(gooPath) - .withValue("goo").build(); - - final LeafSetNode fooLeafSetNode = ImmutableLeafSetNodeBuilder.create() - .withNodeIdentifier(new NodeIdentifier(MIN_MAX_LEAF_LIST_QNAME)) - .withChildValue("foo").build(); - - modificationTree.write(MIN_MAX_LEAF_LIST_PATH, fooLeafSetNode); - modificationTree.write(MIN_MAX_LEAF_LIST_PATH.node(barPath), barLeafSetEntry); - modificationTree.merge(MIN_MAX_LEAF_LIST_PATH.node(gooPath), gooLeafSetEntry); - modificationTree.delete(MIN_MAX_LEAF_LIST_PATH.node(gooPath)); - modificationTree.ready(); - - inMemoryDataTree.validate(modificationTree); - final DataTreeCandidate prepare1 = inMemoryDataTree.prepare(modificationTree); - inMemoryDataTree.commit(prepare1); - - final InMemoryDataTreeSnapshot snapshotAfterCommit = inMemoryDataTree.takeSnapshot(); - final Optional> masterContainer = snapshotAfterCommit.readNode(MASTER_CONTAINER_PATH); - assertTrue(masterContainer.isPresent()); - final Optional> leafList = ((NormalizedNodeContainer) masterContainer.get()).getChild( - new NodeIdentifier(MIN_MAX_LEAF_LIST_QNAME)); - assertTrue(leafList.isPresent()); - assertTrue(leafList.get().getValue().size() == 2); - } - - @Test(expected=DataValidationFailedException.class) - public void minMaxLeafListFail() throws DataValidationFailedException { - final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification(); - - final NodeWithValue fooPath = new NodeWithValue<>(MIN_MAX_LIST_QNAME, "foo"); - final NodeWithValue barPath = new NodeWithValue<>(MIN_MAX_LIST_QNAME, "bar"); - final NodeWithValue gooPath = new NodeWithValue<>(MIN_MAX_LIST_QNAME, "goo"); - final NodeWithValue fuuPath = new NodeWithValue<>(MIN_MAX_LIST_QNAME, "fuu"); - - final LeafSetEntryNode barLeafSetEntry = ImmutableLeafSetEntryNodeBuilder.create() - .withNodeIdentifier(barPath) - .withValue("bar").build(); - final LeafSetEntryNode gooLeafSetEntry = ImmutableLeafSetEntryNodeBuilder.create() - .withNodeIdentifier(gooPath) - .withValue("goo").build(); - final LeafSetEntryNode fuuLeafSetEntry = ImmutableLeafSetEntryNodeBuilder.create() - .withNodeIdentifier(fuuPath) - .withValue("fuu").build(); - - final LeafSetNode fooLeafSetNode = ImmutableLeafSetNodeBuilder.create() - .withNodeIdentifier(new NodeIdentifier(MIN_MAX_LEAF_LIST_QNAME)) - .withChildValue("foo").build(); - - modificationTree.write(MIN_MAX_LEAF_LIST_PATH, fooLeafSetNode); - modificationTree.write(MIN_MAX_LEAF_LIST_PATH.node(barPath), barLeafSetEntry); - modificationTree.merge(MIN_MAX_LEAF_LIST_PATH.node(gooPath), gooLeafSetEntry); - modificationTree.write(MIN_MAX_LEAF_LIST_PATH.node(fuuPath), fuuLeafSetEntry); - modificationTree.ready(); - - inMemoryDataTree.validate(modificationTree); - } - - @Test - public void unkeyedListTestPass() throws DataValidationFailedException { - final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification(); - - final UnkeyedListEntryNode foo = ImmutableUnkeyedListEntryNodeBuilder.create() - .withNodeIdentifier(new NodeIdentifier(UNKEYED_LEAF_QNAME)) - .withChild(ImmutableNodes.leafNode(UNKEYED_LEAF_QNAME, "foo")).build(); - final List unkeyedEntries = new ArrayList<>(); - unkeyedEntries.add(foo); - final UnkeyedListNode unkeyedListNode = ImmutableUnkeyedListNodeBuilder.create() - .withNodeIdentifier(new NodeIdentifier(UNKEYED_LIST_QNAME)) - .withValue(unkeyedEntries).build(); - - modificationTree.write(MASTER_CONTAINER_PATH, ImmutableNodes.containerNode(MASTER_CONTAINER_QNAME)); - modificationTree.merge(UNKEYED_LIST_PATH, unkeyedListNode); - modificationTree.ready(); - - inMemoryDataTree.validate(modificationTree); - final DataTreeCandidate prepare1 = inMemoryDataTree.prepare(modificationTree); - inMemoryDataTree.commit(prepare1); - - final InMemoryDataTreeSnapshot snapshotAfterCommit = inMemoryDataTree.takeSnapshot(); - final Optional> unkeyedListRead = snapshotAfterCommit.readNode(UNKEYED_LIST_PATH); - assertTrue(unkeyedListRead.isPresent()); - assertTrue(((UnkeyedListNode) unkeyedListRead.get()).getSize() == 1); - } - - @Test(expected=DataValidationFailedException.class) - public void unkeyedListTestFail() throws DataValidationFailedException { - final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification(); - - final UnkeyedListEntryNode foo = ImmutableUnkeyedListEntryNodeBuilder.create() - .withNodeIdentifier(new NodeIdentifier(UNKEYED_LEAF_QNAME)) - .withChild(ImmutableNodes.leafNode(UNKEYED_LEAF_QNAME, "foo")).build(); - final UnkeyedListEntryNode bar = ImmutableUnkeyedListEntryNodeBuilder.create() - .withNodeIdentifier(new NodeIdentifier(UNKEYED_LEAF_QNAME)) - .withChild(ImmutableNodes.leafNode(UNKEYED_LEAF_QNAME, "bar")).build(); - final List unkeyedEntries = new ArrayList<>(); - unkeyedEntries.add(foo); - unkeyedEntries.add(bar); - final UnkeyedListNode unkeyedListNode = ImmutableUnkeyedListNodeBuilder.create() - .withNodeIdentifier(new NodeIdentifier(UNKEYED_LIST_QNAME)) - .withValue(unkeyedEntries).build(); - - modificationTree.write(UNKEYED_LIST_PATH, unkeyedListNode); - modificationTree.ready(); - - inMemoryDataTree.validate(modificationTree); - } -} diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/MandatoryLeafTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/MandatoryLeafTest.java index 98cd9aef4a..6346167d71 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/MandatoryLeafTest.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/MandatoryLeafTest.java @@ -30,7 +30,7 @@ public class MandatoryLeafTest { @Before public void prepare() throws ReactorException { - schemaContext = RetestModel.createTestContext("/mandatory-leaf-test.yang"); + schemaContext = TestModel.createTestContext("/mandatory-leaf-test.yang"); assertNotNull("Schema context must not be null.", schemaContext); } diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/ModificationMetadataTreeTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/ModificationMetadataTreeTest.java index 5b500bb4cb..0c8052610f 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/ModificationMetadataTreeTest.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/ModificationMetadataTreeTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. + * 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, @@ -32,6 +32,7 @@ import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.Version; 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.parser.spi.meta.ReactorException; /** * @@ -95,7 +96,7 @@ public class ModificationMetadataTreeTest { private RootModificationApplyOperation rootOper; @Before - public void prepare() { + public void prepare() throws ReactorException { schemaContext = TestModel.createTestContext(); assertNotNull("Schema context must not be null.", schemaContext); rootOper = RootModificationApplyOperation.from(SchemaAwareApplyOperation.from(schemaContext, TreeType.OPERATIONAL)); diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/OrderedListTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/OrderedListTest.java index b7f130bcf6..b12c054788 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/OrderedListTest.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/OrderedListTest.java @@ -34,7 +34,7 @@ import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot; import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException; import org.opendaylight.yangtools.yang.data.api.schema.tree.TipProducingDataTree; import org.opendaylight.yangtools.yang.data.api.schema.tree.TreeType; -import org.opendaylight.yangtools.yang.data.impl.RetestUtils; +import org.opendaylight.yangtools.yang.data.impl.TestUtils; import org.opendaylight.yangtools.yang.data.impl.schema.Builders; import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.slf4j.Logger; @@ -60,7 +60,7 @@ public class OrderedListTest { public void setup() throws Exception { final File resourceFile = new File(Bug4295Test.class.getResource("/ordered-list-modification-test.yang") .toURI()); - context = RetestUtils.parseYangSources(resourceFile); + context = TestUtils.parseYangSources(resourceFile); testModule = QNameModule.create(new URI("ordered-list-modification-test"), SimpleDateFormatUtil.getRevisionFormat().parse("1970-01-01")); parentContainer = QName.create(testModule, "parent-container"); diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/RetestModel.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/RetestModel.java deleted file mode 100644 index 8035f5cb43..0000000000 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/RetestModel.java +++ /dev/null @@ -1,50 +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.data.impl.schema.tree; - -import java.io.InputStream; -import java.util.Arrays; -import java.util.Collections; - -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; -import org.opendaylight.yangtools.yang.data.impl.RetestUtils; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; - -public class RetestModel { - - public static final QName TEST_QNAME = QName.create( - "urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test", "2014-03-13", "test"); - public static final QName OUTER_LIST_QNAME = QName.create(TEST_QNAME, "outer-list"); - public static final QName INNER_LIST_QNAME = QName.create(TEST_QNAME, "inner-list"); - public static final QName OUTER_CHOICE_QNAME = QName.create(TEST_QNAME, "outer-choice"); - public static final QName ID_QNAME = QName.create(TEST_QNAME, "id"); - public static final QName NAME_QNAME = QName.create(TEST_QNAME, "name"); - public static final QName VALUE_QNAME = QName.create(TEST_QNAME, "value"); - private static final String DATASTORE_TEST_YANG = "/odl-datastore-test.yang"; - - public static final YangInstanceIdentifier TEST_PATH = YangInstanceIdentifier.of(TEST_QNAME); - public static final YangInstanceIdentifier OUTER_LIST_PATH = YangInstanceIdentifier.builder(TEST_PATH) - .node(OUTER_LIST_QNAME).build(); - public static final QName TWO_QNAME = QName.create(TEST_QNAME, "two"); - public static final QName THREE_QNAME = QName.create(TEST_QNAME, "three"); - - public static InputStream getDatastoreTestInputStream() { - return RetestModel.class.getResourceAsStream(DATASTORE_TEST_YANG); - } - - public static SchemaContext createTestContext() throws ReactorException { - return RetestUtils.parseYangStreams(Arrays.asList(getDatastoreTestInputStream())); - } - - public static SchemaContext createTestContext(String resourcePath) throws ReactorException { - InputStream yangStream = RetestModel.class.getResourceAsStream(resourcePath); - return RetestUtils.parseYangStreams(Collections.singletonList(yangStream)); - } -} diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/Retest_Bug3674Test.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/Retest_Bug3674Test.java deleted file mode 100644 index 8f1d4a5dd2..0000000000 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/Retest_Bug3674Test.java +++ /dev/null @@ -1,52 +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.data.impl.schema.tree; - -import static org.junit.Assert.assertEquals; -import org.junit.Before; -import org.junit.Test; -import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree; -import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate; -import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode; -import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification; -import org.opendaylight.yangtools.yang.data.api.schema.tree.ModificationType; -import org.opendaylight.yangtools.yang.data.api.schema.tree.TreeType; -import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes; -import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; - -/** - * BUG-3674: issuing a delete on a non-existent entry must be preserved in - * DataTreeModification, but should appear as UNMODIFIED in the - * resulting DataTreeCandidate. - */ -public class Retest_Bug3674Test { - private DataTree tree; - - @Before - public void setUp() throws ReactorException { - tree = InMemoryDataTreeFactory.getInstance().create(TreeType.OPERATIONAL); - tree.setSchemaContext(RetestModel.createTestContext()); - - // Create the top-level container - final DataTreeModification mod = tree.takeSnapshot().newModification(); - mod.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME)); - mod.ready(); - tree.commit(tree.prepare(mod)); - } - - @Test - public void testDeleteOfNonExistingNode() { - final DataTreeModification mod = tree.takeSnapshot().newModification(); - mod.delete(TestModel.OUTER_LIST_PATH); - mod.ready(); - - final DataTreeCandidate candidate = tree.prepare(mod); - final DataTreeCandidateNode root = candidate.getRootNode(); - assertEquals(ModificationType.UNMODIFIED, root.getModificationType()); - } -} diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/Retest_ConcurrentTreeModificationTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/Retest_ConcurrentTreeModificationTest.java deleted file mode 100644 index 5ef6bde142..0000000000 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/Retest_ConcurrentTreeModificationTest.java +++ /dev/null @@ -1,636 +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.data.impl.schema.tree; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.mapEntryBuilder; -import static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.mapNodeBuilder; -import com.google.common.base.Optional; -import org.junit.Before; -import org.junit.Test; -import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; -import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode; -import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode; -import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; -import org.opendaylight.yangtools.yang.data.api.schema.tree.ConflictingModificationAppliedException; -import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate; -import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification; -import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException; -import org.opendaylight.yangtools.yang.data.api.schema.tree.TreeType; -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.parser.spi.meta.ReactorException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class Retest_ConcurrentTreeModificationTest { - private static final Logger LOG = LoggerFactory.getLogger(Retest_ConcurrentTreeModificationTest.class); - - private static final Short ONE_ID = 1; - private static final Short TWO_ID = 2; - - private static final YangInstanceIdentifier OUTER_LIST_1_PATH = YangInstanceIdentifier.builder(TestModel.OUTER_LIST_PATH) - .nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, ONE_ID) // - .build(); - - private static final YangInstanceIdentifier OUTER_LIST_2_PATH = YangInstanceIdentifier.builder(TestModel.OUTER_LIST_PATH) - .nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, TWO_ID) // - .build(); - - private static final MapEntryNode FOO_NODE = mapEntryBuilder(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, ONE_ID) // - .withChild(mapNodeBuilder(TestModel.INNER_LIST_QNAME) // - .build()) // - .build(); - - private static final MapEntryNode BAR_NODE = mapEntryBuilder(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, TWO_ID) // - .withChild(mapNodeBuilder(TestModel.INNER_LIST_QNAME) // - .build()) // - .build(); - - private SchemaContext schemaContext; - private InMemoryDataTree inMemoryDataTree; - - @Before - public void prepare() throws ReactorException { - schemaContext = RetestModel.createTestContext(); - assertNotNull("Schema context must not be null.", schemaContext); - inMemoryDataTree = (InMemoryDataTree) InMemoryDataTreeFactory.getInstance().create(TreeType.OPERATIONAL); - inMemoryDataTree.setSchemaContext(schemaContext); - } - - private static ContainerNode createFooTestContainerNode() { - return ImmutableContainerNodeBuilder - .create() - .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME)) - .withChild( - mapNodeBuilder(TestModel.OUTER_LIST_QNAME) - .withChild(FOO_NODE).build()).build(); - } - - private static ContainerNode createBarTestContainerNode() { - return ImmutableContainerNodeBuilder - .create() - .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME)) - .withChild( - mapNodeBuilder(TestModel.OUTER_LIST_QNAME) - .withChild(BAR_NODE).build()).build(); - } - - private static T assertPresentAndType(final Optional potential, final Class type) { - assertNotNull(potential); - assertTrue(potential.isPresent()); - assertTrue(type.isInstance(potential.get())); - return type.cast(potential.get()); - } - - @Test - public void writeWrite1stLevelEmptyTreeTest() throws DataValidationFailedException { - final InMemoryDataTreeSnapshot initialDataTreeSnapshot = inMemoryDataTree.takeSnapshot(); - - final DataTreeModification modificationTree1 = initialDataTreeSnapshot.newModification(); - final DataTreeModification modificationTree2 = initialDataTreeSnapshot.newModification(); - - modificationTree1.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME)); - modificationTree2.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME)); - - modificationTree1.ready(); - modificationTree2.ready(); - inMemoryDataTree.validate(modificationTree1); - final DataTreeCandidate prepare1 = inMemoryDataTree.prepare(modificationTree1); - inMemoryDataTree.commit(prepare1); - - try { - inMemoryDataTree.validate(modificationTree2); - fail("Exception should have been thrown."); - } catch (final ConflictingModificationAppliedException ex) { - LOG.debug("ConflictingModificationAppliedException - '{}' was thrown as expected."); - } - final DataTreeCandidate prepare2 = inMemoryDataTree.prepare(modificationTree2); - inMemoryDataTree.commit(prepare2); - - final Optional> testNodeAfterCommits = modificationTree1.readNode(TestModel.TEST_PATH); - assertPresentAndType(testNodeAfterCommits, ContainerNode.class); - } - - @Test - public void writeMerge1stLevelEmptyTreeTest() throws DataValidationFailedException { - final InMemoryDataTreeSnapshot initialDataTreeSnapshot = inMemoryDataTree.takeSnapshot(); - - final DataTreeModification modificationTree1 = initialDataTreeSnapshot.newModification(); - final DataTreeModification modificationTree2 = initialDataTreeSnapshot.newModification(); - - modificationTree1.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME)); - modificationTree2.merge(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME)); - - modificationTree1.ready(); - modificationTree2.ready(); - - inMemoryDataTree.validate(modificationTree1); - final DataTreeCandidate prepare1 = inMemoryDataTree.prepare(modificationTree1); - inMemoryDataTree.commit(prepare1); - - inMemoryDataTree.validate(modificationTree2); - final DataTreeCandidate prepare2 = inMemoryDataTree.prepare(modificationTree2); - inMemoryDataTree.commit(prepare2); - - final Optional> testNodeAfterCommits = modificationTree1.readNode(TestModel.TEST_PATH); - assertPresentAndType(testNodeAfterCommits, ContainerNode.class); - } - - @Test - public void writeWriteFooBar1stLevelEmptyTreeTest() throws DataValidationFailedException { - final InMemoryDataTreeSnapshot initialDataTreeSnapshot = inMemoryDataTree.takeSnapshot(); - - final DataTreeModification modificationTree1 = initialDataTreeSnapshot.newModification(); - final DataTreeModification modificationTree2 = initialDataTreeSnapshot.newModification(); - - modificationTree1.write(TestModel.TEST_PATH, createFooTestContainerNode()); - modificationTree2.write(TestModel.TEST_PATH, createBarTestContainerNode()); - modificationTree1.ready(); - modificationTree2.ready(); - - inMemoryDataTree.validate(modificationTree1); - final DataTreeCandidate prepare1 = inMemoryDataTree.prepare(modificationTree1); - inMemoryDataTree.commit(prepare1); - - try { - inMemoryDataTree.validate(modificationTree2); - fail("Exception should have been thrown."); - final DataTreeCandidate prepare2 = inMemoryDataTree.prepare(modificationTree2); - inMemoryDataTree.commit(prepare2); - } catch (final ConflictingModificationAppliedException ex) { - LOG.debug("ConflictingModificationAppliedException - '{}' was thrown as expected."); - } - - final InMemoryDataTreeSnapshot snapshotAfterCommits = inMemoryDataTree.takeSnapshot(); - assertPresentAndType(snapshotAfterCommits.readNode(OUTER_LIST_1_PATH), MapEntryNode.class); - assertFalse(snapshotAfterCommits.readNode(OUTER_LIST_2_PATH).isPresent()); - } - - @Test - public void writeMergeFooBar1stLevelEmptyTreeTest() throws DataValidationFailedException { - final InMemoryDataTreeSnapshot initialDataTreeSnapshot = inMemoryDataTree.takeSnapshot(); - - final DataTreeModification modificationTree1 = initialDataTreeSnapshot.newModification(); - final DataTreeModification modificationTree2 = initialDataTreeSnapshot.newModification(); - - modificationTree1.write(TestModel.TEST_PATH, createFooTestContainerNode()); - modificationTree2.merge(TestModel.TEST_PATH, createBarTestContainerNode()); - modificationTree1.ready(); - modificationTree2.ready(); - - inMemoryDataTree.validate(modificationTree1); - final DataTreeCandidate prepare1 = inMemoryDataTree.prepare(modificationTree1); - inMemoryDataTree.commit(prepare1); - - inMemoryDataTree.validate(modificationTree2); - final DataTreeCandidate prepare2 = inMemoryDataTree.prepare(modificationTree2); - inMemoryDataTree.commit(prepare2); - - final InMemoryDataTreeSnapshot snapshotAfterCommits = inMemoryDataTree.takeSnapshot(); - assertPresentAndType(snapshotAfterCommits.readNode(OUTER_LIST_1_PATH), MapEntryNode.class); - assertPresentAndType(snapshotAfterCommits.readNode(OUTER_LIST_2_PATH), MapEntryNode.class); - } - - @Test - public void mergeWriteFooBar1stLevelEmptyTreeTest() throws DataValidationFailedException { - final InMemoryDataTreeSnapshot initialDataTreeSnapshot = inMemoryDataTree.takeSnapshot(); - - final DataTreeModification modificationTree1 = initialDataTreeSnapshot.newModification(); - final DataTreeModification modificationTree2 = initialDataTreeSnapshot.newModification(); - - modificationTree1.merge(TestModel.TEST_PATH, createFooTestContainerNode()); - modificationTree2.write(TestModel.TEST_PATH, createBarTestContainerNode()); - modificationTree1.ready(); - modificationTree2.ready(); - - inMemoryDataTree.validate(modificationTree1); - final DataTreeCandidate prepare1 = inMemoryDataTree.prepare(modificationTree1); - inMemoryDataTree.commit(prepare1); - - try { - inMemoryDataTree.validate(modificationTree2); - fail("Exception should have been thrown."); - final DataTreeCandidate prepare2 = inMemoryDataTree.prepare(modificationTree2); - inMemoryDataTree.commit(prepare2); - } catch (final ConflictingModificationAppliedException ex) { - LOG.debug("ConflictingModificationAppliedException - '{}' was thrown as expected."); - } - - final InMemoryDataTreeSnapshot snapshotAfterCommits = inMemoryDataTree.takeSnapshot(); - assertPresentAndType(snapshotAfterCommits.readNode(OUTER_LIST_1_PATH), MapEntryNode.class); - assertFalse(snapshotAfterCommits.readNode(OUTER_LIST_2_PATH).isPresent()); - } - - @Test - public void mergeMergeFooBar1stLevelEmptyTreeTest() throws DataValidationFailedException { - final InMemoryDataTreeSnapshot initialDataTreeSnapshot = inMemoryDataTree.takeSnapshot(); - - final DataTreeModification modificationTree1 = initialDataTreeSnapshot.newModification(); - final DataTreeModification modificationTree2 = initialDataTreeSnapshot.newModification(); - - modificationTree1.merge(TestModel.TEST_PATH, createFooTestContainerNode()); - modificationTree2.merge(TestModel.TEST_PATH, createBarTestContainerNode()); - modificationTree1.ready(); - modificationTree2.ready(); - - inMemoryDataTree.validate(modificationTree1); - final DataTreeCandidate prepare1 = inMemoryDataTree.prepare(modificationTree1); - inMemoryDataTree.commit(prepare1); - - inMemoryDataTree.validate(modificationTree2); - final DataTreeCandidate prepare2 = inMemoryDataTree.prepare(modificationTree2); - inMemoryDataTree.commit(prepare2); - - final InMemoryDataTreeSnapshot snapshotAfterCommits = inMemoryDataTree.takeSnapshot(); - assertPresentAndType(snapshotAfterCommits.readNode(OUTER_LIST_1_PATH), MapEntryNode.class); - assertPresentAndType(snapshotAfterCommits.readNode(OUTER_LIST_2_PATH), MapEntryNode.class); - } - - @Test - public void writeWriteFooBar1stLevelEmptyContainerTest() throws DataValidationFailedException { - final DataTreeModification initialDataTreeModification = inMemoryDataTree.takeSnapshot().newModification(); - initialDataTreeModification.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME)); - initialDataTreeModification.ready(); - inMemoryDataTree.commit(inMemoryDataTree.prepare(initialDataTreeModification)); - final InMemoryDataTreeSnapshot initialDataTreeSnapshot = inMemoryDataTree.takeSnapshot(); - - final DataTreeModification modificationTree1 = initialDataTreeSnapshot.newModification(); - final DataTreeModification modificationTree2 = initialDataTreeSnapshot.newModification(); - - modificationTree1.write(TestModel.TEST_PATH, createFooTestContainerNode()); - modificationTree2.write(TestModel.TEST_PATH, createBarTestContainerNode()); - modificationTree1.ready(); - modificationTree2.ready(); - - inMemoryDataTree.validate(modificationTree1); - final DataTreeCandidate prepare1 = inMemoryDataTree.prepare(modificationTree1); - inMemoryDataTree.commit(prepare1); - - try { - inMemoryDataTree.validate(modificationTree2); - fail("Exception should have been thrown."); - final DataTreeCandidate prepare2 = inMemoryDataTree.prepare(modificationTree2); - inMemoryDataTree.commit(prepare2); - } catch (final ConflictingModificationAppliedException ex) { - LOG.debug("ConflictingModificationAppliedException - '{}' was thrown as expected."); - } - - final InMemoryDataTreeSnapshot snapshotAfterCommits = inMemoryDataTree.takeSnapshot(); - assertPresentAndType(snapshotAfterCommits.readNode(OUTER_LIST_1_PATH), MapEntryNode.class); - assertFalse(snapshotAfterCommits.readNode(OUTER_LIST_2_PATH).isPresent()); - } - - @Test - public void writeMergeFooBar1stLevelEmptyContainerTest() throws DataValidationFailedException { - final DataTreeModification initialDataTreeModification = inMemoryDataTree.takeSnapshot().newModification(); - initialDataTreeModification.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME)); - initialDataTreeModification.ready(); - inMemoryDataTree.commit(inMemoryDataTree.prepare(initialDataTreeModification)); - final InMemoryDataTreeSnapshot initialDataTreeSnapshot = inMemoryDataTree.takeSnapshot(); - - final DataTreeModification modificationTree1 = initialDataTreeSnapshot.newModification(); - final DataTreeModification modificationTree2 = initialDataTreeSnapshot.newModification(); - - modificationTree1.write(TestModel.TEST_PATH, createFooTestContainerNode()); - modificationTree2.merge(TestModel.TEST_PATH, createBarTestContainerNode()); - modificationTree1.ready(); - modificationTree2.ready(); - - inMemoryDataTree.validate(modificationTree1); - final DataTreeCandidate prepare1 = inMemoryDataTree.prepare(modificationTree1); - inMemoryDataTree.commit(prepare1); - - inMemoryDataTree.validate(modificationTree2); - final DataTreeCandidate prepare2 = inMemoryDataTree.prepare(modificationTree2); - inMemoryDataTree.commit(prepare2); - - final InMemoryDataTreeSnapshot snapshotAfterCommits = inMemoryDataTree.takeSnapshot(); - assertPresentAndType(snapshotAfterCommits.readNode(OUTER_LIST_1_PATH), MapEntryNode.class); - assertPresentAndType(snapshotAfterCommits.readNode(OUTER_LIST_2_PATH), MapEntryNode.class); - } - - @Test - public void mergeWriteFooBar1stLevelEmptyContainerTest() throws DataValidationFailedException { - final DataTreeModification initialDataTreeModification = inMemoryDataTree.takeSnapshot().newModification(); - initialDataTreeModification.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME)); - initialDataTreeModification.ready(); - inMemoryDataTree.commit(inMemoryDataTree.prepare(initialDataTreeModification)); - final InMemoryDataTreeSnapshot initialDataTreeSnapshot = inMemoryDataTree.takeSnapshot(); - - final DataTreeModification modificationTree1 = initialDataTreeSnapshot.newModification(); - final DataTreeModification modificationTree2 = initialDataTreeSnapshot.newModification(); - - modificationTree1.merge(TestModel.TEST_PATH, createFooTestContainerNode()); - modificationTree2.write(TestModel.TEST_PATH, createBarTestContainerNode()); - modificationTree1.ready(); - modificationTree2.ready(); - - inMemoryDataTree.validate(modificationTree1); - final DataTreeCandidate prepare1 = inMemoryDataTree.prepare(modificationTree1); - inMemoryDataTree.commit(prepare1); - - try { - inMemoryDataTree.validate(modificationTree2); - fail("Exception should have been thrown."); - final DataTreeCandidate prepare2 = inMemoryDataTree.prepare(modificationTree2); - inMemoryDataTree.commit(prepare2); - } catch (final ConflictingModificationAppliedException ex) { - LOG.debug("ConflictingModificationAppliedException - '{}' was thrown as expected."); - } - - - final InMemoryDataTreeSnapshot snapshotAfterCommits = inMemoryDataTree.takeSnapshot(); - assertPresentAndType(snapshotAfterCommits.readNode(OUTER_LIST_1_PATH), MapEntryNode.class); - assertFalse(snapshotAfterCommits.readNode(OUTER_LIST_2_PATH).isPresent()); - } - - @Test - public void mergeMergeFooBar1stLevelEmptyContainerTest() throws DataValidationFailedException { - final DataTreeModification initialDataTreeModification = inMemoryDataTree.takeSnapshot().newModification(); - initialDataTreeModification.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME)); - initialDataTreeModification.ready(); - inMemoryDataTree.commit(inMemoryDataTree.prepare(initialDataTreeModification)); - final InMemoryDataTreeSnapshot initialDataTreeSnapshot = inMemoryDataTree.takeSnapshot(); - - final DataTreeModification modificationTree1 = initialDataTreeSnapshot.newModification(); - final DataTreeModification modificationTree2 = initialDataTreeSnapshot.newModification(); - - modificationTree1.merge(TestModel.TEST_PATH, createFooTestContainerNode()); - modificationTree2.merge(TestModel.TEST_PATH, createBarTestContainerNode()); - modificationTree1.ready(); - modificationTree2.ready(); - - inMemoryDataTree.validate(modificationTree1); - final DataTreeCandidate prepare1 = inMemoryDataTree.prepare(modificationTree1); - inMemoryDataTree.commit(prepare1); - - inMemoryDataTree.validate(modificationTree2); - final DataTreeCandidate prepare2 = inMemoryDataTree.prepare(modificationTree2); - inMemoryDataTree.commit(prepare2); - - final InMemoryDataTreeSnapshot snapshotAfterCommits = inMemoryDataTree.takeSnapshot(); - assertPresentAndType(snapshotAfterCommits.readNode(OUTER_LIST_1_PATH), MapEntryNode.class); - assertPresentAndType(snapshotAfterCommits.readNode(OUTER_LIST_2_PATH), MapEntryNode.class); - } - - @Test - public void deleteWriteFooBar1stLevelEmptyContainerTest() throws DataValidationFailedException { - final DataTreeModification initialDataTreeModification = inMemoryDataTree.takeSnapshot().newModification(); - initialDataTreeModification.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME)); - initialDataTreeModification.ready(); - inMemoryDataTree.commit(inMemoryDataTree.prepare(initialDataTreeModification)); - final InMemoryDataTreeSnapshot initialDataTreeSnapshot = inMemoryDataTree.takeSnapshot(); - - final DataTreeModification modificationTree1 = initialDataTreeSnapshot.newModification(); - final DataTreeModification modificationTree2 = initialDataTreeSnapshot.newModification(); - - modificationTree1.delete(TestModel.TEST_PATH); - modificationTree2.write(TestModel.TEST_PATH, createBarTestContainerNode()); - modificationTree1.ready(); - modificationTree2.ready(); - - inMemoryDataTree.validate(modificationTree1); - final DataTreeCandidate prepare1 = inMemoryDataTree.prepare(modificationTree1); - inMemoryDataTree.commit(prepare1); - - try { - inMemoryDataTree.validate(modificationTree2); - fail("Exception should have been thrown."); - final DataTreeCandidate prepare2 = inMemoryDataTree.prepare(modificationTree2); - inMemoryDataTree.commit(prepare2); - } catch (final ConflictingModificationAppliedException ex) { - LOG.debug("ConflictingModificationAppliedException - '{}' was thrown as expected."); - } - - - final InMemoryDataTreeSnapshot snapshotAfterCommits = inMemoryDataTree.takeSnapshot(); - assertFalse(snapshotAfterCommits.readNode(TestModel.TEST_PATH).isPresent()); - } - - @Test - public void deleteMergeFooBar1stLevelEmptyContainerTest() throws DataValidationFailedException { - final DataTreeModification initialDataTreeModification = inMemoryDataTree.takeSnapshot().newModification(); - initialDataTreeModification.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME)); - initialDataTreeModification.ready(); - inMemoryDataTree.commit(inMemoryDataTree.prepare(initialDataTreeModification)); - final InMemoryDataTreeSnapshot initialDataTreeSnapshot = inMemoryDataTree.takeSnapshot(); - - final DataTreeModification modificationTree1 = initialDataTreeSnapshot.newModification(); - final DataTreeModification modificationTree2 = initialDataTreeSnapshot.newModification(); - - modificationTree1.delete(TestModel.TEST_PATH); - modificationTree2.merge(TestModel.TEST_PATH, createBarTestContainerNode()); - modificationTree1.ready(); - modificationTree2.ready(); - - inMemoryDataTree.validate(modificationTree1); - final DataTreeCandidate prepare1 = inMemoryDataTree.prepare(modificationTree1); - inMemoryDataTree.commit(prepare1); - - inMemoryDataTree.validate(modificationTree2); - final DataTreeCandidate prepare2 = inMemoryDataTree.prepare(modificationTree2); - inMemoryDataTree.commit(prepare2); - - final InMemoryDataTreeSnapshot snapshotAfterCommits = inMemoryDataTree.takeSnapshot(); - assertPresentAndType(snapshotAfterCommits.readNode(OUTER_LIST_2_PATH), MapEntryNode.class); - } - - @Test - public void writeWriteFooBar2ndLevelEmptyContainerTest() throws DataValidationFailedException { - final DataTreeModification initialDataTreeModification = inMemoryDataTree.takeSnapshot().newModification(); - initialDataTreeModification.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME)); - initialDataTreeModification.write(TestModel.OUTER_LIST_PATH, mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build()); - initialDataTreeModification.ready(); - inMemoryDataTree.commit(inMemoryDataTree.prepare(initialDataTreeModification)); - final InMemoryDataTreeSnapshot initialDataTreeSnapshot = inMemoryDataTree.takeSnapshot(); - - final DataTreeModification modificationTree1 = initialDataTreeSnapshot.newModification(); - final DataTreeModification modificationTree2 = initialDataTreeSnapshot.newModification(); - - modificationTree1.write(OUTER_LIST_1_PATH, FOO_NODE); - modificationTree2.write(OUTER_LIST_2_PATH, BAR_NODE); - modificationTree1.ready(); - modificationTree2.ready(); - - inMemoryDataTree.validate(modificationTree1); - final DataTreeCandidate prepare1 = inMemoryDataTree.prepare(modificationTree1); - inMemoryDataTree.commit(prepare1); - - inMemoryDataTree.validate(modificationTree2); - final DataTreeCandidate prepare2 = inMemoryDataTree.prepare(modificationTree2); - inMemoryDataTree.commit(prepare2); - - final InMemoryDataTreeSnapshot snapshotAfterCommits = inMemoryDataTree.takeSnapshot(); - assertPresentAndType(snapshotAfterCommits.readNode(OUTER_LIST_1_PATH), MapEntryNode.class); - assertPresentAndType(snapshotAfterCommits.readNode(OUTER_LIST_2_PATH), MapEntryNode.class); - } - - @Test - public void writeMergeFooBar2ndLevelEmptyContainerTest() throws DataValidationFailedException { - final DataTreeModification initialDataTreeModification = inMemoryDataTree.takeSnapshot().newModification(); - initialDataTreeModification.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME)); - initialDataTreeModification.write(TestModel.OUTER_LIST_PATH, mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build()); - initialDataTreeModification.ready(); - inMemoryDataTree.commit(inMemoryDataTree.prepare(initialDataTreeModification)); - final InMemoryDataTreeSnapshot initialDataTreeSnapshot = inMemoryDataTree.takeSnapshot(); - - final DataTreeModification modificationTree1 = initialDataTreeSnapshot.newModification(); - final DataTreeModification modificationTree2 = initialDataTreeSnapshot.newModification(); - - modificationTree1.write(OUTER_LIST_1_PATH, FOO_NODE); - modificationTree2.merge(OUTER_LIST_2_PATH, BAR_NODE); - modificationTree1.ready(); - modificationTree2.ready(); - - inMemoryDataTree.validate(modificationTree1); - final DataTreeCandidate prepare1 = inMemoryDataTree.prepare(modificationTree1); - inMemoryDataTree.commit(prepare1); - - inMemoryDataTree.validate(modificationTree2); - final DataTreeCandidate prepare2 = inMemoryDataTree.prepare(modificationTree2); - inMemoryDataTree.commit(prepare2); - - final InMemoryDataTreeSnapshot snapshotAfterCommits = inMemoryDataTree.takeSnapshot(); - assertPresentAndType(snapshotAfterCommits.readNode(OUTER_LIST_1_PATH), MapEntryNode.class); - assertPresentAndType(snapshotAfterCommits.readNode(OUTER_LIST_2_PATH), MapEntryNode.class); - } - - @Test - public void mergeWriteFooBar2ndLevelEmptyContainerTest() throws DataValidationFailedException { - final DataTreeModification initialDataTreeModification = inMemoryDataTree.takeSnapshot().newModification(); - initialDataTreeModification.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME)); - initialDataTreeModification.write(TestModel.OUTER_LIST_PATH, mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build()); - initialDataTreeModification.ready(); - inMemoryDataTree.commit(inMemoryDataTree.prepare(initialDataTreeModification)); - final InMemoryDataTreeSnapshot initialDataTreeSnapshot = inMemoryDataTree.takeSnapshot(); - - final DataTreeModification modificationTree1 = initialDataTreeSnapshot.newModification(); - final DataTreeModification modificationTree2 = initialDataTreeSnapshot.newModification(); - - modificationTree1.merge(OUTER_LIST_1_PATH, FOO_NODE); - modificationTree2.write(OUTER_LIST_2_PATH, BAR_NODE); - modificationTree1.ready(); - modificationTree2.ready(); - - inMemoryDataTree.validate(modificationTree1); - final DataTreeCandidate prepare1 = inMemoryDataTree.prepare(modificationTree1); - inMemoryDataTree.commit(prepare1); - - inMemoryDataTree.validate(modificationTree2); - final DataTreeCandidate prepare2 = inMemoryDataTree.prepare(modificationTree2); - inMemoryDataTree.commit(prepare2); - - final InMemoryDataTreeSnapshot snapshotAfterCommits = inMemoryDataTree.takeSnapshot(); - assertPresentAndType(snapshotAfterCommits.readNode(OUTER_LIST_1_PATH), MapEntryNode.class); - assertPresentAndType(snapshotAfterCommits.readNode(OUTER_LIST_2_PATH), MapEntryNode.class); - } - - @Test - public void mergeMergeFooBar2ndLevelEmptyContainerTest() throws DataValidationFailedException { - final DataTreeModification initialDataTreeModification = inMemoryDataTree.takeSnapshot().newModification(); - initialDataTreeModification.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME)); - initialDataTreeModification.write(TestModel.OUTER_LIST_PATH, mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build()); - initialDataTreeModification.ready(); - inMemoryDataTree.commit(inMemoryDataTree.prepare(initialDataTreeModification)); - final InMemoryDataTreeSnapshot initialDataTreeSnapshot = inMemoryDataTree.takeSnapshot(); - - final DataTreeModification modificationTree1 = initialDataTreeSnapshot.newModification(); - final DataTreeModification modificationTree2 = initialDataTreeSnapshot.newModification(); - - modificationTree1.merge(OUTER_LIST_1_PATH, FOO_NODE); - modificationTree2.merge(OUTER_LIST_2_PATH, BAR_NODE); - modificationTree1.ready(); - modificationTree2.ready(); - - inMemoryDataTree.validate(modificationTree1); - final DataTreeCandidate prepare1 = inMemoryDataTree.prepare(modificationTree1); - inMemoryDataTree.commit(prepare1); - - inMemoryDataTree.validate(modificationTree2); - final DataTreeCandidate prepare2 = inMemoryDataTree.prepare(modificationTree2); - inMemoryDataTree.commit(prepare2); - - final InMemoryDataTreeSnapshot snapshotAfterCommits = inMemoryDataTree.takeSnapshot(); - assertPresentAndType(snapshotAfterCommits.readNode(OUTER_LIST_1_PATH), MapEntryNode.class); - assertPresentAndType(snapshotAfterCommits.readNode(OUTER_LIST_2_PATH), MapEntryNode.class); - } - - @Test - public void deleteWriteFooBar2ndLevelEmptyContainerTest() throws DataValidationFailedException { - final DataTreeModification initialDataTreeModification = inMemoryDataTree.takeSnapshot().newModification(); - initialDataTreeModification.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME)); - initialDataTreeModification.write(TestModel.OUTER_LIST_PATH, mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build()); - initialDataTreeModification.ready(); - inMemoryDataTree.commit(inMemoryDataTree.prepare(initialDataTreeModification)); - final InMemoryDataTreeSnapshot initialDataTreeSnapshot = inMemoryDataTree.takeSnapshot(); - - final DataTreeModification modificationTree1 = initialDataTreeSnapshot.newModification(); - final DataTreeModification modificationTree2 = initialDataTreeSnapshot.newModification(); - - modificationTree1.delete(TestModel.TEST_PATH); - modificationTree2.merge(OUTER_LIST_2_PATH, BAR_NODE); - modificationTree1.ready(); - modificationTree2.ready(); - - inMemoryDataTree.validate(modificationTree1); - final DataTreeCandidate prepare1 = inMemoryDataTree.prepare(modificationTree1); - inMemoryDataTree.commit(prepare1); - - try { - inMemoryDataTree.validate(modificationTree2); - final DataTreeCandidate prepare2 = inMemoryDataTree.prepare(modificationTree2); - inMemoryDataTree.commit(prepare2); - fail("Exception should have been thrown"); - } catch (final Exception e) { - LOG.debug("Exception was thrown because path no longer exist in tree"); - } - - final InMemoryDataTreeSnapshot snapshotAfterCommits = inMemoryDataTree.takeSnapshot(); - assertFalse(snapshotAfterCommits.readNode(TestModel.TEST_PATH).isPresent()); - } - - @Test - public void deleteMergeFooBar2ndLevelEmptyContainerTest() throws DataValidationFailedException { - final DataTreeModification initialDataTreeModification = inMemoryDataTree.takeSnapshot().newModification(); - initialDataTreeModification.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME)); - initialDataTreeModification.write(TestModel.OUTER_LIST_PATH, mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build()); - initialDataTreeModification.ready(); - inMemoryDataTree.commit(inMemoryDataTree.prepare(initialDataTreeModification)); - final InMemoryDataTreeSnapshot initialDataTreeSnapshot = inMemoryDataTree.takeSnapshot(); - - final DataTreeModification modificationTree1 = initialDataTreeSnapshot.newModification(); - final DataTreeModification modificationTree2 = initialDataTreeSnapshot.newModification(); - - modificationTree1.delete(TestModel.TEST_PATH); - modificationTree2.merge(OUTER_LIST_2_PATH, BAR_NODE); - modificationTree1.ready(); - modificationTree2.ready(); - - inMemoryDataTree.validate(modificationTree1); - final DataTreeCandidate prepare1 = inMemoryDataTree.prepare(modificationTree1); - inMemoryDataTree.commit(prepare1); - - try { - inMemoryDataTree.validate(modificationTree2); - final DataTreeCandidate prepare2 = inMemoryDataTree.prepare(modificationTree2); - inMemoryDataTree.commit(prepare2); - fail("Exception should have been thrown"); - } catch (final Exception e) { - LOG.debug("Exception was thrown because path no longer exist in tree"); - } - - final InMemoryDataTreeSnapshot snapshotAfterCommits = inMemoryDataTree.takeSnapshot(); - assertFalse(snapshotAfterCommits.readNode(TestModel.TEST_PATH).isPresent()); - } -} diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/Retest_ConfigStatementValidationTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/Retest_ConfigStatementValidationTest.java deleted file mode 100644 index 383857ceb7..0000000000 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/Retest_ConfigStatementValidationTest.java +++ /dev/null @@ -1,168 +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.data.impl.schema.tree; - -import static org.junit.Assert.assertNotNull; -import static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.leafNode; -import static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.mapEntryBuilder; -import static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.mapNodeBuilder; - -import com.google.common.base.VerifyException; -import org.junit.Before; -import org.junit.Test; -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; -import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode; -import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode; -import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode; -import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate; -import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException; -import org.opendaylight.yangtools.yang.data.api.schema.tree.TreeType; -import org.opendaylight.yangtools.yang.data.impl.schema.Builders; -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.parser.spi.meta.ReactorException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -// TODO: expand these tests to catch some more obscure cases -public class Retest_ConfigStatementValidationTest { - private static final Logger LOG = LoggerFactory.getLogger(Retest_ConfigStatementValidationTest.class); - - private static final Short ONE_ID = 1; - private static final Short TWO_ID = 2; - - private static final YangInstanceIdentifier OUTER_LIST_1_PATH = YangInstanceIdentifier - .builder(TestModel.OUTER_LIST_PATH).nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, ONE_ID) // - .build(); - - private static final YangInstanceIdentifier OUTER_LIST_2_PATH = YangInstanceIdentifier - .builder(TestModel.OUTER_LIST_PATH).nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, TWO_ID) // - .build(); - - private static final MapEntryNode INNER_FOO_ENTRY_NODE = ImmutableNodes.mapEntry(TestModel.INNER_LIST_QNAME, - TestModel.NAME_QNAME, "foo"); - - private static final MapEntryNode INNER_BAR_ENTRY_NODE = ImmutableNodes - .mapEntryBuilder(QName.create(TestModel.TEST_QNAME, "inner-list2"), TestModel.NAME_QNAME, "foo") - .withChild(ImmutableNodes.leafNode(TestModel.VALUE_QNAME, "value")).build(); - - private static final MapEntryNode FOO_NODE = mapEntryBuilder(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, ONE_ID) // - .withChild(mapNodeBuilder(TestModel.INNER_LIST_QNAME).withChild(INNER_FOO_ENTRY_NODE) // - .build()) // - .build(); - - private static final MapEntryNode BAR_NODE = mapEntryBuilder(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, TWO_ID) // - .withChild(mapNodeBuilder(TestModel.INNER_LIST_QNAME).withChild(INNER_BAR_ENTRY_NODE) // - .build()) // - .build(); - - private SchemaContext schemaContext; - - private static ContainerNode createFooTestContainerNode() { - return ImmutableContainerNodeBuilder.create() - .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME)) - .withChild(mapNodeBuilder(TestModel.OUTER_LIST_QNAME).withChild(FOO_NODE).build()).build(); - } - - private static ContainerNode createBarTestContainerNode() { - return ImmutableContainerNodeBuilder.create() - .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME)) - .withChild(mapNodeBuilder(TestModel.OUTER_LIST_QNAME).withChild(BAR_NODE).build()).build(); - } - - @Before - public void prepare() throws ReactorException { - schemaContext = RetestModel.createTestContext(); - assertNotNull("Schema context must not be null.", schemaContext); - } - - @Test(expected = SchemaValidationFailedException.class) - public void testOnPathFail() throws DataValidationFailedException { - final InMemoryDataTree inMemoryDataTree = (InMemoryDataTree) InMemoryDataTreeFactory.getInstance().create( - TreeType.CONFIGURATION); - inMemoryDataTree.setSchemaContext(schemaContext); - final InMemoryDataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification(); - final YangInstanceIdentifier ii = OUTER_LIST_1_PATH.node( - new YangInstanceIdentifier.NodeIdentifier(TestModel.INNER_LIST_QNAME)).node( - INNER_FOO_ENTRY_NODE.getIdentifier()); - modificationTree.write(ii, INNER_FOO_ENTRY_NODE); - - inMemoryDataTree.validate(modificationTree); - final DataTreeCandidate prepare = inMemoryDataTree.prepare(modificationTree); - inMemoryDataTree.commit(prepare); - } - - @Test(expected = SchemaValidationFailedException.class) - public void testOnDataFail() throws DataValidationFailedException { - final InMemoryDataTree inMemoryDataTree = (InMemoryDataTree) InMemoryDataTreeFactory.getInstance().create( - TreeType.CONFIGURATION); - inMemoryDataTree.setSchemaContext(schemaContext); - final InMemoryDataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification(); - modificationTree.write(TestModel.TEST_PATH, createFooTestContainerNode()); - modificationTree.ready(); - inMemoryDataTree.validate(modificationTree); - final DataTreeCandidate prepare = inMemoryDataTree.prepare(modificationTree); - inMemoryDataTree.commit(prepare); - } - - @Test(expected = SchemaValidationFailedException.class) - public void testOnDataLeafFail() throws DataValidationFailedException { - final InMemoryDataTree inMemoryDataTree = (InMemoryDataTree) InMemoryDataTreeFactory.getInstance().create( - TreeType.CONFIGURATION); - inMemoryDataTree.setSchemaContext(schemaContext); - final InMemoryDataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification(); - modificationTree.write(TestModel.TEST_PATH, createBarTestContainerNode()); - modificationTree.ready(); - inMemoryDataTree.validate(modificationTree); - final DataTreeCandidate prepare = inMemoryDataTree.prepare(modificationTree); - inMemoryDataTree.commit(prepare); - } - - @Test(expected = SchemaValidationFailedException.class) - public void testOnPathCaseLeafFail() throws DataValidationFailedException { - final InMemoryDataTree inMemoryDataTree = (InMemoryDataTree) InMemoryDataTreeFactory.getInstance().create( - TreeType.CONFIGURATION); - inMemoryDataTree.setSchemaContext(schemaContext); - final YangInstanceIdentifier.NodeIdentifier choice1Id = new YangInstanceIdentifier.NodeIdentifier(QName.create( - TestModel.TEST_QNAME, "choice1")); - final YangInstanceIdentifier.NodeIdentifier case2ContId = new YangInstanceIdentifier.NodeIdentifier( - QName.create(TestModel.TEST_QNAME, "case2-cont")); - final YangInstanceIdentifier ii = TestModel.TEST_PATH.node(choice1Id).node(case2ContId); - final ContainerNode case2Cont = Builders.containerBuilder().withNodeIdentifier(case2ContId) - .withChild(leafNode(QName.create(TestModel.TEST_QNAME, "case2-leaf1"), "leaf-value")).build(); - - final InMemoryDataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification(); - modificationTree.write(ii, case2Cont); - modificationTree.ready(); - inMemoryDataTree.validate(modificationTree); - final DataTreeCandidate prepare = inMemoryDataTree.prepare(modificationTree); - inMemoryDataTree.commit(prepare); - } - - @Test(expected = VerifyException.class) - public void testOnDataCaseLeafFail() throws DataValidationFailedException { - final InMemoryDataTree inMemoryDataTree = (InMemoryDataTree) InMemoryDataTreeFactory.getInstance().create( - TreeType.CONFIGURATION); - inMemoryDataTree.setSchemaContext(schemaContext); - final YangInstanceIdentifier.NodeIdentifier choice1Id = new YangInstanceIdentifier.NodeIdentifier(QName.create( - TestModel.TEST_QNAME, "choice1")); - final YangInstanceIdentifier ii = TestModel.TEST_PATH.node(choice1Id); - final ChoiceNode choice1 = Builders.choiceBuilder().withNodeIdentifier(choice1Id) - .withChild(leafNode(QName.create(TestModel.TEST_QNAME, "case1-leaf1"), "leaf-value")).build(); - - final InMemoryDataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification(); - modificationTree.write(ii, choice1); - modificationTree.ready(); - inMemoryDataTree.validate(modificationTree); - final DataTreeCandidate prepare = inMemoryDataTree.prepare(modificationTree); - inMemoryDataTree.commit(prepare); - } -} diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/Retest_ErrorReportingTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/Retest_ErrorReportingTest.java deleted file mode 100644 index da041175dc..0000000000 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/Retest_ErrorReportingTest.java +++ /dev/null @@ -1,75 +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.data.impl.schema.tree; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; -import org.junit.Before; -import org.junit.Test; -import org.opendaylight.yangtools.yang.data.api.schema.tree.ConflictingModificationAppliedException; -import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException; -import org.opendaylight.yangtools.yang.data.api.schema.tree.ModifiedNodeDoesNotExistException; -import org.opendaylight.yangtools.yang.data.api.schema.tree.TreeType; -import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes; -import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; - -public class Retest_ErrorReportingTest { - - private InMemoryDataTree tree; - - @Before - public void setup() throws ReactorException { - tree = (InMemoryDataTree) InMemoryDataTreeFactory.getInstance().create(TreeType.OPERATIONAL); - tree.setSchemaContext(RetestModel.createTestContext()); - } - - @Test - public void writeWithoutParentExisting() { - InMemoryDataTreeModification modification = tree.takeSnapshot().newModification(); - // We write node without creating parent - modification.write(TestModel.OUTER_LIST_PATH, ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build()); - modification.ready(); - try { - tree.validate(modification); - fail("ModifiedNodeDoesNotExistException should be raised"); - } catch (ModifiedNodeDoesNotExistException e) { - assertEquals(TestModel.TEST_PATH, e.getPath()); - } catch (DataValidationFailedException e) { - fail("ModifiedNodeDoesNotExistException expected"); - } - } - - @Test - public void parentConcurrentlyDeletedExisting() { - InMemoryDataTreeModification initial = tree.takeSnapshot().newModification(); - // We write node without creating parent - initial.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME)); - initial.ready(); - // We commit transaction - tree.commit(tree.prepare(initial)); - - InMemoryDataTreeModification writeTx = tree.takeSnapshot().newModification(); - InMemoryDataTreeModification deleteTx = tree.takeSnapshot().newModification(); - deleteTx.delete(TestModel.TEST_PATH); - deleteTx.ready(); - // We commit delete modification - tree.commit(tree.prepare(deleteTx)); - - writeTx.write(TestModel.OUTER_LIST_PATH, ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build()); - writeTx.ready(); - try { - tree.validate(writeTx); - fail("ConflictingModificationAppliedException should be raised"); - } catch (ConflictingModificationAppliedException e) { - assertEquals(TestModel.TEST_PATH, e.getPath()); - } catch (DataValidationFailedException e) { - fail("ConflictingModificationAppliedException expected"); - } - - } -} diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/Retest_ModificationMetadataTreeTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/Retest_ModificationMetadataTreeTest.java deleted file mode 100644 index 7fb92d11d3..0000000000 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/Retest_ModificationMetadataTreeTest.java +++ /dev/null @@ -1,250 +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.data.impl.schema.tree; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; -import static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.mapEntry; -import static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.mapEntryBuilder; -import static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.mapNodeBuilder; -import com.google.common.base.Optional; -import org.junit.Before; -import org.junit.Test; -import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; -import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier; -import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode; -import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode; -import org.opendaylight.yangtools.yang.data.api.schema.MapNode; -import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; -import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree; -import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification; -import org.opendaylight.yangtools.yang.data.api.schema.tree.TreeType; -import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.TreeNodeFactory; -import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.Version; -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.parser.spi.meta.ReactorException; - -/** - * - * Schema structure of document is - * - *
- * container root { 
- *      list list-a {
- *              key leaf-a;
- *              leaf leaf-a;
- *              choice choice-a {
- *                      case one {
- *                              leaf one;
- *                      }
- *                      case two-three {
- *                              leaf two;
- *                              leaf three;
- *                      }
- *              }
- *              list list-b {
- *                      key leaf-b;
- *                      leaf leaf-b;
- *              }
- *      }
- * }
- * 
- * - */ -public class Retest_ModificationMetadataTreeTest { - - private static final Short ONE_ID = 1; - private static final Short TWO_ID = 2; - private static final String TWO_ONE_NAME = "one"; - private static final String TWO_TWO_NAME = "two"; - - private static final YangInstanceIdentifier OUTER_LIST_1_PATH = YangInstanceIdentifier.builder(TestModel.OUTER_LIST_PATH) - .nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, ONE_ID) // - .build(); - - private static final YangInstanceIdentifier OUTER_LIST_2_PATH = YangInstanceIdentifier.builder(TestModel.OUTER_LIST_PATH) - .nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, TWO_ID) // - .build(); - - private static final YangInstanceIdentifier TWO_TWO_PATH = YangInstanceIdentifier.builder(OUTER_LIST_2_PATH) - .node(TestModel.INNER_LIST_QNAME) // - .nodeWithKey(TestModel.INNER_LIST_QNAME, TestModel.NAME_QNAME, TWO_TWO_NAME) // - .build(); - - private static final YangInstanceIdentifier TWO_TWO_VALUE_PATH = YangInstanceIdentifier.builder(TWO_TWO_PATH) - .node(TestModel.VALUE_QNAME) // - .build(); - - private static final MapEntryNode BAR_NODE = mapEntryBuilder(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, TWO_ID) // - .withChild(mapNodeBuilder(TestModel.INNER_LIST_QNAME) // - .withChild(mapEntry(TestModel.INNER_LIST_QNAME, TestModel.NAME_QNAME, TWO_ONE_NAME)) // - .withChild(mapEntry(TestModel.INNER_LIST_QNAME,TestModel.NAME_QNAME, TWO_TWO_NAME)) // - .build()) // - .build(); - - private SchemaContext schemaContext; - private RootModificationApplyOperation rootOper; - - @Before - public void prepare() throws ReactorException { - schemaContext = RetestModel.createTestContext(); - assertNotNull("Schema context must not be null.", schemaContext); - rootOper = RootModificationApplyOperation.from(SchemaAwareApplyOperation.from(schemaContext, TreeType.OPERATIONAL)); - } - - /** - * Returns a test document - * - *
-     * test
-     *     outer-list
-     *          id 1
-     *     outer-list
-     *          id 2
-     *          inner-list
-     *                  name "one"
-     *          inner-list
-     *                  name "two"
-     *
-     * 
- * - * @return - */ - public NormalizedNode createDocumentOne() { - return ImmutableContainerNodeBuilder - .create() - .withNodeIdentifier(new NodeIdentifier(schemaContext.getQName())) - .withChild(createTestContainer()).build(); - - } - - private static ContainerNode createTestContainer() { - return ImmutableContainerNodeBuilder - .create() - .withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME)) - .withChild( - mapNodeBuilder(TestModel.OUTER_LIST_QNAME) - .withChild(mapEntry(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, ONE_ID)) - .withChild(BAR_NODE).build()).build(); - } - - @Test - public void basicReadWrites() { - final DataTreeModification modificationTree = new InMemoryDataTreeModification(new InMemoryDataTreeSnapshot(schemaContext, - TreeNodeFactory.createTreeNodeRecursively(createDocumentOne(), Version.initial()), rootOper), - rootOper); - final Optional> originalBarNode = modificationTree.readNode(OUTER_LIST_2_PATH); - assertTrue(originalBarNode.isPresent()); - assertSame(BAR_NODE, originalBarNode.get()); - - // writes node to /outer-list/1/inner_list/two/value - modificationTree.write(TWO_TWO_VALUE_PATH, ImmutableNodes.leafNode(TestModel.VALUE_QNAME, "test")); - - // reads node to /outer-list/1/inner_list/two/value - // and checks if node is already present - final Optional> barTwoCModified = modificationTree.readNode(TWO_TWO_VALUE_PATH); - assertTrue(barTwoCModified.isPresent()); - assertEquals(ImmutableNodes.leafNode(TestModel.VALUE_QNAME, "test"), barTwoCModified.get()); - - // delete node to /outer-list/1/inner_list/two/value - modificationTree.delete(TWO_TWO_VALUE_PATH); - final Optional> barTwoCAfterDelete = modificationTree.readNode(TWO_TWO_VALUE_PATH); - assertFalse(barTwoCAfterDelete.isPresent()); - } - - - public DataTreeModification createEmptyModificationTree() { - /** - * Creates empty Snapshot with associated schema context. - */ - final DataTree t = InMemoryDataTreeFactory.getInstance().create(TreeType.OPERATIONAL); - t.setSchemaContext(schemaContext); - - /** - * - * Creates Mutable Data Tree based on provided snapshot and schema - * context. - * - */ - return t.takeSnapshot().newModification(); - } - - @Test - public void createFromEmptyState() { - - final DataTreeModification modificationTree = createEmptyModificationTree(); - /** - * Writes empty container node to /test - * - */ - modificationTree.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME)); - - /** - * Writes empty list node to /test/outer-list - */ - modificationTree.write(TestModel.OUTER_LIST_PATH, ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build()); - - /** - * Reads list node from /test/outer-list - */ - final Optional> potentialOuterList = modificationTree.readNode(TestModel.OUTER_LIST_PATH); - assertTrue(potentialOuterList.isPresent()); - - /** - * Reads container node from /test and verifies that it contains test - * node - */ - final Optional> potentialTest = modificationTree.readNode(TestModel.TEST_PATH); - final ContainerNode containerTest = assertPresentAndType(potentialTest, ContainerNode.class); - - /** - * - * Gets list from returned snapshot of /test and verifies it contains - * outer-list - * - */ - assertPresentAndType(containerTest.getChild(new NodeIdentifier(TestModel.OUTER_LIST_QNAME)), MapNode.class); - - } - - @Test - public void writeSubtreeReadChildren() { - final DataTreeModification modificationTree = createEmptyModificationTree(); - modificationTree.write(TestModel.TEST_PATH, createTestContainer()); - final Optional> potential = modificationTree.readNode(TWO_TWO_PATH); - assertPresentAndType(potential, MapEntryNode.class); - } - - @Test - public void writeSubtreeDeleteChildren() { - final DataTreeModification modificationTree = createEmptyModificationTree(); - modificationTree.write(TestModel.TEST_PATH, createTestContainer()); - - // We verify data are present - final Optional> potentialBeforeDelete = modificationTree.readNode(TWO_TWO_PATH); - assertPresentAndType(potentialBeforeDelete, MapEntryNode.class); - - modificationTree.delete(TWO_TWO_PATH); - final Optional> potentialAfterDelete = modificationTree.readNode(TWO_TWO_PATH); - assertFalse(potentialAfterDelete.isPresent()); - - } - - private static T assertPresentAndType(final Optional potential, final Class type) { - assertNotNull(potential); - assertTrue(potential.isPresent()); - assertTrue(type.isInstance(potential.get())); - return type.cast(potential.get()); - } - -} diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/Retest_StoreTreeNodesTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/Retest_StoreTreeNodesTest.java deleted file mode 100644 index baef1acc5e..0000000000 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/Retest_StoreTreeNodesTest.java +++ /dev/null @@ -1,202 +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.data.impl.schema.tree; - -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.junit.Assert.fail; -import static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.mapEntry; -import static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.mapEntryBuilder; -import static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.mapNodeBuilder; - -import com.google.common.base.Optional; - -import java.util.Map; - -import org.junit.Before; -import org.junit.Test; -import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; -import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode; -import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode; -import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; -import org.opendaylight.yangtools.yang.data.api.schema.tree.StoreTreeNodes; -import org.opendaylight.yangtools.yang.data.api.schema.tree.TreeType; -import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.TreeNode; -import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.TreeNodeFactory; -import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.Version; -import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class Retest_StoreTreeNodesTest { - private static final Logger LOG = LoggerFactory.getLogger(Retest_StoreTreeNodesTest.class); - - private static final Short ONE_ID = 1; - private static final Short TWO_ID = 2; - private static final String TWO_ONE_NAME = "one"; - private static final String TWO_TWO_NAME = "two"; - - private static final YangInstanceIdentifier OUTER_LIST_1_PATH = YangInstanceIdentifier.builder(TestModel.OUTER_LIST_PATH) - .nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, ONE_ID) // - .build(); - - private static final YangInstanceIdentifier OUTER_LIST_2_PATH = YangInstanceIdentifier.builder(TestModel.OUTER_LIST_PATH) - .nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, TWO_ID) // - .build(); - - private static final YangInstanceIdentifier TWO_TWO_PATH = YangInstanceIdentifier.builder(OUTER_LIST_2_PATH) - .node(TestModel.INNER_LIST_QNAME) // - .nodeWithKey(TestModel.INNER_LIST_QNAME, TestModel.NAME_QNAME, TWO_TWO_NAME) // - .build(); - - private static final MapEntryNode BAR_NODE = mapEntryBuilder(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, TWO_ID) // - .withChild(mapNodeBuilder(TestModel.INNER_LIST_QNAME) // - .withChild(mapEntry(TestModel.INNER_LIST_QNAME, TestModel.NAME_QNAME, TWO_ONE_NAME)) // - .withChild(mapEntry(TestModel.INNER_LIST_QNAME, TestModel.NAME_QNAME, TWO_TWO_NAME)) // - .build()) // - .build(); - - private SchemaContext schemaContext; - private RootModificationApplyOperation rootOper; - - @Before - public void prepare() throws ReactorException { - schemaContext = RetestModel.createTestContext(); - assertNotNull("Schema context must not be null.", schemaContext); - rootOper = RootModificationApplyOperation.from(SchemaAwareApplyOperation.from(schemaContext, TreeType.OPERATIONAL)); - } - - public NormalizedNode createDocumentOne() { - return ImmutableContainerNodeBuilder - .create() - .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(schemaContext.getQName())) - .withChild(createTestContainer()).build(); - - } - - private static ContainerNode createTestContainer() { - return ImmutableContainerNodeBuilder - .create() - .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME)) - .withChild( - mapNodeBuilder(TestModel.OUTER_LIST_QNAME) - .withChild(mapEntry(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, ONE_ID)) - .withChild(BAR_NODE).build()).build(); - } - - private static T assertPresentAndType(final Optional potential, final Class type) { - assertNotNull(potential); - assertTrue(potential.isPresent()); - assertTrue(type.isInstance(potential.get())); - return type.cast(potential.get()); - } - - @Test - public void findNodeTestNodeFound() { - final InMemoryDataTreeSnapshot inMemoryDataTreeSnapshot = new InMemoryDataTreeSnapshot(schemaContext, - TreeNodeFactory.createTreeNodeRecursively(createDocumentOne(), Version.initial()), rootOper); - final TreeNode rootNode = inMemoryDataTreeSnapshot.getRootNode(); - final Optional node = StoreTreeNodes.findNode(rootNode, OUTER_LIST_1_PATH); - assertPresentAndType(node, TreeNode.class); - } - - @Test - public void findNodeTestNodeNotFound() { - final InMemoryDataTreeSnapshot inMemoryDataTreeSnapshot = new InMemoryDataTreeSnapshot(schemaContext, - TreeNodeFactory.createTreeNodeRecursively(createDocumentOne(), Version.initial()), rootOper); - final TreeNode rootNode = inMemoryDataTreeSnapshot.getRootNode(); - final YangInstanceIdentifier outerList1InvalidPath = YangInstanceIdentifier.builder(TestModel.OUTER_LIST_PATH) - .nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 3) // - .build(); - final Optional node = StoreTreeNodes.findNode(rootNode, outerList1InvalidPath); - assertFalse(node.isPresent()); - } - - @Test - public void findNodeCheckedTestNodeFound() { - final InMemoryDataTreeSnapshot inMemoryDataTreeSnapshot = new InMemoryDataTreeSnapshot(schemaContext, - TreeNodeFactory.createTreeNodeRecursively(createDocumentOne(), Version.initial()), rootOper); - final TreeNode rootNode = inMemoryDataTreeSnapshot.getRootNode(); - TreeNode foundNode = null; - try { - foundNode = StoreTreeNodes.findNodeChecked(rootNode, OUTER_LIST_1_PATH); - } catch (final IllegalArgumentException e) { - fail("Illegal argument exception was thrown and should not have been" + e.getMessage()); - } - assertNotNull(foundNode); - } - - @Test - public void findNodeCheckedTestNodeNotFound() { - final InMemoryDataTreeSnapshot inMemoryDataTreeSnapshot = new InMemoryDataTreeSnapshot(schemaContext, - TreeNodeFactory.createTreeNodeRecursively(createDocumentOne(), Version.initial()), rootOper); - final TreeNode rootNode = inMemoryDataTreeSnapshot.getRootNode(); - final YangInstanceIdentifier outerList1InvalidPath = YangInstanceIdentifier.builder(TestModel.OUTER_LIST_PATH) - .nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 3) // - .build(); - try { - StoreTreeNodes.findNodeChecked(rootNode, outerList1InvalidPath); - fail("Illegal argument exception should have been thrown"); - } catch (final IllegalArgumentException e) { - LOG.debug("Illegal argument exception was thrown as expected: '{}' - '{}'", e.getClass(), e.getMessage()); - } - } - - @Test - public void findClosestOrFirstMatchTestNodeExists() { - final InMemoryDataTreeSnapshot inMemoryDataTreeSnapshot = new InMemoryDataTreeSnapshot(schemaContext, - TreeNodeFactory.createTreeNodeRecursively(createDocumentOne(), Version.initial()), rootOper); - final TreeNode rootNode = inMemoryDataTreeSnapshot.getRootNode(); - final Optional expectedNode = StoreTreeNodes.findNode(rootNode, TWO_TWO_PATH); - assertPresentAndType(expectedNode, TreeNode.class); - final Map.Entry actualNode = StoreTreeNodes.findClosest(rootNode, TWO_TWO_PATH); - assertEquals("Expected node and actual node are not the same", expectedNode.get(), actualNode.getValue()); - } - - @Test - public void findClosestOrFirstMatchTestNodeDoesNotExist() { - final InMemoryDataTreeSnapshot inMemoryDataTreeSnapshot = new InMemoryDataTreeSnapshot(schemaContext, - TreeNodeFactory.createTreeNodeRecursively(createDocumentOne(), Version.initial()), rootOper); - final TreeNode rootNode = inMemoryDataTreeSnapshot.getRootNode(); - final YangInstanceIdentifier outerListInnerListPath = YangInstanceIdentifier.builder(OUTER_LIST_2_PATH) - .node(TestModel.INNER_LIST_QNAME) - .build(); - final YangInstanceIdentifier twoTwoInvalidPath = YangInstanceIdentifier.builder(OUTER_LIST_2_PATH) - .node(TestModel.INNER_LIST_QNAME) // - .nodeWithKey(TestModel.INNER_LIST_QNAME, TestModel.NAME_QNAME, "three") // - .build(); - final Optional expectedNode = StoreTreeNodes.findNode(rootNode, outerListInnerListPath); - assertPresentAndType(expectedNode, TreeNode.class); - final Map.Entry actualNode = StoreTreeNodes.findClosest(rootNode, twoTwoInvalidPath); - assertEquals("Expected node and actual node are not the same", expectedNode.get(), actualNode.getValue()); - } - - @Test - public void getChildTestChildFound() { - final InMemoryDataTreeSnapshot inMemoryDataTreeSnapshot = new InMemoryDataTreeSnapshot(schemaContext, - TreeNodeFactory.createTreeNodeRecursively(createDocumentOne(), Version.initial()), rootOper); - final TreeNode rootNode = inMemoryDataTreeSnapshot.getRootNode(); - final Optional node = StoreTreeNodes.getChild(Optional.fromNullable(rootNode), - TestModel.TEST_PATH.getLastPathArgument()); - assertPresentAndType(node, TreeNode.class); - } - - @Test - public void getChildTestChildNotFound() { - final InMemoryDataTreeSnapshot inMemoryDataTreeSnapshot = new InMemoryDataTreeSnapshot(schemaContext, - TreeNodeFactory.createTreeNodeRecursively(createDocumentOne(), Version.initial()), rootOper); - final TreeNode rootNode = inMemoryDataTreeSnapshot.getRootNode(); - final Optional node = StoreTreeNodes.getChild(Optional.fromNullable(rootNode), - TestModel.OUTER_LIST_PATH.getLastPathArgument()); - assertFalse(node.isPresent()); - } -} diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/StoreTreeNodesTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/StoreTreeNodesTest.java index f191518007..237d61a579 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/StoreTreeNodesTest.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/StoreTreeNodesTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. + * 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, @@ -17,7 +17,9 @@ import static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.ma import static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.mapNodeBuilder; import com.google.common.base.Optional; + import java.util.Map; + import org.junit.Before; import org.junit.Test; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; @@ -31,6 +33,7 @@ import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.TreeNodeFactory; import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.Version; import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder; import org.opendaylight.yangtools.yang.model.api.SchemaContext; +import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -66,7 +69,7 @@ public class StoreTreeNodesTest { private RootModificationApplyOperation rootOper; @Before - public void prepare() { + public void prepare() throws ReactorException { schemaContext = TestModel.createTestContext(); assertNotNull("Schema context must not be null.", schemaContext); rootOper = RootModificationApplyOperation.from(SchemaAwareApplyOperation.from(schemaContext, TreeType.OPERATIONAL)); diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/TestModel.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/TestModel.java index 25e6519148..221042ac3c 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/TestModel.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/TestModel.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. + * 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, @@ -7,20 +7,20 @@ */ package org.opendaylight.yangtools.yang.data.impl.schema.tree; -import com.google.common.io.Resources; -import java.io.IOException; import java.io.InputStream; +import java.util.Arrays; import java.util.Collections; + import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; +import org.opendaylight.yangtools.yang.data.impl.TestUtils; 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; -public final class TestModel { +public class TestModel { - public static final QName TEST_QNAME = QName.create("urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test", "2014-03-13", - "test"); + public static final QName TEST_QNAME = QName.create( + "urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test", "2014-03-13", "test"); public static final QName OUTER_LIST_QNAME = QName.create(TEST_QNAME, "outer-list"); public static final QName INNER_LIST_QNAME = QName.create(TEST_QNAME, "inner-list"); public static final QName OUTER_CHOICE_QNAME = QName.create(TEST_QNAME, "outer-choice"); @@ -30,29 +30,21 @@ public final class TestModel { private static final String DATASTORE_TEST_YANG = "/odl-datastore-test.yang"; public static final YangInstanceIdentifier TEST_PATH = YangInstanceIdentifier.of(TEST_QNAME); - public static final YangInstanceIdentifier OUTER_LIST_PATH = YangInstanceIdentifier.builder(TEST_PATH).node(OUTER_LIST_QNAME).build(); + public static final YangInstanceIdentifier OUTER_LIST_PATH = YangInstanceIdentifier.builder(TEST_PATH) + .node(OUTER_LIST_QNAME).build(); public static final QName TWO_QNAME = QName.create(TEST_QNAME, "two"); public static final QName THREE_QNAME = QName.create(TEST_QNAME, "three"); - private TestModel() { - throw new UnsupportedOperationException(); - } - public static InputStream getDatastoreTestInputStream() { return TestModel.class.getResourceAsStream(DATASTORE_TEST_YANG); } - public static SchemaContext createTestContext() { - return createTestContext(DATASTORE_TEST_YANG); + public static SchemaContext createTestContext() throws ReactorException { + return TestUtils.parseYangStreams(Arrays.asList(getDatastoreTestInputStream())); } - public static SchemaContext createTestContext(String resourcePath) { - YangParserImpl parser = new YangParserImpl(); - try { - return parser.parseSources(Collections.singleton(Resources.asByteSource(TestModel.class - .getResource(resourcePath)))); - } catch (IOException | YangSyntaxErrorException e) { - throw new IllegalStateException("Failed to create context", e); - } + public static SchemaContext createTestContext(String resourcePath) throws ReactorException { + InputStream yangStream = TestModel.class.getResourceAsStream(resourcePath); + return TestUtils.parseYangStreams(Collections.singletonList(yangStream)); } } diff --git a/yang/yang-data-jaxen/src/test/java/org/opendaylight/yangtools/yang/data/jaxen/JaxenTest.java b/yang/yang-data-jaxen/src/test/java/org/opendaylight/yangtools/yang/data/jaxen/JaxenTest.java index 4013366cbb..be8ba083f6 100644 --- a/yang/yang-data-jaxen/src/test/java/org/opendaylight/yangtools/yang/data/jaxen/JaxenTest.java +++ b/yang/yang-data-jaxen/src/test/java/org/opendaylight/yangtools/yang/data/jaxen/JaxenTest.java @@ -47,6 +47,7 @@ import org.opendaylight.yangtools.yang.data.api.schema.xpath.XPathResult; import org.opendaylight.yangtools.yang.data.api.schema.xpath.XPathSchemaContext; import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.opendaylight.yangtools.yang.model.api.SchemaPath; +import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; public class JaxenTest { private ConverterNamespaceContext convertNctx; @@ -67,7 +68,7 @@ public class JaxenTest { @Before public void setup() throws URISyntaxException, IOException, ParseException, XPathExpressionException, - UnsupportedAxisException { + UnsupportedAxisException, ReactorException { final SchemaContext schemaContext = createSchemaContext(); assertNotNull(schemaContext); @@ -214,8 +215,8 @@ public class JaxenTest { return SchemaPath.create(true, rootQName, listAQName, leafAQName); } - private SchemaContext createSchemaContext() throws IOException, URISyntaxException { - return TestUtils.loadSchemaContext(getClass().getResource("/test/documentTest").toURI()); + private SchemaContext createSchemaContext() throws IOException, URISyntaxException, ReactorException { + return TestUtils.loadModules("/test/documentTest"); } private static NormalizedNode createNormalizedNodes() { diff --git a/yang/yang-data-jaxen/src/test/java/org/opendaylight/yangtools/yang/data/jaxen/TestUtils.java b/yang/yang-data-jaxen/src/test/java/org/opendaylight/yangtools/yang/data/jaxen/TestUtils.java index 406475315b..9a5ff3ba71 100644 --- a/yang/yang-data-jaxen/src/test/java/org/opendaylight/yangtools/yang/data/jaxen/TestUtils.java +++ b/yang/yang-data-jaxen/src/test/java/org/opendaylight/yangtools/yang/data/jaxen/TestUtils.java @@ -13,10 +13,13 @@ import static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.ma import static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.mapNodeBuilder; import java.io.File; +import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.net.URI; +import java.net.URISyntaxException; import java.util.ArrayList; +import java.util.Collection; import java.util.List; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; @@ -25,6 +28,12 @@ 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.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.spi.source.StatementStreamSource; +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; final class TestUtils { @@ -47,19 +56,46 @@ final class TestUtils { private TestUtils() { } - public static SchemaContext loadSchemaContext(final URI resourceDirectory) throws IOException { - final YangParserImpl parser = new YangParserImpl(); - final File testDir = new File(resourceDirectory); + static SchemaContext loadModules(final String resourceDirectory) throws IOException, URISyntaxException, + ReactorException { + URI path = TestUtils.class.getResource(resourceDirectory).toURI(); + final File testDir = new File(path); final String[] fileList = testDir.list(); final List testFiles = new ArrayList<>(); if (fileList == null) { - throw new FileNotFoundException(resourceDirectory.toString()); + throw new FileNotFoundException(resourceDirectory); } for (String fileName : fileList) { - testFiles.add(new File(testDir, fileName)); + if (!new File(testDir, fileName).isDirectory()) { + testFiles.add(new File(testDir, fileName)); + } } - SchemaContext ctx = parser.parseFiles(testFiles); - return ctx; + return parseYangSources(testFiles); + } + + public static SchemaContext parseYangSources(StatementStreamSource... sources) + throws SourceException, ReactorException { + + CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR + .newBuild(); + reactor.addSources(sources); + + return reactor.buildEffective(); + } + + public static SchemaContext parseYangSources(File... files) throws SourceException, ReactorException, FileNotFoundException { + + StatementStreamSource[] sources = new StatementStreamSource[files.length]; + + for(int i = 0; i files) throws SourceException, ReactorException, FileNotFoundException { + return parseYangSources(files.toArray(new File[files.size()])); } /** diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/builder/impl/AbstractBuilderTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/builder/impl/AbstractBuilderTest.java deleted file mode 100644 index 684b068e7c..0000000000 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/builder/impl/AbstractBuilderTest.java +++ /dev/null @@ -1,87 +0,0 @@ -package org.opendaylight.yangtools.yang.parser.builder.impl; - -import com.google.common.base.Optional; -import java.net.URI; -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.Date; -import org.junit.Before; -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.model.api.MustDefinition; -import org.opendaylight.yangtools.yang.model.api.SchemaPath; -import org.opendaylight.yangtools.yang.model.util.MustDefinitionImpl; -import org.opendaylight.yangtools.yang.parser.builder.api.UnknownSchemaNodeBuilder; -import org.opendaylight.yangtools.yang.parser.builder.api.UsesNodeBuilder; - -/** - * Created by lukas on 10/14/14. - * - * @deprecated Pre-Beryllium implementation, scheduled for removal. - */ -@Deprecated -public abstract class AbstractBuilderTest { - - protected final static String MODULE_NAMESPACE = "urn:opendaylight.rpc:def:test-model"; - protected final static String REVISION = "2014-10-06"; - protected final static String MODULE_NAME = "test-module"; - protected final static DateFormat SIMPLE_DATE_FORMAT = new SimpleDateFormat("yyyy-mm-dd"); - protected final static String MODULE_PATH = "test/module/path/test-module@" + REVISION + ".yang"; - - protected ModuleBuilder module; - - @Before - public void setUp() throws Exception { - module = new ModuleBuilder(MODULE_NAME, MODULE_PATH); - final Date moduleRevision = SIMPLE_DATE_FORMAT.parse(REVISION); - module.setRevision(moduleRevision); - module.setNamespace(URI.create(MODULE_NAMESPACE)); - module.setPrefix("mod"); - } - - protected MustDefinition provideMustDefinition() { - return MustDefinitionImpl.create("must-condition == value", - Optional.fromNullable("desc"), Optional.fromNullable("reference"), Optional.fromNullable("error-apptag"), - Optional.fromNullable("error-message")); - } - - protected UnknownSchemaNodeBuilder provideUnknownNodeBuilder() { - final QName unknownType = QName.create(module.getNamespace(), module.getRevision(), "unknown-type"); - final QName unknownNode = QName.create(module.getNamespace(), module.getRevision(), "unknown-ext-use"); - final SchemaPath unknownNodePath = SchemaPath.create(true, unknownNode); - final UnknownSchemaNodeBuilder unknownNodeBuilder = new UnknownSchemaNodeBuilderImpl(module.getModuleName(), - 25, unknownNode, unknownNodePath); - unknownNodeBuilder.setNodeType(unknownType); - return unknownNodeBuilder; - } - - protected UnknownSchemaNodeBuilder provideUnknownNodeBuilder(final QName innerPathSegment) { - final QName unknownType = QName.create(module.getNamespace(), module.getRevision(), "unknown-type"); - final QName unknownNode = QName.create(module.getNamespace(), module.getRevision(), "unknown-ext-use"); - final SchemaPath unknownNodePath = SchemaPath.create(true, innerPathSegment, unknownNode); - final UnknownSchemaNodeBuilder unknownNodeBuilder = new UnknownSchemaNodeBuilderImpl(module.getModuleName(), - 25, unknownNode, unknownNodePath); - unknownNodeBuilder.setNodeType(unknownType); - return unknownNodeBuilder; - } - - protected ChoiceBuilder provideChoiceBuilder(final String choiceLocalName) { - final QName choiceName = QName.create(module.getNamespace(), module.getRevision(), choiceLocalName); - final SchemaPath choicePath = SchemaPath.create(true, choiceName); - final ChoiceBuilder choiceBuilder = new ChoiceBuilder(module.getModuleName(), 22, choiceName, choicePath); - - return choiceBuilder; - } - - protected UsesNodeBuilder provideUsesNodeBuilder(final String usesGroupingName) { - final QName targetQName = QName.create(module.getNamespace(), module.getRevision(), usesGroupingName); - return new UsesNodeBuilderImpl(module.getModuleName(), 10, SchemaPath.create(true, targetQName)); - } - - protected ContainerSchemaNodeBuilder provideContainerBuilder(final String containerLocalName) { - final QName containerQName = QName.create(module.getNamespace(), module.getRevision(), containerLocalName); - SchemaPath containerPath = SchemaPath.create(true, containerQName); - - return new ContainerSchemaNodeBuilder(module.getModuleName(), 10, - containerQName, containerPath); - } -} diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/builder/impl/BuilderUtilsTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/builder/impl/BuilderUtilsTest.java deleted file mode 100644 index 11a3f84261..0000000000 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/builder/impl/BuilderUtilsTest.java +++ /dev/null @@ -1,497 +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.yang.parser.builder.impl; - -import static org.junit.Assert.assertEquals; -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 static org.mockito.Mockito.mock; -import com.google.common.base.Optional; -import java.net.URI; -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.NavigableMap; -import java.util.TreeMap; -import org.junit.Before; -import org.junit.Test; -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.model.api.ConstraintDefinition; -import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; -import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; -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.util.Uint16; -import org.opendaylight.yangtools.yang.parser.builder.api.AugmentationSchemaBuilder; -import org.opendaylight.yangtools.yang.parser.builder.api.Builder; -import org.opendaylight.yangtools.yang.parser.builder.api.DataSchemaNodeBuilder; -import org.opendaylight.yangtools.yang.parser.builder.api.SchemaNodeBuilder; -import org.opendaylight.yangtools.yang.parser.builder.api.UsesNodeBuilder; -import org.opendaylight.yangtools.yang.parser.util.YangParseException; - -/** - * Test suite for increasing of test coverage of BuilderUtils implementation. - * - * @see org.opendaylight.yangtools.yang.parser.builder.impl.BuilderUtils - * - * @author Lukas Sedlak <lsedlak@cisco.com> - * - * @deprecated Pre-Beryllium implementation, scheduled for removal. - */ -@Deprecated -public class BuilderUtilsTest { - - private final static String MASTER_MODULE_NAMESPACE = "urn:opendaylight.master-model"; - private final static String MODULES_REVISION = "2014-10-06"; - private final static String MASTER_MODULE = "master-module"; - private final static String DEPENDENT_MODULE_NAMESPACE = "urn:opendaylight.secondary-model"; - private final static String DEPENDENT_MODULE = "depend-module"; - private final static String MASTER_MODULE_PATH = "test/module/path/master-module@" + MODULES_REVISION + ".yang"; - private final static String DEPENDENT_MODULE_PATH = "test/module/path/depend-module@" + MODULES_REVISION + ".yang"; - private final static String DEPENDENT_MODULE_PREFIX = "dep"; - - private final static DateFormat SIMPLE_DATE_FORMAT = new SimpleDateFormat("yyyy-mm-dd"); - - private ModuleBuilder masterModule; - private ModuleBuilder dependentModule; - - @Before - public void setUp() throws Exception { - masterModule = new ModuleBuilder(MASTER_MODULE, MASTER_MODULE_PATH); - dependentModule = new ModuleBuilder(DEPENDENT_MODULE, DEPENDENT_MODULE_PATH); - - final Date moduleRevision = SIMPLE_DATE_FORMAT.parse(MODULES_REVISION); - masterModule.setRevision(moduleRevision); - dependentModule.setRevision(moduleRevision); - - masterModule.setNamespace(URI.create(MASTER_MODULE_NAMESPACE)); - dependentModule.setNamespace(URI.create(DEPENDENT_MODULE_NAMESPACE)); - - masterModule.setNamespace(URI.create(MASTER_MODULE_NAMESPACE)); - dependentModule.setNamespace(URI.create(DEPENDENT_MODULE_NAMESPACE)); - - masterModule.setPrefix("mod"); - dependentModule.setPrefix("mod"); - masterModule.addModuleImport(dependentModule.getModuleName(), dependentModule.getRevision(), DEPENDENT_MODULE_PREFIX); - } - - @Test - public void testFindModuleFromBuildersWithNullPrefix() throws Exception { - final Map> testModules = initModuleBuildersForTest(); - - ModuleBuilder result = BuilderUtils.findModuleFromBuilders(testModules, masterModule, null, 12); - assertEquals(masterModule, result); - - result = BuilderUtils.findModuleFromBuilders(testModules, masterModule, masterModule.getPrefix(), 12); - assertEquals(masterModule, result); - - result = BuilderUtils.findModuleFromBuilders(testModules, masterModule, DEPENDENT_MODULE_PREFIX, 12); - assertEquals(dependentModule, result); - } - - private Map> initModuleBuildersForTest() throws Exception { - final Map> modules = new HashMap<>(); - final String module3Name = "Module3"; - - ModuleBuilder module3 = new ModuleBuilder(module3Name, "test/module/path/module3.yang"); - final Date moduleRevision = SIMPLE_DATE_FORMAT.parse(MODULES_REVISION); - - module3.setRevision(moduleRevision); - module3.setNamespace(URI.create("urn:opendaylight.ternary-model")); - module3.setPrefix("mod"); - - dependentModule.addModuleImport(module3.getModuleName(), module3.getRevision(), "ter"); - - final NavigableMap module1Map = new TreeMap<>(); - module1Map.put(masterModule.getRevision(), masterModule); - - final NavigableMap module2Map = new TreeMap<>(); - module2Map.put(dependentModule.getRevision(), dependentModule); - - final NavigableMap module3Map = new TreeMap<>(); - module3Map.put(module3.getRevision(), module3); - - modules.put(masterModule.getName(), module1Map); - modules.put(dependentModule.getName(), module2Map); - modules.put(module3Name, module3Map); - - return modules; - } - - @Test(expected = YangParseException.class) - public void testFindModuleFromBuildersWithNoImportedModule() throws Exception { - final Map> testModules = initModuleBuildersForTest(); - - BuilderUtils.findModuleFromBuilders(testModules, masterModule, "eth", 12); - } - - @Test(expected = YangParseException.class) - public void testFindModuleFromContextWithDependentModuleImportEqualsToNull() { - final SchemaContext mockContext = mock(SchemaContext.class); - - BuilderUtils.findModuleFromContext(mockContext, masterModule, "inalid-prefix", 14); - } - - @Test(expected = YangParseException.class) - public void testFindModuleFromContextWhereModuleIsNotPresent() { - final SchemaContext mockContext = mock(SchemaContext.class); - - BuilderUtils.findModuleFromContext(mockContext, masterModule, DEPENDENT_MODULE_PREFIX, 14); - } - - @Test(expected = YangParseException.class) - public void testFillAugmentTargetForInvalidTarget() { - AugmentationSchemaBuilder augBuilder = mock(AugmentationSchemaBuilder.class); - Builder invalidTarget = mock(Builder.class); - BuilderUtils.fillAugmentTarget(augBuilder, invalidTarget); - } - - @Test(expected = YangParseException.class) - public void testFillAugmentTargetWithChoiceBuilderContainingInvalidUsesNodeBuilder() { - final QName usesQName = QName.create(masterModule.getNamespace(), masterModule.getRevision(), "test-grouping"); - final UsesNodeBuilder usesNodeBuilder = new UsesNodeBuilderImpl(masterModule.getModuleName(), 10, SchemaPath.create(true, usesQName)); - - final QName augTargetQName = QName.create(masterModule.getNamespace(), masterModule.getRevision(), "target"); - final AugmentationSchemaBuilder augBuilder = new AugmentationSchemaBuilderImpl(masterModule.getModuleName(), 12, - "/target", SchemaPath.create(true, augTargetQName), 1); - - augBuilder.setParent(usesNodeBuilder); - - final QName choiceQName = QName.create(masterModule.getNamespace(), masterModule.getRevision(), "test-choice"); - final ChoiceBuilder choiceBuilder = new ChoiceBuilder(masterModule.getModuleName(), 14, choiceQName, - SchemaPath.create(true, choiceQName)); - - augBuilder.addUsesNode(usesNodeBuilder); - BuilderUtils.fillAugmentTarget(augBuilder, choiceBuilder); - } - - @Test - public void testFillAugmentTargetSetNodeAddedByUses() { - final QName augTargetQName = QName.create(masterModule.getNamespace(), masterModule.getRevision(), "target"); - final AugmentationSchemaBuilder augBuilder = new AugmentationSchemaBuilderImpl(masterModule.getModuleName(), 12, - "/target", SchemaPath.create(true, augTargetQName), 1); - - final String containerLocalName = "top-level-container"; - final QName containerQName = QName.create(masterModule.getNamespace(), masterModule.getRevision(), containerLocalName); - SchemaPath containerPath = SchemaPath.create(true, containerQName); - augBuilder.addChildNode( - new ContainerSchemaNodeBuilder(masterModule.getModuleName(), 10, containerQName, containerPath)); - - final QName choiceQName = QName.create(masterModule.getNamespace(), masterModule.getRevision(), "test-choice"); - final ChoiceBuilder choiceBuilder = new ChoiceBuilder(masterModule.getModuleName(), 14, choiceQName, - SchemaPath.create(true, choiceQName)); - - BuilderUtils.fillAugmentTarget(augBuilder, choiceBuilder); - - ChoiceCaseBuilder result = choiceBuilder.getCaseNodeByName(containerLocalName); - assertNotNull(result); - } - - @Test - public void testFindUnknownNodeInDataNodeContainer() { - final String parentLocalName = "parent"; - final QName containerQName = QName.create(masterModule.getNamespace(), masterModule.getRevision(), parentLocalName); - SchemaPath containerPath = SchemaPath.create(true, containerQName); - - final ContainerSchemaNodeBuilder containerBuilder = new ContainerSchemaNodeBuilder(masterModule.getModuleName(), 10, - containerQName, containerPath); - - final String unknownLocalName = "unknown-ext-use"; - final QName unknownNode = QName.create(masterModule.getNamespace(), masterModule.getRevision(), unknownLocalName); - SchemaPath unknownNodePath = SchemaPath.create(true, containerQName, unknownNode); - UnknownSchemaNodeBuilderImpl unknownNodeBuilder = new UnknownSchemaNodeBuilderImpl(masterModule.getModuleName(), - 22, unknownNode, unknownNodePath); - containerBuilder.addUnknownNodeBuilder(unknownNodeBuilder); - - List path = new ArrayList<>(2); - path.add(unknownNode); - - SchemaNodeBuilder result = BuilderUtils.findSchemaNode(path, containerBuilder); - assertNotNull(result); - assertEquals(unknownNodeBuilder, result); - - path.add(QName.create(masterModule.getNamespace(), masterModule.getRevision(), "foo")); - assertNull(BuilderUtils.findSchemaNode(path, containerBuilder)); - - final QName choiceQName = QName.create(masterModule.getNamespace(), masterModule.getRevision(), "select"); - SchemaPath choicePath = SchemaPath.create(true, choiceQName); - - final ChoiceBuilder choiceBuilder = new ChoiceBuilder(masterModule.getModuleName(), 33, choiceQName, choicePath); - - final QName caseQName = QName.create(masterModule.getNamespace(), masterModule.getRevision(), "simple-case"); - SchemaPath casePath = SchemaPath.create(true, choiceQName, caseQName); - - ChoiceCaseBuilder caseBuilder = new ChoiceCaseBuilder(masterModule.getModuleName(), 35, caseQName, casePath); - choiceBuilder.addCase(caseBuilder); - - choiceBuilder.addUnknownNodeBuilder(unknownNodeBuilder); - - path.clear(); - path.add(caseQName); - result = BuilderUtils.findSchemaNode(path, choiceBuilder); - assertNotNull(result); - assertTrue(result instanceof ChoiceCaseBuilder); - assertEquals(caseBuilder, result); - - path.clear(); - path.add(unknownNode); - result = BuilderUtils.findSchemaNode(path, choiceBuilder); - assertNotNull(result); - assertEquals(unknownNodeBuilder, result); - - path.add(QName.create(masterModule.getNamespace(), masterModule.getRevision(), "foo")); - result = BuilderUtils.findSchemaNode(path, choiceBuilder); - assertNull(result); - - final QName rpcQName = QName.create(masterModule.getNamespace(), masterModule.getRevision(), parentLocalName); - SchemaPath rpcPath = SchemaPath.create(true, rpcQName); - final RpcDefinitionBuilder rpcBuilder = new RpcDefinitionBuilder(masterModule.getModuleName(), 45, rpcQName, rpcPath); - - final QName inputQName = QName.create(masterModule.getNamespace(), masterModule.getRevision(), "input"); - final SchemaPath inputPath = SchemaPath.create(true, rpcQName, inputQName); - - final QName outputQName = QName.create(masterModule.getNamespace(), masterModule.getRevision(), "output"); - final SchemaPath outputPath = SchemaPath.create(true, rpcQName, outputQName); - - final ContainerSchemaNodeBuilder inputBuilder = new ContainerSchemaNodeBuilder(masterModule.getModuleName(), 46, - inputQName, inputPath); - final ContainerSchemaNodeBuilder outputBuilder = new ContainerSchemaNodeBuilder(masterModule.getModuleName(), 76, - outputQName, outputPath); - - rpcBuilder.setInput(inputBuilder); - rpcBuilder.setOutput(outputBuilder); - rpcBuilder.addUnknownNodeBuilder(unknownNodeBuilder); - - path.clear(); - path.add(inputQName); - result = BuilderUtils.findSchemaNode(path, rpcBuilder); - assertNotNull(result); - assertEquals(inputBuilder, result); - - path.clear(); - path.add(outputQName); - result = BuilderUtils.findSchemaNode(path, rpcBuilder); - assertNotNull(result); - assertEquals(outputBuilder, result); - - path.clear(); - path.add(unknownNode); - result = BuilderUtils.findSchemaNode(path, rpcBuilder); - assertNotNull(result); - assertEquals(unknownNodeBuilder, result); - - final QName leafQName = QName.create(masterModule.getNamespace(), masterModule.getRevision(), "simple-leaf"); - SchemaPath leafPath = SchemaPath.create(true, leafQName); - - final LeafSchemaNodeBuilder leafBuilder = new LeafSchemaNodeBuilder(masterModule.getModuleName(), 10, leafQName, leafPath); - leafBuilder.addUnknownNodeBuilder(unknownNodeBuilder); - - path.clear(); - path.add(unknownNode); - result = BuilderUtils.findSchemaNode(path, leafBuilder); - assertNotNull(result); - assertEquals(unknownNodeBuilder, result); - } - - @Test - public void testFindUnknownSchemaNodeInModule() { - final String parentLocalName = "parent"; - final QName containerQName = QName.create(masterModule.getNamespace(), masterModule.getRevision(), parentLocalName); - SchemaPath containerPath = SchemaPath.create(true, containerQName); - - final ContainerSchemaNodeBuilder containerBuilder = new ContainerSchemaNodeBuilder(masterModule.getModuleName(), 10, - containerQName, containerPath); - - final String unknownLocalName = "unknown-ext-use"; - final QName unknownNode = QName.create(masterModule.getNamespace(), masterModule.getRevision(), unknownLocalName); - final SchemaPath unknownNodePath = SchemaPath.create(true, containerQName, unknownNode); - UnknownSchemaNodeBuilderImpl unknownNodeBuilder = new UnknownSchemaNodeBuilderImpl(masterModule.getModuleName(), - 22, unknownNode, unknownNodePath); - containerBuilder.addUnknownNodeBuilder(unknownNodeBuilder); - - masterModule.addChildNode(containerBuilder); - - Optional result = BuilderUtils.findSchemaNodeInModule(unknownNodePath, masterModule); - - assertTrue(result.isPresent()); - assertEquals(result.get(), unknownNodeBuilder); - - final QName invalidUnknownNode = QName.create(masterModule.getNamespace(), masterModule.getRevision(), "invalid-ext-use"); - final SchemaPath invalidPath = SchemaPath.create(true, containerQName, invalidUnknownNode); - - result = BuilderUtils.findSchemaNodeInModule(invalidPath, masterModule); - assertFalse(result.isPresent()); - } - - @Test - public void testFindContainerInRPC() { - - final QName rpcQName = QName.create(masterModule.getNamespace(), masterModule.getRevision(), "send-message"); - SchemaPath rpcPath = SchemaPath.create(true, rpcQName); - final RpcDefinitionBuilder rpcBuilder = masterModule.addRpc(45, rpcQName, rpcPath); - - final QName inputQName = QName.create(masterModule.getNamespace(), masterModule.getRevision(), "input"); - final SchemaPath inputPath = SchemaPath.create(true, rpcQName, inputQName); - - final QName outputQName = QName.create(masterModule.getNamespace(), masterModule.getRevision(), "output"); - final SchemaPath outputPath = SchemaPath.create(true, rpcQName, outputQName); - - Optional requestResult = BuilderUtils.findSchemaNodeInModule(inputPath, masterModule); - assertTrue(requestResult.isPresent()); - - Optional responseResult = BuilderUtils.findSchemaNodeInModule(outputPath, masterModule); - assertTrue(responseResult.isPresent()); - - final ContainerSchemaNodeBuilder inputBuilder = new ContainerSchemaNodeBuilder(masterModule.getModuleName(), 46, - inputQName, inputPath); - final ContainerSchemaNodeBuilder outputBuilder = new ContainerSchemaNodeBuilder(masterModule.getModuleName(), 76, - outputQName, outputPath); - - final QName request = QName.create(masterModule.getNamespace(), masterModule.getRevision(), "request"); - final SchemaPath requestPath = SchemaPath.create(true, rpcQName, inputQName, request); - - final QName response = QName.create(masterModule.getNamespace(), masterModule.getRevision(), "response"); - final SchemaPath responsePath = SchemaPath.create(true, rpcQName, outputQName, response); - - final ContainerSchemaNodeBuilder requestBuilder = new ContainerSchemaNodeBuilder(masterModule.getModuleName(), 50, - request, requestPath); - final ContainerSchemaNodeBuilder responseBuilder = new ContainerSchemaNodeBuilder(masterModule.getModuleName(), 80, - response, responsePath); - - inputBuilder.addChildNode(requestBuilder); - outputBuilder.addChildNode(responseBuilder); - - rpcBuilder.setInput(inputBuilder); - rpcBuilder.setOutput(outputBuilder); - - requestResult = BuilderUtils.findSchemaNodeInModule(requestPath, masterModule); - assertTrue(requestResult.isPresent()); - - responseResult = BuilderUtils.findSchemaNodeInModule(responsePath, masterModule); - assertTrue(responseResult.isPresent()); - - final SchemaPath invalidPath = SchemaPath.create(true, rpcQName, response); - Optional invalidResult = BuilderUtils.findSchemaNodeInModule(invalidPath, masterModule); - assertFalse(invalidResult.isPresent()); - } - - @Test - public void testFindIdentity() { - assertNull(BuilderUtils.findIdentity(Collections.emptySet(), "test-identity")); - } - - @Test - public void testGetModuleByPrefix() { - assertEquals(BuilderUtils.getModuleByPrefix(masterModule, null), masterModule); - assertEquals(BuilderUtils.getModuleByPrefix(masterModule, ""), masterModule); - assertEquals(BuilderUtils.getModuleByPrefix(masterModule, masterModule.getPrefix()), masterModule); - } - - @Test - public void testFindModule() { - final Map> modules = new HashMap<>(1); - final NavigableMap masterModuleMap = new TreeMap<>(); - masterModuleMap.put(masterModule.getRevision(), masterModule); - modules.put(masterModule.getNamespace(), masterModuleMap); - - assertNull(BuilderUtils.findModule(QName.create("test-urn:namespace", "2014-10-08", "impossible-module"), modules)); - - assertEquals(BuilderUtils.findModule(QName.create(masterModule.getNamespace(), null, masterModule.getName()), modules), - masterModule); - } - - @Test - public void testFindBaseIdentity() { - assertNull(BuilderUtils.findBaseIdentity(masterModule, "prefix:ident", 27)); - - final QName identity = QName.create(masterModule.getNamespace(), masterModule.getRevision(), "ident"); - masterModule.addIdentity(identity, 22, SchemaPath.create(true, identity)); - - final IdentitySchemaNodeBuilder result = BuilderUtils - .findBaseIdentity(masterModule, masterModule.getPrefix() + ":ident", 22); - assertNotNull(result); - assertEquals(result.getQName(), identity); - } - - @Test - public void testWrapChildNode() { - final QName leafQName = QName.create(masterModule.getNamespace(), masterModule.getRevision(), "parent-leaf"); - final SchemaPath leafPath = SchemaPath.create(true, leafQName); - final LeafListSchemaNodeBuilder leafListBuilder = new LeafListSchemaNodeBuilder(masterModule.getModuleName(), - 27, leafQName, leafPath); - leafListBuilder.setType(Uint16.getInstance()); - - final LeafListSchemaNode leafList = leafListBuilder.build(); - - DataSchemaNodeBuilder wrapedLeafList = BuilderUtils - .wrapChildNode(masterModule.getModuleName(), 72, leafList, leafPath, leafQName); - - assertNotNull(wrapedLeafList); - assertEquals(wrapedLeafList.getQName(), leafList.getQName()); - } - - @Test(expected = YangParseException.class) - public void wrapChildNodeForUnknownNode() { - final QName qName = QName.create(masterModule.getNamespace(), masterModule.getRevision(), "name"); - final SchemaPath path = SchemaPath.create(true, qName); - - BuilderUtils - .wrapChildNode(masterModule.getModuleName(), 72, new NotExistingDataSchemaNodeImpl(), path, qName); - } - - private static class NotExistingDataSchemaNodeImpl implements DataSchemaNode { - - @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/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/builder/impl/CopyUtilsTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/builder/impl/CopyUtilsTest.java deleted file mode 100644 index 5edc74719c..0000000000 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/builder/impl/CopyUtilsTest.java +++ /dev/null @@ -1,482 +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.yang.parser.builder.impl; - -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 java.util.List; -import org.junit.Test; -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; -import org.opendaylight.yangtools.yang.model.api.SchemaPath; -import org.opendaylight.yangtools.yang.model.api.Status; -import org.opendaylight.yangtools.yang.model.util.Uint16; -import org.opendaylight.yangtools.yang.parser.builder.api.AugmentationSchemaBuilder; -import org.opendaylight.yangtools.yang.parser.builder.api.Builder; -import org.opendaylight.yangtools.yang.parser.builder.api.ConstraintsBuilder; -import org.opendaylight.yangtools.yang.parser.builder.api.DataSchemaNodeBuilder; -import org.opendaylight.yangtools.yang.parser.builder.api.GroupingBuilder; -import org.opendaylight.yangtools.yang.parser.builder.api.SchemaNodeBuilder; -import org.opendaylight.yangtools.yang.parser.builder.api.TypeDefinitionBuilder; -import org.opendaylight.yangtools.yang.parser.builder.api.UnknownSchemaNodeBuilder; -import org.opendaylight.yangtools.yang.parser.builder.api.UsesNodeBuilder; -import org.opendaylight.yangtools.yang.parser.util.YangParseException; - -/** - * Test suite for increasing of test coverage of CopyUtils implementation. - * - * @see org.opendaylight.yangtools.yang.parser.builder.impl.CopyUtils - * - * @author Lukas Sedlak <lsedlak@cisco.com> - * - * @deprecated Pre-Beryllium implementation, scheduled for removal. - */ -@Deprecated -public class CopyUtilsTest extends AbstractBuilderTest { - - @Test(expected = YangParseException.class) - public void testCopyOfUnknownTypeOfDataSchemaNode() { - final String leafLocalName = "leaf-to-refine"; - final QName leafName = QName.create(module.getNamespace(), module.getRevision(), leafLocalName); - final SchemaPath leafPath = SchemaPath.create(true, leafName); - final LeafSchemaNodeBuilder leafBuilder = new LeafSchemaNodeBuilder(module.getModuleName(), 22, leafName, leafPath); - - CopyUtils.copy(new InvalidDataSchemaNodeBuilder(), leafBuilder, false); - } - - @Test - public void testCopyAnyxmlWithAnyxmlOriginalNodeAndUnknownNodes() { - final String parentAnyxmlLocalName = "original-anyxml"; - final QName parentAnyxmlName = QName.create(module.getNamespace(), module.getRevision(), parentAnyxmlLocalName); - final SchemaPath parentAnyxmlPath = SchemaPath.create(true, parentAnyxmlName); - final AnyXmlBuilder parentAnyXmlBuilder = new AnyXmlBuilder(module.getModuleName(), 22, parentAnyxmlName, parentAnyxmlPath); - - final String anyxmlLocalName = "anyxml"; - final QName anyxmlName = QName.create(module.getNamespace(), module.getRevision(), anyxmlLocalName); - final SchemaPath anyxmlPath = SchemaPath.create(true, anyxmlName); - final AnyXmlBuilder anyXmlBuilder = new AnyXmlBuilder(module.getModuleName(), 22, anyxmlName, anyxmlPath); - - anyXmlBuilder.setOriginal(parentAnyXmlBuilder); - - final UnknownSchemaNodeBuilder unknownSchemaNodeBuilder = provideUnknownNodeBuilder(anyxmlName); - anyXmlBuilder.addUnknownNodeBuilder(unknownSchemaNodeBuilder); - - final AnyXmlBuilder copy = (AnyXmlBuilder) CopyUtils.copy(anyXmlBuilder, anyXmlBuilder, false); - assertFalse(copy.getUnknownNodes().isEmpty()); - assertNotNull(copy.getOriginal()); - assertEquals(copy.getOriginal(), parentAnyXmlBuilder); - } - - @Test - public void testCopyChoiceBuilderWithUnknownNodesAndAugmentation() { - final String originalChoiceLocalName = "original-choice-to-copy"; - final ChoiceBuilder originalChoiceBuilder = provideChoiceBuilder(originalChoiceLocalName); - - final String choiceLocalName = "choice-to-copy"; - final ChoiceBuilder choiceBuilder = provideChoiceBuilder(choiceLocalName); - choiceBuilder.setOriginal(originalChoiceBuilder); - - final UnknownSchemaNodeBuilder unknownSchemaNodeBuilder = provideUnknownNodeBuilder(choiceBuilder.getQName()); - final SchemaPath augPath = SchemaPath.create(true, choiceBuilder.getQName()); - - final AugmentationSchemaBuilder augBuilder = new AugmentationSchemaBuilderImpl(module.getModuleName(), 22, - "/imaginary/path", augPath, 0); - - final UsesNodeBuilder usesNodeBuilder = provideUsesNodeBuilder("test-grouping-use"); - augBuilder.addUsesNode(usesNodeBuilder); - augBuilder.addUnknownNodeBuilder(unknownSchemaNodeBuilder); - - choiceBuilder.addUnknownNodeBuilder(unknownSchemaNodeBuilder); - choiceBuilder.addAugmentation(augBuilder); - - final ChoiceBuilder copy = (ChoiceBuilder)CopyUtils.copy(choiceBuilder, module, false); - List augmentations = copy.getAugmentationBuilders(); - - assertFalse(copy.getUnknownNodes().isEmpty()); - - final UnknownSchemaNodeBuilder copyUnknownNode = copy.getUnknownNodes().get(0); - assertEquals(copyUnknownNode, unknownSchemaNodeBuilder); - - assertFalse(augmentations.isEmpty()); - final AugmentationSchemaBuilder copyAugBuilder = augmentations.get(0); - - assertEquals(copyAugBuilder, augBuilder); - assertEquals(copyAugBuilder.getUnknownNodes().get(0), augBuilder.getUnknownNodes().get(0)); - assertNotEquals(copyAugBuilder.getUsesNodeBuilders().get(0), augBuilder.getUsesNodeBuilders().get(0)); - } - - @Test - public void testCopyChoiceCaseBuilder() { - final String originalChoiceCaseLocalName = "original-choice-case"; - final QName originalChoiceCaseQName = QName.create(module.getNamespace(), module.getRevision(), - originalChoiceCaseLocalName); - final SchemaPath originalChoiceCasePath = SchemaPath.create(true, originalChoiceCaseQName); - final ChoiceCaseBuilder originalChoiceCaseBuilder = new ChoiceCaseBuilder(module.getModuleName(), 10, - originalChoiceCaseQName, originalChoiceCasePath); - - final String choiceCaseLocalName = "test-choice-case"; - final QName choiceCaseQName = QName.create(module.getNamespace(), module.getRevision(), choiceCaseLocalName); - final SchemaPath choiceCasePath = SchemaPath.create(true, choiceCaseQName); - final ChoiceCaseBuilder choiceCaseBuilder = new ChoiceCaseBuilder(module.getModuleName(), 10, choiceCaseQName, - choiceCasePath); - - choiceCaseBuilder.setOriginal(originalChoiceCaseBuilder); - - final UsesNodeBuilder usesNodeBuilder = provideUsesNodeBuilder("test-grouping-use"); - - UnknownSchemaNodeBuilder unknownSchemaNodeBuilder = provideUnknownNodeBuilder(choiceCaseQName); - - choiceCaseBuilder.addUsesNode(usesNodeBuilder); - choiceCaseBuilder.addUnknownNodeBuilder(unknownSchemaNodeBuilder); - - ChoiceCaseBuilder copy = (ChoiceCaseBuilder) CopyUtils.copy(choiceCaseBuilder, module, true); - - assertNotNull(copy); - assertEquals(copy.getUnknownNodes().get(0), choiceCaseBuilder.getUnknownNodes().get(0)); - assertFalse(copy.getUsesNodeBuilders().isEmpty()); - assertNotEquals(copy.getUsesNodeBuilders().get(0), choiceCaseBuilder.getUsesNodeBuilders().get(0)); - } - - @Test(expected = YangParseException.class) - public void testAddGroupingIntoChoiceCaseBuilder() { - final String choiceCaseLocalName = "test-choice-case"; - final QName choiceCaseQName = QName.create(module.getNamespace(), module.getRevision(), choiceCaseLocalName); - final SchemaPath choiceCasePath = SchemaPath.create(true, choiceCaseQName); - final ChoiceCaseBuilder choiceCaseBuilder = new ChoiceCaseBuilder(module.getModuleName(), 10, choiceCaseQName, - choiceCasePath); - - final String groupLocalName = "test-group"; - final QName testGroup = QName.create(module.getNamespace(), module.getRevision(), groupLocalName); - final SchemaPath groupPath = SchemaPath.create(true, choiceCaseQName, testGroup); - final GroupingBuilder grouping = module.addGrouping(12, testGroup, groupPath); - choiceCaseBuilder.addGrouping(grouping); - } - - @Test - public void testCopyContainerSchemaNodeBuilder() { - final ContainerSchemaNodeBuilder containerBuilder = provideContainerBuilder("parent-container"); - - final String groupLocalName = "test-group"; - final GroupingBuilder grouping = provideNestedGroupingDefinition(containerBuilder.getQName(), groupLocalName); - - final String typedefLocalName = "test-type-definition"; - final TypeDefinitionBuilder typedefBuilder = provideNestedTypedef(containerBuilder.getQName(), typedefLocalName); - - final UnknownSchemaNodeBuilder unknownNodeBuilder = provideUnknownNodeBuilder(containerBuilder.getQName()); - - containerBuilder.addGrouping(grouping); - containerBuilder.addTypedef(typedefBuilder); - containerBuilder.addUnknownNodeBuilder(unknownNodeBuilder); - - final ContainerSchemaNodeBuilder copy = (ContainerSchemaNodeBuilder) CopyUtils.copy(containerBuilder, module, true); - - assertNotNull(copy); - - assertFalse(copy.getGroupingBuilders().isEmpty()); - assertFalse(copy.getTypeDefinitionBuilders().isEmpty()); - assertFalse(copy.getUnknownNodes().isEmpty()); - } - - private GroupingBuilder provideNestedGroupingDefinition(final QName parentName, final String groupLocalName) { - final QName testGroup = QName.create(module.getNamespace(), module.getRevision(), groupLocalName); - final SchemaPath groupPath = SchemaPath.create(true, parentName, testGroup); - final GroupingBuilder grouping = module.addGrouping(12, testGroup, groupPath); - - return grouping; - } - - private TypeDefinitionBuilder provideNestedTypedef(final QName parentName, final String typedefLocalName) { - final QName typedefQname = QName.create(module.getNamespace(), module.getRevision(), typedefLocalName); - final SchemaPath typedefPath = SchemaPath.create(true, parentName, typedefQname); - final TypeDefinitionBuilder typedefBuilder = new TypeDefinitionBuilderImpl(module.getModuleName(), 12, - typedefQname, typedefPath); - typedefBuilder.setType(Uint16.getInstance()); - - return typedefBuilder; - } - - @Test - public void testCopyLeafSchemaNodeBuilder() { - final String leafLocalName = "original-leaf"; - final QName leafName = QName.create(module.getNamespace(), module.getRevision(), leafLocalName); - final SchemaPath leafPath = SchemaPath.create(true, leafName); - final LeafSchemaNodeBuilder leafBuilder = new LeafSchemaNodeBuilder(module.getModuleName(), 22, leafName, leafPath); - leafBuilder.setType(Uint16.getInstance()); - - final UnknownSchemaNodeBuilder unknownNodeBuilder = provideUnknownNodeBuilder(leafName); - leafBuilder.addUnknownNodeBuilder(unknownNodeBuilder); - - final LeafSchemaNodeBuilder copy = (LeafSchemaNodeBuilder)CopyUtils.copy(leafBuilder, module, true); - - assertNotNull(copy); - assertFalse(leafBuilder.getUnknownNodes().isEmpty()); - } - - @Test - public void testCopyLeafListSchemaNodeBuilder() { - final String origLeafListLocalName = "original-list-to"; - final QName origLeafListQName = QName.create(module.getNamespace(), module.getRevision(), origLeafListLocalName ); - final SchemaPath origLeafListPath = SchemaPath.create(true, origLeafListQName); - final LeafListSchemaNodeBuilder origLeafListBuilder = new LeafListSchemaNodeBuilder(module.getModuleName(), - 10, origLeafListQName, origLeafListPath); - origLeafListBuilder.setType(Uint16.getInstance()); - - final String leafListLocalName = "leaflist-copy"; - final QName leafListQName = QName.create(module.getNamespace(), module.getRevision(), leafListLocalName); - final SchemaPath leafListPath = SchemaPath.create(true, leafListQName); - final LeafListSchemaNodeBuilder leafListBuilder = new LeafListSchemaNodeBuilder(module.getModuleName(), - 20, leafListQName, leafListPath); - leafListBuilder.setType(Uint16.getInstance()); - - leafListBuilder.setOriginal(origLeafListBuilder); - final UnknownSchemaNodeBuilder unknownNodeBuilder = provideUnknownNodeBuilder(leafListQName); - leafListBuilder.addUnknownNodeBuilder(unknownNodeBuilder); - - final LeafListSchemaNodeBuilder copy = (LeafListSchemaNodeBuilder)CopyUtils.copy(leafListBuilder, module, true); - - assertNotNull(copy); - assertFalse(copy.getUnknownNodes().isEmpty()); - assertNotNull(copy.getUnknownNodes().get(0)); - } - - @Test - public void testCopyListSchemaNodeBuilder() { - final String origListLocalName = "original-list"; - final QName origListQName = QName.create(module.getNamespace(), module.getRevision(), origListLocalName); - final SchemaPath origListPath = SchemaPath.create(true, origListQName); - final ListSchemaNodeBuilder origListBuilder = new ListSchemaNodeBuilder(module.getModuleName(), - 10, origListQName, origListPath); - - final String listLocalName = "copy-of-list"; - final QName listQName = QName.create(module.getNamespace(), module.getRevision(), listLocalName); - final SchemaPath listPath = SchemaPath.create(true, listQName); - final ListSchemaNodeBuilder listBuilder = new ListSchemaNodeBuilder(module.getModuleName(), - 20, listQName, listPath); - - listBuilder.setOriginal(origListBuilder); - - final String groupLocalName = "test-group"; - final GroupingBuilder grouping = provideNestedGroupingDefinition(listBuilder.getQName(), groupLocalName); - listBuilder.addGrouping(grouping); - - final String typedefLocalName = "test-type-definition"; - final TypeDefinitionBuilder typedefBuilder = provideNestedTypedef(listBuilder.getQName(), typedefLocalName); - listBuilder.addTypedef(typedefBuilder); - - final UnknownSchemaNodeBuilder unknownNodeBuilder = provideUnknownNodeBuilder(listBuilder.getQName()); - listBuilder.addUnknownNodeBuilder(unknownNodeBuilder); - - final UsesNodeBuilder usesNodeBuilder = provideUsesNodeBuilder("test-grouping-use"); - listBuilder.addUsesNode(usesNodeBuilder); - - final SchemaPath augPath = SchemaPath.create(true, listBuilder.getQName()); - final AugmentationSchemaBuilder augBuilder = new AugmentationSchemaBuilderImpl(module.getModuleName(), 22, - "/imaginary/path", augPath, 0); - listBuilder.addAugmentation(augBuilder); - - ListSchemaNodeBuilder copy = (ListSchemaNodeBuilder) CopyUtils.copy(listBuilder, module, true); - assertNotNull(copy); - assertFalse(copy.getGroupingBuilders().isEmpty()); - assertFalse(copy.getTypeDefinitionBuilders().isEmpty()); - assertFalse(copy.getUnknownNodes().isEmpty()); - assertFalse(copy.getUsesNodeBuilders().isEmpty()); - assertFalse(copy.getAugmentationBuilders().isEmpty()); - } - - @Test - public void testCopyGroupingBuilder() { - final String groupLocalName = "test-group"; - final QName testGroup = QName.create(module.getNamespace(), module.getRevision(), groupLocalName); - final SchemaPath groupPath = SchemaPath.create(true, testGroup); - final GroupingBuilder grouping = module.addGrouping(12, testGroup, groupPath); - - final String innerGroupLocalName = "inner-group"; - final QName innerGroup = QName.create(module.getNamespace(), module.getRevision(), innerGroupLocalName); - final SchemaPath innerGroupPath = SchemaPath.create(true, testGroup, innerGroup); - final GroupingBuilder innerGrouping = module.addGrouping(12, innerGroup, innerGroupPath); - - grouping.addGrouping(innerGrouping); - - final String typedefLocalName = "test-type-definition"; - final TypeDefinitionBuilder typedefBuilder = provideNestedTypedef(grouping.getQName(), typedefLocalName); - grouping.addTypedef(typedefBuilder); - - final UsesNodeBuilder usesNodeBuilder = provideUsesNodeBuilder(innerGroupLocalName); - grouping.addUsesNode(usesNodeBuilder); - - final UnknownSchemaNodeBuilder unknownNodeBuilder = provideUnknownNodeBuilder(grouping.getQName()); - grouping.addUnknownNodeBuilder(unknownNodeBuilder); - - final GroupingBuilder copy = CopyUtils.copy(grouping, module, true); - assertNotNull(copy); - assertFalse(copy.getGroupingBuilders().isEmpty()); - assertFalse(copy.getTypeDefinitionBuilders().isEmpty()); - assertFalse(copy.getUsesNodeBuilders().isEmpty()); - assertFalse(copy.getUnknownNodes().isEmpty()); - } - - @Test - public void testCopyIdentityrefTypeBuilder() { - final String typedefLocalName = "identity-ref-test-type"; - final QName typedefQname = QName.create(module.getNamespace(), module.getRevision(), typedefLocalName); - final SchemaPath typedefPath = SchemaPath.create(true, typedefQname); - final IdentityrefTypeBuilder typeBuilder = new IdentityrefTypeBuilder(module.getModuleName(), 12, - "base:parent-identity", typedefPath); - - final TypeDefinitionBuilder copy = CopyUtils.copy(typeBuilder, module, true); - assertNotNull(copy); - - //TODO: add additional asserts - } - - @Test - public void testCopyTypeDefinitionBuilderWithUnknownNodes() { - final String typedefLocalName = "test-typedef-with-ext"; - final QName typedefQname = QName.create(module.getNamespace(), module.getRevision(), typedefLocalName); - final SchemaPath typedefPath = SchemaPath.create(true, typedefQname); - final TypeDefinitionBuilder typedefBuilder = new TypeDefinitionBuilderImpl(module.getModuleName(), 12, - typedefQname, typedefPath); - typedefBuilder.setType(Uint16.getInstance()); - - typedefBuilder.addUnknownNodeBuilder(provideUnknownNodeBuilder()); - - TypeDefinitionBuilder copy = CopyUtils.copy(typedefBuilder, module, true); - assertNotNull(copy); - assertFalse(copy.getUnknownNodes().isEmpty()); - } - - // FIXME: Use Mockito instead of this monstrosity - private static final class InvalidDataSchemaNodeBuilder implements DataSchemaNodeBuilder { - - @Override - public SchemaNodeBuilder getOriginal() { - return null; - } - - @Override - public void setOriginal(final SchemaNodeBuilder original) { - - } - - @Override - public boolean isAugmenting() { - return false; - } - - @Override - public void setAugmenting(final boolean augmenting) { - - } - - @Override - public boolean isConfiguration() { - return false; - } - - @Override - public void setConfiguration(final boolean config) { - - } - - @Override - public ConstraintsBuilder getConstraints() { - return null; - } - - @Override - public QName getQName() { - return null; - } - - @Override - public SchemaPath getPath() { - return null; - } - - @Override - public void setPath(final SchemaPath path) { - - } - - @Override - public String getModuleName() { - return null; - } - - @Override - public int getLine() { - return 0; - } - - @Override - public Builder getParent() { - return null; - } - - @Override - public void setParent(final Builder parent) { - - } - - @Override - public void addUnknownNodeBuilder(final UnknownSchemaNodeBuilder unknownNode) { - - } - - @Override - public List getUnknownNodes() { - return null; - } - - @Override - public DataSchemaNode build() { - return null; - } - - @Override - public String getDescription() { - return null; - } - - @Override - public void setDescription(final String description) { - - } - - @Override - public String getReference() { - return null; - } - - @Override - public void setReference(final String reference) { - - } - - @Override - public Status getStatus() { - return null; - } - - @Override - public void setStatus(final Status status) { - - } - - @Override - public boolean isAddedByUses() { - return false; - } - - @Override - public void setAddedByUses(final boolean addedByUses) { - - } - } -} diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/builder/impl/LeafListSchemaNodeBuilderTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/builder/impl/LeafListSchemaNodeBuilderTest.java deleted file mode 100644 index 54d511bb0d..0000000000 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/builder/impl/LeafListSchemaNodeBuilderTest.java +++ /dev/null @@ -1,136 +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.yang.parser.builder.impl; - -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.junit.Test; -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.model.api.DerivableSchemaNode; -import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode; -import org.opendaylight.yangtools.yang.model.api.SchemaPath; -import org.opendaylight.yangtools.yang.model.api.Status; -import org.opendaylight.yangtools.yang.model.util.Uint16; -import org.opendaylight.yangtools.yang.parser.builder.api.UnknownSchemaNodeBuilder; - -/** - * Test suite for increasing of test coverage of LeafListSchemaNodeBuilder implementation. - * - * @see org.opendaylight.yangtools.yang.parser.builder.impl.LeafListSchemaNodeBuilder - * - * @author Lukas Sedlak <lsedlak@cisco.com> - * - * @deprecated Pre-Beryllium implementation, scheduled for removal. - */ -@Deprecated -public class LeafListSchemaNodeBuilderTest extends AbstractBuilderTest { - - @Test - public void testLeafListSchemaNodeBuilderWithBaseLeafListSchemaNode() { - final String baseLeafListLocalName = "base-leaf-list"; - final QName baseLeafListQName = QName.create(module.getNamespace(), module.getRevision(), baseLeafListLocalName); - final SchemaPath baseLeafListPath = SchemaPath.create(true, baseLeafListQName); - final LeafListSchemaNodeBuilder baseLeafListBuilder = new LeafListSchemaNodeBuilder(module.getModuleName(), - 10, baseLeafListQName, baseLeafListPath); - - final UnknownSchemaNodeBuilder unknownNodeBuilder = provideUnknownNodeBuilder(); - - baseLeafListBuilder.addUnknownNodeBuilder(unknownNodeBuilder); - baseLeafListBuilder.setType(Uint16.getInstance()); - final LeafListSchemaNode leafList = baseLeafListBuilder.build(); - - assertNotNull(leafList); - assertFalse(leafList.getUnknownSchemaNodes().isEmpty()); - assertEquals(leafList.getUnknownSchemaNodes().size(), 1); - - final String leafListLocalName = "extended-leaf-list"; - final QName leafListQName = QName.create(module.getNamespace(), module.getRevision(), leafListLocalName); - final SchemaPath leafListPath = SchemaPath.create(true, leafListQName); - final LeafListSchemaNodeBuilder leafListBuilder = new LeafListSchemaNodeBuilder(module.getModuleName(), - 15, leafListQName, leafListPath, leafList); - - final LeafListSchemaNode extendedLeafList = leafListBuilder.build(); - - assertNotNull(extendedLeafList); - assertFalse(extendedLeafList.getUnknownSchemaNodes().isEmpty()); - assertEquals(extendedLeafList.getUnknownSchemaNodes().size(), 1); - - assertNotEquals(leafList, extendedLeafList); - - assertTrue(extendedLeafList instanceof DerivableSchemaNode); - assertTrue(((DerivableSchemaNode) extendedLeafList).getOriginal().isPresent()); - assertEquals(leafList, ((DerivableSchemaNode) extendedLeafList).getOriginal().get()); - } - - @Test - public void testEquals() { - final String baseLeafListLocalName = "leaf-list1"; - final QName baseLeafListQName = QName.create(module.getNamespace(), module.getRevision(), baseLeafListLocalName); - final SchemaPath baseLeafListPath = SchemaPath.create(true, baseLeafListQName); - final LeafListSchemaNodeBuilder baseLeafListBuilder = new LeafListSchemaNodeBuilder(module.getModuleName(), - 10, baseLeafListQName, baseLeafListPath); - - baseLeafListBuilder.setType(Uint16.getInstance()); - final LeafListSchemaNode leafList = baseLeafListBuilder.build(); - - final String leafListLocalName = "leaf-list2"; - final QName leafListQName2 = QName.create(module.getNamespace(), module.getRevision(), leafListLocalName); - final SchemaPath leafListPath2 = SchemaPath.create(true, leafListQName2); - final LeafListSchemaNodeBuilder leafListBuilder2 = new LeafListSchemaNodeBuilder(module.getModuleName(), - 10, leafListQName2, leafListPath2); - - leafListBuilder2.setType(Uint16.getInstance()); - final LeafListSchemaNode leafList2 = leafListBuilder2.build(); - - assertNotEquals(baseLeafListBuilder, null); - assertNotEquals(baseLeafListBuilder, leafListBuilder2); - - assertNotEquals(leafList, null); - assertNotEquals(leafList, leafList2); - - final QName containerQName = QName.create(module.getNamespace(), module.getRevision(), "parent-container"); - final String leafListLocalName3 = "leaf-list2"; - final QName leafListQName3 = QName.create(module.getNamespace(), module.getRevision(), leafListLocalName3); - final SchemaPath leafListPath3 = SchemaPath.create(true, containerQName, leafListQName3); - final LeafListSchemaNodeBuilder leafListBuilder3 = new LeafListSchemaNodeBuilder(module.getModuleName(), - 10, leafListQName3, leafListPath3); - - baseLeafListBuilder.setType(Uint16.getInstance()); - final LeafListSchemaNode leafList3 = baseLeafListBuilder.build(); - - assertNotEquals(leafListBuilder2, leafListBuilder3); - assertNotEquals(leafList3, leafList2); - } - - @Test - public void testLeafListSchemaNodeImplProperties() { - final String descString = "my leaf list description"; - final String leafListLocalName = "base-leaf-list"; - final QName leafListQName = QName.create(module.getNamespace(), module.getRevision(), leafListLocalName); - final SchemaPath leafListPath = SchemaPath.create(true, leafListQName); - final LeafListSchemaNodeBuilder leafListBuilder = new LeafListSchemaNodeBuilder(module.getModuleName(), - 10, leafListQName, leafListPath); - - leafListBuilder.setType(Uint16.getInstance()); - leafListBuilder.setDescription(descString); - final LeafListSchemaNode leafList = leafListBuilder.build(); - - assertEquals(leafList.getQName(), leafListQName); - assertEquals(leafList.getDescription(), descString); - assertEquals(leafList.getStatus(), Status.CURRENT); - assertEquals(leafList.getPath(), leafListPath); - assertEquals(leafList.getType(), Uint16.getInstance()); - assertNull(leafList.getReference()); - - assertEquals("LeafListSchemaNodeImpl[(urn:opendaylight.rpc:def:test-model?revision=2014-01-06)base-leaf-list]", - leafList.toString()); - } -} diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/builder/impl/ModuleBuilderTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/builder/impl/ModuleBuilderTest.java deleted file mode 100644 index 07360bed09..0000000000 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/builder/impl/ModuleBuilderTest.java +++ /dev/null @@ -1,814 +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.yang.parser.builder.impl; - -import static org.junit.Assert.assertEquals; -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 java.net.URI; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.List; -import org.junit.Before; -import org.junit.Test; -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.common.QNameModule; -import org.opendaylight.yangtools.yang.model.api.SchemaPath; -import org.opendaylight.yangtools.yang.model.util.Uint16; -import org.opendaylight.yangtools.yang.parser.builder.api.Builder; -import org.opendaylight.yangtools.yang.parser.builder.api.DataSchemaNodeBuilder; -import org.opendaylight.yangtools.yang.parser.builder.api.GroupingBuilder; -import org.opendaylight.yangtools.yang.parser.builder.api.UnknownSchemaNodeBuilder; -import org.opendaylight.yangtools.yang.parser.util.YangParseException; - -/** - * Test suite for increasing of test coverage of ModuleBuilder implementation. - * - * @see org.opendaylight.yangtools.yang.parser.builder.impl.ModuleBuilder - * - * @author Lukas Sedlak <lsedlak@cisco.com> - * - * @deprecated Pre-Beryllium implementation, scheduled for removal. - */ -@Deprecated -public class ModuleBuilderTest { - - private final static String TEST_MODULE_NAMESPACE = "urn:opendaylight.foo"; - private final static String TEST_MODULE_REVISION = "2014-09-22"; - private final static String MODULE_NAME = "TestModule"; - private static final String TEST_MODULE_PATH = "/test/module/path"; - - private ModuleBuilder moduleBuilder; - - @Before - public void setUp() throws Exception { - moduleBuilder = new ModuleBuilder(MODULE_NAME , TEST_MODULE_PATH); - } - - @Test - public void testGetSetModuleBuilderMethods() throws Exception { - assertEquals("module", moduleBuilder.getStatementName()); - assertEquals(TEST_MODULE_PATH, moduleBuilder.getModuleSourcePath()); - assertNotNull(moduleBuilder.getAllLists()); - final URI namespace = URI.create(TEST_MODULE_NAMESPACE + "?" + TEST_MODULE_REVISION); - moduleBuilder.setNamespace(namespace); - assertEquals(namespace, moduleBuilder.getNamespace()); - moduleBuilder.setBelongsTo("TEST_SUBMODULE"); - assertEquals("TEST_SUBMODULE", moduleBuilder.getBelongsTo()); - final Date revision = new SimpleDateFormat("yyyy-dd-mm").parse(TEST_MODULE_REVISION); - moduleBuilder.setRevision(revision); - assertEquals(revision, moduleBuilder.getRevision()); - } - - @Test(expected = IllegalArgumentException.class) - public void testCheckPrefixFailOnPrefixNull() { - moduleBuilder.addModuleImport("TEST_MODULE", null, null); - } - - @Test(expected = IllegalArgumentException.class) - public void testCheckPrefixFailOnPrefixStringIsEmpty() { - moduleBuilder.addModuleImport("TEST_MODULE", null, ""); - } - - @Test(expected = IllegalArgumentException.class) - public void testCheckPrefixFailOnPrefixEqualsModuleBuilderPrefix() { - moduleBuilder.setPrefix("prefix"); - moduleBuilder.addModuleImport("TEST_MODULE", null, "prefix"); - } - - @Test - public void testGetActualNodeNullResult() { - moduleBuilder.exitNode(); - assertNull(moduleBuilder.getActualNode()); - } - - @Test(expected = YangParseException.class) - public void testSetParent() throws Exception { - moduleBuilder.setParent(new Builder() { - @Override - public String getModuleName() { - return null; - } - - @Override - public int getLine() { - return 0; - } - - @Override - public Builder getParent() { - return null; - } - - @Override - public void setParent(final Builder parent) { - - } - - @Override - public void addUnknownNodeBuilder(final UnknownSchemaNodeBuilder unknownNode) { - - } - - @Override - public List getUnknownNodes() { - return null; - } - - @Override - public Object build() { - return null; - } - }); - } - - @Test(expected = YangParseException.class) - public void testAddExtensionWhereParentNodeIsNotModuleBuilder() throws Exception { - final QName containerQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "top-level-container"); - SchemaPath containerPath = SchemaPath.create(true, containerQName); - moduleBuilder.enterNode(new ContainerSchemaNodeBuilder(MODULE_NAME, 10, containerQName, containerPath)); - final QName extQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-ext"); - SchemaPath extPath = SchemaPath.create(true, containerQName, extQName); - moduleBuilder.addExtension(extQName, 12, extPath); - } - - @Test(expected = YangParseException.class) - public void testAddExtensionWhereNameOfExtensionCollides() throws Exception { - final QName extQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-ext"); - SchemaPath extPath = SchemaPath.create(true, extQName); - moduleBuilder.addExtension(extQName, 12, extPath); - - final QName extQName2 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-ext"); - moduleBuilder.addExtension(extQName2, 22, extPath); - } - - @Test(expected = YangParseException.class) - public void testAddDuplicateGroupingIntoModule() { - final QName testGroup1 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-group"); - final SchemaPath groupPath1 = SchemaPath.create(true, testGroup1); - - final QName testGroup2 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-group"); - final SchemaPath groupPath2 = SchemaPath.create(true, testGroup2); - - moduleBuilder.addGrouping(12, testGroup1, groupPath1); - moduleBuilder.addGrouping(12, testGroup2, groupPath2); - } - - @Test(expected = YangParseException.class) - public void testAddDuplicateGroupingIntoDataNodeContainer() { - final QName containerQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "top-level-container"); - SchemaPath containerPath = SchemaPath.create(true, containerQName); - moduleBuilder.enterNode(new ContainerSchemaNodeBuilder(MODULE_NAME, 10, containerQName, containerPath)); - final QName testGroup1 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-group"); - final SchemaPath groupPath1 = SchemaPath.create(true, containerQName, testGroup1); - - final QName testGroup2 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-group"); - final SchemaPath groupPath2 = SchemaPath.create(true, containerQName, testGroup2); - - moduleBuilder.addGrouping(12, testGroup1, groupPath1); - moduleBuilder.addGrouping(22, testGroup2, groupPath2); - } - - @Test - public void testAddTwoGroupingIntoDataNodeContainer() { - final QName containerQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "top-level-container"); - SchemaPath containerPath = SchemaPath.create(true, containerQName); - moduleBuilder.enterNode(new ContainerSchemaNodeBuilder(MODULE_NAME, 10, containerQName, containerPath)); - final QName testGroup1 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-group"); - final SchemaPath groupPath1 = SchemaPath.create(true, containerQName, testGroup1); - - final QName testGroup2 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-group2"); - final SchemaPath groupPath2 = SchemaPath.create(true, containerQName, testGroup2); - - GroupingBuilder grouping1 = moduleBuilder.addGrouping(12, testGroup1, groupPath1); - GroupingBuilder grouping2 = moduleBuilder.addGrouping(22, testGroup2, groupPath2); - - assertNotNull(grouping1); - assertNotNull(grouping2); - } - - @Test(expected = YangParseException.class) - public void testAddDuplicateGroupingIntoRpcDefinition() { - final QName rpcDefName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "rpc-definition"); - SchemaPath rpcPath = SchemaPath.create(true, rpcDefName); - moduleBuilder.enterNode(new RpcDefinitionBuilder(MODULE_NAME, 10, rpcDefName, rpcPath)); - final QName testGroup1 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-group"); - final SchemaPath groupPath1 = SchemaPath.create(true, rpcDefName, testGroup1); - - final QName testGroup2 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-group"); - final SchemaPath groupPath2 = SchemaPath.create(true, rpcDefName, testGroup2); - - moduleBuilder.addGrouping(12, testGroup1, groupPath1); - moduleBuilder.addGrouping(22, testGroup2, groupPath2); - } - - @Test - public void testAddTwoGroupingsIntoRpcDefinition() { - final QName rpcDefName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "rpc-definition"); - SchemaPath rpcPath = SchemaPath.create(true, rpcDefName); - moduleBuilder.enterNode(new RpcDefinitionBuilder(MODULE_NAME, 10, rpcDefName, rpcPath)); - final QName testGroup1 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-group"); - final SchemaPath groupPath1 = SchemaPath.create(true, rpcDefName, testGroup1); - - final QName testGroup2 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-group2"); - final SchemaPath groupPath2 = SchemaPath.create(true, rpcDefName, testGroup2); - - GroupingBuilder grouping1 = moduleBuilder.addGrouping(12, testGroup1, groupPath1); - GroupingBuilder grouping2 = moduleBuilder.addGrouping(22, testGroup2, groupPath2); - - assertNotNull(grouping1); - assertNotNull(grouping2); - } - - @Test(expected = YangParseException.class) - public void testAddGroupingIntoNonValidStatementDefinition() { - final QName leafListDefName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-leaflist"); - SchemaPath leaflistPath = SchemaPath.create(true, leafListDefName); - moduleBuilder.enterNode(new LeafListSchemaNodeBuilder(MODULE_NAME, 10, leafListDefName, leaflistPath)); - final QName testGroup = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-group"); - final SchemaPath groupPath = SchemaPath.create(true, leafListDefName, testGroup); - - moduleBuilder.addGrouping(12, testGroup, groupPath); - } - - @Test(expected = YangParseException.class) - public void testInvalidAugmentPathTargetString() { - final QName targetSchemaName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "fictive-target-container"); - moduleBuilder.addAugment(12, "something/something", SchemaPath.create(true, targetSchemaName), 0); - } - - @Test(expected = YangParseException.class) - public void testInvalidAugmentPathTargetStringInUsesNode() { - final QName usesNode = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "fictive-uses-node"); - SchemaPath targetPath = SchemaPath.create(true, usesNode); - moduleBuilder.enterNode(new UsesNodeBuilderImpl(MODULE_NAME, 10, targetPath)); - final QName targetSchemaName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "fictive-target-container"); - moduleBuilder.addAugment(12, "/something/something", SchemaPath.create(true, targetSchemaName), 0); - } - - @Test(expected = YangParseException.class) - public void testInvalidAugmentDefinition() { - final QName containerQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "top-level-container"); - SchemaPath containerPath = SchemaPath.create(true, containerQName); - moduleBuilder.enterNode(new ContainerSchemaNodeBuilder(MODULE_NAME, 10, containerQName, containerPath)); - - final QName targetSchemaName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "fictive-target-container"); - moduleBuilder.addAugment(12, "/something/something", SchemaPath.create(true, targetSchemaName), 0); - } - - @Test(expected = YangParseException.class) - public void testInvalidUsesNodeUse() { - final QName leafListDefName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-leaflist"); - SchemaPath leaflistPath = SchemaPath.create(true, leafListDefName); - moduleBuilder.enterNode(new LeafListSchemaNodeBuilder(MODULE_NAME, 10, leafListDefName, leaflistPath)); - - final QName testGroup = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-group"); - final SchemaPath groupPath = SchemaPath.create(true, testGroup); - - moduleBuilder.addUsesNode(17, groupPath); - } - - @Test(expected = YangParseException.class) - public void testAddRefineToNonUsesNodeBuilder() throws Exception { - final QName leafListDefName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-leaflist"); - SchemaPath leaflistPath = SchemaPath.create(true, leafListDefName); - moduleBuilder.enterNode(new LeafListSchemaNodeBuilder(MODULE_NAME, 10, leafListDefName, leaflistPath)); - - moduleBuilder.addRefine(new RefineHolderImpl(MODULE_NAME, 12, "testRefineName")); - } - - @Test(expected = YangParseException.class) - public void testAddRpcToNonModuleBuilder() throws Exception { - final QName containerQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "top-level-container"); - SchemaPath containerPath = SchemaPath.create(true, containerQName); - moduleBuilder.enterNode(new ContainerSchemaNodeBuilder(MODULE_NAME, 10, containerQName, containerPath)); - - final QName rpcDefName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "rpc-definition"); - SchemaPath rpcPath = SchemaPath.create(true, rpcDefName); - - moduleBuilder.addRpc(17, rpcDefName, rpcPath); - } - - @Test(expected = YangParseException.class) - public void testAddRpcWithSameNameAsAlreadyExistingDataNodeContainer() throws Exception { - final QName containerQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "element-foo"); - SchemaPath containerPath = SchemaPath.create(true, containerQName); - moduleBuilder.addContainerNode(10, containerQName, containerPath); - - final QName rpcDefName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "element-foo"); - SchemaPath rpcPath = SchemaPath.create(true, rpcDefName); - moduleBuilder.addRpc(17, rpcDefName, rpcPath); - } - - @Test(expected = YangParseException.class) - public void testAddDuplicateRpc() throws Exception { - final QName rpcDefName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "rpc-definition"); - SchemaPath rpcPath = SchemaPath.create(true, rpcDefName); - moduleBuilder.addRpc(17, rpcDefName, rpcPath); - - final QName rpcDefName2 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "rpc-definition"); - SchemaPath rpcPath2 = SchemaPath.create(true, rpcDefName2); - moduleBuilder.addRpc(23, rpcDefName2, rpcPath2); - } - - @Test(expected = YangParseException.class) - public void testAddRpcWithSameNameAsAlreadyDefinedNotification() throws Exception { - final QName rpcDefName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "rpc-definition"); - SchemaPath rpcPath = SchemaPath.create(true, rpcDefName); - moduleBuilder.addNotification(17, rpcDefName, rpcPath); - - final QName rpcDefName2 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "rpc-definition"); - SchemaPath rpcPath2 = SchemaPath.create(true, rpcDefName2); - moduleBuilder.addRpc(23, rpcDefName2, rpcPath2); - } - - @Test(expected = YangParseException.class) - public void testAddRpcInputForInvalidParent() throws Exception { - final QName rpcDefName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "rpc-definition"); - final QName rpcInput = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "input"); - SchemaPath rpcInputPath = SchemaPath.create(true, rpcDefName, rpcInput); - - moduleBuilder.addRpcInput(23, rpcInput, rpcInputPath); - } - - @Test(expected = YangParseException.class) - public void testAddRpcOutputForInvalidParent() throws Exception { - final QName rpcDefName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "rpc-definition"); - final QName rpcOutput = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "output"); - SchemaPath rpcOutputPath = SchemaPath.create(true, rpcDefName, rpcOutput); - - moduleBuilder.addRpcOutput(rpcOutputPath, rpcOutput, 23); - } - - @Test(expected = YangParseException.class) - public void testAddNotificationForInvalidParent() throws Exception { - final QName containerQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "top-level-container"); - SchemaPath containerPath = SchemaPath.create(true, containerQName); - moduleBuilder.enterNode(new ContainerSchemaNodeBuilder(MODULE_NAME, 10, containerQName, containerPath)); - - final QName notificationName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "notify-this"); - SchemaPath notificationPath = SchemaPath.create(true, notificationName); - - moduleBuilder.addNotification(12, notificationName, notificationPath); - } - - @Test(expected = YangParseException.class) - public void testAddNotificationWithSameNameAsAlreadyExistingDataNodeContainer() throws Exception { - final QName containerQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "notify"); - SchemaPath containerPath = SchemaPath.create(true, containerQName); - moduleBuilder.addContainerNode(10, containerQName, containerPath); - - final QName notificationName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "notify"); - SchemaPath notificationPath = SchemaPath.create(true, notificationName); - - moduleBuilder.addNotification(12, notificationName, notificationPath); - } - - @Test(expected = YangParseException.class) - public void testAddDuplicateNotification() throws Exception { - final QName notificationName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "notify-this"); - SchemaPath notificationPath = SchemaPath.create(true, notificationName); - - moduleBuilder.addNotification(12, notificationName, notificationPath); - - final QName notificationName2 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "notify-this"); - SchemaPath notificationPath2 = SchemaPath.create(true, notificationName2); - - moduleBuilder.addNotification(17, notificationName2, notificationPath2); - } - - @Test(expected = YangParseException.class) - public void testAddNotificationWithSameNameAsAlreadyDefinedRpc() throws Exception { - final QName rpcDefName2 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "notify-this"); - SchemaPath rpcPath2 = SchemaPath.create(true, rpcDefName2); - moduleBuilder.addRpc(17, rpcDefName2, rpcPath2); - - final QName rpcDefName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "notify-this"); - SchemaPath rpcPath = SchemaPath.create(true, rpcDefName); - moduleBuilder.addNotification(23, rpcDefName, rpcPath); - } - - @Test(expected = YangParseException.class) - public void testAddFeatureIntoNonModuleBuilder() throws Exception { - final QName containerQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "top-level-container"); - SchemaPath containerPath = SchemaPath.create(true, containerQName); - moduleBuilder.enterNode(new ContainerSchemaNodeBuilder(MODULE_NAME, 10, containerQName, containerPath)); - - final QName testFeature = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-feature"); - SchemaPath featurePath = SchemaPath.create(true, testFeature); - - moduleBuilder.addFeature(23, testFeature, featurePath); - } - - @Test(expected = YangParseException.class) - public void testAddDuplicateFeature() throws Exception { - final QName testFeature = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-feature"); - SchemaPath featurePath = SchemaPath.create(true, testFeature); - - moduleBuilder.addFeature(23, testFeature, featurePath); - - final QName testFeature2 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-feature"); - SchemaPath featurePath2 = SchemaPath.create(true, testFeature2); - - moduleBuilder.addFeature(23, testFeature2, featurePath2); - } - - @Test - public void testAddTwoFeatures() throws Exception { - final QName testFeature = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-feature"); - SchemaPath featurePath = SchemaPath.create(true, testFeature); - - final FeatureBuilder feature1 = moduleBuilder.addFeature(23, testFeature, featurePath); - - final QName testFeature2 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-feature2"); - SchemaPath featurePath2 = SchemaPath.create(true, testFeature2); - - final FeatureBuilder feature2 = moduleBuilder.addFeature(23, testFeature2, featurePath2); - - assertNotNull(feature1); - assertNotNull(feature2); - } - - @Test(expected = YangParseException.class) - public void testAddCaseWhenParentIsNull() throws Exception { - moduleBuilder.exitNode(); - addTestCase(); - } - - private void addTestCase() { - final QName testCase = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-case"); - SchemaPath testCasePath = SchemaPath.create(true, testCase); - - moduleBuilder.addCase(72, testCase, testCasePath); - } - - @Test(expected = YangParseException.class) - public void testAddCaseWhenParentIsModule() throws Exception { - addTestCase(); - } - - @Test(expected = YangParseException.class) - public void testAddCaseWhenParentIsNotChoiceNorAugmentation() throws Exception { - final QName containerQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "top-level-container"); - SchemaPath containerPath = SchemaPath.create(true, containerQName); - moduleBuilder.enterNode(new ContainerSchemaNodeBuilder(MODULE_NAME, 10, containerQName, containerPath)); - addTestCase(); - } - - @Test(expected = YangParseException.class) - public void testAddDuplicateTypedefIntoContainer() throws Exception { - final QName containerQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "top-level-container"); - SchemaPath containerPath = SchemaPath.create(true, containerQName); - moduleBuilder.enterNode(new ContainerSchemaNodeBuilder(MODULE_NAME, 10, containerQName, containerPath)); - - tryToAddDuplicateTypedef(); - } - - private void tryToAddDuplicateTypedef() { - final QName testTypedef1 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-type-definition"); - SchemaPath testTypedefPath1 = SchemaPath.create(true, testTypedef1); - - final QName testTypedef2 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-type-definition"); - SchemaPath testTypedefPath2 = SchemaPath.create(true, testTypedef2); - - moduleBuilder.addTypedef(23, testTypedef1, testTypedefPath1); - moduleBuilder.addTypedef(44, testTypedef2, testTypedefPath2); - } - - @Test(expected = YangParseException.class) - public void testAddDuplicateTypedefIntoRpcDefinition() throws Exception { - final QName rpcQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "top-level-rpc"); - SchemaPath rpcPath = SchemaPath.create(true, rpcQName); - moduleBuilder.enterNode(new RpcDefinitionBuilder(MODULE_NAME, 10, rpcQName, rpcPath)); - - tryToAddDuplicateTypedef(); - } - - @Test(expected = YangParseException.class) - public void testAddTypedefIntoNonValidStatement() throws Exception { - final QName leafName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-leaf"); - SchemaPath leafPath = SchemaPath.create(true, leafName); - moduleBuilder.enterNode(new LeafSchemaNodeBuilder(MODULE_NAME, 10, leafName, leafPath)); - - final QName testRpc = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-type-definition"); - SchemaPath testRpcPath = SchemaPath.create(true, testRpc); - - moduleBuilder.addTypedef(23, testRpc, testRpcPath); - } - - @Test - public void testAddTwoTypedefsIntoContainer() throws Exception { - final QName containerQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "top-level-container"); - SchemaPath containerPath = SchemaPath.create(true, containerQName); - moduleBuilder.enterNode(new ContainerSchemaNodeBuilder(MODULE_NAME, 10, containerQName, containerPath)); - - tryToAddTwoTypedefs(); - } - - private void tryToAddTwoTypedefs() { - final QName testTypedef1 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-type-definition"); - SchemaPath testTypedefPath1 = SchemaPath.create(true, testTypedef1); - - final QName testTypedef2 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-type-definition2"); - SchemaPath testTypedefPath2 = SchemaPath.create(true, testTypedef2); - - final TypeDefinitionBuilderImpl typedef1 = moduleBuilder.addTypedef(23, testTypedef1, testTypedefPath1); - final TypeDefinitionBuilderImpl typedef2 = moduleBuilder.addTypedef(44, testTypedef2, testTypedefPath2); - - assertNotNull(typedef1); - assertNotNull(typedef2); - } - - @Test - public void testAddTwoTypedefsIntoRpcDefinition() throws Exception { - final QName rpcQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "top-level-rpc"); - SchemaPath rpcPath = SchemaPath.create(true, rpcQName); - moduleBuilder.enterNode(new RpcDefinitionBuilder(MODULE_NAME, 10, rpcQName, rpcPath)); - - tryToAddTwoTypedefs(); - } - - @Test(expected = YangParseException.class) - public void testSetType() throws Exception { - final Uint16 uint = Uint16.getInstance(); - moduleBuilder.setType(uint); - } - - @Test(expected = YangParseException.class) - public void testAddUnionTypeWhenParentIsNull() throws Exception { - moduleBuilder.exitNode(); - - tryToAddUnionType(); - } - - private void tryToAddUnionType() { - final QName unionQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "union-type-def"); - moduleBuilder.addUnionType(25, QNameModule.create(unionQName.getNamespace(), unionQName.getRevision())); - } - - @Test(expected = YangParseException.class) - public void testAddUnionTypeWhenParentIsNotTypeAwareBuilder() throws Exception { - final QName containerQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "top-level-container"); - SchemaPath containerPath = SchemaPath.create(true, containerQName); - moduleBuilder.enterNode(new ContainerSchemaNodeBuilder(MODULE_NAME, 10, containerQName, containerPath)); - - tryToAddUnionType(); - } - - @Test(expected = YangParseException.class) - public void addIdentityrefTypeWhenParentIsNull() throws Exception { - moduleBuilder.exitNode(); - tryToAddIdentityrefType(); - } - - private void tryToAddIdentityrefType() { - final QName identityrefQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "identityref-type-def"); - SchemaPath identityrefPath = SchemaPath.create(true, identityrefQName); - moduleBuilder.addIdentityrefType(25, identityrefPath, "simplebase"); - } - - @Test(expected = YangParseException.class) - public void addIdentityrefTypeWhenParentIsNotTypeAwareBuilder() throws Exception { - final QName containerQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "top-level-container"); - SchemaPath containerPath = SchemaPath.create(true, containerQName); - moduleBuilder.enterNode(new ContainerSchemaNodeBuilder(MODULE_NAME, 10, containerQName, containerPath)); - - tryToAddIdentityrefType(); - } - - @Test(expected = YangParseException.class) - public void testAddDeviationWhereParentIsNotModule() throws Exception { - final QName containerQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "top-level-container"); - SchemaPath containerPath = SchemaPath.create(true, containerQName); - moduleBuilder.enterNode(new ContainerSchemaNodeBuilder(MODULE_NAME, 10, containerQName, containerPath)); - - final QName deviationQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-deviation-name"); - SchemaPath deviationPath = SchemaPath.create(true, deviationQName); - - moduleBuilder.addDeviation(78, deviationPath); - } - - @Test(expected = YangParseException.class) - public void testAddIdentityWhereParentIsNotModule() throws Exception { - final QName containerQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "top-level-container"); - SchemaPath containerPath = SchemaPath.create(true, containerQName); - moduleBuilder.enterNode(new ContainerSchemaNodeBuilder(MODULE_NAME, 10, containerQName, containerPath)); - - tryToAddIdentity(); - } - - private void tryToAddIdentity() { - final QName identityQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-identity-name"); - SchemaPath identityPath = SchemaPath.create(true, identityQName); - - moduleBuilder.addIdentity(identityQName, 78, identityPath); - } - - @Test(expected = YangParseException.class) - public void testAddDuplicateIdentity() throws Exception { - tryToAddIdentity(); - tryToAddIdentity(); - } - - @Test - public void testAddUnknownSchemaNodeDirectlyToParent() throws Exception { - final QName unknownQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "my-extension-use"); - SchemaPath unknownPath = SchemaPath.create(true, unknownQName); - assertTrue(moduleBuilder.getUnknownNodes().isEmpty()); - moduleBuilder.addUnknownSchemaNode(72, unknownQName, unknownPath); - assertFalse(moduleBuilder.getUnknownNodes().isEmpty()); - } - - @Test - public void testAddUnknownSchemaNodeIntoDataNodeContainer() throws Exception { - final QName containerQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "top-level-container"); - SchemaPath containerPath = SchemaPath.create(true, containerQName); - moduleBuilder.enterNode(new ContainerSchemaNodeBuilder(MODULE_NAME, 10, containerQName, containerPath)); - - final QName unknownQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "my-extension-use"); - SchemaPath unknownPath = SchemaPath.create(true, unknownQName); - assertTrue(moduleBuilder.getAllUnknownNodes().isEmpty()); - moduleBuilder.addUnknownSchemaNode(72, unknownQName, unknownPath); - assertFalse(moduleBuilder.getAllUnknownNodes().isEmpty()); - } - - @Test(expected = YangParseException.class) - public void testAddUnknownSchemaNodeIntoNonSchemaNode() throws Exception { - final QName containerQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "top-level-non-schema-node"); - SchemaPath containerPath = SchemaPath.create(true, containerQName); - moduleBuilder.enterNode(new NonSchemaNodeBuilder(MODULE_NAME, 10, containerQName, containerPath)); - - final QName unknownQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "my-extension-use"); - SchemaPath unknownPath = SchemaPath.create(true, unknownQName); - assertTrue(moduleBuilder.getUnknownNodes().isEmpty()); - moduleBuilder.addUnknownSchemaNode(72, unknownQName, unknownPath); - assertFalse(moduleBuilder.getUnknownNodes().isEmpty()); - } - - @Test(expected = YangParseException.class) - public void testAddContainerWithSameNameAsRpcDefintion() throws Exception { - final QName rpcDefName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "message"); - SchemaPath rpcPath = SchemaPath.create(true, rpcDefName); - moduleBuilder.addRpc(70, rpcDefName, rpcPath); - tryToAddContainer(); - } - - private void tryToAddContainer() { - final QName containerQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "message"); - final SchemaPath containerPath = SchemaPath.create(true, containerQName); - - moduleBuilder.addContainerNode(22, containerQName, containerPath); - } - - @Test(expected = YangParseException.class) - public void testAddContainerWithSameNameAsNotificationDefintion() throws Exception { - final QName notificationName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "message"); - SchemaPath notificationPath = SchemaPath.create(true, notificationName); - moduleBuilder.addNotification(70, notificationName, notificationPath); - tryToAddContainer(); - } - - @Test - public void testAddContainerWithAlreadyAddedRpcDefintion() throws Exception { - final QName rpcDefName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "send-message"); - SchemaPath rpcPath = SchemaPath.create(true, rpcDefName); - moduleBuilder.addRpc(70, rpcDefName, rpcPath); - tryToAddContainer(); - - DataSchemaNodeBuilder addedContainer = moduleBuilder.getDataChildByName("message"); - assertNotNull(addedContainer); - } - - @Test - public void testAddContainerWithAlreadyAddedNotificationDefintion() throws Exception { - final QName notificationName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "notify-me"); - SchemaPath notificationPath = SchemaPath.create(true, notificationName); - moduleBuilder.addNotification(70, notificationName, notificationPath); - tryToAddContainer(); - - DataSchemaNodeBuilder addedContainer = moduleBuilder.getDataChildByName("message"); - assertNotNull(addedContainer); - } - - @Test(expected = YangParseException.class) - public void testAddDuplicateSchemaNodeIntoSubnodeOfModule() throws Exception { - final QName containerQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "top-level-container"); - SchemaPath containerPath = SchemaPath.create(true, containerQName); - moduleBuilder.enterNode(new ContainerSchemaNodeBuilder(MODULE_NAME, 10, containerQName, containerPath)); - - final QName leafQName1 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "simple-leaf"); - SchemaPath leafPath1 = SchemaPath.create(true, containerQName, leafQName1); - - final QName leafQName2 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "simple-leaf"); - SchemaPath leafPath2 = SchemaPath.create(true, containerQName, leafQName2); - - moduleBuilder.addLeafNode(12, leafQName1, leafPath1); - moduleBuilder.addLeafNode(20, leafQName2, leafPath2); - } - - @Test(expected = YangParseException.class) - public void testAddDuplicateCaseIntoChoiceCaseNode() throws Exception { - //FIXME: move this into ChoiceBuilderTest !!! - final QName choiceQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "top-level-container"); - SchemaPath choicePath = SchemaPath.create(true, choiceQName); - - moduleBuilder.enterNode(new ChoiceBuilder(MODULE_NAME, 10, choiceQName, choicePath)); - - final QName caseQName1 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "simple-case"); - SchemaPath casePath1 = SchemaPath.create(true, choiceQName, caseQName1); - - final QName caseQName2 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "simple-case"); - SchemaPath casePath2 = SchemaPath.create(true, choiceQName, caseQName2); - - moduleBuilder.addCase(12, caseQName1, casePath1); - moduleBuilder.addCase(20, caseQName2, casePath2); - } - - @Test(expected = YangParseException.class) - public void testAddChoiceWithSameNameAsCase() throws Exception { - final QName choiceQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "my-choice"); - SchemaPath choicePath = SchemaPath.create(true, choiceQName); - - final ChoiceBuilder choiceBuilder = moduleBuilder.addChoice(8, choiceQName, choicePath); - moduleBuilder.enterNode(choiceBuilder); - - final QName caseQName1 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "simple-case"); - SchemaPath casePath1 = SchemaPath.create(true, choiceQName, caseQName1); - - final QName caseQName2 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "simple-case"); - SchemaPath casePath2 = SchemaPath.create(true, choiceQName, caseQName2); - - moduleBuilder.addCase(12, caseQName1, casePath1); - moduleBuilder.addChoice(20, caseQName2, casePath2); - } - - @Test(expected = YangParseException.class) - public void testAddChildToSubnodeForNonDataNodeContainerAndNonChoiceNode() { - final QName leafQName1 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "simple-leaf"); - SchemaPath leafPath1 = SchemaPath.create(true, leafQName1); - - final LeafSchemaNodeBuilder leafBuilder = moduleBuilder.addLeafNode(10, leafQName1, leafPath1); - moduleBuilder.enterNode(leafBuilder); - - final QName leafQName2 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "simple-leaf"); - SchemaPath leafPath2 = SchemaPath.create(true, leafQName1, leafQName2); - - moduleBuilder.addLeafNode(12, leafQName2, leafPath2); - } - - private static class NonSchemaNodeBuilder implements Builder { - - String moduleName; - final int line; - final QName name; - final SchemaPath path; - - public NonSchemaNodeBuilder(final String moduleName, final int line, final QName name, final SchemaPath path) { - this.moduleName = moduleName; - this.line = line; - this.name = name; - this.path = path; - } - - @Override - public String getModuleName() { - return moduleName; - } - - @Override - public int getLine() { - return line; - } - - @Override - public Builder getParent() { - return null; - } - - @Override - public void setParent(final Builder parent) { - - } - - @Override - public void addUnknownNodeBuilder(final UnknownSchemaNodeBuilder unknownNode) { - - } - - @Override - public List getUnknownNodes() { - return null; - } - - @Override - public Object build() { - return null; - } - } -} \ No newline at end of file diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/builder/impl/RefineUtilsTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/builder/impl/RefineUtilsTest.java deleted file mode 100644 index 3c43ecf02b..0000000000 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/builder/impl/RefineUtilsTest.java +++ /dev/null @@ -1,254 +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.yang.parser.builder.impl; - -import static org.junit.Assert.assertEquals; -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.junit.Test; -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.model.api.MustDefinition; -import org.opendaylight.yangtools.yang.model.api.SchemaPath; -import org.opendaylight.yangtools.yang.parser.builder.api.GroupingBuilder; -import org.opendaylight.yangtools.yang.parser.builder.api.UnknownSchemaNodeBuilder; -import org.opendaylight.yangtools.yang.parser.util.YangParseException; - -/** - * Test suite for increasing of test coverage of RefineUtils implementation. - * - * @see org.opendaylight.yangtools.yang.parser.builder.impl.RefineUtils - * - * @author Lukas Sedlak <lsedlak@cisco.com> - * - * @deprecated Pre-Beryllium implementation, scheduled for removal. - */ -@Deprecated -public class RefineUtilsTest extends AbstractBuilderTest { - - @Test - public void testRefineLeafWithEmptyDefaultString() { - final String leafLocalName = "leaf-to-refine"; - final QName leafName = QName.create(module.getNamespace(), module.getRevision(), leafLocalName); - final SchemaPath leafPath = SchemaPath.create(true, leafName); - final LeafSchemaNodeBuilder leafBuilder = new LeafSchemaNodeBuilder(module.getModuleName(), 22, leafName, leafPath); - - final RefineHolderImpl refineBuilder = new RefineHolderImpl(module.getModuleName(), 23, "/"+leafLocalName); - refineBuilder.setDefaultStr(""); - - RefineUtils.performRefine(leafBuilder, refineBuilder); - assertNull(leafBuilder.getDefaultStr()); - } - - @Test - public void testRefineContainer() { - final String containerLocalName = "container-to-refine"; - final QName containerName = QName.create(module.getNamespace(), module.getRevision(), containerLocalName); - final SchemaPath containerPath = SchemaPath.create(true, containerName); - final ContainerSchemaNodeBuilder containerBuilder = new ContainerSchemaNodeBuilder(module.getModuleName(), - 10, containerName, containerPath); - - final RefineHolderImpl refineBuilder = new RefineHolderImpl(module.getModuleName(), 23, "/"+containerLocalName); - refineBuilder.setPresence(null); - - final MustDefinition must = provideMustDefinition(); - refineBuilder.setMust(must); - - final UnknownSchemaNodeBuilder unknownNodeBuilder = provideUnknownNodeBuilder(); - refineBuilder.addUnknownNodeBuilder(unknownNodeBuilder); - - RefineUtils.performRefine(containerBuilder, refineBuilder); - - assertFalse(containerBuilder.getConstraints().getMustDefinitions().isEmpty()); - assertEquals(containerBuilder.getConstraints().getMustDefinitions().size(), 1); - assertFalse(containerBuilder.getUnknownNodes().isEmpty()); - assertEquals(containerBuilder.getUnknownNodes().get(0), unknownNodeBuilder); - } - - - - @Test - public void testRefineList() { - final String listLocalName = "list-to-refine"; - final QName listQName = QName.create(module.getNamespace(), module.getRevision(), listLocalName); - final SchemaPath listPath = SchemaPath.create(true, listQName); - final ListSchemaNodeBuilder listBuilder = new ListSchemaNodeBuilder(module.getModuleName(), - 10, listQName, listPath); - - final RefineHolderImpl refineBuilder = new RefineHolderImpl(module.getModuleName(), 23, "/"+listLocalName); - - final MustDefinition must = provideMustDefinition(); - refineBuilder.setMust(must); - - final UnknownSchemaNodeBuilder unknownNodeBuilder = provideUnknownNodeBuilder(); - refineBuilder.addUnknownNodeBuilder(unknownNodeBuilder); - - refineBuilder.setMinElements(null); - refineBuilder.setMaxElements(null); - - RefineUtils.performRefine(listBuilder, refineBuilder); - assertFalse(listBuilder.getConstraints().getMustDefinitions().isEmpty()); - assertEquals(listBuilder.getConstraints().getMustDefinitions().size(), 1); - assertNull(listBuilder.getConstraints().getMinElements()); - assertNull(listBuilder.getConstraints().getMaxElements()); - assertFalse(listBuilder.getUnknownNodes().isEmpty()); - assertEquals(listBuilder.getUnknownNodes().get(0), unknownNodeBuilder); - } - - @Test - public void testRefineLeafList() { - final String leafListLocalName = "list-to-refine"; - final QName leafListQName = QName.create(module.getNamespace(), module.getRevision(), leafListLocalName); - final SchemaPath leafListPath = SchemaPath.create(true, leafListQName); - final LeafListSchemaNodeBuilder leafListBuilder = new LeafListSchemaNodeBuilder(module.getModuleName(), - 10, leafListQName, leafListPath); - - final RefineHolderImpl refineBuilder = new RefineHolderImpl(module.getModuleName(), 23, "/"+leafListLocalName); - - final MustDefinition must = provideMustDefinition(); - refineBuilder.setMust(null); - - final UnknownSchemaNodeBuilder unknownNodeBuilder = provideUnknownNodeBuilder(); - refineBuilder.addUnknownNodeBuilder(unknownNodeBuilder); - - refineBuilder.setMinElements(null); - refineBuilder.setMaxElements(null); - - RefineUtils.performRefine(leafListBuilder, refineBuilder); - assertTrue(leafListBuilder.getConstraints().getMustDefinitions().isEmpty()); - assertNull(leafListBuilder.getConstraints().getMinElements()); - assertNull(leafListBuilder.getConstraints().getMaxElements()); - assertFalse(leafListBuilder.getUnknownNodes().isEmpty()); - assertEquals(leafListBuilder.getUnknownNodes().get(0), unknownNodeBuilder); - - refineBuilder.setMinElements(Integer.MIN_VALUE); - refineBuilder.setMaxElements(Integer.MAX_VALUE); - refineBuilder.setMust(must); - - RefineUtils.performRefine(leafListBuilder, refineBuilder); - assertFalse(leafListBuilder.getConstraints().getMustDefinitions().isEmpty()); - assertEquals(leafListBuilder.getConstraints().getMustDefinitions().size(), 1); - - assertNotNull(leafListBuilder.getConstraints().getMinElements()); - assertNotNull(leafListBuilder.getConstraints().getMaxElements()); - } - - @Test - public void testRefineChoice() { - final String choiceLocalName = "choice-to-refine"; - final ChoiceBuilder choiceBuilder = provideChoiceBuilder(choiceLocalName); - - final RefineHolderImpl refineBuilder = new RefineHolderImpl(module.getModuleName(), 23, "/"+choiceLocalName); - refineBuilder.setDefaultStr(null); - refineBuilder.setMandatory(null); - - RefineUtils.performRefine(choiceBuilder, refineBuilder); - assertNull(choiceBuilder.getDefaultCase()); - assertFalse(choiceBuilder.getConstraints().isMandatory()); - - final String defaultValue = "choice-default-case"; - refineBuilder.setDefaultStr(defaultValue); - refineBuilder.setMandatory(true); - final UnknownSchemaNodeBuilder unknownNodeBuilder = provideUnknownNodeBuilder(); - refineBuilder.addUnknownNodeBuilder(unknownNodeBuilder); - - RefineUtils.performRefine(choiceBuilder, refineBuilder); - assertNotNull(choiceBuilder.getDefaultCase()); - assertNotNull(choiceBuilder.getConstraints().isMandatory()); - assertFalse(choiceBuilder.getUnknownNodes().isEmpty()); - assertEquals(choiceBuilder.getUnknownNodes().get(0), unknownNodeBuilder); - } - - @Test - public void testRefineAnyxml() { - final String anyxmlLocalName = "anyxml-to-refine"; - final QName anyxmlName = QName.create(module.getNamespace(), module.getRevision(), anyxmlLocalName); - final SchemaPath anyxmlPath = SchemaPath.create(true, anyxmlName); - final AnyXmlBuilder anyXmlBuilder = new AnyXmlBuilder(module.getModuleName(), 22, anyxmlName, anyxmlPath); - - final RefineHolderImpl refineBuilder = new RefineHolderImpl(module.getModuleName(), 23, "/"+anyxmlLocalName); - refineBuilder.setMandatory(null); - refineBuilder.setMust(null); - - RefineUtils.performRefine(anyXmlBuilder, refineBuilder); - assertNull(refineBuilder.isMandatory()); - assertNull(refineBuilder.getMust()); - - final MustDefinition must = provideMustDefinition(); - - refineBuilder.setMandatory(true); - refineBuilder.setMust(must); - - final UnknownSchemaNodeBuilder unknownNodeBuilder = provideUnknownNodeBuilder(); - refineBuilder.addUnknownNodeBuilder(unknownNodeBuilder); - - RefineUtils.performRefine(anyXmlBuilder, refineBuilder); - assertFalse(anyXmlBuilder.getConstraints().getMustDefinitions().isEmpty()); - assertEquals(anyXmlBuilder.getConstraints().getMustDefinitions().size(), 1); - assertFalse(anyXmlBuilder.getUnknownNodes().isEmpty()); - assertEquals(anyXmlBuilder.getUnknownNodes().get(0), unknownNodeBuilder); - assertTrue(anyXmlBuilder.getConstraints().isMandatory()); - } - - @Test(expected = YangParseException.class) - public void testCheckRefineDefault() { - final String groupLocalName = "test-group"; - final QName testGroup = QName.create(module.getNamespace(), module.getRevision(), groupLocalName); - final SchemaPath groupPath = SchemaPath.create(true, testGroup); - final GroupingBuilder grouping = module.addGrouping(12, testGroup, groupPath); - - final RefineHolderImpl refineBuilder = new RefineHolderImpl(module.getModuleName(), 23, "/"+groupLocalName); - refineBuilder.setDefaultStr("invalid-default-value"); - - RefineUtils.performRefine(grouping, refineBuilder); - } - - @Test(expected = YangParseException.class) - public void testCheckRefineMandatory() { - final TypeDefinitionBuilderImpl typedef = initTypedef(); - final RefineHolderImpl refineBuilder = new RefineHolderImpl(module.getModuleName(), 23, "/"+typedef.getQName().getLocalName()); - refineBuilder.setMandatory(true); - RefineUtils.performRefine(typedef, refineBuilder); - } - - private TypeDefinitionBuilderImpl initTypedef() { - final String typedefLocalName = "test-type-definition"; - final QName testTypedef = QName.create(module.getNamespace(), module.getRevision(), typedefLocalName); - SchemaPath testTypedefPath = SchemaPath.create(true, testTypedef); - - return module.addTypedef(23, testTypedef, testTypedefPath); - } - - @Test(expected = YangParseException.class) - public void testCheckRefineMust() { - final TypeDefinitionBuilderImpl typedef = initTypedef(); - final RefineHolderImpl refineBuilder = new RefineHolderImpl(module.getModuleName(), 23, "/"+typedef.getQName().getLocalName()); - - final MustDefinition must = provideMustDefinition(); - refineBuilder.setMust(must); - RefineUtils.performRefine(typedef, refineBuilder); - } - - @Test(expected = YangParseException.class) - public void testCheckRefineMin() { - final TypeDefinitionBuilderImpl typedef = initTypedef(); - final RefineHolderImpl refineBuilder = new RefineHolderImpl(module.getModuleName(), 23, "/"+typedef.getQName().getLocalName()); - - refineBuilder.setMinElements(Integer.MIN_VALUE); - RefineUtils.performRefine(typedef, refineBuilder); - } - - @Test(expected = YangParseException.class) - public void testCheckRefineMax() { - final TypeDefinitionBuilderImpl typedef = initTypedef(); - final RefineHolderImpl refineBuilder = new RefineHolderImpl(module.getModuleName(), 23, "/"+typedef.getQName().getLocalName()); - - refineBuilder.setMaxElements(Integer.MAX_VALUE); - RefineUtils.performRefine(typedef, refineBuilder); - } -} diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/builder/impl/RpcDefinitionBuilderTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/builder/impl/RpcDefinitionBuilderTest.java deleted file mode 100644 index 56b6a181d2..0000000000 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/builder/impl/RpcDefinitionBuilderTest.java +++ /dev/null @@ -1,106 +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.yang.parser.builder.impl; - -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.junit.Test; -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.model.api.RpcDefinition; -import org.opendaylight.yangtools.yang.model.api.SchemaPath; -import org.opendaylight.yangtools.yang.model.api.Status; -import org.opendaylight.yangtools.yang.model.util.Uint16; -import org.opendaylight.yangtools.yang.parser.builder.api.GroupingBuilder; -import org.opendaylight.yangtools.yang.parser.builder.api.TypeDefinitionBuilder; -import org.opendaylight.yangtools.yang.parser.builder.api.UnknownSchemaNodeBuilder; -/** - * Test suite for increasing of test coverage of RpcDefinitionBuilder implementation. - * - * @see org.opendaylight.yangtools.yang.parser.builder.impl.RpcDefinitionBuilder - * - * @author Lukas Sedlak <lsedlak@cisco.com> - * - * @deprecated Pre-Beryllium implementation, scheduled for removal. - */ -@Deprecated -public class RpcDefinitionBuilderTest extends AbstractBuilderTest { - - @Test - public void testBuild() { - final QName rpcQName = QName.create(module.getNamespace(), module.getRevision(), "send-message"); - SchemaPath rpcPath = SchemaPath.create(true, rpcQName); - final RpcDefinitionBuilder rpcBuilder = new RpcDefinitionBuilder(module.getModuleName(), 10, rpcQName, rpcPath); - - final QName testTypedef = QName.create(module.getNamespace(), module.getRevision(), "test-typedef"); - final SchemaPath testTypedefPath = SchemaPath.create(true, rpcQName, testTypedef); - final TypeDefinitionBuilder typedefBuilder = new TypeDefinitionBuilderImpl(module.getModuleName(), - 12, testTypedef, testTypedefPath); - typedefBuilder.setType(Uint16.getInstance()); - - rpcBuilder.addTypedef(typedefBuilder); - - final QName testGroup = QName.create(module.getNamespace(), module.getRevision(), "test-group"); - final SchemaPath groupPath = SchemaPath.create(true, rpcQName, testGroup); - final GroupingBuilder groupBuilder = new GroupingBuilderImpl(module.getModuleName(), 15, testGroup, groupPath); - - rpcBuilder.addGrouping(groupBuilder); - - final QName unknownNode = QName.create(module.getNamespace(), module.getRevision(), "unknown-ext-use"); - final SchemaPath unknownNodePath = SchemaPath.create(true, rpcQName, unknownNode); - final UnknownSchemaNodeBuilder unknownNodeBuilder = new UnknownSchemaNodeBuilderImpl(module.getModuleName(), - 25, unknownNode, unknownNodePath); - - rpcBuilder.addUnknownNodeBuilder(unknownNodeBuilder); - - final RpcDefinitionBuilder rpcBuilder2 = new RpcDefinitionBuilder(module.getModuleName(), 10, rpcQName, rpcPath); - final RpcDefinitionBuilder rpcBuilder3 = new RpcDefinitionBuilder(module.getModuleName(), 10, unknownNode, rpcPath); - final RpcDefinitionBuilder rpcBuilder4 = new RpcDefinitionBuilder(module.getModuleName(), 10, rpcQName, unknownNodePath); - - assertEquals(rpcBuilder, rpcBuilder2); - assertNotEquals(rpcBuilder, null); - assertNotEquals(rpcBuilder, rpcBuilder3); - assertNotEquals(rpcBuilder, rpcBuilder4); - - assertEquals(rpcBuilder.toString(), "rpc send-message"); - - final RpcDefinition instance = rpcBuilder.build(); - - assertNotNull(instance); - - final RpcDefinition sameInstance = rpcBuilder.build(); - assertTrue(sameInstance == instance); - assertEquals(sameInstance, instance); - - assertEquals(instance.getPath(), rpcPath); - assertEquals(instance.getStatus(), Status.CURRENT); - assertNull(instance.getOutput()); - assertFalse(instance.getTypeDefinitions().isEmpty()); - assertFalse(instance.getGroupings().isEmpty()); - assertFalse(instance.getUnknownSchemaNodes().isEmpty()); - - assertEquals(instance.getTypeDefinitions().size(), 1); - assertEquals(instance.getGroupings().size(), 1); - assertEquals(instance.getUnknownSchemaNodes().size(), 1); - - RpcDefinition instance2 = rpcBuilder2.build(); - RpcDefinition instance3 = rpcBuilder3.build(); - RpcDefinition instance4 = rpcBuilder4.build(); - - assertEquals(instance, instance2); - assertNotEquals(instance, null); - assertNotEquals(instance, instance3); - assertNotEquals(instance, instance4); - - assertEquals(instance.toString(), "RpcDefinitionImpl[qname=(urn:opendaylight.rpc:def:test-model?" + - "revision=2014-01-06)send-message, path=AbsoluteSchemaPath{path=[(urn:opendaylight.rpc:def:test-model?" + - "revision=2014-01-06)send-message]}, input=null, output=null]"); - } -} diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/builder/impl/TypeDefinitionBuilderImplTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/builder/impl/TypeDefinitionBuilderImplTest.java deleted file mode 100644 index 4ee663537c..0000000000 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/builder/impl/TypeDefinitionBuilderImplTest.java +++ /dev/null @@ -1,73 +0,0 @@ -/** - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - */ -package org.opendaylight.yangtools.yang.parser.builder.impl; - -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.util.List; -import org.junit.Test; -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.model.api.SchemaPath; -import org.opendaylight.yangtools.yang.model.api.TypeDefinition; -import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode; -import org.opendaylight.yangtools.yang.model.util.Int16; -import org.opendaylight.yangtools.yang.parser.builder.api.UnknownSchemaNodeBuilder; - -/** - * @deprecated Pre-Beryllium implementation, scheduled for removal. - */ -@Deprecated -public class TypeDefinitionBuilderImplTest { - - @Test - public void getUnknownNodesTest() { - - SchemaPath path = SchemaPath.create(true, QName.create("myModuleName"),QName.create("MyTypeDefName")); - int line = 1; - String moduleName = "myModuleName"; - QName qName = QName.create("MyTypeDefName"); - - TypeDefinitionBuilderImpl typeDefinitionBuilderImpl = new TypeDefinitionBuilderImpl(moduleName,line,qName,path); - typeDefinitionBuilderImpl.setType(Int16.getInstance()); - - path = SchemaPath.create(true, QName.create("myModuleName"),QName.create("MyUnknownNodeName1")); - line = 1; - moduleName = "myModuleName"; - qName = QName.create("MyUnknownNodeName1"); - - UnknownSchemaNodeBuilderImpl unknownSchemaNodeBuilder1 = new UnknownSchemaNodeBuilderImpl(moduleName,line,qName,path); - - path = SchemaPath.create(true, QName.create("myModuleName"),QName.create("MyUnknownNodeName2")); - line = 2; - moduleName = "myModuleName"; - qName = QName.create("MyUnknownNodeName2"); - - UnknownSchemaNodeBuilderImpl unknownSchemaNodeBuilder2 = new UnknownSchemaNodeBuilderImpl(moduleName,line,qName,path); - - typeDefinitionBuilderImpl.addUnknownNodeBuilder(unknownSchemaNodeBuilder1); - typeDefinitionBuilderImpl.addUnknownNodeBuilder(unknownSchemaNodeBuilder2); - - List unknownNodesBuilders = typeDefinitionBuilderImpl.getUnknownNodes(); - - assertNotNull(unknownNodesBuilders); - assertFalse(unknownNodesBuilders.isEmpty()); - assertEquals(2,unknownNodesBuilders.size()); - assertTrue(unknownNodesBuilders.contains(unknownSchemaNodeBuilder1)); - assertTrue(unknownNodesBuilders.contains(unknownSchemaNodeBuilder2)); - - TypeDefinition> instance = typeDefinitionBuilderImpl.build(); - - List unknownNodes = instance.getUnknownSchemaNodes(); - - assertNotNull(unknownNodes); - assertFalse(unknownNodes.isEmpty()); - assertEquals(2,unknownNodes.size()); - assertTrue(unknownNodes.contains(unknownSchemaNodeBuilder1.build())); - assertTrue(unknownNodes.contains(unknownSchemaNodeBuilder2.build())); - - } - -} diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/AugmentTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/AugmentTest.java deleted file mode 100644 index e53afc975d..0000000000 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/AugmentTest.java +++ /dev/null @@ -1,457 +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.yang.parser.impl; - -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.FileNotFoundException; -import java.net.URI; -import java.text.DateFormat; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Date; -import java.util.List; -import java.util.Set; -import org.junit.BeforeClass; -import org.junit.Test; -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.model.api.AugmentationSchema; -import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode; -import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode; -import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode; -import org.opendaylight.yangtools.yang.model.api.DataNodeContainer; -import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; -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.RpcDefinition; -import org.opendaylight.yangtools.yang.model.api.SchemaPath; -import org.opendaylight.yangtools.yang.model.util.BaseTypes; - -public class AugmentTest { - private static final URI fooNS = URI.create("urn:opendaylight.foo"); - private static final URI barNS = URI.create("urn:opendaylight.bar"); - private static final URI bazNS = URI.create("urn:opendaylight.baz"); - private static Date fooRev; - private static Date barRev; - private static Date bazRev; - private static QName q0; - private static QName q1; - private static QName q2; - - private Set modules; - - @BeforeClass - public static void init() throws FileNotFoundException, ParseException { - DateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); - fooRev = simpleDateFormat.parse("2013-10-13"); - barRev = simpleDateFormat.parse("2013-10-14"); - bazRev = simpleDateFormat.parse("2013-10-15"); - - q0 = QName.create(barNS, barRev, "interfaces"); - q1 = QName.create(barNS, barRev, "ifEntry"); - q2 = QName.create(bazNS, bazRev, "augment-holder"); - } - - @Test - public void testAugmentParsing() throws Exception { - modules = TestUtils.loadModules(getClass().getResource("/augment-test/augment-in-augment").toURI()); - SchemaPath expectedSchemaPath; - List qnames = new ArrayList<>(); - qnames.add(q0); - qnames.add(q1); - qnames.add(q2); - - // foo.yang - Module module1 = TestUtils.findModule(modules, "foo"); - Set augmentations = module1.getAugmentations(); - assertEquals(1, augmentations.size()); - AugmentationSchema augment = augmentations.iterator().next(); - assertNotNull(augment); - - expectedSchemaPath = SchemaPath.create(qnames, true); - assertEquals(expectedSchemaPath, augment.getTargetPath()); - - Collection augmentChildren = augment.getChildNodes(); - assertEquals(4, augmentChildren.size()); - for (DataSchemaNode dsn : augmentChildren) { - TestUtils.checkIsAugmenting(dsn, false); - } - - LeafSchemaNode ds0ChannelNumber = (LeafSchemaNode) augment.getDataChildByName("ds0ChannelNumber"); - LeafSchemaNode interfaceId = (LeafSchemaNode) augment.getDataChildByName("interface-id"); - ContainerSchemaNode schemas = (ContainerSchemaNode) augment.getDataChildByName("schemas"); - ChoiceSchemaNode odl = (ChoiceSchemaNode) augment.getDataChildByName("odl"); - - assertNotNull(ds0ChannelNumber); - assertNotNull(interfaceId); - assertNotNull(schemas); - assertNotNull(odl); - - // leaf ds0ChannelNumber - QName qname = QName.create(fooNS, fooRev, "ds0ChannelNumber"); - qnames.add(qname); - assertEquals(qname, ds0ChannelNumber.getQName()); - expectedSchemaPath = SchemaPath.create(qnames, true); - assertEquals(expectedSchemaPath, ds0ChannelNumber.getPath()); - assertFalse(ds0ChannelNumber.isAugmenting()); - // type of leaf ds0ChannelNumber - QName typeQName = BaseTypes.constructQName("string"); - List typePath = Collections.singletonList(typeQName); - expectedSchemaPath = SchemaPath.create(typePath, true); - assertEquals(expectedSchemaPath, ds0ChannelNumber.getType().getPath()); - - // leaf interface-id - qname = QName.create(fooNS, fooRev, "interface-id"); - assertEquals(qname, interfaceId.getQName()); - qnames.set(3, qname); - expectedSchemaPath = SchemaPath.create(qnames, true); - assertEquals(expectedSchemaPath, interfaceId.getPath()); - assertFalse(interfaceId.isAugmenting()); - - // container schemas - qname = QName.create(fooNS, fooRev, "schemas"); - assertEquals(qname, schemas.getQName()); - qnames.set(3, qname); - expectedSchemaPath = SchemaPath.create(qnames, true); - assertEquals(expectedSchemaPath, schemas.getPath()); - assertFalse(schemas.isAugmenting()); - - // choice odl - qname = QName.create(fooNS, fooRev, "odl"); - assertEquals(qname, odl.getQName()); - qnames.set(3, qname); - expectedSchemaPath = SchemaPath.create(qnames, true); - assertEquals(expectedSchemaPath, odl.getPath()); - assertFalse(odl.isAugmenting()); - - // baz.yang - Module module3 = TestUtils.findModule(modules, "baz"); - augmentations = module3.getAugmentations(); - assertEquals(3, augmentations.size()); - AugmentationSchema augment1 = null; - AugmentationSchema augment2 = null; - AugmentationSchema augment3 = null; - for (AugmentationSchema as : augmentations) { - if (as.getWhenCondition() == null) { - augment3 = as; - } else if ("if:ifType='ds0'".equals(as.getWhenCondition().toString())) { - augment1 = as; - } else if ("if:ifType='ds2'".equals(as.getWhenCondition().toString())) { - augment2 = as; - } - } - assertNotNull(augment1); - assertNotNull(augment2); - assertNotNull(augment3); - - assertEquals(1, augment1.getChildNodes().size()); - ContainerSchemaNode augmentHolder = (ContainerSchemaNode) augment1.getDataChildByName("augment-holder"); - assertNotNull(augmentHolder); - - assertEquals(1, augment2.getChildNodes().size()); - ContainerSchemaNode augmentHolder2 = (ContainerSchemaNode) augment2.getDataChildByName("augment-holder2"); - assertNotNull(augmentHolder2); - - assertEquals(1, augment3.getChildNodes().size()); - LeafSchemaNode pause = (LeafSchemaNode) augment3.getDataChildByName("pause"); - assertNotNull(pause); - } - - @Test - public void testAugmentResolving() throws Exception { - modules = TestUtils.loadModules(getClass().getResource("/augment-test/augment-in-augment").toURI()); - Module module2 = TestUtils.findModule(modules, "bar"); - ContainerSchemaNode interfaces = (ContainerSchemaNode) module2.getDataChildByName("interfaces"); - ListSchemaNode ifEntry = (ListSchemaNode) interfaces.getDataChildByName("ifEntry"); - - SchemaPath expectedPath; - List qnames = new ArrayList<>(); - qnames.add(q0); - qnames.add(q1); - qnames.add(q2); - - // baz.yang - // augment "/br:interfaces/br:ifEntry" { - ContainerSchemaNode augmentHolder = (ContainerSchemaNode) ifEntry.getDataChildByName("augment-holder"); - TestUtils.checkIsAugmenting(augmentHolder, true); - assertEquals(q2, augmentHolder.getQName()); - expectedPath = SchemaPath.create(qnames, true); - assertEquals(expectedPath, augmentHolder.getPath()); - - // foo.yang - // augment "/br:interfaces/br:ifEntry/bz:augment-holder" - LeafSchemaNode ds0ChannelNumber = (LeafSchemaNode) augmentHolder.getDataChildByName("ds0ChannelNumber"); - LeafSchemaNode interfaceId = (LeafSchemaNode) augmentHolder.getDataChildByName("interface-id"); - ContainerSchemaNode schemas = (ContainerSchemaNode) augmentHolder.getDataChildByName("schemas"); - ChoiceSchemaNode odl = (ChoiceSchemaNode) augmentHolder.getDataChildByName("odl"); - - assertNotNull(ds0ChannelNumber); - assertNotNull(interfaceId); - assertNotNull(schemas); - assertNotNull(odl); - - // leaf ds0ChannelNumber - QName qname = QName.create(fooNS, fooRev, "ds0ChannelNumber"); - assertEquals(qname, ds0ChannelNumber.getQName()); - qnames.add(qname); - expectedPath = SchemaPath.create(qnames, true); - assertEquals(expectedPath, ds0ChannelNumber.getPath()); - - // leaf interface-id - qname = QName.create(fooNS, fooRev, "interface-id"); - assertEquals(qname, interfaceId.getQName()); - qnames.set(3, qname); - expectedPath = SchemaPath.create(qnames, true); - assertEquals(expectedPath, interfaceId.getPath()); - - // container schemas - qname = QName.create(fooNS, fooRev, "schemas"); - assertEquals(qname, schemas.getQName()); - qnames.set(3, qname); - expectedPath = SchemaPath.create(qnames, true); - assertEquals(expectedPath, schemas.getPath()); - - // choice odl - qname = QName.create(fooNS, fooRev, "odl"); - assertEquals(qname, odl.getQName()); - qnames.set(3, qname); - expectedPath = SchemaPath.create(qnames, true); - assertEquals(expectedPath, odl.getPath()); - } - - @Test - public void testAugmentedChoice() throws Exception { - modules = TestUtils.loadModules(getClass().getResource("/augment-test/augment-in-augment").toURI()); - Module module2 = TestUtils.findModule(modules, "bar"); - ContainerSchemaNode interfaces = (ContainerSchemaNode) module2.getDataChildByName("interfaces"); - ListSchemaNode ifEntry = (ListSchemaNode) interfaces.getDataChildByName("ifEntry"); - ContainerSchemaNode augmentedHolder = (ContainerSchemaNode) ifEntry.getDataChildByName("augment-holder"); - TestUtils.checkIsAugmenting(augmentedHolder, true); - - // foo.yang - // augment "/br:interfaces/br:ifEntry/bz:augment-holder" - ChoiceSchemaNode odl = (ChoiceSchemaNode) augmentedHolder.getDataChildByName("odl"); - assertNotNull(odl); - Set cases = odl.getCases(); - assertEquals(4, cases.size()); - - ChoiceCaseNode id = null; - ChoiceCaseNode node1 = null; - ChoiceCaseNode node2 = null; - ChoiceCaseNode node3 = null; - - for (ChoiceCaseNode ccn : cases) { - if ("id".equals(ccn.getQName().getLocalName())) { - id = ccn; - } else if ("node1".equals(ccn.getQName().getLocalName())) { - node1 = ccn; - } else if ("node2".equals(ccn.getQName().getLocalName())) { - node2 = ccn; - } else if ("node3".equals(ccn.getQName().getLocalName())) { - node3 = ccn; - } - } - - assertNotNull(id); - assertNotNull(node1); - assertNotNull(node2); - assertNotNull(node3); - - SchemaPath expectedPath; - List qnames = new ArrayList<>(); - qnames.add(q0); - qnames.add(q1); - qnames.add(q2); - qnames.add(QName.create(fooNS, fooRev, "odl")); - - // case id - QName qname = QName.create(fooNS, fooRev, "id"); - assertEquals(qname, id.getQName()); - qnames.add(qname); - expectedPath = SchemaPath.create(qnames, true); - assertEquals(expectedPath, id.getPath()); - Collection idChildren = id.getChildNodes(); - assertEquals(1, idChildren.size()); - - // case node1 - qname = QName.create(fooNS, fooRev, "node1"); - assertEquals(qname, node1.getQName()); - qnames.set(4, qname); - expectedPath = SchemaPath.create(qnames, true); - assertEquals(expectedPath, node1.getPath()); - Collection node1Children = node1.getChildNodes(); - assertTrue(node1Children.isEmpty()); - - // case node2 - qname = QName.create(fooNS, fooRev, "node2"); - assertEquals(qname, node2.getQName()); - qnames.set(4, qname); - expectedPath = SchemaPath.create(qnames, true); - assertEquals(expectedPath, node2.getPath()); - Collection node2Children = node2.getChildNodes(); - assertTrue(node2Children.isEmpty()); - - // case node3 - qname = QName.create(fooNS, fooRev, "node3"); - assertEquals(qname, node3.getQName()); - qnames.set(4, qname); - expectedPath = SchemaPath.create(qnames, true); - assertEquals(expectedPath, node3.getPath()); - Collection node3Children = node3.getChildNodes(); - assertEquals(1, node3Children.size()); - - // test cases - qnames.clear(); - qnames.add(q0); - qnames.add(q1); - qnames.add(q2); - qnames.add(QName.create(fooNS, fooRev, "odl")); - - // case id child - qnames.add(QName.create(fooNS, fooRev, "id")); - qnames.add(QName.create(fooNS, fooRev, "id")); - LeafSchemaNode caseIdChild = (LeafSchemaNode) idChildren.iterator().next(); - assertNotNull(caseIdChild); - expectedPath = SchemaPath.create(qnames, true); - assertEquals(expectedPath, caseIdChild.getPath()); - - // case node3 child - qnames.set(4, QName.create(fooNS, fooRev, "node3")); - qnames.set(5, QName.create(fooNS, fooRev, "node3")); - ContainerSchemaNode caseNode3Child = (ContainerSchemaNode) node3Children.iterator().next(); - assertNotNull(caseNode3Child); - expectedPath = SchemaPath.create(qnames, true); - assertEquals(expectedPath, caseNode3Child.getPath()); - } - - @Test - public void testAugmentRpc() throws Exception { - modules = TestUtils.loadModules(getClass().getResource("/augment-test/rpc").toURI()); - final URI NS_BAR = URI.create("urn:opendaylight:bar"); - final URI NS_FOO = URI.create("urn:opendaylight:foo"); - final Date revision = new SimpleDateFormat("yyyy-MM-dd").parse("2013-10-11"); - - Module bar = TestUtils.findModule(modules, "bar"); - Set rpcs = bar.getRpcs(); - assertEquals(2, rpcs.size()); - - RpcDefinition submit = null; - for (RpcDefinition rpc : rpcs) { - if ("submit".equals(rpc.getQName().getLocalName())) { - submit = rpc; - break; - } - } - assertNotNull(submit); - - QName submitQName = QName.create(NS_BAR, revision, "submit"); - assertEquals(submitQName, submit.getQName()); - ContainerSchemaNode input = submit.getInput(); - QName inputQName = QName.create(NS_BAR, revision, "input"); - assertEquals(inputQName, input.getQName()); - ChoiceSchemaNode arguments = (ChoiceSchemaNode) input.getDataChildByName("arguments"); - QName argumentsQName = QName.create(NS_BAR, revision, "arguments"); - assertEquals(argumentsQName, arguments.getQName()); - assertFalse(arguments.isAugmenting()); - Set cases = arguments.getCases(); - assertEquals(3, cases.size()); - - ChoiceCaseNode attach = null; - ChoiceCaseNode create = null; - ChoiceCaseNode destroy = null; - for (ChoiceCaseNode child : cases) { - if ("attach".equals(child.getQName().getLocalName())) { - attach = child; - } else if ("create".equals(child.getQName().getLocalName())) { - create = child; - } else if ("destroy".equals(child.getQName().getLocalName())) { - destroy = child; - } - } - assertNotNull(attach); - assertNotNull(create); - assertNotNull(destroy); - - assertTrue(attach.isAugmenting()); - assertTrue(create.isAugmenting()); - assertTrue(destroy.isAugmenting()); - - SchemaPath expectedPath; - QName[] qnames = new QName[4]; - qnames[0] = submitQName; - qnames[1] = inputQName; - qnames[2] = argumentsQName; - - // case attach - qnames[3] = QName.create(NS_FOO, revision, "attach"); - assertEquals(qnames[3], attach.getQName()); - expectedPath = SchemaPath.create(Arrays.asList(qnames), true); - assertEquals(expectedPath, attach.getPath()); - Collection attachChildren = attach.getChildNodes(); - assertEquals(1, attachChildren.size()); - - // case create - qnames[3] = QName.create(NS_FOO, revision, "create"); - assertEquals(qnames[3], create.getQName()); - expectedPath = SchemaPath.create(Arrays.asList(qnames), true); - assertEquals(expectedPath, create.getPath()); - Collection createChildren = create.getChildNodes(); - assertEquals(1, createChildren.size()); - - // case attach - qnames[3] = QName.create(NS_FOO, revision, "destroy"); - assertEquals(qnames[3], destroy.getQName()); - expectedPath = SchemaPath.create(Arrays.asList(qnames), true); - assertEquals(expectedPath, destroy.getPath()); - Collection destroyChildren = destroy.getChildNodes(); - assertEquals(1, destroyChildren.size()); - } - - @Test - public void testAugmentInUsesResolving() throws Exception { - modules = TestUtils.loadModules(getClass().getResource("/augment-test/augment-in-uses").toURI()); - assertEquals(1, modules.size()); - - Module test = modules.iterator().next(); - DataNodeContainer links = (DataNodeContainer) test.getDataChildByName("links"); - DataNodeContainer link = (DataNodeContainer) links.getDataChildByName("link"); - DataNodeContainer nodes = (DataNodeContainer) link.getDataChildByName("nodes"); - ContainerSchemaNode node = (ContainerSchemaNode) nodes.getDataChildByName("node"); - Set augments = node.getAvailableAugmentations(); - assertEquals(1, augments.size()); - assertEquals(1, node.getChildNodes().size()); - LeafSchemaNode id = (LeafSchemaNode) node.getDataChildByName("id"); - assertTrue(id.isAugmenting()); - } - - @Test - public void caseShortHandAugmentingTest() throws Exception { - modules = TestUtils.loadModules(getClass().getResource("/choice-case-type-test-models").toURI()); - - Module findModule = TestUtils.findModule(modules, "choice-monitoring"); - - ContainerSchemaNode netconf = (ContainerSchemaNode) findModule.getDataChildByName("netconf-state"); - ContainerSchemaNode datastores = (ContainerSchemaNode) netconf.getDataChildByName("datastores"); - ListSchemaNode datastore = (ListSchemaNode) datastores.getDataChildByName("datastore"); - ContainerSchemaNode locks = (ContainerSchemaNode) datastore.getDataChildByName("locks"); - ChoiceSchemaNode lockType = (ChoiceSchemaNode)locks.getDataChildByName("lock-type"); - - ChoiceCaseNode leafAugCase = lockType.getCaseNodeByName("leaf-aug-case"); - assertTrue(leafAugCase.isAugmenting()); - DataSchemaNode leafAug = leafAugCase.getDataChildByName("leaf-aug-case"); - assertFalse(leafAug.isAugmenting()); - } - -} diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/AugmentToExtensionTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/AugmentToExtensionTest.java deleted file mode 100644 index d8e2789157..0000000000 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/AugmentToExtensionTest.java +++ /dev/null @@ -1,70 +0,0 @@ -/** - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - */ -package org.opendaylight.yangtools.yang.parser.impl; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import java.io.IOException; -import java.net.URISyntaxException; -import java.util.Set; - -import org.junit.Test; -import org.opendaylight.yangtools.yang.model.api.AugmentationSchema; -import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode; -import org.opendaylight.yangtools.yang.model.api.Module; -import org.opendaylight.yangtools.yang.model.api.UsesNode; -import org.opendaylight.yangtools.yang.parser.util.YangParseException; - -public class AugmentToExtensionTest { - private Set modules; - - @Test(expected = YangParseException.class) - public void testIncorrectPath() throws IOException, URISyntaxException { - modules = TestUtils.loadModules(getClass().getResource("/augment-to-extension-test/incorrect-path").toURI()); - - } - - @Test - public void testCorrectPathIntoUnsupportedTarget() throws IOException, URISyntaxException { - modules = TestUtils.loadModules(getClass().getResource( - "/augment-to-extension-test/correct-path-into-unsupported-target").toURI()); - - Module devicesModul = TestUtils.findModule(modules, "augment-module"); - - ContainerSchemaNode devicesContainer = (ContainerSchemaNode) devicesModul.getDataChildByName("my-container"); - Set uses = devicesContainer.getUses(); - - boolean augmentationIsInContainer = false; - for (UsesNode usesNode : uses) { - Set augmentations = usesNode.getAugmentations(); - for (AugmentationSchema augmentationSchema : augmentations) { - augmentationIsInContainer = true; - } - } - - assertFalse(augmentationIsInContainer); - } - - @Test - public void testCorrectAugment() throws IOException, URISyntaxException { - modules = TestUtils.loadModules(getClass().getResource("/augment-to-extension-test/correct-augment").toURI()); - - Module devicesModul = TestUtils.findModule(modules, "augment-module"); - - ContainerSchemaNode devicesContainer = (ContainerSchemaNode) devicesModul.getDataChildByName("my-container"); - Set uses = devicesContainer.getUses(); - - boolean augmentationIsInContainer = false; - for (UsesNode usesNode : uses) { - Set augmentations = usesNode.getAugmentations(); - for (AugmentationSchema augmentationSchema : augmentations) { - augmentationIsInContainer = true; - } - } - - assertTrue(augmentationIsInContainer); - } - -} diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/AugmentationSchemaBuilderImplTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/AugmentationSchemaBuilderImplTest.java deleted file mode 100644 index ce0648f919..0000000000 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/AugmentationSchemaBuilderImplTest.java +++ /dev/null @@ -1,66 +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.yang.parser.impl; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import com.google.common.base.Optional; -import com.google.common.collect.Iterables; -import org.junit.Before; -import org.junit.Test; -import org.opendaylight.yangtools.yang.model.api.AugmentationSchema; -import org.opendaylight.yangtools.yang.model.api.SchemaPath; -import org.opendaylight.yangtools.yang.parser.builder.impl.AugmentationSchemaBuilderImpl; - -/** - * @deprecated Pre-Beryllium implementation, scheduled for removal. - */ -@Deprecated -public class AugmentationSchemaBuilderImplTest { - - private AugmentationSchemaBuilderImpl augmentSchemaBuilderImpl; - private AugmentationSchemaBuilderImpl augmentSchemaBuilderImpl2; - private AugmentationSchemaBuilderImpl augmentSchemaBuilderImpl3; - private AugmentationSchemaBuilderImpl augmentSchemaBuilderImpl4; - private AugmentationSchema augmentSchema; - - @Before - public void init() { - augmentSchemaBuilderImpl = new AugmentationSchemaBuilderImpl("test-module", 10, "augment-test/rpc", SchemaPath.ROOT, 1); - augmentSchemaBuilderImpl2 = new AugmentationSchemaBuilderImpl("test-module", 10, "augment-test/rpc2", SchemaPath.ROOT, 1); - augmentSchemaBuilderImpl3 = augmentSchemaBuilderImpl; - augmentSchemaBuilderImpl4 = new AugmentationSchemaBuilderImpl("test-module", 10, null, SchemaPath.ROOT, 1); - augmentSchema = augmentSchemaBuilderImpl.build(); - } - - @Test - public void testgetPath() { - assertTrue(Iterables.isEmpty(augmentSchemaBuilderImpl.getPath().getPathFromRoot())); - } - - @Test - public void testEquals() { - assertFalse(augmentSchemaBuilderImpl.equals("test")); - assertFalse(augmentSchemaBuilderImpl.equals(null)); - assertTrue(augmentSchemaBuilderImpl.equals(augmentSchemaBuilderImpl3)); - assertFalse(augmentSchemaBuilderImpl4.equals(augmentSchemaBuilderImpl)); - assertFalse(augmentSchemaBuilderImpl.equals(augmentSchemaBuilderImpl2)); - } - - @Test - public void testGetOriginalDefinition() { - augmentSchema = augmentSchemaBuilderImpl.build(); - Optional origDefinition = augmentSchema.getOriginalDefinition(); - assertFalse(origDefinition.isPresent()); - } - - @Test - public void testGetUnknownSchemaNodes() { - assertTrue(Iterables.isEmpty(augmentSchema.getUnknownSchemaNodes())); - } -} diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/Bug1412Test.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/Bug1412Test.java deleted file mode 100644 index 1ff22d9454..0000000000 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/Bug1412Test.java +++ /dev/null @@ -1,90 +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.yang.parser.impl; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import java.net.URI; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.List; -import java.util.Set; -import org.junit.Test; -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.common.QNameModule; -import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode; -import org.opendaylight.yangtools.yang.model.api.Module; -import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode; - -/** - * Test ANTLR4 grammar capability to parse description statement in unknown node. - * - * Note: Everything under unknown node is unknown node. - */ -public class Bug1412Test { - - @Test - public void test() throws Exception { - Set modules = TestUtils.loadModules(getClass().getResource("/bugs/bug1412").toURI()); - Module bug1412 = TestUtils.findModule(modules, "bug1412"); - assertNotNull(bug1412); - - ContainerSchemaNode node = (ContainerSchemaNode) bug1412.getDataChildByName("node"); - List unknownNodes = node.getUnknownSchemaNodes(); - assertEquals(1, unknownNodes.size()); - UnknownSchemaNode action = unknownNodes.get(0); - - Date revision = new SimpleDateFormat("yyyy-MM-dd").parse("2014-07-25"); - QNameModule qm = QNameModule.create(URI.create("urn:test:bug1412"), revision); - QName expectedNodeType = QName.create("urn:test:bug1412:ext:definitions", "2014-07-25", "action"); - assertEquals(expectedNodeType, action.getNodeType()); - assertEquals("hello", action.getNodeParameter()); - QName expectedQName = QName.create(qm, "hello"); - assertEquals(expectedQName, action.getQName()); - - unknownNodes = action.getUnknownSchemaNodes(); - assertEquals(4, unknownNodes.size()); - UnknownSchemaNode info = null; - UnknownSchemaNode description = null; - UnknownSchemaNode actionPoint = null; - UnknownSchemaNode output = null; - for (UnknownSchemaNode un : unknownNodes) { - if ("info".equals(un.getNodeType().getLocalName())) { - info = un; - } else if ("description".equals(un.getNodeType().getLocalName())) { - description = un; - } else if ("actionpoint".equals(un.getNodeType().getLocalName())) { - actionPoint = un; - } else if ("output".equals(un.getNodeType().getLocalName())) { - output = un; - } - } - assertNotNull(info); - assertNotNull(description); - assertNotNull(actionPoint); - assertNotNull(output); - - expectedNodeType = QName.create("urn:test:bug1412:ext:definitions", "2014-07-25", "info"); - assertEquals(expectedNodeType, info.getNodeType()); - assertEquals("greeting", info.getNodeParameter()); - - expectedNodeType = QName.create(qm, "description"); - assertEquals(expectedNodeType, description.getNodeType()); - assertEquals("say greeting", description.getNodeParameter()); - - expectedNodeType = QName.create("urn:test:bug1412:ext:definitions", "2014-07-25", "actionpoint"); - assertEquals(expectedNodeType, actionPoint.getNodeType()); - assertEquals("entry", actionPoint.getNodeParameter()); - - expectedNodeType = QName.create(qm, "output"); - assertEquals(expectedNodeType, output.getNodeType()); - assertEquals("", output.getNodeParameter()); - } - -} diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/Bug1413Test.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/Bug1413Test.java deleted file mode 100644 index e9f09bb0cd..0000000000 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/Bug1413Test.java +++ /dev/null @@ -1,42 +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.yang.parser.impl; - -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.Test; -import org.opendaylight.yangtools.yang.model.api.ExtensionDefinition; -import org.opendaylight.yangtools.yang.model.api.Module; - -/** - * Test ANTLR4 grammar capability to parse unknown node in extension argument - * declaration. - * - * Note: Everything under unknown node is unknown node. - */ -public class Bug1413Test { - - @Test - public void test() throws Exception { - Set modules = TestUtils.loadModules(getClass().getResource("/bugs/bug1413").toURI()); - Module bug1413 = TestUtils.findModule(modules, "bug1413"); - assertNotNull(bug1413); - - List extensions = bug1413.getExtensionSchemaNodes(); - assertEquals(1, extensions.size()); - - ExtensionDefinition info = extensions.get(0); - assertEquals("text", info.getArgument()); - assertTrue(info.isYinElement()); - } - -} diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/Bug2291Test.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/Bug2291Test.java deleted file mode 100644 index 1e19ea2587..0000000000 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/Bug2291Test.java +++ /dev/null @@ -1,26 +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.yang.parser.impl; - -import java.io.File; -import java.util.Arrays; -import org.junit.Test; -import org.opendaylight.yangtools.yang.model.parser.api.YangContextParser; - -public class Bug2291Test { - - @Test - public void testRevisionWithExt() throws Exception { - File extdef = new File(getClass().getResource("/bugs/bug2291/bug2291-ext.yang").toURI()); - File bug = new File(getClass().getResource("/bugs/bug2291/bug2291.yang").toURI()); - File inet = new File(getClass().getResource("/ietf/ietf-inet-types@2010-09-24.yang").toURI()); - YangContextParser parser = new YangParserImpl(); - parser.parseFiles(Arrays.asList(extdef, bug, inet)); - } - -} diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/Bug3799Test.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/Bug3799Test.java deleted file mode 100644 index b9caef748f..0000000000 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/Bug3799Test.java +++ /dev/null @@ -1,58 +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.parser.impl; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import java.util.Collection; -import java.util.Set; -import org.junit.Test; -import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; -import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode; -import org.opendaylight.yangtools.yang.model.api.Module; -import org.opendaylight.yangtools.yang.model.api.NotificationDefinition; - -public class Bug3799Test { - - @Test - public void test() throws Exception { - - Set modules = TestUtils.loadModules(getClass().getResource( - "/bugs/bug3799").toURI()); - assertNotNull(modules); - assertEquals(1, modules.size()); - - Module testModule = modules.iterator().next(); - Set subModules = testModule.getSubmodules(); - assertNotNull(subModules); - assertEquals(1, subModules.size()); - - Module testSubmodule = subModules.iterator().next(); - - Set notifications = testSubmodule - .getNotifications(); - assertNotNull(notifications); - assertEquals(1, notifications.size()); - - NotificationDefinition bazNotification = notifications.iterator() - .next(); - Collection childNodes = bazNotification.getChildNodes(); - assertNotNull(childNodes); - assertEquals(1, childNodes.size()); - - DataSchemaNode child = childNodes.iterator().next(); - assertTrue(child instanceof LeafSchemaNode); - - LeafSchemaNode leafBar = (LeafSchemaNode) child; - String bar = leafBar.getQName().getLocalName(); - assertEquals("bar", bar); - } - -} diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/Bug394Test.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/Bug394Test.java deleted file mode 100644 index 421926668a..0000000000 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/Bug394Test.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.yang.parser.impl; - -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.Test; -import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode; -import org.opendaylight.yangtools.yang.model.api.ExtensionDefinition; -import org.opendaylight.yangtools.yang.model.api.Module; -import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode; - -/** - * Test antlr grammar capability to parse nested unknown nodes. - */ -public class Bug394Test { - - @Test - public void testParseList() throws Exception { - Set modules = TestUtils.loadModules(getClass().getResource("/bugs/bug394").toURI()); - Module bug394 = TestUtils.findModule(modules, "bug394"); - assertNotNull(bug394); - Module bug394_ext = TestUtils.findModule(modules, "bug394-ext"); - assertNotNull(bug394_ext); - - ContainerSchemaNode logrecords = (ContainerSchemaNode) bug394.getDataChildByName("logrecords"); - assertNotNull(logrecords); - - List nodes = logrecords.getUnknownSchemaNodes(); - assertEquals(2, nodes.size()); - - List extensions = bug394_ext.getExtensionSchemaNodes(); - assertEquals(2, extensions.size()); - - assertTrue(extensions.contains(nodes.get(0).getExtensionDefinition())); - assertTrue(extensions.contains(nodes.get(1).getExtensionDefinition())); - } - -} diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/Bug4079Test.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/Bug4079Test.java deleted file mode 100644 index 626a399dff..0000000000 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/Bug4079Test.java +++ /dev/null @@ -1,170 +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.parser.impl; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import java.io.IOException; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.net.URISyntaxException; -import java.util.Set; -import java.util.regex.Pattern; -import java.util.regex.PatternSyntaxException; -import org.junit.Test; -import org.opendaylight.yangtools.yang.model.api.Module; - -public class Bug4079Test { - - private Set modules; - - @Test - public void testModuleCompilation() throws URISyntaxException, IOException { - modules = TestUtils.loadModules(getClass().getResource("/bugs/bug4079").toURI()); - assertNotNull(modules); - } - - @Test - public void testValidPatternFix() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { - Method method = ParserListenerUtils.class.getDeclaredMethod("fixUnicodeScriptPattern", String.class); - assertNotNull(method); - assertEquals("fixUnicodeScriptPattern", method.getName()); - - method.setAccessible(true); - - String fixedUnicodeScriptPattern = (String) method.invoke(null,"(\\p{IsArrows})*+"); - assertEquals("(\\p{InArrows})*+", fixedUnicodeScriptPattern); - assertNotNull(Pattern.compile(fixedUnicodeScriptPattern)); - - fixedUnicodeScriptPattern = (String) method.invoke(null,"(\\p{IsDingbats})++"); - assertEquals("(\\p{InDingbats})++", fixedUnicodeScriptPattern); - assertNotNull(Pattern.compile(fixedUnicodeScriptPattern)); - - fixedUnicodeScriptPattern = (String) method.invoke(null,"(\\p{IsSpecials})?+"); - assertEquals("(\\p{InSpecials})?+", fixedUnicodeScriptPattern); - assertNotNull(Pattern.compile(fixedUnicodeScriptPattern)); - - fixedUnicodeScriptPattern = (String) method.invoke(null,"(\\p{IsBatak}){4}+"); - assertEquals("(\\p{IsBatak}){4}+", fixedUnicodeScriptPattern); - assertNotNull(Pattern.compile(fixedUnicodeScriptPattern)); - - fixedUnicodeScriptPattern = (String) method.invoke(null,"(\\p{IsLatin}){4,6}+"); - assertEquals("(\\p{IsLatin}){4,6}+", fixedUnicodeScriptPattern); - assertNotNull(Pattern.compile(fixedUnicodeScriptPattern)); - - fixedUnicodeScriptPattern = (String) method.invoke(null,"(\\p{IsTibetan}){4,}+"); - assertEquals("(\\p{IsTibetan}){4,}+", fixedUnicodeScriptPattern); - assertNotNull(Pattern.compile(fixedUnicodeScriptPattern)); - - fixedUnicodeScriptPattern = (String) method.invoke(null, "(\\p{IsAlphabetic}){4}?"); - assertEquals("(\\p{IsAlphabetic}){4}?", fixedUnicodeScriptPattern); - assertNotNull(Pattern.compile(fixedUnicodeScriptPattern)); - - fixedUnicodeScriptPattern = (String) method.invoke(null, "(\\p{IsLowercase}){4,6}?"); - assertEquals("(\\p{IsLowercase}){4,6}?", fixedUnicodeScriptPattern); - assertNotNull(Pattern.compile(fixedUnicodeScriptPattern)); - - fixedUnicodeScriptPattern = (String) method.invoke(null, "(\\p{IsUppercase}){4,}?"); - assertEquals("(\\p{IsUppercase}){4,}?", fixedUnicodeScriptPattern); - assertNotNull(Pattern.compile(fixedUnicodeScriptPattern)); - - fixedUnicodeScriptPattern = (String) method.invoke(null,"(\\p{IsBasicLatin}|\\p{IsLatin-1Supplement})*"); - assertEquals("(\\p{InBasicLatin}|\\p{InLatin-1Supplement})*", fixedUnicodeScriptPattern); - assertNotNull(Pattern.compile(fixedUnicodeScriptPattern)); - - fixedUnicodeScriptPattern = (String) method.invoke(null, "(\\p{InBasicLatin}|\\p{InLatin-1Supplement})+"); - assertEquals("(\\p{InBasicLatin}|\\p{InLatin-1Supplement})+", fixedUnicodeScriptPattern); - assertNotNull(Pattern.compile(fixedUnicodeScriptPattern)); - - fixedUnicodeScriptPattern = (String) method.invoke(null, "(\\p{IsBasicLatin}|\\p{InLatin-1Supplement})?"); - assertEquals("(\\p{InBasicLatin}|\\p{InLatin-1Supplement})?", fixedUnicodeScriptPattern); - assertNotNull(Pattern.compile(fixedUnicodeScriptPattern)); - - fixedUnicodeScriptPattern = (String) method.invoke(null, "(\\p{InBasicLatin}|\\p{IsLatin-1Supplement}){4}"); - assertEquals("(\\p{InBasicLatin}|\\p{InLatin-1Supplement}){4}", fixedUnicodeScriptPattern); - assertNotNull(Pattern.compile(fixedUnicodeScriptPattern)); - - fixedUnicodeScriptPattern = (String) method.invoke(null, "(\\p{IsLatin}|\\p{IsArmenian}){2,4}"); - assertEquals("(\\p{IsLatin}|\\p{IsArmenian}){2,4}", fixedUnicodeScriptPattern); - assertNotNull(Pattern.compile(fixedUnicodeScriptPattern)); - - fixedUnicodeScriptPattern = (String) method.invoke(null, "(\\p{IsLatin}|\\p{IsBasicLatin}){2,}"); - assertEquals("(\\p{IsLatin}|\\p{InBasicLatin}){2,}", fixedUnicodeScriptPattern); - assertNotNull(Pattern.compile(fixedUnicodeScriptPattern)); - - fixedUnicodeScriptPattern = (String) method.invoke(null, "(\\p{IsBasicLatin}|\\p{IsLatin})*?"); - assertEquals("(\\p{InBasicLatin}|\\p{IsLatin})*?", fixedUnicodeScriptPattern); - assertNotNull(Pattern.compile(fixedUnicodeScriptPattern)); - - fixedUnicodeScriptPattern = (String) method.invoke(null, "(\\p{IsBasicLatin}|\\p{IsLatin-1Supplement}" + - "|\\p{IsArrows})+?"); - assertEquals("(\\p{InBasicLatin}|\\p{InLatin-1Supplement}|\\p{InArrows})+?", fixedUnicodeScriptPattern); - assertNotNull(Pattern.compile(fixedUnicodeScriptPattern)); - - fixedUnicodeScriptPattern = (String) method.invoke(null, "(\\p{InBasicLatin}|\\p{IsLatin-1Supplement}|" + - "\\p{IsLatin})??"); - assertEquals("(\\p{InBasicLatin}|\\p{InLatin-1Supplement}|\\p{IsLatin})??", fixedUnicodeScriptPattern); - assertNotNull(Pattern.compile(fixedUnicodeScriptPattern)); - - fixedUnicodeScriptPattern = (String) method.invoke(null,"(\\\\\\p{IsBasicLatin})*+"); - assertEquals("(\\\\\\p{InBasicLatin})*+", fixedUnicodeScriptPattern); - assertNotNull(Pattern.compile(fixedUnicodeScriptPattern)); - - fixedUnicodeScriptPattern = (String) method.invoke(null,"(\\\\\\\\\\p{IsBasicLatin})*+"); - assertEquals("(\\\\\\\\\\p{InBasicLatin})*+", fixedUnicodeScriptPattern); - assertNotNull(Pattern.compile(fixedUnicodeScriptPattern)); - - fixedUnicodeScriptPattern = (String) method.invoke(null,"(\\\\\\\\\\\\\\p{IsBasicLatin})*+"); - assertEquals("(\\\\\\\\\\\\\\p{InBasicLatin})*+", fixedUnicodeScriptPattern); - assertNotNull(Pattern.compile(fixedUnicodeScriptPattern)); - } - - @Test(expected = PatternSyntaxException.class) - public void testInvalidPattern() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { - Method method = ParserListenerUtils.class.getDeclaredMethod("fixUnicodeScriptPattern", String.class); - assertNotNull(method); - assertEquals("fixUnicodeScriptPattern", method.getName()); - - method.setAccessible(true); - - String fixedUnicodeScriptPattern = (String) method.invoke(null,"(\\\\p{IsBasicLatin})*+"); - assertEquals("(\\\\p{IsBasicLatin})*+", fixedUnicodeScriptPattern); - // should throw exception - Pattern.compile(fixedUnicodeScriptPattern); - } - - @Test(expected = PatternSyntaxException.class) - public void testInvalidPattern2() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { - Method method = ParserListenerUtils.class.getDeclaredMethod("fixUnicodeScriptPattern", String.class); - assertNotNull(method); - assertEquals("fixUnicodeScriptPattern", method.getName()); - - method.setAccessible(true); - - String fixedUnicodeScriptPattern = (String) method.invoke(null,"(\\p{IsSpecials}|\\\\\\\\p{IsBasicLatin})*+"); - assertEquals("(\\p{InSpecials}|\\\\\\\\p{IsBasicLatin})*+", fixedUnicodeScriptPattern); - // should throw exception - Pattern.compile(fixedUnicodeScriptPattern); - } - - @Test(expected = PatternSyntaxException.class) - public void testInvalidPattern3() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { - Method method = ParserListenerUtils.class.getDeclaredMethod("fixUnicodeScriptPattern", String.class); - assertNotNull(method); - assertEquals("fixUnicodeScriptPattern", method.getName()); - - method.setAccessible(true); - - String fixedUnicodeScriptPattern = (String) method.invoke(null,"(\\\\\\\\\\\\p{IsBasicLatin}|\\p{IsTags})*+"); - assertEquals("(\\\\\\\\\\\\p{IsBasicLatin}|\\p{IsTags})*+", fixedUnicodeScriptPattern); - // should throw exception - Pattern.compile(fixedUnicodeScriptPattern); - } -} diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/GroupingTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/GroupingTest.java deleted file mode 100644 index fc6ed21b79..0000000000 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/GroupingTest.java +++ /dev/null @@ -1,585 +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.yang.parser.impl; - -import static org.junit.Assert.assertEquals; -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 java.io.File; -import java.io.IOException; -import java.net.URI; -import java.net.URISyntaxException; -import java.text.SimpleDateFormat; -import java.util.Collection; -import java.util.Collections; -import java.util.Date; -import java.util.List; -import java.util.Map; -import java.util.Set; -import org.junit.Before; -import org.junit.Test; -import org.opendaylight.yangtools.yang.model.api.AnyXmlSchemaNode; -import org.opendaylight.yangtools.yang.model.api.AugmentationSchema; -import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode; -import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode; -import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode; -import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; -import org.opendaylight.yangtools.yang.model.api.GroupingDefinition; -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.MustDefinition; -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.UnknownSchemaNode; -import org.opendaylight.yangtools.yang.model.api.UsesNode; -import org.opendaylight.yangtools.yang.model.parser.api.YangContextParser; -import org.opendaylight.yangtools.yang.model.util.SchemaNodeUtils; - -public class GroupingTest { - private Set modules; - - @Before - public void init() throws IOException, URISyntaxException { - modules = TestUtils.loadModules(getClass().getResource("/model").toURI()); - assertEquals(3, modules.size()); - } - - @Test - public void testRefine() { - Module testModule = TestUtils.findModule(modules, "foo"); - ContainerSchemaNode peer = (ContainerSchemaNode) testModule.getDataChildByName("peer"); - ContainerSchemaNode destination = (ContainerSchemaNode) peer.getDataChildByName("destination"); - - Set usesNodes = destination.getUses(); - assertEquals(1, usesNodes.size()); - UsesNode usesNode = usesNodes.iterator().next(); - Map refines = usesNode.getRefines(); - assertEquals(4, refines.size()); - - LeafSchemaNode refineLeaf = null; - ContainerSchemaNode refineContainer = null; - ListSchemaNode refineList = null; - LeafSchemaNode refineInnerLeaf = null; - for (Map.Entry entry : refines.entrySet()) { - SchemaNode value = entry.getValue(); - if ("address".equals(value.getQName().getLocalName())) { - refineLeaf = (LeafSchemaNode) value; - } else if ("port".equals(value.getQName().getLocalName())) { - refineContainer = (ContainerSchemaNode) value; - } else if ("addresses".equals(value.getQName().getLocalName())) { - refineList = (ListSchemaNode) value; - } else if ("id".equals(value.getQName().getLocalName())) { - refineInnerLeaf = (LeafSchemaNode) value; - } - } - - // leaf address - assertNotNull(refineLeaf); - assertEquals("IP address of target node", refineLeaf.getDescription()); - assertEquals("address reference added by refine", refineLeaf.getReference()); - assertFalse(refineLeaf.isConfiguration()); - assertFalse(refineLeaf.getConstraints().isMandatory()); - Set leafMustConstraints = refineLeaf.getConstraints().getMustConstraints(); - assertEquals(1, leafMustConstraints.size()); - MustDefinition leafMust = leafMustConstraints.iterator().next(); - assertEquals("\"ifType != 'ethernet' or (ifType = 'ethernet' and ifMTU = 1500)\"", leafMust.toString()); - assertEquals(1, refineLeaf.getUnknownSchemaNodes().size()); - - // container port - assertNotNull(refineContainer); - Set mustConstraints = refineContainer.getConstraints().getMustConstraints(); - assertTrue(mustConstraints.isEmpty()); - assertEquals("description of port defined by refine", refineContainer.getDescription()); - assertEquals("port reference added by refine", refineContainer.getReference()); - assertFalse(refineContainer.isConfiguration()); - assertTrue(refineContainer.isPresenceContainer()); - - // list addresses - assertNotNull(refineList); - assertEquals("description of addresses defined by refine", refineList.getDescription()); - assertEquals("addresses reference added by refine", refineList.getReference()); - assertFalse(refineList.isConfiguration()); - assertEquals(2, (int) refineList.getConstraints().getMinElements()); - assertEquals(Integer.MAX_VALUE, (int) refineList.getConstraints().getMaxElements()); - - // leaf id - assertNotNull(refineInnerLeaf); - assertEquals("id of address", refineInnerLeaf.getDescription()); - } - - @Test - public void testGrouping() { - Module testModule = TestUtils.findModule(modules, "baz"); - Set groupings = testModule.getGroupings(); - assertEquals(1, groupings.size()); - GroupingDefinition grouping = groupings.iterator().next(); - Collection children = grouping.getChildNodes(); - assertEquals(5, children.size()); - } - - @Test - public void testUses() { - // suffix _u = added by uses - // suffix _g = defined in grouping - - Module testModule = TestUtils.findModule(modules, "baz"); - - // get grouping - Set groupings = testModule.getGroupings(); - assertEquals(1, groupings.size()); - GroupingDefinition grouping = groupings.iterator().next(); - - testModule = TestUtils.findModule(modules, "foo"); - - // get node containing uses - ContainerSchemaNode peer = (ContainerSchemaNode) testModule.getDataChildByName("peer"); - ContainerSchemaNode destination = (ContainerSchemaNode) peer.getDataChildByName("destination"); - - // check uses - Set uses = destination.getUses(); - assertEquals(1, uses.size()); - - // check uses process - AnyXmlSchemaNode data_u = (AnyXmlSchemaNode) destination.getDataChildByName("data"); - assertNotNull(data_u); - assertTrue(data_u.isAddedByUses()); - - AnyXmlSchemaNode data_g = (AnyXmlSchemaNode) grouping.getDataChildByName("data"); - assertNotNull(data_g); - assertFalse(data_g.isAddedByUses()); - assertFalse(data_u.equals(data_g)); - assertEquals(data_g, SchemaNodeUtils.getRootOriginalIfPossible(data_u)); - - ChoiceSchemaNode how_u = (ChoiceSchemaNode) destination.getDataChildByName("how"); - assertNotNull(how_u); - TestUtils.checkIsAddedByUses(how_u, true); - assertEquals(2, how_u.getCases().size()); - - ChoiceSchemaNode how_g = (ChoiceSchemaNode) grouping.getDataChildByName("how"); - assertNotNull(how_g); - TestUtils.checkIsAddedByUses(how_g, false); - assertEquals(2, how_g.getCases().size()); - assertFalse(how_u.equals(how_g)); - assertEquals(how_g, SchemaNodeUtils.getRootOriginalIfPossible(how_u)); - - LeafSchemaNode address_u = (LeafSchemaNode) destination.getDataChildByName("address"); - assertNotNull(address_u); - assertEquals("1.2.3.4", address_u.getDefault()); - assertEquals("IP address of target node", address_u.getDescription()); - assertEquals("address reference added by refine", address_u.getReference()); - assertFalse(address_u.isConfiguration()); - assertTrue(address_u.isAddedByUses()); - assertFalse(address_u.getConstraints().isMandatory()); - - LeafSchemaNode address_g = (LeafSchemaNode) grouping.getDataChildByName("address"); - assertNotNull(address_g); - assertFalse(address_g.isAddedByUses()); - assertNull(address_g.getDefault()); - assertEquals("Target IP address", address_g.getDescription()); - assertNull(address_g.getReference()); - assertTrue(address_g.isConfiguration()); - assertFalse(address_u.equals(address_g)); - assertTrue(address_g.getConstraints().isMandatory()); - assertEquals(address_g, SchemaNodeUtils.getRootOriginalIfPossible(address_u)); - - ContainerSchemaNode port_u = (ContainerSchemaNode) destination.getDataChildByName("port"); - assertNotNull(port_u); - TestUtils.checkIsAddedByUses(port_u, true); - - ContainerSchemaNode port_g = (ContainerSchemaNode) grouping.getDataChildByName("port"); - assertNotNull(port_g); - TestUtils.checkIsAddedByUses(port_g, false); - assertFalse(port_u.equals(port_g)); - assertEquals(port_g, SchemaNodeUtils.getRootOriginalIfPossible(port_u)); - - ListSchemaNode addresses_u = (ListSchemaNode) destination.getDataChildByName("addresses"); - assertNotNull(addresses_u); - TestUtils.checkIsAddedByUses(addresses_u, true); - - ListSchemaNode addresses_g = (ListSchemaNode) grouping.getDataChildByName("addresses"); - assertNotNull(addresses_g); - TestUtils.checkIsAddedByUses(addresses_g, false); - assertFalse(addresses_u.equals(addresses_g)); - assertEquals(addresses_g, SchemaNodeUtils.getRootOriginalIfPossible(addresses_u)); - - // grouping defined by 'uses' - Set groupings_u = destination.getGroupings(); - assertEquals(1, groupings_u.size()); - GroupingDefinition grouping_u = groupings_u.iterator().next(); - TestUtils.checkIsAddedByUses(grouping_u, true); - - // grouping defined in 'grouping' node - Set groupings_g = grouping.getGroupings(); - assertEquals(1, groupings_g.size()); - GroupingDefinition grouping_g = groupings_g.iterator().next(); - TestUtils.checkIsAddedByUses(grouping_g, false); - assertFalse(grouping_u.equals(grouping_g)); - - List nodes_u = destination.getUnknownSchemaNodes(); - assertEquals(1, nodes_u.size()); - UnknownSchemaNode node_u = nodes_u.get(0); - assertTrue(node_u.isAddedByUses()); - - List nodes_g = grouping.getUnknownSchemaNodes(); - assertEquals(1, nodes_g.size()); - UnknownSchemaNode node_g = nodes_g.get(0); - assertFalse(node_g.isAddedByUses()); - assertFalse(node_u.equals(node_g)); - } - - @Test - public void testUsesUnderModule() { - // suffix _u = added by uses - // suffix _g = defined in grouping - - Module testModule = TestUtils.findModule(modules, "baz"); - - // get grouping - Set groupings = testModule.getGroupings(); - assertEquals(1, groupings.size()); - GroupingDefinition grouping = groupings.iterator().next(); - - // get node containing uses - Module foo = TestUtils.findModule(modules, "foo"); - - // check uses - Set uses = foo.getUses(); - assertEquals(1, uses.size()); - - // check uses process - AnyXmlSchemaNode data_u = (AnyXmlSchemaNode) foo.getDataChildByName("data"); - assertNotNull(data_u); - assertTrue(data_u.isAddedByUses()); - - AnyXmlSchemaNode data_g = (AnyXmlSchemaNode) grouping.getDataChildByName("data"); - assertNotNull(data_g); - assertFalse(data_g.isAddedByUses()); - assertFalse(data_u.equals(data_g)); - assertEquals(data_g, SchemaNodeUtils.getRootOriginalIfPossible(data_u)); - - ChoiceSchemaNode how_u = (ChoiceSchemaNode) foo.getDataChildByName("how"); - assertNotNull(how_u); - TestUtils.checkIsAddedByUses(how_u, true); - assertFalse(how_u.isAugmenting()); - Set cases_u = how_u.getCases(); - assertEquals(2, cases_u.size()); - ChoiceCaseNode interval = how_u.getCaseNodeByName("interval"); - assertFalse(interval.isAugmenting()); - LeafSchemaNode name = (LeafSchemaNode) interval.getDataChildByName("name"); - assertTrue(name.isAugmenting()); - LeafSchemaNode intervalLeaf = (LeafSchemaNode) interval.getDataChildByName("interval"); - assertFalse(intervalLeaf.isAugmenting()); - - ChoiceSchemaNode how_g = (ChoiceSchemaNode) grouping.getDataChildByName("how"); - assertNotNull(how_g); - TestUtils.checkIsAddedByUses(how_g, false); - assertFalse(how_u.equals(how_g)); - assertEquals(how_g, SchemaNodeUtils.getRootOriginalIfPossible(how_u)); - - LeafSchemaNode address_u = (LeafSchemaNode) foo.getDataChildByName("address"); - assertNotNull(address_u); - assertNull(address_u.getDefault()); - assertEquals("Target IP address", address_u.getDescription()); - assertNull(address_u.getReference()); - assertTrue(address_u.isConfiguration()); - assertTrue(address_u.isAddedByUses()); - - LeafSchemaNode address_g = (LeafSchemaNode) grouping.getDataChildByName("address"); - assertNotNull(address_g); - assertFalse(address_g.isAddedByUses()); - assertNull(address_g.getDefault()); - assertEquals("Target IP address", address_g.getDescription()); - assertNull(address_g.getReference()); - assertTrue(address_g.isConfiguration()); - assertFalse(address_u.equals(address_g)); - assertEquals(address_g, SchemaNodeUtils.getRootOriginalIfPossible(address_u)); - - ContainerSchemaNode port_u = (ContainerSchemaNode) foo.getDataChildByName("port"); - assertNotNull(port_u); - TestUtils.checkIsAddedByUses(port_u, true); - - ContainerSchemaNode port_g = (ContainerSchemaNode) grouping.getDataChildByName("port"); - assertNotNull(port_g); - TestUtils.checkIsAddedByUses(port_g, false); - assertFalse(port_u.equals(port_g)); - assertEquals(port_g, SchemaNodeUtils.getRootOriginalIfPossible(port_u)); - - ListSchemaNode addresses_u = (ListSchemaNode) foo.getDataChildByName("addresses"); - assertNotNull(addresses_u); - TestUtils.checkIsAddedByUses(addresses_u, true); - - ListSchemaNode addresses_g = (ListSchemaNode) grouping.getDataChildByName("addresses"); - assertNotNull(addresses_g); - TestUtils.checkIsAddedByUses(addresses_g, false); - assertFalse(addresses_u.equals(addresses_g)); - assertEquals(addresses_g, SchemaNodeUtils.getRootOriginalIfPossible(addresses_u)); - - // grouping defined by 'uses' - Set groupings_u = foo.getGroupings(); - assertEquals(1, groupings_u.size()); - GroupingDefinition grouping_u = groupings_u.iterator().next(); - TestUtils.checkIsAddedByUses(grouping_u, true); - - // grouping defined in 'grouping' node - Set groupings_g = grouping.getGroupings(); - assertEquals(1, groupings_g.size()); - GroupingDefinition grouping_g = groupings_g.iterator().next(); - TestUtils.checkIsAddedByUses(grouping_g, false); - assertFalse(grouping_u.equals(grouping_g)); - - List nodes_u = foo.getUnknownSchemaNodes(); - assertEquals(1, nodes_u.size()); - UnknownSchemaNode node_u = nodes_u.get(0); - assertTrue(node_u.isAddedByUses()); - - List nodes_g = grouping.getUnknownSchemaNodes(); - assertEquals(1, nodes_g.size()); - UnknownSchemaNode node_g = nodes_g.get(0); - assertFalse(node_g.isAddedByUses()); - assertFalse(node_u.equals(node_g)); - - UsesNode un = uses.iterator().next(); - Set usesAugments = un.getAugmentations(); - assertEquals(1, usesAugments.size()); - AugmentationSchema augment = usesAugments.iterator().next(); - assertEquals("inner augment", augment.getDescription()); - Collection children = augment.getChildNodes(); - assertEquals(1, children.size()); - DataSchemaNode leaf = children.iterator().next(); - assertTrue(leaf instanceof LeafSchemaNode); - assertEquals("name", leaf.getQName().getLocalName()); - } - - @Test - public void testCascadeUses() throws Exception { - File yangFile = new File(getClass().getResource("/grouping-test/cascade-uses.yang").toURI()); - YangContextParser parser = new YangParserImpl(); - modules = parser.parseFiles(Collections.singleton(yangFile)).getModules(); - assertEquals(1, modules.size()); - - Module testModule = TestUtils.findModule(modules, "cascade-uses"); - Set groupings = testModule.getGroupings(); - - GroupingDefinition gu = null; - GroupingDefinition gv = null; - GroupingDefinition gx = null; - GroupingDefinition gy = null; - GroupingDefinition gz = null; - GroupingDefinition gzz = null; - for (GroupingDefinition gd : groupings) { - String name = gd.getQName().getLocalName(); - switch (name) { - case "grouping-U": - gu = gd; - break; - case "grouping-V": - gv = gd; - break; - case "grouping-X": - gx = gd; - break; - case "grouping-Y": - gy = gd; - break; - case "grouping-Z": - gz = gd; - break; - case "grouping-ZZ": - gzz = gd; - break; - } - } - assertNotNull(gu); - assertNotNull(gv); - assertNotNull(gx); - assertNotNull(gy); - assertNotNull(gz); - assertNotNull(gzz); - - URI expectedNS = URI.create("urn:grouping:cascade-uses"); - Date expectedRev = new SimpleDateFormat("yyyy-MM-dd").parse("2013-07-18"); - String expectedPref = "cu"; - SchemaPath expectedPath; - - // grouping-U - Collection childNodes = gu.getChildNodes(); - assertEquals(7, childNodes.size()); - - LeafSchemaNode leafGroupingU = (LeafSchemaNode) gu.getDataChildByName("leaf-grouping-U"); - assertNotNull(leafGroupingU); - assertFalse(leafGroupingU.isAddedByUses()); - assertFalse(SchemaNodeUtils.getOriginalIfPossible(leafGroupingU).isPresent()); - - for (DataSchemaNode childNode : childNodes) { - if (!(childNode.getQName().equals(leafGroupingU.getQName()))) { - TestUtils.checkIsAddedByUses(childNode, true); - } - } - - // grouping-V - childNodes = gv.getChildNodes(); - assertEquals(4, childNodes.size()); - LeafSchemaNode leafGroupingV = null; - ContainerSchemaNode containerGroupingV = null; - for (DataSchemaNode childNode : childNodes) { - if ("leaf-grouping-V".equals(childNode.getQName().getLocalName())) { - leafGroupingV = (LeafSchemaNode) childNode; - } else if ("container-grouping-V".equals(childNode.getQName().getLocalName())) { - containerGroupingV = (ContainerSchemaNode) childNode; - } else { - TestUtils.checkIsAddedByUses(childNode, true); - } - } - assertNotNull(leafGroupingV); - assertFalse(leafGroupingV.isAddedByUses()); - - // grouping-V/container-grouping-V - assertNotNull(containerGroupingV); - assertFalse(containerGroupingV.isAddedByUses()); - expectedPath = TestUtils.createPath(true, expectedNS, expectedRev, expectedPref, "grouping-V", - "container-grouping-V"); - assertEquals(expectedPath, containerGroupingV.getPath()); - childNodes = containerGroupingV.getChildNodes(); - assertEquals(2, childNodes.size()); - for (DataSchemaNode childNode : childNodes) { - TestUtils.checkIsAddedByUses(childNode, true); - } - - // grouping-V/container-grouping-V/leaf-grouping-X - LeafSchemaNode leafXinContainerV = (LeafSchemaNode) containerGroupingV.getDataChildByName("leaf-grouping-X"); - assertNotNull(leafXinContainerV); - expectedPath = TestUtils.createPath(true, expectedNS, expectedRev, expectedPref, "grouping-V", - "container-grouping-V", "leaf-grouping-X"); - assertEquals(expectedPath, leafXinContainerV.getPath()); - // grouping-V/container-grouping-V/leaf-grouping-Y - LeafSchemaNode leafYinContainerV = (LeafSchemaNode) containerGroupingV.getDataChildByName("leaf-grouping-Y"); - assertNotNull(leafYinContainerV); - expectedPath = TestUtils.createPath(true, expectedNS, expectedRev, expectedPref, "grouping-V", - "container-grouping-V", "leaf-grouping-Y"); - assertEquals(expectedPath, leafYinContainerV.getPath()); - - // grouping-X - childNodes = gx.getChildNodes(); - assertEquals(2, childNodes.size()); - - // grouping-X/leaf-grouping-X - LeafSchemaNode leafXinGX = (LeafSchemaNode) gx.getDataChildByName("leaf-grouping-X"); - assertNotNull(leafXinGX); - assertFalse(leafXinGX.isAddedByUses()); - expectedPath = TestUtils.createPath(true, expectedNS, expectedRev, expectedPref, "grouping-X", - "leaf-grouping-X"); - assertEquals(expectedPath, leafXinGX.getPath()); - - // grouping-X/leaf-grouping-Y - LeafSchemaNode leafYinGX = (LeafSchemaNode) gx.getDataChildByName("leaf-grouping-Y"); - assertNotNull(leafYinGX); - assertTrue(leafYinGX.isAddedByUses()); - expectedPath = TestUtils.createPath(true, expectedNS, expectedRev, expectedPref, "grouping-X", - "leaf-grouping-Y"); - assertEquals(expectedPath, leafYinGX.getPath()); - - // grouping-Y - childNodes = gy.getChildNodes(); - assertEquals(1, childNodes.size()); - - // grouping-Y/leaf-grouping-Y - LeafSchemaNode leafYinGY = (LeafSchemaNode) gy.getDataChildByName("leaf-grouping-Y"); - assertNotNull(leafYinGY); - assertFalse(leafYinGY.isAddedByUses()); - expectedPath = TestUtils.createPath(true, expectedNS, expectedRev, expectedPref, "grouping-Y", - "leaf-grouping-Y"); - assertEquals(expectedPath, leafYinGY.getPath()); - - // grouping-Z - childNodes = gz.getChildNodes(); - assertEquals(1, childNodes.size()); - - // grouping-Z/leaf-grouping-Z - LeafSchemaNode leafZinGZ = (LeafSchemaNode) gz.getDataChildByName("leaf-grouping-Z"); - assertNotNull(leafZinGZ); - assertFalse(leafZinGZ.isAddedByUses()); - expectedPath = TestUtils.createPath(true, expectedNS, expectedRev, expectedPref, "grouping-Z", - "leaf-grouping-Z"); - assertEquals(expectedPath, leafZinGZ.getPath()); - - // grouping-ZZ - childNodes = gzz.getChildNodes(); - assertEquals(1, childNodes.size()); - - // grouping-ZZ/leaf-grouping-ZZ - LeafSchemaNode leafZZinGZZ = (LeafSchemaNode) gzz.getDataChildByName("leaf-grouping-ZZ"); - assertNotNull(leafZZinGZZ); - assertFalse(leafZZinGZZ.isAddedByUses()); - expectedPath = TestUtils.createPath(true, expectedNS, expectedRev, expectedPref, "grouping-ZZ", - "leaf-grouping-ZZ"); - assertEquals(expectedPath, leafZZinGZZ.getPath()); - - // TEST getOriginal from grouping-U - assertEquals(gv.getDataChildByName("leaf-grouping-V"), SchemaNodeUtils.getRootOriginalIfPossible(gu.getDataChildByName("leaf-grouping-V"))); - containerGroupingV = (ContainerSchemaNode) gu.getDataChildByName("container-grouping-V"); - assertEquals(gv.getDataChildByName("container-grouping-V"), SchemaNodeUtils.getRootOriginalIfPossible(containerGroupingV)); - assertEquals(gx.getDataChildByName("leaf-grouping-X"), SchemaNodeUtils.getRootOriginalIfPossible(containerGroupingV.getDataChildByName("leaf-grouping-X") - )); - assertEquals(gy.getDataChildByName("leaf-grouping-Y"), SchemaNodeUtils.getRootOriginalIfPossible(containerGroupingV.getDataChildByName("leaf-grouping-Y") - )); - - assertEquals(gz.getDataChildByName("leaf-grouping-Z"), SchemaNodeUtils.getRootOriginalIfPossible(gu.getDataChildByName("leaf-grouping-Z"))); - assertEquals(gzz.getDataChildByName("leaf-grouping-ZZ"), SchemaNodeUtils.getRootOriginalIfPossible(gu.getDataChildByName("leaf-grouping-ZZ") - )); - - // TEST getOriginal from grouping-V - assertEquals(gz.getDataChildByName("leaf-grouping-Z"), SchemaNodeUtils.getRootOriginalIfPossible(gv.getDataChildByName("leaf-grouping-Z"))); - assertEquals(gzz.getDataChildByName("leaf-grouping-ZZ"), SchemaNodeUtils.getRootOriginalIfPossible(gv.getDataChildByName("leaf-grouping-ZZ") - )); - - // TEST getOriginal from grouping-X - assertEquals(gy.getDataChildByName("leaf-grouping-Y"),SchemaNodeUtils.getRootOriginalIfPossible( gx.getDataChildByName("leaf-grouping-Y"))); - } - - @Test - public void testAddedByUsesLeafTypeQName() throws IOException, - URISyntaxException { - - Set loadModules = TestUtils.loadModules(getClass().getResource( - "/added-by-uses-leaf-test").toURI()); - - assertEquals(2, loadModules.size()); - - Module foo = null; - Module imp = null; - for (Module module : loadModules) { - if (module.getName().equals("foo")) { - foo = module; - } - if (module.getName().equals("import-module")) { - imp = module; - } - } - - LeafSchemaNode leaf = (LeafSchemaNode) ((ContainerSchemaNode) foo - .getDataChildByName("my-container")) - .getDataChildByName("my-leaf"); - - TypeDefinition impType = null; - Set> typeDefinitions = imp.getTypeDefinitions(); - for (TypeDefinition typeDefinition : typeDefinitions) { - if (typeDefinition.getQName().getLocalName().equals("imp-type")) { - impType = typeDefinition; - break; - } - } - - assertEquals(leaf.getType().getQName(), impType.getQName()); - - } - -} diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/ListKeysTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/ListKeysTest.java deleted file mode 100644 index 41d3b08382..0000000000 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/ListKeysTest.java +++ /dev/null @@ -1,60 +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.parser.impl; - -import java.io.File; -import java.io.IOException; -import java.net.URISyntaxException; - -import org.junit.Test; -import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException; -import org.opendaylight.yangtools.yang.parser.util.YangParseException; - -public class ListKeysTest { - - @Test - public void correctListKeysTest() throws IOException, YangSyntaxErrorException, URISyntaxException { - File yangFile = new File(getClass().getResource("/list-keys-test/correct-list-keys-test.yang").toURI()); - - YangParserImpl parser = YangParserImpl.getInstance(); - parser.parseFile(yangFile, yangFile.getParentFile()); - } - - @Test(expected = YangParseException.class) - public void incorrectListKeysTest1() throws IOException, YangSyntaxErrorException, URISyntaxException { - File yangFile = new File(getClass().getResource("/list-keys-test/incorrect-list-keys-test.yang").toURI()); - - YangParserImpl parser = YangParserImpl.getInstance(); - parser.parseFile(yangFile, yangFile.getParentFile()); - } - - @Test(expected = YangParseException.class) - public void incorrectListKeysTest2() throws IOException, YangSyntaxErrorException, URISyntaxException { - File yangFile = new File(getClass().getResource("/list-keys-test/incorrect-list-keys-test2.yang").toURI()); - - YangParserImpl parser = YangParserImpl.getInstance(); - parser.parseFile(yangFile, yangFile.getParentFile()); - } - - @Test(expected = YangParseException.class) - public void incorrectListKeysTest3() throws IOException, YangSyntaxErrorException, URISyntaxException { - File yangFile = new File(getClass().getResource("/list-keys-test/incorrect-list-keys-test3.yang").toURI()); - - YangParserImpl parser = YangParserImpl.getInstance(); - parser.parseFile(yangFile, yangFile.getParentFile()); - } - - @Test(expected = YangParseException.class) - public void incorrectListKeysTest4() throws IOException, YangSyntaxErrorException, URISyntaxException { - File yangFile = new File(getClass().getResource("/list-keys-test/incorrect-list-keys-test4.yang").toURI()); - - YangParserImpl parser = YangParserImpl.getInstance(); - parser.parseFile(yangFile, yangFile.getParentFile()); - } - -} diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/OrderingTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/OrderingTest.java deleted file mode 100644 index 8aabb81fbd..0000000000 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/OrderingTest.java +++ /dev/null @@ -1,129 +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.yang.parser.impl; - -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import java.io.IOException; -import java.net.URISyntaxException; -import java.util.Collection; -import java.util.Set; -import org.junit.Test; -import org.opendaylight.yangtools.yang.model.api.AugmentationSchema; -import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode; -import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; -import org.opendaylight.yangtools.yang.model.api.GroupingDefinition; -import org.opendaylight.yangtools.yang.model.api.Module; -import org.opendaylight.yangtools.yang.model.api.TypeDefinition; - -public class OrderingTest { - - @Test - public void testOrderingTypedef() throws IOException, URISyntaxException { - Set modules = TestUtils.loadModules(getClass().getResource("/model").toURI()); - Module bar = TestUtils.findModule(modules, "bar"); - Set> typedefs = bar.getTypeDefinitions(); - String[] expectedOrder = new String[] { "int32-ext1", "int32-ext2", "invalid-string-pattern", - "multiple-pattern-string", "my-decimal-type", "my-union", "my-union-ext", "nested-union2", - "string-ext1", "string-ext2", "string-ext3", "string-ext4" }; - String[] actualOrder = new String[typedefs.size()]; - - int i = 0; - for (TypeDefinition type : typedefs) { - actualOrder[i] = type.getQName().getLocalName(); - i++; - } - assertArrayEquals(expectedOrder, actualOrder); - } - - @Test - public void testOrderingChildNodes() throws IOException, URISyntaxException { - Set modules = TestUtils.loadModules(getClass().getResource("/model").toURI()); - Module foo = TestUtils.findModule(modules, "foo"); - AugmentationSchema augment1 = null; - for (AugmentationSchema as : foo.getAugmentations()) { - if ("if:ifType='ds0'".equals(as.getWhenCondition().toString())) { - augment1 = as; - break; - } - } - assertNotNull(augment1); - - String[] expectedOrder = new String[] { "ds0ChannelNumber", "interface-id", "my-type", "schemas", "odl" }; - String[] actualOrder = new String[expectedOrder.length]; - - int i = 0; - for (DataSchemaNode augmentChild : augment1.getChildNodes()) { - actualOrder[i] = augmentChild.getQName().getLocalName(); - i++; - } - - assertArrayEquals(expectedOrder, actualOrder); - } - - @Test - public void testOrderingNestedChildNodes1() throws IOException, URISyntaxException { - Set modules = TestUtils.loadModules(getClass().getResource("/model").toURI()); - Module foo = TestUtils.findModule(modules, "foo"); - - Collection childNodes = foo.getChildNodes(); - String[] expectedOrder = new String[] { "int32-leaf", "string-leaf", "invalid-pattern-string-leaf", - "invalid-direct-string-pattern-def-leaf", "multiple-pattern-string-leaf", - "multiple-pattern-direct-string-def-leaf", "length-leaf", "decimal-leaf", "decimal-leaf2", "ext", - "union-leaf", "custom-union-leaf", "transfer", "datas", "mycont", "data", "how", "address", "port", - "addresses", "peer", "id", "foo-id","sub-ext", "sub-transfer", "sub-datas" }; - String[] actualOrder = new String[childNodes.size()]; - - int i = 0; - for (DataSchemaNode child : childNodes) { - actualOrder[i] = child.getQName().getLocalName(); - i++; - } - assertArrayEquals(expectedOrder, actualOrder); - } - - @Test - public void testOrderingNestedChildNodes2() throws IOException, URISyntaxException { - Set modules = TestUtils.loadModules(getClass().getResource("/model").toURI()); - Module baz = TestUtils.findModule(modules, "baz"); - Set groupings = baz.getGroupings(); - assertEquals(1, groupings.size()); - GroupingDefinition target = groupings.iterator().next(); - - Collection childNodes = target.getChildNodes(); - String[] expectedOrder = new String[] { "data", "how", "address", "port", "addresses" }; - String[] actualOrder = new String[childNodes.size()]; - - int i = 0; - for (DataSchemaNode child : childNodes) { - actualOrder[i] = child.getQName().getLocalName(); - i++; - } - assertArrayEquals(expectedOrder, actualOrder); - } - - @Test - public void testOrderingNestedChildNodes3() throws Exception { - Module baz = TestUtils.loadModule(getClass().getResourceAsStream("/ordering/foo.yang")); - ContainerSchemaNode x = (ContainerSchemaNode) baz.getDataChildByName("x"); - Collection childNodes = x.getChildNodes(); - - String[] expectedOrder = new String[] { "x15", "x10", "x5", "x1", "a5", "a1", "x2", "b5", "b1", "x3", "ax15", "ax5" }; - String[] actualOrder = new String[childNodes.size()]; - - int i = 0; - for (DataSchemaNode child : childNodes) { - actualOrder[i] = child.getQName().getLocalName(); - i++; - } - assertArrayEquals(expectedOrder, actualOrder); - } - -} diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/ParsingExtensionValueTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/ParsingExtensionValueTest.java deleted file mode 100644 index 404b208203..0000000000 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/ParsingExtensionValueTest.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.yang.parser.impl; - -import static org.junit.Assert.assertEquals; - -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.Set; -import org.junit.Before; -import org.junit.Test; -import org.opendaylight.yangtools.yang.model.api.Module; - -/** - * Test for testing of extensions and their arguments. - * - * @author Lukas Sedlak <lsedlak@cisco.com> - */ -public class ParsingExtensionValueTest { - - private Set modules; - - @Before - public void init() throws Exception { - DateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); - - modules = TestUtils.loadModules(getClass().getResource("/extensions").toURI()); - assertEquals(2, modules.size()); - } - - @Test - public void parsingExtensionArgsTest() { - - } -} diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/SameQNamesInChoiceTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/SameQNamesInChoiceTest.java deleted file mode 100644 index 9aef0687f9..0000000000 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/SameQNamesInChoiceTest.java +++ /dev/null @@ -1,57 +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.yang.parser.impl; - -import static org.junit.Assert.assertNotNull; - -import java.io.File; -import java.net.URI; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -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.parser.util.YangParseException; - -public class SameQNamesInChoiceTest { - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - @Test - public void testSameQNameInChoice() throws Exception { - thrown.expect(YangParseException.class); - thrown.expectMessage("Choice has two nodes case with same qnames"); - - SchemaContext context; - File yangFile = new File(getClass().getResource("/bugs/qnameDuplicity/two-same-node-in-choice/two-same-nodes-in-choice-case.yang").toURI()); - File dependenciesDir = new File(getClass().getResource("/bugs/qnameDuplicity/two-same-node-in-choice").toURI()); - YangContextParser parser = new YangParserImpl(); - context = parser.parseFile(yangFile, dependenciesDir); - - Module testModule = context.findModuleByNamespace(URI.create("urn:test:two:same-nodes-in-choice-case")).iterator().next(); - assertNotNull(testModule); - } - - - @Test - public void testAugmentedNodeIntoChoiceCase() throws Exception { - thrown.expect(YangParseException.class); - thrown.expectMessage("Choice has two nodes case with same qnames"); - - SchemaContext context; - File yangFile = new File(getClass().getResource("/bugs/qnameDuplicity/augment/two-cases.yang").toURI()); - File dependenciesDir = new File(getClass().getResource("/bugs/qnameDuplicity/augment").toURI()); - YangContextParser parser = new YangParserImpl(); - context = parser.parseFile(yangFile, dependenciesDir); - - Module testModule = context.findModuleByNamespace(URI.create("urn:test:two:cases")).iterator().next(); - assertNotNull(testModule); - } -} diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/SchemaContextTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/SchemaContextTest.java deleted file mode 100644 index b358ea8d46..0000000000 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/SchemaContextTest.java +++ /dev/null @@ -1,81 +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.yang.parser.impl; - -import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.doReturn; - -import com.google.common.collect.ImmutableSet; - -import java.net.URI; -import java.net.URISyntaxException; -import java.text.ParseException; -import java.util.Collections; -import java.util.Date; -import java.util.Map; - -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil; -import org.opendaylight.yangtools.yang.model.api.Module; -import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; - -public class SchemaContextTest { - @Mock - private Module oldModule; - - @Mock - private Module newModule; - - private Map sources; - - private URI ns; - private Date oldDate; - private Date newDate; - - @Before - public void setUp() throws ParseException, URISyntaxException { - MockitoAnnotations.initMocks(this); - - ns = new URI("http://abc"); - oldDate = SimpleDateFormatUtil.getRevisionFormat().parse("2014-07-20"); - newDate = SimpleDateFormatUtil.getRevisionFormat().parse("2014-07-22"); - - doReturn("abc").when(oldModule).getName(); - doReturn(oldDate).when(oldModule).getRevision(); - doReturn(ns).when(oldModule).getNamespace(); - doReturn("abc").when(newModule).getName(); - doReturn(newDate).when(newModule).getRevision(); - doReturn(ns).when(newModule).getNamespace(); - - sources = Collections.emptyMap(); - } - - @Test - public void testModuleOrdering() { - SchemaContext sc; - Module m; - - sc = new SchemaContextImpl(ImmutableSet.of(newModule, oldModule), sources); - m = sc.findModuleByName("abc", null); - assertEquals(newDate, m.getRevision()); - m = sc.findModuleByNamespaceAndRevision(ns, null); - assertEquals(newDate, m.getRevision()); - - sc = new SchemaContextImpl(ImmutableSet.of(oldModule, newModule), sources); - m = sc.findModuleByName("abc", null); - assertEquals(newDate, m.getRevision()); - m = sc.findModuleByNamespaceAndRevision(ns, null); - assertEquals(newDate, m.getRevision()); - } - - -} diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/TestUtils.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/TestUtils.java deleted file mode 100644 index dcbaa85a06..0000000000 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/TestUtils.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.yang.parser.impl; - -import static org.junit.Assert.assertEquals; -import com.google.common.io.ByteSource; -import com.google.common.io.ByteStreams; -import java.io.ByteArrayInputStream; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.net.URI; -import java.text.DateFormat; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Date; -import java.util.List; -import java.util.Set; -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode; -import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode; -import org.opendaylight.yangtools.yang.model.api.DataNodeContainer; -import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; -import org.opendaylight.yangtools.yang.model.api.GroupingDefinition; -import org.opendaylight.yangtools.yang.model.api.Module; -import org.opendaylight.yangtools.yang.model.api.ModuleImport; -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.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.util.NamedByteArrayInputStream; - -final class TestUtils { - - private TestUtils() { - } - - public static SchemaContext loadSchemaContext(final URI resourceDirectory) - throws IOException { - final YangContextParser parser = new YangParserImpl(); - final File testDir = new File(resourceDirectory); - final String[] fileList = testDir.list(); - final List testFiles = new ArrayList<>(); - if (fileList == null) { - throw new FileNotFoundException(resourceDirectory.toString()); - } - for (String fileName : fileList) { - testFiles.add(new File(testDir, fileName)); - } - return parser.parseFiles(testFiles); - } - - public static Set loadModules(final URI resourceDirectory) - throws IOException { - return loadSchemaContext(resourceDirectory).getModules(); - } - - public static Set loadModules(final List input) throws IOException, YangSyntaxErrorException { - Collection sources = BuilderUtils.streamsToByteSources(input); - final YangContextParser parser = new YangParserImpl(); - SchemaContext ctx = parser.parseSources(sources); - return ctx.getModules(); - } - - public static Module loadModule(final InputStream stream) throws IOException, YangSyntaxErrorException { - final YangContextParser parser = new YangParserImpl(); - ByteSource source = new ByteSource() { - @Override - public InputStream openStream() throws IOException { - return NamedByteArrayInputStream.create(stream); - } - }; - final Collection sources = Collections.singletonList(source); - SchemaContext ctx = parser.parseSources(sources); - return ctx.getModules().iterator().next(); - } - - public static Module loadModuleWithContext(final String name, final InputStream stream, final SchemaContext context) - throws IOException, YangSyntaxErrorException { - final YangContextParser parser = new YangParserImpl(); - - final byte[] streamContent = ByteStreams.toByteArray(stream); - - ByteSource source = new ByteSource() { - @Override - public InputStream openStream() throws IOException { - return new ByteArrayInputStream(streamContent); - } - }; - - final Collection sources = Collections.singletonList(source); - SchemaContext ctx = parser.parseSources(sources, context); - final Set modules = ctx.getModules(); - stream.close(); - Module result = null; - for (Module module : modules) { - if (module.getName().equals(name)) { - result = module; - break; - } - } - return result; - } - - public static Set loadModulesWithContext(final Collection input, final SchemaContext context) - throws IOException, YangSyntaxErrorException { - Collection sources = BuilderUtils.streamsToByteSources(input); - final YangContextParser parser = new YangParserImpl(); - SchemaContext ctx = parser.parseSources(sources, context); - final Set modules = ctx.getModules(); - return modules; - } - - public static Module findModule(final Set modules, final String moduleName) { - Module result = null; - for (Module module : modules) { - if (module.getName().equals(moduleName)) { - result = module; - break; - } - } - return result; - } - - public static ModuleImport findImport(final Set imports, final String prefix) { - ModuleImport result = null; - for (ModuleImport moduleImport : imports) { - if (moduleImport.getPrefix().equals(prefix)) { - result = moduleImport; - break; - } - } - return result; - } - - public static TypeDefinition findTypedef(final Set> typedefs, final String name) { - TypeDefinition result = null; - for (TypeDefinition td : typedefs) { - if (td.getQName().getLocalName().equals(name)) { - result = td; - break; - } - } - return result; - } - - public static SchemaPath createPath(final boolean absolute, final URI namespace, final Date revision, final String prefix, final String... names) { - List path = new ArrayList<>(); - for (String name : names) { - path.add(QName.create(namespace, revision, name)); - } - return SchemaPath.create(path, absolute); - } - - public static Date createDate(final String date) { - Date result; - final DateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); - try { - result = simpleDateFormat.parse(date); - } catch (ParseException e) { - result = null; - } - return result; - } - - /** - * Test if node has augmenting flag set to expected value. In case this is - * DataNodeContainer/ChoiceNode, check its child nodes/case nodes too. - * - * @param node - * node to check - * @param expected - * expected value - */ - public static void checkIsAugmenting(final DataSchemaNode node, final boolean expected) { - assertEquals(expected, node.isAugmenting()); - if (node instanceof DataNodeContainer) { - for (DataSchemaNode child : ((DataNodeContainer) node).getChildNodes()) { - checkIsAugmenting(child, expected); - } - } else if (node instanceof ChoiceSchemaNode) { - for (ChoiceCaseNode caseNode : ((ChoiceSchemaNode) node).getCases()) { - checkIsAugmenting(caseNode, expected); - } - } - } - - /** - * Check if node has addedByUses flag set to expected value. In case this is - * DataNodeContainer/ChoiceNode, check its child nodes/case nodes too. - * - * @param node - * node to check - * @param expected - * expected value - */ - public static void checkIsAddedByUses(final DataSchemaNode node, final boolean expected) { - assertEquals(expected, node.isAddedByUses()); - if (node instanceof DataNodeContainer) { - for (DataSchemaNode child : ((DataNodeContainer) node).getChildNodes()) { - checkIsAddedByUses(child, expected); - } - } else if (node instanceof ChoiceSchemaNode) { - for (ChoiceCaseNode caseNode : ((ChoiceSchemaNode) node).getCases()) { - checkIsAddedByUses(caseNode, expected); - } - } - } - - public static void checkIsAddedByUses(final GroupingDefinition node, final boolean expected) { - assertEquals(expected, node.isAddedByUses()); - for (DataSchemaNode child : ((DataNodeContainer) node).getChildNodes()) { - checkIsAddedByUses(child, expected); - } - } - - public static List findModules(final Set modules, final String moduleName) { - List result = new ArrayList<>(); - for (Module module : modules) { - if (module.getName().equals(moduleName)) { - result.add(module); - } - } - return result; - } - -} diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/TwoRevisionsTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/TwoRevisionsTest.java deleted file mode 100644 index 5e29a76719..0000000000 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/TwoRevisionsTest.java +++ /dev/null @@ -1,24 +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.yang.parser.impl; - -import static org.junit.Assert.assertEquals; - -import java.util.Set; -import org.junit.Test; -import org.opendaylight.yangtools.yang.model.api.Module; - -public class TwoRevisionsTest { - - @Test - public void testTwoRevisions() throws Exception { - Set modules = TestUtils.loadModules(getClass().getResource("/ietf").toURI()); - assertEquals(2, TestUtils.findModules(modules, "network-topology").size()); - } - -} diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/TypesResolutionTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/TypesResolutionTest.java deleted file mode 100644 index d88f88b19b..0000000000 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/TypesResolutionTest.java +++ /dev/null @@ -1,357 +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.yang.parser.impl; - -import static org.junit.Assert.assertEquals; -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 java.io.File; -import java.math.BigInteger; -import java.net.URI; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.Set; -import org.junit.Before; -import org.junit.Test; -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode; -import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode; -import org.opendaylight.yangtools.yang.model.api.Module; -import org.opendaylight.yangtools.yang.model.api.Status; -import org.opendaylight.yangtools.yang.model.api.TypeDefinition; -import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition.Bit; -import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition.EnumPair; -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.StringTypeDefinition; -import org.opendaylight.yangtools.yang.model.parser.api.YangContextParser; -import org.opendaylight.yangtools.yang.model.util.BitsType; -import org.opendaylight.yangtools.yang.model.util.EnumerationType; -import org.opendaylight.yangtools.yang.model.util.ExtendedType; -import org.opendaylight.yangtools.yang.model.util.IdentityrefType; -import org.opendaylight.yangtools.yang.model.util.InstanceIdentifierType; -import org.opendaylight.yangtools.yang.model.util.UnionType; -import org.opendaylight.yangtools.yang.parser.util.YangParseException; - -public class TypesResolutionTest { - private Set testedModules; - - @Before - public void init() throws Exception { - File yangFile = new File(getClass().getResource("/types/custom-types-test@2012-4-4.yang").toURI()); - File dependenciesDir = new File(getClass().getResource("/ietf").toURI()); - YangContextParser parser = new YangParserImpl(); - testedModules = parser.parseFile(yangFile, dependenciesDir).getModules(); - assertEquals(4, testedModules.size()); - } - - @Test - public void testIPVersion() { - Module tested = TestUtils.findModule(testedModules, "ietf-inet-types"); - Set> typedefs = tested.getTypeDefinitions(); - assertEquals(14, typedefs.size()); - - TypeDefinition type = TestUtils.findTypedef(typedefs, "ip-version"); - assertTrue(type.getDescription().contains("This value represents the version of the IP protocol.")); - assertTrue(type.getReference().contains("RFC 2460: Internet Protocol, Version 6 (IPv6) Specification")); - - EnumerationType enumType = (EnumerationType) type.getBaseType(); - List values = enumType.getValues(); - assertEquals(3, values.size()); - - EnumPair value0 = values.get(0); - assertEquals("unknown", value0.getName()); - assertEquals(0, (int) value0.getValue()); - assertEquals("An unknown or unspecified version of the Internet protocol.", value0.getDescription()); - - EnumPair value1 = values.get(1); - assertEquals("ipv4", value1.getName()); - assertEquals(1, (int) value1.getValue()); - assertEquals("The IPv4 protocol as defined in RFC 791.", value1.getDescription()); - - EnumPair value2 = values.get(2); - assertEquals("ipv6", value2.getName()); - assertEquals(2, (int) value2.getValue()); - assertEquals("The IPv6 protocol as defined in RFC 2460.", value2.getDescription()); - } - - @Test - public void testEnumeration() { - Module tested = TestUtils.findModule(testedModules, "custom-types-test"); - Set> typedefs = tested.getTypeDefinitions(); - - TypeDefinition type = TestUtils.findTypedef(typedefs, "ip-version"); - EnumerationType enumType = (EnumerationType) type.getBaseType(); - List values = enumType.getValues(); - assertEquals(4, values.size()); - - EnumPair value0 = values.get(0); - assertEquals("unknown", value0.getName()); - assertEquals(0, (int) value0.getValue()); - assertEquals("An unknown or unspecified version of the Internet protocol.", value0.getDescription()); - - EnumPair value1 = values.get(1); - assertEquals("ipv4", value1.getName()); - assertEquals(19, (int) value1.getValue()); - assertEquals("The IPv4 protocol as defined in RFC 791.", value1.getDescription()); - - EnumPair value2 = values.get(2); - assertEquals("ipv6", value2.getName()); - assertEquals(7, (int) value2.getValue()); - assertEquals("The IPv6 protocol as defined in RFC 2460.", value2.getDescription()); - - EnumPair value3 = values.get(3); - assertEquals("default", value3.getName()); - assertEquals(20, (int) value3.getValue()); - assertEquals("default ip", value3.getDescription()); - } - - @Test - public void testIpAddress() { - Module tested = TestUtils.findModule(testedModules, "ietf-inet-types"); - Set> typedefs = tested.getTypeDefinitions(); - TypeDefinition type = TestUtils.findTypedef(typedefs, "ip-address"); - UnionType baseType = (UnionType) type.getBaseType(); - List> unionTypes = baseType.getTypes(); - - ExtendedType ipv4 = (ExtendedType) unionTypes.get(0); - assertTrue(ipv4.getBaseType() instanceof StringTypeDefinition); - String expectedPattern = "^(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\.){3}" - + "([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])" + "(%[\\p{N}\\p{L}]+)?$"; - assertEquals(expectedPattern, ipv4.getPatternConstraints().get(0).getRegularExpression()); - - ExtendedType ipv6 = (ExtendedType) unionTypes.get(1); - assertTrue(ipv6.getBaseType() instanceof StringTypeDefinition); - List ipv6Patterns = ipv6.getPatternConstraints(); - expectedPattern = "^((:|[0-9a-fA-F]{0,4}):)([0-9a-fA-F]{0,4}:){0,5}" - + "((([0-9a-fA-F]{0,4}:)?(:|[0-9a-fA-F]{0,4}))|" + "(((25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\\.){3}" - + "(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])))" + "(%[\\p{N}\\p{L}]+)?$"; - assertEquals(expectedPattern, ipv6Patterns.get(0).getRegularExpression()); - - expectedPattern = "^(([^:]+:){6}(([^:]+:[^:]+)|(.*\\..*)))|" + "((([^:]+:)*[^:]+)?::(([^:]+:)*[^:]+)?)" - + "(%.+)?$"; - assertEquals(expectedPattern, ipv6Patterns.get(1).getRegularExpression()); - } - - @Test - public void testDomainName() { - Module tested = TestUtils.findModule(testedModules, "ietf-inet-types"); - Set> typedefs = tested.getTypeDefinitions(); - ExtendedType type = (ExtendedType) TestUtils.findTypedef(typedefs, "domain-name"); - assertTrue(type.getBaseType() instanceof StringTypeDefinition); - List patterns = type.getPatternConstraints(); - assertEquals(1, patterns.size()); - String expectedPattern = "^((([a-zA-Z0-9_]([a-zA-Z0-9\\-_]){0,61})?[a-zA-Z0-9]\\.)*" - + "([a-zA-Z0-9_]([a-zA-Z0-9\\-_]){0,61})?[a-zA-Z0-9]\\.?)" + "|\\.$"; - assertEquals(expectedPattern, patterns.get(0).getRegularExpression()); - - List lengths = type.getLengthConstraints(); - assertEquals(1, lengths.size()); - LengthConstraint length = type.getLengthConstraints().get(0); - assertEquals(BigInteger.ONE, length.getMin()); - assertEquals(BigInteger.valueOf(253), length.getMax()); - } - - @Test - public void testInstanceIdentifier1() { - Module tested = TestUtils.findModule(testedModules, "custom-types-test"); - LeafSchemaNode leaf = (LeafSchemaNode) tested.getDataChildByName("inst-id-leaf1"); - InstanceIdentifierType leafType = (InstanceIdentifierType) leaf.getType(); - assertFalse(leafType.requireInstance()); - assertEquals(1, leaf.getUnknownSchemaNodes().size()); - } - - @Test - public void testInstanceIdentifier2() { - Module tested = TestUtils.findModule(testedModules, "custom-types-test"); - LeafSchemaNode leaf = (LeafSchemaNode) tested.getDataChildByName("inst-id-leaf2"); - InstanceIdentifierType leafType = (InstanceIdentifierType) leaf.getType(); - assertTrue(leafType.requireInstance()); - } - - @Test - public void testIdentity() { - Module tested = TestUtils.findModule(testedModules, "custom-types-test"); - Set identities = tested.getIdentities(); - assertEquals(5, identities.size()); - IdentitySchemaNode cryptoAlg = null; - IdentitySchemaNode cryptoBase = null; - IdentitySchemaNode cryptoId = null; - for (IdentitySchemaNode id : identities) { - if (id.getQName().getLocalName().equals("crypto-alg")) { - cryptoAlg = id; - } else if ("crypto-base".equals(id.getQName().getLocalName())) { - cryptoBase = id; - } else if ("crypto-id".equals(id.getQName().getLocalName())) { - cryptoId = id; - } - } - assertNotNull(cryptoAlg); - IdentitySchemaNode baseIdentity = cryptoAlg.getBaseIdentity(); - assertEquals("crypto-base", baseIdentity.getQName().getLocalName()); - assertTrue(cryptoAlg.getDerivedIdentities().isEmpty()); - assertNull(baseIdentity.getBaseIdentity()); - - assertNotNull(cryptoBase); - assertNull(cryptoBase.getBaseIdentity()); - assertEquals(3, cryptoBase.getDerivedIdentities().size()); - - assertNotNull(cryptoId); - assertEquals(1, cryptoId.getUnknownSchemaNodes().size()); - } - - @Test - public void testBitsType1() { - Module tested = TestUtils.findModule(testedModules, "custom-types-test"); - LeafSchemaNode leaf = (LeafSchemaNode) tested.getDataChildByName("mybits"); - BitsType leafType = (BitsType) leaf.getType(); - List bits = leafType.getBits(); - assertEquals(3, bits.size()); - - Bit bit1 = bits.get(0); - assertEquals("disable-nagle", bit1.getName()); - assertEquals(0L, (long) bit1.getPosition()); - - Bit bit2 = bits.get(1); - assertEquals("auto-sense-speed", bit2.getName()); - assertEquals(1L, (long) bit2.getPosition()); - - Bit bit3 = bits.get(2); - assertEquals("10-Mb-only", bit3.getName()); - assertEquals(2L, (long) bit3.getPosition()); - } - - @Test - public void testBitsType2() { - Module tested = TestUtils.findModule(testedModules, "custom-types-test"); - Set> typedefs = tested.getTypeDefinitions(); - TypeDefinition testedType = TestUtils.findTypedef(typedefs, "access-operations-type"); - - BitsType bitsType = (BitsType) testedType.getBaseType(); - List bits = bitsType.getBits(); - assertEquals(5, bits.size()); - - Bit bit0 = bits.get(0); - assertEquals(0L, (long) bit0.getPosition()); - - Bit bit1 = bits.get(1); - assertEquals(500L, (long) bit1.getPosition()); - - Bit bit2 = bits.get(2); - assertEquals(501L, (long) bit2.getPosition()); - - Bit bit3 = bits.get(3); - assertEquals(365L, (long) bit3.getPosition()); - - Bit bit4 = bits.get(4); - assertEquals(502L, (long) bit4.getPosition()); - } - - @Test - public void testIanaTimezones() { - Module tested = TestUtils.findModule(testedModules, "iana-timezones"); - Set> typedefs = tested.getTypeDefinitions(); - TypeDefinition testedType = TestUtils.findTypedef(typedefs, "iana-timezone"); - - String expectedDesc = "A timezone location as defined by the IANA timezone"; - assertTrue(testedType.getDescription().contains(expectedDesc)); - assertTrue(testedType.getReference().isEmpty()); - assertEquals(Status.CURRENT, testedType.getStatus()); - - QName testedTypeQName = testedType.getQName(); - assertEquals(URI.create("urn:ietf:params:xml:ns:yang:iana-timezones"), testedTypeQName.getNamespace()); - assertEquals(TestUtils.createDate("2012-07-09"), testedTypeQName.getRevision()); - assertEquals("iana-timezone", testedTypeQName.getLocalName()); - - EnumerationType enumType = (EnumerationType) testedType.getBaseType(); - List values = enumType.getValues(); - assertEquals(415, values.size()); // 0-414 - - EnumPair enum168 = values.get(168); - assertEquals("America/Danmarkshavn", enum168.getName()); - assertEquals(168, (int) enum168.getValue()); - assertEquals("east coast, north of Scoresbysund", enum168.getDescription()); - - EnumPair enum374 = values.get(374); - assertEquals("America/Indiana/Winamac", enum374.getName()); - assertEquals(374, (int) enum374.getValue()); - assertEquals("Eastern Time - Indiana - Pulaski County", enum374.getDescription()); - } - - @Test - public void testObjectId128() { - Module tested = TestUtils.findModule(testedModules, "ietf-yang-types"); - Set> typedefs = tested.getTypeDefinitions(); - ExtendedType testedType = (ExtendedType) TestUtils.findTypedef(typedefs, "object-identifier-128"); - - List patterns = testedType.getPatternConstraints(); - assertEquals(1, patterns.size()); - PatternConstraint pattern = patterns.get(0); - assertEquals("^\\d*(\\.\\d*){1,127}$", pattern.getRegularExpression()); - - QName testedTypeQName = testedType.getQName(); - assertEquals(URI.create("urn:ietf:params:xml:ns:yang:ietf-yang-types"), testedTypeQName.getNamespace()); - assertEquals(TestUtils.createDate("2010-09-24"), testedTypeQName.getRevision()); - assertEquals("object-identifier-128", testedTypeQName.getLocalName()); - - ExtendedType testedTypeBase = (ExtendedType) testedType.getBaseType(); - patterns = testedTypeBase.getPatternConstraints(); - assertEquals(1, patterns.size()); - - pattern = patterns.get(0); - assertEquals("^(([0-1](\\.[1-3]?[0-9]))|(2\\.(0|([1-9]\\d*))))(\\.(0|([1-9]\\d*)))*$", - pattern.getRegularExpression()); - - QName testedTypeBaseQName = testedTypeBase.getQName(); - assertEquals(URI.create("urn:ietf:params:xml:ns:yang:ietf-yang-types"), testedTypeBaseQName.getNamespace()); - assertEquals(TestUtils.createDate("2010-09-24"), testedTypeBaseQName.getRevision()); - assertEquals("object-identifier", testedTypeBaseQName.getLocalName()); - } - - @Test - public void testIdentityref() { - Module tested = TestUtils.findModule(testedModules, "custom-types-test"); - Set> typedefs = tested.getTypeDefinitions(); - TypeDefinition testedType = TestUtils.findTypedef(typedefs, "service-type-ref"); - IdentityrefType baseType = (IdentityrefType) testedType.getBaseType(); - QName identity = baseType.getIdentity().getQName(); - assertEquals(URI.create("urn:custom.types.demo"), identity.getNamespace()); - assertEquals(TestUtils.createDate("2012-04-16"), identity.getRevision()); - assertEquals("service-type", identity.getLocalName()); - - LeafSchemaNode type = (LeafSchemaNode) tested.getDataChildByName("type"); - assertNotNull(type); - } - - @Test - public void testUnionWithExt() throws Exception { - File extdef = new File(getClass().getResource("/types/union-with-ext/extdef.yang").toURI()); - File unionbug = new File(getClass().getResource("/types/union-with-ext/unionbug.yang").toURI()); - File inet = new File(getClass().getResource("/ietf/ietf-inet-types@2010-09-24.yang").toURI()); - YangContextParser parser = new YangParserImpl(); - parser.parseFiles(Arrays.asList(extdef, unionbug, inet)); - } - - @Test - public void testUnionWithBits() throws Exception { - File unionbits = new File(getClass().getResource("/types/union-with-bits/union-bits-model.yang").toURI()); - YangContextParser parser = new YangParserImpl(); - parser.parseFiles(Collections.singletonList(unionbits)); - } - - @Test(expected = YangParseException.class) - public void testUnionInList() throws Exception { - File unioninlist = new File(getClass().getResource("/types/union-in-list/unioninlisttest.yang").toURI()); - YangContextParser parser = new YangParserImpl(); - parser.parseFiles(Collections.singletonList(unioninlist)); - } -} diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/UsesAugmentTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/UsesAugmentTest.java deleted file mode 100644 index 48ce134171..0000000000 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/UsesAugmentTest.java +++ /dev/null @@ -1,651 +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.yang.parser.impl; - -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.collect.Lists; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.net.URI; -import java.net.URISyntaxException; -import java.text.DateFormat; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Collection; -import java.util.Date; -import java.util.LinkedList; -import java.util.List; -import java.util.Set; -import org.junit.Before; -import org.junit.Test; -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode; -import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode; -import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; -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.NotificationDefinition; -import org.opendaylight.yangtools.yang.model.api.SchemaPath; -import org.opendaylight.yangtools.yang.model.api.TypeDefinition; -import org.opendaylight.yangtools.yang.model.util.BaseTypes; -import org.opendaylight.yangtools.yang.model.util.BooleanType; -import org.opendaylight.yangtools.yang.model.util.ExtendedType; -import org.opendaylight.yangtools.yang.model.util.Uint32; -import org.opendaylight.yangtools.yang.model.util.Uint8; -import org.opendaylight.yangtools.yang.model.util.UnionType; - -public class UsesAugmentTest { - private static final URI UG_NS = URI.create("urn:opendaylight:params:xml:ns:yang:uses-grouping"); - private static final URI GD_NS = URI.create("urn:opendaylight:params:xml:ns:yang:grouping-definitions"); - private Date UG_REV; - private Date GD_REV; - - private Set modules; - - @Before - public void init() throws FileNotFoundException, ParseException { - DateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); - UG_REV = simpleDateFormat.parse("2013-07-30"); - GD_REV = simpleDateFormat.parse("2013-09-04"); - } - - /** - * Structure of testing model: - * - * notification pcreq - * |-- leaf version (U) - * |-- leaf type (U) - * |-- list requests - * |-- |-- container rp - * |-- |-- |-- leaf priority (U) - * |-- |-- |-- container box (U) - * |-- |-- |-- |-- container order (A) - * |-- |-- |-- |-- |-- leaf delete (U) - * |-- |-- |-- |-- |-- |-- leaf setup (U) - * |-- |-- |-- leaf processing-rule (U) - * |-- |-- |-- leaf ignore (U) - * |-- |-- path-key-expansion - * |-- |-- |-- container path-key - * |-- |-- |-- |-- list path-keys (U) - * |-- |-- |-- |-- |-- leaf version (U) - * |-- |-- |-- |-- |-- leaf type (U) - * |-- |-- |-- |-- |-- leaf processing-rule (U) - * |-- |-- |-- |-- |-- leaf ignore (U) - * |-- |-- container segment-computation - * |-- |-- |-- container p2p - * |-- |-- |-- |-- container endpoints - * |-- |-- |-- |-- |-- leaf processing-rule (U) - * |-- |-- |-- |-- |-- leaf ignore (U) - * |-- |-- |-- |-- |-- container box (U) - * |-- |-- |-- |-- |-- choice address-family (U) - * |-- |-- |-- |-- |-- |-- case ipv4 - * |-- |-- |-- |-- |-- |-- |-- leaf source-ipv4-address - * |-- |-- |-- |-- |-- |-- case ipv6 - * |-- |-- |-- |-- |-- |-- |-- leaf source-ipv6-address - * |-- |-- |-- |-- container reported-route - * |-- |-- |-- |-- |-- container bandwidth - * |-- |-- |-- |-- |-- list subobjects(U) - * |-- |-- |-- |-- |-- leaf processing-rule (U) - * |-- |-- |-- |-- |-- leaf ignore (U) - * |-- |-- |-- |-- container bandwidth (U) - * |-- |-- |-- |-- |-- container bandwidth (U) - * |-- |-- |-- |-- |-- leaf processing-rule (U) - * |-- |-- |-- |-- |-- leaf ignore (U) - * |-- list svec - * |-- |-- list metric - * |-- |-- |-- leaf metric-type (U) - * |-- |-- |-- container box (U) - * |-- |-- |-- leaf processing-rule (U) - * |-- |-- |-- leaf ignore (U) - * |-- |-- leaf link-diverse (U) - * |-- |-- leaf processing-rule (U) - * |-- |-- leaf ignore (U) - * - * U = added by uses A = added by augment - * - * @throws Exception if exception occurs - */ - @Test - public void testAugmentInUses() throws Exception { - modules = TestUtils.loadModules(getClass().getResource("/grouping-test").toURI()); - Module testModule = TestUtils.findModule(modules, "uses-grouping"); - - LinkedList path = new LinkedList<>(); - - // * notification pcreq - Set notifications = testModule.getNotifications(); - assertEquals(1, notifications.size()); - NotificationDefinition pcreq = notifications.iterator().next(); - assertNotNull(pcreq); - QName expectedQName = QName.create(UG_NS, UG_REV, "pcreq"); - path.offer(expectedQName); - SchemaPath expectedPath = SchemaPath.create(path, true); - assertEquals(expectedPath, pcreq.getPath()); - Collection childNodes = pcreq.getChildNodes(); - assertEquals(4, childNodes.size()); - // * |-- leaf version - LeafSchemaNode version = (LeafSchemaNode) pcreq.getDataChildByName("version"); - assertNotNull(version); - expectedQName = QName.create(UG_NS, UG_REV, "version"); - path.offer(expectedQName); - expectedPath = SchemaPath.create(path, true); - assertEquals(expectedPath, version.getPath()); - expectedQName = QName.create(GD_NS, GD_REV, "protocol-version"); - path.offer(expectedQName); - expectedPath = SchemaPath.create(Lists.newArrayList(expectedQName), true); - assertEquals(expectedPath, version.getType().getPath()); - assertEquals(Uint8.getInstance(), version.getType().getBaseType()); - assertTrue(version.isAddedByUses()); - // * |-- leaf type - LeafSchemaNode type = (LeafSchemaNode) pcreq.getDataChildByName("type"); - assertNotNull(type); - expectedQName = QName.create(UG_NS, UG_REV, "type"); - assertTrue(type.isAddedByUses()); - path.pollLast(); - path.pollLast(); - path.offer(expectedQName); - expectedPath = SchemaPath.create(path, true); - assertEquals(expectedPath, type.getPath()); - expectedQName = QName.create(GD_NS, GD_REV, "int-ext"); - path.offer(expectedQName); - expectedPath = SchemaPath.create(Lists.newArrayList(expectedQName), true); - assertEquals(expectedPath, type.getType().getPath()); - UnionType union = (UnionType)type.getType().getBaseType(); - assertEquals(SchemaPath.create(true, BaseTypes.constructQName("union")), union.getPath()); - assertEquals(2, union.getTypes().size()); - // * |-- list requests - ListSchemaNode requests = (ListSchemaNode) pcreq.getDataChildByName("requests"); - assertNotNull(requests); - expectedQName = QName.create(UG_NS, UG_REV, "requests"); - assertEquals(expectedQName, requests.getQName()); - path.pollLast(); - path.pollLast(); - path.offer(expectedQName); - expectedPath = SchemaPath.create(path, true); - assertEquals(expectedPath, requests.getPath()); - assertFalse(requests.isAddedByUses()); - childNodes = requests.getChildNodes(); - assertEquals(3, childNodes.size()); - // * |-- |-- container rp - ContainerSchemaNode rp = (ContainerSchemaNode) requests.getDataChildByName("rp"); - assertNotNull(rp); - expectedQName = QName.create(UG_NS, UG_REV, "rp"); - path.offer(expectedQName); - expectedPath = SchemaPath.create(path, true); - assertEquals(expectedPath, rp.getPath()); - assertFalse(rp.isAddedByUses()); - childNodes = rp.getChildNodes(); - assertEquals(4, childNodes.size()); - // * |-- |-- |-- leaf processing-rule - LeafSchemaNode processingRule = (LeafSchemaNode) rp.getDataChildByName("processing-rule"); - assertNotNull(processingRule); - expectedQName = QName.create(UG_NS, UG_REV, "processing-rule"); - assertEquals(expectedQName, processingRule.getQName()); - path.offer(expectedQName); - expectedPath = SchemaPath.create(path, true); - assertEquals(expectedPath, processingRule.getPath()); - assertEquals(BooleanType.getInstance(), processingRule.getType()); - assertTrue(processingRule.isAddedByUses()); - // * |-- |-- |-- leaf ignore - LeafSchemaNode ignore = (LeafSchemaNode) rp.getDataChildByName("ignore"); - assertNotNull(ignore); - expectedQName = QName.create(UG_NS, UG_REV, "ignore"); - assertEquals(expectedQName, ignore.getQName()); - path.pollLast(); - path.offer(expectedQName); - expectedPath = SchemaPath.create(path, true); - assertEquals(expectedPath, ignore.getPath()); - assertEquals(BooleanType.getInstance(), ignore.getType()); - assertTrue(ignore.isAddedByUses()); - // * |-- |-- |-- leaf priority - LeafSchemaNode priority = (LeafSchemaNode) rp.getDataChildByName("priority"); - assertNotNull(priority); - expectedQName = QName.create(UG_NS, UG_REV, "priority"); - assertEquals(expectedQName, priority.getQName()); - path.pollLast(); - path.offer(expectedQName); - expectedPath = SchemaPath.create(path, true); - assertEquals(expectedPath, priority.getPath()); - expectedQName = QName.create(UG_NS, UG_REV, "uint8"); - path.offer(expectedQName); - expectedPath = SchemaPath.create(path, true); - // TODO - //assertEquals(expectedPath, priority.getType().getPath()); - assertEquals(Uint8.getInstance(), priority.getType().getBaseType()); - assertTrue(priority.isAddedByUses()); - // * |-- |-- |-- container box - ContainerSchemaNode box = (ContainerSchemaNode) rp.getDataChildByName("box"); - assertNotNull(box); - expectedQName = QName.create(UG_NS, UG_REV, "box"); - assertEquals(expectedQName, box.getQName()); - path.pollLast(); - path.pollLast(); - path.offer(expectedQName); - expectedPath = SchemaPath.create(path, true); - assertEquals(expectedPath, box.getPath()); - assertTrue(box.isAddedByUses()); - // * |-- |-- |-- |-- container order - ContainerSchemaNode order = (ContainerSchemaNode) box.getDataChildByName("order"); - assertNotNull(order); - expectedQName = QName.create(UG_NS, UG_REV, "order"); - assertEquals(expectedQName, order.getQName()); - path.offer(expectedQName); - expectedPath = SchemaPath.create(path, true); - assertEquals(expectedPath, order.getPath()); - assertTrue(order.isAddedByUses()); - assertTrue(order.isAugmenting()); - assertEquals(2, order.getChildNodes().size()); - // * |-- |-- |-- |-- |-- leaf delete - LeafSchemaNode delete = (LeafSchemaNode) order.getDataChildByName("delete"); - assertNotNull(delete); - expectedQName = QName.create(UG_NS, UG_REV, "delete"); - assertEquals(expectedQName, delete.getQName()); - path.offer(expectedQName); - expectedPath = SchemaPath.create(path, true); - assertEquals(expectedPath, delete.getPath()); - assertEquals(Uint32.getInstance(), delete.getType()); - assertTrue(delete.isAddedByUses()); - // * |-- |-- |-- |-- |-- leaf setup - LeafSchemaNode setup = (LeafSchemaNode) order.getDataChildByName("setup"); - assertNotNull(setup); - expectedQName = QName.create(UG_NS, UG_REV, "setup"); - assertEquals(expectedQName, setup.getQName()); - path.pollLast(); - path.offer(expectedQName); - expectedPath = SchemaPath.create(path, true); - assertEquals(expectedPath, setup.getPath()); - assertEquals(Uint32.getInstance(), setup.getType()); - assertTrue(setup.isAddedByUses()); - // * |-- |-- path-key-expansion - ContainerSchemaNode pke = (ContainerSchemaNode) requests.getDataChildByName("path-key-expansion"); - assertNotNull(pke); - expectedQName = QName.create(UG_NS, UG_REV, "path-key-expansion"); - assertEquals(expectedQName, pke.getQName()); - path.pollLast(); - path.pollLast(); - path.pollLast(); - path.pollLast(); - path.offer(expectedQName); - expectedPath = SchemaPath.create(path, true); - assertEquals(expectedPath, pke.getPath()); - assertFalse(pke.isAddedByUses()); - // * |-- |-- |-- path-key - ContainerSchemaNode pathKey = (ContainerSchemaNode) pke.getDataChildByName("path-key"); - assertNotNull(pathKey); - expectedQName = QName.create(UG_NS, UG_REV, "path-key"); - assertEquals(expectedQName, pathKey.getQName()); - path.offer(expectedQName); - expectedPath= SchemaPath.create(path, true); - assertEquals(expectedPath, pathKey.getPath()); - assertFalse(pathKey.isAddedByUses()); - assertEquals(3, pathKey.getChildNodes().size()); - // * |-- |-- |-- |-- leaf processing-rule - processingRule = (LeafSchemaNode) pathKey.getDataChildByName("processing-rule"); - assertNotNull(processingRule); - expectedQName = QName.create(UG_NS, UG_REV, "processing-rule"); - assertEquals(expectedQName, processingRule.getQName()); - path.offer(expectedQName); - expectedPath= SchemaPath.create(path, true); - assertEquals(expectedPath, processingRule.getPath()); - assertEquals(BooleanType.getInstance(), processingRule.getType()); - assertTrue(processingRule.isAddedByUses()); - // * |-- |-- |-- |-- leaf ignore - ignore = (LeafSchemaNode) pathKey.getDataChildByName("ignore"); - assertNotNull(ignore); - expectedQName = QName.create(UG_NS, UG_REV, "ignore"); - assertEquals(expectedQName, ignore.getQName()); - path.pollLast(); - path.offer(expectedQName); - expectedPath= SchemaPath.create(path, true); - assertEquals(expectedPath, ignore.getPath()); - assertEquals(BooleanType.getInstance(), ignore.getType()); - assertTrue(ignore.isAddedByUses()); - // * |-- |-- |-- |-- list path-keys - ListSchemaNode pathKeys = (ListSchemaNode) pathKey.getDataChildByName("path-keys"); - assertNotNull(pathKeys); - expectedQName = QName.create(UG_NS, UG_REV, "path-keys"); - assertEquals(expectedQName, pathKeys.getQName()); - path.pollLast(); - path.offer(expectedQName); - expectedPath= SchemaPath.create(path, true); - assertEquals(expectedPath, pathKeys.getPath()); - assertTrue(pathKeys.isAddedByUses()); - childNodes = pathKeys.getChildNodes(); - assertEquals(2, childNodes.size()); - // * |-- |-- |-- |-- |-- leaf version - version = (LeafSchemaNode) pathKeys.getDataChildByName("version"); - assertNotNull(version); - expectedQName = QName.create(UG_NS, UG_REV, "version"); - assertEquals(expectedQName, version.getQName()); - path.offer(expectedQName); - expectedPath= SchemaPath.create(path, true); - assertEquals(expectedPath, version.getPath()); - assertTrue(version.getType() instanceof ExtendedType); - assertEquals(Uint8.getInstance(), version.getType().getBaseType()); - assertTrue(version.isAddedByUses()); - assertTrue(version.isAugmenting()); - // * |-- |-- |-- |-- |-- leaf type - type = (LeafSchemaNode) pathKeys.getDataChildByName("type"); - assertNotNull(type); - expectedQName = QName.create(UG_NS, UG_REV, "type"); - assertEquals(expectedQName, type.getQName()); - path.pollLast(); - path.offer(expectedQName); - expectedPath= SchemaPath.create(path, true); - assertEquals(expectedPath, type.getPath()); - assertTrue(type.getType() instanceof ExtendedType); - assertTrue(type.isAddedByUses()); - assertTrue(type.isAugmenting()); - // * |-- |-- container segment-computation - ContainerSchemaNode sc = (ContainerSchemaNode) requests.getDataChildByName("segment-computation"); - assertNotNull(sc); - expectedQName = QName.create(UG_NS, UG_REV, "segment-computation"); - assertEquals(expectedQName, sc.getQName()); - path.pollLast(); - path.pollLast(); - path.pollLast(); - path.pollLast(); - path.offer(expectedQName); - expectedPath= SchemaPath.create(path, true); - assertEquals(expectedPath, sc.getPath()); - assertFalse(sc.isAddedByUses()); - // * |-- |-- |-- container p2p - ContainerSchemaNode p2p = (ContainerSchemaNode) sc.getDataChildByName("p2p"); - assertNotNull(p2p); - expectedQName = QName.create(UG_NS, UG_REV, "p2p"); - assertEquals(expectedQName, p2p.getQName()); - path.offer(expectedQName); - expectedPath= SchemaPath.create(path, true); - assertEquals(expectedPath, p2p.getPath()); - assertFalse(p2p.isAddedByUses()); - // * |-- |-- |-- |-- container endpoints - ContainerSchemaNode endpoints = (ContainerSchemaNode) p2p.getDataChildByName("endpoints"); - assertNotNull(endpoints); - expectedQName = QName.create(UG_NS, UG_REV, "endpoints"); - assertEquals(expectedQName, endpoints.getQName()); - path.offer(expectedQName); - expectedPath= SchemaPath.create(path, true); - assertEquals(expectedPath, endpoints.getPath()); - assertFalse(endpoints.isAddedByUses()); - // * |-- |-- |-- |-- |-- leaf processing-rule - processingRule = (LeafSchemaNode) endpoints.getDataChildByName("processing-rule"); - assertNotNull(processingRule); - expectedQName = QName.create(UG_NS, UG_REV, "processing-rule"); - assertEquals(expectedQName, processingRule.getQName()); - path.offer(expectedQName); - expectedPath= SchemaPath.create(path, true); - assertEquals(expectedPath, processingRule.getPath()); - assertEquals(BooleanType.getInstance(), processingRule.getType()); - assertTrue(processingRule.isAddedByUses()); - // * |-- |-- |-- |-- |-- leaf ignore - ignore = (LeafSchemaNode) endpoints.getDataChildByName("ignore"); - assertNotNull(ignore); - expectedQName = QName.create(UG_NS, UG_REV, "ignore"); - assertEquals(expectedQName, ignore.getQName()); - path.pollLast(); - path.offer(expectedQName); - expectedPath= SchemaPath.create(path, true); - assertEquals(expectedPath, ignore.getPath()); - assertEquals(BooleanType.getInstance(), ignore.getType()); - assertTrue(ignore.isAddedByUses()); - // * |-- |-- |-- |-- |-- container box - box = (ContainerSchemaNode) endpoints.getDataChildByName("box"); - assertNotNull(box); - expectedQName = QName.create(UG_NS, UG_REV, "box"); - assertEquals(expectedQName, box.getQName()); - path.pollLast(); - path.offer(expectedQName); - expectedPath= SchemaPath.create(path, true); - assertEquals(expectedPath, box.getPath()); - assertTrue(box.isAddedByUses()); - // * |-- |-- |-- |-- |-- choice address-family - ChoiceSchemaNode af = (ChoiceSchemaNode) endpoints.getDataChildByName("address-family"); - assertNotNull(af); - expectedQName = QName.create(UG_NS, UG_REV, "address-family"); - assertEquals(expectedQName, af.getQName()); - path.pollLast(); - path.offer(expectedQName); - expectedPath= SchemaPath.create(path, true); - assertEquals(expectedPath, af.getPath()); - assertTrue(af.isAddedByUses()); - // * |-- |-- |-- |-- container reported-route - ContainerSchemaNode reportedRoute = (ContainerSchemaNode) p2p.getDataChildByName("reported-route"); - assertNotNull(reportedRoute); - expectedQName = QName.create(UG_NS, UG_REV, "reported-route"); - assertEquals(expectedQName, reportedRoute.getQName()); - path.pollLast(); - path.pollLast(); - path.offer(expectedQName); - expectedPath= SchemaPath.create(path, true); - assertEquals(expectedPath, reportedRoute.getPath()); - assertFalse(reportedRoute.isAddedByUses()); - // * |-- |-- |-- |-- |-- leaf processing-rule - processingRule = (LeafSchemaNode) reportedRoute.getDataChildByName("processing-rule"); - assertNotNull(processingRule); - expectedQName = QName.create(UG_NS, UG_REV, "processing-rule"); - assertEquals(expectedQName, processingRule.getQName()); - path.offer(expectedQName); - expectedPath= SchemaPath.create(path, true); - assertEquals(expectedPath, processingRule.getPath()); - assertEquals(BooleanType.getInstance(), processingRule.getType()); - assertTrue(processingRule.isAddedByUses()); - // * |-- |-- |-- |-- |-- leaf ignore - ignore = (LeafSchemaNode) reportedRoute.getDataChildByName("ignore"); - assertNotNull(ignore); - expectedQName = QName.create(UG_NS, UG_REV, "ignore"); - assertEquals(expectedQName, ignore.getQName()); - path.pollLast(); - path.offer(expectedQName); - expectedPath= SchemaPath.create(path, true); - assertEquals(expectedPath, ignore.getPath()); - assertEquals(BooleanType.getInstance(), ignore.getType()); - assertTrue(ignore.isAddedByUses()); - // * |-- |-- |-- |-- |-- list subobjects - ListSchemaNode subobjects = (ListSchemaNode) reportedRoute.getDataChildByName("subobjects"); - assertNotNull(subobjects); - expectedQName = QName.create(UG_NS, UG_REV, "subobjects"); - assertEquals(expectedQName, subobjects.getQName()); - path.pollLast(); - path.offer(expectedQName); - expectedPath= SchemaPath.create(path, true); - assertEquals(expectedPath, subobjects.getPath()); - assertTrue(subobjects.isAddedByUses()); - // * |-- |-- |-- |-- |-- container bandwidth - ContainerSchemaNode bandwidth = (ContainerSchemaNode) reportedRoute.getDataChildByName("bandwidth"); - assertNotNull(bandwidth); - expectedQName = QName.create(UG_NS, UG_REV, "bandwidth"); - assertEquals(expectedQName, bandwidth.getQName()); - path.pollLast(); - path.offer(expectedQName); - expectedPath= SchemaPath.create(path, true); - assertEquals(expectedPath, bandwidth.getPath()); - assertFalse(bandwidth.isAddedByUses()); - // * |-- |-- |-- |-- container bandwidth - bandwidth = (ContainerSchemaNode) p2p.getDataChildByName("bandwidth"); - assertNotNull(bandwidth); - expectedQName = QName.create(UG_NS, UG_REV, "bandwidth"); - assertEquals(expectedQName, bandwidth.getQName()); - path.pollLast(); - path.pollLast(); - path.offer(expectedQName); - expectedPath= SchemaPath.create(path, true); - assertEquals(expectedPath, bandwidth.getPath()); - assertTrue(bandwidth.isAddedByUses()); - // * |-- |-- |-- |-- |-- leaf processing-rule - processingRule = (LeafSchemaNode) bandwidth.getDataChildByName("processing-rule"); - assertNotNull(processingRule); - expectedQName = QName.create(UG_NS, UG_REV, "processing-rule"); - assertEquals(expectedQName, processingRule.getQName()); - path.offer(expectedQName); - expectedPath= SchemaPath.create(path, true); - assertEquals(expectedPath, processingRule.getPath()); - assertEquals(BooleanType.getInstance(), processingRule.getType()); - assertTrue(processingRule.isAddedByUses()); - // * |-- |-- |-- |-- |-- leaf ignore - ignore = (LeafSchemaNode) bandwidth.getDataChildByName("ignore"); - assertNotNull(ignore); - expectedQName = QName.create(UG_NS, UG_REV, "ignore"); - assertEquals(expectedQName, ignore.getQName()); - path.pollLast(); - path.offer(expectedQName); - expectedPath= SchemaPath.create(path, true); - assertEquals(expectedPath, ignore.getPath()); - assertEquals(BooleanType.getInstance(), ignore.getType()); - assertTrue(ignore.isAddedByUses()); - // * |-- |-- |-- |-- |-- container bandwidth - ContainerSchemaNode bandwidthInner = (ContainerSchemaNode) bandwidth.getDataChildByName("bandwidth"); - assertNotNull(bandwidthInner); - expectedQName = QName.create(UG_NS, UG_REV, "bandwidth"); - assertEquals(expectedQName, bandwidth.getQName()); - path.pollLast(); - path.offer(expectedQName); - expectedPath= SchemaPath.create(path, true); - assertEquals(expectedPath, bandwidthInner.getPath()); - assertTrue(bandwidthInner.isAddedByUses()); - // * |-- list svec - ListSchemaNode svec = (ListSchemaNode) pcreq.getDataChildByName("svec"); - assertNotNull(svec); - expectedQName = QName.create(UG_NS, UG_REV, "svec"); - assertEquals(expectedQName, svec.getQName()); - path.pollLast(); - path.pollLast(); - path.pollLast(); - path.pollLast(); - path.pollLast(); - path.offer(expectedQName); - expectedPath= SchemaPath.create(path, true); - assertEquals(expectedPath, svec.getPath()); - assertFalse(svec.isAddedByUses()); - // * |-- |-- leaf link-diverse - LeafSchemaNode linkDiverse = (LeafSchemaNode) svec.getDataChildByName("link-diverse"); - assertNotNull(linkDiverse); - expectedQName = QName.create(UG_NS, UG_REV, "link-diverse"); - assertEquals(expectedQName, linkDiverse.getQName()); - path.offer(expectedQName); - expectedPath= SchemaPath.create(path, true); - assertEquals(expectedPath, linkDiverse.getPath()); - assertEquals(BooleanType.getInstance(), linkDiverse.getType()); - assertTrue(linkDiverse.isAddedByUses()); - // * |-- |-- leaf processing-rule - processingRule = (LeafSchemaNode) svec.getDataChildByName("processing-rule"); - assertNotNull(processingRule); - expectedQName = QName.create(UG_NS, UG_REV, "processing-rule"); - assertEquals(expectedQName, processingRule.getQName()); - path.pollLast(); - path.offer(expectedQName); - expectedPath= SchemaPath.create(path, true); - assertEquals(expectedPath, processingRule.getPath()); - assertEquals(BooleanType.getInstance(), processingRule.getType()); - assertTrue(processingRule.isAddedByUses()); - // * |-- |-- leaf ignore - ignore = (LeafSchemaNode) svec.getDataChildByName("ignore"); - assertNotNull(ignore); - expectedQName = QName.create(UG_NS, UG_REV, "ignore"); - assertEquals(expectedQName, ignore.getQName()); - path.pollLast(); - path.offer(expectedQName); - expectedPath= SchemaPath.create(path, true); - assertEquals(expectedPath, ignore.getPath()); - assertEquals(BooleanType.getInstance(), ignore.getType()); - assertTrue(ignore.isAddedByUses()); - // * |-- |-- list metric - ListSchemaNode metric = (ListSchemaNode) svec.getDataChildByName("metric"); - assertNotNull(metric); - expectedQName = QName.create(UG_NS, UG_REV, "metric"); - assertEquals(expectedQName, metric.getQName()); - path.pollLast(); - path.offer(expectedQName); - expectedPath= SchemaPath.create(path, true); - assertEquals(expectedPath, metric.getPath()); - assertFalse(metric.isAddedByUses()); - // * |-- |-- |-- leaf metric-type - LeafSchemaNode metricType = (LeafSchemaNode) metric.getDataChildByName("metric-type"); - assertNotNull(metricType); - expectedQName = QName.create(UG_NS, UG_REV, "metric-type"); - assertEquals(expectedQName, metricType.getQName()); - path.offer(expectedQName); - expectedPath= SchemaPath.create(path, true); - assertEquals(expectedPath, metricType.getPath()); - assertEquals(Uint8.getInstance(), metricType.getType()); - assertTrue(metricType.isAddedByUses()); - // * |-- |-- |-- box - box = (ContainerSchemaNode) metric.getDataChildByName("box"); - assertNotNull(box); - expectedQName = QName.create(UG_NS, UG_REV, "box"); - assertEquals(expectedQName, box.getQName()); - path.pollLast(); - path.offer(expectedQName); - expectedPath= SchemaPath.create(path, true); - assertEquals(expectedPath, box.getPath()); - assertTrue(box.isAddedByUses()); - // * |-- |-- |-- leaf processing-rule - processingRule = (LeafSchemaNode) metric.getDataChildByName("processing-rule"); - assertNotNull(processingRule); - expectedQName = QName.create(UG_NS, UG_REV, "processing-rule"); - assertEquals(expectedQName, processingRule.getQName()); - path.pollLast(); - path.offer(expectedQName); - expectedPath= SchemaPath.create(path, true); - assertEquals(expectedPath, processingRule.getPath()); - assertEquals(BooleanType.getInstance(), processingRule.getType()); - assertTrue(processingRule.isAddedByUses()); - // * |-- |-- |-- leaf ignore - ignore = (LeafSchemaNode) metric.getDataChildByName("ignore"); - assertNotNull(ignore); - expectedQName = QName.create(UG_NS, UG_REV, "ignore"); - assertEquals(expectedQName, ignore.getQName()); - path.pollLast(); - path.offer(expectedQName); - expectedPath= SchemaPath.create(path, true); - assertEquals(expectedPath, ignore.getPath()); - assertEquals(BooleanType.getInstance(), ignore.getType()); - assertTrue(ignore.isAddedByUses()); - } - - @Test - public void testTypedefs() throws IOException, URISyntaxException { - modules = TestUtils.loadModules(getClass().getResource("/grouping-test").toURI()); - Module testModule = TestUtils.findModule(modules, "grouping-definitions"); - Set> types = testModule.getTypeDefinitions(); - - TypeDefinition intExt = null; - for(TypeDefinition td : types) { - if("int-ext".equals(td.getQName().getLocalName())) { - intExt = td; - } - } - assertNotNull(intExt); - - List path = Lists.newArrayList(QName.create(GD_NS, GD_REV, "int-ext")); - SchemaPath expectedPath = SchemaPath.create(path, true); - assertEquals(expectedPath, intExt.getPath()); - - UnionType union = (UnionType)intExt.getBaseType(); - - TypeDefinition uint8 = null; - TypeDefinition pv = null; - for(TypeDefinition td : union.getTypes()) { - if("uint8".equals(td.getQName().getLocalName())) { - uint8 = td; - } else if("protocol-version".equals(td.getQName().getLocalName())) { - pv = td; - } - } - assertNotNull(uint8); - assertNotNull(pv); - - QName q1 = BaseTypes.constructQName("union"); - expectedPath = SchemaPath.create(Lists.newArrayList(q1), true); - assertEquals(expectedPath, union.getPath()); - } - -} diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/YangModelValidationListTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/YangModelValidationListTest.java deleted file mode 100644 index b4fab3b81a..0000000000 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/YangModelValidationListTest.java +++ /dev/null @@ -1,110 +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.yang.parser.impl; - -import static org.hamcrest.CoreMatchers.containsString; -import static org.junit.Assert.assertThat; - -import org.junit.Before; -import org.junit.Test; -import org.opendaylight.yangtools.antlrv4.code.gen.YangParser.Default_stmtContext; -import org.opendaylight.yangtools.antlrv4.code.gen.YangParser.Key_stmtContext; -import org.opendaylight.yangtools.antlrv4.code.gen.YangParser.Leaf_stmtContext; -import org.opendaylight.yangtools.antlrv4.code.gen.YangParser.List_stmtContext; -import org.opendaylight.yangtools.antlrv4.code.gen.YangParser.Mandatory_stmtContext; -import org.opendaylight.yangtools.antlrv4.code.gen.YangParser.Ordered_by_argContext; -import org.opendaylight.yangtools.antlrv4.code.gen.YangParser.Type_stmtContext; -import org.opendaylight.yangtools.antlrv4.code.gen.YangParser.Unique_stmtContext; -import org.opendaylight.yangtools.yang.parser.util.YangValidationException; - -public class YangModelValidationListTest { - - private YangModelBasicValidationListener valid; - - @Before - public void setUp() { - valid = new YangModelBasicValidationListener(); - } - - @Test(expected = YangValidationException.class) - public void testKeyValidationDuplicates() { - - List_stmtContext list = YangModelValidationTest.mockStatement( - List_stmtContext.class, "list"); - Key_stmtContext key = YangModelValidationTest.mockStatement( - Key_stmtContext.class, "leaf1 leaf2 leaf1 leaf1"); - YangModelValidationTest.addChild(list, key); - - try { - valid.enterKey_stmt(key); - } catch (YangValidationException e) { - assertThat(e.getMessage(), - containsString("contains duplicates:[leaf1]")); - throw e; - } - } - - @Test(expected = YangValidationException.class) - public void testUniqueValidationDuplicates() { - List_stmtContext list = YangModelValidationTest.mockStatement( - List_stmtContext.class, "list"); - Unique_stmtContext unique = YangModelValidationTest.mockStatement( - Unique_stmtContext.class, "leaf1/a leaf2/n leaf1/a leaf1"); - YangModelValidationTest.addChild(list, unique); - - try { - valid.enterUnique_stmt(unique); - } catch (YangValidationException e) { - assertThat(e.getMessage(), - containsString("contains duplicates:[leaf1/a]")); - throw e; - } - } - - @Test(expected = YangValidationException.class) - public void testOrderBy() { - Ordered_by_argContext ctx = YangModelValidationTest.mockStatement( - Ordered_by_argContext.class, "unknown"); - - try { - valid.enterOrdered_by_arg(ctx); - } catch (YangValidationException e) { - assertThat( - e.getMessage(), - containsString("Ordered-by:unknown, illegal value for Ordered-by statement, only permitted:")); - throw e; - } - } - - @Test(expected = YangValidationException.class) - public void testLeaf() { - Leaf_stmtContext ctx = YangModelValidationTest.mockStatement( - Leaf_stmtContext.class, "leaf1"); - Default_stmtContext def = YangModelValidationTest.mockStatement( - Default_stmtContext.class, "default"); - YangModelValidationTest.addChild(ctx, def); - Type_stmtContext typ = YangModelValidationTest.mockStatement( - Type_stmtContext.class, "type"); - YangModelValidationTest.addChild(ctx, def); - YangModelValidationTest.addChild(ctx, typ); - - Mandatory_stmtContext mand = YangModelValidationTest.mockStatement( - Mandatory_stmtContext.class, null); - YangModelValidationTest.addChild(ctx, mand); - - try { - valid.enterLeaf_stmt(ctx); - } catch (YangValidationException e) { - assertThat( - e.getMessage(), - containsString("Both Mandatory and Default statement present")); - throw e; - } - } - -} diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/YangModelValidationModuleTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/YangModelValidationModuleTest.java deleted file mode 100644 index 47dce2c29a..0000000000 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/YangModelValidationModuleTest.java +++ /dev/null @@ -1,177 +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.yang.parser.impl; - -import static org.hamcrest.CoreMatchers.containsString; -import static org.junit.Assert.assertThat; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.mock; - -import org.junit.Before; -import org.junit.Test; -import org.opendaylight.yangtools.antlrv4.code.gen.YangParser.Module_header_stmtsContext; -import org.opendaylight.yangtools.antlrv4.code.gen.YangParser.Module_stmtContext; -import org.opendaylight.yangtools.antlrv4.code.gen.YangParser.Namespace_stmtContext; -import org.opendaylight.yangtools.antlrv4.code.gen.YangParser.Revision_stmtContext; -import org.opendaylight.yangtools.antlrv4.code.gen.YangParser.Revision_stmtsContext; -import org.opendaylight.yangtools.antlrv4.code.gen.YangParser.Yang_version_stmtContext; -import org.opendaylight.yangtools.yang.parser.util.YangValidationException; - -public class YangModelValidationModuleTest { - - private YangModelBasicValidationListener valid; - - @Before - public void setUp() { - valid = new YangModelBasicValidationListener(); - } - - @Test(expected = YangValidationException.class) - public void testRevisionInvalidDateFormat() { - Revision_stmtContext mockedRev = mockModuleWithRevision("badFormat", - "module1"); - - try { - valid.enterRevision_stmt(mockedRev); - } catch (YangValidationException e) { - assertThat( - e.getMessage(), - containsString("Revision:badFormat, invalid date format expected date format is:")); - throw e; - } - } - - @Test - public void testRevisionValidDateFormat() { - Revision_stmtContext mockedRev = mockModuleWithRevision( - YangModelValidationTest.getFormattedDate(), "module1"); - - valid.enterRevision_stmt(mockedRev); - } - - @Test(expected = YangValidationException.class) - public void testNoHeaderStmts() { - Revision_stmtContext rev = mockModuleWithRevision("1999-4-5", "module1"); - - try { - valid.enterModule_stmt((Module_stmtContext) rev.getParent() - .getParent()); - } catch (YangValidationException e) { - assertThat( - e.getMessage(), - containsString("Missing Module-header statement in Module:module1")); - throw e; - } - } - - @Test(expected = YangValidationException.class) - public void testMultipleModulesPerSession() { - Module_stmtContext module1 = (Module_stmtContext) mockModuleWithRevision( - "1999-09-10", "m1").getParent().getParent(); - YangModelValidationTest.addChild(module1, YangModelValidationTest - .mockStatement(Namespace_stmtContext.class, "")); - - Module_stmtContext module2 = (Module_stmtContext) mockModuleWithRevision( - "1999-09-10", "m2").getParent().getParent(); - YangModelValidationTest.addChild(module1, YangModelValidationTest - .mockStatement(Namespace_stmtContext.class, "")); - valid.enterModule_stmt(module1); - - try { - valid.enterModule_stmt(module2); - } catch (YangValidationException e) { - assertThat(e.getMessage(), - containsString("Multiple (sub)modules per file")); - throw e; - } - } - - @Test(expected = YangValidationException.class) - public void testNoNamespace() { - Module_header_stmtsContext header = YangModelValidationTest - .mockStatement(Module_header_stmtsContext.class, null); - Module_stmtContext mod = YangModelValidationTest.mockStatement( - Module_stmtContext.class, "module1"); - YangModelValidationTest.addChild(mod, header); - - try { - valid.enterModule_header_stmts(header); - } catch (YangValidationException e) { - assertThat( - e.getMessage(), - containsString("Missing Namespace statement in Module-header:")); - throw e; - } - } - - @Test(expected = YangValidationException.class) - public void testNoPrefix() { - Module_header_stmtsContext header = YangModelValidationTest - .mockStatement(Module_header_stmtsContext.class, null); - Namespace_stmtContext nmspc = YangModelValidationTest.mockStatement( - Namespace_stmtContext.class, "http://test"); - Module_stmtContext mod = YangModelValidationTest.mockStatement( - Module_stmtContext.class, "module1"); - YangModelValidationTest.addChild(mod, header); - YangModelValidationTest.addChild(header, nmspc); - - try { - valid.enterModule_header_stmts(header); - } catch (YangValidationException e) { - assertThat( - e.getMessage(), - containsString("Missing Prefix statement in Module-header:")); - throw e; - } - } - - @Test(expected = YangValidationException.class) - public void testInvalidYangVersion() { - - Yang_version_stmtContext yangVersion = YangModelValidationTest - .mockStatement(Yang_version_stmtContext.class, "55Unsup"); - - Module_stmtContext mod = YangModelValidationTest.mockStatement( - Module_stmtContext.class, "module1"); - YangModelValidationTest.addChild(mod, yangVersion); - - try { - valid.enterYang_version_stmt(yangVersion); - } catch (YangValidationException e) { - assertThat( - e.getMessage(), - containsString("Unsupported yang version:55Unsup, supported version:" - + BasicValidations.SUPPORTED_YANG_VERSION)); - throw e; - } - } - - @Test - public void testValidYangVersion() { - - Yang_version_stmtContext ctx = mock(Yang_version_stmtContext.class); - doReturn(1).when(ctx).getChildCount(); - YangModelValidationTest.mockName(ctx, "1"); - - valid.enterYang_version_stmt(ctx); - } - - private static Revision_stmtContext mockModuleWithRevision(final String date, - final String moduleName) { - Revision_stmtContext mockedRev = YangModelValidationTest.mockStatement( - Revision_stmtContext.class, date); - Revision_stmtsContext revs = YangModelValidationTest.mockStatement( - Revision_stmtsContext.class, null); - Module_stmtContext mod = YangModelValidationTest.mockStatement( - Module_stmtContext.class, moduleName); - - YangModelValidationTest.addChild(revs, mockedRev); - YangModelValidationTest.addChild(mod, revs); - return mockedRev; - } -} diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/YangModelValidationSubModuleTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/YangModelValidationSubModuleTest.java deleted file mode 100644 index 9d5bb19e09..0000000000 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/YangModelValidationSubModuleTest.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.yang.parser.impl; - -import static org.hamcrest.CoreMatchers.containsString; -import static org.junit.Assert.assertThat; -import static org.mockito.Mockito.mock; -import org.antlr.v4.runtime.tree.ParseTree; -import org.junit.Before; -import org.junit.Test; -import org.opendaylight.yangtools.antlrv4.code.gen.YangParser.Belongs_to_stmtContext; -import org.opendaylight.yangtools.antlrv4.code.gen.YangParser.Submodule_header_stmtsContext; -import org.opendaylight.yangtools.antlrv4.code.gen.YangParser.Submodule_stmtContext; -import org.opendaylight.yangtools.yang.parser.util.YangValidationException; - -public class YangModelValidationSubModuleTest { - - private YangModelBasicValidationListener valid; - - @Before - public void setUp() { - valid = new YangModelBasicValidationListener(); - } - - @Test(expected = YangValidationException.class) - public void testNoRevision() { - - Submodule_stmtContext ctx = YangModelValidationTest.mockStatement( - Submodule_stmtContext.class, "submodule1"); - - try { - valid.enterSubmodule_stmt(ctx); - } catch (YangValidationException e) { - assertThat( - e.getMessage(), - containsString("Missing Submodule-header statement in Submodule:submodule")); - throw e; - } - } - - @Test(expected = YangValidationException.class) - public void testNoBelongsTo() { - Submodule_header_stmtsContext header = mock(Submodule_header_stmtsContext.class); - mockSubmoduleParent(header, "submodule"); - - try { - valid.enterSubmodule_header_stmts(header); - } catch (YangValidationException e) { - assertThat( - e.getMessage(), - containsString("Missing Belongs-to statement in Submodule-header:")); - throw e; - } - } - - @Test(expected = YangValidationException.class) - public void testBelongsToNoPrefix() { - Belongs_to_stmtContext belongsTo = YangModelValidationTest - .mockStatement(Belongs_to_stmtContext.class, "supermodule"); - - mockSubmoduleParent(belongsTo, "submodule"); - - try { - valid.enterBelongs_to_stmt(belongsTo); - } catch (YangValidationException e) { - assertThat( - e.getMessage(), - containsString("Missing Prefix statement in Belongs-to:supermodule")); - throw e; - } - } - - private static Submodule_stmtContext mockSubmoduleParent(final ParseTree child, - final String moduleName) { - Submodule_stmtContext ctx = YangModelValidationTest.mockStatement( - Submodule_stmtContext.class, moduleName); - YangModelValidationTest.addChild(ctx, child); - return ctx; - } -} diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/YangModelValidationTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/YangModelValidationTest.java deleted file mode 100644 index 1fb4303b02..0000000000 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/YangModelValidationTest.java +++ /dev/null @@ -1,272 +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.yang.parser.impl; - -import static org.hamcrest.CoreMatchers.containsString; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; -import com.google.common.collect.Sets; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Date; -import java.util.HashSet; -import java.util.List; -import org.antlr.v4.runtime.Token; -import org.antlr.v4.runtime.tree.ParseTree; -import org.antlr.v4.runtime.tree.TerminalNode; -import org.junit.Before; -import org.junit.Test; -import org.opendaylight.yangtools.antlrv4.code.gen.YangParser.Augment_stmtContext; -import org.opendaylight.yangtools.antlrv4.code.gen.YangParser.Deviate_add_stmtContext; -import org.opendaylight.yangtools.antlrv4.code.gen.YangParser.Deviate_delete_stmtContext; -import org.opendaylight.yangtools.antlrv4.code.gen.YangParser.Deviation_stmtContext; -import org.opendaylight.yangtools.antlrv4.code.gen.YangParser.Import_stmtContext; -import org.opendaylight.yangtools.antlrv4.code.gen.YangParser.Include_stmtContext; -import org.opendaylight.yangtools.antlrv4.code.gen.YangParser.Module_stmtContext; -import org.opendaylight.yangtools.antlrv4.code.gen.YangParser.Namespace_stmtContext; -import org.opendaylight.yangtools.antlrv4.code.gen.YangParser.Prefix_stmtContext; -import org.opendaylight.yangtools.antlrv4.code.gen.YangParser.Revision_date_stmtContext; -import org.opendaylight.yangtools.antlrv4.code.gen.YangParser.Status_argContext; -import org.opendaylight.yangtools.antlrv4.code.gen.YangParser.StringContext; -import org.opendaylight.yangtools.yang.parser.util.YangValidationException; - -public class YangModelValidationTest { - - private YangModelBasicValidationListener valid; - - @Before - public void setUp() { - - valid = new YangModelBasicValidationListener(); - } - - @Test - public void testPrefixes() { - Prefix_stmtContext pref = mockStatement(Prefix_stmtContext.class, "unique1"); - Module_stmtContext module = mockStatement(Module_stmtContext.class, "module1"); - addChild(module, pref); - - valid.enterPrefix_stmt(pref); - - pref = mockStatement(Prefix_stmtContext.class, "unique1"); - module = mockStatement(Module_stmtContext.class, "module1"); - addChild(module, pref); - - try { - valid.enterPrefix_stmt(pref); - } catch (Exception e) { - return; - } - - fail("Validation Exception should have occured"); - } - - @Test - public void testNamespace() { - - Namespace_stmtContext namespace = mockStatement(Namespace_stmtContext.class, "http://test.parsing.uri.com"); - Module_stmtContext module = mockStatement(Module_stmtContext.class, "module1"); - addChild(module, namespace); - - valid.enterNamespace_stmt(namespace); - - namespace = mockStatement(Namespace_stmtContext.class, "invalid uri"); - module = mockStatement(Module_stmtContext.class, "module1"); - addChild(module, namespace); - - try { - valid.enterNamespace_stmt(namespace); - } catch (YangValidationException e) { - assertThat(e.getMessage(), containsString("Namespace:invalid uri cannot be parsed as URI")); - return; - } - - fail("Validation Exception should have occured"); - } - - @Test - public void testImports() { - Import_stmtContext impor = mockImport("unique1", "p1"); - Module_stmtContext mod = mockStatement(Module_stmtContext.class, "module1"); - addChild(mod, impor); - - valid.enterImport_stmt(impor); - - impor = mockImport("unique1", "p2"); - mod = mockStatement(Module_stmtContext.class, "module1"); - addChild(mod, impor); - - try { - valid.enterImport_stmt(impor); - } catch (YangValidationException e) { - assertThat(e.getMessage(), containsString("Import:unique1 not unique")); - return; - } - - fail("Validation Exception should have occured"); - } - - @Test - public void testIncludes() { - Include_stmtContext incl = mockInclude("unique1"); - Module_stmtContext mod = mockStatement(Module_stmtContext.class, "module1"); - addChild(mod, incl); - valid.enterInclude_stmt(incl); - - incl = mockInclude("unique1"); - mod = mockStatement(Module_stmtContext.class, "module1"); - addChild(mod, incl); - - try { - valid.enterInclude_stmt(incl); - } catch (YangValidationException e) { - assertThat(e.getMessage(), containsString("Include:unique1 not unique in (sub)module")); - return; - } - - fail("Validation Exception should have occured"); - } - - @Test - public void testIdentifierMatching() { - List ids = new ArrayList<>(); - // valid - ids.add("_ok98-.87.-.8...88-asdAD"); - ids.add("AA.bcd"); - ids.add("a"); - // invalid - ids.add("9aa"); - ids.add("-"); - ids.add("."); - - int thrown = 0; - for (String id : ids) { - try { - Module_stmtContext module = mock(Module_stmtContext.class); - Token token = mock(Token.class); - when(module.getStart()).thenReturn(token); - BasicValidations.checkIdentifierInternal(module, id); - } catch (YangValidationException e) { - thrown++; - } - } - - assertEquals(3, thrown); - } - - @Test(expected = YangValidationException.class) - public void testAugument() { - Augment_stmtContext augument = mockStatement(Augment_stmtContext.class, "/a:*abc/a:augument1"); - Module_stmtContext mod1 = mockStatement(Module_stmtContext.class, "mod1"); - addChild(mod1, augument); - - Token token = mock(Token.class); - when(augument.getStart()).thenReturn(token); - - try { - valid.enterAugment_stmt(augument); - } catch (YangValidationException e) { - assertThat( - e.getMessage(), - containsString("Schema node id:/a:*abc/a:augument1 not in required format, details:Prefixed id:a:*abc not in required format")); - throw e; - } - } - - @Test - public void testDeviate() { - Deviation_stmtContext ctx = mockStatement(Deviation_stmtContext.class, "deviations"); - Deviate_add_stmtContext add = mockStatement(Deviate_add_stmtContext.class, "add"); - Deviate_delete_stmtContext del = mockStatement(Deviate_delete_stmtContext.class, "delete"); - - addChild(ctx, add); - addChild(ctx, del); - - valid.enterDeviation_stmt(ctx); - - HashSet> types = Sets.newHashSet(); - types.add(Deviate_add_stmtContext.class); - types.add(Deviate_delete_stmtContext.class); - - int count = ValidationUtil.countPresentChildrenOfType(ctx, types); - assertEquals(2, count); - } - - @Test(expected = YangValidationException.class) - public void testStatus() throws Exception { - Status_argContext status = mockStatement(Status_argContext.class, "unknown"); - try { - valid.enterStatus_arg(status); - } catch (YangValidationException e) { - assertThat(e.getMessage(), containsString("illegal value for Status statement, only permitted:")); - throw e; - } - } - - private static Import_stmtContext mockImport(final String name, final String prefixName) { - Import_stmtContext impor = mockStatement(Import_stmtContext.class, name); - - Prefix_stmtContext prefix = mockStatement(Prefix_stmtContext.class, prefixName); - Revision_date_stmtContext revDate = mockStatement(Revision_date_stmtContext.class, getFormattedDate()); - - addChild(impor, prefix); - addChild(impor, revDate); - return impor; - } - - static String getFormattedDate() { - return new SimpleDateFormat("yyyy-MM-dd").format(new Date()); - } - - private static Include_stmtContext mockInclude(final String name) { - Include_stmtContext incl = mockStatement(Include_stmtContext.class, name); - - Revision_date_stmtContext revDate = mockStatement(Revision_date_stmtContext.class, getFormattedDate()); - - addChild(incl, revDate); - return incl; - } - - static void mockName(final ParseTree stmt, final String name) { - doReturn(1).when(stmt).getChildCount(); - - TerminalNode terminalNode = mock(TerminalNode.class); - doReturn(name).when(terminalNode).getText(); - - StringContext nameCtx = mock(StringContext.class); - doReturn(nameCtx).when(stmt).getChild(0); - doReturn(terminalNode).when(nameCtx).getChild(0); - doReturn(name).when(terminalNode).getText(); - - doReturn(Collections.singletonList(terminalNode)).when(nameCtx).STRING(); - } - - static T mockStatement(final Class stmtType, final String name) { - T stmt = stmtType.cast(mock(stmtType)); - - doReturn(0).when(stmt).getChildCount(); - - if (name != null) { - mockName(stmt, name); - } - return stmt; - } - - static void addChild(final ParseTree parent, final ParseTree child) { - int childCount = parent.getChildCount() + 1; - doReturn(childCount).when(parent).getChildCount(); - doReturn(child).when(parent).getChild(childCount - 1); - doReturn(parent).when(child).getParent(); - } - -} diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/YangParserIdentityTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/YangParserIdentityTest.java deleted file mode 100644 index 788802622c..0000000000 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/YangParserIdentityTest.java +++ /dev/null @@ -1,54 +0,0 @@ -package org.opendaylight.yangtools.yang.parser.impl; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.net.URISyntaxException; -import java.util.Set; -import org.junit.Test; -import org.opendaylight.yangtools.yang.model.api.Module; -import org.opendaylight.yangtools.yang.model.api.ModuleImport; -import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException; -import org.opendaylight.yangtools.yang.parser.util.YangParseException; - -public class YangParserIdentityTest { - - // base identity name equals identity name - @Test(expected = YangParseException.class) - public void testParsingIdentityTestModuleShouldThrowYangParseException() - throws IOException, URISyntaxException, YangSyntaxErrorException { - File yang = new File(getClass().getResource( - "/identity/identitytest.yang").toURI()); - InputStream stream = new FileInputStream(yang); - TestUtils.loadModule(stream); - } - - // same module prefixed base identity name equals identity name - @Test(expected = YangParseException.class) - public void testParsingPrefixIdentityTestModuleShouldThrowYangParseException() - throws URISyntaxException, IOException, YangSyntaxErrorException { - File yang = new File(getClass().getResource( - "/identity/prefixidentitytest.yang").toURI()); - InputStream stream = new FileInputStream(yang); - TestUtils.loadModule(stream); - } - - // imported module prefixed base identity name equals identity name, but - // prefix differs - @Test - public void testParsingImportPrefixIdentityTestModuleShouldThrowYangParseException() - throws URISyntaxException, IOException, YangSyntaxErrorException { - Set modules = TestUtils.loadModules(getClass().getResource( - "/identity/import").toURI()); - Module module = TestUtils.findModule(modules, - "prefiximportidentitytest"); - Set imports = module.getImports(); - assertEquals(imports.size(), 1); - ModuleImport dummy = TestUtils.findImport(imports, "dummy"); - assertNotEquals(dummy.getPrefix(), module.getPrefix()); - } -} diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/YangParserNegativeTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/YangParserNegativeTest.java deleted file mode 100644 index 41d76c3997..0000000000 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/YangParserNegativeTest.java +++ /dev/null @@ -1,258 +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.yang.parser.impl; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import java.io.File; -import java.io.FileInputStream; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import org.junit.Test; -import org.opendaylight.yangtools.yang.model.parser.api.YangContextParser; -import org.opendaylight.yangtools.yang.parser.util.YangParseException; -import org.opendaylight.yangtools.yang.parser.util.YangValidationException; - -public class YangParserNegativeTest { - - @Test - public void testInvalidImport() throws Exception { - File yang = new File(getClass().getResource("/negative-scenario/testfile1.yang").toURI()); - try { - try (InputStream stream = new FileInputStream(yang)) { - TestUtils.loadModule(stream); - fail("ValidationException should by thrown"); - } - } catch (YangValidationException e) { - assertTrue(e.getMessage().contains("Not existing module imported")); - } - } - - @Test - public void testTypeNotFound() throws Exception { - File yang = new File(getClass().getResource("/negative-scenario/testfile2.yang").toURI()); - try { - try (InputStream stream = new FileInputStream(yang)) { - TestUtils.loadModule(stream); - fail("YangParseException should by thrown"); - } - } catch (YangParseException e) { - assertEquals(e.getMessage(), "Error in module 'test2' at line 24: Referenced type 'int-ext' not found."); - } - } - - @Test - public void testInvalidAugmentTarget() throws Exception { - File yang1 = new File(getClass().getResource("/negative-scenario/testfile0.yang").toURI()); - File yang2 = new File(getClass().getResource("/negative-scenario/testfile3.yang").toURI()); - try { - final List streams = new ArrayList<>(2); - try (InputStream testFile0 = new FileInputStream(yang1)) { - streams.add(testFile0); - try (InputStream testFile3 = new FileInputStream(yang2)) { - streams.add(testFile3); - assertEquals("Expected loaded files count is 2", 2, streams.size()); - TestUtils.loadModules(streams); - fail("YangParseException should by thrown"); - } - } - } catch (YangParseException e) { - assertEquals( - "Error in module 'test3' at line 10: Error in augment parsing: failed to find augment target: augment /data:unknown", - e.getMessage()); - } - } - - @Test - public void testInvalidRefine() throws Exception { - File yang = new File(getClass().getResource("/negative-scenario/testfile4.yang").toURI()); - try { - try (InputStream stream = new FileInputStream(yang)) { - TestUtils.loadModule(stream); - fail("YangParseException should by thrown"); - } - } catch (YangParseException e) { - assertTrue(e.getMessage().contains("Can not refine 'presence' for 'node'.")); - } - } - - @Test - public void testInvalidLength() throws Exception { - File yang = new File(getClass().getResource("/negative-scenario/testfile5.yang").toURI()); - try { - try (InputStream stream = new FileInputStream(yang)) { - TestUtils.loadModule(stream); - fail("YangParseException should by thrown"); - } - } catch (YangParseException e) { - assertTrue(e.getMessage().contains("Invalid length constraint: <4, 10>")); - } - } - - @Test - public void testInvalidRange() throws Exception { - File yang = new File(getClass().getResource("/negative-scenario/testfile6.yang").toURI()); - try { - try (InputStream stream = new FileInputStream(yang)) { - TestUtils.loadModule(stream); - fail("YangParseException should by thrown"); - } - } catch (YangParseException e) { - assertTrue(e.getMessage().contains("Invalid range constraint: <5, 20>")); - } - } - - @Test - public void testDuplicateContainer() throws Exception { - File yang = new File(getClass().getResource("/negative-scenario/duplicity/container.yang").toURI()); - try { - try (InputStream stream = new FileInputStream(yang)) { - TestUtils.loadModule(stream); - fail("YangParseException should by thrown"); - } - } catch (YangParseException e) { - String expected = "Error in module 'container' at line 10: Can not add 'container foo': node with same name 'foo' already declared at line 6."; - assertEquals(expected, e.getMessage()); - } - } - - @Test - public void testDuplicateContainerList() throws Exception { - File yang = new File(getClass().getResource("/negative-scenario/duplicity/container-list.yang").toURI()); - try { - try (InputStream stream = new FileInputStream(yang)) { - TestUtils.loadModule(stream); - fail("YangParseException should by thrown"); - } - } catch (YangParseException e) { - String expected = "Error in module 'container-list' at line 10: Can not add 'list foo': node with same name 'foo' already declared at line 6."; - assertEquals(expected, e.getMessage()); - } - } - - @Test - public void testDuplicateContainerLeaf() throws Exception { - File yang = new File(getClass().getResource("/negative-scenario/duplicity/container-leaf.yang").toURI()); - try { - try (InputStream stream = new FileInputStream(yang)) { - TestUtils.loadModule(stream); - fail("YangParseException should by thrown"); - } - } catch (YangParseException e) { - String expected = "Error in module 'container-leaf' at line 10: Can not add 'leaf foo': node with same name 'foo' already declared at line 6."; - assertEquals(expected, e.getMessage()); - } - } - - @Test - public void testDuplicateTypedef() throws Exception { - File yang = new File(getClass().getResource("/negative-scenario/duplicity/typedef.yang").toURI()); - try { - try (InputStream stream = new FileInputStream(yang)) { - TestUtils.loadModule(stream); - fail("YangParseException should by thrown"); - } - } catch (YangParseException e) { - String expected = "Error in module 'typedef' at line 10: typedef with same name 'int-ext' already declared at line 6."; - assertEquals(expected, e.getMessage()); - } - } - - @Test - public void testDuplicityInAugmentTarget1() throws Exception { - File yang1 = new File(getClass().getResource("/negative-scenario/duplicity/augment0.yang").toURI()); - File yang2 = new File(getClass().getResource("/negative-scenario/duplicity/augment1.yang").toURI()); - try { - try (InputStream stream1 = new FileInputStream(yang1); InputStream stream2 = new FileInputStream(yang2)) { - TestUtils.loadModules(Arrays.asList(stream1, stream2)); - fail("YangParseException should by thrown"); - } - } catch (YangParseException e) { - assertTrue(e.getMessage().contains("Error in module 'augment1'")); - assertTrue(e.getMessage().contains("Failed to perform augmentation:")); - - } - } - - @Test - public void testDuplicityInAugmentTarget2() throws Exception { - File yang1 = new File(getClass().getResource("/negative-scenario/duplicity/augment0.yang").toURI()); - File yang2 = new File(getClass().getResource("/negative-scenario/duplicity/augment2.yang").toURI()); - try { - try (InputStream stream1 = new FileInputStream(yang1); InputStream stream2 = new FileInputStream(yang2)) { - TestUtils.loadModules(Arrays.asList(stream1, stream2)); - fail("YangParseException should by thrown"); - } - } catch (YangParseException e) { - assertTrue(e.getMessage().contains("Error in module ")); - assertTrue(e.getMessage().contains("case with same name already declared ")); - } - } - - @Test - public void testMandatoryInAugment() throws Exception { - File yang1 = new File(getClass().getResource("/negative-scenario/testfile8.yang").toURI()); - File yang2 = new File(getClass().getResource("/negative-scenario/testfile7.yang").toURI()); - try { - try (InputStream stream1 = new FileInputStream(yang1); InputStream stream2 = new FileInputStream(yang2)) { - TestUtils.loadModules(Arrays.asList(stream1, stream2)); - fail("YangParseException should by thrown"); - } - } catch (YangParseException e) { - String expected = "Error in module 'testfile7' at line 18: Error in augment parsing: cannot augment mandatory node linkleaf"; - assertEquals(expected, e.getMessage()); - } - } - - @Test - public void testWrongDependenciesDir() throws Exception { - try { - File yangFile = new File(getClass().getResource("/types/custom-types-test@2012-4-4.yang").toURI()); - File dependenciesDir = new File("/invalid"); - YangContextParser parser = new YangParserImpl(); - parser.parseFile(yangFile, dependenciesDir); - fail("Exception should by thrown"); - } catch (IllegalStateException e) { - String expected = File.separator + "invalid does not exists"; - assertEquals(expected, e.getMessage()); - } - } - - @Test - public void testWrongDependenciesDir2() throws Exception { - try { - File yangFile = new File(getClass().getResource("/types/custom-types-test@2012-4-4.yang").toURI()); - File dependenciesDir = new File(getClass().getResource("/model").toURI()); - YangContextParser parser = new YangParserImpl(); - parser.parseFile(yangFile, dependenciesDir); - fail("Exception should by thrown"); - } catch (YangValidationException e) { - String expected = "Not existing module imported"; - assertTrue(e.getMessage().contains(expected)); - } - } - - @Test - public void testInvalidListKeyDefinition() throws Exception { - File yang1 = new File(getClass().getResource("/negative-scenario/invalid-list-key-def.yang").toURI()); - try { - try (InputStream stream1 = new FileInputStream(yang1)) { - TestUtils.loadModule(stream1); - fail("YangParseException should by thrown"); - } - } catch (YangParseException e) { - String expected = "Error in module 'invalid-list-key-def' at line 6: Failed to resolve list key for name rib-id"; - assertEquals(expected, e.getMessage()); - } - } - -} diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/YangParserSimpleTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/YangParserSimpleTest.java deleted file mode 100644 index afc6de24e0..0000000000 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/YangParserSimpleTest.java +++ /dev/null @@ -1,211 +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.yang.parser.impl; - -import static org.junit.Assert.assertEquals; -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.junit.Before; - -import org.junit.Test; -import org.opendaylight.yangtools.yang.model.api.UsesNode; -import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode; -import org.opendaylight.yangtools.yang.model.api.GroupingDefinition; -import org.opendaylight.yangtools.yang.model.api.ListSchemaNode; -import org.opendaylight.yangtools.yang.model.api.TypeDefinition; -import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode; -import org.opendaylight.yangtools.yang.model.api.MustDefinition; -import org.opendaylight.yangtools.yang.model.api.Status; -import org.opendaylight.yangtools.yang.model.api.ConstraintDefinition; -import org.opendaylight.yangtools.yang.model.api.AnyXmlSchemaNode; -import java.net.URI; -import java.text.DateFormat; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.Set; -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.model.api.Module; -import org.opendaylight.yangtools.yang.model.api.SchemaPath; - -public class YangParserSimpleTest { - private final URI snNS = URI.create("urn:opendaylight:simple-nodes"); - private Date snRev; - private final String snPref = "sn"; - - private final DateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); - private Set modules; - - @Before - public void init() throws Exception { - snRev = simpleDateFormat.parse("2013-07-30"); - modules = TestUtils.loadModules(getClass().getResource("/simple-test").toURI()); - } - - @Test - public void testParseAnyXml() { - Module testModule = TestUtils.findModule(modules, "simple-nodes"); - AnyXmlSchemaNode data = (AnyXmlSchemaNode) testModule.getDataChildByName("data"); - assertNotNull("'anyxml data not found'", data); - - // test SchemaNode args - QName qname = data.getQName(); - assertEquals("data", qname.getLocalName()); - assertEquals(snNS, qname.getNamespace()); - assertEquals(snRev, qname.getRevision()); - assertEquals("anyxml desc", data.getDescription()); - assertEquals("data ref", data.getReference()); - assertEquals(Status.OBSOLETE, data.getStatus()); - assertEquals(0, data.getUnknownSchemaNodes().size()); - // test DataSchemaNode args - assertFalse(data.isAugmenting()); - assertFalse(data.isConfiguration()); - ConstraintDefinition constraints = data.getConstraints(); - assertEquals("class != 'wheel'", constraints.getWhenCondition().toString()); - Set mustConstraints = constraints.getMustConstraints(); - assertEquals(2, constraints.getMustConstraints().size()); - - String must1 = "\"ifType != 'ethernet' or (ifType = 'ethernet' and ifMTU = 1500)\""; - String errMsg1 = "An ethernet MTU must be 1500"; - String must2 = "\"ifType != 'atm' or (ifType = 'atm' and ifMTU <= 17966 and ifMTU >= 64)\""; - String errMsg2 = "An atm MTU must be 64 .. 17966"; - - boolean found1 = false; - boolean found2 = false; - for (MustDefinition must : mustConstraints) { - if (must1.equals(must.toString())) { - found1 = true; - assertEquals(errMsg1, must.getErrorMessage()); - } else if (must2.equals(must.toString())) { - found2 = true; - assertEquals(errMsg2, must.getErrorMessage()); - assertEquals("anyxml data error-app-tag", must.getErrorAppTag()); - assertEquals("an error occured in data", must.getDescription()); - assertEquals("data must ref", must.getReference()); - } - } - assertTrue(found1); - assertTrue(found2); - - assertTrue(constraints.isMandatory()); - assertNull(constraints.getMinElements()); - assertNull(constraints.getMaxElements()); - } - - @Test - public void testParseContainer() { - Module test = TestUtils.findModule(modules, "simple-nodes"); - - ContainerSchemaNode nodes = (ContainerSchemaNode) test.getDataChildByName("nodes"); - // test SchemaNode args - QName expectedQName = QName.create(snNS, snRev, "nodes"); - assertEquals(expectedQName, nodes.getQName()); - SchemaPath expectedPath = TestUtils.createPath(true, snNS, snRev, snPref, "nodes"); - assertEquals(expectedPath, nodes.getPath()); - assertEquals("nodes collection", nodes.getDescription()); - assertEquals("nodes ref", nodes.getReference()); - assertEquals(Status.CURRENT, nodes.getStatus()); - assertEquals(0, nodes.getUnknownSchemaNodes().size()); - // test DataSchemaNode args - assertFalse(nodes.isAugmenting()); - assertFalse(nodes.isConfiguration()); - - // constraints - ConstraintDefinition constraints = nodes.getConstraints(); - assertEquals("class != 'wheel'", constraints.getWhenCondition().toString()); - Set mustConstraints = constraints.getMustConstraints(); - assertEquals(2, constraints.getMustConstraints().size()); - - String must1 = "\"ifType != 'atm' or (ifType = 'atm' and ifMTU <= 17966 and ifMTU >= 64)\""; - String errMsg1 = "An atm MTU must be 64 .. 17966"; - String must2 = "ifId != 0"; - - boolean found1 = false; - boolean found2 = false; - for (MustDefinition must : mustConstraints) { - if (must1.equals(must.toString())) { - found1 = true; - assertEquals(errMsg1, must.getErrorMessage()); - } else if (must2.equals(must.toString())) { - found2 = true; - assertNull(must.getErrorMessage()); - assertNull(must.getErrorAppTag()); - assertNull(must.getDescription()); - assertNull(must.getReference()); - } - } - assertTrue(found1); - assertTrue(found2); - - assertFalse(constraints.isMandatory()); - assertNull(constraints.getMinElements()); - assertNull(constraints.getMaxElements()); - assertTrue(nodes.isPresenceContainer()); - - // typedef - Set> typedefs = nodes.getTypeDefinitions(); - assertEquals(1, typedefs.size()); - TypeDefinition nodesType = typedefs.iterator().next(); - QName typedefQName = QName.create(snNS, snRev, "nodes-type"); - assertEquals(typedefQName, nodesType.getQName()); - SchemaPath nodesTypePath = TestUtils.createPath(true, snNS, snRev, snPref, "nodes", "nodes-type"); - assertEquals(nodesTypePath, nodesType.getPath()); - assertTrue(nodesType.getDescription().isEmpty()); - assertTrue(nodesType.getReference().isEmpty()); - assertEquals(Status.CURRENT, nodesType.getStatus()); - assertEquals(0, nodesType.getUnknownSchemaNodes().size()); - - // child nodes - // total size = 8: defined 6, inserted by uses 2 - assertEquals(8, nodes.getChildNodes().size()); - LeafListSchemaNode added = (LeafListSchemaNode)nodes.getDataChildByName("added"); - assertEquals(createPath("nodes", "added"), added.getPath()); - assertEquals(createPath("mytype"), added.getType().getPath()); - - ListSchemaNode links = (ListSchemaNode) nodes.getDataChildByName("links"); - assertFalse(links.isUserOrdered()); - - Set groupings = nodes.getGroupings(); - assertEquals(1, groupings.size()); - GroupingDefinition nodeGroup = groupings.iterator().next(); - QName groupQName = QName.create(snNS, snRev, "node-group"); - assertEquals(groupQName, nodeGroup.getQName()); - SchemaPath nodeGroupPath = TestUtils.createPath(true, snNS, snRev, snPref, "nodes", "node-group"); - assertEquals(nodeGroupPath, nodeGroup.getPath()); - - Set uses = nodes.getUses(); - assertEquals(1, uses.size()); - UsesNode use = uses.iterator().next(); - assertEquals(nodeGroupPath, use.getGroupingPath()); - } - - - private final URI ns = URI.create("urn:opendaylight:simple-nodes"); - private Date rev; - private final String prefix = "sn"; - - private SchemaPath createPath(final String... names) { - try { - rev = new SimpleDateFormat("yyyy-MM-dd").parse("2013-07-30"); - } catch (ParseException e) { - e.printStackTrace(); - } - - List path = new ArrayList<>(); - for (String name : names) { - path.add(QName.create(ns, rev, name)); - } - return SchemaPath.create(path, true); - } - -} diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/YangParserTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/YangParserTest.java deleted file mode 100644 index a8da2ba4f2..0000000000 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/YangParserTest.java +++ /dev/null @@ -1,963 +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.yang.parser.impl; - -import static org.junit.Assert.assertEquals; -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 static org.junit.Assert.fail; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.math.BigInteger; -import java.net.URI; -import java.net.URISyntaxException; -import java.text.DateFormat; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Date; -import java.util.Iterator; -import java.util.List; -import java.util.Set; -import org.junit.Before; -import org.junit.Test; -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.model.api.AugmentationSchema; -import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode; -import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode; -import org.opendaylight.yangtools.yang.model.api.ConstraintDefinition; -import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode; -import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; -import org.opendaylight.yangtools.yang.model.api.Deviation; -import org.opendaylight.yangtools.yang.model.api.Deviation.Deviate; -import org.opendaylight.yangtools.yang.model.api.ExtensionDefinition; -import org.opendaylight.yangtools.yang.model.api.FeatureDefinition; -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.ModuleIdentifier; -import org.opendaylight.yangtools.yang.model.api.ModuleImport; -import org.opendaylight.yangtools.yang.model.api.NotificationDefinition; -import org.opendaylight.yangtools.yang.model.api.RpcDefinition; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.model.api.SchemaPath; -import org.opendaylight.yangtools.yang.model.api.Status; -import org.opendaylight.yangtools.yang.model.api.TypeDefinition; -import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode; -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.parser.api.YangContextParser; -import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException; -import org.opendaylight.yangtools.yang.model.util.Decimal64; -import org.opendaylight.yangtools.yang.model.util.ExtendedType; -import org.opendaylight.yangtools.yang.model.util.Int16; -import org.opendaylight.yangtools.yang.model.util.Int32; -import org.opendaylight.yangtools.yang.model.util.StringType; -import org.opendaylight.yangtools.yang.model.util.Uint32; -import org.opendaylight.yangtools.yang.model.util.UnionType; -import org.opendaylight.yangtools.yang.parser.builder.impl.BuilderUtils; -import org.opendaylight.yangtools.yang.parser.util.YangParseException; - -public class YangParserTest { - public static final String FS = File.separator; - - private final URI fooNS = URI.create("urn:opendaylight.foo"); - private final URI barNS = URI.create("urn:opendaylight.bar"); - private final URI bazNS = URI.create("urn:opendaylight.baz"); - private Date fooRev; - private Date barRev; - private Date bazRev; - - private Set modules; - - @Before - public void init() throws Exception { - DateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); - fooRev = simpleDateFormat.parse("2013-02-27"); - barRev = simpleDateFormat.parse("2013-07-03"); - bazRev = simpleDateFormat.parse("2013-02-27"); - - modules = TestUtils.loadModules(getClass().getResource("/model").toURI()); - assertEquals(3, modules.size()); - } - - @Test - public void testHeaders() throws ParseException { - Module foo = TestUtils.findModule(modules, "foo"); - - assertEquals("foo", foo.getName()); - assertEquals("1", foo.getYangVersion()); - assertEquals(fooNS, foo.getNamespace()); - assertEquals("foo", foo.getPrefix()); - - Set imports = foo.getImports(); - assertEquals(2, imports.size()); - - ModuleImport import2 = TestUtils.findImport(imports, "br"); - assertEquals("bar", import2.getModuleName()); - assertEquals(barRev, import2.getRevision()); - - ModuleImport import3 = TestUtils.findImport(imports, "bz"); - assertEquals("baz", import3.getModuleName()); - assertEquals(bazRev, import3.getRevision()); - - assertEquals("opendaylight", foo.getOrganization()); - assertEquals("http://www.opendaylight.org/", foo.getContact()); - Date expectedRevision = TestUtils.createDate("2013-02-27"); - assertEquals(expectedRevision, foo.getRevision()); - assertEquals(" WILL BE DEFINED LATER", foo.getReference()); - } - - @Test - public void testParseList() { - Module bar = TestUtils.findModule(modules, "bar"); - URI expectedNamespace = URI.create("urn:opendaylight.bar"); - String expectedPrefix = "bar"; - - ContainerSchemaNode interfaces = (ContainerSchemaNode) bar.getDataChildByName("interfaces"); - - ListSchemaNode ifEntry = (ListSchemaNode) interfaces.getDataChildByName("ifEntry"); - // test SchemaNode args - QName expectedQName = QName.create(expectedNamespace, barRev, "ifEntry"); - assertEquals(expectedQName, ifEntry.getQName()); - SchemaPath expectedPath = TestUtils.createPath(true, expectedNamespace, barRev, expectedPrefix, "interfaces", - "ifEntry"); - assertEquals(expectedPath, ifEntry.getPath()); - assertNull(ifEntry.getDescription()); - assertNull(ifEntry.getReference()); - assertEquals(Status.CURRENT, ifEntry.getStatus()); - assertEquals(0, ifEntry.getUnknownSchemaNodes().size()); - // test DataSchemaNode args - assertFalse(ifEntry.isAugmenting()); - assertTrue(ifEntry.isConfiguration()); - ConstraintDefinition constraints = ifEntry.getConstraints(); - assertNull(constraints.getWhenCondition()); - assertEquals(0, constraints.getMustConstraints().size()); - assertTrue(constraints.isMandatory()); - assertEquals(1, (int) constraints.getMinElements()); - assertEquals(11, (int) constraints.getMaxElements()); - // test AugmentationTarget args - Set availableAugmentations = ifEntry.getAvailableAugmentations(); - assertEquals(2, availableAugmentations.size()); - // test ListSchemaNode args - List expectedKey = new ArrayList<>(); - expectedKey.add(QName.create(expectedNamespace, barRev, "ifIndex")); - assertEquals(expectedKey, ifEntry.getKeyDefinition()); - assertFalse(ifEntry.isUserOrdered()); - // test DataNodeContainer args - assertEquals(0, ifEntry.getTypeDefinitions().size()); - assertEquals(4, ifEntry.getChildNodes().size()); - assertEquals(0, ifEntry.getGroupings().size()); - assertEquals(0, ifEntry.getUses().size()); - - LeafSchemaNode ifIndex = (LeafSchemaNode) ifEntry.getDataChildByName("ifIndex"); - assertEquals(ifEntry.getKeyDefinition().get(0), ifIndex.getQName()); - assertTrue(ifIndex.getType() instanceof Uint32); - LeafSchemaNode ifMtu = (LeafSchemaNode) ifEntry.getDataChildByName("ifMtu"); - assertTrue(ifMtu.getType() instanceof Int32); - } - - @Test - public void testTypedefRangesResolving() throws ParseException { - Module foo = TestUtils.findModule(modules, "foo"); - LeafSchemaNode int32Leaf = (LeafSchemaNode) foo.getDataChildByName("int32-leaf"); - - ExtendedType leafType = (ExtendedType) int32Leaf.getType(); - QName leafTypeQName = leafType.getQName(); - assertEquals("int32-ext2", leafTypeQName.getLocalName()); - assertEquals(fooNS, leafTypeQName.getNamespace()); - assertEquals(fooRev, leafTypeQName.getRevision()); - assertNull(leafType.getUnits()); - assertNull(leafType.getDefaultValue()); - assertTrue(leafType.getLengthConstraints().isEmpty()); - assertTrue(leafType.getPatternConstraints().isEmpty()); - List ranges = leafType.getRangeConstraints(); - assertEquals(1, ranges.size()); - RangeConstraint range = ranges.get(0); - assertEquals(BigInteger.valueOf(12), range.getMin()); - assertEquals(BigInteger.valueOf(20), range.getMax()); - - ExtendedType baseType = (ExtendedType) leafType.getBaseType(); - QName baseTypeQName = baseType.getQName(); - assertEquals("int32-ext2", baseTypeQName.getLocalName()); - assertEquals(barNS, baseTypeQName.getNamespace()); - assertEquals(barRev, baseTypeQName.getRevision()); - assertEquals("mile", baseType.getUnits()); - assertEquals("11", baseType.getDefaultValue()); - assertTrue(leafType.getLengthConstraints().isEmpty()); - assertTrue(leafType.getPatternConstraints().isEmpty()); - List baseTypeRanges = baseType.getRangeConstraints(); - assertEquals(2, baseTypeRanges.size()); - RangeConstraint baseTypeRange1 = baseTypeRanges.get(0); - assertEquals(BigInteger.valueOf(3), baseTypeRange1.getMin()); - assertEquals(BigInteger.valueOf(9), baseTypeRange1.getMax()); - RangeConstraint baseTypeRange2 = baseTypeRanges.get(1); - assertEquals(BigInteger.valueOf(11), baseTypeRange2.getMin()); - assertEquals(BigInteger.valueOf(20), baseTypeRange2.getMax()); - - ExtendedType base = (ExtendedType) baseType.getBaseType(); - QName baseQName = base.getQName(); - assertEquals("int32-ext1", baseQName.getLocalName()); - assertEquals(barNS, baseQName.getNamespace()); - assertEquals(barRev, baseQName.getRevision()); - assertNull(base.getUnits()); - assertNull(base.getDefaultValue()); - assertTrue(leafType.getLengthConstraints().isEmpty()); - assertTrue(leafType.getPatternConstraints().isEmpty()); - List baseRanges = base.getRangeConstraints(); - assertEquals(1, baseRanges.size()); - RangeConstraint baseRange = baseRanges.get(0); - assertEquals(BigInteger.valueOf(2), baseRange.getMin()); - assertEquals(BigInteger.valueOf(20), baseRange.getMax()); - - assertTrue(base.getBaseType() instanceof Int32); - } - - @Test - public void testTypedefPatternsResolving() { - Module foo = TestUtils.findModule(modules, "foo"); - LeafSchemaNode stringleaf = (LeafSchemaNode) foo.getDataChildByName("string-leaf"); - - ExtendedType type = (ExtendedType) stringleaf.getType(); - QName typeQName = type.getQName(); - assertEquals("string-ext4", typeQName.getLocalName()); - assertEquals(barNS, typeQName.getNamespace()); - assertEquals(barRev, typeQName.getRevision()); - assertNull(type.getUnits()); - assertNull(type.getDefaultValue()); - List patterns = type.getPatternConstraints(); - assertEquals(1, patterns.size()); - PatternConstraint pattern = patterns.iterator().next(); - assertEquals("^[e-z]*$", pattern.getRegularExpression()); - assertTrue(type.getLengthConstraints().isEmpty()); - assertTrue(type.getRangeConstraints().isEmpty()); - - ExtendedType baseType1 = (ExtendedType) type.getBaseType(); - QName baseType1QName = baseType1.getQName(); - assertEquals("string-ext3", baseType1QName.getLocalName()); - assertEquals(barNS, baseType1QName.getNamespace()); - assertEquals(barRev, baseType1QName.getRevision()); - assertNull(baseType1.getUnits()); - assertNull(baseType1.getDefaultValue()); - patterns = baseType1.getPatternConstraints(); - assertEquals(1, patterns.size()); - pattern = patterns.iterator().next(); - assertEquals("^[b-u]*$", pattern.getRegularExpression()); - assertTrue(baseType1.getLengthConstraints().isEmpty()); - assertTrue(baseType1.getRangeConstraints().isEmpty()); - - ExtendedType baseType2 = (ExtendedType) baseType1.getBaseType(); - QName baseType2QName = baseType2.getQName(); - assertEquals("string-ext2", baseType2QName.getLocalName()); - assertEquals(barNS, baseType2QName.getNamespace()); - assertEquals(barRev, baseType2QName.getRevision()); - assertNull(baseType2.getUnits()); - assertNull(baseType2.getDefaultValue()); - assertTrue(baseType2.getPatternConstraints().isEmpty()); - List baseType2Lengths = baseType2.getLengthConstraints(); - assertEquals(1, baseType2Lengths.size()); - LengthConstraint length = baseType2Lengths.get(0); - assertEquals(BigInteger.valueOf(6), length.getMin()); - assertEquals(BigInteger.TEN, length.getMax()); - assertTrue(baseType2.getRangeConstraints().isEmpty()); - - ExtendedType baseType3 = (ExtendedType) baseType2.getBaseType(); - QName baseType3QName = baseType3.getQName(); - assertEquals("string-ext1", baseType3QName.getLocalName()); - assertEquals(barNS, baseType3QName.getNamespace()); - assertEquals(barRev, baseType3QName.getRevision()); - assertNull(baseType3.getUnits()); - assertNull(baseType3.getDefaultValue()); - patterns = baseType3.getPatternConstraints(); - assertEquals(1, patterns.size()); - pattern = patterns.iterator().next(); - assertEquals("^[a-k]*$", pattern.getRegularExpression()); - List baseType3Lengths = baseType3.getLengthConstraints(); - assertEquals(1, baseType3Lengths.size()); - length = baseType3Lengths.get(0); - assertEquals(BigInteger.valueOf(5), length.getMin()); - assertEquals(BigInteger.valueOf(11), length.getMax()); - assertTrue(baseType3.getRangeConstraints().isEmpty()); - - assertTrue(baseType3.getBaseType() instanceof StringType); - } - - @Test - public void testTypedefInvalidPatternsResolving() { - Module foo = TestUtils.findModule(modules, "foo"); - final LeafSchemaNode invalidPatternStringLeaf = (LeafSchemaNode) foo.getDataChildByName("invalid-pattern-string-leaf"); - ExtendedType type = (ExtendedType) invalidPatternStringLeaf.getType(); - QName typeQName = type.getQName(); - assertEquals("invalid-string-pattern", typeQName.getLocalName()); - assertEquals(barNS, typeQName.getNamespace()); - assertEquals(barRev, typeQName.getRevision()); - assertNull(type.getUnits()); - assertNull(type.getDefaultValue()); - List patterns = type.getPatternConstraints(); - assertTrue(patterns.isEmpty()); - - final LeafSchemaNode invalidDirectStringPatternDefLeaf = (LeafSchemaNode) foo.getDataChildByName("invalid-direct-string-pattern-def-leaf"); - type = (ExtendedType) invalidDirectStringPatternDefLeaf.getType(); - typeQName = type.getQName(); - assertEquals("string", typeQName.getLocalName()); - assertEquals(fooNS, typeQName.getNamespace()); - assertEquals(fooRev, typeQName.getRevision()); - assertNull(type.getUnits()); - assertNull(type.getDefaultValue()); - patterns = type.getPatternConstraints(); - assertTrue(patterns.isEmpty()); - - final LeafSchemaNode multiplePatternStringLeaf = (LeafSchemaNode) foo.getDataChildByName("multiple-pattern-string-leaf"); - type = (ExtendedType) multiplePatternStringLeaf.getType(); - typeQName = type.getQName(); - assertEquals("multiple-pattern-string", typeQName.getLocalName()); - assertEquals(barNS, typeQName.getNamespace()); - assertEquals(barRev, typeQName.getRevision()); - assertNull(type.getUnits()); - assertNull(type.getDefaultValue()); - patterns = type.getPatternConstraints(); - assertTrue(!patterns.isEmpty()); - assertEquals(1, patterns.size()); - PatternConstraint pattern = patterns.iterator().next(); - assertEquals("^[e-z]*$", pattern.getRegularExpression()); - assertTrue(type.getLengthConstraints().isEmpty()); - assertTrue(type.getRangeConstraints().isEmpty()); - - final LeafSchemaNode multiplePatternDirectStringDefLeaf = (LeafSchemaNode) foo.getDataChildByName("multiple-pattern-direct-string-def-leaf"); - type = (ExtendedType) multiplePatternDirectStringDefLeaf.getType(); - typeQName = type.getQName(); - assertEquals("string", typeQName.getLocalName()); - assertEquals(fooNS, typeQName.getNamespace()); - assertEquals(fooRev, typeQName.getRevision()); - assertNull(type.getUnits()); - assertNull(type.getDefaultValue()); - patterns = type.getPatternConstraints(); - assertTrue(!patterns.isEmpty()); - assertEquals(2, patterns.size()); - - boolean isEZPattern = false; - boolean isADPattern = false; - for (final PatternConstraint patternConstraint : patterns) { - if (patternConstraint.getRegularExpression().equals("^[e-z]*$")) { - isEZPattern = true; - } else if (patternConstraint.getRegularExpression().equals("^[a-d]*$")) { - isADPattern = true; - } - } - assertTrue(isEZPattern); - assertTrue( isADPattern); - } - - @Test - public void testTypedefLengthsResolving() { - Module foo = TestUtils.findModule(modules, "foo"); - - LeafSchemaNode lengthLeaf = (LeafSchemaNode) foo.getDataChildByName("length-leaf"); - ExtendedType type = (ExtendedType) lengthLeaf.getType(); - - QName typeQName = type.getQName(); - assertEquals("string-ext2", typeQName.getLocalName()); - assertEquals(fooNS, typeQName.getNamespace()); - assertEquals(fooRev, typeQName.getRevision()); - assertNull(type.getUnits()); - assertNull(type.getDefaultValue()); - assertTrue(type.getPatternConstraints().isEmpty()); - List typeLengths = type.getLengthConstraints(); - assertEquals(1, typeLengths.size()); - LengthConstraint length = typeLengths.get(0); - assertEquals(BigInteger.valueOf(7), length.getMin()); - assertEquals(BigInteger.TEN, length.getMax()); - assertTrue(type.getRangeConstraints().isEmpty()); - - ExtendedType baseType1 = (ExtendedType) type.getBaseType(); - QName baseType1QName = baseType1.getQName(); - assertEquals("string-ext2", baseType1QName.getLocalName()); - assertEquals(barNS, baseType1QName.getNamespace()); - assertEquals(barRev, baseType1QName.getRevision()); - assertNull(baseType1.getUnits()); - assertNull(baseType1.getDefaultValue()); - assertTrue(baseType1.getPatternConstraints().isEmpty()); - List baseType2Lengths = baseType1.getLengthConstraints(); - assertEquals(1, baseType2Lengths.size()); - length = baseType2Lengths.get(0); - assertEquals(BigInteger.valueOf(6), length.getMin()); - assertEquals(BigInteger.TEN, length.getMax()); - assertTrue(baseType1.getRangeConstraints().isEmpty()); - - ExtendedType baseType2 = (ExtendedType) baseType1.getBaseType(); - QName baseType2QName = baseType2.getQName(); - assertEquals("string-ext1", baseType2QName.getLocalName()); - assertEquals(barNS, baseType2QName.getNamespace()); - assertEquals(barRev, baseType2QName.getRevision()); - assertNull(baseType2.getUnits()); - assertNull(baseType2.getDefaultValue()); - List patterns = baseType2.getPatternConstraints(); - assertEquals(1, patterns.size()); - PatternConstraint pattern = patterns.iterator().next(); - assertEquals("^[a-k]*$", pattern.getRegularExpression()); - List baseType3Lengths = baseType2.getLengthConstraints(); - assertEquals(1, baseType3Lengths.size()); - length = baseType3Lengths.get(0); - assertEquals(BigInteger.valueOf(5), length.getMin()); - assertEquals(BigInteger.valueOf(11), length.getMax()); - assertTrue(baseType2.getRangeConstraints().isEmpty()); - - assertTrue(baseType2.getBaseType() instanceof StringType); - } - - @Test - public void testTypedefDecimal1() { - Module foo = TestUtils.findModule(modules, "foo"); - LeafSchemaNode testleaf = (LeafSchemaNode) foo.getDataChildByName("decimal-leaf"); - - ExtendedType type = (ExtendedType) testleaf.getType(); - QName typeQName = type.getQName(); - assertEquals("my-decimal-type", typeQName.getLocalName()); - assertEquals(fooNS, typeQName.getNamespace()); - assertEquals(fooRev, typeQName.getRevision()); - assertNull(type.getUnits()); - assertNull(type.getDefaultValue()); - assertEquals(4, (int) type.getFractionDigits()); - assertTrue(type.getLengthConstraints().isEmpty()); - assertTrue(type.getPatternConstraints().isEmpty()); - assertTrue(type.getRangeConstraints().isEmpty()); - - ExtendedType typeBase = (ExtendedType) type.getBaseType(); - QName typeBaseQName = typeBase.getQName(); - assertEquals("my-decimal-type", typeBaseQName.getLocalName()); - assertEquals(barNS, typeBaseQName.getNamespace()); - assertEquals(barRev, typeBaseQName.getRevision()); - assertNull(typeBase.getUnits()); - assertNull(typeBase.getDefaultValue()); - assertNull(typeBase.getFractionDigits()); - assertTrue(typeBase.getLengthConstraints().isEmpty()); - assertTrue(typeBase.getPatternConstraints().isEmpty()); - assertTrue(typeBase.getRangeConstraints().isEmpty()); - - Decimal64 decimal = (Decimal64) typeBase.getBaseType(); - assertEquals(6, (int) decimal.getFractionDigits()); - } - - @Test - public void testTypedefDecimal2() { - Module foo = TestUtils.findModule(modules, "foo"); - LeafSchemaNode testleaf = (LeafSchemaNode) foo.getDataChildByName("decimal-leaf2"); - - ExtendedType type = (ExtendedType) testleaf.getType(); - QName typeQName = type.getQName(); - assertEquals("my-decimal-type", typeQName.getLocalName()); - assertEquals(barNS, typeQName.getNamespace()); - assertEquals(barRev, typeQName.getRevision()); - assertNull(type.getUnits()); - assertNull(type.getDefaultValue()); - assertNull(type.getFractionDigits()); - assertTrue(type.getLengthConstraints().isEmpty()); - assertTrue(type.getPatternConstraints().isEmpty()); - assertTrue(type.getRangeConstraints().isEmpty()); - - Decimal64 baseTypeDecimal = (Decimal64) type.getBaseType(); - assertEquals(6, (int) baseTypeDecimal.getFractionDigits()); - } - - @Test - public void testTypedefUnion() { - Module foo = TestUtils.findModule(modules, "foo"); - LeafSchemaNode unionleaf = (LeafSchemaNode) foo.getDataChildByName("union-leaf"); - - ExtendedType type = (ExtendedType) unionleaf.getType(); - QName typeQName = type.getQName(); - assertEquals("my-union-ext", typeQName.getLocalName()); - assertEquals(barNS, typeQName.getNamespace()); - assertEquals(barRev, typeQName.getRevision()); - assertNull(type.getUnits()); - assertNull(type.getDefaultValue()); - assertNull(type.getFractionDigits()); - assertTrue(type.getLengthConstraints().isEmpty()); - assertTrue(type.getPatternConstraints().isEmpty()); - assertTrue(type.getRangeConstraints().isEmpty()); - - ExtendedType baseType = (ExtendedType) type.getBaseType(); - QName baseTypeQName = baseType.getQName(); - assertEquals("my-union", baseTypeQName.getLocalName()); - assertEquals(barNS, baseTypeQName.getNamespace()); - assertEquals(barRev, baseTypeQName.getRevision()); - assertNull(baseType.getUnits()); - assertNull(baseType.getDefaultValue()); - assertNull(baseType.getFractionDigits()); - assertTrue(baseType.getLengthConstraints().isEmpty()); - assertTrue(baseType.getPatternConstraints().isEmpty()); - assertTrue(baseType.getRangeConstraints().isEmpty()); - - UnionType unionType = (UnionType) baseType.getBaseType(); - List> unionTypes = unionType.getTypes(); - assertEquals(2, unionTypes.size()); - - ExtendedType unionType1 = (ExtendedType) unionTypes.get(0); - QName unionType1QName = baseType.getQName(); - assertEquals("my-union", unionType1QName.getLocalName()); - assertEquals(barNS, unionType1QName.getNamespace()); - assertEquals(barRev, unionType1QName.getRevision()); - assertNull(unionType1.getUnits()); - assertNull(unionType1.getDefaultValue()); - assertNull(unionType1.getFractionDigits()); - assertTrue(unionType1.getLengthConstraints().isEmpty()); - assertTrue(unionType1.getPatternConstraints().isEmpty()); - List ranges = unionType1.getRangeConstraints(); - assertEquals(1, ranges.size()); - RangeConstraint range = ranges.get(0); - assertEquals(BigInteger.ONE, range.getMin()); - assertEquals(BigInteger.valueOf(100), range.getMax()); - assertTrue(unionType1.getBaseType() instanceof Int16); - - assertTrue(unionTypes.get(1) instanceof Int32); - } - - @Test - public void testNestedUnionResolving() { - Module foo = TestUtils.findModule(modules, "foo"); - LeafSchemaNode testleaf = (LeafSchemaNode) foo.getDataChildByName("custom-union-leaf"); - - ExtendedType type = (ExtendedType) testleaf.getType(); - QName testleafTypeQName = type.getQName(); - assertEquals(bazNS, testleafTypeQName.getNamespace()); - assertEquals(bazRev, testleafTypeQName.getRevision()); - assertEquals("union1", testleafTypeQName.getLocalName()); - assertNull(type.getUnits()); - assertNull(type.getDefaultValue()); - assertNull(type.getFractionDigits()); - assertTrue(type.getLengthConstraints().isEmpty()); - assertTrue(type.getPatternConstraints().isEmpty()); - assertTrue(type.getRangeConstraints().isEmpty()); - - ExtendedType typeBase = (ExtendedType) type.getBaseType(); - QName typeBaseQName = typeBase.getQName(); - assertEquals(bazNS, typeBaseQName.getNamespace()); - assertEquals(bazRev, typeBaseQName.getRevision()); - assertEquals("union2", typeBaseQName.getLocalName()); - assertNull(typeBase.getUnits()); - assertNull(typeBase.getDefaultValue()); - assertNull(typeBase.getFractionDigits()); - assertTrue(typeBase.getLengthConstraints().isEmpty()); - assertTrue(typeBase.getPatternConstraints().isEmpty()); - assertTrue(typeBase.getRangeConstraints().isEmpty()); - - UnionType union = (UnionType) typeBase.getBaseType(); - List> unionTypes = union.getTypes(); - assertEquals(2, unionTypes.size()); - assertTrue(unionTypes.get(0) instanceof Int32); - assertTrue(unionTypes.get(1) instanceof ExtendedType); - - ExtendedType unionType1 = (ExtendedType) unionTypes.get(1); - QName uniontType1QName = unionType1.getQName(); - assertEquals(barNS, uniontType1QName.getNamespace()); - assertEquals(barRev, uniontType1QName.getRevision()); - assertEquals("nested-union2", uniontType1QName.getLocalName()); - assertNull(unionType1.getUnits()); - assertNull(unionType1.getDefaultValue()); - assertNull(unionType1.getFractionDigits()); - assertTrue(unionType1.getLengthConstraints().isEmpty()); - assertTrue(unionType1.getPatternConstraints().isEmpty()); - assertTrue(unionType1.getRangeConstraints().isEmpty()); - - UnionType nestedUnion = (UnionType) unionType1.getBaseType(); - List> nestedUnion2Types = nestedUnion.getTypes(); - assertEquals(2, nestedUnion2Types.size()); - assertTrue(nestedUnion2Types.get(0) instanceof StringType); - assertTrue(nestedUnion2Types.get(1) instanceof ExtendedType); - - ExtendedType myUnionExt = (ExtendedType) nestedUnion2Types.get(1); - QName myUnionExtQName = myUnionExt.getQName(); - assertEquals(barNS, myUnionExtQName.getNamespace()); - assertEquals(barRev, myUnionExtQName.getRevision()); - assertEquals("my-union-ext", myUnionExtQName.getLocalName()); - assertNull(myUnionExt.getUnits()); - assertNull(myUnionExt.getDefaultValue()); - assertNull(myUnionExt.getFractionDigits()); - assertTrue(myUnionExt.getLengthConstraints().isEmpty()); - assertTrue(myUnionExt.getPatternConstraints().isEmpty()); - assertTrue(myUnionExt.getRangeConstraints().isEmpty()); - - ExtendedType myUnion = (ExtendedType) myUnionExt.getBaseType(); - QName myUnionQName = myUnion.getQName(); - assertEquals(barNS, myUnionQName.getNamespace()); - assertEquals(barRev, myUnionQName.getRevision()); - assertEquals("my-union", myUnionQName.getLocalName()); - assertNull(myUnion.getUnits()); - assertNull(myUnion.getDefaultValue()); - assertNull(myUnion.getFractionDigits()); - assertTrue(myUnion.getLengthConstraints().isEmpty()); - assertTrue(myUnion.getPatternConstraints().isEmpty()); - assertTrue(myUnion.getRangeConstraints().isEmpty()); - - UnionType myUnionBase = (UnionType) myUnion.getBaseType(); - List> myUnionBaseTypes = myUnionBase.getTypes(); - assertEquals(2, myUnionBaseTypes.size()); - assertTrue(myUnionBaseTypes.get(0) instanceof ExtendedType); - assertTrue(myUnionBaseTypes.get(1) instanceof Int32); - - ExtendedType int16Ext = (ExtendedType) myUnionBaseTypes.get(0); - QName int16ExtQName = int16Ext.getQName(); - assertEquals(barNS, int16ExtQName.getNamespace()); - assertEquals(barRev, int16ExtQName.getRevision()); - assertEquals("int16", int16ExtQName.getLocalName()); - assertNull(int16Ext.getUnits()); - assertNull(int16Ext.getDefaultValue()); - assertNull(int16Ext.getFractionDigits()); - assertTrue(int16Ext.getLengthConstraints().isEmpty()); - assertTrue(int16Ext.getPatternConstraints().isEmpty()); - List ranges = int16Ext.getRangeConstraints(); - assertEquals(1, ranges.size()); - RangeConstraint range = ranges.get(0); - assertEquals(BigInteger.ONE, range.getMin()); - assertEquals(BigInteger.valueOf(100), range.getMax()); - - assertTrue(int16Ext.getBaseType() instanceof Int16); - } - - @Test - public void testChoice() { - Module foo = TestUtils.findModule(modules, "foo"); - ContainerSchemaNode transfer = (ContainerSchemaNode) foo.getDataChildByName("transfer"); - ChoiceSchemaNode how = (ChoiceSchemaNode) transfer.getDataChildByName("how"); - Set cases = how.getCases(); - assertEquals(5, cases.size()); - ChoiceCaseNode input = null; - ChoiceCaseNode output = null; - for (ChoiceCaseNode caseNode : cases) { - if ("input".equals(caseNode.getQName().getLocalName())) { - input = caseNode; - } else if ("output".equals(caseNode.getQName().getLocalName())) { - output = caseNode; - } - } - assertNotNull(input); - assertNotNull(input.getPath()); - assertNotNull(output); - assertNotNull(output.getPath()); - } - - @Test - public void testDeviation() { - Module foo = TestUtils.findModule(modules, "foo"); - Set deviations = foo.getDeviations(); - assertEquals(1, deviations.size()); - Deviation dev = deviations.iterator().next(); - assertEquals("system/user ref", dev.getReference()); - - List path = new ArrayList<>(); - path.add(QName.create(barNS, barRev, "interfaces")); - path.add(QName.create(barNS, barRev, "ifEntry")); - SchemaPath expectedPath = SchemaPath.create(path, true); - - assertEquals(expectedPath, dev.getTargetPath()); - assertEquals(Deviate.ADD, dev.getDeviate()); - } - - @Test - public void testUnknownNode() { - Module baz = TestUtils.findModule(modules, "baz"); - ContainerSchemaNode network = (ContainerSchemaNode) baz.getDataChildByName("network"); - List unknownNodes = network.getUnknownSchemaNodes(); - assertEquals(1, unknownNodes.size()); - UnknownSchemaNode unknownNode = unknownNodes.get(0); - assertNotNull(unknownNode.getNodeType()); - assertEquals("point", unknownNode.getNodeParameter()); - } - - @Test - public void testFeature() { - Module baz = TestUtils.findModule(modules, "baz"); - Set features = baz.getFeatures(); - assertEquals(1, features.size()); - } - - @Test - public void testExtension() { - Module baz = TestUtils.findModule(modules, "baz"); - List extensions = baz.getExtensionSchemaNodes(); - assertEquals(1, extensions.size()); - ExtensionDefinition extension = extensions.get(0); - assertEquals("name", extension.getArgument()); - assertEquals("Takes as argument a name string. Makes the code generator use the given name in the #define.", - extension.getDescription()); - assertTrue(extension.isYinElement()); - } - - @Test - public void testNotification() { - Module baz = TestUtils.findModule(modules, "baz"); - String expectedPrefix = "c"; - - Set notifications = baz.getNotifications(); - assertEquals(1, notifications.size()); - - NotificationDefinition notification = notifications.iterator().next(); - // test SchemaNode args - QName expectedQName = QName.create(bazNS, bazRev, "event"); - assertEquals(expectedQName, notification.getQName()); - SchemaPath expectedPath = TestUtils.createPath(true, bazNS, bazRev, expectedPrefix, "event"); - assertEquals(expectedPath, notification.getPath()); - assertNull(notification.getDescription()); - assertNull(notification.getReference()); - assertEquals(Status.CURRENT, notification.getStatus()); - assertEquals(0, notification.getUnknownSchemaNodes().size()); - // test DataNodeContainer args - assertEquals(0, notification.getTypeDefinitions().size()); - assertEquals(3, notification.getChildNodes().size()); - assertEquals(0, notification.getGroupings().size()); - assertEquals(0, notification.getUses().size()); - - LeafSchemaNode eventClass = (LeafSchemaNode) notification.getDataChildByName("event-class"); - assertTrue(eventClass.getType() instanceof StringType); - LeafSchemaNode severity = (LeafSchemaNode) notification.getDataChildByName("severity"); - assertTrue(severity.getType() instanceof StringType); - } - - @Test - public void testRpc() { - Module baz = TestUtils.findModule(modules, "baz"); - - Set rpcs = baz.getRpcs(); - assertEquals(1, rpcs.size()); - - RpcDefinition rpc = rpcs.iterator().next(); - assertEquals("Retrieve all or part of a specified configuration.", rpc.getDescription()); - assertEquals("RFC 6241, Section 7.1", rpc.getReference()); - } - - @Test - public void testTypePath() throws ParseException { - Module bar = TestUtils.findModule(modules, "bar"); - Set> types = bar.getTypeDefinitions(); - - // int32-ext1 - ExtendedType int32ext1 = (ExtendedType) TestUtils.findTypedef(types, "int32-ext1"); - QName int32TypedefQName = int32ext1.getQName(); - - assertEquals(barNS, int32TypedefQName.getNamespace()); - assertEquals(barRev, int32TypedefQName.getRevision()); - assertEquals("int32-ext1", int32TypedefQName.getLocalName()); - - SchemaPath typeSchemaPath = int32ext1.getPath(); - Iterable typePath = typeSchemaPath.getPathFromRoot(); - Iterator typePathIt = typePath.iterator(); - assertEquals(int32TypedefQName, typePathIt.next()); - assertFalse(typePathIt.hasNext()); - - // int32-ext1/int32 - Int32 int32 = (Int32) int32ext1.getBaseType(); - assertEquals(Int32.getInstance(), int32); - } - - @Test - public void testTypePath2() throws ParseException { - Module bar = TestUtils.findModule(modules, "bar"); - Set> types = bar.getTypeDefinitions(); - - // my-decimal-type - ExtendedType myDecType = (ExtendedType) TestUtils.findTypedef(types, "my-decimal-type"); - QName myDecTypeQName = myDecType.getQName(); - - assertEquals(barNS, myDecTypeQName.getNamespace()); - assertEquals(barRev, myDecTypeQName.getRevision()); - assertEquals("my-decimal-type", myDecTypeQName.getLocalName()); - - SchemaPath typeSchemaPath = myDecType.getPath(); - Iterable typePath = typeSchemaPath.getPathFromRoot(); - Iterator typePathIt = typePath.iterator(); - assertEquals(myDecTypeQName, typePathIt.next()); - assertFalse(typePathIt.hasNext()); - - // my-base-int32-type/int32 - Decimal64 dec64 = (Decimal64) myDecType.getBaseType(); - QName dec64QName = dec64.getQName(); - - assertEquals(URI.create("urn:ietf:params:xml:ns:yang:1"), dec64QName.getNamespace()); - assertNull(dec64QName.getRevision()); - assertEquals("decimal64", dec64QName.getLocalName()); - - SchemaPath dec64SchemaPath = dec64.getPath(); - Iterable dec64Path = dec64SchemaPath.getPathFromRoot(); - Iterator dec64PathIt = dec64Path.iterator(); - assertEquals(myDecTypeQName, dec64PathIt.next()); - assertEquals(dec64QName, dec64PathIt.next()); - assertFalse(dec64PathIt.hasNext()); - } - - @Test - public void testParseMethod1() throws Exception { - File yangFile = new File(getClass().getResource("/parse-methods/m1.yang").toURI()); - File dependenciesDir = new File(getClass().getResource("/parse-methods").toURI()); - YangContextParser parser = new YangParserImpl(); - modules = parser.parseFile(yangFile, dependenciesDir).getModules(); - assertEquals(6, modules.size()); - } - - @Test - public void testParseMethod2() throws Exception { - File yangFile = new File(getClass().getResource("/parse-methods/m1.yang").toURI()); - File dependenciesDir = new File(getClass().getResource("/parse-methods/dependencies").toURI()); - YangContextParser parser = new YangParserImpl(); - modules = parser.parseFile(yangFile, dependenciesDir).getModules(); - assertEquals(6, modules.size()); - } - - @Test - public void testSorting() throws Exception { - // Correct order: m2, m4, m6, m8, m7, m6, m3, m1 - File yangFile = new File(getClass().getResource("/sorting-test/m1.yang").toURI()); - File dependenciesDir = new File(getClass().getResource("/sorting-test").toURI()); - YangContextParser parser = new YangParserImpl(); - modules = parser.parseFile(yangFile, dependenciesDir).getModules(); - SchemaContext ctx = new SchemaContextImpl(modules, Collections.emptyMap()); - checkOrder(modules); - assertSetEquals(modules, ctx.getModules()); - - // ########## - parser = new YangParserImpl(); - final File testDir = dependenciesDir; - final String[] fileList = testDir.list(); - final List testFiles = new ArrayList<>(); - if (fileList == null) { - throw new FileNotFoundException(dependenciesDir.getAbsolutePath()); - } - for (String fileName : fileList) { - testFiles.add(new File(testDir, fileName)); - } - Set newModules = parser.parseFiles(testFiles).getModules(); - assertSetEquals(newModules, modules); - ctx = new SchemaContextImpl(newModules, Collections.emptyMap()); - assertSetEquals(newModules, ctx.getModules()); - // ########## - newModules = parser.parseFiles(testFiles, null).getModules(); - assertSetEquals(newModules, modules); - ctx = new SchemaContextImpl(newModules, Collections.emptyMap()); - assertSetEquals(newModules, ctx.getModules()); - // ########## - List streams = new ArrayList<>(); - for (File f : testFiles) { - streams.add(new FileInputStream(f)); - } - newModules = parser.parseSources(BuilderUtils.filesToByteSources(testFiles)).getModules(); - assertSetEquals(newModules, modules); - ctx = new SchemaContextImpl(newModules, Collections.emptyMap()); - assertSetEquals(newModules, ctx.getModules()); - // ########## - streams.clear(); - for (File f : testFiles) { - streams.add(new FileInputStream(f)); - } - newModules = parser.parseSources(BuilderUtils.filesToByteSources(testFiles), null).getModules(); - assertSetEquals(newModules, modules); - ctx = new SchemaContextImpl(newModules, Collections.emptyMap()); - assertSetEquals(newModules, ctx.getModules()); - } - - private static void checkOrder(final Collection modules) { - Iterator it = modules.iterator(); - Module m = it.next(); - assertEquals("m2", m.getName()); - m = it.next(); - assertEquals("m4", m.getName()); - m = it.next(); - assertEquals("m6", m.getName()); - m = it.next(); - assertEquals("m8", m.getName()); - m = it.next(); - assertEquals("m7", m.getName()); - m = it.next(); - assertEquals("m5", m.getName()); - m = it.next(); - assertEquals("m3", m.getName()); - m = it.next(); - assertEquals("m1", m.getName()); - } - - private static void assertSetEquals(final Set s1, final Set s2) { - assertEquals(s1, s2); - Iterator it = s1.iterator(); - for (Module m : s2) { - assertEquals(m, it.next()); - } - } - - @Test - public void testSubmodules() throws Exception { - Module foo = TestUtils.findModule(modules, "foo"); - - DataSchemaNode id = foo.getDataChildByName("id"); - assertNotNull(id); - DataSchemaNode subExt = foo.getDataChildByName("sub-ext"); - assertNotNull(subExt); - DataSchemaNode subTransfer = foo.getDataChildByName("sub-transfer"); - assertNotNull(subTransfer); - - assertEquals(2, foo.getExtensionSchemaNodes().size()); - assertEquals(2, foo.getAugmentations().size()); - } - - @Test - public void unknownStatementInSubmoduleHeaderTest() throws IOException, URISyntaxException { - - File yang = new File(getClass().getResource("/yang-grammar-test/submodule-header-extension.yang").toURI()); - - try { - YangParserImpl.getInstance().parseFile(yang, yang.getParentFile()); - } catch (YangSyntaxErrorException | YangParseException e) { - e.printStackTrace(); - fail("YangSyntaxErrorException or YangParseException should not be thrown"); - } - - } - - @Test - public void unknownStatementBetweenRevisionsTest() throws IOException, URISyntaxException { - - File yangModul = new File(getClass().getResource("/yang-grammar-test/revisions-extension.yang").toURI()); - File yangSubmodul = new File(getClass().getResource("/yang-grammar-test/submodule-header-extension.yang") - .toURI()); - - List yangs = new ArrayList<>(); - yangs.add(yangModul); - yangs.add(yangSubmodul); - - try { - YangParserImpl.getInstance().parseFiles(yangs); - } catch (YangParseException e) { - e.printStackTrace(); - fail("YangParseException should not be thrown"); - } - } - - @Test - public void unknownStatementsInStatementsTest() throws IOException, URISyntaxException { - File yangModule1 = new File(getClass().getResource("/yang-grammar-test/stmtsep-in-statements.yang").toURI()); - File yangModule2 = new File(getClass().getResource("/yang-grammar-test/stmtsep-in-statements2.yang").toURI()); - File yangSubModule = new File(getClass().getResource("/yang-grammar-test/stmtsep-in-statements-sub.yang").toURI()); - - List yangs = new ArrayList<>(); - yangs.add(yangModule1); - yangs.add(yangModule2); - yangs.add(yangSubModule); - - try { - YangParserImpl.getInstance().parseFiles(yangs); - } catch (YangParseException e) { - e.printStackTrace(); - fail("YangParseException should not be thrown"); - } - } -} diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/YangParserWithContextTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/YangParserWithContextTest.java deleted file mode 100644 index 3103774910..0000000000 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/YangParserWithContextTest.java +++ /dev/null @@ -1,400 +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.yang.parser.impl; - -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.collect.Lists; -import com.google.common.io.ByteSource; -import com.google.common.io.Resources; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.math.BigInteger; -import java.net.URI; -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.Date; -import java.util.List; -import java.util.Map; -import java.util.Set; -import org.junit.Test; -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.model.api.AnyXmlSchemaNode; -import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode; -import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode; -import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; -import org.opendaylight.yangtools.yang.model.api.Deviation; -import org.opendaylight.yangtools.yang.model.api.Deviation.Deviate; -import org.opendaylight.yangtools.yang.model.api.GroupingDefinition; -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.MustDefinition; -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.UnknownSchemaNode; -import org.opendaylight.yangtools.yang.model.api.UsesNode; -import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint; -import org.opendaylight.yangtools.yang.model.parser.api.YangContextParser; -import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException; -import org.opendaylight.yangtools.yang.model.util.ExtendedType; - -public class YangParserWithContextTest { - private final DateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); - private final YangParserImpl parser = new YangParserImpl(); - - private SchemaContext createContext(final String... resources) throws IOException, YangSyntaxErrorException { - final List srcs = new ArrayList<>(resources.length); - for (String resource : resources) { - srcs.add(Resources.asByteSource(getClass().getResource(resource))); - } - - return parser.parseSources(srcs); - } - - @Test - public void testTypeFromContext() throws Exception { - SchemaContext context = createContext("/ietf/ietf-inet-types@2010-09-24.yang"); - - InputStream stream2 = new FileInputStream(new File(getClass().getResource("/context-test/test1.yang").toURI())); - Module module = TestUtils.loadModuleWithContext("test1", stream2, context); - stream2.close(); - assertNotNull(module); - - LeafSchemaNode leaf = (LeafSchemaNode) module.getDataChildByName("id"); - - ExtendedType leafType = (ExtendedType) leaf.getType(); - QName qname = leafType.getQName(); - assertEquals(URI.create("urn:simple.demo.test1"), qname.getNamespace()); - assertEquals(simpleDateFormat.parse("2013-06-18"), qname.getRevision()); - assertEquals("port-number", qname.getLocalName()); - - ExtendedType leafBaseType = (ExtendedType) leafType.getBaseType(); - qname = leafBaseType.getQName(); - assertEquals(URI.create("urn:ietf:params:xml:ns:yang:ietf-inet-types"), qname.getNamespace()); - assertEquals(simpleDateFormat.parse("2010-09-24"), qname.getRevision()); - assertEquals("port-number", qname.getLocalName()); - - ExtendedType dscpExt = (ExtendedType) TestUtils.findTypedef(module.getTypeDefinitions(), "dscp-ext"); - List ranges = dscpExt.getRangeConstraints(); - assertEquals(1, ranges.size()); - RangeConstraint range = ranges.get(0); - assertEquals(BigInteger.ZERO, range.getMin()); - assertEquals(BigInteger.valueOf(63), range.getMax()); - } - - @Test - public void testUsesFromContext() throws Exception { - SchemaContext context = createContext("/model/baz.yang", "/model/bar.yang", "/model/foo.yang", "/model/subfoo.yang"); - Module testModule; - try (InputStream stream = new FileInputStream(new File(getClass().getResource("/context-test/test2.yang") - .toURI()))) { - testModule = TestUtils.loadModuleWithContext("test2", stream, context); - } - assertNotNull(testModule); - - // suffix _u = added by uses - // suffix _g = defined in grouping from context - - // get grouping - Module contextModule = context.findModuleByNamespace(URI.create("urn:opendaylight.baz")).iterator().next(); - assertNotNull(contextModule); - Set groupings = contextModule.getGroupings(); - assertEquals(1, groupings.size()); - GroupingDefinition grouping = groupings.iterator().next(); - - // get node containing uses - ContainerSchemaNode peer = (ContainerSchemaNode) testModule.getDataChildByName("peer"); - ContainerSchemaNode destination = (ContainerSchemaNode) peer.getDataChildByName("destination"); - - // check uses - Set uses = destination.getUses(); - assertEquals(1, uses.size()); - - // check uses process - AnyXmlSchemaNode data_u = (AnyXmlSchemaNode) destination.getDataChildByName("data"); - assertNotNull(data_u); - assertTrue(data_u.isAddedByUses()); - - AnyXmlSchemaNode data_g = (AnyXmlSchemaNode) grouping.getDataChildByName("data"); - assertNotNull(data_g); - assertFalse(data_g.isAddedByUses()); - assertFalse(data_u.equals(data_g)); - - ChoiceSchemaNode how_u = (ChoiceSchemaNode) destination.getDataChildByName("how"); - assertNotNull(how_u); - assertTrue(how_u.isAddedByUses()); - - ChoiceSchemaNode how_g = (ChoiceSchemaNode) grouping.getDataChildByName("how"); - assertNotNull(how_g); - assertFalse(how_g.isAddedByUses()); - assertFalse(how_u.equals(how_g)); - - LeafSchemaNode address_u = (LeafSchemaNode) destination.getDataChildByName("address"); - assertNotNull(address_u); - assertTrue(address_u.isAddedByUses()); - - LeafSchemaNode address_g = (LeafSchemaNode) grouping.getDataChildByName("address"); - assertNotNull(address_g); - assertFalse(address_g.isAddedByUses()); - assertFalse(address_u.equals(address_g)); - - ContainerSchemaNode port_u = (ContainerSchemaNode) destination.getDataChildByName("port"); - assertNotNull(port_u); - assertTrue(port_u.isAddedByUses()); - - ContainerSchemaNode port_g = (ContainerSchemaNode) grouping.getDataChildByName("port"); - assertNotNull(port_g); - assertFalse(port_g.isAddedByUses()); - assertFalse(port_u.equals(port_g)); - - ListSchemaNode addresses_u = (ListSchemaNode) destination.getDataChildByName("addresses"); - assertNotNull(addresses_u); - assertTrue(addresses_u.isAddedByUses()); - - ListSchemaNode addresses_g = (ListSchemaNode) grouping.getDataChildByName("addresses"); - assertNotNull(addresses_g); - assertFalse(addresses_g.isAddedByUses()); - assertFalse(addresses_u.equals(addresses_g)); - - // grouping defined by 'uses' - Set groupings_u = destination.getGroupings(); - assertEquals(1, groupings_u.size()); - GroupingDefinition grouping_u = groupings_u.iterator().next(); - assertTrue(grouping_u.isAddedByUses()); - - // grouping defined in 'grouping' node - Set groupings_g = grouping.getGroupings(); - assertEquals(1, groupings_g.size()); - GroupingDefinition grouping_g = groupings_g.iterator().next(); - assertFalse(grouping_g.isAddedByUses()); - assertFalse(grouping_u.equals(grouping_g)); - - List nodes_u = destination.getUnknownSchemaNodes(); - assertEquals(1, nodes_u.size()); - UnknownSchemaNode node_u = nodes_u.get(0); - assertTrue(node_u.isAddedByUses()); - - List nodes_g = grouping.getUnknownSchemaNodes(); - assertEquals(1, nodes_g.size()); - UnknownSchemaNode node_g = nodes_g.get(0); - assertFalse(node_g.isAddedByUses()); - assertFalse(node_u.equals(node_g)); - } - - @Test - public void testUsesRefineFromContext() throws Exception { - SchemaContext context = createContext("/model/baz.yang", "/model/bar.yang", "/model/foo.yang", "/model/subfoo.yang"); - - Module module; - try (InputStream stream = new FileInputStream(new File(getClass().getResource("/context-test/test2.yang") - .toURI()))) { - module = TestUtils.loadModuleWithContext("test2", stream, context); - } - assertNotNull(module); - - ContainerSchemaNode peer = (ContainerSchemaNode) module.getDataChildByName("peer"); - ContainerSchemaNode destination = (ContainerSchemaNode) peer.getDataChildByName("destination"); - Set usesNodes = destination.getUses(); - assertEquals(1, usesNodes.size()); - UsesNode usesNode = usesNodes.iterator().next(); - - // test grouping path - List path = new ArrayList<>(); - QName qname = QName.create(URI.create("urn:opendaylight.baz"), simpleDateFormat.parse("2013-02-27"), "target"); - path.add(qname); - SchemaPath expectedPath = SchemaPath.create(path, true); - assertEquals(expectedPath, usesNode.getGroupingPath()); - - // test refine - Map refines = usesNode.getRefines(); - assertEquals(3, refines.size()); - - LeafSchemaNode refineLeaf = null; - ContainerSchemaNode refineContainer = null; - ListSchemaNode refineList = null; - for (Map.Entry entry : refines.entrySet()) { - SchemaNode value = entry.getValue(); - if (value instanceof LeafSchemaNode) { - refineLeaf = (LeafSchemaNode) value; - } else if (value instanceof ContainerSchemaNode) { - refineContainer = (ContainerSchemaNode) value; - } else if (value instanceof ListSchemaNode) { - refineList = (ListSchemaNode) value; - } - } - - // leaf address - assertNotNull(refineLeaf); - assertEquals("address", refineLeaf.getQName().getLocalName()); - assertEquals("description of address defined by refine", refineLeaf.getDescription()); - assertEquals("address reference added by refine", refineLeaf.getReference()); - assertFalse(refineLeaf.isConfiguration()); - assertTrue(refineLeaf.getConstraints().isMandatory()); - Set leafMustConstraints = refineLeaf.getConstraints().getMustConstraints(); - assertEquals(1, leafMustConstraints.size()); - MustDefinition leafMust = leafMustConstraints.iterator().next(); - assertEquals("\"ifType != 'ethernet' or (ifType = 'ethernet' and ifMTU = 1500)\"", leafMust.toString()); - - // container port - assertNotNull(refineContainer); - Set mustConstraints = refineContainer.getConstraints().getMustConstraints(); - assertTrue(mustConstraints.isEmpty()); - assertEquals("description of port defined by refine", refineContainer.getDescription()); - assertEquals("port reference added by refine", refineContainer.getReference()); - assertFalse(refineContainer.isConfiguration()); - assertTrue(refineContainer.isPresenceContainer()); - - // list addresses - assertNotNull(refineList); - assertEquals("description of addresses defined by refine", refineList.getDescription()); - assertEquals("addresses reference added by refine", refineList.getReference()); - assertFalse(refineList.isConfiguration()); - assertEquals(2, (int) refineList.getConstraints().getMinElements()); - assertEquals(12, (int) refineList.getConstraints().getMaxElements()); - } - - @Test - public void testIdentity() throws Exception { - SchemaContext context; - File yangFile = new File(getClass().getResource("/types/custom-types-test@2012-4-4.yang").toURI()); - File dependenciesDir = new File(getClass().getResource("/ietf").toURI()); - YangContextParser parser = new YangParserImpl(); - context = parser.parseFile(yangFile, dependenciesDir); - - Module module; - try (InputStream stream = new FileInputStream(new File(getClass().getResource("/context-test/test3.yang") - .toURI()))) { - module = TestUtils.loadModuleWithContext("test3", stream, context); - } - assertNotNull(module); - - Set identities = module.getIdentities(); - assertEquals(1, identities.size()); - - IdentitySchemaNode identity = identities.iterator().next(); - QName idQName = identity.getQName(); - assertEquals(URI.create("urn:simple.demo.test3"), idQName.getNamespace()); - assertEquals(simpleDateFormat.parse("2013-06-18"), idQName.getRevision()); - assertEquals("pt", idQName.getLocalName()); - - IdentitySchemaNode baseIdentity = identity.getBaseIdentity(); - QName idBaseQName = baseIdentity.getQName(); - assertEquals(URI.create("urn:custom.types.demo"), idBaseQName.getNamespace()); - assertEquals(simpleDateFormat.parse("2012-04-16"), idBaseQName.getRevision()); - assertEquals("service-type", idBaseQName.getLocalName()); - } - - @Test - public void testUnknownNodes() throws Exception { - SchemaContext context; - File yangFile = new File(getClass().getResource("/types/custom-types-test@2012-4-4.yang").toURI()); - File dependenciesDir = new File(getClass().getResource("/ietf").toURI()); - YangContextParser parser = new YangParserImpl(); - context = parser.parseFile(yangFile, dependenciesDir); - - Module module; - try (InputStream stream = new FileInputStream(new File(getClass().getResource("/context-test/test3.yang") - .toURI()))) { - module = TestUtils.loadModuleWithContext("test3", stream, context); - } - - ContainerSchemaNode network = (ContainerSchemaNode) module.getDataChildByName("network"); - List unknownNodes = network.getUnknownSchemaNodes(); - assertEquals(1, unknownNodes.size()); - - UnknownSchemaNode un = unknownNodes.get(0); - QName unType = un.getNodeType(); - assertEquals(URI.create("urn:custom.types.demo"), unType.getNamespace()); - assertEquals(simpleDateFormat.parse("2012-04-16"), unType.getRevision()); - assertEquals("mountpoint", unType.getLocalName()); - assertEquals("point", un.getNodeParameter()); - assertNotNull(un.getExtensionDefinition()); - } - - @Test - public void testAugment() throws Exception { - // load first module - String resource = "/context-augment-test/test4.yang"; - SchemaContext context = parser.parseFiles(Collections.singleton(new File(getClass().getResource(resource) - .toURI()))); - - // load another modules and parse them against already existing context - File test1 = new File(getClass().getResource("/context-augment-test/test1.yang").toURI()); - File test2 = new File(getClass().getResource("/context-augment-test/test2.yang").toURI()); - File test3 = new File(getClass().getResource("/context-augment-test/test3.yang").toURI()); - Set modules = parser.parseFiles(Arrays.asList(test1, test2, test3), context).getModules(); - assertNotNull(modules); - - Module t4 = TestUtils.findModule(modules, "test4"); - ContainerSchemaNode interfaces = (ContainerSchemaNode) t4.getDataChildByName("interfaces"); - ListSchemaNode ifEntry = (ListSchemaNode) interfaces.getDataChildByName("ifEntry"); - - // test augmentation process - ContainerSchemaNode augmentHolder = (ContainerSchemaNode) ifEntry.getDataChildByName("augment-holder"); - assertNotNull(augmentHolder); - DataSchemaNode ds0 = augmentHolder.getDataChildByName("ds0ChannelNumber"); - assertNotNull(ds0); - DataSchemaNode interfaceId = augmentHolder.getDataChildByName("interface-id"); - assertNotNull(interfaceId); - DataSchemaNode higherLayerIf = augmentHolder.getDataChildByName("higher-layer-if"); - assertNotNull(higherLayerIf); - ContainerSchemaNode schemas = (ContainerSchemaNode) augmentHolder.getDataChildByName("schemas"); - assertNotNull(schemas); - assertNotNull(schemas.getDataChildByName("id")); - - // test augment target after augmentation: check if it is same instance - ListSchemaNode ifEntryAfterAugment = (ListSchemaNode) interfaces.getDataChildByName("ifEntry"); - assertTrue(ifEntry == ifEntryAfterAugment); - } - - @Test - public void testDeviation() throws Exception { - // load first module - SchemaContext context = parser.parseFiles(Collections.singleton( - new File(getClass().getResource("/model/bar.yang").toURI()))); - - // load another modules and parse them against already existing context - Set modules; - try (InputStream stream = new FileInputStream(new File(getClass().getResource( - "/context-test/deviation-test.yang").toURI()))) { - List input = Lists.newArrayList(stream); - modules = TestUtils.loadModulesWithContext(input, context); - } - assertNotNull(modules); - - // test deviation - Module testModule = TestUtils.findModule(modules, "deviation-test"); - Set deviations = testModule.getDeviations(); - assertEquals(1, deviations.size()); - Deviation dev = deviations.iterator().next(); - - assertEquals("system/user ref", dev.getReference()); - - URI expectedNS = URI.create("urn:opendaylight.bar"); - DateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); - Date expectedRev = simpleDateFormat.parse("2013-07-03"); - List path = new ArrayList<>(); - path.add(QName.create(expectedNS, expectedRev, "interfaces")); - path.add(QName.create(expectedNS, expectedRev, "ifEntry")); - SchemaPath expectedPath = SchemaPath.create(path, true); - - assertEquals(expectedPath, dev.getTargetPath()); - assertEquals(Deviate.ADD, dev.getDeviate()); - } - -} diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/util/SchemaContextUtilTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/util/SchemaContextUtilTest.java index 3b7bcb60fb..7a166f7af2 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/util/SchemaContextUtilTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/util/SchemaContextUtilTest.java @@ -38,7 +38,8 @@ import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException import org.opendaylight.yangtools.yang.model.util.Int32; import org.opendaylight.yangtools.yang.model.util.RevisionAwareXPathImpl; import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil; -import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl; +import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; +import org.opendaylight.yangtools.yang.stmt.TestUtils; public class SchemaContextUtilTest { @Mock @@ -73,13 +74,9 @@ public class SchemaContextUtilTest { @Test public void findNodeInSchemaContextTest() throws URISyntaxException, IOException, YangSyntaxErrorException, - ParseException { + ParseException, ReactorException { - File resourceFile = new File(getClass().getResource("/schema-context-util-test/my-module.yang").toURI()); - File resourceDir = resourceFile.getParentFile(); - - YangParserImpl parser = YangParserImpl.getInstance(); - SchemaContext context = parser.parseFile(resourceFile, resourceDir); + SchemaContext context = TestUtils.parseYangSources("/schema-context-util-test"); Module myModule = context.findModuleByNamespaceAndRevision(new URI("uri:my-module"), QName.parseRevision("2014-10-07")); @@ -191,13 +188,9 @@ public class SchemaContextUtilTest { @Test public void findNodeInSchemaContextTest2() throws URISyntaxException, IOException, YangSyntaxErrorException, - ParseException { - - File resourceFile = new File(getClass().getResource("/schema-context-util-test/my-module.yang").toURI()); - File resourceDir = resourceFile.getParentFile(); + ParseException, ReactorException { - YangParserImpl parser = YangParserImpl.getInstance(); - SchemaContext context = parser.parseFile(resourceFile, resourceDir); + SchemaContext context = TestUtils.parseYangSources("/schema-context-util-test") ; Module myModule = context.findModuleByNamespaceAndRevision(new URI("uri:my-module"), QName.parseRevision("2014-10-07")); @@ -289,13 +282,9 @@ public class SchemaContextUtilTest { @Test public void findNodeInSchemaContextTest3() throws URISyntaxException, IOException, YangSyntaxErrorException, - ParseException { - - File resourceFile = new File(getClass().getResource("/schema-context-util-test/my-module.yang").toURI()); - File resourceDir = resourceFile.getParentFile(); + ParseException, ReactorException { - YangParserImpl parser = YangParserImpl.getInstance(); - SchemaContext context = parser.parseFile(resourceFile, resourceDir); + SchemaContext context = TestUtils.parseYangSources("/schema-context-util-test"); Module myModule = context.findModuleByNamespaceAndRevision(new URI("uri:my-module"), QName.parseRevision("2014-10-07")); @@ -358,13 +347,10 @@ public class SchemaContextUtilTest { } @Test - public void findParentModuleTest() throws URISyntaxException, IOException, YangSyntaxErrorException, ParseException { + public void findParentModuleTest() throws URISyntaxException, IOException, YangSyntaxErrorException, ParseException, + ReactorException { - File resourceFile = new File(getClass().getResource("/schema-context-util-test/my-module.yang").toURI()); - File resourceDir = resourceFile.getParentFile(); - - YangParserImpl parser = YangParserImpl.getInstance(); - SchemaContext context = parser.parseFile(resourceFile, resourceDir); + SchemaContext context = TestUtils.parseYangSources("/schema-context-util-test"); Module myModule = context.findModuleByNamespaceAndRevision(new URI("uri:my-module"), QName.parseRevision("2014-10-07")); @@ -419,13 +405,10 @@ public class SchemaContextUtilTest { } @Test - public void findDataSchemaNodeTest() throws URISyntaxException, IOException, YangSyntaxErrorException { - - File resourceFile = new File(getClass().getResource("/schema-context-util-test/my-module.yang").toURI()); - File resourceDir = resourceFile.getParentFile(); + public void findDataSchemaNodeTest() throws URISyntaxException, IOException, YangSyntaxErrorException, + ReactorException { - YangParserImpl parser = YangParserImpl.getInstance(); - SchemaContext context = parser.parseFile(resourceFile, resourceDir); + SchemaContext context = TestUtils.parseYangSources("/schema-context-util-test"); Module module = context.findModuleByNamespaceAndRevision(new URI("uri:my-module"), QName.parseRevision("2014-10-07")); @@ -446,15 +429,11 @@ public class SchemaContextUtilTest { } @Test - public void findDataSchemaNodeTest2() throws URISyntaxException, IOException, YangSyntaxErrorException { + public void findDataSchemaNodeTest2() throws URISyntaxException, IOException, YangSyntaxErrorException, ReactorException { // findDataSchemaNode(final SchemaContext context, final Module module, // final RevisionAwareXPath nonCondXPath) { - File resourceFile = new File(getClass().getResource("/schema-context-util-test/my-module.yang").toURI()); - File resourceDir = resourceFile.getParentFile(); - - YangParserImpl parser = YangParserImpl.getInstance(); - SchemaContext context = parser.parseFile(resourceFile, resourceDir); + SchemaContext context = TestUtils.parseYangSources("/schema-context-util-test"); Module module = context.findModuleByNamespaceAndRevision(new URI("uri:my-module"), QName.parseRevision("2014-10-07")); @@ -539,13 +518,9 @@ public class SchemaContextUtilTest { @Test public void findNodeInSchemaContextGroupingsTest() throws URISyntaxException, IOException, - YangSyntaxErrorException, ParseException { - - File resourceFile = new File(getClass().getResource("/schema-context-util-test/my-module.yang").toURI()); - File resourceDir = resourceFile.getParentFile(); + YangSyntaxErrorException, ParseException, ReactorException { - YangParserImpl parser = YangParserImpl.getInstance(); - SchemaContext context = parser.parseFile(resourceFile, resourceDir); + SchemaContext context = TestUtils.parseYangSources("/schema-context-util-test"); Module myModule = context.findModuleByNamespaceAndRevision(new URI("uri:my-module"), QName.parseRevision("2014-10-07")); @@ -733,13 +708,9 @@ public class SchemaContextUtilTest { @Test public void findNodeInSchemaContextGroupingsTest2() throws URISyntaxException, IOException, - YangSyntaxErrorException, ParseException { + YangSyntaxErrorException, ParseException, ReactorException { - File resourceFile = new File(getClass().getResource("/schema-context-util-test/my-module.yang").toURI()); - File resourceDir = resourceFile.getParentFile(); - - YangParserImpl parser = YangParserImpl.getInstance(); - SchemaContext context = parser.parseFile(resourceFile, resourceDir); + SchemaContext context = TestUtils.parseYangSources("/schema-context-util-test"); Module myModule = context.findModuleByNamespaceAndRevision(new URI("uri:my-module"), QName.parseRevision("2014-10-07")); @@ -874,13 +845,9 @@ public class SchemaContextUtilTest { @Test public void findNodeInSchemaContextTheSameNameOfSiblingsTest() throws URISyntaxException, IOException, - YangSyntaxErrorException, ParseException { - - File resourceFile = new File(getClass().getResource("/schema-context-util-test/my-module.yang").toURI()); - File resourceDir = resourceFile.getParentFile(); + YangSyntaxErrorException, ParseException, ReactorException { - YangParserImpl parser = YangParserImpl.getInstance(); - SchemaContext context = parser.parseFile(resourceFile, resourceDir); + SchemaContext context = TestUtils.parseYangSources("/schema-context-util-test"); Module myModule = context.findModuleByNamespaceAndRevision(new URI("uri:my-module"), QName.parseRevision("2014-10-07")); diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/AugmentTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/AugmentArgumentParsingTest.java similarity index 97% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/AugmentTest.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/AugmentArgumentParsingTest.java index 76503fea51..8313267f71 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/AugmentTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/AugmentArgumentParsingTest.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.stmt.test; +package org.opendaylight.yangtools.yang.stmt; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -21,7 +21,7 @@ import org.opendaylight.yangtools.yang.parser.stmt.reactor.EffectiveModelContext import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline; import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl; -public class AugmentTest { +public class AugmentArgumentParsingTest { private static final YangStatementSourceImpl IMPORTED = new YangStatementSourceImpl( "/semantic-statement-parser/augment-arg-parsing/imported.yang", false); diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/AugmentProcessTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/AugmentProcessTest.java similarity index 98% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/AugmentProcessTest.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/AugmentProcessTest.java index 890c47b0fc..4df3f4069b 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/AugmentProcessTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/AugmentProcessTest.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.stmt.test; +package org.opendaylight.yangtools.yang.stmt; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/AugmentSimplestTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/AugmentSimplestTest.java similarity index 93% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/AugmentSimplestTest.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/AugmentSimplestTest.java index e64cc5b9a4..51d0d0b5cb 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/AugmentSimplestTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/AugmentSimplestTest.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.stmt.test; +package org.opendaylight.yangtools.yang.stmt; import static org.junit.Assert.assertNotNull; diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/AugmentTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/AugmentTest.java similarity index 99% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/AugmentTest.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/AugmentTest.java index 066ece47f8..febf7b747e 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/AugmentTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/AugmentTest.java @@ -1,11 +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.yang.stmt.retest; +package org.opendaylight.yangtools.yang.stmt; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/AugmentToExtensionTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/AugmentToExtensionTest.java similarity index 89% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/AugmentToExtensionTest.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/AugmentToExtensionTest.java index 4a2b330053..a5d766fb19 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/AugmentToExtensionTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/AugmentToExtensionTest.java @@ -1,12 +1,14 @@ -/** - * 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.yang.stmt.retest; +package org.opendaylight.yangtools.yang.stmt; import static org.junit.Assert.assertTrue; -import org.opendaylight.yangtools.yang.stmt.test.StmtTestUtils; - import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException; import java.net.URISyntaxException; import java.util.Set; diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/Bug1412Test.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug1412Test.java similarity index 96% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/Bug1412Test.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug1412Test.java index 674900de1b..c87b34c022 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/Bug1412Test.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug1412Test.java @@ -1,11 +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.yang.stmt.retest; +package org.opendaylight.yangtools.yang.stmt; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/Bug1413Test.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug1413Test.java similarity index 91% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/Bug1413Test.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug1413Test.java index 31825cf1d8..22d196712b 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/Bug1413Test.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug1413Test.java @@ -1,11 +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.yang.stmt.retest; +package org.opendaylight.yangtools.yang.stmt; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/Bug2219Test.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug2219Test.java similarity index 94% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/Bug2219Test.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug2219Test.java index 5834e145f7..5a3202b03e 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/Bug2219Test.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug2219Test.java @@ -1,11 +1,11 @@ /* - * 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.yang.parser.impl; +package org.opendaylight.yangtools.yang.stmt; import static org.junit.Assert.assertNotNull; diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/Bug2291Test.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug2291Test.java similarity index 88% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/Bug2291Test.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug2291Test.java index ad6a0dd0dc..ac80873e3c 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/Bug2291Test.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug2291Test.java @@ -1,11 +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.yang.stmt.retest; +package org.opendaylight.yangtools.yang.stmt; import static org.junit.Assert.assertNotNull; import org.opendaylight.yangtools.yang.model.api.SchemaContext; diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/Bug3799Test.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug3799Test.java similarity index 85% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/Bug3799Test.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug3799Test.java index aa948710ba..c322fed9f5 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/Bug3799Test.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug3799Test.java @@ -1,4 +1,12 @@ -package org.opendaylight.yangtools.yang.stmt.test; +/* + * 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.stmt; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/Bug3859Test.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug3859Test.java similarity index 85% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/Bug3859Test.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug3859Test.java index a67ffb4981..012cc1fa55 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/Bug3859Test.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug3859Test.java @@ -1,11 +1,11 @@ /* - * 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.parser.impl; +package org.opendaylight.yangtools.yang.stmt; import static org.junit.Assert.assertNotNull; diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/Bug3874ExtensionTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug3874ExtensionTest.java similarity index 96% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/Bug3874ExtensionTest.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug3874ExtensionTest.java index e27d6e0db1..0441cca398 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/Bug3874ExtensionTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug3874ExtensionTest.java @@ -1,11 +1,11 @@ /* - * 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.stmt.test; +package org.opendaylight.yangtools.yang.stmt; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/Bug394Test.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug394Test.java similarity index 93% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/Bug394Test.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug394Test.java index 82c3165c50..6d6fc0c232 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/Bug394Test.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug394Test.java @@ -1,11 +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.yang.stmt.retest; +package org.opendaylight.yangtools.yang.stmt; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/Bug4079Test.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug4079Test.java similarity index 99% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/Bug4079Test.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug4079Test.java index 7793a61f32..1669b1a477 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/Bug4079Test.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug4079Test.java @@ -6,7 +6,7 @@ * and is available at http://www.eclipse.org/legal/epl-v10.html */ -package org.opendaylight.yangtools.yang.stmt.retest; +package org.opendaylight.yangtools.yang.stmt; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/Bug4231Test.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug4231Test.java similarity index 81% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/Bug4231Test.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug4231Test.java index 1f7ec433a0..3840f86ddf 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/Bug4231Test.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug4231Test.java @@ -1,34 +1,33 @@ /* - * 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.parser.impl; +package org.opendaylight.yangtools.yang.stmt; -import static org.junit.Assert.*; - -import java.text.ParseException; +import static org.junit.Assert.assertNotNull; +import java.io.IOException; import java.net.URI; -import org.opendaylight.yangtools.yang.model.api.SchemaNode; -import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil; -import org.opendaylight.yangtools.yang.common.QNameModule; +import java.net.URISyntaxException; +import java.text.ParseException; +import org.junit.Test; import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.model.api.SchemaPath; +import org.opendaylight.yangtools.yang.common.QNameModule; +import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil; 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.util.SchemaContextUtil; -import java.io.IOException; -import java.net.URISyntaxException; -import org.junit.Test; +import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; public class Bug4231Test { @Test - public void test() throws IOException, URISyntaxException, ParseException { - SchemaContext context = TestUtils.loadSchemaContext(getClass() - .getResource("/bugs/bug4231").toURI()); + public void test() throws IOException, URISyntaxException, ParseException, ReactorException { + SchemaContext context = TestUtils.parseYangSources("/bugs/bug4231"); assertNotNull(context); diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/Bug4410Test.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug4410Test.java similarity index 92% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/Bug4410Test.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug4410Test.java index f8a939bf01..c281af8311 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/Bug4410Test.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug4410Test.java @@ -1,11 +1,11 @@ /* - * 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.stmt.test; +package org.opendaylight.yangtools.yang.stmt; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/Bug4456Test.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug4456Test.java similarity index 96% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/Bug4456Test.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug4456Test.java index 88eb8cdba4..01cea68b48 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/Bug4456Test.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug4456Test.java @@ -1,11 +1,11 @@ /* - * 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.stmt.test; +package org.opendaylight.yangtools.yang.stmt; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/Bug4459Test.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug4459Test.java similarity index 94% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/Bug4459Test.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug4459Test.java index 2d95e5fca5..82dfcc24ee 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/Bug4459Test.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug4459Test.java @@ -1,11 +1,11 @@ /* - * 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.stmt.test; +package org.opendaylight.yangtools.yang.stmt; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/Bug4610Test.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug4610Test.java similarity index 96% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/Bug4610Test.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug4610Test.java index e3e9fb7193..2c189753f9 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/Bug4610Test.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug4610Test.java @@ -1,11 +1,11 @@ /* - * 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.stmt.test; +package org.opendaylight.yangtools.yang.stmt; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/Bug4623Test.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug4623Test.java similarity index 65% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/Bug4623Test.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug4623Test.java index 79f904e0c8..8d4ba96726 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/Bug4623Test.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug4623Test.java @@ -1,19 +1,24 @@ -package org.opendaylight.yangtools.yang.parser.impl; +/* + * 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.stmt; import java.io.File; -import java.math.BigInteger; -import java.util.Arrays; import java.util.List; - import org.junit.Assert; import org.junit.Test; import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode; import org.opendaylight.yangtools.yang.model.api.SchemaContext; +import org.opendaylight.yangtools.yang.model.api.TypeDefinition; import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode; import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint; import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint; -import org.opendaylight.yangtools.yang.model.parser.api.YangContextParser; -import org.opendaylight.yangtools.yang.model.util.ExtendedType; +import org.opendaylight.yangtools.yang.model.api.type.StringTypeDefinition; public class Bug4623Test { @@ -22,10 +27,9 @@ public class Bug4623Test { // given File extdef = new File(getClass().getResource("/bugs/bug4623/extension-def.yang").toURI()); File stringWithExt = new File(getClass().getResource("/bugs/bug4623/string-with-ext.yang").toURI()); - YangContextParser parser = new YangParserImpl(); // when - SchemaContext schemaContext = parser.parseFiles(Arrays.asList(extdef, stringWithExt)); + SchemaContext schemaContext = TestUtils.parseYangSources(extdef, stringWithExt); LeafSchemaNode leaf = (LeafSchemaNode) schemaContext .findModuleByName("types", null) @@ -33,19 +37,19 @@ public class Bug4623Test { // then Assert.assertNotNull(leaf); - Assert.assertNotNull(leaf.getType()); - final List unknownSchemaNodes = leaf.getUnknownSchemaNodes(); - Assert.assertNotNull(leaf.getUnknownSchemaNodes()); + final TypeDefinition type = leaf.getType(); + Assert.assertNotNull(type); + final List unknownSchemaNodes = type.getUnknownSchemaNodes(); + Assert.assertNotNull(unknownSchemaNodes); Assert.assertFalse(unknownSchemaNodes.size() == 0); final UnknownSchemaNode unknownSchemaNode = unknownSchemaNodes.get(0); Assert.assertEquals(unknownSchemaNode.getNodeParameter(), "unknown"); Assert.assertEquals(unknownSchemaNode.getNodeType().getModule().getNamespace().toString(), "urn:simple.extension.typedefs"); - final ExtendedType type = (ExtendedType) leaf.getType(); - final List lengthConstraints = type.getLengthConstraints(); - final List patternConstraints = type.getPatternConstraints(); + final List lengthConstraints = ((StringTypeDefinition) type).getLengthConstraints(); + final List patternConstraints = ((StringTypeDefinition) type).getPatternConstraints(); Assert.assertNotNull(lengthConstraints); Assert.assertNotNull(patternConstraints); @@ -53,23 +57,21 @@ public class Bug4623Test { Assert.assertFalse(patternConstraints.size() == 0); final LengthConstraint lengthConstraint = lengthConstraints.get(0); - Assert.assertEquals(lengthConstraint.getMin(), BigInteger.valueOf(2L)); - Assert.assertEquals(lengthConstraint.getMax(), BigInteger.TEN); + Assert.assertEquals(lengthConstraint.getMin(), Integer.valueOf(2)); + Assert.assertEquals(lengthConstraint.getMax(), Integer.valueOf(10)); final PatternConstraint patternConstraint = patternConstraints.get(0); Assert.assertEquals(patternConstraint.getRegularExpression(), "^[0-9a-fA-F]$"); } - @Test public void testStringTypeWithUnknownSchemaNodeBetweenStringRestrictionStatements() throws Exception { // given File extdef = new File(getClass().getResource("/bugs/bug4623/extension-def.yang").toURI()); File stringWithExt = new File(getClass().getResource("/bugs/bug4623/string-with-ext.yang").toURI()); - YangContextParser parser = new YangParserImpl(); // when - SchemaContext schemaContext = parser.parseFiles(Arrays.asList(extdef, stringWithExt)); + SchemaContext schemaContext = TestUtils.parseYangSources(extdef, stringWithExt); LeafSchemaNode leaf = (LeafSchemaNode) schemaContext .findModuleByName("types", null) @@ -77,19 +79,19 @@ public class Bug4623Test { // then Assert.assertNotNull(leaf); - Assert.assertNotNull(leaf.getType()); - final List unknownSchemaNodes = leaf.getUnknownSchemaNodes(); - Assert.assertNotNull(leaf.getUnknownSchemaNodes()); + final TypeDefinition type = leaf.getType(); + Assert.assertNotNull(type); + final List unknownSchemaNodes = type.getUnknownSchemaNodes(); + Assert.assertNotNull(unknownSchemaNodes); Assert.assertFalse(unknownSchemaNodes.size() == 0); final UnknownSchemaNode unknownSchemaNode = unknownSchemaNodes.get(0); Assert.assertEquals(unknownSchemaNode.getNodeParameter(), "unknown"); Assert.assertEquals(unknownSchemaNode.getNodeType().getModule().getNamespace().toString(), "urn:simple.extension.typedefs"); - final ExtendedType type = (ExtendedType) leaf.getType(); - final List lengthConstraints = type.getLengthConstraints(); - final List patternConstraints = type.getPatternConstraints(); + final List lengthConstraints = ((StringTypeDefinition) type).getLengthConstraints(); + final List patternConstraints = ((StringTypeDefinition) type).getPatternConstraints(); Assert.assertNotNull(lengthConstraints); Assert.assertNotNull(patternConstraints); @@ -97,8 +99,8 @@ public class Bug4623Test { Assert.assertFalse(patternConstraints.size() == 0); final LengthConstraint lengthConstraint = lengthConstraints.get(0); - Assert.assertEquals(lengthConstraint.getMin(), BigInteger.valueOf(2L)); - Assert.assertEquals(lengthConstraint.getMax(), BigInteger.TEN); + Assert.assertEquals(lengthConstraint.getMin(), Integer.valueOf(2)); + Assert.assertEquals(lengthConstraint.getMax(), Integer.valueOf(10)); final PatternConstraint patternConstraint = patternConstraints.get(0); Assert.assertEquals(patternConstraint.getRegularExpression(), "^[0-9a-fA-F]$"); @@ -109,10 +111,9 @@ public class Bug4623Test { // given File extdef = new File(getClass().getResource("/bugs/bug4623/extension-def.yang").toURI()); File stringWithExt = new File(getClass().getResource("/bugs/bug4623/string-with-ext.yang").toURI()); - YangContextParser parser = new YangParserImpl(); // when - SchemaContext schemaContext = parser.parseFiles(Arrays.asList(extdef, stringWithExt)); + SchemaContext schemaContext = TestUtils.parseYangSources(extdef, stringWithExt); LeafSchemaNode leaf = (LeafSchemaNode) schemaContext .findModuleByName("types", null) @@ -120,19 +121,19 @@ public class Bug4623Test { // then Assert.assertNotNull(leaf); - Assert.assertNotNull(leaf.getType()); - final List unknownSchemaNodes = leaf.getUnknownSchemaNodes(); - Assert.assertNotNull(leaf.getUnknownSchemaNodes()); + final TypeDefinition type = leaf.getType(); + Assert.assertNotNull(type); + final List unknownSchemaNodes = type.getUnknownSchemaNodes(); + Assert.assertNotNull(unknownSchemaNodes); Assert.assertFalse(unknownSchemaNodes.size() == 0); final UnknownSchemaNode unknownSchemaNode = unknownSchemaNodes.get(0); Assert.assertEquals(unknownSchemaNode.getNodeParameter(), "unknown"); Assert.assertEquals(unknownSchemaNode.getNodeType().getModule().getNamespace().toString(), "urn:simple.extension.typedefs"); - final ExtendedType type = (ExtendedType) leaf.getType(); - final List lengthConstraints = type.getLengthConstraints(); - final List patternConstraints = type.getPatternConstraints(); + final List lengthConstraints = ((StringTypeDefinition) type).getLengthConstraints(); + final List patternConstraints = ((StringTypeDefinition) type).getPatternConstraints(); Assert.assertNotNull(lengthConstraints); Assert.assertNotNull(patternConstraints); @@ -140,8 +141,8 @@ public class Bug4623Test { Assert.assertFalse(patternConstraints.size() == 0); final LengthConstraint lengthConstraint = lengthConstraints.get(0); - Assert.assertEquals(lengthConstraint.getMin(), BigInteger.valueOf(2L)); - Assert.assertEquals(lengthConstraint.getMax(), BigInteger.TEN); + Assert.assertEquals(lengthConstraint.getMin(), Integer.valueOf(2)); + Assert.assertEquals(lengthConstraint.getMax(), Integer.valueOf(10)); final PatternConstraint patternConstraint = patternConstraints.get(0); Assert.assertEquals(patternConstraint.getRegularExpression(), "^[0-9a-fA-F]$"); diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/Bug4933Test.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug4933Test.java similarity index 93% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/Bug4933Test.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug4933Test.java index 14ba17be33..b927b18325 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/Bug4933Test.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug4933Test.java @@ -1,11 +1,11 @@ /* - * 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.stmt.test; +package org.opendaylight.yangtools.yang.stmt; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/Bug5059.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug5059.java similarity index 88% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/Bug5059.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug5059.java index 35f2437ee5..87544fdb47 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/Bug5059.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug5059.java @@ -1,11 +1,11 @@ /* - * 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.stmt.test; +package org.opendaylight.yangtools.yang.stmt; import static org.junit.Assert.assertNotNull; diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/Bug5101.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug5101.java similarity index 96% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/Bug5101.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug5101.java index 38e26a2e05..a1aa9b1ea7 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/Bug5101.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug5101.java @@ -1,11 +1,11 @@ /* - * 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.stmt.test; +package org.opendaylight.yangtools.yang.stmt; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/Bug5335.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug5335.java similarity index 99% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/Bug5335.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug5335.java index 7946612974..4904566c28 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/Bug5335.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug5335.java @@ -5,7 +5,8 @@ * 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.stmt.test; + +package org.opendaylight.yangtools.yang.stmt; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/Bug5396.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug5396.java similarity index 98% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/Bug5396.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug5396.java index 932339604c..be64e022ae 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/Bug5396.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug5396.java @@ -5,7 +5,8 @@ * 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.stmt.test; + +package org.opendaylight.yangtools.yang.stmt; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/Bug5437.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug5437.java similarity index 96% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/Bug5437.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug5437.java index d912aa8696..3dcadbfc2f 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/Bug5437.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug5437.java @@ -1,11 +1,11 @@ /* - * 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.stmt.test; +package org.opendaylight.yangtools.yang.stmt; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/Bug5481.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug5481.java similarity index 98% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/Bug5481.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug5481.java index 703c5884bb..71f6a89ffa 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/Bug5481.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug5481.java @@ -5,7 +5,8 @@ * 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.stmt.test; + +package org.opendaylight.yangtools.yang.stmt; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/Bug5550.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug5550.java similarity index 93% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/Bug5550.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug5550.java index 828c7eb6f3..88952ef702 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/Bug5550.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug5550.java @@ -1,11 +1,11 @@ /* - * 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.stmt.test; +package org.opendaylight.yangtools.yang.stmt; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/Bug5693Test.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug5693Test.java similarity index 97% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/Bug5693Test.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug5693Test.java index a4cec623a6..f6f3060632 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/Bug5693Test.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug5693Test.java @@ -5,7 +5,8 @@ * 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.stmt.retest; + +package org.opendaylight.yangtools.yang.stmt; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/CaseStmtTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/CaseStmtTest.java similarity index 99% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/CaseStmtTest.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/CaseStmtTest.java index 72c001fa50..0aa86e76a7 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/CaseStmtTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/CaseStmtTest.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.stmt.test; +package org.opendaylight.yangtools.yang.stmt; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/ChoiceStmtTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/ChoiceStmtTest.java similarity index 96% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/ChoiceStmtTest.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/ChoiceStmtTest.java index b63e9d8786..e20922e2e6 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/ChoiceStmtTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/ChoiceStmtTest.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.stmt.test; +package org.opendaylight.yangtools.yang.stmt; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/ControllerStmtParserTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/ControllerStmtParserTest.java similarity index 98% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/ControllerStmtParserTest.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/ControllerStmtParserTest.java index 1a379d5a3b..8dfcfbc37f 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/ControllerStmtParserTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/ControllerStmtParserTest.java @@ -1,11 +1,11 @@ /* - * 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.stmt.test; +package org.opendaylight.yangtools.yang.stmt; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/DeclaredStatementsTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/DeclaredStatementsTest.java similarity index 99% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/DeclaredStatementsTest.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/DeclaredStatementsTest.java index fb6133449b..04eb76b7c4 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/DeclaredStatementsTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/DeclaredStatementsTest.java @@ -6,7 +6,7 @@ * and is available at http://www.eclipse.org/legal/epl-v10.html */ -package org.opendaylight.yangtools.yang.stmt.test; +package org.opendaylight.yangtools.yang.stmt; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/effective/build/test/EffectiveBuildTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/EffectiveBuildTest.java similarity index 94% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/effective/build/test/EffectiveBuildTest.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/EffectiveBuildTest.java index 31e28fdb2d..8371a46de4 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/effective/build/test/EffectiveBuildTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/EffectiveBuildTest.java @@ -1,4 +1,12 @@ -package org.opendaylight.yangtools.yang.stmt.effective.build.test; +/* + * 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.stmt; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/effective/build/test/EffectiveIdentityTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/EffectiveIdentityTest.java similarity index 92% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/effective/build/test/EffectiveIdentityTest.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/EffectiveIdentityTest.java index 109800d5df..c62354933e 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/effective/build/test/EffectiveIdentityTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/EffectiveIdentityTest.java @@ -1,4 +1,12 @@ -package org.opendaylight.yangtools.yang.stmt.effective.build.test; +/* + * 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.stmt; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -19,7 +27,6 @@ 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; -import org.opendaylight.yangtools.yang.stmt.test.StmtTestUtils; import org.junit.Test; public class EffectiveIdentityTest { diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/effective/build/test/EffectiveModuleTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/EffectiveModuleTest.java similarity index 95% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/effective/build/test/EffectiveModuleTest.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/EffectiveModuleTest.java index 257e23716c..7345f40ad8 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/effective/build/test/EffectiveModuleTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/EffectiveModuleTest.java @@ -1,4 +1,12 @@ -package org.opendaylight.yangtools.yang.stmt.effective.build.test; +/* + * 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.stmt; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/effective/build/test/EffectiveModulesAndSubmodulesTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/EffectiveModulesAndSubmodulesTest.java similarity index 95% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/effective/build/test/EffectiveModulesAndSubmodulesTest.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/EffectiveModulesAndSubmodulesTest.java index 3833dcf075..b18c07cded 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/effective/build/test/EffectiveModulesAndSubmodulesTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/EffectiveModulesAndSubmodulesTest.java @@ -1,4 +1,12 @@ -package org.opendaylight.yangtools.yang.stmt.effective.build.test; +/* + * 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.stmt; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -19,7 +27,6 @@ import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementR import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline; import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl; import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.EffectiveSchemaContext; -import org.opendaylight.yangtools.yang.stmt.test.StmtTestUtils; public class EffectiveModulesAndSubmodulesTest { diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/effective/build/test/EffectiveStatementTypeTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/EffectiveStatementTypeTest.java similarity index 99% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/effective/build/test/EffectiveStatementTypeTest.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/EffectiveStatementTypeTest.java index fb095d2aad..c819f8d8a5 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/effective/build/test/EffectiveStatementTypeTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/EffectiveStatementTypeTest.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.stmt.effective.build.test; +package org.opendaylight.yangtools.yang.stmt; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/effective/build/test/EffectiveUsesRefineAndConstraintsTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/EffectiveUsesRefineAndConstraintsTest.java similarity index 96% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/effective/build/test/EffectiveUsesRefineAndConstraintsTest.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/EffectiveUsesRefineAndConstraintsTest.java index 87147ef6ae..51a07ba69d 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/effective/build/test/EffectiveUsesRefineAndConstraintsTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/EffectiveUsesRefineAndConstraintsTest.java @@ -1,4 +1,12 @@ -package org.opendaylight.yangtools.yang.stmt.effective.build.test; +/* + * 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.stmt; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -24,7 +32,6 @@ import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementR import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline; import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl; import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.EffectiveSchemaContext; -import org.opendaylight.yangtools.yang.stmt.test.StmtTestUtils; public class EffectiveUsesRefineAndConstraintsTest { diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/ExtensionStmtTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/ExtensionStmtTest.java similarity index 97% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/ExtensionStmtTest.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/ExtensionStmtTest.java index d52a8b5483..a1656d11b7 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/ExtensionStmtTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/ExtensionStmtTest.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.stmt.test; +package org.opendaylight.yangtools.yang.stmt; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/GroupingAndUsesStmtTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/GroupingAndUsesStmtTest.java similarity index 98% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/GroupingAndUsesStmtTest.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/GroupingAndUsesStmtTest.java index 2cff899fbb..29ef6aa8e7 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/GroupingAndUsesStmtTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/GroupingAndUsesStmtTest.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.stmt.test; +package org.opendaylight.yangtools.yang.stmt; import static org.hamcrest.CoreMatchers.anyOf; import static org.hamcrest.CoreMatchers.is; diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/GroupingTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/GroupingTest.java similarity index 99% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/GroupingTest.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/GroupingTest.java index 4104c39976..4ea17ae029 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/GroupingTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/GroupingTest.java @@ -1,11 +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.yang.stmt.retest; +package org.opendaylight.yangtools.yang.stmt; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/IdentityStmtTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/IdentityStmtTest.java similarity index 98% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/IdentityStmtTest.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/IdentityStmtTest.java index 3f8551f6a9..8703c20c8d 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/IdentityStmtTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/IdentityStmtTest.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.stmt.test; +package org.opendaylight.yangtools.yang.stmt; import static org.hamcrest.CoreMatchers.anyOf; import static org.hamcrest.CoreMatchers.is; diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/ImportResolutionBasicTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/ImportResolutionBasicTest.java similarity index 97% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/ImportResolutionBasicTest.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/ImportResolutionBasicTest.java index cd56e7e472..7e1189f900 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/ImportResolutionBasicTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/ImportResolutionBasicTest.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.stmt.test; +package org.opendaylight.yangtools.yang.stmt; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/ImportRevisionsTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/ImportRevisionsTest.java similarity index 97% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/ImportRevisionsTest.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/ImportRevisionsTest.java index 67d2f7f703..57058b5b01 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/ImportRevisionsTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/ImportRevisionsTest.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.stmt.test; +package org.opendaylight.yangtools.yang.stmt; import static org.junit.Assert.assertNotNull; diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/IncludeResolutionTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/IncludeResolutionTest.java similarity index 92% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/IncludeResolutionTest.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/IncludeResolutionTest.java index 49236cffa6..745f71f22d 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/IncludeResolutionTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/IncludeResolutionTest.java @@ -1,4 +1,12 @@ -package org.opendaylight.yangtools.yang.stmt.test; +/* + * 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.stmt; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/IncludeRevisionsTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/IncludeRevisionsTest.java similarity index 94% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/IncludeRevisionsTest.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/IncludeRevisionsTest.java index 0b48f1f2c3..cfc5e89e63 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/IncludeRevisionsTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/IncludeRevisionsTest.java @@ -1,4 +1,12 @@ -package org.opendaylight.yangtools.yang.stmt.test; +/* + * 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.stmt; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/IncludedStmtsTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/IncludedStmtsTest.java similarity index 97% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/IncludedStmtsTest.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/IncludedStmtsTest.java index 111fee905e..e293bdf4c4 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/IncludedStmtsTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/IncludedStmtsTest.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.stmt.test; +package org.opendaylight.yangtools.yang.stmt; import static org.hamcrest.CoreMatchers.anyOf; import static org.hamcrest.CoreMatchers.is; diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/KeyTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/KeyTest.java similarity index 95% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/KeyTest.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/KeyTest.java index bf6fef1fab..5c3eb5f16c 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/KeyTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/KeyTest.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.stmt.test; +package org.opendaylight.yangtools.yang.stmt; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/ListKeysTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/ListKeysTest.java similarity index 97% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/ListKeysTest.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/ListKeysTest.java index 9183fae915..d772e493c1 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/ListKeysTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/ListKeysTest.java @@ -1,11 +1,11 @@ /* - * 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.stmt.retest; +package org.opendaylight.yangtools.yang.stmt; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/ListTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/ListTest.java similarity index 97% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/ListTest.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/ListTest.java index 8dae4dd336..9555b5646a 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/ListTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/ListTest.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.stmt.test; +package org.opendaylight.yangtools.yang.stmt; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/effective/build/test/MappedEffectiveBuildTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/MappedEffectiveBuildTest.java similarity index 81% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/effective/build/test/MappedEffectiveBuildTest.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/MappedEffectiveBuildTest.java index ced700c974..c541df5ab8 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/effective/build/test/MappedEffectiveBuildTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/MappedEffectiveBuildTest.java @@ -1,4 +1,12 @@ -package org.opendaylight.yangtools.yang.stmt.effective.build.test; +/* + * 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.stmt; import static org.junit.Assert.assertEquals; import java.io.FileNotFoundException; diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/ModuleIdentifierTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/ModuleIdentifierTest.java similarity index 95% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/ModuleIdentifierTest.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/ModuleIdentifierTest.java index 22d30c5a67..5db2262ebf 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/ModuleIdentifierTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/ModuleIdentifierTest.java @@ -1,11 +1,11 @@ /* - * 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.yang.parser.impl; +package org.opendaylight.yangtools.yang.stmt; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/MoreRevisionsTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/MoreRevisionsTest.java similarity index 99% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/MoreRevisionsTest.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/MoreRevisionsTest.java index 8b7a085246..4002451dfe 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/MoreRevisionsTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/MoreRevisionsTest.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.stmt.test; +package org.opendaylight.yangtools.yang.stmt; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/MustAndWhenStmtTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/MustAndWhenStmtTest.java similarity index 97% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/MustAndWhenStmtTest.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/MustAndWhenStmtTest.java index 1c0200f962..63d51c1afa 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/MustAndWhenStmtTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/MustAndWhenStmtTest.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.stmt.test; +package org.opendaylight.yangtools.yang.stmt; import static org.hamcrest.CoreMatchers.anyOf; import static org.hamcrest.CoreMatchers.is; diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/NotificationStmtTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/NotificationStmtTest.java similarity index 95% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/NotificationStmtTest.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/NotificationStmtTest.java index e5ae792a32..8918f44d62 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/NotificationStmtTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/NotificationStmtTest.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.stmt.test; +package org.opendaylight.yangtools.yang.stmt; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/OrderingTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/OrderingTest.java similarity index 98% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/OrderingTest.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/OrderingTest.java index 7fa2df4e0b..3c94b8ebdc 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/OrderingTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/OrderingTest.java @@ -1,11 +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.yang.stmt.retest; +package org.opendaylight.yangtools.yang.stmt; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/ParsingExtensionValueTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/ParsingExtensionValueTest.java similarity index 88% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/ParsingExtensionValueTest.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/ParsingExtensionValueTest.java index 01704fc2eb..10590da39e 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/ParsingExtensionValueTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/ParsingExtensionValueTest.java @@ -1,11 +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.yang.stmt.retest; +package org.opendaylight.yangtools.yang.stmt; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/RpcStmtTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/RpcStmtTest.java similarity index 95% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/RpcStmtTest.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/RpcStmtTest.java index 2fa97092af..47a4b8834b 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/RpcStmtTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/RpcStmtTest.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.stmt.test; +package org.opendaylight.yangtools.yang.stmt; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/SchemaContextTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/SchemaContextTest.java similarity index 95% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/SchemaContextTest.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/SchemaContextTest.java index d6677a9339..18ac884e4c 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/SchemaContextTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/SchemaContextTest.java @@ -1,11 +1,11 @@ /* - * 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.yang.stmt.retest; +package org.opendaylight.yangtools.yang.stmt; import static org.mockito.Mockito.doReturn; import java.net.URI; diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/SchemaContextUtilTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/SchemaContextUtilTest.java similarity index 99% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/SchemaContextUtilTest.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/SchemaContextUtilTest.java index bd614c1381..e0349c5901 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/SchemaContextUtilTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/SchemaContextUtilTest.java @@ -1,11 +1,11 @@ /* - * 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.yang.stmt.retest; +package org.opendaylight.yangtools.yang.stmt; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/StmtTestUtils.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/StmtTestUtils.java similarity index 97% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/StmtTestUtils.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/StmtTestUtils.java index e264b19208..6855026127 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/StmtTestUtils.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/StmtTestUtils.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.stmt.test; +package org.opendaylight.yangtools.yang.stmt; import java.io.FileFilter; diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/SubstatementValidatorTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/SubstatementValidatorTest.java similarity index 94% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/SubstatementValidatorTest.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/SubstatementValidatorTest.java index f4fe296a26..4bd9f8e8a8 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/SubstatementValidatorTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/SubstatementValidatorTest.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.stmt.test; +package org.opendaylight.yangtools.yang.stmt; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; @@ -24,7 +24,7 @@ import org.junit.rules.ExpectedException; import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.parser.spi.meta.MissingSubstatementException; import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; -import org.opendaylight.yangtools.yang.stmt.retest.TestUtils; +import org.opendaylight.yangtools.yang.stmt.TestUtils; public class SubstatementValidatorTest { diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/TestUtils.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/TestUtils.java similarity index 98% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/TestUtils.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/TestUtils.java index 50af9ba031..94d63ae004 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/TestUtils.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/TestUtils.java @@ -1,11 +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.yang.stmt.retest; +package org.opendaylight.yangtools.yang.stmt; import static org.junit.Assert.assertEquals; import java.io.File; @@ -42,7 +42,6 @@ import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceIm import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YinStatementSourceImpl; import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.EffectiveSchemaContext; import org.opendaylight.yangtools.yang.parser.util.NamedFileInputStream; -import org.opendaylight.yangtools.yang.stmt.test.StmtTestUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/TwoRevisionsTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/TwoRevisionsTest.java similarity index 86% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/TwoRevisionsTest.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/TwoRevisionsTest.java index 7e6c419926..edd46fe848 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/TwoRevisionsTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/TwoRevisionsTest.java @@ -1,11 +1,11 @@ /* - * 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.yang.stmt.retest; +package org.opendaylight.yangtools.yang.stmt; import static org.junit.Assert.assertEquals; diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/TypedefConstraintsTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/TypedefConstraintsTest.java similarity index 88% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/TypedefConstraintsTest.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/TypedefConstraintsTest.java index d8b6fc29b4..19017bf025 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/TypedefConstraintsTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/TypedefConstraintsTest.java @@ -1,4 +1,12 @@ -package org.opendaylight.yangtools.yang.stmt.test; +/* + * 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.stmt; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/TypedefSubStmtsTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/TypedefSubStmtsTest.java similarity index 94% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/TypedefSubStmtsTest.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/TypedefSubStmtsTest.java index 7effe22d39..075a3846cc 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/TypedefSubStmtsTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/TypedefSubStmtsTest.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.stmt.test; +package org.opendaylight.yangtools.yang.stmt; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/TypesResolutionTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/TypesResolutionTest.java similarity index 83% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/TypesResolutionTest.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/TypesResolutionTest.java index 94b4464139..01c44391d5 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/TypesResolutionTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/TypesResolutionTest.java @@ -1,11 +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.yang.stmt.retest; +package org.opendaylight.yangtools.yang.stmt; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -13,8 +13,6 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import java.io.File; -import java.math.BigInteger; import java.net.URI; import java.util.List; import java.util.Set; @@ -26,20 +24,18 @@ import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode; import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.Status; import org.opendaylight.yangtools.yang.model.api.TypeDefinition; +import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition; import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition.Bit; +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.api.type.IdentityrefTypeDefinition; +import org.opendaylight.yangtools.yang.model.api.type.InstanceIdentifierTypeDefinition; 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.StringTypeDefinition; -import org.opendaylight.yangtools.yang.model.parser.api.YangContextParser; -import org.opendaylight.yangtools.yang.model.util.BitsType; -import org.opendaylight.yangtools.yang.model.util.EnumerationType; -import org.opendaylight.yangtools.yang.model.util.ExtendedType; -import org.opendaylight.yangtools.yang.model.util.IdentityrefType; -import org.opendaylight.yangtools.yang.model.util.InstanceIdentifierType; -import org.opendaylight.yangtools.yang.model.util.UnionType; -import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl; +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.StatementStreamSource; 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; @@ -50,10 +46,17 @@ public class TypesResolutionTest { @Before public void init() throws Exception { - File yangFile = new File(getClass().getResource("/types/custom-types-test@2012-4-4.yang").toURI()); - File dependenciesDir = new File(getClass().getResource("/ietf").toURI()); - YangContextParser parser = new YangParserImpl(); - testedModules = parser.parseFile(yangFile, dependenciesDir).getModules(); + final StatementStreamSource yangFile = + new YangStatementSourceImpl("/types/custom-types-test@2012-4-4.yang", false); + final StatementStreamSource yangFileDependency1 = + new YangStatementSourceImpl ("/ietf/iana-timezones@2012-07-09.yang", false); + final StatementStreamSource yangFileDependency2 = + new YangStatementSourceImpl ("/ietf/ietf-inet-types@2010-09-24.yang", false); + final StatementStreamSource yangFileDependency3 = + new YangStatementSourceImpl ("/ietf/ietf-yang-types@2010-09-24.yang", false); + + testedModules = TestUtils.parseYangSources(yangFile, yangFileDependency1, yangFileDependency2, + yangFileDependency3).getModules(); assertEquals(4, testedModules.size()); } @@ -67,7 +70,7 @@ public class TypesResolutionTest { assertTrue(type.getDescription().contains("This value represents the version of the IP protocol.")); assertTrue(type.getReference().contains("RFC 2460: Internet Protocol, Version 6 (IPv6) Specification")); - EnumerationType enumType = (EnumerationType) type.getBaseType(); + EnumTypeDefinition enumType = (EnumTypeDefinition) type.getBaseType(); List values = enumType.getValues(); assertEquals(3, values.size()); @@ -93,7 +96,7 @@ public class TypesResolutionTest { Set> typedefs = tested.getTypeDefinitions(); TypeDefinition type = TestUtils.findTypedef(typedefs, "ip-version"); - EnumerationType enumType = (EnumerationType) type.getBaseType(); + EnumTypeDefinition enumType = (EnumTypeDefinition) type.getBaseType(); List values = enumType.getValues(); assertEquals(4, values.size()); @@ -123,16 +126,16 @@ public class TypesResolutionTest { Module tested = TestUtils.findModule(testedModules, "ietf-inet-types"); Set> typedefs = tested.getTypeDefinitions(); TypeDefinition type = TestUtils.findTypedef(typedefs, "ip-address"); - UnionType baseType = (UnionType) type.getBaseType(); + UnionTypeDefinition baseType = (UnionTypeDefinition) type.getBaseType(); List> unionTypes = baseType.getTypes(); - ExtendedType ipv4 = (ExtendedType) unionTypes.get(0); + StringTypeDefinition ipv4 = (StringTypeDefinition) unionTypes.get(0); assertTrue(ipv4.getBaseType() instanceof StringTypeDefinition); String expectedPattern = "^(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\.){3}" + "([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])" + "(%[\\p{N}\\p{L}]+)?$"; assertEquals(expectedPattern, ipv4.getPatternConstraints().get(0).getRegularExpression()); - ExtendedType ipv6 = (ExtendedType) unionTypes.get(1); + StringTypeDefinition ipv6 = (StringTypeDefinition) unionTypes.get(1); assertTrue(ipv6.getBaseType() instanceof StringTypeDefinition); List ipv6Patterns = ipv6.getPatternConstraints(); expectedPattern = "^((:|[0-9a-fA-F]{0,4}):)([0-9a-fA-F]{0,4}:){0,5}" @@ -149,7 +152,7 @@ public class TypesResolutionTest { public void testDomainName() { Module tested = TestUtils.findModule(testedModules, "ietf-inet-types"); Set> typedefs = tested.getTypeDefinitions(); - ExtendedType type = (ExtendedType) TestUtils.findTypedef(typedefs, "domain-name"); + StringTypeDefinition type = (StringTypeDefinition) TestUtils.findTypedef(typedefs, "domain-name"); assertTrue(type.getBaseType() instanceof StringTypeDefinition); List patterns = type.getPatternConstraints(); assertEquals(1, patterns.size()); @@ -160,15 +163,16 @@ public class TypesResolutionTest { List lengths = type.getLengthConstraints(); assertEquals(1, lengths.size()); LengthConstraint length = type.getLengthConstraints().get(0); - assertEquals(BigInteger.ONE, length.getMin()); - assertEquals(BigInteger.valueOf(253), length.getMax()); + assertEquals(Integer.valueOf(1), length.getMin()); + assertEquals(Integer.valueOf(253), length.getMax()); } @Test public void testInstanceIdentifier1() { Module tested = TestUtils.findModule(testedModules, "custom-types-test"); - LeafSchemaNode leaf = (LeafSchemaNode) tested.getDataChildByName("inst-id-leaf1"); - InstanceIdentifierType leafType = (InstanceIdentifierType) leaf.getType(); + LeafSchemaNode leaf = (LeafSchemaNode) tested.getDataChildByName( + QName.create(tested.getQNameModule(), "inst-id-leaf1")); + InstanceIdentifierTypeDefinition leafType = (InstanceIdentifierTypeDefinition) leaf.getType(); assertFalse(leafType.requireInstance()); assertEquals(1, leaf.getUnknownSchemaNodes().size()); } @@ -176,9 +180,10 @@ public class TypesResolutionTest { @Test public void testInstanceIdentifier2() { Module tested = TestUtils.findModule(testedModules, "custom-types-test"); - LeafSchemaNode leaf = (LeafSchemaNode) tested.getDataChildByName("inst-id-leaf2"); - InstanceIdentifierType leafType = (InstanceIdentifierType) leaf.getType(); - assertTrue(leafType.requireInstance()); + LeafSchemaNode leaf = (LeafSchemaNode) tested.getDataChildByName( + QName.create(tested.getQNameModule(), "inst-id-leaf2")); + InstanceIdentifierTypeDefinition leafType = (InstanceIdentifierTypeDefinition) leaf.getType(); + assertFalse(leafType.requireInstance()); } @Test @@ -215,8 +220,9 @@ public class TypesResolutionTest { @Test public void testBitsType1() { Module tested = TestUtils.findModule(testedModules, "custom-types-test"); - LeafSchemaNode leaf = (LeafSchemaNode) tested.getDataChildByName("mybits"); - BitsType leafType = (BitsType) leaf.getType(); + LeafSchemaNode leaf = (LeafSchemaNode) tested.getDataChildByName( + QName.create(tested.getQNameModule(), "mybits")); + BitsTypeDefinition leafType = (BitsTypeDefinition) leaf.getType(); List bits = leafType.getBits(); assertEquals(3, bits.size()); @@ -239,7 +245,7 @@ public class TypesResolutionTest { Set> typedefs = tested.getTypeDefinitions(); TypeDefinition testedType = TestUtils.findTypedef(typedefs, "access-operations-type"); - BitsType bitsType = (BitsType) testedType.getBaseType(); + BitsTypeDefinition bitsType = (BitsTypeDefinition) testedType.getBaseType(); List bits = bitsType.getBits(); assertEquals(5, bits.size()); @@ -253,10 +259,10 @@ public class TypesResolutionTest { assertEquals(501L, (long) bit2.getPosition()); Bit bit3 = bits.get(3); - assertEquals(365L, (long) bit3.getPosition()); + assertEquals(502L, (long) bit3.getPosition()); Bit bit4 = bits.get(4); - assertEquals(502L, (long) bit4.getPosition()); + assertEquals(365L, (long) bit4.getPosition()); } @Test @@ -267,7 +273,7 @@ public class TypesResolutionTest { String expectedDesc = "A timezone location as defined by the IANA timezone"; assertTrue(testedType.getDescription().contains(expectedDesc)); - assertTrue(testedType.getReference().isEmpty()); + assertNull(testedType.getReference()); assertEquals(Status.CURRENT, testedType.getStatus()); QName testedTypeQName = testedType.getQName(); @@ -275,7 +281,7 @@ public class TypesResolutionTest { assertEquals(TestUtils.createDate("2012-07-09"), testedTypeQName.getRevision()); assertEquals("iana-timezone", testedTypeQName.getLocalName()); - EnumerationType enumType = (EnumerationType) testedType.getBaseType(); + EnumTypeDefinition enumType = (EnumTypeDefinition) testedType.getBaseType(); List values = enumType.getValues(); assertEquals(415, values.size()); // 0-414 @@ -294,7 +300,8 @@ public class TypesResolutionTest { public void testObjectId128() { Module tested = TestUtils.findModule(testedModules, "ietf-yang-types"); Set> typedefs = tested.getTypeDefinitions(); - ExtendedType testedType = (ExtendedType) TestUtils.findTypedef(typedefs, "object-identifier-128"); + StringTypeDefinition testedType = (StringTypeDefinition) TestUtils.findTypedef(typedefs, + "object-identifier-128"); List patterns = testedType.getPatternConstraints(); assertEquals(1, patterns.size()); @@ -306,7 +313,7 @@ public class TypesResolutionTest { assertEquals(TestUtils.createDate("2010-09-24"), testedTypeQName.getRevision()); assertEquals("object-identifier-128", testedTypeQName.getLocalName()); - ExtendedType testedTypeBase = (ExtendedType) testedType.getBaseType(); + StringTypeDefinition testedTypeBase = testedType.getBaseType(); patterns = testedTypeBase.getPatternConstraints(); assertEquals(1, patterns.size()); @@ -325,13 +332,13 @@ public class TypesResolutionTest { Module tested = TestUtils.findModule(testedModules, "custom-types-test"); Set> typedefs = tested.getTypeDefinitions(); TypeDefinition testedType = TestUtils.findTypedef(typedefs, "service-type-ref"); - IdentityrefType baseType = (IdentityrefType) testedType.getBaseType(); + IdentityrefTypeDefinition baseType = (IdentityrefTypeDefinition) testedType.getBaseType(); QName identity = baseType.getIdentity().getQName(); assertEquals(URI.create("urn:custom.types.demo"), identity.getNamespace()); assertEquals(TestUtils.createDate("2012-04-16"), identity.getRevision()); assertEquals("service-type", identity.getLocalName()); - LeafSchemaNode type = (LeafSchemaNode) tested.getDataChildByName("type"); + LeafSchemaNode type = (LeafSchemaNode) tested.getDataChildByName(QName.create(tested.getQNameModule(), "type")); assertNotNull(type); } diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/UsesAugmentTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/UsesAugmentTest.java similarity index 99% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/UsesAugmentTest.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/UsesAugmentTest.java index 4adc20e38e..d88d36eade 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/UsesAugmentTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/UsesAugmentTest.java @@ -1,11 +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.yang.stmt.retest; +package org.opendaylight.yangtools.yang.stmt; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/YangFileStmtTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/YangFileStmtTest.java similarity index 97% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/YangFileStmtTest.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/YangFileStmtTest.java index c4481c38ca..9cf23810b5 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/YangFileStmtTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/YangFileStmtTest.java @@ -1,11 +1,11 @@ /* - * 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.stmt.test; +package org.opendaylight.yangtools.yang.stmt; import static org.junit.Assert.assertNotNull; diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/YangModelValidationListTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/YangModelValidationListTest.java similarity index 97% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/YangModelValidationListTest.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/YangModelValidationListTest.java index 70a9926836..8e6013bc46 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/YangModelValidationListTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/YangModelValidationListTest.java @@ -1,11 +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.yang.stmt.retest; +package org.opendaylight.yangtools.yang.stmt; import static org.hamcrest.CoreMatchers.containsString; import static org.junit.Assert.assertThat; diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/YangModelValidationModuleTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/YangModelValidationModuleTest.java similarity index 98% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/YangModelValidationModuleTest.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/YangModelValidationModuleTest.java index 6088ec569c..8818e15b97 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/YangModelValidationModuleTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/YangModelValidationModuleTest.java @@ -1,11 +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.yang.stmt.retest; +package org.opendaylight.yangtools.yang.stmt; import static org.hamcrest.CoreMatchers.containsString; import static org.junit.Assert.assertThat; diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/YangModelValidationSubModuleTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/YangModelValidationSubModuleTest.java similarity index 96% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/YangModelValidationSubModuleTest.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/YangModelValidationSubModuleTest.java index 98f819fc95..51e592a4ee 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/YangModelValidationSubModuleTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/YangModelValidationSubModuleTest.java @@ -1,11 +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.yang.stmt.retest; +package org.opendaylight.yangtools.yang.stmt; import static org.hamcrest.CoreMatchers.containsString; import static org.junit.Assert.assertThat; diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/YangModelValidationTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/YangModelValidationTest.java similarity index 98% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/YangModelValidationTest.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/YangModelValidationTest.java index 2cc4f15304..88be16d280 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/YangModelValidationTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/YangModelValidationTest.java @@ -1,11 +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.yang.stmt.retest; +package org.opendaylight.yangtools.yang.stmt; import static org.hamcrest.CoreMatchers.containsString; import static org.junit.Assert.assertThat; diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/YangParserIdentityTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/YangParserIdentityTest.java similarity index 93% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/YangParserIdentityTest.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/YangParserIdentityTest.java index 662022dbab..17899d1aa7 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/YangParserIdentityTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/YangParserIdentityTest.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.stmt.retest; +package org.opendaylight.yangtools.yang.stmt; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; @@ -21,7 +21,6 @@ import org.opendaylight.yangtools.yang.model.api.ModuleImport; import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException; import org.opendaylight.yangtools.yang.parser.util.NamedFileInputStream; -import org.opendaylight.yangtools.yang.stmt.test.StmtTestUtils; public class YangParserIdentityTest { diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/YangParserNegativeTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/YangParserNegativeTest.java similarity index 88% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/YangParserNegativeTest.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/YangParserNegativeTest.java index cd6e6f5ff5..29543ee044 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/YangParserNegativeTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/YangParserNegativeTest.java @@ -1,11 +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.yang.stmt.retest; +package org.opendaylight.yangtools.yang.stmt; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -22,13 +22,10 @@ import java.util.List; import org.junit.After; import org.junit.Before; import org.junit.Test; -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.InferenceException; import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException; import org.opendaylight.yangtools.yang.parser.spi.source.SourceException; import org.opendaylight.yangtools.yang.parser.util.NamedFileInputStream; -import org.opendaylight.yangtools.yang.parser.util.YangValidationException; public class YangParserNegativeTest { @@ -243,34 +240,6 @@ public class YangParserNegativeTest { } } - @Test - public void testWrongDependenciesDir() throws Exception { - try { - File yangFile = new File(getClass().getResource("/types/custom-types-test@2012-4-4.yang").toURI()); - File dependenciesDir = new File("/invalid"); - YangContextParser parser = new YangParserImpl(); - parser.parseFile(yangFile, dependenciesDir); - fail("Exception should be thrown"); - } catch (IllegalStateException e) { - String expected = File.separator + "invalid does not exists"; - assertEquals(expected, e.getMessage()); - } - } - - @Test - public void testWrongDependenciesDir2() throws Exception { - try { - File yangFile = new File(getClass().getResource("/types/custom-types-test@2012-4-4.yang").toURI()); - File dependenciesDir = new File(getClass().getResource("/model").toURI()); - YangContextParser parser = new YangParserImpl(); - parser.parseFile(yangFile, dependenciesDir); - fail("Exception should be thrown"); - } catch (YangValidationException e) { - String expected = "Not existing module imported"; - assertTrue(e.getMessage().contains(expected)); - } - } - @Test public void testInvalidListKeyDefinition() throws Exception { File yang1 = new File(getClass().getResource("/negative-scenario/invalid-list-key-def.yang").toURI()); diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/YangParserSimpleTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/YangParserSimpleTest.java similarity index 98% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/YangParserSimpleTest.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/YangParserSimpleTest.java index 5451ac7f12..d7799e7ff8 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/YangParserSimpleTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/YangParserSimpleTest.java @@ -1,11 +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.yang.stmt.retest; +package org.opendaylight.yangtools.yang.stmt; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/YangParserTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/YangParserTest.java similarity index 88% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/YangParserTest.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/YangParserTest.java index 72771f6c04..a541a29151 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/YangParserTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/YangParserTest.java @@ -1,11 +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.yang.stmt.retest; +package org.opendaylight.yangtools.yang.stmt; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -58,11 +58,9 @@ import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint; 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.parser.api.YangSyntaxErrorException; import org.opendaylight.yangtools.yang.model.util.type.BaseTypes; -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.StatementStreamSource; 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; @@ -757,91 +755,6 @@ public class YangParserTest { assertFalse(dec64PathIt.hasNext()); } - @Test - public void testParseMethod1() throws Exception { - File yangFile = new File(getClass().getResource("/parse-methods/m1.yang").toURI()); - File dependenciesDir = new File(getClass().getResource("/parse-methods").toURI()); - YangContextParser parser = new YangParserImpl(); - modules = parser.parseFile(yangFile, dependenciesDir).getModules(); - assertEquals(6, modules.size()); - } - - @Test - public void testParseMethod2() throws Exception { - File yangFile = new File(getClass().getResource("/parse-methods/m1.yang").toURI()); - File dependenciesDir = new File(getClass().getResource("/parse-methods/dependencies").toURI()); - YangContextParser parser = new YangParserImpl(); - modules = parser.parseFile(yangFile, dependenciesDir).getModules(); - assertEquals(6, modules.size()); - } - - // @Test - // public void testSorting() throws Exception { - // // Correct order: m2, m4, m6, m8, m7, m6, m3, m1 - // File yangFile = new File(getClass().getResource("/sorting-test/m1.yang").toURI()); - // File dependenciesDir = new File(getClass().getResource("/sorting-test").toURI()); - // YangContextParser parser = new YangParserImpl(); - // modules = parser.parseFile(yangFile, dependenciesDir).getModules(); - // SchemaContext ctx = new SchemaContextImpl(modules, Collections. emptyMap()); - // checkOrder(modules); - // assertSetEquals(modules, ctx.getModules()); - // - // // ########## - // parser = new YangParserImpl(); - // final File testDir = dependenciesDir; - // final String[] fileList = testDir.list(); - // final List testFiles = new ArrayList<>(); - // if (fileList == null) { - // throw new FileNotFoundException(dependenciesDir.getAbsolutePath()); - // } - // for (String fileName : fileList) { - // testFiles.add(new File(testDir, fileName)); - // } - // Set newModules = parser.parseFiles(testFiles).getModules(); - // assertSetEquals(newModules, modules); - // ctx = new SchemaContextImpl(newModules, Collections. emptyMap()); - // assertSetEquals(newModules, ctx.getModules()); - // // ########## - // newModules = parser.parseFiles(testFiles, null).getModules(); - // assertSetEquals(newModules, modules); - // ctx = new SchemaContextImpl(newModules, Collections. emptyMap()); - // assertSetEquals(newModules, ctx.getModules()); - // // ########## - // List streams = new ArrayList<>(); - // for (File f : testFiles) { - // streams.add(new FileInputStream(f)); - // } - // newModules = parser.parseSources(BuilderUtils.filesToByteSources(testFiles)).getModules(); - // assertSetEquals(newModules, modules); - // ctx = new SchemaContextImpl(newModules, Collections. emptyMap()); - // assertSetEquals(newModules, ctx.getModules()); - // // ########## - // streams.clear(); - // for (File f : testFiles) { - // streams.add(new FileInputStream(f)); - // } - // newModules = parser.parseSources(BuilderUtils.filesToByteSources(testFiles), null).getModules(); - // assertSetEquals(newModules, modules); - // ctx = new SchemaContextImpl(newModules, Collections. emptyMap()); - // assertSetEquals(newModules, ctx.getModules()); - // // ########## - // Map mapped = parser.parseYangModelsMapped(testFiles); - // newModules = new LinkedHashSet<>(mapped.values()); - // assertSetEquals(newModules, modules); - // ctx = new SchemaContextImpl(newModules, Collections. emptyMap()); - // assertSetEquals(newModules, ctx.getModules()); - // // ########## - // streams.clear(); - // for (File f : testFiles) { - // streams.add(new FileInputStream(f)); - // } - // Map mappedStreams = parser.parseYangModelsFromStreamsMapped(streams); - // newModules = new LinkedHashSet<>(mappedStreams.values()); - // assertSetEquals(newModules, modules); - // ctx = new SchemaContextImpl(newModules, Collections. emptyMap()); - // assertSetEquals(newModules, ctx.getModules()); - // } - private static void checkOrder(final Collection modules) { Iterator it = modules.iterator(); Module m = it.next(); @@ -886,15 +799,16 @@ public class YangParserTest { } @Test - public void unknownStatementInSubmoduleHeaderTest() throws IOException, URISyntaxException { - - File yang = new File(getClass().getResource("/yang-grammar-test/submodule-header-extension.yang").toURI()); + public void unknownStatementInSubmoduleHeaderTest() throws IOException, URISyntaxException, ReactorException { + StatementStreamSource yang1 = new YangStatementSourceImpl("/yang-grammar-test/revisions-extension.yang", false); + StatementStreamSource yang2 = new YangStatementSourceImpl("/yang-grammar-test/submodule-header-extension.yang", + false); try { - YangParserImpl.getInstance().parseFile(yang, yang.getParentFile()); - } catch (YangSyntaxErrorException | YangParseException e) { + TestUtils.parseYangSources(yang1, yang2); + } catch (YangParseException e) { e.printStackTrace(); - fail("YangSyntaxErrorException or YangParseException should not be thrown"); + fail("YangParseException should not be thrown"); } } diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/YangParserWithContextTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/YangParserWithContextTest.java similarity index 94% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/YangParserWithContextTest.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/YangParserWithContextTest.java index 8918a5adbb..c76545fd4e 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/YangParserWithContextTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/YangParserWithContextTest.java @@ -1,23 +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.yang.stmt.retest; +package org.opendaylight.yangtools.yang.stmt; 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.text.DateFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; import java.util.Date; import java.util.List; import java.util.Map; @@ -44,16 +41,14 @@ import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode; import org.opendaylight.yangtools.yang.model.api.UsesNode; import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint; import org.opendaylight.yangtools.yang.model.api.type.UnsignedIntegerTypeDefinition; -import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl; +import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource; 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; -import org.opendaylight.yangtools.yang.stmt.test.StmtTestUtils; public class YangParserWithContextTest { private final DateFormat simpleDateFormat = new SimpleDateFormat( "yyyy-MM-dd"); - private final YangParserImpl parser = new YangParserImpl(); private static final YangStatementSourceImpl BAR = new YangStatementSourceImpl( "/model/bar.yang", false); @@ -395,20 +390,13 @@ public class YangParserWithContextTest { @Test public void testAugment() throws Exception { - // load first module - String resource = "/context-augment-test/test4.yang"; - SchemaContext context = parser.parseFiles(Collections - .singleton(new File(getClass().getResource(resource).toURI()))); - - // load another modules and parse them against already existing context - File test1 = new File(getClass().getResource( - "/context-augment-test/test1.yang").toURI()); - File test2 = new File(getClass().getResource( - "/context-augment-test/test2.yang").toURI()); - File test3 = new File(getClass().getResource( - "/context-augment-test/test3.yang").toURI()); - Set modules = parser.parseFiles( - Arrays.asList(test1, test2, test3), context).getModules(); + StatementStreamSource resource = new YangStatementSourceImpl("/context-augment-test/test4.yang", false); + StatementStreamSource test1 = new YangStatementSourceImpl("/context-augment-test/test1.yang", false); + StatementStreamSource test2 = new YangStatementSourceImpl("/context-augment-test/test2.yang", false); + StatementStreamSource test3 = new YangStatementSourceImpl("/context-augment-test/test3.yang", false); + + SchemaContext context = TestUtils.parseYangSources(resource, test1, test2, test3); + Set modules = context.getModules(); assertNotNull(modules); Module t4 = TestUtils.findModule(modules, "test4"); diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/YangTypes2StmtTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/YangTypes2StmtTest.java similarity index 98% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/YangTypes2StmtTest.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/YangTypes2StmtTest.java index 1dcc82b131..8df1d65a3d 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/YangTypes2StmtTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/YangTypes2StmtTest.java @@ -1,11 +1,11 @@ /* - * 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.stmt.test; +package org.opendaylight.yangtools.yang.stmt; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/YangTypesStmtTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/YangTypesStmtTest.java similarity index 95% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/YangTypesStmtTest.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/YangTypesStmtTest.java index 83fe5b3ab9..81ed21fdba 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/YangTypesStmtTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/YangTypesStmtTest.java @@ -1,11 +1,11 @@ /* - * 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.stmt.test; +package org.opendaylight.yangtools.yang.stmt; import static org.junit.Assert.assertNotNull; import org.junit.Test; diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/AugmentationSchemaBuilderImplTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/AugmentationSchemaBuilderImplTest.java deleted file mode 100644 index c86351c81e..0000000000 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/AugmentationSchemaBuilderImplTest.java +++ /dev/null @@ -1,66 +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.yang.stmt.retest; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import com.google.common.base.Optional; -import com.google.common.collect.Iterables; -import org.junit.Before; -import org.junit.Test; -import org.opendaylight.yangtools.yang.model.api.AugmentationSchema; -import org.opendaylight.yangtools.yang.model.api.SchemaPath; -import org.opendaylight.yangtools.yang.parser.builder.impl.AugmentationSchemaBuilderImpl; - -/** - * @deprecated Pre-Beryllium implementation, scheduled for removal. - */ -@Deprecated -public class AugmentationSchemaBuilderImplTest { - - private AugmentationSchemaBuilderImpl augmentSchemaBuilderImpl; - private AugmentationSchemaBuilderImpl augmentSchemaBuilderImpl2; - private AugmentationSchemaBuilderImpl augmentSchemaBuilderImpl3; - private AugmentationSchemaBuilderImpl augmentSchemaBuilderImpl4; - private AugmentationSchema augmentSchema; - - @Before - public void init() { - augmentSchemaBuilderImpl = new AugmentationSchemaBuilderImpl("test-module", 10, "augment-test/rpc", SchemaPath.ROOT, 1); - augmentSchemaBuilderImpl2 = new AugmentationSchemaBuilderImpl("test-module", 10, "augment-test/rpc2", SchemaPath.ROOT, 1); - augmentSchemaBuilderImpl3 = augmentSchemaBuilderImpl; - augmentSchemaBuilderImpl4 = new AugmentationSchemaBuilderImpl("test-module", 10, null, SchemaPath.ROOT, 1); - augmentSchema = augmentSchemaBuilderImpl.build(); - } - - @Test - public void testgetPath() { - assertTrue(Iterables.isEmpty(augmentSchemaBuilderImpl.getPath().getPathFromRoot())); - } - - @Test - public void testEquals() { - assertFalse(augmentSchemaBuilderImpl.equals("test")); - assertFalse(augmentSchemaBuilderImpl.equals(null)); - assertTrue(augmentSchemaBuilderImpl.equals(augmentSchemaBuilderImpl3)); - assertFalse(augmentSchemaBuilderImpl4.equals(augmentSchemaBuilderImpl)); - assertFalse(augmentSchemaBuilderImpl.equals(augmentSchemaBuilderImpl2)); - } - - @Test - public void testGetOriginalDefinition() { - augmentSchema = augmentSchemaBuilderImpl.build(); - Optional origDefinition = augmentSchema.getOriginalDefinition(); - assertFalse(origDefinition.isPresent()); - } - - @Test - public void testGetUnknownSchemaNodes() { - assertTrue(Iterables.isEmpty(augmentSchema.getUnknownSchemaNodes())); - } -} diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/Bug2219Test.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/Bug2219Test.java deleted file mode 100644 index dc812cfa68..0000000000 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/Bug2219Test.java +++ /dev/null @@ -1,49 +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.yang.stmt.retest; - -import static org.junit.Assert.assertNotNull; - -import org.junit.Before; -import org.junit.Test; -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.model.api.SchemaPath; -import org.opendaylight.yangtools.yang.parser.builder.api.TypeDefinitionBuilder; -import org.opendaylight.yangtools.yang.parser.builder.impl.CopyUtils; -import org.opendaylight.yangtools.yang.parser.builder.impl.IdentityrefTypeBuilder; -import org.opendaylight.yangtools.yang.parser.builder.impl.ModuleBuilder; - -/** - * NPE is rised during use of CopyUtils.copy operation for IdentityrefTypeBuilder. - * NPE occours in private getData method in CopyUtils.java during QName.create. - * - * The reason for exception is the old.getQName returns null since IdentityrefTypeBuilder.getQName() - * by implementation returns always null. - * - */ -public class Bug2219Test { - - private ModuleBuilder moduleBuilder; - - @Before - public void init() { - moduleBuilder = new ModuleBuilder("test-module", "somePath"); - } - - @Test - public void testCopyIdentityrefTypeBuilder() { - final String typedefLocalName = "identity-ref-test-type"; - final QName typedefQname = QName.create(moduleBuilder.getNamespace(), moduleBuilder.getRevision(), typedefLocalName); - final SchemaPath typedefPath = SchemaPath.create(true, typedefQname); - final IdentityrefTypeBuilder typeBuilder = new IdentityrefTypeBuilder(moduleBuilder.getModuleName(), 12, - "base:parent-identity", typedefPath); - - final TypeDefinitionBuilder copy = CopyUtils.copy(typeBuilder, moduleBuilder, true); - assertNotNull(copy); - } -} diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/ModuleIdentifierTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/ModuleIdentifierTest.java deleted file mode 100644 index 36311dd9bb..0000000000 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/ModuleIdentifierTest.java +++ /dev/null @@ -1,82 +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.yang.stmt.retest; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import com.google.common.base.Optional; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.Date; -import org.junit.Before; -import org.junit.Test; -import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier; -import org.opendaylight.yangtools.yang.parser.builder.impl.ModuleIdentifierImpl; - -public class ModuleIdentifierTest { - - private ModuleIdentifier moduleIdentifier; - private ModuleIdentifier moduleIdentifier2; - private ModuleIdentifier moduleIdentifier3; - private ModuleIdentifier moduleIdentifier4; - private ModuleIdentifier moduleIdentifier5; - - @Before - public void init() throws URISyntaxException { - Optional uri = Optional.of(new URI("testURI")); - Optional uri2 = Optional.of(new URI("testURI2")); - Optional revision = Optional.absent(); - moduleIdentifier = new ModuleIdentifierImpl("test-modulue", uri, revision); - moduleIdentifier2 = new ModuleIdentifierImpl("test-modulue2", uri, revision); - moduleIdentifier3 = moduleIdentifier; - moduleIdentifier4 = new ModuleIdentifierImpl("test-modulue", uri2, revision); - moduleIdentifier5 = new ModuleIdentifierImpl("test-modulue", uri, revision); - } - - @Test - public void testGetQNameModule() { - assertEquals(null, moduleIdentifier.getQNameModule().getRevision()); - } - - @Test - public void testGetRevision() { - assertEquals(null, moduleIdentifier.getRevision()); - } - - @Test - public void testGetName() { - assertEquals("test-modulue", moduleIdentifier.getName()); - } - - @Test - public void getNamespace() throws URISyntaxException { - assertEquals(new URI("testURI"), moduleIdentifier.getNamespace()); - } - - @Test - public void toStringTest() { - assertTrue(moduleIdentifier.toString().contains("ModuleIdentifier")); - } - - @Test - public void testHashCode() { - assertFalse(moduleIdentifier.hashCode() == moduleIdentifier2.hashCode()); - } - - @Test - public void testEquals() { - assertTrue(moduleIdentifier.equals(moduleIdentifier3)); - assertFalse(moduleIdentifier.equals(null)); - assertFalse(moduleIdentifier.equals("test")); - assertFalse(moduleIdentifier.equals(moduleIdentifier2)); - assertFalse(moduleIdentifier.equals(moduleIdentifier4)); - assertTrue(moduleIdentifier.equals(moduleIdentifier5)); - } -} diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/SameQNamesInChoiceTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/SameQNamesInChoiceTest.java deleted file mode 100644 index 33e8dcb44e..0000000000 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/SameQNamesInChoiceTest.java +++ /dev/null @@ -1,58 +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.yang.stmt.retest; - -import static org.junit.Assert.assertNotNull; - -import java.io.File; -import java.net.URI; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -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.parser.impl.YangParserImpl; -import org.opendaylight.yangtools.yang.parser.util.YangParseException; - -public class SameQNamesInChoiceTest { - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - @Test - public void testSameQNameInChoice() throws Exception { - thrown.expect(YangParseException.class); - thrown.expectMessage("Choice has two nodes case with same qnames"); - - SchemaContext context; - File yangFile = new File(getClass().getResource("/bugs/qnameDuplicity/two-same-node-in-choice/two-same-nodes-in-choice-case.yang").toURI()); - File dependenciesDir = new File(getClass().getResource("/bugs/qnameDuplicity/two-same-node-in-choice").toURI()); - YangContextParser parser = new YangParserImpl(); - context = parser.parseFile(yangFile, dependenciesDir); - - Module testModule = context.findModuleByNamespace(URI.create("urn:test:two:same-nodes-in-choice-case")).iterator().next(); - assertNotNull(testModule); - } - - - @Test - public void testAugmentedNodeIntoChoiceCase() throws Exception { - thrown.expect(YangParseException.class); - thrown.expectMessage("Choice has two nodes case with same qnames"); - - SchemaContext context; - File yangFile = new File(getClass().getResource("/bugs/qnameDuplicity/augment/two-cases.yang").toURI()); - File dependenciesDir = new File(getClass().getResource("/bugs/qnameDuplicity/augment").toURI()); - YangContextParser parser = new YangParserImpl(); - context = parser.parseFile(yangFile, dependenciesDir); - - Module testModule = context.findModuleByNamespace(URI.create("urn:test:two:cases")).iterator().next(); - assertNotNull(testModule); - } -} diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/package-info.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/package-info.java deleted file mode 100644 index fc98bd3f31..0000000000 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/package-info.java +++ /dev/null @@ -1,13 +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 - */ - -/** - * This package consists of JUnit tests run against new statement parser - * in order to check and achieve desired functionality - */ -package org.opendaylight.yangtools.yang.stmt.retest; \ No newline at end of file diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/yin/YinFileAugmentStmtTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileAugmentStmtTest.java similarity index 92% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/yin/YinFileAugmentStmtTest.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileAugmentStmtTest.java index 8616e92331..3ca2597723 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/yin/YinFileAugmentStmtTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileAugmentStmtTest.java @@ -1,11 +1,11 @@ /* - * 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.stmt.test.yin; +package org.opendaylight.yangtools.yang.stmt.yin; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -20,7 +20,7 @@ import org.opendaylight.yangtools.yang.model.api.AugmentationSchema; import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode; import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; -import org.opendaylight.yangtools.yang.stmt.retest.TestUtils; +import org.opendaylight.yangtools.yang.stmt.TestUtils; public class YinFileAugmentStmtTest { diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/yin/YinFileChoiceStmtTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileChoiceStmtTest.java similarity index 94% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/yin/YinFileChoiceStmtTest.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileChoiceStmtTest.java index 7f16c66173..dc289de2f9 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/yin/YinFileChoiceStmtTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileChoiceStmtTest.java @@ -1,11 +1,11 @@ /* - * 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.stmt.test.yin; +package org.opendaylight.yangtools.yang.stmt.yin; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -24,7 +24,7 @@ import org.opendaylight.yangtools.yang.model.api.ListSchemaNode; import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath; import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; -import org.opendaylight.yangtools.yang.stmt.retest.TestUtils; +import org.opendaylight.yangtools.yang.stmt.TestUtils; public class YinFileChoiceStmtTest { diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/yin/YinFileExtensionStmtTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileExtensionStmtTest.java similarity index 96% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/yin/YinFileExtensionStmtTest.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileExtensionStmtTest.java index d6290fdae4..99d68e23e9 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/yin/YinFileExtensionStmtTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileExtensionStmtTest.java @@ -1,11 +1,11 @@ /* - * 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.stmt.test.yin; +package org.opendaylight.yangtools.yang.stmt.yin; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -20,7 +20,7 @@ import org.junit.Test; import org.opendaylight.yangtools.yang.model.api.ExtensionDefinition; import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; -import org.opendaylight.yangtools.yang.stmt.retest.TestUtils; +import org.opendaylight.yangtools.yang.stmt.TestUtils; public class YinFileExtensionStmtTest { diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/yin/YinFileFeatureStmtTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileFeatureStmtTest.java similarity index 90% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/yin/YinFileFeatureStmtTest.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileFeatureStmtTest.java index d4740031f8..d823693761 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/yin/YinFileFeatureStmtTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileFeatureStmtTest.java @@ -1,11 +1,11 @@ /* - * 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.stmt.test.yin; +package org.opendaylight.yangtools.yang.stmt.yin; import static org.hamcrest.CoreMatchers.anyOf; import static org.hamcrest.core.Is.is; @@ -21,7 +21,7 @@ import org.junit.Test; import org.opendaylight.yangtools.yang.model.api.FeatureDefinition; import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; -import org.opendaylight.yangtools.yang.stmt.retest.TestUtils; +import org.opendaylight.yangtools.yang.stmt.TestUtils; public class YinFileFeatureStmtTest { diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/yin/YinFileGroupingStmtTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileGroupingStmtTest.java similarity index 93% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/yin/YinFileGroupingStmtTest.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileGroupingStmtTest.java index 03d83e9172..a2514bbbca 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/yin/YinFileGroupingStmtTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileGroupingStmtTest.java @@ -1,11 +1,11 @@ /* - * 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.stmt.test.yin; +package org.opendaylight.yangtools.yang.stmt.yin; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -22,7 +22,7 @@ import org.opendaylight.yangtools.yang.model.api.GroupingDefinition; import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode; import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; -import org.opendaylight.yangtools.yang.stmt.retest.TestUtils; +import org.opendaylight.yangtools.yang.stmt.TestUtils; public class YinFileGroupingStmtTest { diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/yin/YinFileHeaderStmtsTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileHeaderStmtsTest.java similarity index 87% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/yin/YinFileHeaderStmtsTest.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileHeaderStmtsTest.java index 518673b048..487b0a724f 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/yin/YinFileHeaderStmtsTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileHeaderStmtsTest.java @@ -1,11 +1,11 @@ /* - * 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.stmt.test.yin; +package org.opendaylight.yangtools.yang.stmt.yin; import static org.junit.Assert.assertEquals; @@ -16,7 +16,7 @@ import org.junit.Before; import org.junit.Test; import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; -import org.opendaylight.yangtools.yang.stmt.retest.TestUtils; +import org.opendaylight.yangtools.yang.stmt.TestUtils; public class YinFileHeaderStmtsTest { diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/yin/YinFileIdentityStmtTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileIdentityStmtTest.java similarity index 91% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/yin/YinFileIdentityStmtTest.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileIdentityStmtTest.java index 162f09a8a8..4d956a5bdc 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/yin/YinFileIdentityStmtTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileIdentityStmtTest.java @@ -1,11 +1,11 @@ /* - * 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.stmt.test.yin; +package org.opendaylight.yangtools.yang.stmt.yin; import static org.hamcrest.CoreMatchers.anyOf; import static org.hamcrest.core.Is.is; @@ -22,7 +22,7 @@ import org.junit.Test; import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode; import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; -import org.opendaylight.yangtools.yang.stmt.retest.TestUtils; +import org.opendaylight.yangtools.yang.stmt.TestUtils; public class YinFileIdentityStmtTest { diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/yin/YinFileImportStmtTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileImportStmtTest.java similarity index 91% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/yin/YinFileImportStmtTest.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileImportStmtTest.java index a2e9dce99e..50eba7c013 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/yin/YinFileImportStmtTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileImportStmtTest.java @@ -1,11 +1,11 @@ /* - * 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.stmt.test.yin; +package org.opendaylight.yangtools.yang.stmt.yin; import static org.hamcrest.CoreMatchers.anyOf; import static org.hamcrest.core.Is.is; @@ -22,7 +22,7 @@ import org.junit.Test; import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.ModuleImport; import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; -import org.opendaylight.yangtools.yang.stmt.retest.TestUtils; +import org.opendaylight.yangtools.yang.stmt.TestUtils; public class YinFileImportStmtTest { diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/yin/YinFileIncludeStmtTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileIncludeStmtTest.java similarity index 89% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/yin/YinFileIncludeStmtTest.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileIncludeStmtTest.java index 248b695158..8e6624f8d3 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/yin/YinFileIncludeStmtTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileIncludeStmtTest.java @@ -1,11 +1,11 @@ /* - * 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.stmt.test.yin; +package org.opendaylight.yangtools.yang.stmt.yin; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -18,7 +18,7 @@ import org.junit.Before; import org.junit.Test; import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; -import org.opendaylight.yangtools.yang.stmt.retest.TestUtils; +import org.opendaylight.yangtools.yang.stmt.TestUtils; public class YinFileIncludeStmtTest { diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/yin/YinFileLeafListStmtTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileLeafListStmtTest.java similarity index 91% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/yin/YinFileLeafListStmtTest.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileLeafListStmtTest.java index 1d7cea04e3..83b573a54e 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/yin/YinFileLeafListStmtTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileLeafListStmtTest.java @@ -1,11 +1,11 @@ /* - * 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.stmt.test.yin; +package org.opendaylight.yangtools.yang.stmt.yin; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -19,7 +19,7 @@ import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode; import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode; import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; -import org.opendaylight.yangtools.yang.stmt.retest.TestUtils; +import org.opendaylight.yangtools.yang.stmt.TestUtils; public class YinFileLeafListStmtTest { diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/yin/YinFileListStmtTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileListStmtTest.java similarity index 94% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/yin/YinFileListStmtTest.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileListStmtTest.java index 27a27313c3..2f78914bc1 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/yin/YinFileListStmtTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileListStmtTest.java @@ -1,11 +1,11 @@ /* - * 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.stmt.test.yin; +package org.opendaylight.yangtools.yang.stmt.yin; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -27,7 +27,7 @@ import org.opendaylight.yangtools.yang.model.api.TypeDefinition; import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition; import org.opendaylight.yangtools.yang.model.util.type.BaseTypes; import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; -import org.opendaylight.yangtools.yang.stmt.retest.TestUtils; +import org.opendaylight.yangtools.yang.stmt.TestUtils; public class YinFileListStmtTest { diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/yin/YinFileMetaStmtsTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileMetaStmtsTest.java similarity index 93% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/yin/YinFileMetaStmtsTest.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileMetaStmtsTest.java index 5b80c6e16c..29244eff26 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/yin/YinFileMetaStmtsTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileMetaStmtsTest.java @@ -1,11 +1,11 @@ /* - * 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.stmt.test.yin; +package org.opendaylight.yangtools.yang.stmt.yin; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -16,7 +16,7 @@ import org.junit.Before; import org.junit.Test; import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; -import org.opendaylight.yangtools.yang.stmt.retest.TestUtils; +import org.opendaylight.yangtools.yang.stmt.TestUtils; public class YinFileMetaStmtsTest { diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/yin/YinFileRpcStmtTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileRpcStmtTest.java similarity index 92% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/yin/YinFileRpcStmtTest.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileRpcStmtTest.java index 3e2257f023..c00cb6a4c9 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/yin/YinFileRpcStmtTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileRpcStmtTest.java @@ -1,11 +1,11 @@ /* - * 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.stmt.test.yin; +package org.opendaylight.yangtools.yang.stmt.yin; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -18,7 +18,7 @@ import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode; import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.RpcDefinition; import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; -import org.opendaylight.yangtools.yang.stmt.retest.TestUtils; +import org.opendaylight.yangtools.yang.stmt.TestUtils; public class YinFileRpcStmtTest { diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/yin/YinFileStmtTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileStmtTest.java similarity index 95% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/yin/YinFileStmtTest.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileStmtTest.java index 7a794d324d..ed4d952184 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/yin/YinFileStmtTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileStmtTest.java @@ -1,11 +1,11 @@ /* - * 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.stmt.test.yin; +package org.opendaylight.yangtools.yang.stmt.yin; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -23,7 +23,7 @@ import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementR import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline; import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YinStatementSourceImpl; import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.EffectiveSchemaContext; -import org.opendaylight.yangtools.yang.stmt.retest.TestUtils; +import org.opendaylight.yangtools.yang.stmt.TestUtils; public class YinFileStmtTest { diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/yin/YinFileTypeDefStmtTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileTypeDefStmtTest.java similarity index 90% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/yin/YinFileTypeDefStmtTest.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileTypeDefStmtTest.java index 3c42f273fd..0b66a3d24d 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/yin/YinFileTypeDefStmtTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileTypeDefStmtTest.java @@ -1,11 +1,11 @@ /* - * 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.stmt.test.yin; +package org.opendaylight.yangtools.yang.stmt.yin; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -18,7 +18,7 @@ import org.junit.Test; import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.TypeDefinition; import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; -import org.opendaylight.yangtools.yang.stmt.retest.TestUtils; +import org.opendaylight.yangtools.yang.stmt.TestUtils; public class YinFileTypeDefStmtTest { diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/yin/YinFileUsesStmtTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileUsesStmtTest.java similarity index 92% rename from yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/yin/YinFileUsesStmtTest.java rename to yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileUsesStmtTest.java index 0932760014..52c0bb37d5 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/yin/YinFileUsesStmtTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileUsesStmtTest.java @@ -1,11 +1,11 @@ /* - * 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.stmt.test.yin; +package org.opendaylight.yangtools.yang.stmt.yin; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -22,7 +22,7 @@ import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode; import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.UsesNode; import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; -import org.opendaylight.yangtools.yang.stmt.retest.TestUtils; +import org.opendaylight.yangtools.yang.stmt.TestUtils; public class YinFileUsesStmtTest { -- 2.36.6