3 Replies Latest reply: Mar 1, 2010 11:04 AM by Daniel Lechner RSS

Seam doesn't inject members with ScopeType page

Daniel Lechner Novice

Hello!

 

We're using JSFUnit here to test our application from the backing-beans downwards. So we don't care about the HTML pages - we want to call the backing-bean methods directly from the JSFUnit-test-classes.

So first we create a session by creating a new JSFSession with some URL (this is the only line which "depends" on the UI). Everything else is done without WebUI (and thus without HttpUnit).

 

Many tests are already running, but now I came to a point where I don't know what to do. I've created a little example with 3 classes to show whats the problem:

 

@Name("bean1")
@Scope(ScopeType.PAGE)
public class Bean1
{
    private String myString = "1234";
   
    public String getString() { return myString; }
}


@Name("bean2")
@Scope(ScopeType.EVENT)
public class Bean2
{
    @In(create = true)
    private Bean1 bean1;
   
    public void someMethod() {
        System.out.println("bean returns " + bean1.getString());
    }
}


public class SomeTest extends ServletTestCase
{
    public void test1() throws IOException {
        WebClientSpec wcSpec = new WebClientSpec("/evaluations.seam");
        wcSpec.getWebClient().setCssErrorHandler(new SilentCssErrorHandler());
        // Send an HTTP request for the initial page
        JSFSession jsfSession = new JSFSession(wcSpec);

 

        Bean2 bean2 = (Bean2) Component.getInstance("bean2", true);
        bean2.someMethod();
    }
}

 

When executing the test, seam throws an exception:

org.jboss.seam.RequiredException: @In attribute requires non-null value: bean2.bean1

 

But this only happens when the ScopeType of Bean1 is PAGE. When using finer or more coarse types like EVENT or CONVERSATION, everything is fine and there is no exception.

 

So is there anything I am missing?

 

Thanks!

 

Daniel