public void testAttaches() throws Exception {
    // Should attach to anything as long as the fields exists
    EventType parentType = SupportEventTypeFactory.createBeanType(SupportMarketDataBean.class);

    factory.setViewParameters(
        viewFactoryContext,
        Arrays.asList(
            new ExprNode[] {
              SupportExprNodeFactory.makeIdentNodeMD("volume"),
              SupportExprNodeFactory.makeIdentNodeMD("price")
            }));
    factory.attach(parentType, SupportStatementContextFactory.makeContext(), null, null);
    assertEquals(
        Double.class,
        factory.getEventType().getPropertyType(ViewFieldEnum.REGRESSION__SLOPE.getName()));

    try {
      factory.setViewParameters(
          viewFactoryContext, TestViewSupport.toExprListMD(new Object[] {"symbol", "symbol"}));
      factory.attach(parentType, SupportStatementContextFactory.makeContext(), null, null);
      fail();
    } catch (ViewParameterException ex) {
      // expected;
    }
  }
  public void testAttaches() throws Exception {
    // Should attach to anything as long as the fields exists
    EventType parentType = SupportEventTypeFactory.createBeanType(SupportBean.class);

    factory.setViewParameters(
        viewFactoryContext, TestViewSupport.toExprListBean(new Object[] {"intBoxed"}));
    factory.attach(parentType, SupportStatementContextFactory.makeContext(), null, null);
  }
 private void tryParameter(Object[] params, String[] fieldNames) throws Exception {
   GroupByViewFactory factory = new GroupByViewFactory();
   factory.setViewParameters(viewFactoryContext, TestViewSupport.toExprListBean(params));
   factory.attach(
       SupportEventTypeFactory.createBeanType(SupportBean.class),
       SupportStatementContextFactory.makeContext(),
       null,
       null);
   GroupByView view = (GroupByView) factory.makeView(SupportStatementContextFactory.makeContext());
   assertEquals(fieldNames[0], view.getCriteriaExpressions()[0].toExpressionString());
 }
  public void testCanReuse() throws Exception {
    factory.setViewParameters(
        viewFactoryContext,
        TestViewSupport.toExprListBean(new Object[] {"string", "longPrimitive"}));
    factory.attach(
        SupportEventTypeFactory.createBeanType(SupportBean.class),
        SupportStatementContextFactory.makeContext(),
        null,
        null);
    assertFalse(factory.canReuse(new FirstElementView()));
    assertFalse(
        factory.canReuse(
            new GroupByViewImpl(
                SupportStatementContextFactory.makeContext(),
                SupportExprNodeFactory.makeIdentNodesBean("string"),
                null)));
    assertTrue(
        factory.canReuse(
            new GroupByViewImpl(
                SupportStatementContextFactory.makeContext(),
                SupportExprNodeFactory.makeIdentNodesBean("string", "longPrimitive"),
                null)));

    factory.setViewParameters(
        viewFactoryContext,
        TestViewSupport.toExprListBean(
            new Object[] {SupportExprNodeFactory.makeIdentNodesBean("string", "longPrimitive")}));
    assertFalse(
        factory.canReuse(
            new GroupByViewImpl(
                SupportStatementContextFactory.makeContext(),
                SupportExprNodeFactory.makeIdentNodesBean("string"),
                null)));
    assertTrue(
        factory.canReuse(
            new GroupByViewImpl(
                SupportStatementContextFactory.makeContext(),
                SupportExprNodeFactory.makeIdentNodesBean("string", "longPrimitive"),
                null)));
  }
 private void tryInvalidParameter(Object[] parameters) throws Exception {
   try {
     factory.setViewParameters(viewFactoryContext, TestViewSupport.toExprListMD(parameters));
     factory.attach(
         SupportEventTypeFactory.createBeanType(SupportMarketDataBean.class),
         SupportStatementContextFactory.makeContext(),
         null,
         null);
     fail();
   } catch (ViewParameterException ex) {
     // expected
   }
 }
 private void tryParameter(Object[] parameters, String fieldNameX, String fieldNameY)
     throws Exception {
   factory.setViewParameters(viewFactoryContext, TestViewSupport.toExprListMD(parameters));
   factory.attach(
       SupportEventTypeFactory.createBeanType(SupportMarketDataBean.class),
       SupportStatementContextFactory.makeContext(),
       null,
       null);
   RegressionLinestView view =
       (RegressionLinestView)
           factory.makeView(SupportStatementContextFactory.makeAgentInstanceViewFactoryContext());
   assertEquals(fieldNameX, view.getExpressionX().toExpressionString());
   assertEquals(fieldNameY, view.getExpressionY().toExpressionString());
 }
 public void testCanReuse() throws Exception {
   factory.setViewParameters(
       viewFactoryContext, TestViewSupport.toExprListMD(new Object[] {"price", "volume"}));
   factory.attach(
       SupportEventTypeFactory.createBeanType(SupportMarketDataBean.class),
       SupportStatementContextFactory.makeContext(),
       null,
       null);
   assertFalse(factory.canReuse(new FirstElementView()));
   EventType type =
       RegressionLinestView.createEventType(SupportStatementContextFactory.makeContext(), null, 1);
   assertFalse(
       factory.canReuse(
           new RegressionLinestView(
               SupportStatementContextFactory.makeAgentInstanceContext(),
               SupportExprNodeFactory.makeIdentNodeMD("price"),
               SupportExprNodeFactory.makeIdentNodeMD("price"),
               type,
               null)));
   assertFalse(
       factory.canReuse(
           new RegressionLinestView(
               SupportStatementContextFactory.makeAgentInstanceContext(),
               SupportExprNodeFactory.makeIdentNodeMD("volume"),
               SupportExprNodeFactory.makeIdentNodeMD("price"),
               type,
               null)));
   assertTrue(
       factory.canReuse(
           new RegressionLinestView(
               SupportStatementContextFactory.makeAgentInstanceContext(),
               SupportExprNodeFactory.makeIdentNodeMD("price"),
               SupportExprNodeFactory.makeIdentNodeMD("volume"),
               type,
               null)));
 }
 private void tryParameter(Object[] param) throws Exception {
   SizeViewFactory factory = new SizeViewFactory();
   factory.setViewParameters(
       SupportStatementContextFactory.makeViewContext(), TestViewSupport.toExprListBean(param));
   assertTrue(factory.makeView(SupportStatementContextFactory.makeContext()) instanceof SizeView);
 }