Search in sources :

Example 26 with UsersTableModel

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

the class UsersTableModelUnitTest method shouldRemoveTableModelListeners.

@Test
void shouldRemoveTableModelListeners() {
    // Given
    TableModelListener listener = createTestTableModelListener();
    UsersTableModel usersTableModel = new UsersTableModel();
    usersTableModel.addTableModelListener(listener);
    // When
    usersTableModel.removeTableModelListener(listener);
    // Then
    assertThat(usersTableModel.getTableModelListeners(), is(emptyArray()));
}
Also used : TableModelListener(javax.swing.event.TableModelListener) UsersTableModel(org.zaproxy.zap.extension.users.UsersTableModel) Test(org.junit.jupiter.api.Test)

Example 27 with UsersTableModel

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

the class UsersTableModelUnitTest method shouldReturnUserEnabledStateFromFirstColumn.

@Test
void shouldReturnUserEnabledStateFromFirstColumn() {
    // Given
    List<User> usersList = new ArrayList<>();
    usersList.add(createUser());
    usersList.add(createEnabledUser());
    // When
    UsersTableModel usersTableModel = new UsersTableModel(usersList);
    // Then
    assertTrue(usersTableModel.getColumnClass(0) == Boolean.class);
    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 28 with UsersTableModel

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

the class UsersTableModelUnitTest method shouldEnableAllUsers.

@Test
void shouldEnableAllUsers() {
    // 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(true);
    // Then
    assertThat(usersTableModel.getValueAt(0, 0), is(equalTo((Object) true)));
    assertThat(usersTableModel.getValueAt(1, 0), is(equalTo((Object) true)));
    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 29 with UsersTableModel

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

the class UsersTableModelUnitTest method shouldSetUsers.

@Test
void shouldSetUsers() {
    // Given
    TestTableModelListener listener = createTestTableModelListener();
    UsersTableModel usersTableModel = new UsersTableModel();
    usersTableModel.addTableModelListener(listener);
    List<User> usersList = new ArrayList<>();
    User user = createUser();
    usersList.add(user);
    // When
    usersTableModel.setUsers(usersList);
    // 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.isDataChanged(), is(equalTo(true)));
}
Also used : UsersTableModel(org.zaproxy.zap.extension.users.UsersTableModel) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Example 30 with UsersTableModel

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

the class UsersTableModelUnitTest method shouldBeEditableJustTheFirstColumnEvenIfHasNoUsers.

@Test
void shouldBeEditableJustTheFirstColumnEvenIfHasNoUsers() {
    // Given
    UsersTableModel usersTableModel = new UsersTableModel();
    // When / Then
    assertThat(usersTableModel.isCellEditable(0, 0), is(equalTo(true)));
    assertThat(usersTableModel.isCellEditable(0, 1), is(equalTo(false)));
}
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