import java.io.File;
import java.net.URISyntaxException;
-import java.util.Arrays;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
final File[] yangModels = params.getYangSourceDir().listFiles();
try {
- YangParserTestUtils.parseYangSources(Arrays.asList(yangModels));
+ YangParserTestUtils.parseYangFiles(yangModels);
} catch (Exception e) {
LOG.error("Yang files could not be parsed.", e);
}
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.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
private static SchemaContext schemaContext;
@BeforeClass
- public static void setup() throws IOException, URISyntaxException, ReactorException {
- schemaContext = YangParserTestUtils.parseYangSources("/complexjson/yang");
+ public static void setup() {
+ schemaContext = YangParserTestUtils.parseYangResourceDirectory("/complexjson/yang");
}
@Test
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.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
public class Bug4501Test {
private static SchemaContext schemaContext;
@BeforeClass
- public static void initialization() throws IOException, URISyntaxException, ReactorException {
- schemaContext = YangParserTestUtils.parseYangSources("/bug-4501/yang");
+ public static void initialization() {
+ schemaContext = YangParserTestUtils.parseYangResourceDirectory("/bug-4501/yang");
}
@Test
import com.google.common.base.Optional;
import com.google.gson.stream.JsonReader;
-import java.io.File;
import java.io.IOException;
import java.io.StringReader;
import java.net.URISyntaxException;
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.opendaylight.yangtools.yang.parser.spi.source.SourceException;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
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 = YangParserTestUtils.parseYangSources(sourceDir.listFiles());
+ public void newParserLeafRefTest() throws IOException, URISyntaxException {
+ SchemaContext context = YangParserTestUtils.parseYangResourceDirectory("/bug-4969/yang");
assertNotNull(context);
verifyNormalizedNodeResult(context);
}
@Test
- public void newParserLeafRefTest2() throws SourceException, ReactorException, URISyntaxException, IOException {
- File sourceDir = new File(Bug4969Test.class.getResource("/leafref/yang").toURI());
- SchemaContext context = YangParserTestUtils.parseYangSources(sourceDir.listFiles());
+ public void newParserLeafRefTest2() throws URISyntaxException, IOException {
+ SchemaContext context = YangParserTestUtils.parseYangResourceDirectory("/leafref/yang");
assertNotNull(context);
parseJsonToNormalizedNodes(context);
rootQName = QName.create(fooModuleQName, "root");
ipAddressQName = QName.create(fooModuleQName, "ip-address");
- schemaContext = YangParserTestUtils.parseYangSources(
- new File(Bug5446Test.class.getResource("/bug5446/yang/foo.yang").toURI()));
+ schemaContext = YangParserTestUtils.parseYangResources(Bug5446Test.class, "/bug5446/yang/foo.yang");
}
@Test
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.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
public class Bug6112Test {
private static SchemaContext schemaContext;
@BeforeClass
- public static void initialization() throws IOException, URISyntaxException, ReactorException {
- schemaContext = YangParserTestUtils.parseYangSources("/bug-6112/yang");
+ public static void initialization() {
+ schemaContext = YangParserTestUtils.parseYangResourceDirectory("/bug-6112/yang");
}
private static NormalizedNode<?, ?> readJson(final String jsonPath) throws IOException, URISyntaxException {
@Test
public void test() throws Exception {
- final SchemaContext schemaContext = YangParserTestUtils.parseYangSource("/bug7246/yang/rpc-test.yang");
+ final SchemaContext schemaContext = YangParserTestUtils.parseYangResource("/bug7246/yang/rpc-test.yang");
final JsonParser parser = new JsonParser();
final JsonElement expextedJson = parser
.parse(new FileReader(new File(getClass().getResource("/bug7246/json/expected-output.json").toURI())));
import static org.opendaylight.yangtools.yang.data.codec.gson.TestUtils.loadTextFile;
import com.google.gson.stream.JsonReader;
+import java.io.IOException;
import java.io.StringReader;
+import java.net.URISyntaxException;
import org.junit.Ignore;
import org.junit.Test;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
@Ignore("Instance-identifier codec has to be modified according to the RFC7951 to correctly parse this.")
@Test
- public void testRFC7951InstanceIdentifierPath() throws Exception {
- final SchemaContext schemaContext = YangParserTestUtils.parseYangSources("/bug8083/yang/");
+ public void testRFC7951InstanceIdentifierPath() throws IOException, URISyntaxException {
+ final SchemaContext schemaContext = YangParserTestUtils.parseYangResourceDirectory("/bug8083/yang/");
final String inputJson = loadTextFile("/bug8083/json/foo.json");
// deserialization
@Ignore("JSONEmptyCodec needs to be fixed first.")
@Test
- public void testInstanceIdentifierPathWithEmptyListKey() throws Exception {
- final SchemaContext schemaContext = YangParserTestUtils.parseYangSource("/bug8083/yang/baz.yang");
+ public void testInstanceIdentifierPathWithEmptyListKey() throws IOException, URISyntaxException {
+ final SchemaContext schemaContext = YangParserTestUtils.parseYangResource("/bug8083/yang/baz.yang");
final String inputJson = loadTextFile("/bug8083/json/baz.json");
// deserialization
}
@Test
- public void testInstanceIdentifierPathWithIdentityrefListKey() throws Exception {
- final SchemaContext schemaContext = YangParserTestUtils.parseYangSource("/bug8083/yang/zab.yang");
+ public void testInstanceIdentifierPathWithIdentityrefListKey() throws IOException, URISyntaxException {
+ final SchemaContext schemaContext = YangParserTestUtils.parseYangResource("/bug8083/yang/zab.yang");
final String inputJson = loadTextFile("/bug8083/json/zab.json");
// deserialization
}
@Test
- public void testInstanceIdentifierPathWithInstanceIdentifierListKey() throws Exception {
- final SchemaContext schemaContext = YangParserTestUtils.parseYangSource("/bug8083/yang/foobar.yang");
+ public void testInstanceIdentifierPathWithInstanceIdentifierListKey() throws IOException, URISyntaxException {
+ final SchemaContext schemaContext = YangParserTestUtils.parseYangResource("/bug8083/yang/foobar.yang");
final String inputJson = loadTextFile("/bug8083/json/foobar.json");
// deserialization
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;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
/**
private static SchemaContext schemaContext;
@BeforeClass
- public static void initialization() throws IOException, URISyntaxException, ReactorException {
- schemaContext = YangParserTestUtils.parseYangSources("/complexjson/yang");
+ public static void initialization() {
+ schemaContext = YangParserTestUtils.parseYangResourceDirectory("/complexjson/yang");
}
@Test
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;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
/**
private static SchemaContext schemaContext;
@BeforeClass
- public static void initialization() throws IOException, URISyntaxException, ReactorException {
- schemaContext = YangParserTestUtils.parseYangSources("/complexjson/yang");
+ public static void initialization() {
+ schemaContext = YangParserTestUtils.parseYangResourceDirectory("/complexjson/yang");
}
@Test
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.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private static String streamAsString;
@BeforeClass
- public static void initialization() throws IOException, URISyntaxException, ReactorException {
- schemaContext = YangParserTestUtils.parseYangSources("/complexjson/yang");
+ public static void initialization() throws IOException, URISyntaxException {
+ schemaContext = YangParserTestUtils.parseYangResourceDirectory("/complexjson/yang");
streamAsString = loadTextFile(new File(StreamToNormalizedNodeTest.class.getResource(
"/complexjson/complex-json.json").toURI()));
}
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
import org.xml.sax.SAXException;
private static ContainerNode data;
@BeforeClass
- public static void init() throws IOException, URISyntaxException, ReactorException, SAXException,
- XMLStreamException, ParserConfigurationException {
- schemaContext = YangParserTestUtils.parseYangSources("/yang-modeled-anyxml/yang");
+ public static void init() throws XMLStreamException, URISyntaxException, IOException, ParserConfigurationException,
+ SAXException {
+ schemaContext = YangParserTestUtils.parseYangResourceDirectory("/yang-modeled-anyxml/yang");
final Module bazModule = schemaContext.findModuleByName("baz", null);
final ContainerSchemaNode bazCont = (ContainerSchemaNode) bazModule.getDataChildByName(
QName.create(bazModule.getQNameModule(), "baz"));
public void setUp() throws Exception {
fooModuleQName = QNameModule.create(new URI("foo"), SimpleDateFormatUtil.getRevisionFormat().parse(
"2016-03-22"));
-
- schemaContext = YangParserTestUtils.parseYangSource("/bug5396/yang/foo.yang");
+ schemaContext = YangParserTestUtils.parseYangResource("/bug5396/yang/foo.yang");
}
@Test
rootQName = QName.create(fooModuleQName, "root");
ipAddressQName = QName.create(fooModuleQName, "ip-address");
- schemaContext = YangParserTestUtils.parseYangSource("/bug5446/yang/foo.yang");
+ schemaContext = YangParserTestUtils.parseYangResource("/bug5446/yang/foo.yang");
}
@Test
@Ignore("XMLEmptyCodec needs to be fixed first.")
@Test
public void testInstanceIdentifierPathWithEmptyListKey() throws Exception {
- final SchemaContext schemaContext = YangParserTestUtils.parseYangSource("/bug8083/yang/baz.yang");
+ final SchemaContext schemaContext = YangParserTestUtils.parseYangResource("/bug8083/yang/baz.yang");
final Module bazModule = schemaContext.getModules().iterator().next();
final ContainerSchemaNode topCont = (ContainerSchemaNode) bazModule.getDataChildByName(
QName.create(bazModule.getQNameModule(), "top-cont"));
@Test
public void testInstanceIdentifierPathWithIdentityrefListKey() throws Exception {
- final SchemaContext schemaContext = YangParserTestUtils.parseYangSource("/bug8083/yang/zab.yang");
+ final SchemaContext schemaContext = YangParserTestUtils.parseYangResource("/bug8083/yang/zab.yang");
final Module zabModule = schemaContext.getModules().iterator().next();
final ContainerSchemaNode topCont = (ContainerSchemaNode) zabModule.getDataChildByName(
QName.create(zabModule.getQNameModule(), "top-cont"));
@Test
public void testInstanceIdentifierPathWithInstanceIdentifierListKey() throws Exception {
- final SchemaContext schemaContext = YangParserTestUtils.parseYangSource("/bug8083/yang/foobar.yang");
+ final SchemaContext schemaContext = YangParserTestUtils.parseYangResource("/bug8083/yang/foobar.yang");
final Module foobarModule = schemaContext.getModules().iterator().next();
final ContainerSchemaNode topCont = (ContainerSchemaNode) foobarModule.getDataChildByName(
QName.create(foobarModule.getQNameModule(), "top-cont"));
@BeforeClass
public static void setup() throws Exception {
- schemaContext = YangParserTestUtils.parseYangSource("/bug8675/foo.yang");
+ schemaContext = YangParserTestUtils.parseYangResource("/bug8675/foo.yang");
fooModule = schemaContext.getModules().iterator().next();
}
@Test
public void testParsingAttributes() throws Exception {
- final SchemaContext schemaContext = YangParserTestUtils.parseYangSource("/bug8745/foo.yang");
+ final SchemaContext schemaContext = YangParserTestUtils.parseYangResource("/bug8745/foo.yang");
final QName contWithAttributes = QName.create("foo", "1970-01-01", "cont-with-attributes");
final ContainerSchemaNode contWithAttr = (ContainerSchemaNode) SchemaContextUtil.findDataSchemaNode(
schemaContext, SchemaPath.create(true, contWithAttributes));
@Test
public void test() throws Exception {
- final SchemaContext schemaContext = YangParserTestUtils.parseYangSources("/bug8803");
+ final SchemaContext schemaContext = YangParserTestUtils.parseYangResourceDirectory("/bug8803");
final SchemaPath topContPath = SchemaPath.create(true, QName.create("foo-ns", "1970-01-01", "top-cont"));
final SchemaNode dataSchemaNode = SchemaContextUtil.findDataSchemaNode(schemaContext, topContPath);
assertTrue(dataSchemaNode instanceof ContainerSchemaNode);
@Test
public void test() throws Exception {
- final SchemaContext schemaContext = YangParserTestUtils.parseYangSources("/dom-reader-test");
+ final SchemaContext schemaContext = YangParserTestUtils.parseYangResourceDirectory("/dom-reader-test");
final ContainerSchemaNode outerContainerSchema = (ContainerSchemaNode) SchemaContextUtil
.findNodeInSchemaContext(schemaContext, ImmutableList.of(QName.create("foo-ns", "1970-01-01",
"top-cont")));
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableSet;
-import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringWriter;
import java.net.URI;
-import java.net.URISyntaxException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Arrays;
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.parser.spi.meta.ReactorException;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
}
public NormalizedNodeXmlTranslationTest(final String yangPath, final String xmlPath,
- final ContainerNode expectedNode) throws ReactorException, FileNotFoundException, URISyntaxException {
- this.schema = YangParserTestUtils.parseYangSource(yangPath);
+ final ContainerNode expectedNode) {
+ this.schema = YangParserTestUtils.parseYangResource(yangPath);
this.xmlPath = xmlPath;
this.containerNode = (ContainerSchemaNode) getSchemaNode(schema, "test", "container");
this.expectedNode = expectedNode;
import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeWriter;
import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
}
@Test
- public void testNormalizedNodeToXmlSerialization() throws ReactorException, XMLStreamException, IOException,
- SAXException, URISyntaxException {
- final SchemaContext schemaContext = YangParserTestUtils.parseYangSource("/baz.yang");
+ public void testNormalizedNodeToXmlSerialization() throws XMLStreamException, IOException, SAXException {
+ final SchemaContext schemaContext = YangParserTestUtils.parseYangResource("/baz.yang");
final Document doc = loadDocument("/baz.xml");
@Test
public void testLenientParsing() throws Exception {
// unknown child nodes in the top-level-container node will be skipped when the strictParsing is set to false
- final SchemaContext schemaContext = YangParserTestUtils.parseYangSource(
+ final SchemaContext schemaContext = YangParserTestUtils.parseYangResource(
"/strict-parsing-mode-test/foo.yang");
final Module fooModule = schemaContext.getModules().iterator().next();
final ContainerSchemaNode topLevelContainer = (ContainerSchemaNode) fooModule.getDataChildByName(
public void testStrictParsing() throws Exception {
// should fail because strictParsing is switched on and the top-level-container node contains child nodes
// which are not defined in the provided YANG model
- final SchemaContext schemaContext = YangParserTestUtils.parseYangSource(
+ final SchemaContext schemaContext = YangParserTestUtils.parseYangResource(
"/strict-parsing-mode-test/foo.yang");
final Module fooModule = schemaContext.getModules().iterator().next();
final ContainerSchemaNode topLevelContainer = (ContainerSchemaNode) fooModule.getDataChildByName(
@BeforeClass
public static void initialize() throws URISyntaxException, FileNotFoundException, ReactorException {
- schemaContext = YangParserTestUtils.parseYangSource("/leafref-test.yang");
+ schemaContext = YangParserTestUtils.parseYangResource("/leafref-test.yang");
assertNotNull(schemaContext);
assertEquals(1, schemaContext.getModules().size());
leafRefModule = schemaContext.getModules().iterator().next();
mySecondKeyLeaf = QName.create(bazModule, "my-second-key-leaf");
myLeafInList3 = QName.create(bazModule, "my-leaf-in-list-3");
- schemaContext = YangParserTestUtils.parseYangSources("/");
+ schemaContext = YangParserTestUtils.parseYangResourceDirectory("/");
parentContainerSchema = (ContainerSchemaNode) SchemaContextUtil.findNodeInSchemaContext(schemaContext,
ImmutableList.of(parentContainer));
outerContainerSchema = (ContainerSchemaNode) SchemaContextUtil.findNodeInSchemaContext(schemaContext,
myLeaf2 = QName.create(fooModuleQName, "my-leaf-2");
myAnyXMLDataFoo = QName.create(fooModuleQName, "my-anyxml-data");
- schemaContext = YangParserTestUtils.parseYangSources("/anyxml-support/yang");
+ schemaContext = YangParserTestUtils.parseYangResourceDirectory("/anyxml-support/yang");
}
@Test
myContainer2QName = QName.create(bazModuleQName, "my-container-2");
myAnyXMLDataBaz = QName.create(bazModuleQName, "my-anyxml-data");
- schemaContext = YangParserTestUtils.parseYangSources("/anyxml-support/serialization");
+ schemaContext = YangParserTestUtils.parseYangResourceDirectory("/anyxml-support/serialization");
}
@Test
@Before
public void setUp() throws Exception {
final File leafRefTestYang = new File(getClass().getResource("/leafref-test.yang").toURI());
- schema = YangParserTestUtils.parseYangSources(leafRefTestYang);
+ schema = YangParserTestUtils.parseYangFiles(leafRefTestYang);
}
public static Document readXmlToDocument(final String xmlContent) throws SAXException, IOException {
@Before
public void setup() throws Exception {
final File rpcTestYang = new File(getClass().getResource("iid-test.yang").toURI());
- this.schemaContext = YangParserTestUtils.parseYangSources(rpcTestYang);
+ this.schemaContext = YangParserTestUtils.parseYangFiles(rpcTestYang);
final YangInstanceIdentifier.NodeIdentifier container = new YangInstanceIdentifier.NodeIdentifier(
QName.create(InstanceIdentifierForXmlCodecTest.NS, InstanceIdentifierForXmlCodecTest.REVISION, "cont"));
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 = YangParserTestUtils.parseYangSources(rpcTestYang1, rpcTestYang2);
+ this.schema = YangParserTestUtils.parseYangFiles(rpcTestYang1, rpcTestYang2);
}
public static Document readXmlToDocument(final String xmlContent) throws SAXException, IOException {
@BeforeClass
public static void initialize() throws URISyntaxException, FileNotFoundException, ReactorException {
final File file = new File(XmlStreamUtils.class.getResource("/leafref-test.yang").toURI());
- schemaContext = YangParserTestUtils.parseYangSources(file);
+ schemaContext = YangParserTestUtils.parseYangFiles(file);
assertNotNull(schemaContext);
assertEquals(1, schemaContext.getModules().size());
leafRefModule = schemaContext.getModules().iterator().next();
@Test
public void testStringPatternCheckingCodec() throws ReactorException, ParseException, URISyntaxException,
FileNotFoundException {
- final SchemaContext schemaContext = YangParserTestUtils.parseYangSource("/string-pattern-checking-codec-test.yang");
+ final SchemaContext schemaContext = YangParserTestUtils.parseYangResource("/string-pattern-checking-codec-test.yang");
assertNotNull(schemaContext);
final QNameModule testModuleQName = QNameModule.create(new URI("string-pattern-checking-codec-test"),
@Test
public void test() throws Exception {
- final SchemaContext context = YangParserTestUtils.parseYangSources("/bug7844");
+ final SchemaContext context = YangParserTestUtils.parseYangResourceDirectory("/bug7844");
assertNotNull(context);
final LeafRefContext leafRefContext = LeafRefContext.create(context);
@Test
public void dataTreeCanditateValidationTest() throws Exception {
- final SchemaContext context = YangParserTestUtils.parseYangSources("/bug8713/");
+ final SchemaContext context = YangParserTestUtils.parseYangResourceDirectory("/bug8713/");
final LeafRefContext rootLeafRefContext = LeafRefContext.create(context);
final TipProducingDataTree inMemoryDataTree = InMemoryDataTreeFactory.getInstance()
.create(DataTreeConfiguration.DEFAULT_OPERATIONAL);
inMemoryDataTree.commit(writeContributorsCandidate);
}
- private ContainerNode createRootContainer() {
+ private static ContainerNode createRootContainer() {
return Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(foo("root")))
.withChild(ImmutableNodes.leafNode(bar("target"), "target value"))
.withChild(ImmutableNodes.leafNode(bar("ref"), "target value")).build();
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
-import java.io.File;
+
import java.io.FileNotFoundException;
import java.net.URISyntaxException;
-import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
}
- private static void initSchemaContext() throws URISyntaxException,
- FileNotFoundException, ReactorException {
- final File resourceFile = new File(DataTreeCandidateValidatorTest.class
- .getResource("/leafref-validation/leafref-validation.yang")
- .toURI());
- final File resourceDir = resourceFile.getParentFile();
-
- context = YangParserTestUtils.parseYangSources(Arrays.asList(resourceDir
- .listFiles()));
+ private static void initSchemaContext() {
+ context = YangParserTestUtils.parseYangResourceDirectory("/leafref-validation");
final Set<Module> modules = context.getModules();
for (final Module module : modules) {
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
-import java.io.File;
+
import java.io.FileNotFoundException;
import java.net.URISyntaxException;
-import java.util.Arrays;
import java.util.Set;
import org.apache.log4j.BasicConfigurator;
import org.junit.BeforeClass;
desc = QName.create(rootModuleQname, "desc");
}
- private static void initSchemaContext() throws URISyntaxException, FileNotFoundException, ReactorException {
-
- final File resourceFile = new File(DataTreeCandidateValidatorTest.class.getResource(
- "/leafref-validation/leafref-validation2.yang").toURI());
- final File resourceDir = resourceFile.getParentFile();
-
- context = YangParserTestUtils.parseYangSources(Arrays.asList(resourceDir.listFiles()));
+ private static void initSchemaContext() {
+ context = YangParserTestUtils.parseYangResourceDirectory("/leafref-validation");
final Set<Module> modules = context.getModules();
for (final Module module : modules) {
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.net.URISyntaxException;
-import java.util.Arrays;
+
import java.util.Set;
import org.apache.log4j.BasicConfigurator;
import org.junit.BeforeClass;
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;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
}
@BeforeClass
- public static void init() throws FileNotFoundException, ReactorException, URISyntaxException {
-
+ public static void init() {
initSchemaContext();
initLeafRefContext();
initQnames();
desc = QName.create(rootModuleQname, "desc");
}
- private static void initSchemaContext() throws URISyntaxException, FileNotFoundException, ReactorException {
-
- final File resourceFile = new File(DataTreeCandidateValidatorTest.class.getResource(
- "/leafref-validation/leafref-validation3.yang").toURI());
- final File resourceDir = resourceFile.getParentFile();
-
- context = YangParserTestUtils.parseYangSources(Arrays.asList(resourceDir.listFiles()));
+ private static void initSchemaContext() {
+ context = YangParserTestUtils.parseYangResourceDirectory("/leafref-validation");
final Set<Module> modules = context.getModules();
for (final Module module : modules) {
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.FileNotFoundException;
-import java.net.URISyntaxException;
-import java.util.Arrays;
+
import java.util.Map;
import java.util.Set;
import org.junit.BeforeClass;
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.parser.spi.meta.ReactorException;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
public class LeafRefContextTest {
private static LeafRefContext rootLeafRefContext;
@BeforeClass
- public static void init() throws URISyntaxException, FileNotFoundException, ReactorException {
-
- final File resourceFile = new File(LeafRefContextTreeBuilderTest.class.getResource(
- "/leafref-context-test/correct-modules/leafref-test2.yang").toURI());
-
- final File resourceDir = resourceFile.getParentFile();
-
- context = YangParserTestUtils.parseYangSources(Arrays.asList(resourceDir.listFiles()));
+ public static void init() {
+ context = YangParserTestUtils.parseYangResourceDirectory("/leafref-context-test/correct-modules");
final Set<Module> modules = context.getModules();
for (final Module module : modules) {
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.net.URISyntaxException;
-import java.util.Arrays;
+
import java.util.List;
import java.util.Set;
import org.junit.BeforeClass;
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.parser.spi.meta.ReactorException;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
public class LeafRefContextTreeBuilderTest {
private static LeafRefContext rootLeafRefContext;
@BeforeClass
- public static void init() throws URISyntaxException, FileNotFoundException, ReactorException {
- final File resourceFile = new File(LeafRefContextTreeBuilderTest.class.getResource(
- "/leafref-context-test/correct-modules/leafref-test.yang").toURI());
- final File resourceDir = resourceFile.getParentFile();
-
- context = YangParserTestUtils.parseYangSources(Arrays.asList(resourceDir.listFiles()));
+ public static void init() {
+ context = YangParserTestUtils.parseYangResourceDirectory("/leafref-context-test/correct-modules");
final Set<Module> modules = context.getModules();
for (final Module module : modules) {
@Test(expected = IllegalArgumentException.class)
@Ignore
- public void incorrectLeafRefPathTest() throws URISyntaxException, FileNotFoundException, ReactorException {
- final File resourceFile = new File(getClass().getResource(
- "/leafref-context-test/incorrect-modules/leafref-test.yang").toURI());
- final File resourceDir = resourceFile.getParentFile();
-
- final SchemaContext context = YangParserTestUtils.parseYangSources(Arrays.asList(resourceDir.listFiles()));
-
+ public void incorrectLeafRefPathTest() {
+ final SchemaContext context = YangParserTestUtils.parseYangResourceDirectory(
+ "/leafref-context-test/incorrect-modules");
LeafRefContext.create(context);
-
}
}
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 = YangParserTestUtils.parseYangSources(leafRefTestYang);
+ final SchemaContext schema = YangParserTestUtils.parseYangFiles(leafRefTestYang);
final Module module = schema.getModules().iterator().next();
final DataSchemaNode root = module.getDataChildByName(ROOT_CONTAINER);
list = (ListSchemaNode)((ContainerEffectiveStatementImpl) root).getDataChildByName(LIST_MAIN);
package org.opendaylight.yangtools.yang.data.impl.schema;
import static org.junit.Assert.assertEquals;
-import java.io.File;
-import java.io.FileNotFoundException;
+
+import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Collections;
import org.junit.BeforeClass;
import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
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 YangParserTestUtils.parseYangSources(resourceFile);
+ static SchemaContext createTestContext() throws URISyntaxException, ReactorException, IOException,
+ YangSyntaxErrorException {
+ return YangParserTestUtils.parseYangResources(InstanceIdToNodesTest.class, "/filter-test.yang");
}
@BeforeClass
public void setUp() throws URISyntaxException, FileNotFoundException, ReactorException {
final File resourceFile = new File(getClass().getResource(
"test.yang").toURI());
- schema = YangParserTestUtils.parseYangSources(resourceFile);
+ schema = YangParserTestUtils.parseYangFiles(resourceFile);
containerNode = (ContainerSchemaNode) getSchemaNode(schema, "test", "container");
}
private static SchemaContext getSchemaContext(final String filePath) throws URISyntaxException,
ReactorException, FileNotFoundException {
- return YangParserTestUtils.parseYangSource(filePath);
+ return YangParserTestUtils.parseYangResource(filePath);
}
private static YangInstanceIdentifier.NodeIdentifier getNodeIdentifier(final String ns, final String name) {
@Test
public void test() throws Exception {
- final SchemaContext schemaContext = YangParserTestUtils.parseYangSource("/schema-utils-test/foo.yang");
+ final SchemaContext schemaContext = YangParserTestUtils.parseYangResource("/schema-utils-test/foo.yang");
assertTrue(SchemaUtils.findDataParentSchemaOnPath(schemaContext,
SchemaPath.create(true, qN("my-name"), qN("my-name"))) instanceof ContainerSchemaNode);
assertTrue(SchemaUtils.findDataParentSchemaOnPath(schemaContext,
@Test
public void testNameConflicts() throws Exception {
final SchemaContext schemaContext = YangParserTestUtils
- .parseYangSource("/schema-utils-test/name-conflicts.yang");
+ .parseYangResource("/schema-utils-test/name-conflicts.yang");
// test my-name conflicts
assertEquals(8, SchemaUtils.findParentSchemaNodesOnPath(schemaContext,
SchemaPath.create(true, qN("my-name"), qN("my-name"), qN("my-name"))).size());
@Test
public void testFactoryInstantiation() throws ReactorException, FileNotFoundException, URISyntaxException {
- SchemaContext schemaContext = YangParserTestUtils.parseYangSource("/foo.yang");
+ SchemaContext schemaContext = YangParserTestUtils.parseYangResource("/foo.yang");
DomToNormalizedNodeParserFactory factory = DomToNormalizedNodeParserFactory.getInstance(
DomUtils.defaultValueCodecProvider(), schemaContext,
.parse("2016-03-22"));
root = QName.create(fooModuleQName, "root");
schemaContext = YangParserTestUtils
- .parseYangSources(new File(getClass().getResource("/bug5396/yang/foo.yang").toURI()));
+ .parseYangFiles(new File(getClass().getResource("/bug5396/yang/foo.yang").toURI()));
}
@Test
rootQName = QName.create(fooModuleQName, "root");
ipAddressQName = QName.create(fooModuleQName, "ip-address");
- schemaContext = YangParserTestUtils.parseYangSources(new File(getClass().getResource("/bug5446/yang/foo.yang").toURI()));
+ schemaContext = YangParserTestUtils.parseYangFiles(new File(getClass().getResource("/bug5446/yang/foo.yang").toURI()));
}
@Test
@Test
public void testLenientParsingOfUnkeyedListEntries() throws Exception {
- final SchemaContext schemaContext = YangParserTestUtils.parseYangSource("/bug6392/foo.yang");
+ final SchemaContext schemaContext = YangParserTestUtils.parseYangResource("/bug6392/foo.yang");
assertNotNull(schemaContext);
final Date revision = SimpleDateFormatUtil.getRevisionFormat().parse("2017-03-10");
public static SchemaContext getSchemaContext() throws ReactorException, IOException, YangSyntaxErrorException,
URISyntaxException {
- final SchemaContext schemaContext = YangParserTestUtils.parseYangSource("/dom-serializer-test/serializer-test.yang");
+ final SchemaContext schemaContext = YangParserTestUtils.parseYangResource("/dom-serializer-test/serializer-test.yang");
assertNotNull("Schema context must not be null.", schemaContext);
return schemaContext;
import static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.leafNode;
import com.google.common.base.Preconditions;
-import com.google.common.collect.Collections2;
-import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import java.io.IOException;
import java.io.InputStream;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
-import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.xml.stream.XMLOutputFactory;
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.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
}
public NormalizedNodeXmlTranslationTest(final String yangPath, final String xmlPath,
- final ContainerNode expectedNode) throws ReactorException {
- schema = parseTestSchema(yangPath);
+ final ContainerNode expectedNode) {
+ schema = YangParserTestUtils.parseYangResources(NormalizedDataBuilderTest.class, yangPath);
this.xmlPath = xmlPath;
this.containerNode = (ContainerSchemaNode) NormalizedDataBuilderTest.getSchemaNode(schema, "test", "container");
this.expectedNode = expectedNode;
private final ContainerSchemaNode containerNode;
private final String xmlPath;
- SchemaContext parseTestSchema(final String... yangPath) throws ReactorException {
- return YangParserTestUtils.parseYangStreams(getTestYangs(yangPath));
- }
-
- List<InputStream> getTestYangs(final String... yangPaths) {
- return ImmutableList.copyOf(Collections2.transform(Arrays.asList(yangPaths),
- 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);
myLeaf3 = QName.create(fooModuleQName, "my-leaf-3");
myLeaf2 = QName.create(fooModuleQName, "my-leaf-2");
myAnyXMLDataFoo = QName.create(fooModuleQName, "my-anyxml-data");
- schemaContext = YangParserTestUtils.parseYangSources("/anyxml-support/yang");
+ schemaContext = YangParserTestUtils.parseYangResourceDirectory("/anyxml-support/yang");
}
@Test
myContainer2QName = QName.create(bazModuleQName, "my-container-2");
myAnyXMLDataBaz = QName.create(bazModuleQName, "my-anyxml-data");
- schemaContext = YangParserTestUtils.parseYangSources("/anyxml-support/serialization");
+ schemaContext = YangParserTestUtils.parseYangResourceDirectory("/anyxml-support/serialization");
}
@Test
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 java.io.InputStream;
-import java.util.Collections;
import org.junit.Before;
import org.junit.Test;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
inMemoryDataTree.setSchemaContext(schemaContext);
}
- public static InputStream getDatastoreTestInputStream() {
- return getInputStream(ODL_DATASTORE_TEST_YANG);
- }
-
- private static InputStream getInputStream(final String resourceName) {
- return TestModel.class.getResourceAsStream(ODL_DATASTORE_TEST_YANG);
- }
-
public static SchemaContext createTestContext() throws ReactorException {
- return YangParserTestUtils.parseYangStreams(Collections.singletonList(getDatastoreTestInputStream()));
+ return YangParserTestUtils.parseYangResource(ODL_DATASTORE_TEST_YANG);
}
@Test
final Optional<NormalizedNode<?, ?>> readNode = modificationAfterTx.readNode(TestModel.OUTER_LIST_PATH);
assertTrue(readNode.isPresent());
assertEquals(2, ((NormalizedNodeContainer<?,?,?>)readNode.get()).getValue().size());
-
}
-
}
package org.opendaylight.yangtools.yang.data.impl.schema.tree;
import static org.junit.Assert.assertEquals;
+
+import java.io.IOException;
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.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.model.parser.api.YangSyntaxErrorException;
import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
/**
private DataTree tree;
@Before
- public void setUp() throws ReactorException {
+ public void setUp() throws ReactorException, IOException, YangSyntaxErrorException {
tree = InMemoryDataTreeFactory.getInstance().create(TreeType.OPERATIONAL);
tree.setSchemaContext(TestModel.createTestContext());
public void init() throws Exception {
final File resourceFile = new File(Bug4295Test.class.getResource("/bug-4295/foo.yang")
.toURI());
- context = YangParserTestUtils.parseYangSources(resourceFile);
+ context = YangParserTestUtils.parseYangFiles(resourceFile);
foo = QNameModule.create(new URI("foo"), SimpleDateFormatUtil.getRevisionFormat().parse("1970-01-01"));
root = QName.create(foo, "root");
subRoot = QName.create(foo, "sub-root");
public static SchemaContext createTestContext() throws IOException, YangSyntaxErrorException, ReactorException,
URISyntaxException {
- return YangParserTestUtils.parseYangSource("/bug-4454-test.yang");
+ return YangParserTestUtils.parseYangResource("/bug-4454-test.yang");
}
@Test
inMemoryDataTree.commit(prepare);
}
- private static void testMandatoryLeaf2IsPresent(final SchemaContext schemaContext, boolean withPresenceContianer)
+ private static void testMandatoryLeaf2IsPresent(final SchemaContext schemaContext, final boolean withPresenceContianer)
throws DataValidationFailedException {
final InMemoryDataTree inMemoryDataTree = initDataTree(schemaContext);
inMemoryDataTree.commit(prepare);
}
- private static DataContainerChild<?, ?> createTaskDataContainer(boolean withMandatoryNode) {
+ private static DataContainerChild<?, ?> createTaskDataContainer(final boolean withMandatoryNode) {
DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> taskDataBuilder = Builders.containerBuilder()
.withNodeIdentifier(new NodeIdentifier(TASK_DATA))
.withChild(ImmutableNodes.leafNode(OTHER_DATA, "foo"));
return taskDataBuilder.build();
}
- private static DataContainerChild<?, ?> createTaskDataMultipleContainer(boolean withPresenceContianer) {
+ private static DataContainerChild<?, ?> createTaskDataMultipleContainer(final boolean withPresenceContianer) {
DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> nonPresenceContainerBuilder = Builders
.containerBuilder()
.withNodeIdentifier(new NodeIdentifier(NON_PRESENCE_CONTAINER))
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafNodeBuilder;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private static final Logger LOG = LoggerFactory.getLogger(DataTreeCandidates.class);
- private static final SchemaContext SCHEMA_CONTEXT;
-
- static {
- try {
- SCHEMA_CONTEXT = TestModel.createTestContext();
- } catch (ReactorException e) {
- throw new ExceptionInInitializerError(e);
- }
- }
+ private static final SchemaContext SCHEMA_CONTEXT = TestModel.createTestContext();
private DataTree dataTree;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
+
import com.google.common.base.Optional;
-import java.io.InputStream;
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.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.parser.spi.meta.ReactorException;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
.builder(MASTER_CONTAINER_PATH).node(UNKEYED_LIST_QNAME).build();
@Before
- public void prepare() throws ReactorException {
+ public void prepare() {
schemaContext = createTestContext();
assertNotNull("Schema context must not be null.", schemaContext);
inMemoryDataTree = (InMemoryDataTree) InMemoryDataTreeFactory.getInstance().create(TreeType.OPERATIONAL);
inMemoryDataTree.commit(inMemoryDataTree.prepare(modificationTree));
}
- public static InputStream getDatastoreTestInputStream() {
- return getInputStream(CONSTRAINTS_VALIDATION_TEST_YANG);
- }
-
- private static InputStream getInputStream(final String resourceName) {
- return TestModel.class.getResourceAsStream(CONSTRAINTS_VALIDATION_TEST_YANG);
- }
-
- public static SchemaContext createTestContext() throws ReactorException {
- return YangParserTestUtils.parseYangStreams(Collections.singletonList(getDatastoreTestInputStream()));
+ public static SchemaContext createTestContext() {
+ return YangParserTestUtils.parseYangResource(CONSTRAINTS_VALIDATION_TEST_YANG);
}
@Test
public void setup() throws Exception {
final File resourceFile = new File(Bug4295Test.class.getResource("/ordered-list-modification-test.yang")
.toURI());
- context = YangParserTestUtils.parseYangSources(resourceFile);
+ context = YangParserTestUtils.parseYangFiles(resourceFile);
testModule = QNameModule.create(new URI("ordered-list-modification-test"),
SimpleDateFormatUtil.getRevisionFormat().parse("1970-01-01"));
parentContainer = QName.create(testModule, "parent-container");
*/
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.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
public class TestModel {
public static final QName TWO_QNAME = QName.create(TEST_QNAME, "two");
public static final QName THREE_QNAME = QName.create(TEST_QNAME, "three");
- public static InputStream getDatastoreTestInputStream() {
- return TestModel.class.getResourceAsStream(DATASTORE_TEST_YANG);
- }
-
- public static SchemaContext createTestContext() throws ReactorException {
- return YangParserTestUtils.parseYangStreams(Arrays.asList(getDatastoreTestInputStream()));
+ public static SchemaContext createTestContext() {
+ return createTestContext(DATASTORE_TEST_YANG);
}
- public static SchemaContext createTestContext(String resourcePath) throws ReactorException {
- InputStream yangStream = TestModel.class.getResourceAsStream(resourcePath);
- return YangParserTestUtils.parseYangStreams(Collections.singletonList(yangStream));
+ public static SchemaContext createTestContext(final String resourcePath) {
+ return YangParserTestUtils.parseYangResources(TestModel.class, resourcePath);
}
}
public void testBitIsSetFunction() throws Exception {
final Set<String> setOfBits = ImmutableSet.of("UP", "PROMISCUOUS");
- final SchemaContext schemaContext = YangParserTestUtils.parseYangSource(
+ final SchemaContext schemaContext = YangParserTestUtils.parseYangResources(BitIsSetXPathFunctionTest.class,
"/yang-xpath-functions-test/bit-is-set-function/foo.yang");
assertNotNull(schemaContext);
public void testInvalidTypeOfCorrespondingSchemaNode() throws Exception {
final Set<String> setOfBits = ImmutableSet.of("UP", "PROMISCUOUS");
- final SchemaContext schemaContext = YangParserTestUtils.parseYangSource(
+ final SchemaContext schemaContext = YangParserTestUtils.parseYangResources(BitIsSetXPathFunctionTest.class,
"/yang-xpath-functions-test/bit-is-set-function/foo-invalid.yang");
assertNotNull(schemaContext);
public void testInvalidNormalizedNodeValueType() throws Exception {
final String invalidNodeValueType = "value of invalid type";
- final SchemaContext schemaContext = YangParserTestUtils.parseYangSource(
+ final SchemaContext schemaContext = YangParserTestUtils.parseYangResources(BitIsSetXPathFunctionTest.class,
"/yang-xpath-functions-test/bit-is-set-function/foo.yang");
assertNotNull(schemaContext);
public void shouldFailOnUnknownBitArgument() throws Exception {
final Set<String> setOfBits = ImmutableSet.of("UP", "PROMISCUOUS");
- final SchemaContext schemaContext = YangParserTestUtils.parseYangSource(
+ final SchemaContext schemaContext = YangParserTestUtils.parseYangResources(BitIsSetXPathFunctionTest.class,
"/yang-xpath-functions-test/bit-is-set-function/foo.yang");
assertNotNull(schemaContext);
@Test
public void testDerefFunctionForInstanceIdentifier() throws Exception {
- final SchemaContext schemaContext = YangParserTestUtils.parseYangSource(
+ final SchemaContext schemaContext = YangParserTestUtils.parseYangResources(DerefXPathFunctionTest.class,
"/yang-xpath-functions-test/deref-function-iid/foo.yang");
assertNotNull(schemaContext);
@Test
public void testDerefFunctionForLeafref() throws Exception {
// tests absolute and relative leafref that references a leaf node
- final SchemaContext schemaContext = YangParserTestUtils.parseYangSource(
+ final SchemaContext schemaContext = YangParserTestUtils.parseYangResources(DerefXPathFunctionTest.class,
"/yang-xpath-functions-test/deref-function-leafref/foo.yang");
assertNotNull(schemaContext);
@Test
public void testDerefFunctionForLeafref2() throws Exception {
// tests leafref that references a leaf-list node
- final SchemaContext schemaContext = YangParserTestUtils.parseYangSource(
+ final SchemaContext schemaContext = YangParserTestUtils.parseYangResources(DerefXPathFunctionTest.class,
"/yang-xpath-functions-test/deref-function-leafref/foo.yang");
assertNotNull(schemaContext);
@Test
public void testDerivedFromFunction() throws Exception {
// also includes test for derived-from-or-self function
- final SchemaContext schemaContext = YangParserTestUtils.parseYangSources(ImmutableList.of(
+ final SchemaContext schemaContext = YangParserTestUtils.parseYangResources(DerivedFromXPathFunctionTest.class,
"/yang-xpath-functions-test/derived-from-function/foo.yang",
- "/yang-xpath-functions-test/derived-from-function/bar.yang"));
+ "/yang-xpath-functions-test/derived-from-function/bar.yang");
assertNotNull(schemaContext);
final XPathSchemaContext jaxenSchemaContext = jaxenSchemaContextFactory.createContext(schemaContext);
@Test
public void testInvalidTypeOfCorrespondingSchemaNode() throws Exception {
- final SchemaContext schemaContext = YangParserTestUtils.parseYangSource(
+ final SchemaContext schemaContext = YangParserTestUtils.parseYangResources(DerivedFromXPathFunctionTest.class,
"/yang-xpath-functions-test/derived-from-function/bar-invalid.yang");
assertNotNull(schemaContext);
@Test
public void testInvalidNormalizedNodeValueType() throws Exception {
- final SchemaContext schemaContext = YangParserTestUtils.parseYangSources(ImmutableList.of(
+ final SchemaContext schemaContext = YangParserTestUtils.parseYangResources(DerivedFromXPathFunctionTest.class,
"/yang-xpath-functions-test/derived-from-function/foo.yang",
- "/yang-xpath-functions-test/derived-from-function/bar.yang"));
+ "/yang-xpath-functions-test/derived-from-function/bar.yang");
assertNotNull(schemaContext);
final XPathSchemaContext jaxenSchemaContext = jaxenSchemaContextFactory.createContext(schemaContext);
@Test
public void shouldFailOnUnknownPrefixOfIdentity() throws Exception {
- final SchemaContext schemaContext = YangParserTestUtils.parseYangSources(ImmutableList.of(
+ final SchemaContext schemaContext = YangParserTestUtils.parseYangResources(DerivedFromXPathFunctionTest.class,
"/yang-xpath-functions-test/derived-from-function/foo.yang",
- "/yang-xpath-functions-test/derived-from-function/bar.yang"));
+ "/yang-xpath-functions-test/derived-from-function/bar.yang");
assertNotNull(schemaContext);
final XPathSchemaContext jaxenSchemaContext = jaxenSchemaContextFactory.createContext(schemaContext);
@Test
public void shouldFailOnMalformedIdentityArgument() throws Exception {
- final SchemaContext schemaContext = YangParserTestUtils.parseYangSources(ImmutableList.of(
+ final SchemaContext schemaContext = YangParserTestUtils.parseYangResources(DerivedFromXPathFunctionTest.class,
"/yang-xpath-functions-test/derived-from-function/foo.yang",
- "/yang-xpath-functions-test/derived-from-function/bar.yang"));
+ "/yang-xpath-functions-test/derived-from-function/bar.yang");
assertNotNull(schemaContext);
final XPathSchemaContext jaxenSchemaContext = jaxenSchemaContextFactory.createContext(schemaContext);
@Test
public void shouldFailOnUnknownIdentityArgument() throws Exception {
- final SchemaContext schemaContext = YangParserTestUtils.parseYangSources(ImmutableList.of(
+ final SchemaContext schemaContext = YangParserTestUtils.parseYangResources(DerivedFromXPathFunctionTest.class,
"/yang-xpath-functions-test/derived-from-function/foo.yang",
- "/yang-xpath-functions-test/derived-from-function/bar.yang"));
+ "/yang-xpath-functions-test/derived-from-function/bar.yang");
assertNotNull(schemaContext);
final XPathSchemaContext jaxenSchemaContext = jaxenSchemaContextFactory.createContext(schemaContext);
@Test
public void testEnumValueFunction() throws Exception {
- final SchemaContext schemaContext = YangParserTestUtils.parseYangSource(
+ final SchemaContext schemaContext = YangParserTestUtils.parseYangResources(EnumValueXPathFunctionTest.class,
"/yang-xpath-functions-test/enum-value-function/foo.yang");
assertNotNull(schemaContext);
@Test
public void testInvalidTypeOfCorrespondingSchemaNode() throws Exception {
- final SchemaContext schemaContext = YangParserTestUtils.parseYangSource(
+ final SchemaContext schemaContext = YangParserTestUtils.parseYangResources(EnumValueXPathFunctionTest.class,
"/yang-xpath-functions-test/enum-value-function/foo-invalid.yang");
assertNotNull(schemaContext);
@Test
public void testInvalidNormalizedNodeValueType() throws Exception {
- final SchemaContext schemaContext = YangParserTestUtils.parseYangSource(
+ final SchemaContext schemaContext = YangParserTestUtils.parseYangResources(EnumValueXPathFunctionTest.class,
"/yang-xpath-functions-test/enum-value-function/foo.yang");
assertNotNull(schemaContext);
@Test
public void shouldFailOnUnknownEnumNodeValue() throws Exception {
- final SchemaContext schemaContext = YangParserTestUtils.parseYangSource(
+ final SchemaContext schemaContext = YangParserTestUtils.parseYangResources(EnumValueXPathFunctionTest.class,
"/yang-xpath-functions-test/enum-value-function/foo.yang");
assertNotNull(schemaContext);
}
private static SchemaContext createSchemaContext() throws IOException, URISyntaxException, ReactorException {
- return YangParserTestUtils.parseYangSources("/test/documentTest");
+ return YangParserTestUtils.parseYangResourceDirectory("/test/documentTest");
}
private static NormalizedNode<?, ?> createNormalizedNodes() {
@Test
public void contextHolderTest() throws Exception {
- final File testYang1 = new File(getClass().getResource("/test.yang").toURI());
- final File testYang2 = new File(getClass().getResource("/test2.yang").toURI());
- final SchemaContext context = YangParserTestUtils.parseYangSources(testYang1, testYang2);
+ final SchemaContext context = YangParserTestUtils.parseYangResources(getClass(), "/test.yang", "/test2.yang");
final Set<Module> yangModules = new HashSet<>();
final ContextHolder cxH = new ContextHolder(context, yangModules, ImmutableSet.of());
assertEquals(context, cxH.getContext());
*/
Module findModuleByName(String name, Date revision);
+ default Optional<Module> findAnyModuleByName(final String name) {
+ return Optional.fromNullable(findModuleByName(name, null));
+ }
+
/**
* Returns module instance (from the context) with concrete namespace.
*
import org.opendaylight.yangtools.concepts.Delegator;
/**
- * A resource-backed {@link YangTextSchemaSource}.
+ * A resource-backed {@link YinTextSchemaSource}.
*/
final class ResourceYangTextSchemaSource extends YangTextSchemaSource implements Delegator<URL> {
private final URL url;
--- /dev/null
+/*
+ * 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.model.repo.api;
+
+import com.google.common.base.MoreObjects.ToStringHelper;
+import com.google.common.base.Preconditions;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.Optional;
+import org.opendaylight.yangtools.concepts.Delegator;
+
+/**
+ * A resource-backed {@link YangTextSchemaSource}.
+ */
+final class ResourceYinTextSchemaSource extends YinTextSchemaSource implements Delegator<URL> {
+ private final URL url;
+
+ ResourceYinTextSchemaSource(final SourceIdentifier identifier, final URL url) {
+ super(identifier);
+ this.url = Preconditions.checkNotNull(url);
+ }
+
+ @Override
+ public URL getDelegate() {
+ return url;
+ }
+
+ @Override
+ protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
+ return toStringHelper.add("url", url);
+ }
+
+ @Override
+ public InputStream openStream() throws IOException {
+ return url.openStream();
+ }
+
+ @Override
+ public Optional<String> getSymbolicName() {
+ return Optional.of(url.toString());
+ }
+}
* @throws NullPointerException if file is null
*/
public static YangTextSchemaSource forFile(final File file) {
- Preconditions.checkArgument(file.isFile(), "Supplied file %s is not a file");
+ Preconditions.checkArgument(file.isFile(), "Supplied file %s is not a file", file);
return new YangTextFileSchemaSource(identifierFromFilename(file.getName()), file);
}
--- /dev/null
+/*
+ * Copyright (c) 2017 Pantheon Technologies, s.r.o. and others. All rights 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.model.repo.api;
+
+import com.google.common.base.MoreObjects.ToStringHelper;
+import com.google.common.base.Preconditions;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.file.Files;
+import java.util.Optional;
+import org.opendaylight.yangtools.concepts.Delegator;
+
+/**
+ * A {@link YinTextSchemaSource} backed by a file.
+ *
+ * @author Robert Varga
+ */
+final class YinTextFileSchemaSource extends YinTextSchemaSource implements Delegator<File> {
+ private final File file;
+
+ YinTextFileSchemaSource(final SourceIdentifier identifier, final File file) {
+ super(identifier);
+ this.file = Preconditions.checkNotNull(file);
+ }
+
+ @Override
+ public File getDelegate() {
+ return file;
+ }
+
+ @Override
+ public InputStream openStream() throws IOException {
+ return Files.newInputStream(file.toPath());
+ }
+
+ @Override
+ protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
+ return toStringHelper.add("file", file);
+ }
+
+ @Override
+ public Optional<String> getSymbolicName() {
+ return Optional.of(file.toString());
+ }
+}
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import com.google.common.io.ByteSource;
+import com.google.common.io.Resources;
+import java.io.File;
import java.io.IOException;
import java.io.InputStream;
+import java.net.URL;
import java.util.Map.Entry;
import javax.annotation.Nonnull;
import org.opendaylight.yangtools.concepts.Delegator;
return new DelegatedYinTextSchemaSource(identifier, delegate);
}
+ public static YinTextSchemaSource forFile(final File file) {
+ Preconditions.checkArgument(file.isFile(), "Supplied file %s is not a file", file);
+ return new YinTextFileSchemaSource(identifierFromFilename(file.getName()), file);
+ }
+
+ public static YinTextSchemaSource forResource(final Class<?> clazz, final String resourceName) {
+ final String fileName = resourceName.substring(resourceName.lastIndexOf('/') + 1);
+ final SourceIdentifier identifier = identifierFromFilename(fileName);
+ final URL url = Resources.getResource(clazz, resourceName);
+ return new ResourceYinTextSchemaSource(identifier, url);
+ }
+
private static final class DelegatedYinTextSchemaSource extends YinTextSchemaSource
implements Delegator<ByteSource> {
private final ByteSource delegate;
public class Bug2444Test {
@Test
public void test() throws Exception {
- final SchemaContext schema = YangParserTestUtils.parseYangSources("/bugs/bug2444/yang");
+ final SchemaContext schema = YangParserTestUtils.parseYangResourceDirectory("/bugs/bug2444/yang");
assertNotNull(schema);
final File outDir = new File("target/bug2444-export");
package org.opendaylight.yangtools.yang.model.export.test;
import static org.junit.Assert.assertNotNull;
+
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
public class Bug4504Test {
@Test
public void test() throws Exception {
- SchemaContext schema = YangParserTestUtils.parseYangSources("/bugs/bug4504");
+ SchemaContext schema = YangParserTestUtils.parseYangResourceDirectory("/bugs/bug4504");
assertNotNull(schema);
final File outDir = new File("target/bug4504-export");
outDir.mkdirs();
public class Bug5531Test {
@Test
public void test() throws Exception {
- SchemaContext schema = YangParserTestUtils.parseYangSources("/bugs/bug5531");
+ SchemaContext schema = YangParserTestUtils.parseYangResourceDirectory("/bugs/bug5531");
assertNotNull(schema);
assertNotNull(schema.getModules());
@Test
public void testImplicitInputAndOutputInRpc() throws Exception {
- final SchemaContext schemaContext = YangParserTestUtils.parseYangSource("/bugs/bug6856/foo.yang");
+ final SchemaContext schemaContext = YangParserTestUtils.parseYangResources(Bug6856Test.class,
+ "/bugs/bug6856/foo.yang");
assertNotNull(schemaContext);
final OutputStream byteArrayOutputStream = new ByteArrayOutputStream();
@Test
public void testExplicitInputAndOutputInRpc() throws Exception {
- final SchemaContext schemaContext = YangParserTestUtils.parseYangSource("/bugs/bug6856/bar.yang");
+ final SchemaContext schemaContext = YangParserTestUtils.parseYangResources(Bug6856Test.class,
+ "/bugs/bug6856/bar.yang");
assertNotNull(schemaContext);
final OutputStream byteArrayOutputStream = new ByteArrayOutputStream();
@Test
public void testSchemaContextEmitter() throws ReactorException, IOException, URISyntaxException,
XMLStreamException, SAXException {
- final SchemaContext schemaContext = YangParserTestUtils.parseYangSources("/schema-context-emitter-test");
+ final SchemaContext schemaContext = YangParserTestUtils.parseYangResourceDirectory(
+ "/schema-context-emitter-test");
assertNotNull(schemaContext);
assertEquals(1, schemaContext.getModules().size());
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableSet;
-import java.io.InputStream;
+import java.io.IOException;
import java.util.Date;
import java.util.HashSet;
import java.util.Objects;
import org.opendaylight.yangtools.yang.model.api.ModuleImport;
import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
+import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
+import org.opendaylight.yangtools.yang.parser.rfc6020.repo.YangStatementStreamSource;
import org.opendaylight.yangtools.yang.parser.spi.source.DeclarationInTextSource;
import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.SupportedExtensionsMapping;
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
-import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl;
-import org.opendaylight.yangtools.yang.parser.util.NamedInputStream;
/**
* Helper transfer object which holds basic and dependency information for YANG
* Extracts {@link YangModelDependencyInfo} from input stream containing a YANG model. This parsing does not
* validate full YANG module, only parses header up to the revisions and imports.
*
- * @param yangStream Opened Input stream containing text source of YANG model
+ * @param refClass Base search class
+ * @param resourceName resource name, relative to refClass
* @return {@link YangModelDependencyInfo}
- * @throws IllegalArgumentException If input stream is not valid YANG stream
+ * @throws YangSyntaxErrorException If the resource does not pass syntactic analysis
+ * @throws IOException When the resource cannot be read
+ * @throws IllegalArgumentException
+ * If input stream is not valid YANG stream
*/
- public static YangModelDependencyInfo fromInputStream(final InputStream yangStream) {
- final StatementContext yangAST = new YangStatementSourceImpl(yangStream).getYangAST();
- return parseAST(yangAST, yangStream instanceof NamedInputStream ? yangStream.toString() : null);
+ public static YangModelDependencyInfo forResource(final Class<?> refClass, final String resourceName)
+ throws IOException, YangSyntaxErrorException {
+ final YangStatementStreamSource source = YangStatementStreamSource.create(
+ YangTextSchemaSource.forResource(refClass, resourceName));
+ final ParserRuleContext ast = source.getYangAST();
+ Preconditions.checkArgument(ast instanceof StatementContext);
+ return parseAST((StatementContext) ast, source.getIdentifier().toYangFilename());
}
private static YangModelDependencyInfo parseModuleContext(final StatementContext module, final String sourceName) {
getReference(sourceName, subStatementContext));
final Date revisionDate = revisionDateStr == null ? null : QName.parseRevision(revisionDateStr);
final Optional<SemVer> importSemVer = Optional.fromNullable(findSemanticVersion(subStatementContext,
- sourceName));
+ sourceName));
result.add(new ModuleImportImpl(importedModuleName, revisionDate, importSemVer));
}
}
import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
import org.opendaylight.yangtools.yang.model.repo.api.StatementParserMode;
import org.opendaylight.yangtools.yang.parser.impl.util.YangModelDependencyInfo;
+import org.opendaylight.yangtools.yang.parser.rfc6020.repo.YangStatementStreamSource;
import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
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.parser.util.ASTSchemaSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
res.getResolvedSources(), res.getUnsatisfiedImports());
}
- final Map<SourceIdentifier, ParserRuleContext> asts = Maps.transformValues(srcs, ASTSchemaSource::getAST);
final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild(
statementParserMode, supportedFeatures);
- for (final Entry<SourceIdentifier, ParserRuleContext> e : asts.entrySet()) {
- final ParserRuleContext parserRuleCtx = e.getValue();
+ for (final Entry<SourceIdentifier, ASTSchemaSource> e : srcs.entrySet()) {
+ final ASTSchemaSource ast = e.getValue();
+ final ParserRuleContext parserRuleCtx = ast.getAST();
Preconditions.checkArgument(parserRuleCtx instanceof StatementContext,
"Unsupported context class %s for source %s", parserRuleCtx.getClass(), e.getKey());
- reactor.addSource(new YangStatementSourceImpl(e.getKey(), (StatementContext) parserRuleCtx));
+ reactor.addSource(YangStatementStreamSource.create(e.getKey(), (StatementContext) parserRuleCtx,
+ ast.getSymbolicName().orElse(null)));
}
final SchemaContext schemaContext;
return new YangStatementStreamSource(source.getIdentifier(), parser, context);
}
+ public static YangStatementStreamSource create(final SourceIdentifier identifier, final StatementContext context,
+ final String symbolicName) {
+ return new YangStatementStreamSource(identifier, new YangStatementParserListenerImpl(symbolicName), context);
+ }
+
@Override
public void writePreLinkage(final StatementWriter writer, final QNameToStatementDefinition stmtDef) {
yangStatementModelParser.setAttributes(writer, stmtDef);
import com.google.common.annotations.Beta;
import com.google.common.util.concurrent.Futures;
+import java.io.IOException;
import javax.xml.parsers.SAXParser;
import javax.xml.transform.dom.DOMSource;
import org.opendaylight.yangtools.util.xml.UntrustedXML;
import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistry;
import org.opendaylight.yangtools.yang.model.repo.util.SchemaSourceTransformer;
import org.w3c.dom.Document;
+import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
/**
*/
@Beta
public final class YinTextToDomTransformer extends SchemaSourceTransformer<YinTextSchemaSource, YinDomSchemaSource> {
-
- @Deprecated
- public static final Transformation<YinTextSchemaSource, YinDomSchemaSource> TRANSFORMATION = input -> {
- final Document doc = UntrustedXML.newDocumentBuilder().newDocument();
- final SAXParser parser = UntrustedXML.newSAXParser();
- final DefaultHandler handler = new StatementSourceReferenceHandler(doc, null);
- parser.parse(input.openStream(), handler);
-
- return Futures.immediateCheckedFuture(YinDomSchemaSource.create(input.getIdentifier(), new DOMSource(doc)));
- };
-
private YinTextToDomTransformer(final SchemaRepository provider, final SchemaSourceRegistry consumer) {
- super(provider, YinTextSchemaSource.class, consumer, YinDomSchemaSource.class, TRANSFORMATION);
+ super(provider, YinTextSchemaSource.class, consumer, YinDomSchemaSource.class,
+ input -> Futures.immediateCheckedFuture(transformSource(input)));
}
public static YinTextToDomTransformer create(final SchemaRepository provider, final SchemaSourceRegistry consumer) {
return new YinTextToDomTransformer(provider, consumer);
}
+ public static YinDomSchemaSource transformSource(final YinTextSchemaSource source) throws SAXException, IOException {
+ final Document doc = UntrustedXML.newDocumentBuilder().newDocument();
+ final SAXParser parser = UntrustedXML.newSAXParser();
+ final DefaultHandler handler = new StatementSourceReferenceHandler(doc, null);
+ parser.parse(source.openStream(), handler);
+ return YinDomSchemaSource.create(source.getIdentifier(), new DOMSource(doc));
+ }
+
}
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
-import com.google.common.io.ByteSource;
-import java.io.IOException;
-import java.io.InputStream;
import java.util.Arrays;
import java.util.Collection;
import java.util.EnumMap;
-import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import javax.annotation.Nonnull;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
import org.opendaylight.yangtools.yang.model.repo.api.StatementParserMode;
-import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
-import org.opendaylight.yangtools.yang.parser.rfc6020.repo.YangStatementStreamSource;
import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
import org.opendaylight.yangtools.yang.parser.spi.meta.StatementSupportBundle;
import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
import org.opendaylight.yangtools.yang.parser.spi.validation.ValidationBundlesNamespace.ValidationBundleType;
-import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl;
public final class CrossSourceStatementReactor {
private final Map<ModelProcessingPhase, StatementSupportBundle> supportedTerminology;
public EffectiveSchemaContext buildEffective() throws ReactorException {
return context.buildEffective();
}
-
- /**
- * Add specified sources and assemble the resulting SchemaContext.
- *
- * @deprecated Use {@link #addSources(Collection)} and {@link #buildEffective()} instead.
- */
- @Deprecated
- public SchemaContext buildEffective(final Collection<ByteSource> yangByteSources) throws ReactorException,
- IOException {
- for (final ByteSource source : yangByteSources) {
- if (source instanceof YangTextSchemaSource) {
- try {
- addSource(YangStatementStreamSource.create((YangTextSchemaSource) source));
- } catch (YangSyntaxErrorException e) {
- throw new IOException("Source " + source + " failed to parse", e);
- }
- } else {
- addSource(new YangStatementSourceImpl(source.openStream()));
- }
- }
-
- return buildEffective();
- }
-
- /**
- * Add specified sources and assemble the resulting SchemaContext.
- *
- * @deprecated Use {@link #addSources(Collection)} and {@link #buildEffective()} instead.
- */
- @Deprecated
- public SchemaContext buildEffective(final List<InputStream> yangInputStreams) throws ReactorException {
- for (final InputStream yangInputStream : yangInputStreams) {
- addSource(new YangStatementSourceImpl(yangInputStream));
- }
-
- return buildEffective();
- }
}
}
+++ /dev/null
-/*
- * 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.stmt.rfc6020;
-
-import com.google.common.base.Throwables;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URISyntaxException;
-import org.antlr.v4.runtime.tree.ParseTreeWalker;
-import org.opendaylight.yangtools.antlrv4.code.gen.YangStatementParser.StatementContext;
-import org.opendaylight.yangtools.yang.common.YangVersion;
-import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
-import org.opendaylight.yangtools.yang.parser.impl.YangStatementParserListenerImpl;
-import org.opendaylight.yangtools.yang.parser.rfc6020.repo.YangStatementStreamSource;
-import org.opendaylight.yangtools.yang.parser.spi.source.PrefixToModule;
-import org.opendaylight.yangtools.yang.parser.spi.source.QNameToStatementDefinition;
-import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
-import org.opendaylight.yangtools.yang.parser.spi.source.StatementWriter;
-import org.opendaylight.yangtools.yang.parser.util.NamedFileInputStream;
-import org.opendaylight.yangtools.yang.parser.util.NamedInputStream;
-
-/**
- * This class represents implementation of StatementStreamSource in order to emit YANG statements using supplied
- * StatementWriter.
- *
- * @deprecated Use {@link YangStatementStreamSource} instead.
- */
-@Deprecated
-public final class YangStatementSourceImpl implements StatementStreamSource {
- private final YangStatementParserListenerImpl yangStatementModelParser;
- private final StatementContext statementContext;
- private final String sourceName;
-
- public YangStatementSourceImpl(final String fileName, final boolean isAbsolute) {
- try {
- final NamedFileInputStream is = loadFile(fileName, isAbsolute);
- sourceName = is.toString();
- statementContext = YangStatementStreamSource.parseYangSource(is);
- yangStatementModelParser = new YangStatementParserListenerImpl(sourceName);
- } catch (IOException | URISyntaxException | YangSyntaxErrorException e) {
- throw Throwables.propagate(e);
- }
- }
-
- public YangStatementSourceImpl(final InputStream inputStream) {
- try {
- sourceName = inputStream instanceof NamedInputStream ? inputStream.toString() : null;
- statementContext = YangStatementStreamSource.parseYangSource(inputStream);
- yangStatementModelParser = new YangStatementParserListenerImpl(sourceName);
- } catch (IOException | YangSyntaxErrorException e) {
- throw Throwables.propagate(e);
- }
- }
-
- public YangStatementSourceImpl(final SourceIdentifier identifier, final StatementContext statementContext) {
- this.statementContext = statementContext;
- this.sourceName = identifier.getName();
- yangStatementModelParser = new YangStatementParserListenerImpl(sourceName);
- }
-
- @Override
- public void writePreLinkage(final StatementWriter writer, final QNameToStatementDefinition stmtDef) {
- yangStatementModelParser.setAttributes(writer, stmtDef);
- ParseTreeWalker.DEFAULT.walk(yangStatementModelParser, statementContext);
- }
-
- @Override
- public void writeLinkage(final StatementWriter writer, final QNameToStatementDefinition stmtDef,
- final PrefixToModule preLinkagePrefixes) {
- writeLinkage(writer, stmtDef, preLinkagePrefixes, YangVersion.VERSION_1);
- }
-
- @Override
- public void writeLinkage(final StatementWriter writer, final QNameToStatementDefinition stmtDef,
- final PrefixToModule preLinkagePrefixes, final YangVersion yangVersion) {
- yangStatementModelParser.setAttributes(writer, stmtDef, preLinkagePrefixes, yangVersion);
- ParseTreeWalker.DEFAULT.walk(yangStatementModelParser, statementContext);
- }
-
- @Override
- public void writeLinkageAndStatementDefinitions(final StatementWriter writer,
- final QNameToStatementDefinition stmtDef, final PrefixToModule prefixes) {
- writeLinkageAndStatementDefinitions(writer, stmtDef, prefixes, YangVersion.VERSION_1);
- }
-
- @Override
- public void writeLinkageAndStatementDefinitions(final StatementWriter writer,
- final QNameToStatementDefinition stmtDef, final PrefixToModule prefixes, final YangVersion yangVersion) {
- yangStatementModelParser.setAttributes(writer, stmtDef, prefixes, yangVersion);
- ParseTreeWalker.DEFAULT.walk(yangStatementModelParser, statementContext);
- }
-
- @Override
- public void writeFull(final StatementWriter writer, final QNameToStatementDefinition stmtDef,
- final PrefixToModule prefixes) {
- writeFull(writer, stmtDef, prefixes, YangVersion.VERSION_1);
- }
-
- @Override
- public void writeFull(final StatementWriter writer, final QNameToStatementDefinition stmtDef,
- final PrefixToModule prefixes, final YangVersion yangVersion) {
- yangStatementModelParser.setAttributes(writer, stmtDef, prefixes, yangVersion);
- ParseTreeWalker.DEFAULT.walk(yangStatementModelParser, statementContext);
- }
-
- private NamedFileInputStream loadFile(final String fileName, final boolean isAbsolute)
- throws URISyntaxException, IOException {
- //TODO: we need absolute path first!
- return isAbsolute ? new NamedFileInputStream(new File(fileName), fileName)
- : new NamedFileInputStream(new File(getClass().getResource(fileName).toURI()), fileName);
- }
-
- public StatementContext getYangAST() {
- return statementContext;
- }
-
- @Override
- public String toString() {
- return sourceName;
- }
-}
+++ /dev/null
-/*
- * 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.stmt.rfc6020;
-
-import com.google.common.base.Throwables;
-import com.google.common.collect.ForwardingObject;
-import com.google.common.io.ByteSource;
-import com.google.common.io.ByteStreams;
-import com.google.common.io.Files;
-import java.io.File;
-import java.io.InputStream;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
-import org.opendaylight.yangtools.yang.model.repo.api.YinDomSchemaSource;
-import org.opendaylight.yangtools.yang.model.repo.api.YinTextSchemaSource;
-import org.opendaylight.yangtools.yang.parser.rfc6020.repo.YinStatementStreamSource;
-import org.opendaylight.yangtools.yang.parser.rfc6020.repo.YinTextToDomTransformer;
-import org.opendaylight.yangtools.yang.parser.spi.source.PrefixToModule;
-import org.opendaylight.yangtools.yang.parser.spi.source.QNameToStatementDefinition;
-import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
-import org.opendaylight.yangtools.yang.parser.spi.source.StatementWriter;
-
-/**
- * This class represents implementation of StatementStreamSource
- * in order to emit YIN statements using supplied StatementWriter.
- *
- * @deprecated Scheduled for removal. Use {@link YinStatementStreamSource} instead.
- */
-@Deprecated
-public final class YinStatementSourceImpl extends ForwardingObject implements StatementStreamSource {
- private final StatementStreamSource delegate;
-
- private YinStatementSourceImpl(final YinDomSchemaSource source) {
- this.delegate = YinStatementStreamSource.create(source);
- }
-
- @Override
- public StatementStreamSource delegate() {
- return delegate;
- }
-
- public YinStatementSourceImpl(final InputStream inputStream) {
- this(newStreamSource(inputStream));
- }
-
- private static YinDomSchemaSource newStreamSource(final InputStream inputStream) {
- final SourceIdentifier id = YinTextSchemaSource.identifierFromFilename(inputStream.toString());
-
- try {
- final YinTextSchemaSource text = YinTextSchemaSource.delegateForByteSource(id,
- ByteSource.wrap(ByteStreams.toByteArray(inputStream)));
- return YinTextToDomTransformer.TRANSFORMATION.apply(text).get();
- } catch (Exception e) {
- throw Throwables.propagate(e);
- }
- }
-
- private static YinDomSchemaSource newStreamSource(final String fileName, final boolean isAbsolute) {
- try {
- final File file;
- if (isAbsolute) {
- file = new File(fileName);
- } else {
- file = new File(YinStatementSourceImpl.class.getResource(fileName).toURI());
- }
-
- final YinTextSchemaSource text = YinTextSchemaSource.delegateForByteSource(
- YinTextSchemaSource.identifierFromFilename(file.getName()), Files.asByteSource(file));
-
- return YinTextToDomTransformer.TRANSFORMATION.apply(text).get();
- } catch (Exception e) {
- throw Throwables.propagate(e);
- }
- }
-
- public YinStatementSourceImpl(final String fileName, final boolean isAbsolute) {
- this(newStreamSource(fileName, isAbsolute));
- }
-
- @Override
- public void writePreLinkage(final StatementWriter writer, final QNameToStatementDefinition stmtDef) {
- delegate.writePreLinkage(writer, stmtDef);
- }
-
- @Override
- public void writeLinkage(final StatementWriter writer, final QNameToStatementDefinition stmtDef,
- final PrefixToModule preLinkagePrefixes) {
- delegate.writeLinkage(writer, stmtDef, preLinkagePrefixes);
-
- }
-
- @Override
- public void writeLinkageAndStatementDefinitions(final StatementWriter writer, final QNameToStatementDefinition stmtDef,
- final PrefixToModule prefixes) {
- delegate.writeLinkageAndStatementDefinitions(writer, stmtDef, prefixes);
- }
-
- @Override
- public void writeFull(final StatementWriter writer, final QNameToStatementDefinition stmtDef,
- final PrefixToModule prefixes) {
- delegate().writeFull(writer, stmtDef, prefixes);
- }
-
-}
+++ /dev/null
-/*
- * 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.util;
-
-/**
- * @deprecated This exception is not produced anywhere and is scheduled for removal.
- */
-// TODO: switch to checked exception, add YangSemanticException
-@Deprecated
-public class YangParseException extends RuntimeException {
- private static final long serialVersionUID = 1239548963471793178L;
-
- public YangParseException(final String errorMsg) {
- super(errorMsg);
- }
-
- public YangParseException(final String errorMsg, final Exception exception) {
- super(errorMsg, exception);
- }
-
- public YangParseException(final String moduleName, final int line, final String errorMsg) {
- super("Error in module '" + moduleName + "' at line " + line + ": " + errorMsg);
- }
-
- public YangParseException(final String moduleName, final int line, final String errorMsg, final Exception exception) {
- super("Error in module '" + moduleName + "' at line " + line + ": " + errorMsg, exception);
- }
-}
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
-import java.io.InputStream;
+
+import java.io.IOException;
import org.junit.Test;
+import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
public class YangModelDependencyInfoTest {
@Test
- public void testModuleWithNoImports() {
- InputStream stream = getClass().getResourceAsStream("/ietf/ietf-inet-types@2010-09-24.yang");
- YangModelDependencyInfo info = YangModelDependencyInfo.fromInputStream(stream);
+ public void testModuleWithNoImports() throws IOException, YangSyntaxErrorException {
+ YangModelDependencyInfo info = YangModelDependencyInfo.forResource(getClass(),
+ "/ietf/ietf-inet-types@2010-09-24.yang");
assertNotNull(info);
assertEquals("ietf-inet-types", info.getName());
assertEquals("2010-09-24", info.getFormattedRevision());
}
@Test
- public void testModuleWithImports() {
- InputStream stream = getClass().getResourceAsStream("/parse-methods/dependencies/m2@2013-09-30.yang");
- YangModelDependencyInfo info = YangModelDependencyInfo.fromInputStream(stream);
+ public void testModuleWithImports() throws IOException, YangSyntaxErrorException {
+ YangModelDependencyInfo info = YangModelDependencyInfo.forResource(getClass(),
+ "/parse-methods/dependencies/m2@2013-09-30.yang");
assertNotNull(info);
assertEquals("m2", info.getName());
assertEquals("2013-09-30", info.getFormattedRevision());
}
@Test
- public void testModuleWithoutRevision() {
- InputStream stream = getClass().getResourceAsStream("/no-revision/module-without-revision.yang");
- YangModelDependencyInfo info = YangModelDependencyInfo.fromInputStream(stream);
+ public void testModuleWithoutRevision() throws IOException, YangSyntaxErrorException {
+ YangModelDependencyInfo info = YangModelDependencyInfo.forResource(getClass(),
+ "/no-revision/module-without-revision.yang");
assertNotNull(info);
assertEquals("module-without-revision", info.getName());
assertNull(info.getFormattedRevision());
}
@Test
- public void testEquals() {
- InputStream stream1 = getClass().getResourceAsStream("/ietf/ietf-inet-types@2010-09-24.yang");
- YangModelDependencyInfo info1 = YangModelDependencyInfo.fromInputStream(stream1);
- InputStream stream2 = getClass().getResourceAsStream("/no-revision/module-without-revision.yang");
- YangModelDependencyInfo info2 = YangModelDependencyInfo.fromInputStream(stream2);
+ public void testEquals() throws IOException, YangSyntaxErrorException {
+ YangModelDependencyInfo info1 = YangModelDependencyInfo.forResource(getClass(),
+ "/ietf/ietf-inet-types@2010-09-24.yang");
+ YangModelDependencyInfo info2 = YangModelDependencyInfo.forResource(getClass(),
+ "/no-revision/module-without-revision.yang");
assertTrue(info1.equals(info1));
assertFalse(info1.equals(null));
- assertFalse(info1.equals(stream1));
assertFalse(info1.equals(info2));
}
@Test
- public void testHashcode() {
- InputStream stream = getClass().getResourceAsStream("/no-revision/module-without-revision.yang");
- YangModelDependencyInfo info = YangModelDependencyInfo.fromInputStream(stream);
-
+ public void testHashcode() throws IOException, YangSyntaxErrorException {
+ YangModelDependencyInfo info = YangModelDependencyInfo.forResource(getClass(),
+ "/no-revision/module-without-revision.yang");
assertNotEquals("hashcode", 31, info.hashCode());
}
}
import static org.junit.Assert.assertEquals;
-import org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier;
-
import com.google.common.base.Optional;
import java.util.HashMap;
import java.util.Map;
import org.junit.Test;
+import org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier;
import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
import org.opendaylight.yangtools.yang.parser.impl.util.YangModelDependencyInfo;
public void testModulesWithoutRevisionAndImport() throws Exception {
final Map<SourceIdentifier, YangModelDependencyInfo> map = new HashMap<>();
- addToMap(map, YangModelDependencyInfo.ModuleDependencyInfo.fromInputStream(getClass().getResourceAsStream("/no-revision/imported.yang")));
- addToMap(map, YangModelDependencyInfo.ModuleDependencyInfo.fromInputStream(getClass().getResourceAsStream("/no-revision/imported@2012-12-12.yang")));
- addToMap(map, YangModelDependencyInfo.ModuleDependencyInfo.fromInputStream(getClass().getResourceAsStream("/no-revision/top@2012-10-10.yang")));
+ addToMap(map, YangModelDependencyInfo.ModuleDependencyInfo.forResource(getClass(), "/no-revision/imported.yang"));
+ addToMap(map, YangModelDependencyInfo.ModuleDependencyInfo.forResource(getClass(), "/no-revision/imported@2012-12-12.yang"));
+ addToMap(map, YangModelDependencyInfo.ModuleDependencyInfo.forResource(getClass(), "/no-revision/top@2012-10-10.yang"));
final DependencyResolver resolved = RevisionDependencyResolver.create(map);
final Map<SourceIdentifier, YangModelDependencyInfo> map = new HashMap<>();
// Subfoo does not have parent in reactor
- addToMap(map, YangModelDependencyInfo.ModuleDependencyInfo.fromInputStream(getClass().getResourceAsStream("/model/subfoo.yang")));
- addToMap(map, YangModelDependencyInfo.ModuleDependencyInfo.fromInputStream(getClass().getResourceAsStream("/model/bar.yang")));
- addToMap(map, YangModelDependencyInfo.ModuleDependencyInfo.fromInputStream(getClass().getResourceAsStream("/model/baz.yang")));
+ addToMap(map, YangModelDependencyInfo.ModuleDependencyInfo.forResource(getClass(), "/model/subfoo.yang"));
+ addToMap(map, YangModelDependencyInfo.ModuleDependencyInfo.forResource(getClass(), "/model/bar.yang"));
+ addToMap(map, YangModelDependencyInfo.ModuleDependencyInfo.forResource(getClass(), "/model/baz.yang"));
final DependencyResolver resolved = RevisionDependencyResolver.create(map);
public void testSubmodule() throws Exception {
final Map<SourceIdentifier, YangModelDependencyInfo> map = new HashMap<>();
- addToMap(map, YangModelDependencyInfo.ModuleDependencyInfo.fromInputStream(getClass().getResourceAsStream("/model/subfoo.yang")));
- addToMap(map, YangModelDependencyInfo.ModuleDependencyInfo.fromInputStream(getClass().getResourceAsStream("/model/foo.yang")));
- addToMap(map, YangModelDependencyInfo.ModuleDependencyInfo.fromInputStream(getClass().getResourceAsStream("/model/bar.yang")));
- addToMap(map, YangModelDependencyInfo.ModuleDependencyInfo.fromInputStream(getClass().getResourceAsStream("/model/baz.yang")));
+ addToMap(map, YangModelDependencyInfo.ModuleDependencyInfo.forResource(getClass(), "/model/subfoo.yang"));
+ addToMap(map, YangModelDependencyInfo.ModuleDependencyInfo.forResource(getClass(), "/model/foo.yang"));
+ addToMap(map, YangModelDependencyInfo.ModuleDependencyInfo.forResource(getClass(), "/model/bar.yang"));
+ addToMap(map, YangModelDependencyInfo.ModuleDependencyInfo.forResource(getClass(), "/model/baz.yang"));
final DependencyResolver resolved = RevisionDependencyResolver.create(map);
import java.io.IOException;
import java.net.URISyntaxException;
import java.text.ParseException;
-import java.util.Arrays;
import org.junit.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
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.parser.api.YangSyntaxErrorException;
import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
+import org.opendaylight.yangtools.yang.parser.rfc6020.repo.YangStatementStreamSource;
import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
public class ConstraintDefinitionsTest {
@Test
- public void testConstraintDefinitions() throws ParseException, ReactorException, URISyntaxException, IOException {
+ public void testConstraintDefinitions() throws ParseException, ReactorException, URISyntaxException, IOException,
+ YangSyntaxErrorException {
final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
- final YangTextSchemaSource source = YangTextSchemaSource.forResource("/constraint-definitions-test/foo.yang");
-
- final SchemaContext schemaContext = reactor.buildEffective(Arrays.asList(source));
+ reactor.addSource(YangStatementStreamSource.create(
+ YangTextSchemaSource.forResource("/constraint-definitions-test/foo.yang")));
+ final SchemaContext schemaContext = reactor.buildEffective();
assertNotNull(schemaContext);
final Module testModule = schemaContext.findModuleByName("foo",
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.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
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.common.QNameModule;
import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
import org.opendaylight.yangtools.yang.common.YangConstants;
import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
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.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.TypeUtils;
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<Module> modules;
-
- @BeforeClass
- public static void init() throws FileNotFoundException, ParseException {
- final DateFormat simpleDateFormat = SimpleDateFormatUtil.getRevisionFormat();
- 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");
- }
+ private static final QNameModule FOO = QNameModule.create(
+ URI.create("urn:opendaylight.foo"), QName.parseRevision("2013-10-13"));
+ private static final QNameModule BAR = QNameModule.create(
+ URI.create("urn:opendaylight.bar"), QName.parseRevision("2013-10-14"));
+ private static final QNameModule BAZ = QNameModule.create(
+ URI.create("urn:opendaylight.baz"), QName.parseRevision("2013-10-15"));
+
+ private static final QName Q0 = QName.create(BAR, "interfaces");
+ private static final QName Q1 = QName.create(BAR, "ifEntry");
+ private static final QName Q2 = QName.create(BAZ, "augment-holder");
@Test
public void testAugmentParsing() throws Exception {
- modules = TestUtils.loadModules(getClass().getResource("/augment-test/augment-in-augment").toURI());
+ final SchemaContext context = TestUtils.loadModules(getClass().getResource("/augment-test/augment-in-augment")
+ .toURI());
SchemaPath expectedSchemaPath;
final List<QName> qnames = new ArrayList<>();
- qnames.add(q0);
- qnames.add(q1);
- qnames.add(q2);
+ qnames.add(Q0);
+ qnames.add(Q1);
+ qnames.add(Q2);
// foo.yang
- final Module module1 = TestUtils.findModule(modules, "foo");
+ final Module module1 = TestUtils.findModule(context, "foo").get();
Set<AugmentationSchema> augmentations = module1.getAugmentations();
assertEquals(1, augmentations.size());
final AugmentationSchema augment = augmentations.iterator().next();
assertNotNull(odl);
// leaf ds0ChannelNumber
- QName qname = QName.create(fooNS, fooRev, "ds0ChannelNumber");
+ QName qname = QName.create(FOO, "ds0ChannelNumber");
qnames.add(qname);
assertEquals(qname, ds0ChannelNumber.getQName());
expectedSchemaPath = SchemaPath.create(qnames, true);
assertEquals(expectedSchemaPath, ds0ChannelNumber.getType().getPath());
// leaf interface-id
- qname = QName.create(fooNS, fooRev, "interface-id");
+ qname = QName.create(FOO, "interface-id");
assertEquals(qname, interfaceId.getQName());
qnames.set(3, qname);
expectedSchemaPath = SchemaPath.create(qnames, true);
assertFalse(interfaceId.isAugmenting());
// container schemas
- qname = QName.create(fooNS, fooRev, "schemas");
+ qname = QName.create(FOO, "schemas");
assertEquals(qname, schemas.getQName());
qnames.set(3, qname);
expectedSchemaPath = SchemaPath.create(qnames, true);
assertFalse(schemas.isAugmenting());
// choice odl
- qname = QName.create(fooNS, fooRev, "odl");
+ qname = QName.create(FOO, "odl");
assertEquals(qname, odl.getQName());
qnames.set(3, qname);
expectedSchemaPath = SchemaPath.create(qnames, true);
assertFalse(odl.isAugmenting());
// baz.yang
- final Module module3 = TestUtils.findModule(modules, "baz");
+ final Module module3 = TestUtils.findModule(context, "baz").get();
augmentations = module3.getAugmentations();
assertEquals(3, augmentations.size());
AugmentationSchema augment1 = null;
@Test
public void testAugmentResolving() throws Exception {
- modules = TestUtils.loadModules(getClass().getResource("/augment-test/augment-in-augment").toURI());
- final Module module2 = TestUtils.findModule(modules, "bar");
+ final SchemaContext context = TestUtils.loadModules(getClass().getResource("/augment-test/augment-in-augment")
+ .toURI());
+ final Module module2 = TestUtils.findModule(context, "bar").get();
final ContainerSchemaNode interfaces = (ContainerSchemaNode) module2.getDataChildByName(QName.create(
module2.getQNameModule(), "interfaces"));
final ListSchemaNode ifEntry = (ListSchemaNode) interfaces.getDataChildByName(QName.create(
SchemaPath expectedPath;
final List<QName> qnames = new ArrayList<>();
- qnames.add(q0);
- qnames.add(q1);
- qnames.add(q2);
+ qnames.add(Q0);
+ qnames.add(Q1);
+ qnames.add(Q2);
// baz.yang
// augment "/br:interfaces/br:ifEntry" {
- final ContainerSchemaNode augmentHolder = (ContainerSchemaNode) ifEntry.getDataChildByName(QName.create(bazNS,
- bazRev, "augment-holder"));
+ final ContainerSchemaNode augmentHolder = (ContainerSchemaNode) ifEntry.getDataChildByName(QName.create(BAZ,
+ "augment-holder"));
TestUtils.checkIsAugmenting(augmentHolder, true);
- assertEquals(q2, augmentHolder.getQName());
+ assertEquals(Q2, augmentHolder.getQName());
expectedPath = SchemaPath.create(qnames, true);
assertEquals(expectedPath, augmentHolder.getPath());
// foo.yang
// augment "/br:interfaces/br:ifEntry/bz:augment-holder"
- final LeafSchemaNode ds0ChannelNumber = (LeafSchemaNode) augmentHolder.getDataChildByName(QName.create(fooNS,
- fooRev, "ds0ChannelNumber"));
- final LeafSchemaNode interfaceId = (LeafSchemaNode) augmentHolder.getDataChildByName(QName.create(fooNS,
- fooRev, "interface-id"));
- final ContainerSchemaNode schemas = (ContainerSchemaNode) augmentHolder.getDataChildByName(QName.create(fooNS,
- fooRev, "schemas"));
- final ChoiceSchemaNode odl = (ChoiceSchemaNode) augmentHolder.getDataChildByName(QName.create(fooNS, fooRev,
- "odl"));
+ final LeafSchemaNode ds0ChannelNumber = (LeafSchemaNode) augmentHolder.getDataChildByName(QName.create(FOO,
+ "ds0ChannelNumber"));
+ final LeafSchemaNode interfaceId = (LeafSchemaNode) augmentHolder.getDataChildByName(QName.create(FOO,
+ "interface-id"));
+ final ContainerSchemaNode schemas = (ContainerSchemaNode) augmentHolder.getDataChildByName(QName.create(FOO,
+ "schemas"));
+ final ChoiceSchemaNode odl = (ChoiceSchemaNode) augmentHolder.getDataChildByName(QName.create(FOO, "odl"));
assertNotNull(ds0ChannelNumber);
assertNotNull(interfaceId);
assertNotNull(odl);
// leaf ds0ChannelNumber
- QName qname = QName.create(fooNS, fooRev, "ds0ChannelNumber");
+ QName qname = QName.create(FOO, "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");
+ qname = QName.create(FOO, "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");
+ qname = QName.create(FOO, "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");
+ qname = QName.create(FOO, "odl");
assertEquals(qname, odl.getQName());
qnames.set(3, qname);
expectedPath = SchemaPath.create(qnames, true);
@Test
public void testAugmentedChoice() throws Exception {
- modules = TestUtils.loadModules(getClass().getResource("/augment-test/augment-in-augment").toURI());
- final Module module2 = TestUtils.findModule(modules, "bar");
+ final SchemaContext context = TestUtils.loadModules(getClass().getResource("/augment-test/augment-in-augment")
+ .toURI());
+ final Module module2 = TestUtils.findModule(context, "bar").get();
final ContainerSchemaNode interfaces = (ContainerSchemaNode) module2.getDataChildByName(QName.create(
module2.getQNameModule(), "interfaces"));
final ListSchemaNode ifEntry = (ListSchemaNode) interfaces.getDataChildByName(QName.create(
module2.getQNameModule(), "ifEntry"));
final ContainerSchemaNode augmentedHolder = (ContainerSchemaNode) ifEntry.getDataChildByName(QName.create(
- bazNS, bazRev, "augment-holder"));
+ BAZ, "augment-holder"));
TestUtils.checkIsAugmenting(augmentedHolder, true);
// foo.yang
// augment "/br:interfaces/br:ifEntry/bz:augment-holder"
- final ChoiceSchemaNode odl = (ChoiceSchemaNode) augmentedHolder.getDataChildByName(QName.create(fooNS, fooRev,
- "odl"));
+ final ChoiceSchemaNode odl = (ChoiceSchemaNode) augmentedHolder.getDataChildByName(QName.create(FOO, "odl"));
assertNotNull(odl);
final Set<ChoiceCaseNode> cases = odl.getCases();
assertEquals(4, cases.size());
SchemaPath expectedPath;
final List<QName> qnames = new ArrayList<>();
- qnames.add(q0);
- qnames.add(q1);
- qnames.add(q2);
- qnames.add(QName.create(fooNS, fooRev, "odl"));
+ qnames.add(Q0);
+ qnames.add(Q1);
+ qnames.add(Q2);
+ qnames.add(QName.create(FOO, "odl"));
// case id
- QName qname = QName.create(fooNS, fooRev, "id");
+ QName qname = QName.create(FOO, "id");
assertEquals(qname, id.getQName());
qnames.add(qname);
expectedPath = SchemaPath.create(qnames, true);
assertEquals(1, idChildren.size());
// case node1
- qname = QName.create(fooNS, fooRev, "node1");
+ qname = QName.create(FOO, "node1");
assertEquals(qname, node1.getQName());
qnames.set(4, qname);
expectedPath = SchemaPath.create(qnames, true);
assertTrue(node1Children.isEmpty());
// case node2
- qname = QName.create(fooNS, fooRev, "node2");
+ qname = QName.create(FOO, "node2");
assertEquals(qname, node2.getQName());
qnames.set(4, qname);
expectedPath = SchemaPath.create(qnames, true);
assertTrue(node2Children.isEmpty());
// case node3
- qname = QName.create(fooNS, fooRev, "node3");
+ qname = QName.create(FOO, "node3");
assertEquals(qname, node3.getQName());
qnames.set(4, qname);
expectedPath = SchemaPath.create(qnames, true);
// test cases
qnames.clear();
- qnames.add(q0);
- qnames.add(q1);
- qnames.add(q2);
- qnames.add(QName.create(fooNS, fooRev, "odl"));
+ qnames.add(Q0);
+ qnames.add(Q1);
+ qnames.add(Q2);
+ qnames.add(QName.create(FOO, "odl"));
// case id child
- qnames.add(QName.create(fooNS, fooRev, "id"));
- qnames.add(QName.create(fooNS, fooRev, "id"));
+ qnames.add(QName.create(FOO, "id"));
+ qnames.add(QName.create(FOO, "id"));
final 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"));
+ qnames.set(4, QName.create(FOO, "node3"));
+ qnames.set(5, QName.create(FOO, "node3"));
final ContainerSchemaNode caseNode3Child = (ContainerSchemaNode) node3Children.iterator().next();
assertNotNull(caseNode3Child);
expectedPath = SchemaPath.create(qnames, true);
@Test
public void testAugmentRpc() throws Exception {
- modules = TestUtils.loadModules(getClass().getResource("/augment-test/rpc").toURI());
+ final SchemaContext context = 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 = SimpleDateFormatUtil.getRevisionFormat().parse("2013-10-11");
- final Module bar = TestUtils.findModule(modules, "bar");
+ final Module bar = TestUtils.findModule(context, "bar").get();
final Set<RpcDefinition> rpcs = bar.getRpcs();
assertEquals(2, rpcs.size());
@Test
public void testAugmentInUsesResolving() throws Exception {
- modules = TestUtils.loadModules(getClass().getResource("/augment-test/augment-in-uses").toURI());
- assertEquals(1, modules.size());
+ final SchemaContext context = TestUtils.loadModules(getClass().getResource("/augment-test/augment-in-uses")
+ .toURI());
+ assertEquals(1, context.getModules().size());
- final Module test = modules.iterator().next();
+ final Module test = context.getModules().iterator().next();
final DataNodeContainer links = (DataNodeContainer) test.getDataChildByName(QName.create(test.getQNameModule(),
"links"));
final DataNodeContainer link = (DataNodeContainer) links.getDataChildByName(QName.create(test.getQNameModule(),
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.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.UsesNode;
import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
public class AugmentToExtensionTest {
- private Set<Module> modules;
+ private SchemaContext context;
@Test(expected = SomeModifiersUnresolvedException.class)
public void testIncorrectPath() throws Exception {
- modules = TestUtils.loadModules(getClass().getResource("/augment-to-extension-test/incorrect-path").toURI());
+ context = TestUtils.loadModules(getClass().getResource("/augment-to-extension-test/incorrect-path").toURI());
}
/*
public void testCorrectPathIntoUnsupportedTarget() throws Exception {
try {
- modules = TestUtils.loadModules(getClass().getResource(
+ context = TestUtils.loadModules(getClass().getResource(
"/augment-to-extension-test/correct-path-into-unsupported-target").toURI());
} catch (final Exception e) {
StmtTestUtils.log(e, " ");
throw e;
}
- final Module devicesModule = TestUtils.findModule(modules, "augment-module");
+ final Module devicesModule = TestUtils.findModule(context, "augment-module").get();
final ContainerSchemaNode devicesContainer = (ContainerSchemaNode) devicesModule.getDataChildByName(QName
.create(devicesModule.getQNameModule(), "my-container"));
@Test
public void testCorrectAugment() throws Exception {
- modules = TestUtils.loadModules(getClass().getResource("/augment-to-extension-test/correct-augment").toURI());
+ context = TestUtils.loadModules(getClass().getResource("/augment-to-extension-test/correct-augment").toURI());
- final Module devicesModule = TestUtils.findModule(modules, "augment-module");
+ final Module devicesModule = TestUtils.findModule(context, "augment-module").get();
final ContainerSchemaNode devicesContainer = (ContainerSchemaNode) devicesModule.getDataChildByName(QName
.create(devicesModule.getQNameModule(), "my-container"));
import java.net.URI;
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;
@Test
public void test() throws Exception {
-
- Set<Module> modules = null;
-
-
- modules = TestUtils.loadModules(getClass().getResource("/bugs/bug1412").toURI());
-
-
- final Module bug1412 = TestUtils.findModule(modules, "bug1412");
- assertNotNull(bug1412);
+ final Module bug1412 = TestUtils.findModule(
+ TestUtils.loadModules(getClass().getResource("/bugs/bug1412").toURI()), "bug1412").get();
final ContainerSchemaNode node = (ContainerSchemaNode) bug1412.getDataChildByName(QName.create(
bug1412.getQNameModule(), "node"));
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
public void test() throws Exception {
- Set<Module> modules = TestUtils.loadModules(getClass().getResource("/bugs/bug1413").toURI());
- Module bug1413 = TestUtils.findModule(modules, "bug1413");
+ final Module bug1413 = TestUtils.findModule(
+ TestUtils.loadModules(getClass().getResource("/bugs/bug1413").toURI()), "bug1413").get();
assertNotNull(bug1413);
List<ExtensionDefinition> extensions = bug1413.getExtensionSchemaNodes();
import static org.junit.Assert.assertNotNull;
-import java.util.Set;
import org.junit.Test;
import org.opendaylight.yangtools.yang.model.api.Module;
public class Bug3859Test {
-
@Test
public void test() throws Exception {
- Set<Module> modules = TestUtils.loadModules(getClass().getResource("/bugs/bug3859").toURI());
- Module bug3859 = TestUtils.findModule(modules, "reference-in-unknown");
+ final Module bug3859 = TestUtils.findModule(
+ TestUtils.loadModules(getClass().getResource("/bugs/bug3859").toURI()), "reference-in-unknown").get();
assertNotNull(bug3859);
}
-
}
import static org.junit.Assert.assertTrue;
import java.util.List;
-import java.util.Set;
import org.junit.Test;
import org.opendaylight.yangtools.yang.common.QName;
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.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
/**
@Test
public void testParseList() throws Exception {
- final Set<Module> modules = TestUtils.loadModules(getClass().getResource("/bugs/bug394-retest").toURI());
- final Module bug394 = TestUtils.findModule(modules, "bug394");
- assertNotNull(bug394);
- final Module bug394_ext = TestUtils.findModule(modules, "bug394-ext");
- assertNotNull(bug394_ext);
+ final SchemaContext context = TestUtils.loadModules(getClass().getResource("/bugs/bug394-retest").toURI());
+ final Module bug394 = TestUtils.findModule(context, "bug394").get();
+ final Module bug394_ext = TestUtils.findModule(context, "bug394-ext").get();
final ContainerSchemaNode logrecords = (ContainerSchemaNode) bug394.getDataChildByName(QName.create(
bug394.getQNameModule(), "logrecords"));
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
-import java.io.File;
-import java.io.FileNotFoundException;
+import java.io.IOException;
import org.junit.Before;
import org.junit.Test;
import org.opendaylight.yangtools.yang.model.api.Module;
+import org.opendaylight.yangtools.yang.model.repo.api.YinTextSchemaSource;
import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
-import org.opendaylight.yangtools.yang.parser.util.NamedFileInputStream;
+import org.xml.sax.SAXException;
public class Bug5693Test {
- private final String pathToModuleFoo = getClass().getResource("/bugs/bug5693/foo.yin").getPath();
private Module foo;
/**
* Use input stream to load Yin module.
*/
@Before
- public void initTest() throws FileNotFoundException, ReactorException {
- foo = TestUtils.loadYinModule(new NamedFileInputStream(new File(pathToModuleFoo), pathToModuleFoo));
- assertNotNull(foo);
+ public void initTest() throws ReactorException, SAXException, IOException {
+ foo = TestUtils.loadYinModule(YinTextSchemaSource.forResource(getClass(), "/bugs/bug5693/foo.yin"));
}
/**
import java.net.URI;
import java.net.URISyntaxException;
import java.text.ParseException;
-import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Set;
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.parser.api.YangSyntaxErrorException;
import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
+import org.opendaylight.yangtools.yang.parser.rfc6020.repo.YangStatementStreamSource;
import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
import org.opendaylight.yangtools.yang.parser.stmt.reactor.EffectiveSchemaContext;
public class EffectiveSchemaContextTest {
@Test
- public void testEffectiveSchemaContext() throws ReactorException, ParseException, URISyntaxException, IOException {
+ public void testEffectiveSchemaContext() throws ReactorException, ParseException, URISyntaxException, IOException,
+ YangSyntaxErrorException {
final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
- final YangTextSchemaSource source1 = YangTextSchemaSource.forResource(
- "/effective-schema-context-test/foo.yang");
- final YangTextSchemaSource source2 = YangTextSchemaSource.forResource(
- "/effective-schema-context-test/bar.yang");
- final YangTextSchemaSource source3 = YangTextSchemaSource.forResource(
- "/effective-schema-context-test/baz.yang");
+ final YangStatementStreamSource source1 = YangStatementStreamSource.create(YangTextSchemaSource.forResource(
+ "/effective-schema-context-test/foo.yang"));
+ final YangStatementStreamSource source2 = YangStatementStreamSource.create(YangTextSchemaSource.forResource(
+ "/effective-schema-context-test/bar.yang"));
+ final YangStatementStreamSource source3 = YangStatementStreamSource.create(YangTextSchemaSource.forResource(
+ "/effective-schema-context-test/baz.yang"));
- final SchemaContext schemaContext = reactor.buildEffective(Arrays.asList(source1, source2, source3));
+ reactor.addSources(source1, source2, source3);
+ final SchemaContext schemaContext = reactor.buildEffective();
assertNotNull(schemaContext);
final Set<DataSchemaNode> dataDefinitions = schemaContext.getDataDefinitions();
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
+import java.io.IOException;
import java.net.URI;
import java.text.ParseException;
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.common.QName;
-import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
+import org.opendaylight.yangtools.yang.common.QNameModule;
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.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.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.YangSyntaxErrorException;
import org.opendaylight.yangtools.yang.model.util.SchemaNodeUtils;
import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
public class GroupingTest {
- private Set<Module> modules;
+ private SchemaContext ctx;
+ private Module foo;
+ private Module baz;
@Before
public void init() throws Exception {
- modules = TestUtils.loadModules(getClass().getResource("/model").toURI());
- assertEquals(3, modules.size());
+ ctx = TestUtils.loadModules(getClass().getResource("/model").toURI());
+ foo = TestUtils.findModule(ctx, "foo").get();
+ baz = TestUtils.findModule(ctx, "baz").get();
+ assertEquals(3, ctx.getModules().size());
}
@Test
public void testRefine() {
- final Module testModule = TestUtils.findModule(modules, "foo");
+ final Module testModule = TestUtils.findModule(ctx, "foo").get();
final ContainerSchemaNode peer = (ContainerSchemaNode) testModule.getDataChildByName(QName.create(
testModule.getQNameModule(), "peer"));
final ContainerSchemaNode destination = (ContainerSchemaNode) peer.getDataChildByName(QName.create(
@Test
public void testGrouping() {
- final Module testModule = TestUtils.findModule(modules, "baz");
+ final Module testModule = TestUtils.findModule(ctx, "baz").get();
final Set<GroupingDefinition> groupings = testModule.getGroupings();
assertEquals(1, groupings.size());
final GroupingDefinition grouping = groupings.iterator().next();
// suffix _u = added by uses
// suffix _g = defined in grouping
- final Module baz = TestUtils.findModule(modules, "baz");
// get grouping
final Set<GroupingDefinition> groupings = baz.getGroupings();
assertEquals(1, groupings.size());
final GroupingDefinition grouping = groupings.iterator().next();
- final Module foo = TestUtils.findModule(modules, "foo");
-
// get node containing uses
final ContainerSchemaNode peer = (ContainerSchemaNode) foo.getDataChildByName(QName.create(
foo.getQNameModule(), "peer"));
// suffix _u = added by uses
// suffix _g = defined in grouping
- final Module testModule = TestUtils.findModule(modules, "baz");
-
// get grouping
- final Set<GroupingDefinition> groupings = testModule.getGroupings();
+ final Set<GroupingDefinition> groupings = baz.getGroupings();
assertEquals(1, groupings.size());
final GroupingDefinition grouping = groupings.iterator().next();
- // get node containing uses
- final Module foo = TestUtils.findModule(modules, "foo");
-
// check uses
final Set<UsesNode> uses = foo.getUses();
assertEquals(1, uses.size());
assertTrue(data_u.isAddedByUses());
final AnyXmlSchemaNode data_g = (AnyXmlSchemaNode) grouping.getDataChildByName(QName.create(
- testModule.getQNameModule(), "data"));
+ baz.getQNameModule(), "data"));
assertNotNull(data_g);
assertFalse(data_g.isAddedByUses());
assertFalse(data_u.equals(data_g));
assertFalse(intervalLeaf.isAugmenting());
final ChoiceSchemaNode how_g = (ChoiceSchemaNode) grouping.getDataChildByName(QName.create(
- testModule.getQNameModule(), "how"));
+ baz.getQNameModule(), "how"));
assertNotNull(how_g);
TestUtils.checkIsAddedByUses(how_g, false);
assertFalse(how_u.equals(how_g));
assertTrue(address_u.isAddedByUses());
final LeafSchemaNode address_g = (LeafSchemaNode) grouping.getDataChildByName(QName.create(
- testModule.getQNameModule(), "address"));
+ baz.getQNameModule(), "address"));
assertNotNull(address_g);
assertFalse(address_g.isAddedByUses());
assertNull(address_g.getDefault());
TestUtils.checkIsAddedByUses(port_u, true);
final ContainerSchemaNode port_g = (ContainerSchemaNode) grouping.getDataChildByName(QName.create(
- testModule.getQNameModule(), "port"));
+ baz.getQNameModule(), "port"));
assertNotNull(port_g);
TestUtils.checkIsAddedByUses(port_g, false);
assertFalse(port_u.equals(port_g));
TestUtils.checkIsAddedByUses(addresses_u, true);
final ListSchemaNode addresses_g = (ListSchemaNode) grouping.getDataChildByName(QName.create(
- testModule.getQNameModule(), "addresses"));
+ baz.getQNameModule(), "addresses"));
assertNotNull(addresses_g);
TestUtils.checkIsAddedByUses(addresses_g, false);
assertFalse(addresses_u.equals(addresses_g));
}
@Test
- public void testCascadeUses() throws ReactorException, ParseException {
- modules = TestUtils.loadModules(Collections.singletonList(getClass().getResourceAsStream(
- "/grouping-test/cascade-uses.yang")));
- assertEquals(1, modules.size());
+ public void testCascadeUses() throws ReactorException, ParseException, IOException, YangSyntaxErrorException {
+ ctx = TestUtils.loadModuleResources(getClass(), "/grouping-test/cascade-uses.yang");
+ assertEquals(1, ctx.getModules().size());
- final Module testModule = TestUtils.findModule(modules, "cascade-uses");
+ final Module testModule = TestUtils.findModule(ctx, "cascade-uses").get();
final Set<GroupingDefinition> groupings = testModule.getGroupings();
GroupingDefinition gu = null;
assertNotNull(gz);
assertNotNull(gzz);
- final URI expectedNS = URI.create("urn:grouping:cascade-uses");
- final Date expectedRev = SimpleDateFormatUtil.getRevisionFormat().parse("2013-07-18");
- final String expectedPref = "cu";
+ final QNameModule expectedModule = QNameModule.create(
+ URI.create("urn:grouping:cascade-uses"), QName.parseRevision("2013-07-18"));
SchemaPath expectedPath;
// grouping-U
assertFalse(SchemaNodeUtils.getOriginalIfPossible(leafGroupingU).isPresent());
for (final DataSchemaNode childNode : childNodes) {
- if (!(childNode.getQName().equals(leafGroupingU.getQName()))) {
+ if (!childNode.getQName().equals(leafGroupingU.getQName())) {
TestUtils.checkIsAddedByUses(childNode, true);
}
}
// grouping-V/container-grouping-V
assertNotNull(containerGroupingV);
assertFalse(containerGroupingV.isAddedByUses());
- expectedPath = TestUtils.createPath(true, expectedNS, expectedRev, expectedPref, "grouping-V",
- "container-grouping-V");
+ expectedPath = TestUtils.createPath(true, expectedModule, "grouping-V", "container-grouping-V");
assertEquals(expectedPath, containerGroupingV.getPath());
childNodes = containerGroupingV.getChildNodes();
assertEquals(2, childNodes.size());
final LeafSchemaNode leafXinContainerV = (LeafSchemaNode) containerGroupingV.getDataChildByName(QName.create(
testModule.getQNameModule(), "leaf-grouping-X"));
assertNotNull(leafXinContainerV);
- expectedPath = TestUtils.createPath(true, expectedNS, expectedRev, expectedPref, "grouping-V",
- "container-grouping-V", "leaf-grouping-X");
+ expectedPath = TestUtils.createPath(true, expectedModule, "grouping-V", "container-grouping-V",
+ "leaf-grouping-X");
assertEquals(expectedPath, leafXinContainerV.getPath());
// grouping-V/container-grouping-V/leaf-grouping-Y
final LeafSchemaNode leafYinContainerV = (LeafSchemaNode) containerGroupingV.getDataChildByName(QName.create(
testModule.getQNameModule(), "leaf-grouping-Y"));
assertNotNull(leafYinContainerV);
- expectedPath = TestUtils.createPath(true, expectedNS, expectedRev, expectedPref, "grouping-V",
- "container-grouping-V", "leaf-grouping-Y");
+ expectedPath = TestUtils.createPath(true, expectedModule, "grouping-V", "container-grouping-V",
+ "leaf-grouping-Y");
assertEquals(expectedPath, leafYinContainerV.getPath());
// grouping-X
testModule.getQNameModule(), "leaf-grouping-X"));
assertNotNull(leafXinGX);
assertFalse(leafXinGX.isAddedByUses());
- expectedPath = TestUtils.createPath(true, expectedNS, expectedRev, expectedPref, "grouping-X",
- "leaf-grouping-X");
+ expectedPath = TestUtils.createPath(true, expectedModule, "grouping-X", "leaf-grouping-X");
assertEquals(expectedPath, leafXinGX.getPath());
// grouping-X/leaf-grouping-Y
testModule.getQNameModule(), "leaf-grouping-Y"));
assertNotNull(leafYinGX);
assertTrue(leafYinGX.isAddedByUses());
- expectedPath = TestUtils.createPath(true, expectedNS, expectedRev, expectedPref, "grouping-X",
- "leaf-grouping-Y");
+ expectedPath = TestUtils.createPath(true, expectedModule, "grouping-X", "leaf-grouping-Y");
assertEquals(expectedPath, leafYinGX.getPath());
// grouping-Y
testModule.getQNameModule(), "leaf-grouping-Y"));
assertNotNull(leafYinGY);
assertFalse(leafYinGY.isAddedByUses());
- expectedPath = TestUtils.createPath(true, expectedNS, expectedRev, expectedPref, "grouping-Y",
- "leaf-grouping-Y");
+ expectedPath = TestUtils.createPath(true, expectedModule, "grouping-Y", "leaf-grouping-Y");
assertEquals(expectedPath, leafYinGY.getPath());
// grouping-Z
testModule.getQNameModule(), "leaf-grouping-Z"));
assertNotNull(leafZinGZ);
assertFalse(leafZinGZ.isAddedByUses());
- expectedPath = TestUtils.createPath(true, expectedNS, expectedRev, expectedPref, "grouping-Z",
- "leaf-grouping-Z");
+ expectedPath = TestUtils.createPath(true, expectedModule, "grouping-Z", "leaf-grouping-Z");
assertEquals(expectedPath, leafZinGZ.getPath());
// grouping-ZZ
testModule.getQNameModule(), "leaf-grouping-ZZ"));
assertNotNull(leafZZinGZZ);
assertFalse(leafZZinGZZ.isAddedByUses());
- expectedPath = TestUtils.createPath(true, expectedNS, expectedRev, expectedPref, "grouping-ZZ",
- "leaf-grouping-ZZ");
+ expectedPath = TestUtils.createPath(true, expectedModule, "grouping-ZZ", "leaf-grouping-ZZ");
assertEquals(expectedPath, leafZZinGZZ.getPath());
// TEST getOriginal from grouping-U
@Test
public void testAddedByUsesLeafTypeQName() throws Exception {
-
- final Set<Module> loadModules = TestUtils.loadModules(getClass().getResource("/added-by-uses-leaf-test")
+ final SchemaContext loadModules = TestUtils.loadModules(getClass().getResource("/added-by-uses-leaf-test")
.toURI());
-
- assertEquals(2, loadModules.size());
-
- Module foo = null;
- Module imp = null;
- for (final Module module : loadModules) {
- if (module.getName().equals("foo")) {
- foo = module;
- }
- if (module.getName().equals("import-module")) {
- imp = module;
- }
- }
-
- assertNotNull(foo);
- assertNotNull(imp);
+ assertEquals(2, loadModules.getModules().size());
+ foo = TestUtils.findModule(loadModules, "foo").get();
+ final Module imp = TestUtils.findModule(loadModules, "import-module").get();
final LeafSchemaNode leaf = (LeafSchemaNode) ((ContainerSchemaNode) foo.getDataChildByName(QName.create(
foo.getQNameModule(), "my-container")))
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.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.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
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.parser.api.YangSyntaxErrorException;
+import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
public class OrderingTest {
+ private SchemaContext context;
+ private Module foo;
+ private Module bar;
+ private Module baz;
+
+ @Before
+ public void setup() throws ReactorException, IOException, YangSyntaxErrorException, URISyntaxException {
+ context = TestUtils.loadModules(getClass().getResource("/model").toURI());
+ foo = TestUtils.findModule(context, "foo").get();
+ bar = TestUtils.findModule(context, "bar").get();
+ baz = TestUtils.findModule(context, "baz").get();
+ }
+
@Test
public void testOrderingTypedef() throws Exception {
- final Set<Module> modules = TestUtils.loadModules(getClass().getResource("/model").toURI());
- final Module bar = TestUtils.findModule(modules, "bar");
final Set<TypeDefinition<?>> typedefs = bar.getTypeDefinitions();
final String[] expectedOrder = new String[] { "int32-ext1", "int32-ext2",
"string-ext1", "string-ext2", "string-ext3", "string-ext4",
@Test
public void testOrderingChildNodes() throws Exception {
- final Set<Module> modules = TestUtils.loadModules(getClass().getResource("/model").toURI());
- final Module foo = TestUtils.findModule(modules, "foo");
AugmentationSchema augment1 = null;
for (final AugmentationSchema as : foo.getAugmentations()) {
if (as.getChildNodes().size() == 5) {
@Test
public void testOrderingNestedChildNodes1() throws Exception {
- final Set<Module> modules = TestUtils.loadModules(getClass().getResource("/model").toURI());
- final Module foo = TestUtils.findModule(modules, "foo");
-
final Collection<DataSchemaNode> childNodes = foo.getChildNodes();
final String[] expectedOrder = new String[] { "int32-leaf", "string-leaf",
"invalid-pattern-string-leaf",
@Test
public void testOrderingNestedChildNodes2() throws Exception {
- final Set<Module> modules = TestUtils.loadModules(getClass().getResource("/model").toURI());
- final Module baz = TestUtils.findModule(modules, "baz");
final Set<GroupingDefinition> groupings = baz.getGroupings();
assertEquals(1, groupings.size());
final GroupingDefinition target = groupings.iterator().next();
@Test
public void testOrderingNestedChildNodes3() throws Exception {
- final Module baz = TestUtils.loadModule(getClass().getResourceAsStream(
- "/ordering/foo.yang"));
+ final Module baz = TestUtils.loadModuleResources(getClass(), "/ordering/foo.yang")
+ .getModules().iterator().next();
final ContainerSchemaNode x = (ContainerSchemaNode) baz
.getDataChildByName(QName.create(baz.getQNameModule(), "x"));
final Collection<DataSchemaNode> childNodes = x.getChildNodes();
}
assertArrayEquals(expectedOrder, actualOrder);
}
-
}
package org.opendaylight.yangtools.yang.stmt;
+import com.google.common.io.Files;
import java.io.File;
import java.io.FileFilter;
-import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import org.opendaylight.yangtools.yang.model.api.ModuleImport;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
+import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
import org.opendaylight.yangtools.yang.model.repo.api.StatementParserMode;
import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
+import org.opendaylight.yangtools.yang.model.repo.api.YinTextSchemaSource;
import org.opendaylight.yangtools.yang.parser.rfc6020.repo.YangStatementStreamSource;
+import org.opendaylight.yangtools.yang.parser.rfc6020.repo.YinStatementStreamSource;
+import org.opendaylight.yangtools.yang.parser.rfc6020.repo.YinTextToDomTransformer;
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.YinStatementSourceImpl;
-import org.opendaylight.yangtools.yang.parser.util.NamedFileInputStream;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.xml.sax.SAXException;
public class StmtTestUtils {
}
public static SchemaContext parseYinSources(final String yinSourcesDirectoryPath, final StatementParserMode statementParserMode)
- throws SourceException, ReactorException, FileNotFoundException, URISyntaxException {
-
+ throws URISyntaxException, SAXException, IOException, ReactorException {
final URL resourceDir = StmtTestUtils.class.getResource(yinSourcesDirectoryPath);
- final File testSourcesDir = new File(resourceDir.toURI());
-
- return parseYinSources(statementParserMode, testSourcesDir.listFiles(YIN_FILE_FILTER));
- }
-
- public static SchemaContext parseYinSources(final StatementParserMode statementParserMode, final File... files)
- throws SourceException, ReactorException, FileNotFoundException {
-
+ final File[] files = new File(resourceDir.toURI()).listFiles(YIN_FILE_FILTER);
final StatementStreamSource[] sources = new StatementStreamSource[files.length];
-
for (int i = 0; i < files.length; i++) {
- sources[i] = new YinStatementSourceImpl(new NamedFileInputStream(files[i], files[i].getPath()));
+ final SourceIdentifier identifier = YinTextSchemaSource.identifierFromFilename(files[i].getName());
+
+ sources[i] = YinStatementStreamSource.create(YinTextToDomTransformer.transformSource(
+ YinTextSchemaSource.delegateForByteSource(identifier, Files.asByteSource(files[i]))));
}
return parseYinSources(statementParserMode, sources);
}
public static SchemaContext parseYinSources(final StatementParserMode statementParserMode, final StatementStreamSource... sources)
- throws SourceException, ReactorException {
+ throws ReactorException {
final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild(statementParserMode);
reactor.addSources(sources);
@Test
public void noException() throws Exception {
- final Set<Module> modules = TestUtils.loadModules(getClass().getResource("/augment-test/augment-in-augment")
- .toURI());
- assertNotNull(modules);
+ assertNotNull(TestUtils.loadModules(getClass().getResource("/augment-test/augment-in-augment").toURI()));
}
@Test
@Test
public void bug6173Test() throws Exception {
final Set<Module> loadModules = TestUtils.loadModules(getClass().getResource(
- "/substatement-validator/empty-element").toURI());
+ "/substatement-validator/empty-element").toURI()).getModules();
assertEquals(1, loadModules.size());
}
import java.io.File;
import java.io.IOException;
-import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Collection;
import java.util.Date;
import java.util.List;
+import java.util.Optional;
import java.util.Set;
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.common.YangConstants;
import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
+import org.opendaylight.yangtools.yang.model.repo.api.YinTextSchemaSource;
import org.opendaylight.yangtools.yang.parser.rfc6020.repo.YangStatementStreamSource;
+import org.opendaylight.yangtools.yang.parser.rfc6020.repo.YinStatementStreamSource;
+import org.opendaylight.yangtools.yang.parser.rfc6020.repo.YinTextToDomTransformer;
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.reactor.CrossSourceStatementReactor.BuildAction;
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.YinStatementSourceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.xml.sax.SAXException;
public final class TestUtils {
private static final Logger LOG = LoggerFactory.getLogger(TestUtils.class);
private TestUtils() {
}
- public static Set<Module> loadModules(final URI resourceDirectory)
- throws SourceException, ReactorException, IOException, YangSyntaxErrorException {
+ public static SchemaContext loadModules(final URI resourceDirectory)
+ throws ReactorException, IOException, YangSyntaxErrorException {
final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR
.newBuild();
File[] files = new File(resourceDirectory).listFiles();
}
}
- SchemaContext ctx = reactor.buildEffective();
- return ctx.getModules();
+ return reactor.buildEffective();
}
- public static Set<Module> loadModules(final List<InputStream> streams)
- throws SourceException, ReactorException {
- final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR
- .newBuild();
- for (InputStream inputStream : streams) {
- reactor.addSource(new YangStatementSourceImpl(inputStream));
+ public static SchemaContext loadModuleResources(final Class<?> refClass, final String... resourceNames)
+ throws IOException, ReactorException, YangSyntaxErrorException {
+ final BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+
+ for (String resourceName : resourceNames) {
+ reactor.addSource(YangStatementStreamSource.create(YangTextSchemaSource.forResource(refClass, resourceName)));
}
- SchemaContext ctx = reactor.buildEffective();
- return ctx.getModules();
+ return reactor.buildEffective();
}
- public static Set<Module> loadYinModules(final URI resourceDirectory) throws ReactorException {
- final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+ public static SchemaContext loadYinModules(final URI resourceDirectory) throws ReactorException, SAXException,
+ IOException {
+ final BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
for (File file : new File(resourceDirectory).listFiles()) {
- reactor.addSource(new YinStatementSourceImpl(file.getPath(), true));
- }
-
- SchemaContext ctx = reactor.buildEffective();
- return ctx.getModules();
- }
-
- public static Set<Module> loadYinModules(final List<InputStream> streams) throws SourceException, ReactorException {
- final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
- for (InputStream inputStream : streams) {
- reactor.addSource(new YinStatementSourceImpl(inputStream));
+ reactor.addSource(YinStatementStreamSource.create(YinTextToDomTransformer.transformSource(
+ YinTextSchemaSource.forFile(file))));
}
- SchemaContext ctx = reactor.buildEffective();
- return ctx.getModules();
- }
-
- public static Module loadModule(final InputStream stream)
- throws SourceException, ReactorException {
- final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR
- .newBuild();
- reactor.addSource(new YangStatementSourceImpl(stream));
- SchemaContext ctx = reactor.buildEffective();
- return ctx.getModules().iterator().next();
+ return reactor.buildEffective();
}
- public static Module loadYinModule(final InputStream stream) throws SourceException, ReactorException {
+ public static Module loadYinModule(final YinTextSchemaSource source) throws ReactorException, SAXException, IOException {
final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
- reactor.addSources(new YinStatementSourceImpl(stream));
+ reactor.addSources(YinStatementStreamSource.create(YinTextToDomTransformer.transformSource(source)));
SchemaContext ctx = reactor.buildEffective();
return ctx.getModules().iterator().next();
}
- public static Module findModule(final Set<Module> modules,
- final String moduleName) {
- Module result = null;
- for (Module module : modules) {
- if (module.getName().equals(moduleName)) {
- result = module;
- break;
- }
- }
- return result;
+ public static Optional<Module> findModule(final SchemaContext context, final String moduleName) {
+ return context.getModules().stream().filter(module -> moduleName.equals(module.getName())).findAny();
}
- public static ModuleImport findImport(final Set<ModuleImport> imports,
- final String prefix) {
+ public static ModuleImport findImport(final Set<ModuleImport> imports, final String prefix) {
ModuleImport result = null;
for (ModuleImport moduleImport : imports) {
if (moduleImport.getPrefix().equals(prefix)) {
return result;
}
- public static TypeDefinition<?> findTypedef(
- final Set<TypeDefinition<?>> typedefs, final String name) {
+ public static TypeDefinition<?> findTypedef(final Set<TypeDefinition<?>> typedefs, final String name) {
TypeDefinition<?> result = null;
for (TypeDefinition<?> td : typedefs) {
if (td.getQName().getLocalName().equals(name)) {
return result;
}
- public static SchemaPath createPath(final boolean absolute,
- final URI namespace, final Date revision, final String prefix,
- final String... names) {
- List<QName> path = new ArrayList<>();
+ public static SchemaPath createPath(final boolean absolute, final QNameModule module, final String... names) {
+ List<QName> path = new ArrayList<>(names.length);
for (String name : names) {
- path.add(QName.create(namespace, revision, name));
+ path.add(QName.create(module, name));
}
return SchemaPath.create(path, absolute);
}
* @param expected
* expected value
*/
- public static void checkIsAugmenting(final DataSchemaNode node,
- final boolean expected) {
+ public static void checkIsAugmenting(final DataSchemaNode node, final boolean expected) {
assertEquals(expected, node.isAugmenting());
if (node instanceof DataNodeContainer) {
for (DataSchemaNode child : ((DataNodeContainer) node)
* @param expected
* expected value
*/
- public static void checkIsAddedByUses(final DataSchemaNode node,
- final boolean expected) {
+ public static void checkIsAddedByUses(final DataSchemaNode node, final boolean expected) {
assertEquals(expected, node.isAddedByUses());
if (node instanceof DataNodeContainer) {
for (DataSchemaNode child : ((DataNodeContainer) node)
}
}
- public static void checkIsAddedByUses(final GroupingDefinition node,
- final boolean expected) {
+ public static void checkIsAddedByUses(final GroupingDefinition node, final boolean expected) {
assertEquals(expected, node.isAddedByUses());
for (DataSchemaNode child : node.getChildNodes()) {
checkIsAddedByUses(child, expected);
public static SchemaContext parseYangSources(final String yangSourcesDirectoryPath)
throws SourceException, ReactorException, URISyntaxException, IOException, YangSyntaxErrorException {
- URL resourceDir = StmtTestUtils.class
- .getResource(yangSourcesDirectoryPath);
+ URL resourceDir = StmtTestUtils.class.getResource(yangSourcesDirectoryPath);
File testSourcesDir = new File(resourceDir.toURI());
return parseYangSources(testSourcesDir.listFiles());
@Test
public void testTwoRevisions() throws Exception {
- Set<Module> modules = TestUtils.loadModules(getClass().getResource("/ietf").toURI());
+ Set<Module> modules = TestUtils.loadModules(getClass().getResource("/ietf").toURI()).getModules();
//FIXME: following assert needs module revisions .equals() solution first
assertEquals(2, TestUtils.findModules(modules, "network-topology").size());
}
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
public class TypesResolutionTest {
- private Set<Module> testedModules;
+ private SchemaContext context;
@Before
public void init() throws Exception {
final StatementStreamSource yangFileDependency1 = sourceForResource("/ietf/iana-timezones@2012-07-09.yang");
final StatementStreamSource yangFileDependency2 = sourceForResource("/ietf/ietf-inet-types@2010-09-24.yang");
final StatementStreamSource yangFileDependency3 = sourceForResource("/ietf/ietf-yang-types@2010-09-24.yang");
-
- testedModules = TestUtils.parseYangSources(yangFile, yangFileDependency1, yangFileDependency2,
- yangFileDependency3).getModules();
- assertEquals(4, testedModules.size());
+ context = TestUtils.parseYangSources(yangFile, yangFileDependency1, yangFileDependency2, yangFileDependency3);
+ assertEquals(4, context.getModules().size());
}
@Test
public void testIPVersion() {
- Module tested = TestUtils.findModule(testedModules, "ietf-inet-types");
+ Module tested = TestUtils.findModule(context, "ietf-inet-types").get();
Set<TypeDefinition<?>> typedefs = tested.getTypeDefinitions();
assertEquals(14, typedefs.size());
@Test
public void testEnumeration() {
- Module tested = TestUtils.findModule(testedModules, "custom-types-test");
+ Module tested = TestUtils.findModule(context, "custom-types-test").get();
Set<TypeDefinition<?>> typedefs = tested.getTypeDefinitions();
TypeDefinition<?> type = TestUtils.findTypedef(typedefs, "ip-version");
@Test
public void testIpAddress() {
- Module tested = TestUtils.findModule(testedModules, "ietf-inet-types");
+ Module tested = TestUtils.findModule(context, "ietf-inet-types").get();
Set<TypeDefinition<?>> typedefs = tested.getTypeDefinitions();
TypeDefinition<?> type = TestUtils.findTypedef(typedefs, "ip-address");
UnionTypeDefinition baseType = (UnionTypeDefinition) type.getBaseType();
@Test
public void testDomainName() {
- Module tested = TestUtils.findModule(testedModules, "ietf-inet-types");
+ Module tested = TestUtils.findModule(context, "ietf-inet-types").get();
Set<TypeDefinition<?>> typedefs = tested.getTypeDefinitions();
StringTypeDefinition type = (StringTypeDefinition) TestUtils.findTypedef(typedefs, "domain-name");
assertNotNull(type.getBaseType());
@Test
public void testInstanceIdentifier1() {
- Module tested = TestUtils.findModule(testedModules, "custom-types-test");
+ Module tested = TestUtils.findModule(context, "custom-types-test").get();
LeafSchemaNode leaf = (LeafSchemaNode) tested.getDataChildByName(
QName.create(tested.getQNameModule(), "inst-id-leaf1"));
InstanceIdentifierTypeDefinition leafType = (InstanceIdentifierTypeDefinition) leaf.getType();
@Test
public void testInstanceIdentifier2() {
- Module tested = TestUtils.findModule(testedModules, "custom-types-test");
+ Module tested = TestUtils.findModule(context, "custom-types-test").get();
LeafSchemaNode leaf = (LeafSchemaNode) tested.getDataChildByName(
QName.create(tested.getQNameModule(), "inst-id-leaf2"));
InstanceIdentifierTypeDefinition leafType = (InstanceIdentifierTypeDefinition) leaf.getType();
@Test
public void testIdentity() {
- Module tested = TestUtils.findModule(testedModules, "custom-types-test");
+ Module tested = TestUtils.findModule(context, "custom-types-test").get();
Set<IdentitySchemaNode> identities = tested.getIdentities();
assertEquals(5, identities.size());
IdentitySchemaNode cryptoAlg = null;
@Test
public void testBitsType1() {
- Module tested = TestUtils.findModule(testedModules, "custom-types-test");
+ Module tested = TestUtils.findModule(context, "custom-types-test").get();
LeafSchemaNode leaf = (LeafSchemaNode) tested.getDataChildByName(
QName.create(tested.getQNameModule(), "mybits"));
BitsTypeDefinition leafType = (BitsTypeDefinition) leaf.getType();
@Test
public void testBitsType2() {
- Module tested = TestUtils.findModule(testedModules, "custom-types-test");
+ Module tested = TestUtils.findModule(context, "custom-types-test").get();
Set<TypeDefinition<?>> typedefs = tested.getTypeDefinitions();
TypeDefinition<?> testedType = TestUtils.findTypedef(typedefs, "access-operations-type");
@Test
public void testIanaTimezones() {
- Module tested = TestUtils.findModule(testedModules, "iana-timezones");
+ Module tested = TestUtils.findModule(context, "iana-timezones").get();
Set<TypeDefinition<?>> typedefs = tested.getTypeDefinitions();
TypeDefinition<?> testedType = TestUtils.findTypedef(typedefs, "iana-timezone");
@Test
public void testObjectId128() {
- Module tested = TestUtils.findModule(testedModules, "ietf-yang-types");
+ Module tested = TestUtils.findModule(context, "ietf-yang-types").get();
Set<TypeDefinition<?>> typedefs = tested.getTypeDefinitions();
StringTypeDefinition testedType = (StringTypeDefinition) TestUtils.findTypedef(typedefs,
"object-identifier-128");
@Test
public void testIdentityref() {
- Module tested = TestUtils.findModule(testedModules, "custom-types-test");
+ Module tested = TestUtils.findModule(context, "custom-types-test").get();
Set<TypeDefinition<?>> typedefs = tested.getTypeDefinitions();
TypeDefinition<?> testedType = TestUtils.findTypedef(typedefs, "service-type-ref");
IdentityrefTypeDefinition baseType = (IdentityrefTypeDefinition) testedType.getBaseType();
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
-import java.io.FileNotFoundException;
+import java.io.IOException;
import java.net.URI;
-import java.text.DateFormat;
-import java.text.ParseException;
+import java.net.URISyntaxException;
import java.util.ArrayDeque;
import java.util.Collection;
-import java.util.Date;
import java.util.Deque;
import java.util.Set;
import org.junit.Before;
import org.junit.Test;
import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
+import org.opendaylight.yangtools.yang.common.QNameModule;
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.ListSchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.UnsignedIntegerTypeDefinition;
+import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
+import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
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<Module> modules;
+ private static final QNameModule UG = QNameModule.create(
+ URI.create("urn:opendaylight:params:xml:ns:yang:uses-grouping"), QName.parseRevision("2013-07-30"));
+ private static final QNameModule GD = QNameModule.create(
+ URI.create("urn:opendaylight:params:xml:ns:yang:grouping-definitions"), QName.parseRevision("2013-09-04"));
+
+ private SchemaContext context;
@Before
- public void init() throws FileNotFoundException, ParseException {
- final DateFormat simpleDateFormat = SimpleDateFormatUtil.getRevisionFormat();
- UG_REV = simpleDateFormat.parse("2013-07-30");
- GD_REV = simpleDateFormat.parse("2013-09-04");
+ public void init() throws ReactorException, IOException, YangSyntaxErrorException, URISyntaxException {
+ context = TestUtils.loadModules(getClass().getResource("/grouping-test").toURI());
}
/**
*/
@Test
public void testAugmentInUses() throws Exception {
- modules = TestUtils.loadModules(getClass().getResource("/grouping-test").toURI());
- final Module testModule = TestUtils.findModule(modules, "uses-grouping");
+ final Module testModule = TestUtils.findModule(context, "uses-grouping").get();
final Deque<QName> path = new ArrayDeque<>();
assertEquals(1, notifications.size());
final NotificationDefinition pcreq = notifications.iterator().next();
assertNotNull(pcreq);
- QName expectedQName = QName.create(UG_NS, UG_REV, "pcreq");
+ QName expectedQName = QName.create(UG, "pcreq");
path.offer(expectedQName);
SchemaPath expectedPath = SchemaPath.create(path, true);
assertEquals(expectedPath, pcreq.getPath());
LeafSchemaNode version = (LeafSchemaNode) pcreq.getDataChildByName(QName.create(testModule.getQNameModule(),
"version"));
assertNotNull(version);
- expectedQName = QName.create(UG_NS, UG_REV, "version");
+ expectedQName = QName.create(UG, "version");
path.offer(expectedQName);
expectedPath = SchemaPath.create(path, true);
assertEquals(expectedPath, version.getPath());
- expectedQName = QName.create(UG_NS, UG_REV, "version");
+ expectedQName = QName.create(UG, "version");
path.offer(expectedQName);
expectedPath = SchemaPath.create(true, pcreq.getQName(), expectedQName);
assertEquals(expectedPath, version.getType().getPath());
LeafSchemaNode type = (LeafSchemaNode) pcreq.getDataChildByName(QName.create(testModule.getQNameModule(),
"type"));
assertNotNull(type);
- expectedQName = QName.create(UG_NS, UG_REV, "type");
+ expectedQName = QName.create(UG, "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");
+ expectedQName = QName.create(GD, "int-ext");
path.offer(expectedQName);
expectedPath = SchemaPath.create(true, expectedQName);
assertEquals(expectedPath, type.getType().getPath());
final ListSchemaNode requests = (ListSchemaNode) pcreq.getDataChildByName(QName.create(
testModule.getQNameModule(), "requests"));
assertNotNull(requests);
- expectedQName = QName.create(UG_NS, UG_REV, "requests");
+ expectedQName = QName.create(UG, "requests");
assertEquals(expectedQName, requests.getQName());
path.pollLast();
path.pollLast();
final ContainerSchemaNode rp = (ContainerSchemaNode) requests.getDataChildByName(QName.create(
testModule.getQNameModule(), "rp"));
assertNotNull(rp);
- expectedQName = QName.create(UG_NS, UG_REV, "rp");
+ expectedQName = QName.create(UG, "rp");
path.offer(expectedQName);
expectedPath = SchemaPath.create(path, true);
assertEquals(expectedPath, rp.getPath());
LeafSchemaNode processingRule = (LeafSchemaNode) rp.getDataChildByName(QName.create(
testModule.getQNameModule(), "processing-rule"));
assertNotNull(processingRule);
- expectedQName = QName.create(UG_NS, UG_REV, "processing-rule");
+ expectedQName = QName.create(UG, "processing-rule");
assertEquals(expectedQName, processingRule.getQName());
path.offer(expectedQName);
expectedPath = SchemaPath.create(path, true);
LeafSchemaNode ignore = (LeafSchemaNode) rp.getDataChildByName(QName.create(testModule.getQNameModule(),
"ignore"));
assertNotNull(ignore);
- expectedQName = QName.create(UG_NS, UG_REV, "ignore");
+ expectedQName = QName.create(UG, "ignore");
assertEquals(expectedQName, ignore.getQName());
path.pollLast();
path.offer(expectedQName);
final LeafSchemaNode priority = (LeafSchemaNode) rp.getDataChildByName(QName.create(
testModule.getQNameModule(), "priority"));
assertNotNull(priority);
- expectedQName = QName.create(UG_NS, UG_REV, "priority");
+ expectedQName = QName.create(UG, "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");
+ expectedQName = QName.create(UG, "uint8");
path.offer(expectedQName);
expectedPath = SchemaPath.create(path, true);
// TODO
ContainerSchemaNode box = (ContainerSchemaNode) rp.getDataChildByName(QName.create(testModule.getQNameModule(),
"box"));
assertNotNull(box);
- expectedQName = QName.create(UG_NS, UG_REV, "box");
+ expectedQName = QName.create(UG, "box");
assertEquals(expectedQName, box.getQName());
path.pollLast();
path.pollLast();
final ContainerSchemaNode order = (ContainerSchemaNode) box.getDataChildByName(QName.create(
testModule.getQNameModule(), "order"));
assertNotNull(order);
- expectedQName = QName.create(UG_NS, UG_REV, "order");
+ expectedQName = QName.create(UG, "order");
assertEquals(expectedQName, order.getQName());
path.offer(expectedQName);
expectedPath = SchemaPath.create(path, true);
final LeafSchemaNode delete = (LeafSchemaNode) order.getDataChildByName(QName.create(
testModule.getQNameModule(), "delete"));
assertNotNull(delete);
- expectedQName = QName.create(UG_NS, UG_REV, "delete");
+ expectedQName = QName.create(UG, "delete");
assertEquals(expectedQName, delete.getQName());
path.offer(expectedQName);
expectedPath = SchemaPath.create(path, true);
final LeafSchemaNode setup = (LeafSchemaNode) order.getDataChildByName(QName.create(
testModule.getQNameModule(), "setup"));
assertNotNull(setup);
- expectedQName = QName.create(UG_NS, UG_REV, "setup");
+ expectedQName = QName.create(UG, "setup");
assertEquals(expectedQName, setup.getQName());
path.pollLast();
path.offer(expectedQName);
final ContainerSchemaNode pke = (ContainerSchemaNode) requests.getDataChildByName(QName.create(
testModule.getQNameModule(), "path-key-expansion"));
assertNotNull(pke);
- expectedQName = QName.create(UG_NS, UG_REV, "path-key-expansion");
+ expectedQName = QName.create(UG, "path-key-expansion");
assertEquals(expectedQName, pke.getQName());
path.pollLast();
path.pollLast();
final ContainerSchemaNode pathKey = (ContainerSchemaNode) pke.getDataChildByName(QName.create(
testModule.getQNameModule(), "path-key"));
assertNotNull(pathKey);
- expectedQName = QName.create(UG_NS, UG_REV, "path-key");
+ expectedQName = QName.create(UG, "path-key");
assertEquals(expectedQName, pathKey.getQName());
path.offer(expectedQName);
expectedPath = SchemaPath.create(path, true);
processingRule = (LeafSchemaNode) pathKey.getDataChildByName(QName.create(testModule.getQNameModule(),
"processing-rule"));
assertNotNull(processingRule);
- expectedQName = QName.create(UG_NS, UG_REV, "processing-rule");
+ expectedQName = QName.create(UG, "processing-rule");
assertEquals(expectedQName, processingRule.getQName());
path.offer(expectedQName);
expectedPath = SchemaPath.create(path, true);
// * |-- |-- |-- |-- leaf ignore
ignore = (LeafSchemaNode) pathKey.getDataChildByName(QName.create(testModule.getQNameModule(), "ignore"));
assertNotNull(ignore);
- expectedQName = QName.create(UG_NS, UG_REV, "ignore");
+ expectedQName = QName.create(UG, "ignore");
assertEquals(expectedQName, ignore.getQName());
path.pollLast();
path.offer(expectedQName);
final ListSchemaNode pathKeys = (ListSchemaNode) pathKey.getDataChildByName(QName.create(
testModule.getQNameModule(), "path-keys"));
assertNotNull(pathKeys);
- expectedQName = QName.create(UG_NS, UG_REV, "path-keys");
+ expectedQName = QName.create(UG, "path-keys");
assertEquals(expectedQName, pathKeys.getQName());
path.pollLast();
path.offer(expectedQName);
// * |-- |-- |-- |-- |-- leaf version
version = (LeafSchemaNode) pathKeys.getDataChildByName(QName.create(testModule.getQNameModule(), "version"));
assertNotNull(version);
- expectedQName = QName.create(UG_NS, UG_REV, "version");
+ expectedQName = QName.create(UG, "version");
assertEquals(expectedQName, version.getQName());
path.offer(expectedQName);
expectedPath = SchemaPath.create(path, true);
// * |-- |-- |-- |-- |-- leaf type
type = (LeafSchemaNode) pathKeys.getDataChildByName(QName.create(testModule.getQNameModule(), "type"));
assertNotNull(type);
- expectedQName = QName.create(UG_NS, UG_REV, "type");
+ expectedQName = QName.create(UG, "type");
assertEquals(expectedQName, type.getQName());
path.pollLast();
path.offer(expectedQName);
final ContainerSchemaNode sc = (ContainerSchemaNode) requests.getDataChildByName(QName.create(
testModule.getQNameModule(), "segment-computation"));
assertNotNull(sc);
- expectedQName = QName.create(UG_NS, UG_REV, "segment-computation");
+ expectedQName = QName.create(UG, "segment-computation");
assertEquals(expectedQName, sc.getQName());
path.pollLast();
path.pollLast();
final ContainerSchemaNode p2p = (ContainerSchemaNode) sc.getDataChildByName(QName.create(
testModule.getQNameModule(), "p2p"));
assertNotNull(p2p);
- expectedQName = QName.create(UG_NS, UG_REV, "p2p");
+ expectedQName = QName.create(UG, "p2p");
assertEquals(expectedQName, p2p.getQName());
path.offer(expectedQName);
expectedPath = SchemaPath.create(path, true);
final ContainerSchemaNode endpoints = (ContainerSchemaNode) p2p.getDataChildByName(QName.create(
testModule.getQNameModule(), "endpoints"));
assertNotNull(endpoints);
- expectedQName = QName.create(UG_NS, UG_REV, "endpoints");
+ expectedQName = QName.create(UG, "endpoints");
assertEquals(expectedQName, endpoints.getQName());
path.offer(expectedQName);
expectedPath = SchemaPath.create(path, true);
processingRule = (LeafSchemaNode) endpoints.getDataChildByName(QName.create(testModule.getQNameModule(),
"processing-rule"));
assertNotNull(processingRule);
- expectedQName = QName.create(UG_NS, UG_REV, "processing-rule");
+ expectedQName = QName.create(UG, "processing-rule");
assertEquals(expectedQName, processingRule.getQName());
path.offer(expectedQName);
expectedPath = SchemaPath.create(path, true);
// * |-- |-- |-- |-- |-- leaf ignore
ignore = (LeafSchemaNode) endpoints.getDataChildByName(QName.create(testModule.getQNameModule(), "ignore"));
assertNotNull(ignore);
- expectedQName = QName.create(UG_NS, UG_REV, "ignore");
+ expectedQName = QName.create(UG, "ignore");
assertEquals(expectedQName, ignore.getQName());
path.pollLast();
path.offer(expectedQName);
// * |-- |-- |-- |-- |-- container box
box = (ContainerSchemaNode) endpoints.getDataChildByName(QName.create(testModule.getQNameModule(), "box"));
assertNotNull(box);
- expectedQName = QName.create(UG_NS, UG_REV, "box");
+ expectedQName = QName.create(UG, "box");
assertEquals(expectedQName, box.getQName());
path.pollLast();
path.offer(expectedQName);
final ChoiceSchemaNode af = (ChoiceSchemaNode) endpoints.getDataChildByName(QName.create(
testModule.getQNameModule(), "address-family"));
assertNotNull(af);
- expectedQName = QName.create(UG_NS, UG_REV, "address-family");
+ expectedQName = QName.create(UG, "address-family");
assertEquals(expectedQName, af.getQName());
path.pollLast();
path.offer(expectedQName);
final ContainerSchemaNode reportedRoute = (ContainerSchemaNode) p2p.getDataChildByName(QName.create(
testModule.getQNameModule(), "reported-route"));
assertNotNull(reportedRoute);
- expectedQName = QName.create(UG_NS, UG_REV, "reported-route");
+ expectedQName = QName.create(UG, "reported-route");
assertEquals(expectedQName, reportedRoute.getQName());
path.pollLast();
path.pollLast();
processingRule = (LeafSchemaNode) reportedRoute.getDataChildByName(QName.create(testModule.getQNameModule(),
"processing-rule"));
assertNotNull(processingRule);
- expectedQName = QName.create(UG_NS, UG_REV, "processing-rule");
+ expectedQName = QName.create(UG, "processing-rule");
assertEquals(expectedQName, processingRule.getQName());
path.offer(expectedQName);
expectedPath = SchemaPath.create(path, true);
// * |-- |-- |-- |-- |-- leaf ignore
ignore = (LeafSchemaNode) reportedRoute.getDataChildByName(QName.create(testModule.getQNameModule(), "ignore"));
assertNotNull(ignore);
- expectedQName = QName.create(UG_NS, UG_REV, "ignore");
+ expectedQName = QName.create(UG, "ignore");
assertEquals(expectedQName, ignore.getQName());
path.pollLast();
path.offer(expectedQName);
final ListSchemaNode subobjects = (ListSchemaNode) reportedRoute.getDataChildByName(QName.create(
testModule.getQNameModule(), "subobjects"));
assertNotNull(subobjects);
- expectedQName = QName.create(UG_NS, UG_REV, "subobjects");
+ expectedQName = QName.create(UG, "subobjects");
assertEquals(expectedQName, subobjects.getQName());
path.pollLast();
path.offer(expectedQName);
ContainerSchemaNode bandwidth = (ContainerSchemaNode) reportedRoute.getDataChildByName(QName.create(
testModule.getQNameModule(), "bandwidth"));
assertNotNull(bandwidth);
- expectedQName = QName.create(UG_NS, UG_REV, "bandwidth");
+ expectedQName = QName.create(UG, "bandwidth");
assertEquals(expectedQName, bandwidth.getQName());
path.pollLast();
path.offer(expectedQName);
bandwidth = (ContainerSchemaNode) p2p
.getDataChildByName(QName.create(testModule.getQNameModule(), "bandwidth"));
assertNotNull(bandwidth);
- expectedQName = QName.create(UG_NS, UG_REV, "bandwidth");
+ expectedQName = QName.create(UG, "bandwidth");
assertEquals(expectedQName, bandwidth.getQName());
path.pollLast();
path.pollLast();
processingRule = (LeafSchemaNode) bandwidth.getDataChildByName(QName.create(testModule.getQNameModule(),
"processing-rule"));
assertNotNull(processingRule);
- expectedQName = QName.create(UG_NS, UG_REV, "processing-rule");
+ expectedQName = QName.create(UG, "processing-rule");
assertEquals(expectedQName, processingRule.getQName());
path.offer(expectedQName);
expectedPath = SchemaPath.create(path, true);
// * |-- |-- |-- |-- |-- leaf ignore
ignore = (LeafSchemaNode) bandwidth.getDataChildByName(QName.create(testModule.getQNameModule(), "ignore"));
assertNotNull(ignore);
- expectedQName = QName.create(UG_NS, UG_REV, "ignore");
+ expectedQName = QName.create(UG, "ignore");
assertEquals(expectedQName, ignore.getQName());
path.pollLast();
path.offer(expectedQName);
final ContainerSchemaNode bandwidthInner = (ContainerSchemaNode) bandwidth.getDataChildByName(QName.create(
testModule.getQNameModule(), "bandwidth"));
assertNotNull(bandwidthInner);
- expectedQName = QName.create(UG_NS, UG_REV, "bandwidth");
+ expectedQName = QName.create(UG, "bandwidth");
assertEquals(expectedQName, bandwidth.getQName());
path.pollLast();
path.offer(expectedQName);
final ListSchemaNode svec = (ListSchemaNode) pcreq.getDataChildByName(QName.create(testModule.getQNameModule(),
"svec"));
assertNotNull(svec);
- expectedQName = QName.create(UG_NS, UG_REV, "svec");
+ expectedQName = QName.create(UG, "svec");
assertEquals(expectedQName, svec.getQName());
path.pollLast();
path.pollLast();
final LeafSchemaNode linkDiverse = (LeafSchemaNode) svec.getDataChildByName(QName.create(
testModule.getQNameModule(), "link-diverse"));
assertNotNull(linkDiverse);
- expectedQName = QName.create(UG_NS, UG_REV, "link-diverse");
+ expectedQName = QName.create(UG, "link-diverse");
assertEquals(expectedQName, linkDiverse.getQName());
path.offer(expectedQName);
expectedPath = SchemaPath.create(path, true);
processingRule = (LeafSchemaNode) svec.getDataChildByName(QName.create(testModule.getQNameModule(),
"processing-rule"));
assertNotNull(processingRule);
- expectedQName = QName.create(UG_NS, UG_REV, "processing-rule");
+ expectedQName = QName.create(UG, "processing-rule");
assertEquals(expectedQName, processingRule.getQName());
path.pollLast();
path.offer(expectedQName);
// * |-- |-- leaf ignore
ignore = (LeafSchemaNode) svec.getDataChildByName(QName.create(testModule.getQNameModule(), "ignore"));
assertNotNull(ignore);
- expectedQName = QName.create(UG_NS, UG_REV, "ignore");
+ expectedQName = QName.create(UG, "ignore");
assertEquals(expectedQName, ignore.getQName());
path.pollLast();
path.offer(expectedQName);
final ListSchemaNode metric = (ListSchemaNode) svec.getDataChildByName(QName.create(
testModule.getQNameModule(), "metric"));
assertNotNull(metric);
- expectedQName = QName.create(UG_NS, UG_REV, "metric");
+ expectedQName = QName.create(UG, "metric");
assertEquals(expectedQName, metric.getQName());
path.pollLast();
path.offer(expectedQName);
final LeafSchemaNode metricType = (LeafSchemaNode) metric.getDataChildByName(QName.create(
testModule.getQNameModule(), "metric-type"));
assertNotNull(metricType);
- expectedQName = QName.create(UG_NS, UG_REV, "metric-type");
+ expectedQName = QName.create(UG, "metric-type");
assertEquals(expectedQName, metricType.getQName());
path.offer(expectedQName);
expectedPath = SchemaPath.create(path, true);
// * |-- |-- |-- box
box = (ContainerSchemaNode) metric.getDataChildByName(QName.create(testModule.getQNameModule(), "box"));
assertNotNull(box);
- expectedQName = QName.create(UG_NS, UG_REV, "box");
+ expectedQName = QName.create(UG, "box");
assertEquals(expectedQName, box.getQName());
path.pollLast();
path.offer(expectedQName);
processingRule = (LeafSchemaNode) metric.getDataChildByName(QName.create(testModule.getQNameModule(),
"processing-rule"));
assertNotNull(processingRule);
- expectedQName = QName.create(UG_NS, UG_REV, "processing-rule");
+ expectedQName = QName.create(UG, "processing-rule");
assertEquals(expectedQName, processingRule.getQName());
path.pollLast();
path.offer(expectedQName);
// * |-- |-- |-- leaf ignore
ignore = (LeafSchemaNode) metric.getDataChildByName(QName.create(testModule.getQNameModule(), "ignore"));
assertNotNull(ignore);
- expectedQName = QName.create(UG_NS, UG_REV, "ignore");
+ expectedQName = QName.create(UG, "ignore");
assertEquals(expectedQName, ignore.getQName());
path.pollLast();
path.offer(expectedQName);
@Test
public void testTypedefs() throws Exception {
- modules = TestUtils.loadModules(getClass().getResource("/grouping-test").toURI());
- final Module testModule = TestUtils.findModule(modules, "grouping-definitions");
+ final Module testModule = TestUtils.findModule(context, "grouping-definitions").get();
final Set<TypeDefinition<?>> types = testModule.getTypeDefinitions();
TypeDefinition<?> intExt = null;
}
assertNotNull(intExt);
- SchemaPath expectedPath = SchemaPath.create(true, QName.create(GD_NS, GD_REV, "int-ext"));
+ SchemaPath expectedPath = SchemaPath.create(true, QName.create(GD, "int-ext"));
assertEquals(expectedPath, intExt.getPath());
final UnionTypeDefinition union = (UnionTypeDefinition) intExt.getBaseType();
assertNotNull(uint8);
assertNotNull(pv);
- expectedPath = SchemaPath.create(true, QName.create(GD_NS, GD_REV, "int-ext"),
- QName.create(GD_NS, GD_REV, "union"));
+ expectedPath = SchemaPath.create(true, QName.create(GD, "int-ext"), QName.create(GD, "union"));
assertEquals(expectedPath, union.getPath());
}
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.InputStream;
-import java.net.URISyntaxException;
+import java.io.IOException;
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.spi.meta.ReactorException;
import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
-import org.opendaylight.yangtools.yang.parser.util.NamedFileInputStream;
public class YangParserIdentityTest {
// base identity name equals identity name
@Test(expected = SomeModifiersUnresolvedException.class)
- public void testParsingIdentityTestModule() throws URISyntaxException, ReactorException, FileNotFoundException {
- File yang = new File(getClass().getResource("/identity/identitytest.yang").toURI());
- InputStream stream = new NamedFileInputStream(yang, yang.getPath());
+ public void testParsingIdentityTestModule() throws IOException, ReactorException, YangSyntaxErrorException {
try {
- TestUtils.loadModule(stream);
+ TestUtils.loadModuleResources(getClass(), "/identity/identitytest.yang");
} catch (SomeModifiersUnresolvedException e) {
StmtTestUtils.log(e, " ");
throw e;
// same module prefixed base identity name equals identity name
@Test(expected = SomeModifiersUnresolvedException.class)
- public void testParsingPrefixIdentityTestModule() throws URISyntaxException,
- ReactorException, FileNotFoundException {
- File yang = new File(getClass().getResource("/identity/prefixidentitytest.yang").toURI());
- InputStream stream = new NamedFileInputStream(yang, yang.getPath());
+ public void testParsingPrefixIdentityTestModule() throws IOException, ReactorException, YangSyntaxErrorException {
try {
- TestUtils.loadModule(stream);
+ TestUtils.loadModuleResources(getClass(), "/identity/prefixidentitytest.yang");
} catch (SomeModifiersUnresolvedException e) {
StmtTestUtils.log(e, " ");
throw e;
// prefix differs
@Test
public void testParsingImportPrefixIdentityTestModule() throws Exception {
- Set<Module> modules = TestUtils.loadModules(getClass().getResource("/identity/import").toURI());
- Module module = TestUtils.findModule(modules, "prefiximportidentitytest");
+ Module module = TestUtils.findModule(TestUtils.loadModules(getClass().getResource("/identity/import").toURI()),
+ "prefiximportidentitytest").get();
Set<ModuleImport> imports = module.getImports();
assertEquals(imports.size(), 1);
ModuleImport dummy = TestUtils.findImport(imports, "dummy");
*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import com.google.common.base.Throwables;
import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.InputStream;
+import java.io.IOException;
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
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;
public class YangParserNegativeTest {
}
@Test
- public void testInvalidImport() throws Exception {
- final File yang = new File(getClass().getResource("/negative-scenario/testfile1.yang").toURI());
+ public void testInvalidImport() throws IOException, ReactorException, YangSyntaxErrorException {
try {
- try (InputStream stream = new NamedFileInputStream(yang, yang.getPath())) {
- TestUtils.loadModule(stream);
- fail("SomeModifiersUnresolvedException should be thrown");
- }
+ TestUtils.loadModuleResources(getClass(), "/negative-scenario/testfile1.yang");
+ fail("SomeModifiersUnresolvedException should be thrown");
} catch (final SomeModifiersUnresolvedException e) {
final Throwable rootCause = Throwables.getRootCause(e);
assertTrue(rootCause instanceof InferenceException);
}
@Test
- public void testTypeNotFound() throws Exception {
- final File yang = new File(getClass().getResource("/negative-scenario/testfile2.yang").toURI());
+ public void testTypeNotFound() throws IOException, ReactorException, YangSyntaxErrorException {
try {
- try (InputStream stream = new NamedFileInputStream(yang, yang.getPath())) {
- TestUtils.loadModule(stream);
- fail("InferenceException should be thrown");
- }
+ TestUtils.loadModuleResources(getClass(), "/negative-scenario/testfile2.yang");
+ fail("InferenceException should be thrown");
} catch (final SomeModifiersUnresolvedException e) {
final Throwable rootCause = Throwables.getRootCause(e);
assertTrue(rootCause instanceof InferenceException);
}
@Test
- public void testInvalidAugmentTarget() throws Exception {
- final File yang1 = new File(getClass().getResource("/negative-scenario/testfile0.yang").toURI());
- final File yang2 = new File(getClass().getResource("/negative-scenario/testfile3.yang").toURI());
+ public void testInvalidAugmentTarget() throws IOException, ReactorException, YangSyntaxErrorException {
try {
- final List<InputStream> streams = new ArrayList<>(2);
- try (InputStream testFile0 = new NamedFileInputStream(yang1, yang1.getPath())) {
- streams.add(testFile0);
- try (InputStream testFile3 = new NamedFileInputStream(yang2, yang2.getPath())) {
- streams.add(testFile3);
- assertEquals("Expected loaded files count is 2", 2, streams.size());
- TestUtils.loadModules(streams);
- fail("SomeModifiersUnresolvedException should be thrown");
- }
- }
+ TestUtils.loadModuleResources(getClass(),
+ "/negative-scenario/testfile0.yang",
+ "/negative-scenario/testfile3.yang");
+ fail("SomeModifiersUnresolvedException should be thrown");
} catch (final SomeModifiersUnresolvedException e) {
final Throwable rootCause = Throwables.getRootCause(e);
assertTrue(rootCause instanceof InferenceException);
}
@Test
- public void testInvalidRefine() throws Exception {
- final File yang = new File(getClass().getResource("/negative-scenario/testfile4.yang").toURI());
+ public void testInvalidRefine() throws IOException, ReactorException, YangSyntaxErrorException {
try {
- try (InputStream stream = new NamedFileInputStream(yang, yang.getPath())) {
- TestUtils.loadModule(stream);
- fail("SourceException should be thrown");
- }
+ TestUtils.loadModuleResources(getClass(), "/negative-scenario/testfile4.yang");
+ fail("ReactorException should be thrown");
} catch (final ReactorException e) {
assertTrue(e.getCause().getMessage().contains("Error in module 'test4' in the refine of uses " +
"'Relative{path=[(urn:simple.container.demo?revision=1970-01-01)node]}': can not perform refine of 'PRESENCE' for" +
}
@Test
- public void testInvalidLength() throws Exception {
- final File yang = new File(getClass().getResource("/negative-scenario/testfile5.yang").toURI());
+ public void testInvalidLength() throws IOException, YangSyntaxErrorException {
try {
- try (InputStream stream = new NamedFileInputStream(yang, yang.getPath())) {
- TestUtils.loadModule(stream);
- fail("YangParseException should be thrown");
- }
+ TestUtils.loadModuleResources(getClass(), "/negative-scenario/testfile5.yang");
+ fail("ReactorException should be thrown");
} catch (final ReactorException e) {
assertTrue(e.getCause().getMessage().contains("Invalid length constraint: <4, 10>"));
}
}
@Test
- public void testInvalidRange() throws Exception {
- final File yang = new File(getClass().getResource("/negative-scenario/testfile6.yang").toURI());
+ public void testInvalidRange() throws IOException, YangSyntaxErrorException {
try {
- try (InputStream stream = new NamedFileInputStream(yang, yang.getPath())) {
- TestUtils.loadModule(stream);
- fail("Exception should be thrown");
- }
+ TestUtils.loadModuleResources(getClass(), "/negative-scenario/testfile6.yang");
+ fail("ReactorException should be thrown");
} catch (final ReactorException e) {
assertTrue(e.getCause().getMessage().contains("Invalid range constraint: <5, 20>"));
}
}
@Test
- public void testDuplicateContainer() throws Exception {
- final File yang = new File(getClass().getResource("/negative-scenario/duplicity/container.yang").toURI());
+ public void testDuplicateContainer() throws IOException, YangSyntaxErrorException {
try {
- try (InputStream stream = new NamedFileInputStream(yang, yang.getPath())) {
- TestUtils.loadModule(stream);
- fail("SourceException should be thrown");
- }
+ TestUtils.loadModuleResources(getClass(), "/negative-scenario/duplicity/container.yang");
+ fail("SourceException should be thrown");
} catch (final ReactorException e) {
final String expected = "Error in module 'container': cannot add '(urn:simple.container" +
".demo?revision=1970-01-01)foo'. Node name collision: '(urn:simple.container" +
}
@Test
- public void testDuplicateContainerList() throws Exception {
- final File yang = new File(getClass().getResource("/negative-scenario/duplicity/container-list.yang").toURI());
+ public void testDuplicateContainerList() throws IOException, YangSyntaxErrorException {
try {
- try (InputStream stream = new NamedFileInputStream(yang, yang.getPath())) {
- TestUtils.loadModule(stream);
- fail("SourceException should be thrown");
- }
+ TestUtils.loadModuleResources(getClass(), "/negative-scenario/duplicity/container-list.yang");
+ fail("SourceException should be thrown");
} catch (final ReactorException e) {
final String expected = "Error in module 'container-list': cannot add '(urn:simple.container" +
".demo?revision=1970-01-01)foo'. Node name collision: '(urn:simple.container" +
}
@Test
- public void testDuplicateContainerLeaf() throws Exception {
- final File yang = new File(getClass().getResource("/negative-scenario/duplicity/container-leaf.yang").toURI());
+ public void testDuplicateContainerLeaf() throws IOException, YangSyntaxErrorException {
try {
- try (InputStream stream = new NamedFileInputStream(yang, yang.getPath())) {
- TestUtils.loadModule(stream);
- fail("SourceException should be thrown");
- }
+ TestUtils.loadModuleResources(getClass(), "/negative-scenario/duplicity/container-leaf.yang");
+ fail("SourceException should be thrown");
} catch (final ReactorException e) {
final String expected = "Error in module 'container-leaf': cannot add '(urn:simple.container" +
".demo?revision=1970-01-01)foo'. Node name collision: '(urn:simple.container" +
}
@Test
- public void testDuplicateTypedef() throws Exception {
- final File yang = new File(getClass().getResource("/negative-scenario/duplicity/typedef.yang").toURI());
+ public void testDuplicateTypedef() throws IOException, YangSyntaxErrorException {
try {
- try (InputStream stream = new NamedFileInputStream(yang, yang.getPath())) {
- TestUtils.loadModule(stream);
- fail("SourceException should be thrown");
- }
+ TestUtils.loadModuleResources(getClass(), "/negative-scenario/duplicity/typedef.yang");
+ fail("SourceException should be thrown");
} catch (final ReactorException e) {
assertTrue(e.getCause().getMessage().startsWith(
"Duplicate name for typedef (urn:simple.container.demo?revision=1970-01-01)int-ext [at"));
}
@Test
- public void testDuplicityInAugmentTarget1() throws Exception {
- final File yang1 = new File(getClass().getResource("/negative-scenario/duplicity/augment0.yang").toURI());
- final File yang2 = new File(getClass().getResource("/negative-scenario/duplicity/augment1.yang").toURI());
- try (InputStream stream1 = new NamedFileInputStream(yang1, yang1.getPath());
- InputStream stream2 = new NamedFileInputStream(yang2, yang2.getPath())) {
- TestUtils.loadModules(Arrays.asList(stream1, stream2));
- testLog = output.toString();
- assertTrue(testLog.contains("An augment cannot add node named 'id' because this name is already used in target"));
- }
+ public void testDuplicityInAugmentTarget1() throws IOException, ReactorException, YangSyntaxErrorException {
+ TestUtils.loadModuleResources(getClass(),
+ "/negative-scenario/duplicity/augment0.yang",
+ "/negative-scenario/duplicity/augment1.yang");
+ testLog = output.toString();
+ assertTrue(testLog.contains("An augment cannot add node named 'id' because this name is already used in target"));
}
@Test
- public void testDuplicityInAugmentTarget2() throws Exception {
- final File yang1 = new File(getClass().getResource("/negative-scenario/duplicity/augment0.yang").toURI());
- final File yang2 = new File(getClass().getResource("/negative-scenario/duplicity/augment2.yang").toURI());
- try (InputStream stream1 = new NamedFileInputStream(yang1, yang1.getPath());
- InputStream stream2 = new NamedFileInputStream(yang2, yang2.getPath())) {
- TestUtils.loadModules(Arrays.asList(stream1, stream2));
- testLog = output.toString();
- assertTrue(testLog.contains("An augment cannot add node named 'delta' because this name is already used in target"));
- }
+ public void testDuplicityInAugmentTarget2() throws IOException, ReactorException, YangSyntaxErrorException {
+ TestUtils.loadModuleResources(getClass(),
+ "/negative-scenario/duplicity/augment0.yang",
+ "/negative-scenario/duplicity/augment2.yang");
+ testLog = output.toString();
+ assertTrue(testLog.contains("An augment cannot add node named 'delta' because this name is already used in target"));
}
@Test
- public void testMandatoryInAugment() throws Exception {
- final File yang1 = new File(getClass().getResource("/negative-scenario/testfile8.yang").toURI());
- final File yang2 = new File(getClass().getResource("/negative-scenario/testfile7.yang").toURI());
- try (InputStream stream1 = new NamedFileInputStream(yang1, yang1.getPath());
- InputStream stream2 = new NamedFileInputStream(yang2, yang2.getPath())) {
- TestUtils.loadModules(Arrays.asList(stream1, stream2));
- testLog = output.toString();
- assertTrue(testLog.contains(
- "An augment cannot add node 'linkleaf' because it is mandatory and in module different than target"));
- }
+ public void testMandatoryInAugment() throws IOException, ReactorException, YangSyntaxErrorException {
+ TestUtils.loadModuleResources(getClass(),
+ "/negative-scenario/testfile8.yang",
+ "/negative-scenario/testfile7.yang");
+ testLog = output.toString();
+ assertTrue(testLog.contains(
+ "An augment cannot add node 'linkleaf' because it is mandatory and in module different than target"));
}
@Test
- public void testInvalidListKeyDefinition() throws Exception {
- final File yang1 = new File(getClass().getResource("/negative-scenario/invalid-list-key-def.yang").toURI());
+ public void testInvalidListKeyDefinition() throws IOException, YangSyntaxErrorException {
try {
- try (InputStream stream1 = new NamedFileInputStream(yang1, yang1.getPath())) {
- TestUtils.loadModule(stream1);
- fail("InferenceException should be thrown");
- }
+ TestUtils.loadModuleResources(getClass(), "/negative-scenario/invalid-list-key-def.yang");
+ fail("InferenceException should be thrown");
} catch (final ReactorException e) {
- final String expected = "Key 'rib-id' misses node 'rib-id' in list '(invalid:list:key:def?revision=1970-01-01)" +
- "application-map'";
+ final String expected = "Key 'rib-id' misses node 'rib-id' in list "
+ + "'(invalid:list:key:def?revision=1970-01-01)application-map'";
assertTrue(e.getCause().getMessage().startsWith(expected));
}
}
-
}
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.common.SimpleDateFormatUtil;
import org.opendaylight.yangtools.yang.model.api.AnyXmlSchemaNode;
import org.opendaylight.yangtools.yang.model.api.ConstraintDefinition;
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.SchemaPath;
import org.opendaylight.yangtools.yang.model.api.Status;
import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
import org.opendaylight.yangtools.yang.model.api.UsesNode;
public class YangParserSimpleTest {
- private final URI snNS = URI.create("urn:opendaylight:simple-nodes");
- private Date snRev;
- private final String snPref = "sn";
+ private static final QNameModule SN =
+ QNameModule.create(URI.create("urn:opendaylight:simple-nodes"), QName.parseRevision("2013-07-30"));
+ private static final QName SN_NODES = QName.create(SN, "nodes");
+ private static final SchemaPath SN_NODES_PATH = SchemaPath.create(true, SN_NODES);
- private Set<Module> modules;
+ private SchemaContext context;
+ private Module testModule;
@Before
public void init() throws Exception {
- snRev = SimpleDateFormatUtil.getRevisionFormat().parse("2013-07-30");
- modules = TestUtils.loadModules(getClass().getResource("/simple-test").toURI());
+ context = TestUtils.loadModules(getClass().getResource("/simple-test").toURI());
+ testModule = TestUtils.findModule(context, "simple-nodes").get();
}
@Test
public void testParseAnyXml() {
- final Module testModule = TestUtils.findModule(modules, "simple-nodes");
final AnyXmlSchemaNode data = (AnyXmlSchemaNode) testModule.getDataChildByName(QName.create(testModule.getQNameModule(), "data"));
assertNotNull("'anyxml data not found'", data);
assertFalse(data.equals(null));
"path=AbsoluteSchemaPath{path=[(urn:opendaylight:simple-nodes?revision=2013-07-30)data]}]", data.toString());
// test SchemaNode args
- final QName qname = data.getQName();
- assertEquals("data", qname.getLocalName());
- assertEquals(snNS, qname.getNamespace());
- assertEquals(snRev, qname.getRevision());
+ assertEquals(QName.create(SN, "data"), data.getQName());
assertEquals("anyxml desc", data.getDescription());
assertEquals("data ref", data.getReference());
assertEquals(Status.OBSOLETE, data.getStatus());
@Test
public void testParseContainer() throws ParseException {
- final Module test = TestUtils.findModule(modules, "simple-nodes");
-
- final ContainerSchemaNode nodes = (ContainerSchemaNode) test.getDataChildByName(QName.create(test.getQNameModule(), "nodes"));
+ final ContainerSchemaNode nodes = (ContainerSchemaNode) testModule
+ .getDataChildByName(QName.create(testModule.getQNameModule(), "nodes"));
// test SchemaNode args
- final QName expectedQName = QName.create(snNS, snRev, "nodes");
- assertEquals(expectedQName, nodes.getQName());
- final SchemaPath expectedPath = TestUtils.createPath(true, snNS, snRev, snPref, "nodes");
- assertEquals(expectedPath, nodes.getPath());
+ assertEquals(SN_NODES, nodes.getQName());
+ assertEquals(SN_NODES_PATH, nodes.getPath());
assertEquals("nodes collection", nodes.getDescription());
assertEquals("nodes ref", nodes.getReference());
assertEquals(Status.CURRENT, nodes.getStatus());
final Set<TypeDefinition<?>> typedefs = nodes.getTypeDefinitions();
assertEquals(1, typedefs.size());
final TypeDefinition<?> nodesType = typedefs.iterator().next();
- final QName typedefQName = QName.create(snNS, snRev, "nodes-type");
+ final QName typedefQName = QName.create(SN, "nodes-type");
assertEquals(typedefQName, nodesType.getQName());
- final SchemaPath nodesTypePath = TestUtils.createPath(true, snNS, snRev, snPref, "nodes", "nodes-type");
- assertEquals(nodesTypePath, nodesType.getPath());
+ assertEquals(SN_NODES_PATH.createChild(QName.create(SN, "nodes-type")), nodesType.getPath());
assertNull(nodesType.getDescription());
assertNull(nodesType.getReference());
assertEquals(Status.CURRENT, nodesType.getStatus());
// child nodes
// total size = 8: defined 6, inserted by uses 2
assertEquals(8, nodes.getChildNodes().size());
- final LeafListSchemaNode added = (LeafListSchemaNode)nodes.getDataChildByName(QName.create(test.getQNameModule(), "added"));
+ final LeafListSchemaNode added = (LeafListSchemaNode)nodes.getDataChildByName(QName.create(testModule.getQNameModule(), "added"));
assertEquals(createPath("nodes", "added"), added.getPath());
assertEquals(createPath("mytype"), added.getType().getPath());
- final ListSchemaNode links = (ListSchemaNode) nodes.getDataChildByName(QName.create(test.getQNameModule(), "links"));
+ final ListSchemaNode links = (ListSchemaNode) nodes.getDataChildByName(QName.create(testModule.getQNameModule(), "links"));
assertFalse(links.isUserOrdered());
final Set<GroupingDefinition> groupings = nodes.getGroupings();
assertEquals(1, groupings.size());
final GroupingDefinition nodeGroup = groupings.iterator().next();
- final QName groupQName = QName.create(snNS, snRev, "node-group");
+ final QName groupQName = QName.create(SN, "node-group");
assertEquals(groupQName, nodeGroup.getQName());
- final SchemaPath nodeGroupPath = TestUtils.createPath(true, snNS, snRev, snPref, "nodes", "node-group");
+ final SchemaPath nodeGroupPath = SN_NODES_PATH.createChild(groupQName);
assertEquals(nodeGroupPath, nodeGroup.getPath());
final Set<UsesNode> uses = nodes.getUses();
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 static org.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResource;
-import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
-import java.text.DateFormat;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Collection;
import org.junit.Before;
import org.junit.Test;
import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
+import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.common.YangConstants;
import org.opendaylight.yangtools.yang.common.YangVersion;
import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
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.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<Module> modules;
+ private static final QNameModule FOO = QNameModule.create(
+ URI.create("urn:opendaylight.foo"), QName.parseRevision("2013-02-27"));
+ private static final QNameModule BAR = QNameModule.create(
+ URI.create("urn:opendaylight.bar"), QName.parseRevision("2013-07-03"));
+ private static final QNameModule BAZ = QNameModule.create(
+ URI.create("urn:opendaylight.baz"), QName.parseRevision("2013-02-27"));
+
+ private SchemaContext context;
+ private Module foo;
+ private Module bar;
+ private Module baz;
@Before
public void init() throws Exception {
- final DateFormat simpleDateFormat = SimpleDateFormatUtil.getRevisionFormat();
- 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());
+ context = TestUtils.loadModules(getClass().getResource("/model").toURI());
+ foo = TestUtils.findModule(context, "foo").get();
+ bar = TestUtils.findModule(context, "bar").get();
+ baz = TestUtils.findModule(context, "baz").get();
}
@Test
public void testHeaders() throws ParseException {
- final Module foo = TestUtils.findModule(modules, "foo");
-
assertEquals("foo", foo.getName());
assertEquals(YangVersion.VERSION_1.toString(), foo.getYangVersion());
- assertEquals(fooNS, foo.getNamespace());
+ assertEquals(FOO.getNamespace(), foo.getNamespace());
assertEquals("foo", foo.getPrefix());
final Set<ModuleImport> imports = foo.getImports();
final ModuleImport import2 = TestUtils.findImport(imports, "br");
assertEquals("bar", import2.getModuleName());
- assertEquals(barRev, import2.getRevision());
+ assertEquals(BAR.getRevision(), import2.getRevision());
final ModuleImport import3 = TestUtils.findImport(imports, "bz");
assertEquals("baz", import3.getModuleName());
- assertEquals(bazRev, import3.getRevision());
+ assertEquals(BAZ.getRevision(), import3.getRevision());
assertEquals("opendaylight", foo.getOrganization());
assertEquals("http://www.opendaylight.org/", foo.getContact());
@Test
public void testParseList() {
- final Module bar = TestUtils.findModule(modules, "bar");
- final URI expectedNamespace = URI.create("urn:opendaylight.bar");
- final String expectedPrefix = "bar";
-
final ContainerSchemaNode interfaces = (ContainerSchemaNode) bar.getDataChildByName(QName.create(
bar.getQNameModule(), "interfaces"));
final ListSchemaNode ifEntry = (ListSchemaNode) interfaces.getDataChildByName(QName.create(bar.getQNameModule(),
"ifEntry"));
// test SchemaNode args
- final QName expectedQName = QName.create(expectedNamespace, barRev, "ifEntry");
- assertEquals(expectedQName, ifEntry.getQName());
- final SchemaPath expectedPath = TestUtils.createPath(true, expectedNamespace, barRev, expectedPrefix,
- "interfaces", "ifEntry");
+ assertEquals(QName.create(BAR, "ifEntry"), ifEntry.getQName());
+
+ final SchemaPath expectedPath = TestUtils.createPath(true, BAR, "interfaces", "ifEntry");
assertEquals(expectedPath, ifEntry.getPath());
assertNull(ifEntry.getDescription());
assertNull(ifEntry.getReference());
assertEquals(2, availableAugmentations.size());
// test ListSchemaNode args
final List<QName> expectedKey = new ArrayList<>();
- expectedKey.add(QName.create(expectedNamespace, barRev, "ifIndex"));
+ expectedKey.add(QName.create(BAR, "ifIndex"));
assertEquals(expectedKey, ifEntry.getKeyDefinition());
assertFalse(ifEntry.isUserOrdered());
// test DataNodeContainer args
@Test
public void testTypedefRangesResolving() throws ParseException {
- final Module foo = TestUtils.findModule(modules, "foo");
final LeafSchemaNode int32Leaf = (LeafSchemaNode) foo.getDataChildByName(QName.create(foo.getQNameModule(), "int32-leaf"));
final IntegerTypeDefinition leafType = (IntegerTypeDefinition) int32Leaf.getType();
- final QName leafTypeQName = leafType.getQName();
- assertEquals("int32-ext2", leafTypeQName.getLocalName());
- assertEquals(fooNS, leafTypeQName.getNamespace());
- assertEquals(fooRev, leafTypeQName.getRevision());
+ assertEquals(QName.create(FOO, "int32-ext2"), leafType.getQName());
assertEquals("mile", leafType.getUnits());
assertEquals("11", leafType.getDefaultValue());
assertEquals(20, range.getMax().intValue());
final IntegerTypeDefinition baseType = leafType.getBaseType();
- final QName baseTypeQName = baseType.getQName();
- assertEquals("int32-ext2", baseTypeQName.getLocalName());
- assertEquals(barNS, baseTypeQName.getNamespace());
- assertEquals(barRev, baseTypeQName.getRevision());
+ assertEquals(QName.create(BAR, "int32-ext2"), baseType.getQName());
assertEquals("mile", baseType.getUnits());
assertEquals("11", baseType.getDefaultValue());
final IntegerTypeDefinition base = baseType.getBaseType();
final QName baseQName = base.getQName();
assertEquals("int32-ext1", baseQName.getLocalName());
- assertEquals(barNS, baseQName.getNamespace());
- assertEquals(barRev, baseQName.getRevision());
+ assertEquals(BAR, baseQName.getModule());
assertNull(base.getUnits());
assertNull(base.getDefaultValue());
@Test
public void testTypedefPatternsResolving() {
- final Module foo = TestUtils.findModule(modules, "foo");
final LeafSchemaNode stringleaf = (LeafSchemaNode) foo.getDataChildByName(QName.create(foo.getQNameModule(), "string-leaf"));
assertTrue(stringleaf.getType() instanceof StringTypeDefinition);
final StringTypeDefinition type = (StringTypeDefinition) stringleaf.getType();
final QName typeQName = type.getQName();
assertEquals("string-ext4", typeQName.getLocalName());
- assertEquals(barNS, typeQName.getNamespace());
- assertEquals(barRev, typeQName.getRevision());
+ assertEquals(BAR, typeQName.getModule());
assertNull(type.getUnits());
assertNull(type.getDefaultValue());
List<PatternConstraint> patterns = type.getPatternConstraints();
final StringTypeDefinition baseType1 = type.getBaseType();
final QName baseType1QName = baseType1.getQName();
assertEquals("string-ext3", baseType1QName.getLocalName());
- assertEquals(barNS, baseType1QName.getNamespace());
- assertEquals(barRev, baseType1QName.getRevision());
+ assertEquals(BAR, baseType1QName.getModule());
assertNull(baseType1.getUnits());
assertNull(baseType1.getDefaultValue());
patterns = baseType1.getPatternConstraints();
final StringTypeDefinition baseType2 = baseType1.getBaseType();
final QName baseType2QName = baseType2.getQName();
assertEquals("string-ext2", baseType2QName.getLocalName());
- assertEquals(barNS, baseType2QName.getNamespace());
- assertEquals(barRev, baseType2QName.getRevision());
+ assertEquals(BAR, baseType2QName.getModule());
assertNull(baseType2.getUnits());
assertNull(baseType2.getDefaultValue());
assertTrue(baseType2.getPatternConstraints().isEmpty());
assertEquals(10, length.getMax().intValue());
final StringTypeDefinition baseType3 = baseType2.getBaseType();
- final QName baseType3QName = baseType3.getQName();
- assertEquals("string-ext1", baseType3QName.getLocalName());
- assertEquals(barNS, baseType3QName.getNamespace());
- assertEquals(barRev, baseType3QName.getRevision());
+ assertEquals(QName.create(BAR, "string-ext1"), baseType3.getQName());
assertNull(baseType3.getUnits());
assertNull(baseType3.getDefaultValue());
patterns = baseType3.getPatternConstraints();
@Test
public void testTypedefInvalidPatternsResolving() {
- final Module foo = TestUtils.findModule(modules, "foo");
final LeafSchemaNode invalidPatternStringLeaf = (LeafSchemaNode) foo
.getDataChildByName(QName.create(foo.getQNameModule(), "invalid-pattern-string-leaf"));
StringTypeDefinition type = (StringTypeDefinition) invalidPatternStringLeaf.getType();
- QName typeQName = type.getQName();
- assertEquals("invalid-string-pattern", typeQName.getLocalName());
- assertEquals(barNS, typeQName.getNamespace());
- assertEquals(barRev, typeQName.getRevision());
+ assertEquals(QName.create(BAR, "invalid-string-pattern"), type.getQName());
assertNull(type.getUnits());
assertNull(type.getDefaultValue());
List<PatternConstraint> patterns = type.getPatternConstraints();
final LeafSchemaNode invalidDirectStringPatternDefLeaf = (LeafSchemaNode) foo
.getDataChildByName(QName.create(foo.getQNameModule(), "invalid-direct-string-pattern-def-leaf"));
type = (StringTypeDefinition) invalidDirectStringPatternDefLeaf.getType();
- typeQName = type.getQName();
- assertEquals("string", typeQName.getLocalName());
- assertEquals(YangConstants.RFC6020_YANG_NAMESPACE, typeQName.getNamespace());
- assertNull(typeQName.getRevision());
+
+ assertEquals(QName.create(YangConstants.RFC6020_YANG_MODULE, "string"), type.getQName());
assertNull(type.getUnits());
assertNull(type.getDefaultValue());
patterns = type.getPatternConstraints();
final LeafSchemaNode multiplePatternStringLeaf = (LeafSchemaNode) foo
.getDataChildByName(QName.create(foo.getQNameModule(), "multiple-pattern-string-leaf"));
type = (StringTypeDefinition) multiplePatternStringLeaf.getType();
- typeQName = type.getQName();
- assertEquals("multiple-pattern-string", typeQName.getLocalName());
- assertEquals(barNS, typeQName.getNamespace());
- assertEquals(barRev, typeQName.getRevision());
+ assertEquals(QName.create(BAR, "multiple-pattern-string"), type.getQName());
assertNull(type.getUnits());
assertNull(type.getDefaultValue());
patterns = type.getPatternConstraints();
final LeafSchemaNode multiplePatternDirectStringDefLeaf = (LeafSchemaNode) foo
.getDataChildByName(QName.create(foo.getQNameModule(), "multiple-pattern-direct-string-def-leaf"));
type = (StringTypeDefinition) multiplePatternDirectStringDefLeaf.getType();
- typeQName = type.getQName();
- assertEquals("string", typeQName.getLocalName());
- assertEquals(fooNS, typeQName.getNamespace());
- assertEquals(fooRev, typeQName.getRevision());
+ assertEquals(QName.create(FOO, "string"), type.getQName());
assertNull(type.getUnits());
assertNull(type.getDefaultValue());
patterns = type.getPatternConstraints();
@Test
public void testTypedefLengthsResolving() {
- final Module foo = TestUtils.findModule(modules, "foo");
-
final LeafSchemaNode lengthLeaf = (LeafSchemaNode) foo.getDataChildByName(QName.create(foo.getQNameModule(), "length-leaf"));
final StringTypeDefinition type = (StringTypeDefinition) lengthLeaf.getType();
- final QName typeQName = type.getQName();
- assertEquals("string-ext2", typeQName.getLocalName());
- assertEquals(fooNS, typeQName.getNamespace());
- assertEquals(fooRev, typeQName.getRevision());
+ assertEquals(QName.create(FOO, "string-ext2"), type.getQName());
assertNull(type.getUnits());
assertNull(type.getDefaultValue());
assertTrue(type.getPatternConstraints().isEmpty());
assertEquals(10, length.getMax().intValue());
final StringTypeDefinition baseType1 = type.getBaseType();
- final QName baseType1QName = baseType1.getQName();
- assertEquals("string-ext2", baseType1QName.getLocalName());
- assertEquals(barNS, baseType1QName.getNamespace());
- assertEquals(barRev, baseType1QName.getRevision());
+ assertEquals(QName.create(BAR, "string-ext2"), baseType1.getQName());
assertNull(baseType1.getUnits());
assertNull(baseType1.getDefaultValue());
assertTrue(baseType1.getPatternConstraints().isEmpty());
assertEquals(10, length.getMax().intValue());
final StringTypeDefinition baseType2 = baseType1.getBaseType();
- final QName baseType2QName = baseType2.getQName();
- assertEquals("string-ext1", baseType2QName.getLocalName());
- assertEquals(barNS, baseType2QName.getNamespace());
- assertEquals(barRev, baseType2QName.getRevision());
+ assertEquals(QName.create(BAR, "string-ext1"), baseType2.getQName());
assertNull(baseType2.getUnits());
assertNull(baseType2.getDefaultValue());
final List<PatternConstraint> patterns = baseType2.getPatternConstraints();
@Test
public void testTypedefDecimal1() {
- final Module foo = TestUtils.findModule(modules, "foo");
final LeafSchemaNode testleaf = (LeafSchemaNode) foo.getDataChildByName(QName.create(foo.getQNameModule(), "decimal-leaf"));
assertTrue(testleaf.getType() instanceof DecimalTypeDefinition);
final DecimalTypeDefinition type = (DecimalTypeDefinition) testleaf.getType();
- final QName typeQName = type.getQName();
- assertEquals("my-decimal-type", typeQName.getLocalName());
- assertEquals(barNS, typeQName.getNamespace());
- assertEquals(barRev, typeQName.getRevision());
+ assertEquals(QName.create(BAR, "my-decimal-type"), type.getQName());
assertNull(type.getUnits());
assertNull(type.getDefaultValue());
assertEquals(6, type.getFractionDigits().intValue());
assertEquals(1, type.getRangeConstraints().size());
final DecimalTypeDefinition typeBase = type.getBaseType();
- final QName typeBaseQName = typeBase.getQName();
- assertEquals("decimal64", typeBaseQName.getLocalName());
- assertEquals(barNS, typeBaseQName.getNamespace());
- assertEquals(barRev, typeBaseQName.getRevision());
+ assertEquals(QName.create(BAR, "decimal64"), typeBase.getQName());
assertNull(typeBase.getUnits());
assertNull(typeBase.getDefaultValue());
assertEquals(6, typeBase.getFractionDigits().intValue());
@Test
public void testTypedefDecimal2() {
- final Module foo = TestUtils.findModule(modules, "foo");
final LeafSchemaNode testleaf = (LeafSchemaNode) foo.getDataChildByName(QName.create(foo.getQNameModule(), "decimal-leaf2"));
assertTrue(testleaf.getType() instanceof DecimalTypeDefinition);
final DecimalTypeDefinition type = (DecimalTypeDefinition) testleaf.getType();
- final QName typeQName = type.getQName();
- assertEquals("my-decimal-type", typeQName.getLocalName());
- assertEquals(barNS, typeQName.getNamespace());
- assertEquals(barRev, typeQName.getRevision());
+ assertEquals(QName.create(BAR, "my-decimal-type"), type.getQName());
assertNull(type.getUnits());
assertNull(type.getDefaultValue());
assertEquals(6, type.getFractionDigits().intValue());
@Test
public void testTypedefUnion() {
- final Module foo = TestUtils.findModule(modules, "foo");
final LeafSchemaNode unionleaf = (LeafSchemaNode) foo.getDataChildByName(QName.create(foo.getQNameModule(), "union-leaf"));
assertTrue(unionleaf.getType() instanceof UnionTypeDefinition);
final UnionTypeDefinition type = (UnionTypeDefinition) unionleaf.getType();
- final QName typeQName = type.getQName();
- assertEquals("my-union-ext", typeQName.getLocalName());
- assertEquals(barNS, typeQName.getNamespace());
- assertEquals(barRev, typeQName.getRevision());
+ assertEquals(QName.create(BAR, "my-union-ext"), type.getQName());
assertNull(type.getUnits());
assertNull(type.getDefaultValue());
final UnionTypeDefinition baseType = type.getBaseType();
- final QName baseTypeQName = baseType.getQName();
- assertEquals("my-union", baseTypeQName.getLocalName());
- assertEquals(barNS, baseTypeQName.getNamespace());
- assertEquals(barRev, baseTypeQName.getRevision());
+ assertEquals(QName.create(BAR, "my-union"), baseType.getQName());
assertNull(baseType.getUnits());
assertNull(baseType.getDefaultValue());
assertEquals(2, unionTypes.size());
final IntegerTypeDefinition unionType1 = (IntegerTypeDefinition) unionTypes.get(0);
- final QName unionType1QName = baseType.getQName();
- assertEquals("my-union", unionType1QName.getLocalName());
- assertEquals(barNS, unionType1QName.getNamespace());
- assertEquals(barRev, unionType1QName.getRevision());
+ assertEquals(QName.create(BAR, "my-union"), baseType.getQName());
assertNull(unionType1.getUnits());
assertNull(unionType1.getDefaultValue());
@Test
public void testNestedUnionResolving() {
- final Module foo = TestUtils.findModule(modules, "foo");
final LeafSchemaNode testleaf = (LeafSchemaNode) foo.getDataChildByName(QName.create(foo.getQNameModule(), "custom-union-leaf"));
assertTrue(testleaf.getType() instanceof UnionTypeDefinition);
final UnionTypeDefinition type = (UnionTypeDefinition) testleaf.getType();
- final QName testleafTypeQName = type.getQName();
- assertEquals(bazNS, testleafTypeQName.getNamespace());
- assertEquals(bazRev, testleafTypeQName.getRevision());
- assertEquals("union1", testleafTypeQName.getLocalName());
+ assertEquals(QName.create(BAZ, "union1"), type.getQName());
assertNull(type.getUnits());
assertNull(type.getDefaultValue());
final UnionTypeDefinition typeBase = type.getBaseType();
- final QName typeBaseQName = typeBase.getQName();
- assertEquals(bazNS, typeBaseQName.getNamespace());
- assertEquals(bazRev, typeBaseQName.getRevision());
- assertEquals("union2", typeBaseQName.getLocalName());
+ assertEquals(QName.create(BAZ, "union2"), typeBase.getQName());
assertNull(typeBase.getUnits());
assertNull(typeBase.getDefaultValue());
assertTrue(unionTypes.get(1) instanceof UnionTypeDefinition);
final UnionTypeDefinition unionType1 = (UnionTypeDefinition) unionTypes.get(1);
- final QName uniontType1QName = unionType1.getQName();
- assertEquals(barNS, uniontType1QName.getNamespace());
- assertEquals(barRev, uniontType1QName.getRevision());
- assertEquals("nested-union2", uniontType1QName.getLocalName());
+ assertEquals(QName.create(BAR, "nested-union2"), unionType1.getQName());
assertNull(unionType1.getUnits());
assertNull(unionType1.getDefaultValue());
assertTrue(nestedUnion2Types.get(0) instanceof UnionTypeDefinition);
final UnionTypeDefinition myUnionExt = (UnionTypeDefinition) nestedUnion2Types.get(0);
- final QName myUnionExtQName = myUnionExt.getQName();
- assertEquals(barNS, myUnionExtQName.getNamespace());
- assertEquals(barRev, myUnionExtQName.getRevision());
- assertEquals("my-union-ext", myUnionExtQName.getLocalName());
+ assertEquals(QName.create(BAR, "my-union-ext"), myUnionExt.getQName());
assertNull(myUnionExt.getUnits());
assertNull(myUnionExt.getDefaultValue());
final UnionTypeDefinition myUnion = myUnionExt.getBaseType();
- final QName myUnionQName = myUnion.getQName();
- assertEquals(barNS, myUnionQName.getNamespace());
- assertEquals(barRev, myUnionQName.getRevision());
- assertEquals("my-union", myUnionQName.getLocalName());
+ assertEquals(QName.create(BAR, "my-union"), myUnion.getQName());
assertNull(myUnion.getUnits());
assertNull(myUnion.getDefaultValue());
assertEquals(BaseTypes.int32Type(), myUnionBaseTypes.get(1));
final IntegerTypeDefinition int16Ext = (IntegerTypeDefinition) myUnionBaseTypes.get(0);
- final QName int16ExtQName = int16Ext.getQName();
- assertEquals(barNS, int16ExtQName.getNamespace());
- assertEquals(barRev, int16ExtQName.getRevision());
- assertEquals("int16", int16ExtQName.getLocalName());
+ assertEquals(QName.create(BAR, "int16"), int16Ext.getQName());
assertNull(int16Ext.getUnits());
assertNull(int16Ext.getDefaultValue());
final List<RangeConstraint> ranges = int16Ext.getRangeConstraints();
@Test
public void testChoice() {
- final Module foo = TestUtils.findModule(modules, "foo");
final ContainerSchemaNode transfer = (ContainerSchemaNode) foo.getDataChildByName(QName.create(foo.getQNameModule(), "transfer"));
final ChoiceSchemaNode how = (ChoiceSchemaNode) transfer.getDataChildByName(QName.create(foo.getQNameModule(), "how"));
final Set<ChoiceCaseNode> cases = how.getCases();
@Test
public void testDeviation() {
- final Module foo = TestUtils.findModule(modules, "foo");
final Set<Deviation> deviations = foo.getDeviations();
assertEquals(1, deviations.size());
final Deviation dev = deviations.iterator().next();
assertEquals("system/user ref", dev.getReference());
- final List<QName> path = new ArrayList<>();
- path.add(QName.create(barNS, barRev, "interfaces"));
- path.add(QName.create(barNS, barRev, "ifEntry"));
- final SchemaPath expectedPath = SchemaPath.create(path, true);
+ final SchemaPath expectedPath = SchemaPath.create(true,
+ QName.create(BAR, "interfaces"),
+ QName.create(BAR, "ifEntry"));
assertEquals(expectedPath, dev.getTargetPath());
assertEquals(DeviateKind.ADD, dev.getDeviates().iterator().next().getDeviateType());
@Test
public void testUnknownNode() {
- final Module baz = TestUtils.findModule(modules, "baz");
final ContainerSchemaNode network = (ContainerSchemaNode) baz.getDataChildByName(QName.create(baz.getQNameModule(), "network"));
final List<UnknownSchemaNode> unknownNodes = network.getUnknownSchemaNodes();
assertEquals(1, unknownNodes.size());
@Test
public void testFeature() {
- final Module baz = TestUtils.findModule(modules, "baz");
final Set<FeatureDefinition> features = baz.getFeatures();
assertEquals(1, features.size());
}
@Test
public void testExtension() {
- final Module baz = TestUtils.findModule(modules, "baz");
final List<ExtensionDefinition> extensions = baz.getExtensionSchemaNodes();
assertEquals(1, extensions.size());
final ExtensionDefinition extension = extensions.get(0);
@Test
public void testNotification() {
- final Module baz = TestUtils.findModule(modules, "baz");
- final String expectedPrefix = "c";
-
final Set<NotificationDefinition> notifications = baz.getNotifications();
assertEquals(1, notifications.size());
final NotificationDefinition notification = notifications.iterator().next();
// test SchemaNode args
- final QName expectedQName = QName.create(bazNS, bazRev, "event");
- assertEquals(expectedQName, notification.getQName());
- final SchemaPath expectedPath = TestUtils.createPath(true, bazNS, bazRev, expectedPrefix, "event");
+ assertEquals(QName.create(BAZ, "event"), notification.getQName());
+ final SchemaPath expectedPath = SchemaPath.create(true, QName.create(BAZ, "event"));
assertEquals(expectedPath, notification.getPath());
assertNull(notification.getDescription());
assertNull(notification.getReference());
@Test
public void testRpc() {
- final Module baz = TestUtils.findModule(modules, "baz");
-
final Set<RpcDefinition> rpcs = baz.getRpcs();
assertEquals(1, rpcs.size());
@Test
public void testTypePath() throws ParseException {
- final Module bar = TestUtils.findModule(modules, "bar");
final Set<TypeDefinition<?>> types = bar.getTypeDefinitions();
// int32-ext1
final IntegerTypeDefinition int32ext1 = (IntegerTypeDefinition) TestUtils.findTypedef(types, "int32-ext1");
- final QName int32TypedefQName = int32ext1.getQName();
-
- assertEquals(barNS, int32TypedefQName.getNamespace());
- assertEquals(barRev, int32TypedefQName.getRevision());
- assertEquals("int32-ext1", int32TypedefQName.getLocalName());
+ final QName int32TypedefQName = QName.create(BAR, "int32-ext1");
+ assertEquals(int32TypedefQName, int32ext1.getQName());
final SchemaPath typeSchemaPath = int32ext1.getPath();
final Iterable<QName> typePath = typeSchemaPath.getPathFromRoot();
@Test
public void testTypePath2() throws ParseException {
- final Module bar = TestUtils.findModule(modules, "bar");
final Set<TypeDefinition<?>> types = bar.getTypeDefinitions();
// my-decimal-type
final DecimalTypeDefinition myDecType = (DecimalTypeDefinition) TestUtils.findTypedef(types, "my-decimal-type");
final QName myDecTypeQName = myDecType.getQName();
- assertEquals(barNS, myDecTypeQName.getNamespace());
- assertEquals(barRev, myDecTypeQName.getRevision());
+ assertEquals(BAR, myDecTypeQName.getModule());
assertEquals("my-decimal-type", myDecTypeQName.getLocalName());
final SchemaPath typeSchemaPath = myDecType.getPath();
final DecimalTypeDefinition dec64 = myDecType.getBaseType();
final QName dec64QName = dec64.getQName();
- assertEquals(barNS, dec64QName.getNamespace());
- assertEquals(barRev, dec64QName.getRevision());
+ assertEquals(BAR, dec64QName.getModule());
assertEquals("decimal64", dec64QName.getLocalName());
final SchemaPath dec64SchemaPath = dec64.getPath();
@Test
public void testSubmodules() {
- final Module foo = TestUtils.findModule(modules, "foo");
-
final DataSchemaNode id = foo.getDataChildByName(QName.create(foo.getQNameModule(), "id"));
assertNotNull(id);
final DataSchemaNode subExt = foo.getDataChildByName(QName.create(foo.getQNameModule(), "sub-ext"));
public void unknownStatementInSubmoduleHeaderTest() throws IOException, URISyntaxException, ReactorException {
final StatementStreamSource yang1 = sourceForResource("/yang-grammar-test/revisions-extension.yang");
final StatementStreamSource yang2 = sourceForResource("/yang-grammar-test/submodule-header-extension.yang");
-
- try {
- TestUtils.parseYangSources(yang1, yang2);
- } catch (final YangParseException e) {
- e.printStackTrace();
- fail("YangParseException should not be thrown");
- }
-
+ TestUtils.parseYangSources(yang1, yang2);
}
@Test
final StatementStreamSource test3 = sourceForResource("/context-augment-test/test3.yang");
final SchemaContext context = TestUtils.parseYangSources(resource, test1, test2, test3);
- final Set<Module> modules = context.getModules();
- assertNotNull(modules);
-
- final Module t4 = TestUtils.findModule(modules, "test4");
+ final Module t4 = TestUtils.findModule(context, "test4").get();
final ContainerSchemaNode interfaces = (ContainerSchemaNode) t4.getDataChildByName(QName.create(
t4.getQNameModule(), "interfaces"));
final ListSchemaNode ifEntry = (ListSchemaNode) interfaces.getDataChildByName(QName.create(t4.getQNameModule(),
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
-import java.io.FileNotFoundException;
+import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import org.junit.Test;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.repo.api.StatementParserMode;
import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
-import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
+import org.xml.sax.SAXException;
public class YinOpenconfigVersionTest {
@Test
- public void basicTest() throws SourceException, FileNotFoundException, ReactorException, URISyntaxException {
+ public void basicTest() throws URISyntaxException, SAXException, IOException, ReactorException {
SchemaContext context = StmtTestUtils.parseYinSources("/openconfig-version/yin-input/basic",
StatementParserMode.SEMVER_MODE);
assertNotNull(context);
- Module foo = context.findModuleByNamespace(new URI("foo")).iterator().next();
- Module bar = context.findModuleByNamespace(new URI("bar")).iterator().next();
- Module semVer = context.findModuleByNamespace(new URI("http://openconfig.net/yang/openconfig-ext"))
+ Module foo = context.findModuleByNamespace(URI.create("foo")).iterator().next();
+ Module bar = context.findModuleByNamespace(URI.create("bar")).iterator().next();
+ Module semVer = context.findModuleByNamespace(URI.create("http://openconfig.net/yang/openconfig-ext"))
.iterator().next();
assertEquals(SemVer.valueOf("0.0.1"), semVer.getSemanticVersion());
}
@Test
- public void basicImportTest1() throws SourceException, FileNotFoundException, ReactorException, URISyntaxException {
+ public void basicImportTest1() throws URISyntaxException, SAXException, IOException, ReactorException {
SchemaContext context = StmtTestUtils.parseYinSources("/openconfig-version/yin-input/basic-import",
StatementParserMode.SEMVER_MODE);
assertNotNull(context);
- Module foo = context.findModuleByNamespace(new URI("foo")).iterator().next();
- Module semVer = context.findModuleByNamespace(new URI("http://openconfig.net/yang/openconfig-ext"))
+ Module foo = context.findModuleByNamespace(URI.create("foo")).iterator().next();
+ Module semVer = context.findModuleByNamespace(URI.create("http://openconfig.net/yang/openconfig-ext"))
.iterator().next();
assertEquals(SemVer.valueOf("0.0.1"), semVer.getSemanticVersion());
}
@Test
- public void basicImportErrTest1() throws SourceException, FileNotFoundException, ReactorException,
- URISyntaxException {
+ public void basicImportErrTest1() throws URISyntaxException, SAXException, IOException {
try {
StmtTestUtils.parseYinSources("/openconfig-version/yin-input/basic-import-invalid", StatementParserMode.SEMVER_MODE);
fail("Test should fail due to invalid openconfig version");
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
+import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Iterator;
import java.util.Set;
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.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
import org.opendaylight.yangtools.yang.stmt.TestUtils;
+import org.xml.sax.SAXException;
public class YinFileAugmentStmtTest {
- private Set<Module> modules;
+ private SchemaContext context;
@Before
- public void init() throws URISyntaxException, ReactorException {
- modules = TestUtils.loadYinModules(getClass().getResource("/semantic-statement-parser/yin/modules").toURI());
- assertEquals(9, modules.size());
+ public void init() throws ReactorException, SAXException, IOException, URISyntaxException {
+ context = TestUtils.loadYinModules(getClass().getResource("/semantic-statement-parser/yin/modules").toURI());
+ assertEquals(9, context.getModules().size());
}
@Test
public void testAugment() {
- final Module testModule = TestUtils.findModule(modules, "main-impl");
+ final Module testModule = TestUtils.findModule(context, "main-impl").get();
assertNotNull(testModule);
final Set<AugmentationSchema> augmentations = testModule.getAugmentations();
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
+import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Iterator;
-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.ListSchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
import org.opendaylight.yangtools.yang.stmt.TestUtils;
+import org.xml.sax.SAXException;
public class YinFileChoiceStmtTest {
- private Set<Module> modules;
+ private SchemaContext context;
@Before
- public void init() throws URISyntaxException, ReactorException {
- modules = TestUtils.loadYinModules(getClass().getResource("/semantic-statement-parser/yin/modules").toURI());
- assertEquals(9, modules.size());
+ public void init() throws ReactorException, SAXException, IOException, URISyntaxException {
+ context = TestUtils.loadYinModules(getClass().getResource("/semantic-statement-parser/yin/modules").toURI());
+ assertEquals(9, context.getModules().size());
}
@Test
public void testChoiceAndCases() {
- final Module testModule = TestUtils.findModule(modules, "config");
+ final Module testModule = TestUtils.findModule(context, "config").get();
assertNotNull(testModule);
final ContainerSchemaNode container = (ContainerSchemaNode) testModule.getDataChildByName(QName.create(
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
+import java.io.IOException;
import java.net.URISyntaxException;
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.model.api.ExtensionDefinition;
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;
import org.opendaylight.yangtools.yang.stmt.TestUtils;
+import org.xml.sax.SAXException;
public class YinFileExtensionStmtTest {
- private Set<Module> modules;
+ private SchemaContext context;
@Before
- public void init() throws URISyntaxException, ReactorException {
- modules = TestUtils.loadYinModules(getClass().getResource("/semantic-statement-parser/yin/modules").toURI());
- assertEquals(9, modules.size());
+ public void init() throws ReactorException, SAXException, IOException, URISyntaxException {
+ context = TestUtils.loadYinModules(getClass().getResource("/semantic-statement-parser/yin/modules").toURI());
+ assertEquals(9, context.getModules().size());
}
@Test
public void testExtensions() {
- Module testModule = TestUtils.findModule(modules, "config");
+ Module testModule = TestUtils.findModule(context, "config").get();
assertNotNull(testModule);
List<ExtensionDefinition> extensions = testModule.getExtensionSchemaNodes();
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
+import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Iterator;
import java.util.Set;
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.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
import org.opendaylight.yangtools.yang.stmt.TestUtils;
+import org.xml.sax.SAXException;
public class YinFileFeatureStmtTest {
- private Set<Module> modules;
+ private SchemaContext context;
@Before
- public void init() throws URISyntaxException, ReactorException {
- modules = TestUtils.loadYinModules(getClass().getResource
- ("/semantic-statement-parser/yin/feature-test/").toURI());
- assertEquals(1, modules.size());
+ public void init() throws ReactorException, SAXException, IOException, URISyntaxException {
+ context = TestUtils.loadYinModules(getClass().getResource("/semantic-statement-parser/yin/feature-test/")
+ .toURI());
+ assertEquals(1, context.getModules().size());
}
@Test
public void testFeature() {
- Module testModule = TestUtils.findModule(modules, "yang-with-features");
+ Module testModule = TestUtils.findModule(context, "yang-with-features").get();
assertNotNull(testModule);
Set<FeatureDefinition> features = testModule.getFeatures();
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
+import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Collection;
import java.util.Iterator;
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.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
import org.opendaylight.yangtools.yang.stmt.TestUtils;
+import org.xml.sax.SAXException;
public class YinFileGroupingStmtTest {
- private Set<Module> modules;
+ private SchemaContext context;
@Before
- public void init() throws URISyntaxException, ReactorException {
- modules = TestUtils.loadYinModules(getClass().getResource("/semantic-statement-parser/yin/modules").toURI());
- assertEquals(9, modules.size());
+ public void init() throws ReactorException, SAXException, IOException, URISyntaxException {
+ context = TestUtils.loadYinModules(getClass().getResource("/semantic-statement-parser/yin/modules").toURI());
+ assertEquals(9, context.getModules().size());
}
@Test
public void testGrouping() throws URISyntaxException {
- final Module testModule = TestUtils.findModule(modules, "config");
+ final Module testModule = TestUtils.findModule(context, "config").get();
assertNotNull(testModule);
final Set<GroupingDefinition> groupings = testModule.getGroupings();
import static org.junit.Assert.assertEquals;
+import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
-import java.util.Set;
import org.junit.Before;
import org.junit.Test;
import org.opendaylight.yangtools.yang.common.YangVersion;
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;
import org.opendaylight.yangtools.yang.stmt.TestUtils;
+import org.xml.sax.SAXException;
public class YinFileHeaderStmtsTest {
- private Set<Module> modules;
+ private SchemaContext modules;
@Before
- public void init() throws URISyntaxException, ReactorException {
+ public void init() throws URISyntaxException, ReactorException, SAXException, IOException {
modules = TestUtils.loadYinModules(getClass().getResource("/semantic-statement-parser/yin/modules").toURI());
- assertEquals(9, modules.size());
+ assertEquals(9, modules.getModules().size());
}
@Test
public void testYinFileHeader() throws URISyntaxException {
- Module testModule = TestUtils.findModule(modules, "config");
+ Module testModule = TestUtils.findModule(modules, "config").get();
assertEquals(YangVersion.VERSION_1.toString(), testModule.getYangVersion());
assertEquals(new URI("urn:opendaylight:params:xml:ns:yang:controller:config"), testModule.getNamespace());
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
+import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Iterator;
import java.util.Set;
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.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
import org.opendaylight.yangtools.yang.stmt.TestUtils;
+import org.xml.sax.SAXException;
public class YinFileIdentityStmtTest {
- private Set<Module> modules;
+ private SchemaContext context;
@Before
- public void init() throws URISyntaxException, ReactorException {
- modules = TestUtils.loadYinModules(getClass().getResource("/semantic-statement-parser/yin/modules").toURI());
- assertEquals(9, modules.size());
+ public void init() throws URISyntaxException, ReactorException, SAXException, IOException {
+ context = TestUtils.loadYinModules(getClass().getResource("/semantic-statement-parser/yin/modules").toURI());
+ assertEquals(9, context.getModules().size());
}
@Test
public void testIdentity() throws URISyntaxException {
- Module testModule = TestUtils.findModule(modules, "config");
+ Module testModule = TestUtils.findModule(context, "config").get();
assertNotNull(testModule);
Set<IdentitySchemaNode> identities = testModule.getIdentities();
id = idIterator.next();
assertThat(id.getQName().getLocalName(), anyOf(is("module-type"), is("service-type")));
assertNull(id.getBaseIdentity());
-
}
}
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
+import java.io.IOException;
import java.net.URISyntaxException;
import java.text.ParseException;
import java.util.Iterator;
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.api.SchemaContext;
import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
import org.opendaylight.yangtools.yang.stmt.TestUtils;
+import org.xml.sax.SAXException;
public class YinFileImportStmtTest {
- private Set<Module> modules;
+ private SchemaContext context;
@Before
- public void init() throws URISyntaxException, ReactorException {
- modules = TestUtils.loadYinModules(getClass().getResource("/semantic-statement-parser/yin/modules").toURI());
- assertEquals(9, modules.size());
+ public void init() throws URISyntaxException, ReactorException, SAXException, IOException {
+ context = TestUtils.loadYinModules(getClass().getResource("/semantic-statement-parser/yin/modules").toURI());
+ assertEquals(9, context.getModules().size());
}
@Test
public void testImport() throws ParseException {
- Module testModule = TestUtils.findModule(modules, "ietf-netconf-monitoring");
+ Module testModule = TestUtils.findModule(context, "ietf-netconf-monitoring").get();
assertNotNull(testModule);
Set<ModuleImport> imports = testModule.getImports();
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Iterator;
-import java.util.Set;
import org.junit.Before;
import org.junit.Test;
import org.opendaylight.yangtools.yang.model.api.Module;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
import org.opendaylight.yangtools.yang.stmt.TestUtils;
+import org.xml.sax.SAXException;
public class YinFileIncludeStmtTest {
- private Set<Module> modules;
+ private SchemaContext context;
@Before
- public void init() throws URISyntaxException, ReactorException {
- modules = TestUtils.loadYinModules(getClass().getResource
+ public void init() throws URISyntaxException, ReactorException, SAXException, IOException {
+ context = TestUtils.loadYinModules(getClass().getResource
("/semantic-statement-parser/yin/include-belongs-to-test").toURI());
- assertEquals(1, modules.size());
+ assertEquals(1, context.getModules().size());
}
@Test
public void testInclude() throws URISyntaxException {
- Module parentModule = TestUtils.findModule(modules, "parent");
+ Module parentModule = TestUtils.findModule(context, "parent").get();
assertNotNull(parentModule);
assertEquals(1, parentModule.getSubmodules().size());
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
+import java.io.IOException;
import java.net.URISyntaxException;
-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.ContainerSchemaNode;
import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
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;
import org.opendaylight.yangtools.yang.stmt.TestUtils;
+import org.xml.sax.SAXException;
public class YinFileLeafListStmtTest {
- private Set<Module> modules;
+ private SchemaContext context;
@Before
- public void init() throws URISyntaxException, ReactorException {
- modules = TestUtils.loadYinModules(getClass().getResource("/semantic-statement-parser/yin/modules").toURI());
- assertEquals(9, modules.size());
+ public void init() throws URISyntaxException, ReactorException, SAXException, IOException {
+ context = TestUtils.loadYinModules(getClass().getResource("/semantic-statement-parser/yin/modules").toURI());
+ assertEquals(9, context.getModules().size());
}
@Test
public void testLeafList() {
- final Module testModule = TestUtils.findModule(modules, "ietf-netconf-monitoring");
+ final Module testModule = TestUtils.findModule(context, "ietf-netconf-monitoring").get();
assertNotNull(testModule);
ContainerSchemaNode container = (ContainerSchemaNode) testModule.getDataChildByName(QName.create(
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
+import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Collection;
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.LeafSchemaNode;
import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.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.TestUtils;
+import org.xml.sax.SAXException;
public class YinFileListStmtTest {
- private Set<Module> modules;
+ private SchemaContext context;
@Before
- public void init() throws URISyntaxException, ReactorException {
- modules = TestUtils.loadYinModules(getClass().getResource("/semantic-statement-parser/yin/modules").toURI());
- assertEquals(9, modules.size());
+ public void init() throws URISyntaxException, ReactorException, SAXException, IOException {
+ context = TestUtils.loadYinModules(getClass().getResource("/semantic-statement-parser/yin/modules").toURI());
+ assertEquals(9, context.getModules().size());
}
@Test
- public void testListAndLeaves() throws URISyntaxException {
- final Module testModule = TestUtils.findModule(modules, "config");
+ public void testListAndLeaves() {
+ final Module testModule = TestUtils.findModule(context, "config").get();
assertNotNull(testModule);
final ContainerSchemaNode container = (ContainerSchemaNode) testModule.getDataChildByName(QName.create(
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import java.io.IOException;
import java.net.URISyntaxException;
-import java.util.Set;
import org.junit.Before;
import org.junit.Test;
import org.opendaylight.yangtools.yang.model.api.Module;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
import org.opendaylight.yangtools.yang.stmt.TestUtils;
+import org.xml.sax.SAXException;
public class YinFileMetaStmtsTest {
- private Set<Module> modules;
+ private SchemaContext context;
@Before
- public void init() throws URISyntaxException, ReactorException {
- modules = TestUtils.loadYinModules(getClass().getResource("/semantic-statement-parser/yin/modules").toURI());
- assertEquals(9, modules.size());
+ public void init() throws URISyntaxException, ReactorException, SAXException, IOException {
+ context = TestUtils.loadYinModules(getClass().getResource("/semantic-statement-parser/yin/modules").toURI());
+ assertEquals(9, context.getModules().size());
}
@Test
public void testMetaStatements() throws URISyntaxException {
- Module testModule = TestUtils.findModule(modules, "ietf-netconf-monitoring");
+ Module testModule = TestUtils.findModule(context, "ietf-netconf-monitoring").get();
assertNotNull(testModule);
assertEquals("IETF NETCONF (Network Configuration) Working Group", testModule.getOrganization());
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Set;
import org.junit.Before;
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.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
import org.opendaylight.yangtools.yang.stmt.TestUtils;
+import org.xml.sax.SAXException;
public class YinFileRpcStmtTest {
- private Set<Module> modules;
+ private SchemaContext context;
@Before
- public void init() throws URISyntaxException, ReactorException {
- modules = TestUtils.loadYinModules(getClass().getResource
- ("/semantic-statement-parser/yin/modules").toURI());
- assertEquals(9, modules.size());
+ public void init() throws URISyntaxException, ReactorException, SAXException, IOException {
+ context = TestUtils.loadYinModules(getClass().getResource("/semantic-statement-parser/yin/modules").toURI());
+ assertEquals(9, context.getModules().size());
}
@Test
public void testRpc() {
- Module testModule = TestUtils.findModule(modules, "ietf-netconf-monitoring");
- assertNotNull(testModule);
+ Module testModule = TestUtils.findModule(context, "ietf-netconf-monitoring").get();
Set<RpcDefinition> rpcs = testModule.getRpcs();
assertEquals(1, rpcs.size());
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
+import java.io.IOException;
import java.net.URISyntaxException;
-import java.util.Set;
import org.junit.Before;
import org.junit.Test;
-import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.model.repo.api.YinTextSchemaSource;
+import org.opendaylight.yangtools.yang.parser.rfc6020.repo.YinStatementStreamSource;
+import org.opendaylight.yangtools.yang.parser.rfc6020.repo.YinTextToDomTransformer;
import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
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.YinStatementSourceImpl;
import org.opendaylight.yangtools.yang.stmt.TestUtils;
+import org.xml.sax.SAXException;
public class YinFileStmtTest {
private static final StatementStreamSource INVALID_YIN_FILE = createSource("incorrect-foo.yin");
private static final StatementStreamSource INVALID_YIN_FILE_2 = createSource("incorrect-bar.yin");
- private Set<Module> modules;
+ private SchemaContext context;
private static StatementStreamSource createSource(final String name) {
- return new YinStatementSourceImpl("/semantic-statement-parser/yin/" + name, false);
+ try {
+ return YinStatementStreamSource.create(YinTextToDomTransformer.transformSource(
+ YinTextSchemaSource.forResource(YinFileStmtTest.class, "/semantic-statement-parser/yin/" + name)));
+ } catch (SAXException | IOException e) {
+ throw new IllegalArgumentException(e);
+ }
}
@Before
- public void init() throws URISyntaxException, ReactorException {
- modules = TestUtils.loadYinModules(getClass().getResource("/semantic-statement-parser/yin/modules").toURI());
+ public void init() throws URISyntaxException, ReactorException, SAXException, IOException {
+ context = TestUtils.loadYinModules(getClass().getResource("/semantic-statement-parser/yin/modules").toURI());
}
@Test
public void readAndParseYinFileTestModel() throws SourceException, ReactorException {
CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+
addSources(reactor, YIN_FILE, EXT_FILE, EXT_USE_FILE);
SchemaContext result = reactor.buildEffective();
assertNotNull(result);
@Test
public void testModulesSize() {
- assertEquals(modules.size(), 9);
+ assertEquals(context.getModules().size(), 9);
}
private static void addSources(final CrossSourceStatementReactor.BuildAction reactor, final
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Iterator;
import java.util.Set;
import org.junit.Before;
import org.junit.Test;
import org.opendaylight.yangtools.yang.model.api.Module;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
import org.opendaylight.yangtools.yang.stmt.TestUtils;
+import org.xml.sax.SAXException;
public class YinFileTypeDefStmtTest {
- private Set<Module> modules;
+ private SchemaContext context;
@Before
- public void init() throws URISyntaxException, ReactorException {
- modules = TestUtils.loadYinModules(getClass().getResource("/semantic-statement-parser/yin/modules").toURI());
- assertEquals(9, modules.size());
+ public void init() throws URISyntaxException, ReactorException, SAXException, IOException {
+ context = TestUtils.loadYinModules(getClass().getResource("/semantic-statement-parser/yin/modules").toURI());
+ assertEquals(9, context.getModules().size());
}
@Test
- public void testTypedef() throws URISyntaxException {
- Module testModule = TestUtils.findModule(modules, "config");
+ public void testTypedef() {
+ Module testModule = TestUtils.findModule(context, "config").get();
assertNotNull(testModule);
Set<TypeDefinition<?>> typeDefs = testModule.getTypeDefinitions();
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
+import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Iterator;
import java.util.Set;
import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.UsesNode;
import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
import org.opendaylight.yangtools.yang.stmt.TestUtils;
+import org.xml.sax.SAXException;
public class YinFileUsesStmtTest {
- private Set<Module> modules;
+ private SchemaContext context;
@Before
- public void init() throws URISyntaxException, ReactorException {
- modules = TestUtils.loadYinModules(getClass().getResource("/semantic-statement-parser/yin/modules").toURI());
- assertEquals(9, modules.size());
+ public void init() throws URISyntaxException, ReactorException, SAXException, IOException {
+ context = TestUtils.loadYinModules(getClass().getResource("/semantic-statement-parser/yin/modules").toURI());
+ assertEquals(9, context.getModules().size());
}
@Test
public void testUses() {
- final Module testModule = TestUtils.findModule(modules, "main-impl");
+ final Module testModule = TestUtils.findModule(context, "main-impl").get();
assertNotNull(testModule);
final Set<AugmentationSchema> augmentations = testModule.getAugmentations();
package org.opendaylight.yangtools.yang.test.util;
import com.google.common.annotations.Beta;
-import com.google.common.base.Preconditions;
import java.io.File;
import java.io.FileFilter;
-import java.io.FileNotFoundException;
-import java.io.InputStream;
+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 java.util.Set;
+import java.util.stream.Collectors;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.YangConstants;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
import org.opendaylight.yangtools.yang.model.repo.api.StatementParserMode;
+import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
+import org.opendaylight.yangtools.yang.parser.rfc6020.repo.YangStatementStreamSource;
import org.opendaylight.yangtools.yang.parser.rfc6020.repo.YinStatementStreamSource;
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;
-import org.opendaylight.yangtools.yang.parser.util.NamedFileInputStream;
/**
* Utility class which provides convenience methods for producing effective schema context based on the supplied
* Creates a new effective schema context containing the specified YANG source. Statement parser mode is set to
* default mode and all YANG features are supported.
*
- * @param yangSourcePath relative path to the YANG file to be parsed
+ * @param resource relative path to the YANG file to be parsed
*
* @return effective schema context
- *
- * @throws ReactorException if there is an error in the parsed YANG source
- * @throws FileNotFoundException if the specified file does not exist
- * @throws URISyntaxException if the specified file does not exist
*/
- public static SchemaContext parseYangSource(final String yangSourcePath) throws ReactorException,
- FileNotFoundException, URISyntaxException {
- return parseYangSource(yangSourcePath, StatementParserMode.DEFAULT_MODE);
+ public static SchemaContext parseYangResource(final String resource) {
+ return parseYangResource(resource, StatementParserMode.DEFAULT_MODE);
}
/**
- * Creates a new effective schema context containing the specified YANG source. Statement parser mode is set to
- * default mode.
- *
- * @param yangSourcePath relative path to the YANG file to be parsed
- * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
- * model are resolved
+ * Creates a new effective schema context containing the specified YANG source. All YANG features are supported.
*
+ * @param resource relative path to the YANG file to be parsed
+ * @param parserMode mode of statement parser
* @return effective schema context
- *
- * @throws ReactorException if there is an error in the parsed YANG source
- * @throws FileNotFoundException if the specified file does not exist
- * @throws URISyntaxException if the specified file does not exist
*/
- public static SchemaContext parseYangSource(final String yangSourcePath, final Set<QName> supportedFeatures)
- throws ReactorException, FileNotFoundException, URISyntaxException {
- return parseYangSource(yangSourcePath, supportedFeatures, StatementParserMode.DEFAULT_MODE);
+ public static SchemaContext parseYangResource(final String resource, final StatementParserMode parserMode) {
+ return parseYangResource(resource, parserMode, null);
}
/**
- * Creates a new effective schema context containing the specified YANG source. All YANG features are supported.
- *
- * @param yangSourcePath relative path to the YANG file to be parsed
- * @param statementParserMode mode of statement parser
+ * Creates a new effective schema context containing the specified YANG source. Statement parser mode is set to
+ * default mode.
*
+ * @param resource relative path to the YANG file to be parsed
+ * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
+ * model are resolved
* @return effective schema context
- *
- * @throws ReactorException if there is an error in the parsed YANG source
- * @throws FileNotFoundException if the specified file does not exist
- * @throws URISyntaxException if the specified file does not exist
*/
- public static SchemaContext parseYangSource(final String yangSourcePath,
- final StatementParserMode statementParserMode) throws ReactorException, FileNotFoundException,
- URISyntaxException {
- return parseYangSource(yangSourcePath, null, statementParserMode);
+ public static SchemaContext parseYangResource(final String resource, final Set<QName> supportedFeatures) {
+ return parseYangResource(resource, StatementParserMode.DEFAULT_MODE, supportedFeatures);
}
/**
* Creates a new effective schema context containing the specified YANG source.
*
- * @param yangSourcePath relative path to the YANG file to be parsed
+ * @param resource relative path to the YANG file to be parsed
* @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
* model are resolved
- * @param statementParserMode mode of statement parser
- *
+ * @param parserMode mode of statement parser
* @return effective schema context
- *
- * @throws ReactorException if there is an error in the parsed YANG source
- * @throws FileNotFoundException if the specified file does not exist
- * @throws URISyntaxException if the specified file does not exist
*/
- public static SchemaContext parseYangSource(final String yangSourcePath, final Set<QName> supportedFeatures,
- final StatementParserMode statementParserMode) throws ReactorException, FileNotFoundException,
- URISyntaxException {
- final URI sourcePath = YangParserTestUtils.class.getResource(yangSourcePath).toURI();
- final File sourceFile = new File(sourcePath);
- return parseYangSources(supportedFeatures, statementParserMode, sourceFile);
+ public static SchemaContext parseYangResource(final String resource, final StatementParserMode parserMode,
+ final Set<QName> supportedFeatures) {
+ final YangTextSchemaSource source = YangTextSchemaSource.forResource(YangParserTestUtils.class, resource);
+ return parseYangSources(parserMode, supportedFeatures, source);
}
/**
* Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
* default mode and all YANG features are supported.
*
- * @param sources YANG sources to be parsed
- *
- * @return effective schema context
- *
- * @throws ReactorException if there is an error in one of the parsed YANG sources
- *
- * @deprecated Migration method only, do not use.
- */
- @Deprecated
- public static SchemaContext parseYangSources(final YangStatementSourceImpl... sources) throws ReactorException {
- return parseYangSources(StatementParserMode.DEFAULT_MODE, sources);
- }
-
- /**
- * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
- * default mode.
- *
- * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
- * models are resolved
- * @param sources YANG sources to be parsed
- *
- * @return effective schema context
- * @throws ReactorException if there is an error in one of the parsed YANG sources
- *
- * @deprecated Migration method only, do not use.
- */
- @Deprecated
- public static SchemaContext parseYangSources(final Set<QName> supportedFeatures,
- final YangStatementSourceImpl... sources) throws ReactorException {
- return parseYangSources(supportedFeatures, StatementParserMode.DEFAULT_MODE, sources);
- }
-
- /**
- * Creates a new effective schema context containing the specified YANG sources. All YANG features are supported.
- *
- * @param statementParserMode mode of statement parser
- * @param sources YANG sources to be parsed
- *
- * @return effective schema context
- * @throws ReactorException if there is an error in one of the parsed YANG sources
- *
- * @deprecated Migration method only, do not use.
- */
- @Deprecated
- public static SchemaContext parseYangSources(final StatementParserMode statementParserMode,
- final YangStatementSourceImpl... sources) throws ReactorException {
- return parseYangSources(null, statementParserMode, sources);
- }
-
- /**
- * Creates a new effective schema context containing the specified YANG sources.
- *
- * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
- * models are resolved
- * @param statementParserMode mode of statement parser
- * @param sources YANG sources to be parsed
- *
+ * @param files YANG files to be parsed
* @return effective schema context
- *
- * @throws ReactorException if there is an error in one of the parsed YANG sources
*/
- public static SchemaContext parseYangSources(final Set<QName> supportedFeatures,
- final StatementParserMode statementParserMode, final YangStatementSourceImpl... sources)
- throws ReactorException {
- final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild(
- statementParserMode, supportedFeatures);
- reactor.addSources(sources);
-
- return reactor.buildEffective();
+ public static SchemaContext parseYangFiles(final File... files) {
+ return parseYangFiles(Arrays.asList(files));
}
/**
* Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
* default mode and all YANG features are supported.
*
- * @param files YANG files to be parsed
- *
+ * @param files collection of YANG files to be parsed
* @return effective schema context
- *
- * @throws ReactorException if there is an error in one of the parsed YANG sources
- * @throws FileNotFoundException if one of the specified files does not exist
*/
- public static SchemaContext parseYangSources(final File... files) throws ReactorException, FileNotFoundException {
- return parseYangSources(StatementParserMode.DEFAULT_MODE, files);
+ public static SchemaContext parseYangFiles(final Collection<File> files) {
+ return parseYangFiles(StatementParserMode.DEFAULT_MODE, files);
}
/**
* @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
* models are resolved
* @param files YANG files to be parsed
- *
* @return effective schema context
- *
- * @throws ReactorException if there is an error in one of the parsed YANG sources
- * @throws FileNotFoundException if one of the specified files does not exist
*/
- public static SchemaContext parseYangSources(final Set<QName> supportedFeatures, final File... files)
- throws ReactorException, FileNotFoundException {
- return parseYangSources(supportedFeatures, StatementParserMode.DEFAULT_MODE, files);
+ public static SchemaContext parseYangFiles(final Set<QName> supportedFeatures, final File... files) {
+ return parseYangFiles(supportedFeatures, Arrays.asList(files));
}
- /**
- * Creates a new effective schema context containing the specified YANG sources. All YANG features are supported.
- *
- * @param statementParserMode mode of statement parser
- * @param files YANG files to be parsed
- *
- * @return effective schema context
- *
- * @throws ReactorException if there is an error in one of the parsed YANG sources
- * @throws FileNotFoundException if one of the specified files does not exist
- */
- public static SchemaContext parseYangSources(final StatementParserMode statementParserMode, final File... files)
- throws ReactorException, FileNotFoundException {
- return parseYangSources(null, statementParserMode, files);
+ public static SchemaContext parseYangFiles(final Set<QName> supportedFeatures, final Collection<File> files) {
+ return parseYangFiles(supportedFeatures, StatementParserMode.DEFAULT_MODE, files);
}
/**
- * Creates a new effective schema context containing the specified YANG sources.
+ * Creates a new effective schema context containing the specified YANG sources. All YANG features are supported.
*
- * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
- * models are resolved
- * @param statementParserMode mode of statement parser
+ * @param parserMode mode of statement parser
* @param files YANG files to be parsed
- *
* @return effective schema context
- *
- * @throws ReactorException if there is an error in one of the parsed YANG sources
- * @throws FileNotFoundException if one of the specified files does not exist
*/
- public static SchemaContext parseYangSources(final Set<QName> supportedFeatures,
- final StatementParserMode statementParserMode, final File... files) throws ReactorException,
- FileNotFoundException {
- final YangStatementSourceImpl[] sources = new YangStatementSourceImpl[files.length];
- for (int i = 0; i < files.length; i++) {
- sources[i] = new YangStatementSourceImpl(new NamedFileInputStream(files[i], files[i].getPath()));
- }
-
- return parseYangSources(supportedFeatures, statementParserMode, sources);
- }
-
- /**
- * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
- * default mode and all YANG features are supported.
- *
- * @param files collection of YANG files to be parsed
- *
- * @return effective schema context
- *
- * @throws ReactorException if there is an error in one of the parsed YANG sources
- * @throws FileNotFoundException if one of the specified files does not exist
- */
- public static SchemaContext parseYangSources(final Collection<File> files) throws ReactorException,
- FileNotFoundException {
- return parseYangSources(files, StatementParserMode.DEFAULT_MODE);
- }
-
- /**
- * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
- * default mode.
- *
- * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
- * models are resolved
- * @param files collection of YANG files to be parsed
- *
- * @return effective schema context
- *
- * @throws ReactorException if there is an error in one of the parsed YANG sources
- * @throws FileNotFoundException if one of the specified files does not exist
- */
- public static SchemaContext parseYangSources(final Collection<File> files, final Set<QName> supportedFeatures)
- throws ReactorException, FileNotFoundException {
- return parseYangSources(files, supportedFeatures, StatementParserMode.DEFAULT_MODE);
+ public static SchemaContext parseYangFiles(final StatementParserMode parserMode, final File... files) {
+ return parseYangFiles(parserMode, Arrays.asList(files));
}
/**
* Creates a new effective schema context containing the specified YANG sources. All YANG features are supported.
*
- * @param statementParserMode mode of statement parser
+ * @param parserMode mode of statement parser
* @param files collection of YANG files to be parsed
- *
* @return effective schema context
- *
- * @throws ReactorException if there is an error in one of the parsed YANG sources
- * @throws FileNotFoundException if one of the specified files does not exist
*/
- public static SchemaContext parseYangSources(final Collection<File> files,
- final StatementParserMode statementParserMode) throws ReactorException, FileNotFoundException {
- return parseYangSources(files, null, statementParserMode);
+ public static SchemaContext parseYangFiles(final StatementParserMode parserMode, final Collection<File> files) {
+ return parseYangFiles(null, parserMode, files);
}
/**
*
* @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
* models are resolved
- * @param statementParserMode mode of statement parser
- * @param files collection of YANG files to be parsed
- *
- * @return effective schema context
- *
- * @throws ReactorException if there is an error in one of the parsed YANG sources
- * @throws FileNotFoundException if one of the specified files does not exist
- */
- public static SchemaContext parseYangSources(final Collection<File> files, final Set<QName> supportedFeatures,
- final StatementParserMode statementParserMode) throws ReactorException, FileNotFoundException {
- return parseYangSources(supportedFeatures, statementParserMode, files.toArray(new File[files.size()]));
- }
-
- /**
- * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
- * default mode and all YANG features are supported.
- *
- * @param yangSourcesDirectoryPath relative path to the directory with YANG files to be parsed
- *
- * @return effective schema context
- *
- * @throws ReactorException if there is an error in one of the parsed YANG sources
- * @throws FileNotFoundException if the specified directory does not exist
- * @throws URISyntaxException if the specified directory does not exist
- */
- public static SchemaContext parseYangSources(final String yangSourcesDirectoryPath) throws ReactorException,
- FileNotFoundException, URISyntaxException {
- return parseYangSources(yangSourcesDirectoryPath, StatementParserMode.DEFAULT_MODE);
- }
-
- /**
- * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
- * default mode.
- *
- * @param yangSourcesDirectoryPath relative path to the directory with YANG files to be parsed
- * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
- * models are resolved
- *
- * @return effective schema context
- *
- * @throws ReactorException if there is an error in one of the parsed YANG sources
- * @throws FileNotFoundException if the specified directory does not exist
- * @throws URISyntaxException if the specified directory does not exist
- */
- public static SchemaContext parseYangSources(final String yangSourcesDirectoryPath,
- final Set<QName> supportedFeatures) throws ReactorException, FileNotFoundException,
- URISyntaxException {
- return parseYangSources(yangSourcesDirectoryPath, supportedFeatures, StatementParserMode.DEFAULT_MODE);
- }
-
- /**
- * Creates a new effective schema context containing the specified YANG sources. All YANG features are supported.
- *
- * @param yangSourcesDirectoryPath relative path to the directory with YANG files to be parsed
- * @param statementParserMode mode of statement parser
- *
+ * @param parserMode mode of statement parser
+ * @param files YANG files to be parsed
* @return effective schema context
- *
- * @throws ReactorException if there is an error in one of the parsed YANG sources
- * @throws FileNotFoundException if the specified directory does not exist
- * @throws URISyntaxException if the specified directory does not exist
*/
- public static SchemaContext parseYangSources(final String yangSourcesDirectoryPath,
- final StatementParserMode statementParserMode) throws ReactorException, FileNotFoundException,
- URISyntaxException {
- return parseYangSources(yangSourcesDirectoryPath, null, statementParserMode);
+ public static SchemaContext parseYangFiles(final Set<QName> supportedFeatures,
+ final StatementParserMode parserMode, final File... files) {
+ return parseYangFiles(supportedFeatures, parserMode, Arrays.asList(files));
}
/**
* Creates a new effective schema context containing the specified YANG sources.
*
- * @param yangSourcesDirectoryPath relative path to the directory with YANG files to be parsed
* @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
* models are resolved
- * @param statementParserMode mode of statement parser
- *
+ * @param parserMode mode of statement parser
+ * @param files YANG files to be parsed
* @return effective schema context
- *
- * @throws ReactorException if there is an error in one of the parsed YANG sources
- * @throws FileNotFoundException if the specified directory does not exist
- * @throws URISyntaxException if the specified directory does not exist
*/
- public static SchemaContext parseYangSources(final String yangSourcesDirectoryPath,
- final Set<QName> supportedFeatures, final StatementParserMode statementParserMode)
- throws ReactorException, FileNotFoundException, URISyntaxException {
- final URI directoryPath = YangParserTestUtils.class.getResource(yangSourcesDirectoryPath).toURI();
- final File dir = new File(directoryPath);
-
- return parseYangSources(supportedFeatures, statementParserMode, dir.listFiles(YANG_FILE_FILTER));
+ public static SchemaContext parseYangFiles(final Set<QName> supportedFeatures,
+ final StatementParserMode parserMode, final Collection<File> files) {
+ return parseYangSources(supportedFeatures, parserMode,
+ files.stream().map(YangTextSchemaSource::forFile).collect(Collectors.toList()));
}
/**
* Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
* default mode and all YANG features are supported.
*
- * @param yangDirs relative paths to the directories containing YANG files to be parsed
- * @param yangFiles relative paths to the YANG files to be parsed
- *
+ * @param resourcePath relative path to the directory with YANG files to be parsed
* @return effective schema context
- *
- * @throws ReactorException if there is an error in one of the parsed YANG sources
- * @throws FileNotFoundException if one of the specified directories or files does not exist
- * @throws URISyntaxException if one of the specified directories or files does not exist
*/
- public static SchemaContext parseYangSources(final List<String> yangDirs, final List<String> yangFiles)
- throws FileNotFoundException, ReactorException, URISyntaxException {
- return parseYangSources(yangDirs, yangFiles, StatementParserMode.DEFAULT_MODE);
- }
-
- /**
- * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
- * default mode.
- *
- * @param yangDirs relative paths to the directories containing YANG files to be parsed
- * @param yangFiles relative paths to the YANG files to be parsed
- * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
- * models are resolved
- *
- * @return effective schema context
- *
- * @throws ReactorException if there is an error in one of the parsed YANG sources
- * @throws FileNotFoundException if one of the specified directories or files does not exist
- * @throws URISyntaxException if one of the specified directories or files does not exist
- */
- public static SchemaContext parseYangSources(final List<String> yangDirs, final List<String> yangFiles,
- final Set<QName> supportedFeatures) throws FileNotFoundException, ReactorException,
- URISyntaxException {
- return parseYangSources(yangDirs, yangFiles, supportedFeatures, StatementParserMode.DEFAULT_MODE);
+ public static SchemaContext parseYangResourceDirectory(final String resourcePath) {
+ return parseYangResourceDirectory(resourcePath, StatementParserMode.DEFAULT_MODE);
}
/**
* Creates a new effective schema context containing the specified YANG sources. All YANG features are supported.
*
- * @param yangDirs relative paths to the directories containing YANG files to be parsed
- * @param yangFiles relative paths to the YANG files to be parsed
- * @param statementParserMode mode of statement parser
- *
+ * @param resourcePath relative path to the directory with YANG files to be parsed
+ * @param parserMode mode of statement parser
* @return effective schema context
- *
- * @throws ReactorException if there is an error in one of the parsed YANG sources
- * @throws FileNotFoundException if one of the specified directories or files does not exist
- * @throws URISyntaxException if one of the specified directories or files does not exist
*/
- public static SchemaContext parseYangSources(final List<String> yangDirs, final List<String> yangFiles,
- final StatementParserMode statementParserMode) throws FileNotFoundException, ReactorException,
- URISyntaxException {
- return parseYangSources(yangDirs, yangFiles, null, statementParserMode);
- }
-
- /**
- * Creates a new effective schema context containing the specified YANG sources.
- *
- * @param yangDirs relative paths to the directories containing YANG files to be parsed
- * @param yangFiles relative paths to the YANG files to be parsed
- * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
- * models are resolved
- * @param statementParserMode mode of statement parser
- *
- * @return effective schema context
- *
- * @throws ReactorException if there is an error in one of the parsed YANG sources
- * @throws FileNotFoundException if one of the specified directories or files does not exist
- * @throws URISyntaxException if one of the specified directories or files does not exist
- */
- public static SchemaContext parseYangSources(final List<String> yangDirs, final List<String> yangFiles,
- final Set<QName> supportedFeatures, final StatementParserMode statementParserMode)
- throws FileNotFoundException, ReactorException, URISyntaxException {
- final List<File> allYangFiles = new ArrayList<>();
- for (final String yangDir : yangDirs) {
- allYangFiles.addAll(getYangFiles(yangDir));
- }
-
- for (final String yangFile : yangFiles) {
- final URI filePath = YangParserTestUtils.class.getResource(yangFile).toURI();
- allYangFiles.add(new File(filePath));
- }
-
- return parseYangSources(allYangFiles, supportedFeatures, statementParserMode);
- }
-
- /**
- * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
- * default mode and all YANG features are supported.
- *
- * @param filePaths relative paths to the YANG files to be parsed
- *
- * @return effective schema context
- *
- * @throws ReactorException if there is an error in one of the parsed YANG sources
- */
- public static SchemaContext parseYangSources(final List<String> filePaths) throws ReactorException {
- return parseYangSources(filePaths, StatementParserMode.DEFAULT_MODE);
+ public static SchemaContext parseYangResourceDirectory(final String resourcePath,
+ final StatementParserMode parserMode) {
+ return parseYangResourceDirectory(resourcePath, null, parserMode);
}
/**
* Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
* default mode.
*
+ * @param resourcePath relative path to the directory with YANG files to be parsed
* @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
* models are resolved
- * @param filePaths relative paths to the YANG files to be parsed
- *
- * @return effective schema context
- *
- * @throws ReactorException if there is an error in one of the parsed YANG sources
- */
- public static SchemaContext parseYangSources(final List<String> filePaths, final Set<QName> supportedFeatures)
- throws ReactorException {
- return parseYangSources(filePaths, supportedFeatures, StatementParserMode.DEFAULT_MODE);
- }
-
- /**
- * Creates a new effective schema context containing the specified YANG sources. All YANG features are supported.
- *
- * @param statementParserMode mode of statement parser
- * @param filePaths relative paths to the YANG files to be parsed
- *
* @return effective schema context
- *
- * @throws ReactorException if there is an error in one of the parsed YANG sources
*/
- public static SchemaContext parseYangSources(final List<String> filePaths,
- final StatementParserMode statementParserMode) throws ReactorException {
- return parseYangSources(filePaths, (Set<QName>) null, statementParserMode);
+ public static SchemaContext parseYangResourceDirectory(final String resourcePath,
+ final Set<QName> supportedFeatures) {
+ return parseYangResourceDirectory(resourcePath, supportedFeatures, StatementParserMode.DEFAULT_MODE);
}
/**
* Creates a new effective schema context containing the specified YANG sources.
*
+ * @param resourcePath relative path to the directory with YANG files to be parsed
* @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
* models are resolved
- * @param statementParserMode mode of statement parser
- * @param filePaths relative paths to the YANG files to be parsed
- *
+ * @param parserMode mode of statement parser
* @return effective schema context
- *
- * @throws ReactorException if there is an error in one of the parsed YANG sources
*/
- public static SchemaContext parseYangSources(final List<String> filePaths,
- final Set<QName> supportedFeatures, final StatementParserMode statementParserMode)
- throws ReactorException {
- final YangStatementSourceImpl[] sources = new YangStatementSourceImpl[filePaths.size()];
-
- for (int i = 0; i < filePaths.size(); i++) {
- sources[i] = new YangStatementSourceImpl(YangParserTestUtils.class.getResourceAsStream(filePaths.get(i)));
+ public static SchemaContext parseYangResourceDirectory(final String resourcePath,
+ final Set<QName> supportedFeatures, final StatementParserMode parserMode) {
+ final URI directoryPath;
+ try {
+ directoryPath = YangParserTestUtils.class.getResource(resourcePath).toURI();
+ } catch (URISyntaxException e) {
+ throw new IllegalArgumentException("Failed to open resource " + resourcePath, e);
}
-
- return parseYangSources(supportedFeatures, statementParserMode, sources);
+ return parseYangFiles(supportedFeatures, parserMode, new File(directoryPath).listFiles(YANG_FILE_FILTER));
}
/**
* Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
* default mode and all YANG features are supported.
*
- * @param streams input streams containing YANG sources to be parsed
- *
+ * @param clazz Resource lookup base
+ * @param resources Resource names to be looked up
* @return effective schema context
- *
- * @throws ReactorException if there is an error in one of the parsed YANG sources
*/
- public static SchemaContext parseYangStreams(final List<InputStream> streams) throws ReactorException {
- return parseYangStreams(streams, StatementParserMode.DEFAULT_MODE);
+ public static SchemaContext parseYangResources(final Class<?> clazz, final String... resources) {
+ final List<YangTextSchemaSource> sources = new ArrayList<>(resources.length);
+ for (final String r : resources) {
+ sources.add(YangTextSchemaSource.forResource(clazz, r));
+ }
+ return parseYangSources(null, StatementParserMode.DEFAULT_MODE, sources);
}
/**
* Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
* default mode.
*
- * @param streams input streams containing YANG sources to be parsed
+ * @param yangDirs relative paths to the directories containing YANG files to be parsed
+ * @param yangFiles relative paths to the YANG files to be parsed
* @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
* models are resolved
- *
* @return effective schema context
- *
- * @throws ReactorException if there is an error in one of the parsed YANG sources
*/
- public static SchemaContext parseYangStreams(final List<InputStream> streams, final Set<QName> supportedFeatures)
- throws ReactorException {
- return parseYangStreams(streams, supportedFeatures, StatementParserMode.DEFAULT_MODE);
+ public static SchemaContext parseYangResources(final List<String> yangDirs, final List<String> yangFiles,
+ final Set<QName> supportedFeatures) {
+ return parseYangResources(yangDirs, yangFiles, supportedFeatures, StatementParserMode.DEFAULT_MODE);
}
/**
* Creates a new effective schema context containing the specified YANG sources. All YANG features are supported.
*
- * @param streams input streams containing YANG sources to be parsed
+ * @param yangResourceDirs relative paths to the directories containing YANG files to be parsed
+ * @param yangResources relative paths to the YANG files to be parsed
* @param statementParserMode mode of statement parser
- *
* @return effective schema context
- *
- * @throws ReactorException if there is an error in one of the parsed YANG sources
*/
- public static SchemaContext parseYangStreams(final List<InputStream> streams,
- final StatementParserMode statementParserMode) throws ReactorException {
- return parseYangStreams(streams, null, statementParserMode);
+ public static SchemaContext parseYangResources(final List<String> yangResourceDirs,
+ final List<String> yangResources, final StatementParserMode statementParserMode) {
+ return parseYangResources(yangResourceDirs, yangResources, null, statementParserMode);
}
/**
* Creates a new effective schema context containing the specified YANG sources.
*
+ * @param yangResourceDirs relative paths to the directories containing YANG files to be parsed
+ * @param yangResources relative paths to the YANG files to be parsed
* @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
* models are resolved
* @param statementParserMode mode of statement parser
- * @param streams input streams containing YANG sources to be parsed
- *
- * @return effective schema context
- *
- * @throws ReactorException if there is an error in one of the parsed YANG sources
- */
- public static SchemaContext parseYangStreams(final List<InputStream> streams, final Set<QName> supportedFeatures,
- final StatementParserMode statementParserMode) throws ReactorException {
- final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild(
- statementParserMode, supportedFeatures);
- return reactor.buildEffective(streams);
- }
-
- /**
- * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
- * default mode and all YANG features are supported.
- *
- * @param streams input streams containing YANG sources to be parsed
- *
* @return effective schema context
- *
- * @throws ReactorException if there is an error in one of the parsed YANG sources
*/
- public static SchemaContext parseYangStreams(final InputStream... streams) throws ReactorException {
- return parseYangStreams(Arrays.asList(streams));
- }
+ public static SchemaContext parseYangResources(final List<String> yangResourceDirs,
+ final List<String> yangResources, final Set<QName> supportedFeatures,
+ final StatementParserMode statementParserMode) {
+ final List<File> allYangFiles = new ArrayList<>();
+ for (final String yangDir : yangResourceDirs) {
+ allYangFiles.addAll(getYangFiles(yangDir));
+ }
- /**
- * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
- * default mode.
- *
- * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
- * models are resolved
- * @param streams input streams containing YANG sources to be parsed
- *
- * @return effective schema context
- *
- * @throws ReactorException if there is an error in one of the parsed YANG sources
- */
- public static SchemaContext parseYangStreams(final Set<QName> supportedFeatures,
- final InputStream... streams) throws ReactorException {
- return parseYangStreams(Arrays.asList(streams), supportedFeatures);
- }
+ for (final String yangFile : yangResources) {
+ try {
+ allYangFiles.add(new File(YangParserTestUtils.class.getResource(yangFile).toURI()));
+ } catch (URISyntaxException e) {
+ throw new IllegalArgumentException("Invalid resource " + yangFile, e);
+ }
+ }
- /**
- * Creates a new effective schema context containing the specified YANG sources. All YANG features are supported.
- *
- * @param statementParserMode mode of statement parser
- * @param streams input streams containing YANG sources to be parsed
- *
- * @return effective schema context
- *
- * @throws ReactorException if there is an error in one of the parsed YANG sources
- */
- public static SchemaContext parseYangStreams(final StatementParserMode statementParserMode,
- final InputStream... streams) throws ReactorException {
- return parseYangStreams(Arrays.asList(streams), statementParserMode);
+ return parseYangFiles(supportedFeatures, statementParserMode, allYangFiles);
}
- /**
- * Creates a new effective schema context containing the specified YANG sources.
- *
- * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
- * models are resolved
- * @param statementParserMode mode of statement parser
- * @param streams input streams containing YANG sources to be parsed
- *
- * @return effective schema context
- *
- * @throws ReactorException if there is an error in one of the parsed YANG sources
- */
- public static SchemaContext parseYangStreams(final Set<QName> supportedFeatures,
- final StatementParserMode statementParserMode, final InputStream... streams) throws ReactorException {
- return parseYangStreams(Arrays.asList(streams), supportedFeatures, statementParserMode);
+ public static SchemaContext parseYangSources(final StatementParserMode parserMode,
+ final Set<QName> supportedFeatures, final YangTextSchemaSource... sources) {
+ return parseYangSources(supportedFeatures, parserMode, Arrays.asList(sources));
}
- /**
- * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to
- * default mode and all YANG features are supported.
- *
- * @param clazz Resource lookup base
- * @param resources Resource names to be looked up
- *
- * @return effective schema context
- *
- * @throws ReactorException if there is an error in one of the parsed YANG sources
- */
- public static SchemaContext parseYangResources(final Class<?> clazz, final String... resources)
- throws ReactorException {
- final List<InputStream> streams = new ArrayList<>(resources.length);
- for (final String r : resources) {
- final InputStream is = clazz.getResourceAsStream(r);
- Preconditions.checkArgument(is != null, "Resource %s not found", r);
- streams.add(is);
+ public static SchemaContext parseYangSources(final Set<QName> supportedFeatures,
+ final StatementParserMode parserMode, final Collection<? extends YangTextSchemaSource> sources) {
+ final Collection<YangStatementStreamSource> streams = new ArrayList<>(sources.size());
+ for (YangTextSchemaSource source : sources) {
+ try {
+ streams.add(YangStatementStreamSource.create(source));
+ } catch (IOException e) {
+ throw new IllegalArgumentException("Failed to read source " + source, e);
+ } catch (YangSyntaxErrorException e) {
+ throw new IllegalArgumentException("Malformed source " + source, e);
+ }
}
- return parseYangStreams(streams);
+ return parseSources(supportedFeatures, parserMode, streams);
}
/**
* default mode and all YANG features are supported.
*
* @param sources YIN sources to be parsed
- *
* @return effective schema context
- *
- * @throws ReactorException if there is an error in one of the parsed YIN sources
*/
- public static SchemaContext parseYinSources(final YinStatementStreamSource... sources) throws ReactorException {
+ public static SchemaContext parseYinSources(final YinStatementStreamSource... sources) {
return parseYinSources(StatementParserMode.DEFAULT_MODE, sources);
}
*/
public static SchemaContext parseYinSources(final Set<QName> supportedFeatures,
final YinStatementStreamSource... sources) throws ReactorException {
- return parseYinSources(supportedFeatures, StatementParserMode.DEFAULT_MODE, sources);
+ return parseSources(supportedFeatures, StatementParserMode.DEFAULT_MODE, sources);
}
/**
*
* @param statementParserMode mode of statement parser
* @param sources YIN sources to be parsed
- *
* @return effective schema context
- *
- * @throws ReactorException if there is an error in one of the parsed YIN sources
*/
public static SchemaContext parseYinSources(final StatementParserMode statementParserMode,
- final YinStatementStreamSource... sources) throws ReactorException {
- return parseYinSources(null, statementParserMode, sources);
+ final YinStatementStreamSource... sources) {
+ return parseSources(null, statementParserMode, sources);
+ }
+
+ /**
+ * Creates a new effective schema context containing the specified YANG sources.
+ *
+ * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
+ * models are resolved
+ * @param parserMode mode of statement parser
+ * @param sources sources to be parsed
+ *
+ * @return effective schema context
+ */
+ public static SchemaContext parseSources(final Set<QName> supportedFeatures,
+ final StatementParserMode parserMode, final StatementStreamSource... sources) {
+ return parseSources(supportedFeatures, parserMode, Arrays.asList(sources));
}
/**
- * Creates a new effective schema context containing the specified YIN sources.
+ * Creates a new effective schema context containing the specified YANG sources.
*
- * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YIN
+ * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG
* models are resolved
* @param statementParserMode mode of statement parser
- * @param sources YIN sources to be parsed
+ * @param sources sources to be parsed
*
* @return effective schema context
- *
- * @throws ReactorException if there is an error in one of the parsed YIN sources
*/
- public static SchemaContext parseYinSources(final Set<QName> supportedFeatures,
- final StatementParserMode statementParserMode, final YinStatementStreamSource... sources)
- throws ReactorException {
+ public static SchemaContext parseSources(final Set<QName> supportedFeatures,
+ final StatementParserMode statementParserMode, final Collection<? extends StatementStreamSource> sources) {
final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild(
- statementParserMode, supportedFeatures);
+ statementParserMode);
+ if (supportedFeatures != null) {
+ reactor.setSupportedFeatures(supportedFeatures);
+ }
reactor.addSources(sources);
- return reactor.buildEffective();
+ try {
+ return reactor.buildEffective();
+ } catch (ReactorException e) {
+ throw new IllegalStateException(e);
+ }
}
- private static Collection<File> getYangFiles(final String yangSourcesDirectoryPath) throws URISyntaxException {
- final URI directoryPath = YangParserTestUtils.class.getResource(yangSourcesDirectoryPath).toURI();
- final File dir = new File(directoryPath);
-
- return Arrays.asList(dir.listFiles(YANG_FILE_FILTER));
+ private static Collection<File> getYangFiles(final String resourcePath) {
+ final URI directoryPath;
+ try {
+ directoryPath = YangParserTestUtils.class.getResource(resourcePath).toURI();
+ } catch (URISyntaxException e) {
+ throw new IllegalArgumentException("Failed to open resource directory " + resourcePath, e);
+ }
+ return Arrays.asList(new File(directoryPath).listFiles(YANG_FILE_FILTER));
}
}