Search in sources :

Example 6 with SecurityGroupResponse

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));
}
Also used : Field(java.lang.reflect.Field) Set(java.util.Set) SecurityGroupResponse(org.apache.cloudstack.api.response.SecurityGroupResponse) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 7 with SecurityGroupResponse

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());
}
Also used : Field(java.lang.reflect.Field) SecurityGroupResponse(org.apache.cloudstack.api.response.SecurityGroupResponse) Test(org.junit.Test)

Example 8 with SecurityGroupResponse

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());
}
Also used : Account(com.cloud.user.Account) Hashtable(java.util.Hashtable) ArrayList(java.util.ArrayList) SecurityGroupResponse(org.apache.cloudstack.api.response.SecurityGroupResponse) SecurityGroupJoinVO(com.cloud.api.query.vo.SecurityGroupJoinVO)

Example 9 with SecurityGroupResponse

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());
}
Also used : Field(java.lang.reflect.Field) SecurityGroupResponse(org.apache.cloudstack.api.response.SecurityGroupResponse) Test(org.junit.Test)

Example 10 with SecurityGroupResponse

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());
}
Also used : Field(java.lang.reflect.Field) SecurityGroupResponse(org.apache.cloudstack.api.response.SecurityGroupResponse) Test(org.junit.Test)

Aggregations

SecurityGroupResponse (org.apache.cloudstack.api.response.SecurityGroupResponse)14 Field (java.lang.reflect.Field)6 Test (org.junit.Test)6 SecurityGroupJoinVO (com.cloud.api.query.vo.SecurityGroupJoinVO)3 ArrayList (java.util.ArrayList)3 Set (java.util.Set)3 ServerApiException (org.apache.cloudstack.api.ServerApiException)3 Matchers.anyString (org.mockito.Matchers.anyString)3 Account (com.cloud.user.Account)2 NicSecondaryIpVO (com.cloud.vm.dao.NicSecondaryIpVO)2 HashMap (java.util.HashMap)2 AffinityGroupResponse (org.apache.cloudstack.affinity.AffinityGroupResponse)2 NicResponse (org.apache.cloudstack.api.response.NicResponse)2 NicSecondaryIpResponse (org.apache.cloudstack.api.response.NicSecondaryIpResponse)2 SecurityGroupRuleResponse (org.apache.cloudstack.api.response.SecurityGroupRuleResponse)2 ResourceTagJoinVO (com.cloud.api.query.vo.ResourceTagJoinVO)1 SecurityGroup (com.cloud.network.security.SecurityGroup)1 SecurityGroupVMMapVO (com.cloud.network.security.SecurityGroupVMMapVO)1 SecurityRule (com.cloud.network.security.SecurityRule)1 ProjectAccount (com.cloud.projects.ProjectAccount)1