Search in sources :

Example 31 with UsageVO

use of com.cloud.usage.UsageVO in project cloudstack by apache.

the class QuotaManagerImplTest method testAggregatePendingQuotaRecordsForAccount.

@Test
public void testAggregatePendingQuotaRecordsForAccount() {
    AccountVO accountVO = new AccountVO();
    accountVO.setId(2L);
    accountVO.setDomainId(1L);
    accountVO.setType(Account.ACCOUNT_TYPE_NORMAL);
    UsageVO usageVO = new UsageVO();
    usageVO.setQuotaCalculated(0);
    usageVO.setUsageType(UsageTypes.ALLOCATED_VM);
    List<UsageVO> usageVOList = new ArrayList<UsageVO>();
    usageVOList.add(usageVO);
    Pair<List<? extends UsageVO>, Integer> usageRecords = new Pair<List<? extends UsageVO>, Integer>(usageVOList, usageVOList.size());
    QuotaUsageVO quotaUsageVO = new QuotaUsageVO();
    quotaUsageVO.setAccountId(2L);
    Mockito.doReturn(quotaUsageVO).when(quotaManager).updateQuotaAllocatedVMUsage(Mockito.eq(usageVO));
    assertTrue(quotaManager.aggregatePendingQuotaRecordsForAccount(accountVO, new Pair<List<? extends UsageVO>, Integer>(null, 0)).size() == 0);
    assertTrue(quotaManager.aggregatePendingQuotaRecordsForAccount(accountVO, usageRecords).size() == 1);
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) QuotaUsageVO(org.apache.cloudstack.quota.vo.QuotaUsageVO) UsageVO(com.cloud.usage.UsageVO) QuotaAccountVO(org.apache.cloudstack.quota.vo.QuotaAccountVO) AccountVO(com.cloud.user.AccountVO) Pair(com.cloud.utils.Pair) QuotaUsageVO(org.apache.cloudstack.quota.vo.QuotaUsageVO) Test(org.junit.Test)

Aggregations

UsageVO (com.cloud.usage.UsageVO)31 DecimalFormat (java.text.DecimalFormat)21 ArrayList (java.util.ArrayList)6 Date (java.util.Date)6 QuotaUsageVO (org.apache.cloudstack.quota.vo.QuotaUsageVO)5 AccountVO (com.cloud.user.AccountVO)4 Test (org.junit.Test)4 HashMap (java.util.HashMap)3 List (java.util.List)3 QuotaAccountVO (org.apache.cloudstack.quota.vo.QuotaAccountVO)3 UsageNetworkVO (com.cloud.usage.UsageNetworkVO)2 Pair (com.cloud.utils.Pair)2 DomainVO (com.cloud.domain.DomainVO)1 UsageBackupVO (com.cloud.usage.UsageBackupVO)1 UsageVmDiskVO (com.cloud.usage.UsageVmDiskVO)1 TransactionLegacy (com.cloud.utils.db.TransactionLegacy)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 BigDecimal (java.math.BigDecimal)1 PreparedStatement (java.sql.PreparedStatement)1 UsageRecordResponse (org.apache.cloudstack.api.response.UsageRecordResponse)1