@Test
public void testExecute() {
Policy policy = new PlotViewPolicy();
PolicyContext context;
ViewInfo plotViewInfo = new ViewInfo(PlotViewManifestation.class, "Plot", ViewType.OBJECT);
// Plot views should be allowed for leaf component with a feed
context = new PolicyContext();
context.setProperty(PolicyContext.PropertyName.TARGET_VIEW_INFO.getName(),
plotViewInfo);
context.setProperty(PolicyContext.PropertyName.TARGET_COMPONENT.getName(),
leafWithAFeedComponent);
Assert.assertTrue(policy.execute(context).getStatus());
// ...but not without a feed
context = new PolicyContext();
context.setProperty(PolicyContext.PropertyName.TARGET_VIEW_INFO.getName(),
plotViewInfo);
context.setProperty(PolicyContext.PropertyName.TARGET_COMPONENT.getName(),
leafWithOutAFeedComponent);
Assert.assertFalse(policy.execute(context).getStatus());
// Plot view policy should not reject non-plot, ever
for (AbstractComponent ac : new AbstractComponent[] { leafWithAFeedComponent, leafWithOutAFeedComponent, nonLeafComponent} ) {
for (ViewType vt : ViewType.values()) {
ViewInfo someViewInfo = new ViewInfo(NonPlotView.class, "NonPlot", vt);
context = new PolicyContext();
context.setProperty(PolicyContext.PropertyName.TARGET_VIEW_INFO.getName(),
someViewInfo);
context.setProperty(PolicyContext.PropertyName.TARGET_COMPONENT.getName(),
ac);