You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by yka <in...@jcoder.de> on 2013/03/03 19:43:14 UTC

Wicket Tester with BookmarkablePageLink

Hi all,

are there any known problems with testing BookmarkablePageLinks?
Im trying to click a BookmarkablePageLink from my start page and receive the
following trace. I dont understand why he cant use the public constructor.
I've wrote the default constructor...


org.apache.wicket.WicketRuntimeException: Internal error in WicketTester.
Please report this in Wicket's Issue Tracker.
	at
org.apache.wicket.util.tester.BaseWicketTester.clickLink(BaseWicketTester.java:1879)
	at
org.apache.wicket.util.tester.BaseWicketTester.clickLink(BaseWicketTester.java:1760)
	at
com.customer.web.AbstractBasePageTester.homepageRendersSuccessfully(AbstractBasePageTester.java:70)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
	at
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
	at
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at
org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
	at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
	at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
	at
org.mockito.internal.runners.JUnit45AndHigherRunnerImpl.run(JUnit45AndHigherRunnerImpl.java:37)
	at org.mockito.runners.MockitoJUnitRunner.run(MockitoJUnitRunner.java:62)
	at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
	at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: org.apache.wicket.WicketRuntimeException: Can't instantiate page
using constructor 'public com.customer.CreateCustomer()'. Might be it
doesn't exist, may be it is not visible (public).
	at
org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:193)
	at
org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:66)
	at
org.apache.wicket.DefaultMapperContext.newPageInstance(DefaultMapperContext.java:133)
	at
org.apache.wicket.core.request.handler.PageProvider.resolvePageInstance(PageProvider.java:278)
	at
org.apache.wicket.core.request.handler.PageProvider.getPageInstance(PageProvider.java:166)
	at
org.apache.wicket.util.tester.BaseWicketTester$LastPageRecordingPageRendererProvider.get(BaseWicketTester.java:2628)
	at
org.apache.wicket.util.tester.BaseWicketTester$LastPageRecordingPageRendererProvider.get(BaseWicketTester.java:2614)
	at
org.apache.wicket.core.request.handler.RenderPageRequestHandler.respond(RenderPageRequestHandler.java:164)
	at
org.apache.wicket.request.cycle.RequestCycle$HandlerExecutor.respond(RequestCycle.java:840)
	at
org.apache.wicket.request.RequestHandlerStack.execute(RequestHandlerStack.java:64)
	at
org.apache.wicket.request.cycle.RequestCycle.execute(RequestCycle.java:254)
	at
org.apache.wicket.request.cycle.RequestCycle.processRequest(RequestCycle.java:211)
	at
org.apache.wicket.request.cycle.RequestCycle.processRequestAndDetach(RequestCycle.java:282)
	at
org.apache.wicket.util.tester.BaseWicketTester.processRequest(BaseWicketTester.java:643)
	at
org.apache.wicket.util.tester.BaseWicketTester.processRequest(BaseWicketTester.java:572)
	at
org.apache.wicket.util.tester.BaseWicketTester.processRequest(BaseWicketTester.java:544)
	at
org.apache.wicket.util.tester.BaseWicketTester.startPage(BaseWicketTester.java:1186)
	at
org.apache.wicket.util.tester.BaseWicketTester.clickLink(BaseWicketTester.java:1875)
	... 28 more
Caused by: java.lang.reflect.InvocationTargetException
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
	at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
	at
org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:174)
	... 45 more
Caused by: java.lang.IllegalStateException: BeanFactory not initialized or
already closed - call 'refresh' before accessing beans via the
ApplicationContext
	at
org.springframework.context.support.AbstractRefreshableApplicationContext.getBeanFactory(AbstractRefreshableApplicationContext.java:172)
	at
org.springframework.context.support.AbstractApplicationContext.getBeanNamesForType(AbstractApplicationContext.java:1174)
	at
