Permalink
Browse files

[Icons] Test getAsset in component providers

  • Loading branch information...
VWoeltjen committed Sep 12, 2013
1 parent 8a4faa9 commit 9388c5961f5426fdb3a4f727b678b67e9309d273
@@ -21,13 +21,21 @@
*******************************************************************************/
package gov.nasa.arc.mct.graphics;
+import gov.nasa.arc.mct.components.AbstractComponent;
import gov.nasa.arc.mct.graphics.component.GraphicalComponent;
import gov.nasa.arc.mct.graphics.view.GraphicalManifestation;
import gov.nasa.arc.mct.graphics.view.StaticGraphicalView;
+import gov.nasa.arc.mct.gui.View;
import gov.nasa.arc.mct.policy.PolicyInfo;
import gov.nasa.arc.mct.services.component.AbstractComponentProvider;
import gov.nasa.arc.mct.services.component.ComponentTypeInfo;
+import gov.nasa.arc.mct.services.component.CreateWizardUI;
+import gov.nasa.arc.mct.services.component.TypeInfo;
import gov.nasa.arc.mct.services.component.ViewInfo;
+import gov.nasa.arc.mct.services.component.ViewType;
+
+import javax.swing.Icon;
+import javax.swing.ImageIcon;
import org.testng.Assert;
import org.testng.annotations.BeforeTest;
@@ -86,5 +94,46 @@ public void testComponentTypeInfos() {
Assert.assertTrue(foundGraphicalComponent);
}
-
+
+
+ @Test
+ public void testAssets() {
+ for (ViewInfo viewInfo : provider.getViews("")) {
+ // Verify that there's an icon
+ Assert.assertNotNull(provider.getAsset(viewInfo, ImageIcon.class));
+ // Verify that assignability is correctly assessed
+ Assert.assertNotNull(provider.getAsset(viewInfo, Icon.class));
+ // Verify that unknown types are not reported by getAsset
+ Assert.assertNull(provider.getAsset(viewInfo, UnknownType.class));
+ }
+ for (ComponentTypeInfo compInfo : provider.getComponentTypes()) {
+ // Verify that there's a wizard
+ Assert.assertNotNull(provider.getAsset(compInfo, CreateWizardUI.class));
+ // Verify that unknown types are not reported by getAsset
+ Assert.assertNull(provider.getAsset(compInfo, UnknownType.class));
+ }
+ // Verify that unknown types consistently return null
+ TypeInfo<?>[] unknowns = {
+ new TypeInfo<Object>(UnknownType.class){},
+ new ComponentTypeInfo("","",UnknownComponent.class),
+ new ViewInfo(UnknownView.class, "", "", ViewType.OBJECT)
+ };
+ for (TypeInfo<?> unknown : unknowns) {
+ Assert.assertNull(provider.getAsset(unknown, ImageIcon.class));
+ Assert.assertNull(provider.getAsset(unknown, CreateWizardUI.class));
+ Assert.assertNull(provider.getAsset(unknown, UnknownType.class));
+ }
+ }
+
+ private static class UnknownType {}
+ private static class UnknownComponent extends AbstractComponent {
+ @SuppressWarnings("unused") // Verified when ComponentTypeInfo is instantiated
+ public UnknownComponent() {}
+ }
+ private static class UnknownView extends View {
+ private static final long serialVersionUID = 1L;
+
+ @SuppressWarnings("unused") // Verified when ViewInfo is instantiated
+ public UnknownView (AbstractComponent ac, ViewInfo vi) {}
+ }
}
@@ -29,14 +29,24 @@
import gov.nasa.arc.mct.evaluator.view.MultiChildRemovalPolicy;
import gov.nasa.arc.mct.evaluator.view.MultiCompositionPolicy;
import gov.nasa.arc.mct.policy.PolicyInfo;
+import gov.nasa.arc.mct.services.component.ComponentProvider;
+import gov.nasa.arc.mct.services.component.ComponentTypeInfo;
+import gov.nasa.arc.mct.services.component.CreateWizardUI;
+import gov.nasa.arc.mct.services.component.TypeInfo;
import gov.nasa.arc.mct.services.component.ViewInfo;
import gov.nasa.arc.mct.services.component.ViewType;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
+import java.util.List;
+
+import javax.swing.Icon;
+import javax.swing.ImageIcon;
import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
public class TestEvaluatorComponentProvider {
@@ -81,23 +91,66 @@ public void testPolicyInfos() {
@Test
public void testViews() {
- Collection<ViewInfo> views = evaluatorProvider.getViews(EvaluatorComponent.class.getName());
- Assert.assertEquals(views.size(), 3);
- Assert.assertTrue(views.contains(new ViewInfo(ExpressionsViewManifestation.class,"", ViewType.OBJECT)));
- Assert.assertTrue(views.contains(new ViewInfo(ExpressionsViewManifestation.class,"", ExpressionsViewManifestation.class.getName(), ViewType.CENTER, true, EvaluatorComponent.class)));
-
- Iterator<ViewInfo> it = evaluatorProvider.getViews(EvaluatorComponent.class.getName()).iterator();
- Assert.assertEquals(it.next(), new ViewInfo(InfoViewManifestation.class, InfoViewManifestation.VIEW_NAME, ViewType.OBJECT));
- Assert.assertEquals(it.next(), new ViewInfo(ExpressionsViewManifestation.class, ExpressionsViewManifestation.VIEW_NAME, ViewType.OBJECT));
-
- views = multiProvider.getViews(MultiComponent.class.getName());
- Assert.assertEquals(views.size(), 3);
- Assert.assertTrue(views.contains(new ViewInfo(MultiViewManifestation.class, MultiViewManifestation.VIEW_NAME, InfoViewManifestation.class.getName(), ViewType.CENTER, true, MultiComponent.class)));
-
- it = multiProvider.getViews(MultiComponent.class.getName()).iterator();
- Assert.assertEquals(it.next(), new ViewInfo(InfoViewManifestation.class, InfoViewManifestation.VIEW_NAME, InfoViewManifestation.class.getName(), ViewType.OBJECT, false, MultiComponent.class));
- Assert.assertEquals(it.next(), new ViewInfo(MultiViewManifestation.class, MultiViewManifestation.VIEW_NAME, ViewType.OBJECT));
- Assert.assertEquals(it.next(), new ViewInfo(MultiViewManifestation.class, MultiViewManifestation.VIEW_NAME, InfoViewManifestation.class.getName(), ViewType.CENTER, true, MultiComponent.class));
+ Collection<ViewInfo> views = evaluatorProvider.getViews(EvaluatorComponent.class.getName());
+ Assert.assertEquals(views.size(), 3);
+ Assert.assertTrue(views.contains(new ViewInfo(ExpressionsViewManifestation.class,"", ViewType.OBJECT)));
+ Assert.assertTrue(views.contains(new ViewInfo(ExpressionsViewManifestation.class,"", ExpressionsViewManifestation.class.getName(), ViewType.CENTER, true, EvaluatorComponent.class)));
+
+ // Should return only one view (info) when component is unknown
+ Assert.assertEquals(evaluatorProvider.getViews("unknowncomponent").size(), 1);
+
+ Iterator<ViewInfo> it = evaluatorProvider.getViews(EvaluatorComponent.class.getName()).iterator();
+ Assert.assertEquals(it.next(), new ViewInfo(InfoViewManifestation.class, InfoViewManifestation.VIEW_NAME, ViewType.OBJECT));
+ Assert.assertEquals(it.next(), new ViewInfo(ExpressionsViewManifestation.class, ExpressionsViewManifestation.VIEW_NAME, ViewType.OBJECT));
+
+ views = multiProvider.getViews(MultiComponent.class.getName());
+ Assert.assertEquals(views.size(), 3);
+ Assert.assertTrue(views.contains(new ViewInfo(MultiViewManifestation.class, MultiViewManifestation.VIEW_NAME, InfoViewManifestation.class.getName(), ViewType.CENTER, true, MultiComponent.class)));
+
+ it = multiProvider.getViews(MultiComponent.class.getName()).iterator();
+ Assert.assertEquals(it.next(), new ViewInfo(InfoViewManifestation.class, InfoViewManifestation.VIEW_NAME, InfoViewManifestation.class.getName(), ViewType.OBJECT, false, MultiComponent.class));
+ Assert.assertEquals(it.next(), new ViewInfo(MultiViewManifestation.class, MultiViewManifestation.VIEW_NAME, ViewType.OBJECT));
+ Assert.assertEquals(it.next(), new ViewInfo(MultiViewManifestation.class, MultiViewManifestation.VIEW_NAME, InfoViewManifestation.class.getName(), ViewType.CENTER, true, MultiComponent.class));
}
-
+
+ @Test (dataProvider="assetTestCases")
+ public void testAssets(ComponentProvider provider, TypeInfo<?> info, Class<?> assetType, boolean expected) {
+ // Used to verify whether provider offers certain assets
+ if (expected) {
+ Assert.assertNotNull(provider.getAsset(info, assetType));
+ } else {
+ Assert.assertNull(provider.getAsset(info, assetType));
+ }
+ }
+
+ @DataProvider
+ public Object[][] assetTestCases() {
+ List<Object[]> cases = new ArrayList<Object[]>();
+ // Consider all view types
+ for (ViewType type : ViewType.values()) {
+ ViewInfo info = new ViewInfo(InfoViewManifestation.class, InfoViewManifestation.VIEW_NAME, InfoViewManifestation.class.getName(), type);
+ ViewInfo expr = new ViewInfo(ExpressionsViewManifestation.class, ExpressionsViewManifestation.VIEW_NAME, InfoViewManifestation.class.getName(), type);
+ TypeInfo<?> eval = new ComponentTypeInfo("","",EvaluatorComponent.class);
+ TypeInfo<?> mult = new ComponentTypeInfo("","",MultiComponent.class);
+ for (TypeInfo<?> vi : new TypeInfo<?>[]{info,expr,eval,mult}) {
+ // Expressions view should have an image icon
+ cases.add(new Object[] { new EvaluatorComponentProvider(), vi, ImageIcon.class, vi.getTypeClass().equals(ExpressionsViewManifestation.class)});
+ // Verify assignable check also recognizes icon
+ cases.add(new Object[] { new EvaluatorComponentProvider(), vi, Icon.class, vi.getTypeClass().equals(ExpressionsViewManifestation.class)});
+ // Evaluator should have a wizard
+ cases.add(new Object[] { new EvaluatorComponentProvider(), vi, CreateWizardUI.class, vi.getTypeClass().equals(EvaluatorComponent.class)});
+ // Multi component providers have no icons
+ cases.add(new Object[] { new MultiComponentProvider(), vi, ImageIcon.class, false});
+ // As above
+ cases.add(new Object[] { new MultiComponentProvider(), vi, Icon.class, false});
+ // MultiComponent should have a wizard
+ cases.add(new Object[] { new MultiComponentProvider(), vi, CreateWizardUI.class, vi.getTypeClass().equals(MultiComponent.class)});
+ }
+ }
+ Object[][] returnValue = new Object[cases.size()][];
+ for (int i = 0; i < cases.size(); i++) {
+ returnValue[i] = cases.get(i);
+ }
+ return returnValue;
+ }
}
@@ -21,24 +21,37 @@
*******************************************************************************/
package gov.nasa.jsc.mct.executables.buttons;
-import gov.nasa.arc.mct.gui.MenuItemInfo;
-import gov.nasa.arc.mct.platform.spi.Platform;
-import gov.nasa.arc.mct.platform.spi.PlatformAccess;
-import gov.nasa.arc.mct.platform.spi.RoleService;
-import gov.nasa.arc.mct.services.internal.component.User;
-import gov.nasa.jsc.mct.executable.buttons.ExecutableButtonComponent;
-import gov.nasa.jsc.mct.executable.buttons.ExecutableButtonComponentProvider;
-import gov.nasa.jsc.mct.executables.buttons.actions.ExecutableButtonAction;
-
-import java.util.Collection;
-
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
-import org.testng.Assert;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
+import gov.nasa.arc.mct.gui.MenuItemInfo;
+import gov.nasa.arc.mct.platform.spi.Platform;
+import gov.nasa.arc.mct.platform.spi.PlatformAccess;
+import gov.nasa.arc.mct.platform.spi.RoleService;
+import gov.nasa.arc.mct.services.component.ComponentProvider;
+import gov.nasa.arc.mct.services.component.ComponentTypeInfo;
+import gov.nasa.arc.mct.services.component.CreateWizardUI;
+import gov.nasa.arc.mct.services.component.TypeInfo;
+import gov.nasa.arc.mct.services.component.ViewInfo;
+import gov.nasa.arc.mct.services.component.ViewType;
+import gov.nasa.arc.mct.services.internal.component.User;
+import gov.nasa.jsc.mct.executable.buttons.ExecutableButtonComponent;
+import gov.nasa.jsc.mct.executable.buttons.ExecutableButtonComponentProvider;
+import gov.nasa.jsc.mct.executable.buttons.view.ExecutableButtonManifestation;
+import gov.nasa.jsc.mct.executables.buttons.actions.ExecutableButtonAction;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import javax.swing.Icon;
+import javax.swing.ImageIcon;
+
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.testng.Assert;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
public class TestExecutableButtonComponentProvider {
private ExecutableButtonComponentProvider provider;
@@ -92,5 +105,38 @@ public void testMenuItemInfos() {
@Test
public void testPolicyInfos() {
Assert.assertTrue(provider.getPolicyInfos().isEmpty());
+ }
+
+ @Test (dataProvider="assetTestCases")
+ public void testAssets(ComponentProvider provider, TypeInfo<?> info, Class<?> assetType, boolean expected) {
+ // Used to verify whether provider offers certain assets
+ if (expected) {
+ Assert.assertNotNull(provider.getAsset(info, assetType));
+ } else {
+ Assert.assertNull(provider.getAsset(info, assetType));
+ }
+ }
+
+ @DataProvider
+ public Object[][] assetTestCases() {
+ List<Object[]> cases = new ArrayList<Object[]>();
+ // Consider all view types
+ for (ViewType type : ViewType.values()) {
+ TypeInfo<?> view = new ViewInfo(ExecutableButtonManifestation.class, ExecutableButtonManifestation.VIEW_NAME, ExecutableButtonManifestation.class.getName(), type);
+ TypeInfo<?> comp = new ComponentTypeInfo("","",ExecutableButtonComponent.class);
+ for (TypeInfo<?> vi : new TypeInfo<?>[]{view, comp}) {
+ // Executable buttons have no view or component icons currently
+ cases.add(new Object[] { new ExecutableButtonComponentProvider(), vi, ImageIcon.class, false});
+ // As above
+ cases.add(new Object[] { new ExecutableButtonComponentProvider(), vi, Icon.class, false});
+ // Executable buttons should have a wizard
+ cases.add(new Object[] { new ExecutableButtonComponentProvider(), vi, CreateWizardUI.class, vi.getTypeClass().equals(ExecutableButtonComponent.class)});
+ }
+ }
+ Object[][] returnValue = new Object[cases.size()][];
+ for (int i = 0; i < cases.size(); i++) {
+ returnValue[i] = cases.get(i);
+ }
+ return returnValue;
}
}
@@ -21,17 +21,21 @@
*******************************************************************************/
package gov.nasa.arc.mct.fastplot;
-import gov.nasa.arc.mct.policy.PolicyInfo;
-import gov.nasa.arc.mct.services.component.ViewInfo;
-import gov.nasa.arc.mct.services.component.ViewType;
-import gov.nasa.arc.mct.fastplot.view.PlotViewManifestation;
-
-import java.util.Collection;
-import java.util.Collections;
-
-import org.testng.Assert;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
+import gov.nasa.arc.mct.fastplot.view.PlotViewManifestation;
+import gov.nasa.arc.mct.policy.PolicyInfo;
+import gov.nasa.arc.mct.services.component.TypeInfo;
+import gov.nasa.arc.mct.services.component.ViewInfo;
+import gov.nasa.arc.mct.services.component.ViewType;
+
+import java.util.Collection;
+import java.util.Collections;
+
+import javax.swing.Icon;
+import javax.swing.ImageIcon;
+
+import org.testng.Assert;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
public class TestPlotViewProvider {
@@ -57,5 +61,27 @@ public void testGetViewRoles() {
public void testGetPolicyInfos() {
Collection<PolicyInfo> infos = provider.getPolicyInfos();
Assert.assertEquals(infos.size(), 2);
- }
+ }
+
+ @Test
+ public void testGetAsset() {
+ @SuppressWarnings("serial")
+ class UnknownType extends ImageIcon {};
+
+ for (ViewInfo viewInfo : provider.getViews("")) {
+ // Should have an icon
+ Assert.assertNotNull(provider.getAsset(viewInfo, ImageIcon.class));
+ // Should obey assignable rules for icon
+ Assert.assertNotNull(provider.getAsset(viewInfo, Icon.class));
+ Assert.assertNull(provider.getAsset(viewInfo, UnknownType.class));
+ }
+
+ // Should not have assets for unknown types
+ TypeInfo<?> unknownInfo = new TypeInfo<UnknownType>(UnknownType.class){};
+ for (Class<?> type : new Class<?>[] {ImageIcon.class,Icon.class,UnknownType.class}) {
+ Assert.assertNull(provider.getAsset(unknownInfo, type));
+ }
+
+ }
+
}
Oops, something went wrong.

0 comments on commit 9388c59

Please sign in to comment.