本文整理汇总了Java中org.opendaylight.yangtools.yang.test.util.YangParserTestUtils类的典型用法代码示例。如果您正苦于以下问题:Java YangParserTestUtils类的具体用法?Java YangParserTestUtils怎么用?Java YangParserTestUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
YangParserTestUtils类属于org.opendaylight.yangtools.yang.test.util包,在下文中一共展示了YangParserTestUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadYangs
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; //导入依赖的package包/类
private Module loadYangs(final File testedModule, final String moduleName)
throws Exception {
final List<InputStream> yangISs = new ArrayList<>();
yangISs.addAll(getStreams("/ietf-inet-types.yang"));
yangISs.add(new FileInputStream(testedModule));
yangISs.addAll(getConfigApiYangInputStreams());
this.context = YangParserTestUtils.parseYangStreams(yangISs);
// close ISs
for (final InputStream is : yangISs) {
is.close();
}
this.namesToModules = YangModelSearchUtils.mapModulesByNames(this.context
.getModules());
this.configModule = this.namesToModules.get(ConfigConstants.CONFIG_MODULE);
final Module module = this.namesToModules.get(moduleName);
Preconditions.checkNotNull(module, "Cannot get module %s from %s",
moduleName, this.namesToModules.keySet());
return module;
}
示例2: testStopOnUnknownLanguageExtension
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; //导入依赖的package包/类
@Test
public void testStopOnUnknownLanguageExtension() throws Exception {
List<InputStream> yangISs = Lists.newArrayList(getClass()
.getResourceAsStream("test-ifcWithUnknownExtension.yang"));
yangISs.addAll(getConfigApiYangInputStreams());
try {
context = YangParserTestUtils.parseYangStreams(yangISs);
namesToModules = YangModelSearchUtils.mapModulesByNames(context.getModules());
configModule = namesToModules.get(ConfigConstants.CONFIG_MODULE);
threadsModule = namesToModules.get(ConfigConstants.CONFIG_THREADS_MODULE);
try {
super.testCreateFromIdentities();
fail();
} catch (IllegalStateException e) {
assertTrue(e.getMessage(),
e.getMessage().startsWith("Unexpected unknown schema node."));
}
} finally {
for (InputStream is : yangISs) {
is.close();
}
}
}
示例3: createTestContext
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; //导入依赖的package包/类
public static SchemaContext createTestContext() {
final List<InputStream> sources;
try {
sources = Collections.singletonList(
Resources.asByteSource(TestModel.class.getResource(DATASTORE_TEST_YANG)).openStream());
} catch (IOException e1) {
throw new ExceptionInInitializerError(e1);
}
try {
return YangParserTestUtils.parseYangStreams(sources);
} catch (ReactorException e) {
throw new RuntimeException("Unable to build schema context from " + sources, e);
}
}
示例4: setUp
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; //导入依赖的package包/类
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
final BindingBrokerTestFactory testFactory = new BindingBrokerTestFactory();
testFactory.setExecutor(MoreExecutors.newDirectExecutorService());
testFactory.setStartWithParsedSchema(true);
testContext = testFactory.getTestContext();
testContext.start();
domMountPointService = testContext.getDomMountProviderService();
bindingMountPointService = testContext.getBindingMountPointService();
assertNotNull(domMountPointService);
final InputStream moduleStream = BindingReflections.getModuleInfo(
OpendaylightTestRpcServiceService.class)
.getModuleSourceStream();
assertNotNull(moduleStream);
final List<InputStream> rpcModels = Collections.singletonList(moduleStream);
schemaContext = YangParserTestUtils.parseYangStreams(rpcModels);
}
示例5: 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);
}
示例6: init
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; //导入依赖的package包/类
@BeforeClass
public static void init() throws XMLStreamException, URISyntaxException, IOException, ParserConfigurationException,
SAXException {
schemaContext = YangParserTestUtils.parseYangResourceDirectory("/yang-modeled-anyxml/yang");
final Module bazModule = schemaContext.findModules("baz").iterator().next();
final ContainerSchemaNode bazCont = (ContainerSchemaNode) bazModule.getDataChildByName(
QName.create(bazModule.getQNameModule(), "baz"));
assertNotNull(bazCont);
final InputStream resourceAsStream = YangModeledAnyXmlSupportTest.class.getResourceAsStream(
"/yang-modeled-anyxml/xml/baz.xml");
final XMLInputFactory factory = XMLInputFactory.newInstance();
final XMLStreamReader reader = factory.createXMLStreamReader(resourceAsStream);
final NormalizedNodeResult result = new NormalizedNodeResult();
final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result);
final XmlParserStream xmlParser = XmlParserStream.create(streamWriter, schemaContext, bazCont);
xmlParser.parse(reader);
assertNotNull(result.getResult());
assertTrue(result.getResult() instanceof ContainerNode);
data = (ContainerNode) result.getResult();
}
示例7: 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();
}
}
}
示例8: testImplicitInputAndOutputInRpc
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; //导入依赖的package包/类
@Test
public void testImplicitInputAndOutputInRpc() throws Exception {
final SchemaContext schemaContext = YangParserTestUtils.parseYangResources(Bug6856Test.class,
"/bugs/bug6856/foo.yang");
assertNotNull(schemaContext);
final OutputStream byteArrayOutputStream = new ByteArrayOutputStream();
final BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(byteArrayOutputStream);
final Module fooModule = schemaContext.findModule("foo", Revision.of("2017-02-28")).get();
YinExportUtils.writeModuleToOutputStream(schemaContext, fooModule, bufferedOutputStream);
final String output = byteArrayOutputStream.toString();
assertNotNull(output);
assertFalse(output.isEmpty());
assertFalse(output.contains("<input>"));
assertFalse(output.contains("<output>"));
}
示例9: testExplicitInputAndOutputInRpc
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; //导入依赖的package包/类
@Test
public void testExplicitInputAndOutputInRpc() throws Exception {
final SchemaContext schemaContext = YangParserTestUtils.parseYangResources(Bug6856Test.class,
"/bugs/bug6856/bar.yang");
assertNotNull(schemaContext);
final OutputStream byteArrayOutputStream = new ByteArrayOutputStream();
final BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(byteArrayOutputStream);
final Module barModule = schemaContext.findModule("bar", Revision.of("2017-02-28")).get();
YinExportUtils.writeModuleToOutputStream(schemaContext, barModule, bufferedOutputStream);
final String output = byteArrayOutputStream.toString();
assertNotNull(output);
assertFalse(output.isEmpty());
assertTrue(output.contains("<input>"));
assertTrue(output.contains("<output>"));
}
示例10: test
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; //导入依赖的package包/类
@Test
public void test() throws Exception {
final SchemaContext schema = YangParserTestUtils.parseYangResourceDirectory("/bugs/bug2444/yang");
assertNotNull(schema);
final ImmutableSet<Module> modulesAndSubmodules = getAllModulesAndSubmodules(schema);
for (final Module module : modulesAndSubmodules) {
final OutputStream byteArrayOutputStream = new ByteArrayOutputStream();
final BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(byteArrayOutputStream);
try {
YinExportUtils.writeModuleToOutputStream(schema, module, bufferedOutputStream);
final String output = byteArrayOutputStream.toString();
assertNotNull(output);
assertNotEquals(0, output.length());
final Document doc = YinExportTestUtils.loadDocument("/bugs/bug2444/yin", module);
assertXMLEquals(module.getName(), doc, output);
} finally {
byteArrayOutputStream.close();
bufferedOutputStream.close();
}
}
}
示例11: test
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; //导入依赖的package包/类
@Test
public void test() throws Exception {
SchemaContext schema = YangParserTestUtils.parseYangResourceDirectory("/bugs/bug5531");
assertNotNull(schema);
assertNotNull(schema.getModules());
assertEquals(1, schema.getModules().size());
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(byteArrayOutputStream);
// write small module of size less than 8kB
for (Module module : schema.getModules()) {
YinExportUtils.writeModuleToOutputStream(schema, module, bufferedOutputStream);
}
String output = byteArrayOutputStream.toString();
// if all changes were flushed then following conditions are satisfied
assertNotEquals("Output should not be empty", 0, output.length());
assertTrue("Output should contains start of the module", output.contains("<module"));
assertTrue("Output should contains end of the module", output.contains("</module>"));
}
示例12: init
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; //导入依赖的package包/类
@BeforeClass
public static void init() {
context = YangParserTestUtils.parseYangResourceDirectory("/leafref-context-test/correct-modules");
final Set<Module> modules = context.getModules();
for (final Module module : modules) {
if (module.getName().equals("import-mod")) {
impMod = module;
}
if (module.getName().equals("leafref-test")) {
tstMod = module;
}
}
imp = impMod.getQNameModule();
tst = tstMod.getQNameModule();
rootLeafRefContext = LeafRefContext.create(context);
}
示例13: dataTreeCanditateValidationTest
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; //导入依赖的package包/类
@Test
public void dataTreeCanditateValidationTest() throws Exception {
final SchemaContext context = YangParserTestUtils.parseYangResourceDirectory("/bug8713/");
final LeafRefContext rootLeafRefContext = LeafRefContext.create(context);
final DataTree inMemoryDataTree = new InMemoryDataTreeFactory().create(
DataTreeConfiguration.DEFAULT_OPERATIONAL, context);
final ContainerNode root = createRootContainer();
final YangInstanceIdentifier rootPath = YangInstanceIdentifier.of(foo("root"));
final DataTreeModification writeModification = inMemoryDataTree.takeSnapshot().newModification();
writeModification.write(rootPath, root);
writeModification.ready();
final DataTreeCandidate writeContributorsCandidate = inMemoryDataTree.prepare(writeModification);
LeafRefValidatation.validate(writeContributorsCandidate, rootLeafRefContext);
inMemoryDataTree.commit(writeContributorsCandidate);
}
示例14: 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);
}
示例15: 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);
}