// 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);
// 
// 	}
// 
// }


import java.util.ArrayList;
import java.util.List;
import org.junit.Test;
import org.springframework.http.HttpEntity;
import org.springframework.http.client.ClientHttpRequestInterceptor;
import org.springframework.test.web.client.MockRestServiceServer;
import org.springframework.test.web.client.response.MockRestResponseCreators;
import org.springframework.web.client.RestTemplate;
import biz.deinum.multitenant.context.TenantContextTestUtil;
import static org.springframework.http.HttpMethod.GET;
import static org.springframework.test.web.client.match.MockRestRequestMatchers.*;
/*
 * Copyright 2007-2016 the original author or authors.
 *
 * 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 biz.deinum.multitenant.http.client;





/**
 * @author marten
 */
public class TenantContextHeaderInterceptorTest {

	private TenantContextHeaderInterceptor interceptor = new TenantContextHeaderInterceptor();

	@Test
	public void shouldSetHeaderOnRequest() {
		this.interceptor.setHeaderName("context");

		List<ClientHttpRequestInterceptor> interceptors = new ArrayList<>();
		interceptors.add(this.interceptor);

		RestTemplate template = new RestTemplate();
		template.setInterceptors(interceptors);

		MockRestServiceServer mockServer = MockRestServiceServer.createServer(template);

		mockServer.expect(requestTo("/test"))
				.andExpect(method(GET))
				.andExpect(header("context", "test-context"))
				.andRespond(MockRestResponseCreators.withSuccess());

// 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/http/client/TenantContextHeaderInterceptorTest.java
import java.util.ArrayList;
import java.util.List;
import org.junit.Test;
import org.springframework.http.HttpEntity;
import org.springframework.http.client.ClientHttpRequestInterceptor;
import org.springframework.test.web.client.MockRestServiceServer;
import org.springframework.test.web.client.response.MockRestResponseCreators;
import org.springframework.web.client.RestTemplate;
import biz.deinum.multitenant.context.TenantContextTestUtil;
import static org.springframework.http.HttpMethod.GET;
import static org.springframework.test.web.client.match.MockRestRequestMatchers.*;

/*
 * Copyright 2007-2016 the original author or authors.
 *
 * 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 biz.deinum.multitenant.http.client;





/**
 * @author marten
 */
public class TenantContextHeaderInterceptorTest {

	private TenantContextHeaderInterceptor interceptor = new TenantContextHeaderInterceptor();

	@Test
	public void shouldSetHeaderOnRequest() {
		this.interceptor.setHeaderName("context");

		List<ClientHttpRequestInterceptor> interceptors = new ArrayList<>();
		interceptors.add(this.interceptor);

		RestTemplate template = new RestTemplate();
		template.setInterceptors(interceptors);

		MockRestServiceServer mockServer = MockRestServiceServer.createServer(template);

		mockServer.expect(requestTo("/test"))
				.andExpect(method(GET))
				.andExpect(header("context", "test-context"))
				.andRespond(MockRestResponseCreators.withSuccess());

		TenantContextTestUtil.setCurrentTenant("test-context");