Search in sources :

Example 16 with ThrottleProperties

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

the class DataProcessAndPublishingAgentTest method setDataReference.

@Test
public void setDataReference() throws Exception {
    ThrottleProperties throttleProperties = new ThrottleProperties();
    DataPublisher dataPublisher = Mockito.mock(DataPublisher.class);
    Mockito.when(dataPublisher.tryPublish(Mockito.any(Event.class))).thenReturn(true);
    DataProcessAndPublishingAgent dataProcessAndPublishingAgent = new DataProcessAndPublishingAgentWrapper(throttleProperties);
    AuthenticationContext authenticationContext = new AuthenticationContext();
    MessageContext messageContext = Mockito.mock(Axis2MessageContext.class);
    org.apache.axis2.context.MessageContext axis2MsgCntxt = Mockito.mock(org.apache.axis2.context.MessageContext.class);
    Mockito.when(((Axis2MessageContext) messageContext).getAxis2MessageContext()).thenReturn(axis2MsgCntxt);
    VerbInfoDTO verbInfoDTO = new VerbInfoDTO();
    verbInfoDTO.setContentAware(false);
    ArrayList<VerbInfoDTO> list = new ArrayList<VerbInfoDTO>();
    list.add(verbInfoDTO);
    API api = new API();
    api.setUuid(UUID.randomUUID().toString());
    api.setApiName(apiName);
    api.setApiVersion(apiVersion);
    api.setApiProvider("admin");
    Mockito.when(messageContext.getProperty(APIMgtGatewayConstants.API_OBJECT)).thenReturn(api);
    Mockito.when(messageContext.getProperty(APIConstants.VERB_INFO_DTO)).thenReturn(list);
    Mockito.when(axis2MsgCntxt.getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS)).thenReturn(new TreeMap<>());
    dataProcessAndPublishingAgent.setDataReference(applicationLevelThrottleKey, applicationLevelTier, apiLevelThrottleKey, apiLevelTier, subscriptionLevelThrottleKey, subscriptionLevelTier, resourceLevelThrottleKey, resourceLevelTier, authorizedUser, apiContext, apiVersion, appTenant, apiTenant, appId, messageContext, authenticationContext);
    dataProcessAndPublishingAgent.run();
}
Also used : AuthenticationContext(org.wso2.carbon.apimgt.gateway.handlers.security.AuthenticationContext) ArrayList(java.util.ArrayList) VerbInfoDTO(org.wso2.carbon.apimgt.impl.dto.VerbInfoDTO) DataPublisher(org.wso2.carbon.databridge.agent.DataPublisher) Event(org.wso2.carbon.databridge.commons.Event) API(org.wso2.carbon.apimgt.keymgt.model.entity.API) MessageContext(org.apache.synapse.MessageContext) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext) ThrottleProperties(org.wso2.carbon.apimgt.impl.dto.ThrottleProperties) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext) Test(org.junit.Test)

Example 17 with ThrottleProperties

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

the class DataProcessAndPublishingAgentTest method setDataReferenceWithHeaderConditionEnable.

