// Path: spring-multi-tenancy-core/src/main/java/biz/deinum/multitenant/context/TenantContextHolder.java
// public abstract class TenantContextHolder {
// 
// 	public static final String MODE_THREADLOCAL = "MODE_THREADLOCAL";
// 	public static final String MODE_INHERITABLETHREADLOCAL = "MODE_INHERITABLETHREADLOCAL";
// 	public static final String MODE_GLOBAL = "MODE_GLOBAL";
// 	public static final String SYSTEM_PROPERTY = "multi_tenant.strategy";
// 
// 	private static String strategyName = System.getProperty(SYSTEM_PROPERTY, MODE_THREADLOCAL);
// 
// 	private static TenantContextHolderStrategy strategy;
// 
// 	static {
// 		initialize();
// 	}
// 
// 	private static void initialize() {
// 		if ((strategyName == null) || "".equals(strategyName)) {
// 			// Set default
// 			strategyName = MODE_THREADLOCAL;
// 		}
// 
// 		if (strategyName.equals(MODE_THREADLOCAL)) {
// 			strategy = new ThreadLocalTenantContextHolderStrategy();
// 		}
// 		else if (strategyName.equals(MODE_INHERITABLETHREADLOCAL)) {
// 			strategy = new InheritableThreadLocalTenantContextHolderStrategy();
// 		}
// 		else if (strategyName.equals(MODE_GLOBAL)) {
// 			strategy = new GlobalTenantContextHolderStrategy();
// 		}
// 		else {
// 			// Try to load a custom strategy
// 			try {
// 				Class<?> clazz = Class.forName(strategyName);
// 				Constructor<?> customStrategy = clazz.getConstructor();
// 				strategy = (TenantContextHolderStrategy) customStrategy.newInstance();
// 			}
// 			catch (Exception ex) {
// 				ReflectionUtils.handleReflectionException(ex);
// 			}
// 		}
// 	}
// 
// 	public static TenantContext getContext() {
// 		TenantContext context = strategy.getContext();
// 		return context;
// 	}
// 
// 	public static void setContext(final TenantContext context) {
// 		strategy.setContext(context);
// 	}
// 
// 	public static void clearContext() {
// 		strategy.clearContext();
// 	}
// 
// 	public static TenantContext createEmptyContext() {
// 		return strategy.createEmptyContext();
// 	}
// 
// 	/**
// 	 * Changes the preferred strategy. Do <em>NOT</em> call this method more than once for
// 	 * a given JVM, as it will re-initialize the strategy and adversely affect any
// 	 * existing threads using the old strategy.
// 	 *
// 	 * @param strategyName the fully qualified class name of the strategy that should be
// 	 * used.
// 	 */
// 	public static void setStrategyName(String strategyName) {
// 		TenantContextHolder.strategyName = strategyName;
// 		initialize();
// 	}
// 
// 	@Override
// 	public String toString() {
// 		return String.format("TenantContextHolder [strategy=%s]", strategyName);
// 	}
// }
// 
// Path: spring-multi-tenancy-core/src/test/java/biz/deinum/multitenant/context/TenantContextTestUtil.java
// public abstract class TenantContextTestUtil {
// 
// 	public static void setCurrentTenant(String tenant) {
// 
// 		TenantContext mockContext = new MockTenantContext();
// 		mockContext.setTenant(tenant);
// 
// 		TenantContextHolder.setContext(mockContext);
// 
// 	}
// 
// }
// 
// Path: spring-multi-tenancy-core/src/test/java/biz/deinum/multitenant/ws/MockWebServiceConnection.java
// public abstract class MockWebServiceConnection implements WebServiceConnection,
// 		HeadersAwareReceiverWebServiceConnection,
// 		HeadersAwareSenderWebServiceConnection {
// }


