*/
package org.opendaylight.yangtools.yang.parser.impl;
-import static org.junit.Assert.*;
+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.FileNotFoundException;
+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.YangModelParser;
+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 {
- File yangFile = new File(getClass().getResource("/types/custom-types-test@2012-4-4.yang").getPath());
- File dependenciesDir = new File(getClass().getResource("/ietf").getPath());
- YangModelParser parser = new YangParserImpl();
- testedModules = parser.parseYangModels(yangFile, dependenciesDir);
+ 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());
}
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
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);
assertNotNull(cryptoBase);
assertNull(cryptoBase.getBaseIdentity());
assertEquals(3, cryptoBase.getDerivedIdentities().size());
+
+ assertNotNull(cryptoId);
+ assertEquals(1, cryptoId.getUnknownSchemaNodes().size());
}
@Test
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));
+ }
+
}