incubator-cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wid...@apache.org
Subject [8/38] git commit: refs/heads/qemu-img - CLOUDSTACK-1295 : Added usage unit tests Fixed Component annontation for usage parsers Fixed mvn target to run usage removed UsageServerComponentConfig which is not required Added region_id to account table in clo
Date Mon, 18 Feb 2013 17:21:26 GMT
CLOUDSTACK-1295 : Added usage unit tests
Fixed Component annontation for usage parsers
Fixed mvn target to run usage
removed UsageServerComponentConfig which is not required
Added region_id to account table in cloud_usage db

Conflicts:
	setup/db/db/schema-40to410.sql


Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/7d61ee6e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/7d61ee6e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/7d61ee6e

Branch: refs/heads/qemu-img
Commit: 7d61ee6e99ffa355516da11fc08d30193e109e39
Parents: 3c764c0
Author: Kishan Kavala <kishan@cloud.com>
Authored: Fri Feb 15 18:27:24 2013 +0530
Committer: Kishan Kavala <kishan@cloud.com>
Committed: Fri Feb 15 18:41:28 2013 +0530

----------------------------------------------------------------------
 .../cloudstack/api/command/test/UsageCmdTest.java  |   69 ++++++
 setup/db/create-schema-premium.sql                 |    1 +
 setup/db/db/schema-40to410.sql                     |    2 +
 usage/pom.xml                                      |    5 +
 usage/resources/usageApplicationContext.xml        |    5 +-
 usage/src/com/cloud/usage/UsageManagerImpl.java    |    2 +
 .../cloud/usage/UsageServerComponentConfig.java    |  180 ---------------
 .../usage/parser/NetworkOfferingUsageParser.java   |    3 +-
 .../com/cloud/usage/parser/NetworkUsageParser.java |    2 +
 .../usage/parser/PortForwardingUsageParser.java    |    5 +-
 .../usage/parser/SecurityGroupUsageParser.java     |    3 +-
 .../com/cloud/usage/parser/StorageUsageParser.java |    3 +-
 .../cloud/usage/parser/VMInstanceUsageParser.java  |    9 +-
 .../com/cloud/usage/parser/VPNUserUsageParser.java |    3 +-
 .../com/cloud/usage/parser/VolumeUsageParser.java  |    3 +-
 usage/test/com/cloud/usage/UsageManagerTest.java   |   97 ++++++++
 .../cloud/usage/UsageManagerTestConfiguration.java |   94 ++++++++
 usage/test/resources/UsageManagerTestContext.xml   |   42 ++++
 18 files changed, 335 insertions(+), 193 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7d61ee6e/api/test/org/apache/cloudstack/api/command/test/UsageCmdTest.java
