use of au.gov.asd.tac.constellation.graph.ReadableGraph in project constellation by constellation-app.
the class DataAccessUtilitiesNGTest method loadDataAccessState.
@Test
public void loadDataAccessState() {
// Create current data access view state and set some parameters
// The code currenly only looks at the first tab so parameter2
// value will be ignored
final DataAccessState currentState = new DataAccessState();
currentState.newTab();
currentState.add("parameter1", "parameter1_new_value");
currentState.newTab();
currentState.add("parameter2", "parameter2_new_value");
// mock graph
final Graph graph = mock(Graph.class);
final ReadableGraph rGraph = mock(ReadableGraph.class);
when(graph.getReadableGraph()).thenReturn(rGraph);
// mock data access state attribute in graph
when(rGraph.getAttribute(GraphElementType.META, "dataaccess_state")).thenReturn(2);
when(rGraph.getObjectValue(2, 0)).thenReturn(currentState);
// mock tab pane
final DataAccessPane dataAccessPane = mock(DataAccessPane.class);
final DataAccessTabPane dataAccessTabPane = mock(DataAccessTabPane.class);
final TabPane tabPane = mock(TabPane.class);
final Tab currentTab = mock(Tab.class);
when(dataAccessPane.getDataAccessTabPane()).thenReturn(dataAccessTabPane);
when(dataAccessTabPane.getCurrentTab()).thenReturn(currentTab);
when(dataAccessTabPane.getTabPane()).thenReturn(tabPane);
when(tabPane.getTabs()).thenReturn(FXCollections.observableArrayList(currentTab, mock(Tab.class)));
try (final MockedStatic<DataAccessTabPane> daTabPaneMockedStatic = Mockito.mockStatic(DataAccessTabPane.class)) {
final QueryPhasePane queryPhasePane = mock(QueryPhasePane.class);
daTabPaneMockedStatic.when(() -> DataAccessTabPane.getQueryPhasePane(currentTab)).thenReturn(queryPhasePane);
final GlobalParametersPane globalParametersPane = mock(GlobalParametersPane.class);
final PluginParameters globalPluginParameters = mock(PluginParameters.class);
final PluginParameter pluginParameter1 = mock(PluginParameter.class);
final PluginParameter pluginParameter2 = mock(PluginParameter.class);
when(queryPhasePane.getGlobalParametersPane()).thenReturn(globalParametersPane);
when(globalParametersPane.getParams()).thenReturn(globalPluginParameters);
when(globalPluginParameters.getParameters()).thenReturn(Map.of("parameter1", pluginParameter1, "parameter2", pluginParameter2));
DataAccessUtilities.loadDataAccessState(dataAccessPane, graph);
verify(pluginParameter1).setStringValue("parameter1_new_value");
verify(pluginParameter2, never()).setStringValue(anyString());
verify(rGraph).release();
}
}
use of au.gov.asd.tac.constellation.graph.ReadableGraph in project constellation by constellation-app.
the class DataAccessUtilitiesNGTest method loadDataAccessState_empty_state.
@Test
public void loadDataAccessState_empty_state() {
// mock graph
final Graph graph = mock(Graph.class);
final ReadableGraph rGraph = mock(ReadableGraph.class);
when(graph.getReadableGraph()).thenReturn(rGraph);
// mock data access state attribute in graph
when(rGraph.getAttribute(GraphElementType.META, "dataaccess_state")).thenReturn(2);
when(rGraph.getObjectValue(2, 0)).thenReturn(new DataAccessState());
// mock tab pane
final DataAccessPane dataAccessPane = mock(DataAccessPane.class);
final DataAccessTabPane dataAccessTabPane = mock(DataAccessTabPane.class);
final Tab currentTab = mock(Tab.class);
when(dataAccessPane.getDataAccessTabPane()).thenReturn(dataAccessTabPane);
when(dataAccessTabPane.getCurrentTab()).thenReturn(currentTab);
try (final MockedStatic<DataAccessTabPane> daTabPaneMockedStatic = Mockito.mockStatic(DataAccessTabPane.class)) {
DataAccessUtilities.loadDataAccessState(dataAccessPane, graph);
daTabPaneMockedStatic.verifyNoInteractions();
verify(rGraph).release();
}
}
use of au.gov.asd.tac.constellation.graph.ReadableGraph in project constellation by constellation-app.
the class QueryServices method advancedQuery.
/**
* Performs an 'advanced query'.
* <p>
* This method determines the maximum number of needed threads, and assigns
* a work package to each thread. Upon all child threads completing their
* queries, it joins and returns the results.
*
* @param rules List of individual rules to perform queries for.
* @param type The <code>GraphElementType</code> to perform a quick query
* on.
* @param isAnd <code>true</code> to perform 'AND' based search,
* <code>false</code> to perform 'OR'.
*
* @return List of <code>FindResults</code>, with each
* <code>FindResult</code> representing an individual positive result to the
* query.
*
* @see ArrayList
* @see FindResult
* @see GraphElementType
*/
public List<FindResult> advancedQuery(final ArrayList<FindRule> rules, final GraphElementType type, final boolean isAnd) {
final ReadableGraph rg = graph.getReadableGraph();
try {
results = new boolean[type.getElementCount(rg)];
Arrays.fill(results, isAnd);
final int numThreadsNeeded = Math.min(AVAILABLE_THREADS, rules.size());
final CyclicBarrier barrier = new CyclicBarrier(numThreadsNeeded + 1);
try {
// Determine the workpackage for each thread. Each 'package' is comprised of 1 or more FindRules.
final List<List<FindRule>> workPackage = new ArrayList<>(numThreadsNeeded);
for (int i = 0; i < numThreadsNeeded; i++) {
workPackage.add(new ArrayList<>());
}
for (int i = 0; i < rules.size(); i++) {
final int allocateTo = i % numThreadsNeeded;
workPackage.get(allocateTo).add(rules.get(i));
}
// Allocate work and start threads:
for (int i = 0; i < numThreadsNeeded; i++) {
final ThreadedFind tf = new ThreadedFind(rg, barrier, this, type, workPackage.get(i), isAnd, i);
final Thread t = new Thread(tf);
t.start();
}
} finally {
// Await the conclusion of all threads:
try {
barrier.await();
} catch (final InterruptedException ex) {
LOGGER.log(Level.SEVERE, THREAD_INTERRUPTED, ex);
Thread.currentThread().interrupt();
} catch (final BrokenBarrierException ex) {
LOGGER.log(Level.SEVERE, ex.getLocalizedMessage(), ex);
}
}
// Determine the actual results from the bitset:
for (int i = 0; i < results.length; i++) {
if (results[i]) {
// Construct a new FindResult and store the id and type of the found element.
final int id = type.getElement(rg, i);
final long uid = type.getUID(rg, id);
final FindResult fr = new FindResult(id, uid, type);
findResults.add(fr);
}
}
return findResults;
} finally {
rg.release();
}
}
use of au.gov.asd.tac.constellation.graph.ReadableGraph in project constellation by constellation-app.
the class BasicFindPluginNGTest method getAttributes.
/**
* Used to convert the string variant of attributes to the Attribute object
*
* @return the list of Attribute objects
*/
private ArrayList<Attribute> getAttributes() {
final FindViewTopComponent findViewTopComponent = mock(FindViewTopComponent.class);
FindViewController instance = FindViewController.getDefault().init(findViewTopComponent);
final GraphManager gm = Mockito.mock(GraphManager.class);
when(gm.getAllGraphs()).thenReturn(graphMap);
ArrayList<Attribute> attributes = new ArrayList<>();
try (MockedStatic<GraphManager> mockedStatic = Mockito.mockStatic(GraphManager.class)) {
mockedStatic.when(() -> GraphManager.getDefault()).thenReturn(gm);
GraphElementType type = GraphElementType.VERTEX;
List<String> result = instance.populateAttributes(type, attributes, Long.MIN_VALUE);
ReadableGraph rg = graph.getReadableGraph();
for (int i = 0; i < result.size(); i++) {
int attributeInt = rg.getAttribute(type, result.get(i));
GraphAttribute ga = new GraphAttribute(rg, attributeInt);
if (ga.getAttributeType().equals("string")) {
attributes.add(new GraphAttribute(rg, attributeInt));
System.out.println(attributes.get(i).getName() + " = attribute name");
}
}
rg.close();
}
return attributes;
}
use of au.gov.asd.tac.constellation.graph.ReadableGraph in project constellation by constellation-app.
the class ReplacePluginNGTest method getAttributes.
/**
* Used to convert the string variant of attributes to the Attribute object
*
* @return the list of Attribute objects
*/
private ArrayList<Attribute> getAttributes() {
final FindViewTopComponent findViewTopComponent = mock(FindViewTopComponent.class);
FindViewController instance = FindViewController.getDefault().init(findViewTopComponent);
final GraphManager gm = Mockito.mock(GraphManager.class);
when(gm.getAllGraphs()).thenReturn(graphMap);
ArrayList<Attribute> attributes = new ArrayList<>();
try (MockedStatic<GraphManager> mockedStatic = Mockito.mockStatic(GraphManager.class)) {
mockedStatic.when(() -> GraphManager.getDefault()).thenReturn(gm);
GraphElementType type = GraphElementType.VERTEX;
List<String> result = instance.populateAttributes(type, attributes, Long.MIN_VALUE);
ReadableGraph rg = graph.getReadableGraph();
for (int i = 0; i < result.size(); i++) {
int attributeInt = rg.getAttribute(type, result.get(i));
GraphAttribute ga = new GraphAttribute(rg, attributeInt);
if (ga.getAttributeType().equals("string")) {
attributes.add(new GraphAttribute(rg, attributeInt));
}
}
rg.close();
}
return attributes;
}
Aggregations