Java Code Examples for org.wso2.carbon.registry.core.RegistryConstants#PATH_SEPARATOR
The following examples show how to use
org.wso2.carbon.registry.core.RegistryConstants#PATH_SEPARATOR .
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: AbstractAPIManager.java From carbon-apimgt with Apache License 2.0 | 6 votes |
/** * get the thumbnailLastUpdatedTime for a thumbnail for a given api * * @param apiIdentifier * @return * @throws APIManagementException */ @Override public String getThumbnailLastUpdatedTime(APIIdentifier apiIdentifier) throws APIManagementException { String artifactPath = APIConstants.API_IMAGE_LOCATION + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getProviderName() + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getApiName() + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getVersion(); String thumbPath = artifactPath + RegistryConstants.PATH_SEPARATOR + APIConstants.API_ICON_IMAGE; try { if (registry.resourceExists(thumbPath)) { Resource res = registry.get(thumbPath); Date lastModifiedTime = res.getLastModified(); return lastModifiedTime == null ? String.valueOf(res.getCreatedTime().getTime()) : String.valueOf(lastModifiedTime.getTime()); } } catch (RegistryException e) { String msg = "Error while loading API icon from the registry"; throw new APIManagementException(msg, e); } return null; }
Example 2
Source File: ApplicationManagementServiceImpl.java From carbon-identity-framework with Apache License 2.0 | 6 votes |
private void updateApplicationPermissions(ServiceProvider updatedApp, String updatedAppName, String storedAppName) throws RegistryException, IdentityApplicationManagementException { String applicationNode = ApplicationMgtUtil.getApplicationPermissionPath() + RegistryConstants .PATH_SEPARATOR + storedAppName; org.wso2.carbon.registry.api.Registry tenantGovReg = CarbonContext.getThreadLocalCarbonContext() .getRegistry(RegistryType.USER_GOVERNANCE); boolean exist = tenantGovReg.resourceExists(applicationNode); if (exist && !StringUtils.equals(storedAppName, updatedAppName)) { ApplicationMgtUtil.renameAppPermissionPathNode(storedAppName, updatedAppName); } if (updatedApp.getPermissionAndRoleConfig() != null && ArrayUtils.isNotEmpty(updatedApp.getPermissionAndRoleConfig().getPermissions())) { ApplicationMgtUtil.updatePermissions(updatedAppName, updatedApp.getPermissionAndRoleConfig().getPermissions()); } }
Example 3
Source File: AbstractAPIManager.java From carbon-apimgt with Apache License 2.0 | 6 votes |
public String addResourceFile(Identifier identifier, String resourcePath, ResourceFile resourceFile) throws APIManagementException { try { Resource thumb = registry.newResource(); thumb.setContentStream(resourceFile.getContent()); thumb.setMediaType(resourceFile.getContentType()); registry.put(resourcePath, thumb); if (MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equalsIgnoreCase(tenantDomain)) { return RegistryConstants.PATH_SEPARATOR + "registry" + RegistryConstants.PATH_SEPARATOR + "resource" + RegistryConstants.PATH_SEPARATOR + "_system" + RegistryConstants.PATH_SEPARATOR + "governance" + resourcePath; } else { return "/t/" + tenantDomain + RegistryConstants.PATH_SEPARATOR + "registry" + RegistryConstants.PATH_SEPARATOR + "resource" + RegistryConstants.PATH_SEPARATOR + "_system" + RegistryConstants.PATH_SEPARATOR + "governance" + resourcePath; } } catch (RegistryException e) { String msg = "Error while adding the resource to the registry"; throw new APIManagementException(msg, e); } }
Example 4
Source File: PolicyPublisher.java From carbon-identity with Apache License 2.0 | 6 votes |
public void deleteSubscriber(String subscriberId) throws EntitlementException { String subscriberPath; if (subscriberId == null) { log.error("Subscriber Id can not be null"); throw new EntitlementException("Subscriber Id can not be null"); } if (EntitlementConstants.PDP_SUBSCRIBER_ID.equals(subscriberId.trim())) { log.error("Can not delete PDP publisher"); throw new EntitlementException("Can not delete PDP publisher"); } try { subscriberPath = PDPConstants.ENTITLEMENT_POLICY_PUBLISHER + RegistryConstants.PATH_SEPARATOR + subscriberId; if (registry.resourceExists(subscriberPath)) { registry.delete(subscriberPath); } } catch (RegistryException e) { log.error("Error while deleting subscriber details", e); throw new EntitlementException("Error while deleting subscriber details", e); } }
Example 5
Source File: AbstractAPIManagerTestCase.java From carbon-apimgt with Apache License 2.0 | 6 votes |
@Test public void testIsAPIProductAvailable() throws RegistryException, APIManagementException { APIProductIdentifier apiProductIdentifier = getAPIProductIdentifier(SAMPLE_API_NAME, API_PROVIDER, SAMPLE_API_VERSION); String path = APIConstants.API_ROOT_LOCATION + RegistryConstants.PATH_SEPARATOR + apiProductIdentifier.getProviderName() + RegistryConstants.PATH_SEPARATOR + apiProductIdentifier.getName() + RegistryConstants.PATH_SEPARATOR + apiProductIdentifier.getVersion(); Mockito.when(registry.resourceExists(path)).thenThrow(RegistryException.class).thenReturn(true); AbstractAPIManager abstractAPIManager = new AbstractAPIManagerWrapper(registry); try { abstractAPIManager.isAPIProductAvailable(apiProductIdentifier); Assert.fail("Exception not thrown for error scenario"); } catch (APIManagementException e) { Assert.assertTrue(e.getMessage().contains("Failed to check availability of API Product")); } Assert.assertTrue(abstractAPIManager.isAPIProductAvailable(apiProductIdentifier)); }
Example 6
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 7
Source File: AbstractAPIManager.java From carbon-apimgt with Apache License 2.0 | 5 votes |
/** * Checks whether the given document already exists for the given api/product * * @param identifier API/Product Identifier * @param docName Name of the document * @return true if document already exists for the given api/product * @throws APIManagementException if failed to check existence of the documentation */ public boolean isDocumentationExist(Identifier identifier, String docName) throws APIManagementException { String docPath = ""; docPath = APIConstants.API_ROOT_LOCATION + RegistryConstants.PATH_SEPARATOR + identifier.getProviderName() + RegistryConstants.PATH_SEPARATOR + identifier.getName() + RegistryConstants.PATH_SEPARATOR + identifier.getVersion() + RegistryConstants.PATH_SEPARATOR + APIConstants.DOC_DIR + RegistryConstants.PATH_SEPARATOR + docName; try { return registry.resourceExists(docPath); } catch (RegistryException e) { String msg = "Failed to check existence of the document :" + docPath; throw new APIManagementException(msg, e); } }
Example 8
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 9
Source File: AbstractAPIManager.java From carbon-apimgt with Apache License 2.0 | 5 votes |
public boolean isAPIProductAvailable(APIProductIdentifier identifier) throws APIManagementException { String path = APIConstants.API_ROOT_LOCATION + RegistryConstants.PATH_SEPARATOR + identifier.getProviderName() + RegistryConstants.PATH_SEPARATOR + identifier.getName() + RegistryConstants.PATH_SEPARATOR + identifier.getVersion(); try { return registry.resourceExists(path); } catch (RegistryException e) { String msg = "Failed to check availability of API Product :" + path; throw new APIManagementException(msg, e); } }
Example 10
Source File: AbstractAPIManager.java From carbon-apimgt with Apache License 2.0 | 5 votes |
public boolean isAPIAvailable(APIIdentifier identifier) throws APIManagementException { String path = APIConstants.API_ROOT_LOCATION + RegistryConstants.PATH_SEPARATOR + identifier.getProviderName() + RegistryConstants.PATH_SEPARATOR + identifier.getApiName() + RegistryConstants.PATH_SEPARATOR + identifier.getVersion(); try { return registry.resourceExists(path); } catch (RegistryException e) { String msg = "Failed to check availability of api :" + path; throw new APIManagementException(msg, e); } }
Example 11
Source File: APIImportUtil.java From carbon-apimgt with Apache License 2.0 | 5 votes |
/** * This method adds API sequences to the imported API. If the sequence is a newly defined one, it is added. * * @param pathToArchive location of the extracted folder of the API */ private static void addSOAPToREST(String pathToArchive, API importedApi, Registry registry) throws APIImportExportException { String inFlowFileLocation = pathToArchive + File.separator + SOAPTOREST + File.separator + IN; String outFlowFileLocation = pathToArchive + File.separator + SOAPTOREST + File.separator + OUT; //Adding in-sequence, if any if (CommonUtil.checkFileExistence(inFlowFileLocation)) { APIIdentifier apiId = importedApi.getId(); String soapToRestLocationIn = APIConstants.API_ROOT_LOCATION + RegistryConstants.PATH_SEPARATOR + apiId.getProviderName() + RegistryConstants.PATH_SEPARATOR + apiId.getApiName() + RegistryConstants.PATH_SEPARATOR + apiId.getVersion() + RegistryConstants.PATH_SEPARATOR + SOAPToRESTConstants.SequenceGen.SOAP_TO_REST_IN_RESOURCE; String soapToRestLocationOut = APIConstants.API_ROOT_LOCATION + RegistryConstants.PATH_SEPARATOR + apiId.getProviderName() + RegistryConstants.PATH_SEPARATOR + apiId.getApiName() + RegistryConstants.PATH_SEPARATOR + apiId.getVersion() + RegistryConstants.PATH_SEPARATOR + SOAPToRESTConstants.SequenceGen.SOAP_TO_REST_OUT_RESOURCE; try { // Import inflow mediation logic Path inFlowDirectory = Paths.get(inFlowFileLocation); ImportMediationLogic(inFlowDirectory, registry, soapToRestLocationIn); // Import outflow mediation logic Path outFlowDirectory = Paths.get(outFlowFileLocation); ImportMediationLogic(outFlowDirectory, registry, soapToRestLocationOut); } catch (DirectoryIteratorException e) { throw new APIImportExportException("Error in importing SOAP to REST mediation logic", e); } } }
Example 12
Source File: APIExportUtil.java From carbon-apimgt with Apache License 2.0 | 5 votes |
/** * Retrieve API Specific sequence details from the registry. * * @param sequenceName Name of the sequence * @param type Sequence type * @param registry Current tenant registry * @return Registry resource name of the sequence and its content * @throws APIImportExportException If an error occurs while retrieving registry elements */ private static AbstractMap.SimpleEntry<String, OMElement> getAPISpecificSequence(APIIdentifier api, String sequenceName, String type, Registry registry) throws APIImportExportException { String regPath = APIConstants.API_ROOT_LOCATION + RegistryConstants.PATH_SEPARATOR + api.getProviderName() + RegistryConstants.PATH_SEPARATOR + api.getApiName() + RegistryConstants.PATH_SEPARATOR + api.getVersion() + RegistryConstants.PATH_SEPARATOR + type; return getSeqDetailsFromRegistry(sequenceName, regPath, registry); }
Example 13
Source File: RegistrySubscriptionManager.java From carbon-commons with Apache License 2.0 | 5 votes |
/** * Calculates the JMS subscription stored path for a WSSubscription using subscription id and * the topic name. * * @param subscriptionID the subscription ID * @param topicName the topic name * @return the JMS subscription resource path for a subscription */ private String getJMSSubResourcePath(String subscriptionID, String topicName) { String resourcePath = this.topicStoragePath; // first convert the . to / topicName = topicName.replaceAll("\\.", RegistryConstants.PATH_SEPARATOR); if (!topicName.startsWith(RegistryConstants.PATH_SEPARATOR)) { resourcePath = resourcePath + RegistryConstants.PATH_SEPARATOR; } // this topic name can have # and * marks if the user wants to subscribes to the // child topics as well. but we consider the topic here as the topic name just before any // special character. // eg. if topic name is myTopic/*/* then topic name is myTopic if (topicName.indexOf(STAR_WILDCARD) > -1) { topicName = topicName.substring(0, topicName.indexOf(STAR_WILDCARD)); } else if (topicName.indexOf(HASH_WILDCARD) > -1) { topicName = topicName.substring(0, topicName.indexOf(HASH_WILDCARD)); } resourcePath = resourcePath + topicName; if (!resourcePath.endsWith(RegistryConstants.PATH_SEPARATOR)) { resourcePath = resourcePath + RegistryConstants.PATH_SEPARATOR; } resourcePath = resourcePath + (EventBrokerConstants.EB_CONF_JMS_SUBSCRIPTION_COLLECTION_NAME + RegistryConstants.PATH_SEPARATOR + subscriptionID); return resourcePath; }
Example 14
Source File: Util.java From carbon-commons with Apache License 2.0 | 5 votes |
/** * Sends an email to the user with the link to verify. * @param data of the user * @param serviceConfig, EmailVerifier Configuration. * @throws Exception, if sending the user verification mail failed. */ public static void requestUserVerification(Map<String, String> data, EmailVerifierConfig serviceConfig) throws Exception { String emailAddress = data.get("email"); emailAddress = emailAddress.trim(); try { String secretKey = UUID.randomUUID().toString(); // User is supposed to give where he wants to store the intermediate data. // But, here there is no tenant signing in happened yet. // So get the super tenant registry instance. Registry registry = Util.getConfigSystemRegistry(MultitenantConstants.SUPER_TENANT_ID); Resource resource = registry.newResource(); // store the redirector url resource.setProperty("redirectPath", serviceConfig.getRedirectPath()); // store the user data, redirectPath can be overwritten here. for (String s : data.keySet()) { resource.setProperty(s, data.get(s)); } resource.setVersionableChange(false); String secretKeyPath = EMAIL_VERIFICATION_COLLECTION + RegistryConstants.PATH_SEPARATOR + secretKey; registry.put(secretKeyPath, resource); // sending the mail EmailSender sender = new EmailSender(serviceConfig, emailAddress, secretKey, PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(true), data); sender.sendEmail(); } catch (Exception e) { String msg = "Error in sending the email to validation."; log.error(msg, e); throw new Exception(msg, e); } }
Example 15
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(); }
Example 16
Source File: PolicyPublisher.java From carbon-identity-framework with Apache License 2.0 | 4 votes |
public void persistSubscriber(PublisherDataHolder holder, boolean update) throws EntitlementException { Collection policyCollection; String subscriberPath; String subscriberId = null; if (holder == null || holder.getPropertyDTOs() == null) { log.error("Publisher data can not be null"); throw new EntitlementException("Publisher data can not be null"); } for (PublisherPropertyDTO dto : holder.getPropertyDTOs()) { if (SUBSCRIBER_ID.equals(dto.getId())) { subscriberId = dto.getValue(); } } if (subscriberId == null) { log.error("Subscriber Id can not be null"); throw new EntitlementException("Subscriber Id can not be null"); } try { if (registry.resourceExists(PDPConstants.ENTITLEMENT_POLICY_PUBLISHER)) { policyCollection = registry.newCollection(); registry.put(PDPConstants.ENTITLEMENT_POLICY_PUBLISHER, policyCollection); } subscriberPath = PDPConstants.ENTITLEMENT_POLICY_PUBLISHER + RegistryConstants.PATH_SEPARATOR + subscriberId; Resource resource; PublisherDataHolder oldHolder = null; if (registry.resourceExists(subscriberPath)) { if (update) { resource = registry.get(subscriberPath); oldHolder = new PublisherDataHolder(resource, false); } else { throw new EntitlementException("Subscriber ID already exists"); } } else { resource = registry.newResource(); } populateProperties(holder, oldHolder, resource); registry.put(subscriberPath, resource); } catch (RegistryException e) { log.error("Error while persisting subscriber details", e); throw new EntitlementException("Error while persisting subscriber details", e); } }
Example 17
Source File: PolicyPublisher.java From carbon-identity with Apache License 2.0 | 4 votes |
public void persistSubscriber(PublisherDataHolder holder, boolean update) throws EntitlementException { Collection policyCollection; String subscriberPath; String subscriberId = null; if (holder == null || holder.getPropertyDTOs() == null) { log.error("Publisher data can not be null"); throw new EntitlementException("Publisher data can not be null"); } for (PublisherPropertyDTO dto : holder.getPropertyDTOs()) { if (SUBSCRIBER_ID.equals(dto.getId())) { subscriberId = dto.getValue(); } } if (subscriberId == null) { log.error("Subscriber Id can not be null"); throw new EntitlementException("Subscriber Id can not be null"); } try { if (registry.resourceExists(PDPConstants.ENTITLEMENT_POLICY_PUBLISHER)) { policyCollection = registry.newCollection(); registry.put(PDPConstants.ENTITLEMENT_POLICY_PUBLISHER, policyCollection); } subscriberPath = PDPConstants.ENTITLEMENT_POLICY_PUBLISHER + RegistryConstants.PATH_SEPARATOR + subscriberId; Resource resource; PublisherDataHolder oldHolder = null; if (registry.resourceExists(subscriberPath)) { if (update) { resource = registry.get(subscriberPath); oldHolder = new PublisherDataHolder(resource, false); } else { throw new EntitlementException("Subscriber ID already exists"); } } else { resource = registry.newResource(); } populateProperties(holder, oldHolder, resource); registry.put(subscriberPath, resource); } catch (RegistryException e) { log.error("Error while persisting subscriber details", e); throw new EntitlementException("Error while persisting subscriber details", e); } }
Example 18
Source File: AbstractAPIManagerTestCase.java From carbon-apimgt with Apache License 2.0 | 4 votes |
@Test public void testGetAllDocumentation() throws APIManagementException, RegistryException { Registry registry = Mockito.mock(UserRegistry.class); AbstractAPIManager abstractAPIManager = new AbstractAPIManagerWrapper(genericArtifactManager, registry, null); abstractAPIManager.registry = registry; GenericArtifact genericArtifact = getGenericArtifact(SAMPLE_API_NAME, API_PROVIDER, SAMPLE_API_VERSION, "sample"); genericArtifact.setAttribute(APIConstants.DOC_TYPE, "Other"); genericArtifact.setAttribute(APIConstants.DOC_SOURCE_TYPE, "URL"); Association association = new Association(); String associationDestinationPath = "doc/destination"; association.setDestinationPath(associationDestinationPath); Association[] associations = new Association[] { association }; APIIdentifier identifier = getAPIIdentifier(SAMPLE_API_NAME, API_PROVIDER, SAMPLE_API_VERSION); String apiResourcePath = APIConstants.API_ROOT_LOCATION + RegistryConstants.PATH_SEPARATOR + identifier.getProviderName() + RegistryConstants.PATH_SEPARATOR + identifier.getApiName() + RegistryConstants.PATH_SEPARATOR + identifier.getVersion() + APIConstants.API_RESOURCE_NAME; Mockito.when(registry.getAssociations(apiResourcePath, APIConstants.DOCUMENTATION_ASSOCIATION)) .thenThrow(RegistryException.class).thenReturn(associations); PowerMockito.mockStatic(APIUtil.class); PowerMockito.when(APIUtil.getAPIPath(identifier)).thenReturn(apiResourcePath); Mockito.when(genericArtifact.getPath()).thenReturn("test"); String docName = "sample"; Documentation documentation = new Documentation(DocumentationType.HOWTO, docName); PowerMockito.when(APIUtil.getDocumentation(genericArtifact)).thenReturn(documentation); try { abstractAPIManager.getAllDocumentation(identifier); Assert.fail("Registry exception not thrown for error scenario"); } catch (APIManagementException e) { Assert.assertTrue(e.getMessage().contains("Failed to get documentations for api")); } Resource resource = new ResourceImpl(); resource.setUUID(SAMPLE_RESOURCE_ID); Mockito.when(registry.get(associationDestinationPath)).thenReturn(resource); Mockito.when(genericArtifactManager.getGenericArtifact(SAMPLE_RESOURCE_ID)).thenReturn(genericArtifact); List<Documentation> documentationList = abstractAPIManager.getAllDocumentation(identifier); Assert.assertNotNull(documentationList); Assert.assertEquals(documentationList.size(), 1); String documentationName = "doc1"; String contentPath = APIConstants.API_LOCATION + RegistryConstants.PATH_SEPARATOR + identifier.getProviderName() + RegistryConstants.PATH_SEPARATOR + identifier.getApiName() + RegistryConstants.PATH_SEPARATOR + identifier.getVersion() + RegistryConstants.PATH_SEPARATOR + APIConstants.DOC_DIR + RegistryConstants.PATH_SEPARATOR + RegistryConstants.PATH_SEPARATOR + documentationName; genericArtifact.setAttribute(APIConstants.DOC_SOURCE_TYPE, "In line"); genericArtifact.setAttribute(APIConstants.DOC_NAME, documentationName); ResourceDO resourceDO = new ResourceDO(); resourceDO.setLastUpdatedOn(12344567); Resource resource1 = new ResourceImpl(contentPath, resourceDO); Mockito.when(registry.get(contentPath)).thenReturn(resource1); documentationList = abstractAPIManager.getAllDocumentation(identifier); Assert.assertNotNull(documentationList); Assert.assertEquals(documentationList.size(), 1); }
Example 19
Source File: ApplicationMgtUtil.java From carbon-identity with Apache License 2.0 | 2 votes |
public static String getApplicationPermissionPath() { return CarbonConstants.UI_PERMISSION_NAME + RegistryConstants.PATH_SEPARATOR + APPLICATION_ROOT_PERMISSION; }
Example 20
Source File: RegistryResourceMgtServiceImpl.java From carbon-identity-framework with Apache License 2.0 | 2 votes |
/** * Get the registry path for the resource based on it's locale. Here we follow a convention that the leaf element * of the path is the resource and we name the resource by it's locale value. We can derive the type of the resource * using the path. ( eg: /identity/challengeQuestions/Set1/question1/en_us) * * @param path Path to the resource relative to the root of the configuration registry to the parent directory of * the resource * @param locale locale of the resource which will also be the name of the resource. * @return */ private String getRegistryPath(String path, String locale) { locale = validateLocale(locale); path = path + RegistryConstants.PATH_SEPARATOR + locale; return path; }