use of org.apache.cloudstack.api.response.QuotaTariffResponse in project cloudstack by apache.
the class QuotaTariffListCmdTest method testQuotaTariffListCmd.
@Test
public void testQuotaTariffListCmd() throws NoSuchFieldException, IllegalAccessException {
QuotaTariffListCmd cmd = new QuotaTariffListCmd();
Field rbField = QuotaTariffListCmd.class.getDeclaredField("_responseBuilder");
rbField.setAccessible(true);
rbField.set(cmd, responseBuilder);
List<QuotaTariffVO> quotaTariffVOList = new ArrayList<QuotaTariffVO>();
QuotaTariffVO tariff = new QuotaTariffVO();
tariff.setEffectiveOn(new Date());
tariff.setCurrencyValue(new BigDecimal(100));
tariff.setUsageType(QuotaTypes.MEMORY);
quotaTariffVOList.add(new QuotaTariffVO());
Mockito.when(responseBuilder.listQuotaTariffPlans(Mockito.eq(cmd))).thenReturn(new Pair<>(quotaTariffVOList, quotaTariffVOList.size()));
Mockito.when(responseBuilder.createQuotaTariffResponse(Mockito.any(QuotaTariffVO.class))).thenReturn(new QuotaTariffResponse());
cmd.execute();
Mockito.verify(responseBuilder, Mockito.times(1)).createQuotaTariffResponse(Mockito.any(QuotaTariffVO.class));
}
use of org.apache.cloudstack.api.response.QuotaTariffResponse in project cloudstack by apache.
the class QuotaTariffListCmd method execute.
@Override
public void execute() {
final Pair<List<QuotaTariffVO>, Integer> result = _responseBuilder.listQuotaTariffPlans(this);
final List<QuotaTariffResponse> responses = new ArrayList<QuotaTariffResponse>();
for (final QuotaTariffVO resource : result.first()) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Result desc=" + resource.getDescription() + " date=" + resource.getEffectiveOn() + " val=" + resource.getCurrencyValue());
}
responses.add(_responseBuilder.createQuotaTariffResponse(resource));
}
final ListResponse<QuotaTariffResponse> response = new ListResponse<QuotaTariffResponse>();
response.setResponses(responses, result.second());
response.setResponseName(getCommandName());
setResponseObject(response);
}
use of org.apache.cloudstack.api.response.QuotaTariffResponse in project cloudstack by apache.
the class QuotaTariffUpdateCmd method execute.
@Override
public void execute() {
final QuotaTariffVO result = _responseBuilder.updateQuotaTariffPlan(this);
if (result == null) {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update quota tariff plan");
}
final QuotaTariffResponse response = _responseBuilder.createQuotaTariffResponse(result);
response.setResponseName(getCommandName());
setResponseObject(response);
}
use of org.apache.cloudstack.api.response.QuotaTariffResponse in project cloudstack by apache.
the class QuotaTariffUpdateCmdTest method testQuotaTariffUpdateCmd.
@Test
public void testQuotaTariffUpdateCmd() throws NoSuchFieldException, IllegalAccessException {
QuotaTariffUpdateCmd cmd = new QuotaTariffUpdateCmd();
Field rbField = QuotaTariffUpdateCmd.class.getDeclaredField("_responseBuilder");
rbField.setAccessible(true);
rbField.set(cmd, responseBuilder);
QuotaTariffVO tariff = new QuotaTariffVO();
tariff.setEffectiveOn(new Date());
tariff.setCurrencyValue(new BigDecimal(100));
tariff.setUsageType(QuotaTypes.MEMORY);
Mockito.when(responseBuilder.updateQuotaTariffPlan(Mockito.eq(cmd))).thenReturn(null);
try {
cmd.execute();
} catch (ServerApiException e) {
assertTrue(e.getErrorCode().equals(ApiErrorCode.INTERNAL_ERROR));
}
Mockito.when(responseBuilder.updateQuotaTariffPlan(Mockito.eq(cmd))).thenReturn(tariff);
Mockito.when(responseBuilder.createQuotaTariffResponse(Mockito.eq(tariff))).thenReturn(new QuotaTariffResponse());
cmd.execute();
Mockito.verify(responseBuilder, Mockito.times(1)).createQuotaTariffResponse(Mockito.eq(tariff));
}
Aggregations