Search in sources :

Example 26 with ThrottleProperties

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

the class APIManagerComponentTest method testShouldActivateWhenAllPrerequisitesMet.

@Test
public void testShouldActivateWhenAllPrerequisitesMet() throws Exception {
    PowerMockito.mockStatic(APIMgtDBUtil.class);
    PowerMockito.mockStatic(APIUtil.class);
    PowerMockito.mockStatic(AuthorizationUtils.class);
    PowerMockito.mockStatic(RegistryUtils.class);
    PowerMockito.mockStatic(ServiceReferenceHolder.class);
    PowerMockito.mockStatic(SQLConstantManagerFactory.class);
    ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class);
    ComponentContext componentContext = Mockito.mock(ComponentContext.class);
    BundleContext bundleContext = Mockito.mock(BundleContext.class);
    APIManagerConfiguration configuration = Mockito.mock(APIManagerConfiguration.class);
    APIManagerConfigurationService configurationService = Mockito.mock(APIManagerConfigurationService.class);
    AuthorizationManager authManager = Mockito.mock(AuthorizationManager.class);
    Registry registry = Mockito.mock(Registry.class);
    RealmService realmService = Mockito.mock(RealmService.class);
    UserRealm userRealm = Mockito.mock(UserRealm.class);
    OutputEventAdapterService adapterService = Mockito.mock(OutputEventAdapterService.class);
    ThrottleProperties throttleProperties = new ThrottleProperties();
    Mockito.doNothing().when(configuration).load(Mockito.anyString());
    Mockito.doNothing().when(authManager).authorizeRole(Mockito.anyString(), Mockito.anyString(), Mockito.anyString());
    Mockito.doNothing().when(adapterService).create(null);
    Mockito.when(componentContext.getBundleContext()).thenReturn(bundleContext);
    Mockito.when(registry.resourceExists(Mockito.anyString())).thenReturn(true);
    Mockito.when(configuration.getFirstProperty(Mockito.anyString())).thenReturn("").thenReturn(null);
    Mockito.when(bundleContext.registerService("", CommonConfigDeployer.class, null)).thenReturn(null);
    Mockito.when(authManager.isRoleAuthorized(Mockito.anyString(), Mockito.anyString(), Mockito.anyString())).thenReturn(true);
    Mockito.when(serviceReferenceHolder.getRealmService()).thenReturn(realmService);
    Mockito.when(serviceReferenceHolder.getAPIManagerConfigurationService()).thenReturn(configurationService);
    Mockito.when(serviceReferenceHolder.getOutputEventAdapterService()).thenReturn(adapterService);
    Mockito.when(configurationService.getAPIManagerConfiguration()).thenReturn(configuration);
    Mockito.when(realmService.getTenantUserRealm(Mockito.anyInt())).thenReturn(userRealm);
    Mockito.when(userRealm.getAuthorizationManager()).thenReturn(authManager);
    Mockito.when(configuration.getThrottleProperties()).thenReturn(throttleProperties);
    PowerMockito.doNothing().when(APIMgtDBUtil.class, "initialize");
    PowerMockito.doNothing().when(APIUtil.class, "loadTenantExternalStoreConfig", Mockito.anyString());
    PowerMockito.doNothing().when(AuthorizationUtils.class, "addAuthorizeRoleListener", Mockito.anyInt(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString());
    PowerMockito.doNothing().when(SQLConstantManagerFactory.class, "initializeSQLConstantManager");
    PowerMockito.when(APIUtil.getMountedPath(null, "")).thenReturn("");
    PowerMockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
    PowerMockito.when(RegistryUtils.getAbsolutePath(null, null)).thenReturn("");
    PowerMockito.whenNew(APIManagerConfiguration.class).withAnyArguments().thenReturn(configuration);
    PowerMockito.mockStatic(ApiMgtDAO.class);
    ApiMgtDAO apiMgtDAO = Mockito.mock(ApiMgtDAO.class);
    PowerMockito.when(ApiMgtDAO.getInstance()).thenReturn(apiMgtDAO);
    APIManagerConfiguration config = ServiceReferenceHolder.getInstance().getAPIManagerConfigurationService().getAPIManagerConfiguration();
    APIManagerComponent apiManagerComponent = new APIManagerComponentWrapper(registry);
    GatewayArtifactSynchronizerProperties synchronizerProperties = new GatewayArtifactSynchronizerProperties();
    Mockito.when(config.getGatewayArtifactSynchronizerProperties()).thenReturn(synchronizerProperties);
    EventHubConfigurationDto eventHubConfigurationDto = new EventHubConfigurationDto();
    eventHubConfigurationDto.setEnabled(true);
    eventHubConfigurationDto.setInitDelay(0);
    eventHubConfigurationDto.setUsername("a");
    eventHubConfigurationDto.setPassword("sss".toCharArray());
    eventHubConfigurationDto.setServiceUrl("https://localhost");
    EventHubConfigurationDto.EventHubPublisherConfiguration eventHubPublisherConfiguration = new EventHubConfigurationDto.EventHubPublisherConfiguration();
    eventHubConfigurationDto.setEventHubPublisherConfiguration(eventHubPublisherConfiguration);
    Mockito.when(config.getEventHubConfigurationDto()).thenReturn(eventHubConfigurationDto);
    try {
        apiManagerComponent.activate(componentContext);
    } catch (FileNotFoundException f) {
        // Exception thrown here means that method was continued without the configuration file
        Assert.fail("Should not throw an exception");
    }
}
Also used : APIManagerConfiguration(org.wso2.carbon.apimgt.impl.APIManagerConfiguration) ComponentContext(org.osgi.service.component.ComponentContext) APIManagerConfigurationService(org.wso2.carbon.apimgt.impl.APIManagerConfigurationService) GatewayArtifactSynchronizerProperties(org.wso2.carbon.apimgt.impl.dto.GatewayArtifactSynchronizerProperties) FileNotFoundException(java.io.FileNotFoundException) ApiMgtDAO(org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO) Registry(org.wso2.carbon.registry.api.Registry) EventHubConfigurationDto(org.wso2.carbon.apimgt.impl.dto.EventHubConfigurationDto) UserRealm(org.wso2.carbon.user.api.UserRealm) RealmService(org.wso2.carbon.user.core.service.RealmService) OutputEventAdapterService(org.wso2.carbon.event.output.adapter.core.OutputEventAdapterService) APIManagerComponentWrapper(org.wso2.carbon.apimgt.impl.internal.util.APIManagerComponentWrapper) AuthorizationManager(org.wso2.carbon.user.api.AuthorizationManager) BundleContext(org.osgi.framework.BundleContext) ThrottleProperties(org.wso2.carbon.apimgt.impl.dto.ThrottleProperties) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 27 with ThrottleProperties

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

