Search in sources :

Example 6 with GitTagEntry

use of com.epam.pipeline.entity.git.GitTagEntry 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 7 with GitTagEntry

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

the class GitManagerTest method shouldFetchPipelineDocs.

@Test
public void shouldFetchPipelineDocs() throws GitClientException {
    final Pipeline pipeline = testingPipeline();
    final GitRepositoryEntry bla = new GitRepositoryEntry();
    bla.setName(README_FILE);
    bla.setType(BLOB_TYPE);
    final List<GitRepositoryEntry> tree = singletonList(bla);
    givenThat(get(urlPathEqualTo(api(REPOSITORY_TREE))).withQueryParam(REF_NAME, equalTo(TEST_REVISION)).withQueryParam(PATH, equalTo(DOCS + "/")).withQueryParam(RECURSIVE, equalTo(String.valueOf(false))).willReturn(okJson(with(tree))));
    final GitTagEntry tag = new GitTagEntry();
    givenThat(get(urlPathEqualTo(api(REPOSITORY_TAGS + "/" + TEST_REVISION))).willReturn(okJson(with(tag))));
    final List<GitRepositoryEntry> repoEntries = gitManager.getPipelineDocs(pipeline.getId(), TEST_REVISION);
    final boolean noEntries = repoEntries.isEmpty();
    final boolean docsOnly = repoEntries.stream().filter(e -> !e.getName().startsWith(".")).allMatch(e -> e.getName().endsWith(".md"));
    assertFalse(noEntries);
    assertTrue(docsOnly);
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) PipelineManager(com.epam.pipeline.manager.pipeline.PipelineManager) SneakyThrows(lombok.SneakyThrows) Date(java.util.Date) IsEmptyString.isEmptyString(org.hamcrest.text.IsEmptyString.isEmptyString) ZonedDateTime(java.time.ZonedDateTime) SystemPreferences(com.epam.pipeline.manager.preference.SystemPreferences) Autowired(org.springframework.beans.factory.annotation.Autowired) StringUtils(org.apache.commons.lang3.StringUtils) WireMock.notFound(com.github.tomakehurst.wiremock.client.WireMock.notFound) Collections.singletonList(java.util.Collections.singletonList) Assert.assertThat(org.junit.Assert.assertThat) MockitoAnnotations(org.mockito.MockitoAnnotations) Matchers.anyBoolean(org.mockito.Matchers.anyBoolean) WireMockConfiguration.wireMockConfig(com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig) Matchers.eq(org.mockito.Matchers.eq) After(org.junit.After) PipelineSourceItemVO(com.epam.pipeline.controller.vo.PipelineSourceItemVO) WireMock.givenThat(com.github.tomakehurst.wiremock.client.WireMock.givenThat) WireMock.post(com.github.tomakehurst.wiremock.client.WireMock.post) Path(java.nio.file.Path) Pipeline(com.epam.pipeline.entity.pipeline.Pipeline) SpyBean(org.springframework.boot.test.mock.mockito.SpyBean) GitProject(com.epam.pipeline.entity.git.GitProject) UploadFileMetadata(com.epam.pipeline.controller.vo.UploadFileMetadata) GIT_MASTER_REPOSITORY(com.epam.pipeline.manager.git.GitManager.GIT_MASTER_REPOSITORY) Matchers.any(org.mockito.Matchers.any) Base64(java.util.Base64) List(java.util.List) PipelineSourceItemsVO(com.epam.pipeline.controller.vo.PipelineSourceItemsVO) Whitebox(org.mockito.internal.util.reflection.Whitebox) GitRepositoryUrl(com.epam.pipeline.entity.git.GitRepositoryUrl) Matchers.contains(org.hamcrest.Matchers.contains) Assert.assertFalse(org.junit.Assert.assertFalse) UTC(java.time.ZoneOffset.UTC) CmdExecutor(com.epam.pipeline.manager.CmdExecutor) Comparator.reverseOrder(java.util.Comparator.reverseOrder) UnsupportedEncodingException(java.io.UnsupportedEncodingException) GitTagEntry(com.epam.pipeline.entity.git.GitTagEntry) GitClientException(com.epam.pipeline.exception.git.GitClientException) Mock(org.mockito.Mock) CoreMatchers.not(org.hamcrest.CoreMatchers.not) GitRepositoryEntry(com.epam.pipeline.entity.git.GitRepositoryEntry) WireMock.okJson(com.github.tomakehurst.wiremock.client.WireMock.okJson) CONTENT_TYPE(com.google.common.net.HttpHeaders.CONTENT_TYPE) Matchers.anyString(org.mockito.Matchers.anyString) Value(org.springframework.beans.factory.annotation.Value) WireMockRule(com.github.tomakehurst.wiremock.junit.WireMockRule) GitCommitEntry(com.epam.pipeline.entity.git.GitCommitEntry) AbstractManagerTest(com.epam.pipeline.manager.AbstractManagerTest) Before(org.junit.Before) InjectMocks(org.mockito.InjectMocks) WireMock.get(com.github.tomakehurst.wiremock.client.WireMock.get) WireMock.urlPathEqualTo(com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo) WireMock.equalTo(com.github.tomakehurst.wiremock.client.WireMock.equalTo) PreferenceManager(com.epam.pipeline.manager.preference.PreferenceManager) GitFile(com.epam.pipeline.entity.git.GitFile) Files(java.nio.file.Files) Assert.assertNotNull(org.junit.Assert.assertNotNull) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) File(java.io.File) URLEncoder(java.net.URLEncoder) Rule(org.junit.Rule) Ignore(org.junit.Ignore) WireMock.created(com.github.tomakehurst.wiremock.client.WireMock.created) Paths(java.nio.file.Paths) Revision(com.epam.pipeline.entity.pipeline.Revision) DRAFT_PREFIX(com.epam.pipeline.manager.git.GitManager.DRAFT_PREFIX) Collections(java.util.Collections) GitRepositoryEntry(com.epam.pipeline.entity.git.GitRepositoryEntry) GitTagEntry(com.epam.pipeline.entity.git.GitTagEntry) Pipeline(com.epam.pipeline.entity.pipeline.Pipeline) AbstractManagerTest(com.epam.pipeline.manager.AbstractManagerTest) Test(org.junit.Test)

