X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=opendaylight%2Fmd-sal%2Fsal-netconf-connector%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Fconnect%2Fnetconf%2Fschema%2Fmapping%2FNetconfMessageTransformerTest.java;h=643c67af287862b92619d295be11ac2f8b8baa0b;hb=9db24f2b887db47a63e56579ecdd6839b0a31b55;hp=ea0941e8eec98d5f15e2b6d4876b9b9dab71e3fb;hpb=40c2487f8068ee8ba045798d3be716899c77a6e6;p=controller.git diff --git a/opendaylight/md-sal/sal-netconf-connector/src/test/java/org/opendaylight/controller/sal/connect/netconf/schema/mapping/NetconfMessageTransformerTest.java b/opendaylight/md-sal/sal-netconf-connector/src/test/java/org/opendaylight/controller/sal/connect/netconf/schema/mapping/NetconfMessageTransformerTest.java index ea0941e8ee..643c67af28 100644 --- a/opendaylight/md-sal/sal-netconf-connector/src/test/java/org/opendaylight/controller/sal/connect/netconf/schema/mapping/NetconfMessageTransformerTest.java +++ b/opendaylight/md-sal/sal-netconf-connector/src/test/java/org/opendaylight/controller/sal/connect/netconf/schema/mapping/NetconfMessageTransformerTest.java @@ -21,6 +21,7 @@ import static org.opendaylight.controller.sal.connect.netconf.util.NetconfMessag import static org.opendaylight.controller.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_EDIT_CONFIG_QNAME; import static org.opendaylight.controller.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_GET_CONFIG_QNAME; import static org.opendaylight.controller.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_GET_QNAME; +import static org.opendaylight.controller.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_LOCK_QNAME; import static org.opendaylight.controller.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_RUNNING_QNAME; import static org.opendaylight.controller.sal.connect.netconf.util.NetconfMessageTransformUtil.createEditConfigStructure; import static org.opendaylight.controller.sal.connect.netconf.util.NetconfMessageTransformUtil.toFilterStructure; @@ -35,7 +36,9 @@ import java.io.IOException; import java.util.Collections; import java.util.List; import java.util.Map; +import javax.xml.transform.dom.DOMSource; import org.custommonkey.xmlunit.Diff; +import org.custommonkey.xmlunit.ElementNameAndAttributeQualifier; import org.custommonkey.xmlunit.XMLUnit; import org.hamcrest.CoreMatchers; import org.junit.Before; @@ -64,6 +67,7 @@ import org.opendaylight.yangtools.yang.data.api.schema.MapNode; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; import org.opendaylight.yangtools.yang.data.impl.schema.Builders; import org.opendaylight.yangtools.yang.model.api.SchemaContext; +import org.w3c.dom.Element; import org.xml.sax.SAXException; public class NetconfMessageTransformerTest { @@ -77,11 +81,30 @@ public class NetconfMessageTransformerTest { XMLUnit.setIgnoreAttributeOrder(true); XMLUnit.setIgnoreComments(true); - schema = getSchema(); + schema = getSchema(true); netconfMessageTransformer = getTransformer(schema); } + @Test + public void testLockRequestBaseSchemaNotPresent() throws Exception { + final SchemaContext partialSchema = getSchema(false); + final NetconfMessageTransformer transformer = getTransformer(partialSchema); + final NetconfMessage netconfMessage = transformer.toRpcRequest(toPath(NETCONF_LOCK_QNAME), + NetconfBaseOps.getLockContent(NETCONF_CANDIDATE_QNAME)); + + assertThat(XmlUtil.toString(netconfMessage.getDocument()), CoreMatchers.containsString(""; + + transformer.toRpcResult(new NetconfMessage(XmlUtil.readXmlToDocument(result)), toPath(NETCONF_LOCK_QNAME)); + } + @Test public void testDiscardChangesRequest() throws Exception { final NetconfMessage netconfMessage = netconfMessageTransformer.toRpcRequest(toPath(NETCONF_DISCARD_CHANGES_QNAME), @@ -95,16 +118,17 @@ public class NetconfMessageTransformerTest { NetconfRemoteSchemaYangSourceProvider.createGetSchemaRequest("module", Optional.of("2012-12-12"))); assertSimilarXml(netconfMessage, "\n" + "\n" + - "yang\n" + + "x:yang\n" + "module\n" + "2012-12-12\n" + "\n" + ""); } + @Test public void tesGetSchemaResponse() throws Exception { - final NetconfMessageTransformer netconfMessageTransformer = getTransformer(getSchema()); + final NetconfMessageTransformer netconfMessageTransformer = getTransformer(getSchema(true)); final NetconfMessage response = new NetconfMessage(XmlUtil.readXmlToDocument( "\n" + @@ -119,8 +143,8 @@ public class NetconfMessageTransformerTest { final DOMRpcResult compositeNodeRpcResult = netconfMessageTransformer.toRpcResult(response, toPath(GET_SCHEMA_QNAME)); assertTrue(compositeNodeRpcResult.getErrors().isEmpty()); assertNotNull(compositeNodeRpcResult.getResult()); - final Object schemaContent = ((AnyXmlNode) ((ContainerNode) compositeNodeRpcResult.getResult()).getValue().iterator().next()).getValue().getValue(); - assertThat(schemaContent.toString(), CoreMatchers.containsString("Random YANG SCHEMA")); + final DOMSource schemaContent = ((AnyXmlNode) ((ContainerNode) compositeNodeRpcResult.getResult()).getValue().iterator().next()).getValue(); + assertThat(((Element) schemaContent.getNode()).getTextContent(), CoreMatchers.containsString("Random YANG SCHEMA")); } @Test @@ -133,14 +157,14 @@ public class NetconfMessageTransformerTest { "\n" + "module\n" + "2012-12-12\n" + - "yang\n" + + "x:yang\n" + "\n" + "\n" + "\n" + "\n" + "")); - final NetconfMessageTransformer netconfMessageTransformer = getTransformer(getSchema()); + final NetconfMessageTransformer netconfMessageTransformer = getTransformer(getSchema(true)); final DOMRpcResult compositeNodeRpcResult = netconfMessageTransformer.toRpcResult(response, toPath(NETCONF_GET_CONFIG_QNAME)); assertTrue(compositeNodeRpcResult.getErrors().isEmpty()); assertNotNull(compositeNodeRpcResult.getResult()); @@ -203,7 +227,7 @@ public class NetconfMessageTransformerTest { final MapEntryNode schemaNode = Builders.mapEntryBuilder().withNodeIdentifier(identifierWithPredicates).withValue(values).build(); final YangInstanceIdentifier id = YangInstanceIdentifier.builder().node(NetconfState.QNAME).node(Schemas.QNAME).node(Schema.QNAME).nodeWithKey(Schema.QNAME, keys).build(); - final DataContainerChild editConfigStructure = createEditConfigStructure(NetconfDevice.INIT_SCHEMA_CTX, id, Optional.of(ModifyAction.REPLACE), Optional.>fromNullable(schemaNode)); + final DataContainerChild editConfigStructure = createEditConfigStructure(NetconfDevice.INIT_SCHEMA_CTX, id, Optional.absent(), Optional.>fromNullable(schemaNode)); final DataContainerChild target = NetconfBaseOps.getTargetNode(NETCONF_CANDIDATE_QNAME); @@ -221,7 +245,7 @@ public class NetconfMessageTransformerTest { "\n" + "module\n" + "2012-12-12\n" + - "yang\n" + + "x:yang\n" + "\n" + "\n" + "\n" + @@ -232,6 +256,7 @@ public class NetconfMessageTransformerTest { private void assertSimilarXml(final NetconfMessage netconfMessage, final String xmlContent) throws SAXException, IOException { final Diff diff = XMLUnit.compareXML(netconfMessage.getDocument(), XmlUtil.readXmlToDocument(xmlContent)); + diff.overrideElementQualifier(new ElementNameAndAttributeQualifier()); assertTrue(diff.toString(), diff.similar()); } @@ -272,9 +297,11 @@ public class NetconfMessageTransformerTest { assertNull(compositeNodeRpcResult.getResult()); } - public SchemaContext getSchema() { + public SchemaContext getSchema(boolean addBase) { final ModuleInfoBackedContext moduleInfoBackedContext = ModuleInfoBackedContext.create(); - moduleInfoBackedContext.addModuleInfos(Collections.singleton($YangModuleInfoImpl.getInstance())); + if(addBase) { + moduleInfoBackedContext.addModuleInfos(Collections.singleton($YangModuleInfoImpl.getInstance())); + } moduleInfoBackedContext.addModuleInfos(Collections.singleton(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.$YangModuleInfoImpl.getInstance())); return moduleInfoBackedContext.tryToCreateSchemaContext().get(); }