the class CommonConfigDeployerTestCase method testCreatedConfigurationContext.

@Test
public void testCreatedConfigurationContext() throws APIManagementException {
    PowerMockito.mockStatic(CommonUtil.class);
    System.setProperty(CARBON_HOME, "");
    PrivilegedCarbonContext privilegedCarbonContext = Mockito.mock(PrivilegedCarbonContext.class);
    PowerMockito.mockStatic(PrivilegedCarbonContext.class);
    PowerMockito.when(PrivilegedCarbonContext.getThreadLocalCarbonContext()).thenReturn(privilegedCarbonContext);
    Mockito.when(privilegedCarbonContext.getTenantDomain()).thenReturn(TENANT_DOMAIN);
    Mockito.when(privilegedCarbonContext.getTenantId()).thenReturn(TENANT_ID);
    ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class);
    PowerMockito.mockStatic(ServiceReferenceHolder.class);
    PowerMockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
    APIManagerConfigurationService apiManagerConfigurationService = Mockito.mock(APIManagerConfigurationService.class);
    Mockito.when(serviceReferenceHolder.getAPIManagerConfigurationService()).thenReturn(apiManagerConfigurationService);
    APIManagerConfiguration apiManagerConfiguration = Mockito.mock(APIManagerConfiguration.class);
    Mockito.when(apiManagerConfigurationService.getAPIManagerConfiguration()).thenReturn(apiManagerConfiguration);
    ThrottleProperties throttleProperties = new ThrottleProperties();
    RegistryService registryService = Mockito.mock(RegistryService.class);
    Mockito.when(ServiceReferenceHolder.getInstance().getRegistryService()).thenReturn(registryService);
    Mockito.when(apiManagerConfiguration.getThrottleProperties()).thenReturn(throttleProperties);
    ThrottleProperties.PolicyDeployer policyDeployer = Mockito.mock(ThrottleProperties.PolicyDeployer.class);
    throttleProperties.setPolicyDeployer(policyDeployer);
    Mockito.when(apiManagerConfiguration.getFirstProperty(APIConstants.API_GATEWAY_TYPE)).thenReturn(APIConstants.API_GATEWAY_TYPE_SYNAPSE);
    ConfigurationContext configurationContext = Mockito.mock(ConfigurationContext.class);
    PowerMockito.mockStatic(APIUtil.class);
    CommonConfigDeployer commonConfigDeployer = new CommonConfigDeployer();
    commonConfigDeployer.createdConfigurationContext(configurationContext);
    PowerMockito.verifyStatic(APIUtil.class);
    APIUtil.createDefaultRoles(TENANT_ID);
    PowerMockito.verifyStatic(APIUtil.class);
    APIUtil.loadAndSyncTenantConf(TENANT_DOMAIN);
