mirror of
https://github.com/apache/cloudstack.git
synced 2025-12-15 18:12:35 +01:00
Fixed up unit testing to use only an in class TestConfiguration
This commit is contained in:
parent
074df0b415
commit
3722d66aae
@ -30,11 +30,6 @@
|
|||||||
<artifactId>cloud-api</artifactId>
|
<artifactId>cloud-api</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.cloudstack</groupId>
|
|
||||||
<artifactId>cloud-framework-api</artifactId>
|
|
||||||
<version>${project.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.cxf</groupId>
|
<groupId>org.apache.cxf</groupId>
|
||||||
<artifactId>cxf-bundle-jaxrs</artifactId>
|
<artifactId>cxf-bundle-jaxrs</artifactId>
|
||||||
@ -55,6 +50,11 @@
|
|||||||
<artifactId>cloud-framework-rest</artifactId>
|
<artifactId>cloud-framework-rest</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.cloudstack</groupId>
|
||||||
|
<artifactId>cloud-framework-ipc</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<build>
|
<build>
|
||||||
<defaultGoal>install</defaultGoal>
|
<defaultGoal>install</defaultGoal>
|
||||||
|
|||||||
@ -50,11 +50,11 @@ public class StoragePoolHostVO implements StoragePoolHostAssoc {
|
|||||||
private String localPath;
|
private String localPath;
|
||||||
|
|
||||||
@Column(name=GenericDaoBase.CREATED_COLUMN)
|
@Column(name=GenericDaoBase.CREATED_COLUMN)
|
||||||
private final Date created = null;
|
private Date created = null;
|
||||||
|
|
||||||
@Column(name="last_updated")
|
@Column(name="last_updated")
|
||||||
@Temporal(value=TemporalType.TIMESTAMP)
|
@Temporal(value=TemporalType.TIMESTAMP)
|
||||||
private final Date lastUpdated = null;
|
private Date lastUpdated = null;
|
||||||
|
|
||||||
|
|
||||||
public StoragePoolHostVO() {
|
public StoragePoolHostVO() {
|
||||||
|
|||||||
@ -20,6 +20,7 @@ import java.io.IOException;
|
|||||||
|
|
||||||
import org.apache.cloudstack.storage.allocator.StorageAllocatorTestConfiguration.Library;
|
import org.apache.cloudstack.storage.allocator.StorageAllocatorTestConfiguration.Library;
|
||||||
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDaoImpl;
|
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDaoImpl;
|
||||||
|
import org.apache.cloudstack.test.utils.SpringUtils;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.ComponentScan;
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
@ -36,7 +37,6 @@ import com.cloud.host.dao.HostDaoImpl;
|
|||||||
import com.cloud.storage.StorageManager;
|
import com.cloud.storage.StorageManager;
|
||||||
import com.cloud.storage.dao.StoragePoolDetailsDaoImpl;
|
import com.cloud.storage.dao.StoragePoolDetailsDaoImpl;
|
||||||
import com.cloud.storage.dao.VMTemplateDaoImpl;
|
import com.cloud.storage.dao.VMTemplateDaoImpl;
|
||||||
import com.cloud.utils.component.SpringComponentScanUtils;
|
|
||||||
import com.cloud.vm.UserVmManager;
|
import com.cloud.vm.UserVmManager;
|
||||||
|
|
||||||
|
|
||||||
@ -67,7 +67,7 @@ public class StorageAllocatorTestConfiguration {
|
|||||||
public boolean match(MetadataReader mdr, MetadataReaderFactory arg1) throws IOException {
|
public boolean match(MetadataReader mdr, MetadataReaderFactory arg1) throws IOException {
|
||||||
mdr.getClassMetadata().getClassName();
|
mdr.getClassMetadata().getClassName();
|
||||||
ComponentScan cs = StorageAllocatorTestConfiguration.class.getAnnotation(ComponentScan.class);
|
ComponentScan cs = StorageAllocatorTestConfiguration.class.getAnnotation(ComponentScan.class);
|
||||||
return SpringComponentScanUtils.includedInBasePackageClasses(mdr.getClassMetadata().getClassName(), cs);
|
return SpringUtils.includedInBasePackageClasses(mdr.getClassMetadata().getClassName(), cs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -24,6 +24,7 @@ import org.apache.cloudstack.framework.rpc.RpcProvider;
|
|||||||
import org.apache.cloudstack.storage.HostEndpointRpcServer;
|
import org.apache.cloudstack.storage.HostEndpointRpcServer;
|
||||||
import org.apache.cloudstack.storage.endpoint.EndPointSelector;
|
import org.apache.cloudstack.storage.endpoint.EndPointSelector;
|
||||||
import org.apache.cloudstack.storage.test.ChildTestConfiguration.Library;
|
import org.apache.cloudstack.storage.test.ChildTestConfiguration.Library;
|
||||||
|
import org.apache.cloudstack.test.utils.SpringUtils;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.ComponentScan;
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
@ -75,7 +76,6 @@ import com.cloud.storage.swift.SwiftManager;
|
|||||||
import com.cloud.tags.dao.ResourceTagsDaoImpl;
|
import com.cloud.tags.dao.ResourceTagsDaoImpl;
|
||||||
import com.cloud.template.TemplateManager;
|
import com.cloud.template.TemplateManager;
|
||||||
import com.cloud.user.dao.UserDaoImpl;
|
import com.cloud.user.dao.UserDaoImpl;
|
||||||
import com.cloud.utils.component.SpringComponentScanUtils;
|
|
||||||
import com.cloud.vm.VirtualMachineManager;
|
import com.cloud.vm.VirtualMachineManager;
|
||||||
import com.cloud.vm.dao.ConsoleProxyDaoImpl;
|
import com.cloud.vm.dao.ConsoleProxyDaoImpl;
|
||||||
import com.cloud.vm.dao.DomainRouterDao;
|
import com.cloud.vm.dao.DomainRouterDao;
|
||||||
@ -222,7 +222,7 @@ public class ChildTestConfiguration extends TestConfiguration {
|
|||||||
public boolean match(MetadataReader mdr, MetadataReaderFactory arg1) throws IOException {
|
public boolean match(MetadataReader mdr, MetadataReaderFactory arg1) throws IOException {
|
||||||
mdr.getClassMetadata().getClassName();
|
mdr.getClassMetadata().getClassName();
|
||||||
ComponentScan cs = ChildTestConfiguration.class.getAnnotation(ComponentScan.class);
|
ComponentScan cs = ChildTestConfiguration.class.getAnnotation(ComponentScan.class);
|
||||||
return SpringComponentScanUtils.includedInBasePackageClasses(mdr.getClassMetadata().getClassName(), cs);
|
return SpringUtils.includedInBasePackageClasses(mdr.getClassMetadata().getClassName(), cs);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,12 +16,74 @@
|
|||||||
// under the License.
|
// under the License.
|
||||||
package com.cloud.agent.manager;
|
package com.cloud.agent.manager;
|
||||||
|
|
||||||
import com.cloud.agent.api.*;
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.ejb.Local;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.naming.ConfigurationException;
|
||||||
|
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import com.cloud.agent.api.Answer;
|
||||||
|
import com.cloud.agent.api.AttachIsoCommand;
|
||||||
|
import com.cloud.agent.api.AttachVolumeCommand;
|
||||||
|
import com.cloud.agent.api.BackupSnapshotCommand;
|
||||||
|
import com.cloud.agent.api.BumpUpPriorityCommand;
|
||||||
|
import com.cloud.agent.api.CheckHealthCommand;
|
||||||
|
import com.cloud.agent.api.CheckNetworkCommand;
|
||||||
|
import com.cloud.agent.api.CheckRouterCommand;
|
||||||
|
import com.cloud.agent.api.CheckVirtualMachineCommand;
|
||||||
|
import com.cloud.agent.api.CleanupNetworkRulesCmd;
|
||||||
|
import com.cloud.agent.api.ClusterSyncCommand;
|
||||||
|
import com.cloud.agent.api.Command;
|
||||||
|
import com.cloud.agent.api.ComputeChecksumCommand;
|
||||||
|
import com.cloud.agent.api.CreatePrivateTemplateFromSnapshotCommand;
|
||||||
|
import com.cloud.agent.api.CreatePrivateTemplateFromVolumeCommand;
|
||||||
|
import com.cloud.agent.api.CreateStoragePoolCommand;
|
||||||
|
import com.cloud.agent.api.CreateVolumeFromSnapshotCommand;
|
||||||
|
import com.cloud.agent.api.DeleteSnapshotBackupCommand;
|
||||||
|
import com.cloud.agent.api.DeleteStoragePoolCommand;
|
||||||
|
import com.cloud.agent.api.GetDomRVersionCmd;
|
||||||
|
import com.cloud.agent.api.GetHostStatsCommand;
|
||||||
|
import com.cloud.agent.api.GetStorageStatsCommand;
|
||||||
|
import com.cloud.agent.api.GetVmStatsCommand;
|
||||||
|
import com.cloud.agent.api.GetVncPortCommand;
|
||||||
|
import com.cloud.agent.api.MaintainCommand;
|
||||||
|
import com.cloud.agent.api.ManageSnapshotCommand;
|
||||||
|
import com.cloud.agent.api.MigrateCommand;
|
||||||
|
import com.cloud.agent.api.ModifyStoragePoolCommand;
|
||||||
|
import com.cloud.agent.api.NetworkUsageCommand;
|
||||||
|
import com.cloud.agent.api.PingTestCommand;
|
||||||
|
import com.cloud.agent.api.PrepareForMigrationCommand;
|
||||||
|
import com.cloud.agent.api.RebootCommand;
|
||||||
|
import com.cloud.agent.api.SecStorageSetupCommand;
|
||||||
|
import com.cloud.agent.api.SecStorageVMSetupCommand;
|
||||||
|
import com.cloud.agent.api.SecurityGroupRulesCmd;
|
||||||
|
import com.cloud.agent.api.StartCommand;
|
||||||
|
import com.cloud.agent.api.StopCommand;
|
||||||
|
import com.cloud.agent.api.StoragePoolInfo;
|
||||||
import com.cloud.agent.api.check.CheckSshCommand;
|
import com.cloud.agent.api.check.CheckSshCommand;
|
||||||
import com.cloud.agent.api.proxy.CheckConsoleProxyLoadCommand;
|
import com.cloud.agent.api.proxy.CheckConsoleProxyLoadCommand;
|
||||||
import com.cloud.agent.api.proxy.WatchConsoleProxyLoadCommand;
|
import com.cloud.agent.api.proxy.WatchConsoleProxyLoadCommand;
|
||||||
import com.cloud.agent.api.routing.*;
|
import com.cloud.agent.api.routing.DhcpEntryCommand;
|
||||||
import com.cloud.agent.api.storage.*;
|
import com.cloud.agent.api.routing.IpAssocCommand;
|
||||||
|
import com.cloud.agent.api.routing.LoadBalancerConfigCommand;
|
||||||
|
import com.cloud.agent.api.routing.SavePasswordCommand;
|
||||||
|
import com.cloud.agent.api.routing.SetFirewallRulesCommand;
|
||||||
|
import com.cloud.agent.api.routing.SetPortForwardingRulesCommand;
|
||||||
|
import com.cloud.agent.api.routing.SetStaticNatRulesCommand;
|
||||||
|
import com.cloud.agent.api.routing.VmDataCommand;
|
||||||
|
import com.cloud.agent.api.storage.CopyVolumeCommand;
|
||||||
|
import com.cloud.agent.api.storage.CreateCommand;
|
||||||
|
import com.cloud.agent.api.storage.DeleteTemplateCommand;
|
||||||
|
import com.cloud.agent.api.storage.DestroyCommand;
|
||||||
|
import com.cloud.agent.api.storage.DownloadCommand;
|
||||||
|
import com.cloud.agent.api.storage.DownloadProgressCommand;
|
||||||
|
import com.cloud.agent.api.storage.ListTemplateCommand;
|
||||||
|
import com.cloud.agent.api.storage.ListVolumeCommand;
|
||||||
|
import com.cloud.agent.api.storage.PrimaryStorageDownloadCommand;
|
||||||
import com.cloud.simulator.MockConfigurationVO;
|
import com.cloud.simulator.MockConfigurationVO;
|
||||||
import com.cloud.simulator.MockHost;
|
import com.cloud.simulator.MockHost;
|
||||||
import com.cloud.simulator.MockVMVO;
|
import com.cloud.simulator.MockVMVO;
|
||||||
@ -34,14 +96,6 @@ import com.cloud.utils.db.DB;
|
|||||||
import com.cloud.utils.db.Transaction;
|
import com.cloud.utils.db.Transaction;
|
||||||
import com.cloud.utils.exception.CloudRuntimeException;
|
import com.cloud.utils.exception.CloudRuntimeException;
|
||||||
import com.cloud.vm.VirtualMachine.State;
|
import com.cloud.vm.VirtualMachine.State;
|
||||||
import org.apache.log4j.Logger;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
import javax.ejb.Local;
|
|
||||||
import javax.inject.Inject;
|
|
||||||
import javax.naming.ConfigurationException;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
@Local(value = { SimulatorManager.class })
|
@Local(value = { SimulatorManager.class })
|
||||||
@ -256,7 +310,7 @@ public class SimulatorManagerImpl extends ManagerBase implements SimulatorManage
|
|||||||
return Answer.createUnsupportedCommandAnswer(cmd);
|
return Answer.createUnsupportedCommandAnswer(cmd);
|
||||||
}
|
}
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
s_logger.error("Failed execute cmd: " + e.toString());
|
s_logger.error("Failed execute cmd: ", e);
|
||||||
txn.rollback();
|
txn.rollback();
|
||||||
return new Answer(cmd, false, e.toString());
|
return new Answer(cmd, false, e.toString());
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
62
pom.xml
62
pom.xml
@ -1,13 +1,12 @@
|
|||||||
<!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor
|
<!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor
|
||||||
license agreements. See the NOTICE file distributed with this work for additional
|
license agreements. See the NOTICE file distributed with this work for additional
|
||||||
information regarding copyright ownership. The ASF licenses this file to
|
information regarding copyright ownership. The ASF licenses this file to you under
|
||||||
you under the Apache License, Version 2.0 (the "License"); you may not use
|
the Apache License, Version 2.0 (the "License"); you may not use this file except
|
||||||
this file except in compliance with the License. You may obtain a copy of
|
in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||||
the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required
|
Unless required by applicable law or agreed to in writing, software distributed under
|
||||||
by applicable law or agreed to in writing, software distributed under the
|
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
|
||||||
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
|
||||||
OF ANY KIND, either express or implied. See the License for the specific
|
governing permissions and limitations under the License. -->
|
||||||
language governing permissions and limitations under the License. -->
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
@ -171,6 +170,7 @@
|
|||||||
<module>framework</module>
|
<module>framework</module>
|
||||||
<module>test</module>
|
<module>test</module>
|
||||||
<module>client</module>
|
<module>client</module>
|
||||||
|
<module>services</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
<dependencyManagement>
|
<dependencyManagement>
|
||||||
@ -206,22 +206,18 @@
|
|||||||
<version>${org.springframework.version}</version>
|
<version>${org.springframework.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- <dependency> <groupId>org.springframework</groupId> <artifactId>spring-expression</artifactId>
|
<!-- <dependency> <groupId>org.springframework</groupId> <artifactId>spring-expression</artifactId>
|
||||||
<version>${org.springframework.version}</version> </dependency> <dependency>
|
<version>${org.springframework.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId>
|
||||||
<groupId>org.springframework</groupId> <artifactId>spring-beans</artifactId>
|
<artifactId>spring-beans</artifactId> <version>${org.springframework.version}</version>
|
||||||
<version>${org.springframework.version}</version> </dependency> <dependency>
|
</dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-aop</artifactId>
|
||||||
<groupId>org.springframework</groupId> <artifactId>spring-aop</artifactId>
|
<version>${org.springframework.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId>
|
||||||
<version>${org.springframework.version}</version> </dependency> <dependency>
|
<artifactId>spring-context-support</artifactId> <version>${org.springframework.version}</version>
|
||||||
<groupId>org.springframework</groupId> <artifactId>spring-context-support</artifactId>
|
</dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-tx</artifactId>
|
||||||
<version>${org.springframework.version}</version> </dependency> <dependency>
|
<version>${org.springframework.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId>
|
||||||
<groupId>org.springframework</groupId> <artifactId>spring-tx</artifactId>
|
<artifactId>spring-jdbc</artifactId> <version>${org.springframework.version}</version>
|
||||||
<version>${org.springframework.version}</version> </dependency> <dependency>
|
</dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-orm</artifactId>
|
||||||
<groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId>
|
<version>${org.springframework.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId>
|
||||||
<version>${org.springframework.version}</version> </dependency> <dependency>
|
<artifactId>spring-oxm</artifactId> <version>${org.springframework.version}</version>
|
||||||
<groupId>org.springframework</groupId> <artifactId>spring-orm</artifactId>
|
</dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId>
|
||||||
<version>${org.springframework.version}</version> </dependency> <dependency>
|
|
||||||
<groupId>org.springframework</groupId> <artifactId>spring-oxm</artifactId>
|
|
||||||
<version>${org.springframework.version}</version> </dependency> <dependency>
|
|
||||||
<groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId>
|
|
||||||
<version>${org.springframework.version}</version> </dependency> -->
|
<version>${org.springframework.version}</version> </dependency> -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.mockito</groupId>
|
<groupId>org.mockito</groupId>
|
||||||
@ -265,6 +261,20 @@
|
|||||||
<testOutputDirectory>${basedir}/${cs.target.dir}/test-classes</testOutputDirectory>
|
<testOutputDirectory>${basedir}/${cs.target.dir}/test-classes</testOutputDirectory>
|
||||||
<pluginManagement>
|
<pluginManagement>
|
||||||
<plugins>
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-clean-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<excludeDefaultDirectories>true</excludeDefaultDirectories>
|
||||||
|
<filesets>
|
||||||
|
<fileset>
|
||||||
|
<directory>target</directory>
|
||||||
|
<includes>
|
||||||
|
<include>**/*</include>
|
||||||
|
</includes>
|
||||||
|
</fileset>
|
||||||
|
</filesets>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-release-plugin</artifactId>
|
<artifactId>maven-release-plugin</artifactId>
|
||||||
@ -504,7 +514,7 @@
|
|||||||
<cs.target.dir>target-eclipse</cs.target.dir>
|
<cs.target.dir>target-eclipse</cs.target.dir>
|
||||||
</properties>
|
</properties>
|
||||||
</profile>
|
</profile>
|
||||||
<profile>
|
<profile>
|
||||||
<id>developer</id>
|
<id>developer</id>
|
||||||
<properties>
|
<properties>
|
||||||
<marvin.config>tools/devcloud/devcloud.cfg</marvin.config>
|
<marvin.config>tools/devcloud/devcloud.cfg</marvin.config>
|
||||||
@ -521,7 +531,7 @@
|
|||||||
</properties>
|
</properties>
|
||||||
<modules>
|
<modules>
|
||||||
<module>developer</module>
|
<module>developer</module>
|
||||||
<!--module>tools/devcloud</module-->
|
<!--module>tools/devcloud</module -->
|
||||||
</modules>
|
</modules>
|
||||||
</profile>
|
</profile>
|
||||||
<profile>
|
<profile>
|
||||||
|
|||||||
@ -95,6 +95,11 @@
|
|||||||
<artifactId>cloud-framework-events</artifactId>
|
<artifactId>cloud-framework-events</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.cloudstack</groupId>
|
||||||
|
<artifactId>cloud-utils</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<build>
|
<build>
|
||||||
<defaultGoal>install</defaultGoal>
|
<defaultGoal>install</defaultGoal>
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@ -73,7 +73,7 @@ public class ConsoleProxyServlet extends HttpServlet {
|
|||||||
@Inject AccountManager _accountMgr;
|
@Inject AccountManager _accountMgr;
|
||||||
@Inject VirtualMachineManager _vmMgr;
|
@Inject VirtualMachineManager _vmMgr;
|
||||||
@Inject ManagementServer _ms;
|
@Inject ManagementServer _ms;
|
||||||
@Inject IdentityService _identityService;
|
@Inject IdentityService _identityService;
|
||||||
|
|
||||||
static ManagementServer s_ms;
|
static ManagementServer s_ms;
|
||||||
|
|
||||||
@ -81,13 +81,13 @@ public class ConsoleProxyServlet extends HttpServlet {
|
|||||||
|
|
||||||
public ConsoleProxyServlet() {
|
public ConsoleProxyServlet() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init(ServletConfig config) throws ServletException {
|
public void init(ServletConfig config) throws ServletException {
|
||||||
SpringBeanAutowiringSupport.processInjectionBasedOnServletContext(this, config.getServletContext());
|
SpringBeanAutowiringSupport.processInjectionBasedOnServletContext(this, config.getServletContext());
|
||||||
s_ms = _ms;
|
s_ms = _ms;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doPost(HttpServletRequest req, HttpServletResponse resp) {
|
protected void doPost(HttpServletRequest req, HttpServletResponse resp) {
|
||||||
doGet(req, resp);
|
doGet(req, resp);
|
||||||
@ -274,7 +274,7 @@ public class ConsoleProxyServlet extends HttpServlet {
|
|||||||
|
|
||||||
private void handleAuthRequest(HttpServletRequest req, HttpServletResponse resp, long vmId) {
|
private void handleAuthRequest(HttpServletRequest req, HttpServletResponse resp, long vmId) {
|
||||||
|
|
||||||
// TODO authentication channel between console proxy VM and management server needs to be secured,
|
// TODO authentication channel between console proxy VM and management server needs to be secured,
|
||||||
// the data is now being sent through private network, but this is apparently not enough
|
// the data is now being sent through private network, but this is apparently not enough
|
||||||
VMInstanceVO vm = _vmMgr.findById(vmId);
|
VMInstanceVO vm = _vmMgr.findById(vmId);
|
||||||
if(vm == null) {
|
if(vm == null) {
|
||||||
@ -334,11 +334,11 @@ public class ConsoleProxyServlet extends HttpServlet {
|
|||||||
private String getEncryptorPassword() {
|
private String getEncryptorPassword() {
|
||||||
String key = _ms.getEncryptionKey();
|
String key = _ms.getEncryptionKey();
|
||||||
String iv = _ms.getEncryptionIV();
|
String iv = _ms.getEncryptionIV();
|
||||||
|
|
||||||
ConsoleProxyPasswordBasedEncryptor.KeyIVPair keyIvPair = new ConsoleProxyPasswordBasedEncryptor.KeyIVPair(key, iv);
|
ConsoleProxyPasswordBasedEncryptor.KeyIVPair keyIvPair = new ConsoleProxyPasswordBasedEncryptor.KeyIVPair(key, iv);
|
||||||
return _gson.toJson(keyIvPair);
|
return _gson.toJson(keyIvPair);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String composeThumbnailUrl(String rootUrl, VMInstanceVO vm, HostVO hostVo, int w, int h) {
|
private String composeThumbnailUrl(String rootUrl, VMInstanceVO vm, HostVO hostVo, int w, int h) {
|
||||||
StringBuffer sb = new StringBuffer(rootUrl);
|
StringBuffer sb = new StringBuffer(rootUrl);
|
||||||
|
|
||||||
@ -385,8 +385,7 @@ public class ConsoleProxyServlet extends HttpServlet {
|
|||||||
Ternary<String, String, String> parsedHostInfo = parseHostInfo(portInfo.first());
|
Ternary<String, String, String> parsedHostInfo = parseHostInfo(portInfo.first());
|
||||||
|
|
||||||
String sid = vm.getVncPassword();
|
String sid = vm.getVncPassword();
|
||||||
String tag = String.valueOf(vm.getId());
|
String tag = vm.getUuid();
|
||||||
tag = _identityService.getIdentityUuid("vm_instance", tag);
|
|
||||||
String ticket = genAccessTicket(host, String.valueOf(portInfo.second()), sid, tag);
|
String ticket = genAccessTicket(host, String.valueOf(portInfo.second()), sid, tag);
|
||||||
ConsoleProxyPasswordBasedEncryptor encryptor = new ConsoleProxyPasswordBasedEncryptor(getEncryptorPassword());
|
ConsoleProxyPasswordBasedEncryptor encryptor = new ConsoleProxyPasswordBasedEncryptor(getEncryptorPassword());
|
||||||
ConsoleProxyClientParam param = new ConsoleProxyClientParam();
|
ConsoleProxyClientParam param = new ConsoleProxyClientParam();
|
||||||
@ -473,12 +472,12 @@ public class ConsoleProxyServlet extends HttpServlet {
|
|||||||
} catch (PermissionDeniedException ex) {
|
} catch (PermissionDeniedException ex) {
|
||||||
if (accountObj.getType() == Account.ACCOUNT_TYPE_NORMAL) {
|
if (accountObj.getType() == Account.ACCOUNT_TYPE_NORMAL) {
|
||||||
if (s_logger.isDebugEnabled()) {
|
if (s_logger.isDebugEnabled()) {
|
||||||
s_logger.debug("VM access is denied. VM owner account " + vm.getAccountId()
|
s_logger.debug("VM access is denied. VM owner account " + vm.getAccountId()
|
||||||
+ " does not match the account id in session " + accountObj.getId() + " and caller is a normal user");
|
+ " does not match the account id in session " + accountObj.getId() + " and caller is a normal user");
|
||||||
}
|
}
|
||||||
} else if(accountObj.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN || accountObj.getType() == Account.ACCOUNT_TYPE_READ_ONLY_ADMIN) {
|
} else if(accountObj.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN || accountObj.getType() == Account.ACCOUNT_TYPE_READ_ONLY_ADMIN) {
|
||||||
if(s_logger.isDebugEnabled()) {
|
if(s_logger.isDebugEnabled()) {
|
||||||
s_logger.debug("VM access is denied. VM owner account " + vm.getAccountId()
|
s_logger.debug("VM access is denied. VM owner account " + vm.getAccountId()
|
||||||
+ " does not match the account id in session " + accountObj.getId() + " and the domain-admin caller does not manage the target domain");
|
+ " does not match the account id in session " + accountObj.getId() + " and the domain-admin caller does not manage the target domain");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -515,7 +514,7 @@ public class ConsoleProxyServlet extends HttpServlet {
|
|||||||
account = _accountMgr.getAccount(user.getAccountId());
|
account = _accountMgr.getAccount(user.getAccountId());
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((user == null) || (user.getRemoved() != null) || !user.getState().equals(Account.State.enabled)
|
if ((user == null) || (user.getRemoved() != null) || !user.getState().equals(Account.State.enabled)
|
||||||
|| (account == null) || !account.getState().equals(Account.State.enabled)) {
|
|| (account == null) || !account.getState().equals(Account.State.enabled)) {
|
||||||
s_logger.warn("Deleted/Disabled/Locked user with id=" + userId + " attempting to access public API");
|
s_logger.warn("Deleted/Disabled/Locked user with id=" + userId + " attempting to access public API");
|
||||||
return false;
|
return false;
|
||||||
@ -586,7 +585,7 @@ public class ConsoleProxyServlet extends HttpServlet {
|
|||||||
if (!user.getState().equals(Account.State.enabled) || !account.getState().equals(Account.State.enabled)) {
|
if (!user.getState().equals(Account.State.enabled) || !account.getState().equals(Account.State.enabled)) {
|
||||||
s_logger.debug("disabled or locked user accessing the api, userid = " + user.getId() + "; name = " + user.getUsername() + "; state: " + user.getState() + "; accountState: " + account.getState());
|
s_logger.debug("disabled or locked user accessing the api, userid = " + user.getId() + "; name = " + user.getUsername() + "; state: " + user.getState() + "; accountState: " + account.getState());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// verify secret key exists
|
// verify secret key exists
|
||||||
secretKey = user.getSecretKey();
|
secretKey = user.getSecretKey();
|
||||||
@ -632,10 +631,10 @@ public class ConsoleProxyServlet extends HttpServlet {
|
|||||||
case '>': sb.append(">"); break;
|
case '>': sb.append(">"); break;
|
||||||
case '&': sb.append("&"); break;
|
case '&': sb.append("&"); break;
|
||||||
case '"': sb.append("""); break;
|
case '"': sb.append("""); break;
|
||||||
case ' ': sb.append(" ");break;
|
case ' ': sb.append(" ");break;
|
||||||
default: sb.append(c); break;
|
default: sb.append(c); break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,6 +19,7 @@ package com.cloud.network.security;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.apache.cloudstack.test.utils.SpringUtils;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.ComponentScan;
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
@ -60,7 +61,6 @@ import com.cloud.tags.dao.ResourceTagsDaoImpl;
|
|||||||
import com.cloud.user.AccountManager;
|
import com.cloud.user.AccountManager;
|
||||||
import com.cloud.user.DomainManager;
|
import com.cloud.user.DomainManager;
|
||||||
import com.cloud.user.dao.AccountDaoImpl;
|
import com.cloud.user.dao.AccountDaoImpl;
|
||||||
import com.cloud.utils.component.SpringComponentScanUtils;
|
|
||||||
import com.cloud.vm.UserVmManager;
|
import com.cloud.vm.UserVmManager;
|
||||||
import com.cloud.vm.VirtualMachineManager;
|
import com.cloud.vm.VirtualMachineManager;
|
||||||
import com.cloud.vm.dao.NicDaoImpl;
|
import com.cloud.vm.dao.NicDaoImpl;
|
||||||
@ -151,7 +151,7 @@ public class SecurityGroupManagerTestConfiguration {
|
|||||||
public boolean match(MetadataReader mdr, MetadataReaderFactory arg1) throws IOException {
|
public boolean match(MetadataReader mdr, MetadataReaderFactory arg1) throws IOException {
|
||||||
mdr.getClassMetadata().getClassName();
|
mdr.getClassMetadata().getClassName();
|
||||||
ComponentScan cs = SecurityGroupManagerTestConfiguration.class.getAnnotation(ComponentScan.class);
|
ComponentScan cs = SecurityGroupManagerTestConfiguration.class.getAnnotation(ComponentScan.class);
|
||||||
return SpringComponentScanUtils.includedInBasePackageClasses(mdr.getClassMetadata().getClassName(), cs);
|
return SpringUtils.includedInBasePackageClasses(mdr.getClassMetadata().getClassName(), cs);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,6 +19,7 @@ package com.cloud.snapshot;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.apache.cloudstack.test.utils.SpringUtils;
|
||||||
import org.springframework.context.annotation.ComponentScan;
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
import org.springframework.context.annotation.ComponentScan.Filter;
|
import org.springframework.context.annotation.ComponentScan.Filter;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
@ -36,7 +37,6 @@ import com.cloud.host.dao.HostTagsDaoImpl;
|
|||||||
import com.cloud.storage.dao.SnapshotDaoImpl;
|
import com.cloud.storage.dao.SnapshotDaoImpl;
|
||||||
import com.cloud.storage.dao.VolumeDaoImpl;
|
import com.cloud.storage.dao.VolumeDaoImpl;
|
||||||
import com.cloud.tags.dao.ResourceTagsDaoImpl;
|
import com.cloud.tags.dao.ResourceTagsDaoImpl;
|
||||||
import com.cloud.utils.component.SpringComponentScanUtils;
|
|
||||||
import com.cloud.vm.dao.NicDaoImpl;
|
import com.cloud.vm.dao.NicDaoImpl;
|
||||||
import com.cloud.vm.dao.VMInstanceDaoImpl;
|
import com.cloud.vm.dao.VMInstanceDaoImpl;
|
||||||
|
|
||||||
@ -65,7 +65,7 @@ public class SnapshotDaoTestConfiguration {
|
|||||||
public boolean match(MetadataReader mdr, MetadataReaderFactory arg1) throws IOException {
|
public boolean match(MetadataReader mdr, MetadataReaderFactory arg1) throws IOException {
|
||||||
mdr.getClassMetadata().getClassName();
|
mdr.getClassMetadata().getClassName();
|
||||||
ComponentScan cs = SnapshotDaoTestConfiguration.class.getAnnotation(ComponentScan.class);
|
ComponentScan cs = SnapshotDaoTestConfiguration.class.getAnnotation(ComponentScan.class);
|
||||||
return SpringComponentScanUtils.includedInBasePackageClasses(mdr.getClassMetadata().getClassName(), cs);
|
return SpringUtils.includedInBasePackageClasses(mdr.getClassMetadata().getClassName(), cs);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,6 +20,7 @@ package com.cloud.storage.dao;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDaoImpl;
|
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDaoImpl;
|
||||||
|
import org.apache.cloudstack.test.utils.SpringUtils;
|
||||||
import org.springframework.context.annotation.ComponentScan;
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
import org.springframework.context.annotation.ComponentScan.Filter;
|
import org.springframework.context.annotation.ComponentScan.Filter;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
@ -28,7 +29,6 @@ import org.springframework.core.type.classreading.MetadataReader;
|
|||||||
import org.springframework.core.type.classreading.MetadataReaderFactory;
|
import org.springframework.core.type.classreading.MetadataReaderFactory;
|
||||||
import org.springframework.core.type.filter.TypeFilter;
|
import org.springframework.core.type.filter.TypeFilter;
|
||||||
|
|
||||||
import com.cloud.utils.component.SpringComponentScanUtils;
|
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@ComponentScan(basePackageClasses={
|
@ComponentScan(basePackageClasses={
|
||||||
@ -46,7 +46,7 @@ public class StoragePoolDaoTestConfiguration {
|
|||||||
public boolean match(MetadataReader mdr, MetadataReaderFactory arg1) throws IOException {
|
public boolean match(MetadataReader mdr, MetadataReaderFactory arg1) throws IOException {
|
||||||
mdr.getClassMetadata().getClassName();
|
mdr.getClassMetadata().getClassName();
|
||||||
ComponentScan cs = StoragePoolDaoTestConfiguration.class.getAnnotation(ComponentScan.class);
|
ComponentScan cs = StoragePoolDaoTestConfiguration.class.getAnnotation(ComponentScan.class);
|
||||||
return SpringComponentScanUtils.includedInBasePackageClasses(mdr.getClassMetadata().getClassName(), cs);
|
return SpringUtils.includedInBasePackageClasses(mdr.getClassMetadata().getClassName(), cs);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,6 +19,7 @@ package com.cloud.vm.dao;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.apache.cloudstack.test.utils.SpringUtils;
|
||||||
import org.springframework.context.annotation.ComponentScan;
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
import org.springframework.context.annotation.ComponentScan.Filter;
|
import org.springframework.context.annotation.ComponentScan.Filter;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
@ -27,7 +28,6 @@ import org.springframework.core.type.classreading.MetadataReader;
|
|||||||
import org.springframework.core.type.classreading.MetadataReaderFactory;
|
import org.springframework.core.type.classreading.MetadataReaderFactory;
|
||||||
import org.springframework.core.type.filter.TypeFilter;
|
import org.springframework.core.type.filter.TypeFilter;
|
||||||
|
|
||||||
import com.cloud.utils.component.SpringComponentScanUtils;
|
|
||||||
import com.cloud.vm.dao.UserVmCloneSettingDaoImpl;
|
import com.cloud.vm.dao.UserVmCloneSettingDaoImpl;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@ -45,7 +45,7 @@ public class UserVmCloneSettingDaoTestConfiguration {
|
|||||||
public boolean match(MetadataReader mdr, MetadataReaderFactory arg1) throws IOException {
|
public boolean match(MetadataReader mdr, MetadataReaderFactory arg1) throws IOException {
|
||||||
mdr.getClassMetadata().getClassName();
|
mdr.getClassMetadata().getClassName();
|
||||||
ComponentScan cs = UserVmCloneSettingDaoTestConfiguration.class.getAnnotation(ComponentScan.class);
|
ComponentScan cs = UserVmCloneSettingDaoTestConfiguration.class.getAnnotation(ComponentScan.class);
|
||||||
return SpringComponentScanUtils.includedInBasePackageClasses(mdr.getClassMetadata().getClassName(), cs);
|
return SpringUtils.includedInBasePackageClasses(mdr.getClassMetadata().getClassName(), cs);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,6 +19,7 @@ package com.cloud.vm.dao;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.apache.cloudstack.test.utils.SpringUtils;
|
||||||
import org.springframework.context.annotation.ComponentScan;
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
import org.springframework.context.annotation.ComponentScan.Filter;
|
import org.springframework.context.annotation.ComponentScan.Filter;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
@ -27,7 +28,6 @@ import org.springframework.core.type.classreading.MetadataReader;
|
|||||||
import org.springframework.core.type.classreading.MetadataReaderFactory;
|
import org.springframework.core.type.classreading.MetadataReaderFactory;
|
||||||
import org.springframework.core.type.filter.TypeFilter;
|
import org.springframework.core.type.filter.TypeFilter;
|
||||||
|
|
||||||
import com.cloud.utils.component.SpringComponentScanUtils;
|
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@ComponentScan(basePackageClasses={
|
@ComponentScan(basePackageClasses={
|
||||||
@ -43,7 +43,7 @@ public class UserVmDaoTestConfiguration {
|
|||||||
public boolean match(MetadataReader mdr, MetadataReaderFactory arg1) throws IOException {
|
public boolean match(MetadataReader mdr, MetadataReaderFactory arg1) throws IOException {
|
||||||
mdr.getClassMetadata().getClassName();
|
mdr.getClassMetadata().getClassName();
|
||||||
ComponentScan cs = UserVmDaoTestConfiguration.class.getAnnotation(ComponentScan.class);
|
ComponentScan cs = UserVmDaoTestConfiguration.class.getAnnotation(ComponentScan.class);
|
||||||
return SpringComponentScanUtils.includedInBasePackageClasses(mdr.getClassMetadata().getClassName(), cs);
|
return SpringUtils.includedInBasePackageClasses(mdr.getClassMetadata().getClassName(), cs);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,6 +19,7 @@ package com.cloud.vpc;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.apache.cloudstack.test.utils.SpringUtils;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.ComponentScan;
|
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.AccountManager;
|
||||||
import com.cloud.user.dao.AccountDaoImpl;
|
import com.cloud.user.dao.AccountDaoImpl;
|
||||||
import com.cloud.user.dao.UserStatisticsDaoImpl;
|
import com.cloud.user.dao.UserStatisticsDaoImpl;
|
||||||
import com.cloud.utils.component.SpringComponentScanUtils;
|
|
||||||
import com.cloud.vm.UserVmManager;
|
import com.cloud.vm.UserVmManager;
|
||||||
import com.cloud.vm.dao.DomainRouterDaoImpl;
|
import com.cloud.vm.dao.DomainRouterDaoImpl;
|
||||||
import com.cloud.vm.dao.NicDaoImpl;
|
import com.cloud.vm.dao.NicDaoImpl;
|
||||||
@ -236,7 +236,7 @@ public class VpcTestConfiguration {
|
|||||||
public boolean match(MetadataReader mdr, MetadataReaderFactory arg1) throws IOException {
|
public boolean match(MetadataReader mdr, MetadataReaderFactory arg1) throws IOException {
|
||||||
mdr.getClassMetadata().getClassName();
|
mdr.getClassMetadata().getClassName();
|
||||||
ComponentScan cs = VpcTestConfiguration.class.getAnnotation(ComponentScan.class);
|
ComponentScan cs = VpcTestConfiguration.class.getAnnotation(ComponentScan.class);
|
||||||
return SpringComponentScanUtils.includedInBasePackageClasses(mdr.getClassMetadata().getClassName(), cs);
|
return SpringUtils.includedInBasePackageClasses(mdr.getClassMetadata().getClassName(), cs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -24,6 +24,7 @@ import static org.mockito.Matchers.anyString;
|
|||||||
import static org.mockito.Matchers.eq;
|
import static org.mockito.Matchers.eq;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
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.AffinityGroupDao;
|
||||||
import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao;
|
import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao;
|
||||||
|
import org.apache.cloudstack.test.utils.SpringUtils;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Mockito;
|
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.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
||||||
|
|
||||||
import com.cloud.event.EventUtils;
|
import com.cloud.event.EventUtils;
|
||||||
import com.cloud.event.EventVO;
|
import com.cloud.event.EventVO;
|
||||||
@ -48,6 +59,7 @@ import com.cloud.exception.ResourceInUseException;
|
|||||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||||
import com.cloud.user.Account;
|
import com.cloud.user.Account;
|
||||||
import com.cloud.user.AccountManager;
|
import com.cloud.user.AccountManager;
|
||||||
|
import com.cloud.user.AccountService;
|
||||||
import com.cloud.user.AccountVO;
|
import com.cloud.user.AccountVO;
|
||||||
import com.cloud.user.UserContext;
|
import com.cloud.user.UserContext;
|
||||||
import com.cloud.user.dao.AccountDao;
|
import com.cloud.user.dao.AccountDao;
|
||||||
@ -57,7 +69,7 @@ import com.cloud.vm.VirtualMachine;
|
|||||||
import com.cloud.vm.dao.UserVmDao;
|
import com.cloud.vm.dao.UserVmDao;
|
||||||
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@ContextConfiguration(locations = "classpath:/affinityContext.xml")
|
@ContextConfiguration(loader = AnnotationConfigContextLoader.class)
|
||||||
public class AffinityApiUnitTest {
|
public class AffinityApiUnitTest {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@ -188,4 +200,57 @@ public class AffinityApiUnitTest {
|
|||||||
_affinityService.updateVMAffinityGroups(10L, affinityGroupIds);
|
_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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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.PrimaryDataStoreDao;
|
||||||
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDaoImpl;
|
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDaoImpl;
|
||||||
import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailsDao;
|
import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailsDao;
|
||||||
|
import org.apache.cloudstack.test.utils.SpringUtils;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.ComponentScan;
|
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.tags.dao.ResourceTagsDaoImpl;
|
||||||
import com.cloud.user.dao.AccountDaoImpl;
|
import com.cloud.user.dao.AccountDaoImpl;
|
||||||
import com.cloud.user.dao.UserDaoImpl;
|
import com.cloud.user.dao.UserDaoImpl;
|
||||||
import com.cloud.utils.component.SpringComponentScanUtils;
|
|
||||||
import com.cloud.vm.dao.InstanceGroupDaoImpl;
|
import com.cloud.vm.dao.InstanceGroupDaoImpl;
|
||||||
import com.cloud.vm.dao.NicDaoImpl;
|
import com.cloud.vm.dao.NicDaoImpl;
|
||||||
import com.cloud.vm.dao.NicSecondaryIpDaoImpl;
|
import com.cloud.vm.dao.NicSecondaryIpDaoImpl;
|
||||||
@ -338,7 +338,7 @@ public class ChildTestConfiguration {
|
|||||||
public boolean match(MetadataReader mdr, MetadataReaderFactory arg1) throws IOException {
|
public boolean match(MetadataReader mdr, MetadataReaderFactory arg1) throws IOException {
|
||||||
mdr.getClassMetadata().getClassName();
|
mdr.getClassMetadata().getClassName();
|
||||||
ComponentScan cs = ChildTestConfiguration.class.getAnnotation(ComponentScan.class);
|
ComponentScan cs = ChildTestConfiguration.class.getAnnotation(ComponentScan.class);
|
||||||
return SpringComponentScanUtils.includedInBasePackageClasses(mdr.getClassMetadata().getClassName(), cs);
|
return SpringUtils.includedInBasePackageClasses(mdr.getClassMetadata().getClassName(), cs);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,42 +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 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. -->
|
|
||||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
|
|
||||||
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop"
|
|
||||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
|
||||||
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
|
|
||||||
http://www.springframework.org/schema/tx
|
|
||||||
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
|
|
||||||
http://www.springframework.org/schema/aop
|
|
||||||
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
|
|
||||||
http://www.springframework.org/schema/context
|
|
||||||
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
|
|
||||||
|
|
||||||
<context:annotation-config />
|
|
||||||
|
|
||||||
<!-- @DB support -->
|
|
||||||
<bean id="componentContext" class="com.cloud.utils.component.ComponentContext" />
|
|
||||||
|
|
||||||
<bean id="transactionContextBuilder" class="com.cloud.utils.db.TransactionContextBuilder" />
|
|
||||||
<bean id="actionEventInterceptor" class="com.cloud.event.ActionEventInterceptor" />
|
|
||||||
<bean id="instantiatePostProcessor" class="com.cloud.utils.component.ComponentInstantiationPostProcessor">
|
|
||||||
<property name="Interceptors">
|
|
||||||
<list>
|
|
||||||
<ref bean="transactionContextBuilder" />
|
|
||||||
<ref bean="actionEventInterceptor" />
|
|
||||||
</list>
|
|
||||||
</property>
|
|
||||||
</bean>
|
|
||||||
|
|
||||||
<bean class="org.apache.cloudstack.affinity.AffinityApiTestConfiguration" />
|
|
||||||
|
|
||||||
|
|
||||||
</beans>
|
|
||||||
@ -23,9 +23,9 @@
|
|||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>org.apache.cloudstack</groupId>
|
<groupId>org.apache.cloudstack</groupId>
|
||||||
<artifactId>cloudstack</artifactId>
|
<artifactId>cloudstack-services</artifactId>
|
||||||
<version>4.2.0-SNAPSHOT</version>
|
<version>4.2.0-SNAPSHOT</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<build>
|
<build>
|
||||||
<defaultGoal>install</defaultGoal>
|
<defaultGoal>install</defaultGoal>
|
||||||
|
|||||||
@ -18,13 +18,13 @@
|
|||||||
-->
|
-->
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>cloudstack-service-secondary-storage</artifactId>
|
<artifactId>cloud-secondary-storage</artifactId>
|
||||||
<name>Apache CloudStack Secondary Storage Service</name>
|
<name>Apache CloudStack Secondary Storage Service</name>
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>org.apache.cloudstack</groupId>
|
<groupId>org.apache.cloudstack</groupId>
|
||||||
<artifactId>cloudstack</artifactId>
|
<artifactId>cloudstack-services</artifactId>
|
||||||
<version>4.2.0-SNAPSHOT</version>
|
<version>4.2.0-SNAPSHOT</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|||||||
@ -1,15 +1,14 @@
|
|||||||
<!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor
|
<!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor
|
||||||
license agreements. See the NOTICE file distributed with this work for additional
|
license agreements. See the NOTICE file distributed with this work for additional
|
||||||
information regarding copyright ownership. The ASF licenses this file to
|
information regarding copyright ownership. The ASF licenses this file to you under
|
||||||
you under the Apache License, Version 2.0 (the "License"); you may not use
|
the Apache License, Version 2.0 (the "License"); you may not use this file except
|
||||||
this file except in compliance with the License. You may obtain a copy of
|
in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||||
the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required
|
Unless required by applicable law or agreed to in writing, software distributed under
|
||||||
by applicable law or agreed to in writing, software distributed under the
|
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
|
||||||
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
|
||||||
OF ANY KIND, either express or implied. See the License for the specific
|
governing permissions and limitations under the License. -->
|
||||||
language governing permissions and limitations under the License. -->
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>cloud-marvin</artifactId>
|
<artifactId>cloud-marvin</artifactId>
|
||||||
<name>Apache CloudStack marvin</name>
|
<name>Apache CloudStack marvin</name>
|
||||||
@ -35,7 +34,7 @@
|
|||||||
</goals>
|
</goals>
|
||||||
<configuration>
|
<configuration>
|
||||||
<target>
|
<target>
|
||||||
<delete dir="marvin/cloudstackAPI"/>
|
<delete dir="marvin/cloudstackAPI" />
|
||||||
<echo>Deleting ${project.artifactId} API sources</echo>
|
<echo>Deleting ${project.artifactId} API sources</echo>
|
||||||
</target>
|
</target>
|
||||||
</configuration>
|
</configuration>
|
||||||
@ -83,7 +82,7 @@
|
|||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
<!-- Custom profiles for sync and integration tests-->
|
<!-- Custom profiles for sync and integration tests -->
|
||||||
<profiles>
|
<profiles>
|
||||||
<profile>
|
<profile>
|
||||||
<id>marvin.sync</id>
|
<id>marvin.sync</id>
|
||||||
@ -160,6 +159,26 @@
|
|||||||
</properties>
|
</properties>
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.codehaus.gmaven</groupId>
|
||||||
|
<artifactId>gmaven-plugin</artifactId>
|
||||||
|
<version>1.5</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>setproperty</id>
|
||||||
|
<phase>validate</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>execute</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<source>
|
||||||
|
pom.properties['resolved.basedir']=project.basedir.absolutePath.replace('\','/').replace('D:','/cyg/d');
|
||||||
|
pom.properties['resolved.userdir']='${user.dir}'.replace('\','/').replace('D:','/cyg/d');
|
||||||
|
</source>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.codehaus.mojo</groupId>
|
<groupId>org.codehaus.mojo</groupId>
|
||||||
<artifactId>exec-maven-plugin</artifactId>
|
<artifactId>exec-maven-plugin</artifactId>
|
||||||
@ -177,18 +196,18 @@
|
|||||||
<arguments>
|
<arguments>
|
||||||
<argument>deployAndRun.py</argument>
|
<argument>deployAndRun.py</argument>
|
||||||
<argument>-c</argument>
|
<argument>-c</argument>
|
||||||
<argument>${user.dir}/${marvin.config}</argument>
|
<argument>${resolved.userdir}/${marvin.config}</argument>
|
||||||
<argument>-t</argument>
|
<argument>-t</argument>
|
||||||
<argument>/tmp/t.log</argument>
|
<argument>/tmp/t.log</argument>
|
||||||
<argument>-r</argument>
|
<argument>-r</argument>
|
||||||
<argument>/tmp/r.log</argument>
|
<argument>/tmp/r.log</argument>
|
||||||
<argument>-f</argument>
|
<argument>-f</argument>
|
||||||
<argument>${basedir}/marvin/testSetupSuccess.py</argument>
|
<argument>${resolved.basedir}/marvin/testSetupSuccess.py</argument>
|
||||||
</arguments>
|
</arguments>
|
||||||
</configuration>
|
</configuration>
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
</profile>
|
</profile>
|
||||||
|
|||||||
@ -25,7 +25,8 @@ import com.cloud.usage.dao.*;
|
|||||||
import com.cloud.usage.parser.*;
|
import com.cloud.usage.parser.*;
|
||||||
import com.cloud.user.dao.AccountDaoImpl;
|
import com.cloud.user.dao.AccountDaoImpl;
|
||||||
import com.cloud.user.dao.UserStatisticsDaoImpl;
|
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.mockito.Mockito;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.ComponentScan;
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
@ -87,7 +88,7 @@ public class UsageManagerTestConfiguration {
|
|||||||
public boolean match(MetadataReader mdr, MetadataReaderFactory arg1) throws IOException {
|
public boolean match(MetadataReader mdr, MetadataReaderFactory arg1) throws IOException {
|
||||||
mdr.getClassMetadata().getClassName();
|
mdr.getClassMetadata().getClassName();
|
||||||
ComponentScan cs = UsageManagerTestConfiguration.class.getAnnotation(ComponentScan.class);
|
ComponentScan cs = UsageManagerTestConfiguration.class.getAnnotation(ComponentScan.class);
|
||||||
return SpringComponentScanUtils.includedInBasePackageClasses(mdr.getClassMetadata().getClassName(), cs);
|
return SpringUtils.includedInBasePackageClasses(mdr.getClassMetadata().getClassName(), cs);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,40 +20,38 @@ import javax.persistence.Table;
|
|||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import com.cloud.utils.exception.CSExceptionErrorCode;
|
|
||||||
|
|
||||||
|
|
||||||
public class AnnotationHelper extends Object {
|
public class AnnotationHelper extends Object {
|
||||||
// This class contains routines to help query annotation elements of objects.
|
// This class contains routines to help query annotation elements of objects.
|
||||||
|
|
||||||
public static final Logger s_logger = Logger.getLogger(AnnotationHelper.class.getName());
|
public static final Logger s_logger = Logger.getLogger(AnnotationHelper.class.getName());
|
||||||
|
|
||||||
public static String getTableName(Object proxyObj) {
|
public static String getTableName(Object proxyObj) {
|
||||||
// The cglib class is generated by cglib during runtime.
|
// The cglib class is generated by cglib during runtime.
|
||||||
|
|
||||||
Class<?> curClass = proxyObj.getClass();
|
Class<?> curClass = proxyObj.getClass();
|
||||||
if (curClass == null) {
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (curClass.getSuperclass() != null && curClass.getSuperclass().getName() != "java.lang.Object") {
|
while (curClass.getSuperclass() != null && curClass.getSuperclass().getName() != "java.lang.Object") {
|
||||||
curClass = curClass.getSuperclass();
|
curClass = curClass.getSuperclass();
|
||||||
}
|
}
|
||||||
// At this point, curClass is the root base class of proxyObj's class, and curClass is not java.lang.Object.
|
// 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) {
|
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 null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return tabObj.name();
|
return tabObj.name();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
113
utils/src/org/apache/cloudstack/test/utils/SpringUtils.java
Normal file
113
utils/src/org/apache/cloudstack/test/utils/SpringUtils.java
Normal file
@ -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: <li>
|
||||||
|
* - Specify @ComponentScan with basePackageClasses, includeFilters, and
|
||||||
|
* useDefaultFilters=true. See the following example.
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* @ComponentScan(basePackageClasses={AffinityGroupServiceImpl.class, EventUtils.class},
|
||||||
|
* includeFilters={@Filter(value=TestConfiguration.Library.class, type=FilterType.CUSTOM)},
|
||||||
|
* useDefaultFilters=false)
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* - 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.
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* 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);
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* @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<ComponentMethodInterceptor> interceptors = new ArrayList<ComponentMethodInterceptor>();
|
||||||
|
interceptors.add(new TransactionContextBuilder());
|
||||||
|
processor.setInterceptors(interceptors);
|
||||||
|
|
||||||
|
return processor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user