jakarta-cactus-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Erik Hatcher <li...@ehatchersolutions.com>
Subject StrutsTestCase / Struts 1.1b2 / Cactus - ConcurrentModificationException
Date Fri, 13 Sep 2002 23:15:23 GMT
Deryl or others that may have encountered this....

I'm using Struts 1.1b2 and StrutsTestCase 1.1 for Servlet 2.3 spec.

Trying to run a second test case I'm getting whats immediately below. 
Any ideas on what is going wrong?  I'm fairly certain its not my test 
case code or base test case additions to StrutsTestCase, but perhaps 
some nasty interaction with StrutsTestCase and Struts?


15:27:09,353 ERROR [STDERR] java.util.ConcurrentModificationException
15:27:09,363 ERROR [STDERR]     at
java.util.HashMap$HashIterator.next(HashMap.j
ava:731)
15:27:09,363 ERROR [STDERR]     at
org.apache.catalina.util.Enumerator.nextEleme
nt(Enumerator.java:166)
15:27:09,373 ERROR [STDERR]     at
servletunit.struts.CactusStrutsTestCase.getAc
tionServlet(CactusStrutsTestCase.java:285)
15:27:09,373 ERROR [STDERR]     at
servletunit.struts.CactusStrutsTestCase.actio
nPerform(CactusStrutsTestCase.java:349)
15:27:09,383 ERROR [STDERR]     at
edu.darden.alumni.contactinfo.ContactInfoTest
.testSaveContactInfo(ContactInfoTest.java:17)
15:27:09,393 ERROR [STDERR]     at
java.lang.reflect.Method.invoke(Native Method
)
15:27:09,403 ERROR [STDERR]     at
org.apache.cactus.AbstractTestCase.runServerT
est(AbstractTestCase.java:332)

My test case looks like this:

public class ContactInfoTest extends StrutsFormTestCase {
     public void beginSaveContactInfo(WebRequest theRequest) {
         theRequest.setAuthentication(
                 new BasicAuthentication("alumni", "alumni"));
     }
     public void testSaveContactInfo() throws Exception {
         setRequestPathInfo("/alumni/updateContactInfo");
         ContactInfoForm form = new ContactInfoForm();
         form.reset();  // my ValidatorForm subclass forces this method
to exist
         addToParameters(form);
         actionPerform();
         verifyForward("success");
     }

     public ContactInfoTest(String s) {
         super(s);
     }
}


And my base test case is below.  This could be considered a donation to 
the StrutsTestCase project, actually, although it needs to be 
generalized a bit more.  It adds the ability to just set up a form bean 
rather than HTTP request parameters (and convert a bean to request 
parameters under the covers).  One note: I have a BaseForm that all my 
Struts forms extend from and I've hidden the original method (made it 
final) and proxy that to the reset() method that all our forms are 
required to implement (I've yet to need the request or mapping in a 
reset method, so I took it away from implementers for now).



package edu.darden.alumni.cactus;

import servletunit.struts.CactusStrutsTestCase;

import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.util.HashMap;
import java.util.Iterator;
import java.lang.reflect.InvocationTargetException;

import org.apache.commons.beanutils.PropertyUtils;
import org.apache.struts.action.ActionForm;

abstract public class StrutsFormTestCase extends CactusStrutsTestCase {
     private static final List invisibleFields = new ArrayList();
     private static final List basicFields = new ArrayList();

     static {
         invisibleFields.add("multipartRequestHandler");
         invisibleFields.add("resultValueMap");
         invisibleFields.add("class");
         invisibleFields.add("validatorResults");
         invisibleFields.add("servletWrapper");

         basicFields.add("java.lang.Integer");
         basicFields.add("java.lang.String");
         basicFields.add("java.lang.Boolean");
     }

     private final Map getBeanMap(Object bean, String prefix) throws
IllegalAccessException, InvocationTargetException, NoSuchMethodException
{
         String thisPrefix = prefix == null ? "" : prefix + ".";
         Map map = new HashMap();
         Map flatFields = PropertyUtils.describe(bean);
         Iterator iterator = flatFields.keySet().iterator();
         while (iterator.hasNext()) {
             String key = (String) iterator.next();
             if (invisibleFields.contains(key)) {
                 continue;
             }

             Object value = flatFields.get(key);

             if ((value != null) && !
basicFields.contains(value.getClass().getName())) {
                 map.putAll(getBeanMap(value, thisPrefix + key));
             }
             else {
                 map.put(thisPrefix + key, value);
             }
         }
         return map;
     }

     /**
      * @todo Add checks for boolean/Boolean and set to "on" or omit if
false
      */
     private final void addToParameters(Map map) {
         Iterator iterator = map.keySet().iterator();
         while (iterator.hasNext()) {
             String key = (String) iterator.next();
             Object value = map.get(key);
             String paramValue = "";
             if (value != null) {
                 paramValue = value.toString();
             }
             System.out.println("key = " + key + " value = " +
paramValue);
             addRequestParameter(key, paramValue);
         }
     }

     protected final void addToParameters(ActionForm form) throws
Exception {
         addToParameters(getBeanMap(form, null));
     }

     public StrutsFormTestCase(String name) {
         super(name);
     }
}





--
To unsubscribe, e-mail:   <mailto:cactus-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:cactus-user-help@jakarta.apache.org>


Mime
View raw message