Obtain WebApplicationContext in Spring 3.1 Junit test -


due custom framework dependencies, cannot upgrade spring 3.2+. i'm stuck on 3.1.x. trying obtain webapplicationcontext in spring junit test so:

@runwith(springjunit4classrunner.class) @contextconfiguration(locations = "file:src/main/webapp/web-inf/spring/context.xml") public class webintegrationtest {      @autowired     private webapplicationcontext ctx; 

this, expected, not load webapplicationcontext.

i realize in spring 3.2 or later use @webappconfiguration tell spring want web context provided, how can achieve dependency constraints?

i stuck on 3.1, @ least until can enough testing around code upgrade - can't test enough until can working webapplicationcontext...

it isn't hard construct webapplicationcontext, whole morning of trial , error.

so, test like

@runwith(springjunit4classrunner.class) @contextconfiguration(loader = myloader.class,     locations =     {     "file:web-inf/springcontexts/spring-security-common.xml",     "file:web-inf/springcontexts/webapp-common.xml" }) public class loginintegrationtest { 

you can define

public class myloader implements contextloader {      @override     public string[] processlocations(class<?> clazz, string... locations) {         return locations;     }      @override     public applicationcontext loadcontext(string... locations) throws exception {         xmlwebapplicationcontext result = new xmlwebapplicationcontext();         mockservletcontext servletcontext = new mockservletcontext("target/webapp", new filesystemresourceloader());         result.setservletcontext(servletcontext);         result.setservletconfig(new mockservletconfig(servletcontext));         result.setconfiglocations(locations);         result.refresh();         return result;     } } 

you'll need change paths match own, or pass them around somehow.


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -