protected HttpServletRequest getMockRequest()

in src/java/org/apache/fulcrum/testcontainer/BaseUnit4Test.java [219:288]


	protected HttpServletRequest getMockRequest() 
	{
		HttpServletRequest request = mock(HttpServletRequest.class);
		HttpSession session = mock(HttpSession.class);

		doAnswer(new Answer<Object>() 
		{
			@Override
			public Object answer(InvocationOnMock invocation) throws Throwable 
			{
				String key = (String) invocation.getArguments()[0];
				return attributes.get(key);
			}
		}).when(session).getAttribute(anyString());

		doAnswer(new Answer<Object>() 
		{
			@Override
			public Object answer(InvocationOnMock invocation) throws Throwable 
			{
				String key = (String) invocation.getArguments()[0];
				Object value = invocation.getArguments()[1];
				attributes.put(key, value);
				return null;
			}
		}).when(session).setAttribute(anyString(), any());

		when(session.getMaxInactiveInterval()).thenReturn(maxInactiveInterval);

		doAnswer(new Answer<Integer>() 
		{
			@Override
			public Integer answer(InvocationOnMock invocation) throws Throwable {
				return Integer.valueOf(maxInactiveInterval);
			}
		}).when(session).getMaxInactiveInterval();

		doAnswer(new Answer<Object>() 
		{
			@Override
			public Object answer(InvocationOnMock invocation) throws Throwable 
			{
				Integer value = (Integer) invocation.getArguments()[0];
				maxInactiveInterval = value.intValue();
				return null;
			}
		}).when(session).setMaxInactiveInterval(anyInt());

		when(session.isNew()).thenReturn(true);
		when(request.getSession()).thenReturn(session);

		when(request.getServerName()).thenReturn("bob");
		when(request.getProtocol()).thenReturn("http");
		when(request.getScheme()).thenReturn("scheme");
		when(request.getPathInfo()).thenReturn("damn");
		when(request.getServletPath()).thenReturn("damn2");
		when(request.getContextPath()).thenReturn("wow");
		when(request.getContentType()).thenReturn("text/html");

		when(request.getCharacterEncoding()).thenReturn("US-ASCII");
		when(request.getServerPort()).thenReturn(8080);
		when(request.getLocale()).thenReturn(Locale.US);

		when(request.getHeader("Content-type")).thenReturn("text/html");
		when(request.getHeader("Accept-Language")).thenReturn("en-US");

		Vector<String> v = new Vector<String>();
		when(request.getParameterNames()).thenReturn(v.elements());
		return request;
	}