// PowerMockito.verifyStatic(APIUtil.class);
// APIUtil.addDefaultTenantAdvancedThrottlePolicies(TENANT_DOMAIN, TENANT_ID);
}
Also used : ServiceReferenceHolder(org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) APIManagerConfiguration(org.wso2.carbon.apimgt.impl.APIManagerConfiguration) APIManagerConfigurationService(org.wso2.carbon.apimgt.impl.APIManagerConfigurationService) PrivilegedCarbonContext(org.wso2.carbon.context.PrivilegedCarbonContext) RegistryService(org.wso2.carbon.registry.core.service.RegistryService) ThrottleProperties(org.wso2.carbon.apimgt.impl.dto.ThrottleProperties) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 28 with ThrottleProperties

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

the class ThrottleConditionEvaluator method isThrottledWithinCondition.

private boolean isThrottledWithinCondition(MessageContext axis2MessageContext, AuthenticationContext authContext, List<ConditionDto> conditionDtoList) {
    ThrottleProperties throttleProperties = ServiceReferenceHolder.getInstance().getThrottleProperties();
    boolean status = true;
    for (ConditionDto condition : conditionDtoList) {
        status = true;
        if (condition.getIpCondition() != null) {
            if (!isMatchingIP(axis2MessageContext, condition.getIpCondition())) {
                status = false;
            }
        } else if (condition.getIpRangeCondition() != null) {
            if (!isWithinIP(axis2MessageContext, condition.getIpRangeCondition())) {
                status = false;
            }
        }
        if (condition.getHeaderConditions() != null && throttleProperties.isEnableHeaderConditions() && !condition.getHeaderConditions().getValues().isEmpty()) {
            if (!isHeaderPresent(axis2MessageContext, condition.getHeaderConditions())) {
                status = false;
            }
        }
        if (condition.getJwtClaimConditions() != null && throttleProperties.isEnableJwtConditions() && !condition.getJwtClaimConditions().getValues().isEmpty()) {
            if (!isJWTClaimPresent(authContext, condition.getJwtClaimConditions())) {
                status = false;
            }
        }
        if (condition.getQueryParameterConditions() != null && throttleProperties.isEnableQueryParamConditions() && !condition.getQueryParameterConditions().getValues().isEmpty()) {
            if (!isQueryParamPresent(axis2MessageContext, condition.getQueryParameterConditions())) {
                status = false;
            }
        }
        if (status) {
            break;
        }
    }
    return status;
}
Also used : ConditionDto(org.wso2.carbon.apimgt.impl.dto.ConditionDto) ThrottleProperties(org.wso2.carbon.apimgt.impl.dto.ThrottleProperties)

Example 29 with ThrottleProperties

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

the class AbstractAPIManagerTestCase method testGetPoliciesIncludeUnlimitedThrottletier.

