Add seperate class to facilitate unit tests related to the LifeCycleManagementTest

feature/appm-store/pbac
Gathika94 6 years ago
parent 64507c1011
commit c8b983fb93

@ -52,7 +52,7 @@ import org.wso2.carbon.device.application.mgt.core.exception.LifeCycleManagement
import org.wso2.carbon.device.application.mgt.core.exception.NotFoundException;
import org.wso2.carbon.device.application.mgt.core.exception.VisibilityManagementDAOException;
import org.wso2.carbon.device.application.mgt.core.internal.DataHolder;
import org.wso2.carbon.device.application.mgt.core.lifecycle.LifecycleStateManger;
import org.wso2.carbon.device.application.mgt.core.lifecycle.LifecycleStateManager;
import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
@ -77,12 +77,12 @@ public class ApplicationManagerImpl implements ApplicationManager {
private ApplicationDAO applicationDAO;
private ApplicationReleaseDAO applicationReleaseDAO;
private LifecycleStateDAO lifecycleStateDAO;
private LifecycleStateManger lifecycleStateManger;
private LifecycleStateManager lifecycleStateManager;
public ApplicationManagerImpl() {
initDataAccessObjects();
lifecycleStateManger = DataHolder.getInstance().getLifecycleStateManager();
lifecycleStateManager = DataHolder.getInstance().getLifecycleStateManager();
}
private void initDataAccessObjects() {
@ -576,7 +576,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
LifecycleState appLifecycleState = getLifecycleState(applicationId, applicationRelease.getUuid());
LifecycleState newAppLifecycleState = getLifecycleStateInstant(AppLifecycleState.REMOVED.toString(),
appLifecycleState.getCurrentState());
if (lifecycleStateManger.isValidStateChange(newAppLifecycleState.getPreviousState(),
if (lifecycleStateManager.isValidStateChange(newAppLifecycleState.getPreviousState(),
newAppLifecycleState.getCurrentState(),userName,tenantId)) {
this.lifecycleStateDAO
.addLifecycleState(newAppLifecycleState, applicationId, applicationRelease.getUuid(),
@ -623,7 +623,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
LifecycleState newAppLifecycleState = getLifecycleStateInstant(AppLifecycleState.REMOVED.toString(),
appLifecycleState.getCurrentState());
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
if (lifecycleStateManger.isValidStateChange(newAppLifecycleState.getPreviousState(),
if (lifecycleStateManager.isValidStateChange(newAppLifecycleState.getPreviousState(),
newAppLifecycleState.getCurrentState(),userName,tenantId)) {
this.lifecycleStateDAO
.addLifecycleState(newAppLifecycleState, applicationId, applicationRelease.getUuid(),
@ -949,7 +949,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
+ releaseUuid);
}
lifecycleState.setNextStates(new ArrayList<>(lifecycleStateManger.getNextLifecycleStates(lifecycleState.getCurrentState())));
lifecycleState.setNextStates(new ArrayList<>(lifecycleStateManager.getNextLifecycleStates(lifecycleState.getCurrentState())));
} catch (ApplicationManagementException e) {
throw new ApplicationManagementException("Failed to get application and application management", e);
@ -985,7 +985,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
state.setUpdatedBy(userName);
if (state.getCurrentState() != null && state.getPreviousState() != null) {
if (lifecycleStateManger.isValidStateChange(state.getPreviousState(), state.getCurrentState(),userName,
if (lifecycleStateManager.isValidStateChange(state.getPreviousState(), state.getCurrentState(),userName,
tenantId)) {
//todo if current state of the adding lifecycle state is PUBLISHED, need to check whether is there
//todo any other application release in PUBLISHED state for the application( i.e for the appid)

@ -31,7 +31,7 @@ import org.wso2.carbon.device.application.mgt.core.config.ConfigurationManager;
import org.wso2.carbon.device.application.mgt.common.config.UIConfiguration;
import org.wso2.carbon.device.application.mgt.core.dao.common.ApplicationManagementDAOFactory;
import org.wso2.carbon.device.application.mgt.core.impl.ConfigManagerImpl;
import org.wso2.carbon.device.application.mgt.core.lifecycle.LifecycleStateManger;
import org.wso2.carbon.device.application.mgt.core.lifecycle.LifecycleStateManager;
import org.wso2.carbon.device.application.mgt.core.lifecycle.config.LifecycleState;
import org.wso2.carbon.device.application.mgt.core.util.ApplicationManagementUtil;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
@ -79,10 +79,10 @@ public class ApplicationManagementServiceComponent {
List<LifecycleState> lifecycleStates = ConfigurationManager.getInstance().
getConfiguration().getLifecycleStates();
LifecycleStateManger lifecycleStateManger = ApplicationManagementUtil.getLifecycleStateMangerInstance();
lifecycleStateManger.init(lifecycleStates);
DataHolder.getInstance().setLifecycleStateManger(lifecycleStateManger);
bundleContext.registerService(LifecycleStateManger.class.getName(), lifecycleStateManger, null);
LifecycleStateManager lifecycleStateManager = ApplicationManagementUtil.getLifecycleStateMangerInstance();
lifecycleStateManager.init(lifecycleStates);
DataHolder.getInstance().setLifecycleStateManger(lifecycleStateManager);
bundleContext.registerService(LifecycleStateManager.class.getName(), lifecycleStateManager, null);
ApplicationManager applicationManager = ApplicationManagementUtil.getApplicationManagerInstance();
DataHolder.getInstance().setApplicationManager(applicationManager);

@ -23,7 +23,7 @@ import org.wso2.carbon.device.application.mgt.common.services.ApplicationStorage
import org.wso2.carbon.device.application.mgt.common.services.ConfigManager;
import org.wso2.carbon.device.application.mgt.common.services.ReviewManager;
import org.wso2.carbon.device.application.mgt.common.services.SubscriptionManager;
import org.wso2.carbon.device.application.mgt.core.lifecycle.LifecycleStateManger;
import org.wso2.carbon.device.application.mgt.core.lifecycle.LifecycleStateManager;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.user.core.service.RealmService;
@ -44,7 +44,7 @@ public class DataHolder {
private ApplicationStorageManager applicationStorageManager;
private LifecycleStateManger lifecycleStateManger;
private LifecycleStateManager lifecycleStateManager;
private ConfigManager configManager;
@ -106,12 +106,12 @@ public class DataHolder {
return applicationStorageManager;
}
public LifecycleStateManger getLifecycleStateManager() {
return lifecycleStateManger;
public LifecycleStateManager getLifecycleStateManager() {
return lifecycleStateManager;
}
public void setLifecycleStateManger(LifecycleStateManger lifecycleStateManger) {
this.lifecycleStateManger = lifecycleStateManger;
public void setLifecycleStateManger(LifecycleStateManager lifecycleStateManager) {
this.lifecycleStateManager = lifecycleStateManager;
}
public ConfigManager getConfigManager() {

@ -55,10 +55,10 @@ import java.util.Set;
/**
* This class represents the activities related to lifecycle management
*/
public class LifecycleStateManger {
public class LifecycleStateManager {
private Map<String, State> lifecycleStates;
private static Log log = LogFactory.getLog(LifecycleStateManger.class);
private static Log log = LogFactory.getLog(LifecycleStateManager.class);
public void init(List<LifecycleState> states) throws LifecycleManagementException {
lifecycleStates = new HashMap<>();
@ -80,17 +80,6 @@ public class LifecycleStateManger {
}
}
public void initializeLifeCycleDetails(List<LifecycleState> 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<String> getNextLifecycleStates(String currentLifecycleState) {
return lifecycleStates.get(currentLifecycleState.toUpperCase()).getProceedingStates();
@ -136,7 +125,6 @@ public class LifecycleStateManger {
if (pair.getKey().toString().equalsIgnoreCase(currentState)) {
return lifecycleStates.get(pair.getKey().toString());
}
//it.remove();
}
return null;
}
@ -165,19 +153,23 @@ public class LifecycleStateManger {
return null;
}
public boolean isUpdatable(String state){
public boolean isUpdatable(String state) {
State currentState = getMatchingState(state);
if(currentState.getIsAppUpdatable()){
if (currentState.getIsAppUpdatable()) {
return true;
}
return false;
}
public boolean isInstallable(String state){
public boolean isInstallable(String state) {
State currentState = getMatchingState(state);
if(currentState.getIsAppInstallable()){
if (currentState.getIsAppInstallable()) {
return true;
}
return false;
}
public void setLifecycleStates(Map<String, State> lifecycleStates) {
this.lifecycleStates = lifecycleStates;
}
}

@ -27,7 +27,7 @@ import org.wso2.carbon.device.application.mgt.common.services.ReviewManager;
import org.wso2.carbon.device.application.mgt.common.services.SubscriptionManager;
import org.wso2.carbon.device.application.mgt.core.config.ConfigurationManager;
import org.wso2.carbon.device.application.mgt.core.config.Extension;
import org.wso2.carbon.device.application.mgt.core.lifecycle.LifecycleStateManger;
import org.wso2.carbon.device.application.mgt.core.lifecycle.LifecycleStateManager;
import java.lang.reflect.Constructor;
@ -64,10 +64,10 @@ public class ApplicationManagementUtil {
return getInstance(extension, ApplicationStorageManager.class);
}
public static LifecycleStateManger getLifecycleStateMangerInstance() throws InvalidConfigurationException {
public static LifecycleStateManager getLifecycleStateMangerInstance() throws InvalidConfigurationException {
ConfigurationManager configurationManager = ConfigurationManager.getInstance();
Extension extension = configurationManager.getExtension(Extension.Name.LifecycleStateManager);
return getInstance(extension, LifecycleStateManger.class);
return getInstance(extension, LifecycleStateManager.class);
}
private static <T> T getInstance(Extension extension, Class<T> cls) throws InvalidConfigurationException {

@ -0,0 +1,25 @@
package org.wso2.carbon.device.application.mgt.core;
import org.wso2.carbon.device.application.mgt.core.lifecycle.LifecycleStateManager;
import org.wso2.carbon.device.application.mgt.core.lifecycle.State;
import org.wso2.carbon.device.application.mgt.core.lifecycle.config.LifecycleState;
import java.util.HashMap;
import java.util.List;
public class LifeCycleStateManagerTest extends LifecycleStateManager {
public void initializeLifeCycleDetails(List<LifecycleState> states) {
HashMap<String, State> 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()));
}
setLifecycleStates(lifecycleStates);
}
}

@ -6,7 +6,7 @@ import org.testng.annotations.Test;
import org.wso2.carbon.device.application.mgt.common.exception.LifecycleManagementException;
import org.wso2.carbon.device.application.mgt.core.config.Configuration;
import org.wso2.carbon.device.application.mgt.core.config.ConfigurationManager;
import org.wso2.carbon.device.application.mgt.core.lifecycle.LifecycleStateManger;
import org.wso2.carbon.device.application.mgt.core.lifecycle.LifecycleStateManager;
import org.wso2.carbon.device.application.mgt.core.lifecycle.config.LifecycleState;
import java.util.List;
@ -15,72 +15,70 @@ import java.util.Set;
public class LifecycleManagementTest {
private List<LifecycleState> lifecycleStates;
private LifecycleStateManger lifecycleStateManger;
private LifecycleStateManager lifecycleStateManager;
private final String CURRENT_STATE = "Approved";
private final String NEXT_STATE = "Published";
private final String BOGUS_STATE = "Removed";
private final String UPDATABLE_STATE = "Created";
private final String NON_UPDATABLE_STATE= "Removed";
private final String NON_UPDATABLE_STATE = "Removed";
private final String INSTALLABLE_STATE = "Published";
private final String UNINSTALlABLE_STATE = "Removed";
@BeforeClass
public void init() throws LifecycleManagementException {
ConfigurationManager configurationManager = ConfigurationManager.getInstance();
Configuration configuration = configurationManager.getConfiguration();
lifecycleStates = configuration.getLifecycleStates();
lifecycleStateManger = new LifecycleStateManger();
lifecycleStateManger.initializeLifeCycleDetails(lifecycleStates);
lifecycleStateManager = new LifeCycleStateManagerTest();
((LifeCycleStateManagerTest) lifecycleStateManager).initializeLifeCycleDetails(lifecycleStates);
}
@Test
@Test
public void checkValidNextLifecycleState() {
Set<String> proceedingStates = lifecycleStateManger.getNextLifecycleStates(CURRENT_STATE);
Set<String> proceedingStates = lifecycleStateManager.getNextLifecycleStates(CURRENT_STATE);
Assert.assertTrue("Invalid proceeding state of: " + CURRENT_STATE,
proceedingStates.contains(NEXT_STATE.toUpperCase()));
proceedingStates.contains(NEXT_STATE.toUpperCase()));
}
@Test
public void checkInvalidNextLifecycleState() {
Set<String> proceedingStates = lifecycleStateManger.getNextLifecycleStates(CURRENT_STATE);
Set<String> proceedingStates = lifecycleStateManager.getNextLifecycleStates(CURRENT_STATE);
Assert.assertFalse("Invalid proceeding state of: " + CURRENT_STATE,
proceedingStates.contains(BOGUS_STATE.toUpperCase()));
proceedingStates.contains(BOGUS_STATE.toUpperCase()));
}
@Test
public void CheckUpdatableState() {
Boolean isUpdatable = lifecycleStateManger.isUpdatable(UPDATABLE_STATE);
Boolean isUpdatable = lifecycleStateManager.isUpdatable(UPDATABLE_STATE);
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);
Boolean isUpdatable = lifecycleStateManager.isUpdatable(NON_UPDATABLE_STATE);
Assert.assertFalse("Non Updatable state: " + NON_UPDATABLE_STATE, isUpdatable);
}
@Test
public void CheckInstallableState() {
Boolean isInstallable = lifecycleStateManger.isInstallable(INSTALLABLE_STATE);
Assert.assertTrue("Installable state: " + INSTALLABLE_STATE,isInstallable);
Boolean isInstallable = lifecycleStateManager.isInstallable(INSTALLABLE_STATE);
Assert.assertTrue("Installable state: " + INSTALLABLE_STATE, isInstallable);
}
@Test
public void CheckUnInstallableState() {
Boolean isInstallable = lifecycleStateManger.isInstallable(UNINSTALlABLE_STATE);
Assert.assertFalse("UnInstallable state: " + UNINSTALlABLE_STATE,isInstallable);
Boolean isInstallable = lifecycleStateManager.isInstallable(UNINSTALlABLE_STATE);
Assert.assertFalse("UnInstallable state: " + UNINSTALlABLE_STATE, isInstallable);
}
@Test
public void check() {
Set<String> proceedingStates = lifecycleStateManger.getNextLifecycleStates(CURRENT_STATE);
Set<String> proceedingStates = lifecycleStateManager.getNextLifecycleStates(CURRENT_STATE);
Assert.assertFalse("Invalid proceeding state of: " + CURRENT_STATE,
proceedingStates.contains(BOGUS_STATE.toUpperCase()));
}
}

@ -29,7 +29,7 @@
<ClassName>org.wso2.carbon.device.application.mgt.core.impl.ReviewManagerImpl</ClassName>
</Extension>
<Extension name="LifecycleStateManager">
<ClassName>org.wso2.carbon.device.application.mgt.core.lifecycle.LifecycleStateManger</ClassName>
<ClassName>org.wso2.carbon.device.application.mgt.core.lifecycle.LifecycleStateManager</ClassName>
</Extension>
<Extension name="SubscriptionManager">
<ClassName>org.wso2.carbon.device.application.mgt.core.impl.SubscriptionManagerImpl</ClassName>

@ -29,7 +29,7 @@
<ClassName>org.wso2.carbon.device.application.mgt.core.impl.ReviewManagerImpl</ClassName>
</Extension>
<Extension name="LifecycleStateManager">
<ClassName>org.wso2.carbon.device.application.mgt.core.lifecycle.LifecycleStateManger</ClassName>
<ClassName>org.wso2.carbon.device.application.mgt.core.lifecycle.LifecycleStateManager</ClassName>
</Extension>
<Extension name="SubscriptionManager">
<ClassName>org.wso2.carbon.device.application.mgt.core.impl.SubscriptionManagerImpl</ClassName>

Loading…
Cancel
Save