Fix merge conflicts

apim420
tcdlpds 5 months ago
commit 4b92df7638

@ -120,7 +120,9 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
throw new BadRequestException(msg);
} else if (HttpStatus.SC_NOT_FOUND == response.code()) {
String msg = "Shared scope key not found : " + key;
log.info(msg);
if (log.isDebugEnabled()) {
log.debug(msg);
}
return false;
} else {
String msg = "Response : " + response.code() + response.body();

@ -160,6 +160,13 @@ import java.util.Map;
roles = {"Internal/devicemgt-user"},
permissions = {"/device-mgt/devices/change-status"}
),
@Scope(
name = "Update status of a given operation",
description = "Updates the status of a given operation of a given device",
key = "dm:devices:ops:status:update",
roles = {"Internal/devicemgt-user"},
permissions = {"/device-mgt/devices/operations/status-update"}
),
@Scope(
name = "Enroll Device",
description = "Register a device",
@ -2709,12 +2716,12 @@ public interface DeviceManagementService {
@ApiOperation(
produces = MediaType.APPLICATION_JSON,
httpMethod = "PUT",
value = "Update status of a given opeation",
value = "Update status of a given operation",
notes = "Updates the status of a given operation of a given device in Entgra IoT Server.",
tags = "Device Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = Constants.SCOPE, value = "dm:devices:ops:view")
@ExtensionProperty(name = Constants.SCOPE, value = "dm:devices:ops:status:update")
})
}
)

