Search in sources :

Example 1 with DOMSourceAnyxmlNode

use of org.opendaylight.yangtools.yang.data.api.schema.DOMSourceAnyxmlNode in project controller by opendaylight.

the class NormalizedNodePrunerTest method testAnyXMLNodeNotPrunedWhenHasParent.

@Test
public void testAnyXMLNodeNotPrunedWhenHasParent() throws IOException {
    AbstractNormalizedNodePruner pruner = prunerFullSchema(TestModel.TEST_PATH);
    DOMSourceAnyxmlNode child = Builders.anyXmlBuilder().withNodeIdentifier(new NodeIdentifier(TestModel.ANY_XML_QNAME)).withValue(mock(DOMSource.class)).build();
    NormalizedNode input = Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME)).withChild(child).build();
    NormalizedNodeWriter.forStreamWriter(pruner).write(input);
    NormalizedNode actual = pruner.getResult().orElseThrow();
    assertEquals("normalizedNode", input, actual);
}
Also used : DOMSourceAnyxmlNode(org.opendaylight.yangtools.yang.data.api.schema.DOMSourceAnyxmlNode) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) Test(org.junit.Test)

Example 2 with DOMSourceAnyxmlNode

use of org.opendaylight.yangtools.yang.data.api.schema.DOMSourceAnyxmlNode in project yangtools by opendaylight.

the class AnyXmlSupportTest method getParsedAnyXmlValue.

private static DOMSource getParsedAnyXmlValue(final NormalizedNode transformedInput, final QName anyxmlName) {
    assertTrue(transformedInput instanceof ContainerNode);
    final ContainerNode cont1 = (ContainerNode) transformedInput;
    final DataContainerChild child = cont1.childByArg(new NodeIdentifier(anyxmlName));
    assertTrue(child instanceof DOMSourceAnyxmlNode);
    final DOMSourceAnyxmlNode anyXmlNode = (DOMSourceAnyxmlNode) child;
    return anyXmlNode.body();
}
Also used : DOMSourceAnyxmlNode(org.opendaylight.yangtools.yang.data.api.schema.DOMSourceAnyxmlNode) DataContainerChild(org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)

Example 3 with DOMSourceAnyxmlNode

use of org.opendaylight.yangtools.yang.data.api.schema.DOMSourceAnyxmlNode in project netconf by opendaylight.

the class NetconfMessageTransformerTest method testGetSchemaResponse.

