You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by cr...@apache.org on 2005/09/18 05:51:27 UTC

svn commit: r289885 - in /struts/shale/trunk/core-library/src/test/org/apache/shale/view: ConcreteFacesBean.java ConcreteFacesBeanTestCase.java ConcreteViewController.java ConcreteViewControllerTestCase.java

Author: craigmcc
Date: Sat Sep 17 20:51:21 2005
New Revision: 289885

URL: http://svn.apache.org/viewcvs?rev=289885&view=rev
Log:
Add test cases for o.a.s.v.{AbstractFacesBean,AbstractViewController}

Added:
    struts/shale/trunk/core-library/src/test/org/apache/shale/view/ConcreteFacesBean.java
    struts/shale/trunk/core-library/src/test/org/apache/shale/view/ConcreteFacesBeanTestCase.java
    struts/shale/trunk/core-library/src/test/org/apache/shale/view/ConcreteViewController.java
    struts/shale/trunk/core-library/src/test/org/apache/shale/view/ConcreteViewControllerTestCase.java

Added: struts/shale/trunk/core-library/src/test/org/apache/shale/view/ConcreteFacesBean.java
URL: http://svn.apache.org/viewcvs/struts/shale/trunk/core-library/src/test/org/apache/shale/view/ConcreteFacesBean.java?rev=289885&view=auto
==============================================================================
--- struts/shale/trunk/core-library/src/test/org/apache/shale/view/ConcreteFacesBean.java (added)
+++ struts/shale/trunk/core-library/src/test/org/apache/shale/view/ConcreteFacesBean.java Sat Sep 17 20:51:21 2005
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shale.view;
+
+/**
+ * <p>Concrete subclass of <code>AbstractFacesBean</code> so we can
+ * test the underlying functionality.</p>
+ */
+public class ConcreteFacesBean extends AbstractFacesBean {
+
+
+    public ConcreteFacesBean() {
+        super();
+    }
+
+    public ConcreteFacesBean(String id) {
+        this.id = id;
+    }
+
+    private String id = null;
+    public String getId() { return this.id; }
+    public void setId(String id) { this.id = id; }
+
+
+}
\ No newline at end of file

Added: struts/shale/trunk/core-library/src/test/org/apache/shale/view/ConcreteFacesBeanTestCase.java
URL: http://svn.apache.org/viewcvs/struts/shale/trunk/core-library/src/test/org/apache/shale/view/ConcreteFacesBeanTestCase.java?rev=289885&view=auto
==============================================================================
--- struts/shale/trunk/core-library/src/test/org/apache/shale/view/ConcreteFacesBeanTestCase.java (added)
+++ struts/shale/trunk/core-library/src/test/org/apache/shale/view/ConcreteFacesBeanTestCase.java Sat Sep 17 20:51:21 2005
@@ -0,0 +1,184 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shale.view;
+
+import java.util.Map;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import org.apache.shale.test.base.AbstractJsfTestCase;
+
+/**
+ * <p>Test case for <code>AbstractFacesBean</code>.</p>
+ */
+public class ConcreteFacesBeanTestCase extends AbstractJsfTestCase {
+    
+    // ------------------------------------------------------------ Constructors
+
+
+    // Construct a new instance of this test case.
+    public ConcreteFacesBeanTestCase(String name) {
+        super(name);
+    }
+
+
+    // ---------------------------------------------------- Overall Test Methods
+
+
+    // Set up instance variables required by this test case.
+    public void setUp() {
+
+        super.setUp();
+
+        // Set up the instance we will be testing
+        bean = new ConcreteFacesBean();
+
+    }
+
+
+    // Return the tests included in this test case.
+    public static Test suite() {
+
+        return (new TestSuite(ConcreteFacesBeanTestCase.class));
+
+    }
+
+
+    // Tear down instance variables required by this test case.
+    public void tearDown() {
+
+        bean = null;
+        super.tearDown();
+
+    }
+
+
+    // ------------------------------------------------------ Instance Variables
+
+
+    // The instance to be tested
+    AbstractFacesBean bean = null;
+
+    
+    // ------------------------------------------------------------ Test Methods
+
+
+    // Test access to application scope attributes
+    public void testApplicationMap() {
+
+        servletContext.setAttribute("foo", "bar");
+        Map map = bean.getApplicationMap();
+        assertTrue(map.containsKey("foo"));
+        assertTrue(map.containsValue("bar"));
+        assertEquals("bar", map.get("foo"));
+        map.put("baz", "bop");
+        assertEquals("bop", servletContext.getAttribute("baz"));
+        map.remove("foo");
+        assertNull(servletContext.getAttribute("foo"));
+
+    }
+
+
+    // Test the getBean() method
+    public void testGetBean() {
+
+        servletContext.setAttribute("foo1", "bar1");
+        request.setAttribute("foo2", "bar2");
+        session.setAttribute("foo3", "bar3");
+        assertEquals("bar1", bean.getBean("foo1"));
+        assertEquals("bar2", bean.getBean("foo2"));
+        assertEquals("bar3", bean.getBean("foo3"));
+
+    }
+
+
+    // Test the getValue() method
+    public void testGetValue() {
+
+        servletContext.setAttribute("foo", new ConcreteFacesBean("bar"));
+        assertEquals("bar", bean.getValue("#{foo.id}"));
+
+    }
+
+
+    // Test pristine instance
+    public void testPristine() {
+
+        assertNotNull(bean.getApplication());
+        assertNotNull(bean.getApplicationMap());
+        assertNotNull(bean.getExternalContext());
+        assertNotNull(bean.getFacesContext());
+        assertNotNull(bean.getLifecycle());
+        assertNotNull(bean.getRequestMap());
+        assertNotNull(bean.getSessionMap());
+
+    }
+
+
+    // Test access to request scope attributes
+    public void testRequestMap() {
+
+        request.setAttribute("foo", "bar");
+        Map map = bean.getRequestMap();
+        assertTrue(map.containsKey("foo"));
+        assertTrue(map.containsValue("bar"));
+        assertEquals("bar", map.get("foo"));
+        map.put("baz", "bop");
+        assertEquals("bop", request.getAttribute("baz"));
+        map.remove("foo");
+        assertNull(request.getAttribute("foo"));
+
+    }
+
+
+    // Test access to session scope attributes
+    public void testSessionMap() {
+
+        session.setAttribute("foo", "bar");
+        Map map = bean.getSessionMap();
+        assertTrue(map.containsKey("foo"));
+        assertTrue(map.containsValue("bar"));
+        assertEquals("bar", map.get("foo"));
+        map.put("baz", "bop");
+        assertEquals("bop", session.getAttribute("baz"));
+        map.remove("foo");
+        assertNull(session.getAttribute("foo"));
+
+    }
+
+
+    // Test the setBean()method
+    public void testSetBean() {
+
+        bean.setBean("foo", "bar");
+        assertEquals("bar", bean.getBean("foo"));
+        assertEquals("bar", request.getAttribute("foo"));
+
+    }
+
+
+    // Test the setValue() method
+    public void testSetValue() {
+
+        servletContext.setAttribute("foo", new ConcreteFacesBean("bar"));
+        bean.setValue("#{foo.id}", "baz");
+        assertEquals("baz", bean.getValue("#{foo.id}"));
+        assertEquals("baz", ((ConcreteFacesBean) servletContext.getAttribute("foo")).getId());
+
+    }
+
+
+}