org.springframework.beans.factory.BeanFactoryUtils.beanNamesForTypeIncludingAncestors(BeanFactoryUtils.java:144)
	at
org.apache.wicket.spring.injection.annot.AnnotProxyFieldValueFactory.getBeanNameOfClass(AnnotProxyFieldValueFactory.java:211)
	at
org.apache.wicket.spring.injection.annot.AnnotProxyFieldValueFactory.getBeanName(AnnotProxyFieldValueFactory.java:179)
	at
org.apache.wicket.spring.injection.annot.AnnotProxyFieldValueFactory.getFieldValue(AnnotProxyFieldValueFactory.java:113)
	at org.apache.wicket.injection.Injector.inject(Injector.java:111)
	at
org.apache.wicket.spring.injection.annot.SpringComponentInjector.inject(SpringComponentInjector.java:127)
	at
org.apache.wicket.spring.injection.annot.SpringComponentInjector.onInstantiation(SpringComponentInjector.java:133)
	at
org.apache.wicket.application.ComponentInstantiationListenerCollection$1.notify(ComponentInstantiationListenerCollection.java:38)
	at
org.apache.wicket.application.ComponentInstantiationListenerCollection$1.notify(ComponentInstantiationListenerCollection.java:34)
	at
org.apache.wicket.util.listener.ListenerCollection.notify(ListenerCollection.java:80)
	at
org.apache.wicket.application.ComponentInstantiationListenerCollection.onInstantiation(ComponentInstantiationListenerCollection.java:33)
	at org.apache.wicket.Component.<init>(Component.java:683)
	at org.apache.wicket.MarkupContainer.<init>(MarkupContainer.java:120)
	at org.apache.wicket.Page.<init>(Page.java:172)
	at org.apache.wicket.Page.<init>(Page.java:136)
	at org.apache.wicket.markup.html.WebPage.<init>(WebPage.java:76)
	at com.index.Start.<init>(Start.java:12)
	at com.customer.CreateCustomer.<init>(CreateCustomer.java:24)
	... 50 more




--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Wicket-Tester-with-BookmarkablePageLink-tp4656921.html
Sent from the Users forum mailing list archive at Nabble.com.

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


Re: Wicket Tester with BookmarkablePageLink

Posted by yka <in...@jcoder.de>.
Thanks mate. Works fine now :)



--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Wicket-Tester-with-BookmarkablePageLink-tp4656921p4657091.html
Sent from the Users forum mailing list archive at Nabble.com.

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


Re: Wicket Tester with BookmarkablePageLink

Posted by vineet semwal <vi...@gmail.com>.
i meant something like this ..
  @Before
    public void setUp()
    {
        MockitoAnnotations.initMocks(this);
        tester = new WicketTester(createApplication());
        ApplicationContextMock appctx = new ApplicationContextMock();
        appctx.putBean(customerService);
        SpringComponentInjector componentInjector = new
SpringComponentInjector(tester.getApplication(), appctx, false);

tester.getApplication().getComponentInstantiationListeners().add(componentInjector);
    }
    private static WebApplication createApplication(){
        return new MockApplication(){
            @Override
            public Session newSession(Request request, Response response) {
                return new CustomSession(request); // if you have extended
session in your application
            }
        };
    }

 @Test
        public void homepageRendersSuccessfully() {
      //your test..
}


On Thu, Mar 7, 2013 at 1:21 AM, yka <in...@jcoder.de> wrote:

