Search in sources :

Example 11 with GitCommitEntry

use of com.epam.pipeline.entity.git.GitCommitEntry in project cloud-pipeline by epam.

the class GitManagerTest method getConfigFile.

@Test
public void getConfigFile() {
    final Pipeline pipeline = testingPipeline();
    final String sha = "somecommitsha";
    final Revision revision = new Revision("Initial commit", "", new Date(), DRAFT_PREFIX + sha);
    pipeline.setCurrentVersion(revision);
    final GitCommitEntry initialCommit = new GitCommitEntry();
    initialCommit.setMessage("New pipeline initial commit");
    initialCommit.setCreatedAt("2017-07-25T13:13:11Z");
    initialCommit.setId(sha);
    givenThat(get(urlPathEqualTo(api(REPOSITORY_COMMITS + "/" + initialCommit.getId()))).willReturn(okJson(with(initialCommit))));
    final GitTagEntry tag = new GitTagEntry();
    tag.setName(TEST_REVISION);
    givenThat(get(urlPathEqualTo(api(REPOSITORY_TAGS + "/" + tag.getName()))).willReturn(okJson(with(tag))));
    final File file = gitManager.getConfigFile(pipeline, pipeline.getCurrentVersion().getCommitId());
    assertThat(file.getParentFile().exists(), is(true));
}
Also used : Revision(com.epam.pipeline.entity.pipeline.Revision) IsEmptyString.isEmptyString(org.hamcrest.text.IsEmptyString.isEmptyString) Matchers.anyString(org.mockito.Matchers.anyString) GitTagEntry(com.epam.pipeline.entity.git.GitTagEntry) GitFile(com.epam.pipeline.entity.git.GitFile) File(java.io.File) Date(java.util.Date) Pipeline(com.epam.pipeline.entity.pipeline.Pipeline) GitCommitEntry(com.epam.pipeline.entity.git.GitCommitEntry) AbstractManagerTest(com.epam.pipeline.manager.AbstractManagerTest) Test(org.junit.Test)

Example 12 with GitCommitEntry

use of com.epam.pipeline.entity.git.GitCommitEntry in project cloud-pipeline by epam.

the class GitManagerTest method shouldGetCommits.

@Test
public void shouldGetCommits() throws GitClientException {
    final Pipeline pipeline = testingPipeline();
    final GitCommitEntry expectedCommit = new GitCommitEntry();
    givenThat(get(urlPathEqualTo(api(REPOSITORY_COMMITS))).withQueryParam(REF_NAME, equalTo(pipeline.getCurrentVersion().getCommitId())).willReturn(okJson(with(singletonList(expectedCommit)))));
    final List<GitCommitEntry> commits = gitManager.getCommits(pipeline, pipeline.getCurrentVersion().getCommitId());
    assertThat(commits, contains(expectedCommit));
}
Also used : Pipeline(com.epam.pipeline.entity.pipeline.Pipeline) GitCommitEntry(com.epam.pipeline.entity.git.GitCommitEntry) AbstractManagerTest(com.epam.pipeline.manager.AbstractManagerTest) Test(org.junit.Test)

Example 13 with GitCommitEntry

use of com.epam.pipeline.entity.git.GitCommitEntry in project cloud-pipeline by epam.

the class GitManagerTest method shouldUpdateFiles.

@Test
public void shouldUpdateFiles() throws GitClientException {
    final Pipeline pipeline = testingPipeline();
    final String lastCommit = pipeline.getCurrentVersion().getCommitId();
    final PipelineSourceItemVO bla = new PipelineSourceItemVO();
    bla.setLastCommitId(lastCommit);
    bla.setContents(FILE_CONTENT);
    bla.setComment("Update some file");
    bla.setPath(DOCS + "/" + README_FILE);
    bla.setPreviousPath(DOCS + "/" + README_FILE);
    final PipelineSourceItemsVO sourceItemVOList = new PipelineSourceItemsVO();
    sourceItemVOList.setLastCommitId(lastCommit);
    sourceItemVOList.setItems(singletonList(bla));
    final GitCommitEntry expectedCommit = new GitCommitEntry();
    givenThat(post(urlPathEqualTo(api(REPOSITORY_COMMITS))).willReturn(okJson(with(expectedCommit))));
    final GitCommitEntry resultingCommit = gitManager.updateFiles(pipeline, sourceItemVOList);
    assertThat(resultingCommit, is(expectedCommit));
}
Also used : PipelineSourceItemVO(com.epam.pipeline.controller.vo.PipelineSourceItemVO) IsEmptyString.isEmptyString(org.hamcrest.text.IsEmptyString.isEmptyString) Matchers.anyString(org.mockito.Matchers.anyString) PipelineSourceItemsVO(com.epam.pipeline.controller.vo.PipelineSourceItemsVO) Pipeline(com.epam.pipeline.entity.pipeline.Pipeline) GitCommitEntry(com.epam.pipeline.entity.git.GitCommitEntry) AbstractManagerTest(com.epam.pipeline.manager.AbstractManagerTest) Test(org.junit.Test)

Example 14 with GitCommitEntry

use of com.epam.pipeline.entity.git.GitCommitEntry in project cloud-pipeline by epam.

the class GitManagerTest method shouldCreatePipelineRevision.

