org.apache.wicket.util.tester.WicketTester Java Examples

The following examples show how to use org.apache.wicket.util.tester.WicketTester. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OrienteerTestModule.java    From Orienteer with Apache License 2.0 6 votes vote down vote up
@Override
protected void configure() {
	
	bind(Boolean.class).annotatedWith(Names.named("testing")).toInstance(true);
	bindListener(InstanceOfMatcher.createFor(WebApplication.class), new TypeListener() {
		
		@Override
		public <I> void hear(TypeLiteral<I> type, final TypeEncounter<I> encounter) {
			final Provider<Injector> injectorProvider = encounter.getProvider(Injector.class);
			encounter.register((InjectionListener<Object>) injected -> {
                   WebApplication app = (WebApplication) injected;
                   app.getComponentInstantiationListeners().add(new GuiceComponentInjector(app, injectorProvider.get()));
               });
		}
	});
	bind(OrienteerTester.class).asEagerSingleton();
	Provider<OrienteerTester> provider = binder().getProvider(OrienteerTester.class);
	bind(WicketTester.class).toProvider(provider);
	bind(WicketOrientDbTester.class).toProvider(provider);
}
 
Example #2
Source File: BootstrapPaginatorTest.java    From pm-wicket-utils with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void testRenderComponent(){
	WicketTester tester = createTester();
	BootstrapPaginator paginator = new BootstrapPaginator("paginator", Model.of(100)) {
		private static final long serialVersionUID = -4486050808642574868L;

		@Override
		public void onPageChange(AjaxRequestTarget target, IModel<Integer> page) {
		}
	};
	paginator.setTotalResults(Model.of(100));
	tester.startComponentInPage(paginator);
	tester.assertDisabled("paginator:first:link");
	tester.assertDisabled("paginator:previous:link");
	tester.assertEnabled("paginator:next:link");
	tester.assertEnabled("paginator:last:link");
}
 
Example #3
Source File: BootstrapPaginatorTest.java    From pm-wicket-utils with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void testLastButton(){
	WicketTester tester = createTester();
	final Boxed<Integer> pageBox = new Boxed<Integer>();
	
	BootstrapPaginator paginator = new BootstrapPaginator("paginator", Model.of(100)) {
		private static final long serialVersionUID = -4486050808642574868L;

		@Override
		public void onPageChange(AjaxRequestTarget target, IModel<Integer> page) {
			pageBox.value=page.getObject();
		}
	};
	paginator.setTotalResults(Model.of(100));
	paginator.setNumberResultsPerPage(10);
	tester.startComponentInPage(paginator);
	
	tester.clickLink("paginator:last:link");
	assertEquals(9, (int) pageBox.value);
	tester.assertDisabled("paginator:last:link");
	tester.assertDisabled("paginator:next:link");
	tester.assertEnabled("paginator:previous:link");
	tester.assertEnabled("paginator:first:link");
	
}
 
Example #4
Source File: BootstrapPaginatorTest.java    From pm-wicket-utils with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void testNextButton(){
	WicketTester tester = createTester();
	final Boxed<Integer> pageBox = new Boxed<Integer>();
	
	BootstrapPaginator paginator = new BootstrapPaginator("paginator", Model.of(100)) {
		private static final long serialVersionUID = -4486050808642574868L;

		@Override
		public void onPageChange(AjaxRequestTarget target, IModel<Integer> page) {
			pageBox.value=page.getObject();
		}
	};
	paginator.setTotalResults(Model.of(100));
	tester.startComponentInPage(paginator);
	tester.clickLink("paginator:next:link");
	assertEquals(1, (int) pageBox.value);
	tester.assertEnabled("paginator:last:link");
	tester.assertEnabled("paginator:next:link");
	tester.assertEnabled("paginator:previous:link");
	tester.assertEnabled("paginator:first:link");
}
 
