From 64507c101162a25e9178eeee03894e877658e73a Mon Sep 17 00:00:00 2001 From: Gathika94 Date: Thu, 4 Apr 2019 05:58:42 +0530 Subject: [PATCH] ensure unit tests related to LifeCycleManager running without issues --- .../mgt/core/lifecycle/LifecycleStateManger.java | 14 +++++++++++++- .../LifecycleManagementTest.java | 9 +++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/lifecycle/LifecycleStateManger.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/lifecycle/LifecycleStateManger.java index 9ee8744cac..4e443d85de 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/lifecycle/LifecycleStateManger.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/lifecycle/LifecycleStateManger.java @@ -80,6 +80,18 @@ public class LifecycleStateManger { } } + public void initializeLifeCycleDetails(List states){ + lifecycleStates = new HashMap<>(); + for (LifecycleState s : states) { + if (s.getProceedingStates() != null) { + s.getProceedingStates().replaceAll(String::toUpperCase); + } + lifecycleStates.put(s.getName().toUpperCase(), new State(s.getName().toUpperCase(), + s.getProceedingStates(), s.getPermission(), s.isAppUpdatable(), s.isAppInstallable(), + s.isInitialState(), s.isEndState())); + } + } + public Set getNextLifecycleStates(String currentLifecycleState) { return lifecycleStates.get(currentLifecycleState.toUpperCase()).getProceedingStates(); } @@ -124,7 +136,7 @@ public class LifecycleStateManger { if (pair.getKey().toString().equalsIgnoreCase(currentState)) { return lifecycleStates.get(pair.getKey().toString()); } - it.remove(); + //it.remove(); } return null; } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/java/org.wso2.carbon.device.application.mgt.core/LifecycleManagementTest.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/java/org.wso2.carbon.device.application.mgt.core/LifecycleManagementTest.java index 2fa5a68506..bd02db0bb7 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/java/org.wso2.carbon.device.application.mgt.core/LifecycleManagementTest.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/java/org.wso2.carbon.device.application.mgt.core/LifecycleManagementTest.java @@ -33,10 +33,10 @@ public class LifecycleManagementTest { Configuration configuration = configurationManager.getConfiguration(); lifecycleStates = configuration.getLifecycleStates(); lifecycleStateManger = new LifecycleStateManger(); - lifecycleStateManger.init(lifecycleStates); + lifecycleStateManger.initializeLifeCycleDetails(lifecycleStates); } - @Test + @Test public void checkValidNextLifecycleState() { Set proceedingStates = lifecycleStateManger.getNextLifecycleStates(CURRENT_STATE); Assert.assertTrue("Invalid proceeding state of: " + CURRENT_STATE, @@ -53,10 +53,11 @@ public class LifecycleManagementTest { @Test public void CheckUpdatableState() { Boolean isUpdatable = lifecycleStateManger.isUpdatable(UPDATABLE_STATE); - Assert.assertTrue("Updatable state: " + CURRENT_STATE, isUpdatable); + System.out.println(isUpdatable); + Assert.assertTrue("Updatable state: " + UPDATABLE_STATE, isUpdatable); } - @Test + @Test public void CheckNonUpdatableState() { Boolean isUpdatable = lifecycleStateManger.isUpdatable(NON_UPDATABLE_STATE); Assert.assertFalse("Non Updatable state: " + CURRENT_STATE, isUpdatable);