use of au.gov.asd.tac.constellation.views.tableview.api.UserTablePreferences in project constellation by constellation-app.
the class TableViewPreferencesIoProviderNGTest method getPreferencesOldVersionWithEmptyEmptySort.
@Test
public void getPreferencesOldVersionWithEmptyEmptySort() throws IOException {
final ObjectMapper objectMapper = new ObjectMapper();
final List<UserTablePreferences> tablePrefs = objectMapper.readValue(new FileInputStream(getClass().getResource("resources/old-preferences.json").getPath()), new TypeReference<List<UserTablePreferences>>() {
});
jsonIOStaticMock.when(() -> JsonIO.loadJsonPreferences(eq(Optional.of("TableViewPreferences")), eq(Optional.of("vertex-")), any(TypeReference.class))).thenReturn(tablePrefs);
final UserTablePreferences tablePreferences = TableViewPreferencesIoProvider.getPreferences(GraphElementType.VERTEX);
final UserTablePreferences expected = new UserTablePreferences();
expected.setColumnOrder(List.of("ABC", "DEF"));
expected.setSortByColumn(ImmutablePair.of("", TableColumn.SortType.ASCENDING));
expected.setMaxRowsPerPage(500);
assertEquals(expected, tablePreferences);
}
use of au.gov.asd.tac.constellation.views.tableview.api.UserTablePreferences in project constellation by constellation-app.
the class PreferenceMenuNGTest method verifySavePreferencesAction.
/**
* Verifies that when the save userTablePreferences button is pressed then
* it will call out to
* {@link TableViewPreferencesIoProvider#savePreferences(GraphElementType, TableView, int)}.
* If certain values are not set, then it will not save the preferences and
* just return.
* <p/>
* There is a lot of mock setup for this so the code tries to re-use as much
* of that as possible which is why its a little weird.
*
* @param savePreferencesMenu the save userTablePreferences menu
* @param isTableViewColumnsEmpty true if when
* {@link TableView#getColumns()} is called it should return an empty list,
* false otherwise
* @param isActivGraphNull true if when
* {@link GraphManager#getActiveGraph()} is called it should return null,
* false otherwise
* @param expectSavePrefsCalled true if it is expected that
* {@link TableViewPreferencesIoProvider#savePreferences(GraphElementType, TableView, int)}
* should have been called, false otherwise
*/
private void verifySavePreferencesAction(final MenuItem savePreferencesMenu, final boolean isTableViewColumnsEmpty, final boolean isActivGraphNull, final boolean expectSavePrefsCalled) {
try (final MockedStatic<TableViewPreferencesIoProvider> tablePrefsIOUtilsMockedStatic = Mockito.mockStatic(TableViewPreferencesIoProvider.class);
final MockedStatic<GraphManager> graphManagerMockedStatic = Mockito.mockStatic(GraphManager.class)) {
final TableView<ObservableList<String>> tableView = mock(TableView.class);
when(table.getTableView()).thenReturn(tableView);
final TableViewState tableViewState = new TableViewState();
tableViewState.setElementType(GraphElementType.VERTEX);
when(tableViewTopComponent.getCurrentState()).thenReturn(tableViewState);
final UserTablePreferences userTablePreferences = new UserTablePreferences();
userTablePreferences.setMaxRowsPerPage(42);
when(activeTableReference.getUserTablePreferences()).thenReturn(userTablePreferences);
final GraphManager graphManager = mock(GraphManager.class);
graphManagerMockedStatic.when(GraphManager::getDefault).thenReturn(graphManager);
final Graph graph = mock(Graph.class);
final ActionEvent actionEvent = mock(ActionEvent.class);
if (isTableViewColumnsEmpty) {
when(tableView.getColumns()).thenReturn(FXCollections.observableArrayList());
} else {
when(tableView.getColumns()).thenReturn(FXCollections.observableArrayList(mock(TableColumn.class)));
}
if (isActivGraphNull) {
when(graphManager.getActiveGraph()).thenReturn(null);
} else {
when(graphManager.getActiveGraph()).thenReturn(graph);
}
savePreferencesMenu.getOnAction().handle(actionEvent);
if (expectSavePrefsCalled) {
tablePrefsIOUtilsMockedStatic.verify(() -> TableViewPreferencesIoProvider.savePreferences(GraphElementType.VERTEX, tableView, 42));
} else {
tablePrefsIOUtilsMockedStatic.verifyNoInteractions();
}
verify(actionEvent).consume();
}
}
use of au.gov.asd.tac.constellation.views.tableview.api.UserTablePreferences in project constellation by constellation-app.
the class PreferenceMenuNGTest method loadPreferences.
@Test
public void loadPreferences() {
try (final MockedStatic<TableViewPreferencesIoProvider> tablePrefIOUtilsMockedStatic = Mockito.mockStatic(TableViewPreferencesIoProvider.class)) {
final TableViewState tableViewState = new TableViewState();
tableViewState.setElementType(GraphElementType.VERTEX);
final Graph graph = mock(Graph.class);
when(tableViewTopComponent.getCurrentState()).thenReturn(tableViewState);
when(tableViewTopComponent.getCurrentGraph()).thenReturn(graph);
// These are the existing table userTablePreferences
final UserTablePreferences currentTablePreferences = new UserTablePreferences();
currentTablePreferences.setMaxRowsPerPage(42);
// There are 4 columns in the table. Set them up and all required variables
// that describe them
when(activeTableReference.getUserTablePreferences()).thenReturn(currentTablePreferences);
final TableView<ObservableList<String>> tableView = mock(TableView.class);
when(table.getTableView()).thenReturn(tableView);
final TableColumn<ObservableList<String>, String> column1 = mock(TableColumn.class);
final TableColumn<ObservableList<String>, String> column2 = mock(TableColumn.class);
final TableColumn<ObservableList<String>, String> column3 = mock(TableColumn.class);
final TableColumn<ObservableList<String>, String> column4 = mock(TableColumn.class);
when(column1.getText()).thenReturn("Column1");
when(column2.getText()).thenReturn("Column2");
when(column3.getText()).thenReturn("Column3");
when(column4.getText()).thenReturn("Column4");
when(tableView.getColumns()).thenReturn(FXCollections.observableList(List.of(column1, column2, column3, column4)));
final Attribute attribute1 = mock(Attribute.class);
final Attribute attribute2 = mock(Attribute.class);
final Attribute attribute3 = mock(Attribute.class);
final Attribute attribute4 = mock(Attribute.class);
final CopyOnWriteArrayList<Column> columnIndex = new CopyOnWriteArrayList<>();
columnIndex.add(new Column("type1", attribute1, column1));
columnIndex.add(new Column("type2", attribute2, column2));
columnIndex.add(new Column("type3", attribute3, column3));
columnIndex.add(new Column("type4", attribute4, column4));
when(table.getColumnIndex()).thenReturn(columnIndex);
// The loaded userTablePreferences specifies 3 of the 4 columns in the table
final UserTablePreferences loadedTablePreferences = new UserTablePreferences();
loadedTablePreferences.setColumnOrder(List.of("Column1", "Column2", "Column4"));
loadedTablePreferences.setSortByColumn(ImmutablePair.of("Column2", TableColumn.SortType.DESCENDING));
loadedTablePreferences.setMaxRowsPerPage(150);
when(activeTableReference.updateVisibleColumns(any(Graph.class), any(TableViewState.class), any(List.class), eq(UpdateMethod.REPLACE))).thenReturn(CompletableFuture.completedFuture(null));
// Create page size option menu items, with one matching the pages size
// in the loaded prefs above
final ToggleGroup toggleGroup = mock(ToggleGroup.class);
final RadioMenuItem pageSizeOption1 = mock(RadioMenuItem.class);
final RadioMenuItem pageSizeOption2 = mock(RadioMenuItem.class);
when(pageSizeOption1.getText()).thenReturn("100");
when(pageSizeOption2.getText()).thenReturn("150");
when(preferencesMenu.getPageSizeToggle()).thenReturn(toggleGroup);
when(toggleGroup.getToggles()).thenReturn(FXCollections.observableList(List.of(pageSizeOption1, pageSizeOption2)));
// Return the loaded userTablePreferences when the load call is made
tablePrefIOUtilsMockedStatic.when(() -> TableViewPreferencesIoProvider.getPreferences(GraphElementType.VERTEX)).thenReturn(loadedTablePreferences);
// Start the test
preferencesMenu.loadPreferences();
verify(column1).setVisible(true);
verify(column2).setVisible(true);
verify(column3, times(0)).setVisible(anyBoolean());
verify(column4).setVisible(true);
verify(activeTableReference).saveSortDetails("Column2", TableColumn.SortType.DESCENDING);
verify(activeTableReference).updateVisibleColumns(same(graph), same(tableViewState), eq(List.of(Tuple.create("type1", attribute1), Tuple.create("type2", attribute2), Tuple.create("type4", attribute4))), eq(UpdateMethod.REPLACE));
verify(pageSizeOption1, times(0)).setSelected(true);
verify(pageSizeOption2, times(1)).setSelected(true);
assertEquals(150, currentTablePreferences.getMaxRowsPerPage());
}
}
use of au.gov.asd.tac.constellation.views.tableview.api.UserTablePreferences in project constellation by constellation-app.
the class PreferenceMenuNGTest method loadPreferencesColumnOrderIsEmpty.
@Test
public void loadPreferencesColumnOrderIsEmpty() {
try (final MockedStatic<TableViewPreferencesIoProvider> tablePrefIOUtilsMockedStatic = Mockito.mockStatic(TableViewPreferencesIoProvider.class)) {
final TableViewState tableViewState = new TableViewState();
tableViewState.setElementType(GraphElementType.VERTEX);
when(tableViewTopComponent.getCurrentState()).thenReturn(tableViewState);
final UserTablePreferences currentTablePreferences = new UserTablePreferences();
currentTablePreferences.setMaxRowsPerPage(42);
when(activeTableReference.getUserTablePreferences()).thenReturn(currentTablePreferences);
final UserTablePreferences loadedTablePreferences = new UserTablePreferences();
loadedTablePreferences.setColumnOrder(Collections.emptyList());
tablePrefIOUtilsMockedStatic.when(() -> TableViewPreferencesIoProvider.getPreferences(GraphElementType.VERTEX)).thenReturn(loadedTablePreferences);
preferencesMenu.loadPreferences();
verify(activeTableReference, times(0)).saveSortDetails(anyString(), any(TableColumn.SortType.class));
verify(activeTableReference, times(0)).updateVisibleColumns(any(Graph.class), any(TableViewState.class), any(List.class), any(UpdateMethod.class));
}
}
use of au.gov.asd.tac.constellation.views.tableview.api.UserTablePreferences in project constellation by constellation-app.
the class TableViewPreferencesIoProviderNGTest method savePreferences.
@Test
public void savePreferences() throws IOException {
final TableColumn<ObservableList<String>, ? extends Object> column1 = mock(TableColumn.class);
final TableColumn<ObservableList<String>, ? extends Object> column2 = mock(TableColumn.class);
final TableColumn<ObservableList<String>, ? extends Object> column3 = mock(TableColumn.class);
final TableColumn<ObservableList<String>, ? extends Object> column4 = mock(TableColumn.class);
when(column1.isVisible()).thenReturn(true);
when(column1.getText()).thenReturn("ABC");
when(column2.isVisible()).thenReturn(true);
when(column2.getText()).thenReturn("DEF");
when(column2.getSortType()).thenReturn(TableColumn.SortType.ASCENDING);
when(column3.isVisible()).thenReturn(false);
when(column3.getText()).thenReturn("GHI");
when(column4.isVisible()).thenReturn(true);
when(column4.getText()).thenReturn("JKL");
final TableView<ObservableList<String>> tableView = mock(TableView.class);
when(tableView.getColumns()).thenReturn(FXCollections.observableList(List.of(column1, column2, column3, column4)));
when(tableView.getSortOrder()).thenReturn(FXCollections.observableList(List.of(column2)));
TableViewPreferencesIoProvider.savePreferences(GraphElementType.TRANSACTION, tableView, 5);
final ObjectMapper objectMapper = new ObjectMapper();
final List<UserTablePreferences> expectedTablePrefs = objectMapper.readValue(new FileInputStream(getClass().getResource("resources/transaction-preferences.json").getPath()), new TypeReference<List<UserTablePreferences>>() {
});
jsonIOStaticMock.verify(() -> JsonIO.saveJsonPreferences(eq(Optional.of("TableViewPreferences")), eq(Optional.of("transaction-")), eq(expectedTablePrefs)));
}
Aggregations