// Path: gwt-sl/src/main/java/org/gwtwidgets/server/spring/ServletUtils.java
// public class ServletUtils {
// 	
// 	private static ThreadLocal<HttpServletResponse> servletResponse = new ThreadLocal<HttpServletResponse>();
// 
// 	/**
// 	 * Adjusts HTTP headers so that browsers won't cache response.
// 	 * @param response
// 	 * For more background see <a href="http://www.onjava.com/pub/a/onjava/excerpt/jebp_3/index2.html">this</a>.
// 	 */
// 	public static void disableResponseCaching(HttpServletResponse response) {
// 		response.setHeader("Expires", "Sat, 1 January 2000 12:00:00 GMT");
// 		response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate");
// 		response.addHeader("Cache-Control", "post-check=0, pre-check=0");
// 		response.setHeader("Pragma", "no-cache");
// 	}
// 
// 	/**
// 	 * Return the request which invokes the service. Valid only if used in the
// 	 * dispatching thread.
// 	 * @return the servlet request
// 	 */
// 	public static HttpServletRequest getRequest() {
// 		return
//             ((ServletRequestAttributes)
//              RequestContextHolder.getRequestAttributes()).getRequest(); 	
// 		}
// 
// 	/**
// 	 * Return the response which accompanies the request. Valid only if used in
// 	 * the dispatching thread.
// 	 * 
// 	 * @return the servlet response
// 	 */
// 	public static HttpServletResponse getResponse() {
// 		return servletResponse.get();
// 	}
// 
// 	/**
// 	 * Assign the current servlet request to a thread local variable. Valid only
// 	 * if used inside the invoking thread scope.
// 	 * @deprecated Does not perform any operation
// 	 * @param request Set the request
// 	 */
// 	public static void setRequest(HttpServletRequest request) {
// 		throw new RuntimeException("setRequest has been deprecated");
// 	}
// 
// 	/**
// 	 * Assign the current servlet response to a thread local variable. Valid
// 	 * only if used inside the invoking thread scope.
// 	 * 
// 	 * @param response Set the response
// 	 */
// 	public static void setResponse(HttpServletResponse response) {
// 		servletResponse.set(response);
// 	}
// 
// }


import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import org.gwtwidgets.server.spring.ServletUtils;
import org.junit.Before;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

/*
 * 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 org.gwtwidgets.server.spring.test;



/**
 * Abstract basis test for unit tests
 * @author George Georgovassilis, g.georgovassilis[at]gmail.com
 *
 */
public abstract class BaseTest{

	protected String readResource(String resource) throws Exception {
		URL url = getClass().getClassLoader().getResource(resource);
		if (url == null)
			url = ClassLoader.getSystemResource(resource);
		if (url == null)
			url = ClassLoader.getSystemClassLoader().getResource(resource);
		URLConnection conn = url.openConnection();
		byte[] b = new byte[conn.getContentLength()];
		InputStream in = conn.getInputStream();
		in.read(b);
		in.close();
		return new String(b, "UTF-8");
	}

	@Before
	public void setUp() throws Exception {
		MockHttpServletRequest request = new MockHttpServletRequest();
		MockHttpServletResponse response = new MockHttpServletResponse();
		// need to override our own request
		RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request));

// Path: gwt-sl/src/main/java/org/gwtwidgets/server/spring/ServletUtils.java
// public class ServletUtils {
// 	
// 	private static ThreadLocal<HttpServletResponse> servletResponse = new ThreadLocal<HttpServletResponse>();
// 
// 	/**
// 	 * Adjusts HTTP headers so that browsers won't cache response.
// 	 * @param response
// 	 * For more background see <a href="http://www.onjava.com/pub/a/onjava/excerpt/jebp_3/index2.html">this</a>.
// 	 */
// 	public static void disableResponseCaching(HttpServletResponse response) {
// 		response.setHeader("Expires", "Sat, 1 January 2000 12:00:00 GMT");
// 		response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate");
// 		response.addHeader("Cache-Control", "post-check=0, pre-check=0");
// 		response.setHeader("Pragma", "no-cache");
// 	}
// 
// 	/**
// 	 * Return the request which invokes the service. Valid only if used in the
// 	 * dispatching thread.
// 	 * @return the servlet request
// 	 */
// 	public static HttpServletRequest getRequest() {
// 		return
//             ((ServletRequestAttributes)
//              RequestContextHolder.getRequestAttributes()).getRequest(); 	
// 		}
// 
// 	/**
// 	 * Return the response which accompanies the request. Valid only if used in
// 	 * the dispatching thread.
// 	 * 
// 	 * @return the servlet response
// 	 */
// 	public static HttpServletResponse getResponse() {
// 		return servletResponse.get();
// 	}
// 
// 	/**
// 	 * Assign the current servlet request to a thread local variable. Valid only
// 	 * if used inside the invoking thread scope.
// 	 * @deprecated Does not perform any operation
// 	 * @param request Set the request
// 	 */
// 	public static void setRequest(HttpServletRequest request) {
// 		throw new RuntimeException("setRequest has been deprecated");
// 	}
// 
// 	/**
// 	 * Assign the current servlet response to a thread local variable. Valid
// 	 * only if used inside the invoking thread scope.
// 	 * 
// 	 * @param response Set the response
// 	 */
// 	public static void setResponse(HttpServletResponse response) {
// 		servletResponse.set(response);
// 	}
// 
// }


// Path: test-webapp/src/test/java/org/gwtwidgets/server/spring/test/BaseTest.java
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import org.gwtwidgets.server.spring.ServletUtils;
import org.junit.Before;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

/*
 * 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 org.gwtwidgets.server.spring.test;



/**
 * Abstract basis test for unit tests
 * @author George Georgovassilis, g.georgovassilis[at]gmail.com
 *
 */
public abstract class BaseTest{

	protected String readResource(String resource) throws Exception {
		URL url = getClass().getClassLoader().getResource(resource);
		if (url == null)
			url = ClassLoader.getSystemResource(resource);
		if (url == null)
			url = ClassLoader.getSystemClassLoader().getResource(resource);
		URLConnection conn = url.openConnection();
		byte[] b = new byte[conn.getContentLength()];
		InputStream in = conn.getInputStream();
		in.read(b);
		in.close();
		return new String(b, "UTF-8");
	}

	@Before
	public void setUp() throws Exception {
		MockHttpServletRequest request = new MockHttpServletRequest();
		MockHttpServletResponse response = new MockHttpServletResponse();
		// need to override our own request
		RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request));

		ServletUtils.setResponse(response);
