Search in sources :

Example 6 with UsersTableModel

use of org.zaproxy.zap.extension.users.UsersTableModel in project zaproxy by zaproxy.

the class UsersListModelUnitTest method shouldReflectClearedTableUsersAndSelectFirstCustomUser.

@Test
void shouldReflectClearedTableUsersAndSelectFirstCustomUser() {
    // Given
    UsersTableModel tableModel = createUsersTableModel(2);
    UsersListModel usersListModel = new UsersListModel(tableModel);
    usersListModel.setSelectedItem(tableModel.getUsers().get(1));
    User customUser = createUser();
    usersListModel.setCustomUsers(new User[] { customUser, createUser() });
    TestListDataListener listener = createTestListDataListener();
    usersListModel.addListDataListener(listener);
    // When
    tableModel.clear();
    // Then
    assertThat(usersListModel.getSize(), is(equalTo(2)));
    assertThat(usersListModel.getSelectedItem(), is(equalTo((Object) customUser)));
    assertThat(listener.getNumberOfEvents(), is(equalTo(2)));
    assertThat(listener.isListItemChanged(0), is(equalTo(true)));
    assertThat(listener.isListItemChanged(1), is(equalTo(true)));
    assertThat(listener.isListItemChanged(-1), is(equalTo(true)));
}
Also used : User(org.zaproxy.zap.users.User) UsersTableModel(org.zaproxy.zap.extension.users.UsersTableModel) Test(org.junit.jupiter.api.Test)

Example 7 with UsersTableModel

use of org.zaproxy.zap.extension.users.UsersTableModel in project zaproxy by zaproxy.

the class UsersListModelUnitTest method shouldGetTableUsers.

@Test
void shouldGetTableUsers() {
    // Given
    UsersTableModel tableModel = createUsersTableModel(2);
    UsersListModel usersListModel = new UsersListModel(tableModel);
    // When
    User user = usersListModel.getElementAt(0);
    // Then
    assertThat(user, is(equalTo(tableModel.getUsers().get(0))));
}
Also used : User(org.zaproxy.zap.users.User) UsersTableModel(org.zaproxy.zap.extension.users.UsersTableModel) Test(org.junit.jupiter.api.Test)

Example 8 with UsersTableModel

use of org.zaproxy.zap.extension.users.UsersTableModel in project zaproxy by zaproxy.

the class UsersListModelUnitTest method shouldFallbackToFirstExistingUserIfSetSelectedInternalUserIsNotFound.

@Test
void shouldFallbackToFirstExistingUserIfSetSelectedInternalUserIsNotFound() {
    // Given
    UsersTableModel tableModel = createUsersTableModel(2);
    UsersListModel usersListModel = new UsersListModel(tableModel);
    TestListDataListener listener = createTestListDataListener();
    usersListModel.addListDataListener(listener);
    // When
    usersListModel.setSelectedInternalItem(createUser());
    // Then
    assertThat(usersListModel.getSelectedItem(), is(equalTo((Object) tableModel.getUsers().get(0))));
    assertThat(listener.getNumberOfEvents(), is(equalTo(1)));
    assertThat(listener.isListItemChanged(-1), is(equalTo(true)));
}
Also used : UsersTableModel(org.zaproxy.zap.extension.users.UsersTableModel) Test(org.junit.jupiter.api.Test)

Example 9 with UsersTableModel

use of org.zaproxy.zap.extension.users.UsersTableModel in project zaproxy by zaproxy.

the class UsersListModelUnitTest method shouldReflectClearedTableUsersAndRemoveSelectionOfClearedUser.

@Test
void shouldReflectClearedTableUsersAndRemoveSelectionOfClearedUser() {
    // Given
    UsersTableModel tableModel = createUsersTableModel(2);
    UsersListModel usersListModel = new UsersListModel(tableModel);
    usersListModel.setSelectedItem(tableModel.getUsers().get(1));
    TestListDataListener listener = createTestListDataListener();
    usersListModel.addListDataListener(listener);
    // When
    tableModel.clear();
    // Then
    assertThat(usersListModel.getSize(), is(equalTo(0)));
    assertThat(usersListModel.getSelectedItem(), is(nullValue()));
    assertThat(listener.getNumberOfEvents(), is(equalTo(2)));
    assertThat(listener.isListItemChanged(0), is(equalTo(true)));
    assertThat(listener.isListItemChanged(1), is(equalTo(true)));
    assertThat(listener.isListItemChanged(-1), is(equalTo(true)));
}
Also used : UsersTableModel(org.zaproxy.zap.extension.users.UsersTableModel) Test(org.junit.jupiter.api.Test)

Example 10 with UsersTableModel

use of org.zaproxy.zap.extension.users.UsersTableModel in project zaproxy by zaproxy.

the class UsersTableModelUnitTest method shouldRemoveElement.

@Test
void shouldRemoveElement() {
    // Given
    TestTableModelListener listener = createTestTableModelListener();
    List<User> usersList = new ArrayList<>();
    User user = createUser();
    usersList.add(user);
    usersList.add(createEnabledUser());
    UsersTableModel usersTableModel = new UsersTableModel(usersList);
    usersTableModel.addTableModelListener(listener);
    // When
    usersTableModel.removeElement(1);
    // Then
    assertThat(usersTableModel.getRowCount(), is(equalTo(1)));
    assertThat(usersTableModel.getElements().size(), is(equalTo(1)));
    assertThat(usersTableModel.getElements().get(0), is(equalTo(user)));
    assertThat(usersTableModel.getElement(0), is(equalTo(user)));
    assertThat(usersTableModel.getUsers().size(), is(equalTo(1)));
    assertThat(usersTableModel.getUsers().get(0), is(equalTo(user)));
    assertThat(listener.getNumberOfEvents(), is(equalTo(1)));
    assertThat(listener.isRowRemoved(1), is(equalTo(true)));
}
Also used : ArrayList(java.util.ArrayList) UsersTableModel(org.zaproxy.zap.extension.users.UsersTableModel) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)49 UsersTableModel (org.zaproxy.zap.extension.users.UsersTableModel)49 ArrayList (java.util.ArrayList)15 User (org.zaproxy.zap.users.User)8 TableModelListener (javax.swing.event.TableModelListener)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1