You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by donarus <pa...@gmail.com> on 2011/11/25 15:05:46 UTC

Re: PageTester with an application that uses tynamo

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


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.