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)));
}
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));
}
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)));
}
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)));
}
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)));
}
Aggregations