From: Will S. <wsa...@us...> - 2005-05-07 23:34:30
|
Update of /cvsroot/mockobjects/mockobjects-java/src/extensions/com/mockobjects/atg/servlet In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29548/src/extensions/com/mockobjects/atg/servlet Added Files: MockDynamoHttpServletResponse.java MockDynamoHttpServletRequest.java MockDynamoServlet.java Log Message: Add revised ATG mockobjects information. --- NEW FILE: MockDynamoHttpServletResponse.java --- /* ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2001-2004 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The name "MockObjects" must not be * used to endorse or promote products derived from this software * without prior written permission. For written permission, please * contact ap...@ap.... * * 5. Products derived from this software may not be called * "MockObjects", nor may "MockObjects" appear in their name, * without prior written permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package com.mockobjects.atg.servlet; import atg.servlet.DynamoHttpServletRequest; import atg.servlet.DynamoHttpServletResponse; import com.mockobjects.ExpectationList; import com.mockobjects.Verifiable; import java.io.IOException; import javax.servlet.http.HttpServletResponse; /** * The mock dynamo response object. Set up the expected local redirect and * verify to make sure the object was used as intended. * * @author Unknown * @version $Revision: 1.1 $ */ public class MockDynamoHttpServletResponse extends DynamoHttpServletResponse implements Verifiable { private ExpectationList myLocalRedirect = new ExpectationList("Local redirect"); private boolean myShouldThrowExceptionOnRedirect = false; public MockDynamoHttpServletResponse() { } public MockDynamoHttpServletResponse(HttpServletResponse arg1) { super(arg1); } public void sendLocalRedirect(String url, DynamoHttpServletRequest request) throws IOException { myLocalRedirect.addActual(url); myLocalRedirect.addActual(request); if (myShouldThrowExceptionOnRedirect) { throw new IOException("Mock exception"); } } public void setExpectedLocalRedirect(String url, DynamoHttpServletRequest request) { myLocalRedirect.addExpected(url); myLocalRedirect.addExpected(request); } public void setupThrowExceptionOnRedirect() { myShouldThrowExceptionOnRedirect = true; } public String toString() { return "MockDynamoHttpServletResponse"; } public void verify() { myLocalRedirect.verify(); } } --- NEW FILE: MockDynamoHttpServletRequest.java --- /* ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2001-2004 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The name "MockObjects" must not be * used to endorse or promote products derived from this software * without prior written permission. For written permission, please * contact ap...@ap.... * * 5. Products derived from this software may not be called * "MockObjects", nor may "MockObjects" appear in their name, * without prior written permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package com.mockobjects.atg.servlet; import atg.nucleus.naming.ParameterName; import atg.servlet.DynamoHttpServletRequest; import atg.servlet.DynamoHttpServletResponse; import atg.servlet.DynamoServlet; import com.mockobjects.ExpectationSet; import com.mockobjects.MapEntry; import com.mockobjects.util.Verifier; import java.io.IOException; import java.util.HashMap; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; /** * The mock object for the dynamo HTTP request. Set this up with the values * you expect to be called, and then pass it into the class which operates on * the request. * * @author Unknown * @version $Revision: 1.1 $ */ public class MockDynamoHttpServletRequest extends DynamoHttpServletRequest { private ExpectationSet myExpectedOutputParameters = new ExpectationSet("Output Parameters"); private ExpectationSet myServicedLocalParameter = new ExpectationSet("Serviced Local Params"); private HashMap myCookieParameters = new HashMap(); private HashMap myHeaders = new HashMap(); private HashMap myInputParameters = new HashMap(); private HashMap myNamedComponents = new HashMap(); private HashMap myOutputParameters = new HashMap(); public MockDynamoHttpServletRequest() { } public void setParameter(String key, Object value) { myExpectedOutputParameters.addActual(new MapEntry(key, value)); myOutputParameters.put(key, value); } public void verify() { Verifier.verifyObject(this); } public Object getObjectParameter(ParameterName name) { return getObjectParameter(name.getName()); } public Object getObjectParameter(String name) { return myInputParameters.get(name); } public String getParameter(String param1) { return (String) myInputParameters.get(param1); } public boolean serviceLocalParameter(ParameterName name, ServletRequest pRequest, ServletResponse pResponse) throws ServletException, IOException { myServicedLocalParameter.addActual(name.getName()); DynamoServlet servlet = (DynamoServlet) this.getLocalParameter(name); if (servlet != null) { servlet.service((DynamoHttpServletRequest) pRequest, (DynamoHttpServletResponse) pResponse); } return true; } public boolean serviceLocalParameter(String name, ServletRequest request, ServletResponse response) throws ServletException, IOException { myServicedLocalParameter.addActual(name); return true; } public Object getLocalParameter(String parameterName) { return myInputParameters.get(parameterName); } public void setupExpectedOutputParameter(String name, Object value) { myExpectedOutputParameters.addExpected(new MapEntry(name, value)); } public void setupExpectedServicedLocalParameter(String name) { myServicedLocalParameter.addExpected(name); } public void setupExpectedServicedLocalParameter(ParameterName pName) { setupExpectedServicedLocalParameter(pName.getName()); } public void setupInputParameter(String param1, Object param2) { myInputParameters.put(param1, param2); } public void setupInputParameter(ParameterName param1, Object param2) { if (param1 == null) { throw new NullPointerException("null param1"); } setupInputParameter(param1.getName(), param2); } public String getCookieParameter(String parameter) { return (String) myCookieParameters.get(parameter); } public void setupCookieParameter(String key, String parameter) { myCookieParameters.put(key, parameter); } public void setupHeaders(String key, String header) { myHeaders.put(key, header); } public void setupNamedParameter(String name, Object parameter) { myNamedComponents.put(name, parameter); } public String encodeURL(String str) { return str + ";sessionId=123"; } public String getHeader(String param1) { return (String) myHeaders.get(param1); } public Object resolveName(String componentName, boolean param2) { return myNamedComponents.get(componentName); } public String toString() { return "MockDynamoHttpServletRequest"; } } --- NEW FILE: MockDynamoServlet.java --- /* ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2001-2004 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The name "MockObjects" must not be * used to endorse or promote products derived from this software * without prior written permission. For written permission, please * contact ap...@ap.... * * 5. Products derived from this software may not be called * "MockObjects", nor may "MockObjects" appear in their name, * without prior written permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package com.mockobjects.atg.servlet; import atg.servlet.DynamoHttpServletRequest; import atg.servlet.DynamoHttpServletResponse; import atg.servlet.DynamoServlet; import com.mockobjects.ExpectationCounter; import com.mockobjects.Verifiable; import com.mockobjects.util.Verifier; /** * Taken from Piran's patch of mockobjects.com, and never tested. * * @author piran at users.sourceforge.net * @version $Revision: 1.1 $ * * @since Feb 20, 2004 */ public class MockDynamoServlet extends DynamoServlet implements Verifiable { private ExpectationCounter mServiceCalls = new ExpectationCounter("MockDynamoServlet.service"); public void setExpectedServiceCalls(int callCount) { mServiceCalls.setExpected(callCount); } public void service(DynamoHttpServletRequest request, DynamoHttpServletResponse response) throws javax.servlet.ServletException, java.io.IOException { mServiceCalls.inc(); } public void verify() { Verifier.verifyObject(this); } } |