use of io.apiman.plugins.jsonp_policy.beans.JsonpConfigBean in project apiman-plugins by apiman.
the class JsonpPolicyTest method testParseEmptyConfiguration.
@Test
public void testParseEmptyConfiguration() {
// given
String config = "{}";
// when
JsonpConfigBean jsonpConfig = jsonpPolicy.parseConfiguration(config);
// then
assertNull(jsonpConfig.getCallbackParamName());
}
use of io.apiman.plugins.jsonp_policy.beans.JsonpConfigBean in project apiman-plugins by apiman.
the class JsonpPolicyTest method testParseRealConfiguration.
@Test
public void testParseRealConfiguration() {
// given
String parameterName = "jsonp";
String config = "{\"callbackParamName\":\"" + parameterName + "\"}";
// when
JsonpConfigBean jsonpConfig = jsonpPolicy.parseConfiguration(config);
// then
assertEquals(parameterName, jsonpConfig.getCallbackParamName());
}
use of io.apiman.plugins.jsonp_policy.beans.JsonpConfigBean in project apiman-plugins by apiman.
the class JsonpPolicyTest method shouldNotSaveCallbackFunctionNameInContextWhenNotPresent.
@Test
public void shouldNotSaveCallbackFunctionNameInContextWhenNotPresent() throws Exception {
// given
JsonpConfigBean config = new JsonpConfigBean();
config.setCallbackParamName("testParam");
QueryMap queryParams = new QueryMap();
ApiRequest request = new ApiRequest();
request.setQueryParams(queryParams);
IPolicyChain<ApiRequest> chain = mock(IPolicyChain.class);
// when
jsonpPolicy.doApply(request, sContext, config, chain);
// then
assertNull(sContext.getAttribute("callbackFunctionName", null));
verify(chain).doApply(request);
}
use of io.apiman.plugins.jsonp_policy.beans.JsonpConfigBean in project apiman-plugins by apiman.
the class JsonpPolicyTest method shouldRemoveCallbackParamNameFromRequest.
@Test
public void shouldRemoveCallbackParamNameFromRequest() throws Exception {
// given
JsonpConfigBean config = new JsonpConfigBean();
config.setCallbackParamName("testParam");
QueryMap queryParams = new QueryMap();
queryParams.put("testParam", "testFunction");
ApiRequest request = new ApiRequest();
request.setQueryParams(queryParams);
IPolicyChain<ApiRequest> chain = mock(IPolicyChain.class);
// when
jsonpPolicy.doApply(request, sContext, config, chain);
// then
assertNull(request.getQueryParams().get("testParam"));
verify(chain).doApply(request);
}
use of io.apiman.plugins.jsonp_policy.beans.JsonpConfigBean in project apiman-plugins by apiman.
the class JsonpPolicyTest method changeResponseWhenCallbackParamNameIsSavedInContext.
@Test
public void changeResponseWhenCallbackParamNameIsSavedInContext() throws Exception {
JsonpConfigBean config = new JsonpConfigBean();
// given
String functionName = "testFunction";
sContext.setAttribute(JsonpPolicy.CALLBACK_FUNCTION_NAME, functionName);
ApiResponse response = new ApiResponse();
String json = "{\"name\": \"test\"}";
IApimanBuffer chunk = new ByteBuffer(json.getBytes().length);
chunk.append(json);
IAsyncHandler<IApimanBuffer> bodyHandler = mock(IAsyncHandler.class);
// when
IReadWriteStream<ApiResponse> responseDataHandler = jsonpPolicy.getResponseDataHandler(response, sContext, config);
ApiResponse head = responseDataHandler.getHead();
responseDataHandler.bodyHandler(bodyHandler);
responseDataHandler.write(chunk);
responseDataHandler.end();
// then
assertSame(response, head);
verify(bodyHandler).handle(refEq(new ByteBuffer("testFunction(")));
verify(bodyHandler).handle(refEq(new ByteBuffer(json)));
verify(bodyHandler).handle(refEq(new ByteBuffer(")")));
}
Aggregations