Search in sources :

Example 31 with UsersTableModel

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

the class UsersTableModelUnitTest method shouldReturnUserIdFromSecondColumn.

@Test
void shouldReturnUserIdFromSecondColumn() {
    // Given
    List<User> usersList = new ArrayList<>();
    User user1 = createUser();
    int user1Id = user1.getId();
    usersList.add(user1);
    User user2 = createUser();
    int user2Id = user2.getId();
    usersList.add(user2);
    // When
    UsersTableModel usersTableModel = new UsersTableModel(usersList);
    // Then
    assertTrue(usersTableModel.getColumnClass(1) == Integer.class);
    assertThat(usersTableModel.getValueAt(0, 1), is(equalTo((Object) user1Id)));
    assertThat(usersTableModel.getValueAt(1, 1), is(equalTo((Object) user2Id)));
}
Also used : ArrayList(java.util.ArrayList) UsersTableModel(org.zaproxy.zap.extension.users.UsersTableModel) Test(org.junit.jupiter.api.Test)

Example 32 with UsersTableModel

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

the class UsersTableModelUnitTest method shouldFailToRemoveNonExistingElement.

@Test
void shouldFailToRemoveNonExistingElement() {
    // Given
    UsersTableModel usersTableModel = new UsersTableModel();
    // When / Then
    assertThrows(IndexOutOfBoundsException.class, () -> usersTableModel.removeElement(1));
}
Also used : UsersTableModel(org.zaproxy.zap.extension.users.UsersTableModel) Test(org.junit.jupiter.api.Test)

Example 33 with UsersTableModel

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

the class UsersTableModelUnitTest method shouldAddElement.

@Test
void shouldAddElement() {
    // Given
    TestTableModelListener listener = createTestTableModelListener();
    UsersTableModel usersTableModel = new UsersTableModel();
    usersTableModel.addTableModelListener(listener);
    User user = createUser();
    // When
    usersTableModel.addElement(user);
    // 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(listener.getNumberOfEvents(), is(equalTo(1)));
    assertThat(listener.isRowInserted(0), is(equalTo(true)));
}
Also used : UsersTableModel(org.zaproxy.zap.extension.users.UsersTableModel) Test(org.junit.jupiter.api.Test)

Example 34 with UsersTableModel

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

the class UsersTableModelUnitTest method shouldCreateInstanceWithUsersList.

@Test
void shouldCreateInstanceWithUsersList() {
    // Given
    List<User> usersList = new ArrayList<>();
    usersList.add(createUser());
    usersList.add(createUser());
    usersList.add(createUser());
    // When
    UsersTableModel usersTableModel = new UsersTableModel(usersList);
    // Then
    assertThat(usersTableModel.getRowCount(), is(equalTo(usersList.size())));
    assertThat(usersTableModel.getUsers(), is(equalTo(usersList)));
    assertThat(usersTableModel.getElements(), is(equalTo(usersList)));
}
Also used : ArrayList(java.util.ArrayList) UsersTableModel(org.zaproxy.zap.extension.users.UsersTableModel) Test(org.junit.jupiter.api.Test)

Example 35 with UsersTableModel

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

the class UsersListModelUnitTest method shouldReflectAddedTableUserAndSelectFirstTableUserIfNoneSelected.

// TODO test tableChanged
@Test
void shouldReflectAddedTableUserAndSelectFirstTableUserIfNoneSelected() {
    // Given
    UsersTableModel tableModel = createUsersTableModel(2);
    UsersListModel usersListModel = new UsersListModel(tableModel);
    TestListDataListener listener = createTestListDataListener();
    usersListModel.addListDataListener(listener);
    User user = createUser();
    // When
    tableModel.addElement(user);
    // Then
    assertThat(usersListModel.getSize(), is(equalTo(3)));
    assertThat(usersListModel.getElementAt(2), is(equalTo((Object) user)));
    assertThat(usersListModel.getSelectedItem(), is(equalTo((Object) tableModel.getUsers().get(0))));
    assertThat(listener.getNumberOfEvents(), is(equalTo(2)));
    assertThat(listener.isListItemAdded(2), 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)

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