You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Angelo Chen <an...@yahoo.com.hk> on 2008/02/23 15:08:36 UTC

T5 PageTester and ApplicationGlobals

Hi,

I was trying to use PageTester, I got this problem:

the TestServiceImpl is a service injected in the test page, it will be
called from there, but the ApplicationGlobals in the service does not work
under PageTester,  works in a normal web app, maybe I have to mock an
ApplicationGlobals? then, how to do that? any idea? thanks.

A.C.

public class TestServiceImpl implements TestService {
    final private ApplicationGlobals globals;
    public TestServiceImpl(ApplicationGlobals globals) {
        this.globals = globals;
         String temp = globals.getServletContext().getServerInfo(); // this
line cause errors below
    }
    public void hello() {
        System.out.println("hello");
  	}
}

[ERROR] TestService Construction of service TestService failed: Error
invoking constructor org.bfe.istudio.t5.TestServiceImpl(ApplicationGlobals)
(at TestServiceImpl.java:14) (for service 'TestService'):
java.lang.NullPointerException
java.lang.RuntimeException: Error invoking constructor
org.sample.t5.TestServiceImpl(ApplicationGlobals) (at
TestServiceImpl.java:14) (for service 'TestService'):
java.lang.NullPointerException
	at
org.apache.tapestry.ioc.internal.ConstructorServiceCreator.createObject(ConstructorServiceCreator.java:62)
-- 
View this message in context: http://www.nabble.com/T5-PageTester-and-ApplicationGlobals-tp15652400p15652400.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


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


Re: T5 PageTester and ApplicationGlobals

Posted by Angelo Chen <an...@yahoo.com.hk>.
Hi Robert,

Nice tip, it works! and with that, i can use anonymous class to implement a
mock object, or can even use EasyMock to create one, good idea, thanks.

PageTester and Tapestry-Test seems overlapping each other, any guide lines
when to use PageTester and when to use Tapestry-Test?

A.C.


Robert Zeigler wrote:
> 
> You can use AliasOverrides for this purpose.
> 
> 

-- 
View this message in context: http://www.nabble.com/T5-PageTester-and-ApplicationGlobals-tp15652400p15673847.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


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


Re: T5 PageTester and ApplicationGlobals

Posted by Robert Zeigler <ro...@scazdl.org>.
You can use AliasOverrides for this purpose.

You have your normal service defined in your app module.

Then you have your "TestModule" (which can @SubModule your AppModule),  
and in your TestModule, you can:

contributeAliasOverrides(Configuration<AliasContribution> conf) {
   conf.add(AliasContribution.create(MyServiceInterface.class,new  
MyMockImplementation()));
}

Along those lines.
Works like a charm.

Robert

On Feb 23, 2008, at 2/238:04 PM , Angelo Chen wrote:

>
> Hi,
>
> it seems that ApplicationGlobals in the PageTester is like a 'mocked'
> object, not exactly the same as real one, so this does bring up a  
> question:
>
> while testing a page, we have to mock some services that the page  
> uses, what
> I'm doing now is, I'll comment out the service in the  
> AppModule.java, then
> pass a TestAppModule in the PageTester:
>
> PageTester tester = new PageTester(appPackage, appName, "src/main/ 
> webapp",
> TestAppModule.class);
>
> this works, but I have to update the AppModule.java after the test,  
> any idea
> how to do this in an easier way? or what is the better approach when  
> testing
> pages that need to use mock'ed services? Thanks,
>
> A.C.
>
>
>
> Angelo Chen wrote:
>>
>> Hi,
>>
>> I was trying to use PageTester, I got this problem:
>>
>>
>
> -- 
> View this message in context: http://www.nabble.com/T5-PageTester-and-ApplicationGlobals-tp15652400p15659919.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org


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


Re: T5 PageTester and ApplicationGlobals

Posted by Angelo Chen <an...@yahoo.com.hk>.
Hi,

it seems that ApplicationGlobals in the PageTester is like a 'mocked'
object, not exactly the same as real one, so this does bring up a question:

while testing a page, we have to mock some services that the page uses, what
I'm doing now is, I'll comment out the service in the AppModule.java, then
pass a TestAppModule in the PageTester:

PageTester tester = new PageTester(appPackage, appName, "src/main/webapp",
TestAppModule.class);

this works, but I have to update the AppModule.java after the test, any idea
how to do this in an easier way? or what is the better approach when testing
pages that need to use mock'ed services? Thanks,

A.C.



Angelo Chen wrote:
> 
> Hi,
> 
> I was trying to use PageTester, I got this problem:
> 
> 

-- 
View this message in context: http://www.nabble.com/T5-PageTester-and-ApplicationGlobals-tp15652400p15659919.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


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