Video :
samedi 17 avril 2010
samedi 27 mars 2010
Le Jeu de la Mort
Un film à voir absolument ! Il aborde le thème du pouvoir de la télévision, mais à mon avis, il démontre surtout comment notre système éducatif et politique actuel nous transforme en mouton (ou en nazi ensommeillé) !
magnet:?xt=urn:btih:UOMKT5JRYIZTANCKZAVXDQP2CINNJKVF
magnet:?xt=urn:btih:UOMKT5JRYIZTANCKZAVXDQP2CINNJKVF
mercredi 7 octobre 2009
Struts2 interceptor to remove empty parameters
Everything is in the title (or maybe I should say in the code). This simple interceptor removes empty parameters from the request so that, in the actions, the objects and objects properties will be kept at
null
in case of empty parameters. Put this interceptor before the "params" provided one.import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.ActionInvocation; import com.opensymphony.xwork2.interceptor.Interceptor; import java.util.ArrayList; import java.util.Collection; import java.util.Map; import org.apache.commons.lang.ArrayUtils; import org.apache.commons.lang.StringUtils; /** */ public class RemoveEmptyParametersInterceptor implements Interceptor { /** */ public RemoveEmptyParametersInterceptor() { super(); } /** * @see com.opensymphony.xwork2.interceptor.Interceptor#destroy() */ public void destroy() { // Nothing to do. } /** * @see com.opensymphony.xwork2.interceptor.Interceptor#init() */ public void init() { // Nothing to do. } /** * @see com.opensymphony.xwork2.interceptor.Interceptor#intercept(com.opensymphony.xwork2.ActionInvocation) */ public String intercept(final ActionInvocation invocation) throws Exception { final String result; final ActionContext actionContext = invocation.getInvocationContext(); final Mapparameters = actionContext.getParameters(); if (parameters == null) { // Nothing to do. } else { final Collection parametersToRemove = new ArrayList (); for (final Map.Entry entry : parameters.entrySet()) { final Object object = entry.getValue(); if (object instanceof String) { final String value = (String) object; if (StringUtils.isEmpty(value)) { parametersToRemove.add(entry.getKey()); } } else if (object instanceof String[]) { final String[] values = (String[]) object; final Object[] objects = ArrayUtils.removeElement(values, ""); if (objects.length == 0) { parametersToRemove.add(entry.getKey()); } } else { throw new IllegalArgumentException(); } } for (final String parameterToRemove : parametersToRemove) { parameters.remove(parameterToRemove); } } result = invocation.invoke(); return result; } }
lundi 28 septembre 2009
Unit testing Struts2 actions with Spring
For one of the projects on which I am working, I as looking for a solution to test the Struts2 actions while using the Spring plugin for Struts2.
There is a good article here "http://depressedprogrammer.wordpress.com/2007/06/18/unit-testing-struts-2-actions-spring-junit/", but this solution has one major problem, it tests the action alone, not the action inside the whole Struts2 request process.
So I extended the proposed solution to have a full solution to test the actions inside the Struts2 request process, including the interceptors stack, and here is the result :
There is a good article here "http://depressedprogrammer.wordpress.com/2007/06/18/unit-testing-struts-2-actions-spring-junit/", but this solution has one major problem, it tests the action alone, not the action inside the whole Struts2 request process.
So I extended the proposed solution to have a full solution to test the actions inside the Struts2 request process, including the interceptors stack, and here is the result :
/** */ public class AbstractActionTest extends TestCase { /** */ private final ActionProxyFactory actionProxyFactory; /** */ private MockHttpSession session; /** * @param configLocations */ public AbstractActionTest(final String configLocations) { final MockServletContext servletContext = new MockServletContext(); servletContext.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM, configLocations); final ContextLoader contextLoader = new ContextLoader(); contextLoader.initWebApplicationContext(servletContext); final MapinitParams = new Hashtable (); final Dispatcher dispatcher = new Dispatcher(servletContext, initParams); dispatcher.init(); Dispatcher.setInstance(dispatcher); final Container container = dispatcher.getContainer(); this.actionProxyFactory = container.getInstance(ActionProxyFactory.class); this.session = new MockHttpSession(); /* * When testing with mock services, reinitialize the data between each * test. */ // MockData.clear(); // MockData.load(); } /** * @param namespace * @param name * @param parameters * @return a string representing the logical result of the execution. * @throws Exception */ @SuppressWarnings("unchecked") protected String executeAction(final String namespace, final String name, final Map parameters) throws Exception { final ActionProxy actionProxy = this.actionProxyFactory.createActionProxy(namespace, name, null, null, true, false); final ActionInvocation actionInvocation = actionProxy.getInvocation(); final ActionContext actionContext = actionInvocation.getInvocationContext(); actionContext.setParameters(parameters); ActionContext.setContext(actionContext); final MockHttpServletRequest request = new MockHttpServletRequest(); request.setSession(this.session); final MockHttpServletResponse response = new MockHttpServletResponse(); ServletActionContext.setRequest(request); ServletActionContext.setResponse(response); final String result = actionProxy.execute(); // In case the session has been inactivated, we need to reassociate it. this.session = (MockHttpSession) request.getSession(true); return result; } /** * Find a value by evaluating the given expression against the stack in the * default search order. * * @param expr * @return the result of evaluating the expression */ protected Object findValueStackValue(final String expr) { final ActionContext actionContext = ActionContext.getContext(); final ValueStack valueStack = actionContext.getValueStack(); return valueStack.findValue(expr); } /** * Returns the object bound with the specified name in this session, or null * if no object is bound under the name. * * @param name * @return the object with the specified name */ protected Object getSessionValue(final String name) { return this.session.getAttribute(name); } /** * @param name * @param value */ protected void setSessionValue(final String name, final Object value) { this.session.setAttribute(name, value); } }
lundi 29 juin 2009
jeudi 25 juin 2009
jeudi 18 juin 2009
Inscription à :
Articles (Atom)