Java Code Examples for org.wso2.carbon.apimgt.api.model.APIIdentifier#getVersion()
The following examples show how to use
org.wso2.carbon.apimgt.api.model.APIIdentifier#getVersion() .
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: 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 2
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 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: 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 7
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 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 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 10
Source File: APIUtilTest.java From carbon-apimgt with Apache License 2.0 | 5 votes |
@Test public void testIsPerAPISequenceNoPathsInCollection() 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); Collection collection = Mockito.mock(Collection.class); Mockito.when(registry.get(eq(path))).thenReturn(collection); String[] childPaths = {}; Mockito.when(collection.getChildren()).thenReturn(childPaths); boolean isPerAPiSequence = APIUtil.isPerAPISequence("sample", 1, apiIdentifier, "in"); Assert.assertFalse(isPerAPiSequence); }
Example 11
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 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: 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 14
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 15
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 16
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 17
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 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: 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: ApplicationImportExportManager.java From carbon-apimgt with Apache License 2.0 | 4 votes |
/** * Import and add subscriptions of a particular application for the available APIs * * @param appDetails details of the imported application * @param userId username of the subscriber * @param appId application Id * @return a list of APIIdentifiers of the skipped subscriptions * @throws APIManagementException if an error occurs while importing and adding subscriptions */ public List<APIIdentifier> importSubscriptions(Application appDetails, String userId, int appId, Boolean update) throws APIManagementException, UserStoreException { List<APIIdentifier> skippedAPIList = new ArrayList<>(); Set<SubscribedAPI> subscribedAPIs = appDetails.getSubscribedAPIs(); for (SubscribedAPI subscribedAPI : subscribedAPIs) { APIIdentifier apiIdentifier = subscribedAPI.getApiId(); String tenantDomain = MultitenantUtils.getTenantDomain(APIUtil.replaceEmailDomainBack (apiIdentifier.getProviderName())); if (!StringUtils.isEmpty(tenantDomain) && APIUtil.isTenantAvailable(tenantDomain)) { String name = apiIdentifier.getApiName(); String version = apiIdentifier.getVersion(); //creating a solr compatible search query, here we will execute a search query without wildcards StringBuilder searchQuery = new StringBuilder(); String[] searchCriteria = {name, "version:" + version}; for (int i = 0; i < searchCriteria.length; i++) { if (i == 0) { searchQuery = new StringBuilder( APIUtil.getSingleSearchCriteria(searchCriteria[i]).replace("*", "")); } else { searchQuery.append(APIConstants.SEARCH_AND_TAG) .append(APIUtil.getSingleSearchCriteria(searchCriteria[i]).replace("*", "")); } } Map matchedAPIs; matchedAPIs = apiConsumer.searchPaginatedAPIs(searchQuery.toString(), tenantDomain, 0, Integer.MAX_VALUE, false); Set<API> apiSet = (Set<API>) matchedAPIs.get("apis"); if (apiSet != null && !apiSet.isEmpty()) { API api = apiSet.iterator().next(); //tier of the imported subscription Tier tier = subscribedAPI.getTier(); //checking whether the target tier is available if (isTierAvailable(tier, api) && api.getStatus() != null && APIConstants.PUBLISHED.equals(api.getStatus())) { ApiTypeWrapper apiTypeWrapper = new ApiTypeWrapper(api); apiTypeWrapper.setTier(tier.getName()); // add subscription if update flag is not specified // it will throw an error if subscriber already exists if (update == null || !update) { apiConsumer.addSubscription(apiTypeWrapper, userId, appId); } else if (!apiConsumer.isSubscribedToApp(subscribedAPI.getApiId(), userId, appId)) { // on update skip subscriptions that already exists apiConsumer.addSubscription(apiTypeWrapper, userId, appId); } } else { log.error("Failed to import Subscription as API " + name + "-" + version + " as one or more tiers may be unavailable or the API may not have been published "); skippedAPIList.add(subscribedAPI.getApiId()); } } else { log.error("Failed to import Subscription as API " + name + "-" + version + " is not available"); skippedAPIList.add(subscribedAPI.getApiId()); } } else { log.error("Failed to import Subscription as Tenant domain: " + tenantDomain + " is not available"); skippedAPIList.add(subscribedAPI.getApiId()); } } return skippedAPIList; }