cloudstack-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bhaisaab <...@git.apache.org>
Subject [GitHub] cloudstack pull request: Quota
Date Sat, 10 Oct 2015 18:54:08 GMT
Github user bhaisaab commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/768#discussion_r41700263
  
    --- Diff: usage/test/org/apache/cloudstack/quota/QuotaManagerImplTest.java ---
    @@ -0,0 +1,203 @@
    +// Licensed to the Apache Software Foundation (ASF) under one
    +// or more contributor license agreements.  See the NOTICE file
    +// distributed with this work for additional information
    +// regarding copyright ownership.  The ASF licenses this file
    +// to you under the Apache License, Version 2.0 (the
    +// "License"); you may not use this file except in compliance
    +// with the License.  You may obtain a copy of the License at
    +//
    +//   http://www.apache.org/licenses/LICENSE-2.0
    +//
    +// Unless required by applicable law or agreed to in writing,
    +// software distributed under the License is distributed on an
    +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    +// KIND, either express or implied.  See the License for the
    +// specific language governing permissions and limitations
    +// under the License.
    +package org.apache.cloudstack.quota;
    +
    +import com.cloud.usage.UsageVO;
    +import com.cloud.usage.dao.UsageDao;
    +import com.cloud.user.Account;
    +import com.cloud.user.AccountVO;
    +import com.cloud.user.dao.AccountDao;
    +import com.cloud.utils.Pair;
    +import com.cloud.utils.db.TransactionLegacy;
    +import junit.framework.TestCase;
    +import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
    +import org.apache.cloudstack.quota.dao.QuotaAccountDao;
    +import org.apache.cloudstack.quota.dao.QuotaBalanceDao;
    +import org.apache.cloudstack.quota.dao.QuotaTariffDao;
    +import org.apache.cloudstack.quota.dao.QuotaUsageDao;
    +import org.apache.cloudstack.quota.dao.ServiceOfferingDao;
    +import org.apache.cloudstack.quota.vo.QuotaAccountVO;
    +import org.apache.cloudstack.quota.vo.QuotaTariffVO;
    +import org.apache.cloudstack.quota.vo.QuotaUsageVO;
    +import org.apache.cloudstack.usage.UsageTypes;
    +import org.junit.Before;
    +import org.junit.Test;
    +import org.junit.runner.RunWith;
    +import org.mockito.Mock;
    +import org.mockito.Mockito;
    +import org.mockito.Spy;
    +import org.mockito.runners.MockitoJUnitRunner;
    +
    +import javax.naming.ConfigurationException;
    +import java.lang.reflect.Field;
    +import java.math.BigDecimal;
    +import java.util.ArrayList;
    +import java.util.Date;
    +import java.util.HashMap;
    +import java.util.List;
    +import java.util.Map;
    +
    +@RunWith(MockitoJUnitRunner.class)
    +public class QuotaManagerImplTest extends TestCase {
    +
    +    @Mock
    +    private AccountDao accountDao;
    +    @Mock
    +    private QuotaAccountDao quotaAcc;
    +    @Mock
    +    private UsageDao usageDao;
    +    @Mock
    +    private QuotaTariffDao quotaTariffDao;
    +    @Mock
    +    private QuotaUsageDao quotaUsageDao;
    +    @Mock
    +    private ServiceOfferingDao serviceOfferingDao;
    +    @Mock
    +    private QuotaBalanceDao quotaBalanceDao;
    +    @Mock
    +    private ConfigurationDao configDao;
    +
    +    @Spy
    +    QuotaManagerImpl quotaManager = new QuotaManagerImpl();
    +
    +    private void injectMockToField(Object mock, String fieldName) throws NoSuchFieldException,
IllegalAccessException {
    +        Field f = QuotaManagerImpl.class.getDeclaredField(fieldName);
    +        f.setAccessible(true);
    +        f.set(quotaManager, mock);
    +    }
    +
    +    @Before
    +    public void setup() throws IllegalAccessException, NoSuchFieldException, ConfigurationException
{
    +        // Dummy transaction stack setup
    +        TransactionLegacy.open("QuotaManagerImplTest");
    +
    +        injectMockToField(accountDao, "_accountDao");
    +        injectMockToField(quotaAcc, "_quotaAcc");
    +        injectMockToField(usageDao, "_usageDao");
    +        injectMockToField(quotaTariffDao, "_quotaTariffDao");
    +        injectMockToField(quotaUsageDao, "_quotaUsageDao");
    +        injectMockToField(serviceOfferingDao, "_serviceOfferingDao");
    +        injectMockToField(quotaBalanceDao, "_quotaBalanceDao");
    +        injectMockToField(configDao, "_configDao");
    +    }
    +
    +    @Test
    +    public void testStartStop() {
    +        try {
    +            quotaManager.start(); // expected to fail as pid is not available
    --- End diff --
    
    Exception throw by start()


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message