@Test public void test_AddCheckCommandTimeoutParam_ParamsNotAvailable() { UpgradeCatalog221 upgradeCatalog221 = new UpgradeCatalog221(injector); String inputSource = "{ \"path\" : \"test_path\", \"type\" : \"SCRIPT\"}"; String expectedSource = "{\"path\":\"test_path\",\"type\":\"SCRIPT\",\"parameters\":[{\"name\":\"check.command.timeout\",\"display_name\":\"Check command timeout\",\"value\":60.0,\"type\":\"NUMERIC\",\"description\":\"The maximum time before check command will be killed by timeout\",\"units\":\"seconds\"}]}"; String result = upgradeCatalog221.addCheckCommandTimeoutParam(inputSource); Assert.assertEquals(result, expectedSource); }
protected String addCheckCommandTimeoutParam(String source) { JsonObject sourceJson = new JsonParser().parse(source).getAsJsonObject(); JsonArray parametersJson = sourceJson.getAsJsonArray("parameters"); boolean parameterExists = parametersJson != null && !parametersJson.isJsonNull(); if (parameterExists) { Iterator<JsonElement> jsonElementIterator = parametersJson.iterator(); while(jsonElementIterator.hasNext()) { JsonElement element = jsonElementIterator.next(); JsonElement name = element.getAsJsonObject().get("name"); if (name != null && !name.isJsonNull() && name.getAsString().equals("check.command.timeout")) { return sourceJson.toString(); } } } JsonObject checkCommandTimeoutParamJson = new JsonObject(); checkCommandTimeoutParamJson.add("name", new JsonPrimitive("check.command.timeout")); checkCommandTimeoutParamJson.add("display_name", new JsonPrimitive("Check command timeout")); checkCommandTimeoutParamJson.add("value", new JsonPrimitive(60.0)); checkCommandTimeoutParamJson.add("type", new JsonPrimitive("NUMERIC")); checkCommandTimeoutParamJson.add("description", new JsonPrimitive("The maximum time before check command will be killed by timeout")); checkCommandTimeoutParamJson.add("units", new JsonPrimitive("seconds")); if (!parameterExists) { parametersJson = new JsonArray(); parametersJson.add(checkCommandTimeoutParamJson); sourceJson.add("parameters", parametersJson); } else { parametersJson.add(checkCommandTimeoutParamJson); sourceJson.remove("parameters"); sourceJson.add("parameters", parametersJson); } return sourceJson.toString(); }
UpgradeCatalog221 extends AbstractUpgradeCatalog { protected String addCheckCommandTimeoutParam(String source) { JsonObject sourceJson = new JsonParser().parse(source).getAsJsonObject(); JsonArray parametersJson = sourceJson.getAsJsonArray("parameters"); boolean parameterExists = parametersJson != null && !parametersJson.isJsonNull(); if (parameterExists) { Iterator<JsonElement> jsonElementIterator = parametersJson.iterator(); while(jsonElementIterator.hasNext()) { JsonElement element = jsonElementIterator.next(); JsonElement name = element.getAsJsonObject().get("name"); if (name != null && !name.isJsonNull() && name.getAsString().equals("check.command.timeout")) { return sourceJson.toString(); } } } JsonObject checkCommandTimeoutParamJson = new JsonObject(); checkCommandTimeoutParamJson.add("name", new JsonPrimitive("check.command.timeout")); checkCommandTimeoutParamJson.add("display_name", new JsonPrimitive("Check command timeout")); checkCommandTimeoutParamJson.add("value", new JsonPrimitive(60.0)); checkCommandTimeoutParamJson.add("type", new JsonPrimitive("NUMERIC")); checkCommandTimeoutParamJson.add("description", new JsonPrimitive("The maximum time before check command will be killed by timeout")); checkCommandTimeoutParamJson.add("units", new JsonPrimitive("seconds")); if (!parameterExists) { parametersJson = new JsonArray(); parametersJson.add(checkCommandTimeoutParamJson); sourceJson.add("parameters", parametersJson); } else { parametersJson.add(checkCommandTimeoutParamJson); sourceJson.remove("parameters"); sourceJson.add("parameters", parametersJson); } return sourceJson.toString(); } }
UpgradeCatalog221 extends AbstractUpgradeCatalog { protected String addCheckCommandTimeoutParam(String source) { JsonObject sourceJson = new JsonParser().parse(source).getAsJsonObject(); JsonArray parametersJson = sourceJson.getAsJsonArray("parameters"); boolean parameterExists = parametersJson != null && !parametersJson.isJsonNull(); if (parameterExists) { Iterator<JsonElement> jsonElementIterator = parametersJson.iterator(); while(jsonElementIterator.hasNext()) { JsonElement element = jsonElementIterator.next(); JsonElement name = element.getAsJsonObject().get("name"); if (name != null && !name.isJsonNull() && name.getAsString().equals("check.command.timeout")) { return sourceJson.toString(); } } } JsonObject checkCommandTimeoutParamJson = new JsonObject(); checkCommandTimeoutParamJson.add("name", new JsonPrimitive("check.command.timeout")); checkCommandTimeoutParamJson.add("display_name", new JsonPrimitive("Check command timeout")); checkCommandTimeoutParamJson.add("value", new JsonPrimitive(60.0)); checkCommandTimeoutParamJson.add("type", new JsonPrimitive("NUMERIC")); checkCommandTimeoutParamJson.add("description", new JsonPrimitive("The maximum time before check command will be killed by timeout")); checkCommandTimeoutParamJson.add("units", new JsonPrimitive("seconds")); if (!parameterExists) { parametersJson = new JsonArray(); parametersJson.add(checkCommandTimeoutParamJson); sourceJson.add("parameters", parametersJson); } else { parametersJson.add(checkCommandTimeoutParamJson); sourceJson.remove("parameters"); sourceJson.add("parameters", parametersJson); } return sourceJson.toString(); } @Inject  UpgradeCatalog221(Injector injector); }
UpgradeCatalog221 extends AbstractUpgradeCatalog { protected String addCheckCommandTimeoutParam(String source) { JsonObject sourceJson = new JsonParser().parse(source).getAsJsonObject(); JsonArray parametersJson = sourceJson.getAsJsonArray("parameters"); boolean parameterExists = parametersJson != null && !parametersJson.isJsonNull(); if (parameterExists) { Iterator<JsonElement> jsonElementIterator = parametersJson.iterator(); while(jsonElementIterator.hasNext()) { JsonElement element = jsonElementIterator.next(); JsonElement name = element.getAsJsonObject().get("name"); if (name != null && !name.isJsonNull() && name.getAsString().equals("check.command.timeout")) { return sourceJson.toString(); } } } JsonObject checkCommandTimeoutParamJson = new JsonObject(); checkCommandTimeoutParamJson.add("name", new JsonPrimitive("check.command.timeout")); checkCommandTimeoutParamJson.add("display_name", new JsonPrimitive("Check command timeout")); checkCommandTimeoutParamJson.add("value", new JsonPrimitive(60.0)); checkCommandTimeoutParamJson.add("type", new JsonPrimitive("NUMERIC")); checkCommandTimeoutParamJson.add("description", new JsonPrimitive("The maximum time before check command will be killed by timeout")); checkCommandTimeoutParamJson.add("units", new JsonPrimitive("seconds")); if (!parameterExists) { parametersJson = new JsonArray(); parametersJson.add(checkCommandTimeoutParamJson); sourceJson.add("parameters", parametersJson); } else { parametersJson.add(checkCommandTimeoutParamJson); sourceJson.remove("parameters"); sourceJson.add("parameters", parametersJson); } return sourceJson.toString(); } @Inject  UpgradeCatalog221(Injector injector); @Override String getTargetVersion(); @Override String getSourceVersion(); }
UpgradeCatalog221 extends AbstractUpgradeCatalog { protected String addCheckCommandTimeoutParam(String source) { JsonObject sourceJson = new JsonParser().parse(source).getAsJsonObject(); JsonArray parametersJson = sourceJson.getAsJsonArray("parameters"); boolean parameterExists = parametersJson != null && !parametersJson.isJsonNull(); if (parameterExists) { Iterator<JsonElement> jsonElementIterator = parametersJson.iterator(); while(jsonElementIterator.hasNext()) { JsonElement element = jsonElementIterator.next(); JsonElement name = element.getAsJsonObject().get("name"); if (name != null && !name.isJsonNull() && name.getAsString().equals("check.command.timeout")) { return sourceJson.toString(); } } } JsonObject checkCommandTimeoutParamJson = new JsonObject(); checkCommandTimeoutParamJson.add("name", new JsonPrimitive("check.command.timeout")); checkCommandTimeoutParamJson.add("display_name", new JsonPrimitive("Check command timeout")); checkCommandTimeoutParamJson.add("value", new JsonPrimitive(60.0)); checkCommandTimeoutParamJson.add("type", new JsonPrimitive("NUMERIC")); checkCommandTimeoutParamJson.add("description", new JsonPrimitive("The maximum time before check command will be killed by timeout")); checkCommandTimeoutParamJson.add("units", new JsonPrimitive("seconds")); if (!parameterExists) { parametersJson = new JsonArray(); parametersJson.add(checkCommandTimeoutParamJson); sourceJson.add("parameters", parametersJson); } else { parametersJson.add(checkCommandTimeoutParamJson); sourceJson.remove("parameters"); sourceJson.add("parameters", parametersJson); } return sourceJson.toString(); } @Inject  UpgradeCatalog221(Injector injector); @Override String getTargetVersion(); @Override String getSourceVersion();  }