You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by hl...@apache.org on 2004/01/19 22:27:40 UTC
cvs commit: jakarta-tapestry/junit/src/org/apache/tapestry/junit/engine MockService.java TestRequestCycleToString.java
hlship 2004/01/19 13:27:40
Added: junit/src/org/apache/tapestry/junit/engine MockService.java
TestRequestCycleToString.java
Log:
Add tests for RequestContext.toString().
Revision Changes Path
1.1 jakarta-tapestry/junit/src/org/apache/tapestry/junit/engine/MockService.java
Index: MockService.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000-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://apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation", "Tapestry"
* must not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* or "Tapestry", nor may "Apache" or "Tapestry" 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 TAPESTRY CONTRIBUTOR COMMUNITY
* 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 org.apache.tapestry.junit.engine;
import java.io.IOException;
import javax.servlet.ServletException;
import org.apache.tapestry.IComponent;
import org.apache.tapestry.IRequestCycle;
import org.apache.tapestry.engine.IEngineService;
import org.apache.tapestry.engine.IEngineServiceView;
import org.apache.tapestry.engine.ILink;
import org.apache.tapestry.request.ResponseOutputStream;
/**
* Mock implementation of {@link org.apache.tapestry.engine.IEngineService} used in some tests.
*
* @author Howard Lewis Ship
* @version $Id: MockService.java,v 1.1 2004/01/19 21:27:40 hlship Exp $
*/
public class MockService implements IEngineService
{
private String _name;
public MockService(String name)
{
_name = name;
}
public ILink getLink(IRequestCycle cycle, IComponent component, Object[] parameters)
{
return null;
}
public void service(
IEngineServiceView engine,
IRequestCycle cycle,
ResponseOutputStream output)
throws ServletException, IOException
{
}
public String getName()
{
return _name;
}
}
1.1 jakarta-tapestry/junit/src/org/apache/tapestry/junit/engine/TestRequestCycleToString.java
Index: TestRequestCycleToString.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000-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://apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation", "Tapestry"
* must not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* or "Tapestry", nor may "Apache" or "Tapestry" 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 TAPESTRY CONTRIBUTOR COMMUNITY
* 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 org.apache.tapestry.junit.engine;
import org.apache.tapestry.IRequestCycle;
import org.apache.tapestry.engine.IEngineService;
import org.apache.tapestry.engine.RequestCycle;
import org.apache.tapestry.junit.TapestryTestCase;
/**
* Tests {@link org.apache.tapestry.engine.RequestCycle#toString()}.
*
* @author Howard Lewis Ship
* @version $Id: TestRequestCycleToString.java,v 1.1 2004/01/19 21:27:40 hlship Exp $
*/
public class TestRequestCycleToString extends TapestryTestCase
{
public TestRequestCycleToString(String name)
{
super(name);
}
private String toString(Object object)
{
String raw = object.toString();
int bracketx = raw.indexOf("[");
return raw.substring(bracketx + 1, raw.length() - 1);
}
public void testAllNull()
{
IRequestCycle cycle = new RequestCycle(null, null, null, null);
assertEquals(
"rewinding=false,serviceParameters=<null>,attributes=<null>,targetActionId=0,targetComponent=<null>",
toString(cycle));
}
public void testWithServiceParameters()
{
Object[] sp = new Object[] { "alpha", "beta" };
RequestCycle cycle = new RequestCycle(null, null, null, null);
cycle.setServiceParameters(sp);
assertEquals(
"rewinding=false,serviceParameters={alpha,beta},attributes=<null>,targetActionId=0,targetComponent=<null>",
toString(cycle));
}
public void testWithService()
{
IEngineService service = new MockService("test");
IRequestCycle cycle = new RequestCycle(null, null, service, null);
assertEquals(
"rewinding=false,service=test,serviceParameters=<null>,attributes=<null>,targetActionId=0,targetComponent=<null>",
toString(cycle));
}
public void testWithAttributes()
{
IRequestCycle cycle = new RequestCycle(null, null, null, null);
cycle.setAttribute("foo.bar", "baz");
assertEquals(
"rewinding=false,serviceParameters=<null>,attributes={foo.bar=baz},targetActionId=0,targetComponent=<null>",
toString(cycle));
}
// TODO: An amazing amount of work to be able to test loaded pages ... may need
// to do so inside a mock unit test suite since so much machinery is involved.
}
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-dev-help@jakarta.apache.org
RE: cvs commit: jakarta-tapestry/junit/src/org/apache/tapestry/junit/engine MockService.java TestRequestCycleToString.java
Posted by "Howard M. Lewis Ship" <hl...@comcast.net>.
Sure ... as I'm playing around I can start removing those (the extra constructor).
--
Howard M. Lewis Ship
Independent J2EE / Open-Source Java Consultant
Creator, Tapestry: Java Web Components
http://jakarta.apache.org/tapestry/
http://javatapestry.blogspot.com
> -----Original Message-----
> From: Erik Hatcher [mailto:erik@ehatchersolutions.com]
> Sent: Monday, January 19, 2004 4:35 PM
> To: Tapestry development
> Subject: Re: cvs commit:
> jakarta-tapestry/junit/src/org/apache/tapestry/junit/engine
> MockService.java TestRequestCycleToString.java
>
>
>
> On Jan 19, 2004, at 4:27 PM, hlship@apache.org wrote:
> > 1.1
> > jakarta-tapestry/junit/src/org/apache/tapestry/junit/engine/
> > TestRequestCycleToString.java
> >
> > package org.apache.tapestry.junit.engine;
> >
> > import org.apache.tapestry.IRequestCycle;
> > import org.apache.tapestry.engine.IEngineService;
> > import org.apache.tapestry.engine.RequestCycle;
> > import org.apache.tapestry.junit.TapestryTestCase;
> >
> > /**
> > * Tests {@link
> org.apache.tapestry.engine.RequestCycle#toString()}.
> > *
> > * @author Howard Lewis Ship
> > * @version $Id: TestRequestCycleToString.java,v 1.1 2004/01/19
> > 21:27:40 hlship Exp $
> > */
> > public class TestRequestCycleToString extends TapestryTestCase
> > {
> >
> > public TestRequestCycleToString(String name)
> > {
> > super(name);
> > }
>
> I'm not looking at the code at the moment, so not sure if
> TapestryTestCase requires this String-arg constructor, but this is a
> JUnit pet peeve of mine. No worries, of course, but just wanted to
> rant about it and ask that we remove these ctors anytime we
> touch test
> cases :) (only pre JUnit 3.8 required these ctors)
>
> Erik
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-dev-help@jakarta.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-dev-help@jakarta.apache.org
Re: cvs commit: jakarta-tapestry/junit/src/org/apache/tapestry/junit/engine MockService.java TestRequestCycleToString.java
Posted by Erik Hatcher <er...@ehatchersolutions.com>.
On Jan 19, 2004, at 4:27 PM, hlship@apache.org wrote:
> 1.1
> jakarta-tapestry/junit/src/org/apache/tapestry/junit/engine/
> TestRequestCycleToString.java
>
> package org.apache.tapestry.junit.engine;
>
> import org.apache.tapestry.IRequestCycle;
> import org.apache.tapestry.engine.IEngineService;
> import org.apache.tapestry.engine.RequestCycle;
> import org.apache.tapestry.junit.TapestryTestCase;
>
> /**
> * Tests {@link org.apache.tapestry.engine.RequestCycle#toString()}.
> *
> * @author Howard Lewis Ship
> * @version $Id: TestRequestCycleToString.java,v 1.1 2004/01/19
> 21:27:40 hlship Exp $
> */
> public class TestRequestCycleToString extends TapestryTestCase
> {
>
> public TestRequestCycleToString(String name)
> {
> super(name);
> }
I'm not looking at the code at the moment, so not sure if
TapestryTestCase requires this String-arg constructor, but this is a
JUnit pet peeve of mine. No worries, of course, but just wanted to
rant about it and ask that we remove these ctors anytime we touch test
cases :) (only pre JUnit 3.8 required these ctors)
Erik
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-dev-help@jakarta.apache.org