*/
package org.opendaylight.yangtools.yang.parser.impl;
-import static org.junit.Assert.*;
-
-import java.io.FileNotFoundException;
+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.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.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;
private Set<Module> testedModules;
@Before
- public void init() throws FileNotFoundException {
- testedModules = TestUtils.loadModules(getClass().getResource("/types").getPath());
+ 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
List<LengthConstraint> lengths = type.getLengthConstraints();
assertEquals(1, lengths.size());
LengthConstraint length = type.getLengthConstraints().get(0);
- assertEquals(1L, length.getMin());
- assertEquals(253L, length.getMax());
+ assertEquals(BigInteger.ONE, length.getMin());
+ assertEquals(BigInteger.valueOf(253), length.getMax());
}
@Test
LeafSchemaNode leaf = (LeafSchemaNode) tested.getDataChildByName("inst-id-leaf1");
InstanceIdentifier leafType = (InstanceIdentifier) leaf.getType();
assertFalse(leafType.requireInstance());
+ assertEquals(1, leaf.getUnknownSchemaNodes().size());
}
@Test
public void testIdentity() {
Module tested = TestUtils.findModule(testedModules, "custom-types-test");
Set<IdentitySchemaNode> identities = tested.getIdentities();
- IdentitySchemaNode testedIdentity = null;
+ assertEquals(5, identities.size());
+ IdentitySchemaNode cryptoAlg = null;
+ IdentitySchemaNode cryptoBase = null;
+ IdentitySchemaNode cryptoId = null;
for (IdentitySchemaNode id : identities) {
if (id.getQName().getLocalName().equals("crypto-alg")) {
- testedIdentity = id;
- IdentitySchemaNode baseIdentity = id.getBaseIdentity();
- assertEquals("crypto-base", baseIdentity.getQName().getLocalName());
- assertNull(baseIdentity.getBaseIdentity());
+ cryptoAlg = id;
+ } else if ("crypto-base".equals(id.getQName().getLocalName())) {
+ cryptoBase = id;
+ } else if ("crypto-id".equals(id.getQName().getLocalName())) {
+ cryptoId = id;
}
}
- assertNotNull(testedIdentity);
+ 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
Set<TypeDefinition<?>> typedefs = tested.getTypeDefinitions();
TypeDefinition<?> testedType = TestUtils.findTypedef(typedefs, "service-type-ref");
IdentityrefType baseType = (IdentityrefType) testedType.getBaseType();
- QName identity = baseType.getIdentity();
+ QName identity = baseType.getIdentity().getQName();
assertEquals(URI.create("urn:custom.types.demo"), identity.getNamespace());
assertEquals(TestUtils.createDate("2012-04-16"), identity.getRevision());
assertEquals("iit", identity.getPrefix());
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));
+ }
+
}