@Test
public void shouldCreatePipelineRevision() throws GitClientException {
    final String sha = "anothercommitsha";
    final GitCommitEntry commit = new GitCommitEntry();
    commit.setId(sha);
    commit.setAuthoredDate("2017-07-26T13:13:11Z");
    final GitTagEntry tag = new GitTagEntry();
    final String tagName = "v1.0.1";
    tag.setName(tagName);
    tag.setCommit(commit);
    givenThat(post(urlPathEqualTo(api(REPOSITORY_TAGS))).withQueryParam(REF, equalTo(sha)).withQueryParam(TAG_NAME, equalTo(tagName)).willReturn(created().withHeader(CONTENT_TYPE, "application/json").withBody(with(tag))));
    final Pipeline pipeline = testingPipeline();
    final Revision revision = gitManager.createPipelineRevision(pipeline, tagName, sha, "Message", "Release description");
    assertThat(revision.getName(), is(tag.getName()));
    assertThat(revision.getMessage(), is(tag.getMessage()));
}
Also used : Revision(com.epam.pipeline.entity.pipeline.Revision) IsEmptyString.isEmptyString(org.hamcrest.text.IsEmptyString.isEmptyString) Matchers.anyString(org.mockito.Matchers.anyString) GitTagEntry(com.epam.pipeline.entity.git.GitTagEntry) GitCommitEntry(com.epam.pipeline.entity.git.GitCommitEntry) Pipeline(com.epam.pipeline.entity.pipeline.Pipeline) AbstractManagerTest(com.epam.pipeline.manager.AbstractManagerTest) Test(org.junit.Test)

Example 15 with GitCommitEntry

use of com.epam.pipeline.entity.git.GitCommitEntry in project cloud-pipeline by epam.

the class GitManagerTest method shouldRenameFolder.

@Test
@Ignore
public void shouldRenameFolder() throws GitClientException {
    final Pipeline pipeline = testingPipeline();
    final PipelineSourceItemVO folder = new PipelineSourceItemVO();
    folder.setPreviousPath(DOCS);
    folder.setPath("doc");
    folder.setLastCommitId(pipeline.getCurrentVersion().getCommitId());
    final GitRepositoryEntry bla = new GitRepositoryEntry();
    bla.setName(README_FILE);
    bla.setType(BLOB_TYPE);
    bla.setPath(DOCS + "/" + README_FILE);
    final List<GitRepositoryEntry> tree = singletonList(bla);
    givenThat(get(urlPathEqualTo(api(REPOSITORY_TREE))).withQueryParam(REF_NAME, equalTo(GIT_MASTER_REPOSITORY)).withQueryParam(PATH, equalTo(DOCS)).willReturn(okJson(with(tree))));
    final GitFile file = new GitFile();
    file.setContent(Base64.getEncoder().encodeToString(FILE_CONTENT.getBytes()));
    givenThat(get(urlPathEqualTo(api(REPOSITORY_FILES))).withQueryParam(FILE_PATH, equalTo(DOCS + File.separator + ".gitkeep")).withQueryParam(REF, equalTo(GIT_MASTER_REPOSITORY)).willReturn(okJson(with(file))));
    givenThat(get(urlPathEqualTo(api(REPOSITORY_FILES))).withQueryParam(FILE_PATH, equalTo("doc" + File.separator + ".gitkeep")).withQueryParam(REF, equalTo(GIT_MASTER_REPOSITORY)).willReturn(notFound()));
    final GitCommitEntry expectedCommit = new GitCommitEntry();
    givenThat(post(urlPathEqualTo(api(REPOSITORY_COMMITS))).willReturn(okJson(with(expectedCommit))));
    final GitCommitEntry resultingCommit = gitManager.createOrRenameFolder(pipeline.getId(), folder);
    assertThat(resultingCommit, is(expectedCommit));
}
Also used : PipelineSourceItemVO(com.epam.pipeline.controller.vo.PipelineSourceItemVO) GitFile(com.epam.pipeline.entity.git.GitFile) GitRepositoryEntry(com.epam.pipeline.entity.git.GitRepositoryEntry) Pipeline(com.epam.pipeline.entity.pipeline.Pipeline) GitCommitEntry(com.epam.pipeline.entity.git.GitCommitEntry) Ignore(org.junit.Ignore) AbstractManagerTest(com.epam.pipeline.manager.AbstractManagerTest) Test(org.junit.Test)

Aggregations

GitCommitEntry (com.epam.pipeline.entity.git.GitCommitEntry)15 Pipeline (com.epam.pipeline.entity.pipeline.Pipeline)13 AbstractManagerTest (com.epam.pipeline.manager.AbstractManagerTest)13 Test (org.junit.Test)13 GitFile (com.epam.pipeline.entity.git.GitFile)6 IsEmptyString.isEmptyString (org.hamcrest.text.IsEmptyString.isEmptyString)5 Matchers.anyString (org.mockito.Matchers.anyString)5 PipelineSourceItemVO (com.epam.pipeline.controller.vo.PipelineSourceItemVO)4 GitTagEntry (com.epam.pipeline.entity.git.GitTagEntry)4 Revision (com.epam.pipeline.entity.pipeline.Revision)4 GitRepositoryEntry (com.epam.pipeline.entity.git.GitRepositoryEntry)3 GitClientException (com.epam.pipeline.exception.git.GitClientException)2 UnexpectedResponseStatusException (com.epam.pipeline.exception.git.UnexpectedResponseStatusException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2 Date (java.util.Date)2 Ignore (org.junit.Ignore)2 HttpClientErrorException (org.springframework.web.client.HttpClientErrorException)2 RestTemplate (org.springframework.web.client.RestTemplate)2