Eliminate PlainPatchDataTransactionUtilTest 06/107206/1
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 1 Aug 2023 20:42:15 +0000 (22:42 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 1 Aug 2023 20:56:14 +0000 (22:56 +0200)
Move the tests to AbstractRestconfStrategyTest and add proper
specializations. Also adds a few asserts to actually verify things.

JIRA: NETCONF-1107
Change-Id: I64dbfcd10db082d219a4f5e1a25e22319731e8b1
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/transactions/AbstractRestconfStrategyTest.java
restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/transactions/MdsalRestconfStrategyTest.java
restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/transactions/NetconfRestconfStrategyTest.java
restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/PlainPatchDataTransactionUtilTest.java [deleted file]

index 191e575d88c6229f4c5604a056af0276d76bc2d7..d791b4418909e5d9e2c000f0b80faf418eddd4fb 100644 (file)
@@ -25,6 +25,7 @@ import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.nb.rfc8040.AbstractJukeboxTest;
 import org.opendaylight.restconf.nb.rfc8040.WriteDataParams;
 import org.opendaylight.restconf.nb.rfc8040.rests.utils.DeleteDataTransactionUtil;
+import org.opendaylight.restconf.nb.rfc8040.rests.utils.PlainPatchDataTransactionUtil;
 import org.opendaylight.restconf.nb.rfc8040.rests.utils.PostDataTransactionUtil;
 import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
@@ -51,6 +52,22 @@ abstract class AbstractRestconfStrategyTest extends AbstractJukeboxTest {
                 .build())
             .build())
         .build();
+    static final ContainerNode JUKEBOX_WITH_PLAYLIST = Builders.containerBuilder()
+        .withNodeIdentifier(new NodeIdentifier(JUKEBOX_QNAME))
+        .withChild(Builders.mapBuilder()
+            .withNodeIdentifier(new NodeIdentifier(PLAYLIST_QNAME))
+            .withChild(Builders.mapEntryBuilder()
+                .withNodeIdentifier(NodeIdentifierWithPredicates.of(PLAYLIST_QNAME, NAME_QNAME, "MyFavoriteBand-A"))
+                .withChild(ImmutableNodes.leafNode(NAME_QNAME, "MyFavoriteBand-A"))
+                .withChild(ImmutableNodes.leafNode(DESCRIPTION_QNAME, "band description A"))
+                .build())
+            .withChild(Builders.mapEntryBuilder()
+                .withNodeIdentifier(NodeIdentifierWithPredicates.of(PLAYLIST_QNAME, NAME_QNAME, "MyFavoriteBand-B"))
+                .withChild(ImmutableNodes.leafNode(NAME_QNAME, "MyFavoriteBand-B"))
+                .withChild(ImmutableNodes.leafNode(DESCRIPTION_QNAME, "band description B"))
+                .build())
+            .build())
+        .build();
     static final MapNode PLAYLIST = Builders.mapBuilder()
         .withNodeIdentifier(new NodeIdentifier(PLAYLIST_QNAME))
         .withChild(Builders.mapEntryBuilder()
@@ -133,4 +150,31 @@ abstract class AbstractRestconfStrategyTest extends AbstractJukeboxTest {
     }
 
     abstract @NonNull RestconfStrategy testPostDataFailStrategy(DOMException domException);
+
+    @Test
+    public final void testPatchContainerData() {
+        final var response = PlainPatchDataTransactionUtil.patchData(JUKEBOX_IID, EMPTY_JUKEBOX,
+            testPatchContainerDataStrategy(), JUKEBOX_SCHEMA);
+        assertEquals(200, response.getStatus());
+    }
+
+    abstract @NonNull RestconfStrategy testPatchContainerDataStrategy();
+
+    @Test
+    public final void testPatchLeafData() {
+        final var response = PlainPatchDataTransactionUtil.patchData(GAP_IID, GAP_LEAF,
+            testPatchLeafDataStrategy(), JUKEBOX_SCHEMA);
+        assertEquals(200, response.getStatus());
+    }
+
+    abstract @NonNull RestconfStrategy testPatchLeafDataStrategy();
+
+    @Test
+    public final void testPatchListData() {
+        final var response = PlainPatchDataTransactionUtil.patchData(JUKEBOX_IID, JUKEBOX_WITH_PLAYLIST,
+            testPatchListDataStrategy(), JUKEBOX_SCHEMA);
+        assertEquals(200, response.getStatus());
+    }
+
+    abstract @NonNull RestconfStrategy testPatchListDataStrategy();
 }
index a3b29d4c2e8ac7c56f1d6df0c450ef65e25a2f1e..faa61be9a8922cc432f6b986cbd52aa71fe93388 100644 (file)
@@ -128,4 +128,25 @@ public final class MdsalRestconfStrategyTest extends AbstractRestconfStrategyTes
         doReturn(CommitInfo.emptyFluentFuture()).when(readWrite).commit();
         return new MdsalRestconfStrategy(mockDataBroker);
     }
