From: Jakub Morvay Date: Sat, 17 Nov 2018 14:17:25 +0000 (+0000) Subject: Merge "Migrate restconf to MD-SAL APIs" X-Git-Tag: release/neon~99 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=355bc98a2fd60f8067c05a262c7dd4766edc0ba3;hp=b7537d2482ffb05582749ce80a7ca44c64a5ad6c;p=netconf.git Merge "Migrate restconf to MD-SAL APIs" --- diff --git a/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/AbstractNetconfTopology.java b/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/AbstractNetconfTopology.java index 324ec84727..66eea5692b 100644 --- a/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/AbstractNetconfTopology.java +++ b/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/AbstractNetconfTopology.java @@ -516,6 +516,10 @@ public abstract class AbstractNetconfTopology implements NetconfTopology { } else { throw new IllegalStateException("Unsupported protocol type: " + node.getProtocol().getName().getClass()); } + if (node.getOdlHelloMessageCapabilities() != null) { + reconnectingClientConfigurationBuilder + .withOdlHelloCapabilities(node.getOdlHelloMessageCapabilities().getCapability()); + } return reconnectingClientConfigurationBuilder .withAddress(socketAddress) diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/YangInstanceIdentifierDeserializer.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/YangInstanceIdentifierDeserializer.java index 2009a072c6..89b6fc899b 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/YangInstanceIdentifierDeserializer.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/YangInstanceIdentifierDeserializer.java @@ -394,8 +394,12 @@ public final class YangInstanceIdentifierDeserializer { checkValid(RestconfConstants.SLASH == currentChar(variables.getOffset(), variables.getData()), "Identifier must start with '/'.", variables.getData(), variables.getOffset()); - // skip slash - skipCurrentChar(variables); + // skip consecutive slashes, users often assume restconf URLs behave just as HTTP does by squashing + // multiple slashes into a single one + while (!allCharsConsumed(variables) + && RestconfConstants.SLASH == currentChar(variables.getOffset(), variables.getData())) { + skipCurrentChar(variables); + } // check if slash is not also the last char in identifier checkValid(!allCharsConsumed(variables), "Identifier cannot end with '/'.", diff --git a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/YangInstanceIdentifierDeserializerTest.java b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/YangInstanceIdentifierDeserializerTest.java index 86aa0307b6..8ff0572f0e 100644 --- a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/YangInstanceIdentifierDeserializerTest.java +++ b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/YangInstanceIdentifierDeserializerTest.java @@ -223,6 +223,41 @@ public class YangInstanceIdentifierDeserializerTest { assertTrue("Empty result expected", Iterables.isEmpty(result)); } + /** + * Test of deserialization String URI with identifiers separated by multiple slashes to + * {@code Iterable}. + */ + @Test + public void deserializeMultipleSlashesTest() { + final Iterable result = YangInstanceIdentifierDeserializer + .create(this.schemaContext, "deserializer-test:contA////list-A=40//list-key"); + + assertEquals("Result does not contains expected number of path arguments", 4, Iterables.size(result)); + + final Iterator iterator = result.iterator(); + + // container + assertEquals("Not expected path argument", + YangInstanceIdentifier.NodeIdentifier.create(QName.create("deserializer:test", "2016-06-06", "contA")), + iterator.next()); + + // list + final QName list = QName.create("deserializer:test", "2016-06-06", "list-A"); + assertEquals("Not expected path argument", + YangInstanceIdentifier.NodeIdentifier.create(list), + iterator.next()); + assertEquals("Not expected path argument", + new YangInstanceIdentifier.NodeIdentifierWithPredicates( + list, QName.create(list, "list-key"), 40).toString(), + iterator.next().toString()); + + // leaf + assertEquals("Not expected path argument", + new YangInstanceIdentifier.NodeIdentifier( + QName.create("deserializer:test", "2016-06-06", "list-key")), + iterator.next()); + } + /** * Negative test when supplied SchemaContext is null. Test is expected to fail with * NullPointerException. @@ -263,34 +298,44 @@ public class YangInstanceIdentifierDeserializerTest { YangInstanceIdentifierDeserializer.create(this.schemaContext, "deserializer-test:contA/"); } + /** + * Negative test of validating identifier when there are multiple slashes after container without next identifier. + * Test is expected to fail with IllegalArgumentException. + */ + @Test + public void validArgIdentifierContainerEndsWithMultipleSlashesNegativeTest() { + this.thrown.expect(IllegalArgumentException.class); + YangInstanceIdentifierDeserializer.create(this.schemaContext, "deserializer-test:contA///"); + } + /** * Negative test of validating identifier when there is a slash after list key values without next identifier. Test * is expected to fail with IllegalArgumentException. */ @Test - public void validArgIdentifierListEndsWithSlashLNegativeTest() { + public void validArgIdentifierListEndsWithSlashNegativeTest() { this.thrown.expect(IllegalArgumentException.class); YangInstanceIdentifierDeserializer.create(this.schemaContext, "deserializer-test:list-one-key=value/"); } /** - * Negative test of creating QName when identifier is empty (example: '/'). Test is expected to fail - * with IllegalArgumentException. + * Negative test of validating identifier when there are multiple slashes after list key values without next + * identifier. Test is expected to fail with IllegalArgumentException. */ @Test - public void prepareQnameEmptyIdentifierNegativeTest() { + public void validArgIdentifierListEndsWithSlashesNegativeTest() { this.thrown.expect(IllegalArgumentException.class); - YangInstanceIdentifierDeserializer.create(this.schemaContext, "/"); + YangInstanceIdentifierDeserializer.create(this.schemaContext, "deserializer-test:list-one-key=value//"); } /** - * Negative test of creating QName when two identifiers are separated by two slashes. Test is - * expected to fail with IllegalArgumentException. + * Negative test of creating QName when identifier is empty (example: '/'). Test is expected to fail + * with IllegalArgumentException. */ @Test - public void prepareQnameTwoSlashesNegativeTest() { + public void prepareQnameEmptyIdentifierNegativeTest() { this.thrown.expect(IllegalArgumentException.class); - YangInstanceIdentifierDeserializer.create(this.schemaContext, "deserializer-test:contA//leaf-A"); + YangInstanceIdentifierDeserializer.create(this.schemaContext, "/"); } /**