mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Merge pull request #1017 from ruwany/master
Including additional unit tests for devicemt-core
This commit is contained in:
commit
811e98e4ec
@ -108,7 +108,10 @@ public class TestDeviceManager implements DeviceManager {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public License getLicense(String languageCode) throws LicenseManagementException {
|
public License getLicense(String languageCode) throws LicenseManagementException {
|
||||||
return null;
|
License testLicense = new License();
|
||||||
|
testLicense.setText("This is a dummy license for test device type.");
|
||||||
|
testLicense.setLanguage("ENG");
|
||||||
|
return testLicense;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -18,6 +18,9 @@
|
|||||||
*/
|
*/
|
||||||
package org.wso2.carbon.device.mgt.core.common;
|
package org.wso2.carbon.device.mgt.core.common;
|
||||||
|
|
||||||
|
import org.apache.axis2.AxisFault;
|
||||||
|
import org.apache.axis2.context.ConfigurationContext;
|
||||||
|
import org.apache.axis2.context.ConfigurationContextFactory;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.apache.tomcat.jdbc.pool.PoolProperties;
|
import org.apache.tomcat.jdbc.pool.PoolProperties;
|
||||||
@ -41,12 +44,14 @@ import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
|||||||
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderServiceImpl;
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderServiceImpl;
|
||||||
import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderServiceImpl;
|
import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderServiceImpl;
|
||||||
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
|
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
|
||||||
|
import org.wso2.carbon.email.sender.core.service.EmailSenderServiceImpl;
|
||||||
import org.wso2.carbon.registry.core.config.RegistryContext;
|
import org.wso2.carbon.registry.core.config.RegistryContext;
|
||||||
import org.wso2.carbon.registry.core.exceptions.RegistryException;
|
import org.wso2.carbon.registry.core.exceptions.RegistryException;
|
||||||
import org.wso2.carbon.registry.core.internal.RegistryDataHolder;
|
import org.wso2.carbon.registry.core.internal.RegistryDataHolder;
|
||||||
import org.wso2.carbon.registry.core.jdbc.realm.InMemoryRealmService;
|
import org.wso2.carbon.registry.core.jdbc.realm.InMemoryRealmService;
|
||||||
import org.wso2.carbon.registry.core.service.RegistryService;
|
import org.wso2.carbon.registry.core.service.RegistryService;
|
||||||
import org.wso2.carbon.user.core.service.RealmService;
|
import org.wso2.carbon.user.core.service.RealmService;
|
||||||
|
import org.wso2.carbon.utils.ConfigurationContextService;
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
import javax.xml.bind.JAXBContext;
|
import javax.xml.bind.JAXBContext;
|
||||||
@ -89,6 +94,8 @@ public abstract class BaseDeviceManagementTest {
|
|||||||
DeviceManagementDataHolder.getInstance().setDeviceAccessAuthorizationService(new DeviceAccessAuthorizationServiceImpl());
|
DeviceManagementDataHolder.getInstance().setDeviceAccessAuthorizationService(new DeviceAccessAuthorizationServiceImpl());
|
||||||
DeviceManagementDataHolder.getInstance().setGroupManagementProviderService(new GroupManagementProviderServiceImpl());
|
DeviceManagementDataHolder.getInstance().setGroupManagementProviderService(new GroupManagementProviderServiceImpl());
|
||||||
DeviceManagementDataHolder.getInstance().setDeviceTaskManagerService(null);
|
DeviceManagementDataHolder.getInstance().setDeviceTaskManagerService(null);
|
||||||
|
DeviceManagementDataHolder.getInstance().setEmailSenderService(new TestEmailSenderService());
|
||||||
|
DeviceManagementDataHolder.getInstance().setConfigurationContextService(getConfigContextService());
|
||||||
}
|
}
|
||||||
|
|
||||||
private RegistryService getRegistryService() throws RegistryException {
|
private RegistryService getRegistryService() throws RegistryException {
|
||||||
@ -101,6 +108,19 @@ public abstract class BaseDeviceManagementTest {
|
|||||||
return context.getEmbeddedRegistryService();
|
return context.getEmbeddedRegistryService();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ConfigurationContextService getConfigContextService() throws RegistryException {
|
||||||
|
ConfigurationContext context =
|
||||||
|
null;
|
||||||
|
try {
|
||||||
|
context = ConfigurationContextFactory.createConfigurationContextFromFileSystem
|
||||||
|
("src/test/resources/carbon-home/repository/conf/axis2/axis2.xml");
|
||||||
|
} catch (AxisFault axisFault) {
|
||||||
|
axisFault.printStackTrace();
|
||||||
|
}
|
||||||
|
ConfigurationContextService service = new ConfigurationContextService(context, null);
|
||||||
|
return service;
|
||||||
|
}
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public abstract void init() throws Exception;
|
public abstract void init() throws Exception;
|
||||||
|
|
||||||
|
|||||||
@ -62,8 +62,8 @@ public class TestDataHolder {
|
|||||||
deviceInfo.setIMEI("IMEI-12345");
|
deviceInfo.setIMEI("IMEI-12345");
|
||||||
deviceInfo.setIMSI("IMSI-12344");
|
deviceInfo.setIMSI("IMSI-12344");
|
||||||
deviceInfo.setDeviceModel("DUMMY_MODEL");
|
deviceInfo.setDeviceModel("DUMMY_MODEL");
|
||||||
deviceInfo.setVendor("Google");
|
deviceInfo.setVendor("WSO2");
|
||||||
deviceInfo.setOsVersion("Oreo");
|
deviceInfo.setOsVersion("OREO");
|
||||||
deviceInfo.setOsBuildDate("24-05-2017");
|
deviceInfo.setOsBuildDate("24-05-2017");
|
||||||
deviceInfo.setBatteryLevel(25.0);
|
deviceInfo.setBatteryLevel(25.0);
|
||||||
deviceInfo.setInternalTotalMemory(1.5);
|
deviceInfo.setInternalTotalMemory(1.5);
|
||||||
|
|||||||
@ -24,7 +24,10 @@ import org.wso2.carbon.device.mgt.common.Device;
|
|||||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||||
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
||||||
|
import org.wso2.carbon.device.mgt.common.PaginationRequest;
|
||||||
import org.wso2.carbon.device.mgt.common.TransactionManagementException;
|
import org.wso2.carbon.device.mgt.common.TransactionManagementException;
|
||||||
|
import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationManagementException;
|
||||||
|
import org.wso2.carbon.device.mgt.common.license.mgt.License;
|
||||||
import org.wso2.carbon.device.mgt.core.TestDeviceManagementService;
|
import org.wso2.carbon.device.mgt.core.TestDeviceManagementService;
|
||||||
import org.wso2.carbon.device.mgt.core.authorization.DeviceAccessAuthorizationServiceImpl;
|
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.BaseDeviceManagementTest;
|
||||||
@ -48,6 +51,7 @@ import java.io.InputStream;
|
|||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTest {
|
public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTest {
|
||||||
|
|
||||||
@ -429,6 +433,79 @@ public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTes
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetAvaliableDeviceTypes() {
|
||||||
|
try {
|
||||||
|
List<String> deviceTypes = deviceMgtService.getAvailableDeviceTypes();
|
||||||
|
Assert.assertTrue(!deviceTypes.isEmpty());
|
||||||
|
} catch (DeviceManagementException e) {
|
||||||
|
String msg = "Error occurred while updating the device status";
|
||||||
|
Assert.fail(msg, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"})
|
||||||
|
public void testGetAllDevices() {
|
||||||
|
try {
|
||||||
|
List<Device> devices = deviceMgtService.getAllDevices();
|
||||||
|
Assert.assertTrue(!devices.isEmpty());
|
||||||
|
} catch (DeviceManagementException e) {
|
||||||
|
String msg = "Error occurred while updating the device status";
|
||||||
|
Assert.fail(msg, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(dependsOnMethods = {"testDeviceByDate"})
|
||||||
|
public void testGetAllDevicesWithInfo() {
|
||||||
|
try {
|
||||||
|
List<Device> devices = deviceMgtService.getAllDevices(true);
|
||||||
|
Assert.assertTrue(!devices.isEmpty());
|
||||||
|
Assert.assertTrue(devices.get(0).getDeviceInfo() != null);
|
||||||
|
} catch (DeviceManagementException e) {
|
||||||
|
String msg = "Error occurred while updating the device status";
|
||||||
|
Assert.fail(msg, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(dependsOnMethods = {"testDeviceByDate"})
|
||||||
|
public void testGetLicense() {
|
||||||
|
try {
|
||||||
|
License license = deviceMgtService.getLicense(DEVICE_TYPE, "ENG");
|
||||||
|
Assert.assertTrue(license.getLanguage().equalsIgnoreCase("ENG"));
|
||||||
|
} catch (DeviceManagementException e) {
|
||||||
|
String msg = "Error occurred while updating the device status";
|
||||||
|
Assert.fail(msg, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expectedExceptions = DeviceManagementException.class)
|
||||||
|
public void testSendRegistrationEmailNoMetaInfo() throws ConfigurationManagementException, DeviceManagementException {
|
||||||
|
deviceMgtService.sendRegistrationEmail(null);
|
||||||
|
Assert.assertTrue(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSendRegistrationEmailSuccessFlow() {
|
||||||
|
try {
|
||||||
|
String recipient = "test-user@wso2.com";
|
||||||
|
Properties props = new Properties();
|
||||||
|
props.setProperty("first-name", "Test");
|
||||||
|
props.setProperty("username", "User");
|
||||||
|
props.setProperty("password", "!@#$$$%");
|
||||||
|
|
||||||
|
EmailMetaInfo metaInfo = new EmailMetaInfo(recipient, props);
|
||||||
|
|
||||||
|
deviceMgtService.sendRegistrationEmail(metaInfo);
|
||||||
|
Assert.assertTrue(true);
|
||||||
|
} catch (ConfigurationManagementException e) {
|
||||||
|
Assert.assertTrue(false, "Error in sending registration email : Configration " +
|
||||||
|
"related error" + e.getMessage());
|
||||||
|
} catch (DeviceManagementException e) {
|
||||||
|
Assert.assertTrue(false, "Error in sending registration email" +
|
||||||
|
e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private Date yesterday() {
|
private Date yesterday() {
|
||||||
final Calendar cal = Calendar.getInstance();
|
final Calendar cal = Calendar.getInstance();
|
||||||
cal.add(Calendar.DATE, -1);
|
cal.add(Calendar.DATE, -1);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user