cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject [1/2] git commit: updated refs/heads/master to a71c985
Date Mon, 06 Jul 2015 14:22:41 GMT
Repository: cloudstack
Updated Branches:
  refs/heads/master 31c6b14dd -> a71c98522


findbugs: added test for getServiceProvider of CreateVpcOffering api

Signed-off-by: Daan Hoogland <daan.hoogland@gmail.com>

This closes #538


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

Branch: refs/heads/master
Commit: a71c9852238b01c0728fd2e1cc854dc8d48c0907
Parents: e34389a
Author: Daan Hoogland <daan.hoogland@gmail.com>
Authored: Mon Jul 6 12:07:42 2015 +0200
Committer: Daan Hoogland <daan.hoogland@gmail.com>
Committed: Mon Jul 6 16:22:19 2015 +0200

----------------------------------------------------------------------
 .../apache/cloudstack/api/ApiCmdTestUtil.java   | 17 +++++++
 .../CreateSecondaryStagingStoreCmdTest.java     | 25 +++-------
 .../admin/vpc/CreateVPCOfferingCmdTest.java     | 48 ++++++++++++++++++++
 3 files changed, 71 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a71c9852/api/test/org/apache/cloudstack/api/ApiCmdTestUtil.java
----------------------------------------------------------------------
diff --git a/api/test/org/apache/cloudstack/api/ApiCmdTestUtil.java b/api/test/org/apache/cloudstack/api/ApiCmdTestUtil.java
new file mode 100644
index 0000000..ca4510d
--- /dev/null
+++ b/api/test/org/apache/cloudstack/api/ApiCmdTestUtil.java
@@ -0,0 +1,17 @@
+package org.apache.cloudstack.api;
+
+import java.lang.reflect.Field;
+
+public class ApiCmdTestUtil {
+    public static void set(BaseCmd cmd, String fieldName, Object value)
+            throws IllegalArgumentException, IllegalAccessException {
+        for (Field field : cmd.getClass().getDeclaredFields()) {
+            Parameter parameter = field.getAnnotation(Parameter.class);
+            if (parameter != null && fieldName.equals(parameter.name())) {
+                field.setAccessible(true);
+                field.set(cmd, value);
+            }
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a71c9852/api/test/org/apache/cloudstack/api/command/admin/storage/CreateSecondaryStagingStoreCmdTest.java
----------------------------------------------------------------------
diff --git a/api/test/org/apache/cloudstack/api/command/admin/storage/CreateSecondaryStagingStoreCmdTest.java
b/api/test/org/apache/cloudstack/api/command/admin/storage/CreateSecondaryStagingStoreCmdTest.java
index 901e976..e935842 100644
--- a/api/test/org/apache/cloudstack/api/command/admin/storage/CreateSecondaryStagingStoreCmdTest.java
+++ b/api/test/org/apache/cloudstack/api/command/admin/storage/CreateSecondaryStagingStoreCmdTest.java
@@ -16,28 +16,15 @@
 // under the License.
 package org.apache.cloudstack.api.command.admin.storage;
 
-import java.lang.reflect.Field;
 import java.util.HashMap;
 import java.util.Map;
 
-import junit.framework.Assert;
-
-import org.apache.cloudstack.api.BaseCmd;
-import org.apache.cloudstack.api.Parameter;
+import org.junit.Assert;
 import org.junit.Test;
 
-public class CreateSecondaryStagingStoreCmdTest {
+import org.apache.cloudstack.api.ApiCmdTestUtil;
 
-    static void set(BaseCmd cmd, String fieldName, Object value)
-            throws IllegalArgumentException, IllegalAccessException {
-        for (Field field : cmd.getClass().getDeclaredFields()) {
-            Parameter parameter = field.getAnnotation(Parameter.class);
-            if (parameter != null && fieldName.equals(parameter.name())) {
-                field.setAccessible(true);
-                field.set(cmd, value);
-            }
-        }
-    }
+public class CreateSecondaryStagingStoreCmdTest {
 
     @Test
     public void getDetails() throws IllegalArgumentException,
@@ -48,7 +35,7 @@ public class CreateSecondaryStagingStoreCmdTest {
         kv.put("key", "TEST-KEY");
         kv.put("value", "TEST-VALUE");
         details.put("does not matter", kv);
-        set(cmd, "details", details);
+        ApiCmdTestUtil.set(cmd, "details", details);
         Map<String, String> detailsMap = cmd.getDetails();
         Assert.assertNotNull(detailsMap);
         Assert.assertEquals(1, detailsMap.size());
@@ -60,7 +47,7 @@ public class CreateSecondaryStagingStoreCmdTest {
     public void getDetailsEmpty() throws IllegalArgumentException,
             IllegalAccessException {
         CreateSecondaryStagingStoreCmd cmd = new CreateSecondaryStagingStoreCmd();
-        set(cmd, "details", new HashMap<String, Map<String, String>>());
+        ApiCmdTestUtil.set(cmd, "details", new HashMap<String, Map<String, String>>());
         Assert.assertNull(cmd.getDetails());
     }
 
@@ -68,7 +55,7 @@ public class CreateSecondaryStagingStoreCmdTest {
     public void getDetailsNull() throws IllegalArgumentException,
             IllegalAccessException {
         CreateSecondaryStagingStoreCmd cmd = new CreateSecondaryStagingStoreCmd();
-        set(cmd, "details", null);
+        ApiCmdTestUtil.set(cmd, "details", null);
         Assert.assertNull(cmd.getDetails());
     }
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a71c9852/api/test/org/apache/cloudstack/api/command/admin/vpc/CreateVPCOfferingCmdTest.java
----------------------------------------------------------------------
diff --git a/api/test/org/apache/cloudstack/api/command/admin/vpc/CreateVPCOfferingCmdTest.java
b/api/test/org/apache/cloudstack/api/command/admin/vpc/CreateVPCOfferingCmdTest.java
new file mode 100644
index 0000000..99433ed
--- /dev/null
+++ b/api/test/org/apache/cloudstack/api/command/admin/vpc/CreateVPCOfferingCmdTest.java
@@ -0,0 +1,48 @@
+package org.apache.cloudstack.api.command.admin.vpc;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import org.apache.cloudstack.api.ApiCmdTestUtil;
+import org.apache.cloudstack.api.ApiConstants;
+
+public class CreateVPCOfferingCmdTest {
+
+    @Test
+    public void testServiceProviders() throws IllegalArgumentException,
+            IllegalAccessException {
+        CreateVPCOfferingCmd cmd = new CreateVPCOfferingCmd();
+        HashMap<String, Map<String, String>> providers = new HashMap<String,
Map<String, String>>();
+        HashMap<String, String> kv = new HashMap<String, String>();
+        kv.put("service", "TEST-SERVICE");
+        kv.put("provider", "TEST-PROVIDER");
+        providers.put("does not matter", kv);
+        ApiCmdTestUtil.set(cmd, ApiConstants.SERVICE_PROVIDER_LIST, providers);
+        Map<String, List<String>> providerMap = cmd.getServiceProviders();
+        Assert.assertNotNull(providerMap);
+        Assert.assertEquals(1, providerMap.size());
+        Assert.assertTrue(providerMap.containsKey("TEST-SERVICE"));
+        Assert.assertTrue(providerMap.get("TEST-SERVICE").contains("TEST-PROVIDER"));
+    }
+
+    @Test
+    public void testServiceProvidersEmpty() throws IllegalArgumentException,
+            IllegalAccessException {
+        CreateVPCOfferingCmd cmd = new CreateVPCOfferingCmd();
+        ApiCmdTestUtil.set(cmd, ApiConstants.SERVICE_PROVIDER_LIST, new HashMap<String,
Map<String, String>>());
+        Assert.assertNull(cmd.getServiceProviders());
+    }
+
+    @Test
+    public void getDetailsNull() throws IllegalArgumentException,
+            IllegalAccessException {
+        CreateVPCOfferingCmd cmd = new CreateVPCOfferingCmd();
+        ApiCmdTestUtil.set(cmd, ApiConstants.SERVICE_PROVIDER_LIST, null);
+        Assert.assertNull(cmd.getServiceProviders());
+    }
+
+}


Mime
View raw message