> Hi Vineet,
> tried it out. My setup() method now looks like this:
>
>         @Before
>         public void setUp() {
>                 MockitoAnnotations.initMocks(this);
>                 app = new StartApplication() {
>                         @Override
>                         public ServletContext getServletContext() {
>                                 ServletContext servletContext =
> super.getServletContext();
>                                 ApplicationContextMock appctx = new
> ApplicationContextMock();
>                                 Service service =
> Mockito.mock(Service.class);
>                                 appctx.putBean(service);
>                                 WebApplication application = new
> MockApplication();
>                                 WicketTester tester = new
> WicketTester(application);
>                                 SpringComponentInjector componentInjector
> = new SpringComponentInjector(
>                                                 tester.getApplication(),
> appctx, false);
>
>
> tester.getApplication().getComponentInstantiationListeners()
>                                                 .add(componentInjector);
>
>                                 return servletContext;
>                         }
>                 };
>
>                 org.apache.log4j.Logger logger = org.apache.log4j.Logger
>
> .getLogger("org.apache.wicket.util.tester");
>                 logger.setLevel(Level.DEBUG);
>
>                 tester = new WicketTester(app);
>         }
>
>
> But when I run the test, I get:
>
> java.lang.IllegalStateException: No WebApplicationContext found: no
> ContextLoaderListener registered?
>         at
>
> org.springframework.web.context.support.WebApplicationContextUtils.getRequiredWebApplicationContext(WebApplicationContextUtils.java:90)
>         at
>
> org.apache.wicket.spring.injection.annot.SpringComponentInjector.<init>(SpringComponentInjector.java:81)
>         at com.index.StartApplication.init(StartApplication.java:16)
>         at
> org.apache.wicket.Application.initApplication(Application.java:818)
>         at
>
> org.apache.wicket.util.tester.BaseWicketTester.<init>(BaseWicketTester.java:287)
>         at
>
> org.apache.wicket.util.tester.BaseWicketTester.<init>(BaseWicketTester.java:231)
>         at
> org.apache.wicket.util.tester.WicketTester.<init>(WicketTester.java:184)
>         at
>
> com.customer.web.AbstractBasePageTester.setUp(AbstractBasePageTester.java:71)
>         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>         at
>
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>         at
>
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>         at java.lang.reflect.Method.invoke(Method.java:597)
>         at
>
> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
>         at
>
> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
>         at
>
> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
>         at
>
> org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
>         at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
>         at
>
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
>         at
>
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
>         at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
>         at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
>         at
> org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
>         at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
>         at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
>         at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
>         at
>
> org.mockito.internal.runners.JUnit45AndHigherRunnerImpl.run(JUnit45AndHigherRunnerImpl.java:37)
>         at
> org.mockito.runners.MockitoJUnitRunner.run(MockitoJUnitRunner.java:62)
>         at
>
> org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
>         at
>
> org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
>         at
>
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
>         at
>
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
>         at
>
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
>         at
>
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
>
>
>
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/Wicket-Tester-with-BookmarkablePageLink-tp4656921p4657053.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>


-- 
regards,

Vineet Semwal

Re: Wicket Tester with BookmarkablePageLink

Posted by yka <in...@jcoder.de>.
Hi Vineet,
tried it out. My setup() method now looks like this:

	@Before
	public void setUp() {
		MockitoAnnotations.initMocks(this);
		app = new StartApplication() {
			@Override
			public ServletContext getServletContext() {
				ServletContext servletContext = super.getServletContext();
				ApplicationContextMock appctx = new ApplicationContextMock();
				Service service = Mockito.mock(Service.class);
				appctx.putBean(service);
				WebApplication application = new MockApplication();
				WicketTester tester = new WicketTester(application);
				SpringComponentInjector componentInjector = new SpringComponentInjector(
						tester.getApplication(), appctx, false);

				tester.getApplication().getComponentInstantiationListeners()
						.add(componentInjector);

				return servletContext;
			}
		};

		org.apache.log4j.Logger logger = org.apache.log4j.Logger
				.getLogger("org.apache.wicket.util.tester");
		logger.setLevel(Level.DEBUG);

		tester = new WicketTester(app);
	}


But when I run the test, I get:

java.lang.IllegalStateException: No WebApplicationContext found: no
ContextLoaderListener registered?
	at
org.springframework.web.context.support.WebApplicationContextUtils.getRequiredWebApplicationContext(WebApplicationContextUtils.java:90)
	at
