<commit_before>package io.apiman.plugins.jsonp_policy;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.mockito.Matchers.refEq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;

import io.apiman.gateway.engine.async.IAsyncHandler;
import io.apiman.gateway.engine.beans.ApiRequest;
import io.apiman.gateway.engine.beans.ApiResponse;
import io.apiman.gateway.engine.beans.util.QueryMap;
import io.apiman.gateway.engine.components.IBufferFactoryComponent;
import io.apiman.gateway.engine.io.ByteBuffer;
import io.apiman.gateway.engine.io.IApimanBuffer;
import io.apiman.gateway.engine.io.IReadWriteStream;
import io.apiman.gateway.engine.policy.IPolicyChain;
import io.apiman.gateway.engine.policy.IPolicyContext;
import io.apiman.gateway.engine.policy.PolicyContextImpl;
import io.apiman.plugins.jsonp_policy.beans.JsonpConfigBean;

import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.mockito.Spy;

@SuppressWarnings("nls")
public class JsonpPolicyTest {

    private JsonpPolicy jsonpPolicy;

    @Spy
    private IPolicyContext sContext = new PolicyContextImpl(null);

    @Before
    public void setUp() {
        MockitoAnnotations.initMocks(this);
        Mockito.doReturn(new TestBufferFactory()).when(sContext).getComponent(IBufferFactoryComponent.class);

        jsonpPolicy = new JsonpPolicy();
    }

    @Test
    public void testParseEmptyConfiguration() {
        // given
        String config = "{}";
        // when
        JsonpConfigBean jsonpConfig = jsonpPolicy.parseConfiguration(config);
        // then
        assertNull(jsonpConfig.getCallbackParamName());
    }

    @Test
    public void testParseRealConfiguration() {
        // given
        String parameterName = "jsonp";
        String config = "{\"callbackParamName\":\"" + parameterName + "\"}";
        // when
        JsonpConfigBean jsonpConfig = jsonpPolicy.parseConfiguration(config);
        // then
        assertEquals(parameterName, jsonpConfig.getCallbackParamName());
    }
<commit_msg>updated the jsonp policy test due to a dependency class change<commit_after>package io.apiman.plugins.jsonp_policy;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.mockito.Matchers.refEq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;

import io.apiman.gateway.engine.async.IAsyncHandler;
import io.apiman.gateway.engine.beans.ApiRequest;
import io.apiman.gateway.engine.beans.ApiResponse;
import io.apiman.gateway.engine.beans.util.QueryMap;
import io.apiman.gateway.engine.components.IBufferFactoryComponent;
import io.apiman.gateway.engine.io.ByteBuffer;
import io.apiman.gateway.engine.io.IApimanBuffer;
import io.apiman.gateway.engine.io.IReadWriteStream;
import io.apiman.gateway.engine.policy.IPolicyChain;
import io.apiman.gateway.engine.policy.IPolicyContext;
import io.apiman.gateway.engine.policy.PolicyContextImpl;
import io.apiman.plugins.jsonp_policy.beans.JsonpConfigBean;

import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.mockito.Spy;

@SuppressWarnings("nls")
public class JsonpPolicyTest {

    private JsonpPolicy jsonpPolicy;

    @Spy
    private IPolicyContext sContext = new PolicyContextImpl(null, null);

    @Before
    public void setUp() {
        MockitoAnnotations.initMocks(this);
        Mockito.doReturn(new TestBufferFactory()).when(sContext).getComponent(IBufferFactoryComponent.class);

        jsonpPolicy = new JsonpPolicy();
    }

    @Test
    public void testParseEmptyConfiguration() {
        // given
        String config = "{}";
        // when
        JsonpConfigBean jsonpConfig = jsonpPolicy.parseConfiguration(config);
        // then
        assertNull(jsonpConfig.getCallbackParamName());
    }

    @Test
    public void testParseRealConfiguration() {
        // given
        String parameterName = "jsonp";
        String config = "{\"callbackParamName\":\"" + parameterName + "\"}";
        // when
        JsonpConfigBean jsonpConfig = jsonpPolicy.parseConfiguration(config);
        // then
        assertEquals(parameterName, jsonpConfig.getCallbackParamName());
    }

{'fraction_non_alphanumeric': 0.10449108553373956, 'fraction_numerical': 0.0, 'mean_word_length': 4.013574660633484, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4826641', 'n_tokens_mistral': 1328, 'n_tokens_neox': 1317, 'n_words': 229}