コード例 #1
0
  public void testFormatFooter() {
    JSONRowFormatter fmtr = new JSONRowFormatter();
    Date now = Calendar.getInstance().getTime();
    DateFormat dateFormatter = new SimpleDateFormat("yyyy.MM.dd HH:mm::ss");
    String executionTime = dateFormatter.format(now);
    String expected =
        "],\"executionTime\":\""
            + executionTime
            + "\",\"wasSuccessful\":true,\"error\":null,\"statusCode\":200}";
    assertEquals(expected, fmtr.formatFooter(null, 200));

    expected =
        "],\"executionTime\":\""
            + executionTime
            + "\",\"wasSuccessful\":false,\"error\":\"Not feeling like it\","
            + "\"statusCode\":400}";

    assertEquals(expected, fmtr.formatFooter("Not feeling like it", 400));

    expected += ");";
    attributes.put(JSONRowFormatter.KEY_CALLBACK, "should_not_appear_in_footer");

    fmtr.formatHeader(attributes); // needs to be called to set the callback parameter
    assertEquals(expected, fmtr.formatFooter("Not feeling like it", 400));
  }
コード例 #2
0
  public void testFormatResult() {
    JSONRowFormatter fmtr = new JSONRowFormatter();
    String expected = testProps.getProperty("result.body");
    assertEquals(expected, fmtr.formatResult(Arrays.asList("One", "Two", "Three")));

    expected = "";
    assertEquals(expected, fmtr.formatResult(new ArrayList<String>()));
  }
コード例 #3
0
  public void testFormatHeader() {
    JSONRowFormatter fmtr = new JSONRowFormatter();

    String expected = testProps.getProperty("result.header");
    assertEquals(expected, fmtr.formatHeader(attributes));

    String callback = "user_defined_callback";
    expected = callback + "(" + expected;
    attributes.put(JSONRowFormatter.KEY_CALLBACK, callback);

    assertEquals(expected, fmtr.formatHeader(attributes));
  }