Adding integration tests for Device Retrieval

revert-70aa11f8
Ace 7 years ago
parent 7447e04a66
commit 43462b173a

@ -128,7 +128,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
// However, both enrollments share the same time stamp. When retrieving the device // However, both enrollments share the same time stamp. When retrieving the device
// due to same timestamp, enrollment information is incorrect, intermittently. Hence // due to same timestamp, enrollment information is incorrect, intermittently. Hence
// status also should be taken into consideration when ordering. This should not present a // status also should be taken into consideration when ordering. This should not present a
// problem for other status transitions, as there would be an intermediary 'removed' // problem for other status transitions, as there would be an intermediary removed
// state in between. // state in between.
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setString(1, deviceIdentifier.getType()); stmt.setString(1, deviceIdentifier.getType());

@ -1741,6 +1741,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
if (requireDeviceInfo) { if (requireDeviceInfo) {
this.getAllDeviceInfo(userDevices); this.getAllDeviceInfo(userDevices);
} }
devices.addAll(userDevices);
} }
return devices; return devices;
} }

@ -20,6 +20,7 @@ import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
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.PaginationRequest;
import org.wso2.carbon.device.mgt.common.app.mgt.Application; import org.wso2.carbon.device.mgt.common.app.mgt.Application;
import org.wso2.carbon.device.mgt.common.device.details.DeviceInfo;
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup; 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.common.notification.mgt.Notification; import org.wso2.carbon.device.mgt.common.notification.mgt.Notification;
@ -55,6 +56,28 @@ public class TestDataHolder {
return device; return device;
} }
public static DeviceInfo generateDummyDeviceInfo() {
DeviceInfo deviceInfo = new DeviceInfo();
deviceInfo.setIMEI("IMEI-12345");
deviceInfo.setIMSI("IMSI-12344");
deviceInfo.setDeviceModel("DUMMY_MODEL");
deviceInfo.setVendor("Google");
deviceInfo.setOsVersion("Oreo");
deviceInfo.setOsBuildDate("24-05-2017");
deviceInfo.setBatteryLevel(25.0);
deviceInfo.setInternalTotalMemory(1.5);
deviceInfo.setInternalAvailableMemory(2.5);
deviceInfo.setExternalTotalMemory(16.76);
deviceInfo.setExternalAvailableMemory(4.56);
deviceInfo.setConnectionType("CON_TYPE");
deviceInfo.setSsid("SSID");
deviceInfo.setCpuUsage(23.5);
deviceInfo.setTotalRAMMemory(1.5);
deviceInfo.setAvailableRAMMemory(2.33);
deviceInfo.setPluggedIn(true);
return deviceInfo;
}
public static Notification getNotification(int notificationId, String status, String deviceId, public static Notification getNotification(int notificationId, String status, String deviceId,
String description, String deviceName, int operationId, String description, String deviceName, int operationId,
String deviceType) { String deviceType) {

@ -23,14 +23,28 @@ import org.testng.annotations.Test;
import org.wso2.carbon.device.mgt.common.Device; 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.InvalidDeviceException;
import org.wso2.carbon.device.mgt.common.TransactionManagementException;
import org.wso2.carbon.device.mgt.common.device.details.DeviceInfo;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager;
import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy;
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;
import org.wso2.carbon.device.mgt.core.common.TestDataHolder; 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.config.DeviceConfigurationManager;
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
import org.wso2.carbon.device.mgt.core.device.details.mgt.dao.DeviceDetailsDAO;
import org.wso2.carbon.device.mgt.core.device.details.mgt.dao.DeviceDetailsMgtDAOException;
import org.wso2.carbon.device.mgt.core.dto.DeviceType; import org.wso2.carbon.device.mgt.core.dto.DeviceType;
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder; import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementServiceComponent; import org.wso2.carbon.device.mgt.core.internal.DeviceManagementServiceComponent;
import org.wso2.carbon.device.mgt.core.operation.TestNotificationStrategy;
import org.wso2.carbon.device.mgt.core.operation.mgt.CommandOperation;
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagerImpl;
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;
@ -40,6 +54,14 @@ import org.wso2.carbon.user.core.service.RealmService;
import org.wso2.carbon.utils.multitenancy.MultitenantConstants; import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
import java.io.InputStream; import java.io.InputStream;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List; import java.util.List;
public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTest { public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTest {
@ -47,7 +69,7 @@ public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTes
private static final Log log = LogFactory.getLog(DeviceManagementProviderServiceTest.class); private static final Log log = LogFactory.getLog(DeviceManagementProviderServiceTest.class);
private DeviceManagementProviderService providerService; private DeviceManagementProviderService providerService;
private static final String DEVICE_TYPE = "RANDOM_DEVICE_TYPE"; private static final String DEVICE_TYPE = "RANDOM_DEVICE_TYPE";
private static final String DEVICE_TYPE_2 = "RANDOM_DEVICE_TYPE"; private DeviceDetailsDAO deviceDetailsDAO = DeviceManagementDAOFactory.getDeviceDetailsDAO();
DeviceManagementProviderService deviceMgtService; DeviceManagementProviderService deviceMgtService;
@ -65,7 +87,6 @@ public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTes
DeviceManagementDataHolder.getInstance().setDeviceTaskManagerService(null); DeviceManagementDataHolder.getInstance().setDeviceTaskManagerService(null);
deviceMgtService.registerDeviceType(new TestDeviceManagementService(DEVICE_TYPE, deviceMgtService.registerDeviceType(new TestDeviceManagementService(DEVICE_TYPE,
MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)); MultitenantConstants.SUPER_TENANT_DOMAIN_NAME));
} }
private RegistryService getRegistryService() throws RegistryException { private RegistryService getRegistryService() throws RegistryException {
@ -320,5 +341,114 @@ public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTes
} }
} }
@Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"})
public void testGetDevice() {
try {
Device device = deviceMgtService.getDevice(new DeviceIdentifier("12345",DEVICE_TYPE));
Assert.assertTrue(device.getDeviceIdentifier().equalsIgnoreCase("12345"));
} catch (DeviceManagementException e) {
String msg = "Error occurred while updating the device status";
Assert.fail(msg, e);
}
}
@Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"})
public void testGetDeviceWithInfo() {
try {
Device device = deviceMgtService.getDevice(new DeviceIdentifier("12345", DEVICE_TYPE)
, true);
Assert.assertTrue(device.getDeviceInfo() != null);
} catch (DeviceManagementException e) {
String msg = "Error occurred while updating the device status";
Assert.fail(msg, e);
}
}
@Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"})
public void testGetDeviceWithOutInfo() {
try {
Device device = deviceMgtService.getDevice(new DeviceIdentifier("12345", DEVICE_TYPE)
, false);
Assert.assertTrue(device.getDeviceInfo() == null);
} catch (DeviceManagementException e) {
String msg = "Error occurred while updating the device status";
Assert.fail(msg, e);
}
}
@Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"})
public void testGetAllDevicesOfRole() {
try {
List<Device> devices = deviceMgtService.getAllDevicesOfRole("admin");
Assert.assertTrue(devices.size() > 0);
} catch (DeviceManagementException e) {
String msg = "Error occurred while updating the device status";
Assert.fail(msg, e);
}
}
@Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"})
public void testDeviceByOwner() {
try {
Device device = deviceMgtService.getDevice(new DeviceIdentifier("12345",
DEVICE_TYPE), "admin", true);
Assert.assertTrue(device != null);
} catch (DeviceManagementException e) {
String msg = "Error occurred while updating the device status";
Assert.fail(msg, e);
}
}
@Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"})
public void testDeviceByDate() {
try {
Device initialDevice = deviceMgtService.getDevice(new DeviceIdentifier("12345",
DEVICE_TYPE));
DeviceManagementDAOFactory.beginTransaction();
//Device details table will be reffered when looking for last updated time
//This dao entry is to mimic a device info operation
deviceDetailsDAO.addDeviceInformation(initialDevice.getId(), TestDataHolder
.generateDummyDeviceInfo());
} catch (DeviceManagementException e) {
e.printStackTrace();
} catch (TransactionManagementException e) {
e.printStackTrace();
} catch (DeviceDetailsMgtDAOException e) {
e.printStackTrace();
} finally {
DeviceManagementDAOFactory.closeConnection();
}
try {
Device device = deviceMgtService.getDevice(new DeviceIdentifier("12345",
DEVICE_TYPE), yesterday());
Assert.assertTrue(device != null);
} catch (DeviceManagementException e) {
String msg = "Error occurred while updating the device status";
Assert.fail(msg, e);
}
}
@Test(dependsOnMethods = {"testDeviceByDate"})
public void testDeviceByDateAndOwner() {
try {
Device device = deviceMgtService.getDevice(new DeviceIdentifier("12345",
DEVICE_TYPE), "admin", yesterday(), true);
Assert.assertTrue(device != null);
} catch (DeviceManagementException e) {
String msg = "Error occurred while updating the device status";
Assert.fail(msg, e);
}
}
private Date yesterday() {
final Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, -1);
return cal.getTime();
}
} }
Loading…
Cancel
Save