⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testdynaactionform.java

📁 jakarta-struts-1.2.4-src
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        value = dynaForm.get("mappedProperty", "First Key");
        assertEquals("Can find first value", "First Value", value);

        value = dynaForm.get("mappedProperty", "Second Key");
        assertEquals("Can find second value", "Second Value", value);

        value = dynaForm.get("mappedProperty", "Third Key");
        assertNull("Can not find third value", value);

    }


    /**
     * Corner cases on getSimpleProperty invalid arguments.
     */
    public void testGetSimpleArguments() {

        try {
            dynaForm.get(null);
            fail("Should throw IllegalArgumentException");
        } catch (IllegalArgumentException e) {
            ; // Expected response
        }

    }


    /**
     * Test getSimpleProperty on a boolean property.
     */
    public void testGetSimpleBoolean() {

        Object value = dynaForm.get("booleanProperty");
        assertNotNull("Got a value", value);
        assertTrue("Got correct type", (value instanceof Boolean));
        assertTrue("Got correct value",
                ((Boolean) value).booleanValue() == true);
    }


    /**
     * Test getSimpleProperty on a double property.
     */
    public void testGetSimpleDouble() {

            Object value = dynaForm.get("doubleProperty");
            assertNotNull("Got a value", value);
            assertTrue("Got correct type", (value instanceof Double));
            assertEquals("Got correct value",
                    ((Double) value).doubleValue(),
                    (double) 321.0,
                    (double) 0.005);

    }


    /**
     * Test getSimpleProperty on a float property.
     */
    public void testGetSimpleFloat() {

        Object value = dynaForm.get("floatProperty");
        assertNotNull("Got a value", value);
        assertTrue("Got correct type", (value instanceof Float));
        assertEquals("Got correct value",
                ((Float) value).floatValue(),
                (float) 123.0,
                (float) 0.005);

    }


    /**
     * Test getSimpleProperty on a int property.
     */
    public void testGetSimpleInt() {

        Object value = dynaForm.get("intProperty");
        assertNotNull("Got a value", value);
        assertTrue("Got correct type", (value instanceof Integer));
        assertEquals("Got correct value",
                ((Integer) value).intValue(),
                (int) 123);

    }


    /**
     * Test getSimpleProperty on a long property.
     */
    public void testGetSimpleLong() {

        Object value = dynaForm.get("longProperty");
        assertNotNull("Got a value", value);
        assertTrue("Got correct type", (value instanceof Long));
        assertEquals("Got correct value",
                ((Long) value).longValue(),
                (long) 321);

    }


    /**
     * Test getSimpleProperty on a short property.
     */
    public void testGetSimpleShort() {

        Object value = dynaForm.get("shortProperty");
        assertNotNull("Got a value", value);
        assertTrue("Got correct type", (value instanceof Short));
        assertEquals("Got correct value",
                ((Short) value).shortValue(),
                (short) 987);

    }


    /**
     * Test getSimpleProperty on a String property.
     */
    public void testGetSimpleString() {

        Object value = dynaForm.get("stringProperty");
        assertNotNull("Got a value", value);
        assertTrue("Got correct type", (value instanceof String));
        assertEquals("Got correct value",
                (String) value,
                "This is a string");

    }


    /**
     * Test <code>contains()</code> method for mapped properties.
     */
    public void testMappedContains() {

        assertTrue("Can see first key",
                dynaForm.contains("mappedProperty", "First Key"));

        assertTrue("Can not see unknown key",
                !dynaForm.contains("mappedProperty", "Unknown Key"));

    }


    /**
     * Test <code>remove()</code> method for mapped properties.
     */
    public void testMappedRemove() {

        assertTrue("Can see first key",
                dynaForm.contains("mappedProperty", "First Key"));
        dynaForm.remove("mappedProperty", "First Key");
        assertTrue("Can not see first key",
                !dynaForm.contains("mappedProperty", "First Key"));

        assertTrue("Can not see unknown key",
                !dynaForm.contains("mappedProperty", "Unknown Key"));
        dynaForm.remove("mappedProperty", "Unknown Key");
        assertTrue("Can not see unknown key",
                !dynaForm.contains("mappedProperty", "Unknown Key"));

    }


    /**
     * Corner cases on setIndexedProperty invalid arguments.
     */
    public void testSetIndexedArguments() {

        try {
            dynaForm.set("intArray", -1, new Integer(0));
            fail("Should throw IndexOutOfBoundsException");
        } catch (IndexOutOfBoundsException e) {
            ; // Expected response
        }

    }


    /**
     * Positive and negative tests on setIndexedProperty valid arguments.
     */
    public void testSetIndexedValues() {

        Object value = null;

        dynaForm.set("intArray", 0, new Integer(1));
        value = (Integer) dynaForm.get("intArray", 0);
        assertNotNull("Returned new value 0", value);
        assertTrue("Returned Integer new value 0",
                value instanceof Integer);
        assertEquals("Returned correct new value 0", 1,
                ((Integer) value).intValue());

        dynaForm.set("intIndexed", 1, new Integer(11));
        value = (Integer) dynaForm.get("intIndexed", 1);
        assertNotNull("Returned new value 1", value);
        assertTrue("Returned Integer new value 1",
                value instanceof Integer);
        assertEquals("Returned correct new value 1", 11,
                ((Integer) value).intValue());
        dynaForm.set("listIndexed", 2, "New Value 2");
        value = (String) dynaForm.get("listIndexed", 2);
        assertNotNull("Returned new value 2", value);
        assertTrue("Returned String new value 2",
                value instanceof String);
        assertEquals("Returned correct new value 2", "New Value 2",
                (String) value);

        dynaForm.set("stringArray", 3, "New Value 3");
        value = (String) dynaForm.get("stringArray", 3);
        assertNotNull("Returned new value 3", value);
        assertTrue("Returned String new value 3",
                value instanceof String);
        assertEquals("Returned correct new value 3", "New Value 3",
                (String) value);

        dynaForm.set("stringIndexed", 4, "New Value 4");
        value = (String) dynaForm.get("stringIndexed", 4);
        assertNotNull("Returned new value 4", value);
        assertTrue("Returned String new value 4",
                value instanceof String);
        assertEquals("Returned correct new value 4", "New Value 4",
                (String) value);


    }


    /**
     * Positive and negative tests on setMappedProperty valid arguments.
     */
    public void testSetMappedValues() {


        dynaForm.set("mappedProperty", "First Key", "New First Value");
        assertEquals("Can replace old value",
                "New First Value",
                (String) dynaForm.get("mappedProperty", "First Key"));

        dynaForm.set("mappedProperty", "Fourth Key", "Fourth Value");
        assertEquals("Can set new value",
                "Fourth Value",
                (String) dynaForm.get("mappedProperty", "Fourth Key"));


    }


    /**
     * Test setSimpleProperty on a boolean property.
     */
    public void testSetSimpleBoolean() {

        boolean oldValue =
                ((Boolean) dynaForm.get("booleanProperty")).booleanValue();
        boolean newValue = !oldValue;
        dynaForm.set("booleanProperty", new Boolean(newValue));
        assertTrue("Matched new value",
                newValue ==
                ((Boolean) dynaForm.get("booleanProperty")).booleanValue());

    }


    /**
     * Test setSimpleProperty on a double property.
     */
    public void testSetSimpleDouble() {

        double oldValue =
                ((Double) dynaForm.get("doubleProperty")).doubleValue();
        double newValue = oldValue + 1.0;
        dynaForm.set("doubleProperty", new Double(newValue));
        assertEquals("Matched new value",
                newValue,
                ((Double) dynaForm.get("doubleProperty")).doubleValue(),
                (double) 0.005);

    }


    /**
     * Test setSimpleProperty on a float property.
     */
    public void testSetSimpleFloat() {

        float oldValue =
                ((Float) dynaForm.get("floatProperty")).floatValue();
        float newValue = oldValue + (float) 1.0;
        dynaForm.set("floatProperty", new Float(newValue));
        assertEquals("Matched new value",
                newValue,
                ((Float) dynaForm.get("floatProperty")).floatValue(),
                (float) 0.005);

    }


    /**
     * Test setSimpleProperty on a int property.
     */
    public void testSetSimpleInt() {

        int oldValue =
                ((Integer) dynaForm.get("intProperty")).intValue();
        int newValue = oldValue + 1;
        dynaForm.set("intProperty", new Integer(newValue));
        assertEquals("Matched new value",
                newValue,
                ((Integer) dynaForm.get("intProperty")).intValue());
    }


    /**
     * Test setSimpleProperty on a long property.
     */
    public void testSetSimpleLong() {

        long oldValue =
                ((Long) dynaForm.get("longProperty")).longValue();
        long newValue = oldValue + 1;
        dynaForm.set("longProperty", new Long(newValue));
        assertEquals("Matched new value",
                newValue,
                ((Long) dynaForm.get("longProperty")).longValue());

    }


    /**
     * Test setSimpleProperty on a short property.
     */
    public void testSetSimpleShort() {

        short oldValue =
                ((Short) dynaForm.get("shortProperty")).shortValue();
        short newValue = (short) (oldValue + 1);
        dynaForm.set("shortProperty", new Short(newValue));
        assertEquals("Matched new value",
                newValue,
                ((Short) dynaForm.get("shortProperty")).shortValue());

    }


    /**
     * Test setSimpleProperty on a String property.
     */
    public void testSetSimpleString() {

        String oldValue = (String) dynaForm.get("stringProperty");
        String newValue = oldValue + " Extra Value";
        dynaForm.set("stringProperty", newValue);
        assertEquals("Matched new value",
                newValue,
                (String) dynaForm.get("stringProperty"));

    }


    // ------------------------------------------------------ Protected Methods


    /**
     * Set up the complex properties that cannot be configured from the
     * initial value expression.
     */
    protected void setupComplexProperties() {

        List listIndexed = new ArrayList();
        listIndexed.add("String 0");
        listIndexed.add("String 1");
        listIndexed.add("String 2");
        listIndexed.add("String 3");
        listIndexed.add("String 4");
        dynaForm.set("listIndexed", listIndexed);

        Map mappedProperty = new HashMap();
        mappedProperty.put("First Key", "First Value");
        mappedProperty.put("Second Key", "Second Value");
        dynaForm.set("mappedProperty", mappedProperty);

        Map mappedIntProperty = new HashMap();
        mappedIntProperty.put("One", new Integer(1));
        mappedIntProperty.put("Two", new Integer(2));
        dynaForm.set("mappedIntProperty", mappedIntProperty);

    }



    /**
     * Base for testGetDescriptorXxxxx() series of tests.
     *
     * @param name Name of the property to be retrieved
     * @param type Expected class type of this property
     */
    protected void testGetDescriptorBase(String name, Class type) {

        DynaProperty descriptor =
                dynaForm.getDynaClass().getDynaProperty(name);
        assertNotNull("Got descriptor", descriptor);
        assertEquals("Got correct type", type, descriptor.getType());

    }


}


class DynaActionFormMapping extends ActionMapping {

    public DynaActionFormMapping(ModuleConfig appConfig) {
        this.appConfig = appConfig;
    }

    private ModuleConfig appConfig = null;

    public ModuleConfig getModuleConfig() {
        return (this.appConfig);
    }

    public String getName() {
        return ("dynaForm");
    }

}



class DynaActionFormConfig extends ModuleConfigImpl {

    public DynaActionFormConfig(FormBeanConfig beanConfig) {
        super("");
        this.beanConfig = beanConfig;
    }

    private FormBeanConfig beanConfig = null;

    public FormBeanConfig findFormBeanConfig(String name) {
        return (this.beanConfig);
    }


}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -