Java Code Examples for org.wso2.carbon.apimgt.api.model.APIIdentifier#getProviderName()
The following examples show how to use
org.wso2.carbon.apimgt.api.model.APIIdentifier#getProviderName() .
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: AbstractAPIManagerTestCase.java From carbon-apimgt with Apache License 2.0 | 6 votes |
@Test public void testIsDocumentationExist() throws APIManagementException, RegistryException { AbstractAPIManager abstractAPIManager = new AbstractAPIManagerWrapper(registry); APIIdentifier identifier = getAPIIdentifier(SAMPLE_API_NAME, API_PROVIDER, SAMPLE_API_VERSION); String docName = "sampleDoc"; String docPath = APIConstants.API_ROOT_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 + docName; Mockito.when(registry.resourceExists(docPath)).thenThrow(RegistryException.class).thenReturn(true); try { abstractAPIManager.isDocumentationExist(identifier, docName); Assert.fail("Registry exception not thrown for error scenario"); } catch (APIManagementException e) { Assert.assertTrue(e.getMessage().contains("Failed to check existence of the document")); } Assert.assertTrue(abstractAPIManager.isDocumentationExist(identifier, docName)); }
Example 2
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 3
Source File: AbstractAPIManagerTestCase.java From carbon-apimgt with Apache License 2.0 | 6 votes |
@Test public void testGetWsdl() throws APIManagementException, RegistryException, IOException { Resource resourceMock = Mockito.mock(Resource.class); AbstractAPIManager abstractAPIManager = new AbstractAPIManagerWrapper(registry); APIIdentifier identifier = getAPIIdentifier(SAMPLE_API_NAME, API_PROVIDER, SAMPLE_API_VERSION); String wsdlName = identifier.getProviderName() + "--" + identifier.getApiName() + identifier.getVersion() + ".wsdl"; String wsdlResourcePath = APIConstants.API_WSDL_RESOURCE_LOCATION + wsdlName; Resource resource = new ResourceImpl(wsdlResourcePath, new ResourceDO()); Mockito.when(registry.get(wsdlResourcePath)).thenThrow(RegistryException.class).thenReturn(resource); Mockito.when(registry.resourceExists(wsdlResourcePath)).thenReturn(true); try { abstractAPIManager.getWSDL(identifier); } catch (APIManagementException e) { Assert.assertTrue(e.getMessage().contains("Error while getting wsdl file from the registry")); } String wsdlContent = "sample wsdl"; resource.setContent(wsdlContent); InputStream inputStream = new ArrayInputStream(); Mockito.when(resourceMock.getContentStream()).thenReturn(inputStream); Assert.assertEquals(wsdlContent, IOUtils.toString(abstractAPIManager.getWSDL(identifier).getContent())); PowerMockito.mockStatic(IOUtils.class); }
Example 4
Source File: AbstractAPIManagerTestCase.java From carbon-apimgt with Apache License 2.0 | 6 votes |
@Test public void testIsAPIAvailable() throws RegistryException, APIManagementException { APIIdentifier apiIdentifier = getAPIIdentifier(SAMPLE_API_NAME, API_PROVIDER, SAMPLE_API_VERSION); String path = APIConstants.API_ROOT_LOCATION + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getProviderName() + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getApiName() + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getVersion(); Mockito.when(registry.resourceExists(path)).thenThrow(RegistryException.class).thenReturn(true); AbstractAPIManager abstractAPIManager = new AbstractAPIManagerWrapper(registry); try { abstractAPIManager.isAPIAvailable(apiIdentifier); Assert.fail("Exception not thrown for error scenario"); } catch (APIManagementException e) { Assert.assertTrue(e.getMessage().contains("Failed to check availability of api")); } Assert.assertTrue(abstractAPIManager.isAPIAvailable(apiIdentifier)); }
Example 5
Source File: APIUtilTest.java From carbon-apimgt with Apache License 2.0 | 6 votes |
@Test public void testIsPerAPISequenceResourceMissing() 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(false); boolean isPerAPiSequence = APIUtil.isPerAPISequence("sample", 1, apiIdentifier, "in"); Assert.assertFalse(isPerAPiSequence); }
Example 6
Source File: APIUtilTest.java From carbon-apimgt with Apache License 2.0 | 6 votes |
@Test public void testIsPerAPISequenceSequenceMissing() 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); Mockito.when(registry.get(eq(path))).thenReturn(null); boolean isPerAPiSequence = APIUtil.isPerAPISequence("sample", 1, apiIdentifier, "in"); Assert.assertFalse(isPerAPiSequence); }
Example 7
Source File: APIUtilTest.java From carbon-apimgt with Apache License 2.0 | 5 votes |
@Test public void testGetCustomInSequence() 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 + "in" + 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, "in", apiIdentifier); Assert.assertNotNull(customSequence); sampleSequence.close(); }
Example 8
Source File: AbstractAPIManagerTestCase.java From carbon-apimgt with Apache License 2.0 | 5 votes |
@Test public void testGetDocumentation() throws APIManagementException, RegistryException { Registry registry = Mockito.mock(UserRegistry.class); AbstractAPIManager abstractAPIManager = new AbstractAPIManagerWrapper(genericArtifactManager, registry, null); APIIdentifier identifier = getAPIIdentifier(SAMPLE_API_NAME, API_PROVIDER, SAMPLE_API_VERSION); 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 + documentationName; GenericArtifact genericArtifact = getGenericArtifact(SAMPLE_API_NAME, API_PROVIDER, SAMPLE_API_VERSION, "sample"); String docType = "other"; genericArtifact.setAttribute(APIConstants.DOC_TYPE, docType); genericArtifact.setAttribute(APIConstants.DOC_SOURCE_TYPE, "URL"); Resource resource = new ResourceImpl(); resource.setUUID(SAMPLE_RESOURCE_ID); Mockito.when(registry.get(contentPath)).thenThrow(RegistryException.class).thenReturn(resource); Mockito.when(genericArtifactManager.getGenericArtifact(SAMPLE_RESOURCE_ID)).thenReturn(genericArtifact); try { abstractAPIManager.getDocumentation(identifier, DocumentationType.OTHER, documentationName); Assert.fail("Registry exception not thrown for error scenario"); } catch (APIManagementException e) { Assert.assertTrue(e.getMessage().contains("Failed to get documentation details")); } Assert.assertTrue( abstractAPIManager.getDocumentation(identifier, DocumentationType.OTHER, documentationName).getId() .equals(genericArtifact.getId())); }
Example 9
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 10
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 11
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 12
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 13
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 14
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 15
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 16
Source File: APIUtilTest.java From carbon-apimgt with Apache License 2.0 | 5 votes |
@Test public void testGetMediationSequenceUuidCustomSequence() 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(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 17
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 18
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 19
Source File: AbstractAPIManagerTestCase.java From carbon-apimgt with Apache License 2.0 | 4 votes |
@Test public void testGetAllApiSpecificMediationPolicies() throws RegistryException, APIManagementException, IOException, XMLStreamException { APIIdentifier identifier = getAPIIdentifier(SAMPLE_API_NAME, API_PROVIDER, SAMPLE_API_VERSION); String parentCollectionPath = APIConstants.API_ROOT_LOCATION + RegistryConstants.PATH_SEPARATOR + identifier.getProviderName() + RegistryConstants.PATH_SEPARATOR + identifier.getApiName() + RegistryConstants.PATH_SEPARATOR + identifier.getVersion() + APIConstants.API_RESOURCE_NAME; parentCollectionPath = parentCollectionPath.substring(0, parentCollectionPath.lastIndexOf("/")); Collection parentCollection = new CollectionImpl(); parentCollection.setChildren(new String[] { parentCollectionPath + RegistryConstants.PATH_SEPARATOR + APIConstants.API_CUSTOM_SEQUENCE_TYPE_IN, parentCollectionPath + RegistryConstants.PATH_SEPARATOR + APIConstants.API_CUSTOM_SEQUENCE_TYPE_OUT, parentCollectionPath + RegistryConstants.PATH_SEPARATOR + APIConstants.API_CUSTOM_SEQUENCE_TYPE_FAULT }); Collection childCollection = new CollectionImpl(); childCollection.setChildren(new String[] { "mediation1" }); Mockito.when(registry.get(parentCollectionPath)).thenThrow(RegistryException.class) .thenReturn(parentCollection); Mockito.when(registry.get( parentCollectionPath + RegistryConstants.PATH_SEPARATOR + APIConstants.API_CUSTOM_SEQUENCE_TYPE_IN)) .thenReturn(childCollection); Resource resource = new ResourceImpl(); resource.setUUID(SAMPLE_RESOURCE_ID); String mediationPolicyContent = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<sequence xmlns=\"http://ws.apache.org/ns/synapse\" name=\"default-endpoint\">\n</sequence>"; resource.setContent(mediationPolicyContent); Mockito.when(registry.get("mediation1")).thenReturn(resource); AbstractAPIManager abstractAPIManager = new AbstractAPIManagerWrapper(registry); try { abstractAPIManager.getAllApiSpecificMediationPolicies(identifier); Assert.fail("Registry exception not thrown for error scenario"); } catch (APIManagementException e) { Assert.assertTrue( e.getMessage().contains("Error occurred while getting Api Specific mediation policies ")); } Assert.assertEquals(abstractAPIManager.getAllApiSpecificMediationPolicies(identifier).size(), 1); PowerMockito.mockStatic(IOUtils.class); PowerMockito.mockStatic(AXIOMUtil.class); PowerMockito.when(IOUtils.toString((InputStream) Mockito.any(), Mockito.anyString())) .thenThrow(IOException.class).thenReturn(mediationPolicyContent); PowerMockito.when(AXIOMUtil.stringToOM(Mockito.anyString())).thenThrow(XMLStreamException.class); abstractAPIManager.getAllApiSpecificMediationPolicies(identifier);// covers exception which is only logged abstractAPIManager.getAllApiSpecificMediationPolicies(identifier);// covers exception which is only logged }
Example 20
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); }