mercredi 20 octobre 2010

Vive la révolution !

Grévistes de toutes professions, unissez-vous ! Faites tomber ce gouvernement de merde qui vous opprime depuis son élection. Pensez à 1789 ou 1968, la France est un peuple qui se révolte quand il est opprimé. Soyez dignes d'être français, sortez vos drapeaux et défendez la vraie démocratie, la liberté et l'égalité !!!

dimanche 6 juin 2010

Le vrai coût des trajets maison-travail-maison

Voici une petite étude sur le vrai coût des trajets maison-travail-maison.

Prenons l'exemple d'une personne qui doit effectuer tous les jours un parcours maison-travail-maison de 1h par trajet (1h pour l'aller et 1h pour le retour). Cette personne perdra donc 2h par jour dans ses trajets. Si l'on considère qu'une année de travail contient environ 225 jours, cela fait donc 450h par an, et 4500h sur 10 ans.

Si maintenant on compare ces heures avec les heures d'une personne qui n'a pas de trajet à faire, il faut prendre en compte certains critères. Les heures de trajet sont des heures réelles, sachant que dans une journée il y a en moyenne 16h réelles (24h - 8h dormies). De plus, comme je viens de l'indiquer précédemment, une année de travail contient environ 225 jours.

Donc, si l'on rapporte les 4500h perdues dans les trajets sur 10 ans, celà fait 4500 / 16 = ~280 jours = ~15 mois de travail. Cele signifie qu'une personne qui travaille 10 ans et qui a 1h de trajet matin et soir perd l'équivalent de 15 mois de temps travail dans ces trajets.

Ou bien dit encore d'une autre manière, si une personne travail depuis chez elle et a la possibilité de transformer le temps de trajet en temps de travail, alors elle n'aura besoin de travail que 8 ans et 9 mois au lieu de 10 ans. Ce qui n'est pas négligeable !

De plus, ici je ne prends pas en compte le coût financier et le stress générés par ces trajets.

À bon entendeur, salut !

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

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 Map parameters = 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 :

/**
 */
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 Map initParams = 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);
    }
}