Example #5
Source File: BootstrapPaginatorTest.java    From pm-wicket-utils with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void testPreviousButton(){
	WicketTester tester = createTester();
	final Boxed<Integer> pageBox = new Boxed<Integer>();
	
	BootstrapPaginator paginator = new BootstrapPaginator("paginator", Model.of(100)) {
		private static final long serialVersionUID = -4486050808642574868L;

		@Override
		public void onPageChange(AjaxRequestTarget target, IModel<Integer> page) {
			pageBox.value=page.getObject();
		}
	};
	paginator.setTotalResults(Model.of(100));
	paginator.setModelObject(2);
	tester.startComponentInPage(paginator);
	tester.clickLink("paginator:previous:link");
	assertEquals(1, (int) pageBox.value);
	tester.assertEnabled("paginator:last:link");
	tester.assertEnabled("paginator:next:link");
	tester.assertEnabled("paginator:previous:link");
	tester.assertEnabled("paginator:first:link");
}
 
Example #6
Source File: WicketOrientDbFilterTesterScope.java    From wicket-orientdb with Apache License 2.0 6 votes vote down vote up
@Override
public Statement apply(final Statement base, Description description) {
    return new Statement() {
        @Override
        public void evaluate() throws Throwable {
            WicketTester tester = create();
            List<OClass> testClasses = Lists.newArrayList();
            try {
                testClasses = initTestClasses();
                base.evaluate();
            } finally {
                deleteClassesAndDocuments(testClasses);
                tester.destroy();
            }
        }
    };
}
 
Example #7
Source File: BootstrapPaginatorTest.java    From pm-wicket-utils with GNU Lesser General Public License v3.0 6 votes vote down vote up
private WicketTester createTester(){
	WicketTester tester = new WicketTester(new WebApplication() {
		
		@Override
		public Class<? extends Page> getHomePage() {
			return null;
		}
	}){
		@Override
		protected String createPageMarkup(String componentId) {
			return "<div class=\"pagination pagination-small pagination-right\" wicket:id=\"paginator\">"+
					"</div>";
		}
	};
	
	return tester;
}
 
Example #8
Source File: BootstrapPaginatorTest.java    From pm-wicket-utils with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void testShowHiddenComponents(){
	WicketTester tester = createTester();
	BootstrapPaginator paginator = new BootstrapPaginator("paginator", Model.of(100)) {
		private static final long serialVersionUID = -4486050808642574868L;
		
		@Override
		public void onPageChange(AjaxRequestTarget target, IModel<Integer> page) {
		}
	};
	
	paginator.setTotalResults(Model.of(100));
	paginator.setShowLastButton(false);
	paginator.setShowFirstButton(false);
	paginator.setShowNextButton(false);
	paginator.setShowPreviousButton(false);
	
	tester.startComponentInPage(paginator);
	tester.assertInvisible("paginator:first:link");
	tester.assertInvisible("paginator:previous:link");
	tester.assertInvisible("paginator:next:link");
	tester.assertInvisible("paginator:last:link");
}
 
Example #9
Source File: BootstrapPaginatorTest.java    From pm-wicket-utils with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void testNumberButton(){
	WicketTester tester = createTester();
	final Boxed<Integer> pageBox = new Boxed<Integer>();
	
	BootstrapPaginator paginator = new BootstrapPaginator("paginator", Model.of(100)) {
		private static final long serialVersionUID = -4486050808642574868L;

		@Override
		public void onPageChange(AjaxRequestTarget target, IModel<Integer> page) {
			pageBox.value=page.getObject();
		}
	};
	paginator.setTotalResults(Model.of(100));
	paginator.setNumberResultsPerPage(10);
	tester.startComponentInPage(paginator);
	tester.clickLink("paginator:page:4:link");
	assertEquals(4, (int) pageBox.value);
	tester.assertEnabled("paginator:last:link");
	tester.assertEnabled("paginator:next:link");
	tester.assertEnabled("paginator:previous:link");
	tester.assertEnabled("paginator:first:link");
	tester.assertLabel("paginator:page:2:link:label", "5");
}
 
Example #10
Source File: BootstrapPaginatorTest.java    From pm-wicket-utils with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void testFirstButton(){
	WicketTester tester = createTester();
	final Boxed<Integer> pageBox = new Boxed<Integer>();
	
	BootstrapPaginator paginator = new BootstrapPaginator("paginator", Model.of(100)) {
		private static final long serialVersionUID = -4486050808642574868L;

		@Override
		public void onPageChange(AjaxRequestTarget target, IModel<Integer> page) {
			pageBox.value=page.getObject();
		}
	};
	paginator.setTotalResults(Model.of(100));
	paginator.setModelObject(2);
	tester.startComponentInPage(paginator);
	tester.clickLink("paginator:first:link");
	assertEquals(0, (int) pageBox.value);
	tester.assertEnabled("paginator:last:link");
	tester.assertEnabled("paginator:next:link");
	tester.assertDisabled("paginator:previous:link");
	tester.assertDisabled("paginator:first:link");
}
 
