@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()); } }
@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)); } }
@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__")); }
@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)); }
public String toJsonString() throws JsonGenerationException, JsonMappingException, IOException { return JsonUtil.toJsonString(this); }