vendredi 25 septembre 2015

Testing the Execution order of handlers injected by Spring Framework

I'm using Spring Framework to inject several dependency into my code, and one of the beans look like this

<bean id="handlerChain" class="com.abc.ChainHelper">
    <property name="handlers">
        <list>
            <bean class="com.abc.AuthenticationHandler" />
            <bean class="com.abc.Handler1" />
            <ref bean="Handler2" />
        </list>
    </property>
</bean>

ChainHelper takes the list of handlers and executes the process for every handler in the order given. I have a unit test in ChainHelper to ensure that ChainHelper processes every handler in the order given. However, in the current project I'm working on, Handler1 should only be processed when AuthenticationHandler finishes authenticating a job.

AuthenticationHandler look something like this

public class AuthenticationHandler extends AbstractHandler {
    //variable declarations and constructor

    @Override
    public void process(Job job) throws Throwable {
        //some code to verify the identity of the job
        job.isVerified = verificationResult;
    }

    //some helper methods
}

and Handler1 look something like this

public class Handler1 extends AbstractHandler {
    //variable declarations and constructor

    @Override
    public void process(Job job) throws Throwable {
        if (job.isVerified) {
            //do verified job stuff
        } else {
            //do unverified job stuff
        }
    }

    //some helper methods
}

So I want to write a test to enforce that no one accidentally change the order in the list and break everything.

This seems too big for a unit test, since I'm testing the order of execution of multiple handlers and not an individual piece of code. However, I don't feel like it is big enough for a integration test. The reason is that the way I understood integration test is that it tests a specific request with valid and invalid input, and make sure we are getting the correct result based on the input, and this dependency is injected on every types of request, so it doesn't quite fit the integration tests.

So my question is how should I go about testing the execution order of this particular injection?

Aucun commentaire:

Enregistrer un commentaire