org.apache.wicket.spring.injection.annot.SpringComponentInjector.<init>(SpringComponentInjector.java:81)
	at com.index.StartApplication.init(StartApplication.java:16)
	at org.apache.wicket.Application.initApplication(Application.java:818)
	at
org.apache.wicket.util.tester.BaseWicketTester.<init>(BaseWicketTester.java:287)
	at
org.apache.wicket.util.tester.BaseWicketTester.<init>(BaseWicketTester.java:231)
	at org.apache.wicket.util.tester.WicketTester.<init>(WicketTester.java:184)
	at
com.customer.web.AbstractBasePageTester.setUp(AbstractBasePageTester.java:71)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
	at
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
	at
org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
	at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
	at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
	at
org.mockito.internal.runners.JUnit45AndHigherRunnerImpl.run(JUnit45AndHigherRunnerImpl.java:37)
	at org.mockito.runners.MockitoJUnitRunner.run(MockitoJUnitRunner.java:62)
	at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
	at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)




--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Wicket-Tester-with-BookmarkablePageLink-tp4656921p4657053.html
Sent from the Users forum mailing list archive at Nabble.com.

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


Re: Wicket Tester with BookmarkablePageLink

Posted by vineet semwal <vi...@gmail.com>.
aha forgot to paste that ,that createApplication() is just returning new
MockApplication()


On Tue, Mar 5, 2013 at 1:41 AM, vineet semwal <vi...@gmail.com>wrote:

> i was expecting that..,, you don't have to create real applicationcontext,
> just use ApplicationContextMock,below is the sample of how you should set
> up your test,if you don't understand anything,feel free to ask..
> ApplicationContextMock  appctx = new ApplicationContextMock();
>        Service service=Mockito.mock(Service.class);
>        appctx.putBean(service);
>        WebApplication application=createApplication();
>         WicketTester tester = new WicketTester(application);
>         SpringComponentInjector componentInjector = new
> SpringComponentInjector(tester.getApplication(), appctx, false);
>
> tester.getApplication().getComponentInstantiationListeners().add(componentInjector);
>
>
>
> On Tue, Mar 5, 2013 at 12:47 AM, yka <in...@jcoder.de> wrote:
>
>> Sure, this is the test code:
>>
>> public class AbstractBasePageTester {
>>         private WicketTester tester;
>>
>>         private StartApplication app;
>>
>>         @Mock
>>         private CustomerService aService;
>>
>>         @Before
>>         public void setUp() {
>>                 MockitoAnnotations.initMocks(this);
>>                 app = new StartApplication() {
>>                         @Override
>>                         public ServletContext getServletContext() {
>>                                 ServletContext servletContext =
>> super.getServletContext();
>>                                 XmlWebApplicationContext
>> applicationContext = new
>> XmlWebApplicationContext();
>>                                 applicationContext
>>
>> .setConfigLocation("classpath:applicationContext.xml");
>>
>> applicationContext.setServletContext(servletContext);
>>                                 // applicationContext.refresh();
>>                                 servletContext
>>                                                 .setAttribute(
>>
>> WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE,
>>
>> applicationContext);
>>
>>                                 return servletContext;
>>                         }
>>                 };
>>
>>                 org.apache.log4j.Logger logger = org.apache.log4j.Logger
>>
>> .getLogger("org.apache.wicket.util.tester");
>>                 logger.setLevel(Level.DEBUG);
>>
>>                 tester = new WicketTester(app);
>>         }
>>
>>         @Test
>>         public void homepageRendersSuccessfully() {
>>                 // start and render the test page
>>                 tester.startPage(Start.class);
>>                 tester.assertRenderedPage(Start.class);
>>                 tester.assertNoErrorMessage();
>>                 tester.debugComponentTrees();
>>                 tester.assertComponent("createCustomerLink",
>> BookmarkablePageLink.class);
>>                 tester.assertComponent("showCustomersLink",
>> BookmarkablePageLink.class);
>>                 tester.clickLink("createCustomerLink");
>>         }
>>
>> }
>>
>>
>>
>> And this the normal code:
>> public class Start extends WebPage {
>>
>>         public Start() {
>>                 BookmarkablePageLink<CreateCustomer> customerLink = new
>> BookmarkablePageLink<CreateCustomer>(
>>                                 "createCustomerLink",
>> CreateCustomer.class);
>>                 customerLink.add(new Label("createCustomerLabel",
>>                                 getString("createCustomerLabel")));
>>                 add(customerLink);
>>                 BookmarkablePageLink<ShowCustomers> showCustomersLink =
>> new
>> BookmarkablePageLink<ShowCustomers>(
>>                                 "showCustomersLink", ShowCustomers.class);
>>                 showCustomersLink.add(new Label("showCustomersLabel",
>>                                 getString("showCustomersLabel")));
>>                 add(showCustomersLink);
>>         }
>> }
>>
>> public class StartApplication extends WebApplication {
>>
>>         @Override
>>         public Class<Start> getHomePage() {
>>                 return Start.class;
>>         }
>>
>>         @Override
>>         protected void init() {
>>                 super.init();
>>                 SpringComponentInjector springComponentInjector = new
>> SpringComponentInjector(
>>                                 this);
>>
>> getComponentInstantiationListeners().add(springComponentInjector);
>>
>>         }
>>
>> }
>>
>>
>>
>> --
>> View this message in context:
>> http://apache-wicket.1842946.n4.nabble.com/Wicket-Tester-with-BookmarkablePageLink-tp4656921p4656954.html
>> Sent from the Users forum mailing list archive at Nabble.com.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>
>
> --
> regards,
>
> Vineet Semwal
>