----------------------------------------------------------------------
diff --git a/api/test/org/apache/cloudstack/api/command/test/UsageCmdTest.java b/api/test/org/apache/cloudstack/api/command/test/UsageCmdTest.java
new file mode 100644
index 0000000..1f218f4
--- /dev/null
+++ b/api/test/org/apache/cloudstack/api/command/test/UsageCmdTest.java
@@ -0,0 +1,69 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package org.apache.cloudstack.api.command.test;
+
+import junit.framework.TestCase;
+import org.apache.cloudstack.api.command.admin.usage.GetUsageRecordsCmd;
+import org.apache.cloudstack.usage.Usage;
+import org.apache.cloudstack.usage.UsageService;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.mockito.Mockito;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class UsageCmdTest extends TestCase {
+
+    private GetUsageRecordsCmd getUsageRecordsCmd;
+
+    @Rule
+    public ExpectedException expectedException = ExpectedException.none();
+
+    @Before
+    public void setUp() {
+
+        getUsageRecordsCmd = new GetUsageRecordsCmd() {
+
+        };
+    }
+
+    @Test
+    public void testExecuteSuccess() {
+        UsageService usageService = Mockito.mock(UsageService.class);
+        getUsageRecordsCmd._usageService = usageService;
+        getUsageRecordsCmd.execute();
+    }
+
+    @Test
+    public void testExecuteEmptyResult() {
+
+        UsageService usageService = Mockito.mock(UsageService.class);
+
+        List usageRecords = new ArrayList<Usage>();
+
+        Mockito.when(usageService.getUsageRecords(getUsageRecordsCmd)).thenReturn(
+                usageRecords);
+
+        getUsageRecordsCmd._usageService = usageService;
+        getUsageRecordsCmd.execute();
+
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7d61ee6e/setup/db/create-schema-premium.sql
----------------------------------------------------------------------
diff --git a/setup/db/create-schema-premium.sql b/setup/db/create-schema-premium.sql
index 2f86c0b..e30812b 100644
--- a/setup/db/create-schema-premium.sql
+++ b/setup/db/create-schema-premium.sql
@@ -137,6 +137,7 @@ CREATE TABLE  `cloud_usage`.`account` (
   `cleanup_needed` tinyint(1) NOT NULL default '0',
   `network_domain` varchar(100) COMMENT 'Network domain name of the Vms of the account',
   `default_zone_id` bigint unsigned,
+  `region_id` int unsigned NOT NULL,
   CONSTRAINT `uc_account__uuid` UNIQUE (`uuid`),
   PRIMARY KEY  (`id`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7d61ee6e/setup/db/db/schema-40to410.sql
----------------------------------------------------------------------
diff --git a/setup/db/db/schema-40to410.sql b/setup/db/db/schema-40to410.sql
index 7f00441..3ea8bbd 100644
--- a/setup/db/db/schema-40to410.sql
+++ b/setup/db/db/schema-40to410.sql
@@ -1323,3 +1323,5 @@ INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Account Defaults',
'DEFAULT'
 INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Project Defaults', 'DEFAULT', 'management-server',
'max.project.cpus', '40', 'The default maximum number of cpu cores that can be used for a
project');
 
 INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Project Defaults', 'DEFAULT', 'management-server',
'max.project.memory', '40960', 'The default maximum memory (in MB) that can be used for a
project');
+
+ALTER TABLE `cloud_usage`.`account` ADD COLUMN `region_id` int unsigned NOT NULL DEFAULT
'1';

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7d61ee6e/usage/pom.xml
----------------------------------------------------------------------
diff --git a/usage/pom.xml b/usage/pom.xml
index bf2001b..4b408c4 100644
--- a/usage/pom.xml
+++ b/usage/pom.xml
@@ -42,6 +42,11 @@
     <defaultGoal>install</defaultGoal>
     <sourceDirectory>src</sourceDirectory>
     <testSourceDirectory>test</testSourceDirectory>
+      <testResources>
+          <testResource>
+              <directory>test/resources</directory>
+          </testResource>
+      </testResources>
     <resources>
       <resource>
           <directory>resources</directory>

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7d61ee6e/usage/resources/usageApplicationContext.xml
----------------------------------------------------------------------
diff --git a/usage/resources/usageApplicationContext.xml b/usage/resources/usageApplicationContext.xml
index 32da93e..0340038 100644
--- a/usage/resources/usageApplicationContext.xml
+++ b/usage/resources/usageApplicationContext.xml
@@ -31,7 +31,9 @@
                       http://www.springframework.org/schema/context/spring-context-3.0.xsd">
                    
 
   <context:annotation-config />
-  <context:component-scan base-package="com.cloud.usage" />
+  <context:component-scan base-package="com.cloud.usage, com.cloud.event.dao, com.cloud.user.dao,
com.cloud.configuration.dao, com.cloud.alert.dao, com.cloud.domain.dao">
+  	<context:exclude-filter type="assignable" expression="com.cloud.usage.UsageServiceImpl"/>
+  </context:component-scan>
   
   <!--
     @DB support
@@ -48,6 +50,5 @@
   
   <bean id="transactionContextBuilder" class="com.cloud.utils.db.TransactionContextBuilder"
/>
   <bean id="ComponentContext" class="com.cloud.utils.component.ComponentContext" />
-  <bean id="UsageServerConfig" class="com.cloud.usage.UsageServerComponentConfig" />
  
 </beans>

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7d61ee6e/usage/src/com/cloud/usage/UsageManagerImpl.java
----------------------------------------------------------------------
diff --git a/usage/src/com/cloud/usage/UsageManagerImpl.java b/usage/src/com/cloud/usage/UsageManagerImpl.java
index 1ebe892..bfdca1d 100644
--- a/usage/src/com/cloud/usage/UsageManagerImpl.java
+++ b/usage/src/com/cloud/usage/UsageManagerImpl.java
@@ -35,6 +35,7 @@ import javax.naming.ConfigurationException;
 
 import org.apache.log4j.Logger;
 import org.apache.cloudstack.usage.UsageTypes;
+import org.springframework.stereotype.Component;
 
 import com.cloud.alert.AlertManager;
 import com.cloud.configuration.dao.ConfigurationDao;
@@ -79,6 +80,7 @@ import com.cloud.utils.db.SearchCriteria;
 import com.cloud.utils.db.Transaction;
 import com.cloud.utils.exception.CloudRuntimeException;
 
+@Component
 @Local(value={UsageManager.class})
 public class UsageManagerImpl extends ManagerBase implements UsageManager, Runnable {
     public static final Logger s_logger = Logger.getLogger(UsageManagerImpl.class.getName());

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7d61ee6e/usage/src/com/cloud/usage/UsageServerComponentConfig.java
----------------------------------------------------------------------
diff --git a/usage/src/com/cloud/usage/UsageServerComponentConfig.java b/usage/src/com/cloud/usage/UsageServerComponentConfig.java
deleted file mode 100644
index aa8682c..0000000
--- a/usage/src/com/cloud/usage/UsageServerComponentConfig.java
+++ /dev/null
@@ -1,180 +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.usage;
-
-import org.springframework.context.annotation.Bean;
-
-import org.springframework.context.annotation.Configuration;
-
-import com.cloud.cluster.agentlb.dao.HostTransferMapDao;
-import com.cloud.cluster.agentlb.dao.HostTransferMapDaoImpl;
-import com.cloud.dc.dao.*;
-import com.cloud.service.dao.ServiceOfferingDaoImpl;
-import com.cloud.vm.dao.*;
-import com.cloud.network.dao.*;
-import com.cloud.host.dao.*;
-
-import com.cloud.utils.crypt.EncryptionSecretKeyChecker;  
-import com.cloud.vm.dao.VMInstanceDaoImpl; 
-import com.cloud.vm.dao.UserVmDaoImpl;
-import com.cloud.event.dao.EventDaoImpl; 
-import com.cloud.user.dao.UserStatisticsDaoImpl; 
-import com.cloud.network.dao.IPAddressDaoImpl; 
-import com.cloud.domain.dao.DomainDaoImpl; 
-import com.cloud.user.dao.AccountDaoImpl; 
-import com.cloud.user.dao.UserAccountDaoImpl; 
-import com.cloud.configuration.dao.ConfigurationDaoImpl; 
-import com.cloud.alert.dao.AlertDaoImpl;
-import com.cloud.event.dao.UsageEventDaoImpl; 
-import com.cloud.service.dao.ServiceOfferingDao;
-import com.cloud.event.dao.EventDao;
-import com.cloud.user.dao.UserStatisticsDao;
-import com.cloud.domain.dao.DomainDao;
-import com.cloud.user.dao.*;
-import com.cloud.configuration.dao.ConfigurationDao;
-import com.cloud.alert.dao.AlertDao;
-import com.cloud.event.dao.UsageEventDao;
-import com.cloud.tags.dao.*;
-
-@Configuration
-public class UsageServerComponentConfig {
-
-	@Bean
-	public HostTransferMapDao HostTransferDao() {
-		return new HostTransferMapDaoImpl();
-	}
-
-	@Bean
-	public ClusterDao ClusterDao() {
-		return new ClusterDaoImpl();
-	}
-
-	@Bean
-	public HostPodDao HostPodDao() {
-		return new HostPodDaoImpl();
-	}
-	
-	@Bean
-	public UserVmDetailsDao UserVmDetailsDao() {
-		return new UserVmDetailsDaoImpl();
-	}
-	
-	@Bean
-	public VlanDaoImpl VlanDaoImpl() {
-		return new VlanDaoImpl();
-	}
-	
-	@Bean
-	public PodVlanMapDao PodVlanMapDao() {
-		return new PodVlanMapDaoImpl();
-	}
-	
-	@Bean
-	public AccountVlanMapDao AccountVlanMapDao() {
-		return new AccountVlanMapDaoImpl();
-	}
-
-	@Bean
-	public EncryptionSecretKeyChecker EncryptionSecretKeyChecker() {
-		return new EncryptionSecretKeyChecker();
-	}
-	
-	@Bean
-	public VMInstanceDao VmInstanceDao() {
-		return new VMInstanceDaoImpl();
-	}
-
-	@Bean
-	public UserVmDao UserVmDao() {
-		return new UserVmDaoImpl();
-	}
-
-	@Bean
-	public ServiceOfferingDao ServiceOfferingDao() {
-		return new ServiceOfferingDaoImpl();
-	}
-	
-	@Bean
-	public EventDao EventDao() {
-		return new EventDaoImpl();
-	}
-
-	@Bean
-	public UserStatisticsDao UserStatisticsDao() {
-		return new UserStatisticsDaoImpl();
-	}
-
-	@Bean
-	public IPAddressDao IPAddressDao() {
-		return new IPAddressDaoImpl();
-	}
-	
-	@Bean
-	public DomainDao DomainDao() {
-		return new DomainDaoImpl();
-	}
-
-	@Bean
-	public AccountDao AccountDao() {
-		return new AccountDaoImpl();
-	}
-
-	@Bean
-	public UserAccountDao UserAccountDao() {
-		return new UserAccountDaoImpl();
-	}
-
-	@Bean
-	public ConfigurationDao ConfigurationDao() {
-		return new ConfigurationDaoImpl();
-	}
-
-	@Bean
-	public AlertDao AlertDao() {
-		return new AlertDaoImpl();
-	}
-
-	@Bean
-	public UsageEventDao UsageEventDao() {
-		return new UsageEventDaoImpl();
-	}
-
-	@Bean
-	public ResourceTagsDaoImpl ResourceTagsDaoImpl() {
-		return new ResourceTagsDaoImpl();
-	}
-
-	@Bean
-	public NicDao NicDao() {
-		return new NicDaoImpl();
-	}
-
-	@Bean
-	public HostDao HostDao() {
-		return new HostDaoImpl();
-	}
-
-	@Bean
-	public HostDetailsDao HostDetailsDao() {
-		return new HostDetailsDaoImpl();
-	}
-
-	@Bean
-	public HostTagsDao HostTagsDao() {
-		return new HostTagsDaoImpl();
-	}
-}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7d61ee6e/usage/src/com/cloud/usage/parser/NetworkOfferingUsageParser.java
----------------------------------------------------------------------
diff --git a/usage/src/com/cloud/usage/parser/NetworkOfferingUsageParser.java b/usage/src/com/cloud/usage/parser/NetworkOfferingUsageParser.java
index d026b76..21ad193 100644
--- a/usage/src/com/cloud/usage/parser/NetworkOfferingUsageParser.java
+++ b/usage/src/com/cloud/usage/parser/NetworkOfferingUsageParser.java
@@ -35,8 +35,9 @@ import com.cloud.usage.dao.UsageDao;
 import com.cloud.usage.dao.UsageNetworkOfferingDao;
 import com.cloud.user.AccountVO;
 import com.cloud.utils.Pair;
+import org.springframework.stereotype.Component;
 
-
+@Component
 public class NetworkOfferingUsageParser {
     public static final Logger s_logger = Logger.getLogger(NetworkOfferingUsageParser.class.getName());
     

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7d61ee6e/usage/src/com/cloud/usage/parser/NetworkUsageParser.java
----------------------------------------------------------------------
diff --git a/usage/src/com/cloud/usage/parser/NetworkUsageParser.java b/usage/src/com/cloud/usage/parser/NetworkUsageParser.java
index a891fdd..3da6854 100644
--- a/usage/src/com/cloud/usage/parser/NetworkUsageParser.java
+++ b/usage/src/com/cloud/usage/parser/NetworkUsageParser.java
@@ -34,7 +34,9 @@ import com.cloud.usage.dao.UsageNetworkDao;
 import com.cloud.user.AccountVO;
 
 import com.cloud.utils.db.SearchCriteria;
+import org.springframework.stereotype.Component;
 
+@Component
 public class NetworkUsageParser {
 public static final Logger s_logger = Logger.getLogger(NetworkUsageParser.class.getName());
 

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7d61ee6e/usage/src/com/cloud/usage/parser/PortForwardingUsageParser.java
----------------------------------------------------------------------
diff --git a/usage/src/com/cloud/usage/parser/PortForwardingUsageParser.java b/usage/src/com/cloud/usage/parser/PortForwardingUsageParser.java
index 4780d14..1f74bcf 100644
--- a/usage/src/com/cloud/usage/parser/PortForwardingUsageParser.java
+++ b/usage/src/com/cloud/usage/parser/PortForwardingUsageParser.java
@@ -35,8 +35,9 @@ import com.cloud.usage.dao.UsageDao;
 import com.cloud.usage.dao.UsagePortForwardingRuleDao;
 import com.cloud.user.AccountVO;
 import com.cloud.utils.Pair;
+import org.springframework.stereotype.Component;
 
-
+@Component
 public class PortForwardingUsageParser {
     public static final Logger s_logger = Logger.getLogger(PortForwardingUsageParser.class.getName());
     
@@ -49,7 +50,7 @@ public class PortForwardingUsageParser {
     @PostConstruct
     void init() {
     	m_usageDao = _usageDao;
-    	_usagePFRuleDao = _usagePFRuleDao;
+    	m_usagePFRuleDao = _usagePFRuleDao;
     }
     
     public static boolean parse(AccountVO account, Date startDate, Date endDate) {

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7d61ee6e/usage/src/com/cloud/usage/parser/SecurityGroupUsageParser.java
----------------------------------------------------------------------
diff --git a/usage/src/com/cloud/usage/parser/SecurityGroupUsageParser.java b/usage/src/com/cloud/usage/parser/SecurityGroupUsageParser.java
index df859b8..25de883 100644
--- a/usage/src/com/cloud/usage/parser/SecurityGroupUsageParser.java
+++ b/usage/src/com/cloud/usage/parser/SecurityGroupUsageParser.java
@@ -35,8 +35,9 @@ import com.cloud.usage.dao.UsageDao;
 import com.cloud.usage.dao.UsageSecurityGroupDao;
 import com.cloud.user.AccountVO;
 import com.cloud.utils.Pair;
+import org.springframework.stereotype.Component;
 
-
+@Component
 public class SecurityGroupUsageParser {
     public static final Logger s_logger = Logger.getLogger(SecurityGroupUsageParser.class.getName());
     

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7d61ee6e/usage/src/com/cloud/usage/parser/StorageUsageParser.java
----------------------------------------------------------------------
diff --git a/usage/src/com/cloud/usage/parser/StorageUsageParser.java b/usage/src/com/cloud/usage/parser/StorageUsageParser.java
index 4e3817e..337e8e2 100644
--- a/usage/src/com/cloud/usage/parser/StorageUsageParser.java
+++ b/usage/src/com/cloud/usage/parser/StorageUsageParser.java
@@ -36,8 +36,9 @@ import com.cloud.usage.dao.UsageDao;
 import com.cloud.usage.dao.UsageStorageDao;
 import com.cloud.user.AccountVO;
 import com.cloud.utils.Pair;
+import org.springframework.stereotype.Component;
 
-
+@Component
 public class StorageUsageParser {
     public static final Logger s_logger = Logger.getLogger(StorageUsageParser.class.getName());
     

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7d61ee6e/usage/src/com/cloud/usage/parser/VMInstanceUsageParser.java
----------------------------------------------------------------------
diff --git a/usage/src/com/cloud/usage/parser/VMInstanceUsageParser.java b/usage/src/com/cloud/usage/parser/VMInstanceUsageParser.java
index 2e7ee59..2072220 100644
--- a/usage/src/com/cloud/usage/parser/VMInstanceUsageParser.java
+++ b/usage/src/com/cloud/usage/parser/VMInstanceUsageParser.java
@@ -35,16 +35,17 @@ import com.cloud.usage.dao.UsageDao;
 import com.cloud.usage.dao.UsageVMInstanceDao;
 import com.cloud.user.AccountVO;
 import com.cloud.utils.Pair;
+import org.springframework.stereotype.Component;
 
-
+@Component
 public class VMInstanceUsageParser {
     public static final Logger s_logger = Logger.getLogger(VMInstanceUsageParser.class.getName());
-    
+
     private static UsageDao m_usageDao;
     private static UsageVMInstanceDao m_usageInstanceDao;
 
-    @Inject private static UsageDao _usageDao;;
-    @Inject private static UsageVMInstanceDao _usageInstanceDao;
+    @Inject private UsageDao _usageDao;;
+    @Inject private UsageVMInstanceDao _usageInstanceDao;
     
     @PostConstruct
     void init() {

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7d61ee6e/usage/src/com/cloud/usage/parser/VPNUserUsageParser.java
----------------------------------------------------------------------
diff --git a/usage/src/com/cloud/usage/parser/VPNUserUsageParser.java b/usage/src/com/cloud/usage/parser/VPNUserUsageParser.java
index c76de28..7afc97c 100644
--- a/usage/src/com/cloud/usage/parser/VPNUserUsageParser.java
+++ b/usage/src/com/cloud/usage/parser/VPNUserUsageParser.java
@@ -35,8 +35,9 @@ import com.cloud.usage.dao.UsageDao;
 import com.cloud.usage.dao.UsageVPNUserDao;
 import com.cloud.user.AccountVO;
 import com.cloud.utils.Pair;
+import org.springframework.stereotype.Component;
 
-
+@Component
 public class VPNUserUsageParser {
     public static final Logger s_logger = Logger.getLogger(VPNUserUsageParser.class.getName());
     

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7d61ee6e/usage/src/com/cloud/usage/parser/VolumeUsageParser.java
----------------------------------------------------------------------
diff --git a/usage/src/com/cloud/usage/parser/VolumeUsageParser.java b/usage/src/com/cloud/usage/parser/VolumeUsageParser.java
index 6d9fe5d..2ac1e0a 100644
--- a/usage/src/com/cloud/usage/parser/VolumeUsageParser.java
+++ b/usage/src/com/cloud/usage/parser/VolumeUsageParser.java
@@ -35,8 +35,9 @@ import com.cloud.usage.dao.UsageDao;
 import com.cloud.usage.dao.UsageVolumeDao;
 import com.cloud.user.AccountVO;
 import com.cloud.utils.Pair;
+import org.springframework.stereotype.Component;
 
-
+@Component
 public class VolumeUsageParser {
     public static final Logger s_logger = Logger.getLogger(VolumeUsageParser.class.getName());
     

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7d61ee6e/usage/test/com/cloud/usage/UsageManagerTest.java
----------------------------------------------------------------------
diff --git a/usage/test/com/cloud/usage/UsageManagerTest.java b/usage/test/com/cloud/usage/UsageManagerTest.java
new file mode 100644
index 0000000..eac3fcb
--- /dev/null
+++ b/usage/test/com/cloud/usage/UsageManagerTest.java
@@ -0,0 +1,97 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.usage;
+
+import com.cloud.usage.parser.*;
+import com.cloud.user.AccountVO;
+import com.cloud.utils.component.ComponentContext;
+import junit.framework.TestCase;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+import javax.inject.Inject;
+import javax.naming.ConfigurationException;
+import java.util.Date;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(locations = "classpath:/UsageManagerTestContext.xml")
+public class UsageManagerTest extends TestCase {
+    @Inject
+    UsageManagerImpl _usageMgr = null;
+    @Inject
+    VMInstanceUsageParser vmParser = null;
+    @Inject
+    IPAddressUsageParser ipParser = null;
+    @Inject
+    LoadBalancerUsageParser lbParser = null;
+    @Inject
+    NetworkOfferingUsageParser noParser = null;
+    @Inject
+    NetworkUsageParser netParser = null;
+    @Inject
+    PortForwardingUsageParser pfParser = null;
+    @Inject
+    SecurityGroupUsageParser sgParser = null;
+    @Inject
+    StorageUsageParser stParser = null;
+    @Inject
+    VolumeUsageParser volParser = null;
+    @Inject
+    VPNUserUsageParser vpnParser = null;
+
+    Date startDate = null;
+    Date endDate = null;
+
+    @Before
+    public void setup() throws Exception {
+        System.setProperty("pid", "5678");
+        ComponentContext.initComponentsLifeCycle();
+        startDate = new Date();
+        endDate = new Date(100000L +  System.currentTimeMillis());
+    }
+
+    @Test
+    public void testParse() throws ConfigurationException {
+        UsageJobVO job = new UsageJobVO();
+        _usageMgr.parse(job, System.currentTimeMillis(), 100000L +  System.currentTimeMillis());
+    }
+
+    @Test
+    public void testSchedule() throws ConfigurationException {
+        _usageMgr.scheduleParse();
+    }
+
+    @Test
+    public void testParsers() throws ConfigurationException {
+        AccountVO account = new AccountVO();
+        account.setId(2L);
+        vmParser.parse(account, startDate, endDate);
+        ipParser.parse(account, startDate, endDate);
+        lbParser.parse(account, startDate, endDate);
+        noParser.parse(account, startDate, endDate);
+        netParser.parse(account, startDate, endDate);
+        pfParser.parse(account, startDate, endDate);
+        sgParser.parse(account, startDate, endDate);
+        stParser.parse(account, startDate, endDate);
+        volParser.parse(account, startDate, endDate);
+        vpnParser.parse(account, startDate, endDate);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7d61ee6e/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
new file mode 100644
index 0000000..d7cf046
--- /dev/null
+++ b/usage/test/com/cloud/usage/UsageManagerTestConfiguration.java
@@ -0,0 +1,94 @@
+// 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.usage;
+
+import com.cloud.alert.AlertManager;
+import com.cloud.configuration.dao.ConfigurationDaoImpl;
+import com.cloud.event.dao.UsageEventDao;
+import com.cloud.usage.UsageManagerTestConfiguration.Library;
+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.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 java.io.IOException;
+
+@Configuration
+@ComponentScan(basePackageClasses={
+        AccountDaoImpl.class,
+        UsageDaoImpl.class,
+        UsageJobDaoImpl.class,
+        UsageVMInstanceDaoImpl.class,
+        UsageIPAddressDaoImpl.class,
+        UsageNetworkDaoImpl.class,
+        UsageVolumeDaoImpl.class,
+        UsageStorageDaoImpl.class,
+        UsageLoadBalancerPolicyDaoImpl.class,
+        UsagePortForwardingRuleDaoImpl.class,
+        UsageNetworkOfferingDaoImpl.class,
+        UsageVPNUserDaoImpl.class,
+        UsageSecurityGroupDaoImpl.class,
+        ConfigurationDaoImpl.class,
+        UsageManagerImpl.class,
+        VMInstanceUsageParser.class,
+        IPAddressUsageParser.class,
+        LoadBalancerUsageParser.class,
+        NetworkOfferingUsageParser.class,
+        NetworkUsageParser.class,
+        PortForwardingUsageParser.class,
+        SecurityGroupUsageParser.class,
+        StorageUsageParser.class,
+        VolumeUsageParser.class,
+        VPNUserUsageParser.class,
+        UserStatisticsDaoImpl.class},
+        includeFilters={@Filter(value=Library.class, type=FilterType.CUSTOM)},
+        useDefaultFilters=false
+        )
+public class UsageManagerTestConfiguration {
+
+    @Bean
+    public AlertManager alertManager() {
+        return Mockito.mock(AlertManager.class);
+    }
+
+    @Bean
+    public UsageEventDao usageEventDao() {
+        return Mockito.mock(UsageEventDao.class);
+    }
+
+    public static class Library implements TypeFilter {
+
+        @Override
+        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);
+        }
+
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7d61ee6e/usage/test/resources/UsageManagerTestContext.xml
----------------------------------------------------------------------
diff --git a/usage/test/resources/UsageManagerTestContext.xml b/usage/test/resources/UsageManagerTestContext.xml
new file mode 100644
index 0000000..ad4757a
--- /dev/null
+++ b/usage/test/resources/UsageManagerTestContext.xml
@@ -0,0 +1,42 @@
+<!-- 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 -->
+  <aop:config proxy-target-class="true">
+    <aop:aspect id="dbContextBuilder" ref="transactionContextBuilder">
+      <aop:pointcut id="captureAnyMethod" expression="execution(* *(..))" />
+
+      <aop:around pointcut-ref="captureAnyMethod" method="AroundAnyMethod" />
+    </aop:aspect>
+
+  </aop:config>
+
+  <bean id="transactionContextBuilder" class="com.cloud.utils.db.TransactionContextBuilder"
/>
+  <bean id="componentContext" class="com.cloud.utils.component.ComponentContext"/>
+  <bean id="TestConfiguration"
+    class="com.cloud.usage.UsageManagerTestConfiguration" />
+  <bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor">
+    <property name="requiredParameterValue" value="false" />
+  </bean>
+</beans>


Mime
View raw message