From 7d61ee6e99ffa355516da11fc08d30193e109e39 Mon Sep 17 00:00:00 2001 From: Kishan Kavala Date: Fri, 15 Feb 2013 18:27:24 +0530 Subject: [PATCH] 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 --- .../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 +- .../src/com/cloud/usage/UsageManagerImpl.java | 2 + .../usage/UsageServerComponentConfig.java | 180 ------------------ .../parser/NetworkOfferingUsageParser.java | 3 +- .../usage/parser/NetworkUsageParser.java | 2 + .../parser/PortForwardingUsageParser.java | 5 +- .../parser/SecurityGroupUsageParser.java | 3 +- .../usage/parser/StorageUsageParser.java | 3 +- .../usage/parser/VMInstanceUsageParser.java | 9 +- .../usage/parser/VPNUserUsageParser.java | 3 +- .../cloud/usage/parser/VolumeUsageParser.java | 3 +- .../com/cloud/usage/UsageManagerTest.java | 97 ++++++++++ .../usage/UsageManagerTestConfiguration.java | 94 +++++++++ .../resources/UsageManagerTestContext.xml | 42 ++++ 18 files changed, 335 insertions(+), 193 deletions(-) create mode 100644 api/test/org/apache/cloudstack/api/command/test/UsageCmdTest.java delete mode 100644 usage/src/com/cloud/usage/UsageServerComponentConfig.java create mode 100644 usage/test/com/cloud/usage/UsageManagerTest.java create mode 100644 usage/test/com/cloud/usage/UsageManagerTestConfiguration.java create mode 100644 usage/test/resources/UsageManagerTestContext.xml 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 00000000000..1f218f47e2a --- /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(); + + Mockito.when(usageService.getUsageRecords(getUsageRecordsCmd)).thenReturn( + usageRecords); + + getUsageRecordsCmd._usageService = usageService; + getUsageRecordsCmd.execute(); + + } + +} diff --git a/setup/db/create-schema-premium.sql b/setup/db/create-schema-premium.sql index 2f86c0b9ab5..e30812ba68e 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; diff --git a/setup/db/db/schema-40to410.sql b/setup/db/db/schema-40to410.sql index 7f0044127f6..3ea8bbdbb73 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'; diff --git a/usage/pom.xml b/usage/pom.xml index bf2001b432c..4b408c4313b 100644 --- a/usage/pom.xml +++ b/usage/pom.xml @@ -42,6 +42,11 @@ install src test + + + test/resources + + resources diff --git a/usage/resources/usageApplicationContext.xml b/usage/resources/usageApplicationContext.xml index 32da93eecbc..0340038a06a 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"> - + + + + + + + + + + + + + + + + + + + + + + + +