use of org.apache.cloudstack.api.response.SecurityGroupResponse in project cloudstack by apache.
the class SecurityGroupJoinDaoImplTest method virtualMachineIDsTwoTest.
@Test
public void virtualMachineIDsTwoTest() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
when(vsg.getId()).thenReturn(3L);
SecurityGroupResponse securityGroupResponse = _securityGroupJoinDaoImpl.newSecurityGroupResponse(vsg, caller);
Field fieldVirtualMachineIds = securityGroupResponse.getClass().getDeclaredField("virtualMachineIds");
fieldVirtualMachineIds.setAccessible(true);
Set<String> virtualMachineIds = (Set<String>) fieldVirtualMachineIds.get(securityGroupResponse);
assertEquals(2, virtualMachineIds.size());
assertTrue(virtualMachineIds.contains(uuidOne));
assertTrue(virtualMachineIds.contains(uuidTwo));
}
use of org.apache.cloudstack.api.response.SecurityGroupResponse in project cloudstack by apache.
the class SecurityGroupJoinDaoImplTest method virtualMachineCountEmptyTest.
@Test
public void virtualMachineCountEmptyTest() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
when(vsg.getId()).thenReturn(1L);
SecurityGroupResponse securityGroupResponse = _securityGroupJoinDaoImpl.newSecurityGroupResponse(vsg, caller);
Field virtualMachineCount = securityGroupResponse.getClass().getDeclaredField("virtualMachineCount");
virtualMachineCount.setAccessible(true);
assertEquals(0, ((Integer) virtualMachineCount.get(securityGroupResponse)).intValue());
}
use of org.apache.cloudstack.api.response.SecurityGroupResponse in project cloudstack by apache.
the class ViewResponseHelper method createSecurityGroupResponses.
public static List<SecurityGroupResponse> createSecurityGroupResponses(List<SecurityGroupJoinVO> securityGroups) {
Account caller = CallContext.current().getCallingAccount();
Hashtable<Long, SecurityGroupResponse> vrDataList = new Hashtable<Long, SecurityGroupResponse>();
// Initialise the vrdatalist with the input data
for (SecurityGroupJoinVO vr : securityGroups) {
SecurityGroupResponse vrData = vrDataList.get(vr.getId());
if (vrData == null) {
// first time encountering this sg
vrData = ApiDBUtils.newSecurityGroupResponse(vr, caller);
} else {
// update rules for 1 to many mapping fields
vrData = ApiDBUtils.fillSecurityGroupDetails(vrData, vr);
}
vrDataList.put(vr.getId(), vrData);
}
return new ArrayList<SecurityGroupResponse>(vrDataList.values());
}
use of org.apache.cloudstack.api.response.SecurityGroupResponse in project cloudstack by apache.
the class SecurityGroupJoinDaoImplTest method virtualMachineCountTwoTest.
@Test
public void virtualMachineCountTwoTest() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
when(vsg.getId()).thenReturn(3L);
SecurityGroupResponse securityGroupResponse = _securityGroupJoinDaoImpl.newSecurityGroupResponse(vsg, caller);
Field virtualMachineCount = securityGroupResponse.getClass().getDeclaredField("virtualMachineCount");
virtualMachineCount.setAccessible(true);
assertEquals(2, ((Integer) virtualMachineCount.get(securityGroupResponse)).intValue());
}
use of org.apache.cloudstack.api.response.SecurityGroupResponse in project cloudstack by apache.
the class SecurityGroupJoinDaoImplTest method virtualMachineCountOneTest.
@Test
public void virtualMachineCountOneTest() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
when(vsg.getId()).thenReturn(2L);
SecurityGroupResponse securityGroupResponse = _securityGroupJoinDaoImpl.newSecurityGroupResponse(vsg, caller);
Field virtualMachineCount = securityGroupResponse.getClass().getDeclaredField("virtualMachineCount");
virtualMachineCount.setAccessible(true);
assertEquals(1, ((Integer) virtualMachineCount.get(securityGroupResponse)).intValue());
}
Aggregations