use of org.wso2.carbon.apimgt.gateway.throttling.util.KeyTemplateRetriever in project carbon-apimgt by wso2.
the class KeyTemplateRetrieverTest method run.
@Test
public void run() throws Exception {
Map map = new HashMap();
map.put("$userId", "$userId");
map.put("$apiContext", "$apiContext");
map.put("$apiVersion", "$apiVersion");
String content = "[\"$userId\",\"$apiContext\",\"$apiVersion\"]";
PowerMockito.mockStatic(APIUtil.class);
HttpClient httpClient = Mockito.mock(HttpClient.class);
HttpResponse httpResponse = Mockito.mock(HttpResponse.class);
BasicHttpEntity httpEntity = new BasicHttpEntity();
httpEntity.setContent(new ByteArrayInputStream(content.getBytes()));
Mockito.when(httpResponse.getEntity()).thenReturn(httpEntity);
Mockito.when(httpClient.execute(Mockito.any(HttpGet.class))).thenReturn(httpResponse);
StatusLine status = Mockito.mock(StatusLine.class);
Mockito.when(status.getStatusCode()).thenReturn(200);
Mockito.when(httpResponse.getStatusLine()).thenReturn(status);
BDDMockito.given(APIUtil.getHttpClient(Mockito.anyInt(), Mockito.anyString())).willReturn(httpClient);
EventHubConfigurationDto eventHubConfigurationDto = new EventHubConfigurationDto();
eventHubConfigurationDto.setUsername("admin");
eventHubConfigurationDto.setPassword("admin".toCharArray());
eventHubConfigurationDto.setEnabled(true);
eventHubConfigurationDto.setServiceUrl("http://localhost:18084/internal/data/v1");
ThrottleDataHolder throttleDataHolder = new ThrottleDataHolder();
KeyTemplateRetriever keyTemplateRetriever = new KeyTemplateRetrieverWrapper(eventHubConfigurationDto, throttleDataHolder);
keyTemplateRetriever.run();
Map<String, String> keyTemplateMap = throttleDataHolder.getKeyTemplateMap();
Assert.assertNotNull(keyTemplateMap);
Assert.assertEquals(map, keyTemplateMap);
}
use of org.wso2.carbon.apimgt.gateway.throttling.util.KeyTemplateRetriever in project carbon-apimgt by wso2.
the class GatewayStartupListener method retrieveBlockConditionsAndKeyTemplates.
private void retrieveBlockConditionsAndKeyTemplates() {
if (throttleProperties.getBlockCondition().isEnabled()) {
BlockingConditionRetriever webServiceThrottleDataRetriever = new BlockingConditionRetriever();
webServiceThrottleDataRetriever.startWebServiceThrottleDataRetriever();
KeyTemplateRetriever webServiceBlockConditionsRetriever = new KeyTemplateRetriever();
webServiceBlockConditionsRetriever.startKeyTemplateDataRetriever();
// Start web service based revoked JWT tokens retriever.
// Advanced throttle properties & blocking conditions have to be enabled for JWT token
// retrieval due to the throttle config dependency for this feature.
RevokedJWTTokensRetriever webServiceRevokedJWTTokensRetriever = new RevokedJWTTokensRetriever();
webServiceRevokedJWTTokensRetriever.startRevokedJWTTokensRetriever();
}
}
Aggregations