download(final URL url,
43 | final Path target) throws IOException {
44 | final URLConnection connection = url.openConnection();
45 | connection.setConnectTimeout(CONN_TIMEOUT_MS);
46 | connection.setReadTimeout(DOWNLOAD_TIMEOUT_MS);
47 | connection.setRequestProperty("Connection", "close");
48 | connection.setRequestProperty("Pragma", "no-cache");
49 | ((HttpURLConnection) connection).setInstanceFollowRedirects(true);
50 | connection.connect();
51 | try (InputStream input = connection.getInputStream()) {
52 | Files.copy(input, target, StandardCopyOption.REPLACE_EXISTING);
53 | return Optional.of(target);
54 | }
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/src/main/java/io/qameta/allure/bamboo/util/ExceptionUtil.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016-2024 Qameta Software Inc
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package io.qameta.allure.bamboo.util;
17 |
18 | import java.io.PrintWriter;
19 | import java.io.StringWriter;
20 |
21 | public final class ExceptionUtil {
22 |
23 | private ExceptionUtil() {
24 | // do not instantiate
25 | }
26 |
27 | public static String stackTraceToString(final Throwable e) {
28 | final StringWriter sw = new StringWriter();
29 | e.printStackTrace(new PrintWriter(sw));
30 | return sw.toString();
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/main/java/io/qameta/allure/bamboo/util/FileStringReplacer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016-2024 Qameta Software Inc
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package io.qameta.allure.bamboo.util;
17 |
18 | import org.jetbrains.annotations.NotNull;
19 |
20 | import java.io.IOException;
21 | import java.nio.charset.StandardCharsets;
22 | import java.nio.file.Files;
23 | import java.nio.file.Path;
24 | import java.util.regex.Pattern;
25 |
26 | public final class FileStringReplacer {
27 |
28 | private FileStringReplacer() {
29 | // do not instantiate
30 | }
31 |
32 | public static void replaceInFile(final Path filePath,
33 | final String oldString,
34 | final String newString) throws IOException {
35 | String content = new String(Files.readAllBytes(filePath), StandardCharsets.UTF_8);
36 | content = content.replaceAll(oldString, newString);
37 | Files.write(filePath, content.getBytes(StandardCharsets.UTF_8));
38 | }
39 |
40 | public static void replaceInFile(final Path filePath,
41 | final @NotNull Pattern pattern,
42 | final String newString) throws IOException {
43 | String content = new String(Files.readAllBytes(filePath), StandardCharsets.UTF_8);
44 | content = pattern.matcher(content).replaceAll(newString);
45 | Files.write(filePath, content.getBytes(StandardCharsets.UTF_8));
46 | }
47 |
48 | }
49 |
--------------------------------------------------------------------------------
/src/main/java/io/qameta/allure/bamboo/util/ZipUtil.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016-2024 Qameta Software Inc
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package io.qameta.allure.bamboo.util;
17 |
18 | import io.qameta.allure.bamboo.AllurePluginException;
19 | import net.lingala.zip4j.ZipFile;
20 | import org.apache.commons.compress.archivers.ArchiveEntry;
21 | import org.apache.commons.compress.archivers.ArchiveException;
22 | import org.apache.commons.compress.archivers.ArchiveInputStream;
23 | import org.apache.commons.compress.archivers.ArchiveStreamFactory;
24 | import org.apache.commons.compress.utils.IOUtils;
25 | import org.apache.commons.io.FileUtils;
26 | import org.jetbrains.annotations.NotNull;
27 | import org.slf4j.Logger;
28 | import org.slf4j.LoggerFactory;
29 |
30 | import java.io.File;
31 | import java.io.IOException;
32 | import java.io.InputStream;
33 | import java.io.OutputStream;
34 | import java.nio.file.Files;
35 | import java.nio.file.Path;
36 | import java.nio.file.Paths;
37 | import java.nio.file.StandardCopyOption;
38 |
39 | public final class ZipUtil {
40 |
41 | private static final Logger LOGGER = LoggerFactory.getLogger(ZipUtil.class);
42 | private static final String DIRECTORY_CREATE_ERROR = "The directory: %s couldn't be created successfully";
43 |
44 | private ZipUtil() {
45 | // do not instantiate
46 | }
47 |
48 | public static void unzip(final @NotNull Path zipFilePath,
49 | final String outputDir) throws IOException, ArchiveException {
50 |
51 | final ArchiveStreamFactory asf = new ArchiveStreamFactory();
52 |
53 | try (InputStream zipStream = Files.newInputStream(zipFilePath)) {
54 | try (ArchiveInputStream ais = asf.createArchiveInputStream(ArchiveStreamFactory.ZIP, zipStream)) {
55 | ArchiveEntry entry = ais.getNextEntry();
56 | while (entry != null) {
57 | final Path entryPath = Paths.get(outputDir, entry.getName());
58 | final File entryFile = entryPath.toFile();
59 |
60 | if (!entry.isDirectory()) {
61 | final File parentEntryFile = entryFile.getParentFile();
62 | if (parentEntryFile.isDirectory() && !(parentEntryFile.mkdirs() || parentEntryFile.exists())) {
63 | throw new IOException(String.format(DIRECTORY_CREATE_ERROR, parentEntryFile.getPath()));
64 | }
65 |
66 | try (OutputStream outputStream = Files.newOutputStream(entryPath)) {
67 | IOUtils.copy(ais, outputStream);
68 | }
69 | } else if (!(entryFile.mkdirs() || entryFile.exists())) {
70 | throw new IOException(String.format(DIRECTORY_CREATE_ERROR, entryFile.getPath()));
71 | }
72 | entry = ais.getNextEntry();
73 | }
74 | }
75 | }
76 | }
77 |
78 | public static void zipReportFolder(final @NotNull Path srcFolder,
79 | final @NotNull Path targetDir) throws IOException {
80 | try {
81 | final Path zipReportTmpDir = Files.createTempDirectory("tmp_allure_report");
82 | final Path zipReport = zipReportTmpDir.resolve("report.zip");
83 | try (ZipFile zp = new ZipFile(zipReport.toFile())) {
84 | zp.addFolder(srcFolder.toFile());
85 | }
86 | Files.move(zipReport, targetDir, StandardCopyOption.REPLACE_EXISTING);
87 | FileUtils.deleteQuietly(zipReportTmpDir.toFile());
88 | } catch (Exception e) {
89 | LOGGER.error("Failed to zip allure report", e);
90 | throw new AllurePluginException("Unexpected error", e);
91 | }
92 | }
93 | }
94 |
--------------------------------------------------------------------------------
/src/main/resources/META-INF/spring/plugin-context.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/src/main/resources/allure-bamboo.properties:
--------------------------------------------------------------------------------
1 | allure.task.help.link=https://allurereport.org/
2 | allure.task.help.title=Go to Allure website!
3 | webitems.system.admin.build.allureReport=Allure Report
4 | admin.allureReportConfig.edit.title=Configure Allure Reporting
5 | admin.allureReportConfig.description=
6 | allure.plugin.title=Allure Report
7 | allure.config.title=Allure Reporting
8 | custom.allure.config.enabled.label=Enable Allure Building
9 | custom.allure.config.enabled.default.label=Build Allure for all builds by default
10 | custom.allure.config.failed.only.label=Build report only for failed builds
11 | custom.allure.artifact.name.label=Artifact name to use
12 | custom.allure.config.download.enabled.label=Download if no executable present
13 | custom.allure.config.download.url.label=Allure binary base url
14 | allure.config.download.url.error.required=Allure binary base url is required
15 | custom.allure.config.local.storage.label=Allure local storage
16 | allure.config.local.storage.required=Allure local storage is required
17 | custom.allure.config.logo.enabled.label=Enable report custom logo
18 | custom.allure.logo.url.label=Custom logo
19 | custom.allure.config.reports.cleanup.enabled.label=Enable reports cleanup
20 | custom.allure.max.stored.reports.count.label=Count reports to store
21 |
--------------------------------------------------------------------------------
/src/main/resources/atlassian-plugin.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | ${project.description}
4 | ${project.version}
5 |
6 | images/logo.png
7 | images/logo.png
8 | 1
9 | compatible
10 | true
11 |
12 |
13 |
14 |
15 |
16 |
17 | Tears down and saves data for MyBambooPlugin if the Chain has the plugin enabled
18 |
19 |
20 |
21 |
22 | If you enable the allure report generation in the "Other" tab, this task is automatically executed without
23 | adding it to your pipeline. However, you can still add it to your pipeline if you want to see it.
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
33 | Plugin to configure Allure build
34 |
35 |
36 |
37 |
38 |
40 |
41 | /chain/result/viewAllure.action?buildKey=${planKey}&buildNumber=${buildNumber}
42 |
43 |
44 | /chain/result/viewAllure.action?buildKey=${immutablePlan.key}&buildNumber=${resultsSummary.buildNumber}
45 |
46 |
47 |
48 |
49 | /chain/result/viewAllure.action?buildKey=${planKey}&buildNumber=${buildNumber}
50 |
51 |
52 |
53 |
54 |
55 |
57 | /chain/result/viewAllure.action?buildKey=${planKey}&buildNumber=${buildNumber}
58 | /chain/result/viewAllure.action?buildKey=${planKey}&buildNumber=${buildNumber}
59 | /templates/viewAllureReport.ftl
60 | /error.ftl
61 |
62 |
63 |
64 |
65 |
66 | /allure/report/*
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 | /admin/editAllureReportConfig.action
82 |
83 |
84 |
85 |
86 |
87 |
89 | /templates/editAllureReportConfig.ftl
90 | /templates/editAllureReportConfig.ftl
91 |
92 |
93 |
94 | /templates/editAllureReportConfig.ftl
95 | /templates/editAllureReportConfig.ftl
96 | /admin/editAllureReportConfig.action
97 |
98 |
99 |
100 |
101 |
--------------------------------------------------------------------------------
/src/main/resources/images/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/allure-framework/allure-bamboo/d0f6f2e0dbe582fe935da71931364e1ccc81e91d/src/main/resources/images/icon.png
--------------------------------------------------------------------------------
/src/main/resources/images/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/allure-framework/allure-bamboo/d0f6f2e0dbe582fe935da71931364e1ccc81e91d/src/main/resources/images/logo.png
--------------------------------------------------------------------------------
/src/main/resources/images/logo_deprecated.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/allure-framework/allure-bamboo/d0f6f2e0dbe582fe935da71931364e1ccc81e91d/src/main/resources/images/logo_deprecated.png
--------------------------------------------------------------------------------
/src/main/resources/templates/editAllureBambooConfiguration.ftl:
--------------------------------------------------------------------------------
1 | [@ui.bambooSection titleKey="allure.config.title"]
2 | [@ww.checkbox labelKey='custom.allure.config.enabled.label' name='custom.allure.config.enabled' toggle='true' /]
3 |
4 | [@ww.checkbox labelKey='custom.allure.config.failed.only.label' name='custom.allure.config.failed.only' toggle='true' /]
5 |
6 | [@ww.select cssClass="builderSelectWidget" labelKey="executable.type" name="custom.allure.config.executable" required="true"
7 | list=uiConfigBean.getExecutableLabels('allure') dependsOn='custom.allure.config.enabled' showOn='true'
8 | extraUtility=addExecutableLink /]
9 |
10 | [@ww.textfield labelKey="custom.allure.artifact.name.label" name="custom.allure.artifact.name" required="false"/]
11 |
12 | [@ww.textfield labelKey="custom.allure.logo.url.label" name="custom.allure.logo.url" required="false"/]
13 |
14 | [@ww.textfield labelKey="custom.allure.max.stored.reports.count.label" name="custom.allure.max.stored.reports.count" required="false"/]
15 |
16 | [/@ui.bambooSection]
17 |
--------------------------------------------------------------------------------
/src/main/resources/templates/editAllureReportConfig.ftl:
--------------------------------------------------------------------------------
1 | [#-- @ftlvariable name="action" type="io.qameta.allure.bamboo.ConfigureAllureReportAction" --]
2 | [#-- @ftlvariable name="" type="io.qameta.allure.bamboo.ConfigureAllureReportAction" --]
3 |
4 |
5 |
6 | [@ww.text name='allure.plugin.title' /]
7 |
8 |
9 |
10 |
11 | [@ww.text name='allure.plugin.title' /]
12 |
13 | [@ww.text name='admin.allureReportConfig.description' /]
14 |
15 | [@ww.form action="saveAllureReportConfig"
16 | id="saveAllureReportConfigForm"
17 | submitLabelKey='global.buttons.update'
18 | titleKey='admin.allureReportConfig.edit.title'
19 | cancelUri='/admin/editAllureReportConfig.action'
20 | ]
21 | [@ww.checkbox labelKey='custom.allure.config.download.enabled.label' name='downloadEnabled' toggle='true' /]
22 |
23 | [@ww.checkbox labelKey='custom.allure.config.logo.enabled.label' name='customLogoEnabled' toggle='false' /]
24 |
25 | [@ww.checkbox labelKey='custom.allure.config.enabled.default.label' name='enabledByDefault' toggle='true' /]
26 |
27 | [@ww.checkbox labelKey='custom.allure.config.reports.cleanup.enabled.label' name='enabledReportsCleanup' toggle='false' /]
28 |
29 | [@ww.textfield labelKey='custom.allure.config.download.url.label' name='localStoragePath' required='true'/]
30 |
31 | [@ww.textfield labelKey='custom.allure.config.local.storage.label' name='downloadBaseUrl' required='true'/]
32 | [/@ww.form]
33 |
34 |
--------------------------------------------------------------------------------
/src/main/resources/templates/error.ftl:
--------------------------------------------------------------------------------
1 | [#-- @ftlvariable name="action" type="com.atlassian.bamboo.logger.AdminErrorAction" --]
2 | [#-- @ftlvariable name="" type="com.atlassian.bamboo.logger.AdminErrorAction" --]
3 |
4 |
5 |
6 | [@ww.text name='error.title' /]
7 |
8 |
9 |
10 |
11 | [@ui.header pageKey='error.heading' /]
12 |
13 | [#if formattedActionErrors?has_content]
14 | [@ui.messageBox type='warning']
15 | [#list formattedActionErrors as error]
16 | ${error}
17 | [/#list]
18 | [/@ui.messageBox]
19 | [/#if]
20 |
21 |
22 |
--------------------------------------------------------------------------------
/src/main/resources/templates/viewAllureBambooConfiguration.ftl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/allure-framework/allure-bamboo/d0f6f2e0dbe582fe935da71931364e1ccc81e91d/src/main/resources/templates/viewAllureBambooConfiguration.ftl
--------------------------------------------------------------------------------
/src/main/resources/templates/viewAllureReport.ftl:
--------------------------------------------------------------------------------
1 | [#-- @ftlvariable name="" type="io.qameta.allure.bamboo.ViewAllureReport" --]
2 |
3 |
4 | [#assign reportUrl = "${bestBaseUrl}/plugins/servlet/allure/report/${planKey}/${buildNumber}/"]
5 | [#assign reportZipUrl = "${bestBaseUrl}/plugins/servlet/allure/report/${planKey}/${buildNumber}/report.zip"]
6 | [@ui.header pageKey='buildResult.changes.title' object='${immutablePlan.name} ${resultsSummary.buildNumber}' title=true/]
7 |
8 |
23 |
24 |
25 | Expand
26 | Download
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/src/test/java/io/qameta/allure/bamboo/AllureCommandLineSupportTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016-2024 Qameta Software Inc
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package io.qameta.allure.bamboo;
17 |
18 | import org.junit.Test;
19 |
20 | import static org.hamcrest.MatcherAssert.assertThat;
21 | import static org.hamcrest.Matchers.equalTo;
22 |
23 | public class AllureCommandLineSupportTest {
24 |
25 | private static final String OUTPUT = ", enabled: true\n"
26 | + ", enabled: true\n"
27 | + ", enabled: true\n"
28 | + ", enabled: true\n"
29 | + "Found 4 results readers\n"
30 | + "Found %d results for source 1491867175333-0\n"
31 | + "## Summary\n"
32 | + "Found %d test cases (%d failed, %d broken)\n"
33 | + "Success percentage: %s\n"
34 | + "Creating index.html...\n"
35 | + "Couldn't find template in cache for \"index.html.ftl\"(\"en_US\", UTF-8, parsed); "
36 | + "will try to load it.\n"
37 | + "TemplateLoader.findTemplateSource(\"index.html.ftl\"): Found";
38 |
39 | private final AllureCommandLineSupport support = new AllureCommandLineSupport();
40 |
41 | @Test
42 | public void itShouldReturnNotContainingTestcasesResult() throws Exception {
43 | final AllureGenerateResult result = support.parseGenerateOutput(String.format(OUTPUT, 0, 0, 0, 0, "Unknown"));
44 | assertThat(result.isContainsTestCases(), equalTo(false));
45 | }
46 |
47 | @Test
48 | public void itShouldReturnContainingTestcasesResult() throws Exception {
49 | final AllureGenerateResult result = support.parseGenerateOutput(String.format(OUTPUT, 1, 5, 2, 1, "80"));
50 | assertThat(result.isContainsTestCases(), equalTo(true));
51 |
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/src/test/java/io/qameta/allure/bamboo/AllureDownloaderTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016-2024 Qameta Software Inc
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package io.qameta.allure.bamboo;
17 |
18 | import org.junit.After;
19 | import org.junit.Before;
20 | import org.junit.Rule;
21 | import org.junit.Test;
22 | import org.mockito.InjectMocks;
23 | import org.mockito.Mock;
24 | import org.mockito.junit.MockitoRule;
25 |
26 | import java.io.File;
27 | import java.nio.file.Paths;
28 |
29 | import static org.apache.commons.io.FileUtils.deleteQuietly;
30 | import static org.junit.Assert.assertTrue;
31 | import static org.mockito.Mockito.when;
32 | import static org.mockito.junit.MockitoJUnit.rule;
33 |
34 | public class AllureDownloaderTest {
35 |
36 | @Rule
37 | public MockitoRule mockitoRule = rule();
38 | @Mock
39 | private AllureSettingsManager settingsManager;
40 | private AllureGlobalConfig settings;
41 |
42 | @InjectMocks
43 | private AllureDownloader downloader;
44 |
45 | private String homeDir;
46 |
47 | @Before
48 | public void setUp() {
49 | homeDir = Paths.get(System.getProperty("java.io.tmpdir"), "allure-home").toString();
50 | settings = new AllureGlobalConfig();
51 | when(settingsManager.getSettings()).thenReturn(settings);
52 | }
53 |
54 | @Test
55 | public void itShouldDownloadAndExtractAllureRelease() {
56 | downloader.downloadAndExtractAllureTo(homeDir, "2.17.2");
57 | final File f = Paths.get(homeDir, "bin", "allure").toFile();
58 | assertTrue(f.exists());
59 | }
60 |
61 | @After
62 | public void tearDown() {
63 | deleteQuietly(Paths.get(homeDir).toFile());
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/src/test/java/io/qameta/allure/bamboo/AllureExecutableProviderTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016-2024 Qameta Software Inc
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package io.qameta.allure.bamboo;
17 |
18 | import org.junit.Before;
19 | import org.junit.Rule;
20 | import org.junit.Test;
21 | import org.mockito.InjectMocks;
22 | import org.mockito.Mock;
23 | import org.mockito.junit.MockitoRule;
24 |
25 | import java.nio.file.Path;
26 | import java.nio.file.Paths;
27 | import java.util.Optional;
28 |
29 | import static io.qameta.allure.bamboo.AllureExecutableProvider.BIN;
30 | import static io.qameta.allure.bamboo.AllureExecutableProvider.DEFAULT_VERSION;
31 | import static org.mockito.ArgumentMatchers.anyString;
32 | import static org.mockito.Mockito.verify;
33 | import static org.mockito.Mockito.when;
34 | import static org.mockito.junit.MockitoJUnit.rule;
35 |
36 | public class AllureExecutableProviderTest {
37 |
38 | private static final String ALLURE_2_21_0 = "Allure 2.21.0";
39 | private static final String EXECUTABLE_NAME_2_21_0 = "2.21.0";
40 | private final String homeDir = "/home/allure";
41 |
42 | @Rule
43 | public MockitoRule mockitoRule = rule();
44 | @Mock
45 | private BambooExecutablesManager executablesManager;
46 | @Mock
47 | private AllureDownloader downloader;
48 | @Mock
49 | private AllureCommandLineSupport cmdLine;
50 | @InjectMocks
51 | private AllureExecutableProvider provider;
52 | private AllureGlobalConfig config;
53 | private Path allureCmdPath;
54 | private Path allureBatCmdPath;
55 |
56 | @Before
57 | public void setUp() throws Exception {
58 | config = new AllureGlobalConfig();
59 | allureCmdPath = Paths.get(homeDir, BIN, "allure");
60 | allureBatCmdPath = Paths.get(homeDir, BIN, "allure.bat");
61 | when(downloader.downloadAndExtractAllureTo(anyString(), anyString())).thenReturn(Optional.empty());
62 | }
63 |
64 | @Test
65 | public void itShouldProvideDefaultVersion() throws Exception {
66 | provide("Allure WITHOUT VERSION");
67 | verify(downloader).downloadAndExtractAllureTo(homeDir, DEFAULT_VERSION);
68 | }
69 |
70 | @Test
71 | public void itShouldProvideTheGivenVersionWithFullSemverWithoutName() throws Exception {
72 | provide(EXECUTABLE_NAME_2_21_0);
73 | verify(downloader).downloadAndExtractAllureTo(homeDir, EXECUTABLE_NAME_2_21_0);
74 | }
75 |
76 | @Test
77 | public void itShouldProvideTheGivenVersionWithFullSemverWithoutMilestone() throws Exception {
78 | provide(ALLURE_2_21_0);
79 | verify(downloader).downloadAndExtractAllureTo(homeDir, EXECUTABLE_NAME_2_21_0);
80 | }
81 |
82 | @Test
83 | public void itShouldProvideTheGivenVersionWithMajorMinorWithoutMilestone() throws Exception {
84 | provide("Allure 2.13.7");
85 | verify(downloader).downloadAndExtractAllureTo(homeDir, "2.13.7");
86 | }
87 |
88 | @Test
89 | public void itShouldProvideTheGivenVersionWithMilestone() throws Exception {
90 | provide("Allure 2.0-BETA4");
91 | verify(downloader).downloadAndExtractAllureTo(homeDir, "2.0-BETA4");
92 | }
93 |
94 | private Optional provide(String executableName) {
95 | when(executablesManager.getExecutableByName(executableName)).thenReturn(Optional.of(homeDir));
96 | return provider.provide(config, executableName);
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/src/test/java/io/qameta/allure/bamboo/AllureExecutableTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016-2024 Qameta Software Inc
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package io.qameta.allure.bamboo;
17 |
18 | import org.junit.Before;
19 | import org.junit.Rule;
20 | import org.junit.Test;
21 | import org.mockito.Mock;
22 | import org.mockito.junit.MockitoRule;
23 |
24 | import java.nio.file.Files;
25 | import java.nio.file.Path;
26 | import java.nio.file.Paths;
27 |
28 | import static java.util.Collections.singleton;
29 | import static org.mockito.Mockito.verify;
30 | import static org.mockito.Mockito.when;
31 | import static org.mockito.junit.MockitoJUnit.rule;
32 |
33 | public class AllureExecutableTest {
34 | private static final String OPTIONS = "-o";
35 | private static final String GENERATE = "generate";
36 | private static final String BIN_BASH = "/bin/bash";
37 | @Rule
38 | public MockitoRule mockitoRule = rule();
39 |
40 | private final Path path = Paths.get("/tmp/where-allure/installed");
41 |
42 | @Mock
43 | private AllureCommandLineSupport cmdLine;
44 |
45 | private AllureExecutable executable;
46 | private Path fromDir;
47 | private Path toDir;
48 |
49 | @Before
50 | @SuppressWarnings("UnstableApiUsage")
51 | public void setUp() throws Exception {
52 | executable = new AllureExecutable(path, cmdLine);
53 | fromDir = Files.createTempDirectory("tmp_from");
54 | toDir = Files.createTempDirectory("tmp_to");
55 | }
56 |
57 | @Test
58 | public void itShouldInvokeAllureGenerateOnUnixWithBash() throws Exception {
59 | when(cmdLine.hasCommand(BIN_BASH))
60 | .thenReturn(true);
61 | when(cmdLine.isUnix())
62 | .thenReturn(true);
63 |
64 | executable.generate(singleton(fromDir), toDir);
65 |
66 | verify(cmdLine)
67 | .runCommand(BIN_BASH, path.toString(), GENERATE, OPTIONS, toDir.toString(), fromDir.toString());
68 | }
69 |
70 | @Test
71 | public void itShouldInvokeAllureGenerateOnUnixWithoutBash() throws Exception {
72 | when(cmdLine.hasCommand(BIN_BASH))
73 | .thenReturn(false);
74 | when(cmdLine.isUnix())
75 | .thenReturn(true);
76 |
77 | executable.generate(singleton(fromDir), toDir);
78 |
79 | verify(cmdLine)
80 | .runCommand(path.toString(), GENERATE, OPTIONS, toDir.toString(), fromDir.toString());
81 | }
82 |
83 | @Test
84 | public void itShouldInvokeAllureGenerateOnWindows() throws Exception {
85 | when(cmdLine.isUnix())
86 | .thenReturn(false);
87 |
88 | executable.generate(singleton(fromDir), toDir);
89 |
90 | verify(cmdLine)
91 | .runCommand(path.toString(), GENERATE, OPTIONS, toDir.toString(), fromDir.toString());
92 |
93 | }
94 | }
95 |
--------------------------------------------------------------------------------
/src/test/java/io/qameta/allure/bamboo/AllureReportServletTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016-2024 Qameta Software Inc
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package io.qameta.allure.bamboo;
17 |
18 | import org.junit.Test;
19 |
20 | import java.util.regex.Matcher;
21 |
22 | import static io.qameta.allure.bamboo.AllureReportServlet.getUrlPattern;
23 | import static org.junit.Assert.assertTrue;
24 |
25 | public class AllureReportServletTest {
26 |
27 | @Test
28 | public void itShouldMatchThePattern() throws Exception {
29 | final Matcher matcher = getUrlPattern().matcher("/plugins/servlet/allure/report/STPCI-STPITCONFLUENCE60/15/");
30 | assertTrue(matcher.matches());
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/test/java/io/qameta/allure/bamboo/SecondAllureExecutableProviderTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016-2024 Qameta Software Inc
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package io.qameta.allure.bamboo;
17 |
18 | import org.junit.Before;
19 | import org.junit.Rule;
20 | import org.junit.Test;
21 | import org.mockito.InjectMocks;
22 | import org.mockito.Mock;
23 | import org.mockito.junit.MockitoRule;
24 |
25 | import java.nio.file.Path;
26 | import java.nio.file.Paths;
27 | import java.util.Optional;
28 |
29 | import static io.qameta.allure.bamboo.AllureExecutableProvider.BIN;
30 | import static org.hamcrest.CoreMatchers.equalTo;
31 | import static org.hamcrest.MatcherAssert.assertThat;
32 | import static org.mockito.Mockito.when;
33 | import static org.mockito.junit.MockitoJUnit.rule;
34 |
35 | public class SecondAllureExecutableProviderTest {
36 |
37 | private static final String ALLURE_2_21_0 = "Allure 2.21.0";
38 | private static final String EXECUTABLE_NAME_2_21_0 = "2.21.0";
39 | private final String homeDir = "/home/allure";
40 |
41 | @Rule
42 | public MockitoRule mockitoRule = rule();
43 | @Mock
44 | private BambooExecutablesManager executablesManager;
45 | @Mock
46 | private AllureDownloader downloader;
47 | @Mock
48 | private AllureCommandLineSupport cmdLine;
49 | @InjectMocks
50 | private AllureExecutableProvider provider;
51 | private AllureGlobalConfig config;
52 | private Path allureCmdPath;
53 | private Path allureBatCmdPath;
54 |
55 | @Before
56 | public void setUp() throws Exception {
57 | config = new AllureGlobalConfig();
58 | allureCmdPath = Paths.get(homeDir, BIN, "allure");
59 | allureBatCmdPath = Paths.get(homeDir, BIN, "allure.bat");
60 | }
61 |
62 | @Test
63 | public void itShouldProvideExecutableForUnix() throws Exception {
64 | when(cmdLine.hasCommand(allureCmdPath.toString())).thenReturn(true);
65 | when(cmdLine.isWindows()).thenReturn(false);
66 |
67 | final Optional res = provide("Allure 2.0-BETA5");
68 |
69 | assertThat(res.isPresent(), equalTo(true));
70 | assertThat(res.get().getCmdPath(), equalTo(allureCmdPath));
71 | }
72 |
73 | @Test
74 | public void itShouldProvideExecutableForWindows() throws Exception {
75 | when(cmdLine.hasCommand(allureBatCmdPath.toString())).thenReturn(true);
76 | when(cmdLine.isWindows()).thenReturn(true);
77 |
78 | final Optional res = provide(ALLURE_2_21_0);
79 |
80 | assertThat(res.isPresent(), equalTo(true));
81 | assertThat(res.get().getCmdPath(), equalTo(allureBatCmdPath));
82 | }
83 |
84 | private Optional provide(String executableName) {
85 | when(executablesManager.getExecutableByName(executableName)).thenReturn(Optional.of(homeDir));
86 | return provider.provide(config, executableName);
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/src/test/java/io/qameta/allure/bamboo/util/ExceptionUtilTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016-2024 Qameta Software Inc
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package io.qameta.allure.bamboo.util;
17 |
18 | import org.junit.Test;
19 |
20 | import static io.qameta.allure.bamboo.util.ExceptionUtil.stackTraceToString;
21 | import static org.hamcrest.MatcherAssert.assertThat;
22 | import static org.hamcrest.Matchers.containsString;
23 |
24 | public class ExceptionUtilTest {
25 |
26 | @Test
27 | public void itShouldPrintStackTraceIntoString() {
28 | try {
29 | throw new RuntimeException("Print me please");
30 | } catch (RuntimeException e) {
31 | final String trace = stackTraceToString(e);
32 | assertThat(trace, containsString("RuntimeException: Print me please"));
33 | assertThat(trace, containsString("itShouldPrintStackTraceIntoString(ExceptionUtilTest.java:29)"));
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/test/resources/log4j.properties:
--------------------------------------------------------------------------------
1 | log4j.rootLogger=INFO, stdout
2 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender
3 | log4j.appender.stdout.Target=System.out
4 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
5 | log4j.appender.stdout.layout.ConversionPattern=%m%n
6 | log4j.logger.org.mortbay.log=INFO
7 |
--------------------------------------------------------------------------------