Search in sources :

Example 16 with UsersTableModel

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

the class UsersTableModelUnitTest method shouldNotChangeUsersEnabledStateIfNonBooleanOrFirstColumn.

@Test
void shouldNotChangeUsersEnabledStateIfNonBooleanOrFirstColumn() {
    // Given
    TestTableModelListener listener = createTestTableModelListener();
    List<User> usersList = new ArrayList<>();
    usersList.add(createUser());
    usersList.add(createEnabledUser());
    UsersTableModel usersTableModel = new UsersTableModel(usersList);
    usersTableModel.addTableModelListener(listener);
    // When
    usersTableModel.setValueAt(15, 0, 0);
    usersTableModel.setValueAt("Some Value", 1, 0);
    usersTableModel.setValueAt(true, 1, 1);
    // Then
    assertThat(listener.getNumberOfEvents(), is(equalTo(0)));
    assertThat(usersTableModel.getValueAt(0, 0), is(equalTo((Object) false)));
    assertThat(usersTableModel.getValueAt(1, 0), is(equalTo((Object) true)));
}
Also used : ArrayList(java.util.ArrayList) UsersTableModel(org.zaproxy.zap.extension.users.UsersTableModel) Test(org.junit.jupiter.api.Test)

Example 17 with UsersTableModel

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

the class UsersTableModelUnitTest method shouldModifyElement.

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

Example 18 with UsersTableModel

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

the class UsersTableModelUnitTest method shouldRemoveAllUsers.

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

Example 19 with UsersTableModel

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

the class UsersTableModelUnitTest method shouldDisableAllUsers.

@Test
void shouldDisableAllUsers() {
    // Given
    TestTableModelListener listener = createTestTableModelListener();
    List<User> usersList = new ArrayList<>();
    usersList.add(createUser());
    usersList.add(createEnabledUser());
    UsersTableModel usersTableModel = new UsersTableModel(usersList);
    usersTableModel.addTableModelListener(listener);
    // When
    usersTableModel.setAllEnabled(false);
    // Then
    assertThat(usersTableModel.getValueAt(0, 0), is(equalTo((Object) false)));
    assertThat(usersTableModel.getValueAt(1, 0), is(equalTo((Object) false)));
    assertThat(listener.getNumberOfEvents(), is(equalTo(1)));
    assertThat(listener.isCellChanged(0, 0), is(equalTo(true)));
    assertThat(listener.isCellChanged(1, 0), is(equalTo(true)));
}
Also used : ArrayList(java.util.ArrayList) UsersTableModel(org.zaproxy.zap.extension.users.UsersTableModel) Test(org.junit.jupiter.api.Test)

Example 20 with UsersTableModel

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

the class UsersTableModelUnitTest method shouldFailToGetValueOfNonExistingRow.

@Test
void shouldFailToGetValueOfNonExistingRow() {
    // Given
    UsersTableModel usersTableModel = new UsersTableModel();
    // When / Then
    assertThrows(IndexOutOfBoundsException.class, () -> usersTableModel.getValueAt(0, 0));
}
Also used : 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