diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 83f1f9bd480..0b180fbcc8c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -81,6 +81,10 @@ jobs: GCP_SERVICE_ACCOUNT_PATH: '${{ github.workspace }}/key_file.json' SCM_TEST_REPO_URL: ${{ secrets.SCM_TEST_REPO_URL }} SCM_TEST_REPO_PAT: ${{ secrets.SCM_TEST_REPO_PAT }} + SCM_TEST_REPO_URL_GITLAB: ${{ secrets.SCM_TEST_REPO_URL_GITLAB }} + SCM_TEST_REPO_PAT_GITLAB: ${{ secrets.SCM_TEST_REPO_PAT_GITLAB }} + SCM_TEST_REPO_URL_BITBUCKET: ${{ secrets.SCM_TEST_REPO_URL_BITBUCKET }} + SCM_TEST_REPO_PAT_BITBUCKET: ${{ secrets.SCM_TEST_REPO_PAT_BITBUCKET }} run: | echo $GCP_SERVICE_ACCOUNT_CONTENTS > ./key_file.json yarn run cdap-full-build-more-memory # Build UI diff --git a/pom.xml b/pom.xml index 96dcc835ea3..1ae3042d65f 100644 --- a/pom.xml +++ b/pom.xml @@ -183,7 +183,7 @@ org.apache.rat apache-rat-plugin - 0.10 + 0.11 rat-check @@ -599,6 +599,8 @@ TestRunner.java + TestRunnerWithGitlab.java + TestRunnerWithBitbucket.java classes 4 diff --git a/src/e2e-test/features/source.control.management.repository.feature b/src/e2e-test/features/source.control.management.repository.feature index c8adb0f01f7..d7582fda976 100644 --- a/src/e2e-test/features/source.control.management.repository.feature +++ b/src/e2e-test/features/source.control.management.repository.feature @@ -14,7 +14,7 @@ # the License. # -@Integration_Tests +@Integration_Tests @SCM_GITHUB_TEST @SCM_GITLAB_TEST @SCM_BITBUCKET_TEST Feature: Source Control Management - Repository Configuration CRUD operations @SOURCE_CONTROL_MANAGEMENT_TEST diff --git a/src/e2e-test/features/source.control.management.sync.apps.feature b/src/e2e-test/features/source.control.management.sync.apps.feature index 7bceffbe458..e6861940210 100644 --- a/src/e2e-test/features/source.control.management.sync.apps.feature +++ b/src/e2e-test/features/source.control.management.sync.apps.feature @@ -14,7 +14,7 @@ # the License. # -@Integration_Tests +@Integration_Tests @SCM_GITHUB_TEST @SCM_GITLAB_TEST @SCM_BITBUCKET_TEST Feature: Source Control Management - Pulling and pushing applications Background: When Open Source Control Management Page diff --git a/src/e2e-test/java/io/cdap/cdap/ui/runners/TestRunner.java b/src/e2e-test/java/io/cdap/cdap/ui/runners/TestRunner.java index 941f7a5115a..44d5bfeee94 100644 --- a/src/e2e-test/java/io/cdap/cdap/ui/runners/TestRunner.java +++ b/src/e2e-test/java/io/cdap/cdap/ui/runners/TestRunner.java @@ -26,7 +26,7 @@ @RunWith(Cucumber.class) @CucumberOptions( features = {"src/e2e-test/features"}, - glue = {"io.cdap.cdap.ui.stepsdesign", "stepsdesign"}, + glue = {"io.cdap.cdap.ui.stepsdesign", "io.cdap.cdap.ui.testconfig.github", "stepsdesign"}, tags = {"not @ignore"}, plugin = {"pretty", "html:target/cucumber-html-report/tethering", "json:target/cucumber-reports/cucumber-tethering.json", diff --git a/src/e2e-test/java/io/cdap/cdap/ui/runners/TestRunnerWithBitbucket.java b/src/e2e-test/java/io/cdap/cdap/ui/runners/TestRunnerWithBitbucket.java new file mode 100644 index 00000000000..68237e60c2a --- /dev/null +++ b/src/e2e-test/java/io/cdap/cdap/ui/runners/TestRunnerWithBitbucket.java @@ -0,0 +1,36 @@ +/* + * Copyright © 2024 Cask Data, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package io.cdap.cdap.ui.runners; + +import io.cucumber.junit.Cucumber; +import io.cucumber.junit.CucumberOptions; +import org.junit.runner.RunWith; + +/** + * Test Runner to execute namespace creation related test cases. + */ +@RunWith(Cucumber.class) +@CucumberOptions( + features = {"src/e2e-test/features"}, + glue = {"io.cdap.cdap.ui.stepsdesign", "io.cdap.cdap.ui.testconfig.bitbucket", "stepsdesign"}, + tags = {"@SCM_BITBUCKET_TEST"}, + plugin = {"pretty", "html:target/cucumber-html-report/tethering", + "json:target/cucumber-reports/cucumber-tethering.json", + "junit:target/cucumber-reports/cucumber-tethering.xml"} +) +public class TestRunnerWithBitbucket { +} diff --git a/src/e2e-test/java/io/cdap/cdap/ui/runners/TestRunnerWithGitlab.java b/src/e2e-test/java/io/cdap/cdap/ui/runners/TestRunnerWithGitlab.java new file mode 100644 index 00000000000..69fcde5c557 --- /dev/null +++ b/src/e2e-test/java/io/cdap/cdap/ui/runners/TestRunnerWithGitlab.java @@ -0,0 +1,36 @@ +/* + * Copyright © 2024 Cask Data, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package io.cdap.cdap.ui.runners; + +import io.cucumber.junit.Cucumber; +import io.cucumber.junit.CucumberOptions; +import org.junit.runner.RunWith; + +/** + * Test Runner to execute namespace creation related test cases. + */ +@RunWith(Cucumber.class) +@CucumberOptions( + features = {"src/e2e-test/features"}, + glue = {"io.cdap.cdap.ui.stepsdesign", "io.cdap.cdap.ui.testconfig.gitlab", "stepsdesign"}, + tags = {"@SCM_GITLAB_TEST"}, + plugin = {"pretty", "html:target/cucumber-html-report/tethering", + "json:target/cucumber-reports/cucumber-tethering.json", + "junit:target/cucumber-reports/cucumber-tethering.xml"} +) +public class TestRunnerWithGitlab { +} diff --git a/src/e2e-test/java/io/cdap/cdap/ui/stepsdesign/AfterActions.java b/src/e2e-test/java/io/cdap/cdap/ui/stepsdesign/AfterActions.java index 38ba7972744..4786a8c69c5 100644 --- a/src/e2e-test/java/io/cdap/cdap/ui/stepsdesign/AfterActions.java +++ b/src/e2e-test/java/io/cdap/cdap/ui/stepsdesign/AfterActions.java @@ -19,10 +19,7 @@ import io.cdap.cdap.ui.utils.Constants; import io.cdap.cdap.ui.utils.Helper; import io.cucumber.java.After; -import org.eclipse.jgit.api.errors.GitAPIException; - import java.io.File; -import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; @@ -41,9 +38,4 @@ public static void cleanupDownloadDirectory() { Helper.cleanupDirectory(downloadsDir); } } - - @After(order = 1, value = "@SOURCE_CONTROL_MANAGEMENT_TEST") - public void cleanUpTestBranch() throws IOException, GitAPIException { - Helper.cleanupSCMTestBranch(); - } } diff --git a/src/e2e-test/java/io/cdap/cdap/ui/stepsdesign/BeforeActions.java b/src/e2e-test/java/io/cdap/cdap/ui/stepsdesign/BeforeActions.java index 4e2047fd99f..61bb45aeb52 100644 --- a/src/e2e-test/java/io/cdap/cdap/ui/stepsdesign/BeforeActions.java +++ b/src/e2e-test/java/io/cdap/cdap/ui/stepsdesign/BeforeActions.java @@ -16,18 +16,12 @@ package io.cdap.cdap.ui.stepsdesign; -import com.google.common.base.Strings; -import io.cdap.cdap.ui.utils.Constants; import io.cdap.cdap.ui.utils.Helper; -import io.cdap.e2e.utils.PluginPropertyUtils; import io.cucumber.java.Before; -import org.eclipse.jgit.api.errors.GitAPIException; +import java.io.IOException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.IOException; -import java.util.UUID; - public class BeforeActions { private static final Logger logger = LoggerFactory.getLogger(stepsdesign.BeforeActions.class); @@ -36,24 +30,4 @@ public void loginIfRequired() throws IOException { logger.info("-----------------Logging in if required------------------"); Helper.loginIfRequired(); } - - @Before(order = 1, value = "@SOURCE_CONTROL_MANAGEMENT_TEST") - public void createGitBranchConfig() throws GitAPIException, IOException { - String gitRepoUrl = System.getenv("SCM_TEST_REPO_URL"); - if (!Strings.isNullOrEmpty(gitRepoUrl)) { - PluginPropertyUtils.addPluginProp(Constants.GIT_REPO_URL_PROP_NAME, gitRepoUrl); - } - - String gitPAT = System.getenv("SCM_TEST_REPO_PAT"); - if (!Strings.isNullOrEmpty(gitPAT)) { - PluginPropertyUtils.addPluginProp(Constants.GIT_PAT_PROP_NAME, gitPAT); - } - - if (Strings.isNullOrEmpty(PluginPropertyUtils.pluginProp(Constants.GIT_BRANCH_PROP_NAME))) { - String branchName = "cdf-e2e-test-" + UUID.randomUUID(); - PluginPropertyUtils.addPluginProp(Constants.GIT_BRANCH_PROP_NAME, branchName); - } - - Helper.createSCMRemoteBranch(); - } } diff --git a/src/e2e-test/java/io/cdap/cdap/ui/stepsdesign/SourceControlManagement.java b/src/e2e-test/java/io/cdap/cdap/ui/stepsdesign/SourceControlManagement.java index 3be17979873..ad5efd7810c 100644 --- a/src/e2e-test/java/io/cdap/cdap/ui/stepsdesign/SourceControlManagement.java +++ b/src/e2e-test/java/io/cdap/cdap/ui/stepsdesign/SourceControlManagement.java @@ -42,6 +42,14 @@ public void openAddRepositoryButton() { ElementHelper.clickOnElement(Helper.locateElementByTestId("link-repository-button")); } + private void selectScmProvider(String providerType) { + WebElement scmProviderSelect = Helper.locateElementByTestId("select-provider"); + ElementHelper.clickOnElement(scmProviderSelect); + WebElement providerOption = Helper.locateElementByTestId("option-" + providerType); + WaitHelper.waitForElementToBeDisplayed(providerOption); + ElementHelper.clickOnElement(providerOption); + } + private void addRepoUrl(String repoUrl) { WebElement repoUrlInput = Helper.locateElementByTestId("repoUrl"); ElementHelper.clearElementValue(repoUrlInput); @@ -122,6 +130,7 @@ public void addFakeRepositoryConfiguration() { @Then("Add test repository configuration") public void addTestRepositoryConfiguration() { + selectScmProvider(PluginPropertyUtils.pluginProp(Constants.SCM_PROVIDER_PROP_NAME)); addRepoUrl(PluginPropertyUtils.pluginProp(Constants.GIT_REPO_URL_PROP_NAME)); addTokenName(Constants.FAKE_TOKEN_NAME); addToken(PluginPropertyUtils.pluginProp(Constants.GIT_PAT_PROP_NAME)); @@ -174,6 +183,7 @@ public void pipelineBannerIsShownWithMessage(String message) { @When("Initialize the repository config") public void initializeRepoConfig() { openAddRepositoryButton(); + selectScmProvider(PluginPropertyUtils.pluginProp(Constants.SCM_PROVIDER_PROP_NAME)); addRepoUrl(PluginPropertyUtils.pluginProp(Constants.GIT_REPO_URL_PROP_NAME)); addToken(PluginPropertyUtils.pluginProp(Constants.GIT_PAT_PROP_NAME)); addTokenName("e2e-test-token"); diff --git a/src/e2e-test/java/io/cdap/cdap/ui/testconfig/bitbucket/AfterActions.java b/src/e2e-test/java/io/cdap/cdap/ui/testconfig/bitbucket/AfterActions.java new file mode 100644 index 00000000000..8f437db9f58 --- /dev/null +++ b/src/e2e-test/java/io/cdap/cdap/ui/testconfig/bitbucket/AfterActions.java @@ -0,0 +1,30 @@ +/* + * Copyright © 2024 Cask Data, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package io.cdap.cdap.ui.testconfig.bitbucket; + +import io.cdap.cdap.ui.utils.Helper; +import io.cdap.cdap.ui.utils.ScmProviderType; +import io.cucumber.java.After; +import java.io.IOException; +import org.eclipse.jgit.api.errors.GitAPIException; + +public class AfterActions { + @After(order = 1, value = "@SCM_BITBUCKET_TEST") + public void cleanUpTestBranch() throws IOException, GitAPIException { + Helper.cleanupSCMTestBranch(ScmProviderType.BITBUCKET_CLOUD); + } +} diff --git a/src/e2e-test/java/io/cdap/cdap/ui/testconfig/bitbucket/BeforeActions.java b/src/e2e-test/java/io/cdap/cdap/ui/testconfig/bitbucket/BeforeActions.java new file mode 100644 index 00000000000..cf27f7c4686 --- /dev/null +++ b/src/e2e-test/java/io/cdap/cdap/ui/testconfig/bitbucket/BeforeActions.java @@ -0,0 +1,42 @@ +/* + * Copyright © 2024 Cask Data, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package io.cdap.cdap.ui.testconfig.bitbucket; + +import io.cdap.cdap.ui.testconfig.common.ScmConfigHelper; +import io.cdap.cdap.ui.utils.Constants; +import io.cdap.cdap.ui.utils.Helper; +import io.cdap.cdap.ui.utils.ScmProviderType; +import io.cdap.e2e.utils.PluginPropertyUtils; +import io.cucumber.java.Before; +import java.io.IOException; +import org.eclipse.jgit.api.errors.GitAPIException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class BeforeActions { + private static final Logger logger = LoggerFactory.getLogger(stepsdesign.BeforeActions.class); + + @Before(order = 1, value = "@SCM_BITBUCKET_TEST") + public void createBitbucketBranchConfig() throws GitAPIException, IOException { + logger.info("----------------- Using bitbucket for SCM ------------------"); + PluginPropertyUtils.addPluginProp(Constants.SCM_PROVIDER_PROP_NAME, "BITBUCKET_CLOUD"); + ScmConfigHelper.setupScmCredentials( + "SCM_TEST_REPO_URL_BITBUCKET", + "SCM_TEST_REPO_PAT_BITBUCKET"); + Helper.createSCMRemoteBranch(ScmProviderType.BITBUCKET_CLOUD); + } +} diff --git a/src/e2e-test/java/io/cdap/cdap/ui/testconfig/common/ScmConfigHelper.java b/src/e2e-test/java/io/cdap/cdap/ui/testconfig/common/ScmConfigHelper.java new file mode 100644 index 00000000000..7c708a112c9 --- /dev/null +++ b/src/e2e-test/java/io/cdap/cdap/ui/testconfig/common/ScmConfigHelper.java @@ -0,0 +1,41 @@ +/* + * Copyright © 2024 Cask Data, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package io.cdap.cdap.ui.testconfig.common; + +import com.google.common.base.Strings; +import io.cdap.cdap.ui.utils.Constants; +import io.cdap.e2e.utils.PluginPropertyUtils; +import java.util.UUID; + +public class ScmConfigHelper { + public static void setupScmCredentials(String repoUrlVarName, String repoPatVarName) { + String gitRepoUrl = System.getenv(repoUrlVarName); + if (!Strings.isNullOrEmpty(gitRepoUrl)) { + PluginPropertyUtils.addPluginProp(Constants.GIT_REPO_URL_PROP_NAME, gitRepoUrl); + } + + String gitPAT = System.getenv(repoPatVarName); + if (!Strings.isNullOrEmpty(gitPAT)) { + PluginPropertyUtils.addPluginProp(Constants.GIT_PAT_PROP_NAME, gitPAT); + } + + if (Strings.isNullOrEmpty(PluginPropertyUtils.pluginProp(Constants.GIT_BRANCH_PROP_NAME))) { + String branchName = "cdf-e2e-test-" + UUID.randomUUID(); + PluginPropertyUtils.addPluginProp(Constants.GIT_BRANCH_PROP_NAME, branchName); + } + } +} diff --git a/src/e2e-test/java/io/cdap/cdap/ui/testconfig/github/AfterActions.java b/src/e2e-test/java/io/cdap/cdap/ui/testconfig/github/AfterActions.java new file mode 100644 index 00000000000..4ee3a618483 --- /dev/null +++ b/src/e2e-test/java/io/cdap/cdap/ui/testconfig/github/AfterActions.java @@ -0,0 +1,30 @@ +/* + * Copyright © 2024 Cask Data, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package io.cdap.cdap.ui.testconfig.github; + +import io.cdap.cdap.ui.utils.Helper; +import io.cdap.cdap.ui.utils.ScmProviderType; +import io.cucumber.java.After; +import java.io.IOException; +import org.eclipse.jgit.api.errors.GitAPIException; + +public class AfterActions { + @After(order = 1, value = "@SCM_GITHUB_TEST") + public void cleanUpTestBranch() throws IOException, GitAPIException { + Helper.cleanupSCMTestBranch(ScmProviderType.GITHUB); + } +} diff --git a/src/e2e-test/java/io/cdap/cdap/ui/testconfig/github/BeforeActions.java b/src/e2e-test/java/io/cdap/cdap/ui/testconfig/github/BeforeActions.java new file mode 100644 index 00000000000..4a72851e1ea --- /dev/null +++ b/src/e2e-test/java/io/cdap/cdap/ui/testconfig/github/BeforeActions.java @@ -0,0 +1,42 @@ +/* + * Copyright © 2024 Cask Data, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package io.cdap.cdap.ui.testconfig.github; + +import io.cdap.cdap.ui.testconfig.common.ScmConfigHelper; +import io.cdap.cdap.ui.utils.Constants; +import io.cdap.cdap.ui.utils.Helper; +import io.cdap.cdap.ui.utils.ScmProviderType; +import io.cdap.e2e.utils.PluginPropertyUtils; +import io.cucumber.java.Before; +import java.io.IOException; +import org.eclipse.jgit.api.errors.GitAPIException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class BeforeActions { + private static final Logger logger = LoggerFactory.getLogger(stepsdesign.BeforeActions.class); + + @Before(order = 1, value = "@SCM_GITHUB_TEST") + public void createGithubBranchConfig() throws GitAPIException, IOException { + logger.info("----------------- Using Github for SCM ------------------"); + PluginPropertyUtils.addPluginProp(Constants.SCM_PROVIDER_PROP_NAME, "GITHUB"); + ScmConfigHelper.setupScmCredentials( + "SCM_TEST_REPO_URL", + "SCM_TEST_REPO_PAT"); + Helper.createSCMRemoteBranch(ScmProviderType.GITHUB); + } +} diff --git a/src/e2e-test/java/io/cdap/cdap/ui/testconfig/gitlab/AfterActions.java b/src/e2e-test/java/io/cdap/cdap/ui/testconfig/gitlab/AfterActions.java new file mode 100644 index 00000000000..8300de095de --- /dev/null +++ b/src/e2e-test/java/io/cdap/cdap/ui/testconfig/gitlab/AfterActions.java @@ -0,0 +1,30 @@ +/* + * Copyright © 2024 Cask Data, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package io.cdap.cdap.ui.testconfig.gitlab; + +import io.cdap.cdap.ui.utils.Helper; +import io.cdap.cdap.ui.utils.ScmProviderType; +import io.cucumber.java.After; +import java.io.IOException; +import org.eclipse.jgit.api.errors.GitAPIException; + +public class AfterActions { + @After(order = 1, value = "@SCM_GITLAB_TEST") + public void cleanUpTestBranch() throws IOException, GitAPIException { + Helper.cleanupSCMTestBranch(ScmProviderType.GITLAB); + } +} diff --git a/src/e2e-test/java/io/cdap/cdap/ui/testconfig/gitlab/BeforeActions.java b/src/e2e-test/java/io/cdap/cdap/ui/testconfig/gitlab/BeforeActions.java new file mode 100644 index 00000000000..8c6343b024b --- /dev/null +++ b/src/e2e-test/java/io/cdap/cdap/ui/testconfig/gitlab/BeforeActions.java @@ -0,0 +1,42 @@ +/* + * Copyright © 2024 Cask Data, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package io.cdap.cdap.ui.testconfig.gitlab; + +import io.cdap.cdap.ui.testconfig.common.ScmConfigHelper; +import io.cdap.cdap.ui.utils.Constants; +import io.cdap.cdap.ui.utils.Helper; +import io.cdap.cdap.ui.utils.ScmProviderType; +import io.cdap.e2e.utils.PluginPropertyUtils; +import io.cucumber.java.Before; +import java.io.IOException; +import org.eclipse.jgit.api.errors.GitAPIException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class BeforeActions { + private static final Logger logger = LoggerFactory.getLogger(stepsdesign.BeforeActions.class); + + @Before(order = 1, value = "@SCM_GITLAB_TEST") + public void createGitlabBranchConfig() throws GitAPIException, IOException { + logger.info("----------------- Using Gitlab for SCM ------------------"); + PluginPropertyUtils.addPluginProp(Constants.SCM_PROVIDER_PROP_NAME, "GITLAB"); + ScmConfigHelper.setupScmCredentials( + "SCM_TEST_REPO_URL_GITLAB", + "SCM_TEST_REPO_PAT_GITLAB"); + Helper.createSCMRemoteBranch(ScmProviderType.GITLAB); + } +} diff --git a/src/e2e-test/java/io/cdap/cdap/ui/utils/Constants.java b/src/e2e-test/java/io/cdap/cdap/ui/utils/Constants.java index aec8c33c2c4..2ebaeb357d2 100644 --- a/src/e2e-test/java/io/cdap/cdap/ui/utils/Constants.java +++ b/src/e2e-test/java/io/cdap/cdap/ui/utils/Constants.java @@ -96,4 +96,5 @@ private static double getRandomArbitrary(int min, int max) { public static final int GIT_COMMAND_TIMEOUT_SECONDS = 10; public static final String GIT_PAT_PROP_NAME = "gitPAT"; public static final String GIT_PATH_PREFIX_PROP_NAME = "gitRepositoryPathPrefix"; + public static final String SCM_PROVIDER_PROP_NAME = "scmProvider"; } diff --git a/src/e2e-test/java/io/cdap/cdap/ui/utils/Helper.java b/src/e2e-test/java/io/cdap/cdap/ui/utils/Helper.java index 618927799e5..35f4d747a05 100644 --- a/src/e2e-test/java/io/cdap/cdap/ui/utils/Helper.java +++ b/src/e2e-test/java/io/cdap/cdap/ui/utils/Helper.java @@ -32,6 +32,18 @@ import io.cdap.e2e.utils.PluginPropertyUtils; import io.cdap.e2e.utils.SeleniumDriver; import io.cdap.e2e.utils.WaitHelper; +import java.io.File; +import java.io.IOException; +import java.io.Reader; +import java.net.URISyntaxException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; +import java.util.stream.Collectors; import org.apache.commons.io.FileUtils; import org.apache.http.NameValuePair; import org.apache.http.client.utils.URIBuilder; @@ -59,19 +71,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.File; -import java.io.IOException; -import java.io.Reader; -import java.net.URISyntaxException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; -import java.util.stream.Collectors; - public class Helper implements CdfHelper { private static final Gson GSON = new Gson(); @@ -497,14 +496,14 @@ public static void gotoDeployedPipeline(String pipelineName) { SeleniumDriver.openPage(Constants.BASE_PIPELINES_URL + "/view/" + pipelineName); } - public static void createSCMRemoteBranch() throws IOException, GitAPIException { + public static void createSCMRemoteBranch(ScmProviderType scmProviderType) throws IOException, GitAPIException { String branch = PluginPropertyUtils.pluginProp(Constants.GIT_BRANCH_PROP_NAME); if (Strings.isNullOrEmpty(branch)) { throw new IllegalArgumentException("SCM testing default branch is not specified"); } Path tempDir = Files.createTempDirectory("e2e-clone-repo"); - CredentialsProvider creds = getCredentialsProvider(); + CredentialsProvider creds = getCredentialsProvider(scmProviderType); try (Git git = cloneRemote(tempDir, creds)) { git.checkout().setCreateBranch(true).setName(branch).call(); git.push() @@ -516,9 +515,9 @@ public static void createSCMRemoteBranch() throws IOException, GitAPIException { DirUtils.deleteDirectoryContents(tempDir.toFile()); } - public static void cleanupSCMTestBranch() throws IOException, GitAPIException { + public static void cleanupSCMTestBranch(ScmProviderType providerType) throws IOException, GitAPIException { Path tempDir = Files.createTempDirectory("e2e-clone-repo"); - CredentialsProvider creds = getCredentialsProvider(); + CredentialsProvider creds = getCredentialsProvider(providerType); try (Git git = cloneRemote(tempDir, creds)) { String branch = PluginPropertyUtils.pluginProp(Constants.GIT_BRANCH_PROP_NAME); //delete branch on remote @@ -531,13 +530,17 @@ public static void cleanupSCMTestBranch() throws IOException, GitAPIException { DirUtils.deleteDirectoryContents(tempDir.toFile()); } - private static CredentialsProvider getCredentialsProvider() { + private static CredentialsProvider getCredentialsProvider(ScmProviderType providerType) { String token = PluginPropertyUtils.pluginProp(Constants.GIT_PAT_PROP_NAME); if (Strings.isNullOrEmpty(token)) { throw new IllegalArgumentException("SCM testing token is not specified"); } - return new UsernamePasswordCredentialsProvider("oauth2", token); + String userName = "oauth2"; + if (providerType == ScmProviderType.BITBUCKET_CLOUD) { + userName = "x-token-auth"; + } + return new UsernamePasswordCredentialsProvider(userName, token); } private static Git cloneRemote(Path dir, CredentialsProvider creds) throws GitAPIException { diff --git a/src/e2e-test/java/io/cdap/cdap/ui/utils/ScmProviderType.java b/src/e2e-test/java/io/cdap/cdap/ui/utils/ScmProviderType.java new file mode 100644 index 00000000000..100337bbc7c --- /dev/null +++ b/src/e2e-test/java/io/cdap/cdap/ui/utils/ScmProviderType.java @@ -0,0 +1,24 @@ +/* + * Copyright © 2024 Cask Data, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package io.cdap.cdap.ui.utils; + +public enum ScmProviderType { + GITHUB, + GITLAB, + BITBUCKET_SERVER, + BITBUCKET_CLOUD +} diff --git a/src/e2e-test/resources/pluginParameters.properties b/src/e2e-test/resources/pluginParameters.properties index 3038b8d2b2a..98ec5e4cce6 100644 --- a/src/e2e-test/resources/pluginParameters.properties +++ b/src/e2e-test/resources/pluginParameters.properties @@ -12,6 +12,7 @@ # License for the specific language governing permissions and limitations under # the License. +scmProvider=GITHUB gitRepositoryUrl=replace-with-env-variable gitPAT=replace-with-env-variable gitRepositoryPathPrefix=cdap-pipelines