forked from community/device-mgt-core
parent
da61c08fac
commit
41d1408b14
@ -0,0 +1,59 @@
|
||||
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 ThreadLocal<Integer> tenant = new ThreadLocal<Integer>();
|
||||
|
||||
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("1234");
|
||||
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,60 @@
|
||||
package org.wso2.carbon.device.mgt.core.service;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
import org.wso2.carbon.device.mgt.core.common.BaseDeviceManagementTest;
|
||||
|
||||
public class ApplicationManagementProviderServiceTests extends BaseDeviceManagementTest{
|
||||
|
||||
private static final Log log = LogFactory.getLog(ApplicationManagementProviderServiceTests.class);
|
||||
|
||||
@BeforeClass
|
||||
@Override
|
||||
public void init() throws Exception {
|
||||
this.initDatSource();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddApplications() {
|
||||
|
||||
/* ArrayList<Application> sourceApplications = new ArrayList<Application>();
|
||||
sourceApplications.add(TestDataHolder.generateApplicationDummyData("Test App2"));
|
||||
sourceApplications.add(TestDataHolder.generateApplicationDummyData("Test App3"));
|
||||
|
||||
DeviceManagementTests deviceManagementDAOTests = new DeviceManagementTests();
|
||||
deviceManagementDAOTests.testAddDeviceTest();
|
||||
|
||||
Device device = TestDataHolder.initialTestDevice;
|
||||
|
||||
try {
|
||||
DeviceManagementDAOFactory.openConnection();
|
||||
|
||||
|
||||
} catch (DeviceManagementDAOException e) {
|
||||
log.error("Error occurred while adding application", e);
|
||||
} finally {
|
||||
try {
|
||||
DeviceManagementDAOFactory.closeConnection();
|
||||
} catch (DeviceManagementDAOException e) {
|
||||
log.warn("Error occurred while closing the connection", e);
|
||||
}
|
||||
}
|
||||
*//* Retrieving the application by its name *//*
|
||||
Application target = null;
|
||||
try {
|
||||
target = this.getApplication(source.getApplicationIdentifier(), -1234);
|
||||
} catch (DeviceManagementDAOException e) {
|
||||
String msg = "Error occurred while retrieving application info";
|
||||
log.error(msg, e);
|
||||
Assert.fail(msg, e);
|
||||
}
|
||||
|
||||
Assert.assertEquals(target.getApplicationIdentifier(), source.getApplicationIdentifier(), "Application added is not as same as " +
|
||||
"what's " +
|
||||
"retrieved");*/
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
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();
|
||||
DeviceManagementPluginRepository deviceManagementPluginRepository = new DeviceManagementPluginRepository();
|
||||
TestDeviceManagementService testDeviceManagementService = new TestDeviceManagementService();
|
||||
deviceManagementPluginRepository.addDeviceManagementProvider(testDeviceManagementService);
|
||||
deviceManagementProviderService = new DeviceManagementProviderServiceImpl(deviceManagementPluginRepository,
|
||||
true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testEnrollment() {
|
||||
|
||||
try {
|
||||
DeviceManagerUtil.registerDeviceType(TestDataHolder.TEST_DEVICE_TYPE);
|
||||
TestDataHolder.tenant.set(TestDataHolder.SUPER_TENANT_ID);
|
||||
Device device = TestDataHolder.generateDummyDeviceData(TestDataHolder.TEST_DEVICE_TYPE);
|
||||
boolean isEnrolled = deviceManagementProviderService.enrollDevice(device);
|
||||
|
||||
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(){
|
||||
// PrivilegedCarbonContext.endTenantFlow();
|
||||
}
|
||||
}
|
Loading…
Reference in new issue