/*
* Copyright 2005-2006 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 org.strecks.web;
import static org.easymock.EasyMock.expect;
import static org.easymock.classextension.EasyMock.createStrictMock;
import static org.easymock.classextension.EasyMock.replay;
import static org.easymock.classextension.EasyMock.verify;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.testng.annotations.Test;
/**
* @author Phil Zoio
*/
public class TestWebHelperImpl
{
@Test
public void test()
{
HttpServletRequest request = createStrictMock(HttpServletRequest.class);
HttpSession session = createStrictMock(HttpSession.class);
ServletContext context = createStrictMock(ServletContext.class);
WebHelperImpl wc = new WebHelperImpl(request, context);
// 1.
request.setAttribute("name1", "value1");
expect(request.getSession()).andReturn(session);
session.setAttribute("name2", "value2");
context.setAttribute("name3", "value3");
// 2.
request.removeAttribute("name1");
expect(request.getSession(false)).andReturn(session);
session.removeAttribute("name2");
context.removeAttribute("name3");
// 3.
expect(request.getSession(false)).andReturn(null);
replay(request);
replay(session);
replay(context);
// 1.
wc.setRequestAttribute("name1", "value1");
wc.setSessionAttribute("name2", "value2");
wc.setContextAttribute("name3", "value3");
// 2.
wc.removeRequestAttribute("name1");
wc.removeSessionAttribute("name2");
wc.removeContextAttribute("name3");
// 3.
// Now try remove from session when it is null - notice, no expected call to session
wc.removeSessionAttribute("name2");
verify(request);
verify(session);
verify(context);
}
}