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.context;
016:
017: import static org.easymock.classextension.EasyMock.createStrictMock;
018: import static org.easymock.classextension.EasyMock.replay;
019: import static org.easymock.classextension.EasyMock.verify;
020:
021: import javax.servlet.ServletContext;
022: import javax.servlet.http.HttpServletRequest;
023: import javax.servlet.http.HttpServletResponse;
024:
025: import org.apache.struts.action.ActionForm;
026: import org.apache.struts.action.ActionMapping;
027: import org.testng.annotations.BeforeMethod;
028: import org.testng.annotations.Test;
029:
030: /**
031: * @author Phil Zoio
032: */
033: public class TestActionContextImpl {
034:
035: private HttpServletRequest request;
036:
037: private HttpServletResponse response;
038:
039: private ServletContext serlvetContext;
040:
041: private ActionForm actionForm;
042:
043: private ActionMapping actionMapping;
044:
045: @BeforeMethod
046: public void setUp() {
047: request = createStrictMock(HttpServletRequest.class);
048: response = createStrictMock(HttpServletResponse.class);
049: serlvetContext = createStrictMock(ServletContext.class);
050: actionForm = createStrictMock(ActionForm.class);
051: actionMapping = createStrictMock(ActionMapping.class);
052: }
053:
054: @Test
055: public void testActionContextFactory() {
056:
057: replay(request);
058:
059: ActionContext actionContext = new ActionContextFactoryImpl()
060: .createActionContext(request, response, serlvetContext,
061: actionForm, actionMapping);
062: assert actionContext.getRequest() == request;
063: assert actionContext.getResponse() == response;
064: assert actionContext.getContext() == serlvetContext;
065: assert actionContext.getForm() == actionForm;
066: assert actionContext.getMapping() == actionMapping;
067:
068: verify(request);
069: }
070:
071: @Test
072: public void testActionContextFactoryWithWrapper() {
073: replay(request);
074:
075: ActionContext actionContext = new ActionContextFactoryImpl()
076: .createActionContext(request, response, serlvetContext,
077: actionForm, actionMapping);
078: assert actionContext.getRequest() == request;
079: assert actionContext.getResponse() == response;
080: assert actionContext.getContext() == serlvetContext;
081: assert actionContext.getForm() == actionForm;
082: assert actionContext.getMapping() == actionMapping;
083:
084: verify(request);
085: }
086:
087: @Test
088: public void testActionContextImpl1() {
089: ActionContextImpl actionContext = new ActionContextImpl(
090: request, response, serlvetContext, actionForm,
091: actionMapping);
092: assert actionContext.getRequest() == request;
093: assert actionContext.getResponse() == response;
094: assert actionContext.getContext() == serlvetContext;
095: assert actionContext.getForm() == actionForm;
096: assert actionContext.getMapping() == actionMapping;
097: }
098:
099: @Test
100: public void testActionContextImpl2() {
101: ActionContextImpl actionContext = new ActionContextImpl(
102: request, response, serlvetContext, null, actionMapping);
103: assert actionContext.getRequest() == request;
104: assert actionContext.getResponse() == response;
105: assert actionContext.getContext() == serlvetContext;
106: assert actionContext.getForm() == null;
107: assert actionContext.getMapping() == actionMapping;
108: }
109:
110: @Test(expectedExceptions=IllegalArgumentException.class)
111: public void testActionContextImpl3() {
112: new ActionContextImpl(null, response, serlvetContext, null,
113: actionMapping);
114: }
115:
116: @Test(expectedExceptions=IllegalArgumentException.class)
117: public void testActionContextImpl4() {
118: new ActionContextImpl(request, null, serlvetContext, null,
119: actionMapping);
120: }
121:
122: @Test(expectedExceptions=IllegalArgumentException.class)
123: public void testActionContextImpl5() {
124: new ActionContextImpl(request, response, null, null,
125: actionMapping);
126: }
127:
128: @Test(expectedExceptions=IllegalArgumentException.class)
129: public void testActionContextImpl6() {
130: new ActionContextImpl(request, response, serlvetContext, null,
131: null);
132: }
133:
134: }
|