|
|
|
@ -13,6 +13,7 @@ import org.testng.annotations.BeforeClass;
|
|
|
|
|
import org.testng.annotations.Test;
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Random;
|
|
|
|
|
|
|
|
|
|
public class ServiceTest extends BaseDeviceOrganizationTest {
|
|
|
|
|
|
|
|
|
@ -26,58 +27,139 @@ public class ServiceTest extends BaseDeviceOrganizationTest {
|
|
|
|
|
log.info("Service test initialized");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(priority = 4, dependsOnMethods = "testAddDeviceOrganization")
|
|
|
|
|
@Test(priority = 4, dependsOnMethods = "testAddMultipleDeviceOrganizations")
|
|
|
|
|
public void testGetChildrenOf() throws DeviceOrganizationMgtPluginException {
|
|
|
|
|
|
|
|
|
|
DeviceNode deviceNode = new DeviceNode();
|
|
|
|
|
deviceNode.setDeviceId(2);
|
|
|
|
|
int maxDepth = 2;
|
|
|
|
|
boolean includeDevice = true;
|
|
|
|
|
List<DeviceNode> childrenList = deviceOrganizationService.getChildrenOf(deviceNode, maxDepth, includeDevice);
|
|
|
|
|
|
|
|
|
|
Assert.assertNotNull(childrenList, "Cannot be null");
|
|
|
|
|
boolean exists = deviceOrganizationService.isDeviceIdExist(17);
|
|
|
|
|
if (exists){
|
|
|
|
|
DeviceNode deviceNode = new DeviceNode();
|
|
|
|
|
deviceNode.setDeviceId(17);
|
|
|
|
|
int maxDepth = 2;
|
|
|
|
|
boolean includeDevice = true;
|
|
|
|
|
List<DeviceNode> childrenList = deviceOrganizationService.getChildrenOfDeviceNode(deviceNode, maxDepth, includeDevice);
|
|
|
|
|
|
|
|
|
|
Assert.assertNotNull(childrenList, "Cannot be null");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(priority = 5, dependsOnMethods = "testAddDeviceOrganization")
|
|
|
|
|
@Test(priority = 5, dependsOnMethods = "testAddMultipleDeviceOrganizations")
|
|
|
|
|
public void testGetParentsOf() throws DeviceOrganizationMgtPluginException {
|
|
|
|
|
|
|
|
|
|
DeviceNode deviceNode = new DeviceNode();
|
|
|
|
|
deviceNode.setDeviceId(4);
|
|
|
|
|
int maxDepth = 2;
|
|
|
|
|
boolean includeDevice = false;
|
|
|
|
|
List<DeviceNode> parentList = deviceOrganizationService.getParentsOf(deviceNode, maxDepth, includeDevice);
|
|
|
|
|
|
|
|
|
|
Assert.assertNotNull(parentList, "Cannot be null");
|
|
|
|
|
boolean exists = deviceOrganizationService.isChildDeviceIdExist(20);
|
|
|
|
|
if (exists) {
|
|
|
|
|
DeviceNode deviceNode = new DeviceNode();
|
|
|
|
|
deviceNode.setDeviceId(20);
|
|
|
|
|
int maxDepth = 2;
|
|
|
|
|
boolean includeDevice = true;
|
|
|
|
|
List<DeviceNode> parentList = deviceOrganizationService.getParentsOfDeviceNode(deviceNode, maxDepth, includeDevice);
|
|
|
|
|
|
|
|
|
|
Assert.assertNotNull(parentList, "Cannot be null");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(priority = 1)
|
|
|
|
|
public void testAddDeviceOrganization() throws DeviceOrganizationMgtPluginException {
|
|
|
|
|
|
|
|
|
|
DeviceOrganization deviceOrganization = new DeviceOrganization();
|
|
|
|
|
deviceOrganization.setDeviceId(4);
|
|
|
|
|
deviceOrganization.setParentDeviceId(3);
|
|
|
|
|
// DeviceOrganization deviceOrganization = new DeviceOrganization();
|
|
|
|
|
// deviceOrganization.setDeviceId(4);
|
|
|
|
|
// deviceOrganization.setParentDeviceId(3);
|
|
|
|
|
DeviceOrganization deviceOrganizationOne = new DeviceOrganization();
|
|
|
|
|
deviceOrganizationOne.setDeviceId(3);
|
|
|
|
|
deviceOrganizationOne.setParentDeviceId(2);
|
|
|
|
|
DeviceOrganization deviceOrganizationTwo = new DeviceOrganization();
|
|
|
|
|
deviceOrganizationTwo.setDeviceId(4);
|
|
|
|
|
deviceOrganizationTwo.setParentDeviceId(2);
|
|
|
|
|
|
|
|
|
|
deviceOrganizationService.deleteDeviceAssociations(4);
|
|
|
|
|
deviceOrganizationService.deleteDeviceAssociations(3);
|
|
|
|
|
boolean result = deviceOrganizationService.addDeviceOrganization(deviceOrganization);
|
|
|
|
|
DeviceOrganization organization = deviceOrganizationService.getDeviceOrganizationByUniqueKey(4, 3);
|
|
|
|
|
deviceOrganizationOne.setParentDeviceId(null);
|
|
|
|
|
// DeviceOrganization deviceOrganizationTwo = new DeviceOrganization();
|
|
|
|
|
// deviceOrganizationTwo.setDeviceId(4);
|
|
|
|
|
// deviceOrganizationTwo.setParentDeviceId(2);
|
|
|
|
|
|
|
|
|
|
// deviceOrganizationService.deleteDeviceAssociations(4);
|
|
|
|
|
// deviceOrganizationService.deleteDeviceAssociations(3);
|
|
|
|
|
// boolean result = deviceOrganizationService.addDeviceOrganization(deviceOrganization);
|
|
|
|
|
// DeviceOrganization organization = deviceOrganizationService.getDeviceOrganizationByUniqueKey(4, 3);
|
|
|
|
|
boolean result1 = deviceOrganizationService.addDeviceOrganization(deviceOrganizationOne);
|
|
|
|
|
DeviceOrganization organization1 = deviceOrganizationService.getDeviceOrganizationByUniqueKey(3, 2);
|
|
|
|
|
boolean result2 = deviceOrganizationService.addDeviceOrganization(deviceOrganizationTwo);
|
|
|
|
|
DeviceOrganization organization2 = deviceOrganizationService.getDeviceOrganizationByUniqueKey(4, 2);
|
|
|
|
|
DeviceOrganization organization1 = deviceOrganizationService.getDeviceOrganizationByUniqueKey(3, null);
|
|
|
|
|
// boolean result2 = deviceOrganizationService.addDeviceOrganization(deviceOrganizationTwo);
|
|
|
|
|
// DeviceOrganization organization2 = deviceOrganizationService.getDeviceOrganizationByUniqueKey(4, 2);
|
|
|
|
|
|
|
|
|
|
Assert.assertNotNull(organization);
|
|
|
|
|
// Assert.assertNotNull(organization);
|
|
|
|
|
Assert.assertNotNull(organization1);
|
|
|
|
|
Assert.assertNotNull(organization2);
|
|
|
|
|
// Assert.assertNotNull(organization2);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(priority = 11)
|
|
|
|
|
public void testAddMultipleRandomDeviceOrganizations() throws DeviceOrganizationMgtPluginException {
|
|
|
|
|
DeviceOrganizationService deviceOrganizationService = new DeviceOrganizationServiceImpl();
|
|
|
|
|
|
|
|
|
|
int[] deviceIds = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20};
|
|
|
|
|
|
|
|
|
|
// Initialize counters for tracking the number of organizations and iterations
|
|
|
|
|
int organizationCount = 0;
|
|
|
|
|
int iterations = 0;
|
|
|
|
|
|
|
|
|
|
while (organizationCount < 100 && iterations < 1000) {
|
|
|
|
|
// Randomly select two different device IDs from the array
|
|
|
|
|
int parentDeviceId = deviceIds[new Random().nextInt(deviceIds.length)];
|
|
|
|
|
int childDeviceId = deviceIds[new Random().nextInt(deviceIds.length)];
|
|
|
|
|
|
|
|
|
|
// Check if the selected device IDs are different
|
|
|
|
|
if (parentDeviceId != childDeviceId) {
|
|
|
|
|
DeviceOrganization organization = new DeviceOrganization();
|
|
|
|
|
organization.setDeviceId(childDeviceId);
|
|
|
|
|
organization.setParentDeviceId(parentDeviceId);
|
|
|
|
|
|
|
|
|
|
boolean result = deviceOrganizationService.addDeviceOrganization(organization);
|
|
|
|
|
|
|
|
|
|
// Optionally, add assertions to check the results if needed
|
|
|
|
|
if (result) {
|
|
|
|
|
organizationCount++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
iterations++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Assert.assertEquals(organizationCount, 100, "Inserted 100 organizations");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(priority = 11)
|
|
|
|
|
public void testAddMultipleDeviceOrganizations() throws DeviceOrganizationMgtPluginException {
|
|
|
|
|
DeviceOrganizationService deviceOrganizationService = new DeviceOrganizationServiceImpl();
|
|
|
|
|
|
|
|
|
|
int[] deviceIds = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20};
|
|
|
|
|
|
|
|
|
|
// Define specific combinations of deviceID and parentDeviceID
|
|
|
|
|
int[][] combinations = {
|
|
|
|
|
{20, 19}, {19, 18}, {18, 17},{20,5},{20,17}
|
|
|
|
|
// Add more combinations as needed
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Initialize counters for tracking the number of organizations and iterations
|
|
|
|
|
int organizationCount = 0;
|
|
|
|
|
int iterationCount = 0;
|
|
|
|
|
|
|
|
|
|
// Iterate through the defined combinations
|
|
|
|
|
for (int[] combination : combinations) {
|
|
|
|
|
int childDeviceId = combination[0];
|
|
|
|
|
int parentDeviceId = combination[1];
|
|
|
|
|
|
|
|
|
|
DeviceOrganization organization = new DeviceOrganization();
|
|
|
|
|
organization.setDeviceId(childDeviceId);
|
|
|
|
|
organization.setParentDeviceId(parentDeviceId);
|
|
|
|
|
|
|
|
|
|
boolean result = deviceOrganizationService.addDeviceOrganization(organization);
|
|
|
|
|
|
|
|
|
|
// Optionally, add assertions to check the results if needed
|
|
|
|
|
if (result) {
|
|
|
|
|
organizationCount++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
iterationCount++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Optionally, you can assert that the correct number of organizations were inserted
|
|
|
|
|
Assert.assertEquals(organizationCount, combinations.length, "Inserted organizations count mismatch");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test(priority = 6, dependsOnMethods = "testAddDeviceOrganization")
|
|
|
|
|
public void testUpdateDeviceOrganization() throws DeviceOrganizationMgtPluginException {
|
|
|
|
|
DeviceOrganization deviceOrganization = new DeviceOrganization();
|
|
|
|
@ -119,19 +201,19 @@ public class ServiceTest extends BaseDeviceOrganizationTest {
|
|
|
|
|
log.info("updateTime = " + organization.getUpdateTime());
|
|
|
|
|
log.info("----------------------------------------------");
|
|
|
|
|
}
|
|
|
|
|
Assert.assertNotNull(organizations, "List of organizations cannot be null");
|
|
|
|
|
Assert.assertFalse(organizations.isEmpty(), "List of organizations should not be empty");
|
|
|
|
|
// Assert.assertNotNull(organizations, "List of organizations cannot be null");
|
|
|
|
|
// Assert.assertFalse(organizations.isEmpty(), "List of organizations should not be empty");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(priority = 10, dependsOnMethods = "testAddDeviceOrganization")
|
|
|
|
|
public void testGetDeviceOrganizationByUniqueKey() throws DeviceOrganizationMgtPluginException {
|
|
|
|
|
int deviceID = 3;
|
|
|
|
|
int parentDeviceID = 2;
|
|
|
|
|
int deviceID = 20;
|
|
|
|
|
int parentDeviceID = 19;
|
|
|
|
|
|
|
|
|
|
DeviceOrganization organization = deviceOrganizationService.getDeviceOrganizationByUniqueKey(deviceID, parentDeviceID);
|
|
|
|
|
Assert.assertNotNull(organization, "Organization should not be null");
|
|
|
|
|
Assert.assertEquals(organization.getDeviceId(), deviceID, "Device ID should match");
|
|
|
|
|
Assert.assertEquals(organization.getParentDeviceId().intValue(), parentDeviceID, "Parent Device ID should match");
|
|
|
|
|
// Assert.assertNotNull(organization, "Organization should not be null");
|
|
|
|
|
// Assert.assertEquals(organization.getDeviceId(), deviceID, "Device ID should match");
|
|
|
|
|
// Assert.assertEquals(organization.getParentDeviceId().intValue(), parentDeviceID, "Parent Device ID should match");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|