+
+    @Override
+    RestconfStrategy testPatchContainerDataStrategy() {
+        doReturn(readWrite).when(mockDataBroker).newReadWriteTransaction();
+        doReturn(CommitInfo.emptyFluentFuture()).when(readWrite).commit();
+        return new MdsalRestconfStrategy(mockDataBroker);
+    }
+
+    @Override
+    RestconfStrategy testPatchLeafDataStrategy() {
+        doReturn(readWrite).when(mockDataBroker).newReadWriteTransaction();
+        doReturn(CommitInfo.emptyFluentFuture()).when(readWrite).commit();
+        return new MdsalRestconfStrategy(mockDataBroker);
+    }
+
+    @Override
+    RestconfStrategy testPatchListDataStrategy() {
+        doReturn(readWrite).when(mockDataBroker).newReadWriteTransaction();
+        doReturn(CommitInfo.emptyFluentFuture()).when(readWrite).commit();
+        return new MdsalRestconfStrategy(mockDataBroker);
+    }
 }
index c1741ad7c3259ab7dbe3b9b6dbffdfb2e0b45d3f..073f6a629ad5c5e2d71f204264aa18bea7f3d73e 100644 (file)
@@ -91,6 +91,29 @@ public final class NetconfRestconfStrategyTest extends AbstractRestconfStrategyT
         return new NetconfRestconfStrategy(netconfService);
     }
 
