示例#1
0
 private static void checkJsonDatasetsOne(JsonValue v) {
   assertTrue(v.isObject());
   JsonObject obj = v.getAsObject();
   assertNotNull(obj.get("ds.name"));
   assertNotNull(obj.get("ds.services"));
   assertNotNull(obj.get("ds.state"));
   assertTrue(obj.get("ds.services").isArray());
 }
示例#2
0
 private static void checkJsonStatsAll(JsonValue v) {
   assertNotNull(v.getAsObject().get("datasets"));
   JsonObject a = v.getAsObject().get("datasets").getAsObject();
   for (String dsname : a.keys()) {
     JsonValue obj = a.get(dsname).getAsObject();
     checkJsonStatsOne(obj);
   }
 }
示例#3
0
 @Test
 public void list_backups_1() {
   try (TypedInputStream in = execHttpGet(urlRoot + "$/" + opListBackups)) {
     assertEqualsIgnoreCase(WebContent.contentTypeJSON, in.getContentType());
     JsonValue v = JSON.parseAny(in);
     assertNotNull(v.getAsObject().get("backups"));
   }
 }
示例#4
0
 @Test
 public void server_1() {
   JsonValue jv = httpGetJson(ServerTest.urlRoot + "$/" + opServer);
   JsonObject obj = jv.getAsObject();
   // Now optional : assertTrue(obj.hasKey(JsonConst.admin)) ;
   assertTrue(obj.hasKey(JsonConst.datasets));
   assertTrue(obj.hasKey(JsonConst.uptime));
   assertTrue(obj.hasKey(JsonConst.startDT));
 }
示例#5
0
 @Test
 public void list_datasets_2() {
   try (TypedInputStream in = execHttpGet(urlRoot + "$/" + opDatasets)) {
     assertEqualsIgnoreCase(WebContent.contentTypeJSON, in.getContentType());
     JsonValue v = JSON.parseAny(in);
     assertNotNull(v.getAsObject().get("datasets"));
     checkJsonDatasetsAll(v);
   }
 }
示例#6
0
 private static void checkExistsNotActive(String name) {
   adminPing(name);
   try {
     askPing(name);
     fail("askPing did not cause an Http Exception");
   } catch (HttpException ex) {
   }
   JsonValue v = getDatasetDescription(name);
   assertFalse(v.getAsObject().get("ds.state").getAsBoolean().value());
 }
示例#7
0
  private String execSleepTask(String name, int millis) {
    String url = urlRoot + "$/sleep";
    if (name != null) {
      if (name.startsWith("/")) name = name.substring(1);
      url = url + "/" + name;
    }

    JsonResponseHandler x = new JsonResponseHandler();
    HttpOp.execHttpPost(url + "?interval=" + millis, null, WebContent.contentTypeJSON, x);
    JsonValue v = x.getJSON();
    String id = v.getAsObject().get("taskId").getAsString().value();
    return id;
  }
示例#8
0
 private void checkTask(JsonValue v) {
   assertNotNull(v);
   assertTrue(v.isObject());
   // System.out.println(v) ;
   JsonObject obj = v.getAsObject();
   try {
     assertTrue(obj.hasKey("task"));
     assertTrue(obj.hasKey("taskId"));
     // Not present until it runs : "started"
   } catch (AssertionError ex) {
     System.out.println(obj);
     throw ex;
   }
 }
示例#9
0
 private static void checkJsonStatsOne(JsonValue v) {
   checkJsonStatsCounters(v);
   JsonObject obj1 = v.getAsObject().get("endpoints").getAsObject();
   for (String srvName : obj1.keys()) {
     JsonObject obj2 = obj1.get(srvName).getAsObject();
     assertTrue(obj2.hasKey("description"));
     assertTrue(obj2.hasKey("operation"));
     checkJsonStatsCounters(obj2);
   }
 }
示例#10
0
  @Test
  public void task_4() {
    // Timing dependent.
    // Create a "short" running task
    String x = execSleepTask(null, 1);
    // Check exists in the list of all tasks (should be "finished")
    checkInTasks(x);
    String url = urlRoot + "$/tasks/" + x;

    boolean finished = false;
    for (int i = 0; i < 10; i++) {
      if (i != 0) Lib.sleep(25);
      JsonValue v = httpGetJson(url);
      checkTask(v);
      if (v.getAsObject().hasKey("finished")) {
        finished = true;
        break;
      }
    }
    if (!finished) fail("Task has not finished");
  }
示例#11
0
 private void checkInTasks(String x) {
   String url = urlRoot + "$/tasks";
   JsonValue v = httpGetJson(url);
   assertTrue(v.isArray());
   JsonArray array = v.getAsArray();
   int found = 0;
   for (int i = 0; i < array.size(); i++) {
     JsonValue jv = array.get(i);
     assertTrue(jv.isObject());
     JsonObject obj = jv.getAsObject();
     checkTask(obj);
     if (obj.get("taskId").getAsString().value().equals(x)) {
       found++;
     }
   }
   assertEquals("Occurence of taskId count", 1, found);
 }
示例#12
0
 private static void checkJsonStatsCounters(JsonValue v) {
   JsonObject obj = v.getAsObject();
   assertTrue(obj.hasKey("Requests"));
   assertTrue(obj.hasKey("RequestsGood"));
   assertTrue(obj.hasKey("RequestsBad"));
 }
示例#13
0
 private static void checkJsonDatasetsAll(JsonValue v) {
   assertNotNull(v.getAsObject().get("datasets"));
   JsonArray a = v.getAsObject().get("datasets").getAsArray();
   for (JsonValue v2 : a) checkJsonDatasetsOne(v2);
 }
示例#14
0
 // Specific dataset
 @Test
 public void list_datasets_5() {
   JsonValue v = getDatasetDescription(datasetPath);
   checkJsonDatasetsOne(v.getAsObject());
 }