private Iterable<TestResult> pruneToDepth(List<TestResult> results, Integer depth) { // Prune the response to the requested depth // 0 - TestResult // 1 - TestCapability // 2 - TestSuite // 3 - TestCase // 4 - Entire response // null - Entire response if (depth == null || depth > 3) { return results; } for (TestResult result : results) { if (depth == 0) { result.getTestCapabilities().clear(); } else { for (TestCapability testCapability : result.getTestCapabilities()) { if (depth == 1) { testCapability.getTestSuites().clear(); } else { for (TestSuite testSuite : testCapability.getTestSuites()) { if (depth == 2) { testSuite.getTestCases().clear(); } else { // depth == 3 for (TestCase testCase : testSuite.getTestCases()) { testCase.getTestSteps().clear(); } } } } } } } return results; }
private void assertSuite( TestSuite suite, String desc, int success, int fail, int skip, int total, long duration) { assertThat(suite.getType(), is(TestSuiteType.Functional)); assertThat(suite.getDescription(), is(desc)); assertThat(suite.getFailedTestCaseCount(), is(fail)); assertThat(suite.getSuccessTestCaseCount(), is(success)); assertThat(suite.getSkippedTestCaseCount(), is(skip)); assertThat(suite.getTotalTestCaseCount(), is(total)); assertThat(suite.getDuration(), is(duration)); assertThat(suite.getStartTime(), is(0l)); assertThat(suite.getEndTime(), is(0l)); }
@Test public void test_endToend() throws Exception { String artifacts = getJson("job-artifacts.json"); String cucumberJson = getJson("two-features.json"); URI lastBuildArtifactUri = URI.create( "http://server/job/job1/lastSuccessfulBuild/api/json?tree=timestamp,duration,number,fullDisplayName,building,artifacts[fileName,relativePath]"); URI cucumberJsonUri = URI.create( "http://server/job/job1/lastSuccessfulBuild/artifact/job1/test1/report/web/cucumber.json"); when(rest.exchange( eq(lastBuildArtifactUri), eq(HttpMethod.GET), Matchers.any(HttpEntity.class), eq(String.class))) .thenReturn(new ResponseEntity<String>(artifacts, HttpStatus.OK)); when(rest.exchange( eq(cucumberJsonUri), eq(HttpMethod.GET), Matchers.any(HttpEntity.class), eq(String.class))) .thenReturn(new ResponseEntity<String>(cucumberJson, HttpStatus.OK)); TestResult testResult = defaultJenkinsClient.getCucumberTestResult("http://server/job/job1/"); Collection<TestCapability> capabilities = testResult.getTestCapabilities(); assertThat(capabilities, notNullValue()); Iterator<TestCapability> capabilityIterator = capabilities.iterator(); TestCapability capability = capabilityIterator.next(); List<TestSuite> suites = (List<TestSuite>) capability.getTestSuites(); assertThat(suites, notNullValue()); Iterator<TestSuite> suiteIt = suites.iterator(); Iterator<TestCase> testCaseIt; TestSuite suite; suite = suiteIt.next(); testCaseIt = suite.getTestCases().iterator(); assertSuite(suite, "Feature:eCUKE Feature", 4, 0, 0, 4, 15019839l); assertTestCase( testCaseIt.next(), "ecuke-feature;i-say-hi", "Scenario:I say hi", 4001555l, TestCaseStatus.Success); assertThat(testCaseIt.hasNext(), is(true)); assertTestCase( testCaseIt.next(), "ecuke-feature;you-say-hi", "Scenario:You say hi", 1001212l, TestCaseStatus.Success); assertThat(testCaseIt.hasNext(), is(true)); assertTestCase( testCaseIt.next(), "ecuke-feature;eating-cucumbers", "Scenario Outline:Eating Cucumbers", 2013197l, TestCaseStatus.Success); assertThat(testCaseIt.hasNext(), is(true)); assertTestCase( testCaseIt.next(), "ecuke-feature;eating-cucumbers", "Scenario Outline:Eating Cucumbers", 8003875l, TestCaseStatus.Success); assertThat(testCaseIt.hasNext(), is(false)); }