|
|
@ -31,6 +31,7 @@ import org.wso2.carbon.device.mgt.core.common.BaseDeviceManagementTest;
|
|
|
|
import org.wso2.carbon.device.mgt.core.common.TestDataHolder;
|
|
|
|
import org.wso2.carbon.device.mgt.core.common.TestDataHolder;
|
|
|
|
|
|
|
|
|
|
|
|
import java.sql.SQLException;
|
|
|
|
import java.sql.SQLException;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
|
|
public class GroupPersistTests extends BaseDeviceManagementTest {
|
|
|
|
public class GroupPersistTests extends BaseDeviceManagementTest {
|
|
|
@ -47,7 +48,7 @@ public class GroupPersistTests extends BaseDeviceManagementTest {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void testAddGroupTest() {
|
|
|
|
public void addGroupTest() {
|
|
|
|
DeviceGroup deviceGroup = TestDataHolder.generateDummyGroupData();
|
|
|
|
DeviceGroup deviceGroup = TestDataHolder.generateDummyGroupData();
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
GroupManagementDAOFactory.beginTransaction();
|
|
|
|
GroupManagementDAOFactory.beginTransaction();
|
|
|
@ -72,7 +73,7 @@ public class GroupPersistTests extends BaseDeviceManagementTest {
|
|
|
|
log.debug("Group name: " + group.getName());
|
|
|
|
log.debug("Group name: " + group.getName());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test(dependsOnMethods = {"testAddGroupTest"})
|
|
|
|
@Test(dependsOnMethods = {"addGroupTest"})
|
|
|
|
public void getGroupTest() {
|
|
|
|
public void getGroupTest() {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
GroupManagementDAOFactory.openConnection();
|
|
|
|
GroupManagementDAOFactory.openConnection();
|
|
|
@ -96,7 +97,82 @@ public class GroupPersistTests extends BaseDeviceManagementTest {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test(dependsOnMethods = {"testAddGroupTest"})
|
|
|
|
@Test(dependsOnMethods = {"addGroupTest"})
|
|
|
|
|
|
|
|
public void shareGroupTest() {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
GroupManagementDAOFactory.beginTransaction();
|
|
|
|
|
|
|
|
List<String> addedRoles = new ArrayList<>();
|
|
|
|
|
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
|
|
|
|
String role = "role-" + i;
|
|
|
|
|
|
|
|
groupDAO.addRole(groupId, role, TestDataHolder.SUPER_TENANT_ID);
|
|
|
|
|
|
|
|
addedRoles.add(role);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
GroupManagementDAOFactory.commitTransaction();
|
|
|
|
|
|
|
|
List<String> roles = groupDAO.getRoles(groupId, TestDataHolder.SUPER_TENANT_ID);
|
|
|
|
|
|
|
|
Assert.assertEquals(roles, addedRoles, "Added roles are not equal to returned roles.");
|
|
|
|
|
|
|
|
log.debug("Group shared with roles.");
|
|
|
|
|
|
|
|
} catch (GroupManagementDAOException e) {
|
|
|
|
|
|
|
|
String msg = "Error occurred while find group by name.";
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
Assert.fail(msg, e);
|
|
|
|
|
|
|
|
} catch (TransactionManagementException e) {
|
|
|
|
|
|
|
|
String msg = "Error occurred while opening a connection to the data source.";
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
Assert.fail(msg, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
GroupManagementDAOFactory.closeConnection();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test(dependsOnMethods = {"shareGroupTest"})
|
|
|
|
|
|
|
|
public void getShareGroupTest() {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
GroupManagementDAOFactory.openConnection();
|
|
|
|
|
|
|
|
List<String> roles = groupDAO.getRoles(groupId, TestDataHolder.SUPER_TENANT_ID);
|
|
|
|
|
|
|
|
roles.remove(0);
|
|
|
|
|
|
|
|
List<DeviceGroup> deviceGroups = groupDAO.getGroups(roles.toArray(new String[roles.size()]), TestDataHolder.SUPER_TENANT_ID);
|
|
|
|
|
|
|
|
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) {
|
|
|
|
|
|
|
|
String msg = "Error occurred while getting groups shared with roles.";
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
Assert.fail(msg, e);
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
|
|
|
String msg = "Error occurred while opening a connection to the data source.";
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
Assert.fail(msg, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
GroupManagementDAOFactory.closeConnection();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test(dependsOnMethods = {"getShareGroupTest"})
|
|
|
|
|
|
|
|
public void unshareGroupTest() {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
GroupManagementDAOFactory.beginTransaction();
|
|
|
|
|
|
|
|
List<String> rolesToRemove = groupDAO.getRoles(groupId, TestDataHolder.SUPER_TENANT_ID);
|
|
|
|
|
|
|
|
for (String role : rolesToRemove) {
|
|
|
|
|
|
|
|
groupDAO.removeRole(groupId, role, TestDataHolder.SUPER_TENANT_ID);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
GroupManagementDAOFactory.commitTransaction();
|
|
|
|
|
|
|
|
List<String> roles = groupDAO.getRoles(groupId, TestDataHolder.SUPER_TENANT_ID);
|
|
|
|
|
|
|
|
Assert.assertNotEquals(roles, rolesToRemove, "Roles not removed.");
|
|
|
|
|
|
|
|
log.debug("Group unshared with given roles.");
|
|
|
|
|
|
|
|
} catch (GroupManagementDAOException e) {
|
|
|
|
|
|
|
|
String msg = "Error occurred while find group by name.";
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
Assert.fail(msg, e);
|
|
|
|
|
|
|
|
} catch (TransactionManagementException e) {
|
|
|
|
|
|
|
|
String msg = "Error occurred while opening a connection to the data source.";
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
Assert.fail(msg, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
GroupManagementDAOFactory.closeConnection();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test(dependsOnMethods = {"addGroupTest"})
|
|
|
|
public void addDeviceToGroupTest() {
|
|
|
|
public void addDeviceToGroupTest() {
|
|
|
|
Device initialTestDevice = TestDataHolder.initialTestDevice;
|
|
|
|
Device initialTestDevice = TestDataHolder.initialTestDevice;
|
|
|
|
DeviceGroup deviceGroup = getGroupById(groupId);
|
|
|
|
DeviceGroup deviceGroup = getGroupById(groupId);
|
|
|
@ -162,7 +238,7 @@ public class GroupPersistTests extends BaseDeviceManagementTest {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test(dependsOnMethods = {"removeDeviceFromGroupTest"})
|
|
|
|
@Test(dependsOnMethods = {"removeDeviceFromGroupTest", "unshareGroupTest"})
|
|
|
|
public void updateGroupTest() {
|
|
|
|
public void updateGroupTest() {
|
|
|
|
String name = "Test Updated";
|
|
|
|
String name = "Test Updated";
|
|
|
|
String desc = "Desc updated";
|
|
|
|
String desc = "Desc updated";
|
|
|
|