@Test
public void setDataReferenceWithHeaderConditionEnable() throws Exception {
    ThrottleProperties throttleProperties = new ThrottleProperties();
    throttleProperties.setEnableHeaderConditions(true);
    DataProcessAndPublishingAgent dataProcessAndPublishingAgent = new DataProcessAndPublishingAgentWrapper(throttleProperties);
    AuthenticationContext authenticationContext = new AuthenticationContext();
    MessageContext messageContext = Mockito.mock(Axis2MessageContext.class);
    org.apache.axis2.context.MessageContext axis2MsgCntxt = Mockito.mock(org.apache.axis2.context.MessageContext.class);
    Mockito.when(((Axis2MessageContext) messageContext).getAxis2MessageContext()).thenReturn(axis2MsgCntxt);
    Mockito.when(axis2MsgCntxt.getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS)).thenReturn(new TreeMap<>());
    VerbInfoDTO verbInfoDTO = new VerbInfoDTO();
    verbInfoDTO.setContentAware(false);
    ArrayList<VerbInfoDTO> list = new ArrayList<VerbInfoDTO>();
    list.add(verbInfoDTO);
    API api = new API();
    api.setUuid(UUID.randomUUID().toString());
    api.setApiName(apiName);
    api.setApiVersion(apiVersion);
    api.setApiProvider("admin");
    Mockito.when(messageContext.getProperty(APIMgtGatewayConstants.API_OBJECT)).thenReturn(api);
    Mockito.when(messageContext.getProperty(APIConstants.VERB_INFO_DTO)).thenReturn(list);
    dataProcessAndPublishingAgent.setDataReference(applicationLevelThrottleKey, applicationLevelTier, apiLevelThrottleKey, null, subscriptionLevelThrottleKey, subscriptionLevelTier, resourceLevelThrottleKey, resourceLevelTier, authorizedUser, apiContext, apiVersion, appTenant, apiTenant, appId, messageContext, authenticationContext);
    dataProcessAndPublishingAgent.run();
}
Also used : AuthenticationContext(org.wso2.carbon.apimgt.gateway.handlers.security.AuthenticationContext) ArrayList(java.util.ArrayList) VerbInfoDTO(org.wso2.carbon.apimgt.impl.dto.VerbInfoDTO) API(org.wso2.carbon.apimgt.keymgt.model.entity.API) MessageContext(org.apache.synapse.MessageContext) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext) ThrottleProperties(org.wso2.carbon.apimgt.impl.dto.ThrottleProperties) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext) Test(org.junit.Test)

Example 18 with ThrottleProperties

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

the class DataProcessAndPublishingAgentTest method testEnableQueryParamConditionWithoutQueryParams.

@Test
public void testEnableQueryParamConditionWithoutQueryParams() throws Exception {
    ThrottleProperties throttleProperties = new ThrottleProperties();
    throttleProperties.setEnableQueryParamConditions(true);
    throttleProperties.setEnableJwtConditions(true);
    DataProcessAndPublishingAgent dataProcessAndPublishingAgent = new DataProcessAndPublishingAgentWrapper(throttleProperties);
    AuthenticationContext authenticationContext = new AuthenticationContext();
    MessageContext messageContext = Mockito.mock(Axis2MessageContext.class);
    org.apache.axis2.context.MessageContext axis2MsgCntxt = Mockito.mock(org.apache.axis2.context.MessageContext.class);
    Mockito.when(((Axis2MessageContext) messageContext).getAxis2MessageContext()).thenReturn(axis2MsgCntxt);
    Mockito.when(axis2MsgCntxt.getProperty(NhttpConstants.REST_URL_POSTFIX)).thenReturn("");
    TreeMap headers = new TreeMap();
    headers.put(APIMgtGatewayConstants.X_FORWARDED_FOR, "192.168.1.1");
    Mockito.when(axis2MsgCntxt.getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS)).thenReturn(headers);
    VerbInfoDTO verbInfoDTO = new VerbInfoDTO();
    verbInfoDTO.setContentAware(false);
    ArrayList<VerbInfoDTO> list = new ArrayList<VerbInfoDTO>();
    list.add(verbInfoDTO);
    API api = new API();
    api.setUuid(UUID.randomUUID().toString());
    api.setApiName(apiName);
    api.setApiVersion(apiVersion);
    api.setApiProvider("admin");
    Mockito.when(messageContext.getProperty(APIMgtGatewayConstants.API_OBJECT)).thenReturn(api);
    Mockito.when(messageContext.getProperty(APIConstants.VERB_INFO_DTO)).thenReturn(list);
    dataProcessAndPublishingAgent.setDataReference(applicationLevelThrottleKey, applicationLevelTier, apiLevelThrottleKey, null, subscriptionLevelThrottleKey, subscriptionLevelTier, resourceLevelThrottleKey, resourceLevelTier, authorizedUser, apiContext, apiVersion, appTenant, apiTenant, appId, messageContext, authenticationContext);
    dataProcessAndPublishingAgent.run();
}
Also used : AuthenticationContext(org.wso2.carbon.apimgt.gateway.handlers.security.AuthenticationContext) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) VerbInfoDTO(org.wso2.carbon.apimgt.impl.dto.VerbInfoDTO) API(org.wso2.carbon.apimgt.keymgt.model.entity.API) MessageContext(org.apache.synapse.MessageContext) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext) ThrottleProperties(org.wso2.carbon.apimgt.impl.dto.ThrottleProperties) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext) Test(org.junit.Test)