Example #11
Source File: AjaxListSetViewTest.java    From pm-wicket-utils with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Before
public void setUp(){
	tester = new WicketTester(new WebApplication() {
		
		@Override
		public Class<? extends Page> getHomePage() {
			return null;
		}
		
	});
}
 
Example #12
Source File: AbstractWicketTest.java    From the-app with Apache License 2.0 5 votes vote down vote up
@Before
public void initializeWicketTester() throws Exception {
    initMocks(this);
    ApplicationContextMock appctx = initializeApplicationContext();
    TestShopApplication application = new TestShopApplication(appctx);
    wicketTester = new WicketTester(application);
}
 
Example #13
Source File: AbstractWicketTest.java    From AppStash with Apache License 2.0 5 votes vote down vote up
@Before
public void initializeWicketTester() throws Exception {
    initMocks(this);
    ApplicationContextMock appctx = initializeApplicationContext();
    TestShopApplication application = new TestShopApplication(appctx);
    wicketTester = new WicketTester(application);
}
 
Example #14
Source File: AbstractEnduserITCase.java    From syncope with Apache License 2.0 5 votes vote down vote up
@BeforeAll
public static void setUp() {
    Locale.setDefault(Locale.ENGLISH);

    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
    ctx.register(SyncopeEnduserWebApplicationTestConfig.class);
    ctx.register(SyncopeWebApplication.class);
    ctx.refresh();

    TESTER = new WicketTester(ctx.getBean(SyncopeWebApplication.class));

    SYNCOPE_SERVICE = new SyncopeClientFactoryBean().
            setAddress(ADDRESS).create(ADMIN_UNAME, ADMIN_PWD).
            getService(SyncopeService.class);
}
 
Example #15
Source File: AbstractConsoleITCase.java    From syncope with Apache License 2.0 5 votes vote down vote up
@BeforeAll
public static void setUp() {
    Locale.setDefault(Locale.ENGLISH);

    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
    ctx.register(SyncopeConsoleWebApplicationTestConfig.class);
    ctx.register(SyncopeWebApplication.class);
    ctx.register(SyncopeIdMConsoleContext.class);
    ctx.refresh();

    TESTER = new WicketTester(ctx.getBean(SyncopeWebApplication.class)) {

        // Remove this method when upgrading to Wicket 9.0.0-M6 - see WICKET-6766
        @Override
        protected IPageManagerProvider newTestPageManagerProvider() {
            return () -> new MockPageManager() {

                @Override
                public boolean supportsVersioning() {
                    return true;
                }
            };
        }
    };

    SYNCOPE_SERVICE = new SyncopeClientFactoryBean().
            setAddress(ADDRESS).create(ADMIN_UNAME, ADMIN_PWD).
            getService(SyncopeService.class);
}
 
Example #16
Source File: AbstractTest.java    From syncope with Apache License 2.0 5 votes vote down vote up
@BeforeAll
public static void setupTester() throws IOException {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
    ctx.register(SyncopeConsoleWebApplicationTestConfig.class);
    ctx.register(TestSyncopeWebApplication.class);
    ctx.refresh();

    TESTER = new WicketTester(ctx.getBean(SyncopeWebApplication.class));
}
 
Example #17
Source File: WicketUtilsTest.java    From projectforge-webapp with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void isParent()
{
  new WicketTester(new WebApplication() {
    @Override
    public Class< ? extends Page> getHomePage()
    {
      return null;
    }
  });
  final WebMarkupContainer c1 = new WebMarkupContainer("c1");
  final WebMarkupContainer c2 = new WebMarkupContainer("c2");
  c1.add(c2);
  final WebMarkupContainer c3 = new WebMarkupContainer("c3");
  c2.add(c3);
  final Label l1 = new Label("l1", "l1");
  c3.add(l1);
  final Label l2 = new Label("l2", "l2");
  c1.add(l2);
  final Label l3 = new Label("l3", "l3");
  assertFalse(WicketUtils.isParent(c1, c1));
  assertTrue(WicketUtils.isParent(c1, c2));
  assertFalse(WicketUtils.isParent(c2, c1));
  assertTrue(WicketUtils.isParent(c1, c3));
  assertTrue(WicketUtils.isParent(c1, l1));
  assertTrue(WicketUtils.isParent(c2, l1));
  assertTrue(WicketUtils.isParent(c3, l1));
  assertTrue(WicketUtils.isParent(c1, l2));
  assertFalse(WicketUtils.isParent(c2, l2));
  assertFalse(WicketUtils.isParent(c1, l3));
}
 
