Search in sources :

Example 1 with QuotaBalanceResponse

use of org.apache.cloudstack.api.response.QuotaBalanceResponse in project cloudstack by apache.

the class QuotaBalanceCmdTest method testQuotaBalanceCmd.

@Test
public void testQuotaBalanceCmd() throws NoSuchFieldException, IllegalAccessException {
    QuotaBalanceCmd cmd = new QuotaBalanceCmd();
    Field rbField = QuotaBalanceCmd.class.getDeclaredField("_responseBuilder");
    rbField.setAccessible(true);
    rbField.set(cmd, responseBuilder);
    List<QuotaBalanceVO> quotaBalanceVOList = new ArrayList<QuotaBalanceVO>();
    Mockito.when(responseBuilder.getQuotaBalance(Mockito.any(cmd.getClass()))).thenReturn(quotaBalanceVOList);
    Mockito.when(responseBuilder.createQuotaLastBalanceResponse(Mockito.eq(quotaBalanceVOList), Mockito.any(Date.class))).thenReturn(new QuotaBalanceResponse());
    Mockito.when(responseBuilder.createQuotaBalanceResponse(Mockito.eq(quotaBalanceVOList), Mockito.any(Date.class), Mockito.any(Date.class))).thenReturn(new QuotaBalanceResponse());
    Mockito.when(responseBuilder.startOfNextDay(Mockito.any(Date.class))).thenReturn(new Date());
    // end date not specified
    cmd.setStartDate(new Date());
    cmd.setEndDate(null);
    cmd.execute();
    Mockito.verify(responseBuilder, Mockito.times(1)).createQuotaLastBalanceResponse(Mockito.eq(quotaBalanceVOList), Mockito.any(Date.class));
    Mockito.verify(responseBuilder, Mockito.times(0)).createQuotaBalanceResponse(Mockito.eq(quotaBalanceVOList), Mockito.any(Date.class), Mockito.any(Date.class));
    // end date specified
    cmd.setEndDate(new Date());
    cmd.execute();
    Mockito.verify(responseBuilder, Mockito.times(1)).createQuotaBalanceResponse(Mockito.eq(quotaBalanceVOList), Mockito.any(Date.class), Mockito.any(Date.class));
}
Also used : Field(java.lang.reflect.Field) QuotaBalanceResponse(org.apache.cloudstack.api.response.QuotaBalanceResponse) ArrayList(java.util.ArrayList) QuotaBalanceVO(org.apache.cloudstack.quota.vo.QuotaBalanceVO) Date(java.util.Date) Test(org.junit.Test)

Example 2 with QuotaBalanceResponse

use of org.apache.cloudstack.api.response.QuotaBalanceResponse in project cloudstack by apache.

the class QuotaBalanceCmd method execute.

@Override
public void execute() {
    List<QuotaBalanceVO> quotaUsage = _responseBuilder.getQuotaBalance(this);
    QuotaBalanceResponse response;
    if (endDate == null) {
        response = _responseBuilder.createQuotaLastBalanceResponse(quotaUsage, getStartDate());
    } else {
        response = _responseBuilder.createQuotaBalanceResponse(quotaUsage, getStartDate(), new Date(endDate.getTime()));
    }
    response.setResponseName(getCommandName());
    setResponseObject(response);
}
Also used : QuotaBalanceResponse(org.apache.cloudstack.api.response.QuotaBalanceResponse) QuotaBalanceVO(org.apache.cloudstack.quota.vo.QuotaBalanceVO) Date(java.util.Date)

Aggregations

Date (java.util.Date)2 QuotaBalanceResponse (org.apache.cloudstack.api.response.QuotaBalanceResponse)2 QuotaBalanceVO (org.apache.cloudstack.quota.vo.QuotaBalanceVO)2 Field (java.lang.reflect.Field)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1