Пример #1
0
  /** Test method. */
  @Test
  public void foldLeft1Test() {
    query("hof:fold-left1(1 to 10, function($x, $y) { $x + $y })", "55");
    error("hof:fold-left1((), function($x, $y) { $x + $y })", EMPTYFOUND);

    // should be unrolled and evaluated at compile time
    final int limit = FnForEach.UNROLL_LIMIT;
    check(
        "hof:fold-left1(1 to " + limit + ", function($a,$b) {$a+$b})",
        "55",
        "empty(//" + Util.className(HofFoldLeft1.class) + "[contains(@name, 'fold-left1')])",
        "exists(*/" + Util.className(Int.class) + ')');
    // should be unrolled but not evaluated at compile time
    check(
        "hof:fold-left1(1 to " + limit + ", function($a,$b) {0*random:integer($a)+$b})",
        "10",
        "empty(//" + Util.className(HofFoldLeft1.class) + "[contains(@name, 'fold-left1')])",
        "empty(*/" + Util.className(Int.class) + ')',
        "count(//" + Util.className(Arith.class) + "[@op = '+']) eq 9");
    // should not be unrolled
    check(
        "hof:fold-left1(1 to " + (limit + 1) + ", function($a,$b) {$a+$b})",
        "66",
        "exists(//" + Util.className(HofFoldLeft1.class) + "[contains(@name, 'fold-left1')])");
  }
Пример #2
0
  /**
   * Tests writing of request content when @src is set.
   *
   * @throws IOException I/O Exception
   */
  @Test
  public void writeFromResource() throws IOException {
    // Create a file form which will be read
    final IOFile file = new IOFile(Prop.TMP, Util.className(FnHttpTest.class));
    file.write(token("test"));

    // Request
    final HttpRequest req = new HttpRequest();
    req.payloadAttrs.put("src", file.url());
    req.payloadAttrs.put("method", "binary");
    // HTTP connection
    final FakeHttpConnection fakeConn = new FakeHttpConnection(new URL("http://www.test.com"));
    HttpClient.setRequestContent(fakeConn.getOutputStream(), req);

    // Delete file
    file.delete();

    assertEquals(fakeConn.out.toString(Strings.UTF8), "test");
  }