From 281f5c3508cd3b6b3bc2617b38bde66c39fad4bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Zaj=C4=85czkowski?= Date: Tue, 13 Nov 2018 00:00:37 +0100 Subject: [PATCH] [#76] Explicitly creating staging repository in Nexus - WIP Internal implementation in the Exploratory E2E tests to verify it with Travis. --- .../functional/e2e/BasicSmokeE2ESpec.groovy | 2 ++ .../functional/e2e/ExploratoryE2ESpec.groovy | 26 +++++++++++++++---- .../resources/sampleProjects/nexus-at-minimal | 2 +- .../infra/SimplifiedHttpJsonRestClient.groovy | 4 +-- .../nexus/logic/RepositoryCreator.groovy | 25 ++++++++++++++++++ 5 files changed, 51 insertions(+), 8 deletions(-) create mode 100644 src/main/groovy/io/codearte/gradle/nexus/logic/RepositoryCreator.groovy diff --git a/src/funcTest/groovy/io/codearte/gradle/nexus/functional/e2e/BasicSmokeE2ESpec.groovy b/src/funcTest/groovy/io/codearte/gradle/nexus/functional/e2e/BasicSmokeE2ESpec.groovy index f771182..4ac3da4 100644 --- a/src/funcTest/groovy/io/codearte/gradle/nexus/functional/e2e/BasicSmokeE2ESpec.groovy +++ b/src/funcTest/groovy/io/codearte/gradle/nexus/functional/e2e/BasicSmokeE2ESpec.groovy @@ -2,9 +2,11 @@ package io.codearte.gradle.nexus.functional.e2e import io.codearte.gradle.nexus.functional.BaseNexusStagingFunctionalSpec import nebula.test.functional.ExecutionResult +import spock.lang.Ignore import spock.lang.Stepwise @Stepwise +@Ignore("Temporary to verify staging repository uplaod from travis in exploratory e2e tests") class BasicSmokeE2ESpec extends BaseNexusStagingFunctionalSpec implements E2ESpecHelperTrait { def "should get staging profile"() { diff --git a/src/funcTest/groovy/io/codearte/gradle/nexus/functional/e2e/ExploratoryE2ESpec.groovy b/src/funcTest/groovy/io/codearte/gradle/nexus/functional/e2e/ExploratoryE2ESpec.groovy index 3bd0ee0..7d3e679 100644 --- a/src/funcTest/groovy/io/codearte/gradle/nexus/functional/e2e/ExploratoryE2ESpec.groovy +++ b/src/funcTest/groovy/io/codearte/gradle/nexus/functional/e2e/ExploratoryE2ESpec.groovy @@ -6,6 +6,7 @@ import io.codearte.gradle.nexus.functional.BaseNexusStagingFunctionalSpec import io.codearte.gradle.nexus.infra.SimplifiedHttpJsonRestClient import io.codearte.gradle.nexus.logic.OperationRetrier import io.codearte.gradle.nexus.logic.RepositoryCloser +import io.codearte.gradle.nexus.logic.RepositoryCreator import io.codearte.gradle.nexus.logic.RepositoryDropper import io.codearte.gradle.nexus.logic.RepositoryFetcher import io.codearte.gradle.nexus.logic.RepositoryReleaser @@ -36,6 +37,7 @@ class ExploratoryE2ESpec extends BaseNexusStagingFunctionalSpec implements E2ESp @NotYetImplemented def "remove all staging repositories if exist as clean up"() {} + //TODO: Remove "should" prefix, it's default by convention def "should get staging profile id from server e2e"() { given: StagingProfileFetcher fetcher = new StagingProfileFetcher(client, E2E_SERVER_BASE_PATH) @@ -45,15 +47,31 @@ class ExploratoryE2ESpec extends BaseNexusStagingFunctionalSpec implements E2ESp stagingProfileId == E2E_STAGING_PROFILE_ID } - def "should upload artifacts to server"() { + def "should create staging repository explicitly e2e"() { given: + RepositoryCreator creator = new RepositoryCreator(client, E2E_SERVER_BASE_PATH) + when: + String stagingRepositoryId = creator.createStagingRepositoryAndReturnId(E2E_STAGING_PROFILE_ID) + then: + println stagingRepositoryId + stagingRepositoryId.startsWith("iogitlabnexus-at") + and: + propagateStagingRepositoryIdToAnotherTest(stagingRepositoryId) + } + + def "should upload artifacts to server e2e"() { + given: + assert resolvedStagingRepositoryId + and: copyResources("sampleProjects//nexus-at-minimal", "") when: - ExecutionResult result = runTasksSuccessfully('uploadArchives') + ExecutionResult result = runTasksSuccessfully('uploadArchives', + "-Pe2eRepositoryUrl=${E2E_SERVER_BASE_PATH}staging/deployByRepositoryId/${resolvedStagingRepositoryId}") then: result.standardOutput.contains('Uploading: io/gitlab/nexus-at/minimal/nexus-at-minimal/') } + //TODO: Adjust to (optionally) just get repository ID in getNonTransitioningRepositoryStateById() def "should get open repository id from server e2e"() { given: RepositoryFetcher fetcher = new RepositoryFetcher(client, E2E_SERVER_BASE_PATH) @@ -61,9 +79,7 @@ class ExploratoryE2ESpec extends BaseNexusStagingFunctionalSpec implements E2ESp String stagingRepositoryId = fetcher.getOpenRepositoryIdForStagingProfileId(E2E_STAGING_PROFILE_ID) then: println stagingRepositoryId - stagingRepositoryId.startsWith("iogitlabnexus-at") - and: - propagateStagingRepositoryIdToAnotherTest(stagingRepositoryId) + stagingRepositoryId == resolvedStagingRepositoryId } def "should get not in transition open repository state by repository id from server e2e"() { diff --git a/src/funcTest/resources/sampleProjects/nexus-at-minimal b/src/funcTest/resources/sampleProjects/nexus-at-minimal index c6abaac..2ab7999 160000 --- a/src/funcTest/resources/sampleProjects/nexus-at-minimal +++ b/src/funcTest/resources/sampleProjects/nexus-at-minimal @@ -1 +1 @@ -Subproject commit c6abaace9801e9d8617cc810fe90d033385d423d +Subproject commit 2ab79997978554b9d4b933b23a860e9a005de795 diff --git a/src/main/groovy/io/codearte/gradle/nexus/infra/SimplifiedHttpJsonRestClient.groovy b/src/main/groovy/io/codearte/gradle/nexus/infra/SimplifiedHttpJsonRestClient.groovy index f94d994..8e6572b 100644 --- a/src/main/groovy/io/codearte/gradle/nexus/infra/SimplifiedHttpJsonRestClient.groovy +++ b/src/main/groovy/io/codearte/gradle/nexus/infra/SimplifiedHttpJsonRestClient.groovy @@ -36,8 +36,8 @@ class SimplifiedHttpJsonRestClient { return (Map) sendRequestHandlingErrors(uri, null, restClient.&get, RequestType.GET).data } - void post(String uri, Map content) { - sendRequestHandlingErrors(uri, content, restClient.&post, RequestType.POST) + Map post(String uri, Map content) { + return (Map) sendRequestHandlingErrors(uri, content, restClient.&post, RequestType.POST).data } private HttpResponseDecorator sendRequestHandlingErrors(String uri, Map content, Closure clientMethodHandler, RequestType requestTypeName) { diff --git a/src/main/groovy/io/codearte/gradle/nexus/logic/RepositoryCreator.groovy b/src/main/groovy/io/codearte/gradle/nexus/logic/RepositoryCreator.groovy new file mode 100644 index 0000000..04d07ce --- /dev/null +++ b/src/main/groovy/io/codearte/gradle/nexus/logic/RepositoryCreator.groovy @@ -0,0 +1,25 @@ +package io.codearte.gradle.nexus.logic + +import groovy.transform.InheritConstructors +import groovy.util.logging.Slf4j +import io.codearte.gradle.nexus.infra.SimplifiedHttpJsonRestClient + +//@InheritConstructors //TODO: Why broken??? +@Slf4j +class RepositoryCreator extends BaseOperationExecutor { + + RepositoryCreator(SimplifiedHttpJsonRestClient client, String nexusUrl) { + super(client, nexusUrl) + } + + String createStagingRepositoryAndReturnId(String stagingProfileId) { + log.info("Creating staging repository for staging profile '$stagingProfileId'") + Map responseAsMap = client.post(nexusUrl + "/staging/profiles/${stagingProfileId}/start", + [data: [description: "Explicitly created by gradle-nexus-staging-plugin"]]) + + log.info("Raw response as map: $responseAsMap") + String repositoryId = responseAsMap.data.stagedRepositoryId + log.info("Created staging repository with id: $repositoryId") + return repositoryId + } +}