Package net.sourceforge.stripes.mock

Examples of net.sourceforge.stripes.mock.MockRoundtrip


        runValidationTests(ExtendOverloadSetterAgainActionBean.class);
    }

    protected void runValidationTests(Class<? extends BaseActionBean<User>> type) throws Exception {
        // Trigger the validation errors
        MockRoundtrip trip = new MockRoundtrip(StripesTestFixture.getServletContext(), type);
        trip.execute("login");
        ValidationErrors errors = trip.getValidationErrors();
        Assert.assertNotNull(errors, "Expected validation errors but got none");
        Assert.assertFalse(errors.isEmpty(), "Expected validation errors but got none");
        Assert.assertEquals(errors.size(), 2, "Expected two validation errors but got " + errors.size());

        // Now add the required parameters and make sure the validation errors don't happen
        trip.addParameter("model.username", "Scooby");
        trip.addParameter("model.password", "Shaggy");
        trip.execute("login");
        errors = trip.getValidationErrors();
        Assert.assertTrue(errors == null || errors.isEmpty(), "Got unexpected validation errors");

        BaseActionBean<User> bean = trip.getActionBean(type);
        Assert.assertNotNull(bean);
        Assert.assertNotNull(bean.getModel());
        Assert.assertEquals(bean.getModel().getUsername(), "Scooby");
        Assert.assertEquals(bean.getModel().getPassword(), "Shaggy");
    }
View Full Code Here


    @Validate(converter=OneToManyTypeConverter.class) private List<Long> numbers;
    @Validate(converter=OneToManyTypeConverter.class) private List<Date> dates;

    @Test(groups="fast")
    public void testListOfLong() throws Exception {
        MockRoundtrip trip = new MockRoundtrip(StripesTestFixture.getServletContext(), getClass());
        trip.addParameter("numbers", "123 456 789");
        trip.execute();
        OneToManyTypeConverterTest bean = trip.getActionBean(getClass());
        List<Long> numbers = bean.getNumbers();
        Assert.assertEquals(numbers, Literal.list(123l, 456l, 789l));
    }
