Package net.sourceforge.stripes.mock

Examples of net.sourceforge.stripes.mock.MockRoundtrip


        Assert.assertEquals(bean.getMapEnumString().get(Color.blue), "Blue");
    }

    @Test(groups="fast")
    public void bindNestedMap() throws Exception {
        MockRoundtrip trip = getRoundtrip();
        trip.addParameter("testBean.longMap[1]", "1");
        trip.addParameter("testBean.longMap[2]", "2");
        trip.addParameter("testBean.longMap[3]", "3");
        trip.execute();

        MapBindingTests bean = trip.getActionBean(MapBindingTests.class);
        Assert.assertEquals(bean.getTestBean().getLongMap().get(1l), new Long(1));
        Assert.assertEquals(bean.getTestBean().getLongMap().get(2l), new Long(2));
        Assert.assertEquals(bean.getTestBean().getLongMap().get(3l), new Long(3));
    }
View Full Code Here


     *
     * @see http://www.stripesframework.org/jira/browse/STS-604
     */
    @Test(groups="fast")
    public void testValidatePublicField() throws Exception {
        MockRoundtrip trip = new MockRoundtrip(getMockServletContext(), getClass());
        trip.execute("validatePublicField");
        ActionBean actionBean = trip.getActionBean(getClass());
        Assert.assertEquals(actionBean.getContext().getValidationErrors().size(), 1);
    }
View Full Code Here

        Assert.assertEquals(bean.getTestBean().getLongMap().get(3l), new Long(3));
    }

    @Test(groups="fast")
    public void bindKeyGreaterThanMaxInt() throws Exception {
        MockRoundtrip trip = getRoundtrip();
        trip.addParameter("testBean.longMap[9999999999l]", "1");
        trip.execute();

        MapBindingTests bean = trip.getActionBean(MapBindingTests.class);
        Assert.assertEquals(bean.getTestBean().getLongMap().get(9999999999l), new Long(1));
    }