-- 
regards,

Vineet Semwal

Re: Wicket Tester with BookmarkablePageLink

Posted by vineet semwal <vi...@gmail.com>.
i was expecting that..,, you don't have to create real applicationcontext,
just use ApplicationContextMock,below is the sample of how you should set
up your test,if you don't understand anything,feel free to ask..
ApplicationContextMock  appctx = new ApplicationContextMock();
       Service service=Mockito.mock(Service.class);
       appctx.putBean(service);
       WebApplication application=createApplication();
        WicketTester tester = new WicketTester(application);
        SpringComponentInjector componentInjector = new
SpringComponentInjector(tester.getApplication(), appctx, false);

tester.getApplication().getComponentInstantiationListeners().add(componentInjector);



On Tue, Mar 5, 2013 at 12:47 AM, yka <in...@jcoder.de> wrote:

> Sure, this is the test code:
>
> public class AbstractBasePageTester {
>         private WicketTester tester;
>
>         private StartApplication app;
>
>         @Mock
>         private CustomerService aService;
>
>         @Before
>         public void setUp() {
>                 MockitoAnnotations.initMocks(this);
>                 app = new StartApplication() {
>                         @Override
>                         public ServletContext getServletContext() {
>                                 ServletContext servletContext =
> super.getServletContext();
>                                 XmlWebApplicationContext
> applicationContext = new
> XmlWebApplicationContext();
>                                 applicationContext
>
> .setConfigLocation("classpath:applicationContext.xml");
>
> applicationContext.setServletContext(servletContext);
>                                 // applicationContext.refresh();
>                                 servletContext
>                                                 .setAttribute(
>
> WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE,
>
> applicationContext);
>
>                                 return servletContext;
>                         }
>                 };
>
>                 org.apache.log4j.Logger logger = org.apache.log4j.Logger
>
> .getLogger("org.apache.wicket.util.tester");
>                 logger.setLevel(Level.DEBUG);
>
>                 tester = new WicketTester(app);
>         }
>
>         @Test
>         public void homepageRendersSuccessfully() {
>                 // start and render the test page
>                 tester.startPage(Start.class);
>                 tester.assertRenderedPage(Start.class);
>                 tester.assertNoErrorMessage();
>                 tester.debugComponentTrees();
>                 tester.assertComponent("createCustomerLink",
> BookmarkablePageLink.class);
>                 tester.assertComponent("showCustomersLink",
> BookmarkablePageLink.class);
>                 tester.clickLink("createCustomerLink");
>         }
>
> }
>
>
>
> And this the normal code:
> public class Start extends WebPage {
>
>         public Start() {
>                 BookmarkablePageLink<CreateCustomer> customerLink = new
> BookmarkablePageLink<CreateCustomer>(
>                                 "createCustomerLink",
> CreateCustomer.class);
>                 customerLink.add(new Label("createCustomerLabel",
>                                 getString("createCustomerLabel")));
>                 add(customerLink);
>                 BookmarkablePageLink<ShowCustomers> showCustomersLink = new
> BookmarkablePageLink<ShowCustomers>(
>                                 "showCustomersLink", ShowCustomers.class);
>                 showCustomersLink.add(new Label("showCustomersLabel",
>                                 getString("showCustomersLabel")));
>                 add(showCustomersLink);
>         }
> }
>
> public class StartApplication extends WebApplication {
>
>         @Override
>         public Class<Start> getHomePage() {
>                 return Start.class;
>         }
>
>         @Override
>         protected void init() {
>                 super.init();
>                 SpringComponentInjector springComponentInjector = new
> SpringComponentInjector(
>                                 this);
>
> getComponentInstantiationListeners().add(springComponentInjector);
>
>         }
>
> }
>
>
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/Wicket-Tester-with-BookmarkablePageLink-tp4656921p4656954.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>


-- 
regards,

Vineet Semwal

Re: Wicket Tester with BookmarkablePageLink

Posted by yka <in...@jcoder.de>.
Sure, this is the test code:

public class AbstractBasePageTester {
	private WicketTester tester;

	private StartApplication app;

	@Mock
	private CustomerService aService;

	@Before
	public void setUp() {
		MockitoAnnotations.initMocks(this);
		app = new StartApplication() {
			@Override
			public ServletContext getServletContext() {
				ServletContext servletContext = super.getServletContext();
				XmlWebApplicationContext applicationContext = new
XmlWebApplicationContext();
				applicationContext
						.setConfigLocation("classpath:applicationContext.xml");
				applicationContext.setServletContext(servletContext);
				// applicationContext.refresh();
				servletContext
						.setAttribute(
								WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE,
								applicationContext);

				return servletContext;
			}
		};

		org.apache.log4j.Logger logger = org.apache.log4j.Logger
				.getLogger("org.apache.wicket.util.tester");
		logger.setLevel(Level.DEBUG);

		tester = new WicketTester(app);
	}

	@Test
	public void homepageRendersSuccessfully() {
		// start and render the test page
		tester.startPage(Start.class);
		tester.assertRenderedPage(Start.class);
		tester.assertNoErrorMessage();
		tester.debugComponentTrees();
		tester.assertComponent("createCustomerLink", BookmarkablePageLink.class);
		tester.assertComponent("showCustomersLink", BookmarkablePageLink.class);
		tester.clickLink("createCustomerLink");
	}

}



And this the normal code:
public class Start extends WebPage {

	public Start() {
		BookmarkablePageLink<CreateCustomer> customerLink = new
BookmarkablePageLink<CreateCustomer>(
				"createCustomerLink", CreateCustomer.class);
		customerLink.add(new Label("createCustomerLabel",
				getString("createCustomerLabel")));
		add(customerLink);
		BookmarkablePageLink<ShowCustomers> showCustomersLink = new
BookmarkablePageLink<ShowCustomers>(
				"showCustomersLink", ShowCustomers.class);
		showCustomersLink.add(new Label("showCustomersLabel",
				getString("showCustomersLabel")));
		add(showCustomersLink);
	}
}

public class StartApplication extends WebApplication {

