diff --git a/build.gradle b/build.gradle index 1f907a7..4b6aa3e 100644 --- a/build.gradle +++ b/build.gradle @@ -38,6 +38,8 @@ dependencyManagement { } } +ext['junit-jupiter.version'] = "${junitVersion}" + dependencies { if (releaseMode) { implementation 'com.epam.reportportal:commons-dao' @@ -55,6 +57,11 @@ dependencies { implementation 'net.oauth.core:oauth-httpclient4:20090913' implementation 'org.apache.tika:tika-core:1.14' implementation 'javax.inject:javax.inject:1' + + testImplementation "org.junit.jupiter:junit-jupiter" + testImplementation "org.junit.jupiter:junit-jupiter-params" + testImplementation "org.junit.jupiter:junit-jupiter-api" + testImplementation "org.junit.jupiter:junit-jupiter-engine" } wrapper { @@ -105,3 +112,15 @@ task assemblePlugin(type: Copy) { task assemblePlugins(type: Copy) { dependsOn subprojects.assemblePlugin } + +test { + useJUnitPlatform() + maxParallelForks = 1 + testLogging { + events = ['failed'] + exceptionFormat = 'short' + } + reports { + junitXml.required = true + } +} diff --git a/gradle.properties b/gradle.properties index 4ca0e3e..e6b40dd 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,4 @@ version=5.12.0 description=EPAM Report portal. Rally Integration Plugin pluginId = rally +junitVersion=5.11.0 diff --git a/src/main/java/com/epam/reportportal/extension/bugtracking/rally/RallyStrategy.java b/src/main/java/com/epam/reportportal/extension/bugtracking/rally/RallyStrategy.java index aa49f10..024bfe6 100644 --- a/src/main/java/com/epam/reportportal/extension/bugtracking/rally/RallyStrategy.java +++ b/src/main/java/com/epam/reportportal/extension/bugtracking/rally/RallyStrategy.java @@ -52,6 +52,7 @@ import com.epam.reportportal.extension.bugtracking.BtsExtension; import com.epam.reportportal.extension.bugtracking.InternalTicket; import com.epam.reportportal.extension.bugtracking.InternalTicketAssembler; +import com.epam.reportportal.extension.bugtracking.rally.validator.IntegrationValidator; import com.epam.reportportal.extension.util.FileNameExtractor; import com.epam.reportportal.model.externalsystem.AllowedValue; import com.epam.reportportal.model.externalsystem.PostFormField; @@ -171,6 +172,7 @@ public boolean testConnection(Integration integration) { .orElseThrow(() -> new ReportPortalException(UNABLE_INTERACT_WITH_INTEGRATION, "Rally Project value cannot be NULL" )); + IntegrationValidator.validateThirdPartyUrl(integration); try (RallyRestApi restApi = getClient(integration.getParams())) { QueryRequest rq = new QueryRequest(PROJECT); diff --git a/src/main/java/com/epam/reportportal/extension/bugtracking/rally/validator/IntegrationValidator.java b/src/main/java/com/epam/reportportal/extension/bugtracking/rally/validator/IntegrationValidator.java new file mode 100644 index 0000000..352996f --- /dev/null +++ b/src/main/java/com/epam/reportportal/extension/bugtracking/rally/validator/IntegrationValidator.java @@ -0,0 +1,51 @@ +/* + * Copyright 2024 EPAM Systems + * + * 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 com.epam.reportportal.extension.bugtracking.rally.validator; + +import com.epam.reportportal.rules.commons.validation.BusinessRule; +import com.epam.reportportal.rules.commons.validation.Suppliers; +import com.epam.reportportal.rules.exception.ErrorType; +import com.epam.ta.reportportal.commons.Predicates; +import com.epam.ta.reportportal.entity.integration.Integration; + +/** + * @author Siarhei Hrabko + */ +public final class IntegrationValidator { + + private static final String RALLY_BASE_URL = "https://rally1.rallydev.com"; + + private IntegrationValidator() { + //static only + } + + + /** + * Validates Validates Rally server url. + * + * @param integration {@link Integration} + */ + public static void validateThirdPartyUrl(Integration integration) { + var valid = String.valueOf(integration.getParams().getParams().get("url")) + .startsWith(RALLY_BASE_URL); + + BusinessRule.expect(valid, Predicates.equalTo(true)) + .verify(ErrorType.BAD_REQUEST_ERROR, + Suppliers.formattedSupplier("Integration url is not acceptable") + ); + } +} diff --git a/src/test/java/com/epam/reportportal/extension/bugtracking/rally/validator/IntegrationValidatorTest.java b/src/test/java/com/epam/reportportal/extension/bugtracking/rally/validator/IntegrationValidatorTest.java new file mode 100644 index 0000000..3d8c634 --- /dev/null +++ b/src/test/java/com/epam/reportportal/extension/bugtracking/rally/validator/IntegrationValidatorTest.java @@ -0,0 +1,63 @@ +/* + * Copyright 2024 EPAM Systems + * + * 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 com.epam.reportportal.extension.bugtracking.rally.validator; + +import com.epam.reportportal.rules.exception.ReportPortalException; +import com.epam.ta.reportportal.entity.integration.Integration; +import com.epam.ta.reportportal.entity.integration.IntegrationParams; +import java.util.HashMap; +import java.util.Map; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; + +class IntegrationValidatorTest { + + @ParameterizedTest + @CsvSource(value = { + "https://rally1.rallydev.com", + "https://rally1.rallydev.com/" + }, delimiter = ',') + void validateThirdPartyUrl(String url) { + Assertions.assertDoesNotThrow(() -> + IntegrationValidator.validateThirdPartyUrl(getIntegration(url))); + } + + @ParameterizedTest + @CsvSource(value = { + "http://rally1.rallydev.com", + "https://zloi.hacker.com" + }, delimiter = ',') + void validateThirdPartyUrlFailed(String url) { + Assertions.assertThrows(ReportPortalException.class, () -> + IntegrationValidator.validateThirdPartyUrl(getIntegration(url))); + } + + private static Integration getIntegration(String url) { + Map params = new HashMap<>(); + params.put("url", url); + + IntegrationParams integrationParams = new IntegrationParams(); + integrationParams.setParams(params); + + Integration integration = new Integration(); + integration.setParams(integrationParams); + + return integration; + } + +}