+    @Override
+    RestconfStrategy testPatchContainerDataStrategy() {
+        doReturn(Futures.immediateFuture(new DefaultDOMRpcResult())).when(netconfService).merge(any(), any(),any(),
+            any());
+        return new NetconfRestconfStrategy(netconfService);
+    }
+
+    @Override
+    RestconfStrategy testPatchLeafDataStrategy() {
+        doReturn(Futures.immediateFuture(new DefaultDOMRpcResult())).when(netconfService)
+            .merge(any(), any(), any(), any());
+        doReturn(Futures.immediateFuture(new DefaultDOMRpcResult())).when(netconfService).commit();
+        return new NetconfRestconfStrategy(netconfService);
+    }
+
+    @Override
+    RestconfStrategy testPatchListDataStrategy() {
+        doReturn(Futures.immediateFuture(new DefaultDOMRpcResult())).when(netconfService).commit();
+        doReturn(Futures.immediateFuture(new DefaultDOMRpcResult())).when(netconfService)
+            .merge(any(), any(),any(),any());
+        return new NetconfRestconfStrategy(netconfService);
+    }
+
     @Test
     public void testPutCreateContainerData() {
         doReturn(immediateFluentFuture(Optional.empty())).when(netconfService).getConfig(JUKEBOX_IID);
diff --git a/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/PlainPatchDataTransactionUtilTest.java b/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/PlainPatchDataTransactionUtilTest.java
deleted file mode 100644 (file)
index 058f55d..0000000
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- * Copyright (c) 2020 Lumina Networks, Inc. and others. All rights reserved.
- * 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.restconf.nb.rfc8040.rests.utils;
-
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.verify;
-
-import com.google.common.util.concurrent.Futures;
-import java.util.Optional;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
-import org.opendaylight.mdsal.common.api.CommitInfo;
-import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
-import org.opendaylight.mdsal.dom.api.DOMDataBroker;
-import org.opendaylight.mdsal.dom.api.DOMDataTreeReadTransaction;
-import org.opendaylight.mdsal.dom.api.DOMDataTreeReadWriteTransaction;
-import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction;
-import org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult;
-import org.opendaylight.netconf.dom.api.NetconfDataTreeService;
-import org.opendaylight.restconf.nb.rfc8040.AbstractJukeboxTest;
-import org.opendaylight.restconf.nb.rfc8040.rests.transactions.MdsalRestconfStrategy;
-import org.opendaylight.restconf.nb.rfc8040.rests.transactions.NetconfRestconfStrategy;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
-import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
-import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
-import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
-
-@RunWith(MockitoJUnitRunner.StrictStubs.class)
-public class PlainPatchDataTransactionUtilTest extends AbstractJukeboxTest {
-    private static final ContainerNode JUKEBOX_WITH_PLAYLIST = Builders.containerBuilder()
-        .withNodeIdentifier(new NodeIdentifier(JUKEBOX_QNAME))
-        .withChild(Builders.mapBuilder()
-            .withNodeIdentifier(new NodeIdentifier(PLAYLIST_QNAME))
-            .withChild(Builders.mapEntryBuilder()
-                .withNodeIdentifier(NodeIdentifierWithPredicates.of(PLAYLIST_QNAME, NAME_QNAME, "MyFavoriteBand-A"))
-                .withChild(ImmutableNodes.leafNode(NAME_QNAME, "MyFavoriteBand-A"))
-                .withChild(ImmutableNodes.leafNode(DESCRIPTION_QNAME, "band description A"))
-                .build())
-            .withChild(Builders.mapEntryBuilder()
-                .withNodeIdentifier(NodeIdentifierWithPredicates.of(PLAYLIST_QNAME, NAME_QNAME, "MyFavoriteBand-B"))
-                .withChild(ImmutableNodes.leafNode(NAME_QNAME, "MyFavoriteBand-B"))
-                .withChild(ImmutableNodes.leafNode(DESCRIPTION_QNAME, "band description B"))
-                .build())
-            .build())
-        .build();
-
-    @Mock
-    private DOMDataTreeReadWriteTransaction readWrite;
-    @Mock
-    private DOMDataTreeReadTransaction read;
-    @Mock
-    private DOMDataTreeWriteTransaction write;
-    @Mock
-    private DOMDataBroker mockDataBroker;
-    @Mock
-    private NetconfDataTreeService netconfService;
-
-    @Before
-    public void before() {
-        doReturn(Futures.immediateFuture(new DefaultDOMRpcResult())).when(netconfService).lock();
-        doReturn(Futures.immediateFuture(new DefaultDOMRpcResult())).when(netconfService).unlock();
-    }
-
-    @Test
-    public void testPatchContainerData() {
-        doReturn(readWrite).when(mockDataBroker).newReadWriteTransaction();
-        doReturn(CommitInfo.emptyFluentFuture()).when(readWrite).commit();
-        doReturn(Futures.immediateFuture(new DefaultDOMRpcResult())).when(netconfService).commit();
-        doReturn(Futures.immediateFuture(new DefaultDOMRpcResult())).when(netconfService).merge(any(), any(),any(),
-                any());
-
-        PlainPatchDataTransactionUtil.patchData(JUKEBOX_IID, EMPTY_JUKEBOX,
-            new MdsalRestconfStrategy(mockDataBroker), JUKEBOX_SCHEMA);
-        verify(readWrite).merge(LogicalDatastoreType.CONFIGURATION, JUKEBOX_IID, EMPTY_JUKEBOX);
-
-        PlainPatchDataTransactionUtil.patchData(JUKEBOX_IID, EMPTY_JUKEBOX,
-            new NetconfRestconfStrategy(netconfService), JUKEBOX_SCHEMA);
-        verify(netconfService).merge(LogicalDatastoreType.CONFIGURATION, JUKEBOX_IID, EMPTY_JUKEBOX,
-            Optional.empty());
-    }
-
-    @Test
-    public void testPatchLeafData() {
-        doReturn(readWrite).when(mockDataBroker).newReadWriteTransaction();
-        doReturn(CommitInfo.emptyFluentFuture()).when(readWrite).commit();
-        doReturn(Futures.immediateFuture(new DefaultDOMRpcResult())).when(netconfService)
-            .merge(any(), any(), any(), any());
-        doReturn(Futures.immediateFuture(new DefaultDOMRpcResult())).when(netconfService).commit();
-
-        PlainPatchDataTransactionUtil.patchData(GAP_IID, GAP_LEAF, new MdsalRestconfStrategy(mockDataBroker),
-            JUKEBOX_SCHEMA);
-        verify(readWrite).merge(LogicalDatastoreType.CONFIGURATION, GAP_IID, GAP_LEAF);
-
-        PlainPatchDataTransactionUtil.patchData(GAP_IID, GAP_LEAF, new NetconfRestconfStrategy(netconfService),
-            JUKEBOX_SCHEMA);
-        verify(netconfService).lock();
-        verify(netconfService).merge(LogicalDatastoreType.CONFIGURATION, GAP_IID, GAP_LEAF, Optional.empty());
-    }
-
-    @Test
-    public void testPatchListData() {
-        doReturn(readWrite).when(mockDataBroker).newReadWriteTransaction();
-        doReturn(CommitInfo.emptyFluentFuture()).when(readWrite).commit();
-        doReturn(Futures.immediateFuture(new DefaultDOMRpcResult())).when(netconfService).commit();
-        doReturn(Futures.immediateFuture(new DefaultDOMRpcResult())).when(netconfService)
-            .merge(any(), any(),any(),any());
-
-        PlainPatchDataTransactionUtil.patchData(JUKEBOX_IID, JUKEBOX_WITH_PLAYLIST,
-            new MdsalRestconfStrategy(mockDataBroker), JUKEBOX_SCHEMA);
-        verify(readWrite).merge(LogicalDatastoreType.CONFIGURATION, JUKEBOX_IID, JUKEBOX_WITH_PLAYLIST);
-
-        PlainPatchDataTransactionUtil.patchData(JUKEBOX_IID, JUKEBOX_WITH_PLAYLIST,
-            new NetconfRestconfStrategy(netconfService), JUKEBOX_SCHEMA);
-        verify(netconfService).merge(LogicalDatastoreType.CONFIGURATION, JUKEBOX_IID, JUKEBOX_WITH_PLAYLIST,
-            Optional.empty());
-    }
-}