<commit_before>package nl.nn.adapterframework.http.rest;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.mockito.Mockito;
import org.springframework.core.task.TaskExecutor;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import nl.nn.adapterframework.configuration.Configuration;
import nl.nn.adapterframework.configuration.ConfigurationException;
import nl.nn.adapterframework.core.Adapter;
import nl.nn.adapterframework.core.IPipe;
import nl.nn.adapterframework.core.PipeLine;
import nl.nn.adapterframework.core.PipeLineExit;
import nl.nn.adapterframework.parameters.Parameter;
import nl.nn.adapterframework.pipes.EchoPipe;
import nl.nn.adapterframework.pipes.Json2XmlValidator;
import nl.nn.adapterframework.receivers.GenericReceiver;
import nl.nn.adapterframework.util.MessageKeeper;
import nl.nn.adapterframework.util.RunStateEnum;

public class OpenApiTestBase extends Mockito {

	private static TaskExecutor taskExecutor;
	private Configuration configuration;
	private ThreadLocalServlet servlets = new ThreadLocalServlet();

	@BeforeClass
	public static void beforeClass() {
		ApiServiceDispatcher.getInstance().clear();
	}

	@Before
	public void setUp() throws ServletException {
		configuration = mock(Configuration.class);
	}

	@After
	public void tearDown() {
		servlets.remove();

		configuration = null;
	}

	@AfterClass
	public static void afterClass() {
		ApiServiceDispatcher.getInstance().clear();
	}

	private static class ThreadLocalServlet extends ThreadLocal<ApiListenerServlet> {
		@Override
		public ApiListenerServlet get() {
			ApiListenerServlet servlet = super.get();
			if(servlet == null) {
				servlet = new ApiListenerServlet();
				try {
					servlet.init();
				} catch (ServletException e) {
					throw new RuntimeException("error starting servlet");
				}
				set(servlet);
			}
			return servlet;
		}

		@Override
		public void remove() {
			ApiListenerServlet servlet = super.get();
			if(servlet != null) {
				servlet.destroy();
			}
			super.remove();
		}
	}

	/**
	 * TaskExecutor used to start and configure adapters
	 */
	private static TaskExecutor getTaskExecutor() {
		if(taskExecutor == null) {
			ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
			executor.setCorePoolSize(2);
			executor.setMaxPoolSize(10);
			executor.initialize();
			taskExecutor = executor;
		}
		return taskExecutor;
	}

	protected HttpServletRequest createRequest(String method, String uri) {
		MockHttpServletRequest request = new MockHttpServletRequest(method.toUpperCase(), uri);
		request.setPathInfo(uri);
		return request;
	}

	protected String callOpenApi(String uri) throws ServletException, IOException {
		return service(createRequest("get", uri + "/openapi.json"));
	}
<commit_msg>Change async threadpool to sync threadpool (#1238)<commit_after>package nl.nn.adapterframework.http.rest;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.mockito.Mockito;
import org.springframework.core.task.SyncTaskExecutor;
import org.springframework.core.task.TaskExecutor;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;

import nl.nn.adapterframework.configuration.Configuration;
import nl.nn.adapterframework.configuration.ConfigurationException;
import nl.nn.adapterframework.core.Adapter;
import nl.nn.adapterframework.core.IPipe;
import nl.nn.adapterframework.core.PipeLine;
import nl.nn.adapterframework.core.PipeLineExit;
import nl.nn.adapterframework.parameters.Parameter;
import nl.nn.adapterframework.pipes.EchoPipe;
import nl.nn.adapterframework.pipes.Json2XmlValidator;
import nl.nn.adapterframework.receivers.GenericReceiver;
import nl.nn.adapterframework.util.MessageKeeper;
import nl.nn.adapterframework.util.RunStateEnum;

public class OpenApiTestBase extends Mockito {

	private static TaskExecutor taskExecutor;
	private Configuration configuration;
	private ThreadLocalServlet servlets = new ThreadLocalServlet();

	@BeforeClass
	public static void beforeClass() {
		ApiServiceDispatcher.getInstance().clear();
	}

	@Before
	public void setUp() throws ServletException {
		configuration = mock(Configuration.class);
	}

	@After
	public void tearDown() {
		servlets.remove();

		configuration = null;
	}

	@AfterClass
	public static void afterClass() {
		ApiServiceDispatcher.getInstance().clear();
	}

	private static class ThreadLocalServlet extends ThreadLocal<ApiListenerServlet> {
		@Override
		public ApiListenerServlet get() {
			ApiListenerServlet servlet = super.get();
			if(servlet == null) {
				servlet = new ApiListenerServlet();
				try {
					servlet.init();
				} catch (ServletException e) {
					throw new RuntimeException("error starting servlet");
				}
				set(servlet);
			}
			return servlet;
		}

		@Override
		public void remove() {
			ApiListenerServlet servlet = super.get();
			if(servlet != null) {
				servlet.destroy();
			}
			super.remove();
		}
	}

	/**
	 * TaskExecutor used to start and configure adapters
	 */
	private static TaskExecutor getTaskExecutor() {
		if(taskExecutor == null) {
			//Make sure all threads are joining the calling thread
			SyncTaskExecutor executor = new SyncTaskExecutor();
			taskExecutor = executor;
		}
		return taskExecutor;
	}

	protected HttpServletRequest createRequest(String method, String uri) {
		MockHttpServletRequest request = new MockHttpServletRequest(method.toUpperCase(), uri);
		request.setPathInfo(uri);
		return request;
	}

	protected String callOpenApi(String uri) throws ServletException, IOException {
		return service(createRequest("get", uri + "/openapi.json"));
	}

{'fraction_non_alphanumeric': 0.09906708129720124, 'fraction_numerical': 0.0016289056715533836, 'mean_word_length': 5.242144177449168, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '7661825', 'n_tokens_mistral': 2049, 'n_tokens_neox': 1914, 'n_words': 424}