Search in sources :

Example 86 with APIManagerConfiguration

use of org.wso2.carbon.apimgt.impl.APIManagerConfiguration in project carbon-apimgt by wso2.

the class APIProviderImplTest method init.

@Before
public void init() throws Exception {
    System.setProperty("carbon.home", APIProviderImplTest.class.getResource("/").getFile());
    PowerMockito.mockStatic(ApiMgtDAO.class);
    PowerMockito.mockStatic(GatewayArtifactsMgtDAO.class);
    PowerMockito.mockStatic(ScopesDAO.class);
    PowerMockito.mockStatic(PrivilegedCarbonContext.class);
    PowerMockito.mockStatic(RegistryUtils.class);
    PowerMockito.mockStatic(GovernanceUtils.class);
    PowerMockito.mockStatic(WorkflowExecutorFactory.class);
    PowerMockito.mockStatic(LifecycleBeanPopulator.class);
    PowerMockito.mockStatic(KeyManagerHolder.class);
    PowerMockito.mockStatic(Caching.class);
    PowerMockito.mockStatic(PaginationContext.class);
    PowerMockito.mockStatic(APIUtil.class);
    PowerMockito.mockStatic(APIGatewayManager.class);
    PowerMockito.mockStatic(CertificateManagerImpl.class);
    PowerMockito.mockStatic(RegistryPersistenceUtil.class);
    apimgtDAO = Mockito.mock(ApiMgtDAO.class);
    gatewayArtifactsMgtDAO = Mockito.mock(GatewayArtifactsMgtDAO.class);
    scopesDAO = Mockito.mock(ScopesDAO.class);
    keyManager = Mockito.mock(KeyManager.class);
    apiPersistenceInstance = Mockito.mock(APIPersistence.class);
    certificateManager = Mockito.mock(CertificateManagerImpl.class);
    Mockito.when(keyManager.getResourceByApiId(Mockito.anyString())).thenReturn(null);
    Mockito.when(keyManager.registerNewResource(Mockito.any(API.class), Mockito.any(Map.class))).thenReturn(true);
    KeyManagerDto keyManagerDto = new KeyManagerDto();
    keyManagerDto.setName("default");
    keyManagerDto.setKeyManager(keyManager);
    keyManagerDto.setIssuer("https://localhost");
    Map<String, KeyManagerDto> tenantKeyManagerDtoMap = new HashMap<>();
    tenantKeyManagerDtoMap.put("default", keyManagerDto);
    PowerMockito.when(KeyManagerHolder.getTenantKeyManagers("carbon.super")).thenReturn(tenantKeyManagerDtoMap);
    PowerMockito.when(CertificateManagerImpl.getInstance()).thenReturn(certificateManager);
    PowerMockito.when(APIUtil.isAPIManagementEnabled()).thenReturn(false);
    PowerMockito.when(APIUtil.replaceEmailDomainBack(Mockito.anyString())).thenReturn("admin");
    Mockito.when(APIUtil.replaceEmailDomain(Mockito.anyString())).thenReturn("admin");
    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());
    artifactManager = Mockito.mock(GenericArtifactManager.class);
    registry = Mockito.mock(Registry.class);
    PowerMockito.when(APIUtil.getArtifactManager(any(Registry.class), Mockito.anyString())).thenReturn(artifactManager);
    artifact = Mockito.mock(GenericArtifact.class);
    gatewayManager = Mockito.mock(APIGatewayManager.class);
    Mockito.when(APIGatewayManager.getInstance()).thenReturn(gatewayManager);
    TestUtils.mockRegistryAndUserRealm(-1234);
    TestUtils.mockAPICacheClearence();
    TestUtils.mockAPIMConfiguration();
    mockDocumentationCreation();
    config = Mockito.mock(APIManagerConfiguration.class);
    APIManagerConfigurationService apiManagerConfigurationService = new APIManagerConfigurationServiceImpl(config);
    ServiceReferenceHolder.getInstance().setAPIManagerConfigurationService(apiManagerConfigurationService);
    APIManagerConfiguration config = ServiceReferenceHolder.getInstance().getAPIManagerConfigurationService().getAPIManagerConfiguration();
    GatewayArtifactSynchronizerProperties synchronizerProperties = new GatewayArtifactSynchronizerProperties();
    Mockito.when(config.getGatewayArtifactSynchronizerProperties()).thenReturn(synchronizerProperties);
    Mockito.when(config.getApiRecommendationEnvironment()).thenReturn(null);
    PowerMockito.when(APIUtil.replaceSystemProperty(Mockito.anyString())).thenAnswer((Answer<String>) invocation -> {
        Object[] args = invocation.getArguments();
        return (String) args[0];
    });
    TestUtils.initConfigurationContextService(true);
    superTenantDomain = "carbon.super";
}
Also used : RegistryAuthorizationManager(org.wso2.carbon.registry.core.jdbc.realm.RegistryAuthorizationManager) StringUtils(org.apache.commons.lang.StringUtils) ApiTypeWrapper(org.wso2.carbon.apimgt.api.model.ApiTypeWrapper) APIPersistenceException(org.wso2.carbon.apimgt.persistence.exceptions.APIPersistenceException) PaginationContext(org.wso2.carbon.registry.core.pagination.PaginationContext) LifecycleBean(org.wso2.carbon.governance.custom.lifecycles.checklist.beans.LifecycleBean) QuotaPolicy(org.wso2.carbon.apimgt.api.model.policy.QuotaPolicy) RealmService(org.wso2.carbon.user.core.service.RealmService) ResourceImpl(org.wso2.carbon.registry.core.ResourceImpl) ImportExportAPI(org.wso2.carbon.apimgt.impl.importexport.ImportExportAPI) Map(java.util.Map) XMLStreamException(javax.xml.stream.XMLStreamException) ApplicationPolicy(org.wso2.carbon.apimgt.api.model.policy.ApplicationPolicy) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException) APIPolicy(org.wso2.carbon.apimgt.api.model.policy.APIPolicy) AuthorizationManager(org.wso2.carbon.user.api.AuthorizationManager) DocumentationType(org.wso2.carbon.apimgt.api.model.DocumentationType) GatewayArtifactSynchronizerProperties(org.wso2.carbon.apimgt.impl.dto.GatewayArtifactSynchronizerProperties) ContentType(org.apache.http.entity.ContentType) Set(java.util.Set) WorkflowConstants(org.wso2.carbon.apimgt.impl.workflow.WorkflowConstants) HTTPVerbCondition(org.wso2.carbon.apimgt.api.model.policy.HTTPVerbCondition) RegistryPersistenceUtil(org.wso2.carbon.apimgt.persistence.utils.RegistryPersistenceUtil) UserStoreManager(org.wso2.carbon.user.core.UserStoreManager) Matchers.any(org.mockito.Matchers.any) IOUtils(org.apache.commons.io.IOUtils) SubscriptionPolicy(org.wso2.carbon.apimgt.api.model.policy.SubscriptionPolicy) APIImportExportException(org.wso2.carbon.apimgt.impl.importexport.APIImportExportException) SubscribedAPI(org.wso2.carbon.apimgt.api.model.SubscribedAPI) GraphQLSchemaDefinition(org.wso2.carbon.apimgt.impl.definitions.GraphQLSchemaDefinition) MultitenantUtils(org.wso2.carbon.utils.multitenancy.MultitenantUtils) Assert.assertFalse(org.junit.Assert.assertFalse) PublisherAPIProduct(org.wso2.carbon.apimgt.persistence.dto.PublisherAPIProduct) QName(javax.xml.namespace.QName) CarbonConstants(org.wso2.carbon.CarbonConstants) APIIdentifier(org.wso2.carbon.apimgt.api.model.APIIdentifier) RegistryService(org.wso2.carbon.registry.core.service.RegistryService) APIStore(org.wso2.carbon.apimgt.api.model.APIStore) BlockConditionNotFoundException(org.wso2.carbon.apimgt.api.BlockConditionNotFoundException) APIStateChangeSimpleWorkflowExecutor(org.wso2.carbon.apimgt.impl.workflow.APIStateChangeSimpleWorkflowExecutor) FaultGatewaysException(org.wso2.carbon.apimgt.api.FaultGatewaysException) UserRealm(org.wso2.carbon.user.api.UserRealm) GovernanceArtifact(org.wso2.carbon.governance.api.common.dataobjects.GovernanceArtifact) RunWith(org.junit.runner.RunWith) GlobalPolicy(org.wso2.carbon.apimgt.api.model.policy.GlobalPolicy) Association(org.wso2.carbon.registry.core.Association) SuppressStaticInitializationFor(org.powermock.core.classloader.annotations.SuppressStaticInitializationFor) ArrayList(java.util.ArrayList) DocumentationContent(org.wso2.carbon.apimgt.api.model.DocumentationContent) Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) RegistryConstants(org.wso2.carbon.registry.core.RegistryConstants) WorkflowProperties(org.wso2.carbon.apimgt.impl.dto.WorkflowProperties) Resource(org.wso2.carbon.registry.core.Resource) APIStateChangeResponse(org.wso2.carbon.apimgt.api.model.APIStateChangeResponse) Collection(org.wso2.carbon.registry.core.Collection) PowerMockito(org.powermock.api.mockito.PowerMockito) Before(org.junit.Before) URITemplate(org.wso2.carbon.apimgt.api.model.URITemplate) DuplicateAPIException(org.wso2.carbon.apimgt.api.model.DuplicateAPIException) Condition(org.wso2.carbon.apimgt.api.model.policy.Condition) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) APIMgtResourceAlreadyExistsException(org.wso2.carbon.apimgt.api.APIMgtResourceAlreadyExistsException) ScopesDAO(org.wso2.carbon.apimgt.impl.dao.ScopesDAO) Field(java.lang.reflect.Field) APIProduct(org.wso2.carbon.apimgt.api.model.APIProduct) APIRevision(org.wso2.carbon.apimgt.api.model.APIRevision) ApiMgtDAO(org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO) File(java.io.File) Assert.assertNull(org.junit.Assert.assertNull) TreeMap(java.util.TreeMap) Subscriber(org.wso2.carbon.apimgt.api.model.Subscriber) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) KeyManagerHolder(org.wso2.carbon.apimgt.impl.factory.KeyManagerHolder) KeyManagerDto(org.wso2.carbon.apimgt.impl.dto.KeyManagerDto) Assert(org.junit.Assert) Assert.assertEquals(org.junit.Assert.assertEquals) GenericArtifactManager(org.wso2.carbon.governance.api.generic.GenericArtifactManager) RegistryContext(org.wso2.carbon.registry.core.config.RegistryContext) ArtifactSynchronizerException(org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.exception.ArtifactSynchronizerException) KeyManager(org.wso2.carbon.apimgt.api.model.KeyManager) APIProductMapper(org.wso2.carbon.apimgt.persistence.mapper.APIProductMapper) RegistryUtils(org.wso2.carbon.registry.core.utils.RegistryUtils) XMLInputFactory(javax.xml.stream.XMLInputFactory) PolicyConstants(org.wso2.carbon.apimgt.api.model.policy.PolicyConstants) APIPersistence(org.wso2.carbon.apimgt.persistence.APIPersistence) Pipeline(org.wso2.carbon.apimgt.api.model.policy.Pipeline) BlockConditionsDTO(org.wso2.carbon.apimgt.api.model.BlockConditionsDTO) XMLStreamReader(javax.xml.stream.XMLStreamReader) UserRegistry(org.wso2.carbon.registry.core.session.UserRegistry) GovernanceUtils(org.wso2.carbon.governance.api.util.GovernanceUtils) NotifierConstants(org.wso2.carbon.apimgt.impl.notification.NotifierConstants) NotificationExecutor(org.wso2.carbon.apimgt.impl.notification.NotificationExecutor) APIUtil(org.wso2.carbon.apimgt.impl.utils.APIUtil) UUID(java.util.UUID) DocumentSourceType(org.wso2.carbon.apimgt.api.model.Documentation.DocumentSourceType) WorkflowException(org.wso2.carbon.apimgt.impl.workflow.WorkflowException) List(java.util.List) JSONObject(org.json.simple.JSONObject) DocumentVisibility(org.wso2.carbon.apimgt.api.model.Documentation.DocumentVisibility) Modifier(java.lang.reflect.Modifier) ResourceFile(org.wso2.carbon.apimgt.api.model.ResourceFile) TenantManager(org.wso2.carbon.user.core.tenant.TenantManager) PublisherAPI(org.wso2.carbon.apimgt.persistence.dto.PublisherAPI) SortedMap(java.util.SortedMap) AssertNotNull(org.apache.synapse.unittest.testcase.data.classes.AssertNotNull) Provider(org.wso2.carbon.apimgt.api.model.Provider) Matchers(org.mockito.Matchers) UserStoreException(org.wso2.carbon.user.api.UserStoreException) PrivilegedCarbonContext(org.wso2.carbon.context.PrivilegedCarbonContext) HashMap(java.util.HashMap) HashSet(java.util.HashSet) APIProductIdentifier(org.wso2.carbon.apimgt.api.model.APIProductIdentifier) Property(org.wso2.carbon.governance.custom.lifecycles.checklist.util.Property) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) RequestCountLimit(org.wso2.carbon.apimgt.api.model.policy.RequestCountLimit) PowerMockRunner(org.powermock.modules.junit4.PowerMockRunner) API(org.wso2.carbon.apimgt.api.model.API) ServiceReferenceHolder(org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder) JavaUtils(org.apache.axis2.util.JavaUtils) NotificationDTO(org.wso2.carbon.apimgt.impl.notification.NotificationDTO) DEFAULT_DIALECT_URI(org.wso2.carbon.apimgt.impl.token.ClaimsRetriever.DEFAULT_DIALECT_URI) OMElement(org.apache.axiom.om.OMElement) Tier(org.wso2.carbon.apimgt.api.model.Tier) UserApplicationAPIUsage(org.wso2.carbon.apimgt.api.dto.UserApplicationAPIUsage) GovernanceException(org.wso2.carbon.governance.api.exception.GovernanceException) APIPublisher(org.wso2.carbon.apimgt.api.model.APIPublisher) WorkflowExecutorFactory(org.wso2.carbon.apimgt.impl.workflow.WorkflowExecutorFactory) Documentation(org.wso2.carbon.apimgt.api.model.Documentation) Assert.assertNotNull(org.junit.Assert.assertNotNull) CertificateManagerImpl(org.wso2.carbon.apimgt.impl.certificatemgt.CertificateManagerImpl) Caching(javax.cache.Caching) WorkflowExecutor(org.wso2.carbon.apimgt.impl.workflow.WorkflowExecutor) GatewayArtifactsMgtDAO(org.wso2.carbon.apimgt.impl.dao.GatewayArtifactsMgtDAO) GenericArtifact(org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact) ArtifactSaver(org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.ArtifactSaver) WorkflowDTO(org.wso2.carbon.apimgt.impl.dto.WorkflowDTO) Mockito(org.mockito.Mockito) OMException(org.apache.axiom.om.OMException) Ignore(org.junit.Ignore) Registry(org.wso2.carbon.registry.core.Registry) CheckListItem(org.wso2.carbon.governance.custom.lifecycles.checklist.util.CheckListItem) StAXOMBuilder(org.apache.axiom.om.impl.builder.StAXOMBuilder) WorkflowStatus(org.wso2.carbon.apimgt.impl.workflow.WorkflowStatus) OASParserUtil(org.wso2.carbon.apimgt.impl.definitions.OASParserUtil) CORSConfiguration(org.wso2.carbon.apimgt.api.model.CORSConfiguration) Organization(org.wso2.carbon.apimgt.persistence.dto.Organization) LifecycleBeanPopulator(org.wso2.carbon.governance.custom.lifecycles.checklist.util.LifecycleBeanPopulator) InputStream(java.io.InputStream) GenericArtifact(org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact) GenericArtifactManager(org.wso2.carbon.governance.api.generic.GenericArtifactManager) HashMap(java.util.HashMap) GatewayArtifactsMgtDAO(org.wso2.carbon.apimgt.impl.dao.GatewayArtifactsMgtDAO) GatewayArtifactSynchronizerProperties(org.wso2.carbon.apimgt.impl.dto.GatewayArtifactSynchronizerProperties) ScopesDAO(org.wso2.carbon.apimgt.impl.dao.ScopesDAO) ApiMgtDAO(org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO) KeyManagerDto(org.wso2.carbon.apimgt.impl.dto.KeyManagerDto) PrivilegedCarbonContext(org.wso2.carbon.context.PrivilegedCarbonContext) UserRegistry(org.wso2.carbon.registry.core.session.UserRegistry) Registry(org.wso2.carbon.registry.core.Registry) ImportExportAPI(org.wso2.carbon.apimgt.impl.importexport.ImportExportAPI) SubscribedAPI(org.wso2.carbon.apimgt.api.model.SubscribedAPI) PublisherAPI(org.wso2.carbon.apimgt.persistence.dto.PublisherAPI) API(org.wso2.carbon.apimgt.api.model.API) KeyManager(org.wso2.carbon.apimgt.api.model.KeyManager) CertificateManagerImpl(org.wso2.carbon.apimgt.impl.certificatemgt.CertificateManagerImpl) Map(java.util.Map) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap) HashMap(java.util.HashMap) APIPersistence(org.wso2.carbon.apimgt.persistence.APIPersistence) Before(org.junit.Before)