View Full Code Here

     * @see http://www.stripesframework.org/jira/browse/STS-610
     */
    @Test(groups="extensions")
    @SuppressWarnings({ "unchecked", "rawtypes" })
    public void testValidateTypeConverterExtendsStock() throws Exception {
        MockRoundtrip trip = new MockRoundtrip(getMockServletContext(), getClass());
        Locale locale = trip.getRequest().getLocale();
        TypeConverterFactory factory = StripesFilter.getConfiguration().getTypeConverterFactory();
        TypeConverter<?> tc = factory.getTypeConverter(Integer.class, locale);
        try {
            factory.add(Integer.class, MyIntegerTypeConverter.class);
            trip.addParameter("shouldBeDoubled", "42");
            trip.addParameter("shouldNotBeDoubled", "42");
            trip.execute("validateTypeConverters");
            ValidationAnnotationsTest actionBean = trip.getActionBean(getClass());
            Assert.assertEquals(actionBean.shouldBeDoubled, new Integer(84));
            Assert.assertEquals(actionBean.shouldNotBeDoubled, new Integer(42));
        }
        finally {
            Class<? extends TypeConverter> tcType = tc == null ? null : tc.getClass();
View Full Code Here

        Assert.assertEquals(bean.getTestBean().getLongMap().get(9999999999l), new Long(1));
    }

    @Test(groups="fast")
    public void bindKeyGreaterThanMaxIntII() throws Exception {
        MockRoundtrip trip = getRoundtrip();
        trip.addParameter("testBean.longMap['9999999999']", "1");
        trip.execute();

        MapBindingTests bean = trip.getActionBean(MapBindingTests.class);
        Assert.assertEquals(bean.getTestBean().getLongMap().get(9999999999l), new Long(1));
    }
View Full Code Here

        Assert.assertEquals(bean.getTestBean().getLongMap().get(9999999999l), new Long(1));
    }

    @Test(groups="fast")
    public void writeThroughBeanInMap() throws Exception {
        MockRoundtrip trip = getRoundtrip();
        trip.addParameter("mapEnumTestBean['red'].longProperty", "1");
        trip.addParameter("mapEnumTestBean['red'].intProperty", "2");
        trip.addParameter("mapEnumTestBean['green'].longProperty", "3");
        trip.addParameter("mapEnumTestBean['green'].intProperty", "4");
        trip.execute();

        MapBindingTests bean = trip.getActionBean(MapBindingTests.class);
        Assert.assertNotNull(bean.getMapEnumTestBean().get(Color.red));
        Assert.assertNotNull(bean.getMapEnumTestBean().get(Color.green));
        Assert.assertEquals(bean.getMapEnumTestBean().get(Color.red).getLongProperty(), new Long(1));
        Assert.assertEquals(bean.getMapEnumTestBean().get(Color.red).getIntProperty(), 2);
        Assert.assertEquals(bean.getMapEnumTestBean().get(Color.green).getLongProperty(), new Long(3));
View Full Code Here

    public void testValidateTypeConverterDoesNotExtendStock() throws Exception {
        TypeConverterFactory factory = StripesFilter.getConfiguration().getTypeConverterFactory();
        Class<? extends TypeConverter> oldtc = factory.getTypeConverter(//
                String.class, Locale.getDefault()).getClass();
        try {
            MockRoundtrip trip = new MockRoundtrip(getMockServletContext(), getClass());
            factory.add(String.class, MyStringTypeConverter.class);
            trip.addParameter("shouldBeUpperCased", "test");
            trip.addParameter("shouldNotBeUpperCased", "test");
            trip.execute("validateTypeConverters");
            ValidationAnnotationsTest actionBean = trip.getActionBean(getClass());
            Assert.assertEquals(actionBean.shouldBeUpperCased, "TEST");
            Assert.assertEquals(actionBean.shouldNotBeUpperCased, "test");
        }
        finally {
            factory.add(String.class, (Class<? extends TypeConverter<?>>) oldtc);
View Full Code Here

        Assert.assertEquals(bean.getMapEnumTestBean().get(Color.green).getIntProperty(), 4);
    }

    @Test(groups="fast")
    public void bindDateKeysInMap() throws Exception {
        MockRoundtrip trip = getRoundtrip();
        trip.getRequest().addLocale(Locale.ENGLISH);
        trip.addParameter("mapDateDate['31-Dec-1999']", "01/01/2000");
        trip.execute();

        Calendar cal = Calendar.getInstance();
        cal.clear();
        cal.set(1999,Calendar.DECEMBER,31);
        Date key = cal.getTime();

        MapBindingTests bean = trip.getActionBean(MapBindingTests.class);
        Assert.assertNotNull(bean.getMapDateDate().get(key));
    }
View Full Code Here

     *
     * @see http://www.stripesframework.org/jira/browse/STS-521
     */
    @Test(groups="fast")
    public void testValidateEncryptedEmptyString() throws Exception {
        MockRoundtrip trip = new MockRoundtrip(getMockServletContext(), getClass());
        trip.addParameter("encryptedParam", CryptoUtil.encrypt(""));
        trip.execute("validateEncrypted");
        ValidationAnnotationsTest actionBean = trip.getActionBean(getClass());
        Assert.assertNull(actionBean.encryptedParam);
    }
View Full Code Here

        this.typelessMap.put("foo", new TestBean());
    }

    @Test(groups="fast")
    public void bindThroughTypelessMap() throws Exception {
        MockRoundtrip trip = getRoundtrip();
        trip.addParameter("typelessMap[1].longProperty", "1234");
        trip.addParameter("typelessMap[2l].nestedBean.longProperty", "4321");
        trip.addParameter("typelessMap['foo'].enumProperty", "Sixth");
        trip.execute();

        MapBindingTests bean = trip.getActionBean(MapBindingTests.class);
        Assert.assertEquals( ((TestBean) bean.getTypelessMap().get(1)).getLongProperty(), new Long(1234));
        Assert.assertEquals( ((TestBean) bean.getTypelessMap().get(2l)).getNestedBean().getLongProperty(), new Long(4321));
        Assert.assertEquals( ((TestBean) bean.getTypelessMap().get("foo")).getEnumProperty(), TestEnum.Sixth);
    }
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.