@ -19,6 +19,7 @@ package io.entgra.device.mgt.core.device.mgt.core.common;
import io.entgra.device.mgt.core.device.mgt.common.*;
import io.entgra.device.mgt.core.device.mgt.common.app.mgt.Application;
import io.entgra.device.mgt.core.device.mgt.common.device.details.DeviceData;
import io.entgra.device.mgt.core.device.mgt.common.device.details.DeviceInfo;
import io.entgra.device.mgt.core.device.mgt.common.group.mgt.DeviceGroup;
import io.entgra.device.mgt.core.device.mgt.common.notification.mgt.Notification;
@ -28,6 +29,7 @@ import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Properties;
import java.util.Calendar;
public class TestDataHolder {
@ -35,11 +37,18 @@ public class TestDataHolder {
public final static Integer SUPER_TENANT_ID = -1234;
public final static String SUPER_TENANT_DOMAIN = "carbon.super";
public final static String initialDeviceIdentifier = "12345";
public final static String initialDeviceName = "TEST-DEVICE";
public final static String OWNER = "admin";
public static final String OPERATION_CONFIG = "TEST-OPERATION-";
public static Device initialTestDevice;
public static DeviceType initialTestDeviceType;
public static Date getTimeBefore(int minutes) {
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.MINUTE, -minutes);
return calendar.getTime();
}
public static Device generateDummyDeviceData(String deviceType) {
Device device = new Device();
device.setEnrolmentInfo(generateEnrollmentInfo(new Date().getTime(), new Date().getTime(), OWNER, EnrolmentInfo
@ -137,6 +146,15 @@ public class TestDataHolder {
return device;
}
public static DeviceData generateDummyDevice(DeviceIdentifier deviceIdentifier) {
DeviceData deviceData = new DeviceData();
deviceData.setDeviceIdentifier(deviceIdentifier);
deviceData.setDeviceOwner(OWNER);
deviceData.setDeviceOwnership(EnrolmentInfo.OwnerShip.BYOD.toString());
deviceData.setLastModifiedDate(getTimeBefore(1));
return deviceData;
}
public static DeviceType generateDeviceTypeData(String devTypeName) {
DeviceType deviceType = new DeviceType();
deviceType.setName(devTypeName);

@ -37,6 +37,7 @@ import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@ -92,6 +93,7 @@ public class DevicePersistTests extends BaseDeviceManagementTest {
public void testAddDeviceTest() {
int tenantId = TestDataHolder.SUPER_TENANT_ID;
Device device = TestDataHolder.generateDummyDeviceData(TestDataHolder.TEST_DEVICE_TYPE);
device.setName(TestDataHolder.initialDeviceName);
try {
DeviceManagementDAOFactory.beginTransaction();
@ -278,6 +280,7 @@ public class DevicePersistTests extends BaseDeviceManagementTest {
pr.setStatusList(Collections.singletonList(Status.ACTIVE.name()));
List<Device> results = deviceDAO.getDevicesByStatus(pr, TestDataHolder.SUPER_TENANT_ID);
Assert.assertEquals(1, results.size(), "No device returned");
DeviceManagementDAOFactory.commitTransaction();
} catch (DeviceManagementDAOException e) {
throw new DeviceManagementDAOException("Error occurred while retrieving the current status of the " +
"enrolment", e);
@ -286,4 +289,509 @@ public class DevicePersistTests extends BaseDeviceManagementTest {
}
}
@Test(dependsOnMethods = "testAddDeviceTest")
public void getDevicesByTenantId() throws DeviceManagementDAOException, TransactionManagementException {
try {
DeviceManagementDAOFactory.beginTransaction();
List<Device> results = deviceDAO.getDevices(TestDataHolder.SUPER_TENANT_ID);
Assert.assertEquals(1, results.size(), "No device returned");
DeviceManagementDAOFactory.commitTransaction();
} catch (DeviceManagementDAOException e) {
throw new DeviceManagementDAOException("Error occurred while retrieving the device" + e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
}
@Test(dependsOnMethods = "testAddDeviceTest")
public void getDeviceByDeviceId() throws DeviceManagementDAOException, TransactionManagementException {
Device device = TestDataHolder.initialTestDevice;
try {
DeviceManagementDAOFactory.beginTransaction();
Device results = deviceDAO.getDevice(device.getDeviceIdentifier(), TestDataHolder.SUPER_TENANT_ID);
Assert.assertNotNull(results.getDeviceIdentifier(), "No device returned");
DeviceManagementDAOFactory.commitTransaction();
} catch (DeviceManagementDAOException e) {
throw new DeviceManagementDAOException("Error occurred while retrieving the device" + e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
}
@Test(dependsOnMethods = "testAddDeviceTest")
public void getDeviceByDeviceIdentifierWithTenantId() throws DeviceManagementDAOException, TransactionManagementException {
Device device = TestDataHolder.initialTestDevice;
try {
DeviceManagementDAOFactory.beginTransaction();
DeviceIdentifier deviceIdentifier = new DeviceIdentifier(device.getDeviceIdentifier(), device.getType());
Device results = deviceDAO.getDevice(deviceIdentifier, TestDataHolder.SUPER_TENANT_ID);
Assert.assertNotNull(results.getDeviceIdentifier(), "No device returned");
DeviceManagementDAOFactory.commitTransaction();
} catch (DeviceManagementDAOException e) {
throw new DeviceManagementDAOException("Error occurred while retrieving the device" + e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
}
@Test(dependsOnMethods = "testAddDeviceTest")
public void getDeviceByDeviceData() throws DeviceManagementDAOException, TransactionManagementException {
Device device = TestDataHolder.initialTestDevice;
DeviceIdentifier deviceIdentifier = new DeviceIdentifier(device.getDeviceIdentifier(), device.getType());
DeviceData deviceData = TestDataHolder.generateDummyDevice(deviceIdentifier);
try {
DeviceManagementDAOFactory.beginTransaction();
Device results = deviceDAO.getDevice(deviceData, TestDataHolder.SUPER_TENANT_ID);
Assert.assertNotNull(results.getDeviceIdentifier(), "No device returned");
DeviceManagementDAOFactory.commitTransaction();
} catch (DeviceManagementDAOException e) {
throw new DeviceManagementDAOException("Error occurred while retrieving the device" + e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
}
@Test(dependsOnMethods = "testAddDeviceTest")
public void getDeviceByOwner() throws DeviceManagementDAOException, TransactionManagementException {
Device device = TestDataHolder.initialTestDevice;
DeviceIdentifier deviceIdentifier = new DeviceIdentifier(device.getDeviceIdentifier(), device.getType());
try {
DeviceManagementDAOFactory.beginTransaction();
Device results = deviceDAO.getDevice(deviceIdentifier, TestDataHolder.OWNER, TestDataHolder.SUPER_TENANT_ID);
Assert.assertNotNull(results.getDeviceIdentifier(), "No device returned");
DeviceManagementDAOFactory.commitTransaction();
} catch (DeviceManagementDAOException e) {
throw new DeviceManagementDAOException("Error occurred while retrieving the device" + e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
}
@Test(dependsOnMethods = "testAddDeviceTest")
public void getDeviceByDateSince() throws DeviceManagementDAOException, TransactionManagementException {
Device device = TestDataHolder.initialTestDevice;
DeviceIdentifier deviceIdentifier = new DeviceIdentifier(device.getDeviceIdentifier(), device.getType());
try {
DeviceManagementDAOFactory.beginTransaction();
Device results = deviceDAO.getDevice(deviceIdentifier, TestDataHolder.getTimeBefore(1), TestDataHolder.SUPER_TENANT_ID);
Assert.assertNotNull(results.getDeviceIdentifier(), "No device returned");
DeviceManagementDAOFactory.commitTransaction();
} catch (DeviceManagementDAOException e) {
throw new DeviceManagementDAOException("Error occurred while retrieving the device" + e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
}
@Test(dependsOnMethods = "testAddDeviceTest")
public void getDeviceByDateSinceWithDeviceId() throws DeviceManagementDAOException, TransactionManagementException {
Device device = TestDataHolder.initialTestDevice;
try {
DeviceManagementDAOFactory.beginTransaction();
Device results = deviceDAO.getDevice(device.getDeviceIdentifier(), TestDataHolder.getTimeBefore(1), TestDataHolder.SUPER_TENANT_ID);
Assert.assertNotNull(results.getDeviceIdentifier(), "No device returned");
DeviceManagementDAOFactory.commitTransaction();
} catch (DeviceManagementDAOException e) {
throw new DeviceManagementDAOException("Error occurred while retrieving the device" + e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
}
@Test(dependsOnMethods = "testAddDeviceTest")
public void getDeviceByEnrollmentStatus() throws DeviceManagementDAOException, TransactionManagementException {
Device device = TestDataHolder.initialTestDevice;
DeviceIdentifier deviceIdentifier = new DeviceIdentifier(device.getDeviceIdentifier(), device.getType());
try {
DeviceManagementDAOFactory.beginTransaction();
Device results = deviceDAO.getDevice(deviceIdentifier, Status.ACTIVE, TestDataHolder.SUPER_TENANT_ID);
Assert.assertEquals(device.getDeviceIdentifier(), results.getDeviceIdentifier(), "No device returned");
DeviceManagementDAOFactory.commitTransaction();
} catch (DeviceManagementDAOException e) {
throw new DeviceManagementDAOException("Error occurred while retrieving the device" + e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
}
@Test(dependsOnMethods = "testAddDeviceTest")
public void getDeviceByDeviceIdentifier() throws DeviceManagementDAOException, TransactionManagementException {
Device device = TestDataHolder.initialTestDevice;
DeviceIdentifier deviceIdentifier = new DeviceIdentifier(device.getDeviceIdentifier(), device.getType());
try {
DeviceManagementDAOFactory.beginTransaction();
SingletonMap results = deviceDAO.getDevice(deviceIdentifier);
Assert.assertNotNull(results, "No device returned");
DeviceManagementDAOFactory.commitTransaction();
} catch (DeviceManagementDAOException e) {
throw new DeviceManagementDAOException("Error occurred while retrieving the device" + e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
}
@Test(dependsOnMethods = "testAddDeviceTest")
public void getDeviceByDeviceType() throws DeviceManagementDAOException, TransactionManagementException {
Device device = TestDataHolder.initialTestDevice;
try {
DeviceManagementDAOFactory.beginTransaction();
List<Device> results = deviceDAO.getDevices(device.getType(), TestDataHolder.SUPER_TENANT_ID);
Assert.assertEquals(1, results.size(), "No device returned");
DeviceManagementDAOFactory.commitTransaction();
} catch (DeviceManagementDAOException e) {
throw new DeviceManagementDAOException("Error occurred while retrieving the device" + e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
}
@Test(dependsOnMethods = "testAddDeviceTest")
public void getAllocatedDevices() throws DeviceManagementDAOException, TransactionManagementException {
Device device = TestDataHolder.initialTestDevice;
try {
DeviceManagementDAOFactory.beginTransaction();
List<Device> results = deviceDAO.getAllocatedDevices(device.getType(), TestDataHolder.SUPER_TENANT_ID, 1, 0);
Assert.assertEquals(1, results.size(), "No device returned");
DeviceManagementDAOFactory.commitTransaction();
} catch (DeviceManagementDAOException e) {
throw new DeviceManagementDAOException("Error occurred while retrieving the device" + e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
}
@Test(dependsOnMethods = "testAddDeviceTest")
public void getDevicesOfUser() throws DeviceManagementDAOException, TransactionManagementException {
try {
DeviceManagementDAOFactory.beginTransaction();
List<Device> results = deviceDAO.getDevicesOfUser(TestDataHolder.OWNER, TestDataHolder.SUPER_TENANT_ID);
Assert.assertEquals(1, results.size(), "No device returned");
DeviceManagementDAOFactory.commitTransaction();
} catch (DeviceManagementDAOException e) {
throw new DeviceManagementDAOException("Error occurred while retrieving the device" + e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
}
@Test(dependsOnMethods = "testAddDeviceTest")
public void getDevicesOfUserWithDeviceType() throws DeviceManagementDAOException, TransactionManagementException {
Device device = TestDataHolder.initialTestDevice;
try {
DeviceManagementDAOFactory.beginTransaction();
List<Device> results = deviceDAO.getDevicesOfUser(TestDataHolder.OWNER, device.getType(), TestDataHolder.SUPER_TENANT_ID);
Assert.assertEquals(1, results.size(), "No device returned");
DeviceManagementDAOFactory.commitTransaction();
} catch (DeviceManagementDAOException e) {
throw new DeviceManagementDAOException("Error occurred while retrieving the device" + e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
}
@Test(dependsOnMethods = "testAddDeviceTest")
public void getDevicesOfUserWithDeviceStatus() throws DeviceManagementDAOException, TransactionManagementException {
List<String> status = new ArrayList<>() ;
status.add(Status.ACTIVE.name());
try {
DeviceManagementDAOFactory.beginTransaction();
List<Device> results = deviceDAO.getDevicesOfUser(TestDataHolder.OWNER, TestDataHolder.SUPER_TENANT_ID, status);
Assert.assertEquals(1, results.size(), "No device returned");
DeviceManagementDAOFactory.commitTransaction();
} catch (DeviceManagementDAOException e) {
throw new DeviceManagementDAOException("Error occurred while retrieving the device" + e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
}
@Test(dependsOnMethods = "testAddDeviceTest")
public void getCountOfDevicesInGroup() throws DeviceManagementDAOException, TransactionManagementException {
PaginationRequest pr = new PaginationRequest(0, 10);
pr.setGroupId(1);
try {
DeviceManagementDAOFactory.beginTransaction();
int results = deviceDAO.getCountOfDevicesInGroup(pr, TestDataHolder.SUPER_TENANT_ID);
Assert.assertEquals(0, results, "No device count returned in group");
DeviceManagementDAOFactory.commitTransaction();
} catch (DeviceManagementDAOException e) {
throw new DeviceManagementDAOException("Error occurred while retrieving the device count" + e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
}
@Test(dependsOnMethods = "testAddDeviceTest")
public void getDeviceCountWithOwner() throws DeviceManagementDAOException, TransactionManagementException {
try {
DeviceManagementDAOFactory.beginTransaction();
int results = deviceDAO.getDeviceCount(TestDataHolder.OWNER, TestDataHolder.SUPER_TENANT_ID);
Assert.assertEquals(1, results, "No device returned");
DeviceManagementDAOFactory.commitTransaction();
} catch (DeviceManagementDAOException e) {
throw new DeviceManagementDAOException("Error occurred while retrieving the device" + e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
}
@Test(dependsOnMethods = "testAddDeviceTest")
public void getDeviceCountWithType() throws DeviceManagementDAOException, TransactionManagementException {
Device device = TestDataHolder.initialTestDevice;
try {
DeviceManagementDAOFactory.beginTransaction();
int results = deviceDAO.getDeviceCount(device.getType(), Status.ACTIVE.name(), TestDataHolder.SUPER_TENANT_ID);
Assert.assertEquals(1, results, "No device returned");
DeviceManagementDAOFactory.commitTransaction();
} catch (DeviceManagementDAOException e) {
throw new DeviceManagementDAOException("Error occurred while retrieving the device" + e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
}
@Test(dependsOnMethods = "testAddDeviceTest")
public void setEnrolmentStatusInBulk() throws DeviceManagementDAOException, TransactionManagementException {
Device device = TestDataHolder.initialTestDevice;
List<String> devices = new ArrayList<>() ;
devices.add(device.getDeviceIdentifier());
try {
DeviceManagementDAOFactory.beginTransaction();
boolean results = deviceDAO.setEnrolmentStatusInBulk(device.getType(), Status.ACTIVE.name(),TestDataHolder.SUPER_TENANT_ID, devices );
Assert.assertTrue(results, "No device returned");
DeviceManagementDAOFactory.commitTransaction();
} catch (DeviceManagementDAOException e) {
throw new DeviceManagementDAOException("Error occurred while retrieving the device" + e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
}
@Test(dependsOnMethods = "testAddDeviceTest")
public void getDeviceCount() throws DeviceManagementDAOException, TransactionManagementException {
try {
DeviceManagementDAOFactory.beginTransaction();
int results = deviceDAO.getDeviceCount(TestDataHolder.SUPER_TENANT_ID);
Assert.assertEquals(1, results, "No device returned");
DeviceManagementDAOFactory.commitTransaction();
} catch (DeviceManagementDAOException e) {
throw new DeviceManagementDAOException("Error occurred while retrieving the device" + e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
}
@Test(dependsOnMethods = "testAddDeviceTest")
public void getDeviceCountWithPagination() throws DeviceManagementDAOException, TransactionManagementException {
Device device = TestDataHolder.initialTestDevice;
PaginationRequest pr = new PaginationRequest(0, 10);
pr.setDeviceName(device.getName());
pr.setDeviceType(device.getType());
pr.setOwner(TestDataHolder.OWNER);
try {
DeviceManagementDAOFactory.beginTransaction();
int results = deviceDAO.getDeviceCount(pr, TestDataHolder.SUPER_TENANT_ID);
Assert.assertEquals(1, results, "No device returned");
DeviceManagementDAOFactory.commitTransaction();
} catch (DeviceManagementDAOException e) {
throw new DeviceManagementDAOException("Error occurred while retrieving the device" + e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
}
@Test(dependsOnMethods = "testAddDeviceTest")
public void getDeviceCountByType() throws DeviceManagementDAOException, TransactionManagementException {
Device device = TestDataHolder.initialTestDevice;
try {
DeviceManagementDAOFactory.beginTransaction();
int results = deviceDAO.getDeviceCountByType(device.getType(), TestDataHolder.SUPER_TENANT_ID);
Assert.assertEquals(1, results, "No device returned");
DeviceManagementDAOFactory.commitTransaction();
} catch (DeviceManagementDAOException e) {
throw new DeviceManagementDAOException("Error occurred while retrieving the device" + e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
}
@Test(dependsOnMethods = "testAddDeviceTest")
public void getDeviceCountByUser() throws DeviceManagementDAOException, TransactionManagementException {
try {
DeviceManagementDAOFactory.beginTransaction();
int results = deviceDAO.getDeviceCountByUser(TestDataHolder.OWNER, TestDataHolder.SUPER_TENANT_ID);
Assert.assertEquals(1, results, "No device returned");
DeviceManagementDAOFactory.commitTransaction();
} catch (DeviceManagementDAOException e) {
throw new DeviceManagementDAOException("Error occurred while retrieving the device" + e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
}
@Test(dependsOnMethods = "testAddDeviceTest")
public void getDeviceCountByName() throws DeviceManagementDAOException, TransactionManagementException {
try {
DeviceManagementDAOFactory.beginTransaction();
int results = deviceDAO.getDeviceCountByName(TestDataHolder.initialDeviceName, TestDataHolder.SUPER_TENANT_ID);
Assert.assertEquals(1, results, "No device returned");
DeviceManagementDAOFactory.commitTransaction();
} catch (DeviceManagementDAOException e) {
throw new DeviceManagementDAOException("Error occurred while retrieving the device" + e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
}
@Test(dependsOnMethods = "testAddDeviceTest")
public void getDeviceCountByOwnership() throws DeviceManagementDAOException, TransactionManagementException {
try {
DeviceManagementDAOFactory.beginTransaction();
int results = deviceDAO.getDeviceCountByOwnership(EnrolmentInfo.OwnerShip.BYOD.name(), TestDataHolder.SUPER_TENANT_ID);
Assert.assertEquals(1, results, "No device returned");
DeviceManagementDAOFactory.commitTransaction();
} catch (DeviceManagementDAOException e) {
throw new DeviceManagementDAOException("Error occurred while retrieving the device" + e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
}
@Test(dependsOnMethods = "testAddDeviceTest")
public void getDeviceCountByStatus() throws DeviceManagementDAOException, TransactionManagementException {
try {
DeviceManagementDAOFactory.beginTransaction();
int results = deviceDAO.getDeviceCountByStatus(Status.ACTIVE.name(), TestDataHolder.SUPER_TENANT_ID);
Assert.assertEquals(1, results, "No device returned");
DeviceManagementDAOFactory.commitTransaction();
} catch (DeviceManagementDAOException e) {
throw new DeviceManagementDAOException("Error occurred while retrieving the device" + e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
}
@Test(dependsOnMethods = "testAddDeviceTest")
public void getDeviceCountByStatusWithType() throws DeviceManagementDAOException, TransactionManagementException {
Device device = TestDataHolder.initialTestDevice;
try {
DeviceManagementDAOFactory.beginTransaction();
int results = deviceDAO.getDeviceCountByStatus(device.getType(), Status.ACTIVE.name(), TestDataHolder.SUPER_TENANT_ID);
Assert.assertEquals(1, results, "No device returned");
DeviceManagementDAOFactory.commitTransaction();
} catch (DeviceManagementDAOException e) {
throw new DeviceManagementDAOException("Error occurred while retrieving the device" + e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
}
@Test(dependsOnMethods = "testAddDeviceTest")
public void getActiveEnrolment() throws DeviceManagementDAOException, TransactionManagementException {
Device device = TestDataHolder.initialTestDevice;
DeviceIdentifier deviceIdentifier = new DeviceIdentifier(device.getDeviceIdentifier(), device.getType());
try {
DeviceManagementDAOFactory.beginTransaction();
EnrolmentInfo results = deviceDAO.getActiveEnrolment(deviceIdentifier, TestDataHolder.SUPER_TENANT_ID);
Assert.assertEquals(Status.ACTIVE, results.getStatus(), "No device returned");
DeviceManagementDAOFactory.commitTransaction();
} catch (DeviceManagementDAOException e) {
throw new DeviceManagementDAOException("Error occurred while retrieving the device" + e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
}
@Test(dependsOnMethods = "testAddDeviceTest")
public void getDeviceEnrolledTenants() throws DeviceManagementDAOException, TransactionManagementException {
try {
DeviceManagementDAOFactory.beginTransaction();
List<Integer> results = deviceDAO.getDeviceEnrolledTenants();
Assert.assertEquals(1, results.size(), "No device returned");
DeviceManagementDAOFactory.commitTransaction();
} catch (DeviceManagementDAOException e) {
throw new DeviceManagementDAOException("Error occurred while retrieving the device" + e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
}
@Test(dependsOnMethods = "testAddDeviceTest")
public void findGeoClusters() throws DeviceManagementDAOException, TransactionManagementException {
GeoQuery geoQuery = new GeoQuery(new GeoCoordinate(123, 123), new GeoCoordinate(123, 123), 12345);
try {
DeviceManagementDAOFactory.beginTransaction();
List<GeoCluster> results = deviceDAO.findGeoClusters(geoQuery, TestDataHolder.SUPER_TENANT_ID);
Assert.assertNotNull(results, "No device returned");
DeviceManagementDAOFactory.commitTransaction();
} catch (DeviceManagementDAOException e) {
throw new DeviceManagementDAOException("Error occurred while retrieving the device" + e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
}
@Test(dependsOnMethods = "testAddDeviceTest")
public void getAppNotInstalledDevices() throws DeviceManagementDAOException, TransactionManagementException {
Device device = TestDataHolder.initialTestDevice;
PaginationRequest pr = new PaginationRequest(0, 10);
pr.setDeviceType(device.getType());
try {
DeviceManagementDAOFactory.beginTransaction();
List<Device> results = deviceDAO.getAppNotInstalledDevices(pr, TestDataHolder.SUPER_TENANT_ID, "com.google.calc", "1.0.0");
Assert.assertNotNull(results, "No device returned");
DeviceManagementDAOFactory.commitTransaction();
} catch (DeviceManagementDAOException e) {
throw new DeviceManagementDAOException("Error occurred while retrieving the device" + e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
}
@Test(dependsOnMethods = "testAddDeviceTest")
public void getCountOfAppNotInstalledDevices() throws DeviceManagementDAOException, TransactionManagementException {
Device device = TestDataHolder.initialTestDevice;
PaginationRequest pr = new PaginationRequest(0, 10);
pr.setDeviceType(device.getType());
try {
DeviceManagementDAOFactory.beginTransaction();
int results = deviceDAO.getCountOfAppNotInstalledDevices(pr, TestDataHolder.SUPER_TENANT_ID, "com.google.calc", "1.0.0");
Assert.assertEquals(1, results, "No device returned");
DeviceManagementDAOFactory.commitTransaction();
} catch (DeviceManagementDAOException e) {
throw new DeviceManagementDAOException("Error occurred while retrieving the device" + e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
}
@Test(dependsOnMethods = "testAddDeviceTest")
public void getDevicesByEncryptionStatus() throws DeviceManagementDAOException, TransactionManagementException {
PaginationRequest pr = new PaginationRequest(0, 10);
try {
DeviceManagementDAOFactory.beginTransaction();
List<Device> results = deviceDAO.getDevicesByEncryptionStatus(pr, TestDataHolder.SUPER_TENANT_ID, false);
Assert.assertNotNull(results, "No device returned");
DeviceManagementDAOFactory.commitTransaction();
} catch (DeviceManagementDAOException e) {
throw new DeviceManagementDAOException("Error occurred while retrieving the device" + e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
}
@Test(dependsOnMethods = "testAddDeviceTest")
public void getCountOfDevicesByEncryptionStatus() throws DeviceManagementDAOException, TransactionManagementException {
try {
DeviceManagementDAOFactory.beginTransaction();
int results = deviceDAO.getCountOfDevicesByEncryptionStatus(TestDataHolder.SUPER_TENANT_ID, true);
Assert.assertEquals(0, results, "No device returned");
DeviceManagementDAOFactory.commitTransaction();
} catch (DeviceManagementDAOException e) {
throw new DeviceManagementDAOException("Error occurred while retrieving the device" + e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
}
}

@ -19,7 +19,9 @@
package io.entgra.device.mgt.core.device.mgt.core.dao;
import io.entgra.device.mgt.core.device.mgt.common.Device;
import io.entgra.device.mgt.core.device.mgt.common.EnrolmentInfo;
import io.entgra.device.mgt.core.device.mgt.common.GroupPaginationRequest;
import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest;
import io.entgra.device.mgt.core.device.mgt.common.exceptions.TransactionManagementException;
import io.entgra.device.mgt.core.device.mgt.common.group.mgt.DeviceGroup;
import io.entgra.device.mgt.core.device.mgt.core.common.BaseDeviceManagementTest;
@ -54,19 +56,18 @@ public class GroupPersistTests extends BaseDeviceManagementTest {
GroupManagementDAOFactory.beginTransaction();
groupId = groupDAO.addGroup(deviceGroup, TestDataHolder.SUPER_TENANT_ID);
GroupManagementDAOFactory.commitTransaction();
GroupManagementDAOFactory.closeConnection();
log.debug("Group added to database. ID: " + groupId);
} catch (GroupManagementDAOException e) {
GroupManagementDAOFactory.rollbackTransaction();
GroupManagementDAOFactory.closeConnection();
String msg = "Error occurred while adding device type '" + deviceGroup.getName() + "'.";
log.error(msg, e);
Assert.fail(msg, e);
} catch (TransactionManagementException e) {
GroupManagementDAOFactory.closeConnection();
String msg = "Error occurred while initiating transaction.";
log.error(msg, e);
Assert.fail(msg, e);
} finally {
GroupManagementDAOFactory.closeConnection();
}
DeviceGroup group = getGroupById(groupId);
if (!isMock()) {
@ -83,22 +84,21 @@ public class GroupPersistTests extends BaseDeviceManagementTest {
request.setGroupName(null);
request.setOwner(null);
List<DeviceGroup> groups = groupDAO.getGroups(request, TestDataHolder.SUPER_TENANT_ID);
GroupManagementDAOFactory.closeConnection();
if (!isMock()) {
Assert.assertNotEquals(groups.size(), 0, "No groups found");
Assert.assertNotNull(groups.get(0), "Group is null");
log.debug("No of Groups found: " + groups.size());
}
} catch (GroupManagementDAOException e) {
GroupManagementDAOFactory.closeConnection();
String msg = "Error occurred while find group by name.";
log.error(msg, e);
Assert.fail(msg, e);
} catch (SQLException e) {
GroupManagementDAOFactory.closeConnection();
String msg = "Error occurred while opening a connection to the data source.";
log.error(msg, e);
Assert.fail(msg, e);
} finally {
GroupManagementDAOFactory.closeConnection();
}
}
@ -114,21 +114,20 @@ public class GroupPersistTests extends BaseDeviceManagementTest {
}
GroupManagementDAOFactory.commitTransaction();
List<String> roles = groupDAO.getRoles(groupId, TestDataHolder.SUPER_TENANT_ID);
GroupManagementDAOFactory.closeConnection();
if (!isMock()) {
Assert.assertEquals(roles, addedRoles, "Added roles are not equal to returned roles.");
}
log.debug("Group shared with roles.");
} catch (GroupManagementDAOException e) {
GroupManagementDAOFactory.closeConnection();
String msg = "Error occurred while find group by name.";
log.error(msg, e);
Assert.fail(msg, e);
} catch (TransactionManagementException e) {
GroupManagementDAOFactory.closeConnection();
String msg = "Error occurred while opening a connection to the data source.";
log.error(msg, e);
Assert.fail(msg, e);
} finally {
GroupManagementDAOFactory.closeConnection();
}
}
@ -141,22 +140,21 @@ public class GroupPersistTests extends BaseDeviceManagementTest {
roles.remove(0);
}
List<DeviceGroup> deviceGroups = groupDAO.getGroups(roles.toArray(new String[roles.size()]), TestDataHolder.SUPER_TENANT_ID);
GroupManagementDAOFactory.closeConnection();
if (!isMock()) {
Assert.assertEquals(deviceGroups.size(), 1, "Unexpected number of device groups found with role.");
Assert.assertEquals(deviceGroups.get(0).getGroupId(), groupId, "Unexpected groupId found with role.");
}
log.debug("Group found for given roles.");
} catch (GroupManagementDAOException e) {
GroupManagementDAOFactory.closeConnection();
String msg = "Error occurred while getting groups shared with roles.";
log.error(msg, e);
Assert.fail(msg, e);
} catch (SQLException e) {
GroupManagementDAOFactory.closeConnection();
String msg = "Error occurred while opening a connection to the data source.";
log.error(msg, e);
Assert.fail(msg, e);
} finally {
GroupManagementDAOFactory.closeConnection();
}
}
@ -271,19 +269,18 @@ public class GroupPersistTests extends BaseDeviceManagementTest {
GroupManagementDAOFactory.beginTransaction();
groupDAO.updateGroup(group, groupId, TestDataHolder.SUPER_TENANT_ID);
GroupManagementDAOFactory.commitTransaction();
GroupManagementDAOFactory.closeConnection();
log.debug("Group updated");
} catch (GroupManagementDAOException e) {
GroupManagementDAOFactory.rollbackTransaction();
GroupManagementDAOFactory.closeConnection();
String msg = "Error occurred while updating group details.";
log.error(msg, e);
Assert.fail(msg, e);
} catch (TransactionManagementException e) {
GroupManagementDAOFactory.closeConnection();
String msg = "Error occurred while initiating transaction.";
log.error(msg, e);
Assert.fail(msg, e);
} finally {
GroupManagementDAOFactory.closeConnection();
}
if (!isMock()) {
group = getGroupById(groupId);
@ -301,20 +298,20 @@ public class GroupPersistTests extends BaseDeviceManagementTest {
GroupManagementDAOFactory.beginTransaction();
groupDAO.deleteGroup(group.getGroupId(), TestDataHolder.SUPER_TENANT_ID);
GroupManagementDAOFactory.commitTransaction();
GroupManagementDAOFactory.closeConnection();
log.debug("Group deleted");
} catch (GroupManagementDAOException e) {
GroupManagementDAOFactory.rollbackTransaction();
GroupManagementDAOFactory.closeConnection();
String msg = "Error occurred while updating group details.";
log.error(msg, e);
Assert.fail(msg, e);
} catch (TransactionManagementException e) {
GroupManagementDAOFactory.closeConnection();
String msg = "Error occurred while initiating transaction.";
log.error(msg, e);
Assert.fail(msg, e);
}
finally {
GroupManagementDAOFactory.closeConnection();
}
group = getGroupById(groupId);
if (!isMock()) {
Assert.assertNull(group, "Group is not deleted");
@ -325,23 +322,290 @@ public class GroupPersistTests extends BaseDeviceManagementTest {
try {
GroupManagementDAOFactory.openConnection();
DeviceGroup deviceGroup = groupDAO.getGroup(groupId, TestDataHolder.SUPER_TENANT_ID);
GroupManagementDAOFactory.closeConnection();
if (deviceGroup == null && isMock()) {
deviceGroup = new DeviceGroup();
deviceGroup.setGroupId(groupId);
}
return deviceGroup;
} catch (GroupManagementDAOException e) {
GroupManagementDAOFactory.closeConnection();
String msg = "Error occurred while retrieving group details.";
log.error(msg, e);
Assert.fail(msg, e);
} catch (SQLException e) {
GroupManagementDAOFactory.closeConnection();
String msg = "Error occurred while opening a connection to the data source.";
log.error(msg, e);
Assert.fail(msg, e);
} finally {
GroupManagementDAOFactory.closeConnection();
}
return null;
}
@Test(dependsOnMethods = {"addDeviceToGroupTest"})
public void getAllDevicesOfGroupWithStatus() {
DeviceGroup deviceGroup = getGroupById(groupId);
Assert.assertNotNull(deviceGroup, "Group is null");
List<String> deviceStatus = new ArrayList<>();
deviceStatus.add(EnrolmentInfo.Status.ACTIVE.name());
try {
GroupManagementDAOFactory.beginTransaction();
groupDAO.getAllDevicesOfGroup(deviceGroup.getName(), deviceStatus, TestDataHolder.SUPER_TENANT_ID);
GroupManagementDAOFactory.commitTransaction();
} catch (GroupManagementDAOException e) {
GroupManagementDAOFactory.rollbackTransaction();
String msg = "Error occurred while getting devices of group '" + groupId + "'.";
log.error(msg, e);
Assert.fail(msg, e);
} catch (TransactionManagementException e) {
String msg = "Error occurred while initiating transaction.";
log.error(msg, e);
Assert.fail(msg, e);
} finally {
GroupManagementDAOFactory.closeConnection();
}
}
@Test(dependsOnMethods = {"addDeviceToGroupTest"})
public void getAllDevicesOfGroup() {
DeviceGroup deviceGroup = getGroupById(groupId);
Assert.assertNotNull(deviceGroup, "Group is null");
try {
GroupManagementDAOFactory.beginTransaction();
groupDAO.getAllDevicesOfGroup(deviceGroup.getName(), TestDataHolder.SUPER_TENANT_ID);
GroupManagementDAOFactory.commitTransaction();
} catch (GroupManagementDAOException e) {
GroupManagementDAOFactory.rollbackTransaction();
String msg = "Error occurred while getting devices of group '" + groupId + "'.";
log.error(msg, e);
Assert.fail(msg, e);
} catch (TransactionManagementException e) {
String msg = "Error occurred while initiating transaction.";
log.error(msg, e);
Assert.fail(msg, e);
} finally {
GroupManagementDAOFactory.closeConnection();
}
}
@Test(dependsOnMethods = {"addDeviceToGroupTest"})
public void getGroupUnassignedDevices() {
DeviceGroup deviceGroup = getGroupById(groupId);
Device device = TestDataHolder.initialTestDevice;
Assert.assertNotNull(deviceGroup, "Group is null");
PaginationRequest pr = new PaginationRequest(0,10);
pr.setDeviceType(device.getType());
List<String> groupNames = new ArrayList<>();
groupNames.add(deviceGroup.getName());
try {
GroupManagementDAOFactory.beginTransaction();
groupDAO.getGroupUnassignedDevices(pr, groupNames);
GroupManagementDAOFactory.commitTransaction();
} catch (GroupManagementDAOException e) {
GroupManagementDAOFactory.rollbackTransaction();
String msg = "Error occurred while getting devices of group '" + groupId + "'.";
log.error(msg, e);
Assert.fail(msg, e);
} catch (TransactionManagementException e) {
String msg = "Error occurred while initiating transaction.";
log.error(msg, e);
Assert.fail(msg, e);
} finally {
GroupManagementDAOFactory.closeConnection();
}
}
@Test(dependsOnMethods = {"addDeviceToGroupTest"})
public void getOwnGroupsCount() {
try {
GroupManagementDAOFactory.beginTransaction();
groupDAO.getOwnGroupsCount(TestDataHolder.OWNER, TestDataHolder.SUPER_TENANT_ID, "/");
GroupManagementDAOFactory.commitTransaction();
} catch (GroupManagementDAOException e) {
GroupManagementDAOFactory.rollbackTransaction();
String msg = "Error occurred while getting own group count for '" + TestDataHolder.OWNER + "'.";
log.error(msg, e);
Assert.fail(msg, e);
} catch (TransactionManagementException e) {
String msg = "Error occurred while initiating transaction.";
log.error(msg, e);
Assert.fail(msg, e);
} finally {
GroupManagementDAOFactory.closeConnection();
}
}
@Test(dependsOnMethods = {"addDeviceToGroupTest"})
public void getOwnGroups() {
try {
GroupManagementDAOFactory.beginTransaction();
groupDAO.getOwnGroups(TestDataHolder.OWNER, TestDataHolder.SUPER_TENANT_ID);
GroupManagementDAOFactory.commitTransaction();
} catch (GroupManagementDAOException e) {
GroupManagementDAOFactory.rollbackTransaction();
String msg = "Error occurred while getting own groups for '" + TestDataHolder.OWNER + "'.";
log.error(msg, e);
Assert.fail(msg, e);
} catch (TransactionManagementException e) {
String msg = "Error occurred while initiating transaction.";
log.error(msg, e);
Assert.fail(msg, e);
} finally {
GroupManagementDAOFactory.closeConnection();
}
}
@Test(dependsOnMethods = {"addDeviceToGroupTest"})
public void getOwnGroupIds() {
try {
GroupManagementDAOFactory.beginTransaction();
groupDAO.getOwnGroupIds(TestDataHolder.OWNER, TestDataHolder.SUPER_TENANT_ID);
GroupManagementDAOFactory.commitTransaction();
} catch (GroupManagementDAOException e) {
GroupManagementDAOFactory.rollbackTransaction();
String msg = "Error occurred while getting own group Ids for '" + TestDataHolder.OWNER + "'.";
log.error(msg, e);
Assert.fail(msg, e);
} catch (TransactionManagementException e) {
String msg = "Error occurred while initiating transaction.";
log.error(msg, e);
Assert.fail(msg, e);
} finally {
GroupManagementDAOFactory.closeConnection();
}
}
@Test(dependsOnMethods = {"addDeviceToGroupTest"})
public void getDeviceCount() {
DeviceGroup deviceGroup = getGroupById(groupId);
Assert.assertNotNull(deviceGroup, "Group is null");
try {
GroupManagementDAOFactory.beginTransaction();
groupDAO.getDeviceCount(deviceGroup.getGroupId(), TestDataHolder.SUPER_TENANT_ID);
GroupManagementDAOFactory.commitTransaction();
} catch (GroupManagementDAOException e) {
GroupManagementDAOFactory.rollbackTransaction();
String msg = "Error occurred while getting device count for '" +groupId+ "'.";
log.error(msg, e);
Assert.fail(msg, e);
} catch (TransactionManagementException e) {
String msg = "Error occurred while initiating transaction.";
log.error(msg, e);
Assert.fail(msg, e);
} finally {
GroupManagementDAOFactory.closeConnection();
}
}
@Test(dependsOnMethods = {"addDeviceToGroupTest"})
public void isDeviceMappedToGroup() {
DeviceGroup deviceGroup = getGroupById(groupId);
Device device = TestDataHolder.initialTestDevice;
Assert.assertNotNull(deviceGroup, "Group is null");
try {
GroupManagementDAOFactory.beginTransaction();
groupDAO.isDeviceMappedToGroup(deviceGroup.getGroupId(), Integer.parseInt(device.getDeviceIdentifier()), TestDataHolder.SUPER_TENANT_ID);
GroupManagementDAOFactory.commitTransaction();
} catch (GroupManagementDAOException e) {
GroupManagementDAOFactory.rollbackTransaction();
String msg = "Error occurred while checking device map to group for '" +groupId+ "'.";
log.error(msg, e);
Assert.fail(msg, e);
} catch (TransactionManagementException e) {
String msg = "Error occurred while initiating transaction.";
log.error(msg, e);
Assert.fail(msg, e);
} finally {
GroupManagementDAOFactory.closeConnection();
}
}
@Test(dependsOnMethods = {"addDeviceToGroupTest"})
public void getGroupCount() {
DeviceGroup deviceGroup = getGroupById(groupId);
GroupPaginationRequest pr = new GroupPaginationRequest(0,10);
pr.setGroupName(deviceGroup.getName());
Assert.assertNotNull(deviceGroup, "Group is null");
try {
GroupManagementDAOFactory.beginTransaction();
groupDAO.getGroupCount(pr, TestDataHolder.SUPER_TENANT_ID);
GroupManagementDAOFactory.commitTransaction();
} catch (GroupManagementDAOException e) {
GroupManagementDAOFactory.rollbackTransaction();
String msg = "Error occurred while getting group count for '" +TestDataHolder.SUPER_TENANT_ID+ "'.";
log.error(msg, e);
Assert.fail(msg, e);
} catch (TransactionManagementException e) {
String msg = "Error occurred while initiating transaction.";
log.error(msg, e);
Assert.fail(msg, e);
} finally {
GroupManagementDAOFactory.closeConnection();
}
}
@Test(dependsOnMethods = {"addDeviceToGroupTest"})
public void getGroupCountWithStatus() {
DeviceGroup deviceGroup = getGroupById(groupId);
Assert.assertNotNull(deviceGroup, "Group is null");
try {
GroupManagementDAOFactory.beginTransaction();
groupDAO.getGroupCount(TestDataHolder.SUPER_TENANT_ID, EnrolmentInfo.Status.ACTIVE.name());
GroupManagementDAOFactory.commitTransaction();
} catch (GroupManagementDAOException e) {
GroupManagementDAOFactory.rollbackTransaction();
String msg = "Error occurred while getting group count for" + TestDataHolder.SUPER_TENANT_ID;
log.error(msg, e);
Assert.fail(msg, e);
} catch (TransactionManagementException e) {
String msg = "Error occurred while initiating transaction.";
log.error(msg, e);
Assert.fail(msg, e);
} finally {
GroupManagementDAOFactory.closeConnection();
}
}
@Test(dependsOnMethods = {"addDeviceToGroupTest"})
public void getRootGroups() {
DeviceGroup deviceGroup = getGroupById(groupId);
Assert.assertNotNull(deviceGroup, "Group is null");
try {
GroupManagementDAOFactory.beginTransaction();
groupDAO.getRootGroups(TestDataHolder.SUPER_TENANT_ID);
GroupManagementDAOFactory.commitTransaction();
} catch (GroupManagementDAOException e) {
GroupManagementDAOFactory.rollbackTransaction();
String msg = "Error occurred while getting group count for " + TestDataHolder.SUPER_TENANT_ID;
log.error(msg, e);
Assert.fail(msg, e);
} catch (TransactionManagementException e) {
String msg = "Error occurred while initiating transaction.";
log.error(msg, e);
Assert.fail(msg, e);
} finally {
GroupManagementDAOFactory.closeConnection();
}
}
@Test(dependsOnMethods = {"addDeviceToGroupTest"})
public void getAllGroupProperties() {
DeviceGroup deviceGroup = getGroupById(groupId);
Assert.assertNotNull(deviceGroup, "Group is null");
try {
GroupManagementDAOFactory.beginTransaction();
groupDAO.getAllGroupProperties(groupId, TestDataHolder.SUPER_TENANT_ID);
GroupManagementDAOFactory.commitTransaction();
} catch (GroupManagementDAOException e) {
GroupManagementDAOFactory.rollbackTransaction();
String msg = "Error occurred while getting groups for " + TestDataHolder.SUPER_TENANT_ID;
log.error(msg, e);
Assert.fail(msg, e);
} catch (TransactionManagementException e) {
String msg = "Error occurred while initiating transaction.";
log.error(msg, e);
Assert.fail(msg, e);
} finally {
GroupManagementDAOFactory.closeConnection();
}
}
}

Loading…
Cancel
Save