@Test
  public void testJsonRPFormatter() throws Exception {
    WMFullResourcePlan fullRp = createRP("test_rp_2", 10, "def");
    addPool(fullRp, "pool1", 0.3, 3, "fair");
    addTrigger(fullRp, "trigger1", "KILL", "BYTES > 2", "pool1");
    addPool(fullRp, "pool2", 0.7, 7, "fcfs");
    addMapping(fullRp, "user", "foo", "pool2");
    addMapping(fullRp, "user", "bar", "pool2");
    formatter.showFullResourcePlan(out, fullRp);
    out.flush();

    ObjectMapper objectMapper = new ObjectMapper();
    JsonNode jsonTree = objectMapper.readTree(bos.toByteArray());

    assertNotNull(jsonTree);
    assertTrue(jsonTree.isObject());
    assertEquals("test_rp_2", jsonTree.get("name").asText());
    assertEquals(10, jsonTree.get("parallelism").asInt());
    assertEquals("def", jsonTree.get("defaultPool").asText());
    assertTrue(jsonTree.get("pools").isArray());
    assertEquals(2, jsonTree.get("pools").size());

    JsonNode pool2 = jsonTree.get("pools").get(0);
    assertEquals("pool2", pool2.get("name").asText());
    assertEquals("fcfs", pool2.get("schedulingPolicy").asText());
    assertEquals(7, pool2.get("parallelism").asInt());
    assertEquals(0.7, pool2.get("allocFraction").asDouble(), 0.00001);
    assertTrue(pool2.get("triggers").isArray());
    assertEquals(0, pool2.get("triggers").size());
    assertTrue(pool2.get("mappings").isArray());
    JsonNode type0 = pool2.get("mappings").get(0);
    assertEquals("user", type0.get("type").asText());
    assertTrue(type0.get("values").isArray());
    assertEquals(2, type0.get("values").size());
    HashSet<String> vals = new HashSet<>();
    for (int i = 0; i < type0.get("values").size(); ++i) {
      vals.add(type0.get("values").get(i).asText());
    }
    assertTrue(vals.contains("foo"));
    assertTrue(vals.contains("bar"));

    JsonNode pool1 = jsonTree.get("pools").get(1);
    assertEquals("pool1", pool1.get("name").asText());
    assertEquals("fair", pool1.get("schedulingPolicy").asText());
    assertEquals(3, pool1.get("parallelism").asInt());
    assertEquals(0.3, pool1.get("allocFraction").asDouble(), 0.00001);
    assertTrue(pool1.get("triggers").isArray());
    assertEquals(1, pool1.get("triggers").size());

    JsonNode trigger1 = pool1.get("triggers").get(0);
    assertEquals("trigger1", trigger1.get("name").asText());
    assertEquals("KILL", trigger1.get("action").asText());
    assertEquals("BYTES > 2", trigger1.get("trigger").asText());
  }
Test class for json resource plan formatter.
ql/src/test/org/apache/hadoop/hive/ql/metadata/formatting/TestJsonRPFormatter.java