From 00819fe4b67b6074f92897fa8cc5d9558dd89d2e Mon Sep 17 00:00:00 2001 From: manoj Date: Wed, 15 Jul 2015 07:38:13 +0530 Subject: [PATCH] Unit tests, application update --- .../device/mgt/core/TestDeviceManager.java | 76 ++++++++++++++++ ...licationManagementProviderServiceTest.java | 88 +++++++++++++++++++ 2 files changed, 164 insertions(+) create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManager.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagementProviderServiceTest.java diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManager.java new file mode 100644 index 0000000000..1e83880cb7 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManager.java @@ -0,0 +1,76 @@ +package org.wso2.carbon.device.mgt.core; + +import org.wso2.carbon.device.mgt.common.*; + +import java.util.List; + +public class TestDeviceManager implements DeviceManager { + + @Override + public FeatureManager getFeatureManager() { + return null; + } + + @Override + public boolean enrollDevice(Device device) throws DeviceManagementException { + return true; + } + + @Override + public boolean modifyEnrollment(Device device) throws DeviceManagementException { + return false; + } + + @Override + public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException { + return false; + } + + @Override + public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException { + return false; + } + + @Override + public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException { + return false; + } + + @Override + public boolean setActive(DeviceIdentifier deviceId, boolean status) throws DeviceManagementException { + return false; + } + + @Override + public List getAllDevices() throws DeviceManagementException { + return null; + } + + @Override + public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException { + return null; + } + + @Override + public boolean updateDeviceInfo(DeviceIdentifier deviceIdentifier, Device device) + throws DeviceManagementException { + return false; + } + + @Override + public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) + throws DeviceManagementException { + return false; + } + + @Override + public boolean isClaimable(DeviceIdentifier deviceId) throws DeviceManagementException { + return false; + } + + @Override + public boolean setStatus(DeviceIdentifier deviceId, String currentOwner, EnrolmentInfo.Status status) + throws DeviceManagementException { + return false; + } +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagementProviderServiceTest.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagementProviderServiceTest.java new file mode 100644 index 0000000000..a8142f2d5c --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagementProviderServiceTest.java @@ -0,0 +1,88 @@ +package org.wso2.carbon.device.mgt.core.app.mgt; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.testng.Assert; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; +import org.wso2.carbon.device.mgt.common.Device; +import org.wso2.carbon.device.mgt.common.DeviceIdentifier; +import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.app.mgt.Application; +import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException; +import org.wso2.carbon.device.mgt.core.DeviceManagementPluginRepository; +import org.wso2.carbon.device.mgt.core.TestDeviceManagementService; +import org.wso2.carbon.device.mgt.core.api.mgt.ApplicationManagementProviderService; +import org.wso2.carbon.device.mgt.core.app.mgt.ApplicationManagerProviderServiceImpl; +import org.wso2.carbon.device.mgt.core.app.mgt.config.AppManagementConfig; +import org.wso2.carbon.device.mgt.core.common.TestDataHolder; + +import java.util.ArrayList; +import java.util.List; + +public class ApplicationManagementProviderServiceTest { + + private ApplicationManagementProviderService appMgtProvider; + private static final Log log = LogFactory.getLog(ApplicationManagementProviderServiceTest.class); + private DeviceManagementPluginRepository deviceManagementPluginRepository = null; + + @BeforeClass + public void init() { + deviceManagementPluginRepository = new DeviceManagementPluginRepository(); + TestDeviceManagementService testDeviceManagementService = new TestDeviceManagementService(TestDataHolder.TEST_DEVICE_TYPE); + try { + deviceManagementPluginRepository.addDeviceManagementProvider(testDeviceManagementService); + } catch (DeviceManagementException e) { + String msg = "Error occurred while initiate plugins '" + TestDataHolder.TEST_DEVICE_TYPE + "'"; + log.error(msg, e); + Assert.fail(msg, e); + } + } + + @Test + public void updateApplicationTest(){ + + List applications = new ArrayList(); + + Application application1 = TestDataHolder.generateApplicationDummyData("org.wso2.app1"); + Application application2 = TestDataHolder.generateApplicationDummyData("org.wso2.app2"); + Application application3 = TestDataHolder.generateApplicationDummyData("org.wso2.app3"); + + applications.add(application1); + applications.add(application2); + applications.add(application3); + + Device device = TestDataHolder.initialTestDevice; + DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); + deviceIdentifier.setId(TestDataHolder.initialDeviceIdentifier); + deviceIdentifier.setType(device.getType()); + + AppManagementConfig appManagementConfig = new AppManagementConfig(); + appMgtProvider = new ApplicationManagerProviderServiceImpl(deviceManagementPluginRepository, true); + + try { + appMgtProvider.updateApplicationListInstalledInDevice(deviceIdentifier, applications); + } catch (ApplicationManagementException appMgtEx){ + String msg = "Error occurred while updating app list '" + TestDataHolder.TEST_DEVICE_TYPE + "'"; + log.error(msg, appMgtEx); + Assert.fail(msg, appMgtEx); + } + + Application application4 = TestDataHolder.generateApplicationDummyData("org.wso2.app3"); + applications = new ArrayList(); + applications.add(application4); + applications.add(application3); + + try { + appMgtProvider.updateApplicationListInstalledInDevice(deviceIdentifier, applications); + List installedApps = appMgtProvider.getApplicationListForDevice(deviceIdentifier); + Assert.assertEquals(installedApps.size(),2,"Num of installed applications should be two"); + } catch (ApplicationManagementException appMgtEx){ + String msg = "Error occurred while updating app list '" + TestDataHolder.TEST_DEVICE_TYPE + "'"; + log.error(msg, appMgtEx); + Assert.fail(msg, appMgtEx); + } + + } + +}