Example 8 with GitTagEntry

use of com.epam.pipeline.entity.git.GitTagEntry 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 9 with GitTagEntry

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

the class GitManagerTest method getPipelineRevision.

@Test
public void getPipelineRevision() throws GitClientException {
    final Pipeline pipeline = testingPipeline();
    final GitTagEntry tag = new GitTagEntry();
    givenThat(get(urlPathEqualTo(api(REPOSITORY_TAGS + "/" + TEST_REVISION))).willReturn(okJson(with(tag))));
    final GitTagEntry revision = gitManager.loadRevision(pipeline, TEST_REVISION);
    assertNotNull(revision);
}
Also used : GitTagEntry(com.epam.pipeline.entity.git.GitTagEntry) Pipeline(com.epam.pipeline.entity.pipeline.Pipeline) AbstractManagerTest(com.epam.pipeline.manager.AbstractManagerTest) Test(org.junit.Test)

Example 10 with GitTagEntry

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

the class GitManagerTest method shouldLoadRevisionWhenItIsDraft.

@Test
public void shouldLoadRevisionWhenItIsDraft() throws GitClientException {
    final Pipeline pipeline = testingPipeline();
    final GitTagEntry tag = new GitTagEntry();
    final String sha = "somecommitsha";
    givenThat(get(urlPathEqualTo(api(REPOSITORY_COMMITS + "/" + sha))).willReturn(okJson(with(tag))));
    final GitTagEntry revision = gitManager.loadRevision(pipeline, DRAFT_PREFIX + sha);
    assertNotNull(revision);
}
Also used : GitTagEntry(com.epam.pipeline.entity.git.GitTagEntry) IsEmptyString.isEmptyString(org.hamcrest.text.IsEmptyString.isEmptyString) Matchers.anyString(org.mockito.Matchers.anyString) Pipeline(com.epam.pipeline.entity.pipeline.Pipeline) AbstractManagerTest(com.epam.pipeline.manager.AbstractManagerTest) Test(org.junit.Test)

Aggregations

GitTagEntry (com.epam.pipeline.entity.git.GitTagEntry)10 Pipeline (com.epam.pipeline.entity.pipeline.Pipeline)7 AbstractManagerTest (com.epam.pipeline.manager.AbstractManagerTest)7 Test (org.junit.Test)7 GitCommitEntry (com.epam.pipeline.entity.git.GitCommitEntry)5 Revision (com.epam.pipeline.entity.pipeline.Revision)5 IsEmptyString.isEmptyString (org.hamcrest.text.IsEmptyString.isEmptyString)5 Matchers.anyString (org.mockito.Matchers.anyString)5 GitFile (com.epam.pipeline.entity.git.GitFile)3 GitClientException (com.epam.pipeline.exception.git.GitClientException)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 UnexpectedResponseStatusException (com.epam.pipeline.exception.git.UnexpectedResponseStatusException)2 File (java.io.File)2 URI (java.net.URI)2 Date (java.util.Date)2 PipelineSourceItemVO (com.epam.pipeline.controller.vo.PipelineSourceItemVO)1 PipelineSourceItemsVO (com.epam.pipeline.controller.vo.PipelineSourceItemsVO)1 UploadFileMetadata (com.epam.pipeline.controller.vo.UploadFileMetadata)1 GitProject (com.epam.pipeline.entity.git.GitProject)1 GitRepositoryEntry (com.epam.pipeline.entity.git.GitRepositoryEntry)1