head	1.5;
access;
symbols;
locks; strict;
comment	@# @;


1.5
date	2001.08.30.16.57.43;	author dlr;	state Exp;
branches;
next	1.4;

1.4
date	2001.08.27.08.49.01;	author dlr;	state Exp;
branches;
next	1.3;

1.3
date	2001.08.27.08.08.36;	author dlr;	state Exp;
branches;
next	1.2;

1.2
date	2001.08.27.07.01.17;	author dlr;	state Exp;
branches;
next	1.1;

1.1
date	2001.08.27.03.26.14;	author dlr;	state Exp;
branches;
next	;


desc
@@


1.5
log
@Updated for latest Turbine API changes.
@
text
@/* ================================================================
 * Copyright (c) 2001 CollabNet.  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 acknowlegement: "This product includes
 * software developed by CollabNet (http://www.collab.net/)."
 * Alternately, this acknowlegement may appear in the software itself, if
 * and wherever such third-party acknowlegements normally appear.
 * 
 * 4. The hosted project names must not be used to endorse or promote
 * products derived from this software without prior written
 * permission. For written permission, please contact info@@collab.net.
 * 
 * 5. Products derived from this software may not use the "Tigris" name
 * nor may "Tigris" appear in their names without prior written
 * permission of CollabNet.
 * 
 * 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 COLLABNET 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 CollabNet.
 */

package org.tigris.helm.tool;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

import org.apache.commons.collections.ExtendedProperties;
import org.apache.commons.util.exception.NestableException;

import org.apache.turbine.ParameterParser;
import org.apache.turbine.ParameterParser;

import org.apache.velocity.VelocityContext;
import org.apache.velocity.context.Context;

/**
 * Unit tests {@@link org.tigris.helm.tool.BOFactoryService}.
 *
 * @@author <a href="mailto:dlr@@collab.net">Daniel Rall</a>
 */
public class BOFactoryServiceTest extends TestCase
{
    private static final String[][] PROPS =
    {
        { "currentFoo.peer",
          "org.tigris.helm.tool.BOFactoryServiceTest$FooPeer" },
        { "currentFoo.parameterKey", "fooID" },
        { "currentFoo.default", "otherFoo" }
    };

    private BOFactoryService labRat;

    public static Test suite()
    {
        TestSuite suite = new TestSuite();
        suite.addTest(new BOFactoryServiceTest
            ("BOFactoryServiceTest"));
        return suite;
    }

    public BOFactoryServiceTest(String name)
    {
        super(name);
    }

    protected void setUp()
        throws Exception
    {
        labRat = new BOFactoryService();
        ExtendedProperties cfg = new ExtendedProperties();
        for (int i = 0; i < PROPS.length; i++)
        {
            cfg.addProperty(PROPS[i][0], PROPS[i][1]);
        }
        labRat.parseConfig(cfg);
        //labRat.setInit(true);
    }

    protected void runTest()
        throws Throwable
    {
        Context context = new VelocityContext();
        ParameterParser p = new ParameterParser();
        String id = "37";
        p.setString("fooID", id);
        labRat.processParameters(p, context);
        Foo foo = (Foo) context.get("currentFoo");
        assert("processParameters(ParameterParser, Context) failed to  " +
               "add business object to context",
               foo != null && foo instanceof Foo);
        assertEquals("processParameters(ParameterParser, Context) got " +
                     "bogus parameter for business object",
                     id, foo.id);
    }

    protected void tearDown()
    {
        labRat = null;
    }

    private static class Foo
    {
        protected String id;

        protected Foo(String id)
        {
            this.id = id;
        }
    }

    private static class FooPeer
    {
        public static Foo getInstance(String id)
        {
            return new Foo(id);
        }
    }
}
@


1.4
log
@Test nows fully tests BOFactoryService and successfully runs to
completion.
@
text
@d56 2
a57 2
import org.apache.fulcrum.util.parser.DefaultParameterParser;
import org.apache.fulcrum.util.parser.ParameterParser;
d109 1
a109 1
        ParameterParser p = new DefaultParameterParser();
@


1.3
log
@Test now fails due to some fleshing out of runTest(), but is closer to
what it needs to be.  We need a HttpServletRequest instance...other
than implementing the interface myself, the only other idea I've come
up with is to use Cactus or hack BOFactoryService a tiny bit.
@
text
@d56 3
d109 4
a112 2
        // TODO
        //labRat.processParameters(req, context);
d114 1
a114 1
        assert("processParameters(HttpServletRequest, Context) failed to  " +
d117 3
d127 1
a127 1
    private class Foo
d137 1
a137 1
    private class FooPeer
d139 1
a139 1
        public Foo getInstance(String id)
@


1.2
log
@Setup using fake business object now executes properly.
@
text
@d56 3
d105 1
d107 5
d121 6
d133 1
a133 1
            return new Foo();
@


1.1
log
@Start of a unit test for BOFactoryService.
@
text
@d65 4
a68 3
        { "currentUser.peer", "org.tigris.helm.om.UserPeer" },
        { "currentUser.parameterKey", "userID" },
        { "currentUser.default", "loginUser" }
d108 12
@