View Full Code Here

        Assert.assertEquals(numbers, Literal.list(123l, 456l, 789l));
    }

    @Test(groups="fast")
    public void testListOfDate() throws Exception {
        MockRoundtrip trip = new MockRoundtrip(StripesTestFixture.getServletContext(), getClass());
        trip.getRequest().addLocale(Locale.ENGLISH);
        trip.addParameter("dates", "12/31/2005, 1/1/2006, 6/15/2008, 7/7/2007");
        trip.execute();
        OneToManyTypeConverterTest bean = trip.getActionBean(getClass());
        List<Date> dates = bean.getDates();

        DateFormat format = new SimpleDateFormat("MM/dd/yyyy");
        Assert.assertEquals(dates, Literal.list(format.parse("12/31/2005"),
                                                format.parse("1/1/2006"),
View Full Code Here

                                                format.parse("7/7/2007")));
    }

    @Test(groups="fast")
    public void testWithErrors() throws Exception {
        MockRoundtrip trip = new MockRoundtrip(StripesTestFixture.getServletContext(), getClass());
        trip.addParameter("numbers", "123 456 abc 789 def");
        trip.execute();

        OneToManyTypeConverterTest bean = trip.getActionBean(getClass());
        List<Long> numbers = bean.getNumbers();

        Assert.assertNull(numbers);
        Collection<ValidationError> errors = bean.getContext().getValidationErrors().get("numbers");
        Assert.assertEquals(errors.size(), 2, "There should be two errors!");
View Full Code Here

     * errors generated. The only validation method that should be run is validateAlways() because
     * the others are tied to specific events.
     */
    @Test(groups="fast")
    public void testEventZeroNoErrors() throws Exception {
        MockRoundtrip trip = new MockRoundtrip(StripesTestFixture.getServletContext(), getClass());
        trip.addParameter("numberZero", "99");
        trip.execute("eventZero");

        ValidationFlowTest test = trip.getActionBean(getClass());
        Assert.assertEquals(1, test.validateAlwaysRan);
        Assert.assertEquals(0, test.validateOneRan);
        Assert.assertEquals(0, test.validateTwoRan);
        Assert.assertEquals(0, test.getContext().getValidationErrors().size());
    }
View Full Code Here

     * has a on="one".  The single validaiton error should prevent validateAlways() and
     * validateOne from running.
     */
    @Test(groups="fast")
    public void testEventZeroWithErrors() throws Exception {
        MockRoundtrip trip = new MockRoundtrip(StripesTestFixture.getServletContext(), getClass());
        trip.addParameter("numberZero", "99");
        trip.addParameter("numberOne", "-100");
        trip.execute("eventZero");

        ValidationFlowTest test = trip.getActionBean(getClass());
        Assert.assertEquals(0, test.validateAlwaysRan);
        Assert.assertEquals(0, test.validateOneRan);
        Assert.assertEquals(0, test.validateTwoRan);
        Assert.assertEquals(test.numberZero, 99);
        Assert.assertEquals(1, test.getContext().getValidationErrors().size());
View Full Code Here

     * Number one is a required field also for this event, so we supply it.  This event should
     * cause both validateAlways and validateOne to run.
     */
    @Test(groups="fast")
    public void testEventOneNoErrors() throws Exception {
        MockRoundtrip trip = new MockRoundtrip(StripesTestFixture.getServletContext(), getClass());
        trip.addParameter("numberZero", "100");
        trip.addParameter("numberOne", "101");

        trip.execute("eventOne");

        ValidationFlowTest test = trip.getActionBean(getClass());
        Assert.assertEquals(1, test.validateAlwaysRan);
        Assert.assertEquals(2, test.validateOneRan);
        Assert.assertEquals(0, test.validateTwoRan);
        Assert.assertEquals(test.numberZero, 100);
        Assert.assertEquals(test.numberOne, 101);
View Full Code Here

     * required for this event.  Again this single error should prevent both validateAlways
     * and validateOne from running.
     */
    @Test(groups="fast")
    public void testEventOneWithErrors() throws Exception {
        MockRoundtrip trip = new MockRoundtrip(StripesTestFixture.getServletContext(), getClass());
        trip.addParameter("numberZero", "100");
        trip.addParameter("numberOne", "")// required field for event one
        trip.execute("eventOne");

        ValidationFlowTest test = trip.getActionBean(getClass());
        Assert.assertEquals(0, test.validateAlwaysRan);
        Assert.assertEquals(0, test.validateOneRan);
        Assert.assertEquals(0, test.validateTwoRan);
        Assert.assertEquals(test.numberZero, 100);
        Assert.assertEquals(1, test.getContext().getValidationErrors().size());
View Full Code Here

     * Tests to make sure that event-specific validations are still applied correctly when the
     * event name isn't present in the request.
     */
    @Test(groups="fast")
    public void testEventOneAsDefault() throws Exception {
        MockRoundtrip trip = new MockRoundtrip(StripesTestFixture.getServletContext(), getClass());
        trip.addParameter("numberZero", "100");
        trip.addParameter("numberOne", "101");
        trip.execute();

        ValidationFlowTest test = trip.getActionBean(getClass());
        Assert.assertEquals(1, test.validateAlwaysRan);
        Assert.assertEquals(2, test.validateOneRan);
        Assert.assertEquals(0, test.validateTwoRan);
        Assert.assertEquals(test.numberZero, 100);
        Assert.assertEquals(test.numberOne, 101);
View Full Code Here

     * numberTwo should be required (and is supplied) and validateAlways and validateTwo should
     * run but not validateOne.
     */
    @Test(groups="fast")
    public void testEventTwoNoErrors() throws Exception {
        MockRoundtrip trip = new MockRoundtrip(StripesTestFixture.getServletContext(), getClass());
        trip.addParameter("numberZero", "100");
        trip.addParameter("numberTwo""102");

        trip.execute("eventTwo");

        ValidationFlowTest test = trip.getActionBean(getClass());
        Assert.assertEquals(1, test.validateAlwaysRan);
        Assert.assertEquals(0, test.validateOneRan);
        Assert.assertEquals(2, test.validateTwoRan);
        Assert.assertEquals(test.numberZero, 100);
        Assert.assertEquals(test.numberTwo, 102);
View Full Code Here

TOP

Related Classes of net.sourceforge.stripes.mock.MockRoundtrip

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.