Moved parsing of unknown nodes from implementation to abstract classes.
[controller.git] / opendaylight / sal / yang-prototype / code-generator / yang-model-parser-impl / src / test / java / org / opendaylight / controller / yang / parser / impl / TypesResolutionTest.java
index 2c910ce3f69affe70d54adce8222a9f82ee4aeac..8f49fecc8e473f735a5d59d9b53db927493fa628 100644 (file)
@@ -39,8 +39,7 @@ public class TypesResolutionTest {
 
     @Before
     public void init() throws FileNotFoundException {
-        testedModules = TestUtils.loadModules(getClass().getResource
-                ("/types").getPath());
+        testedModules = TestUtils.loadModules(getClass().getResource("/types").getPath());
     }
 
     @Test
@@ -50,10 +49,8 @@ public class TypesResolutionTest {
         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"));
+        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<EnumPair> values = enumType.getValues();
@@ -62,27 +59,22 @@ public class TypesResolutionTest {
         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());
+        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());
+        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());
+        assertEquals("The IPv6 protocol as defined in RFC 2460.", value2.getDescription());
     }
 
     @Test
     public void testEnumeration() {
-        Module tested = TestUtils
-                .findModule(testedModules, "custom-types-test");
+        Module tested = TestUtils.findModule(testedModules, "custom-types-test");
         Set<TypeDefinition<?>> typedefs = tested.getTypeDefinitions();
 
         TypeDefinition<?> type = TestUtils.findTypedef(typedefs, "ip-version");
@@ -93,21 +85,17 @@ public class TypesResolutionTest {
         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());
+        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());
+        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());
+        assertEquals("The IPv6 protocol as defined in RFC 2460.", value2.getDescription());
 
         EnumPair value3 = values.get(3);
         assertEquals("default", value3.getName());
@@ -126,10 +114,8 @@ public class TypesResolutionTest {
         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.getPatterns().get(0)
-                .getRegularExpression());
+                + "([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.getPatterns().get(0).getRegularExpression());
 
         TypeDefinition<?> ipv4Address = TestUtils.findTypedef(typedefs, "ipv4-address");
         assertEquals(ipv4Address, ipv4);
@@ -138,33 +124,28 @@ public class TypesResolutionTest {
         assertTrue(ipv6.getBaseType() instanceof StringTypeDefinition);
         List<PatternConstraint> ipv6Patterns = ipv6.getPatterns();
         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());
+                + "((([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());
 
         TypeDefinition<?> ipv6Address = TestUtils.findTypedef(typedefs, "ipv6-address");
         assertEquals(ipv6Address, ipv6);
 
-        expectedPattern = "(([^:]+:){6}(([^:]+:[^:]+)|(.*\\..*)))|"
-                + "((([^:]+:)*[^:]+)?::(([^:]+:)*[^:]+)?)" + "(%.+)?";
-        assertEquals(expectedPattern, ipv6Patterns.get(1)
-                .getRegularExpression());
+        expectedPattern = "(([^:]+:){6}(([^:]+:[^:]+)|(.*\\..*)))|" + "((([^:]+:)*[^:]+)?::(([^:]+:)*[^:]+)?)"
+                + "(%.+)?";
+        assertEquals(expectedPattern, ipv6Patterns.get(1).getRegularExpression());
     }
 
     @Test
     public void testDomainName() {
         Module tested = TestUtils.findModule(testedModules, "ietf-inet-types");
         Set<TypeDefinition<?>> typedefs = tested.getTypeDefinitions();
-        ExtendedType type = (ExtendedType)TestUtils.findTypedef(typedefs, "domain-name");
+        ExtendedType type = (ExtendedType) TestUtils.findTypedef(typedefs, "domain-name");
         assertTrue(type.getBaseType() instanceof StringTypeDefinition);
         List<PatternConstraint> patterns = type.getPatterns();
         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]\\.?)"
-                + "|\\.";
+                + "([a-zA-Z0-9_]([a-zA-Z0-9\\-_]){0,61})?[a-zA-Z0-9]\\.?)" + "|\\.";
         assertEquals(expectedPattern, patterns.get(0).getRegularExpression());
 
         List<LengthConstraint> lengths = type.getLengths();
