Compare commits

Invalid templates have been ignored

1 invalid template(s) found pull_request_template.md: frontmatter must start with a separator line

...

15 Commits

Author SHA1 Message Date
Gimhan Wijayawardana 628453b202 Modify permission of operation status update
5 months ago
Lasantha Dharmakeerthi e84a479c23 Add missing test cases for DevicePersistTests and GroupPersistTests
5 months ago
Pramila Niroshan d443fef6e0 Add missing test cases for DevicePersistTests and GroupPersistTests
5 months ago
Navod Zoysa 474dfbb78f Merge pull request 'Fix SQL error' (#412) from fix-sql into master
6 months ago
Lasantha Dharmakeerthi 1aec609bff Fix SQL error
6 months ago
Lasantha Dharmakeerthi c03e317e4b Add filter to display web apps in Enrollment Application Install
6 months ago
Lasantha Dharmakeerthi f0f31c4d5c Fix devices of a group not loading
6 months ago
prathabanKavin b0362c5825 Fix devices of a group not loading
6 months ago
Lasantha Dharmakeerthi 12e65ee7e1 Fix sql syntax errors
6 months ago
Pramila Niroshan f0c48c585d Fix sql syntax errors
6 months ago
Pahansith Gunathilake 1d7438bcd6 Merge pull request 'Fix sql syntax errors' (#407) from pramilaniroshan/device-mgt-core:fix-sql-syntax-erros into master
6 months ago
Charitha Goonetilleke aca7aa3ccc Disable validateOperationCodeFiltering for validateOperationLogFilters
6 months ago
Lasantha Dharmakeerthi 842f14ea2c Add missing permission
6 months ago
Rajitha Kumara 65ac47aec0 Add missing permission
6 months ago
Ashvini Wegodapola 7616c2255c Add filter to get Web apps in Enrollment Application Install
6 months ago

@ -118,6 +118,11 @@ public class Filter {
*/
private boolean isNotRetired;
/**
* To check whether web applications should be returned
*/
private boolean withWebApps;
public int getLimit() {
return limit;
}
@ -221,4 +226,12 @@ public class Filter {
public void setNotRetired(boolean notRetired) {
isNotRetired = notRetired;
}
public boolean isWithWebApps() {
return withWebApps;
}
public void setWithWebApps(boolean withWebApps) {
this.withWebApps = withWebApps;
}
}

@ -178,7 +178,11 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
sql += "AND AP_APP_RELEASE.CURRENT_STATE = ? ";
}
if (deviceTypeId != -1) {
sql += "AND AP_APP.DEVICE_TYPE_ID = ? ";
sql += "AND (AP_APP.DEVICE_TYPE_ID = ? ";
if (filter.isWithWebApps()) {
sql += "OR AP_APP.DEVICE_TYPE_ID = 0 ";
}
sql += ") ";
}
if (filter.isNotRetired()) {
sql += "AND AP_APP.STATUS != 'RETIRED' ";
@ -309,7 +313,11 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
sql += " AND AP_APP_RELEASE.CURRENT_STATE = ?";
}
if (deviceTypeId != -1) {
sql += " AND AP_APP.DEVICE_TYPE_ID = ?";
sql += "AND (AP_APP.DEVICE_TYPE_ID = ? ";
if (filter.isWithWebApps()) {
sql += "OR AP_APP.DEVICE_TYPE_ID = 0 ";
}
sql += ") ";
}
if (filter.isNotRetired()) {
sql += " AND AP_APP.STATUS != 'RETIRED'";

@ -165,6 +165,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:update:status",
roles = {"Internal/devicemgt-user"},
permissions = {"/device-mgt/devices/operations/update-status"}
),
@Scope(
name = "Enroll Device",
description = "Register a device",
@ -2714,12 +2721,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:update:status")
})
}
)

@ -574,7 +574,11 @@ public class RequestValidationUtil {
}
if (operationCode != null && !operationCode.isEmpty()) {
validateOperationCodeFiltering(operationCode, type);
/*
Commenting this as dynamic device types doesn't have configuration based feature manager which
used to define fixed set of operation codes.
*/
// validateOperationCodeFiltering(operationCode, type);
operationLogFilters.setOperationCode(operationCode);
}
return operationLogFilters;

