Search in sources :

Example 1 with GitCommitEntry

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

the class GitManagerTest method shouldCreateFolder.

@Test
public void shouldCreateFolder() throws GitClientException {
    final Pipeline pipeline = testingPipeline();
    final PipelineSourceItemVO folder = new PipelineSourceItemVO();
    folder.setPath(DOCS);
    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))));
    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) AbstractManagerTest(com.epam.pipeline.manager.AbstractManagerTest) Test(org.junit.Test)

Example 2 with GitCommitEntry

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

the class GitManagerTest method shouldNotFailWhenCreateFile.

@Test
public void shouldNotFailWhenCreateFile() throws GitClientException {
    final GitFile gitFile = new GitFile();
    gitFile.setContent(Base64.getEncoder().encodeToString(FILE_CONTENT.getBytes()));
    givenThat(get(urlPathEqualTo(api(REPOSITORY_FILES))).withQueryParam(FILE_PATH, equalTo(DOCS + "/created_file.txt")).withQueryParam(REF, equalTo(GIT_MASTER_REPOSITORY)).willReturn(okJson(with(gitFile))));
    final GitCommitEntry expectedCommit = new GitCommitEntry();
    givenThat(post(urlPathEqualTo(api(REPOSITORY_COMMITS))).willReturn(okJson(with(expectedCommit))));
    final Pipeline pipeline = testingPipeline();
    final GitCommitEntry resultingCommit = gitManager.updateFile(pipeline, DOCS + "/created_file.txt", FILE_CONTENT, "last commit id doesn't matter", "Create file");
    assertThat(resultingCommit, is(expectedCommit));
}
Also used : GitFile(com.epam.pipeline.entity.git.GitFile) 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 3 with GitCommitEntry

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

the class GitManagerTest method shouldRemoveFolder.

@Test
public void shouldRemoveFolder() throws GitClientException {
    final GitRepositoryEntry repositoryEntry = new GitRepositoryEntry();
    repositoryEntry.setName(README_FILE);
    repositoryEntry.setType(BLOB_TYPE);
    final List<GitRepositoryEntry> tree = singletonList(repositoryEntry);
    givenThat(get(urlPathEqualTo(api(REPOSITORY_TREE))).withQueryParam(REF_NAME, equalTo(GIT_MASTER_REPOSITORY)).withQueryParam(PATH, equalTo(DOCS)).withQueryParam(RECURSIVE, equalTo(String.valueOf(true))).willReturn(okJson(with(tree))));
    final GitCommitEntry expectedCommit = new GitCommitEntry();
    givenThat(post(urlPathEqualTo(api(REPOSITORY_COMMITS))).willReturn(okJson(with(expectedCommit))));
    final Pipeline pipeline = testingPipeline();
    final GitCommitEntry resultingCommit = gitManager.removeFolder(pipeline, DOCS, pipeline.getCurrentVersion().getCommitId(), "Remove the folder");
    assertThat(resultingCommit, is(expectedCommit));
}
Also used : GitRepositoryEntry(com.epam.pipeline.entity.git.GitRepositoryEntry) 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 4 with GitCommitEntry

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

the class GitManagerTest method shouldDeleteFile.

@Test
public void shouldDeleteFile() throws GitClientException {
    final Revision revision = new Revision("Initial commit", "", new Date(), "doesn't matter");
    final Pipeline pipeline = testingPipeline();
    pipeline.setCurrentVersion(revision);
    final GitCommitEntry expectedCommit = new GitCommitEntry();
    givenThat(post(urlPathEqualTo(api(REPOSITORY_COMMITS))).willReturn(okJson(with(expectedCommit))));
    final GitCommitEntry resultingCommit = gitManager.deleteFile(pipeline, DOCS + "/" + README_FILE, pipeline.getCurrentVersion().getCommitId(), "Delete file");
    assertThat(resultingCommit, is(expectedCommit));
}
Also used : Revision(com.epam.pipeline.entity.pipeline.Revision) 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 5 with GitCommitEntry

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

the class GitManagerTest method shouldFetchRevision.

@Test
public void shouldFetchRevision() throws GitClientException {
    final Pipeline pipeline = testingPipeline();
    final long pageSize = 1;
    final List<GitTagEntry> tags = Collections.emptyList();
    givenThat(get(urlPathEqualTo(api(REPOSITORY_TAGS))).withQueryParam("per_page", equalTo(String.valueOf(pageSize))).willReturn(okJson(with(tags))));
    final GitCommitEntry initialCommit = new GitCommitEntry();
    initialCommit.setMessage("New pipeline initial commit");
    initialCommit.setCreatedAt("2017-07-25T13:13:11Z");
    final List<GitCommitEntry> commits = singletonList(initialCommit);
    givenThat(get(urlPathEqualTo(api(REPOSITORY_COMMITS))).willReturn(okJson(with(commits))));
    final List<Revision> revisions = gitManager.getPipelineRevisions(pipeline, pageSize);
    assertFalse(revisions.isEmpty());
}
Also used : Revision(com.epam.pipeline.entity.pipeline.Revision) GitTagEntry(com.epam.pipeline.entity.git.GitTagEntry) Pipeline(com.epam.pipeline.entity.pipeline.Pipeline) GitCommitEntry(com.epam.pipeline.entity.git.GitCommitEntry) 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