Search in sources :

Example 1 with JsonValue

use of com.thoughtworks.go.util.JsonValue in project gocd by gocd.

the class P4MaterialTestBase method shouldBeAbleToConvertToJson.

@Test
public void shouldBeAbleToConvertToJson() {
    P4Material p4Material = p4Fixture.material(VIEW);
    Map<String, Object> json = new LinkedHashMap<>();
    p4Material.toJson(json, new StringRevision("123"));
    JsonValue jsonValue = from(json);
    assertThat(jsonValue.getString("scmType"), is("Perforce"));
    assertThat(jsonValue.getString("location"), is(p4Material.getServerAndPort()));
    assertThat(jsonValue.getString("action"), is("Modified"));
}
Also used : JsonValue(com.thoughtworks.go.util.JsonValue) StringRevision(com.thoughtworks.go.domain.materials.mercurial.StringRevision) StringContains.containsString(org.hamcrest.core.StringContains.containsString) Test(org.junit.Test)

Example 2 with JsonValue

use of com.thoughtworks.go.util.JsonValue in project gocd by gocd.

the class GitMaterialTest method shouldBeAbleToConvertToJson.

@Test
public void shouldBeAbleToConvertToJson() {
    Map<String, Object> json = new LinkedHashMap<>();
    git.toJson(json, new StringRevision("123"));
    JsonValue jsonValue = from(json);
    assertThat(jsonValue.getString("scmType"), is("Git"));
    assertThat(new File(jsonValue.getString("location")), is(new File(git.getUrl())));
    assertThat(jsonValue.getString("action"), is("Modified"));
}
Also used : JsonValue(com.thoughtworks.go.util.JsonValue) StringRevision(com.thoughtworks.go.domain.materials.mercurial.StringRevision) StringContains.containsString(org.hamcrest.core.StringContains.containsString) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 3 with JsonValue

use of com.thoughtworks.go.util.JsonValue in project gocd by gocd.

the class SvnMaterialTest method shouldBeAbleToConvertToJson.

@Test
public void shouldBeAbleToConvertToJson() {
    SvnMaterial material = MaterialsMother.svnMaterial("url");
    Map<String, Object> json = new LinkedHashMap<>();
    material.toJson(json, revision);
    JsonValue jsonValue = from(json);
    assertThat(jsonValue.getString("scmType"), is("Subversion"));
    assertThat(new File(jsonValue.getString("location")), is(new File(material.getUrl())));
    assertThat(jsonValue.getString("action"), is("Modified"));
}
Also used : SvnMaterial(com.thoughtworks.go.config.materials.svn.SvnMaterial) JsonValue(com.thoughtworks.go.util.JsonValue) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) File(java.io.File) Test(org.junit.Test)

Example 4 with JsonValue

use of com.thoughtworks.go.util.JsonValue in project gocd by gocd.

the class MaterialRevisionsJsonBuilderTest method shouldRenderDependencyMaterialRevision.

@Test
public void shouldRenderDependencyMaterialRevision() {
    String revision = "cruise/10/dev/1";
    MaterialRevisions revisions = new MaterialRevisions(new MaterialRevision(new DependencyMaterial(new CaseInsensitiveString("cruise"), new CaseInsensitiveString("dev")), new Modification(new Date(), revision, "MOCK_LABEL-12", null)));
    MaterialRevisionsJsonBuilder jsonBuilder = new MaterialRevisionsJsonBuilder(new TrackingTool());
    revisions.accept(jsonBuilder);
    JsonValue revisionsJson = JsonUtils.from(jsonBuilder.json());
    assertThat(revisionsJson.getString(0, "revision_href"), is("pipelines/" + revision));
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) MaterialRevisions(com.thoughtworks.go.domain.MaterialRevisions) JsonValue(com.thoughtworks.go.util.JsonValue) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) MaterialRevision(com.thoughtworks.go.domain.MaterialRevision) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Date(java.util.Date) TrackingTool(com.thoughtworks.go.config.TrackingTool) Test(org.junit.Test)

Example 5 with JsonValue

use of com.thoughtworks.go.util.JsonValue in project gocd by gocd.

the class JobControllerTest method shouldFindTheLatestJobWhenJobStatusIsRequested.

@Test
public void shouldFindTheLatestJobWhenJobStatusIsRequested() throws Exception {
    JobInstance job = JobInstanceMother.buildEndingWithState(JobState.Rescheduled, JobResult.Unknown, "config");
    job.assign("agent", new Date());
    JobInstance newJob = JobInstanceMother.buildEndingWithState(JobState.Building, JobResult.Unknown, "another_config");
    newJob.setId(2);
    newJob.assign("another_agent", new Date());
    String pipelineName = job.getPipelineName();
    String stageName = job.getStageName();
    when(jobInstanceService.buildByIdWithTransitions(job.getId())).thenReturn(job);
    when(jobDetailService.findMostRecentBuild(job.getIdentifier())).thenReturn(newJob);
    when(stageService.getBuildDuration(pipelineName, stageName, newJob)).thenReturn(new DurationBean(newJob.getId(), 5l));
    ModelAndView modelAndView = jobController.handleRequest(pipelineName, stageName, job.getId(), response);
    verify(jobInstanceService).buildByIdWithTransitions(job.getId());
    verify(jobDetailService).findMostRecentBuild(job.getIdentifier());
    verify(stageService).getBuildDuration(pipelineName, stageName, newJob);
    JsonValue json = from(((List) modelAndView.getModel().get("json")).get(0));
    JsonValue buildingInfo = json.getObject("building_info");
    assertThat(buildingInfo.getString("id"), is("2"));
    assertThat(buildingInfo.getString("last_build_duration"), is("5"));
}
Also used : DurationBean(com.thoughtworks.go.dto.DurationBean) JobInstance(com.thoughtworks.go.domain.JobInstance) ModelAndView(org.springframework.web.servlet.ModelAndView) JsonValue(com.thoughtworks.go.util.JsonValue) Date(java.util.Date) Test(org.junit.Test)

Aggregations

JsonValue (com.thoughtworks.go.util.JsonValue)5 Test (org.junit.Test)5 StringRevision (com.thoughtworks.go.domain.materials.mercurial.StringRevision)2 File (java.io.File)2 Date (java.util.Date)2 StringContains.containsString (org.hamcrest.core.StringContains.containsString)2 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)1 TrackingTool (com.thoughtworks.go.config.TrackingTool)1 DependencyMaterial (com.thoughtworks.go.config.materials.dependency.DependencyMaterial)1 SvnMaterial (com.thoughtworks.go.config.materials.svn.SvnMaterial)1 JobInstance (com.thoughtworks.go.domain.JobInstance)1 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)1 MaterialRevisions (com.thoughtworks.go.domain.MaterialRevisions)1 Modification (com.thoughtworks.go.domain.materials.Modification)1 DurationBean (com.thoughtworks.go.dto.DurationBean)1 RandomAccessFile (java.io.RandomAccessFile)1 LinkedHashMap (java.util.LinkedHashMap)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1