DataManager implements IDataManager, IInstanceListener { @Override public List<CallDescriptor> getMatchingPolicies(Api api) { return getMatchingPolicies(api, null); } DataManager(); @Override void addListener(IDataManagerListener listener); @Override void removeListener(IDataManagerListener listener); @Override void addListener(IDataManagerUsedBucketIdsListener listener); @Override void removeListener(IDataManagerUsedBucketIdsListener listener); void setManager(boolean manager); void init(); void destroy(); @Override void setCacheManager(ICacheManager cacheManager); @Override void reloadGateway(String ip); void setTopologyClient(ITopologyClient topologyClient); @Override Set<String> getAllApiIds(); @Override boolean isApiExist(String apiId); @Override void addApi(Api api); @Override boolean endpointExists(String endpoint); @Override void updateApi(Api api); @Override void removeApi(String id); @Override Api getApiById(String id); @Override Api getApiById(String id, boolean getFullDetails); @Override Set<String> getAllAuthIds(); @Override void addAuth(Auth auth); @Override void updateAuth(Auth auth); @Override void removeAuth(String id); @Override Auth getAuthById(String id); @Override Auth getAuthById(String id, boolean getFullDetails); @Override Auth getAuthByAuthKey(String authKey); @Override Auth getAuthByOAuth(String clientId, String clientSecret); @Override Auth getAuthByUserPass(String username, String password); @Override Auth getWsseAuth(String username, String password, boolean isPasswordText, String nonce, String created); @Override Auth getAuthByIP(String ip); @Override Auth getAuthMatching(IAuthMatcher authMatcher); @Override Set<String> getAllPolicy(); @Override void addPolicy(Policy policy); @Override void updatePolicy(Policy policy); @Override void removePolicy(String id); @Override Policy getPolicyById(String id); @Override Policy getPolicyById(String id, boolean getFullDetails); @Override void createBucket(String policyId, QuotaRLBucket bucket); @Override void addAuthsToBucket(String policyId, String bucketId, QuotaRLBucket bucket); @Override void addAuthsToBucket(List<String> policyIds, String bucketId, QuotaRLBucket authIds); @Override void appendAuthsToBucket(List<String> policyIds, String bucketId, QuotaRLBucket authIds); @Override void removeAuthFromBucket(String policyId, String bucketId, String authId); @Override void removeAuthsFromBucket(List<String> policyIds, String bucketId, List<String> authIds); @Override void removeBucket(String policyId, String bucketId); @Override void removeBucket(List<String> policyIds, String bucketId); @Override List<CallDescriptor> getMatchingPolicies(Api api); @Override List<CallDescriptor> getMatchingPolicies(Api api, Auth auth); @Override APIContext getApiContextById(Integer id); @Override Context getPolicyContextById(Integer id); @Override void fillLimitsById(Integer contextId, Limit limit); @Override void putSettingString(String key, String value); @Override void clearSettingString(String key); @Override String getSettingString(String key); @Override void addKey(Key key); @Override Set<String> getAllKeyIds(); @Override Key getKeyById(String id); @Override Key getKeyById(String id, boolean getFullDetails); @Override void updateKey(Key key); @Override void removeKey(String id); @Override void addCert(Certificate cert); @Override Set<String> getAllCertIds(); @Override Set<String> getAllCertIdsForKeyId(String keyId); @Override Certificate getCertById(String id); @Override Certificate getCertById(String id, boolean getFullDetails); @Override void updateCert(Certificate cert); @Override void removeCert(String id); @Override Key generateKey(String id); @Override CertificateRequest getCSR(String keyId); @Override Certificate selfSignKey(String keyId, CertificateRequest csr); @Override void addKeyListener(IEntryListener<String, Key> listener); @Override void removeKeyListener(IEntryListener<String, Key> listener); void setCachedLogLevel(String key, LogLevel level); void clearCachedLogLevel(String key); LogLevel getCachedLogLevel(String key); @Override void addLogLevelListener(IEntryListener<String, LogLevel> listener); @Override void removeLogLevelListener(IEntryListener<String, LogLevel> listener); void setCachedLoggingCategory(Category category, boolean enabled); void clearCachedLoggingCategory(Category category); boolean getCachedLoggingCategory(Category category); @Override boolean deployApi(String apiId, byte[] jarData); @Override ApiJar getApiJar(String apiId); @Override boolean undeployApi(String apiId); @Override void addApiDeploymentListener(IEntryListener<String, ApiJar> listener); @Override void removeApiDeploymentListener(IEntryListener<String, ApiJar> listener); @Override void instanceAdded(InstanceEvent event); @Override void instanceRemoved(InstanceEvent event); @Override void setLogLevel(LogLevel level); @Override LogLevel getLogLevel(); @Override void setSMXLogLevel(LogLevel level); @Override LogLevel getSMXLogLevel(); @Override void setSyslogLevel(LogLevel level); @Override LogLevel getSyslogLevel(); @Override void setLoggingCategory(Category category, boolean enabled); @Override boolean getLoggingCategory(Category category); @Override Set<String> getAllCA(); @Override void addCA(Certificate cert); @Override Certificate getCAById(String id); @Override void updateCA(Certificate cert); @Override void removeCA(String id); @Override void addCAListener(IEntryListener<String, Certificate> listener); @Override void removeCAListener(IEntryListener<String, Certificate> listener); @Override void addCRL(SSLCRL clr); @Override SSLCRL getCRLById(String id); @Override void updateCRL(SSLCRL crl); @Override void removeCRL(String id); @Override Collection<SSLCRL> getAllCRLValues(); @Override Set<String> getAllCRL(); @Override void addCrlListener(IEntryListener<String,SSLCRL> listener); @Override void removeCrlListener(IEntryListener<String,SSLCRL> listener); @SuppressWarnings("unchecked") void setCachingTableApiDetails(ICacheTable<K, V> iCacheTable); @SuppressWarnings("unchecked") void setCachingTableAuthDetails(ICacheTable<K, V> iCacheTable); @SuppressWarnings("unchecked") void setCachingTableAuthIdToAuthToken(ICacheTable<K, V> iCacheTable); @SuppressWarnings("unchecked") void setCachingTableKeyDetails(ICacheTable<K, V> iCacheTable); @SuppressWarnings("unchecked") void setCachingTableCertificateDetails(ICacheTable<K, V> iCacheTable); @SuppressWarnings("unchecked") void setCachingTableCADetails(ICacheTable<K, V> iCacheTable); @SuppressWarnings("unchecked") void setCachingTableApi(ICacheTable<K, V> iCacheTable); @SuppressWarnings("unchecked") void setCachingTableAuth(ICacheTable<K, V> iCacheTable); @SuppressWarnings("unchecked") void setCachingTableAuthIpAddress(ICacheTable<K, V> iCacheTable); @SuppressWarnings("unchecked") void setCachingTablePolicy(ICacheTable<K, V> iCacheTable); @SuppressWarnings("unchecked") void setCachingTableContext(ICacheTable<K, V> iCacheTable); @SuppressWarnings("unchecked") void setCachingTableSettings(ICacheTable<K, V> iCacheTable); @SuppressWarnings("unchecked") void setCachingTableKey(ICacheTable<K, V> iCacheTable); @SuppressWarnings("unchecked") void setCachingTableCertificate(ICacheTable<K, V> iCacheTable); @SuppressWarnings("unchecked") void setCachingTableLogLevel(ICacheTable<K, V> iCacheTable); @SuppressWarnings("unchecked") void setCachingTableCA(ICacheTable<K, V> iCacheTable); @SuppressWarnings("unchecked") void setCachingTableCRL(ICacheTable<K, V> iCacheTable); @SuppressWarnings("unchecked") void setCachingTableApiJars(ICacheTable<K, V> iCacheTable); void setListeners(Set<IDataManagerListener> listeners); void setUsedBucketIds(Set<Integer> usedBucketIds); @Override void addApiListener(IEntryListener<String, Api> listener); @Override void removeApiListener(IEntryListener<String, Api> listener); @Override boolean isIpAllowed(Api api, String ip); @Override void addGlobalProxyListener3(IEntryListener<String, String> listener); @Override void removeGlobalProxyListener3(IEntryListener<String, String> listener);  }
@Test public void testGetMatchingPolicies() { Api api = new Api(); api.setApiDetail(new ApiDetail()); api.setId("id31"); dataManager.addApi(api); Api api2 = new Api(); api2.setApiDetail(new ApiDetail()); api2.setId("id32"); dataManager.addApi(api2); Api api3 = new Api(); api3.setApiDetail(new ApiDetail()); api3.setId("id33"); dataManager.addApi(api3); Api api4 = new Api(); api4.setApiDetail(new ApiDetail()); api4.setId("id34"); dataManager.addApi(api4); Auth auth = new Auth(); auth.setId("id31"); auth.setStatus(StatusType.ACTIVE); AuthDetail detail = new AuthDetail(); auth.setAuthDetail(detail); auth.getAuthDetail().setType(NBAuthType.AUTHKEY); auth.getAuthDetail().setAuthKeyValue("authKey31"); dataManager.addAuth(auth); Auth auth2 = new Auth(); auth2.setId("id32"); auth2.setStatus(StatusType.ACTIVE); AuthDetail detail2 = new AuthDetail(); auth2.setAuthDetail(detail2); auth2.getAuthDetail().setType(NBAuthType.AUTHKEY); auth2.getAuthDetail().setAuthKeyValue("authKey32"); dataManager.addAuth(auth2); Auth auth3 = new Auth(); auth3.setId("id33"); auth3.setStatus(StatusType.ACTIVE); AuthDetail detail3 = new AuthDetail(); auth3.setAuthDetail(detail3); auth3.getAuthDetail().setType(NBAuthType.AUTHKEY); auth3.getAuthDetail().setAuthKeyValue("authKey33"); dataManager.addAuth(auth3); Auth auth4 = new Auth(); auth4.setId("id34"); auth4.setStatus(StatusType.ACTIVE); AuthDetail detail4 = new AuthDetail(); auth4.setAuthDetail(detail4); auth4.getAuthDetail().setType(NBAuthType.BASIC); auth4.getAuthDetail().setUsername("user1"); auth4.getAuthDetail().setPassword(new byte[]{'p', 'a', 's', 's', '1'}); dataManager.addAuth(auth4); Policy policy = new Policy(); policy.setId("id31"); policy.getApiIds().add(api.getId()); QuotaRLBucket authIds = new QuotaRLBucket(); authIds.setId("bucketId"); authIds.getAuthIds().add(auth.getId()); policy.getAuthIds().add(authIds); dataManager.addPolicy(policy); Policy policy2 = new Policy(); policy2.setId("id32"); policy2.getApiIds().add(api2.getId()); policy2.getApiIds().add(api3.getId()); QuotaRLBucket authIds2 = new QuotaRLBucket(); authIds.setId("bucketId2"); authIds2.getAuthIds().add(auth2.getId()); authIds2.getAuthIds().add(auth4.getId()); policy2.getAuthIds().add(authIds2); dataManager.addPolicy(policy2); Policy policy3 = new Policy(); policy3.setId("id33"); policy3.getApiIds().add(api4.getId()); dataManager.addPolicy(policy3); Policy policy4 = new Policy(); policy4.setId("id34"); QuotaRLBucket authIds4 = new QuotaRLBucket(); authIds.setId("bucketId4"); authIds4.getAuthIds().add(auth3.getId()); policy4.getAuthIds().add(authIds4); dataManager.addPolicy(policy4); Policy policy5 = new Policy(); policy5.setId("id35"); policy5.getApiIds().add(api3.getId()); dataManager.addPolicy(policy5); Policy policy6 = new Policy(); policy6.setId("id36"); policy6.getApiIds().add(api3.getId()); QuotaRLBucket authIds6 = new QuotaRLBucket(); authIds.setId("bucketId6"); authIds6.getAuthIds().add(auth3.getId()); policy6.getAuthIds().add(authIds6); dataManager.addPolicy(policy6); Policy policy7 = new Policy(); policy7.setId("id37"); QuotaRLBucket authIds7 = new QuotaRLBucket(); authIds.setId("bucketId7"); authIds7.getAuthIds().add(auth2.getId()); policy7.getAuthIds().add(authIds7); dataManager.addPolicy(policy7); api = dataManager.getApiById(api.getId()); api2 = dataManager.getApiById(api2.getId()); api3 = dataManager.getApiById(api3.getId()); api4 = dataManager.getApiById(api4.getId()); auth = dataManager.getAuthById(auth.getId()); auth2 = dataManager.getAuthById(auth2.getId()); auth3 = dataManager.getAuthById(auth3.getId()); auth4 = dataManager.getAuthById(auth4.getId()); List<CallDescriptor> list1 = dataManager.getMatchingPolicies(api, auth); assertEquals("List1 has correct size", 1, list1.size()); assertEquals("Matching policy is correct", policy.getId(), list1.get(0).getPolicy().getId()); List<CallDescriptor> list2 = dataManager.getMatchingPolicies(api2, auth2); assertEquals("List2 has correct size", 2, list2.size()); assertEquals("Matching policy is correct", policy2.getId(), list2.get(0).getPolicy().getId()); assertEquals("Matching policy is correct", policy7.getId(), list2.get(1).getPolicy().getId()); List<CallDescriptor> list3 = dataManager.getMatchingPolicies(api3, null); assertEquals("List3 has correct size", 1, list3.size()); assertEquals("Matching policy is correct", policy5.getId(), list3.get(0).getPolicy().getId()); List<CallDescriptor> list4 = dataManager.getMatchingPolicies(null, auth3); assertEquals("List4 has correct size", 1, list4.size()); assertEquals("Matching policy is correct", policy4.getId(), list4.get(0).getPolicy().getId()); List<CallDescriptor> list5 = dataManager.getMatchingPolicies(api4, auth3); assertEquals("List5 has correct size", 1, list5.size()); assertEquals("Matching policy is correct", policy4.getId(), list5.get(0).getPolicy().getId()); List<CallDescriptor> list6 = dataManager.getMatchingPolicies(api4, auth4); assertNull("List6 has correct size", list6); List<CallDescriptor> list7 = dataManager.getMatchingPolicies(null, null); assertNull("List7 has correct size", list7); dataManager.removePolicy(policy.getId()); dataManager.removePolicy(policy2.getId()); dataManager.removePolicy(policy3.getId()); dataManager.removePolicy(policy4.getId()); dataManager.removePolicy(policy5.getId()); dataManager.removePolicy(policy6.getId()); dataManager.removePolicy(policy7.getId()); dataManager.removeApi(api.getId()); dataManager.removeApi(api2.getId()); dataManager.removeApi(api3.getId()); dataManager.removeApi(api4.getId()); dataManager.removeAuth(auth.getId()); dataManager.removeAuth(auth2.getId()); dataManager.removeAuth(auth3.getId()); dataManager.removeAuth(auth4.getId()); }