Search in sources :

Example 11 with EffectiveModelContext

use of org.opendaylight.yangtools.yang.model.api.EffectiveModelContext in project yangtools by opendaylight.

the class Bug7246Test method test.

@Test
public void test() throws Exception {
    final EffectiveModelContext schemaContext = YangParserTestUtils.parseYangResource("/bug7246/yang/rpc-test.yang");
    final ContainerNode 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);
    assertEquals(JsonParser.parseReader(new FileReader(new File(getClass().getResource("/bug7246/json/expected-output.json").toURI()), StandardCharsets.UTF_8)), JsonParser.parseString(jsonOutput));
}
Also used : StringWriter(java.io.StringWriter) SchemaPath(org.opendaylight.yangtools.yang.model.api.SchemaPath) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) FileReader(java.io.FileReader) File(java.io.File) StringWriter(java.io.StringWriter) NormalizedNodeWriter(org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeWriter) NormalizedNodeStreamWriter(org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter) Writer(java.io.Writer) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext) Test(org.junit.Test)

Example 12 with EffectiveModelContext

use of org.opendaylight.yangtools.yang.model.api.EffectiveModelContext in project yangtools by opendaylight.

the class Bug8083Test method testInstanceIdentifierPathWithInstanceIdentifierListKey.

@Test
public void testInstanceIdentifierPathWithInstanceIdentifierListKey() throws IOException, URISyntaxException {
    final EffectiveModelContext 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);
}
Also used : NormalizedNodeResult(org.opendaylight.yangtools.yang.data.impl.schema.NormalizedNodeResult) StringReader(java.io.StringReader) ImmutableNormalizedNodeStreamWriter(org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNormalizedNodeStreamWriter) NormalizedNodeStreamWriter(org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter) JsonReader(com.google.gson.stream.JsonReader) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext) Test(org.junit.Test)

Example 13 with EffectiveModelContext

use of org.opendaylight.yangtools.yang.model.api.EffectiveModelContext in project yangtools by opendaylight.

the class Bug8083Test method testInstanceIdentifierPathWithEmptyListKey.

@Test
public void testInstanceIdentifierPathWithEmptyListKey() throws IOException, URISyntaxException {
    final EffectiveModelContext 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);
}
Also used : NormalizedNodeResult(org.opendaylight.yangtools.yang.data.impl.schema.NormalizedNodeResult) StringReader(java.io.StringReader) ImmutableNormalizedNodeStreamWriter(org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNormalizedNodeStreamWriter) NormalizedNodeStreamWriter(org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter) JsonReader(com.google.gson.stream.JsonReader) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext) Test(org.junit.Test)

Example 14 with EffectiveModelContext

use of org.opendaylight.yangtools.yang.model.api.EffectiveModelContext in project yangtools by opendaylight.

the class Bug4969Test method newParserLeafRefTest.

@Test
public void newParserLeafRefTest() throws IOException, URISyntaxException {
    EffectiveModelContext context = YangParserTestUtils.parseYangResourceDirectory("/bug-4969/yang");
    assertNotNull(context);
    verifyNormalizedNodeResult(context);
}
Also used : EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext) Test(org.junit.Test)

Example 15 with EffectiveModelContext

use of org.opendaylight.yangtools.yang.model.api.EffectiveModelContext in project yangtools by opendaylight.

the class Bug4969Test method newParserLeafRefTest2.

@Test
public void newParserLeafRefTest2() throws URISyntaxException, IOException {
    EffectiveModelContext context = YangParserTestUtils.parseYangResourceDirectory("/leafref/yang");
    assertNotNull(context);
    parseJsonToNormalizedNodes(context);
}
Also used : EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext) Test(org.junit.Test)

Aggregations

EffectiveModelContext (org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)182 Test (org.junit.Test)99 Module (org.opendaylight.yangtools.yang.model.api.Module)37 QName (org.opendaylight.yangtools.yang.common.QName)29 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)28 DataSchemaNode (org.opendaylight.yangtools.yang.model.api.DataSchemaNode)26 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)24 LeafSchemaNode (org.opendaylight.yangtools.yang.model.api.LeafSchemaNode)24 ContainerSchemaNode (org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode)21 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)18 QNameModule (org.opendaylight.yangtools.yang.common.QNameModule)16 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)16 NormalizedNodeStreamWriter (org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter)16 IRSchemaSource (org.opendaylight.yangtools.yang.parser.rfc7950.ir.IRSchemaSource)14 DOMMountPoint (org.opendaylight.mdsal.dom.api.DOMMountPoint)13 RestconfDocumentedException (org.opendaylight.restconf.common.errors.RestconfDocumentedException)13 RpcDefinition (org.opendaylight.yangtools.yang.model.api.RpcDefinition)13 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)11 IOException (java.io.IOException)9 Collection (java.util.Collection)9