org.wso2.carbon.registry.core.Collection Java Examples
The following examples show how to use
org.wso2.carbon.registry.core.Collection.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UserRealmProxy.java From carbon-identity with Apache License 2.0 | 6 votes |
private void buildUIPermissionNodeAllSelected(Collection parent, UIPermissionNode parentNode, Registry registry, Registry tenantRegistry) throws RegistryException, UserStoreException { String[] children = parent.getChildren(); UIPermissionNode[] childNodes = new UIPermissionNode[children.length]; for (int i = 0; i < children.length; i++) { String child = children[i]; Resource resource = null; if (registry.resourceExists(child)) { resource = registry.get(child); } else if (tenantRegistry != null) { resource = tenantRegistry.get(child); } else { throw new RegistryException("Permission resource not found in the registry."); } childNodes[i] = getUIPermissionNode(resource, true); if (resource instanceof Collection) { buildUIPermissionNodeAllSelected((Collection) resource, childNodes[i], registry, tenantRegistry); } } parentNode.setNodeList(childNodes); }
Example #2
Source File: SecurityMgtServiceComponent.java From carbon-identity-framework with Apache License 2.0 | 6 votes |
private void addKeystores() throws RegistryException { Registry registry = SecurityServiceHolder.getRegistryService().getGovernanceSystemRegistry(); try { boolean transactionStarted = Transaction.isStarted(); if (!transactionStarted) { registry.beginTransaction(); } if (!registry.resourceExists(SecurityConstants.KEY_STORES)) { Collection kstores = registry.newCollection(); registry.put(SecurityConstants.KEY_STORES, kstores); Resource primResource = registry.newResource(); if (!registry.resourceExists(RegistryResources.SecurityManagement.PRIMARY_KEYSTORE_PHANTOM_RESOURCE)) { registry.put(RegistryResources.SecurityManagement.PRIMARY_KEYSTORE_PHANTOM_RESOURCE, primResource); } } if (!transactionStarted) { registry.commitTransaction(); } } catch (Exception e) { registry.rollbackTransaction(); throw e; } }
Example #3
Source File: SAMLSSOServiceProviderDAO.java From carbon-identity-framework with Apache License 2.0 | 6 votes |
public SAMLSSOServiceProviderDO[] getServiceProviders() throws IdentityException { List<SAMLSSOServiceProviderDO> serviceProvidersList = new ArrayList<>(); try { if (registry.resourceExists(IdentityRegistryResources.SAML_SSO_SERVICE_PROVIDERS)) { Resource samlSSOServiceProvidersResource = registry.get(IdentityRegistryResources .SAML_SSO_SERVICE_PROVIDERS); if (samlSSOServiceProvidersResource instanceof Collection) { Collection samlSSOServiceProvidersCollection = (Collection) samlSSOServiceProvidersResource; String[] resources = samlSSOServiceProvidersCollection.getChildren(); for (String resource : resources) { getChildResources(resource, serviceProvidersList); } } } } catch (RegistryException e) { log.error("Error reading Service Providers from Registry", e); throw IdentityException.error("Error reading Service Providers from Registry", e); } return serviceProvidersList.toArray(new SAMLSSOServiceProviderDO[serviceProvidersList.size()]); }
Example #4
Source File: SAMLSSOServiceProviderDAO.java From carbon-identity-framework with Apache License 2.0 | 6 votes |
/** * This helps to find resources in a recursive manner. * * @param parentResource parent resource Name. * @param serviceProviderList child resource list. * @throws RegistryException */ private void getChildResources(String parentResource, List<SAMLSSOServiceProviderDO> serviceProviderList) throws RegistryException { if (registry.resourceExists(parentResource)) { Resource resource = registry.get(parentResource); if (resource instanceof Collection) { Collection collection = (Collection) resource; String[] resources = collection.getChildren(); for (String res : resources) { getChildResources(res, serviceProviderList); } } else { serviceProviderList.add(resourceToObject(resource)); } } }
Example #5
Source File: CloudServicesUtil.java From attic-stratos with Apache License 2.0 | 6 votes |
public static boolean isServiceNameValid(CloudServicesDescConfig cloudServicesDesc, String cloudServiceName) { if (cloudServiceName == null) { return false; } java.util.Collection<CloudServiceConfig> cloudServiceConfigList = cloudServicesDesc.getCloudServiceConfigs().values(); if (cloudServiceName.equals(StratosConstants.CLOUD_MANAGER_SERVICE)) { return false; } for (CloudServiceConfig cloudServiceConfig : cloudServiceConfigList) { if (cloudServiceConfig.getName().equals(cloudServiceName)) { return true; } } return false; }
Example #6
Source File: DefaultResourceFinder.java From carbon-identity-framework with Apache License 2.0 | 6 votes |
@Override public Set<String> findDescendantResources(String parentResourceId, EvaluationCtx context) throws Exception { Set<String> resourceSet = new HashSet<String>(); registry = EntitlementServiceComponent.getRegistryService().getSystemRegistry(CarbonContext. getThreadLocalCarbonContext().getTenantId()); if (registry.resourceExists(parentResourceId)) { Resource resource = registry.get(parentResourceId); if (resource instanceof Collection) { Collection collection = (Collection) resource; String[] resources = collection.getChildren(); for (String res : resources) { resourceSet.add(res); getChildResources(res, resourceSet); } } else { return null; } } return resourceSet; }
Example #7
Source File: UserRealmProxy.java From carbon-identity-framework with Apache License 2.0 | 6 votes |
private void buildUIPermissionNode(Collection parent, UIPermissionNode parentNode, Registry registry, Registry tenantRegistry, AuthorizationManager authMan, String roleName, String userName) throws RegistryException, UserStoreException { boolean isSelected = false; if (roleName != null) { isSelected = authMan.isRoleAuthorized(roleName, parentNode.getResourcePath(), UserMgtConstants.EXECUTE_ACTION); } else if (userName != null) { isSelected = authMan.isUserAuthorized(userName, parentNode.getResourcePath(), UserMgtConstants.EXECUTE_ACTION); } if (isSelected) { buildUIPermissionNodeAllSelected(parent, parentNode, registry, tenantRegistry); parentNode.setSelected(true); } else { buildUIPermissionNodeNotAllSelected(parent, parentNode, registry, tenantRegistry, authMan, roleName, userName); } }
Example #8
Source File: UserRealmProxy.java From carbon-identity-framework with Apache License 2.0 | 6 votes |
private void buildUIPermissionNodeAllSelected(Collection parent, UIPermissionNode parentNode, Registry registry, Registry tenantRegistry) throws RegistryException, UserStoreException { String[] children = parent.getChildren(); UIPermissionNode[] childNodes = new UIPermissionNode[children.length]; for (int i = 0; i < children.length; i++) { String child = children[i]; Resource resource = null; if (registry.resourceExists(child)) { resource = registry.get(child); } else if (tenantRegistry != null) { resource = tenantRegistry.get(child); } else { throw new RegistryException("Permission resource not found in the registry."); } childNodes[i] = getUIPermissionNode(resource, true); if (resource instanceof Collection) { buildUIPermissionNodeAllSelected((Collection) resource, childNodes[i], registry, tenantRegistry); } } parentNode.setNodeList(childNodes); }
Example #9
Source File: CarbonEntitlementDataFinder.java From carbon-identity-framework with Apache License 2.0 | 6 votes |
/** * This helps to find resources un a recursive manner * * @param node attribute value node * @param parentResource parent resource Name * @return child resource set * @throws RegistryException throws */ private EntitlementTreeNodeDTO getChildResources(EntitlementTreeNodeDTO node, String parentResource) throws RegistryException { if (registry.resourceExists(parentResource)) { String[] resourcePath = parentResource.split("/"); EntitlementTreeNodeDTO childNode = new EntitlementTreeNodeDTO(resourcePath[resourcePath.length - 1]); node.addChildNode(childNode); Resource root = registry.get(parentResource); if (root instanceof Collection) { Collection collection = (Collection) root; String[] resources = collection.getChildren(); for (String resource : resources) { getChildResources(childNode, resource); } } } return node; }
Example #10
Source File: RegistryTopicManager.java From carbon-commons with Apache License 2.0 | 6 votes |
/** * {@inheritDoc} */ @Override public TopicNode getTopicTree() throws EventBrokerException { try { UserRegistry userRegistry = this.registryService.getGovernanceSystemRegistry(EventBrokerHolder.getInstance().getTenantId()); if (!userRegistry.resourceExists(topicStoragePath)) { userRegistry.put(topicStoragePath, userRegistry.newCollection()); } Resource root = userRegistry.get(this.topicStoragePath); TopicNode rootTopic = new TopicNode("/", "/"); buildTopicTree(rootTopic, (Collection) root, userRegistry); return rootTopic; } catch (RegistryException e) { throw new EventBrokerException(e.getMessage(), e); } }
Example #11
Source File: RegistryDataManager.java From product-ei with Apache License 2.0 | 6 votes |
/** * Obtain the STS policy paths from registry * * @param registry * @return * @throws RegistryException */ private List<String> getSTSPolicyPaths(Registry registry) throws RegistryException { List<String> policyPaths = new ArrayList<>(); if (registry.resourceExists(Constant.SERVICE_GROUPS_PATH)) { Collection serviceGroups = (Collection) registry.get(Constant.SERVICE_GROUPS_PATH); if (serviceGroups != null) { for (String serviceGroupPath : serviceGroups.getChildren()) { if (StringUtils.isNotEmpty(serviceGroupPath) && serviceGroupPath.contains(Constant.STS_SERVICE_GROUP)) { String policyCollectionPath = new StringBuilder().append(serviceGroupPath) .append(Constant.SECURITY_POLICY_RESOURCE_PATH).toString(); Collection policies = (Collection) registry.get(policyCollectionPath); if (policies != null) { policyPaths.addAll(Arrays.asList(policies.getChildren())); } } } } } return policyPaths; }
Example #12
Source File: CloudServicesUtil.java From carbon-commons with Apache License 2.0 | 6 votes |
public static boolean isServiceNameValid(CloudServicesDescConfig cloudServicesDesc, String cloudServiceName) { if(cloudServiceName == null) { return false; } java.util.Collection<CloudServiceConfig> cloudServiceConfigList = cloudServicesDesc.getCloudServiceConfigs().values(); if (cloudServiceName.equals(StratosConstants.CLOUD_MANAGER_SERVICE)) { return false; } for (CloudServiceConfig cloudServiceConfig : cloudServiceConfigList) { if (cloudServiceConfig.getName().equals(cloudServiceName)) { return true; } } return false; }
Example #13
Source File: AbstractAPIManager.java From carbon-apimgt with Apache License 2.0 | 6 votes |
public Set<String> getAPIVersions(String providerName, String apiName) throws APIManagementException { Set<String> versionSet = new HashSet<String>(); String apiPath = APIConstants.API_LOCATION + RegistryConstants.PATH_SEPARATOR + providerName + RegistryConstants.PATH_SEPARATOR + apiName; try { Resource resource = registry.get(apiPath); if (resource instanceof Collection) { Collection collection = (Collection) resource; String[] versionPaths = collection.getChildren(); if (versionPaths == null || versionPaths.length == 0) { return versionSet; } for (String path : versionPaths) { versionSet.add(path.substring(apiPath.length() + 1)); } } else { throw new APIManagementException("API version must be a collection " + apiName); } } catch (RegistryException e) { String msg = "Failed to get versions for API: " + apiName; throw new APIManagementException(msg, e); } return versionSet; }
Example #14
Source File: DefaultResourceFinder.java From carbon-identity with Apache License 2.0 | 6 votes |
@Override public Set<String> findDescendantResources(String parentResourceId, EvaluationCtx context) throws Exception { Set<String> resourceSet = new HashSet<String>(); registry = EntitlementServiceComponent.getRegistryService().getSystemRegistry(CarbonContext. getThreadLocalCarbonContext().getTenantId()); if (registry.resourceExists(parentResourceId)) { Resource resource = registry.get(parentResourceId); if (resource instanceof Collection) { Collection collection = (Collection) resource; String[] resources = collection.getChildren(); for (String res : resources) { resourceSet.add(res); getChildResources(res, resourceSet); } } else { return null; } } return resourceSet; }
Example #15
Source File: UserRealmProxy.java From carbon-identity with Apache License 2.0 | 6 votes |
private void buildUIPermissionNode(Collection parent, UIPermissionNode parentNode, Registry registry, Registry tenantRegistry, AuthorizationManager authMan, String roleName, String userName) throws RegistryException, UserStoreException { boolean isSelected = false; if (roleName != null) { isSelected = authMan.isRoleAuthorized(roleName, parentNode.getResourcePath(), UserMgtConstants.EXECUTE_ACTION); } else if (userName != null) { isSelected = authMan.isUserAuthorized(userName, parentNode.getResourcePath(), UserMgtConstants.EXECUTE_ACTION); } if (isSelected) { buildUIPermissionNodeAllSelected(parent, parentNode, registry, tenantRegistry); parentNode.setSelected(true); } else { buildUIPermissionNodeNotAllSelected(parent, parentNode, registry, tenantRegistry, authMan, roleName, userName); } }
Example #16
Source File: RegistryRecoveryDataStore.java From carbon-identity with Apache License 2.0 | 6 votes |
private void deleteOldResourcesIfFound(Registry registry, String userName, String secretKeyPath) { try { if (registry.resourceExists(secretKeyPath.toLowerCase())) { Collection collection = (Collection) registry.get(secretKeyPath.toLowerCase()); String[] resources = collection.getChildren(); for (String resource : resources) { String[] splittedResource = resource.split("___"); if (splittedResource.length == 3) { //PRIMARY USER STORE if (resource.contains("___" + userName + "___")) { registry.delete(resource); } } else if (splittedResource.length == 2) { //SECONDARY USER STORE. Resource is a collection. deleteOldResourcesIfFound(registry, userName, resource); } } } } catch (RegistryException e) { log.error("Error while deleting the old confirmation code \n" + e); } }
Example #17
Source File: IdentityMgtServiceComponent.java From carbon-identity with Apache License 2.0 | 6 votes |
private static void init() { Registry registry; IdentityMgtConfig.getInstance(realmService.getBootstrapRealmConfiguration()); recoveryProcessor = new RecoveryProcessor(); try { registry = IdentityMgtServiceComponent.getRegistryService() .getConfigSystemRegistry(); if (!registry .resourceExists(IdentityMgtConstants.IDENTITY_MANAGEMENT_PATH)) { Collection questionCollection = registry.newCollection(); registry.put(IdentityMgtConstants.IDENTITY_MANAGEMENT_PATH, questionCollection); loadDefaultChallenges(); } } catch (RegistryException e) { log.error("Error while creating registry collection for org.wso2.carbon.identity.mgt component", e); } }
Example #18
Source File: AbstractAPIManagerTestCase.java From carbon-apimgt with Apache License 2.0 | 6 votes |
@Test public void testGetAllWsdls() throws RegistryException, APIManagementException { AbstractAPIManager abstractAPIManager = new AbstractAPIManagerWrapper(registry); Collection parentCollection = new CollectionImpl(); String wsdlResourcepath = APIConstants.API_WSDL_RESOURCE; String resourcePath = wsdlResourcepath + "/wsdl1"; parentCollection.setChildren(new String[] { resourcePath }); Mockito.when(registry.get(wsdlResourcepath)).thenReturn(parentCollection); Resource resource = new ResourceImpl(); Mockito.when(registry.get(resourcePath)).thenThrow(RegistryException.class).thenReturn(resource); Mockito.when(registry.resourceExists(wsdlResourcepath)).thenReturn(true); try { abstractAPIManager.getAllWsdls(); Assert.fail("Exception not thrown for error scenario"); } catch (APIManagementException e) { Assert.assertTrue(e.getMessage().contains("Failed to get wsdl list")); } resource.setUUID(SAMPLE_RESOURCE_ID); List<Wsdl> wsdls = abstractAPIManager.getAllWsdls(); Assert.assertNotNull(wsdls); Assert.assertEquals(wsdls.size(), 1); }
Example #19
Source File: SecurityDeploymentInterceptor.java From carbon-identity with Apache License 2.0 | 6 votes |
private void addKeystores() throws RegistryException { Registry registry = SecurityServiceHolder.getRegistryService().getGovernanceSystemRegistry(); try { boolean transactionStarted = Transaction.isStarted(); if (!transactionStarted) { registry.beginTransaction(); } if (!registry.resourceExists(SecurityConstants.KEY_STORES)) { Collection kstores = registry.newCollection(); registry.put(SecurityConstants.KEY_STORES, kstores); Resource primResource = registry.newResource(); if (!registry.resourceExists(RegistryResources.SecurityManagement.PRIMARY_KEYSTORE_PHANTOM_RESOURCE)) { registry.put(RegistryResources.SecurityManagement.PRIMARY_KEYSTORE_PHANTOM_RESOURCE, primResource); } } if (!transactionStarted) { registry.commitTransaction(); } } catch (Exception e) { registry.rollbackTransaction(); throw e; } }
Example #20
Source File: SequenceUtilsTestCase.java From carbon-apimgt with Apache License 2.0 | 6 votes |
public void testGetRestToSoapConvertedSequence() throws Exception { String provider = "admin"; String apiName = "test-api"; String version = "1.0.0"; String seqType = "in"; String resourceName = "test_get.xml"; Resource resource = Mockito.mock(Resource.class); ResourceImpl resourceImpl = Mockito.mock(ResourceImpl.class); Collection collection = Mockito.mock(Collection.class); String[] paths = new String[0]; byte[] content = new byte[1]; PowerMockito.when(MultitenantUtils.getTenantDomain(Mockito.anyString())).thenReturn("carbon.super"); PowerMockito.when(serviceReferenceHolder.getRegistryService()).thenReturn(registryService); Mockito.when(((Collection)userRegistry.get(Mockito.anyString()))).thenReturn(collection); Mockito.when(collection.getChildren()).thenReturn(paths); Mockito.when(userRegistry.get(Mockito.anyString())).thenReturn(resource); Mockito.when(resource.getContent()).thenReturn(content); Mockito.when(resourceImpl.getName()).thenReturn(resourceName); Mockito.when(tenantManager.getTenantId(Mockito.anyString())).thenReturn(-1); try { SequenceUtils.getRestToSoapConvertedSequence(apiName, version, provider, seqType); } catch (APIManagementException e) { Assert.fail("Failed to get the sequences from the registry"); } }
Example #21
Source File: SequenceUtilsTestCase.java From carbon-apimgt with Apache License 2.0 | 6 votes |
@Test public void testGetSequenceTemplateConfigContext() throws Exception { String seqType = "in_sequences"; String content = "<header description=\"SOAPAction\" name=\"SOAPAction\" scope=\"transport\"" + " value=\"http://ws.cdyne.com/PhoneVerify/query/CheckPhoneNumber\"/>"; Collection collection = new CollectionImpl(); ResourceImpl resource = new ResourceImpl(); resource.setName("checkPhoneNumber_post.xml"); collection.setChildren(new String[] { INSEQUENCE_RESOURCES + "checkPhoneNumber_post.xml" }); Mockito.when(userRegistry.resourceExists(INSEQUENCE_RESOURCES)).thenReturn(true); ConfigContext configContext = Mockito.mock(ConfigContext.class); Mockito.when(userRegistry.get(INSEQUENCE_RESOURCES)).thenReturn(collection); Mockito.when(userRegistry.get(INSEQUENCE_RESOURCES + "checkPhoneNumber_post.xml")).thenReturn(resource); PowerMockito.when(RegistryUtils.decodeBytes(Mockito.any(byte[].class))).thenReturn(content); try { ConfigContext context = SequenceUtils .getSequenceTemplateConfigContext(userRegistry, INSEQUENCE_RESOURCES, seqType, configContext); Assert.assertNotNull(context); } catch (RegistryException e) { Assert.fail("Failed to get the sequences from the registry"); } }
Example #22
Source File: DefaultPolicyDataStore.java From carbon-identity with Apache License 2.0 | 6 votes |
@Override public String getGlobalPolicyAlgorithmName() { Registry registry = EntitlementServiceComponent. getGovernanceRegistry(CarbonContext.getThreadLocalCarbonContext().getTenantId()); String algorithm = null; try { if (registry.resourceExists(policyDataCollection)) { Collection collection = (Collection) registry.get(policyDataCollection); algorithm = collection.getProperty("globalPolicyCombiningAlgorithm"); } } catch (RegistryException e) { if (log.isDebugEnabled()) { log.debug(e); } } // set default if (algorithm == null) { algorithm = "deny-overrides"; } return algorithm; }
Example #23
Source File: CarbonEntitlementDataFinder.java From carbon-identity with Apache License 2.0 | 6 votes |
/** * This helps to find resources un a recursive manner * * @param node attribute value node * @param parentResource parent resource Name * @return child resource set * @throws RegistryException throws */ private EntitlementTreeNodeDTO getChildResources(EntitlementTreeNodeDTO node, String parentResource) throws RegistryException { if (registry.resourceExists(parentResource)) { String[] resourcePath = parentResource.split("/"); EntitlementTreeNodeDTO childNode = new EntitlementTreeNodeDTO(resourcePath[resourcePath.length - 1]); node.addChildNode(childNode); Resource root = registry.get(parentResource); if (root instanceof Collection) { Collection collection = (Collection) root; String[] resources = collection.getChildren(); for (String resource : resources) { getChildResources(childNode, resource); } } } return node; }
Example #24
Source File: APIUtilTest.java From carbon-apimgt with Apache License 2.0 | 5 votes |
@Test public void testGetCustomSequenceNull() throws Exception { APIIdentifier apiIdentifier = Mockito.mock(APIIdentifier.class); ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class); RegistryService registryService = Mockito.mock(RegistryService.class); UserRegistry registry = Mockito.mock(UserRegistry.class); PowerMockito.mockStatic(ServiceReferenceHolder.class); Mockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder); Mockito.when(serviceReferenceHolder.getRegistryService()).thenReturn(registryService); Mockito.when(registryService.getGovernanceSystemRegistry(eq(1))).thenReturn(registry); Collection collection = Mockito.mock(Collection.class); String artifactPath = APIConstants.API_ROOT_LOCATION + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getProviderName() + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getApiName() + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getVersion(); String path = artifactPath + RegistryConstants.PATH_SEPARATOR + "custom" + RegistryConstants.PATH_SEPARATOR; Mockito.when(registry.get(eq(path))).thenReturn(null, null); String[] childPaths = {"test"}; Mockito.when(collection.getChildren()).thenReturn(childPaths); String expectedUUID = UUID.randomUUID().toString(); InputStream sampleSequence = new FileInputStream(Thread.currentThread().getContextClassLoader(). getResource("sampleSequence.xml").getFile()); Resource resource = Mockito.mock(Resource.class); Mockito.when(registry.get(eq("test"))).thenReturn(resource); Mockito.when(resource.getContentStream()).thenReturn(sampleSequence); Mockito.when(resource.getUUID()).thenReturn(expectedUUID); OMElement customSequence = APIUtil.getCustomSequence("sample", 1, "custom", apiIdentifier); Assert.assertNull(customSequence); sampleSequence.close(); }
Example #25
Source File: APIUtilTest.java From carbon-apimgt with Apache License 2.0 | 5 votes |
@Test public void testIsPerAPISequence() throws Exception { APIIdentifier apiIdentifier = Mockito.mock(APIIdentifier.class); ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class); RegistryService registryService = Mockito.mock(RegistryService.class); UserRegistry registry = Mockito.mock(UserRegistry.class); String artifactPath = APIConstants.API_ROOT_LOCATION + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getProviderName() + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getApiName() + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getVersion(); String path = artifactPath + RegistryConstants.PATH_SEPARATOR + "in" + RegistryConstants.PATH_SEPARATOR; PowerMockito.mockStatic(ServiceReferenceHolder.class); Mockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder); Mockito.when(serviceReferenceHolder.getRegistryService()).thenReturn(registryService); Mockito.when(registryService.getGovernanceSystemRegistry(eq(1))).thenReturn(registry); Mockito.when(registry.resourceExists(eq(path))).thenReturn(true); Collection collection = Mockito.mock(Collection.class); Mockito.when(registry.get(eq(path))).thenReturn(collection); String[] childPaths = {"test"}; Mockito.when(collection.getChildren()).thenReturn(childPaths); InputStream sampleSequence = new FileInputStream(Thread.currentThread().getContextClassLoader(). getResource("sampleSequence.xml").getFile()); Resource resource = Mockito.mock(Resource.class); Mockito.when(registry.get(eq("test"))).thenReturn(resource); Mockito.when(resource.getContentStream()).thenReturn(sampleSequence); boolean isPerAPiSequence = APIUtil.isPerAPISequence("sample", 1, apiIdentifier, "in"); Assert.assertTrue(isPerAPiSequence); }
Example #26
Source File: AbstractAPIManager.java From carbon-apimgt with Apache License 2.0 | 5 votes |
/** * Returns the mediation policy registry resource correspond to the given identifier * * @param mediationPolicyId uuid of the mediation resource * @return Registry resource of given identifier or null * @throws APIManagementException If failed to get the registry resource of given uuid */ @Override public Resource getCustomMediationResourceFromUuid(String mediationPolicyId) throws APIManagementException { String resourcePath = APIConstants.API_CUSTOM_SEQUENCE_LOCATION; try { Resource resource = registry.get(resourcePath); //resource : customsequences if (resource instanceof Collection) { Collection typeCollection = (Collection) resource; String[] typeArray = typeCollection.getChildren(); for (String type : typeArray) { Resource typeResource = registry.get(type); //typeResource: in/ out/ fault if (typeResource instanceof Collection) { String[] policyArray = ((Collection) typeResource).getChildren(); if (policyArray.length > 0) { for (String policy : policyArray) { Resource mediationResource = registry.get(policy); //mediationResource: eg .log_in_msg.xml String resourceId = mediationResource.getUUID(); if (resourceId.equals(mediationPolicyId)) { //If registry resource id matches given identifier returns that // registry resource return mediationResource; } } } } } } } catch (RegistryException e) { String msg = "Error while accessing registry objects"; throw new APIManagementException(msg, e); } return null; }
Example #27
Source File: APIUtilTest.java From carbon-apimgt with Apache License 2.0 | 5 votes |
@Test public void testGetCustomFaultSequence() throws Exception { APIIdentifier apiIdentifier = Mockito.mock(APIIdentifier.class); ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class); RegistryService registryService = Mockito.mock(RegistryService.class); UserRegistry registry = Mockito.mock(UserRegistry.class); PowerMockito.mockStatic(ServiceReferenceHolder.class); Mockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder); Mockito.when(serviceReferenceHolder.getRegistryService()).thenReturn(registryService); Mockito.when(registryService.getGovernanceSystemRegistry(eq(1))).thenReturn(registry); Collection collection = Mockito.mock(Collection.class); String artifactPath = APIConstants.API_ROOT_LOCATION + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getProviderName() + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getApiName() + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getVersion(); String path = artifactPath + RegistryConstants.PATH_SEPARATOR + "fault" + RegistryConstants.PATH_SEPARATOR; Mockito.when(registry.get(eq(path))).thenReturn(collection); String[] childPaths = {"test"}; Mockito.when(collection.getChildren()).thenReturn(childPaths); InputStream sampleSequence = new FileInputStream(Thread.currentThread().getContextClassLoader(). getResource("sampleSequence.xml").getFile()); Resource resource = Mockito.mock(Resource.class); Mockito.when(registry.get(eq("test"))).thenReturn(resource); Mockito.when(resource.getContentStream()).thenReturn(sampleSequence); OMElement customSequence = APIUtil.getCustomSequence("sample", 1, "fault", apiIdentifier); Assert.assertNotNull(customSequence); sampleSequence.close(); }
Example #28
Source File: APIUtilTest.java From carbon-apimgt with Apache License 2.0 | 5 votes |
@Test public void testGetCustomOutSequence() throws Exception { APIIdentifier apiIdentifier = Mockito.mock(APIIdentifier.class); ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class); RegistryService registryService = Mockito.mock(RegistryService.class); UserRegistry registry = Mockito.mock(UserRegistry.class); PowerMockito.mockStatic(ServiceReferenceHolder.class); Mockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder); Mockito.when(serviceReferenceHolder.getRegistryService()).thenReturn(registryService); Mockito.when(registryService.getGovernanceSystemRegistry(eq(1))).thenReturn(registry); Collection collection = Mockito.mock(Collection.class); String artifactPath = APIConstants.API_ROOT_LOCATION + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getProviderName() + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getApiName() + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getVersion(); String path = artifactPath + RegistryConstants.PATH_SEPARATOR + "out" + RegistryConstants.PATH_SEPARATOR; Mockito.when(registry.get(eq(path))).thenReturn(collection); String[] childPaths = {"test"}; Mockito.when(collection.getChildren()).thenReturn(childPaths); InputStream sampleSequence = new FileInputStream(Thread.currentThread().getContextClassLoader(). getResource("sampleSequence.xml").getFile()); Resource resource = Mockito.mock(Resource.class); Mockito.when(registry.get(eq("test"))).thenReturn(resource); Mockito.when(resource.getContentStream()).thenReturn(sampleSequence); OMElement customSequence = APIUtil.getCustomSequence("sample", 1, "out", apiIdentifier); Assert.assertNotNull(customSequence); sampleSequence.close(); }
Example #29
Source File: APIUtilTest.java From carbon-apimgt with Apache License 2.0 | 5 votes |
@Test public void testGetMediationSequenceUuidCustomSequenceNotFound() throws Exception { APIIdentifier apiIdentifier = Mockito.mock(APIIdentifier.class); ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class); RegistryService registryService = Mockito.mock(RegistryService.class); UserRegistry registry = Mockito.mock(UserRegistry.class); PowerMockito.mockStatic(ServiceReferenceHolder.class); Mockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder); Mockito.when(serviceReferenceHolder.getRegistryService()).thenReturn(registryService); Mockito.when(registryService.getGovernanceSystemRegistry(eq(1))).thenReturn(registry); Collection collection = Mockito.mock(Collection.class); String artifactPath = APIConstants.API_ROOT_LOCATION + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getProviderName() + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getApiName() + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getVersion(); String path = artifactPath + RegistryConstants.PATH_SEPARATOR + "custom" + RegistryConstants.PATH_SEPARATOR; Mockito.when(registry.get(eq(path))).thenReturn(null, collection); String[] childPaths = {"test"}; Mockito.when(collection.getChildren()).thenReturn(childPaths); String expectedUUID = UUID.randomUUID().toString(); InputStream sampleSequence = new FileInputStream(Thread.currentThread().getContextClassLoader(). getResource("sampleSequence.xml").getFile()); Resource resource = Mockito.mock(Resource.class); Mockito.when(registry.get(eq("test"))).thenReturn(resource); Mockito.when(resource.getContentStream()).thenReturn(sampleSequence); Mockito.when(resource.getUUID()).thenReturn(expectedUUID); String actualUUID = APIUtil.getMediationSequenceUuid("sample", 1, "custom", apiIdentifier); Assert.assertEquals(expectedUUID, actualUUID); sampleSequence.close(); }
Example #30
Source File: APIUtilTest.java From carbon-apimgt with Apache License 2.0 | 5 votes |
@Test public void testGetCustomSequenceNotFound() throws Exception { APIIdentifier apiIdentifier = Mockito.mock(APIIdentifier.class); ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class); RegistryService registryService = Mockito.mock(RegistryService.class); UserRegistry registry = Mockito.mock(UserRegistry.class); PowerMockito.mockStatic(ServiceReferenceHolder.class); Mockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder); Mockito.when(serviceReferenceHolder.getRegistryService()).thenReturn(registryService); Mockito.when(registryService.getGovernanceSystemRegistry(eq(1))).thenReturn(registry); Collection collection = Mockito.mock(Collection.class); String artifactPath = APIConstants.API_ROOT_LOCATION + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getProviderName() + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getApiName() + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getVersion(); String path = artifactPath + RegistryConstants.PATH_SEPARATOR + "custom" + RegistryConstants.PATH_SEPARATOR; Mockito.when(registry.get(eq(path))).thenReturn(null, collection); String[] childPaths = {"test"}; Mockito.when(collection.getChildren()).thenReturn(childPaths); String expectedUUID = UUID.randomUUID().toString(); InputStream sampleSequence = new FileInputStream(Thread.currentThread().getContextClassLoader(). getResource("sampleSequence.xml").getFile()); Resource resource = Mockito.mock(Resource.class); Mockito.when(registry.get(eq("test"))).thenReturn(resource); Mockito.when(resource.getContentStream()).thenReturn(sampleSequence); Mockito.when(resource.getUUID()).thenReturn(expectedUUID); OMElement customSequence = APIUtil.getCustomSequence("sample", 1, "custom", apiIdentifier); Assert.assertNotNull(customSequence); sampleSequence.close(); }