use of com.sdicons.json.model.JSONObject in project gocd by gocd.
the class MaterialRevisionsJsonBuilderTest method shouldNotProcessPackageMaterialComment.
@Test
public void shouldNotProcessPackageMaterialComment() throws Exception {
HashMap<String, String> map = new HashMap<>();
map.put("TYPE", "PACKAGE_MATERIAL");
map.put("TRACKBACK_URL", "google.com");
map.put("COMMENT", "comment");
String packageMaterialComment = JsonHelper.toJsonString(map);
Modification modification = new Modification("user", packageMaterialComment, "some@com", new Date(), "1234");
materialRevisions = new MaterialRevisions(new MaterialRevision(MaterialsMother.packageMaterial(), modification));
JSONArray jsonArray = buildJson();
JSONObject modificationJson = (JSONObject) ((JSONArray) ((JSONObject) jsonArray.get(0)).get("modifications")).get(0);
assertThat(modificationJson.get("comment").render(false), is(JsonHelper.toJsonString(packageMaterialComment)));
}
use of com.sdicons.json.model.JSONObject in project gocd by gocd.
the class MaterialRevisionsJsonBuilderTest method shouldShowEmptyFolderInJson.
@Test
public void shouldShowEmptyFolderInJson() {
svnMaterial.setFolder(null);
JSONArray revisions = buildJson();
assertThat(revisions.size(), is(1));
JSONObject jsonValue = (JSONObject) revisions.get(0);
assertThat(jsonValue.get("folder").render(false), is("\"\""));
}
use of com.sdicons.json.model.JSONObject in project gocd by gocd.
the class JsonValue method getObject.
public JsonValue getObject(Object... keys) {
JsonValue current = this;
for (Object key : keys) {
if (key instanceof String) {
if (!(current.jsonValue instanceof JSONObject)) {
throw new IllegalArgumentException(format("Key '%s' does not refer to any attribute of %s", key, current));
}
JSONValue value = ((JSONObject) current.jsonValue).get((String) key);
if (value == null) {
throw new IllegalArgumentException(format("Key '%s' does not refer to any attribute of %s", key, current));
}
current = new JsonValue(value);
} else if (key instanceof Number) {
int index = ((Number) key).intValue();
try {
current = current.getItem(index);
} catch (Exception e) {
String message = String.format("Can not find #%s element in %s", index, current);
throw new RuntimeException(message, e);
}
} else {
throw new RuntimeException("Could not understand key " + key);
}
if (current == null) {
throw new RuntimeException("No such key " + key + "\n Possible keys are : " + current);
}
}
return current;
}
use of com.sdicons.json.model.JSONObject in project gocd by gocd.
the class MaterialRevisionsJsonBuilderTest method shouldShowEachModificationInJson.
@Test
public void shouldShowEachModificationInJson() {
JSONArray revisions = buildJson();
JSONObject revision = (JSONObject) revisions.get(0);
JSONArray jsonArray = (JSONArray) revision.get("modifications");
assertThat(jsonArray.size(), is(3));
JSONObject modification = (JSONObject) jsonArray.get(2);
assertAttributeInJson(modification, "user", ModificationsMother.MOD_USER);
assertAttributeInJson(modification, "comment", ModificationsMother.MOD_COMMENT);
assertAttributeInJson(modification, "date", DateUtils.formatISO8601(ModificationsMother.TWO_DAYS_AGO_CHECKIN));
JSONArray modifiedFiles = (JSONArray) modification.get("modifiedFiles");
assertThat(modifiedFiles.size(), is(1));
JSONObject file = (JSONObject) modifiedFiles.get(0);
assertAttributeInJson(file, "action", ModificationsMother.MOD_MODIFIED_ACTION.toString());
assertAttributeInJson(file, "fileName", ModificationsMother.MOD_FILE_BUILD_XML);
}
use of com.sdicons.json.model.JSONObject in project gocd by gocd.
the class MaterialRevisionsJsonBuilderTest method shouldContainModificationChanged.
@Test
public void shouldContainModificationChanged() throws Exception {
materialRevisions.getMaterialRevision(0).markAsChanged();
JSONArray revisions = buildJson();
JSONObject revision = (JSONObject) revisions.get(0);
JSONArray jsonArray = (JSONArray) revision.get("modifications");
assertAttributeInJson(revision, "changed", "true");
}
Aggregations