import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.*;
import java.util.Arrays;
import java.util.Collections;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.ws.transport.context.DefaultTransportContext;
import org.springframework.ws.transport.context.TransportContextHolder;
import biz.deinum.multitenant.context.TenantContextHolder;
import biz.deinum.multitenant.context.TenantContextTestUtil;
import biz.deinum.multitenant.ws.MockWebServiceConnection;
import static org.hamcrest.Matchers.is;
	}

	@Test
	public void checkDefaultSettings() throws Exception {

		assertThat(this.interceptor.getHeaderName(), is(DEFAULT_HEADER));
		assertThat(this.interceptor.isThrowExceptionOnMissingTenant(), is(true));
	}

	@Test
	public void whenChangingHeaderNameItShouldBeSet() {

		this.interceptor.setHeaderName(HEADER_NAME);
		assertThat(this.interceptor.getHeaderName(), is(HEADER_NAME));
	}

	@Test(expected = IllegalStateException.class)
	public void whenNoTenantFoundIllegalStateExceptionShouldBeThrown() throws Exception {

		this.interceptor.setThrowExceptionOnMissingTenant(true);
		when(this.connection.getRequestHeaders(DEFAULT_HEADER)).thenReturn(Collections.<String>emptyIterator());
		this.interceptor.handleRequest(null, null);
	}

	@Test
	public void whenNoTenantFoundAndThrowExceptionDisabledThenReturnNull() throws Exception {

		this.interceptor.setThrowExceptionOnMissingTenant(false);
		when(this.connection.getRequestHeaders(DEFAULT_HEADER)).thenReturn(Collections.<String>emptyIterator());
		this.interceptor.handleRequest(null, null);
// Path: spring-multi-tenancy-core/src/main/java/biz/deinum/multitenant/context/TenantContextHolder.java
// public abstract class TenantContextHolder {
// 
// 	public static final String MODE_THREADLOCAL = "MODE_THREADLOCAL";
// 	public static final String MODE_INHERITABLETHREADLOCAL = "MODE_INHERITABLETHREADLOCAL";
// 	public static final String MODE_GLOBAL = "MODE_GLOBAL";
// 	public static final String SYSTEM_PROPERTY = "multi_tenant.strategy";
// 
// 	private static String strategyName = System.getProperty(SYSTEM_PROPERTY, MODE_THREADLOCAL);
// 
// 	private static TenantContextHolderStrategy strategy;
// 
// 	static {
// 		initialize();
// 	}
// 
// 	private static void initialize() {
// 		if ((strategyName == null) || "".equals(strategyName)) {
// 			// Set default
// 			strategyName = MODE_THREADLOCAL;
// 		}
// 
// 		if (strategyName.equals(MODE_THREADLOCAL)) {
// 			strategy = new ThreadLocalTenantContextHolderStrategy();
// 		}
// 		else if (strategyName.equals(MODE_INHERITABLETHREADLOCAL)) {
// 			strategy = new InheritableThreadLocalTenantContextHolderStrategy();
// 		}
// 		else if (strategyName.equals(MODE_GLOBAL)) {
// 			strategy = new GlobalTenantContextHolderStrategy();
// 		}
// 		else {
// 			// Try to load a custom strategy
// 			try {
// 				Class<?> clazz = Class.forName(strategyName);
// 				Constructor<?> customStrategy = clazz.getConstructor();
// 				strategy = (TenantContextHolderStrategy) customStrategy.newInstance();
// 			}
// 			catch (Exception ex) {
// 				ReflectionUtils.handleReflectionException(ex);
// 			}
// 		}
// 	}
// 
// 	public static TenantContext getContext() {
// 		TenantContext context = strategy.getContext();
// 		return context;
// 	}
// 
// 	public static void setContext(final TenantContext context) {
// 		strategy.setContext(context);
// 	}
// 
// 	public static void clearContext() {
// 		strategy.clearContext();
// 	}
// 
// 	public static TenantContext createEmptyContext() {
// 		return strategy.createEmptyContext();
// 	}
// 
// 	/**
// 	 * Changes the preferred strategy. Do <em>NOT</em> call this method more than once for
// 	 * a given JVM, as it will re-initialize the strategy and adversely affect any
// 	 * existing threads using the old strategy.
// 	 *
// 	 * @param strategyName the fully qualified class name of the strategy that should be
// 	 * used.
// 	 */
// 	public static void setStrategyName(String strategyName) {
// 		TenantContextHolder.strategyName = strategyName;
// 		initialize();
// 	}
// 
// 	@Override
// 	public String toString() {
// 		return String.format("TenantContextHolder [strategy=%s]", strategyName);
// 	}
// }
// 
// Path: spring-multi-tenancy-core/src/test/java/biz/deinum/multitenant/context/TenantContextTestUtil.java
// public abstract class TenantContextTestUtil {
// 
// 	public static void setCurrentTenant(String tenant) {
// 
// 		TenantContext mockContext = new MockTenantContext();
// 		mockContext.setTenant(tenant);
// 
// 		TenantContextHolder.setContext(mockContext);
// 
// 	}
// 
// }
// 
// Path: spring-multi-tenancy-core/src/test/java/biz/deinum/multitenant/ws/MockWebServiceConnection.java
// public abstract class MockWebServiceConnection implements WebServiceConnection,
// 		HeadersAwareReceiverWebServiceConnection,
// 		HeadersAwareSenderWebServiceConnection {
// }


// Path: spring-multi-tenancy-core/src/test/java/biz/deinum/multitenant/ws/server/TenantContextEndpointInterceptorTests.java
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.*;
import java.util.Arrays;
import java.util.Collections;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.ws.transport.context.DefaultTransportContext;
import org.springframework.ws.transport.context.TransportContextHolder;
import biz.deinum.multitenant.context.TenantContextHolder;
import biz.deinum.multitenant.context.TenantContextTestUtil;
import biz.deinum.multitenant.ws.MockWebServiceConnection;
import static org.hamcrest.Matchers.is;

	}

	@Test
	public void checkDefaultSettings() throws Exception {

		assertThat(this.interceptor.getHeaderName(), is(DEFAULT_HEADER));
		assertThat(this.interceptor.isThrowExceptionOnMissingTenant(), is(true));
	}

	@Test
	public void whenChangingHeaderNameItShouldBeSet() {

		this.interceptor.setHeaderName(HEADER_NAME);
		assertThat(this.interceptor.getHeaderName(), is(HEADER_NAME));
	}

	@Test(expected = IllegalStateException.class)
	public void whenNoTenantFoundIllegalStateExceptionShouldBeThrown() throws Exception {

		this.interceptor.setThrowExceptionOnMissingTenant(true);
		when(this.connection.getRequestHeaders(DEFAULT_HEADER)).thenReturn(Collections.<String>emptyIterator());
		this.interceptor.handleRequest(null, null);
	}

	@Test
	public void whenNoTenantFoundAndThrowExceptionDisabledThenReturnNull() throws Exception {

		this.interceptor.setThrowExceptionOnMissingTenant(false);
		when(this.connection.getRequestHeaders(DEFAULT_HEADER)).thenReturn(Collections.<String>emptyIterator());
		this.interceptor.handleRequest(null, null);
		assertThat(TenantContextHolder.getContext().getTenant(), is(nullValue()));