Search in sources :

Example 16 with QuotaTariffVO

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));
}
Also used : Field(java.lang.reflect.Field) ServerApiException(org.apache.cloudstack.api.ServerApiException) QuotaTariffVO(org.apache.cloudstack.quota.vo.QuotaTariffVO) QuotaTariffResponse(org.apache.cloudstack.api.response.QuotaTariffResponse) Date(java.util.Date) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 17 with QuotaTariffVO

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;
}
Also used : QuotaTariffVO(org.apache.cloudstack.quota.vo.QuotaTariffVO) Date(java.util.Date) LocalDate(java.time.LocalDate)

Example 18 with QuotaTariffVO

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;
}
Also used : QuotaTariffVO(org.apache.cloudstack.quota.vo.QuotaTariffVO) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Date(java.util.Date) LocalDate(java.time.LocalDate)

Aggregations

QuotaTariffVO (org.apache.cloudstack.quota.vo.QuotaTariffVO)18 BigDecimal (java.math.BigDecimal)13 QuotaUsageVO (org.apache.cloudstack.quota.vo.QuotaUsageVO)10 Date (java.util.Date)6 ArrayList (java.util.ArrayList)5 QuotaTariffResponse (org.apache.cloudstack.api.response.QuotaTariffResponse)4 Test (org.junit.Test)4 LocalDate (java.time.LocalDate)3 Field (java.lang.reflect.Field)2 List (java.util.List)2 ServerApiException (org.apache.cloudstack.api.ServerApiException)2 ServiceOfferingVO (org.apache.cloudstack.quota.vo.ServiceOfferingVO)2 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)1 UsageVO (com.cloud.usage.UsageVO)1 ListResponse (org.apache.cloudstack.api.response.ListResponse)1 QuotaTypes (org.apache.cloudstack.quota.constant.QuotaTypes)1