use of org.wso2.carbon.apimgt.throttle.policy.deployer.internal.ServiceReferenceHolder in project carbon-apimgt by wso2.
the class TestUtils method getTenantManager.
public static TenantManager getTenantManager() throws XMLStreamException {
ServiceReferenceHolder serviceReferenceHolder = getServiceReferenceHolder();
RealmService realmService = Mockito.mock(RealmService.class);
TenantManager tenantManager = Mockito.mock(TenantManager.class);
PowerMockito.when(serviceReferenceHolder.getRealmService()).thenReturn(realmService);
PowerMockito.when(realmService.getTenantManager()).thenReturn(tenantManager);
return tenantManager;
}
use of org.wso2.carbon.apimgt.throttle.policy.deployer.internal.ServiceReferenceHolder in project carbon-apimgt by wso2.
the class UserAwareAPIProviderTest method init.
@Before
public void init() throws Exception {
System.setProperty("carbon.home", "");
apiIdentifier = new APIIdentifier("admin_identifier1_v1.0");
PowerMockito.mockStatic(ApiMgtDAO.class);
PowerMockito.mockStatic(ServiceReferenceHolder.class);
PowerMockito.mockStatic(APIUtil.class);
PowerMockito.mockStatic(RegistryUtils.class);
PowerMockito.mockStatic(PrivilegedCarbonContext.class);
ApiMgtDAO apiMgtDAO = Mockito.mock(ApiMgtDAO.class);
ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class);
TenantManager tenantManager = Mockito.mock(TenantManager.class);
RealmService realmService = Mockito.mock(RealmService.class);
RegistryService registryService = Mockito.mock(RegistryService.class);
userRegistry = Mockito.mock(UserRegistry.class);
GenericArtifactManager artifactManager = Mockito.mock(GenericArtifactManager.class);
APIManagerConfigurationService apiManagerConfigurationService = Mockito.mock(APIManagerConfigurationService.class);
APIManagerConfiguration apiManagerConfiguration = Mockito.mock(APIManagerConfiguration.class);
resource = Mockito.mock(Resource.class, Mockito.CALLS_REAL_METHODS);
Mockito.doReturn(apiManagerConfiguration).when(apiManagerConfigurationService).getAPIManagerConfiguration();
Mockito.doReturn(APIConstants.API_GATEWAY_TYPE_SYNAPSE).when(apiManagerConfiguration).getFirstProperty(APIConstants.API_GATEWAY_TYPE);
Mockito.doReturn("true").when(apiManagerConfiguration).getFirstProperty(APIConstants.API_PUBLISHER_ENABLE_ACCESS_CONTROL_LEVELS);
Mockito.doReturn(userRegistry).when(registryService).getGovernanceUserRegistry(Mockito.anyString(), Mockito.anyInt());
Mockito.doReturn(userRegistry).when(registryService).getGovernanceSystemRegistry();
Mockito.doReturn(userRegistry).when(registryService).getConfigSystemRegistry(Mockito.anyInt());
Mockito.doReturn(userRegistry).when(registryService).getConfigSystemRegistry();
Mockito.doReturn(resource).when(userRegistry).newResource();
Mockito.doReturn(null).when(userRegistry).getUserRealm();
PowerMockito.when(ApiMgtDAO.getInstance()).thenReturn(apiMgtDAO);
PowerMockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
PowerMockito.when(APIUtil.getAPIPath(Mockito.any(APIIdentifier.class))).thenReturn("test");
PowerMockito.when(APIUtil.getArtifactManager(Mockito.any(Registry.class), Mockito.anyString())).thenReturn(artifactManager);
PowerMockito.when(APIUtil.getInternalOrganizationDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)).thenReturn(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
PowerMockito.doNothing().when(ServiceReferenceHolder.class, "setUserRealm", Mockito.any());
PowerMockito.doNothing().when(APIUtil.class, "loadTenantRegistry", Mockito.anyInt());
PowerMockito.when(APIUtil.replaceEmailDomainBack(apiIdentifier.getProviderName())).thenReturn(apiIdentifier.getProviderName());
Mockito.doReturn(realmService).when(serviceReferenceHolder).getRealmService();
Mockito.doReturn(tenantManager).when(realmService).getTenantManager();
Mockito.doReturn(registryService).when(serviceReferenceHolder).getRegistryService();
Mockito.doReturn(apiManagerConfigurationService).when(serviceReferenceHolder).getAPIManagerConfigurationService();
PowerMockito.when(APIUtil.compareRoleList(Mockito.any(String[].class), Mockito.anyString())).thenCallRealMethod();
ConfigurationContextService configurationContextService = TestUtils.initConfigurationContextService(true);
PowerMockito.when(ServiceReferenceHolder.getContextService()).thenReturn(configurationContextService);
userAwareAPIProvider = new UserAwareAPIProvider(ADMIN_ROLE_NAME);
PrivilegedCarbonContext prcontext = Mockito.mock(PrivilegedCarbonContext.class);
PowerMockito.when(PrivilegedCarbonContext.getThreadLocalCarbonContext()).thenReturn(prcontext);
}
use of org.wso2.carbon.apimgt.throttle.policy.deployer.internal.ServiceReferenceHolder in project carbon-apimgt by wso2.
the class DefaultGroupIDExtractorImplTest method getGroupingIdentifiersTestCase.
@Test
public void getGroupingIdentifiersTestCase() throws UserStoreException {
ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class);
PowerMockito.mockStatic(ServiceReferenceHolder.class);
RealmService realmService = Mockito.mock(RealmService.class);
UserRealm userRealm = Mockito.mock(UserRealm.class);
APIManagerConfigurationService apiManagerConfigurationService = Mockito.mock(APIManagerConfigurationService.class);
APIManagerConfiguration apiManagerConfiguration = Mockito.mock(APIManagerConfiguration.class);
TenantManager tenantManager = Mockito.mock(TenantManager.class);
UserStoreManager userStoreManager = Mockito.mock(UserStoreManager.class);
Mockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
Mockito.when(serviceReferenceHolder.getAPIManagerConfigurationService()).thenReturn(apiManagerConfigurationService);
Mockito.when(apiManagerConfigurationService.getAPIManagerConfiguration()).thenReturn(apiManagerConfiguration);
Mockito.when(apiManagerConfiguration.getFirstProperty(APIConstants.API_STORE_GROUP_EXTRACTOR_CLAIM_URI)).thenReturn("http://wso2.org/claims/organization");
Mockito.when(serviceReferenceHolder.getRealmService()).thenReturn(realmService);
Mockito.when(realmService.getTenantManager()).thenReturn(tenantManager);
Mockito.when(tenantManager.getTenantId("carbon.super")).thenReturn(-1234);
Mockito.when(realmService.getTenantUserRealm(-1234)).thenReturn(userRealm);
Mockito.when(userRealm.getUserStoreManager()).thenReturn(userStoreManager);
Mockito.when(userStoreManager.getUserClaimValue(MultitenantUtils.getTenantAwareUsername("user"), "http://wso2.org/claims/organization", null)).thenReturn("organization");
DefaultGroupIDExtractorImpl defaultGroupIDExtractor = new DefaultGroupIDExtractorImpl();
Assert.assertEquals("carbon.super/organization", defaultGroupIDExtractor.getGroupingIdentifiers("{\"user\":\"user\", \"isSuperTenant\":true}"));
Assert.assertEquals("carbon.super/organization", defaultGroupIDExtractor.getGroupingIdentifiers("{\"user\":\"user\", \"isSuperTenant\":false}"));
}
use of org.wso2.carbon.apimgt.throttle.policy.deployer.internal.ServiceReferenceHolder in project carbon-apimgt by wso2.
the class SAMLGroupIDExtractorImplTest method getGroupingIdentifiersTestCase.
@Test
public void getGroupingIdentifiersTestCase() throws ParserConfigurationException, IOException, SAXException, UnmarshallingException, UserStoreException {
SAMLGroupIDExtractorImpl samlGroupIDExtractor = new SAMLGroupIDExtractorImplWrapper();
Mockito.when(DocumentBuilderFactory.newInstance()).thenReturn(documentBuilderFactory);
Mockito.when(documentBuilderFactory.newDocumentBuilder()).thenReturn(documentBuilder);
Mockito.when(documentBuilder.parse(samlGroupIDExtractor.getByteArrayInputStream("test"))).thenReturn(document);
Mockito.when(document.getDocumentElement()).thenReturn(element);
PowerMockito.mockStatic(XMLObjectProviderRegistrySupport.class);
Response response = Mockito.mock(Response.class);
List<Assertion> assertion = new ArrayList();
Subject subject = Mockito.mock(Subject.class);
NameID nameID = Mockito.mock(NameID.class);
Assertion assertion1 = Mockito.mock(Assertion.class);
assertion.add(assertion1);
Mockito.when(XMLObjectProviderRegistrySupport.getUnmarshallerFactory()).thenReturn(unmarshallerFactory);
Mockito.when(unmarshallerFactory.getUnmarshaller(element)).thenReturn(unmarshaller);
Mockito.when(unmarshaller.unmarshall(element)).thenReturn(response);
Mockito.when(response.getAssertions()).thenReturn(assertion);
Mockito.when(assertion.get(0).getSubject()).thenReturn(subject);
Mockito.when(subject.getNameID()).thenReturn(nameID);
Mockito.when(nameID.getValue()).thenReturn("user");
ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class);
PowerMockito.mockStatic(ServiceReferenceHolder.class);
RealmService realmService = Mockito.mock(RealmService.class);
UserRealm userRealm = Mockito.mock(UserRealm.class);
TenantManager tenantManager = Mockito.mock(TenantManager.class);
UserStoreManager userStoreManager = Mockito.mock(UserStoreManager.class);
APIManagerConfigurationService apiManagerConfigService = Mockito.mock(APIManagerConfigurationService.class);
APIManagerConfiguration apiManagerConfig = Mockito.mock(APIManagerConfiguration.class);
Mockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
Mockito.when(serviceReferenceHolder.getRealmService()).thenReturn(realmService);
Mockito.when(realmService.getTenantManager()).thenReturn(tenantManager);
Mockito.when(serviceReferenceHolder.getAPIManagerConfigurationService()).thenReturn(apiManagerConfigService);
Mockito.when(apiManagerConfigService.getAPIManagerConfiguration()).thenReturn(apiManagerConfig);
Mockito.when(apiManagerConfig.getFirstProperty(APIConstants.API_STORE_GROUP_EXTRACTOR_CLAIM_URI)).thenReturn("http://wso2.org/claims/organization");
Mockito.when(tenantManager.getTenantId("carbon.super")).thenReturn(1234);
Mockito.when(realmService.getTenantUserRealm(1234)).thenReturn(userRealm);
Mockito.when(userRealm.getUserStoreManager()).thenReturn(userStoreManager);
Mockito.when(userStoreManager.getUserClaimValue(MultitenantUtils.getTenantAwareUsername("user"), "http://wso2.org/claims/organization", null)).thenReturn("organization");
Assert.assertEquals("carbon.super/organization", samlGroupIDExtractor.getGroupingIdentifiers("test"));
}
use of org.wso2.carbon.apimgt.throttle.policy.deployer.internal.ServiceReferenceHolder in project carbon-apimgt by wso2.
the class TestUtils method mockRegistryAndUserRealm.
public static ServiceReferenceHolder mockRegistryAndUserRealm(int tenantId) throws UserStoreException, RegistryException, XMLStreamException {
ServiceReferenceHolder sh = getServiceReferenceHolder();
RealmService realmService = Mockito.mock(RealmService.class);
TenantManager tm = Mockito.mock(TenantManager.class);
PowerMockito.when(sh.getRealmService()).thenReturn(realmService);
PowerMockito.when(realmService.getTenantManager()).thenReturn(tm);
RegistryService registryService = Mockito.mock(RegistryService.class);
PowerMockito.when(sh.getRegistryService()).thenReturn(registryService);
UserRegistry userReg = Mockito.mock(UserRegistry.class);
PowerMockito.when(registryService.getGovernanceUserRegistry()).thenReturn(userReg);
UserRegistry systemReg = Mockito.mock(UserRegistry.class);
PowerMockito.when(registryService.getConfigSystemRegistry()).thenReturn(systemReg);
UserRealm userRealm = Mockito.mock(UserRealm.class);
UserRealm bootstrapRealm = Mockito.mock(UserRealm.class);
PowerMockito.when(systemReg.getUserRealm()).thenReturn(userRealm);
PowerMockito.doNothing().when(ServiceReferenceHolder.class);
ServiceReferenceHolder.setUserRealm(userRealm);
org.wso2.carbon.user.api.UserRealm userR = Mockito.mock(org.wso2.carbon.user.api.UserRealm.class);
PowerMockito.when(realmService.getTenantUserRealm(-1234)).thenReturn(userR);
AuthorizationManager authManager = Mockito.mock(AuthorizationManager.class);
PowerMockito.when(userR.getAuthorizationManager()).thenReturn(authManager);
PowerMockito.when(realmService.getBootstrapRealm()).thenReturn(bootstrapRealm);
ServiceReferenceHolder.setUserRealm(bootstrapRealm);
PowerMockito.when(tm.getTenantId(Matchers.anyString())).thenReturn(tenantId);
return sh;
}
Aggregations