revert-70aa11f8
Nirothipan 7 years ago
commit de428e7651

@ -50,22 +50,22 @@ public class TestDeviceManager implements DeviceManager {
@Override
public boolean modifyEnrollment(Device device) throws DeviceManagementException {
return false;
return true;
}
@Override
public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
return false;
return true;
}
@Override
public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException {
return false;
return true;
}
@Override
public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException {
return false;
return true;
}
@Override

@ -22,6 +22,7 @@ import org.wso2.carbon.device.mgt.common.PaginationRequest;
import org.wso2.carbon.device.mgt.common.app.mgt.Application;
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup;
import org.wso2.carbon.device.mgt.common.notification.mgt.Notification;
import org.wso2.carbon.device.mgt.common.notification.mgt.Notification;
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
import java.util.ArrayList;
@ -68,6 +69,16 @@ public class TestDataHolder {
return notification;
}
public static Device generateDummyDeviceData(String deviceIdentifier, String deviceType,
EnrolmentInfo enrolmentInfo) {
Device device = new Device();
device.setEnrolmentInfo(enrolmentInfo);
device.setDescription("Test Description");
device.setDeviceIdentifier(deviceIdentifier);
device.setType(deviceType);
return device;
}
public static List<Device> generateDummyDeviceData(List<DeviceIdentifier> deviceIds) {
List<Device> devices = new ArrayList<>();
for (DeviceIdentifier deviceId : deviceIds) {

@ -18,64 +18,163 @@ 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.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.FeatureManager;
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
import org.wso2.carbon.device.mgt.core.TestDeviceManagementService;
import org.wso2.carbon.device.mgt.core.authorization.DeviceAccessAuthorizationServiceImpl;
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.config.DeviceConfigurationManager;
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementServiceComponent;
import org.wso2.carbon.registry.core.config.RegistryContext;
import org.wso2.carbon.registry.core.exceptions.RegistryException;
import org.wso2.carbon.registry.core.internal.RegistryDataHolder;
import org.wso2.carbon.registry.core.jdbc.realm.InMemoryRealmService;
import org.wso2.carbon.registry.core.service.RegistryService;
import org.wso2.carbon.user.core.service.RealmService;
import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
public class DeviceManagementProviderServiceTest {
import java.io.InputStream;
import java.lang.reflect.Method;
import java.util.Date;
public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTest {
private static final Log log = LogFactory.getLog(DeviceManagementProviderServiceTest.class);
private DeviceManagementProviderService providerService;
private static final String DEVICE_TYPE = "RANDOM_DEVICE_TYPE";
private static final String NON_EXISTENT_DEVICE_TYPE = "Test";
DeviceManagementProviderService deviceMgtService;
private Method setProvisioningConfig;
private Method setOperationMonitoringConfig;
private Method setDeviceStatusTaskPluginConfig;
@BeforeClass
public void init() throws Exception {
this.providerService = new DeviceManagementProviderServiceImpl();
DeviceConfigurationManager.getInstance().initConfig();
log.info("Initializing");
deviceMgtService = new DeviceManagementProviderServiceImpl();
DeviceManagementServiceComponent.notifyStartupListeners();
DeviceManagementDataHolder.getInstance().setDeviceManagementProvider(deviceMgtService);
DeviceManagementDataHolder.getInstance().setRegistryService(getRegistryService());
DeviceManagementDataHolder.getInstance().setDeviceAccessAuthorizationService(new DeviceAccessAuthorizationServiceImpl());
DeviceManagementDataHolder.getInstance().setGroupManagementProviderService(new GroupManagementProviderServiceImpl());
DeviceManagementDataHolder.getInstance().setDeviceTaskManagerService(null);
deviceMgtService.registerDeviceType(new TestDeviceManagementService(DEVICE_TYPE,
MultitenantConstants.SUPER_TENANT_DOMAIN_NAME));
}
private RegistryService getRegistryService() throws RegistryException {
RealmService realmService = new InMemoryRealmService();
RegistryDataHolder.getInstance().setRealmService(realmService);
DeviceManagementDataHolder.getInstance().setRealmService(realmService);
InputStream is = this.getClass().getClassLoader().getResourceAsStream("carbon-home/repository/conf/registry.xml");
RegistryContext context = RegistryContext.getBaseInstance(is, realmService);
context.setSetup(true);
return context.getEmbeddedRegistryService();
}
@Test
public void testNullDeviceEnrollment() {
try {
boolean enrollmentStatus = deviceMgtService.enrollDevice(null);
} catch (DeviceManagementException e) {
Assert.assertTrue(true);
}
}
// @Test
// public void testEnrollment() {
// try {
// DeviceManagementPluginRepository deviceManagementPluginRepository = new DeviceManagementPluginRepository();
// TestDeviceManagementService testDeviceManagementService =
// new TestDeviceManagementService(TestDataHolder.TEST_DEVICE_TYPE);
// deviceManagementPluginRepository.addDeviceManagementProvider(testDeviceManagementService);
//
// deviceManagementProviderService = new DeviceManagementProviderServiceImpl();
// DeviceManagerUtil.registerDeviceType(TestDataHolder.TEST_DEVICE_TYPE);
//
// 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 {
// DeviceManagementDAOFactory.closeConnection();
// }
// }
@Test
public void testSuccessfullDeviceEnrollment() {
Device device = TestDataHolder.generateDummyDeviceData(DEVICE_TYPE);
try {
boolean enrollmentStatus = deviceMgtService.enrollDevice(device);
Assert.assertTrue(enrollmentStatus);
} catch (DeviceManagementException e) {
String msg = "Error Occured while enrolling device";
Assert.fail(msg, e);
}
}
@Test
public void testGetFeatureManager() {
public void testNonExistentDeviceType() {
Device device = TestDataHolder.generateDummyDeviceData("abc");
try {
boolean enrollmentStatus = deviceMgtService.enrollDevice(device);
Assert.assertFalse(enrollmentStatus);
} catch (DeviceManagementException e) {
String msg = "Error Occured while enrolling device";
Assert.fail(msg, e);
}
}
@Test(dependsOnMethods = {"testSuccessfullDeviceEnrollment"})
public void testReEnrollmentofSameDeviceUnderSameUser() {
Device device = TestDataHolder.generateDummyDeviceData(DEVICE_TYPE);
try {
boolean enrollment = deviceMgtService.enrollDevice(device);
Assert.assertTrue(enrollment);
} catch (DeviceManagementException e) {
String msg = "Error Occured while enrolling device";
Assert.fail(msg, e);
}
}
@Test(dependsOnMethods = {"testReEnrollmentofSameDeviceUnderSameUser"})
public void testReEnrollmentofSameDeviceWithOtherUser() {
EnrolmentInfo enrolmentInfo = new EnrolmentInfo();
enrolmentInfo.setDateOfEnrolment(new Date().getTime());
enrolmentInfo.setDateOfLastUpdate(new Date().getTime());
enrolmentInfo.setOwner("user1");
enrolmentInfo.setOwnership(EnrolmentInfo.OwnerShip.BYOD);
enrolmentInfo.setStatus(EnrolmentInfo.Status.CREATED);
Device alternateDevice = TestDataHolder.generateDummyDeviceData("12345", DEVICE_TYPE,
enrolmentInfo);
try {
FeatureManager featureManager = providerService.getFeatureManager(NON_EXISTENT_DEVICE_TYPE);
Assert.assertNull(featureManager, "Feature manager retrieved is null, which is expected as the " +
"input device type provided is non existent");
Device retrievedDevice1 = deviceMgtService.getDevice(new DeviceIdentifier("12345", DEVICE_TYPE));
deviceMgtService.enrollDevice(alternateDevice);
Device retrievedDevice2 = deviceMgtService.getDevice(new DeviceIdentifier(alternateDevice
.getDeviceIdentifier(), alternateDevice.getType()));
log.info(retrievedDevice1.getEnrolmentInfo().getOwner());
log.info(retrievedDevice2.getEnrolmentInfo().getOwner());
Assert.assertFalse(retrievedDevice1.getEnrolmentInfo().getOwner().equalsIgnoreCase
(retrievedDevice2.getEnrolmentInfo().getOwner()));
} catch (DeviceManagementException e) {
String msg = "Error Occured while enrolling device";
Assert.fail(msg, e);
}
}
@Test(dependsOnMethods = {"testReEnrollmentofSameDeviceWithOtherUser"})
public void testDisenrollment() {
Device device = TestDataHolder.generateDummyDeviceData(DEVICE_TYPE);
try {
boolean disenrollmentStatus = deviceMgtService.disenrollDevice(new DeviceIdentifier
(device
.getDeviceIdentifier(),
device.getType()));
log.info(disenrollmentStatus);
Assert.assertTrue(disenrollmentStatus);
} catch (DeviceManagementException e) {
String msg = "Error occurred while retrieving feature manager associated with device type '" +
NON_EXISTENT_DEVICE_TYPE + "'";
log.error(msg, e);
String msg = "Error Occured while enrolling device";
Assert.fail(msg, e);
}
}

@ -76,7 +76,7 @@
device caching for upto configured expiry-time in seconds. In clustered setup all worker nodes can enable the
device-cache to improve performance. -->
<DeviceCacheConfiguration>
<Enable>true</Enable>
<Enable>false</Enable>
<ExpiryTime>600</ExpiryTime>
<!--This configuration specifies the number of cache entries in device cache. default capacity is 10000 entries.
This can be configured to higher number if cache eviction happens due to large number of devices in the
@ -84,7 +84,7 @@
<Capacity>10000</Capacity>
</DeviceCacheConfiguration>
<CertificateCacheConfiguration>
<Enable>true</Enable>
<Enable>false</Enable>
<ExpiryTime>86400</ExpiryTime>
</CertificateCacheConfiguration>
<GeoLocationConfiguration>

Loading…
Cancel
Save