Search in sources :

Example 1 with JSONArray

use of com.sdicons.json.model.JSONArray 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("\"\""));
}
Also used : JSONObject(com.sdicons.json.model.JSONObject) JSONArray(com.sdicons.json.model.JSONArray) Test(org.junit.Test)

Example 2 with JSONArray

use of com.sdicons.json.model.JSONArray 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)));
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) JSONObject(com.sdicons.json.model.JSONObject) HashMap(java.util.HashMap) MaterialRevisions(com.thoughtworks.go.domain.MaterialRevisions) JSONArray(com.sdicons.json.model.JSONArray) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) MaterialRevision(com.thoughtworks.go.domain.MaterialRevision) Date(java.util.Date) Test(org.junit.Test)

Example 3 with JSONArray

use of com.sdicons.json.model.JSONArray in project gocd by gocd.

the class MaterialRevisionsJsonBuilderTest method shouldEscapeUsername.

@Test
public void shouldEscapeUsername() throws Exception {
    JSONArray revisions = buildJson();
    JSONObject revision = (JSONObject) revisions.get(0);
    JSONArray jsonArray = (JSONArray) revision.get("modifications");
    JSONObject modification = (JSONObject) jsonArray.get(0);
    assertAttributeInJson(modification, "user", ModificationsMother.MOD_USER_WITH_HTML_CHAR);
    assertAttributeInJson(modification, "comment", escapeHtml(ModificationsMother.MOD_COMMENT_3));
}
Also used : JSONObject(com.sdicons.json.model.JSONObject) JSONArray(com.sdicons.json.model.JSONArray) Test(org.junit.Test)

Example 4 with JSONArray

use of com.sdicons.json.model.JSONArray 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);
}
Also used : JSONObject(com.sdicons.json.model.JSONObject) JSONArray(com.sdicons.json.model.JSONArray) Test(org.junit.Test)

Example 5 with JSONArray

use of com.sdicons.json.model.JSONArray 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");
}
Also used : JSONObject(com.sdicons.json.model.JSONObject) JSONArray(com.sdicons.json.model.JSONArray) Test(org.junit.Test)

Aggregations

JSONArray (com.sdicons.json.model.JSONArray)7 JSONObject (com.sdicons.json.model.JSONObject)6 Test (org.junit.Test)6 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)2 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)2 MaterialRevisions (com.thoughtworks.go.domain.MaterialRevisions)1 Modification (com.thoughtworks.go.domain.materials.Modification)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 List (java.util.List)1