コード例 #1
0
  @Test
  public void testDeletePattern() throws Exception {

    // Search for :"name:chefutil-*";
    String search = "name%3A" + name1.substring(0, 9) + "*";
    search = "name%3A" + "rds-default*";
    final List<String> nodes = ChefUtil.searchNodes(search);

    // final JsonNode jsonNodes = JsonUtil.load(nodes);
    for (String node : nodes) {
      JsonNode json = JsonUtil.load(node);
      ChefUtil.deleteNode(json.get("name").getTextValue());
      logger.debug("Deleted: " + json.get("name").getTextValue());
    }
    search = "name%3A" + name1.substring(0, 9) + "*";
    search = "name%3A" + "rds-*";
    final List<String> clients = ChefUtil.searchClients(search);

    // final JsonNode jsonNodes = JsonUtil.load(nodes);
    for (String client : clients) {
      JsonNode json = JsonUtil.load(client);
      ChefUtil.deleteClient(json.get("name").getTextValue());
      logger.debug("Deleted: " + json.get("name").getTextValue());
    }
  }
コード例 #2
0
 @Test
 public void testClient() throws Exception {
   String json = ChefUtil.createClient(name1);
   assertThat("Create returns private key.", json, containsString("BEGIN"));
   assertThat("Create returns private key.", json, containsString("END"));
   json = ChefUtil.getClient(name1);
   assertThat("Client is created.", json, containsString("\"name\":\"" + name1));
   json = ChefUtil.putClientAsAdmin(name1);
   assertThat("Client can be made admin.", json, containsString("\"admin\":true"));
   json = ChefUtil.getClient(name1);
   assertThat("Client is admin.", json, containsString("\"admin\":true"));
 }
コード例 #3
0
 @Test
 public void testNode() throws Exception {
   String jsonText = ChefUtil.createNode(name1);
   ChefUtil.putNodeAttribute(name1, "__TRANSCEND_TEST__", name1);
   logger.debug(jsonText);
   assertThat("Node is created.", jsonText, containsString(name1));
   jsonText = ChefUtil.getNode(name1);
   logger.debug(jsonText);
   JsonNode json = JsonUtil.load(jsonText);
   // logger.debug(JsonUtil.toJsonPrettyPrintString(json));
   assertThat("Node name is correct.", json.get("name").getTextValue(), is(name1));
 }
コード例 #4
0
  @Test
  public void testDatabagAllInOne() throws Exception {
    final String bagContent = "{\"One\":\"one\", " + "\"Two\":\"two\"}";
    ChefUtil.createDatabagItem(bag1, "item1", bagContent);
    ChefUtil.createDatabagItem(bag1, "item2", bagContent);

    String json = ChefUtil.getDatabagItem(bag1, "item1");
    assertThat("Databag is created, item set.", json, containsString("Two"));

    ChefUtil.deleteDatabagItem(bag1, "item1");
    ChefUtil.deleteDatabag(bag1);
  }
コード例 #5
0
  @Test(expected = ChefUtil.InvalidChefRequest.class)
  public void testClientBadArgs() throws Exception {
    String oldClientId = chefUtil.getChefClientId();
    try {
      chefUtil.setChefClientId("some-bad-garbage-id");

      String json = ChefUtil.createClient(name2);
      logger.debug("Got response:" + json);
      json = ChefUtil.getClient(name2);
      logger.debug("Got response:" + json);
    } finally {
      chefUtil.setChefClientId(oldClientId);
    }
  }
コード例 #6
0
 @AfterClass
 public static void cleanupCreated() throws Exception {
   try {
     ChefUtil.deleteClient(name1);
   } catch (Exception e) {
     // ignore.
   }
   try {
     ChefUtil.deleteDatabag(bag1);
   } catch (Exception e) {
     // ignore.
   }
   try {
     ChefUtil.deleteNode(name1);
   } catch (Exception e) {
     // ignore.
   }
 }
コード例 #7
0
  @Test
  public void testSearchNode() throws Exception {
    try {
      ChefUtil.createNode(name1);
      ChefUtil.putNodeAttribute(name1, "__TRANSCEND_TEST__", name1);
    } catch (Exception e) {
      // ignore failure; may have already been created.
    }

    // Search for :"name:chefutil-*";
    String search = "name%3A" + name1.substring(0, 9) + "*";
    final List<String> nodes = ChefUtil.searchNodes(search);

    // final JsonNode jsonNodes = JsonUtil.load(nodes);
    for (String node : nodes) {
      JsonNode json = JsonUtil.load(node);
      logger.debug(JsonUtil.toJsonPrettyPrintString(json));
    }
  }
コード例 #8
0
  @Test
  public void testNodeUpdateRunlist() throws Exception {
    try {
      ChefUtil.createNode(name1);
      ChefUtil.putNodeAttribute(name1, "__TRANSCEND_TEST__", name1);
    } catch (Exception e) {
      // ignore failure; may have already been created.
    }

    String jsonText = ChefUtil.putNodeRunlist(name1, "role[transcend_defaultrole]");
    logger.debug(jsonText);
    jsonText = ChefUtil.getNode(name1);
    JsonNode json = JsonUtil.load(jsonText);
    logger.debug(JsonUtil.toJsonPrettyPrintString(json));
    assertThat("Node name is correct.", json.get("name").getTextValue(), is(name1));
    assertThat(
        "Node attributes are intact.",
        json.get("normal").toString(),
        containsString("__TRANSCEND_TEST__"));
  }
コード例 #9
0
  @Test
  public void testDatabag() throws Exception {
    String json = ChefUtil.createDatabag(bag1);
    assertThat("Databag is created.", json, containsString(bag1));

    json = ChefUtil.createDatabagItem(bag1, "item1");
    assertThat("Databag item is created.", json, containsString("\"id\":\"item1\""));
    final String databag = ChefUtil.getDatabag(bag1);
    logger.debug("Got databag:" + databag);
    // final JsonNode json = JsonUtil.load(databag);
    ChefUtil.putDatabagItem(bag1, "item1", "{\"id\":\"item1\",\"f\":\"fff\"}");
    json = ChefUtil.getDatabagItem(bag1, "item1");
    assertThat("Databag item put ok.", json, containsString("\"f\":\"fff\""));

    ChefUtil.deleteDatabagItem(bag1, "item1");
    ChefUtil.deleteDatabag(bag1);
  }
コード例 #10
0
 @Test
 public void testBasicGet() throws Exception {
   final String json = ChefUtil.executeJson("GET", "/clients", "");
   assertNotNull("client response is valid", json);
 }