BUG-868: do not use YangInstanceIdentifier.getPath()
authorRobert Varga <rovarga@cisco.com>
Thu, 20 Nov 2014 09:59:09 +0000 (10:59 +0100)
committerTony Tkacik <ttkacik@cisco.com>
Thu, 20 Nov 2014 11:29:54 +0000 (11:29 +0000)
This method has been deprecated, so stop using it.

Change-Id: Ibfaf7e40a3d119ed05ff5743c4869e345d18e298
Signed-off-by: Robert Varga <rovarga@cisco.com>
opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestPostOperationTest.java
opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/URITest.java
opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/XmlAndJsonToCnSnInstanceIdentifierTest.java

index 97cd67d34b70095a1571c1384e4a0e46c61f155a..423825827a4749f559f4b831fad5a71c98338750 100644 (file)
@@ -16,8 +16,8 @@ import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 import static org.opendaylight.controller.sal.restconf.impl.test.RestOperationUtils.XML;
-
 import com.google.common.base.Optional;
+import com.google.common.collect.ImmutableList;
 import com.google.common.util.concurrent.CheckedFuture;
 import com.google.common.util.concurrent.Futures;
 import java.io.IOException;
@@ -188,7 +188,7 @@ public class RestPostOperationTest extends JerseyTest {
         assertEquals(400, post(uri, MediaType.APPLICATION_JSON, ""));
     }
 
