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));
}
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);
}
Aggregations