Example 87 with APIManagerConfiguration

use of org.wso2.carbon.apimgt.impl.APIManagerConfiguration in project carbon-apimgt by wso2.

the class AbstractAPIManagerTestCase method testGetPolicies.

@Test
public void testGetPolicies() throws APIManagementException, org.wso2.carbon.user.api.UserStoreException, RegistryException, XMLStreamException {
    APIPolicy[] policies1 = { new APIPolicy("policy1") };
    ApplicationPolicy[] policies2 = { new ApplicationPolicy("policy2"), new ApplicationPolicy("policy3") };
    SubscriptionPolicy[] policies3 = { new SubscriptionPolicy("policy4"), new SubscriptionPolicy("policy5"), new SubscriptionPolicy("policy6") };
    GlobalPolicy[] policies4 = { new GlobalPolicy("policy7"), new GlobalPolicy("policy8"), new GlobalPolicy("policy9"), new GlobalPolicy("policy0") };
    PowerMockito.mockStatic(APIUtil.class);
    BDDMockito.when(APIUtil.getTenantId(Mockito.anyString())).thenReturn(-1234);
    PowerMockito.when(APIUtil.replaceSystemProperty(Mockito.anyString())).thenAnswer((Answer<String>) invocation -> {
        Object[] args = invocation.getArguments();
        return (String) args[0];
    });
    AbstractAPIManager abstractAPIManager = new AbstractAPIManagerWrapper(apiMgtDAO);
    Mockito.when(apiMgtDAO.getAPIPolicies(Mockito.anyInt())).thenReturn(policies1);
    Mockito.when(apiMgtDAO.getApplicationPolicies(Mockito.anyInt())).thenReturn(policies2);
    Mockito.when(apiMgtDAO.getSubscriptionPolicies(Mockito.anyInt())).thenReturn(policies3);
    Mockito.when(apiMgtDAO.getGlobalPolicies(Mockito.anyInt())).thenReturn(policies4);
    ServiceReferenceHolder sh = mockRegistryAndUserRealm(-1234);
    APIManagerConfigurationService amConfigService = Mockito.mock(APIManagerConfigurationService.class);
    APIManagerConfiguration amConfig = Mockito.mock(APIManagerConfiguration.class);
    ThrottleProperties throttleProperties = Mockito.mock(ThrottleProperties.class, Mockito.RETURNS_MOCKS);
    PowerMockito.when(sh.getAPIManagerConfigurationService()).thenReturn(amConfigService);
    PowerMockito.when(amConfigService.getAPIManagerConfiguration()).thenReturn(amConfig);
    PowerMockito.when(amConfig.getThrottleProperties()).thenReturn(throttleProperties);
    Assert.assertEquals(abstractAPIManager.getPolicies(API_PROVIDER, PolicyConstants.POLICY_LEVEL_API).length, 1);
    Assert.assertEquals(abstractAPIManager.getPolicies(API_PROVIDER, PolicyConstants.POLICY_LEVEL_APP).length, 2);
    PowerMockito.when(throttleProperties.isEnableUnlimitedTier()).thenReturn(false);
    Assert.assertEquals(3, abstractAPIManager.getPolicies(API_PROVIDER, PolicyConstants.POLICY_LEVEL_SUB).length);
    Assert.assertEquals(4, abstractAPIManager.getPolicies(API_PROVIDER, PolicyConstants.POLICY_LEVEL_GLOBAL).length);
    Assert.assertEquals(0, abstractAPIManager.getPolicies(API_PROVIDER, "Test").length);
}
Also used : RegistryAuthorizationManager(org.wso2.carbon.registry.core.jdbc.realm.RegistryAuthorizationManager) APIPersistenceException(org.wso2.carbon.apimgt.persistence.exceptions.APIPersistenceException) PaginationContext(org.wso2.carbon.registry.core.pagination.PaginationContext) RealmService(org.wso2.carbon.user.core.service.RealmService) ResourceImpl(org.wso2.carbon.registry.core.ResourceImpl) Map(java.util.Map) XMLStreamException(javax.xml.stream.XMLStreamException) ApplicationPolicy(org.wso2.carbon.apimgt.api.model.policy.ApplicationPolicy) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException) APIPolicy(org.wso2.carbon.apimgt.api.model.policy.APIPolicy) DocumentationType(org.wso2.carbon.apimgt.api.model.DocumentationType) ContentType(org.apache.http.entity.ContentType) Set(java.util.Set) StandardCharsets(java.nio.charset.StandardCharsets) Matchers.any(org.mockito.Matchers.any) IOUtils(org.apache.commons.io.IOUtils) SubscriptionPolicy(org.wso2.carbon.apimgt.api.model.policy.SubscriptionPolicy) SubscribedAPI(org.wso2.carbon.apimgt.api.model.SubscribedAPI) GraphQLSchemaDefinition(org.wso2.carbon.apimgt.impl.definitions.GraphQLSchemaDefinition) MultitenantUtils(org.wso2.carbon.utils.multitenancy.MultitenantUtils) QName(javax.xml.namespace.QName) TestUtils.mockRegistryAndUserRealm(org.wso2.carbon.apimgt.impl.TestUtils.mockRegistryAndUserRealm) CarbonConstants(org.wso2.carbon.CarbonConstants) APIIdentifier(org.wso2.carbon.apimgt.api.model.APIIdentifier) RegistryService(org.wso2.carbon.registry.core.service.RegistryService) BlockConditionNotFoundException(org.wso2.carbon.apimgt.api.BlockConditionNotFoundException) Mock(org.mockito.Mock) GovernanceArtifact(org.wso2.carbon.governance.api.common.dataobjects.GovernanceArtifact) CARBON_HOME(org.wso2.carbon.utils.ServerConstants.CARBON_HOME) RunWith(org.junit.runner.RunWith) GlobalPolicy(org.wso2.carbon.apimgt.api.model.policy.GlobalPolicy) Association(org.wso2.carbon.registry.core.Association) ArrayList(java.util.ArrayList) Answer(org.mockito.stubbing.Answer) RegistryConstants(org.wso2.carbon.registry.core.RegistryConstants) ResourceDO(org.wso2.carbon.registry.core.jdbc.dataobjects.ResourceDO) Resource(org.wso2.carbon.registry.core.Resource) Collection(org.wso2.carbon.registry.core.Collection) PowerMockito(org.powermock.api.mockito.PowerMockito) PublisherAPISearchResult(org.wso2.carbon.apimgt.persistence.dto.PublisherAPISearchResult) Before(org.junit.Before) GenericArtifactImpl(org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifactImpl) Wsdl(org.wso2.carbon.apimgt.api.model.Wsdl) ThrottleProperties(org.wso2.carbon.apimgt.impl.dto.ThrottleProperties) Test(org.junit.Test) PolicyNotFoundException(org.wso2.carbon.apimgt.api.PolicyNotFoundException) IOException(java.io.IOException) APIMgtResourceAlreadyExistsException(org.wso2.carbon.apimgt.api.APIMgtResourceAlreadyExistsException) ScopesDAO(org.wso2.carbon.apimgt.impl.dao.ScopesDAO) Field(java.lang.reflect.Field) ApiMgtDAO(org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO) BDDMockito(org.mockito.BDDMockito) TreeMap(java.util.TreeMap) Subscriber(org.wso2.carbon.apimgt.api.model.Subscriber) Mediation(org.wso2.carbon.apimgt.api.model.Mediation) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) KeyManagerHolder(org.wso2.carbon.apimgt.impl.factory.KeyManagerHolder) KeyManagerDto(org.wso2.carbon.apimgt.impl.dto.KeyManagerDto) Assert(org.junit.Assert) GenericArtifactManager(org.wso2.carbon.governance.api.generic.GenericArtifactManager) RegistryContext(org.wso2.carbon.registry.core.config.RegistryContext) SortedSet(java.util.SortedSet) KeyManager(org.wso2.carbon.apimgt.api.model.KeyManager) RegistryUtils(org.wso2.carbon.registry.core.utils.RegistryUtils) PolicyConstants(org.wso2.carbon.apimgt.api.model.policy.PolicyConstants) APIPersistence(org.wso2.carbon.apimgt.persistence.APIPersistence) PublisherAPIInfo(org.wso2.carbon.apimgt.persistence.dto.PublisherAPIInfo) UserRegistry(org.wso2.carbon.registry.core.session.UserRegistry) GovernanceUtils(org.wso2.carbon.governance.api.util.GovernanceUtils) Application(org.wso2.carbon.apimgt.api.model.Application) AXIOMUtil(org.apache.axiom.om.util.AXIOMUtil) APIUtil(org.wso2.carbon.apimgt.impl.utils.APIUtil) OASPersistenceException(org.wso2.carbon.apimgt.persistence.exceptions.OASPersistenceException) UUID(java.util.UUID) UserContext(org.wso2.carbon.apimgt.persistence.dto.UserContext) List(java.util.List) Modifier(java.lang.reflect.Modifier) ResourceFile(org.wso2.carbon.apimgt.api.model.ResourceFile) TenantManager(org.wso2.carbon.user.core.tenant.TenantManager) PublisherAPI(org.wso2.carbon.apimgt.persistence.dto.PublisherAPI) SortedMap(java.util.SortedMap) PrivilegedCarbonContext(org.wso2.carbon.context.PrivilegedCarbonContext) HashMap(java.util.HashMap) HashSet(java.util.HashSet) APIProductIdentifier(org.wso2.carbon.apimgt.api.model.APIProductIdentifier) ArrayInputStream(org.apache.derby.iapi.services.io.ArrayInputStream) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) PowerMockRunner(org.powermock.modules.junit4.PowerMockRunner) API(org.wso2.carbon.apimgt.api.model.API) ServiceReferenceHolder(org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder) DEFAULT_DIALECT_URI(org.wso2.carbon.apimgt.impl.token.ClaimsRetriever.DEFAULT_DIALECT_URI) Tier(org.wso2.carbon.apimgt.api.model.Tier) GovernanceException(org.wso2.carbon.governance.api.exception.GovernanceException) DocumentationPersistenceException(org.wso2.carbon.apimgt.persistence.exceptions.DocumentationPersistenceException) Documentation(org.wso2.carbon.apimgt.api.model.Documentation) GenericArtifact(org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact) Mockito(org.mockito.Mockito) UserStoreException(org.wso2.carbon.user.core.UserStoreException) Registry(org.wso2.carbon.registry.core.Registry) Identifier(org.wso2.carbon.apimgt.api.model.Identifier) CollectionImpl(org.wso2.carbon.registry.core.CollectionImpl) APIMgtResourceNotFoundException(org.wso2.carbon.apimgt.api.APIMgtResourceNotFoundException) OASParserUtil(org.wso2.carbon.apimgt.impl.definitions.OASParserUtil) Organization(org.wso2.carbon.apimgt.persistence.dto.Organization) InputStream(java.io.InputStream) ServiceReferenceHolder(org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder) GlobalPolicy(org.wso2.carbon.apimgt.api.model.policy.GlobalPolicy) SubscriptionPolicy(org.wso2.carbon.apimgt.api.model.policy.SubscriptionPolicy) ApplicationPolicy(org.wso2.carbon.apimgt.api.model.policy.ApplicationPolicy) APIPolicy(org.wso2.carbon.apimgt.api.model.policy.APIPolicy) ThrottleProperties(org.wso2.carbon.apimgt.impl.dto.ThrottleProperties) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 88 with APIManagerConfiguration

