use of au.gov.asd.tac.constellation.views.dataaccess.plugins.DataAccessPluginType in project constellation by constellation-app.
the class DataAccessPaneStateNGTest method dataAccessPluginComparator.
@Test
public void dataAccessPluginComparator() {
try (final MockedStatic<DataAccessPluginType> dataAccessPluginTypeMockedStatic = Mockito.mockStatic(DataAccessPluginType.class)) {
dataAccessPluginTypeMockedStatic.when(DataAccessPluginType::getTypeWithPosition).thenReturn(Map.of("type1", 1, "type2", 2, "type3", 2, "type4", 3));
final DataAccessPaneState.DataAccessPluginComparator comparator = new DataAccessPaneState.DataAccessPluginComparator();
final DataAccessPlugin plugin1 = mock(DataAccessPlugin.class);
final DataAccessPlugin plugin2 = mock(DataAccessPlugin.class);
// TYPE POSITION EQUAL
when(plugin1.getType()).thenReturn("type2");
when(plugin2.getType()).thenReturn("type3");
when(plugin1.getPosition()).thenReturn(1);
when(plugin2.getPosition()).thenReturn(2);
assertTrue(comparator.compare(plugin1, plugin2) < 0);
when(plugin1.getPosition()).thenReturn(2);
when(plugin2.getPosition()).thenReturn(1);
assertTrue(comparator.compare(plugin1, plugin2) > 0);
when(plugin1.getPosition()).thenReturn(1);
when(plugin2.getPosition()).thenReturn(1);
assertTrue(comparator.compare(plugin1, plugin2) == 0);
// TYPE POSITION NOT EQUAL
when(plugin1.getType()).thenReturn("type1");
when(plugin2.getType()).thenReturn("type4");
assertTrue(comparator.compare(plugin1, plugin2) < 0);
when(plugin1.getType()).thenReturn("type4");
when(plugin2.getType()).thenReturn("type1");
assertTrue(comparator.compare(plugin1, plugin2) > 0);
}
}
use of au.gov.asd.tac.constellation.views.dataaccess.plugins.DataAccessPluginType in project constellation by constellation-app.
the class LookupPluginsTaskNGTest method get.
@Test
public void get() {
try (final MockedStatic<DataAccessPluginType> dapTypeMockedStatic = Mockito.mockStatic(DataAccessPluginType.class);
final MockedStatic<Lookup> lookupMockedStatic = Mockito.mockStatic(Lookup.class)) {
dapTypeMockedStatic.when(DataAccessPluginType::getTypes).thenReturn(List.of(DataAccessPluginCoreType.DEVELOPER, DataAccessPluginCoreType.UTILITY));
final Lookup defaultLookup = mock(Lookup.class);
lookupMockedStatic.when(Lookup::getDefault).thenReturn(defaultLookup);
// All of the mock creations are being coupled with an interface to
// force the getClass() call on them to be different
// Plugin 1 is disabled and so will be ignored
final DataAccessPlugin plugin1 = mock(DataAccessPlugin.class, withSettings().extraInterfaces(DataAccessPluginType.class));
when(plugin1.isEnabled()).thenReturn(false);
// Plugin 2 is of a type that is not in the listed types above, so
// it will be ignored
final DataAccessPlugin plugin2 = mock(DataAccessPlugin.class, withSettings().extraInterfaces(DataAccessPreQueryValidation.class));
when(plugin2.isEnabled()).thenReturn(true);
when(plugin2.getType()).thenReturn(DataAccessPluginCoreType.IMPORT);
// Plugin 3 is a favourite and should be present in the favourite list
final DataAccessPlugin plugin3 = mock(DataAccessPlugin.class, withSettings().extraInterfaces(MergeNodeType.class));
when(plugin3.isEnabled()).thenReturn(true);
when(plugin3.getType()).thenReturn(DataAccessPluginCoreType.DEVELOPER);
when(plugin3.getName()).thenReturn("Plugin 3");
DataAccessPreferenceUtilities.setFavourite("Plugin 3", true);
when(plugin3.getOverriddenPlugins()).thenReturn(Collections.emptyList());
// Plugin 4 will be present but not a favourite
final DataAccessPlugin plugin4 = mock(DataAccessPlugin.class, withSettings().extraInterfaces(MergeTransactionType.class));
when(plugin4.isEnabled()).thenReturn(true);
when(plugin4.getType()).thenReturn(DataAccessPluginCoreType.UTILITY);
when(plugin4.getName()).thenReturn("Plugin 4");
// Overriden by plugin 4 so should not be present in the returned map
final DataAccessPlugin plugin5 = mock(DataAccessPlugin.class, withSettings().extraInterfaces(Comparable.class));
when(plugin5.isEnabled()).thenReturn(true);
when(plugin5.getType()).thenReturn(DataAccessPluginCoreType.DEVELOPER);
when(plugin5.getName()).thenReturn("Plugin 5");
when(plugin5.getOverriddenPlugins()).thenReturn(Collections.emptyList());
// Overriden by plugin 4 so should not be present in the returned map
final DataAccessPlugin plugin6 = mock(DataAccessPlugin.class, withSettings().extraInterfaces(Serializable.class));
when(plugin6.isEnabled()).thenReturn(true);
when(plugin6.getType()).thenReturn(DataAccessPluginCoreType.DEVELOPER);
when(plugin6.getName()).thenReturn("Plugin 6");
when(plugin6.getOverriddenPlugins()).thenReturn(Collections.emptyList());
// Plugin 4 overrides plugin 5 and plugin 6
when(plugin4.getOverriddenPlugins()).thenReturn(List.of(plugin5.getClass().getName(), plugin6.getClass().getName()));
doReturn(List.of(plugin1, plugin2, plugin3, plugin4, plugin5, plugin6)).when(defaultLookup).lookupAll(DataAccessPlugin.class);
final Map<String, List<DataAccessPlugin>> expectedPlugins = Map.of("Developer", List.of(plugin3), "Utility", List.of(plugin4), "Favourites", List.of(plugin3));
assertEquals(new LookupPluginsTask().get(), expectedPlugins);
}
}
Aggregations