You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by bh...@apache.org on 2013/02/06 15:40:13 UTC
git commit: refs/heads/4.1 - ApiDiscovery: Fix tests and make
constructor light weight, let spring run init()
Updated Branches:
refs/heads/4.1 2ce6b80a2 -> 4d9056c2f
ApiDiscovery: Fix tests and make constructor light weight, let spring run init()
Signed-off-by: Rohit Yadav <bh...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/4d9056c2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/4d9056c2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/4d9056c2
Branch: refs/heads/4.1
Commit: 4d9056c2fe9a2a9b2d65c46995fc29f85c5283c1
Parents: 2ce6b80
Author: Rohit Yadav <bh...@apache.org>
Authored: Wed Feb 6 20:07:27 2013 +0530
Committer: Rohit Yadav <bh...@apache.org>
Committed: Wed Feb 6 20:09:15 2013 +0530
----------------------------------------------------------------------
.../discovery/ApiDiscoveryServiceImpl.java | 14 +++++++----
.../cloudstack/discovery/ApiDiscoveryTest.java | 18 ++++++++++-----
2 files changed, 21 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/4d9056c2/plugins/api/discovery/src/org/apache/cloudstack/discovery/ApiDiscoveryServiceImpl.java
----------------------------------------------------------------------
diff --git a/plugins/api/discovery/src/org/apache/cloudstack/discovery/ApiDiscoveryServiceImpl.java b/plugins/api/discovery/src/org/apache/cloudstack/discovery/ApiDiscoveryServiceImpl.java
index e3bc4d3..087b166 100644
--- a/plugins/api/discovery/src/org/apache/cloudstack/discovery/ApiDiscoveryServiceImpl.java
+++ b/plugins/api/discovery/src/org/apache/cloudstack/discovery/ApiDiscoveryServiceImpl.java
@@ -24,6 +24,7 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
+import javax.annotation.PostConstruct;
import javax.ejb.Local;
import javax.inject.Inject;
@@ -54,13 +55,16 @@ import com.google.gson.annotations.SerializedName;
public class ApiDiscoveryServiceImpl implements ApiDiscoveryService {
private static final Logger s_logger = Logger.getLogger(ApiDiscoveryServiceImpl.class);
- @Inject protected List<APIChecker> s_apiAccessCheckers = null;
+ @Inject protected List<APIChecker> _apiAccessCheckers = null;
+ @Inject protected List<PluggableService> _services = null;
private static Map<String, ApiDiscoveryResponse> s_apiNameDiscoveryResponseMap = null;
- @Inject List<PluggableService> _services;
-
protected ApiDiscoveryServiceImpl() {
super();
+ }
+
+ @PostConstruct
+ void init() {
if (s_apiNameDiscoveryResponseMap == null) {
long startTime = System.nanoTime();
s_apiNameDiscoveryResponseMap = new HashMap<String, ApiDiscoveryResponse>();
@@ -182,7 +186,7 @@ public class ApiDiscoveryServiceImpl implements ApiDiscoveryService {
if (!s_apiNameDiscoveryResponseMap.containsKey(name))
return null;
- for (APIChecker apiChecker : s_apiAccessCheckers) {
+ for (APIChecker apiChecker : _apiAccessCheckers) {
try {
apiChecker.checkAccess(user, name);
} catch (Exception ex) {
@@ -194,7 +198,7 @@ public class ApiDiscoveryServiceImpl implements ApiDiscoveryService {
} else {
for (String apiName : s_apiNameDiscoveryResponseMap.keySet()) {
boolean isAllowed = true;
- for (APIChecker apiChecker : s_apiAccessCheckers) {
+ for (APIChecker apiChecker : _apiAccessCheckers) {
try {
apiChecker.checkAccess(user, apiName);
} catch (Exception ex) {
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/4d9056c2/plugins/api/discovery/test/org/apache/cloudstack/discovery/ApiDiscoveryTest.java
----------------------------------------------------------------------
diff --git a/plugins/api/discovery/test/org/apache/cloudstack/discovery/ApiDiscoveryTest.java b/plugins/api/discovery/test/org/apache/cloudstack/discovery/ApiDiscoveryTest.java
index 3b526dd..320d20a 100644
--- a/plugins/api/discovery/test/org/apache/cloudstack/discovery/ApiDiscoveryTest.java
+++ b/plugins/api/discovery/test/org/apache/cloudstack/discovery/ApiDiscoveryTest.java
@@ -22,6 +22,7 @@ import com.cloud.user.UserVO;
import java.util.*;
import javax.naming.ConfigurationException;
+import com.cloud.utils.component.PluggableService;
import org.apache.cloudstack.acl.APIChecker;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.command.user.discovery.ListApisCmd;
@@ -35,9 +36,9 @@ import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
public class ApiDiscoveryTest {
-
- private static ApiDiscoveryServiceImpl _discoveryService = new ApiDiscoveryServiceImpl();
private static APIChecker _apiChecker = mock(APIChecker.class);
+ private static PluggableService _pluggableService = mock(PluggableService.class);
+ private static ApiDiscoveryServiceImpl _discoveryService = new ApiDiscoveryServiceImpl();
private static Class<?> testCmdClass = ListApisCmd.class;
private static User testUser;
@@ -54,13 +55,18 @@ public class ApiDiscoveryTest {
testApiAsync = false;
testUser = new UserVO();
+ _discoveryService._apiAccessCheckers = (List<APIChecker>) mock(List.class);
+ _discoveryService._services = (List<PluggableService>) mock(List.class);
+
+ when(_apiChecker.checkAccess(any(User.class), anyString())).thenReturn(true);
+ when(_pluggableService.getCommands()).thenReturn(new ArrayList<Class<?>>());
+ when(_discoveryService._apiAccessCheckers.iterator()).thenReturn(Arrays.asList(_apiChecker).iterator());
+ when(_discoveryService._services.iterator()).thenReturn(Arrays.asList(_pluggableService).iterator());
+
Set<Class<?>> cmdClasses = new HashSet<Class<?>>();
cmdClasses.add(ListApisCmd.class);
+ _discoveryService.init();
_discoveryService.cacheResponseMap(cmdClasses);
- _discoveryService.s_apiAccessCheckers = (List<APIChecker>) mock(List.class);
-
- when(_apiChecker.checkAccess(any(User.class), anyString())).thenReturn(true);
- when(_discoveryService.s_apiAccessCheckers.iterator()).thenReturn(Arrays.asList(_apiChecker).iterator());
}
@Test