@@ -176,38 +157,30 @@ public class TypesResolutionTest {
 
     @Test
     public void testInstanceIdentifier1() {
-        Module tested = TestUtils
-                .findModule(testedModules, "custom-types-test");
-        LeafSchemaNode leaf = (LeafSchemaNode) tested
-                .getDataChildByName("inst-id-leaf1");
-        ExtendedType leafType = (ExtendedType) leaf.getType();
-        InstanceIdentifier leafTypeBase = (InstanceIdentifier) leafType
-                .getBaseType();
-        assertFalse(leafTypeBase.requireInstance());
+        Module tested = TestUtils.findModule(testedModules, "custom-types-test");
+        LeafSchemaNode leaf = (LeafSchemaNode) tested.getDataChildByName("inst-id-leaf1");
+        InstanceIdentifier leafType = (InstanceIdentifier) leaf.getType();
+        assertFalse(leafType.requireInstance());
     }
 
     @Test
     public void testInstanceIdentifier2() {
-        Module tested = TestUtils
-                .findModule(testedModules, "custom-types-test");
-        LeafSchemaNode leaf = (LeafSchemaNode) tested
-                .getDataChildByName("inst-id-leaf2");
+        Module tested = TestUtils.findModule(testedModules, "custom-types-test");
+        LeafSchemaNode leaf = (LeafSchemaNode) tested.getDataChildByName("inst-id-leaf2");
         InstanceIdentifier leafType = (InstanceIdentifier) leaf.getType();
         assertTrue(leafType.requireInstance());
     }
 
     @Test
     public void testIdentity() {
-        Module tested = TestUtils
-                .findModule(testedModules, "custom-types-test");
+        Module tested = TestUtils.findModule(testedModules, "custom-types-test");
         Set<IdentitySchemaNode> identities = tested.getIdentities();
         IdentitySchemaNode testedIdentity = null;
         for (IdentitySchemaNode id : identities) {
             if (id.getQName().getLocalName().equals("crypto-alg")) {
                 testedIdentity = id;
                 IdentitySchemaNode baseIdentity = id.getBaseIdentity();
-                assertEquals("crypto-base", baseIdentity.getQName()
-                        .getLocalName());
+                assertEquals("crypto-base", baseIdentity.getQName().getLocalName());
                 assertNull(baseIdentity.getBaseIdentity());
             }
         }
@@ -216,10 +189,8 @@ public class TypesResolutionTest {
 
     @Test
     public void testBitsType1() {
-        Module tested = TestUtils
-                .findModule(testedModules, "custom-types-test");
-        LeafSchemaNode leaf = (LeafSchemaNode) tested
-                .getDataChildByName("mybits");
+        Module tested = TestUtils.findModule(testedModules, "custom-types-test");
+        LeafSchemaNode leaf = (LeafSchemaNode) tested.getDataChildByName("mybits");
         BitsType leafType = (BitsType) leaf.getType();
         List<Bit> bits = leafType.getBits();
         assertEquals(3, bits.size());
@@ -239,11 +210,9 @@ public class TypesResolutionTest {
 
     @Test
     public void testBitsType2() {
-        Module tested = TestUtils
-                .findModule(testedModules, "custom-types-test");
+        Module tested = TestUtils.findModule(testedModules, "custom-types-test");
         Set<TypeDefinition<?>> typedefs = tested.getTypeDefinitions();
-        TypeDefinition<?> testedType = TestUtils.findTypedef(typedefs,
-                "access-operations-type");
+        TypeDefinition<?> testedType = TestUtils.findTypedef(typedefs, "access-operations-type");
 
         BitsType bitsType = (BitsType) testedType.getBaseType();
         List<Bit> bits = bitsType.getBits();
@@ -269,8 +238,7 @@ public class TypesResolutionTest {
     public void testIanaTimezones() {
         Module tested = TestUtils.findModule(testedModules, "iana-timezones");
         Set<TypeDefinition<?>> typedefs = tested.getTypeDefinitions();
-        TypeDefinition<?> testedType = TestUtils.findTypedef(typedefs,
-                "iana-timezone");
+        TypeDefinition<?> testedType = TestUtils.findTypedef(typedefs, "iana-timezone");
 
         String expectedDesc = "A timezone location as defined by the IANA timezone";
         assertTrue(testedType.getDescription().contains(expectedDesc));
@@ -278,10 +246,8 @@ public class TypesResolutionTest {
         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(URI.create("urn:ietf:params:xml:ns:yang:iana-timezones"), testedTypeQName.getNamespace());
+        assertEquals(TestUtils.createDate("2012-07-09"), testedTypeQName.getRevision());
         assertEquals("ianatz", testedTypeQName.getPrefix());
         assertEquals("iana-timezone", testedTypeQName.getLocalName());
 
@@ -292,22 +258,19 @@ public class TypesResolutionTest {
         EnumPair enum168 = values.get(168);
         assertEquals("America/Danmarkshavn", enum168.getName());
         assertEquals(168, (int) enum168.getValue());
-        assertEquals("east coast, north of Scoresbysund",
-                enum168.getDescription());
+        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());
+        assertEquals("Eastern Time - Indiana - Pulaski County", enum374.getDescription());
     }
 
     @Test
     public void testObjectId128() {
         Module tested = TestUtils.findModule(testedModules, "ietf-yang-types");
         Set<TypeDefinition<?>> typedefs = tested.getTypeDefinitions();
-        ExtendedType testedType = (ExtendedType) TestUtils.findTypedef(
-                typedefs, "object-identifier-128");
+        ExtendedType testedType = (ExtendedType) TestUtils.findTypedef(typedefs, "object-identifier-128");
 
         List<PatternConstraint> patterns = testedType.getPatterns();
         assertEquals(1, patterns.size());
@@ -315,10 +278,8 @@ public class TypesResolutionTest {
         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(URI.create("urn:ietf:params:xml:ns:yang:ietf-yang-types"), testedTypeQName.getNamespace());
+        assertEquals(TestUtils.createDate("2010-09-24"), testedTypeQName.getRevision());
         assertEquals("yang", testedTypeQName.getPrefix());
         assertEquals("object-identifier-128", testedTypeQName.getLocalName());
 
@@ -327,30 +288,24 @@ public class TypesResolutionTest {
         assertEquals(1, patterns.size());
 
         pattern = patterns.get(0);
-        assertEquals(
-                "(([0-1](\\.[1-3]?[0-9]))|(2\\.(0|([1-9]\\d*))))(\\.(0|([1-9]\\d*)))*",
+        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(URI.create("urn:ietf:params:xml:ns:yang:ietf-yang-types"), testedTypeBaseQName.getNamespace());
+        assertEquals(TestUtils.createDate("2010-09-24"), testedTypeBaseQName.getRevision());
         assertEquals("yang", testedTypeBaseQName.getPrefix());
         assertEquals("object-identifier", testedTypeBaseQName.getLocalName());
     }
 
     @Test
     public void testIdentityref() {
-        Module tested = TestUtils
-                .findModule(testedModules, "custom-types-test");
+        Module tested = TestUtils.findModule(testedModules, "custom-types-test");
         Set<TypeDefinition<?>> typedefs = tested.getTypeDefinitions();
-        TypeDefinition<?> testedType = TestUtils.findTypedef(typedefs,
-                "service-type-ref");
+        TypeDefinition<?> testedType = TestUtils.findTypedef(typedefs, "service-type-ref");
         IdentityrefType baseType = (IdentityrefType) testedType.getBaseType();
         QName identity = baseType.getIdentity();
-        assertEquals(URI.create("urn:simple.container.demo"),
-                identity.getNamespace());
+        assertEquals(URI.create("urn:simple.container.demo"), identity.getNamespace());
         assertEquals(TestUtils.createDate("2012-04-16"), identity.getRevision());
         assertEquals("iit", identity.getPrefix());
         assertEquals("service-type", identity.getLocalName());