+++ /dev/null
-/*
- * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.opendaylight.netconf.util;
-
-public class NetconfTopologyPathCreator {
-
- public static final String CLUSTERED_DEVICE_SOURCES_RESOLVER = "clusteredDeviceSourcesResolver";
- public static final String MASTER_SOURCE_PROVIDER
- = "masterSourceProvider";
-
- private static final String USER = "/user/";
-
- private String mainPath;
-
- public NetconfTopologyPathCreator(final String topologyId) {
- mainPath = createMainPath("", topologyId);
- }
-
- public NetconfTopologyPathCreator(final String memberAddress, final String topologyId) {
- mainPath = createMainPath(memberAddress, topologyId);
- }
-
- private String createMainPath(final String memberAddress, final String topologyId) {
- return memberAddress + USER + topologyId;
- }
-
- public NetconfTopologyPathCreator withSuffix(final String suffix) {
- mainPath += "/"+suffix;
- return this;
- }
-
- public String build(){
- return mainPath;
- }
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.opendaylight.netconf.util.xml;
-
-import com.google.common.base.Preconditions;
-import java.io.IOException;
-import java.io.InputStream;
-import javax.xml.transform.Source;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.validation.Schema;
-import javax.xml.validation.Validator;
-import org.opendaylight.controller.config.util.xml.XmlUtil;
-import org.w3c.dom.Document;
-import org.xml.sax.SAXException;
-
-public final class XmlNetconfValidator {
-
- private static final Schema SCHEMA;
-
- private XmlNetconfValidator() {}
-
- static {
- final InputStream xmlSchema = XmlNetconfValidator.class.getResourceAsStream("/xml.xsd");
- Preconditions.checkNotNull(xmlSchema, "Cannot find xml.xsd");
-
- final InputStream rfc4714Schema = XmlNetconfValidator.class.getResourceAsStream("/rfc4741.xsd");
- Preconditions.checkNotNull(rfc4714Schema, "Cannot find rfc4741.xsd");
- SCHEMA = XmlUtil.loadSchema(xmlSchema, rfc4714Schema);
- }
-
- public static void validate(Document inputDocument) throws SAXException, IOException {
- final Validator validator = SCHEMA.newValidator();
- final Source source = new DOMSource(inputDocument);
- validator.validate(source);
- }
-}
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
+import java.util.Collections;
+import javax.xml.transform.dom.DOMResult;
+import org.custommonkey.xmlunit.Diff;
+import org.custommonkey.xmlunit.XMLUnit;
+import org.junit.Assert;
+import org.junit.BeforeClass;
import org.junit.Test;
import org.opendaylight.controller.config.util.xml.XmlUtil;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.$YangModuleInfoImpl;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.NetconfState;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.Sessions;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.sessions.Session;
+import org.opendaylight.yangtools.sal.binding.generator.impl.ModuleInfoBackedContext;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
+import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
+import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
+import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
+import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
import org.w3c.dom.Document;
public class NetconfUtilTest {
+ @BeforeClass
+ public static void classSetUp() {
+ XMLUnit.setIgnoreWhitespace(true);
+ }
+
@Test
public void testConflictingVersionDetection() throws Exception {
- Document document = XmlUtil.readXmlToDocument(getClass().getResourceAsStream("/netconfMessages/conflictingversion/conflictingVersionResponse.xml"));
+ final Document document = XmlUtil.readXmlToDocument(getClass().getResourceAsStream("/netconfMessages/conflictingversion/conflictingVersionResponse.xml"));
try{
NetconfUtil.checkIsMessageOk(document);
fail();
- }catch(IllegalStateException e){
+ } catch (final IllegalStateException e) {
assertThat(e.getMessage(), containsString("Optimistic lock failed. Expected parent version 21, was 18"));
}
}
+
+ @Test
+ public void testWriteNormalizedNode() throws Exception {
+ final ModuleInfoBackedContext moduleInfoBackedContext = ModuleInfoBackedContext.create();
+ moduleInfoBackedContext.addModuleInfos(Collections.singletonList($YangModuleInfoImpl.getInstance()));
+ final SchemaContext context = moduleInfoBackedContext.getSchemaContext();
+ final LeafNode username = Builders.leafBuilder()
+ .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(QName.create(Session.QNAME, "username")))
+ .withValue("admin")
+ .build();
+ final MapEntryNode session1 = Builders.mapEntryBuilder()
+ .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifierWithPredicates(Session.QNAME, QName.create(Session.QNAME, "session-id"), 1L))
+ .withChild(username)
+ .build();
+ final MapNode sessionList = Builders.mapBuilder()
+ .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(Session.QNAME))
+ .withChild(session1)
+ .build();
+ final ContainerNode sessions = Builders.containerBuilder()
+ .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(Sessions.QNAME))
+ .withChild(sessionList)
+ .build();
+ final DOMResult result = new DOMResult(XmlUtil.newDocument());
+ final SchemaPath path = SchemaPath.create(true, NetconfState.QNAME);
+ NetconfUtil.writeNormalizedNode(sessions, result, path, context);
+ final Document expected = XmlUtil.readXmlToDocument(getClass().getResourceAsStream("/sessions.xml"));
+ final Document actual = (Document) result.getNode();
+ final Diff diff = XMLUnit.compareXML(expected, actual);
+ Assert.assertTrue(diff.toString(), diff.similar());
+ }
}