Package org.apache.wicket.util.tester

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


  /**
   * @throws Exception
   */
  public void testAuthorized() throws Exception
  {
    WicketTester tester = new WicketTester();
    tester.getApplication()
      .getSecuritySettings()
      .setAuthorizationStrategy(
        new RoleAuthorizationStrategy(new UserRolesAuthorizer("ADMIN")));
    tester.startPage(AdminPage.class);
    tester.assertRenderedPage(AdminPage.class);
  }
View Full Code Here


  /**
   * @throws Exception
   */
  public void testNotAuthorized() throws Exception
  {
    WicketTester tester = new WicketTester();
    tester.getApplication()
      .getSecuritySettings()
      .setAuthorizationStrategy(
        new RoleAuthorizationStrategy(new UserRolesAuthorizer("USER")));
    final class Listener implements IUnauthorizedComponentInstantiationListener
    {
      private boolean eventReceived = false;

      public void onUnauthorizedInstantiation(Component component)
      {
        eventReceived = true;
      }
    }
    Listener listener = new Listener();
    tester.getApplication()
      .getSecuritySettings()
      .setUnauthorizedComponentInstantiationListener(listener);

    try
    {
      tester.startPage(AdminPage.class);
      assertTrue("an authorization exception event should have been received",
        listener.eventReceived);
    }
    catch (Exception e)
    {
View Full Code Here

  private WicketTester tester;

  @Override
  protected void setUp() throws Exception
  {
    tester = new WicketTester();
  }
View Full Code Here

  private WicketTester tester;

  @Override
  protected void setUp() throws Exception
  {
    tester = new WicketTester();
  }
View Full Code Here

   *
   */
  @Before
  public void before()
  {
    tester = new WicketTester(new RepeaterApplication());
  }
View Full Code Here

     * https://issues.apache.org/jira/browse/WICKET-4334
     * https://issues.apache.org/jira/browse/WICKET-4312
     */
    @Test
    public void doNotPreserveJSessionId() {
        WicketTester tester = new WicketTester();
        try {
            headerResponse.render(JavaScriptHeaderItem.forUrl("js-resource.js;jsessionid=1h402r54r4xuep32znicouftm", "some-id", false, null));
            String expected = "<script type=\"text/javascript\" id=\"some-id\" src=\"js-resource.js\"></script>\n";
            String actual = headerResponse.getResponse().toString();
            Assert.assertEquals(expected, actual);
        } finally {
            tester.destroy();
        }
    }
View Full Code Here

  @Test
  public void atmospherePush()
  {
    final String updateTimeIsExecuted = "updateTime is executed!";

    WicketTester tester = new WicketTester();
    HomePage page = new HomePage(new PageParameters())
    {
      @Subscribe
      public void updateTime(AjaxRequestTarget target, Date event)
      {
        super.updateTime(target, event);

        updateTimeCalled.set(true);

        target.appendJavaScript(updateTimeIsExecuted);
      }

      @Subscribe(contextAwareFilter = ReceiverFilter.class)
      public void receiveMessage(AjaxRequestTarget target, ChatMessage message)
      {
        super.receiveMessage(target, message);
        receiveMessageCalled.set(true);
      }
    };

    AtmosphereTester waTester = new AtmosphereTester(tester, page);

    assertThat(updateTimeCalled.get(), is(false));
    assertThat(receiveMessageCalled.get(), is(false));

    Date payload = new Date();
    waTester.post(payload);

    assertThat(updateTimeCalled.get(), is(true));
    assertThat(receiveMessageCalled.get(), is(false));

    tester.assertContains(updateTimeIsExecuted);

    final FormTester form = tester.newFormTester("form");

    form.setValue("input", "Atmosphere rocks!");

    form.submit("send");

    assertThat(updateTimeCalled.get(), is(true));
    assertThat(receiveMessageCalled.get(), is(true));

    // get the the collected so far content of the suspended response
    // Note: it may contain several <ajax-response>s.
    // use waTester.resetResponse() to remove the collected data
    String atmosphereResponse = waTester.getPushedResponse();
//    System.out.println("RES:" + atmosphereResponse);

    // assert
    assertThat(atmosphereResponse,
        is(not(equalTo("<?xml version=\"1.0\" encoding=\"UTF-8\"?><ajax-response></ajax-response>"))));

    waTester.switchOnTestMode();
    // now the assertions are against the Atmosphere's suspended response data
    tester.assertComponentOnAjaxResponse("message");
    waTester.switchOffTestMode();
    // now the assertions will be the real last response

    tester.assertLabel("message", "Atmosphere rocks!");

    tester.destroy();
  }
View Full Code Here

   * WICKET-5447
   */
  @Test
  public void properlyClosed() throws Exception
  {
    WicketTester tester = new WicketTester();

    Label label = new Label("label");
    label.add(new NodeBorder(new boolean[] { true, false, true }));

    tester.startComponentInPage(label);

    tester
      .assertResultPage("<div class=\"tree-branch tree-branch-mid\"><div class=\"tree-subtree\"><div class=\"tree-branch tree-branch-last\"><div class=\"tree-subtree\"><div class=\"tree-branch tree-branch-mid\"><span wicket:id=\"label\" class=\"tree-node\"></span></div></div></div></div></div>");
  }
View Full Code Here

      {
        return new CustomServletWebRequest(servletRequest, filterPath);
      }
    };

    WicketTester tester = new WicketTester(application);
    try
    {
      tester.startPage(new CustomRequestPage());
    }
    finally
    {
      tester.destroy();
    }
  }
View Full Code Here

        {
        });
      }
    });

    return new WicketTester(app)
    {
      @Override
      protected IPageManagerProvider newTestPageManagerProvider()
      {
        return new IPageManagerProvider()
View Full Code Here

TOP

Related Classes of org.apache.wicket.util.tester.WicketTester

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.