Search in sources :

Example 1 with QuotaTariffResponse

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

Example 2 with QuotaTariffResponse

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);
}
Also used : ListResponse(org.apache.cloudstack.api.response.ListResponse) QuotaTariffVO(org.apache.cloudstack.quota.vo.QuotaTariffVO) QuotaTariffResponse(org.apache.cloudstack.api.response.QuotaTariffResponse) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 3 with QuotaTariffResponse

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);
}
Also used : ServerApiException(org.apache.cloudstack.api.ServerApiException) QuotaTariffVO(org.apache.cloudstack.quota.vo.QuotaTariffVO) QuotaTariffResponse(org.apache.cloudstack.api.response.QuotaTariffResponse)

Example 4 with QuotaTariffResponse

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

Aggregations

QuotaTariffResponse (org.apache.cloudstack.api.response.QuotaTariffResponse)4 QuotaTariffVO (org.apache.cloudstack.quota.vo.QuotaTariffVO)4 Field (java.lang.reflect.Field)2 BigDecimal (java.math.BigDecimal)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 ServerApiException (org.apache.cloudstack.api.ServerApiException)2 Test (org.junit.Test)2 List (java.util.List)1 ListResponse (org.apache.cloudstack.api.response.ListResponse)1