Jonathan Barker wrote
> 
> It just occurred to me that these errors are during the running of
> tests.  Suffice it to say I've had challenges getting tests working
> with Spring, while getting an application running has been easy.
> 
> If you don't run your tests, what do you get?  Can you get a runnable
> application - minus tests?  It looks like, as Thiago suggests, that
> you don't have the bean defined, and it may be that you don't have
> Spring wired in properly for *testing*.
> 

You're correct Jonathan, it works fine when I run "mvn jetty:run", but not
when testing. Here's my base class for wiring in Spring for testing:

@ContextConfiguration(locations = {
        "classpath:/applicationContext-resources.xml",
"classpath:/applicationContext-dao.xml",
        "classpath:/applicationContext-service.xml",
"classpath*:/applicationContext.xml",
        "/WEB-INF/applicationContext*.xml"})
public abstract class BasePageTestCase extends
AbstractTransactionalJUnit4SpringContextTests {
    protected PageTester tester;
    protected Document doc;
    protected Map<String, String> fieldValues;
    protected final Log log = LogFactory.getLog(getClass());
    protected static final String MESSAGES = Constants.BUNDLE_KEY;
    private int smtpPort = 25250;

    @Before
    public void onSetUp() {
        String appPackage = "com.company.webapp";
        String appName = "app";

        final MockServletContext servletContext = new MockServletContext();
        ConfigurableWebApplicationContext wac = new
StaticWebApplicationContext();
        // Just setting the parent doesn't seem to work
        // wac.setParent(applicationContext);
        // Workaround below...
        for (String defName : applicationContext.getBeanDefinitionNames()) {
            wac.getBeanFactory().registerSingleton(defName,
applicationContext.getBean(defName));
        }

       
servletContext.addInitParameter(SpringConstants.USE_EXTERNAL_SPRING_CONTEXT,
"true");
       
servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE,
wac);
        tester = new PageTester(appPackage, appName, "src/main/webapp",
AppTestModule.class) {

            @Override
            protected ModuleDef[] provideExtraModuleDefs() {
                return new ModuleDef[]{new SpringModuleDef(servletContext)};
            }
        };

Please let me know if there's a better way to do this.

AppTestModule.java is as follows:


/**
 * AppFuse Test module.
 *
 * @author Serge Eby
 */
@SubModule(AppModule.class)
public class AppTestModule {

    /**
     * Use to allow PageTester to run with spring and spring-security.
     *
     * @param config
     * @param requestGlobals
     */
    public static void
contributeRequestHandler(OrderedConfiguration<RequestFilter> config,
                                                final RequestGlobals
requestGlobals) {
        RequestFilter filter = new RequestFilter() {
            public boolean service(Request request, Response response,
RequestHandler handler)
                    throws IOException {
                requestGlobals.storeServletRequestResponse(
                        new MockHttpServletRequest(),
                        new MockHttpServletResponse());

                return handler.service(request, response);
            }
        };
        config.add("SpringMockHttpRequestAndResponse", filter, "before:*");
    }

}

Thanks,

Matt

--
View this message in context: 
http://tapestry.1045711.n5.nabble.com/Tapestry-5-3-3-Spring-3-1-and-Inject-tp5711099p5711576.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org

Reply via email to