@ -1036,12 +1036,12 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
"(SELECT gd.DEVICE_ID, " +
"gd.DESCRIPTION, " +
"gd.NAME, " +
"gd.DEVICE_IDENTIFICATION, " +
"gd.DEVICE_IDENTIFICATION " +
"FROM " +
"(SELECT d.ID AS DEVICE_ID, " +
"d.DESCRIPTION, " +
"d.NAME, " +
"d.DEVICE_IDENTIFICATION, " +
"d.DEVICE_IDENTIFICATION " +
"FROM DM_DEVICE d, " +
"(SELECT dgm.DEVICE_ID " +
"FROM DM_DEVICE_GROUP_MAP dgm " +
@ -1716,7 +1716,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
String sql = "SELECT d.ID AS DEVICE_ID, d.DESCRIPTION, d.NAME AS DEVICE_NAME, d.LAST_UPDATED_TIMESTAMP, " +
"e.DEVICE_TYPE, e.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.IS_TRANSFERRED, " +
"e.DATE_OF_LAST_UPDATE, e.DATE_OF_ENROLMENT, e.ENROLMENT_ID FROM " +
"(SELECT e.ID, e.DEVICE_ID, e.DEVICE_TYPE, e.OWNER, " +
"(SELECT e.ID, e.DEVICE_ID, e.DEVICE_TYPE, e.DEVICE_IDENTIFICATION, e.OWNER, " +
"e.OWNERSHIP, e.STATUS, e.IS_TRANSFERRED, e.DATE_OF_ENROLMENT, e.DATE_OF_LAST_UPDATE, e.ID AS " +
"ENROLMENT_ID FROM DM_ENROLMENT e WHERE TENANT_ID = ? AND STATUS = ?) e, " +
"DM_DEVICE d WHERE d.ID = e.DEVICE_ID AND d.TENANT_ID = ?";
@ -2365,7 +2365,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
"e.device_id," +
"e.status, " +
"e.date_of_last_update, " +
"e.date_of_enrolment " +
"e.date_of_enrolment, " +
"e.DEVICE_TYPE " +
"FROM dm_enrolment e " +
"INNER JOIN " +
@ -2375,7 +2375,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
"KEY_FIELD = 'encryptionEnabled' " +
"AND VALUE_FIELD = ?) AS di " +
"ON di.DEVICE_ID = e.DEVICE_ID " +
"WHERE e.tenant_id = ?) e1, " +
"WHERE e.tenant_id = ?) e1 " +
"WHERE d.id = e1.device_id " +
"ORDER BY e1.date_of_last_update DESC " +
"LIMIT ? OFFSET ?";
@ -2409,7 +2409,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
try {
Connection conn = getConnection();
String sql =
"SELECT COUNT(DEVICE_ID) " +
"SELECT COUNT(DEVICE_ID) AS DEVICE_COUNT " +
"FROM DM_DEVICE_INFO " +
"WHERE KEY_FIELD = 'encryptionEnabled' " +
"AND VALUE_FIELD = ?";
@ -2417,7 +2417,6 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
try (PreparedStatement ps = conn.prepareStatement(sql)) {
ps.setBoolean(1, isEncrypted);
ps.setInt(2, tenantId);
try (ResultSet rs = ps.executeQuery()) {
return rs.next() ? rs.getInt("DEVICE_COUNT") : 0;

@ -646,8 +646,7 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl {
}
@Override
public List<Device> searchDevicesInGroup(PaginationRequest request, int tenantId)
throws DeviceManagementDAOException {
public List<Device> searchDevicesInGroup(PaginationRequest request, int tenantId) throws DeviceManagementDAOException {
List<Device> devices = null;
int groupId = request.getGroupId();
String deviceType = request.getDeviceType();
@ -687,6 +686,7 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl {
"gd.DESCRIPTION, " +
"gd.NAME, " +
"gd.DEVICE_IDENTIFICATION, " +
"gd.LAST_UPDATED_TIMESTAMP " +
"FROM " +
"(SELECT d.ID AS DEVICE_ID, " +
"d.DESCRIPTION, " +
@ -708,10 +708,10 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl {
sql = sql + " WHERE 1 = 1";
//Add query for last updated timestamp
if (since != null) {
sql = sql + " AND d.LAST_UPDATED_TIMESTAMP > ?";
sql = sql + " AND gd.LAST_UPDATED_TIMESTAMP > ?";
isSinceProvided = true;
}
sql = sql + " ) d1 WHERE d1.DEVICE_ID = e.DEVICE_ID AND TENANT_ID = ? ";
sql = sql + " ) d1 WHERE d1.DEVICE_ID = e.DEVICE_ID AND e.TENANT_ID = ? ";
//Add the query for device-type
if (deviceType != null && !deviceType.isEmpty()) {
sql = sql + " AND e.DEVICE_TYPE = ?";

@ -23,6 +23,7 @@ import io.entgra.device.mgt.core.device.mgt.common.EnrolmentInfo;
import io.entgra.device.mgt.core.device.mgt.common.MonitoringOperation;
import io.entgra.device.mgt.core.device.mgt.common.OperationMonitoringTaskConfig;
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;
@ -32,6 +33,7 @@ import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Properties;
import java.util.Calendar;
public class TestDataHolder {
@ -39,11 +41,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
@ -141,6 +150,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);

@ -18,7 +18,13 @@
package io.entgra.device.mgt.core.device.mgt.core.dao;
import io.entgra.device.mgt.core.device.mgt.common.EnrolmentInfo;
import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest;
import io.entgra.device.mgt.core.device.mgt.common.device.details.DeviceData;
import io.entgra.device.mgt.core.device.mgt.common.geo.service.GeoCluster;
import io.entgra.device.mgt.core.device.mgt.common.geo.service.GeoCoordinate;
import io.entgra.device.mgt.core.device.mgt.common.geo.service.GeoQuery;
import org.apache.commons.collections.map.SingletonMap;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.testng.Assert;
@ -34,6 +40,7 @@ import io.entgra.device.mgt.core.device.mgt.core.common.TestDataHolder;
import io.entgra.device.mgt.core.device.mgt.core.dto.DeviceType;
import java.sql.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@ -89,6 +96,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();
@ -275,6 +283,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);
@ -283,4 +292,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();
}
}
}

@ -18,6 +18,8 @@
package io.entgra.device.mgt.core.device.mgt.core.dao;
import io.entgra.device.mgt.core.device.mgt.common.EnrolmentInfo;
import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.testng.Assert;
@ -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();
}
}
}

@ -469,6 +469,14 @@
<DefaultRoles>Internal/devicemgt-user</DefaultRoles>
</MappedScopeDetails>
</DefaultPermission>
<DefaultPermission>
<Name>/permission/admin/device-mgt/devices/any-group/permitted-actions-under-owning-group</Name>
<MappedScopeDetails>
<Name>Apply permitted actions on any group</Name>
<Key>dm:group:any:permitted</Key>
<DefaultRoles>Internal/devicemgt-user</DefaultRoles>
</MappedScopeDetails>
</DefaultPermission>
</DefaultPermissions>
</DeviceMgtConfiguration>

Loading…
Cancel
Save