use of org.wso2.carbon.apimgt.impl.APIManagerConfiguration in project carbon-apimgt by wso2.

the class AbstractAPIManagerTestCase method testGetPoliciesIncludingUnlimitedTier.

@Test
public void testGetPoliciesIncludingUnlimitedTier() throws APIManagementException, org.wso2.carbon.user.api.UserStoreException, RegistryException, XMLStreamException {
    SubscriptionPolicy[] policies3 = { new SubscriptionPolicy("policy4"), new SubscriptionPolicy("policy5"), new SubscriptionPolicy("policy6"), new SubscriptionPolicy(APIConstants.UNLIMITED_TIER) };
    PowerMockito.mockStatic(APIUtil.class);
    BDDMockito.when(APIUtil.getTenantId(Mockito.anyString())).thenReturn(-1234);
    PowerMockito.when(APIUtil.replaceSystemProperty(Mockito.anyString())).thenAnswer((Answer<String>) invocation -> {
        Object[] args = invocation.getArguments();
        return (String) args[0];
    });
    AbstractAPIManager abstractAPIManager = new AbstractAPIManagerWrapper(apiMgtDAO);
    Mockito.when(apiMgtDAO.getSubscriptionPolicies(Mockito.anyInt())).thenReturn(policies3);
    ServiceReferenceHolder sh = mockRegistryAndUserRealm(-1234);
    APIManagerConfigurationService amConfigService = Mockito.mock(APIManagerConfigurationService.class);
    APIManagerConfiguration amConfig = Mockito.mock(APIManagerConfiguration.class);
    ThrottleProperties throttleProperties = Mockito.mock(ThrottleProperties.class);
    PowerMockito.when(sh.getAPIManagerConfigurationService()).thenReturn(amConfigService);
    PowerMockito.when(amConfigService.getAPIManagerConfiguration()).thenReturn(amConfig);
    PowerMockito.when(amConfig.getThrottleProperties()).thenReturn(throttleProperties);
    Mockito.when(throttleProperties.isEnableUnlimitedTier()).thenReturn(true);
    Assert.assertEquals(4, abstractAPIManager.getPolicies(API_PROVIDER, PolicyConstants.POLICY_LEVEL_SUB).length);
}
Also used : RegistryAuthorizationManager(org.wso2.carbon.registry.core.jdbc.realm.RegistryAuthorizationManager) APIPersistenceException(org.wso2.carbon.apimgt.persistence.exceptions.APIPersistenceException) PaginationContext(org.wso2.carbon.registry.core.pagination.PaginationContext) RealmService(org.wso2.carbon.user.core.service.RealmService) ResourceImpl(org.wso2.carbon.registry.core.ResourceImpl) Map(java.util.Map) XMLStreamException(javax.xml.stream.XMLStreamException) ApplicationPolicy(org.wso2.carbon.apimgt.api.model.policy.ApplicationPolicy) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException) APIPolicy(org.wso2.carbon.apimgt.api.model.policy.APIPolicy) DocumentationType(org.wso2.carbon.apimgt.api.model.DocumentationType) ContentType(org.apache.http.entity.ContentType) Set(java.util.Set) StandardCharsets(java.nio.charset.StandardCharsets) Matchers.any(org.mockito.Matchers.any) IOUtils(org.apache.commons.io.IOUtils) SubscriptionPolicy(org.wso2.carbon.apimgt.api.model.policy.SubscriptionPolicy) SubscribedAPI(org.wso2.carbon.apimgt.api.model.SubscribedAPI) GraphQLSchemaDefinition(org.wso2.carbon.apimgt.impl.definitions.GraphQLSchemaDefinition) MultitenantUtils(org.wso2.carbon.utils.multitenancy.MultitenantUtils) QName(javax.xml.namespace.QName) TestUtils.mockRegistryAndUserRealm(org.wso2.carbon.apimgt.impl.TestUtils.mockRegistryAndUserRealm) CarbonConstants(org.wso2.carbon.CarbonConstants) APIIdentifier(org.wso2.carbon.apimgt.api.model.APIIdentifier) RegistryService(org.wso2.carbon.registry.core.service.RegistryService) BlockConditionNotFoundException(org.wso2.carbon.apimgt.api.BlockConditionNotFoundException) Mock(org.mockito.Mock) GovernanceArtifact(org.wso2.carbon.governance.api.common.dataobjects.GovernanceArtifact) CARBON_HOME(org.wso2.carbon.utils.ServerConstants.CARBON_HOME) RunWith(org.junit.runner.RunWith) GlobalPolicy(org.wso2.carbon.apimgt.api.model.policy.GlobalPolicy) Association(org.wso2.carbon.registry.core.Association) ArrayList(java.util.ArrayList) Answer(org.mockito.stubbing.Answer) RegistryConstants(org.wso2.carbon.registry.core.RegistryConstants) ResourceDO(org.wso2.carbon.registry.core.jdbc.dataobjects.ResourceDO) Resource(org.wso2.carbon.registry.core.Resource) Collection(org.wso2.carbon.registry.core.Collection) PowerMockito(org.powermock.api.mockito.PowerMockito) PublisherAPISearchResult(org.wso2.carbon.apimgt.persistence.dto.PublisherAPISearchResult) Before(org.junit.Before) GenericArtifactImpl(org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifactImpl) Wsdl(org.wso2.carbon.apimgt.api.model.Wsdl) ThrottleProperties(org.wso2.carbon.apimgt.impl.dto.ThrottleProperties) Test(org.junit.Test) PolicyNotFoundException(org.wso2.carbon.apimgt.api.PolicyNotFoundException) IOException(java.io.IOException) APIMgtResourceAlreadyExistsException(org.wso2.carbon.apimgt.api.APIMgtResourceAlreadyExistsException) ScopesDAO(org.wso2.carbon.apimgt.impl.dao.ScopesDAO) Field(java.lang.reflect.Field) ApiMgtDAO(org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO) BDDMockito(org.mockito.BDDMockito) TreeMap(java.util.TreeMap) Subscriber(org.wso2.carbon.apimgt.api.model.Subscriber) Mediation(org.wso2.carbon.apimgt.api.model.Mediation) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) KeyManagerHolder(org.wso2.carbon.apimgt.impl.factory.KeyManagerHolder) KeyManagerDto(org.wso2.carbon.apimgt.impl.dto.KeyManagerDto) Assert(org.junit.Assert) GenericArtifactManager(org.wso2.carbon.governance.api.generic.GenericArtifactManager) RegistryContext(org.wso2.carbon.registry.core.config.RegistryContext) SortedSet(java.util.SortedSet) KeyManager(org.wso2.carbon.apimgt.api.model.KeyManager) RegistryUtils(org.wso2.carbon.registry.core.utils.RegistryUtils) PolicyConstants(org.wso2.carbon.apimgt.api.model.policy.PolicyConstants) APIPersistence(org.wso2.carbon.apimgt.persistence.APIPersistence) PublisherAPIInfo(org.wso2.carbon.apimgt.persistence.dto.PublisherAPIInfo) UserRegistry(org.wso2.carbon.registry.core.session.UserRegistry) GovernanceUtils(org.wso2.carbon.governance.api.util.GovernanceUtils) Application(org.wso2.carbon.apimgt.api.model.Application) AXIOMUtil(org.apache.axiom.om.util.AXIOMUtil) APIUtil(org.wso2.carbon.apimgt.impl.utils.APIUtil) OASPersistenceException(org.wso2.carbon.apimgt.persistence.exceptions.OASPersistenceException) UUID(java.util.UUID) UserContext(org.wso2.carbon.apimgt.persistence.dto.UserContext) List(java.util.List) Modifier(java.lang.reflect.Modifier) ResourceFile(org.wso2.carbon.apimgt.api.model.ResourceFile) TenantManager(org.wso2.carbon.user.core.tenant.TenantManager) PublisherAPI(org.wso2.carbon.apimgt.persistence.dto.PublisherAPI) SortedMap(java.util.SortedMap) PrivilegedCarbonContext(org.wso2.carbon.context.PrivilegedCarbonContext) HashMap(java.util.HashMap) HashSet(java.util.HashSet) APIProductIdentifier(org.wso2.carbon.apimgt.api.model.APIProductIdentifier) ArrayInputStream(org.apache.derby.iapi.services.io.ArrayInputStream) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) PowerMockRunner(org.powermock.modules.junit4.PowerMockRunner) API(org.wso2.carbon.apimgt.api.model.API) ServiceReferenceHolder(org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder) DEFAULT_DIALECT_URI(org.wso2.carbon.apimgt.impl.token.ClaimsRetriever.DEFAULT_DIALECT_URI) Tier(org.wso2.carbon.apimgt.api.model.Tier) GovernanceException(org.wso2.carbon.governance.api.exception.GovernanceException) DocumentationPersistenceException(org.wso2.carbon.apimgt.persistence.exceptions.DocumentationPersistenceException) Documentation(org.wso2.carbon.apimgt.api.model.Documentation) GenericArtifact(org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact) Mockito(org.mockito.Mockito) UserStoreException(org.wso2.carbon.user.core.UserStoreException) Registry(org.wso2.carbon.registry.core.Registry) Identifier(org.wso2.carbon.apimgt.api.model.Identifier) CollectionImpl(org.wso2.carbon.registry.core.CollectionImpl) APIMgtResourceNotFoundException(org.wso2.carbon.apimgt.api.APIMgtResourceNotFoundException) OASParserUtil(org.wso2.carbon.apimgt.impl.definitions.OASParserUtil) Organization(org.wso2.carbon.apimgt.persistence.dto.Organization) InputStream(java.io.InputStream) ServiceReferenceHolder(org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder) SubscriptionPolicy(org.wso2.carbon.apimgt.api.model.policy.SubscriptionPolicy) ThrottleProperties(org.wso2.carbon.apimgt.impl.dto.ThrottleProperties) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 89 with APIManagerConfiguration

use of org.wso2.carbon.apimgt.impl.APIManagerConfiguration in project carbon-apimgt by wso2.

the class APIProviderImplTest method testUpdateAPI_InCreatedState.

@Test
public void testUpdateAPI_InCreatedState() throws Exception {
    APIIdentifier identifier = new APIIdentifier("admin-AT-carbon.super", "API1", "1.0.0");
    Set<String> environments = new HashSet<String>();
    Set<URITemplate> uriTemplates = new HashSet<URITemplate>();
    Set<URITemplate> newUriTemplates = 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);
    URITemplate uriTemplate2 = new URITemplate();
    uriTemplate2.setHTTPVerb("PUT");
    uriTemplate2.setAuthType("Application");
    uriTemplate2.setUriTemplate("/update");
    uriTemplate2.setThrottlingTier("Gold");
    newUriTemplates.add(uriTemplate1);
    newUriTemplates.add(uriTemplate2);
    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(newUriTemplates);
    api.setOrganization("carbon.super");
    API oldApi = new API(identifier);
    oldApi.setStatus(APIConstants.CREATED);
    oldApi.setVisibility("public");
    oldApi.setAccessControl("all");
    oldApi.setContext("/test");
    oldApi.setEnvironments(environments);
    api.setUriTemplates(uriTemplates);
    oldApi.setOrganization("carbon.super");
    List<Documentation> documentationList = getDocumentationList();
    Documentation documentation = documentationList.get(1);
    Mockito.when(APIUtil.getAPIDocPath(api.getId())).thenReturn(documentation.getFilePath());
    APIProviderImplWrapper apiProviderImplWrapper = new APIProviderImplWrapper(apiPersistenceInstance, apimgtDAO, scopesDAO);
    Resource docResource = Mockito.mock(Resource.class);
    Mockito.when(docResource.getUUID()).thenReturn(documentation.getId());
    Mockito.when(apiProviderImplWrapper.registry.get(documentation.getFilePath())).thenReturn(docResource);
    GenericArtifact docArtifact = Mockito.mock(GenericArtifact.class);
    Mockito.when(artifactManager.getGenericArtifact(documentation.getId())).thenReturn(docArtifact);
    Mockito.when(APIUtil.getDocumentation(docArtifact)).thenReturn(documentation);
    Mockito.when(docArtifact.getPath()).thenReturn(artifactPath);
    PowerMockito.doNothing().when(APIUtil.class, "clearResourcePermissions", Mockito.any(), Mockito.any(), Mockito.anyInt());
    String[] roles = { "admin", "subscriber" };
    APIUtil.setResourcePermissions("admin", "Public", roles, artifactPath);
    Mockito.when(docArtifact.getAttribute(APIConstants.DOC_FILE_PATH)).thenReturn("docFilePath");
    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(artifactManager.newGovernanceArtifact(any(QName.class))).thenReturn(artifact);
    Mockito.when(APIUtil.createAPIArtifactContent(artifact, oldApi)).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(oldApi);
    // mock has permission
    Resource apiSourceArtifact = Mockito.mock(Resource.class);
    Mockito.when(apiSourceArtifact.getUUID()).thenReturn("12640983654");
    String apiSourcePath = "path";
    PowerMockito.when(APIUtil.getAPIPath(api.getId())).thenReturn(apiSourcePath);
    PowerMockito.when(APIUtil.getAPIPath(oldApi.getId())).thenReturn(apiSourcePath);
    PowerMockito.when(apiProvider.registry.get(apiSourcePath)).thenReturn(apiSourceArtifact);
    // API Status is CREATED and user has permission
    Mockito.when(artifact.getAttribute(APIConstants.API_OVERVIEW_STATUS)).thenReturn("CREATED");
    Mockito.when(artifactManager.getGenericArtifact(apiSourceArtifact.getUUID())).thenReturn(artifact);
    PowerMockito.when(APIUtil.hasPermission(null, APIConstants.Permissions.API_PUBLISH)).thenReturn(true);
    PowerMockito.when(APIUtil.hasPermission(null, APIConstants.Permissions.API_CREATE)).thenReturn(true);
    Mockito.when(apimgtDAO.getDefaultVersion(identifier)).thenReturn("1.0.0");
    Mockito.when(apimgtDAO.getPublishedDefaultVersion(identifier)).thenReturn("1.0.0");
    // updateDefaultAPIInRegistry
    String defaultAPIPath = APIConstants.API_LOCATION + RegistryConstants.PATH_SEPARATOR + identifier.getProviderName() + RegistryConstants.PATH_SEPARATOR + identifier.getApiName() + RegistryConstants.PATH_SEPARATOR + identifier.getVersion() + APIConstants.API_RESOURCE_NAME;
    Resource defaultAPISourceArtifact = Mockito.mock(Resource.class);
    String defaultAPIUUID = "12640983600";
    Mockito.when(defaultAPISourceArtifact.getUUID()).thenReturn(defaultAPIUUID);
    Mockito.when(apiProvider.registry.get(defaultAPIPath)).thenReturn(defaultAPISourceArtifact);
    GenericArtifact defaultAPIArtifact = Mockito.mock(GenericArtifact.class);
    Mockito.when(artifactManager.getGenericArtifact(defaultAPIUUID)).thenReturn(defaultAPIArtifact);
    Mockito.doNothing().when(artifactManager).updateGenericArtifact(defaultAPIArtifact);
    TestUtils.mockAPIMConfiguration(APIConstants.API_GATEWAY_TYPE, APIConstants.API_GATEWAY_TYPE_SYNAPSE, -1234);
    // updateApiArtifact
    PowerMockito.when(APIUtil.createAPIArtifactContent(artifact, api)).thenReturn(artifact);
    Mockito.when(artifact.getId()).thenReturn("12640983654");
    PowerMockito.when(GovernanceUtils.getArtifactPath(apiProvider.registry, "12640983654")).thenReturn(apiSourcePath);
    // Mock Updating API
    Mockito.doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            apiProvider.createAPI(api);
            return null;
        }
    }).when(artifactManager).updateGenericArtifact(artifact);
    APIManagerConfiguration config = ServiceReferenceHolder.getInstance().getAPIManagerConfigurationService().getAPIManagerConfiguration();
    GatewayArtifactSynchronizerProperties synchronizerProperties = new GatewayArtifactSynchronizerProperties();
    Mockito.when(config.getGatewayArtifactSynchronizerProperties()).thenReturn(synchronizerProperties);
    PowerMockito.when(apiPersistenceInstance.getPublisherAPI(any(Organization.class), any(String.class))).thenReturn(publisherAPI);
    Mockito.when(APIUtil.getTiers(APIConstants.TIER_RESOURCE_TYPE, "carbon.super")).thenReturn(tiers);
    apiProvider.updateAPI(api, oldApi);
    Assert.assertEquals(0, api.getEnvironments().size());
    tiers.remove("Gold", tier);
    tier = new Tier("Unlimited");
    tiers.put("Unlimited", tier);
    try {
        apiProvider.updateAPI(api, oldApi);
    } catch (APIManagementException ex) {
        Assert.assertTrue(ex.getMessage().contains("Invalid x-throttling tier Gold found in api definition for " + "resource POST /add"));
    }
}
Also used : ServiceReferenceHolder(org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder) Organization(org.wso2.carbon.apimgt.persistence.dto.Organization) GatewayArtifactSynchronizerProperties(org.wso2.carbon.apimgt.impl.dto.GatewayArtifactSynchronizerProperties) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) PublisherAPI(org.wso2.carbon.apimgt.persistence.dto.PublisherAPI) APIIdentifier(org.wso2.carbon.apimgt.api.model.APIIdentifier) RegistryService(org.wso2.carbon.registry.core.service.RegistryService) TenantManager(org.wso2.carbon.user.core.tenant.TenantManager) HashSet(java.util.HashSet) GenericArtifact(org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact) Tier(org.wso2.carbon.apimgt.api.model.Tier) QName(javax.xml.namespace.QName) Documentation(org.wso2.carbon.apimgt.api.model.Documentation) URITemplate(org.wso2.carbon.apimgt.api.model.URITemplate) Resource(org.wso2.carbon.registry.core.Resource) UserRegistry(org.wso2.carbon.registry.core.session.UserRegistry) TreeMap(java.util.TreeMap) RealmService(org.wso2.carbon.user.core.service.RealmService) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ImportExportAPI(org.wso2.carbon.apimgt.impl.importexport.ImportExportAPI) SubscribedAPI(org.wso2.carbon.apimgt.api.model.SubscribedAPI) PublisherAPI(org.wso2.carbon.apimgt.persistence.dto.PublisherAPI) API(org.wso2.carbon.apimgt.api.model.API) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 90 with APIManagerConfiguration

