Example usage for org.apache.wicket.extensions.ajax.markup.html.modal ModalWindow getPageRelativePath

List of usage examples for org.apache.wicket.extensions.ajax.markup.html.modal ModalWindow getPageRelativePath

Introduction

In this page you can find the example usage for org.apache.wicket.extensions.ajax.markup.html.modal ModalWindow getPageRelativePath.

Prototype

@Override
public final String getPageRelativePath() 

Source Link

Document

Gets the path to this component relative to its containing page, i.e.

Usage

From source file:org.xaloon.wicket.plugin.user.admin.panel.GroupDetailPanelTest.java

License:Apache License

/**
 * @throws Exception// w ww  .j  a va  2  s. c  o  m
 */
@Test
public void testAssignRole() throws Exception {
    // TEST ASSIGN ROLE TO GROUP
    Assert.assertNotNull(tester.getTagByWicketId("link-assign-entities"));
    tester.clickLink("id:role-admin:choice-management:link-assign-entities");
    tester.assertNoErrorMessage();

    ModalWindow modalWindow = (ModalWindow) tester
            .getComponentFromLastRenderedPage("id:role-admin:choice-management:modal-assign-entities");
    String modalPath = modalWindow.getPageRelativePath() + ":" + modalWindow.getContentId();
    Assert.assertTrue(modalWindow.isVisible());

    // Submit the form
    String formPath = modalPath + ":form";
    FormTester form = tester.newFormTester(formPath);
    form.selectMultiple("choices", new int[] { 1 });

    Mockito.when(groupService.assignChildren((SecurityGroup) Matchers.anyObject(),
            Matchers.anyListOf(SecurityRole.class))).thenAnswer(new Answer<SecurityGroup>() {

                @SuppressWarnings("unchecked")
                @Override
                public SecurityGroup answer(InvocationOnMock invocation) throws Throwable {
                    Object[] args = invocation.getArguments();
                    List<SecurityRole> selections = (List<SecurityRole>) args[1];
                    Assert.assertEquals(1, selections.size());
                    Assert.assertEquals(availableRoles.get(1), selections.get(0));
                    return null;
                }
            });
    // Submit ajax form
    tester.executeAjaxEvent(formPath + ":submit", "onclick");
}

From source file:org.xaloon.wicket.plugin.user.admin.panel.GroupsPanelTest.java

License:Apache License

/**
 * @throws Exception// w w  w .  ja  v  a  2 s.com
 */
@Test
public void testGroupPanelAuthorized() throws Exception {
    MockedApplication app = createMockedApplication();
    WicketTester tester = new WicketTester(app);

    // Set security to True by default
    when(app.getSecurityFacade().hasAny(SecurityAuthorities.SYSTEM_ADMINISTRATOR)).thenReturn(true);

    // Return at least one group
    when(groupService.getCount()).thenReturn(1L);

    SecurityGroup group = mock(SecurityGroup.class);
    when(group.getPath()).thenReturn("group-name");

    List<SecurityGroup> groups = new ArrayList<SecurityGroup>();
    groups.add(group);
    when(groupService.getAuthorities(0, 1)).thenReturn(groups);
    SecurityGroup securityGroup = new JpaGroup();
    when(groupService.newAuthority()).thenReturn(securityGroup);

    tester.startComponentInPage(new GroupsPanel("id", new PageParameters()));

    // Test if there are any items displayed
    assertNotNull(tester.getTagByWicketId("container"));
    assertNotNull(tester.getTagByWicketId("security-groups"));
    assertEquals(1, tester.getTagsByWicketId("name").size());

    // Test creating new group
    tester.clickLink("id:add-new-group");
    tester.assertNoErrorMessage();

    // Get the modal window and submit the form
    ModalWindow modal = (ModalWindow) tester.getComponentFromLastRenderedPage("id:modal-new-group");
    tester.isVisible(modal.getPageRelativePath());
    String modalPath = modal.getPageRelativePath() + ":" + modal.getContentId();

    // Close and re-open form
    closeModalWindow(modal, tester);
    tester.clickLink("id:add-new-group");
    tester.assertNoErrorMessage();
    modal = (ModalWindow) tester.getComponentFromLastRenderedPage("id:modal-new-group");

    // Submit the form
    String formPath = modalPath + ":new-entity";
    FormTester form = tester.newFormTester(formPath);
    form.setValue("name", "testValue");

    // Submit ajax form
    tester.executeAjaxEvent(formPath + ":submit", "onclick");

    // Validate result
    tester.assertNoErrorMessage();

    Assert.assertEquals("testValue", securityGroup.getName());
}

