use of org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder in project carbon-apimgt by wso2.
the class APIProviderImplTest method testAddFileToDocumentation.
/**
* This method tests adding file to documentation method.
* @throws Exception
*
* @throws GovernanceException Governance Exception.
*/
@Test
public void testAddFileToDocumentation() throws Exception {
String apiUUID = "xxxxxxxx";
String docUUID = "yyyyyyyy";
APIIdentifier identifier = new APIIdentifier("admin-AT-carbon.super", "API1", "1.0.0");
Set<String> environments = new HashSet<String>();
Set<URITemplate> uriTemplates = new HashSet<URITemplate>();
Tier tier = new Tier("Gold");
Map<String, Tier> tiers = new TreeMap<>();
tiers.put("Gold", tier);
URITemplate uriTemplate1 = new URITemplate();
uriTemplate1.setHTTPVerb("POST");
uriTemplate1.setAuthType("Application");
uriTemplate1.setUriTemplate("/add");
uriTemplate1.setThrottlingTier("Gold");
uriTemplates.add(uriTemplate1);
final API api = new API(identifier);
api.setStatus(APIConstants.CREATED);
api.setVisibility("public");
api.setAccessControl("all");
api.setTransports("http,https");
api.setContext("/test");
api.setEnvironments(environments);
api.setUriTemplates(uriTemplates);
api.setOrganization("carbon.super");
List<Documentation> documentationList = getDocumentationList();
final APIProviderImplWrapper apiProvider = new APIProviderImplWrapper(apiPersistenceInstance, apimgtDAO, scopesDAO, documentationList, null);
RegistryService registryService = Mockito.mock(RegistryService.class);
UserRegistry userRegistry = Mockito.mock(UserRegistry.class);
ServiceReferenceHolder serviceReferenceHolder = TestUtils.getServiceReferenceHolder();
RealmService realmService = Mockito.mock(RealmService.class);
TenantManager tenantManager = Mockito.mock(TenantManager.class);
Mockito.when(APIUtil.getTiers(APIConstants.TIER_RESOURCE_TYPE, "carbon.super")).thenReturn(tiers);
Mockito.when(artifactManager.newGovernanceArtifact(any(QName.class))).thenReturn(artifact);
Mockito.when(APIUtil.createAPIArtifactContent(artifact, api)).thenReturn(artifact);
PowerMockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
Mockito.when(serviceReferenceHolder.getRegistryService()).thenReturn(registryService);
Mockito.when(registryService.getConfigSystemRegistry(Mockito.anyInt())).thenReturn(userRegistry);
Mockito.when(serviceReferenceHolder.getRealmService()).thenReturn(realmService);
Mockito.when(realmService.getTenantManager()).thenReturn(tenantManager);
PublisherAPI publisherAPI = Mockito.mock(PublisherAPI.class);
PowerMockito.when(apiPersistenceInstance.addAPI(any(Organization.class), any(PublisherAPI.class))).thenReturn(publisherAPI);
apiProvider.addAPI(api);
String fileName = "test.txt";
String contentType = "application/force-download";
Documentation doc = new Documentation(DocumentationType.HOWTO, fileName);
doc.setSourceType(DocumentSourceType.FILE);
PowerMockito.when(APIUtil.getDocumentationFilePath(api.getId(), fileName)).thenReturn("filePath");
InputStream inputStream = Mockito.mock(InputStream.class);
// apiProvider.addFileToDocumentation(api.getId(), doc, fileName, inputStream, contentType);
DocumentationContent content = new DocumentationContent();
ResourceFile resourceFile = new ResourceFile(inputStream, contentType);
content.setResourceFile(resourceFile);
apiProvider.addDocumentationContent(apiUUID, docUUID, "carbon.super", content);
}
use of org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder in project carbon-apimgt by wso2.
the class APIProviderImplTest method prepareForLCStateChangeOfAPIProduct.
private void prepareForLCStateChangeOfAPIProduct(APIProviderImplWrapper apiProvider, APIProduct apiProduct) throws Exception {
RegistryService registryService = Mockito.mock(RegistryService.class);
UserRegistry userRegistry = Mockito.mock(UserRegistry.class);
ServiceReferenceHolder serviceReferenceHolder = TestUtils.getServiceReferenceHolder();
RealmService realmService = Mockito.mock(RealmService.class);
TenantManager tenantManager = Mockito.mock(TenantManager.class);
PowerMockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
Mockito.when(serviceReferenceHolder.getRegistryService()).thenReturn(registryService);
Mockito.when(registryService.getConfigSystemRegistry(Mockito.anyInt())).thenReturn(userRegistry);
Mockito.when(serviceReferenceHolder.getRealmService()).thenReturn(realmService);
Mockito.when(realmService.getTenantManager()).thenReturn(tenantManager);
PrivilegedCarbonContext prContext = Mockito.mock(PrivilegedCarbonContext.class);
PowerMockito.when(PrivilegedCarbonContext.getThreadLocalCarbonContext()).thenReturn(prContext);
PowerMockito.doNothing().when(prContext).setUsername(Mockito.anyString());
PowerMockito.doNothing().when(prContext).setTenantDomain(Mockito.anyString(), Mockito.anyBoolean());
Mockito.when(artifactManager.getGenericArtifact(any(String.class))).thenReturn(artifact);
PowerMockito.when(RegistryPersistenceUtil.createAPIProductArtifactContent(artifact, apiProduct)).thenReturn(artifact);
PowerMockito.when(GovernanceUtils.getArtifactPath(apiProvider.registry, artifact.getId())).thenReturn(artifactPath);
Mockito.doNothing().when(artifactManager).updateGenericArtifact(artifact);
Mockito.when(apiProvider.registry.resourceExists(artifactPath)).thenReturn(false);
}
use of org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder in project carbon-apimgt by wso2.
the class APIProviderImplTest method testGetSubscriberClaims.
@Test
public void testGetSubscriberClaims() throws APIManagementException, UserStoreException, XMLStreamException {
String configuredClaims = "http://wso2.org/claim1,http://wso2.org/claim2";
APIProviderImplWrapper apiProvider = new APIProviderImplWrapper(apimgtDAO, scopesDAO);
// Mock retrieving the tenant domain
PowerMockito.mockStatic(MultitenantUtils.class);
PowerMockito.mockStatic(APIUtil.class);
Mockito.when(MultitenantUtils.getTenantDomain("admin")).thenReturn("carbon.super");
ServiceReferenceHolder serviceReferenceHolder = TestUtils.getServiceReferenceHolder();
RealmService realmService = Mockito.mock(RealmService.class);
TenantManager tenantManager = Mockito.mock(TenantManager.class);
PowerMockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
Mockito.when(serviceReferenceHolder.getRealmService()).thenReturn(realmService);
Mockito.when(realmService.getTenantManager()).thenReturn(tenantManager);
PowerMockito.when(tenantManager.getTenantId(Matchers.anyString())).thenReturn(-1234);
UserStoreManager userStoreManager = Mockito.mock(UserStoreManager.class);
UserRealm userRealm = Mockito.mock(UserRealm.class);
PowerMockito.when(realmService.getTenantUserRealm(-1234)).thenReturn(userRealm);
PowerMockito.when(userRealm.getUserStoreManager()).thenReturn(userStoreManager);
PowerMockito.when(userStoreManager.isExistingUser("admin")).thenReturn(true);
SortedMap<String, String> claimValues = new TreeMap<String, String>();
claimValues.put("claim1", "http://wso2.org/claim1");
claimValues.put("claim2", "http://wso2.org/claim2");
claimValues.put("claim3", "http://wso2.org/claim3");
PowerMockito.when(APIUtil.getClaims("admin", -1234, DEFAULT_DIALECT_URI)).thenReturn(claimValues);
APIManagerConfiguration configuration = Mockito.mock(APIManagerConfiguration.class);
APIManagerConfigurationService configurationService = Mockito.mock(APIManagerConfigurationService.class);
PowerMockito.when(serviceReferenceHolder.getAPIManagerConfigurationService()).thenReturn(configurationService);
PowerMockito.when(configurationService.getAPIManagerConfiguration()).thenReturn(configuration);
Mockito.when(configuration.getFirstProperty(APIConstants.API_PUBLISHER_SUBSCRIBER_CLAIMS)).thenReturn(configuredClaims);
Map subscriberClaims = apiProvider.getSubscriberClaims("admin");
assertNotNull(subscriberClaims);
assertEquals(configuredClaims.split(",").length, subscriberClaims.size());
}
use of org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder in project carbon-apimgt by wso2.
the class APIAdminImplTest method setup.
@Before
public void setup() {
PowerMockito.mockStatic(APIUtil.class);
PowerMockito.mockStatic(ApiMgtDAO.class);
ApiMgtDAO apiMgtDAO = Mockito.mock(ApiMgtDAO.class);
PowerMockito.when(ApiMgtDAO.getInstance()).thenReturn(apiMgtDAO);
apimConfigService = Mockito.mock(APIMConfigService.class);
PowerMockito.mockStatic(ServiceReferenceHolder.class);
serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class);
PowerMockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
Mockito.when(serviceReferenceHolder.getApimConfigService()).thenReturn(apimConfigService);
}
use of org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder in project carbon-apimgt by wso2.
the class APIProviderImplTest method mockSequencesMultiple.
private void mockSequencesMultiple(String seqLoc, String apiSeqLoc, APIIdentifier apiId) throws Exception {
ServiceReferenceHolder sh = PowerMockito.mock(ServiceReferenceHolder.class);
PowerMockito.when(ServiceReferenceHolder.getInstance()).thenReturn(sh);
RegistryService registryService = Mockito.mock(RegistryService.class);
PowerMockito.when(sh.getRegistryService()).thenReturn(registryService);
UserRegistry registry = Mockito.mock(UserRegistry.class);
PowerMockito.when(registryService.getGovernanceSystemRegistry(Matchers.anyInt())).thenReturn(registry);
Mockito.when(registry.resourceExists(seqLoc)).thenReturn(true);
Collection seqCollection = Mockito.mock(Collection.class);
Mockito.when(registry.get(seqLoc)).thenReturn(seqCollection);
String[] seqChildPaths = { "path1", "path2" };
Mockito.when(seqCollection.getChildren()).thenReturn(seqChildPaths);
Resource sequence = Mockito.mock(Resource.class);
Mockito.when(registry.get(seqChildPaths[0])).thenReturn(sequence);
InputStream responseStream = IOUtils.toInputStream("<sequence name=\"pqr\"></sequence>", "UTF-8");
Resource sequence2 = Mockito.mock(Resource.class);
Mockito.when(registry.get(seqChildPaths[1])).thenReturn(sequence2);
InputStream responseStream2 = IOUtils.toInputStream("<sequence name=\"abc\"></sequence>", "UTF-8");
OMElement seqElment = buildOMElement(responseStream);
OMElement seqElment2 = buildOMElement(responseStream2);
PowerMockito.when(APIUtil.buildOMElement(responseStream)).thenReturn(seqElment);
PowerMockito.when(APIUtil.buildOMElement(responseStream2)).thenReturn(seqElment2);
Mockito.when(sequence.getContentStream()).thenReturn(responseStream);
Mockito.when(sequence2.getContentStream()).thenReturn(responseStream2);
}
Aggregations