-    private void mockInvokeRpc(CompositeNode result, boolean sucessful, Collection<RpcError> errors) {
+    private void mockInvokeRpc(final CompositeNode result, final boolean sucessful, final Collection<RpcError> errors) {
 
         DummyRpcResult.Builder<CompositeNode> builder = new DummyRpcResult.Builder<CompositeNode>().result(result)
                 .isSuccessful(sucessful);
@@ -200,7 +200,7 @@ public class RestPostOperationTest extends JerseyTest {
                 Futures.<RpcResult<CompositeNode>> immediateFuture(rpcResult));
     }
 
-    private void mockInvokeRpc(CompositeNode result, boolean sucessful) {
+    private void mockInvokeRpc(final CompositeNode result, final boolean sucessful) {
         mockInvokeRpc(result, sucessful, Collections.<RpcError> emptyList());
     }
 
@@ -229,14 +229,14 @@ public class RestPostOperationTest extends JerseyTest {
         assertEquals(204, post(URI_1, Draft02.MediaTypes.DATA + XML, xmlTestInterface));
         verify(brokerFacade).commitConfigurationDataPost(instanceIdCaptor.capture(), compNodeCaptor.capture());
         String identifier = "[(urn:ietf:params:xml:ns:yang:test-interface?revision=2014-07-01)interfaces]";
-        assertEquals(identifier, instanceIdCaptor.getValue().getPath().toString());
+        assertEquals(identifier, ImmutableList.copyOf(instanceIdCaptor.getValue().getPathArguments()).toString());
 
         String URI_2 = "/config/test-interface:interfaces";
         assertEquals(204, post(URI_2, Draft02.MediaTypes.DATA + XML, xmlBlockData));
         verify(brokerFacade, times(2))
                 .commitConfigurationDataPost(instanceIdCaptor.capture(), compNodeCaptor.capture());
         identifier = "[(urn:ietf:params:xml:ns:yang:test-interface?revision=2014-07-01)interfaces, (urn:ietf:params:xml:ns:yang:test-interface?revision=2014-07-01)block]";
-        assertEquals(identifier, instanceIdCaptor.getValue().getPath().toString());
+        assertEquals(identifier, ImmutableList.copyOf(instanceIdCaptor.getValue().getPathArguments()).toString());
     }
 
     @Test
@@ -264,7 +264,7 @@ public class RestPostOperationTest extends JerseyTest {
         restconfImpl.setControllerContext(controllerContext);
     }
 
-    private int post(String uri, String mediaType, String data) {
+    private int post(final String uri, final String mediaType, final String data) {
         return target(uri).request(mediaType).post(Entity.entity(data, mediaType)).getStatus();
     }
 
index 4900e6a66f1ab9d9d3324c85e6ca5c98f103e5ba..efd5482bfe7925e1dd81706544ca8d1f178ea2ed 100644 (file)
@@ -13,8 +13,8 @@ import static org.junit.Assert.assertTrue;
 import static org.mockito.Matchers.any;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
-
 import com.google.common.base.Optional;
+import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Iterables;
 import java.io.FileNotFoundException;
 import java.util.Set;
@@ -124,7 +124,7 @@ public class URITest {
                 .toInstanceIdentifier("simple-nodes:users/yang-ext:mount/test-interface2:class/student/name");
         assertEquals(
                 "[(urn:ietf:params:xml:ns:yang:test-interface2?revision=2014-08-01)class, (urn:ietf:params:xml:ns:yang:test-interface2?revision=2014-08-01)student[{(urn:ietf:params:xml:ns:yang:test-interface2?revision=2014-08-01)name=name}]]",
-                instanceIdentifier.getInstanceIdentifier().getPath().toString());
+                ImmutableList.copyOf(instanceIdentifier.getInstanceIdentifier().getPathArguments()).toString());
     }
 
     @Test
@@ -140,8 +140,7 @@ public class URITest {
         exception.expect(RestconfDocumentedException.class);
 
         controllerContext.setMountService(null);
-        InstanceIdentifierContext instanceIdentifier = controllerContext
-                .toInstanceIdentifier("simple-nodes:users/yang-ext:mount/test-interface2:class/student/name");
+        controllerContext.toInstanceIdentifier("simple-nodes:users/yang-ext:mount/test-interface2:class/student/name");
     }
 
     @Test
@@ -149,8 +148,7 @@ public class URITest {
         initMountService(false);
         exception.expect(RestconfDocumentedException.class);
 
-        InstanceIdentifierContext instanceIdentifier = controllerContext
-                .toInstanceIdentifier("simple-nodes:users/yang-ext:mount/test-interface2:class");
+        controllerContext.toInstanceIdentifier("simple-nodes:users/yang-ext:mount/test-interface2:class");
     }
 
     public void initMountService(final boolean withSchema) {
index 23e868c8b2d738e040081603234a86038146f593..6bd5178f1343a6b328ea641613abda7424896dc7 100644 (file)
@@ -8,12 +8,12 @@
 package org.opendaylight.controller.sal.restconf.impl.test;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
-
 import java.io.IOException;
 import java.net.URISyntaxException;
-import java.util.List;
+import java.util.Iterator;
 import java.util.Map;
 import javax.ws.rs.WebApplicationException;
 import org.junit.BeforeClass;
@@ -22,12 +22,12 @@ import org.opendaylight.controller.sal.rest.impl.JsonToCompositeNodeProvider;
 import org.opendaylight.controller.sal.rest.impl.XmlToCompositeNodeProvider;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
+import org.opendaylight.yangtools.yang.data.api.Node;
+import org.opendaylight.yangtools.yang.data.api.SimpleNode;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
-import org.opendaylight.yangtools.yang.data.api.Node;
-import org.opendaylight.yangtools.yang.data.api.SimpleNode;
 
 public class XmlAndJsonToCnSnInstanceIdentifierTest extends YangAndXmlAndDataSchemaLoader {
 
@@ -80,52 +80,51 @@ public class XmlAndJsonToCnSnInstanceIdentifierTest extends YangAndXmlAndDataSch
         verifyLeafListPredicate(cnSn);
     }
 
-    private void verifyLeafListPredicate(CompositeNode cnSn) throws URISyntaxException {
+    private void verifyLeafListPredicate(final CompositeNode cnSn) throws URISyntaxException {
         SimpleNode<?> lf11 = getSnWithInstanceIdentifierWhenLeafList(cnSn);
         Object value = lf11.getValue();
         assertTrue(value instanceof YangInstanceIdentifier);
 
         YangInstanceIdentifier instanceIdentifier = (YangInstanceIdentifier) value;
-        List<PathArgument> pathArguments = instanceIdentifier.getPath();
-        assertEquals(3, pathArguments.size());
+        Iterator<PathArgument> it = instanceIdentifier.getPathArguments().iterator();
         String revisionDate = "2014-01-17";
-        assertEquals(TestUtils.buildQName("cont", "instance:identifier:module", revisionDate), pathArguments.get(0)
-                .getNodeType());
-        assertEquals(TestUtils.buildQName("cont1", "instance:identifier:module", revisionDate), pathArguments.get(1)
-                .getNodeType());
-        assertEquals(TestUtils.buildQName("lflst11", "augment:module:leaf:list", "2014-01-27"), pathArguments.get(2)
-                .getNodeType());
 
-        assertTrue(pathArguments.get(2) instanceof NodeWithValue);
-        assertEquals("lflst11_1", ((NodeWithValue) pathArguments.get(2)).getValue());
+        assertEquals(TestUtils.buildQName("cont", "instance:identifier:module", revisionDate), it.next().getNodeType());
+        assertEquals(TestUtils.buildQName("cont1", "instance:identifier:module", revisionDate), it.next().getNodeType());
+
+        PathArgument arg = it.next();
+        assertFalse(it.hasNext());
+        assertEquals(TestUtils.buildQName("lflst11", "augment:module:leaf:list", "2014-01-27"), arg.getNodeType());
+
+        assertTrue(arg instanceof NodeWithValue);
+        assertEquals("lflst11_1", ((NodeWithValue) arg).getValue());
 
     }
 
-    private void verifyListPredicate(CompositeNode cnSn) throws URISyntaxException {
+    private void verifyListPredicate(final CompositeNode cnSn) throws URISyntaxException {
         SimpleNode<?> lf111 = getSnWithInstanceIdentifierWhenList(cnSn);
         Object value = lf111.getValue();
         assertTrue(value instanceof YangInstanceIdentifier);
 
         YangInstanceIdentifier instanceIdentifier = (YangInstanceIdentifier) value;
-        List<PathArgument> pathArguments = instanceIdentifier.getPath();
-        assertEquals(4, pathArguments.size());
+        Iterator<PathArgument> it = instanceIdentifier.getPathArguments().iterator();
         String revisionDate = "2014-01-17";
-        assertEquals(TestUtils.buildQName("cont", "instance:identifier:module", revisionDate), pathArguments.get(0)
-                .getNodeType());
-        assertEquals(TestUtils.buildQName("cont1", "instance:identifier:module", revisionDate), pathArguments.get(1)
-                .getNodeType());
-        assertEquals(TestUtils.buildQName("lst11", "augment:module", revisionDate), pathArguments.get(2).getNodeType());
-        assertEquals(TestUtils.buildQName("lf112", "augment:augment:module", revisionDate), pathArguments.get(3)
-                .getNodeType());
-
-        assertTrue(pathArguments.get(2) instanceof NodeIdentifierWithPredicates);
-        Map<QName, Object> predicates = ((NodeIdentifierWithPredicates) pathArguments.get(2)).getKeyValues();
+        assertEquals(TestUtils.buildQName("cont", "instance:identifier:module", revisionDate), it.next().getNodeType());
+        assertEquals(TestUtils.buildQName("cont1", "instance:identifier:module", revisionDate), it.next().getNodeType());
+
+        PathArgument arg = it.next();
+        assertEquals(TestUtils.buildQName("lst11", "augment:module", revisionDate), arg.getNodeType());
+        assertEquals(TestUtils.buildQName("lf112", "augment:augment:module", revisionDate), it.next().getNodeType());
+        assertFalse(it.hasNext());
+
+        assertTrue(arg instanceof NodeIdentifierWithPredicates);
+        Map<QName, Object> predicates = ((NodeIdentifierWithPredicates) arg).getKeyValues();
         assertEquals(2, predicates.size());
         assertEquals("value1", predicates.get(TestUtils.buildQName("keyvalue111", "augment:module", revisionDate)));
         assertEquals("value2", predicates.get(TestUtils.buildQName("keyvalue112", "augment:module", revisionDate)));
     }
 
-    private SimpleNode<?> getSnWithInstanceIdentifierWhenList(CompositeNode cnSn) throws URISyntaxException {
+    private SimpleNode<?> getSnWithInstanceIdentifierWhenList(final CompositeNode cnSn) throws URISyntaxException {
         CompositeNode cont1 = cnSn.getFirstCompositeByName(TestUtils.buildQName("cont1", "instance:identifier:module",
                 "2014-01-17"));
         assertNotNull(cont1);
@@ -138,7 +137,7 @@ public class XmlAndJsonToCnSnInstanceIdentifierTest extends YangAndXmlAndDataSch
         return lf111;
     }
 
-    private SimpleNode<?> getSnWithInstanceIdentifierWhenLeafList(CompositeNode cnSn) throws URISyntaxException {
+    private SimpleNode<?> getSnWithInstanceIdentifierWhenLeafList(final CompositeNode cnSn) throws URISyntaxException {
         CompositeNode cont1 = cnSn.getFirstCompositeByName(TestUtils.buildQName("cont1", "instance:identifier:module",
                 "2014-01-17"));
         assertNotNull(cont1);