java - Not able to get data from request in Junit when action class implements ParameterAware -


i need write junit struts 2 action class.but action class implementing "parameteraware" interceptor takes parameter map in hashmap , action class takes request parameter hashmap

action class:

public class brokeraction extends actionsupport implements servletrequestaware, servletresponseaware,sessionaware,         parameteraware {      /** parameters. */     private map parameters;      @override     public void setparameters(final map param) {         this.parameters = param;     }     public string getparametervalue(final string param) {         final object varr = getparameters().get(param);         if (varr == null) {             return null;             }         return ((string[]) varr)[0];     }     public string getbrokerdetails()throws pactexception{         string id = getparametervalue("id");    } 

when putting data junit in request hasn't reflected in parameters map

junit:

@test      public void testgetactionproxy() throws exception {           request.setattribute("id", "23");          actionproxy proxy   =  getactionproxy("/getbrokerdetails");          brokeraction brokeraction = (brokeraction) proxy.getaction();          brokeraction.getbrokerdetails();     } 

please how request data reflected in parameters map

unit tests should simple - instead of setting attributes on request , using actionproxy, why not call setparameters set parameters? if unit test calling out code isn't in class testing, becomes more complex , prone failure reasons not related code.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -