Do not use powermock in hwvtepsouthbound-impl 78/94578/1
authorRobert Varga <robert.varga@pantheon.tech>
Sat, 9 Jan 2021 20:32:12 +0000 (21:32 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Sun, 10 Jan 2021 08:53:06 +0000 (09:53 +0100)
Replace reflection access with package @VisibleForTesting fields.

Change-Id: Ic900de4ae5efa8123e1c2ca377b442d39ab011ea
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
hwvtepsouthbound/hwvtepsouthbound-impl/pom.xml
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transact/McastMacsRemoteUpdateCommand.java
hwvtepsouthbound/hwvtepsouthbound-impl/src/test/java/org/opendaylight/ovsdb/hwvtepsouthbound/DataChangeListenerTestBase.java
hwvtepsouthbound/hwvtepsouthbound-impl/src/test/java/org/opendaylight/ovsdb/hwvtepsouthbound/transact/DependencyQueueTest.java [moved from hwvtepsouthbound/hwvtepsouthbound-impl/src/test/java/org/opendaylight/ovsdb/hwvtepsouthbound/DependencyQueueTest.java with 89% similarity]
hwvtepsouthbound/hwvtepsouthbound-impl/src/test/java/org/opendaylight/ovsdb/hwvtepsouthbound/transact/UnMetDependencyGetterTest.java [moved from hwvtepsouthbound/hwvtepsouthbound-impl/src/test/java/org/opendaylight/ovsdb/hwvtepsouthbound/UnMetDependencyGetterTest.java with 88% similarity]

index 0610ae17d1c4b7716ecfd191cd395a6db83b475b..7390ae50d4a0a2de41852c461643fc949331d7dd 100644 (file)
@@ -92,25 +92,16 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
       <groupId>org.opendaylight.mdsal</groupId>
       <artifactId>mdsal-binding-spi</artifactId>
     </dependency>
-    <!-- Testing Dependencies -->
     <dependency>
-      <groupId>org.slf4j</groupId>
-      <artifactId>slf4j-simple</artifactId>
-      <scope>test</scope>
+      <groupId>org.apache.karaf.shell</groupId>
+      <artifactId>org.apache.karaf.shell.core</artifactId>
     </dependency>
+
+    <!-- Testing Dependencies -->
     <dependency>
       <groupId>org.opendaylight.mdsal</groupId>
       <artifactId>mdsal-binding-test-utils</artifactId>
     </dependency>
-    <dependency>
-      <groupId>org.powermock</groupId>
-      <artifactId>powermock-reflect</artifactId>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.karaf.shell</groupId>
-      <artifactId>org.apache.karaf.shell.core</artifactId>
-    </dependency>
   </dependencies>
 
   <build>
index a47f5673573580a42b3f4c64acb0b66d33056e38..bc8a5f966700446d95c3488cbbb32e5e9daa2d45 100644 (file)
@@ -9,6 +9,7 @@ package org.opendaylight.ovsdb.hwvtepsouthbound.transact;
 
 import static org.opendaylight.ovsdb.lib.operations.Operations.op;
 
+import com.google.common.annotations.VisibleForTesting;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Sets;
 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
@@ -41,7 +42,9 @@ import org.slf4j.LoggerFactory;
 public class McastMacsRemoteUpdateCommand
         extends AbstractTransactCommand<RemoteMcastMacs, RemoteMcastMacsKey, HwvtepGlobalAugmentation> {
     private static final Logger LOG = LoggerFactory.getLogger(McastMacsRemoteUpdateCommand.class);
-    private static final McastMacUnMetDependencyGetter MCAST_MAC_DATA_VALIDATOR = new McastMacUnMetDependencyGetter();
+
+    @VisibleForTesting
+    static final McastMacUnMetDependencyGetter MCAST_MAC_DATA_VALIDATOR = new McastMacUnMetDependencyGetter();
 
     public McastMacsRemoteUpdateCommand(final HwvtepOperationalState state,
             final Collection<DataTreeModification<Node>> changes) {
index f0c631a7c3bd2768c046e1d22b1780df7f4cae2b..59775b9d5c844c72adfd6a45bd55e87a59aa1af3 100644 (file)
@@ -75,8 +75,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 public class DataChangeListenerTestBase extends AbstractDataBrokerTest {
-
-    static Logger LOG = LoggerFactory.getLogger(DataChangeListenerTestBase.class);
+    private static final Logger LOG = LoggerFactory.getLogger(DataChangeListenerTestBase.class);
 
     static DataBroker dataBroker;
 
@@ -89,13 +88,13 @@ public class DataChangeListenerTestBase extends AbstractDataBrokerTest {
     Operations operations;
     HwvtepDataChangeListener hwvtepDataChangeListener;
     HwvtepConnectionManager hwvtepConnectionManager;
-    HwvtepConnectionInstance connectionInstance;
+    protected HwvtepConnectionInstance connectionInstance;
 
     ArgumentCaptor<TypedBaseTable> insertOpCapture;
     ArgumentCaptor<List> transactCaptor;
 
     String nodeUuid;
-    InstanceIdentifier<Node> nodeIid;
+    protected InstanceIdentifier<Node> nodeIid;
     InstanceIdentifier<LogicalSwitches> ls0Iid;
     InstanceIdentifier<LogicalSwitches> ls1Iid;
 
@@ -133,7 +132,7 @@ public class DataChangeListenerTestBase extends AbstractDataBrokerTest {
         deleteNode(LogicalDatastoreType.CONFIGURATION);
     }
 
-    static final void setFinalStatic(final Class<?> cls, final String fieldName, final Object newValue)
+    protected static final void setFinalStatic(final Class<?> cls, final String fieldName, final Object newValue)
             throws SecurityException, ReflectiveOperationException {
         Field[] fields = FieldUtils.getAllFields(cls);
         for (Field field : fields) {
@@ -241,8 +240,8 @@ public class DataChangeListenerTestBase extends AbstractDataBrokerTest {
         tx.commit();
     }
 
-    Node addData(final LogicalDatastoreType logicalDatastoreType, final Class<? extends DataObject> dataObject,
-            final String[]... data) {
+    protected final Node addData(final LogicalDatastoreType logicalDatastoreType,
+            final Class<? extends DataObject> dataObject, final String[]... data) {
         NodeBuilder nodeBuilder = prepareNode(nodeIid);
         HwvtepGlobalAugmentationBuilder builder = new HwvtepGlobalAugmentationBuilder();
         if (LogicalSwitches.class == dataObject) {
@@ -5,8 +5,7 @@
  * 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.ovsdb.hwvtepsouthbound;
+package org.opendaylight.ovsdb.hwvtepsouthbound.transact;
 
 import static org.junit.Assert.assertEquals;
 
@@ -18,11 +17,9 @@ import org.junit.runner.RunWith;
 import org.mockito.Mockito;
 import org.mockito.junit.MockitoJUnitRunner;
 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
-import org.opendaylight.ovsdb.hwvtepsouthbound.transact.DependencyQueue;
-import org.opendaylight.ovsdb.hwvtepsouthbound.transact.DependentJob;
-import org.opendaylight.ovsdb.hwvtepsouthbound.transact.HwvtepOperationalState;
-import org.opendaylight.ovsdb.hwvtepsouthbound.transact.McastMacsRemoteUpdateCommand;
-import org.opendaylight.ovsdb.hwvtepsouthbound.transact.UnMetDependencyGetter;
+import org.opendaylight.ovsdb.hwvtepsouthbound.DataChangeListenerTestBase;
+import org.opendaylight.ovsdb.hwvtepsouthbound.SameThreadScheduledExecutor;
+import org.opendaylight.ovsdb.hwvtepsouthbound.TestBuilders;
 import org.opendaylight.ovsdb.lib.notation.UUID;
 import org.opendaylight.ovsdb.lib.operations.TransactionBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation;
@@ -34,7 +31,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hw
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint;
 import org.opendaylight.yangtools.yang.binding.Identifiable;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.powermock.reflect.Whitebox;
 
 @RunWith(MockitoJUnitRunner.Silent.class)
 public class DependencyQueueTest extends DataChangeListenerTestBase {
@@ -52,8 +48,7 @@ public class DependencyQueueTest extends DataChangeListenerTestBase {
     Map<Class<? extends Identifiable>, List<InstanceIdentifier>> unMetDependencies;
 
     void setupForTest() throws Exception {
-        mcastMacDataValidator = Whitebox.getInternalState(McastMacsRemoteUpdateCommand.class,
-                UnMetDependencyGetter.class);
+        mcastMacDataValidator = McastMacsRemoteUpdateCommand.MCAST_MAC_DATA_VALIDATOR;
         opState = new HwvtepOperationalState(connectionInstance);
         mac = TestBuilders.buildRemoteMcastMacs(nodeIid,"FF:FF:FF:FF:FF:FF", "ls0",
                 new String[]{"192.168.122.20", "192.168.122.30"});
@@ -5,8 +5,7 @@
  * 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.ovsdb.hwvtepsouthbound;
+package org.opendaylight.ovsdb.hwvtepsouthbound.transact;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNull;
@@ -16,9 +15,8 @@ import java.util.Map;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.junit.MockitoJUnitRunner;
-import org.opendaylight.ovsdb.hwvtepsouthbound.transact.HwvtepOperationalState;
-import org.opendaylight.ovsdb.hwvtepsouthbound.transact.McastMacsRemoteUpdateCommand;
-import org.opendaylight.ovsdb.hwvtepsouthbound.transact.UnMetDependencyGetter;
+import org.opendaylight.ovsdb.hwvtepsouthbound.DataChangeListenerTestBase;
+import org.opendaylight.ovsdb.hwvtepsouthbound.TestBuilders;
 import org.opendaylight.ovsdb.lib.notation.UUID;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepNodeName;
@@ -28,7 +26,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hw
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint;
 import org.opendaylight.yangtools.yang.binding.Identifiable;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.powermock.reflect.Whitebox;
 
 @RunWith(MockitoJUnitRunner.Silent.class)
 public class UnMetDependencyGetterTest extends DataChangeListenerTestBase {
@@ -40,8 +37,7 @@ public class UnMetDependencyGetterTest extends DataChangeListenerTestBase {
     Map<Class<? extends Identifiable>, List<InstanceIdentifier>> unMetDependencies;
 
     void setupForTest() {
-        mcastMacDataValidator =
-                Whitebox.getInternalState(McastMacsRemoteUpdateCommand.class, UnMetDependencyGetter.class);
+        mcastMacDataValidator = McastMacsRemoteUpdateCommand.MCAST_MAC_DATA_VALIDATOR;
         opState = new HwvtepOperationalState(connectionInstance);
         mac = TestBuilders.buildRemoteMcastMacs(nodeIid, "FF:FF:FF:FF:FF:FF", "ls0",
                 new String[] {"192.168.122.20", "192.168.122.30"});