use of org.wso2.carbon.apimgt.impl.dto.VerbInfoDTO in project carbon-apimgt by wso2.
the class InboundWebsocketProcessorUtilTest method testDoThrottleSuccessForGraphQL.
@Test
public void testDoThrottleSuccessForGraphQL() throws ParseException {
InboundMessageContext inboundMessageContext = new InboundMessageContext();
int msgSize = 100;
VerbInfoDTO verbInfoDTO = new VerbInfoDTO();
verbInfoDTO.setThrottling("Gold");
verbInfoDTO.setRequestKey("liftStatusChange");
String operationId = "1";
APIKeyValidationInfoDTO apiKeyValidationInfoDTO = new APIKeyValidationInfoDTO();
apiKeyValidationInfoDTO.setApplicationTier(APIConstants.UNLIMITED_TIER);
apiKeyValidationInfoDTO.setTier(APIConstants.UNLIMITED_TIER);
apiKeyValidationInfoDTO.setSubscriberTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
apiKeyValidationInfoDTO.setSubscriber("admin");
apiKeyValidationInfoDTO.setApiName("GraphQLAPI");
apiKeyValidationInfoDTO.setApplicationId("12");
inboundMessageContext.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
inboundMessageContext.setApiContext("/graphql");
inboundMessageContext.setVersion("1.0.0");
inboundMessageContext.setUserIP("198.162.10.2");
inboundMessageContext.setInfoDTO(apiKeyValidationInfoDTO);
String subscriptionLevelThrottleKey = apiKeyValidationInfoDTO.getApplicationId() + ":" + inboundMessageContext.getApiContext() + ":" + inboundMessageContext.getVersion();
String applicationLevelThrottleKey = apiKeyValidationInfoDTO.getApplicationId() + ":" + apiKeyValidationInfoDTO.getSubscriber() + "@" + apiKeyValidationInfoDTO.getSubscriberTenantDomain();
PowerMockito.when(WebsocketUtil.isThrottled(verbInfoDTO.getRequestKey(), subscriptionLevelThrottleKey, applicationLevelThrottleKey)).thenReturn(false);
Mockito.when(dataPublisher.tryPublish(Mockito.anyObject())).thenReturn(true);
InboundProcessorResponseDTO inboundProcessorResponseDTO = InboundWebsocketProcessorUtil.doThrottleForGraphQL(msgSize, verbInfoDTO, inboundMessageContext, operationId);
Assert.assertFalse(inboundProcessorResponseDTO.isError());
Assert.assertNull(inboundProcessorResponseDTO.getErrorMessage());
Assert.assertFalse(inboundProcessorResponseDTO.isCloseConnection());
}
use of org.wso2.carbon.apimgt.impl.dto.VerbInfoDTO in project carbon-apimgt by wso2.
the class DataProcessAndPublishingAgentTest method testContentAwareTierPresentAndContentLengthNotPresent.
@Test
public void testContentAwareTierPresentAndContentLengthNotPresent() throws Exception {
ThrottleProperties throttleProperties = new ThrottleProperties();
DataProcessAndPublishingAgent dataProcessAndPublishingAgent = new DataProcessAndPublishingAgentWrapper(throttleProperties);
AuthenticationContext authenticationContext = new AuthenticationContext();
authenticationContext.setIsContentAware(true);
MessageContext messageContext = Mockito.mock(Axis2MessageContext.class);
SOAPFactory fac = OMAbstractFactory.getSOAP12Factory();
SOAPEnvelope env = fac.createSOAPEnvelope();
fac.createSOAPBody(env);
env.getBody().addChild(fac.createOMElement("test", "http://t", "t"));
org.apache.axis2.context.MessageContext axis2MsgCntxt = Mockito.mock(org.apache.axis2.context.MessageContext.class);
Mockito.when(messageContext.getEnvelope()).thenReturn(env);
Mockito.when(((Axis2MessageContext) messageContext).getAxis2MessageContext()).thenReturn(axis2MsgCntxt);
TreeMap headers = new TreeMap();
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();
}
use of org.wso2.carbon.apimgt.impl.dto.VerbInfoDTO 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();
}
use of org.wso2.carbon.apimgt.impl.dto.VerbInfoDTO 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();
}
use of org.wso2.carbon.apimgt.impl.dto.VerbInfoDTO 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();
}
Aggregations