001: /*
002: * Copyright 2005-2006 the original author or authors.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
005: * in compliance with the License. You may obtain a copy of the License at
006: *
007: * http://www.apache.org/licenses/LICENSE-2.0
008: *
009: * Unless required by applicable law or agreed to in writing, software distributed under the License
010: * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
011: * or implied. See the License for the specific language governing permissions and limitations under
012: * the License.
013: */
014:
015: package org.strecks.preprocess;
016:
017: import static org.easymock.EasyMock.expect;
018: import static org.easymock.classextension.EasyMock.createStrictMock;
019: import static org.easymock.classextension.EasyMock.replay;
020: import static org.easymock.classextension.EasyMock.verify;
021:
022: import java.io.IOException;
023:
024: import javax.servlet.ServletException;
025: import javax.servlet.http.HttpServletRequest;
026: import javax.servlet.http.HttpSession;
027:
028: import org.apache.struts.Globals;
029: import org.apache.struts.action.ActionErrors;
030: import org.testng.annotations.Test;
031:
032: /**
033: * @author Phil Zoio
034: */
035: public class TestSessionErrorFormHandler {
036:
037: @Test
038: public void testProcessCachedMessagesNoSession()
039: throws ServletException, IOException {
040:
041: HttpServletRequest request = createStrictMock(HttpServletRequest.class);
042:
043: expect(request.getSession(false)).andReturn(null);
044:
045: replay(request);
046:
047: SessionErrorPreprocessor delegate = new SessionErrorPreprocessor();
048: delegate.preprocessRequest(request);
049:
050: verify(request);
051:
052: }
053:
054: @Test
055: public void testProcessCachedMessagesNoErrors()
056: throws ServletException, IOException {
057:
058: HttpServletRequest request = createStrictMock(HttpServletRequest.class);
059: HttpSession session = createStrictMock(HttpSession.class);
060:
061: expect(request.getSession(false)).andReturn(session);
062: expect(session.getAttribute(Globals.ERROR_KEY)).andReturn(null);
063:
064: replay(request);
065: replay(session);
066:
067: SessionErrorPreprocessor delegate = new SessionErrorPreprocessor();
068: delegate.preprocessRequest(request);
069:
070: verify(request);
071: verify(session);
072:
073: }
074:
075: @Test
076: public void testProcessCachedMessagesWithErrors()
077: throws ServletException, IOException {
078:
079: HttpServletRequest request = createStrictMock(HttpServletRequest.class);
080: HttpSession session = createStrictMock(HttpSession.class);
081:
082: ActionErrors actionErrors = new ActionErrors();
083:
084: expect(request.getSession(false)).andReturn(session);
085: expect(session.getAttribute(Globals.ERROR_KEY)).andReturn(
086: actionErrors);
087: request.setAttribute(Globals.ERROR_KEY, actionErrors);
088:
089: replay(request);
090: replay(session);
091:
092: SessionErrorPreprocessor delegate = new SessionErrorPreprocessor();
093: delegate.preprocessRequest(request);
094:
095: verify(request);
096: verify(session);
097:
098: }
099:
100: }
|