/** @see DATAMONGO-1552 */
  @Test
  public void shouldRenderBucketOutputOperators() {

    BucketOperation operation =
        Aggregation.bucket("field") //
            .andOutputCount()
            .as("titles");

    DBObject dbObject = operation.toDBObject(Aggregation.DEFAULT_CONTEXT);
    assertThat(extractOutput(dbObject), is(JSON.parse("{ titles : { $sum: 1 } }")));
  }
  /** @see DATAMONGO-1552 */
  @Test
  public void shouldRenderAddToSetOperator() {

    BucketOperation operation =
        bucket("field") //
            .andOutput("title")
            .addToSet()
            .as("titles");

    DBObject dbObject = operation.toDBObject(Aggregation.DEFAULT_CONTEXT);
    assertThat(extractOutput(dbObject), is(JSON.parse("{ titles : { $addToSet: \"$title\" } }")));
  }
  /** @see DATAMONGO-1552 */
  @Test
  public void shouldRenderMinOperator() {

    BucketOperation operation =
        bucket("field") //
            .andOutput("score")
            .min()
            .as("min_score");

    DBObject dbObject = operation.toDBObject(Aggregation.DEFAULT_CONTEXT);
    assertThat(extractOutput(dbObject), is(JSON.parse("{ min_score : { $min: \"$score\" } }")));
  }
  /** @see DATAMONGO-1552 */
  @Test
  public void shouldRenderSumWithValueOperator() {

    BucketOperation operation =
        bucket("field") //
            .andOutput("score")
            .sum(4)
            .as("cummulated_score");

    DBObject dbObject = operation.toDBObject(Aggregation.DEFAULT_CONTEXT);
    assertThat(extractOutput(dbObject), is(JSON.parse("{ cummulated_score : { $sum: 4 } }")));
  }
  /** @see DATAMONGO-1552 */
  @Test
  public void shouldRenderSumWithOwnOutputExpression() {

    BucketOperation operation =
        bucket("field") //
            .andOutputExpression("netPrice + tax")
            .apply("$multiply", 5)
            .as("total");

    DBObject dbObject = operation.toDBObject(Aggregation.DEFAULT_CONTEXT);
    assertThat(
        extractOutput(dbObject),
        is(JSON.parse("{ total : { $multiply: [ {$add : [\"$netPrice\", \"$tax\"]}, 5] } }")));
  }
  /** @see DATAMONGO-1552 */
  @Test
  public void shouldRenderBucketOutputExpressions() {

    BucketOperation operation =
        Aggregation.bucket("field") //
            .andOutputExpression("(netPrice + surCharge) * taxrate * [0]", 2)
            .as("grossSalesPrice") //
            .andOutput("title")
            .push()
            .as("titles");

    DBObject dbObject = operation.toDBObject(Aggregation.DEFAULT_CONTEXT);
    assertThat(
        extractOutput(dbObject),
        is(
            JSON.parse(
                "{ \"grossSalesPrice\" : { \"$multiply\" : [ { \"$add\" : [ \"$netPrice\" , \"$surCharge\"]} , \"$taxrate\" , 2]} , \"titles\" : { $push: \"$title\" } }}")));
  }