From source file:org.xaloon.wicket.plugin.user.admin.panel.RoleDetailPanelTest.java

License:Apache License

/**
 * @throws Exception/*from   w w w. j a v  a 2 s. c  o  m*/
 */
@Test
public void testAssignAuthority() throws Exception {
    PageParameters params = new PageParameters();
    params.add(Bookmarkable.PARAM_PATH, path);
    tester.startComponentInPage(new RoleDetailPanel("id", params));
    tester.assertRenderedPage(StartComponentInPage.class);

    Assert.assertNotNull(tester.getTagByWicketId("name"));
    Assert.assertNotNull(tester.getTagByWicketId("authority-admin"));
    Assert.assertEquals(2, tester.getTagsByWicketId("name").size());

    // TEST ASSIGN ROLE TO GROUP
    Assert.assertNotNull(tester.getTagByWicketId("link-assign-entities"));
    tester.clickLink("id:authority-admin:choice-management:link-assign-entities");
    tester.assertNoErrorMessage();

    ModalWindow modalWindow = (ModalWindow) tester
            .getComponentFromLastRenderedPage("id:authority-admin:choice-management:modal-assign-entities");
    String modalPath = modalWindow.getPageRelativePath() + ":" + modalWindow.getContentId();
    Assert.assertTrue(modalWindow.isVisible());

    // Submit the form
    String formPath = modalPath + ":form";
    FormTester form = tester.newFormTester(formPath);
    form.selectMultiple("choices", new int[] { 1 });

    Mockito.when(roleService.assignChildren((SecurityRole) Matchers.anyObject(),
            Matchers.anyListOf(Authority.class))).thenAnswer(new Answer<SecurityGroup>() {

                @SuppressWarnings("unchecked")
                @Override
                public SecurityGroup answer(InvocationOnMock invocation) throws Throwable {
                    Object[] args = invocation.getArguments();
                    List<Authority> selections = (List<Authority>) args[1];
                    Assert.assertEquals(1, selections.size());
                    Assert.assertEquals(availableAuthorities.get(1), selections.get(0));
                    return null;
                }
            });
    // Submit ajax form
    tester.executeAjaxEvent(formPath + ":submit", "onclick");
}

From source file:org.xaloon.wicket.plugin.user.admin.panel.RolesPanelTest.java

License:Apache License

/**
 * @throws Exception/*from www  . ja  va 2s  .  co m*/
 */
@Test
public void testPanelAuthorized() throws Exception {
    MockedApplication app = createMockedApplication();
    WicketTester tester = new WicketTester(app);

    // Set security to True by default
    when(app.getSecurityFacade().hasAny(SecurityAuthorities.SYSTEM_ADMINISTRATOR)).thenReturn(true);

    // Return at least one role
    when(roleService.getCount()).thenReturn(1L);

    SecurityRole role = mock(SecurityRole.class);
    when(role.getPath()).thenReturn("role-name");

    List<SecurityRole> roles = new ArrayList<SecurityRole>();
    roles.add(role);
    when(roleService.getAuthorities(0, 1)).thenReturn(roles);

    SecurityRole securityRole = new JpaRole();
    when(roleService.newAuthority()).thenReturn(securityRole);

    tester.startComponentInPage(new RolesPanel("id", new PageParameters()));
    assertNotNull(tester.getTagByWicketId("container"));
    assertNotNull(tester.getTagByWicketId("security-roles"));
    assertEquals(1, tester.getTagsByWicketId("name").size());

    // Test creating new role
    tester.clickLink("id:add-new-role");
    tester.assertNoErrorMessage();

    // Get the modal window and submit the form
    ModalWindow modal = (ModalWindow) tester.getComponentFromLastRenderedPage("id:modal-new-role");
    tester.isVisible(modal.getPageRelativePath());

    // Close and re-open modal window
    closeModalWindow(modal, tester);
    tester.clickLink("id:add-new-role");
    tester.assertNoErrorMessage();
    modal = (ModalWindow) tester.getComponentFromLastRenderedPage("id:modal-new-role");

    // Take the form
    String modalPath = modal.getPageRelativePath() + ":" + modal.getContentId();
    String formPath = modalPath + ":new-entity";
    FormTester form = tester.newFormTester(formPath);
    form.setValue("name", "testValue");

    // Submit ajax form
    tester.executeAjaxEvent(formPath + ":submit", "onclick");

    // Validate result
    tester.assertNoErrorMessage();

    Assert.assertEquals("testValue", securityRole.getName());
}

