cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject git commit: updated refs/heads/master to c61997f
Date Mon, 30 Sep 2013 11:09:24 GMT
Updated Branches:
  refs/heads/master b7e00d370 -> c61997f02


basic test for ApiDispatcher

Signed-off-by: Laszlo Hornyak <laszlo.hornyak@gmail.com>


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

Branch: refs/heads/master
Commit: c61997f022b6064eab39ca911434dc626944a28a
Parents: b7e00d3
Author: Laszlo Hornyak <laszlo.hornyak@gmail.com>
Authored: Tue Sep 24 23:01:30 2013 +0200
Committer: Daan Hoogland <dhoogland@schubergphilis.com>
Committed: Mon Sep 30 13:08:15 2013 +0200

----------------------------------------------------------------------
 .../apache/cloudstack/context/CallContext.java  |  2 +-
 .../test/com/cloud/api/ApiDispatcherTest.java   | 90 ++++++++++++++++++++
 2 files changed, 91 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c61997f0/api/src/org/apache/cloudstack/context/CallContext.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/context/CallContext.java b/api/src/org/apache/cloudstack/context/CallContext.java
index a62a3da..114f626 100644
--- a/api/src/org/apache/cloudstack/context/CallContext.java
+++ b/api/src/org/apache/cloudstack/context/CallContext.java
@@ -37,7 +37,7 @@ import com.cloud.utils.exception.CloudRuntimeException;
  */
 public class CallContext {
     private static final Logger s_logger = Logger.getLogger(CallContext.class);
-    private static ThreadLocal<CallContext> s_currentContext = new ThreadLocal<CallContext>();
+    private static final ThreadLocal<CallContext> s_currentContext = new ThreadLocal<CallContext>();
 
     private String contextId;
     private Account account;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c61997f0/server/test/com/cloud/api/ApiDispatcherTest.java
----------------------------------------------------------------------
diff --git a/server/test/com/cloud/api/ApiDispatcherTest.java b/server/test/com/cloud/api/ApiDispatcherTest.java
new file mode 100644
index 0000000..9d54aaa
--- /dev/null
+++ b/server/test/com/cloud/api/ApiDispatcherTest.java
@@ -0,0 +1,90 @@
+package com.cloud.api;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.cloudstack.api.BaseCmd;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.context.CallContext;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+
+import com.cloud.exception.ConcurrentOperationException;
+import com.cloud.exception.InsufficientCapacityException;
+import com.cloud.exception.NetworkRuleConflictException;
+import com.cloud.exception.ResourceAllocationException;
+import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.user.Account;
+import com.cloud.user.AccountManager;
+import com.cloud.user.User;
+
+@RunWith(MockitoJUnitRunner.class)
+public class ApiDispatcherTest {
+
+    @Mock
+    AccountManager accountManager;
+    
+    public static class TestCmd extends BaseCmd {
+
+        @Parameter(name = "strparam1")
+        String strparam1;
+        
+        @Parameter(name="intparam1", type=CommandType.INTEGER)
+        int intparam1;
+
+        @Parameter(name="boolparam1", type=CommandType.BOOLEAN)
+        boolean boolparam1;
+
+        @Override
+        public void execute() throws ResourceUnavailableException,
+                InsufficientCapacityException, ServerApiException,
+                ConcurrentOperationException, ResourceAllocationException,
+                NetworkRuleConflictException {
+            // well documented nothing
+        }
+
+        @Override
+        public String getCommandName() {
+            return "test";
+        }
+
+        @Override
+        public long getEntityOwnerId() {
+            return 0;
+        }
+
+    }
+
+    @Before
+    public void setup() {
+        CallContext.register(Mockito.mock(User.class), Mockito.mock(Account.class));
+        new ApiDispatcher().init();
+        ApiDispatcher.getInstance()._accountMgr = accountManager;
+    }
+    
+    @After
+    public void cleanup() {
+        CallContext.unregister();
+    }
+
+    @Test
+    public void processParameters() {
+        HashMap<String, String> params = new HashMap<String, String>();
+        params.put("strparam1", "foo");
+        params.put("intparam1", "100");
+        params.put("boolparam1", "true");
+        TestCmd cmd = new TestCmd();
+        //how lucky that field is not protected, this test would be impossible
+        ApiDispatcher.processParameters(cmd, params);
+        Assert.assertEquals("foo", cmd.strparam1);
+        Assert.assertEquals(100, cmd.intparam1);
+    }
+
+}


Mime
View raw message