use of org.wso2.carbon.apimgt.impl.APIManagerConfiguration 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());
}
Also used : ServiceReferenceHolder(org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder) UserRealm(org.wso2.carbon.user.api.UserRealm) RealmService(org.wso2.carbon.user.core.service.RealmService) UserStoreManager(org.wso2.carbon.user.core.UserStoreManager) TreeMap(java.util.TreeMap) TenantManager(org.wso2.carbon.user.core.tenant.TenantManager) Map(java.util.Map) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap) HashMap(java.util.HashMap) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

APIManagerConfiguration (org.wso2.carbon.apimgt.impl.APIManagerConfiguration)122 Test (org.junit.Test)76 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)67 ServiceReferenceHolder (org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder)51 HashMap (java.util.HashMap)39 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)36 RealmService (org.wso2.carbon.user.core.service.RealmService)33 APIManagerConfigurationService (org.wso2.carbon.apimgt.impl.APIManagerConfigurationService)31 ArrayList (java.util.ArrayList)26 API (org.wso2.carbon.apimgt.api.model.API)25 Before (org.junit.Before)24 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)24 UserRegistry (org.wso2.carbon.registry.core.session.UserRegistry)24 ThrottleProperties (org.wso2.carbon.apimgt.impl.dto.ThrottleProperties)23 TenantManager (org.wso2.carbon.user.core.tenant.TenantManager)23 ApiMgtDAO (org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO)22 MessageContext (org.apache.synapse.MessageContext)20 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)20 Cache (javax.cache.Cache)19 Map (java.util.Map)18