Added: struts/shale/trunk/core-library/src/test/org/apache/shale/view/ConcreteViewController.java
URL: http://svn.apache.org/viewcvs/struts/shale/trunk/core-library/src/test/org/apache/shale/view/ConcreteViewController.java?rev=289885&view=auto
==============================================================================
--- struts/shale/trunk/core-library/src/test/org/apache/shale/view/ConcreteViewController.java (added)
+++ struts/shale/trunk/core-library/src/test/org/apache/shale/view/ConcreteViewController.java Sat Sep 17 20:51:21 2005
@@ -0,0 +1,25 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shale.view;
+
+/**
+ * <p>Concrete subclass of <code>AbstractViewController</code> so we can
+ * test the underlying functionality.</p>
+ */
+public class ConcreteViewController extends AbstractViewController {
+
+}
\ No newline at end of file

Added: struts/shale/trunk/core-library/src/test/org/apache/shale/view/ConcreteViewControllerTestCase.java
URL: http://svn.apache.org/viewcvs/struts/shale/trunk/core-library/src/test/org/apache/shale/view/ConcreteViewControllerTestCase.java?rev=289885&view=auto
==============================================================================
--- struts/shale/trunk/core-library/src/test/org/apache/shale/view/ConcreteViewControllerTestCase.java (added)
+++ struts/shale/trunk/core-library/src/test/org/apache/shale/view/ConcreteViewControllerTestCase.java Sat Sep 17 20:51:21 2005
@@ -0,0 +1,81 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shale.view;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * <p>Test case for <code>AbstractViewController</code>.</p>
+ */
+public class ConcreteViewControllerTestCase extends ConcreteFacesBeanTestCase {
+    
+    // ------------------------------------------------------------ Constructors
+
+
+    // Construct a new instance of this test case.
+    public ConcreteViewControllerTestCase(String name) {
+        super(name);
+    }
+
+
+    // ---------------------------------------------------- Overall Test Methods
+
+
+    // Set up instance variables required by this test case.
+    public void setUp() {
+
+        super.setUp();
+
+        // Set up the instance we will be testing
+        bean = new ConcreteViewController();
+
+    }
+
+
+    // Return the tests included in this test case.
+    public static Test suite() {
+
+        return (new TestSuite(ConcreteViewControllerTestCase.class));
+
+    }
+
+
+    // Tear down instance variables required by this test case.
+    public void tearDown() {
+
+        bean = null;
+        super.tearDown();
+
+    }
+
+
+    // ------------------------------------------------------------ Test Methods
+
+
+    // Test access to the postBack property
+    public void testPostBack() {
+
+        ConcreteViewController cvc = (ConcreteViewController) bean;
+        assertTrue(!cvc.isPostBack());
+        cvc.setPostBack(true);
+        assertTrue(cvc.isPostBack());
+
+    }
+
+
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org