You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by parranz <pa...@bilbomatica.es> on 2011/10/27 13:46:41 UTC
PageTester with an application that uses tynamo
Hi,
I'm trying to create Unit Tests for my application, i've begun with a very
simple example, only calling the index page:
PageTester tester = new PageTester(appPackage, appName,
"src/main/webapp", new Class<?>[] { AppModule.class});
Document doc = tester.renderPage("Index");
Element link = doc.getElementById("login");
But I become the next exception:
org.apache.tapestry5.internal.services.RenderQueueException
Render queue error in BeforeRenderBody[Index:layout.user]: No
SecurityManager accessible to the calling code, either bound to the
org.apache.shiro.util.ThreadContext or as a vm static singleton.
My Application uses tynamo for the authentication. I guess, I need to inject
it somehow, but I have no idea how can I do it. What should I do? Can
somenone help me? Is there any documentation or example somewhere?
Thanx very much!
--
View this message in context: http://tapestry.1045711.n5.nabble.com/PageTester-with-an-application-that-uses-tynamo-tp4942722p4942722.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: PageTester with an application that uses tynamo
Posted by Kalle Korhonen <ka...@gmail.com>.
The securityManager is bound to the executing thread. You'd need to
invoke (Tapestry's) request processing pipeline to get it bound, or
perhaps directly operate Tynamo's SecurityConfiguration directly to
bind it. Any solution likely involves some hacking.
Kalle
On Thu, Oct 27, 2011 at 4:46 AM, parranz <pa...@bilbomatica.es> wrote:
>
> Hi,
>
> I'm trying to create Unit Tests for my application, i've begun with a very
> simple example, only calling the index page:
>
>
> PageTester tester = new PageTester(appPackage, appName,
> "src/main/webapp", new Class<?>[] { AppModule.class});
>
> Document doc = tester.renderPage("Index");
> Element link = doc.getElementById("login");
>
> But I become the next exception:
>
> org.apache.tapestry5.internal.services.RenderQueueException
> Render queue error in BeforeRenderBody[Index:layout.user]: No
> SecurityManager accessible to the calling code, either bound to the
> org.apache.shiro.util.ThreadContext or as a vm static singleton.
>
> My Application uses tynamo for the authentication. I guess, I need to inject
> it somehow, but I have no idea how can I do it. What should I do? Can
> somenone help me? Is there any documentation or example somewhere?
>
> Thanx very much!
>
>
> --
> View this message in context: http://tapestry.1045711.n5.nabble.com/PageTester-with-an-application-that-uses-tynamo-tp4942722p4942722.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: PageTester with an application that uses tynamo
Posted by donarus <pa...@gmail.com>.
*Hi...* It is some time from my last visit, but now I have working example.
Thanks to the
http://shiro-user.582556.n2.nabble.com/Testing-with-Shiro-td5765075.html
Testing with Shiro @ nabble mailing list (user mbrictson)
package cz.donarus.checker.web;
import static org.mockito.Mockito.reset;
import static org.mockito.MockitoAnnotations.initMocks;
import org.apache.shiro.subject.Subject;
import org.apache.shiro.subject.support.SubjectThreadState;
import org.apache.shiro.util.ThreadState;
import org.apache.tapestry5.dom.Document;
import org.apache.tapestry5.test.PageTester;
import org.mockito.Mock;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
public abstract class PageTestCase<T> extends BaseTestCase {
@Mock
protected Subject subject;
private ThreadState threadState;
private PageTester pageTester;
@BeforeClass
public void beforeClass() {
initMocks(this);
threadState = new SubjectThreadState(subject);
threadState.bind();
pageTester = new PageTester("cz.donarus.checker.web", "App",
"src/main/webapp", TestHibernateModule.class);
}
@AfterClass
public void afterClass() {
threadState.clear();
}
@AfterTest
public void afterTest() {
reset(subject);
}
@Test
public void testRenderPageWhenNotAuthenticated() {
Document doc = pageTester.renderPage(getPageName());
String content = doc.toString();
ContentExpectation expectation = getNotAuthContentExpectation();
if (expectation.expected != null) {
for (String sencence : expectation.expected) {
assertContains(content, sencence);
}
}
if (expectation.notExpected != null) {
for (String sencence : expectation.notExpected) {
assertNotContains(content, sencence);
}
}
}
protected static final class ContentExpectation {
private final String[] notExpected;
private final String[] expected;
public ContentExpectation(String[] expected, String[] notExpected) {
this.expected = expected;
this.notExpected = notExpected;
}
}
protected abstract ContentExpectation getNotAuthContentExpectation();
private String getPageName() {
return getPageClass().getSimpleName();
}
protected abstract Class<T> getPageClass();
}
I know this is not perfect code, but better than wire2eye.
--
View this message in context: http://tapestry.1045711.n5.nabble.com/PageTester-with-an-application-that-uses-tynamo-tp4942722p5480370.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: PageTester with an application that uses tynamo
Posted by Robert Zeigler <ro...@roxanemy.com>.
1) Create your page tester instance: PageTester tester = new PageTester("packagename","Appname","contextpath");
2) get the registry from the page tester : tester.getRegistry();
3) Get the RequestGlobals service from the registry: RequestGlobals globals = registry.getService(RequestGlobals.class);
4) store your overrides: globals.storeServletRequestResponse(customRequest, customResponse);
You can use a mock framework (easymock, etc.) to make your life easier in overriding the services servlet request/response.
Cheers,
Robert
On Nov 25, 2011, at 11/258:10 AM , parranz wrote:
>
> Hi,
>
> sorry, I didn't. Eventually I gave up trying :(. If you do, don't forget
> to write it!
>
>
> El 25/11/2011 15:05, donarus [via Tapestry] escribió:
>> hi... Did you found any simple solution on this? I am totaly confused
>> and after 12 hours of searching a solution I'm not able to test any
>> page where user should be logged in.
>>
>>
>> The problem is, i think in TestableRequest/TestableResponse
>> implementation. It should be possible to change TR/TR to provide
>> httpServletResponse/Request, which can be accebted by
>> WebUtils.isHttp(...)
>>
>> But I don't se how to do it..
>>
>> ------------------------------------------------------------------------
>> If you reply to this email, your message will be added to the
>> discussion below:
>> http://tapestry.1045711.n5.nabble.com/PageTester-with-an-application-that-uses-tynamo-tp4942722p5022861.html
>>
>> To unsubscribe from PageTester with an application that uses tynamo,
>> click here
>> <http://tapestry.1045711.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=4942722&code=cGFycmFuekBiaWxib21hdGljYS5lc3w0OTQyNzIyfDIwMDMzMTU1MDk=>.
>> NAML
>> <http://tapestry.1045711.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.InstantMailNamespace&breadcrumbs=instant+emails%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>>
>>
>> No se encontraron virus en este mensaje.
>> Comprobado por AVG - www.avg.com <http://www.avg.com>
>> Versión: 2012.0.1873 / Base de datos de virus: 2101/4637 - Fecha de
>> publicación: 11/24/11
>>
>
>
>
> --
> View this message in context: http://tapestry.1045711.n5.nabble.com/PageTester-with-an-application-that-uses-tynamo-tp4942722p5022869.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: PageTester with an application that uses tynamo
Posted by parranz <pa...@bilbomatica.es>.
Hi,
sorry, I didn't. Eventually I gave up trying :(. If you do, don't forget
to write it!
El 25/11/2011 15:05, donarus [via Tapestry] escribió:
> hi... Did you found any simple solution on this? I am totaly confused
> and after 12 hours of searching a solution I'm not able to test any
> page where user should be logged in.
>
>
> The problem is, i think in TestableRequest/TestableResponse
> implementation. It should be possible to change TR/TR to provide
> httpServletResponse/Request, which can be accebted by
> WebUtils.isHttp(...)
>
> But I don't se how to do it..
>
> ------------------------------------------------------------------------
> If you reply to this email, your message will be added to the
> discussion below:
> http://tapestry.1045711.n5.nabble.com/PageTester-with-an-application-that-uses-tynamo-tp4942722p5022861.html
>
> To unsubscribe from PageTester with an application that uses tynamo,
> click here
> <http://tapestry.1045711.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=4942722&code=cGFycmFuekBiaWxib21hdGljYS5lc3w0OTQyNzIyfDIwMDMzMTU1MDk=>.
> NAML
> <http://tapestry.1045711.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.InstantMailNamespace&breadcrumbs=instant+emails%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>
>
> No se encontraron virus en este mensaje.
> Comprobado por AVG - www.avg.com <http://www.avg.com>
> Versión: 2012.0.1873 / Base de datos de virus: 2101/4637 - Fecha de
> publicación: 11/24/11
>
--
View this message in context: http://tapestry.1045711.n5.nabble.com/PageTester-with-an-application-that-uses-tynamo-tp4942722p5022869.html
Sent from the Tapestry - User mailing list archive at Nabble.com.
Re: PageTester with an application that uses tynamo
Posted by donarus <pa...@gmail.com>.
hi... Did you found any simple solution on this? I am totaly confused and
after 12 hours of searching a solution I'm not able to test any page where
user should be logged in.
The problem is, i think in TestableRequest/TestableResponse implementation.
It should be possible to change TR/TR to provide
httpServletResponse/Request, which can be accebted by WebUtils.isHttp(...)
But I don't se how to do it..
--
View this message in context: http://tapestry.1045711.n5.nabble.com/PageTester-with-an-application-that-uses-tynamo-tp4942722p5022861.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