Return-Path: X-Original-To: apmail-cloudstack-commits-archive@www.apache.org Delivered-To: apmail-cloudstack-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 06FC110706 for ; Mon, 6 May 2013 23:35:01 +0000 (UTC) Received: (qmail 29854 invoked by uid 500); 6 May 2013 23:34:45 -0000 Delivered-To: apmail-cloudstack-commits-archive@cloudstack.apache.org Received: (qmail 29804 invoked by uid 500); 6 May 2013 23:34:45 -0000 Mailing-List: contact commits-help@cloudstack.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cloudstack.apache.org Delivered-To: mailing list commits@cloudstack.apache.org Received: (qmail 28815 invoked by uid 99); 6 May 2013 23:34:44 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 06 May 2013 23:34:43 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id C4DCE888058; Mon, 6 May 2013 23:34:43 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: ahuang@apache.org To: commits@cloudstack.apache.org Date: Mon, 06 May 2013 23:35:32 -0000 Message-Id: <8b4a822d9a414bd88ee1d2b839750564@git.apache.org> In-Reply-To: <6e057524610d405099989be2bef2d4fc@git.apache.org> References: <6e057524610d405099989be2bef2d4fc@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [52/56] [abbrv] Fixed up unit testing to use only an in class TestConfiguration http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3722d66a/server/test/com/cloud/vpc/VpcTestConfiguration.java ---------------------------------------------------------------------- diff --git a/server/test/com/cloud/vpc/VpcTestConfiguration.java b/server/test/com/cloud/vpc/VpcTestConfiguration.java index b1f2f80..7ae83f3 100644 --- a/server/test/com/cloud/vpc/VpcTestConfiguration.java +++ b/server/test/com/cloud/vpc/VpcTestConfiguration.java @@ -19,6 +19,7 @@ package com.cloud.vpc; import java.io.IOException; +import org.apache.cloudstack.test.utils.SpringUtils; import org.mockito.Mockito; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; @@ -91,7 +92,6 @@ import com.cloud.tags.dao.ResourceTagsDaoImpl; import com.cloud.user.AccountManager; import com.cloud.user.dao.AccountDaoImpl; import com.cloud.user.dao.UserStatisticsDaoImpl; -import com.cloud.utils.component.SpringComponentScanUtils; import com.cloud.vm.UserVmManager; import com.cloud.vm.dao.DomainRouterDaoImpl; import com.cloud.vm.dao.NicDaoImpl; @@ -236,7 +236,7 @@ public class VpcTestConfiguration { public boolean match(MetadataReader mdr, MetadataReaderFactory arg1) throws IOException { mdr.getClassMetadata().getClassName(); ComponentScan cs = VpcTestConfiguration.class.getAnnotation(ComponentScan.class); - return SpringComponentScanUtils.includedInBasePackageClasses(mdr.getClassMetadata().getClassName(), cs); + return SpringUtils.includedInBasePackageClasses(mdr.getClassMetadata().getClassName(), cs); } } } http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3722d66a/server/test/org/apache/cloudstack/affinity/AffinityApiUnitTest.java ---------------------------------------------------------------------- diff --git a/server/test/org/apache/cloudstack/affinity/AffinityApiUnitTest.java b/server/test/org/apache/cloudstack/affinity/AffinityApiUnitTest.java index f9c5728..484b044 100644 --- a/server/test/org/apache/cloudstack/affinity/AffinityApiUnitTest.java +++ b/server/test/org/apache/cloudstack/affinity/AffinityApiUnitTest.java @@ -24,6 +24,7 @@ import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.when; +import java.io.IOException; import java.util.ArrayList; import java.util.List; @@ -32,13 +33,23 @@ import javax.naming.ConfigurationException; import org.apache.cloudstack.affinity.dao.AffinityGroupDao; import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao; +import org.apache.cloudstack.test.utils.SpringUtils; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mockito; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.ComponentScan.Filter; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.FilterType; +import org.springframework.core.type.classreading.MetadataReader; +import org.springframework.core.type.classreading.MetadataReaderFactory; +import org.springframework.core.type.filter.TypeFilter; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.support.AnnotationConfigContextLoader; import com.cloud.event.EventUtils; import com.cloud.event.EventVO; @@ -48,6 +59,7 @@ import com.cloud.exception.ResourceInUseException; import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.user.Account; import com.cloud.user.AccountManager; +import com.cloud.user.AccountService; import com.cloud.user.AccountVO; import com.cloud.user.UserContext; import com.cloud.user.dao.AccountDao; @@ -57,7 +69,7 @@ import com.cloud.vm.VirtualMachine; import com.cloud.vm.dao.UserVmDao; @RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations = "classpath:/affinityContext.xml") +@ContextConfiguration(loader = AnnotationConfigContextLoader.class) public class AffinityApiUnitTest { @Inject @@ -188,4 +200,57 @@ public class AffinityApiUnitTest { _affinityService.updateVMAffinityGroups(10L, affinityGroupIds); } + @Configuration + @ComponentScan(basePackageClasses = {AffinityGroupServiceImpl.class, EventUtils.class}, includeFilters = {@Filter(value = TestConfiguration.Library.class, type = FilterType.CUSTOM)}, useDefaultFilters = false) + public static class TestConfiguration extends SpringUtils.CloudStackTestConfiguration { + + @Bean + public AccountDao accountDao() { + return Mockito.mock(AccountDao.class); + } + + @Bean + public AccountService accountService() { + return Mockito.mock(AccountService.class); + } + + @Bean + public AffinityGroupProcessor affinityGroupProcessor() { + return Mockito.mock(AffinityGroupProcessor.class); + } + + @Bean + public AffinityGroupDao affinityGroupDao() { + return Mockito.mock(AffinityGroupDao.class); + } + + @Bean + public AffinityGroupVMMapDao affinityGroupVMMapDao() { + return Mockito.mock(AffinityGroupVMMapDao.class); + } + + @Bean + public AccountManager accountManager() { + return Mockito.mock(AccountManager.class); + } + + @Bean + public EventDao eventDao() { + return Mockito.mock(EventDao.class); + } + + @Bean + public UserVmDao userVMDao() { + return Mockito.mock(UserVmDao.class); + } + + public static class Library implements TypeFilter { + + @Override + public boolean match(MetadataReader mdr, MetadataReaderFactory arg1) throws IOException { + ComponentScan cs = TestConfiguration.class.getAnnotation(ComponentScan.class); + return SpringUtils.includedInBasePackageClasses(mdr.getClassMetadata().getClassName(), cs); + } + } + } } http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3722d66a/server/test/org/apache/cloudstack/networkoffering/ChildTestConfiguration.java ---------------------------------------------------------------------- diff --git a/server/test/org/apache/cloudstack/networkoffering/ChildTestConfiguration.java b/server/test/org/apache/cloudstack/networkoffering/ChildTestConfiguration.java index d47deaa..6f52397 100644 --- a/server/test/org/apache/cloudstack/networkoffering/ChildTestConfiguration.java +++ b/server/test/org/apache/cloudstack/networkoffering/ChildTestConfiguration.java @@ -27,6 +27,7 @@ import org.apache.cloudstack.acl.SecurityChecker; import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDaoImpl; import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailsDao; +import org.apache.cloudstack.test.utils.SpringUtils; import org.mockito.Mockito; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; @@ -94,7 +95,6 @@ import com.cloud.storage.swift.SwiftManager; import com.cloud.tags.dao.ResourceTagsDaoImpl; import com.cloud.user.dao.AccountDaoImpl; import com.cloud.user.dao.UserDaoImpl; -import com.cloud.utils.component.SpringComponentScanUtils; import com.cloud.vm.dao.InstanceGroupDaoImpl; import com.cloud.vm.dao.NicDaoImpl; import com.cloud.vm.dao.NicSecondaryIpDaoImpl; @@ -338,7 +338,7 @@ public class ChildTestConfiguration { public boolean match(MetadataReader mdr, MetadataReaderFactory arg1) throws IOException { mdr.getClassMetadata().getClassName(); ComponentScan cs = ChildTestConfiguration.class.getAnnotation(ComponentScan.class); - return SpringComponentScanUtils.includedInBasePackageClasses(mdr.getClassMetadata().getClassName(), cs); + return SpringUtils.includedInBasePackageClasses(mdr.getClassMetadata().getClassName(), cs); } } http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3722d66a/server/test/resources/affinityContext.xml ---------------------------------------------------------------------- diff --git a/server/test/resources/affinityContext.xml b/server/test/resources/affinityContext.xml deleted file mode 100644 index d41a63d..0000000 --- a/server/test/resources/affinityContext.xml +++ /dev/null @@ -1,42 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3722d66a/services/console-proxy/pom.xml ---------------------------------------------------------------------- diff --git a/services/console-proxy/pom.xml b/services/console-proxy/pom.xml index 2c9e2e6..3aac7b2 100644 --- a/services/console-proxy/pom.xml +++ b/services/console-proxy/pom.xml @@ -23,9 +23,9 @@ pom org.apache.cloudstack - cloudstack + cloudstack-services 4.2.0-SNAPSHOT - ../../pom.xml + ../pom.xml install http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3722d66a/services/secondary-storage/pom.xml ---------------------------------------------------------------------- diff --git a/services/secondary-storage/pom.xml b/services/secondary-storage/pom.xml index 0797c98..eb6c0ee 100644 --- a/services/secondary-storage/pom.xml +++ b/services/secondary-storage/pom.xml @@ -18,13 +18,13 @@ --> 4.0.0 - cloudstack-service-secondary-storage + cloud-secondary-storage Apache CloudStack Secondary Storage Service org.apache.cloudstack - cloudstack + cloudstack-services 4.2.0-SNAPSHOT - ../../pom.xml + ../pom.xml http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3722d66a/tools/marvin/pom.xml ---------------------------------------------------------------------- diff --git a/tools/marvin/pom.xml b/tools/marvin/pom.xml index c050566..25134a8 100644 --- a/tools/marvin/pom.xml +++ b/tools/marvin/pom.xml @@ -1,15 +1,14 @@ + 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. --> + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 cloud-marvin Apache CloudStack marvin @@ -35,7 +34,7 @@ - + Deleting ${project.artifactId} API sources @@ -83,7 +82,7 @@ - + marvin.sync @@ -161,6 +160,26 @@ + org.codehaus.gmaven + gmaven-plugin + 1.5 + + + setproperty + validate + + execute + + + + pom.properties['resolved.basedir']=project.basedir.absolutePath.replace('\','/').replace('D:','/cyg/d'); + pom.properties['resolved.userdir']='${user.dir}'.replace('\','/').replace('D:','/cyg/d'); + + + + + + org.codehaus.mojo exec-maven-plugin 1.2.1 @@ -177,18 +196,18 @@ deployAndRun.py -c - ${user.dir}/${marvin.config} + ${resolved.userdir}/${marvin.config} -t /tmp/t.log -r /tmp/r.log -f - ${basedir}/marvin/testSetupSuccess.py + ${resolved.basedir}/marvin/testSetupSuccess.py - - + + http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3722d66a/usage/test/com/cloud/usage/UsageManagerTestConfiguration.java ---------------------------------------------------------------------- diff --git a/usage/test/com/cloud/usage/UsageManagerTestConfiguration.java b/usage/test/com/cloud/usage/UsageManagerTestConfiguration.java index d7cf046..1d3ed7b 100644 --- a/usage/test/com/cloud/usage/UsageManagerTestConfiguration.java +++ b/usage/test/com/cloud/usage/UsageManagerTestConfiguration.java @@ -25,7 +25,8 @@ import com.cloud.usage.dao.*; import com.cloud.usage.parser.*; import com.cloud.user.dao.AccountDaoImpl; import com.cloud.user.dao.UserStatisticsDaoImpl; -import com.cloud.utils.component.SpringComponentScanUtils; + +import org.apache.cloudstack.test.utils.SpringUtils; import org.mockito.Mockito; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; @@ -87,7 +88,7 @@ public class UsageManagerTestConfiguration { public boolean match(MetadataReader mdr, MetadataReaderFactory arg1) throws IOException { mdr.getClassMetadata().getClassName(); ComponentScan cs = UsageManagerTestConfiguration.class.getAnnotation(ComponentScan.class); - return SpringComponentScanUtils.includedInBasePackageClasses(mdr.getClassMetadata().getClassName(), cs); + return SpringUtils.includedInBasePackageClasses(mdr.getClassMetadata().getClassName(), cs); } } http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3722d66a/utils/src/com/cloud/utils/AnnotationHelper.java ---------------------------------------------------------------------- diff --git a/utils/src/com/cloud/utils/AnnotationHelper.java b/utils/src/com/cloud/utils/AnnotationHelper.java index 954b870..e7a6166 100755 --- a/utils/src/com/cloud/utils/AnnotationHelper.java +++ b/utils/src/com/cloud/utils/AnnotationHelper.java @@ -20,40 +20,38 @@ import javax.persistence.Table; import org.apache.log4j.Logger; -import com.cloud.utils.exception.CSExceptionErrorCode; - public class AnnotationHelper extends Object { // This class contains routines to help query annotation elements of objects. - + public static final Logger s_logger = Logger.getLogger(AnnotationHelper.class.getName()); - + public static String getTableName(Object proxyObj) { // The cglib class is generated by cglib during runtime. - + Class curClass = proxyObj.getClass(); if (curClass == null) { - s_logger.info("\nCould not retrieve class information for proxy object\n"); + s_logger.trace("Could not retrieve class information for proxy object"); return null; } - + while (curClass.getSuperclass() != null && curClass.getSuperclass().getName() != "java.lang.Object") { curClass = curClass.getSuperclass(); } // At this point, curClass is the root base class of proxyObj's class, and curClass is not java.lang.Object. - Table tabObj = (Table)curClass.getAnnotation(Table.class); + Table tabObj = curClass.getAnnotation(Table.class); if (tabObj == null) { - s_logger.info("\n" + curClass + "does not have a Table annotation\n"); + s_logger.trace(curClass + "does not have a Table annotation"); return null; } - + return tabObj.name(); } - + } - - - - + + + + http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3722d66a/utils/src/com/cloud/utils/component/SpringComponentScanUtils.java ---------------------------------------------------------------------- diff --git a/utils/src/com/cloud/utils/component/SpringComponentScanUtils.java b/utils/src/com/cloud/utils/component/SpringComponentScanUtils.java deleted file mode 100644 index 28b84e6..0000000 --- a/utils/src/com/cloud/utils/component/SpringComponentScanUtils.java +++ /dev/null @@ -1,41 +0,0 @@ -// 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 -// 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 com.cloud.utils.component; - -import org.springframework.context.annotation.ComponentScan; - -import com.cloud.utils.exception.CloudRuntimeException; - -public class SpringComponentScanUtils { - - public static boolean includedInBasePackageClasses(String clazzName, ComponentScan cs) { - Class clazzToCheck; - try { - clazzToCheck = Class.forName(clazzName); - } catch (ClassNotFoundException e) { - throw new CloudRuntimeException("Unable to find " + clazzName); - } - Class[] clazzes = cs.basePackageClasses(); - for (Class clazz : clazzes) { - if (clazzToCheck.isAssignableFrom(clazz)) { - return true; - } - } - return false; - } -} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3722d66a/utils/src/org/apache/cloudstack/test/utils/SpringUtils.java ---------------------------------------------------------------------- diff --git a/utils/src/org/apache/cloudstack/test/utils/SpringUtils.java b/utils/src/org/apache/cloudstack/test/utils/SpringUtils.java new file mode 100644 index 0000000..220bd80 --- /dev/null +++ b/utils/src/org/apache/cloudstack/test/utils/SpringUtils.java @@ -0,0 +1,113 @@ +// 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 +// 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.test.utils; + +import java.util.ArrayList; +import java.util.List; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; + +import com.cloud.utils.component.ComponentContext; +import com.cloud.utils.component.ComponentInstantiationPostProcessor; +import com.cloud.utils.component.ComponentMethodInterceptor; +import com.cloud.utils.db.TransactionContextBuilder; +import com.cloud.utils.exception.CloudRuntimeException; + +public class SpringUtils { + + /** + * This method allows you to use @ComponentScan for your unit testing but + * it limits the scope of the classes found to the class specified in + * the @ComponentScan annotation. + * + * Without using this method, the default behavior of @ComponentScan is + * to actually scan in the package of the class specified rather than + * only the class. This can cause extra classes to be loaded which causes + * the classes these extra classes depend on to be loaded. The end effect + * is often most of the project gets loaded. + * + * In order to use this method properly, you must do the following:
  • + * - Specify @ComponentScan with basePackageClasses, includeFilters, and + * useDefaultFilters=true. See the following example. + * + *
    +     *     @ComponentScan(basePackageClasses={AffinityGroupServiceImpl.class, EventUtils.class},
    +     *     includeFilters={@Filter(value=TestConfiguration.Library.class, type=FilterType.CUSTOM)},
    +     *     useDefaultFilters=false)
    +     * 
    + * + * - Create a Library class and use that to call this method. See the + * following example. The Library class you define here is the Library + * class being added in the filter above. + * + *
    +     * public static class Library implements TypeFilter {
    +     *      @Override
    +     *      public boolean match(MetadataReader mdr, MetadataReaderFactory arg1) throws IOException {
    +     *          ComponentScan cs = TestConfiguration.class.getAnnotation(ComponentScan.class);
    +     *          return SpringUtils.includedInBasePackageClasses(mdr.getClassMetadata().getClassName(), cs);
    +     *      }
    +     * }
    +     * 
    + * + * @param clazzName name of the class that should be included in the Spring components + * @param cs ComponentScan annotation that was declared on the configuration + * + * @return + */ + public static boolean includedInBasePackageClasses(String clazzName, ComponentScan cs) { + Class clazzToCheck; + try { + clazzToCheck = Class.forName(clazzName); + } catch (ClassNotFoundException e) { + throw new CloudRuntimeException("Unable to find " + clazzName); + } + Class[] clazzes = cs.basePackageClasses(); + for (Class clazz : clazzes) { + if (clazzToCheck.isAssignableFrom(clazz)) { + return true; + } + } + return false; + } + + public static class CloudStackTestConfiguration { + + @Bean + public ComponentContext componentContext() { + return new ComponentContext(); + } + + @Bean + public TransactionContextBuilder transactionContextBuilder() { + return new TransactionContextBuilder(); + } + + @Bean + public ComponentInstantiationPostProcessor instantiatePostProcessor() { + ComponentInstantiationPostProcessor processor = new ComponentInstantiationPostProcessor(); + + List interceptors = new ArrayList(); + interceptors.add(new TransactionContextBuilder()); + processor.setInterceptors(interceptors); + + return processor; + } + } +}