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