a stupid question but i have to ask public class TypeConversionAction extends ActionSupport { private Map<Entity, String> simpleMap; //where is the initialisation of simpleMap e.g. simpleMap=new java.util.HashMap(); public Map<Entity, String> getSimpleMap() { return simpleMap; } public void setSimpleMap(Map<Entity, String> simpleMap) { this.simpleMap = simpleMap; } public String execute() { return SUCCESS; } }
//then the test-harness: package test.example; import java.util.Map; import org.apache.struts2.StrutsTestCase; import org.junit.Test; import com.opensymphony.xwork2.ActionProxy; import com.opensymphony.xwork2.ActionSupport; public class TypeConversionTest extends StrutsTestCase { private ActionProxy actionProxy; private ActionSupport action; @Test public void test() throws Exception{ Entity entity = new Entity(); entity.setId(1); super.setUp(); request.setParameter("simpleMap[1]", "value"); createAction("/example/Convesion.action"); executeProxy(); Map<Entity, String> complexMap = ((TypeConversionAction) action).getSimpleMap(); assertNotNull(complexMap); //getSimpleMap is NULL in the Action so it would always be NULL here assertFalse(complexMap.isEmpty()); //FAIL it is empty assertEquals("value", complexMap.get(entity)); //Never initialised so this would fail as well } /** * Creates the action with the given actionPath if it wasn't already created * @see isAlreadyCreated * @param actionPath * @throws Exception */ public ActionSupport createAction(String actionPath) throws Exception { actionProxy = getActionProxy(actionPath); action = (ActionSupport) actionProxy.getAction(); return action; } /** * Executes the action created and returns the result * @return * @throws Exception */ public String executeProxy() throws Exception { actionProxy.setExecuteResult(false); return actionProxy.execute(); } } ? Saludos, Martin ______________________________________________ Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen. Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité pour le contenu fourni. Subject: Re: Type conversion on a Map From: mig...@almeida.at To: user@struts.apache.org Date: Fri, 21 Sep 2012 10:31:24 +0100 Sure! Here's a maven project with a failing test case. There's actually a map being built, but it's a <String,String>, and the key reads "OGNL no conversion possible". Cheers, Miguel Almeida On Thu, 2012-09-20 at 19:44 +0200, Lukasz Lenart wrote: Hi, Could you share the unit test as well ? The whole code would be the best :-) Regards --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org