@Test
public void testGetSchemaResponse() throws Exception {
    final NetconfMessageTransformer transformer = getTransformer(SCHEMA);
    final NetconfMessage response = new NetconfMessage(XmlUtil.readXmlToDocument("<rpc-reply message-id=\"101\"\n" + "xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" + "<data\n" + "xmlns=\"urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring\">\n" + "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">\n" + "Random YANG SCHEMA\n" + "</xs:schema>\n" + "</data>\n" + "</rpc-reply>"));
    final DOMRpcResult compositeNodeRpcResult = transformer.toRpcResult(response, GET_SCHEMA_QNAME);
    assertTrue(compositeNodeRpcResult.getErrors().isEmpty());
    assertNotNull(compositeNodeRpcResult.getResult());
    final DOMSource schemaContent = ((DOMSourceAnyxmlNode) ((ContainerNode) compositeNodeRpcResult.getResult()).body().iterator().next()).body();
    assertThat(schemaContent.getNode().getTextContent(), CoreMatchers.containsString("Random YANG SCHEMA"));
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) DOMRpcResult(org.opendaylight.mdsal.dom.api.DOMRpcResult) DOMSourceAnyxmlNode(org.opendaylight.yangtools.yang.data.api.schema.DOMSourceAnyxmlNode) NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) AbstractBaseSchemasTest(org.opendaylight.netconf.sal.connect.netconf.AbstractBaseSchemasTest) Test(org.junit.Test)

Example 4 with DOMSourceAnyxmlNode

use of org.opendaylight.yangtools.yang.data.api.schema.DOMSourceAnyxmlNode in project netconf by opendaylight.

the class FieldsSchemalessRpcStructureTransformerTest method toFilterStructureWithSingleRootTest.

@Test
public void toFilterStructureWithSingleRootTest() throws SAXException, IOException, URISyntaxException {
    final YangInstanceIdentifier rootPath = YangInstanceIdentifier.create(C1_NID);
    final YangInstanceIdentifier leaf1Field = YangInstanceIdentifier.create(LEAF1_NID);
    final YangInstanceIdentifier leaf3Field = YangInstanceIdentifier.create(NodeIdentifierWithPredicates.of(LIST1_QNAME, Map.of(KEY1_QNAME, "key1", KEY2_QNAME, "key2")), C2_NID, LEAF3_NID);
    final YangInstanceIdentifier key1Field = YangInstanceIdentifier.create(NodeIdentifierWithPredicates.of(LIST1_QNAME, Map.of(KEY1_QNAME, "key1", KEY2_QNAME, "key2")), KEY1_NID);
    final FieldsFilter filter = FieldsFilter.of(rootPath, List.of(leaf1Field, leaf3Field, key1Field));
    final DOMSourceAnyxmlNode filterStructure = (DOMSourceAnyxmlNode) transformer.toFilterStructure(Collections.singletonList(filter));
    final Diff diff = getDiff("one-root-filter.xml", filterStructure);
    assertTrue(diff.similar());
}
Also used : DOMSourceAnyxmlNode(org.opendaylight.yangtools.yang.data.api.schema.DOMSourceAnyxmlNode) Diff(org.custommonkey.xmlunit.Diff) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Test(org.junit.Test)

Example 5 with DOMSourceAnyxmlNode

use of org.opendaylight.yangtools.yang.data.api.schema.DOMSourceAnyxmlNode in project netconf by opendaylight.

the class FieldsSchemalessRpcStructureTransformerTest method toFilterStructureWithTwoRootContainersTest.

@Test
public void toFilterStructureWithTwoRootContainersTest() throws SAXException, IOException, URISyntaxException {
    final YangInstanceIdentifier c1RootPath = YangInstanceIdentifier.create(C1_NID);
    final YangInstanceIdentifier cxRootPath = YangInstanceIdentifier.create(CX_NID);
    final YangInstanceIdentifier c2Field = YangInstanceIdentifier.create(LIST1_NID, C2_NID);
    final YangInstanceIdentifier leaf2Field = YangInstanceIdentifier.create(LIST1_NID, C2_NID, LEAF2_NID);
    final YangInstanceIdentifier lxField = YangInstanceIdentifier.create(LX_NID);
    final FieldsFilter filter1 = FieldsFilter.of(c1RootPath, List.of(c2Field, leaf2Field));
    final FieldsFilter filter2 = FieldsFilter.of(cxRootPath, Collections.singletonList(lxField));
    final DOMSourceAnyxmlNode filterStructure = (DOMSourceAnyxmlNode) transformer.toFilterStructure(List.of(filter1, filter2));
    final Diff diff = getDiff("two-roots-filter.xml", filterStructure);
    assertTrue(diff.similar());
}
Also used : DOMSourceAnyxmlNode(org.opendaylight.yangtools.yang.data.api.schema.DOMSourceAnyxmlNode) Diff(org.custommonkey.xmlunit.Diff) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Test(org.junit.Test)

Aggregations

DOMSourceAnyxmlNode (org.opendaylight.yangtools.yang.data.api.schema.DOMSourceAnyxmlNode)30 Test (org.junit.Test)16 DOMSource (javax.xml.transform.dom.DOMSource)15 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)15 Diff (org.custommonkey.xmlunit.Diff)10 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)10 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)10 Document (org.w3c.dom.Document)10 DataContainerChild (org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild)9 QName (org.opendaylight.yangtools.yang.common.QName)8 NetconfMessage (org.opendaylight.netconf.api.NetconfMessage)7 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)7 XmlElement (org.opendaylight.netconf.api.xml.XmlElement)6 Element (org.w3c.dom.Element)6 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)5 IOException (java.io.IOException)4 XMLStreamException (javax.xml.stream.XMLStreamException)4 PathArgument (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument)4 NormalizedNodeStreamWriter (org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter)4 URISyntaxException (java.net.URISyntaxException)3