Update of 
/var/cvs/tests/vpro-wizards/org/mmbase/applications/vprowizards/spring/action
In directory 
james.mmbase.org:/tmp/cvs-serv25208/tests/vpro-wizards/org/mmbase/applications/vprowizards/spring/action

Modified Files:
        CreateNodeActionTest.java CreateRelationActionTest.java 
        AbstractActionTest.java SortRelationActionTest.java 
Added Files:
        AbstractRelationActionTest.java ToggleRelationActionTest.java 
        DeleteNodeActionTest.java UpdateNodeActionTest.java 
Removed Files:
        AbstractRelationTest.java ToggleRelationTest.java 
Log Message:
work in progress on the junit tests


See also: 
http://cvs.mmbase.org/viewcvs/tests/vpro-wizards/org/mmbase/applications/vprowizards/spring/action


AbstractRelationActionTest.java is new



ToggleRelationActionTest.java is new



DeleteNodeActionTest.java is new



UpdateNodeActionTest.java is new



Index: CreateNodeActionTest.java
===================================================================
RCS file: 
/var/cvs/tests/vpro-wizards/org/mmbase/applications/vprowizards/spring/action/CreateNodeActionTest.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- CreateNodeActionTest.java   8 Sep 2008 15:59:04 -0000       1.2
+++ CreateNodeActionTest.java   22 Sep 2008 14:35:40 -0000      1.3
@@ -34,17 +34,8 @@
        @SuppressWarnings("unchecked")
        public void test_no_nodemanager_should_couse_global_error(){
                HttpServletRequest req = 
createRequest("actions[createNode][1].id=testId");
-               assertEquals(1, req.getParameterMap().size());
-               
-               WizardController wc = createWizardController();
-               assertNotNull("transaction is null!", 
wc.getCloudFactory().getTransaction(req));
                try {
-                       ModelAndView mandv = wc.handleRequest(req, null);
-                       Map<String,Object> model = (Map<String, Object>) 
mandv.getModel();
-                       
-                       assertEquals(1, getGlobalErrors(model).size());
-                       assertEquals(0, getFieldErrors(model).size());
-                       assertEquals("error.property.required", 
getGlobalErrors(model).get(0).getMessageKey());
+                       checkRequestCreatesGlobalError(req, 
"error.property.required");
                } catch (Exception e) {
                        log.error(e.getMessage(), e);
                        fail(e.getMessage());
@@ -54,15 +45,8 @@
        public void test_no_referrer_header_should_couse_global_error(){
                setReferrer = false;
                HttpServletRequest req = 
createRequest("actions[createNode][1].nodeType=mags");
-               //create an error by means of an invalid createNodeAction
-               
-               WizardController wc = createWizardController();
                try {
-                       ModelAndView mandv = wc.handleRequest(req, null);
-                       Map<String,Object> model = (Map<String, Object>) 
mandv.getModel();
-                       assertEquals(1, getGlobalErrors(model).size());
-                       assertEquals("error.no.referrer.header", 
getGlobalErrors(model).get(0).getMessageKey());
-                       
+                       checkRequestCreatesGlobalError(req, 
"error.no.referrer.header");
                } catch (Exception e) {
                        log.error(e.getMessage(), e);
                        fail(e.getMessage());
@@ -76,16 +60,8 @@
                HttpServletRequest req = 
createRequest("actions[createNode][1].nodeType=nonexistant");
                assertEquals(1, req.getParameterMap().size());
                
-               WizardController wc = createWizardController();
-               assertNotNull("transaction is null!", 
wc.getCloudFactory().getTransaction(req));
-               
                try {
-                       ModelAndView mandv = wc.handleRequest(req, null);
-                       Map<String,Object> model = (Map<String, Object>) 
mandv.getModel();
-                       
-                       assertEquals(1, getGlobalErrors(model).size());
-                       assertEquals(0, getFieldErrors(model).size());
-                       assertEquals("error.illegal.nodemanager", 
getGlobalErrors(model).get(0).getMessageKey());
+                       checkRequestCreatesGlobalError(req, 
"error.illegal.nodemanager");
                } catch (Exception e) {
                        log.error(e.getMessage(), e);
                        fail(e.getMessage());
@@ -93,15 +69,15 @@
        }
        
        public void test_global_error_should_couse_redirect_to_errorpage(){
+               //TODO:  this is not really a create node action, it should not 
be here
                HttpServletRequest req = 
createRequest("actions[createNode][1].id=fail");
                //create an error by means of an invalid createNodeAction
                
                WizardController wc = createWizardController();
-               ((ReferrerResolver) 
wc.getViewResolver()).setErrorPage("test-errorpage");
                try {
                        ModelAndView mandv = wc.handleRequest(req, null);
                        assertTrue("ModelAndView instance not of expected 
type", ModelAndView.class.isAssignableFrom(mandv.getClass()));
-                       assertEquals( "test-errorpage", mandv.getViewName());
+                       assertEquals( "error-html", mandv.getViewName());
                } catch (Exception e) {
                        log.error(e.getMessage(), e);
                        fail(e.getMessage());
@@ -109,6 +85,7 @@
        }
        
        public void test_legal_nodemanager_should_return_to_referrer(){
+               //TODO:  this is not really a create node action, it should not 
be here
                MockHttpServletRequest req = createRequest(
                                "actions[createNode][1].nodeType=mags" +
                                
"&actions[createNode][1].fields[title]=sometitle" +
@@ -141,7 +118,7 @@
                assertEquals(3, req.getParameterMap().size());
                
                WizardController wc = createWizardController();
-               assertNotNull("transaction is null!", 
wc.getCloudFactory().getTransaction(req));
+               assertNotNull("transaction is null!", 
wc.getCloudFactory().createTransaction(req));
                
                try {
                        ModelAndView mandv = wc.handleRequest(req, null);
@@ -150,8 +127,7 @@
                        View view = mandv.getView();
                        
assertTrue(RedirectView.class.isAssignableFrom(view.getClass()));
                        
-                       assertEquals(0, getGlobalErrors(model).size());
-                       assertEquals(0, getFieldErrors(model).size());
+                       checkNoErrors(mandv);
 
                        //fetch the node we just created
                        Node node = getLastNodeOfType("mags");


Index: CreateRelationActionTest.java
===================================================================
RCS file: 
/var/cvs/tests/vpro-wizards/org/mmbase/applications/vprowizards/spring/action/CreateRelationActionTest.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- CreateRelationActionTest.java       8 Sep 2008 15:59:04 -0000       1.1
+++ CreateRelationActionTest.java       22 Sep 2008 14:35:40 -0000      1.2
@@ -15,27 +15,11 @@
 import org.mmbase.util.logging.Logging;
 import org.springframework.web.servlet.ModelAndView;
 
-public class CreateRelationActionTest extends AbstractRelationTest {
+public class CreateRelationActionTest extends AbstractRelationActionTest {
 
 
        private static final Logger log = 
Logging.getLoggerInstance(CreateRelationActionTest.class);
 
-       public void init() {
-               // create the source and relation node for this test.
-               // using the mynews application we will create a posrel between
-               // mags and news. Let's create a mags and a news object.
-               log.service("initializing source and destination nodes for the 
create relation tests");
-               Cloud cloud = getCloud();
-               Node sourceNode = cloud.getNodeManager("mags").createNode();
-               sourceNode.setStringValue("title", "testmags");
-               sourceNode.commit();
-
-               Node destinationNode = 
cloud.getNodeManager("news").createNode();
-               destinationNode.setStringValue("title", "testnews");
-               destinationNode.commit();
-
-       }
-
        /**
         * deletes all relation nodes of type posrel between sourcenode and 
destinationnode
         * 


Index: AbstractActionTest.java
===================================================================
RCS file: 
/var/cvs/tests/vpro-wizards/org/mmbase/applications/vprowizards/spring/action/AbstractActionTest.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- AbstractActionTest.java     8 Sep 2008 15:59:04 -0000       1.1
+++ AbstractActionTest.java     22 Sep 2008 14:35:40 -0000      1.2
@@ -24,12 +24,14 @@
 import org.springframework.beans.factory.xml.XmlBeanFactory;
 import org.springframework.core.io.ClassPathResource;
 import org.springframework.mock.web.MockHttpServletRequest;
+import org.springframework.web.servlet.ModelAndView;
 
 public abstract class AbstractActionTest extends BridgeTest {
        
        private static final String DUMMY_LOCAL_URL = "www.disco.com/hallo";
        private static final Logger log = 
Logging.getLoggerInstance(AbstractActionTest.class);
        protected boolean setReferrer = true;
+       private MyCloudFactory myCloudFactory = new MyCloudFactory();
 
        public AbstractActionTest(String name) {
                super(name);
@@ -78,7 +80,7 @@
                BeanFactory f = new XmlBeanFactory(new ClassPathResource(
                                
"org/mmbase/applications/vprowizards/spring/resources/vpro-wizards-servlet.test.xml"));
                WizardController wizardController = (WizardController) 
f.getBean("wizardController");
-               wizardController.setCloudFactory(getCloudFactory());
+               wizardController.setCloudFactory(myCloudFactory);
                return wizardController;
        }
        
@@ -127,31 +129,55 @@
                return null;
        }
        
-       protected CloudFactory getCloudFactory(){
-               assertNotNull("can not create cloud factory, for cloud is 
null", getCloud());
-               MyCloudFactory myCloudFactory = new MyCloudFactory(getCloud());
-               return myCloudFactory;
-       }
        
-       static class MyCloudFactory implements CloudFactory{
+       /**
+        * 
+        * @param request
+        * @param globalErrorKey
+        * @return true when there is exactly one global error with matching 
key, and zero field errors, and the the request is redirected to the error page
+        * @throws Exception any exception that might occur.
+        */
+       protected void checkRequestCreatesGlobalError(HttpServletRequest 
request, String globalErrorKey) throws Exception{
+               WizardController wc = createWizardController();
 
-               private Cloud cloud;
+                       ModelAndView mandv = wc.handleRequest(request, null);
+                       Map<String,Object> model = (Map<String, Object>) 
mandv.getModel();
                
-               public MyCloudFactory(Cloud c){
-                       if(c == null){
-                               throw new NullPointerException("oops, cloud 
argument is null");
+                       assertEquals(0, getFieldErrors(model).size());
+                       assertEquals(1, getGlobalErrors(model).size());
+                       assertEquals(globalErrorKey, 
getGlobalErrors(model).get(0).getMessageKey());
+                       
+                       assertTrue("ModelAndView instance not of expected 
type", ModelAndView.class.isAssignableFrom(mandv.getClass()));
+                       //the error page is set in the xml bean configuration. 
check that first if below assertion fails.
+                       assertEquals( "error-html", mandv.getViewName());
                        }
-                       cloud = c;
+       
+       protected void checkNoErrors(ModelAndView mandv){
+               Map<String,Object> model = (Map<String, Object>) 
mandv.getModel();
+               assertEquals(0, getFieldErrors(model).size());
+               assertEquals(0, getFieldErrors(model).size());
                }
                
-               public Transaction getTransaction(HttpServletRequest request) {
-                       Transaction transaction = cloud.getTransaction("test 
transaction");
-                       if(transaction == null){
-                               throw new IllegalStateException("hey, 
transaction is null!");
+       
+       public final class MyCloudFactory implements CloudFactory{
+               public Transaction createTransaction(HttpServletRequest 
request) {
+                       return (Transaction) getTransaction();
                        }
-                       return transaction;
                }
                
+       public static class StaticCloudFactory implements CloudFactory{
+               private Transaction t;
+               
+               public StaticCloudFactory(Transaction t) {
+                       this.t = t;
+               }
+               public Transaction createTransaction(HttpServletRequest 
request) {
+                       log.debug(">> static cloud factory producing 
transaction: "+t);
+                       return t;
+               }
        }
        
+       
+               
+       
 }


Index: SortRelationActionTest.java
===================================================================
RCS file: 
/var/cvs/tests/vpro-wizards/org/mmbase/applications/vprowizards/spring/action/SortRelationActionTest.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- SortRelationActionTest.java 8 Sep 2008 15:59:04 -0000       1.1
+++ SortRelationActionTest.java 22 Sep 2008 14:35:40 -0000      1.2
@@ -5,58 +5,89 @@
 import javax.servlet.http.HttpServletRequest;
 
 import org.mmbase.applications.vprowizards.spring.WizardController;
+import org.mmbase.bridge.Cloud;
+import org.mmbase.bridge.Node;
 import org.mmbase.bridge.Relation;
 import org.mmbase.util.logging.Logger;
 import org.mmbase.util.logging.Logging;
 import org.springframework.web.servlet.ModelAndView;
 
-public class SortRelationActionTest extends AbstractRelationTest {
+public class SortRelationActionTest extends AbstractRelationActionTest {
        private static final Logger log = 
Logging.getLoggerInstance(SortRelationActionTest.class);
 
        @SuppressWarnings("unchecked")
-       public void test_sort_up() {
-               Relation r1 = createRelation(destinationNode, 0);
-               Relation r2 = createRelation(destinationNode2, 1);
-               assertEquals(0, r1.getIntValue("pos"));
-               assertEquals(1, r2.getIntValue("pos"));
-               
-               HttpServletRequest req = createRequest(
-                               
"actions[sortRelation][1].sourceNodeNumber="+sourceNode.getNumber()+
-                               
"&actions[sortRelation][1].destinationNodeNumber="+destinationNode2.getNumber()+
-                               "&actions[sortRelation][1].role=posrel"+
-                               "&actions[sortRelation][1].sortField=pos" +
-                               
"&actions[sortRelation][1].direction="+SortRelationAction.DIRECTION_UP);
+       private void test_sort(String direction, int r1Posvalue, int 
r2PosValue) {
+               Relation r1 = createRelation(destinationNode, r1Posvalue);
+               Relation r2 = createRelation(destinationNode2, r2PosValue);
+               int r1Number = r1.getNumber();
+               int r2Number = r2.getNumber();
+               assertEquals(r1Posvalue, r1.getIntValue("pos"));
+               assertEquals(r2PosValue, r2.getIntValue("pos"));
+
+               HttpServletRequest req = 
createRequest("actions[sortRelation][1].sourceNodeNumber=" + 
sourceNode.getNumber()
+                               + 
"&actions[sortRelation][1].destinationNodeNumber=" + 
destinationNode2.getNumber()
+                               + "&actions[sortRelation][1].role=posrel" + 
"&actions[sortRelation][1].sortField=pos"
+                               + "&actions[sortRelation][1].direction=" + 
direction);
+               // 
"&actions[sortRelation][1].direction="+SortRelationAction.DIRECTION_UP);
                WizardController wc = createWizardController();
                try {
                        ModelAndView mandv = wc.handleRequest(req, null);
-                       Map<String,Object> model = (Map<String, Object>) 
mandv.getModel();
+                       Map<String, Object> model = (Map<String, Object>) 
mandv.getModel();
                        assertNotNull("model is null!", model);
                        
-                       //no errors?
+                       // no errors?
                        assertEquals(0, getGlobalErrors(model).size());
                        assertEquals(0, getFieldErrors(model).size());
                        
-                       log.debug("new pos r1: "+r1.getIntValue("pos"));
-                       log.debug("new pos r2: "+r2.getIntValue("pos"));
-                       log.debug(String.format("r1 node number is %s and r2 
node number is %s", r1.getNumber(), r2.getNumber()));
+                       Cloud c = getCloud();
+
+                       int newr1posvalue = 
c.getNode(r1Number).getIntValue("pos");
+                       int newr2posvalue = 
c.getNode(r2Number).getIntValue("pos");
+
+                       log.debug("new pos r1: " + newr1posvalue);
+                       log.debug("new pos r2: " + newr2posvalue);
+                       log.debug(String.format("r1 node number is %s and r2 
node number is %s", c.getNode(r1Number).getNumber(), c
+                                       .getNode(r2Number).getNumber()));
+
+
+                               if (r1Posvalue != r2PosValue) {
+                                       if 
(direction.equals(SortRelationAction.DIRECTION_UP)) {
+                                               assertTrue("relation 1 should 
have a higher pos value that relation 2",
+                                                               newr1posvalue > 
newr2posvalue);
+                                       }
+                                       if 
(direction.equals(SortRelationAction.DIRECTION_DOWN)) {
+                                               assertTrue("relation 1 should 
have a higher pos value that relation 2",
+                                                               newr1posvalue < 
newr2posvalue);
+                                       }
+                               }else{
+                                       //we're testing the resorting
+                                       assertTrue("relation 1 should not have 
the same value as relation 2", newr1posvalue != newr2posvalue);
+                               }
+                       // delete the relations again.
+                       c.getNode(r1Number).delete(true);
+                       c.getNode(r2Number).delete(true);
                        
-                       //check the new pos fields. they should be switched
-                       assertTrue("relation 1 should have a higher pos value 
that relation 2", r1.getIntValue("pos") > r2.getIntValue("pos"));
                } catch (Exception e) {
                        e.printStackTrace();
                        fail(e.getMessage());
                }
        }
 
+       public void test_sort() {
+               test_sort(SortRelationAction.DIRECTION_UP, 0, 1);
+       }
+
        public void test_sort_down() {
-//             fail("implement");
+               test_sort(SortRelationAction.DIRECTION_DOWN, 0, 1);
        }
 
        public void test_sort_up_with_duplicate_sortfield_values() {
-//             fail("implement");
+               //when the list of relations to be sorted contain double 
values, 
+               //they are renumbered first.
+               //how this is done exactly i don't care, all i care about is 
that 
+               //they don't have the same value anymore
+                test_sort(SortRelationAction.DIRECTION_UP, 1, 1);
        }
 
-       public void test_sort_down_with_duplicate_sortfield_values() {
-//             fail("implement");
-       }
+
 }




_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs

Reply via email to