	@Override
	public Class<Start> getHomePage() {
		return Start.class;
	}

	@Override
	protected void init() {
		super.init();
		SpringComponentInjector springComponentInjector = new
SpringComponentInjector(
				this);
		getComponentInstantiationListeners().add(springComponentInjector);

	}

}



--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Wicket-Tester-with-BookmarkablePageLink-tp4656921p4656954.html
Sent from the Users forum mailing list archive at Nabble.com.

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


Re: Wicket Tester with BookmarkablePageLink

Posted by vineet semwal <vi...@gmail.com>.
that is because your page could not be instantiated by pagefactory,it used
the constructor but that threw exception ,the error message is confusing
you..
look at your stacktrace carefully..below is the problem which i guess is
because
you are not mocking/testing correctly ,post some code ..
Caused by: java.lang.IllegalStateException: BeanFactory not initialized or
already closed - call 'refresh' before accessing beans via the
ApplicationContext


On Mon, Mar 4, 2013 at 12:13 AM, yka <in...@jcoder.de> wrote:

> Hi all,
>
> are there any known problems with testing BookmarkablePageLinks?
> Im trying to click a BookmarkablePageLink from my start page and receive
> the
> following trace. I dont understand why he cant use the public constructor.
> I've wrote the default constructor...
>
>
> org.apache.wicket.WicketRuntimeException: Internal error in WicketTester.
> Please report this in Wicket's Issue Tracker.
>         at
>
> org.apache.wicket.util.tester.BaseWicketTester.clickLink(BaseWicketTester.java:1879)
>         at
>
> org.apache.wicket.util.tester.BaseWicketTester.clickLink(BaseWicketTester.java:1760)
>         at
>
> com.customer.web.AbstractBasePageTester.homepageRendersSuccessfully(AbstractBasePageTester.java:70)
>         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>         at
>
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>         at
>
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>         at java.lang.reflect.Method.invoke(Method.java:597)
>         at
>
> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
>         at
>
> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
>         at
>
> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
>         at
>
> org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
>         at
>
> org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
>         at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
>         at
>
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
>         at
>
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
>         at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
>         at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
>         at
> org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
>         at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
>         at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
>         at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
>         at
>
> org.mockito.internal.runners.JUnit45AndHigherRunnerImpl.run(JUnit45AndHigherRunnerImpl.java:37)
>         at
> org.mockito.runners.MockitoJUnitRunner.run(MockitoJUnitRunner.java:62)
>         at
>
> org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
>         at
>
> org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
>         at
>
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
>         at
>
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
>         at
>
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
>         at
>
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
> Caused by: org.apache.wicket.WicketRuntimeException: Can't instantiate page
> using constructor 'public com.customer.CreateCustomer()'. Might be it
> doesn't exist, may be it is not visible (public).
>         at
>
> org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:193)
>         at
>
> org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:66)
>         at
>
> org.apache.wicket.DefaultMapperContext.newPageInstance(DefaultMapperContext.java:133)
>         at
>
> org.apache.wicket.core.request.handler.PageProvider.resolvePageInstance(PageProvider.java:278)
>         at
>
> org.apache.wicket.core.request.handler.PageProvider.getPageInstance(PageProvider.java:166)
>         at
>
> org.apache.wicket.util.tester.BaseWicketTester$LastPageRecordingPageRendererProvider.get(BaseWicketTester.java:2628)
>         at
>
> org.apache.wicket.util.tester.BaseWicketTester$LastPageRecordingPageRendererProvider.get(BaseWicketTester.java:2614)
>         at
>
> org.apache.wicket.core.request.handler.RenderPageRequestHandler.respond(RenderPageRequestHandler.java:164)
>         at
>
> org.apache.wicket.request.cycle.RequestCycle$HandlerExecutor.respond(RequestCycle.java:840)
>         at
>
> org.apache.wicket.request.RequestHandlerStack.execute(RequestHandlerStack.java:64)
>         at
> org.apache.wicket.request.cycle.RequestCycle.execute(RequestCycle.java:254)
>         at
>
> org.apache.wicket.request.cycle.RequestCycle.processRequest(RequestCycle.java:211)
>         at
>
> org.apache.wicket.request.cycle.RequestCycle.processRequestAndDetach(RequestCycle.java:282)
>         at
>
> org.apache.wicket.util.tester.BaseWicketTester.processRequest(BaseWicketTester.java:643)
>         at
>
> org.apache.wicket.util.tester.BaseWicketTester.processRequest(BaseWicketTester.java:572)
>         at
>
> org.apache.wicket.util.tester.BaseWicketTester.processRequest(BaseWicketTester.java:544)
>         at
>
> org.apache.wicket.util.tester.BaseWicketTester.startPage(BaseWicketTester.java:1186)
>         at
>
> org.apache.wicket.util.tester.BaseWicketTester.clickLink(BaseWicketTester.java:1875)
>         ... 28 more
> Caused by: java.lang.reflect.InvocationTargetException
>         at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
> Method)
>         at
>
> sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
>         at
>
> sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
>         at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
>         at
>
> org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:174)
>         ... 45 more
> Caused by: java.lang.IllegalStateException: BeanFactory not initialized or
> already closed - call 'refresh' before accessing beans via the
> ApplicationContext
>         at
>
> org.springframework.context.support.AbstractRefreshableApplicationContext.getBeanFactory(AbstractRefreshableApplicationContext.java:172)
>         at
>
> org.springframework.context.support.AbstractApplicationContext.getBeanNamesForType(AbstractApplicationContext.java:1174)
>         at
>
> org.springframework.beans.factory.BeanFactoryUtils.beanNamesForTypeIncludingAncestors(BeanFactoryUtils.java:144)
>         at
>
> org.apache.wicket.spring.injection.annot.AnnotProxyFieldValueFactory.getBeanNameOfClass(AnnotProxyFieldValueFactory.java:211)
>         at
>
> org.apache.wicket.spring.injection.annot.AnnotProxyFieldValueFactory.getBeanName(AnnotProxyFieldValueFactory.java:179)
>         at
>
> org.apache.wicket.spring.injection.annot.AnnotProxyFieldValueFactory.getFieldValue(AnnotProxyFieldValueFactory.java:113)
>         at org.apache.wicket.injection.Injector.inject(Injector.java:111)
>         at
>
> org.apache.wicket.spring.injection.annot.SpringComponentInjector.inject(SpringComponentInjector.java:127)
>         at
>
> org.apache.wicket.spring.injection.annot.SpringComponentInjector.onInstantiation(SpringComponentInjector.java:133)
>         at
>
> org.apache.wicket.application.ComponentInstantiationListenerCollection$1.notify(ComponentInstantiationListenerCollection.java:38)
>         at
>
> org.apache.wicket.application.ComponentInstantiationListenerCollection$1.notify(ComponentInstantiationListenerCollection.java:34)
>         at
>
> org.apache.wicket.util.listener.ListenerCollection.notify(ListenerCollection.java:80)
>         at
>
> org.apache.wicket.application.ComponentInstantiationListenerCollection.onInstantiation(ComponentInstantiationListenerCollection.java:33)
>         at org.apache.wicket.Component.<init>(Component.java:683)
>         at
> org.apache.wicket.MarkupContainer.<init>(MarkupContainer.java:120)
>         at org.apache.wicket.Page.<init>(Page.java:172)
>         at org.apache.wicket.Page.<init>(Page.java:136)
>         at org.apache.wicket.markup.html.WebPage.<init>(WebPage.java:76)
>         at com.index.Start.<init>(Start.java:12)
>         at com.customer.CreateCustomer.<init>(CreateCustomer.java:24)
>         ... 50 more
>
>
>
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/Wicket-Tester-with-BookmarkablePageLink-tp4656921.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>


-- 
regards,

Vineet Semwal