From source file:org.xaloon.wicket.plugin.user.admin.panel.UserSecurityPanelTest.java

License:Apache License

/**
 * @throws Exception//from  www. j a va 2s . c o  m
 */
@Test
public void testPanelAuthoritiesAssign() throws Exception {
    // Add mocked invocations

    // return available authorities
    Mockito.when(authorityService.getAuthorities(0, -1)).thenReturn(availableAuthorities);

    // return given authorities to user
    final List<Authority> givenAuthorities = new ArrayList<Authority>();
    givenAuthorities.add(newAuthority(777L, "fake-authority"));
    Mockito.when(details.getAuthorities()).thenReturn(givenAuthorities);

    Mockito.when(authorityService.assignAuthorities((UserDetails) Matchers.anyObject(),
            Matchers.anyListOf(Authority.class))).thenAnswer(new Answer<SecurityGroup>() {

                @SuppressWarnings("unchecked")
                @Override
                public SecurityGroup answer(InvocationOnMock invocation) throws Throwable {
                    Object[] args = invocation.getArguments();
                    List<Authority> selections = (List<Authority>) args[1];
                    Assert.assertEquals(1, selections.size());
                    Assert.assertEquals(availableAuthorities.get(2), selections.get(0));
                    return null;
                }
            });

    // Start the test

    // Start the panel before each test
    PageParameters params = new PageParameters();
    params.add(UsersPage.PARAM_USER_ID, "demo");
    tester.startComponentInPage(new UserSecurityPanel("id", params));
    tester.assertNoErrorMessage();
    tester.assertRenderedPage(BaseWicketTester.StartComponentInPage.class);

    Assert.assertNotNull(tester.getTagByWicketId("authority-admin"));
    Assert.assertNotNull(tester.getTagByWicketId("link-assign-entities"));

    // Open the modal window
    tester.clickLink("id:authority-container:authority-admin:choice-management:link-assign-entities");
    tester.assertNoErrorMessage();

    ModalWindow modalWindow = (ModalWindow) tester.getComponentFromLastRenderedPage(
            "id:authority-container:authority-admin:choice-management:modal-assign-entities");
    String modalPath = modalWindow.getPageRelativePath() + ":" + modalWindow.getContentId();
    Assert.assertTrue(modalWindow.isVisible());

    // Submit the form
    String formPath = modalPath + ":form";
    FormTester form = tester.newFormTester(formPath);
    form.selectMultiple("choices", new int[] { 2 });

    // Submit ajax form
    tester.executeAjaxEvent(formPath + ":submit", "onclick");
}

From source file:org.xaloon.wicket.plugin.user.admin.panel.UserSecurityPanelTest.java

License:Apache License

/**
 * @throws Exception/*  ww  w.  ja  v  a 2  s . c o m*/
 */
