Ejemplo n.º 1
0
 @Test
 public void checkTransformRenameTable() {
   RenameTable input = createMock(RenameTable.class);
   replayAll();
   SelectionSplitter subject = new SelectionSplitter();
   IRelAlgExpr result = subject.transformRenameTable(input);
   verifyAll();
   assertThat(result, is(equalTo((IRelAlgExpr) input)));
 }
Ejemplo n.º 2
0
  @Test
  public void checkTransformSelectionAndsAreSplit() {
    IRelAlgExpr subResult;
    StubResult<IRelAlgExpr> subExpression;
    IRowSelector[] basePredicates = new IRowSelector[3];
    IRowSelector[] results = new IRowSelector[3];
    IRowSelector predicate;

    subResult = createMock(IRelAlgExpr.class);
    subExpression = new StubResult<IRelAlgExpr>(subResult);
    for (int i = 0; i < basePredicates.length; i++) {
      results[i] = createMock(IRowSelector.class);
      List<IRowSelector> currentSubResult = new LinkedList<IRowSelector>();
      currentSubResult.add(results[i]);
      basePredicates[i] = new RowselectorStubResult<Collection<IRowSelector>>(currentSubResult);
    }

    predicate =
        new BinaryOperation(
            new BinaryOperation(basePredicates[0], BooleanValueCombination.AND, basePredicates[1]),
            BooleanValueCombination.AND,
            basePredicates[2]);

    Selection input = new Selection(predicate, subExpression);

    replayAll();
    SelectionSplitter subject = new SelectionSplitter();
    IRelAlgExpr result = subject.transformSelection(input);
    verifyAll();

    Selection[] transformedSelections = new Selection[3];
    assertThat(result, is(instanceOf(Selection.class)));
    transformedSelections[0] = (Selection) result;
    assertThat(transformedSelections[0].getSubExpression(), is(instanceOf(Selection.class)));
    transformedSelections[1] = (Selection) transformedSelections[0].getSubExpression();
    assertThat(transformedSelections[1].getSubExpression(), is(instanceOf(Selection.class)));
    transformedSelections[2] = (Selection) transformedSelections[1].getSubExpression();

    assertThat(transformedSelections[2].getSubExpression(), is(equalTo(subResult)));
    for (int i = 0; i < basePredicates.length; i++) {
      assertThat(
          results[i],
          is(
              anyOf(
                  equalTo(transformedSelections[0].getPredicate()),
                  equalTo(transformedSelections[1].getPredicate()),
                  equalTo(transformedSelections[2].getPredicate()))));
    }
  }
Ejemplo n.º 3
0
  @Test
  public void checkTransformProjection() {
    IRelAlgExpr transformedSubExpression;
    StubResult<IRelAlgExpr> subExpression;
    Collection<IColumnProjection> projections;

    projections = new LinkedList<IColumnProjection>();
    transformedSubExpression = createMock(IRelAlgExpr.class);
    subExpression = new StubResult<IRelAlgExpr>(transformedSubExpression);
    Projection input = new Projection(subExpression, projections);
    replayAll();
    SelectionSplitter subject = new SelectionSplitter();
    IRelAlgExpr result = subject.transformProjection(input);
    verifyAll();
    assertThat(result, is(instanceOf(Projection.class)));
    Projection castedResult = (Projection) result;
    assertThat(castedResult.getSubExpression(), is(equalTo(transformedSubExpression)));
    assertThat(castedResult.getSelectedFields(), is(equalTo(projections)));
  }
Ejemplo n.º 4
0
  @Test
  public void checkTransformProduct() {
    IRelAlgExpr leftResult;
    IRelAlgExpr rightResult;
    StubResult<IRelAlgExpr> left;
    StubResult<IRelAlgExpr> right;

    leftResult = createMock(IRelAlgExpr.class);
    rightResult = createMock(IRelAlgExpr.class);
    left = new StubResult<IRelAlgExpr>(leftResult);
    right = new StubResult<IRelAlgExpr>(rightResult);
    Product input = new Product(left, right);
    replayAll();
    SelectionSplitter subject = new SelectionSplitter();
    IRelAlgExpr result = subject.transformProduct(input);
    verifyAll();
    assertThat(result, is(instanceOf(Product.class)));
    Product castedResult = (Product) result;
    assertThat(castedResult.getLeft(), is(equalTo(leftResult)));
    assertThat(castedResult.getRight(), is(equalTo(rightResult)));
  }