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;
    }
  }
예제 #2
0
  public void testGetType() throws Exception {
    sumNode.addChildNode(new SupportExprNode(Integer.class));
    SupportExprNodeFactory.validate3Stream(sumNode);
    assertEquals(Integer.class, sumNode.getType());

    sumNode = new ExprSumNode(false, false);
    sumNode.addChildNode(new SupportExprNode(Float.class));
    SupportExprNodeFactory.validate3Stream(sumNode);
    assertEquals(Float.class, sumNode.getType());

    sumNode = new ExprSumNode(false, false);
    sumNode.addChildNode(new SupportExprNode(Short.class));
    SupportExprNodeFactory.validate3Stream(sumNode);
    assertEquals(Integer.class, sumNode.getType());
  }
예제 #3
0
  private static LinkedList<ExprNode> makeParams(Class clazz[], String[] values) throws Exception {
    LinkedList<ExprNode> parameters = new LinkedList<ExprNode>();
    if (values == null) {
      return parameters;
    }

    for (int i = 0; i < values.length; i++) {
      ExprNode node;
      String value = values[i];
      if (clazz[i] == String.class) {
        if (value.startsWith("\"")) {
          value = value.replace("\"", "");
          node = new ExprConstantNodeImpl(value);
        } else {
          node = SupportExprNodeFactory.makeIdentNodeBean(value);
        }
      } else if (clazz[i] == Boolean.class) {
        node = new ExprConstantNodeImpl(Boolean.valueOf(value));
      } else {
        node = new ExprConstantNodeImpl(Integer.valueOf(value));
      }
      parameters.add(node);
    }

    return parameters;
  }
예제 #4
0
 public static List<ExprNode> toExprListMD(Object[] constants) throws Exception {
   List<ExprNode> expr = new ArrayList<ExprNode>();
   for (int i = 0; i < constants.length; i++) {
     if (constants[i] instanceof String) {
       expr.add(SupportExprNodeFactory.makeIdentNodeMD(constants[i].toString()));
     } else {
       expr.add(new ExprConstantNodeImpl(constants[i]));
     }
   }
   return expr;
 }
예제 #5
0
  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)));
  }
 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)));
 }
예제 #7
0
 private ExprSumNode makeNode(Object value, Class type) throws Exception {
   ExprSumNode sumNode = new ExprSumNode(false, false);
   sumNode.addChildNode(new SupportExprNode(value, type));
   SupportExprNodeFactory.validate3Stream(sumNode);
   return sumNode;
 }