Archive pour January 2008

Junit et JMock - HttpServletRequest

Thursday 31 January 2008

Voici un test unitaire Junit avec exemple de HttpServletRequest Mocké avec les méthodes getParameter et getParameterNames
public class ParametersUtilTest extends MockObjectTestCase {

private HttpServletRequest mRequest;

protected void setUp() throws Exception {

//initialisation de HttpServletRequest
Mock mock = new Mock(HttpServletRequest.class);

mock.expects(atLeastOnce()).method(”getParameter”).with(eq(Constantes.PARAM1))
.will(returnValue(”monParam1″));
mock.expects(atLeastOnce()).method(”getParameter”).with(eq(Constantes.PARAM2))
.will(returnValue(”monParam2″));

List parameters = new ArrayList();
parameters.add(Constantes.PARAM1);
parameters.add(Constantes.PARAM2);

Enumeration enumeration = Collections.enumeration(parameters);
mock.expects(atLeastOnce()).method(”getParameterNames”).will(returnValue(enumeration));

mRequest = (HttpServletRequest)mock.proxy();

}

public void testAddParameters() throws Exception {

mLogger.info(”DEB ********** testAddParameters **********”);

assertNotNull(mRequest.getParameter(Constantes.PARAM1));

//test construction parametres
assertEquals(ParametersUtil.addParameters(mRequest).toString(), “param1=monParam1&param2=monParam2″);

mLogger.info(”FIN ********** testAddParameters **********”);
}

}


WordPress database error: [Table 'foubert.wp_ss_stats' doesn't exist]
INSERT INTO wp_ss_stats (remote_ip,country,language,domain,referer,resource,user_agent,platform,browser,version,dt) VALUES ('54.156.37.123','Indeterminable','empty','','','/wordpress/?m=200801','CCBot/2.0 (http://commoncrawl.org/faq/)','Indeterminable','Crawler/Search Engine','Indeterminable',1502976382)