本文整理汇总了Java中org.opendaylight.yangtools.yang.test.util.YangParserTestUtils.parseYangResource方法的典型用法代码示例。如果您正苦于以下问题:Java YangParserTestUtils.parseYangResource方法的具体用法?Java YangParserTestUtils.parseYangResource怎么用?Java YangParserTestUtils.parseYangResource使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.opendaylight.yangtools.yang.test.util.YangParserTestUtils
的用法示例。
在下文中一共展示了YangParserTestUtils.parseYangResource方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; //导入方法依赖的package包/类
@Test
public void test() throws Exception {
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())));
final DataContainerChild<? extends PathArgument, ?> inputStructure = ImmutableContainerNodeBuilder.create()
.withNodeIdentifier(new NodeIdentifier(qN("my-name")))
.withChild(ImmutableNodes.leafNode(new NodeIdentifier(qN("my-name")), "my-value")).build();
final SchemaPath rootPath = SchemaPath.create(true, qN("my-name"), qN("input"));
final Writer writer = new StringWriter();
final String jsonOutput = normalizedNodeToJsonStreamTransformation(schemaContext, rootPath, writer,
inputStructure);
final JsonElement serializedJson = parser.parse(jsonOutput);
assertEquals(expextedJson, serializedJson);
}
示例2: test
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; //导入方法依赖的package包/类
@Test
public void test() throws Exception {
final SchemaContext schema = YangParserTestUtils.parseYangResource("/bugs/bug2444/yang/notification.yang");
assertNotNull(schema);
final File outDir = new File("target/bug2444-export");
outDir.mkdirs();
for (final Module module : schema.getModules()) {
exportModule(schema, module, outDir);
final OutputStream byteArrayOutputStream = new ByteArrayOutputStream();
final BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(byteArrayOutputStream);
try {
writeModuleToOutputStream(schema, module, bufferedOutputStream, false);
final String output = byteArrayOutputStream.toString();
assertNotNull(output);
assertNotEquals(0, output.length());
final Document doc = YinExportTestUtils.loadDocument("/bugs/bug2444/yin-effective-emitter", module);
assertXMLEquals(module.getName(), doc, output);
} finally {
byteArrayOutputStream.close();
bufferedOutputStream.close();
}
}
}
示例3: testInstanceIdentifierPathWithEmptyListKey
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; //导入方法依赖的package包/类
@Test
public void testInstanceIdentifierPathWithEmptyListKey() throws Exception {
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"));
assertNotNull(topCont);
final InputStream resourceAsStream = Bug8083Test.class.getResourceAsStream("/bug8083/xml/baz.xml");
final XMLInputFactory factory = XMLInputFactory.newInstance();
final XMLStreamReader reader = factory.createXMLStreamReader(resourceAsStream);
// deserialization
final NormalizedNodeResult result = new NormalizedNodeResult();
final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result);
final XmlParserStream xmlParser = XmlParserStream.create(streamWriter, schemaContext, topCont);
xmlParser.parse(reader);
final NormalizedNode<?, ?> transformedInput = result.getResult();
assertNotNull(transformedInput);
}
示例4: testInstanceIdentifierPathWithIdentityrefListKey
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; //导入方法依赖的package包/类
@Test
public void testInstanceIdentifierPathWithIdentityrefListKey() throws Exception {
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"));
assertNotNull(topCont);
final InputStream resourceAsStream = Bug8083Test.class.getResourceAsStream("/bug8083/xml/zab.xml");
final XMLInputFactory factory = XMLInputFactory.newInstance();
final XMLStreamReader reader = factory.createXMLStreamReader(resourceAsStream);
// deserialization
final NormalizedNodeResult result = new NormalizedNodeResult();
final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result);
final XmlParserStream xmlParser = XmlParserStream.create(streamWriter, schemaContext, topCont);
xmlParser.parse(reader);
final NormalizedNode<?, ?> transformedInput = result.getResult();
assertNotNull(transformedInput);
}
示例5: testInstanceIdentifierPathWithEmptyListKey
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; //导入方法依赖的package包/类
@Test
public void testInstanceIdentifierPathWithEmptyListKey() throws IOException, URISyntaxException {
final SchemaContext schemaContext = YangParserTestUtils.parseYangResource("/bug8083/yang/baz.yang");
final String inputJson = loadTextFile("/bug8083/json/baz.json");
// deserialization
final NormalizedNodeResult result = new NormalizedNodeResult();
final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result);
final JsonParserStream jsonParser = JsonParserStream.create(streamWriter,
JSONCodecFactorySupplier.DRAFT_LHOTKA_NETMOD_YANG_JSON_02.getShared(schemaContext));
jsonParser.parse(new JsonReader(new StringReader(inputJson)));
final NormalizedNode<?, ?> transformedInput = result.getResult();
assertNotNull(transformedInput);
}
示例6: testInstanceIdentifierPathWithIdentityrefListKey
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; //导入方法依赖的package包/类
@Test
public void testInstanceIdentifierPathWithIdentityrefListKey() throws IOException, URISyntaxException {
final SchemaContext schemaContext = YangParserTestUtils.parseYangResource("/bug8083/yang/zab.yang");
final String inputJson = loadTextFile("/bug8083/json/zab.json");
// deserialization
final NormalizedNodeResult result = new NormalizedNodeResult();
final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result);
final JsonParserStream jsonParser = JsonParserStream.create(streamWriter,
JSONCodecFactorySupplier.DRAFT_LHOTKA_NETMOD_YANG_JSON_02.getShared(schemaContext));
jsonParser.parse(new JsonReader(new StringReader(inputJson)));
final NormalizedNode<?, ?> transformedInput = result.getResult();
assertNotNull(transformedInput);
}
示例7: testInstanceIdentifierPathWithInstanceIdentifierListKey
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; //导入方法依赖的package包/类
@Test
public void testInstanceIdentifierPathWithInstanceIdentifierListKey() throws IOException, URISyntaxException {
final SchemaContext schemaContext = YangParserTestUtils.parseYangResource("/bug8083/yang/foobar.yang");
final String inputJson = loadTextFile("/bug8083/json/foobar.json");
// deserialization
final NormalizedNodeResult result = new NormalizedNodeResult();
final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result);
final JsonParserStream jsonParser = JsonParserStream.create(streamWriter,
JSONCodecFactorySupplier.DRAFT_LHOTKA_NETMOD_YANG_JSON_02.getShared(schemaContext));
jsonParser.parse(new JsonReader(new StringReader(inputJson)));
final NormalizedNode<?, ?> transformedInput = result.getResult();
assertNotNull(transformedInput);
}
示例8: testStringPatternCheckingCodec
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; //导入方法依赖的package包/类
@Test
public void testStringPatternCheckingCodec() {
final SchemaContext schemaContext = YangParserTestUtils.parseYangResource(
"/string-pattern-checking-codec-test.yang");
assertNotNull(schemaContext);
final QNameModule testModuleQName = QNameModule.create(URI.create("string-pattern-checking-codec-test"));
final Module testModule = schemaContext.findModules("string-pattern-checking-codec-test").iterator().next();
final ContainerSchemaNode testContainer = (ContainerSchemaNode) testModule.getDataChildByName(
QName.create(testModuleQName, "test-container"));
assertNotNull(testContainer);
final LeafSchemaNode testLeaf = (LeafSchemaNode) testContainer.getDataChildByName(
QName.create(testModuleQName, "string-leaf-with-valid-pattern"));
assertNotNull(testLeaf);
final StringCodec<String> codec = getCodec(testLeaf.getType(), StringCodec.class);
assertNotNull(codec);
assertEquals("ABCD", codec.serialize("ABCD"));
assertEquals("ABCD", codec.deserialize("ABCD"));
try {
codec.deserialize("abcd");
fail("Exception should have been thrown.");
} catch (final IllegalArgumentException ex) {
LOG.debug("IllegalArgumentException was thrown as expected", ex);
assertEquals("Supplied value does not match the regular expression ^[A-Z]+$.", ex.getMessage());
}
}
示例9: init
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; //导入方法依赖的package包/类
@Before
public void init() {
context = YangParserTestUtils.parseYangResource("/bug-4295/foo.yang");
foo = QNameModule.create(URI.create("foo"));
root = QName.create(foo, "root");
subRoot = QName.create(foo, "sub-root");
outerList = QName.create(foo, "outer-list");
innerList = QName.create(foo, "inner-list");
oid = QName.create(foo, "o-id");
iid = QName.create(foo, "i-id");
oleaf = QName.create(foo, "o");
ileaf = QName.create(foo, "i");
inMemoryDataTree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL, context);
}
示例10: initialize
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; //导入方法依赖的package包/类
@BeforeClass
public static void initialize() {
schemaContext = YangParserTestUtils.parseYangResource("/leafref-test.yang");
assertNotNull(schemaContext);
assertEquals(1, schemaContext.getModules().size());
leafRefModule = schemaContext.getModules().iterator().next();
assertNotNull(leafRefModule);
}
示例11: Bug5446Test
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; //导入方法依赖的package包/类
public Bug5446Test() throws Exception {
fooModuleQName = QNameModule.create(URI.create("foo"), Revision.of("2015-11-05"));
rootQName = QName.create(fooModuleQName, "root");
ipAddressQName = QName.create(fooModuleQName, "ip-address");
schemaContext = YangParserTestUtils.parseYangResource("/bug5446/yang/foo.yang");
}
示例12: setup
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; //导入方法依赖的package包/类
@Before
public void setup() {
context = YangParserTestUtils.parseYangResource("/ordered-list-modification-test.yang");
testModule = QNameModule.create(URI.create("ordered-list-modification-test"));
parentContainer = QName.create(testModule, "parent-container");
childContainer = QName.create(testModule, "child-container");
parentOrderedList = QName.create(testModule, "parent-ordered-list");
childOrderedList = QName.create(testModule, "child-ordered-list");
parentKeyLeaf = QName.create(testModule, "parent-key-leaf");
childKeyLeaf = QName.create(testModule, "child-key-leaf");
parentOrdinaryLeaf = QName.create(testModule, "parent-ordinary-leaf");
childOrdinaryLeaf = QName.create(testModule, "child-ordinary-leaf");
inMemoryDataTree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL, context);
}
示例13: test
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; //导入方法依赖的package包/类
@Test
public void test() throws Exception {
final SchemaContext schemaContext = YangParserTestUtils.parseYangResource("/schema-utils-test/foo.yang");
assertTrue(SchemaUtils.findDataParentSchemaOnPath(schemaContext,
SchemaPath.create(true, qN("my-name"), qN("my-name-a"))) instanceof ContainerSchemaNode);
assertTrue(SchemaUtils.findDataParentSchemaOnPath(schemaContext,
SchemaPath.create(true, qN("my-name-2"), qN("my-name-b"))) instanceof NotificationDefinition);
assertTrue(SchemaUtils.findDataParentSchemaOnPath(schemaContext,
SchemaPath.create(true, qN("my-name-2"), qN("my-name-2-b"))) instanceof ActionDefinition);
}
示例14: testNameConflicts
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; //导入方法依赖的package包/类
@Test
public void testNameConflicts() throws Exception {
final SchemaContext schemaContext = YangParserTestUtils
.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-nested"), qN("my-name-nested2"))).size());
// test target container
final Collection<SchemaNode> target = SchemaUtils.findParentSchemaNodesOnPath(schemaContext,
SchemaPath.create(true, qN("my-name-2"), qN("my-name-nested"), qN("target")));
assertEquals(1, target.size());
assertTrue(target.iterator().next() instanceof ContainerSchemaNode);
// test l schema nodes (i.e. container and two leafs)
Collection<SchemaNode> schema = SchemaUtils.findParentSchemaNodesOnPath(schemaContext,
SchemaPath.create(true, qN("my-name-3"), qN("input"), qN("con-3"), qN("l")));
assertEquals(1, schema.size());
assertTrue(schema.iterator().next() instanceof ContainerSchemaNode);
schema = SchemaUtils.findParentSchemaNodesOnPath(schemaContext,
SchemaPath.create(true, qN("my-name-3"), qN("input"), qN("con-1"), qN("l")));
assertEquals(1, schema.size());
assertTrue(schema.iterator().next() instanceof LeafSchemaNode);
schema = SchemaUtils.findParentSchemaNodesOnPath(schemaContext,
SchemaPath.create(true, qN("my-name-3"), qN("input"), qN("con-2"), qN("l")));
assertTrue(schema.isEmpty());
schema = SchemaUtils.findParentSchemaNodesOnPath(schemaContext,
SchemaPath.create(true, qN("my-name-3"), qN("output"), qN("con-2"), qN("l")));
assertEquals(1, schema.size());
assertTrue(schema.iterator().next() instanceof LeafSchemaNode);
}
示例15: testParsingAttributes
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; //导入方法依赖的package包/类
@Test
public void testParsingAttributes() throws Exception {
final SchemaContext schemaContext = YangParserTestUtils.parseYangResource("/bug8745/foo.yang");
final QName contWithAttributes = QName.create("foo", "cont-with-attributes");
final ContainerSchemaNode contWithAttr = (ContainerSchemaNode) SchemaContextUtil.findDataSchemaNode(
schemaContext, SchemaPath.create(true, contWithAttributes));
final Document doc = loadDocument("/bug8745/foo.xml");
final DOMSource domSource = new DOMSource(doc.getDocumentElement());
final DOMResult domResult = new DOMResult(UntrustedXML.newDocumentBuilder().newDocument());
final XMLOutputFactory outputfactory = XMLOutputFactory.newInstance();
outputfactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE);
final XMLStreamWriter xmlStreamWriter = outputfactory.createXMLStreamWriter(domResult);
final NormalizedNodeStreamWriter streamWriter = XMLStreamNormalizedNodeStreamWriter.create(
xmlStreamWriter, schemaContext);
final InputStream resourceAsStream = Bug8745Test.class.getResourceAsStream("/bug8745/foo.xml");
// final XMLStreamReader reader = inputFactory.createXMLStreamReader(resourceAsStream);
final XMLStreamReader reader = new DOMSourceXMLStreamReader(domSource);
final XmlParserStream xmlParser = XmlParserStream.create(streamWriter, schemaContext, contWithAttr);
xmlParser.parse(reader);
XMLUnit.setIgnoreWhitespace(true);
XMLUnit.setNormalize(true);
final String expectedXml = toString(doc.getDocumentElement());
final String serializedXml = toString(domResult.getNode());
final Diff diff = new Diff(expectedXml, serializedXml);
XMLAssert.assertXMLEqual(diff, true);
}