// Path: siden-core/src/main/java/ninja/siden/util/Using.java
// public interface Using {
// 
// 	static <IO extends AutoCloseable, R> R transform(
// 			ExceptionalSupplier<IO, Exception> supplier,
// 			ExceptionalFunction<IO, R, Exception> transformer) {
// 		try (IO t = supplier.get()) {
// 			return transformer.apply(t);
// 		} catch (RuntimeException e) {
// 			throw e;
// 		} catch (Exception e) {
// 			throw new RuntimeException(e);
// 		}
// 	}
// 
// 	static <IO extends AutoCloseable> void consume(
// 			ExceptionalSupplier<IO, Exception> supplier,
// 			ExceptionalConsumer<IO, Exception> consumer) {
// 		try (IO t = supplier.get()) {
// 			consumer.accept(t);
// 		} catch (RuntimeException e) {
// 			throw e;
// 		} catch (Exception e) {
// 			throw new RuntimeException(e);
// 		}
// 	}
// }


import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.config.SocketConfig;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.DefaultHttpRequestRetryHandler;
import org.apache.http.impl.client.HttpClientBuilder;
import io.undertow.server.HttpHandler;
import io.undertow.server.HttpServerExchange;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;
import java.util.logging.ConsoleHandler;
import java.util.logging.Level;
import java.util.logging.Logger;
import mockit.Mock;
import mockit.MockUp;
import ninja.siden.util.Using;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
/*
 * Copyright 2014 SATO taichi
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package ninja.siden.internal;





/**
 * @author taichi
 */
public interface Testing {

	static CloseableHttpClient client() {
		HttpClientBuilder builder = HttpClientBuilder.create();
		builder.setDefaultSocketConfig(SocketConfig.custom().setSoTimeout(2000)
				.build());
		builder.setRetryHandler(new DefaultHttpRequestRetryHandler(0, false));
		return builder.build();
	}

	@FunctionalInterface
	interface ResponseConsumer {
		void accept(HttpResponse response) throws Exception;
	}

	static void request(HttpUriRequest request, ResponseConsumer fn)
			throws Exception {
// Path: siden-core/src/main/java/ninja/siden/util/Using.java
// public interface Using {
// 
// 	static <IO extends AutoCloseable, R> R transform(
// 			ExceptionalSupplier<IO, Exception> supplier,
// 			ExceptionalFunction<IO, R, Exception> transformer) {
// 		try (IO t = supplier.get()) {
// 			return transformer.apply(t);
// 		} catch (RuntimeException e) {
// 			throw e;
// 		} catch (Exception e) {
// 			throw new RuntimeException(e);
// 		}
// 	}
// 
// 	static <IO extends AutoCloseable> void consume(
// 			ExceptionalSupplier<IO, Exception> supplier,
// 			ExceptionalConsumer<IO, Exception> consumer) {
// 		try (IO t = supplier.get()) {
// 			consumer.accept(t);
// 		} catch (RuntimeException e) {
// 			throw e;
// 		} catch (Exception e) {
// 			throw new RuntimeException(e);
// 		}
// 	}
// }


// Path: siden-core/src/test/java/ninja/siden/internal/Testing.java
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.config.SocketConfig;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.DefaultHttpRequestRetryHandler;
import org.apache.http.impl.client.HttpClientBuilder;
import io.undertow.server.HttpHandler;
import io.undertow.server.HttpServerExchange;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;
import java.util.logging.ConsoleHandler;
import java.util.logging.Level;
import java.util.logging.Logger;
import mockit.Mock;
import mockit.MockUp;
import ninja.siden.util.Using;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;

/*
 * Copyright 2014 SATO taichi
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package ninja.siden.internal;





/**
 * @author taichi
 */
public interface Testing {

	static CloseableHttpClient client() {
		HttpClientBuilder builder = HttpClientBuilder.create();
		builder.setDefaultSocketConfig(SocketConfig.custom().setSoTimeout(2000)
				.build());
		builder.setRetryHandler(new DefaultHttpRequestRetryHandler(0, false));
		return builder.build();
	}

	@FunctionalInterface
	interface ResponseConsumer {
		void accept(HttpResponse response) throws Exception;
	}

	static void request(HttpUriRequest request, ResponseConsumer fn)
			throws Exception {
		Using.consume(Testing::client, c -> fn.accept(c.execute(request)));