Example 19 with ThrottleProperties

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

the class DataProcessAndPublishingAgentTest method setDataReferenceWithoutApiLevelTier.

@Test
public void setDataReferenceWithoutApiLevelTier() throws Exception {
    ThrottleProperties throttleProperties = new ThrottleProperties();
    DataProcessAndPublishingAgent dataProcessAndPublishingAgent = new DataProcessAndPublishingAgentWrapper(throttleProperties);
    AuthenticationContext authenticationContext = new AuthenticationContext();
    MessageContext messageContext = Mockito.mock(Axis2MessageContext.class);
    org.apache.axis2.context.MessageContext axis2MsgCntxt = Mockito.mock(org.apache.axis2.context.MessageContext.class);
    Mockito.when(((Axis2MessageContext) messageContext).getAxis2MessageContext()).thenReturn(axis2MsgCntxt);
    API api = new API();
    api.setUuid(UUID.randomUUID().toString());
    api.setApiName(apiName);
    api.setApiVersion(apiVersion);
    api.setApiProvider("admin");
    Mockito.when(messageContext.getProperty(APIMgtGatewayConstants.API_OBJECT)).thenReturn(api);
    dataProcessAndPublishingAgent.setDataReference(applicationLevelThrottleKey, applicationLevelTier, apiLevelThrottleKey, null, subscriptionLevelThrottleKey, subscriptionLevelTier, resourceLevelThrottleKey, resourceLevelTier, authorizedUser, apiContext, apiVersion, appTenant, apiTenant, appId, messageContext, authenticationContext);
}
Also used : AuthenticationContext(org.wso2.carbon.apimgt.gateway.handlers.security.AuthenticationContext) API(org.wso2.carbon.apimgt.keymgt.model.entity.API) MessageContext(org.apache.synapse.MessageContext) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext) ThrottleProperties(org.wso2.carbon.apimgt.impl.dto.ThrottleProperties) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext) Test(org.junit.Test)

Example 20 with ThrottleProperties

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

the class ThrottleDataPublisherPoolTest method testGetThrottleDataPublisher.

@Test
public void testGetThrottleDataPublisher() throws Exception {
    ThrottleProperties throttleProperties = new ThrottleProperties();
    ThrottleProperties.DataPublisherPool dataPublisherPool = new ThrottleProperties.DataPublisherPool();
    dataPublisherPool.setMaxIdle(10);
    dataPublisherPool.setInitIdleCapacity(10);
    throttleProperties.setDataPublisherPool(dataPublisherPool);
    ServiceReferenceHolder.getInstance().setThrottleProperties(throttleProperties);
    ThrottleDataPublisherPool throttleDataPublisherPool = ThrottleDataPublisherPool.getInstance();
    DataProcessAndPublishingAgent dataProcessAndPublishingAgent = throttleDataPublisherPool.get();
    throttleDataPublisherPool.release(dataProcessAndPublishingAgent);
    throttleDataPublisherPool.cleanup();
}
Also used : ThrottleProperties(org.wso2.carbon.apimgt.impl.dto.ThrottleProperties) Test(org.junit.Test)

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