forked from community/device-mgt-core
commit
854b7dda8d
@ -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<Device> 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;
|
||||
}
|
||||
}
|
@ -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<Application> applications = new ArrayList<Application>();
|
||||
|
||||
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<Application>();
|
||||
applications.add(application4);
|
||||
applications.add(application3);
|
||||
|
||||
try {
|
||||
appMgtProvider.updateApplicationListInstalledInDevice(deviceIdentifier, applications);
|
||||
List<Application> 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
package org.wso2.carbon.device.mgt.core.common;
|
||||
|
||||
import org.wso2.carbon.device.mgt.common.Device;
|
||||
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
||||
import org.wso2.carbon.device.mgt.common.app.mgt.Application;
|
||||
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Properties;
|
||||
|
||||
public class TestDataHolder {
|
||||
|
||||
public static Device initialTestDevice;
|
||||
public static DeviceType initialTestDeviceType;
|
||||
public static String TEST_DEVICE_TYPE = "Test";
|
||||
public static Integer SUPER_TENANT_ID = -1234;
|
||||
public static String initialDeviceIdentifier = "12345";
|
||||
|
||||
public static Device generateDummyDeviceData(String deviceType){
|
||||
|
||||
Device device = new Device();
|
||||
EnrolmentInfo enrolmentInfo = new EnrolmentInfo();
|
||||
enrolmentInfo.setDateOfEnrolment(new Date().getTime());
|
||||
enrolmentInfo.setDateOfLastUpdate(new Date().getTime());
|
||||
enrolmentInfo.setOwner("admin");
|
||||
enrolmentInfo.setOwnership(EnrolmentInfo.OwnerShip.BYOD);
|
||||
enrolmentInfo.setStatus(EnrolmentInfo.Status.CREATED);
|
||||
device.setEnrolmentInfo(enrolmentInfo);
|
||||
device.setDescription("Test Description");
|
||||
device.setDeviceIdentifier("12345");
|
||||
device.setType(deviceType);
|
||||
return device;
|
||||
}
|
||||
|
||||
public static DeviceType generateDeviceTypeData(String devTypeName){
|
||||
DeviceType deviceType = new DeviceType();
|
||||
deviceType.setName(devTypeName);
|
||||
return deviceType;
|
||||
}
|
||||
|
||||
public static Application generateApplicationDummyData(String appIdentifier){
|
||||
|
||||
Application application = new Application();
|
||||
Properties properties = new Properties();
|
||||
properties.setProperty("test1","testVal");
|
||||
|
||||
application.setName("SimpleCalculator");
|
||||
application.setCategory("TestCategory");
|
||||
application.setApplicationIdentifier(appIdentifier);
|
||||
application.setType("TestType");
|
||||
application.setVersion("1.0.0");
|
||||
application.setImageUrl("http://test.org/image/");
|
||||
application.setLocationUrl("http://test.org/location/");
|
||||
application.setAppProperties(properties);
|
||||
|
||||
return application;
|
||||
}
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
package org.wso2.carbon.device.mgt.core.service;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.AfterClass;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
import org.wso2.carbon.context.CarbonContext;
|
||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||
import org.wso2.carbon.context.internal.CarbonContextDataHolder;
|
||||
import org.wso2.carbon.device.mgt.common.Device;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||
import org.wso2.carbon.device.mgt.core.DeviceManagementPluginRepository;
|
||||
import org.wso2.carbon.device.mgt.core.TestDeviceManagementService;
|
||||
import org.wso2.carbon.device.mgt.core.common.BaseDeviceManagementTest;
|
||||
import org.wso2.carbon.device.mgt.core.common.TestDataHolder;
|
||||
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException;
|
||||
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
|
||||
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
|
||||
import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
|
||||
|
||||
public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTest {
|
||||
|
||||
private static final Log log = LogFactory.getLog(DeviceManagementProviderServiceTest.class);
|
||||
DeviceManagementProviderService deviceManagementProviderService = null;
|
||||
|
||||
|
||||
@BeforeClass
|
||||
@Override
|
||||
public void init() throws Exception {
|
||||
initDatSource();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEnrollment() {
|
||||
|
||||
try {
|
||||
DeviceManagementPluginRepository deviceManagementPluginRepository = new DeviceManagementPluginRepository();
|
||||
TestDeviceManagementService testDeviceManagementService = new TestDeviceManagementService(TestDataHolder.TEST_DEVICE_TYPE);
|
||||
deviceManagementPluginRepository.addDeviceManagementProvider(testDeviceManagementService);
|
||||
|
||||
deviceManagementProviderService = new DeviceManagementProviderServiceImpl(deviceManagementPluginRepository,
|
||||
true);
|
||||
DeviceManagerUtil.registerDeviceType(TestDataHolder.TEST_DEVICE_TYPE);
|
||||
DeviceManagerUtil.currentTenant.set(TestDataHolder.SUPER_TENANT_ID);
|
||||
|
||||
Device device = TestDataHolder.generateDummyDeviceData(TestDataHolder.TEST_DEVICE_TYPE);
|
||||
boolean isEnrolled = deviceManagementProviderService.enrollDevice(device);
|
||||
|
||||
Assert.assertEquals(isEnrolled,true,"Enrolment fail");
|
||||
if (isEnrolled){
|
||||
TestDataHolder.initialTestDevice = device;
|
||||
}
|
||||
|
||||
} catch (DeviceManagementException e) {
|
||||
String msg = "Error occurred while adding device type '" + TestDataHolder.TEST_DEVICE_TYPE + "'";
|
||||
log.error(msg, e);
|
||||
Assert.fail(msg, e);
|
||||
} finally {
|
||||
try {
|
||||
DeviceManagementDAOFactory.closeConnection();
|
||||
} catch (DeviceManagementDAOException e) {
|
||||
log.warn("Error occurred while closing the connection", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public void cleanResources(){
|
||||
}
|
||||
}
|
Loading…
Reference in new issue