use of org.apache.cloudstack.quota.vo.QuotaTariffVO 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));
}
use of org.apache.cloudstack.quota.vo.QuotaTariffVO in project cloudstack by apache.
the class QuotaResponseBuilderImplTest method makeTariffTestData.
private QuotaTariffVO makeTariffTestData() {
QuotaTariffVO tariffVO = new QuotaTariffVO();
tariffVO.setUsageType(QuotaTypes.IP_ADDRESS);
tariffVO.setUsageName("ip address");
tariffVO.setUsageUnit("IP-Month");
tariffVO.setCurrencyValue(BigDecimal.valueOf(100.19));
tariffVO.setEffectiveOn(new Date());
tariffVO.setUsageDiscriminator("");
return tariffVO;
}
use of org.apache.cloudstack.quota.vo.QuotaTariffVO in project cloudstack by apache.
the class QuotaResponseBuilderImpl method listQuotaTariffPlans.
@Override
public Pair<List<QuotaTariffVO>, Integer> listQuotaTariffPlans(final QuotaTariffListCmd cmd) {
Pair<List<QuotaTariffVO>, Integer> result;
Date effectiveDate = cmd.getEffectiveDate() == null ? new Date() : cmd.getEffectiveDate();
Date adjustedEffectiveDate = _quotaService.computeAdjustedTime(effectiveDate);
if (s_logger.isDebugEnabled()) {
s_logger.debug("Effective datec=" + effectiveDate + " quotatype=" + cmd.getUsageType() + " Adjusted date=" + adjustedEffectiveDate);
}
if (cmd.getUsageType() != null) {
QuotaTariffVO tariffPlan = _quotaTariffDao.findTariffPlanByUsageType(cmd.getUsageType(), adjustedEffectiveDate);
if (tariffPlan != null) {
List<QuotaTariffVO> list = new ArrayList<>();
list.add(tariffPlan);
result = new Pair<>(list, list.size());
} else {
result = new Pair<>(new ArrayList<>(), 0);
}
} else {
result = _quotaTariffDao.listAllTariffPlans(adjustedEffectiveDate, cmd.getStartIndex(), cmd.getPageSizeVal());
}
return result;
}
Aggregations