/src/test/java/com/atlassian/bamboo/plugin/dotnet/tests/nunit/NUnitTestReportCollectorTest.java
Java | 165 lines | 135 code | 27 blank | 3 comment | 1 complexity | 5dcb7dca67d09383b3b82f201c6d7119 MD5 | raw file
Possible License(s): BSD-3-Clause
- package com.atlassian.bamboo.plugin.dotnet.tests.nunit;
- import com.atlassian.bamboo.build.test.TestCollectionResult;
- import com.atlassian.bamboo.results.tests.TestResults;
- import com.atlassian.bamboo.utils.BambooTestUtils;
- import com.atlassian.bamboo.utils.FileVisitor;
- import org.apache.commons.io.FilenameUtils;
- import org.apache.commons.lang3.SystemUtils;
- import org.hamcrest.Matchers;
- import org.jetbrains.annotations.NotNull;
- import org.junit.Before;
- import org.junit.Test;
- import java.io.File;
- import java.util.Collections;
- import java.util.HashSet;
- import java.util.Set;
- import java.util.concurrent.ExecutorService;
- import java.util.concurrent.Executors;
- import java.util.concurrent.TimeUnit;
- import java.util.concurrent.atomic.AtomicInteger;
- import static com.atlassian.bamboo.testutils.matchers.EntityMatchers.testCollectionResult;
- import static org.hamcrest.MatcherAssert.assertThat;
- import static org.hamcrest.Matchers.is;
- import static org.junit.Assert.assertEquals;
- import static org.junit.Assert.fail;
- import static org.junit.Assume.assumeThat;
- /**
- * This test needs to be run with JDK8 (in order to access public property of private inner class implementing a public interface)
- */
- public class NUnitTestReportCollectorTest
- {
- private NUnitTestReportCollector testReportCollector;
- @Before
- public void setUp() throws Exception
- {
- testReportCollector = new NUnitTestReportCollector();
- }
- @Test
- public void testBSP_4922_A() throws Exception
- {
- assumeThat(SystemUtils.IS_JAVA_1_8, is(true));
- final TestCollectionResult result = collect("BSP-4922.Enroll.ThickFacade.Tests.nunit-results.xml");
- assertThat(result,
- testCollectionResult()
- .failedTestResults(0)
- .skippedTestResults(0)
- .successfulTestResults(13)
- .build());
- }
- @Test
- public void testBSP_4922_B() throws Exception
- {
- assumeThat(SystemUtils.IS_JAVA_1_8, is(true));
- final TestCollectionResult result = collect("BSP-4922.IDGrid.Tests.nunit-results.xml");
- assertThat(result,
- testCollectionResult()
- .failedTestResults(0)
- .skippedTestResults(0)
- .successfulTestResults(7)
- .build());
- }
- @Test
- public void testBSP_4960() throws Exception
- {
- assumeThat(SystemUtils.IS_JAVA_1_8, is(true));
- final TestCollectionResult result = collect("BSP-4960.testresult_with_no_results.xml");
- assertThat(result,
- testCollectionResult()
- .failedTestResults(0)
- .skippedTestResults(0)
- .successfulTestResults(0)
- .build());
- }
- @Test
- public void testMultiThreadedCollation() throws Exception
- {
- final AtomicInteger numberOfFilesFound = new AtomicInteger(0);
- final Set<TestResults> failedTestResults = Collections.synchronizedSet(new HashSet<TestResults>());
- final Set<TestResults> successfulTestResults = Collections.synchronizedSet(new HashSet<TestResults>());
- File rootDirectory = BambooTestUtils.getFileFromResourceDirectory(this, "empty_file.xml").getParentFile();
- final ExecutorService executorService = Executors.newFixedThreadPool(8);
- try
- {
- FileVisitor fileVisitor = new FileVisitor(rootDirectory)
- {
- @Override
- public void visitFile(final File file)
- {
- final String fileName = file.getName();
- if (FilenameUtils.isExtension(fileName, testReportCollector.getSupportedFileExtensions()))
- {
- executorService.submit(new Runnable()
- {
- @Override
- public void run()
- {
- try
- {
- numberOfFilesFound.incrementAndGet();
- TestCollectionResult result = testReportCollector.collect(file);
- failedTestResults.addAll(result.getFailedTestResults());
- successfulTestResults.addAll(result.getSuccessfulTestResults());
- }
- catch (Exception e)
- {
- fail();
- }
- }
- });
- }
- }
- };
- fileVisitor.visitFilesThatMatch("BSP*.xml");
- }
- finally
- {
- executorService.shutdown();
- executorService.awaitTermination(2, TimeUnit.MINUTES);
- }
- assertEquals(20, successfulTestResults.size());
- assertEquals(0, failedTestResults.size());
- }
- @Test
- public void testNUnitOrg25Sample() throws Exception
- {
- assumeThat(SystemUtils.IS_JAVA_1_8, is(true));
- final TestCollectionResult result = collect("nunit_org_2_5_sample.xml");
- assertThat(result,
- testCollectionResult()
- .failedTestResults(Matchers.<TestResults>iterableWithSize(3))
- .skippedTestResults(Matchers.<TestResults>iterableWithSize(7))
- .successfulTestResults(Matchers.<TestResults>iterableWithSize(18))
- .build());
- }
- private TestCollectionResult collect(@NotNull String filename) throws Exception
- {
- return testReportCollector.collect(BambooTestUtils.getFileFromResourceDirectory(this, filename));
- }
- }