@Test
public void testPanelRolesAssign() throws Exception {
    // Add mocked invocations

    // return available roles
    Mockito.when(roleService.getAuthorities(0, -1)).thenReturn(availableRoles);

    // return given roles to user
    final List<SecurityRole> givenRoles = new ArrayList<SecurityRole>();
    givenRoles.add(newRole(777L, "fake-role"));
    Mockito.when(details.getRoles()).thenReturn(givenRoles);

    Mockito.when(roleService.assignAuthorities((UserDetails) Matchers.anyObject(),
            Matchers.anyListOf(SecurityRole.class))).thenAnswer(new Answer<SecurityGroup>() {

                @SuppressWarnings("unchecked")
                @Override
                public SecurityGroup answer(InvocationOnMock invocation) throws Throwable {
                    Object[] args = invocation.getArguments();
                    List<SecurityRole> selections = (List<SecurityRole>) args[1];
                    Assert.assertEquals(1, selections.size());
                    Assert.assertEquals(availableRoles.get(2), selections.get(0));
                    return null;
                }
            });

    // Start the test

    // Start the panel before each test
    PageParameters params = new PageParameters();
    params.add(UsersPage.PARAM_USER_ID, "demo");
    tester.startComponentInPage(new UserSecurityPanel("id", params));
    tester.assertNoErrorMessage();
    tester.assertRenderedPage(BaseWicketTester.StartComponentInPage.class);

    Assert.assertNotNull(tester.getTagByWicketId("role-admin"));
    Assert.assertNotNull(tester.getTagByWicketId("link-assign-entities"));

    // Open the modal window
    tester.clickLink("id:role-container:role-admin:choice-management:link-assign-entities");
    tester.assertNoErrorMessage();

    ModalWindow modalWindow = (ModalWindow) tester.getComponentFromLastRenderedPage(
            "id:role-container:role-admin:choice-management:modal-assign-entities");
    String modalPath = modalWindow.getPageRelativePath() + ":" + modalWindow.getContentId();
    Assert.assertTrue(modalWindow.isVisible());

    // Submit the form
    String formPath = modalPath + ":form";
    FormTester form = tester.newFormTester(formPath);
    form.selectMultiple("choices", new int[] { 2 });

    // Submit ajax form
    tester.executeAjaxEvent(formPath + ":submit", "onclick");
}

From source file:org.xaloon.wicket.plugin.user.admin.panel.UserSecurityPanelTest.java

License:Apache License

/**
 * @throws Exception/*  w  w w  .  j a va2s .co  m*/
 */
@Test
public void testPanelGroupsAssign() throws Exception {
    // Add mocked invocations

    // return available groups
    Mockito.when(groupService.getAuthorities(0, -1)).thenReturn(availableGroups);

    // return given groups to user
    final List<SecurityGroup> givenGroups = new ArrayList<SecurityGroup>();
    givenGroups.add(newGroup(777L, "fake-group"));
    Mockito.when(details.getGroups()).thenReturn(givenGroups);

    Mockito.when(groupService.assignAuthorities((UserDetails) Matchers.anyObject(),
            Matchers.anyListOf(SecurityGroup.class))).thenAnswer(new Answer<SecurityGroup>() {

                @SuppressWarnings("unchecked")
                @Override
                public SecurityGroup answer(InvocationOnMock invocation) throws Throwable {
                    Object[] args = invocation.getArguments();
                    List<SecurityGroup> selections = (List<SecurityGroup>) args[1];
                    Assert.assertEquals(1, selections.size());
                    Assert.assertEquals(availableGroups.get(2), selections.get(0));
                    return null;
                }
            });

    // Start the test

    // Start the panel before each test
    PageParameters params = new PageParameters();
    params.add(UsersPage.PARAM_USER_ID, "demo");
    tester.startComponentInPage(new UserSecurityPanel("id", params));
    tester.assertNoErrorMessage();
    tester.assertRenderedPage(BaseWicketTester.StartComponentInPage.class);

    Assert.assertNotNull(tester.getTagByWicketId("group-admin"));
    Assert.assertNotNull(tester.getTagByWicketId("link-assign-entities"));

    // Open the modal window
    tester.clickLink("id:group-container:group-admin:choice-management:link-assign-entities");
    tester.assertNoErrorMessage();

    ModalWindow modalWindow = (ModalWindow) tester.getComponentFromLastRenderedPage(
            "id:group-container:group-admin:choice-management:modal-assign-entities");
    String modalPath = modalWindow.getPageRelativePath() + ":" + modalWindow.getContentId();
    Assert.assertTrue(modalWindow.isVisible());

    // Submit the form
    String formPath = modalPath + ":form";
    FormTester form = tester.newFormTester(formPath);
    form.selectMultiple("choices", new int[] { 2 });

    // Submit ajax form
    tester.executeAjaxEvent(formPath + ":submit", "onclick");
}