Fix unit tests in drools pdp 87/135887/1 java-17
authorFrancescoFioraEst <francesco.fiora@est.tech>
Thu, 31 Aug 2023 11:22:01 +0000 (12:22 +0100)
committerFrancesco Fiora <francesco.fiora@est.tech>
Thu, 31 Aug 2023 11:51:58 +0000 (11:51 +0000)
Issue-ID: POLICY-4815
Change-Id: I27270ec1fd31f73563c4b59308ee42d0787496c1
Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleFeature.java
feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/ControllerSupport.java
feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleFsmUpdateTest.java
feature-lifecycle/src/test/java/org/onap/policy/drools/server/restful/RestLifecycleManagerTest.java

index 27d845b..953f0b3 100644 (file)
@@ -37,7 +37,7 @@ public class LifecycleFeature
      * Lifecycle FSM.
      */
     @Getter
-    public static final LifecycleFsm fsm = new LifecycleFsm();
+    public static LifecycleFsm fsm = new LifecycleFsm();
 
     @Override
     public int getSequenceNumber() {
index 4c1830b..4e0b4bf 100644 (file)
@@ -135,14 +135,10 @@ public class ControllerSupport {
      * Change final marker in static field.
      */
     public static <T> Field unsetFinalStaticAccess(Class<T> clazz, String fieldName)
-            throws NoSuchFieldException, IllegalAccessException {
+            throws NoSuchFieldException {
         Field field = clazz.getDeclaredField(fieldName);
         field.setAccessible(true);
 
-        Field modifiers = Field.class.getDeclaredField("modifiers");
-        modifiers.setAccessible(true);
-        modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
-
         return field;
     }
 
index 31fe3eb..90c0d94 100644 (file)
@@ -163,7 +163,7 @@ public class LifecycleFsmUpdateTest {
             // checkstyle
         }
 
-        //ControllerSupport.setStaticField(LifecycleFeature.class, "fsm", savedFsm);
+        ControllerSupport.setStaticField(LifecycleFeature.class, "fsm", savedFsm);
     }
 
     /**
@@ -177,7 +177,7 @@ public class LifecycleFsmUpdateTest {
                 return new PseudoScheduledExecutorService(new TestTimeMulti());
             }
         };
-        //ControllerSupport.setStaticField(LifecycleFeature.class, "fsm", fsm);
+        ControllerSupport.setStaticField(LifecycleFeature.class, "fsm", fsm);
 
         fsm.setStatusTimerSeconds(15);
         assertTrue(fsm.start());
@@ -206,8 +206,7 @@ public class LifecycleFsmUpdateTest {
         unvalPolicy = getPolicyFromFile(EXAMPLE_OTHER_UNVAL_POLICY_JSON, EXAMPLE_OTHER_UNVAL_POLICY_NAME);
     }
 
-
-    //TODO This test needs to be enabled in java-17 branch
+    @Test
     public void testUpdate() throws CoderException {
         verifyInitState();
 
@@ -365,7 +364,7 @@ public class LifecycleFsmUpdateTest {
     protected void deltaUpdate(List<ToscaPolicy> deploy, List<ToscaPolicy> undeploy, List<ToscaPolicy> active,
             long deployCount, long deploySuccess, long deployFail, long undeployCount, long undeploySuccess,
             long undeployFail) throws CoderException {
-        //assertTrue(fsm.update(getPdpUpdate(deploy, undeploy)));
+        assertTrue(fsm.update(getPdpUpdate(deploy, undeploy)));
         verifyDeploy(active, deployCount, deploySuccess, deployFail, undeployCount, undeploySuccess, undeployFail);
     }
 
index 9a756c7..29ef5a7 100644 (file)
@@ -158,24 +158,20 @@ public class RestLifecycleManagerTest {
      */
     @After
     public void tearDown() {
-        if (fsm != null) {
-            fsm.shutdown();
+        fsm.shutdown();
 
-            NoopTopicFactories.getSourceFactory().destroy();
-            NoopTopicFactories.getSinkFactory().destroy();
+        NoopTopicFactories.getSourceFactory().destroy();
+        NoopTopicFactories.getSinkFactory().destroy();
 
-            HttpClientFactoryInstance.getClientFactory().destroy();
-            HttpServletServerFactoryInstance.getServerFactory().destroy();
+        HttpClientFactoryInstance.getClientFactory().destroy();
+        HttpServletServerFactoryInstance.getServerFactory().destroy();
 
-            PolicyControllerConstants.getFactory().destroy();
-            SystemPersistenceConstants.getManager().setConfigurationDir(null);
-        }
+        PolicyControllerConstants.getFactory().destroy();
+        SystemPersistenceConstants.getManager().setConfigurationDir(null);
 
     }
 
-
-    //TODO The below test needs to be enabled in java-17 branch
-
+    @Test
     public void testMultiPolicyFlow() throws IOException, CoderException {
         /* group assignments */