@Test
public void testGetPoliciesIncludeUnlimitedThrottletier() throws APIManagementException, org.wso2.carbon.user.api.UserStoreException, RegistryException, XMLStreamException {
    SubscriptionPolicy[] policies3 = { new SubscriptionPolicy("policy4"), new SubscriptionPolicy("policy5"), new SubscriptionPolicy("policy6") };
    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, Mockito.RETURNS_MOCKS);
    PowerMockito.when(sh.getAPIManagerConfigurationService()).thenReturn(amConfigService);
    PowerMockito.when(amConfigService.getAPIManagerConfiguration()).thenReturn(amConfig);
    PowerMockito.when(amConfig.getThrottleProperties()).thenReturn(throttleProperties);
    PowerMockito.when(throttleProperties.isEnableUnlimitedTier()).thenReturn(true);
    Assert.assertEquals(3, 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 30 with ThrottleProperties

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

the class PolicyUtilTest method setUp.

@Before
public void setUp() throws Exception {
    System.setProperty("carbon.home", PolicyUtilTest.class.getResource("/").getFile());
    PowerMockito.mockStatic(PrivilegedCarbonContext.class);
    PrivilegedCarbonContext privilegedCarbonContext = Mockito.mock(PrivilegedCarbonContext.class);
    Mockito.when(privilegedCarbonContext.getTenantDomain()).thenReturn("carbon.super");
    PowerMockito.when(PrivilegedCarbonContext.getThreadLocalCarbonContext()).thenReturn(privilegedCarbonContext);
    eventProcessorService = Mockito.mock(EventProcessorService.class);
    PowerMockito.mockStatic(ServiceReferenceHolder.class);
    ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class);
    Mockito.when(serviceReferenceHolder.getEventProcessorService()).thenReturn(eventProcessorService);
    APIManagerConfiguration apiManagerConfiguration = Mockito.mock(APIManagerConfiguration.class);
    ThrottleProperties throttleProperties = Mockito.mock(ThrottleProperties.class);
    String[] skipThrottlePolicies = { "skipPolicy1" };
    Mockito.when(throttleProperties.getSkipRedeployingPolicies()).thenReturn(skipThrottlePolicies);
    Mockito.when(apiManagerConfiguration.getThrottleProperties()).thenReturn(throttleProperties);
    Mockito.when(apiManagerConfiguration.getFirstProperty(APIConstants.VELOCITY_LOGGER)).thenReturn(null);
    Mockito.when(serviceReferenceHolder.getAPIMConfiguration()).thenReturn(apiManagerConfiguration);
    PowerMockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
    policyRetriever = Mockito.mock(PolicyRetriever.class);
    PowerMockito.whenNew(PolicyRetriever.class).withNoArguments().thenReturn(policyRetriever);
}
Also used : ServiceReferenceHolder(org.wso2.carbon.apimgt.throttle.policy.deployer.internal.ServiceReferenceHolder) APIManagerConfiguration(org.wso2.carbon.apimgt.impl.APIManagerConfiguration) PrivilegedCarbonContext(org.wso2.carbon.context.PrivilegedCarbonContext) EventProcessorService(org.wso2.carbon.event.processor.core.EventProcessorService) ThrottleProperties(org.wso2.carbon.apimgt.impl.dto.ThrottleProperties) PolicyRetriever(org.wso2.carbon.apimgt.throttle.policy.deployer.PolicyRetriever) Before(org.junit.Before)

Aggregations

ThrottleProperties (org.wso2.carbon.apimgt.impl.dto.ThrottleProperties)53 Test (org.junit.Test)45 MessageContext (org.apache.synapse.MessageContext)28 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)28 HashMap (java.util.HashMap)22 List (java.util.List)21 TreeMap (java.util.TreeMap)19 ArrayList (java.util.ArrayList)18 ConditionDto (org.wso2.carbon.apimgt.impl.dto.ConditionDto)17 AuthenticationContext (org.wso2.carbon.apimgt.gateway.handlers.security.AuthenticationContext)16 ServiceReferenceHolder (org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder)16 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)15 ApiMgtDAO (org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO)14 RealmService (org.wso2.carbon.user.core.service.RealmService)13 API (org.wso2.carbon.apimgt.keymgt.model.entity.API)12 TenantManager (org.wso2.carbon.user.core.tenant.TenantManager)12 Map (java.util.Map)11 SubscriptionPolicy (org.wso2.carbon.apimgt.api.model.policy.SubscriptionPolicy)11 VerbInfoDTO (org.wso2.carbon.apimgt.impl.dto.VerbInfoDTO)11 APIManagerConfiguration (org.wso2.carbon.apimgt.impl.APIManagerConfiguration)10