Example #18
Source File: WebSocketTest.java    From inception with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp()
{
    // set up "server" and test page
    tester = new WicketTester();
    testVars = new TestEnv();
    page = new WebSocketTestPage(testVars);
    tester.startPage(page);
}
 
Example #19
Source File: AbstractWicketTester.java    From openmeetings with Apache License 2.0 5 votes vote down vote up
public static void checkErrors(WicketTester tester, int count) {
	List<FeedbackMessage> errors = getErrors(tester);
	if (count != errors.size()) {
		for (FeedbackMessage fm : errors) {
			log.debug("Error {}", fm);
		}
	}
	assertEquals(count, errors.size(), String.format("There should be exactly %s errors", count));
}
 
Example #20
Source File: AbstractWicketTester.java    From openmeetings with Apache License 2.0 4 votes vote down vote up
public static <T extends Serializable> AbstractAjaxBehavior getButtonBehavior(WicketTester tester, String path, int idx) {
	Args.notNull(path, "path");
	return (AbstractAjaxBehavior)tester.getComponentFromLastRenderedPage(path + ":dialog:footer:buttons:" + idx + ":button").getBehaviorById(0);
}
 
Example #21
Source File: HomePageIntegrationTest.java    From tutorials with MIT License 4 votes vote down vote up
@Before
public void setUp() {
    tester = new WicketTester(new HelloWorldApplication());
}
 
Example #22
Source File: WicketPageTestBase.java    From projectforge-webapp with GNU General Public License v3.0 4 votes vote down vote up
@Before
public void setUpWicketApplication()
{
  tester = new WicketTester(new WicketTestApplication());
}
 
Example #23
Source File: TestHome.java    From oodt with Apache License 2.0 4 votes vote down vote up
@Override
public void setUp()
{
  FMBrowserApp app = new FMBrowserApp();
	tester = new WicketTester(app);
}
 
Example #24
Source File: StaticInjectorProvider.java    From Orienteer with Apache License 2.0 4 votes vote down vote up
@Override
public void run() {
	WicketTester wicketTester = STATIC_INJECTOR.getInstance(WicketTester.class);
	wicketTester.destroy();
}
 
Example #25
Source File: AbstractWicketTester.java    From openmeetings with Apache License 2.0 4 votes vote down vote up
public static WicketTester getWicketTester(Application app) {
	return getWicketTester(app, -1);
}
 
Example #26
Source File: OrienteerTestRunner.java    From Orienteer with Apache License 2.0 4 votes vote down vote up
@Override
public Object createTest() {
	//Ensure that wicket tester and corresponding application started
	getInjector().getInstance(WicketTester.class);
	return super.createTest();
}
 
Example #27
Source File: WicketWebApplicationTest.java    From spring-boot-example-wicket with Apache License 2.0 4 votes vote down vote up
@Test
public void testMountedPage() {
	WicketTester wicketTester = testService.getWicketTester();
	wicketTester.startPage(MountedPage.class);
	wicketTester.assertRenderedPage(MountedPage.class);
}
 
Example #28
Source File: WicketWebApplicationTest.java    From spring-boot-example-wicket with Apache License 2.0 4 votes vote down vote up
@Test
public void testApplication() {
	WicketTester wicketTester = testService.getWicketTester();
	wicketTester.startPage(Homepage.class);
	wicketTester.assertRenderedPage(Homepage.class);
}
 
Example #29
Source File: TestService.java    From spring-boot-example-wicket with Apache License 2.0 4 votes vote down vote up
public WicketTester getWicketTester() {
	return wicketTester;
}
 
Example #30
Source File: TestService.java    From spring-boot-example-wicket with Apache License 2.0 4 votes vote down vote up
@Override
public void afterPropertiesSet() throws Exception {
	wicketTester = new WicketTester(wicketWebApplication);
}