diff --git a/src/test/java/hudson/plugins/robot/RobotParserTest.java b/src/test/java/hudson/plugins/robot/RobotParserTest.java index a12bd4d..6444083 100644 --- a/src/test/java/hudson/plugins/robot/RobotParserTest.java +++ b/src/test/java/hudson/plugins/robot/RobotParserTest.java @@ -1,212 +1,212 @@ package hudson.plugins.robot; -import java.io.File; +import org.junit.jupiter.api.Test; -import org.junit.Test; +import java.io.File; -public class RobotParserTest { +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; - public void parse(String dir, String mask) { - try { - File directory = new File(RobotParserTest.class.getResource(dir).toURI()); - RobotParser.RobotParserCallable remoteOperation = new RobotParser.RobotParserCallable(mask, null, null); - remoteOperation.invoke(directory, null); - } catch (Exception e) { - e.printStackTrace(); - assert (false); - } - } +class RobotParserTest { @Test - public void testBasic1() { + void testBasic1() { final String dir = "."; final String mask = "low_failure_output.xml"; parse(dir, mask); } @Test - public void testBasic2() { + void testBasic2() { final String dir = "."; final String mask = "rebot_output.xml"; parse(dir, mask); } @Test - public void testBasic3() { + void testBasic3() { final String dir = "blueocean"; final String mask = "output.xml"; parse(dir, mask); } @Test - public void testBasic4() { + void testBasic4() { final String dir = "graph"; final String mask = "output.xml"; parse(dir, mask); } @Test - public void testBasic5() { + void testBasic5() { final String dir = "model"; final String mask = "collisions.xml"; parse(dir, mask); } @Test - public void testBasic6() { + void testBasic6() { final String dir = "model"; final String mask = "new_critical_output.xml"; parse(dir, mask); } @Test - public void testBasic7() { + void testBasic7() { final String dir = "model"; final String mask = "output.xml"; parse(dir, mask); } @Test - public void testBasic8() { + void testBasic8() { final String dir = "model"; final String mask = "suite-setup-and-teardown.xml"; parse(dir, mask); } @Test - public void testBasic9() { + void testBasic9() { final String dir = "model"; final String mask = "testfile.xml"; parse(dir, mask); } @Test - public void testBasic10() { + void testBasic10() { final String dir = "model"; final String mask = "teardown_fail.xml"; parse(dir, mask); } @Test - public void testBasic11() { + void testBasic11() { final String dir = "model"; final String mask = "testfile-001.xml"; parse(dir, mask); } @Test - public void testBasic12() { + void testBasic12() { final String dir = "model"; final String mask = "testfile-002.xml"; parse(dir, mask); } @Test - public void testBasic13() { + void testBasic13() { final String dir = "RobotPublisherSystemTest/jobs/robot/workspace"; final String mask = "output.xml"; parse(dir, mask); } @Test - public void testBasic14() { + void testBasic14() { final String dir = "RobotPublisherSystemTest/jobs/collisions/workspace"; final String mask = "output.xml"; parse(dir, mask); } @Test - public void testBasic15() { + void testBasic15() { final String dir = "RobotPublisherSystemTest/jobs/disable-archive-output-xml/workspace"; final String mask = "output.xml"; parse(dir, mask); } @Test - public void testBasic16() { + void testBasic16() { final String dir = "RobotPublisherSystemTest/jobs/dont-copy/workspace"; final String mask = "output.xml"; parse(dir, mask); } @Test - public void testBasic17() { + void testBasic17() { final String dir = "RobotPublisherSystemTest/jobs/failingtests/workspace"; final String mask = "output.xml"; parse(dir, mask); } @Test - public void testBasic18() { + void testBasic18() { final String dir = "RobotPublisherSystemTest/jobs/robot29output/workspace"; final String mask = "output.xml"; parse(dir, mask); } @Test - public void testBasic19() { + void testBasic19() { final String dir = "RobotPublisherSystemTest/jobs/oldrobotbuild/workspace"; final String mask = "output.xml"; parse(dir, mask); } @Test - public void testNested1() { + void testNested1() { final String dir = "."; final String mask = "nested_output.xml"; parse(dir, mask); } @Test - public void testNested2() { + void testNested2() { final String dir = "."; final String mask = "nested_output2.xml"; parse(dir, mask); } @Test - public void testRobot4() { + void testRobot4() { final String dir = "."; final String mask = "robot4_output.xml"; parse(dir, mask); } @Test - public void testRobot4Nested() { + void testRobot4Nested() { final String dir = "."; final String mask = "robot4_nested_output.xml"; parse(dir, mask); } @Test - public void testRobot4If() { + void testRobot4If() { final String dir = "."; final String mask = "robot4_if_output.xml"; parse(dir, mask); } - /** Robot Framework 5.0 introduced TRY-EXCEPT, WHILE, - * BREAK, and CONTINUE. The output file contains simple - * test cases which use new features. + /** + * Robot Framework 5.0 introduced TRY-EXCEPT, WHILE, + * BREAK, and CONTINUE. The output file contains simple + * test cases which use new features. */ @Test - public void testRobot5TryExceptFinallyWhileContinue() { + void testRobot5TryExceptFinallyWhileContinue() { final String dir = "robot5"; final String mask = "basic_new_features_output.xml"; parse(dir, mask); } @Test - public void testEmptyArgTags() { + void testEmptyArgTags() { final String dir = "."; final String mask = "empty_args-output.xml"; parse(dir, mask); } @Test - public void testRF7InlineVar() { + void testRF7InlineVar() { final String dir = "robot7"; final String mask = "inline_var_output.xml"; parse(dir, mask); } + + private void parse(String dir, String mask) { + assertDoesNotThrow(() -> { + File directory = new File(RobotParserTest.class.getResource(dir).toURI()); + RobotParser.RobotParserCallable remoteOperation = new RobotParser.RobotParserCallable(mask, null, null); + remoteOperation.invoke(directory, null); + }); + } } diff --git a/src/test/java/hudson/plugins/robot/RobotProjectActionTest.java b/src/test/java/hudson/plugins/robot/RobotProjectActionTest.java index 1a3a02d..003f0e1 100644 --- a/src/test/java/hudson/plugins/robot/RobotProjectActionTest.java +++ b/src/test/java/hudson/plugins/robot/RobotProjectActionTest.java @@ -1,100 +1,110 @@ /* -* Copyright 2008-2014 Nokia Solutions and Networks Oy -* -* 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. -*/ + * Copyright 2008-2014 Nokia Solutions and Networks Oy + * + * 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 hudson.plugins.robot; import hudson.model.FreeStyleBuild; import hudson.model.FreeStyleProject; import hudson.plugins.robot.model.RobotResult; -import junit.framework.TestCase; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; import java.io.File; -import java.io.IOException; - -import static org.mockito.Mockito.*; - - -public class RobotProjectActionTest extends TestCase { - - File tmpDir = new File(System.getProperty("java.io.tmpdir")); - File robotFile = new File(tmpDir, "robot_results.xml"); - - protected void setUp() throws Exception { - super.setUp(); - } - - protected void tearDown() throws SecurityException { - if(robotFile.exists()) - robotFile.delete(); - } - - public void testShouldNotDisplayGraph() throws IOException { - FreeStyleProject p = mock(FreeStyleProject.class); - FreeStyleBuild build = new FreeStyleBuild(p); - FreeStyleBuild build2 = spy(build); - when(p.getLastBuild()).thenReturn(build2); - doReturn(null).when(build2).getPreviousBuild(); - doReturn(null).when(build2).getAction(RobotBuildAction.class); - doReturn(null).when(build2).getAction(AggregatedRobotAction.class); - - RobotProjectAction action = new RobotProjectAction(p); - assertFalse(action.isDisplayGraph()); - } - - public void testShouldDisplayGraph() throws IOException { - FreeStyleProject p = mock(FreeStyleProject.class); - FreeStyleBuild build = mock(FreeStyleBuild.class); - when(build.getProject()).thenReturn(p); - when(build.getRootDir()).thenReturn(tmpDir); - RobotResult result = mock(RobotResult.class); - RobotBuildAction buildAction = new RobotBuildAction(build, result, "", null, null, null, false, "", false); - when(build.getAction(RobotBuildAction.class)).thenReturn(buildAction); - when(p.getLastBuild()).thenReturn(build); - - RobotProjectAction action = new RobotProjectAction(p); - assertTrue(action.isDisplayGraph()); - } - - public void testShouldGetLastBuildAction() throws IOException{ - FreeStyleProject p = mock(FreeStyleProject.class); - - FreeStyleBuild lastBuild = mock(FreeStyleBuild.class); - FreeStyleBuild buildWithAction = mock(FreeStyleBuild.class); - when(buildWithAction.getProject()).thenReturn(p); - when(buildWithAction.getRootDir()).thenReturn(tmpDir); - RobotResult result = mock(RobotResult.class); - RobotBuildAction buildAction = new RobotBuildAction(buildWithAction, result, "", null, null, null, false, "", false); - when(buildWithAction.getAction(RobotBuildAction.class)).thenReturn(buildAction); - - when(p.getLastBuild()).thenReturn(lastBuild); - when(lastBuild.getPreviousBuild()).thenReturn(buildWithAction); - - RobotProjectAction projectAction = new RobotProjectAction(p); - assertEquals(buildAction, projectAction.getLastBuildAction()); - } - - public void testShouldReturnNullWhenNoActions() { - FreeStyleProject p = mock(FreeStyleProject.class); - - FreeStyleBuild lastBuild = mock(FreeStyleBuild.class); - FreeStyleBuild firstBuild = mock(FreeStyleBuild.class); - - when(p.getLastBuild()).thenReturn(lastBuild); - when(lastBuild.getPreviousBuild()).thenReturn(firstBuild); - - RobotProjectAction projectAction = new RobotProjectAction(p); - assertNull(projectAction.getLastBuildAction()); - } + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.when; + + +class RobotProjectActionTest { + + private final File tmpDir = new File(System.getProperty("java.io.tmpdir")); + private final File robotFile = new File(tmpDir, "robot_results.xml"); + + + @AfterEach + void tearDown() { + if (robotFile.exists()) { + robotFile.delete(); + } + } + + @Test + void testShouldNotDisplayGraph() throws Exception { + FreeStyleProject p = mock(FreeStyleProject.class); + FreeStyleBuild build = new FreeStyleBuild(p); + FreeStyleBuild build2 = spy(build); + when(p.getLastBuild()).thenReturn(build2); + doReturn(null).when(build2).getPreviousBuild(); + doReturn(null).when(build2).getAction(RobotBuildAction.class); + doReturn(null).when(build2).getAction(AggregatedRobotAction.class); + + RobotProjectAction action = new RobotProjectAction(p); + assertFalse(action.isDisplayGraph()); + } + + @Test + void testShouldDisplayGraph() { + FreeStyleProject p = mock(FreeStyleProject.class); + FreeStyleBuild build = mock(FreeStyleBuild.class); + when(build.getProject()).thenReturn(p); + when(build.getRootDir()).thenReturn(tmpDir); + RobotResult result = mock(RobotResult.class); + RobotBuildAction buildAction = new RobotBuildAction(build, result, "", null, null, null, false, "", false); + when(build.getAction(RobotBuildAction.class)).thenReturn(buildAction); + when(p.getLastBuild()).thenReturn(build); + + RobotProjectAction action = new RobotProjectAction(p); + assertTrue(action.isDisplayGraph()); + } + + @Test + void testShouldGetLastBuildAction() { + FreeStyleProject p = mock(FreeStyleProject.class); + + FreeStyleBuild lastBuild = mock(FreeStyleBuild.class); + FreeStyleBuild buildWithAction = mock(FreeStyleBuild.class); + when(buildWithAction.getProject()).thenReturn(p); + when(buildWithAction.getRootDir()).thenReturn(tmpDir); + RobotResult result = mock(RobotResult.class); + RobotBuildAction buildAction = new RobotBuildAction(buildWithAction, result, "", null, null, null, false, "", false); + when(buildWithAction.getAction(RobotBuildAction.class)).thenReturn(buildAction); + + when(p.getLastBuild()).thenReturn(lastBuild); + when(lastBuild.getPreviousBuild()).thenReturn(buildWithAction); + + RobotProjectAction projectAction = new RobotProjectAction(p); + assertEquals(buildAction, projectAction.getLastBuildAction()); + } + + @Test + void testShouldReturnNullWhenNoActions() { + FreeStyleProject p = mock(FreeStyleProject.class); + + FreeStyleBuild lastBuild = mock(FreeStyleBuild.class); + FreeStyleBuild firstBuild = mock(FreeStyleBuild.class); + + when(p.getLastBuild()).thenReturn(lastBuild); + when(lastBuild.getPreviousBuild()).thenReturn(firstBuild); + + RobotProjectAction projectAction = new RobotProjectAction(p); + assertNull(projectAction.getLastBuildAction()); + } } diff --git a/src/test/java/hudson/plugins/robot/RobotPublisherSystemTest.java b/src/test/java/hudson/plugins/robot/RobotPublisherSystemTest.java index 739aa7a..89bfa0d 100644 --- a/src/test/java/hudson/plugins/robot/RobotPublisherSystemTest.java +++ b/src/test/java/hudson/plugins/robot/RobotPublisherSystemTest.java @@ -24,463 +24,478 @@ import hudson.plugins.robot.model.RobotCaseResult; import hudson.plugins.robot.model.RobotResult; import jenkins.model.Jenkins; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import org.htmlunit.html.HtmlPage; +import org.htmlunit.html.HtmlTable; +import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition; +import org.jenkinsci.plugins.workflow.job.WorkflowJob; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.jvnet.hudson.test.JenkinsRule; +import org.jvnet.hudson.test.JenkinsRule.WebClient; +import org.jvnet.hudson.test.junit.jupiter.WithJenkins; +import org.jvnet.hudson.test.recipes.LocalData; import java.io.File; import java.util.List; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.beans.SamePropertyValuesAs.samePropertyValuesAs; +import static org.htmlunit.WebAssert.assertElementNotPresentByXPath; +import static org.htmlunit.WebAssert.assertElementPresentByXPath; +import static org.htmlunit.WebAssert.assertInputContainsValue; +import static org.htmlunit.WebAssert.assertInputPresent; +import static org.htmlunit.WebAssert.assertTextNotPresent; +import static org.htmlunit.WebAssert.assertTextPresent; +import static org.htmlunit.WebAssert.assertTitleEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +@WithJenkins +class RobotPublisherSystemTest { + + private JenkinsRule j; + + @BeforeEach + void setUp(JenkinsRule rule) { + j = rule; + } -import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition; -import org.jenkinsci.plugins.workflow.job.WorkflowJob; -import org.junit.Rule; -import org.junit.Test; -import org.jvnet.hudson.test.JenkinsRule; -import org.jvnet.hudson.test.JenkinsRule.WebClient; -import org.jvnet.hudson.test.recipes.LocalData; + @Test + void testRoundTripConfig() throws Exception { + FreeStyleProject p = j.jenkins.createProject(FreeStyleProject.class, "testRoundTripConfig"); + RobotPublisher before = new RobotPublisher(null, "a", "b", false, "c", "d", 11, 27, true, "dir1/*.jpg, dir2/*.png", + false, ""); + p.getPublishersList().add(before); + j.configRoundtrip(p); + RobotPublisher after = p.getPublishersList().get(RobotPublisher.class); + assertThat( + "outputPath,outputFileName,reportFileName,logFileName,passThreshold,unstableThreshold,countSkippedTests,otherFiles", + before, samePropertyValuesAs(after)); + } -import org.htmlunit.WebAssert; -import org.htmlunit.html.HtmlPage; -import org.htmlunit.html.HtmlTable; + @Test + void testConfigView() throws Exception { + FreeStyleProject p = j.jenkins.createProject(FreeStyleProject.class, "testConfigView"); + RobotPublisher before = new RobotPublisher(null, "a", "b", false, "c", "d", 11, 27, true, "dir1/*.jpg, dir2/*.png", + false, ""); + p.getPublishersList().add(before); + HtmlPage page = j.createWebClient().getPage(p, "configure"); + assertTextPresent(page, "Publish Robot Framework"); + assertInputPresent(page, "_.outputPath"); + assertInputContainsValue(page, "_.outputPath", "a"); + assertInputPresent(page, "_.outputFileName"); + assertInputContainsValue(page, "_.outputFileName", "b"); + assertInputPresent(page, "_.reportFileName"); + assertInputContainsValue(page, "_.reportFileName", "c"); + assertInputPresent(page, "_.logFileName"); + assertInputContainsValue(page, "_.logFileName", "d"); + assertInputPresent(page, "_.unstableThreshold"); + assertInputContainsValue(page, "_.unstableThreshold", "27.0"); + assertInputPresent(page, "_.passThreshold"); + assertInputContainsValue(page, "_.passThreshold", "11.0"); + assertInputPresent(page, "_.countSkippedTests"); + assertInputContainsValue(page, "_.countSkippedTests", "on"); + assertInputPresent(page, "_.otherFiles"); + assertInputContainsValue(page, "_.otherFiles", "dir1/*.jpg,dir2/*.png"); + } -public class RobotPublisherSystemTest { - - @Rule - public JenkinsRule j = new JenkinsRule(); - - @Test - public void testRoundTripConfig() throws Exception { - FreeStyleProject p = j.jenkins.createProject(FreeStyleProject.class, "testRoundTripConfig"); - RobotPublisher before = new RobotPublisher(null, "a", "b", false, "c", "d", 11, 27, true, "dir1/*.jpg, dir2/*.png", - false, ""); - p.getPublishersList().add(before); - j.configRoundtrip(p); - RobotPublisher after = p.getPublishersList().get(RobotPublisher.class); - assertThat( - "outputPath,outputFileName,reportFileName,logFileName,passThreshold,unstableThreshold,countSkippedTests,otherFiles", - before, samePropertyValuesAs(after)); - } - - @Test - public void testConfigView() throws Exception { - FreeStyleProject p = j.jenkins.createProject(FreeStyleProject.class, "testConfigView"); - RobotPublisher before = new RobotPublisher(null, "a", "b", false, "c", "d", 11, 27, true, "dir1/*.jpg, dir2/*.png", - false, ""); - p.getPublishersList().add(before); - HtmlPage page = j.createWebClient().getPage(p, "configure"); - WebAssert.assertTextPresent(page, "Publish Robot Framework"); - WebAssert.assertInputPresent(page, "_.outputPath"); - WebAssert.assertInputContainsValue(page, "_.outputPath", "a"); - WebAssert.assertInputPresent(page, "_.outputFileName"); - WebAssert.assertInputContainsValue(page, "_.outputFileName", "b"); - WebAssert.assertInputPresent(page, "_.reportFileName"); - WebAssert.assertInputContainsValue(page, "_.reportFileName", "c"); - WebAssert.assertInputPresent(page, "_.logFileName"); - WebAssert.assertInputContainsValue(page, "_.logFileName", "d"); - WebAssert.assertInputPresent(page, "_.unstableThreshold"); - WebAssert.assertInputContainsValue(page, "_.unstableThreshold", "27.0"); - WebAssert.assertInputPresent(page, "_.passThreshold"); - WebAssert.assertInputContainsValue(page, "_.passThreshold", "11.0"); - WebAssert.assertInputPresent(page, "_.countSkippedTests"); - WebAssert.assertInputContainsValue(page, "_.countSkippedTests", "on"); - WebAssert.assertInputPresent(page, "_.otherFiles"); - WebAssert.assertInputContainsValue(page, "_.otherFiles", "dir1/*.jpg,dir2/*.png"); - } - - @LocalData - @Test - public void testPublish() throws Exception { - Run lastBuild = this.executeJobWithSuccess("robot"); - - File storedOutput = new File(lastBuild.getRootDir(), RobotPublisher.DEFAULT_ARCHIVE_DIR + "/output.xml"); - File storedSplitOutput = new File(lastBuild.getRootDir(), RobotPublisher.DEFAULT_ARCHIVE_DIR + "/output-001.xml"); - File storedReport = new File(lastBuild.getRootDir(), RobotPublisher.DEFAULT_ARCHIVE_DIR + "/report.html"); - File storedSplitReport = new File(lastBuild.getRootDir(), RobotPublisher.DEFAULT_ARCHIVE_DIR + "/report.html"); - File storedLog = new File(lastBuild.getRootDir(), RobotPublisher.DEFAULT_ARCHIVE_DIR + "/log.html"); - File storedSplitLog = new File(lastBuild.getRootDir(), RobotPublisher.DEFAULT_ARCHIVE_DIR + "/log-001.html"); - File storedJs = new File(lastBuild.getRootDir(), RobotPublisher.DEFAULT_ARCHIVE_DIR + "/log.js"); - File storedSplitJs1 = new File(lastBuild.getRootDir(), RobotPublisher.DEFAULT_ARCHIVE_DIR + "/log-001.js"); - File storedImage1 = new File(lastBuild.getRootDir(), RobotPublisher.DEFAULT_ARCHIVE_DIR + "/screenshot.png"); - File storedImage2 = new File(lastBuild.getRootDir(), - RobotPublisher.DEFAULT_ARCHIVE_DIR + "/subfolder/screenshot2.png"); - File storedDummy = new File(lastBuild.getRootDir(), RobotPublisher.DEFAULT_ARCHIVE_DIR + "dummy.file"); - - assertTrue("output.xml was not stored", storedOutput.exists()); - assertTrue("output-001.xml was not stored", storedSplitOutput.exists()); - assertTrue("report.html was not stored", storedReport.exists()); - assertTrue("report-001.html was not stored", storedSplitReport.exists()); - assertTrue("log.html was not stored", storedLog.exists()); - assertTrue("log-001.html was not stored", storedSplitLog.exists()); - assertTrue("log.js was not stored", storedJs.exists()); - assertTrue("log-001.js was not stored", storedSplitJs1.exists()); - assertTrue("screenshot.png was not stored", storedImage1.exists()); - assertTrue("screenshot2.png was not stored", storedImage2.exists()); - assertFalse("dummy.file was copied", storedDummy.exists()); - } - - @LocalData - @Test - public void testDontCopyOuputWhendisableArchiveOutput() throws Exception { - Run lastBuild = this.executeJobWithSuccess("disable-archive-output-xml"); - - File storedOutput = new File(lastBuild.getRootDir(), RobotPublisher.DEFAULT_ARCHIVE_DIR + "/output.xml"); - File storedSplitOutput = new File(lastBuild.getRootDir(), RobotPublisher.DEFAULT_ARCHIVE_DIR + "/output-001.xml"); - File storedReport = new File(lastBuild.getRootDir(), RobotPublisher.DEFAULT_ARCHIVE_DIR + "/report.html"); - File storedSplitReport = new File(lastBuild.getRootDir(), RobotPublisher.DEFAULT_ARCHIVE_DIR + "/report.html"); - File storedLog = new File(lastBuild.getRootDir(), RobotPublisher.DEFAULT_ARCHIVE_DIR + "/log.html"); - File storedSplitLog = new File(lastBuild.getRootDir(), RobotPublisher.DEFAULT_ARCHIVE_DIR + "/log-001.html"); - File storedJs = new File(lastBuild.getRootDir(), RobotPublisher.DEFAULT_ARCHIVE_DIR + "/log.js"); - File storedSplitJs1 = new File(lastBuild.getRootDir(), RobotPublisher.DEFAULT_ARCHIVE_DIR + "/log-001.js"); - File storedImage1 = new File(lastBuild.getRootDir(), RobotPublisher.DEFAULT_ARCHIVE_DIR + "/screenshot.png"); - File storedImage2 = new File(lastBuild.getRootDir(), - RobotPublisher.DEFAULT_ARCHIVE_DIR + "/subfolder/screenshot2.png"); - File storedDummy = new File(lastBuild.getRootDir(), RobotPublisher.DEFAULT_ARCHIVE_DIR + "dummy.file"); - - assertFalse("output.xml was copied", storedOutput.exists()); - assertFalse("output-001.xml was copied", storedSplitOutput.exists()); - assertTrue("report.html was not stored", storedReport.exists()); - assertTrue("report-001.html was not stored", storedSplitReport.exists()); - assertTrue("log.html was not stored", storedLog.exists()); - assertTrue("log-001.html was not stored", storedSplitLog.exists()); - assertTrue("log.js was not stored", storedJs.exists()); - assertTrue("log-001.js was not stored", storedSplitJs1.exists()); - assertTrue("screenshot.png was not stored", storedImage1.exists()); - assertTrue("screenshot2.png was not stored", storedImage2.exists()); - assertFalse("dummy.file was copied", storedDummy.exists()); - } - - @LocalData - @Test - public void testDontCopyExcessFilesWhenOtherFilesEmpty() throws Exception { - Run lastBuild = this.executeJobWithSuccess("dont-copy"); - - File storedOutput = new File(lastBuild.getRootDir(), RobotPublisher.DEFAULT_ARCHIVE_DIR + "/output.xml"); - File storedSplitOutput = new File(lastBuild.getRootDir(), RobotPublisher.DEFAULT_ARCHIVE_DIR + "/output-001.xml"); - File storedDummy = new File(lastBuild.getRootDir(), RobotPublisher.DEFAULT_ARCHIVE_DIR + "/dummy.file"); - - assertTrue("output.xml was not stored", storedOutput.exists()); - assertTrue("output-001.xml was not stored", storedSplitOutput.exists()); - assertFalse("dummy.file was copied", storedDummy.exists()); - } - - @LocalData - @Test - public void testActionViewsWithNoRuns() throws Exception { - WebClient wc = j.createWebClient(); - HtmlPage page = wc.goTo("job/robot/"); - - WebAssert.assertElementPresentByXPath(page, "//div[@id='tasks']//a[@href='/jenkins/job/robot/robot']"); - WebAssert.assertElementPresentByXPath(page, - "//div[@id='main-panel']//p[contains(.,'No results available yet.')]"); - WebAssert.assertElementNotPresentByXPath(page, "//div[@id='main-panel']//img[@id='passfailgraph']"); - - page = wc.goTo("job/robot/robot/"); - WebAssert.assertTextPresent(page, "No robot results available yet!"); - } - - @LocalData - @Test - public void testOldActionViewsWithData() throws Exception { - WebClient wc = j.createWebClient(); - HtmlPage page = wc.goTo("job/oldrobotbuild/"); - WebAssert.assertElementPresentByXPath(page, "//div[@id='tasks']//a[@href='/jenkins/job/oldrobotbuild/robot']"); - WebAssert.assertElementPresentByXPath(page, "//div[@id='main-panel']//h4[contains(.,'Latest Robot Results:')]"); - WebAssert.assertElementPresentByXPath(page, "//div[@id='main-panel']//img[@id='passfailgraph']"); - WebAssert.assertElementPresentByXPath(page, - "//div[@id='main-panel']//a[@href='/jenkins/job/oldrobotbuild/1/robot' and contains(text(),'Browse results')]"); - this.verifyTotalsTable(page, 8, 4, 0, "50.0"); - - page = wc.goTo("job/oldrobotbuild/robot/"); - WebAssert.assertTitleEquals(page, "Testcases & Othercases Test Report"); - - page = wc.goTo("job/oldrobotbuild/1/"); - WebAssert.assertElementPresentByXPath(page, - "//div[@id='tasks']//a[@href='/jenkins/job/oldrobotbuild/1/robot']"); - WebAssert.assertElementPresentByXPath(page, "//div[@id='main-panel']//h4[contains(.,'Robot Test Summary:')]"); - WebAssert.assertElementPresentByXPath(page, - "//div[@id='main-panel']//a[@href='/jenkins/job/oldrobotbuild/1/robot' and contains(text(),'Browse results')]"); - this.verifyTotalsTable(page, 8, 4, 0,"50.0"); - - page = wc.goTo("job/oldrobotbuild/1/robot/"); - WebAssert.assertTitleEquals(page, "Testcases & Othercases Test Report"); - } - - @LocalData - @Test - public void testSummariesWithData() throws Exception { - WebClient wc = this.executeJobAndGetWebClient("robot"); - - HtmlPage page = wc.goTo("job/robot/"); - WebAssert.assertElementPresentByXPath(page, "//div[@id='tasks']//a[@href='/jenkins/job/robot/robot']"); - WebAssert.assertElementPresentByXPath(page, "//div[@id='main-panel']//h4[contains(.,'Latest Robot Results:')]"); - WebAssert.assertElementPresentByXPath(page, "//div[@id='main-panel']//img[@id='passfailgraph']"); - WebAssert.assertElementPresentByXPath(page, - "//div[@id='main-panel']//a[@href='/jenkins/job/robot/1/robot' and contains(text(),'Browse results')]"); - WebAssert.assertElementPresentByXPath(page, - "//div[@id='main-panel']//a[@href='/jenkins/job/robot/1/robot/report/report.html' and contains(text(), 'Open report.html')]"); - WebAssert.assertElementPresentByXPath(page, - "//div[@id='main-panel']//a[@href='/jenkins/job/robot/1/robot/report/log.html' and contains(text(), 'Open log.html')]"); - verifyTotalsTable(page, 8, 4, 0,"50.0"); - - page = wc.goTo("job/robot/1/"); - WebAssert.assertElementPresentByXPath(page, "//div[@id='tasks']//a[@href='/jenkins/job/robot/1/robot']"); - WebAssert.assertElementPresentByXPath(page, "//div[@id='main-panel']//h4[contains(.,'Robot Test Summary:')]"); - WebAssert.assertElementPresentByXPath(page, - "//div[@id='main-panel']//a[@href='/jenkins/job/robot/1/robot' and contains(text(),'Browse results')]"); - WebAssert.assertElementPresentByXPath(page, - "//div[@id='main-panel']//a[@href='/jenkins/job/robot/1/robot/report/report.html' and contains(text(), 'Open report.html')]"); - WebAssert.assertElementPresentByXPath(page, - "//div[@id='main-panel']//a[@href='/jenkins/job/robot/1/robot/report/log.html' and contains(text(), 'Open log.html')]"); - verifyTotalsTable(page, 8, 4, 0,"50.0"); - } - - @LocalData - @Test - public void testSummariesWithVariablesInFileNames() throws Exception { - WebClient wc = this.executeJobAndGetWebClient("files-with-env-vars"); - - HtmlPage page = wc.goTo("job/files-with-env-vars/"); - WebAssert.assertElementPresentByXPath(page, "//div[@id='tasks']//a[@href='/jenkins/job/files-with-env-vars/robot']"); - WebAssert.assertElementPresentByXPath(page, "//div[@id='main-panel']//h4[contains(.,'Latest Robot Results:')]"); - WebAssert.assertElementPresentByXPath(page, "//div[@id='main-panel']//img[@id='passfailgraph']"); - WebAssert.assertElementPresentByXPath(page, - "//div[@id='main-panel']//a[@href='/jenkins/job/files-with-env-vars/1/robot' and contains(text(),'Browse results')]"); - WebAssert.assertElementPresentByXPath(page, - "//div[@id='main-panel']//a[@href='/jenkins/job/files-with-env-vars/1/robot/report/report_1.html' and contains(text(), 'Open report_1.html')]"); - WebAssert.assertElementPresentByXPath(page, - "//div[@id='main-panel']//a[@href='/jenkins/job/files-with-env-vars/1/robot/report/log_1.html' and contains(text(), 'Open log_1.html')]"); - verifyTotalsTable(page, 6, 1, 0,"83.3"); - - page = wc.goTo("job/files-with-env-vars/1/"); - WebAssert.assertElementPresentByXPath(page, "//div[@id='tasks']//a[@href='/jenkins/job/files-with-env-vars/1/robot']"); - WebAssert.assertElementPresentByXPath(page, "//div[@id='main-panel']//h4[contains(.,'Robot Test Summary:')]"); - WebAssert.assertElementPresentByXPath(page, - "//div[@id='main-panel']//a[@href='/jenkins/job/files-with-env-vars/1/robot' and contains(text(),'Browse results')]"); - WebAssert.assertElementPresentByXPath(page, - "//div[@id='main-panel']//a[@href='/jenkins/job/files-with-env-vars/1/robot/report/report_1.html' and contains(text(), 'Open report_1.html')]"); - WebAssert.assertElementPresentByXPath(page, - "//div[@id='main-panel']//a[@href='/jenkins/job/files-with-env-vars/1/robot/report/log_1.html' and contains(text(), 'Open log_1.html')]"); - verifyTotalsTable(page, 6, 1, 0,"83.3"); - } - - @LocalData - @Test - public void testRobot29Outputs() throws Exception { - WebClient wc = this.executeJobAndGetWebClient("robot29output"); - HtmlPage page = wc.goTo("job/robot29output/"); - verifyTotalsTable(page, 1, 0, 0,"100.0"); - } - - @LocalData - @Test - public void testCombinedOutputs() throws Exception { - WebClient wc = this.executeJobAndGetWebClient("several-outputs"); - - HtmlPage page = wc.goTo("job/several-outputs/"); - WebAssert.assertElementPresentByXPath(page, - "//div[@id='tasks']//a[@href='/jenkins/job/several-outputs/robot']"); - WebAssert.assertElementPresentByXPath(page, "//div[@id='main-panel']//h4[contains(.,'Latest Robot Results:')]"); - WebAssert.assertElementPresentByXPath(page, "//div[@id='main-panel']//img[@id='passfailgraph']"); - WebAssert.assertElementPresentByXPath(page, - "//div[@id='main-panel']//a[@href='/jenkins/job/several-outputs/1/robot' and contains(text(),'Browse results')]"); - WebAssert.assertElementPresentByXPath(page, - "//div[@id='main-panel']//a[@href='/jenkins/job/several-outputs/1/robot/report/**/report.html' and contains(text(), 'Open **/report.html')]"); - WebAssert.assertElementPresentByXPath(page, - "//div[@id='main-panel']//a[@href='/jenkins/job/several-outputs/1/robot/report/**/log.html' and contains(text(), 'Open **/log.html')]"); - verifyTotalsTable(page, 2, 0, 0,"100.0"); - } - - @LocalData - @Test - public void testReportPage() throws Exception { - WebClient wc = this.executeJobAndGetWebClient("robot"); - - HtmlPage page = wc.goTo("job/robot/robot/"); - WebAssert.assertTextPresent(page, "Robot Framework Test Results"); - WebAssert.assertTextPresent(page, "4 passed, 4 failed"); - WebAssert.assertTextPresent(page, "0:00:00.041 (+0:00:00.041)"); - WebAssert.assertElementPresentByXPath(page, - "//div[@id='main-panel']//a[@href='Testcases%20&%20Othercases/Testcases/Not%20equal' and contains(.,'Testcases & Othercases.Testcases.Not equal')]"); - WebAssert.assertElementPresentByXPath(page, - "//div[@id='main-panel']//a[@href='Testcases%20&%20Othercases/Othercases' and contains(.,'Testcases & Othercases.Othercases')]"); - - page = wc.goTo("job/robot/1/robot/report/"); - WebAssert.assertElementPresentByXPath(page, - "//div[@id='main-panel']//a[@href='output.xml' and contains(.,'output.xml')]"); - - page = wc.goTo("job/robot/1/robot/Testcases%20&%20Othercases"); - WebAssert.assertTextPresent(page, "4 passed, 4 failed"); - WebAssert.assertTextPresent(page, "0:00:00.041 (+0:00:00.041)"); - WebAssert.assertTextPresent(page, "Failed Test Cases"); - WebAssert.assertElementPresentByXPath(page, - "//div[@id='main-panel']//a[@href='Testcases/Not%20equal' and contains(.,'Testcases.Not equal')]"); - WebAssert.assertElementPresentByXPath(page, - "//div[@id='main-panel']//a[@href='Othercases' and contains(.,'Othercases')]"); - - page = wc.goTo("job/robot/1/robot/Testcases%20&%20Othercases/Othercases"); - WebAssert.assertTextPresent(page, "2 passed, 2 failed"); - WebAssert.assertTextPresent(page, "0:00:00.008 (+0:00:00.008)"); - WebAssert.assertTextPresent(page, "Test Cases"); - WebAssert.assertElementPresentByXPath(page, - "//div[@id='main-panel']//a[@href='Not%20equal' and contains(.,'Not equal')]"); - WebAssert.assertElementPresentByXPath(page, - "//div[@id='main-panel']//a[@href='Contains%20string' and contains(.,'Contains string')]"); - - page = wc.goTo("job/robot/1/robot/Testcases%20&%20Othercases/Othercases/Not%20equal"); - WebAssert.assertTextPresent(page, "Not equal"); - WebAssert.assertTextPresent(page, "FAIL"); - WebAssert.assertTextPresent(page, "Message:"); - WebAssert.assertTextPresent(page, "Hello, world! != Good bye, world!"); - WebAssert.assertTextPresent(page, "0:00:00.001 (+0:00:00.001)"); - WebAssert.assertElementPresentByXPath(page, - "//div[@id='main-panel']//img[@src='durationGraph?maxBuildsToShow=0']"); - - page = wc.goTo("job/robot/1/robot/Testcases%20&%20Othercases/Othercases/Contains%20string"); - WebAssert.assertTextPresent(page, "PASS"); - WebAssert.assertTextNotPresent(page, "Message:"); - - } - - @LocalData - @Test - public void testMissingReportFileWithOld() throws Exception { - Project testProject = this.getProject("oldrobotbuild"); - - WebClient wc = j.createWebClient(); - - File buildRoot = testProject.getLastBuild().getRootDir(); - File robotHtmlReport = new File(buildRoot, RobotPublisher.DEFAULT_ARCHIVE_DIR + "/report.html"); - if (!robotHtmlReport.delete()) - fail("Unable to delete report directory"); - - HtmlPage page = wc.goTo("job/oldrobotbuild/robot/"); - WebAssert.assertTextPresent(page, "No Robot html report found!"); - - page = wc.goTo("job/oldrobotbuild/1/robot/"); - WebAssert.assertTextPresent(page, "No Robot html report found!"); - } - - @LocalData - @Test - public void testFailedSince() { - Jenkins jenkins = j.getInstance(); - List projects = jenkins.getAllItems(Project.class); - Run lastRun = null; - for (Project project : projects) { - if (project.getName().equalsIgnoreCase("failingtests")) { - lastRun = project.getLastCompletedBuild(); - } - } - if (lastRun == null) - fail("No build including Robot results was found"); - - RobotBuildAction action = lastRun.getAction(RobotBuildAction.class); - RobotResult result = action.getResult(); - RobotCaseResult firstFailed = result.getAllFailedCases().get(0); - assertEquals(2, firstFailed.getFailedSince()); - } - - @LocalData - @Test - public void testMatrixBuildReportLinks() throws Exception { - WebClient wc = j.createWebClient(); - HtmlPage page = wc.goTo("job/matrix-robot/FOO=bar/2"); - WebAssert.assertElementPresentByXPath(page, - "//div[@id='main-panel']//a[@href='/jenkins/job/matrix-robot/FOO=bar/2/robot' and contains(.,'Browse results')]"); - WebAssert.assertElementPresentByXPath(page, - "//div[@id='main-panel']//a[@href='/jenkins/job/matrix-robot/FOO=bar/2/robot/report/report.html' and contains(.,'Open report.html')]"); - } - - @LocalData - @Test - public void testMatrixBuildSummary() throws Exception { - Jenkins jenkins = j.getInstance(); - List projects = jenkins.getAllItems(MatrixProject.class); - MatrixProject testProject = null; - for (MatrixProject project : projects){ - System.out.println(project.getName()); - if(project.getName().equals("matrix-robot")) testProject = project; - } - if(testProject == null) fail("Couldn't find example project"); - - j.assertBuildStatusSuccess(testProject.scheduleBuild2(0)); - WebClient wc = j.createWebClient(); - HtmlPage page = wc.goTo("job/matrix-robot"); - WebAssert.assertElementPresentByXPath(page, "//div[@id='tasks']//a[@href='/jenkins/job/matrix-robot/robot']"); - WebAssert.assertElementPresentByXPath(page, "//div[@id='main-panel']//img[@id='passfailgraph']"); - - page = wc.goTo("job/matrix-robot/3"); - WebAssert.assertElementPresentByXPath(page, - "//div[@id='main-panel']//a[@href='/jenkins/job/matrix-robot/3/robot']"); - WebAssert.assertElementPresentByXPath(page, "//div[@id='main-panel']//h4[contains(.,'Robot Test Summary:')]"); - WebAssert.assertElementPresentByXPath(page, - "//div[@id='main-panel']//a[@href='/jenkins/job/matrix-robot/3/robot' and contains(text(),'Browse results')]"); - } - - @Test - public void testRobotPipelineStep() throws Exception { + @LocalData + @Test + void testPublish() throws Exception { + Run lastBuild = executeJobWithSuccess("robot"); + + File storedOutput = new File(lastBuild.getRootDir(), RobotPublisher.DEFAULT_ARCHIVE_DIR + "/output.xml"); + File storedSplitOutput = new File(lastBuild.getRootDir(), RobotPublisher.DEFAULT_ARCHIVE_DIR + "/output-001.xml"); + File storedReport = new File(lastBuild.getRootDir(), RobotPublisher.DEFAULT_ARCHIVE_DIR + "/report.html"); + File storedSplitReport = new File(lastBuild.getRootDir(), RobotPublisher.DEFAULT_ARCHIVE_DIR + "/report.html"); + File storedLog = new File(lastBuild.getRootDir(), RobotPublisher.DEFAULT_ARCHIVE_DIR + "/log.html"); + File storedSplitLog = new File(lastBuild.getRootDir(), RobotPublisher.DEFAULT_ARCHIVE_DIR + "/log-001.html"); + File storedJs = new File(lastBuild.getRootDir(), RobotPublisher.DEFAULT_ARCHIVE_DIR + "/log.js"); + File storedSplitJs1 = new File(lastBuild.getRootDir(), RobotPublisher.DEFAULT_ARCHIVE_DIR + "/log-001.js"); + File storedImage1 = new File(lastBuild.getRootDir(), RobotPublisher.DEFAULT_ARCHIVE_DIR + "/screenshot.png"); + File storedImage2 = new File(lastBuild.getRootDir(), + RobotPublisher.DEFAULT_ARCHIVE_DIR + "/subfolder/screenshot2.png"); + File storedDummy = new File(lastBuild.getRootDir(), RobotPublisher.DEFAULT_ARCHIVE_DIR + "dummy.file"); + + assertTrue(storedOutput.exists(), "output.xml was not stored"); + assertTrue(storedSplitOutput.exists(), "output-001.xml was not stored"); + assertTrue(storedReport.exists(), "report.html was not stored"); + assertTrue(storedSplitReport.exists(), "report-001.html was not stored"); + assertTrue(storedLog.exists(), "log.html was not stored"); + assertTrue(storedSplitLog.exists(), "log-001.html was not stored"); + assertTrue(storedJs.exists(), "log.js was not stored"); + assertTrue(storedSplitJs1.exists(), "log-001.js was not stored"); + assertTrue(storedImage1.exists(), "screenshot.png was not stored"); + assertTrue(storedImage2.exists(), "screenshot2.png was not stored"); + assertFalse(storedDummy.exists(), "dummy.file was copied"); + } + + @LocalData + @Test + void testDontCopyOutputWhenDisableArchiveOutput() throws Exception { + Run lastBuild = executeJobWithSuccess("disable-archive-output-xml"); + + File storedOutput = new File(lastBuild.getRootDir(), RobotPublisher.DEFAULT_ARCHIVE_DIR + "/output.xml"); + File storedSplitOutput = new File(lastBuild.getRootDir(), RobotPublisher.DEFAULT_ARCHIVE_DIR + "/output-001.xml"); + File storedReport = new File(lastBuild.getRootDir(), RobotPublisher.DEFAULT_ARCHIVE_DIR + "/report.html"); + File storedSplitReport = new File(lastBuild.getRootDir(), RobotPublisher.DEFAULT_ARCHIVE_DIR + "/report.html"); + File storedLog = new File(lastBuild.getRootDir(), RobotPublisher.DEFAULT_ARCHIVE_DIR + "/log.html"); + File storedSplitLog = new File(lastBuild.getRootDir(), RobotPublisher.DEFAULT_ARCHIVE_DIR + "/log-001.html"); + File storedJs = new File(lastBuild.getRootDir(), RobotPublisher.DEFAULT_ARCHIVE_DIR + "/log.js"); + File storedSplitJs1 = new File(lastBuild.getRootDir(), RobotPublisher.DEFAULT_ARCHIVE_DIR + "/log-001.js"); + File storedImage1 = new File(lastBuild.getRootDir(), RobotPublisher.DEFAULT_ARCHIVE_DIR + "/screenshot.png"); + File storedImage2 = new File(lastBuild.getRootDir(), + RobotPublisher.DEFAULT_ARCHIVE_DIR + "/subfolder/screenshot2.png"); + File storedDummy = new File(lastBuild.getRootDir(), RobotPublisher.DEFAULT_ARCHIVE_DIR + "dummy.file"); + + assertFalse(storedOutput.exists(), "output.xml was copied"); + assertFalse(storedSplitOutput.exists(), "output-001.xml was copied"); + assertTrue(storedReport.exists(), "report.html was not stored"); + assertTrue(storedSplitReport.exists(), "report-001.html was not stored"); + assertTrue(storedLog.exists(), "log.html was not stored"); + assertTrue(storedSplitLog.exists(), "log-001.html was not stored"); + assertTrue(storedJs.exists(), "log.js was not stored"); + assertTrue(storedSplitJs1.exists(), "log-001.js was not stored"); + assertTrue(storedImage1.exists(), "screenshot.png was not stored"); + assertTrue(storedImage2.exists(), "screenshot2.png was not stored"); + assertFalse(storedDummy.exists(), "dummy.file was copied"); + } + + @LocalData + @Test + void testDontCopyExcessFilesWhenOtherFilesEmpty() throws Exception { + Run lastBuild = executeJobWithSuccess("dont-copy"); + + File storedOutput = new File(lastBuild.getRootDir(), RobotPublisher.DEFAULT_ARCHIVE_DIR + "/output.xml"); + File storedSplitOutput = new File(lastBuild.getRootDir(), RobotPublisher.DEFAULT_ARCHIVE_DIR + "/output-001.xml"); + File storedDummy = new File(lastBuild.getRootDir(), RobotPublisher.DEFAULT_ARCHIVE_DIR + "/dummy.file"); + + assertTrue(storedOutput.exists(), "output.xml was not stored"); + assertTrue(storedSplitOutput.exists(), "output-001.xml was not stored"); + assertFalse(storedDummy.exists(), "dummy.file was copied"); + } + + @LocalData + @Test + void testActionViewsWithNoRuns() throws Exception { + WebClient wc = j.createWebClient(); + HtmlPage page = wc.goTo("job/robot/"); + + assertElementPresentByXPath(page, "//div[@id='tasks']//a[@href='/jenkins/job/robot/robot']"); + assertElementPresentByXPath(page, + "//div[@id='main-panel']//p[contains(.,'No results available yet.')]"); + assertElementNotPresentByXPath(page, "//div[@id='main-panel']//img[@id='passfailgraph']"); + + page = wc.goTo("job/robot/robot/"); + assertTextPresent(page, "No robot results available yet!"); + } + + @LocalData + @Test + void testOldActionViewsWithData() throws Exception { + WebClient wc = j.createWebClient(); + HtmlPage page = wc.goTo("job/oldrobotbuild/"); + assertElementPresentByXPath(page, "//div[@id='tasks']//a[@href='/jenkins/job/oldrobotbuild/robot']"); + assertElementPresentByXPath(page, "//div[@id='main-panel']//h4[contains(.,'Latest Robot Results:')]"); + assertElementPresentByXPath(page, "//div[@id='main-panel']//img[@id='passfailgraph']"); + assertElementPresentByXPath(page, + "//div[@id='main-panel']//a[@href='/jenkins/job/oldrobotbuild/1/robot' and contains(text(),'Browse results')]"); + verifyTotalsTable(page, 8, 4, 0, "50.0"); + + page = wc.goTo("job/oldrobotbuild/robot/"); + assertTitleEquals(page, "Testcases & Othercases Test Report"); + + page = wc.goTo("job/oldrobotbuild/1/"); + assertElementPresentByXPath(page, + "//div[@id='tasks']//a[@href='/jenkins/job/oldrobotbuild/1/robot']"); + assertElementPresentByXPath(page, "//div[@id='main-panel']//h4[contains(.,'Robot Test Summary:')]"); + assertElementPresentByXPath(page, + "//div[@id='main-panel']//a[@href='/jenkins/job/oldrobotbuild/1/robot' and contains(text(),'Browse results')]"); + verifyTotalsTable(page, 8, 4, 0, "50.0"); + + page = wc.goTo("job/oldrobotbuild/1/robot/"); + assertTitleEquals(page, "Testcases & Othercases Test Report"); + } + + @LocalData + @Test + void testSummariesWithData() throws Exception { + WebClient wc = executeJobAndGetWebClient("robot"); + + HtmlPage page = wc.goTo("job/robot/"); + assertElementPresentByXPath(page, "//div[@id='tasks']//a[@href='/jenkins/job/robot/robot']"); + assertElementPresentByXPath(page, "//div[@id='main-panel']//h4[contains(.,'Latest Robot Results:')]"); + assertElementPresentByXPath(page, "//div[@id='main-panel']//img[@id='passfailgraph']"); + assertElementPresentByXPath(page, + "//div[@id='main-panel']//a[@href='/jenkins/job/robot/1/robot' and contains(text(),'Browse results')]"); + assertElementPresentByXPath(page, + "//div[@id='main-panel']//a[@href='/jenkins/job/robot/1/robot/report/report.html' and contains(text(), 'Open report.html')]"); + assertElementPresentByXPath(page, + "//div[@id='main-panel']//a[@href='/jenkins/job/robot/1/robot/report/log.html' and contains(text(), 'Open log.html')]"); + verifyTotalsTable(page, 8, 4, 0, "50.0"); + + page = wc.goTo("job/robot/1/"); + assertElementPresentByXPath(page, "//div[@id='tasks']//a[@href='/jenkins/job/robot/1/robot']"); + assertElementPresentByXPath(page, "//div[@id='main-panel']//h4[contains(.,'Robot Test Summary:')]"); + assertElementPresentByXPath(page, + "//div[@id='main-panel']//a[@href='/jenkins/job/robot/1/robot' and contains(text(),'Browse results')]"); + assertElementPresentByXPath(page, + "//div[@id='main-panel']//a[@href='/jenkins/job/robot/1/robot/report/report.html' and contains(text(), 'Open report.html')]"); + assertElementPresentByXPath(page, + "//div[@id='main-panel']//a[@href='/jenkins/job/robot/1/robot/report/log.html' and contains(text(), 'Open log.html')]"); + verifyTotalsTable(page, 8, 4, 0, "50.0"); + } + + @LocalData + @Test + void testSummariesWithVariablesInFileNames() throws Exception { + WebClient wc = executeJobAndGetWebClient("files-with-env-vars"); + + HtmlPage page = wc.goTo("job/files-with-env-vars/"); + assertElementPresentByXPath(page, "//div[@id='tasks']//a[@href='/jenkins/job/files-with-env-vars/robot']"); + assertElementPresentByXPath(page, "//div[@id='main-panel']//h4[contains(.,'Latest Robot Results:')]"); + assertElementPresentByXPath(page, "//div[@id='main-panel']//img[@id='passfailgraph']"); + assertElementPresentByXPath(page, + "//div[@id='main-panel']//a[@href='/jenkins/job/files-with-env-vars/1/robot' and contains(text(),'Browse results')]"); + assertElementPresentByXPath(page, + "//div[@id='main-panel']//a[@href='/jenkins/job/files-with-env-vars/1/robot/report/report_1.html' and contains(text(), 'Open report_1.html')]"); + assertElementPresentByXPath(page, + "//div[@id='main-panel']//a[@href='/jenkins/job/files-with-env-vars/1/robot/report/log_1.html' and contains(text(), 'Open log_1.html')]"); + verifyTotalsTable(page, 6, 1, 0, "83.3"); + + page = wc.goTo("job/files-with-env-vars/1/"); + assertElementPresentByXPath(page, "//div[@id='tasks']//a[@href='/jenkins/job/files-with-env-vars/1/robot']"); + assertElementPresentByXPath(page, "//div[@id='main-panel']//h4[contains(.,'Robot Test Summary:')]"); + assertElementPresentByXPath(page, + "//div[@id='main-panel']//a[@href='/jenkins/job/files-with-env-vars/1/robot' and contains(text(),'Browse results')]"); + assertElementPresentByXPath(page, + "//div[@id='main-panel']//a[@href='/jenkins/job/files-with-env-vars/1/robot/report/report_1.html' and contains(text(), 'Open report_1.html')]"); + assertElementPresentByXPath(page, + "//div[@id='main-panel']//a[@href='/jenkins/job/files-with-env-vars/1/robot/report/log_1.html' and contains(text(), 'Open log_1.html')]"); + verifyTotalsTable(page, 6, 1, 0, "83.3"); + } + + @LocalData + @Test + void testRobot29Outputs() throws Exception { + WebClient wc = executeJobAndGetWebClient("robot29output"); + HtmlPage page = wc.goTo("job/robot29output/"); + verifyTotalsTable(page, 1, 0, 0, "100.0"); + } + + @LocalData + @Test + void testCombinedOutputs() throws Exception { + WebClient wc = executeJobAndGetWebClient("several-outputs"); + + HtmlPage page = wc.goTo("job/several-outputs/"); + assertElementPresentByXPath(page, + "//div[@id='tasks']//a[@href='/jenkins/job/several-outputs/robot']"); + assertElementPresentByXPath(page, "//div[@id='main-panel']//h4[contains(.,'Latest Robot Results:')]"); + assertElementPresentByXPath(page, "//div[@id='main-panel']//img[@id='passfailgraph']"); + assertElementPresentByXPath(page, + "//div[@id='main-panel']//a[@href='/jenkins/job/several-outputs/1/robot' and contains(text(),'Browse results')]"); + assertElementPresentByXPath(page, + "//div[@id='main-panel']//a[@href='/jenkins/job/several-outputs/1/robot/report/**/report.html' and contains(text(), 'Open **/report.html')]"); + assertElementPresentByXPath(page, + "//div[@id='main-panel']//a[@href='/jenkins/job/several-outputs/1/robot/report/**/log.html' and contains(text(), 'Open **/log.html')]"); + verifyTotalsTable(page, 2, 0, 0, "100.0"); + } + + @LocalData + @Test + void testReportPage() throws Exception { + WebClient wc = executeJobAndGetWebClient("robot"); + + HtmlPage page = wc.goTo("job/robot/robot/"); + assertTextPresent(page, "Robot Framework Test Results"); + assertTextPresent(page, "4 passed, 4 failed"); + assertTextPresent(page, "0:00:00.041 (+0:00:00.041)"); + assertElementPresentByXPath(page, + "//div[@id='main-panel']//a[@href='Testcases%20&%20Othercases/Testcases/Not%20equal' and contains(.,'Testcases & Othercases.Testcases.Not equal')]"); + assertElementPresentByXPath(page, + "//div[@id='main-panel']//a[@href='Testcases%20&%20Othercases/Othercases' and contains(.,'Testcases & Othercases.Othercases')]"); + + page = wc.goTo("job/robot/1/robot/report/"); + assertElementPresentByXPath(page, + "//div[@id='main-panel']//a[@href='output.xml' and contains(.,'output.xml')]"); + + page = wc.goTo("job/robot/1/robot/Testcases%20&%20Othercases"); + assertTextPresent(page, "4 passed, 4 failed"); + assertTextPresent(page, "0:00:00.041 (+0:00:00.041)"); + assertTextPresent(page, "Failed Test Cases"); + assertElementPresentByXPath(page, + "//div[@id='main-panel']//a[@href='Testcases/Not%20equal' and contains(.,'Testcases.Not equal')]"); + assertElementPresentByXPath(page, + "//div[@id='main-panel']//a[@href='Othercases' and contains(.,'Othercases')]"); + + page = wc.goTo("job/robot/1/robot/Testcases%20&%20Othercases/Othercases"); + assertTextPresent(page, "2 passed, 2 failed"); + assertTextPresent(page, "0:00:00.008 (+0:00:00.008)"); + assertTextPresent(page, "Test Cases"); + assertElementPresentByXPath(page, + "//div[@id='main-panel']//a[@href='Not%20equal' and contains(.,'Not equal')]"); + assertElementPresentByXPath(page, + "//div[@id='main-panel']//a[@href='Contains%20string' and contains(.,'Contains string')]"); + + page = wc.goTo("job/robot/1/robot/Testcases%20&%20Othercases/Othercases/Not%20equal"); + assertTextPresent(page, "Not equal"); + assertTextPresent(page, "FAIL"); + assertTextPresent(page, "Message:"); + assertTextPresent(page, "Hello, world! != Good bye, world!"); + assertTextPresent(page, "0:00:00.001 (+0:00:00.001)"); + assertElementPresentByXPath(page, + "//div[@id='main-panel']//img[@src='durationGraph?maxBuildsToShow=0']"); + + page = wc.goTo("job/robot/1/robot/Testcases%20&%20Othercases/Othercases/Contains%20string"); + assertTextPresent(page, "PASS"); + assertTextNotPresent(page, "Message:"); + } + + @LocalData + @Test + void testMissingReportFileWithOld() throws Exception { + Project testProject = getProject("oldrobotbuild"); + + WebClient wc = j.createWebClient(); + + File buildRoot = testProject.getLastBuild().getRootDir(); + File robotHtmlReport = new File(buildRoot, RobotPublisher.DEFAULT_ARCHIVE_DIR + "/report.html"); + + assertTrue(robotHtmlReport.delete(), "Unable to delete report directory"); + + HtmlPage page = wc.goTo("job/oldrobotbuild/robot/"); + assertTextPresent(page, "No Robot html report found!"); + + page = wc.goTo("job/oldrobotbuild/1/robot/"); + assertTextPresent(page, "No Robot html report found!"); + } + + @LocalData + @Test + void testFailedSince() { + Jenkins jenkins = j.getInstance(); + List projects = jenkins.getAllItems(Project.class); + Run lastRun = null; + for (Project project : projects) { + if (project.getName().equalsIgnoreCase("failingtests")) { + lastRun = project.getLastCompletedBuild(); + } + } + + assertNotNull(lastRun, "No build including Robot results was found"); + + RobotBuildAction action = lastRun.getAction(RobotBuildAction.class); + RobotResult result = action.getResult(); + RobotCaseResult firstFailed = result.getAllFailedCases().get(0); + assertEquals(2, firstFailed.getFailedSince()); + } + + @LocalData + @Test + void testMatrixBuildReportLinks() throws Exception { + WebClient wc = j.createWebClient(); + HtmlPage page = wc.goTo("job/matrix-robot/FOO=bar/2"); + assertElementPresentByXPath(page, + "//div[@id='main-panel']//a[@href='/jenkins/job/matrix-robot/FOO=bar/2/robot' and contains(.,'Browse results')]"); + assertElementPresentByXPath(page, + "//div[@id='main-panel']//a[@href='/jenkins/job/matrix-robot/FOO=bar/2/robot/report/report.html' and contains(.,'Open report.html')]"); + } + + @LocalData + @Test + void testMatrixBuildSummary() throws Exception { + Jenkins jenkins = j.getInstance(); + List projects = jenkins.getAllItems(MatrixProject.class); + MatrixProject testProject = null; + for (MatrixProject project : projects) { + System.out.println(project.getName()); + if (project.getName().equals("matrix-robot")) { + testProject = project; + } + } + + assertNotNull(testProject, "Couldn't find example project"); + + j.assertBuildStatusSuccess(testProject.scheduleBuild2(0)); + WebClient wc = j.createWebClient(); + HtmlPage page = wc.goTo("job/matrix-robot"); + assertElementPresentByXPath(page, "//div[@id='tasks']//a[@href='/jenkins/job/matrix-robot/robot']"); + assertElementPresentByXPath(page, "//div[@id='main-panel']//img[@id='passfailgraph']"); + + page = wc.goTo("job/matrix-robot/3"); + assertElementPresentByXPath(page, + "//div[@id='main-panel']//a[@href='/jenkins/job/matrix-robot/3/robot']"); + assertElementPresentByXPath(page, "//div[@id='main-panel']//h4[contains(.,'Robot Test Summary:')]"); + assertElementPresentByXPath(page, + "//div[@id='main-panel']//a[@href='/jenkins/job/matrix-robot/3/robot' and contains(text(),'Browse results')]"); + } + + @Test + void testRobotPipelineStep() throws Exception { WorkflowJob pipelineJob = j.jenkins.createProject(WorkflowJob.class, "pipelineJob"); // Replace because of Windows path escapes in pipeline config String outputPath = new File("src/test/resources/hudson/plugins/robot").getAbsolutePath().replace("\\", "\\\\"); String outputFileName = "low_failure_output.xml"; - pipelineJob.setDefinition(new CpsFlowDefinition("node {robot outputFileName: '"+outputFileName+"', outputPath: '"+outputPath+"'}", true)); + pipelineJob.setDefinition(new CpsFlowDefinition("node {robot outputFileName: '" + outputFileName + "', outputPath: '" + outputPath + "'}", true)); j.assertLogContains("Done publishing Robot results.", j.assertBuildStatusSuccess(pipelineJob.scheduleBuild2(0))); } - - private WebClient executeJobAndGetWebClient(String projectName) throws Exception { - this.executeJobWithSuccess(projectName); - return j.createWebClient(); - } - - private AbstractBuild executeJobWithSuccess(String projectName) throws Exception { - return this.executeJob(projectName, true); - } - - private AbstractBuild executeJob(String projectName, boolean success) throws Exception { - Jenkins jenkins = j.getInstance(); - List projects = jenkins.getAllItems(Project.class); - Project testProject = null; - for (Project project : projects) { - if (project.getName().equals(projectName)) - testProject = project; - } - if (testProject == null) - fail("Couldn't find example project"); - if (success) { - j.assertBuildStatusSuccess(testProject.scheduleBuild2(0)); - } else { - j.assertBuildStatus(Result.FAILURE, testProject.scheduleBuild2(0)); - } - return testProject.getLastBuild(); - } - - private Project getProject(String projectName) { - Jenkins jenkins = j.getInstance(); - List projects = jenkins.getAllItems(Project.class); - Project testProject = null; - for (Project project : projects) { - if (project.getName().equals(projectName)) - testProject = project; - } - if (testProject == null) - fail("Couldn't find example project"); - return testProject; - } - - private void verifyTotalsTable(HtmlPage page, int totalTests, int totalFailed, int totalSkipped, String totalPercents) { - HtmlTable table = page.getHtmlElementById("robot-summary-table"); - String expectedTable = "TotalFailedPassedSkippedPass%" - + "Alltests" + totalTests + "" - + "" + totalFailed + "" - + "" + (totalTests - totalFailed) + "" - + "" + totalSkipped + "" - + "" + totalPercents + ""; - assertTrue(table.asXml().replaceAll("\\s", "").contains(expectedTable)); - } + + private WebClient executeJobAndGetWebClient(String projectName) throws Exception { + executeJobWithSuccess(projectName); + return j.createWebClient(); + } + + private AbstractBuild executeJobWithSuccess(String projectName) throws Exception { + return executeJob(projectName, true); + } + + private AbstractBuild executeJob(String projectName, boolean success) throws Exception { + Jenkins jenkins = j.getInstance(); + List projects = jenkins.getAllItems(Project.class); + Project testProject = null; + for (Project project : projects) { + if (project.getName().equals(projectName)) { + testProject = project; + } + } + + assertNotNull(testProject, "Couldn't find example project"); + + if (success) { + j.assertBuildStatusSuccess(testProject.scheduleBuild2(0)); + } else { + j.assertBuildStatus(Result.FAILURE, testProject.scheduleBuild2(0)); + } + return testProject.getLastBuild(); + } + + private Project getProject(String projectName) { + Jenkins jenkins = j.getInstance(); + List projects = jenkins.getAllItems(Project.class); + Project testProject = null; + for (Project project : projects) { + if (project.getName().equals(projectName)) { + testProject = project; + } + } + + assertNotNull(testProject, "Couldn't find example project"); + + return testProject; + } + + private void verifyTotalsTable(HtmlPage page, int totalTests, int totalFailed, int totalSkipped, String totalPercents) { + HtmlTable table = page.getHtmlElementById("robot-summary-table"); + String expectedTable = "TotalFailedPassedSkippedPass%" + + "Alltests" + totalTests + "" + + "" + totalFailed + "" + + "" + (totalTests - totalFailed) + "" + + "" + totalSkipped + "" + + "" + totalPercents + ""; + assertTrue(table.asXml().replaceAll("\\s", "").contains(expectedTable)); + } } diff --git a/src/test/java/hudson/plugins/robot/RobotPublisherTest.java b/src/test/java/hudson/plugins/robot/RobotPublisherTest.java index 1e22fa5..4fd9bdc 100644 --- a/src/test/java/hudson/plugins/robot/RobotPublisherTest.java +++ b/src/test/java/hudson/plugins/robot/RobotPublisherTest.java @@ -1,145 +1,141 @@ /* -* Copyright 2008-2014 Nokia Solutions and Networks Oy -* -* 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. -*/ + * Copyright 2008-2014 Nokia Solutions and Networks Oy + * + * 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 hudson.plugins.robot; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; -import java.io.File; -import java.io.IOException; -import java.net.URISyntaxException; - import com.ctc.wstx.exc.WstxLazyException; +import hudson.model.AbstractBuild; import hudson.model.FreeStyleBuild; import hudson.model.Result; -import hudson.model.AbstractBuild; import hudson.plugins.robot.model.RobotResult; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -public class RobotPublisherTest { - private final boolean countSkipped = false; +import org.junit.jupiter.api.Test; + +import java.io.File; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +class RobotPublisherTest { + private final boolean countSkipped = false; + + @Test + void testBlankConfigShouldReturnDefaults() { + RobotPublisher testable = getRobotPublisher(0, 0); + + assertEquals("output.xml", testable.getOutputFileName()); + assertEquals("report.html", testable.getReportFileName()); + assertEquals("log.html", testable.getLogFileName()); + } + + @Test + void testShouldReturnSuccessWhenThresholdsExceeded() { + RobotPublisher publisher = getRobotPublisher(99.9, 99); + RobotResult mockResult = mock(RobotResult.class); + AbstractBuild mockBuild = mock(FreeStyleBuild.class); + + when(mockBuild.getResult()).thenReturn(Result.SUCCESS); + when(mockResult.getPassPercentage(countSkipped)).thenReturn(100.0); + + assertEquals(Result.SUCCESS, publisher.getBuildResult(mockBuild, mockResult)); + } + + @Test + void testShouldFailWhenFailedBuild() { + RobotPublisher publisher = getRobotPublisher(0, 0); + RobotResult mockResult = mock(RobotResult.class); + AbstractBuild mockBuild = mock(FreeStyleBuild.class); + + when(mockBuild.getResult()).thenReturn(Result.FAILURE); + when(mockResult.getPassPercentage(countSkipped)).thenReturn(100.0); + + assertEquals(Result.FAILURE, publisher.getBuildResult(mockBuild, mockResult)); + } + + @Test + void testShouldFailWhenUnstableThresholdNotExceeded() { + RobotPublisher publisher = getRobotPublisher(90, 50); + RobotResult mockResult = mock(RobotResult.class); + AbstractBuild mockBuild = mock(FreeStyleBuild.class); + + when(mockBuild.getResult()).thenReturn(Result.SUCCESS); + when(mockResult.getPassPercentage(countSkipped)).thenReturn(49.9); + + assertEquals(Result.FAILURE, publisher.getBuildResult(mockBuild, mockResult)); + } + + @Test + void testShouldBeUnstableWhenPassThresholdNotExceeded() { + RobotPublisher publisher = getRobotPublisher(90, 50); + RobotResult mockResult = mock(RobotResult.class); + AbstractBuild mockBuild = mock(FreeStyleBuild.class); + + when(mockBuild.getResult()).thenReturn(Result.SUCCESS); + when(mockResult.getPassPercentage(countSkipped)).thenReturn(89.9); + + assertEquals(Result.UNSTABLE, publisher.getBuildResult(mockBuild, mockResult)); + } + + @Test + void testShouldBeSuccessWithOnlyCritical() { + RobotPublisher publisher = getRobotPublisher(90, 50); + RobotResult mockResult = mock(RobotResult.class); + AbstractBuild mockBuild = mock(FreeStyleBuild.class); + + when(mockBuild.getResult()).thenReturn(Result.SUCCESS); + when(mockResult.getPassPercentage(countSkipped)).thenReturn(90.0); + + assertEquals(Result.SUCCESS, publisher.getBuildResult(mockBuild, mockResult)); + } + + @Test + void testShouldUnstableLowFailures() throws Exception { + RobotParser.RobotParserCallable remoteOperation = new RobotParser.RobotParserCallable("low_failure_output.xml", null, null); + RobotResult result = remoteOperation.invoke(new File(RobotPublisherTest.class.getResource("low_failure_output.xml").toURI()).getParentFile(), null); + result.tally(null); + + assertEquals(1, result.getOverallFailed()); + assertEquals(2001, result.getOverallTotal()); + + RobotPublisher publisher = getRobotPublisher(100, 0); + AbstractBuild mockBuild = mock(FreeStyleBuild.class); + + when(mockBuild.getResult()).thenReturn(Result.SUCCESS); + + assertEquals(Result.UNSTABLE, publisher.getBuildResult(mockBuild, result)); + } + + @Test + void testShouldHandleDurationWithoutTimes() throws Exception { + RobotParser.RobotParserCallable remoteOperation = new RobotParser.RobotParserCallable("rebot_output.xml", null, null); + RobotResult result = remoteOperation.invoke(new File(RobotPublisherTest.class.getResource("rebot_output.xml").toURI()).getParentFile(), null); + result.tally(null); - @Before - public void setUp() throws Exception { - } + assertEquals(151, result.getDuration()); + } - private RobotPublisher getRobotPublisher(double passThreshold, double unstableThreshold) { - return new RobotPublisher(null, "", "", false, "", "", passThreshold, unstableThreshold, countSkipped, "", false, ""); - } - - @Test - public void testBlankConfigShouldReturnDefaults() { - RobotPublisher testable = getRobotPublisher(0, 0); - - Assert.assertEquals("output.xml", testable.getOutputFileName()); - Assert.assertEquals("report.html", testable.getReportFileName()); - Assert.assertEquals("log.html", testable.getLogFileName()); - } - - @Test - public void testShouldReturnSuccessWhenThresholdsExceeded() throws Exception { - RobotPublisher publisher = getRobotPublisher(99.9, 99); - RobotResult mockResult = mock(RobotResult.class); - AbstractBuild mockBuild = mock(FreeStyleBuild.class); - - when(mockBuild.getResult()).thenReturn(Result.SUCCESS); - when(mockResult.getPassPercentage(countSkipped)).thenReturn(100.0); - - Assert.assertEquals(Result.SUCCESS, publisher.getBuildResult(mockBuild, mockResult)); - } - - @Test - public void testShouldFailWhenFailedBuild() throws Exception{ - RobotPublisher publisher = getRobotPublisher(0, 0); - RobotResult mockResult = mock(RobotResult.class); - AbstractBuild mockBuild = mock(FreeStyleBuild.class); - - when(mockBuild.getResult()).thenReturn(Result.FAILURE); - when(mockResult.getPassPercentage(countSkipped)).thenReturn(100.0); - - Assert.assertEquals(Result.FAILURE, publisher.getBuildResult(mockBuild, mockResult)); - } - - @Test - public void testShouldFailWhenUnstableThresholdNotExceeded(){ - RobotPublisher publisher = getRobotPublisher(90, 50); - RobotResult mockResult = mock(RobotResult.class); - AbstractBuild mockBuild = mock(FreeStyleBuild.class); - - when(mockBuild.getResult()).thenReturn(Result.SUCCESS); - when(mockResult.getPassPercentage(countSkipped)).thenReturn(49.9); - - Assert.assertEquals(Result.FAILURE, publisher.getBuildResult(mockBuild, mockResult)); - } - - @Test - public void testShouldBeUnstableWhenPassThresholdNotExceeded(){ - RobotPublisher publisher = getRobotPublisher(90, 50); - RobotResult mockResult = mock(RobotResult.class); - AbstractBuild mockBuild = mock(FreeStyleBuild.class); - - when(mockBuild.getResult()).thenReturn(Result.SUCCESS); - when(mockResult.getPassPercentage(countSkipped)).thenReturn(89.9); - - Assert.assertEquals(Result.UNSTABLE, publisher.getBuildResult(mockBuild, mockResult)); - } - - @Test - public void testShouldBeSuccessWithOnlyCritical(){ - RobotPublisher publisher = getRobotPublisher(90, 50); - RobotResult mockResult = mock(RobotResult.class); - AbstractBuild mockBuild = mock(FreeStyleBuild.class); - - when(mockBuild.getResult()).thenReturn(Result.SUCCESS); - when(mockResult.getPassPercentage(countSkipped)).thenReturn(90.0); - - Assert.assertEquals(Result.SUCCESS, publisher.getBuildResult(mockBuild, mockResult)); - } - - @Test - public void testShouldUnstableLowFailures() throws Exception{ - RobotParser.RobotParserCallable remoteOperation = new RobotParser.RobotParserCallable("low_failure_output.xml", null, null); - RobotResult result = remoteOperation.invoke(new File(RobotPublisherTest.class.getResource("low_failure_output.xml").toURI()).getParentFile(), null); - result.tally(null); - - Assert.assertEquals(1, result.getOverallFailed()); - Assert.assertEquals(2001, result.getOverallTotal()); - - RobotPublisher publisher = getRobotPublisher(100, 0); - AbstractBuild mockBuild = mock(FreeStyleBuild.class); - - when(mockBuild.getResult()).thenReturn(Result.SUCCESS); - - Assert.assertEquals(Result.UNSTABLE, publisher.getBuildResult(mockBuild, result)); - } - - @Test - public void testShouldHandleDurationWithoutTimes() throws Exception { - RobotParser.RobotParserCallable remoteOperation = new RobotParser.RobotParserCallable("rebot_output.xml", null, null); - RobotResult result = remoteOperation.invoke(new File(RobotPublisherTest.class.getResource("rebot_output.xml").toURI()).getParentFile(), null); - result.tally(null); - - Assert.assertEquals(151, result.getDuration()); - } - - @Test(expected = WstxLazyException.class) - public void testOutputFileWithXXEShouldThrowException() throws URISyntaxException, IOException { - RobotParser.RobotParserCallable remoteOperation = new RobotParser.RobotParserCallable("xxe_output.xml", null, null); - RobotResult result = remoteOperation.invoke(new File(RobotPublisherTest.class.getResource("xxe_output.xml").toURI()).getParentFile(), null); - } + @Test + void testOutputFileWithXXEShouldThrowException() { + RobotParser.RobotParserCallable remoteOperation = new RobotParser.RobotParserCallable("xxe_output.xml", null, null); + assertThrows(WstxLazyException.class, () -> + remoteOperation.invoke(new File(RobotPublisherTest.class.getResource("xxe_output.xml").toURI()).getParentFile(), null)); + } + + private RobotPublisher getRobotPublisher(double passThreshold, double unstableThreshold) { + return new RobotPublisher(null, "", "", false, "", "", passThreshold, unstableThreshold, countSkipped, "", false, ""); + } } diff --git a/src/test/java/hudson/plugins/robot/SilentIncorrectnessListener.java b/src/test/java/hudson/plugins/robot/SilentIncorrectnessListener.java index cb67d2a..9e96dea 100644 --- a/src/test/java/hudson/plugins/robot/SilentIncorrectnessListener.java +++ b/src/test/java/hudson/plugins/robot/SilentIncorrectnessListener.java @@ -6,9 +6,9 @@ * get rid of verbose warnings in system tests */ public class SilentIncorrectnessListener implements IncorrectnessListener { - + public void notify(String message, Object origin) { // do nothing. } - + } diff --git a/src/test/java/hudson/plugins/robot/blueocean/BlueRobotTestResultForRobot4Test.java b/src/test/java/hudson/plugins/robot/blueocean/BlueRobotTestResultForRobot4Test.java index cd9990e..891ae2a 100644 --- a/src/test/java/hudson/plugins/robot/blueocean/BlueRobotTestResultForRobot4Test.java +++ b/src/test/java/hudson/plugins/robot/blueocean/BlueRobotTestResultForRobot4Test.java @@ -1,6 +1,5 @@ package hudson.plugins.robot.blueocean; -import static org.junit.Assert.assertEquals; import hudson.model.FreeStyleBuild; import hudson.plugins.robot.RobotBuildAction; import hudson.plugins.robot.RobotParser; @@ -9,24 +8,26 @@ import io.jenkins.blueocean.rest.factory.BlueTestResultFactory.Result; import io.jenkins.blueocean.rest.hal.Link; import io.jenkins.blueocean.rest.model.BlueTestResult; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.io.File; import java.util.Arrays; import java.util.stream.StreamSupport; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; -public class BlueRobotTestResultForRobot4Test { +class BlueRobotTestResultForRobot4Test { + private RobotResult result; private FreeStyleBuild mockBuild; private RobotBuildAction mockAction; private Reachable mockReachable; - @Before - public void setUp() throws Exception { + @BeforeEach + void setUp() throws Exception { RobotParser.RobotParserCallable remoteOperation = new RobotParser.RobotParserCallable("blue_skip.xml", null, null); result = remoteOperation.invoke(new File(BlueRobotTestResultTest.class.getResource("blue_skip.xml").toURI()).getParentFile(), null); result.tally(null); @@ -40,58 +41,68 @@ public void setUp() throws Exception { } @Test - public void testSimpleStacktrace(){ + void testSimpleStacktrace() { BlueTestResult result = getResult("Test 8 Will Always Fail"); assertEquals("Fail", result.getErrorStackTrace()); } @Test - public void testStacktraceWithArguments(){ + void testStacktraceWithArguments() { BlueTestResult result = getResult("Test 9 Will Always Fail"); assertEquals("Fail Optional failure message", result.getErrorStackTrace()); } @Test - public void testStacktraceIsEmpty(){ + void testStacktraceIsEmpty() { BlueTestResult result; - for(String testCase : Arrays.asList("Test 1 Will Always Pass", - "Test 2 Will Always Pass", - "Test 3 Will Always Pass", - "Test 4 Will Always Pass But Is Skipped", - "Test 5 Will Always Fail But Is Skipped", - "Test 6 Will Always Fail But Is Skipped", - "Test 7 Will Always Fail But Is Skipped", - "Test 10 Will Always Fail But Is Skipped On Failure", - "Test 11 Will Always Fail But Is Skipped On Failure", - "Test 12 Will Always Pass But Is Skipped On Failure")){ + for (String testCase : Arrays.asList("Test 1 Will Always Pass", + "Test 2 Will Always Pass", + "Test 3 Will Always Pass", + "Test 4 Will Always Pass But Is Skipped", + "Test 5 Will Always Fail But Is Skipped", + "Test 6 Will Always Fail But Is Skipped", + "Test 7 Will Always Fail But Is Skipped", + "Test 10 Will Always Fail But Is Skipped On Failure", + "Test 11 Will Always Fail But Is Skipped On Failure", + "Test 12 Will Always Pass But Is Skipped On Failure")) { result = getResult(testCase); assertEquals("", result.getErrorStackTrace()); } } @Test - public void testForLoopStackTrace() throws Exception { + void testForLoopStackTrace() { BlueTestResult result = getResult("For Loop Failure"); - String helper = "FOR IN RANGE\n Log ${x}\n Nested Keyword ${x}\n Log ${arg}\n Run Keyword If ${x}==1 Fail\n" + - " Log ${x}\n Nested Keyword ${x}\n Log ${arg}\n Run Keyword If ${x}==1 Fail\n Fail\nEND"; + String helper = """ + FOR IN RANGE + Log ${x} + Nested Keyword ${x} + Log ${arg} + Run Keyword If ${x}==1 Fail + Log ${x} + Nested Keyword ${x} + Log ${arg} + Run Keyword If ${x}==1 Fail + Fail + END"""; assertEquals(helper, result.getErrorStackTrace()); } @Test - public void testIfElseStackTrace() throws Exception { + void testIfElseStackTrace() { BlueTestResult result = getResult("If Else Failure"); String helper = "Set Variable mikki hiiri\nIF\n Fail\nELSE\n Nested Keyword ${var}\n Log ${arg}\n Fail ${var}\nEND"; assertEquals(helper, result.getErrorStackTrace()); } @Test - public void testIfFailure() throws Exception { + void testIfFailure() { BlueTestResult result = getResult("If Failure"); String helper = "Set Variable mikki hiiri\nIF\n Nested Keyword ${var}\n Log ${arg}\n Fail\nEND"; assertEquals(helper, result.getErrorStackTrace()); } - private BlueTestResult getResult(String filterCondition){ + private BlueTestResult getResult(String filterCondition) { BlueRobotTestResult.FactoryImpl factory = new BlueRobotTestResult.FactoryImpl(); Result blueResult = factory.getBlueTestResults(mockBuild, mockReachable); return StreamSupport.stream(blueResult.results.spliterator(), false) diff --git a/src/test/java/hudson/plugins/robot/blueocean/BlueRobotTestResultTest.java b/src/test/java/hudson/plugins/robot/blueocean/BlueRobotTestResultTest.java index 7ab7ddb..e43638d 100644 --- a/src/test/java/hudson/plugins/robot/blueocean/BlueRobotTestResultTest.java +++ b/src/test/java/hudson/plugins/robot/blueocean/BlueRobotTestResultTest.java @@ -1,15 +1,5 @@ package hudson.plugins.robot.blueocean; -import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.mock; - -import java.io.File; -import java.util.stream.StreamSupport; - -import org.junit.Before; -import org.junit.Test; - import hudson.model.FreeStyleBuild; import hudson.plugins.robot.RobotBuildAction; import hudson.plugins.robot.RobotParser; @@ -18,67 +8,80 @@ import io.jenkins.blueocean.rest.factory.BlueTestResultFactory.Result; import io.jenkins.blueocean.rest.hal.Link; import io.jenkins.blueocean.rest.model.BlueTestResult; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.io.File; +import java.util.stream.StreamSupport; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; -public class BlueRobotTestResultTest { +class BlueRobotTestResultTest { - private RobotResult result; - private FreeStyleBuild mockBuild; - private RobotBuildAction mockAction; - private Reachable mockReachable; + private RobotResult result; + private FreeStyleBuild mockBuild; + private RobotBuildAction mockAction; + private Reachable mockReachable; - @Before - public void setUp() throws Exception { - RobotParser.RobotParserCallable remoteOperation = new RobotParser.RobotParserCallable("output.xml", null, null); - result = remoteOperation.invoke(new File(BlueRobotTestResultTest.class.getResource("output.xml").toURI()).getParentFile(), null); - result.tally(null); + @BeforeEach + void setUp() throws Exception { + RobotParser.RobotParserCallable remoteOperation = new RobotParser.RobotParserCallable("output.xml", null, null); + result = remoteOperation.invoke(new File(BlueRobotTestResultTest.class.getResource("output.xml").toURI()).getParentFile(), null); + result.tally(null); - mockBuild = mock(FreeStyleBuild.class); - mockAction = mock(RobotBuildAction.class); - mockReachable = mock(Reachable.class); - doReturn(mockAction).when(mockBuild).getAction(RobotBuildAction.class); - doReturn(result.getAllCases()).when(mockAction).getAllTests(); - doReturn(new Link("/")).when(mockReachable).getLink(); - } + mockBuild = mock(FreeStyleBuild.class); + mockAction = mock(RobotBuildAction.class); + mockReachable = mock(Reachable.class); + doReturn(mockAction).when(mockBuild).getAction(RobotBuildAction.class); + doReturn(result.getAllCases()).when(mockAction).getAllTests(); + doReturn(new Link("/")).when(mockReachable).getLink(); + } - @Test - public void testSimpleTrace() { - BlueTestResult result = getResult("Failed Test"); - assertEquals("Fail This fails!", result.getErrorStackTrace()); - assertEquals("This fails!", result.getErrorDetails()); - } + @Test + void testSimpleTrace() { + BlueTestResult result = getResult("Failed Test"); + assertEquals("Fail This fails!", result.getErrorStackTrace()); + assertEquals("This fails!", result.getErrorDetails()); + } - @Test - public void testNestedTrace(){ - BlueTestResult result = getResult("Nested failed test"); - assertEquals("My failed Keyword\n The real failed keyword\n Fail Really fails!", result.getErrorStackTrace()); - assertEquals("Really fails!", result.getErrorDetails()); - } + @Test + void testNestedTrace() { + BlueTestResult result = getResult("Nested failed test"); + assertEquals("My failed Keyword\n The real failed keyword\n Fail Really fails!", result.getErrorStackTrace()); + assertEquals("Really fails!", result.getErrorDetails()); + } - @Test - public void testNestedNotFirst() { - BlueTestResult result = getResult("Nested with not first"); - String helper = "Should Be Equal ${MESSAGE} Hello, world!\nShould Be Equal ${MESSAGE} Hello, world!\n" + - "My failed Keyword\n The real failed keyword\n Fail Really fails!"; - assertEquals(helper, result.getErrorStackTrace()); - assertEquals("Really fails!", result.getErrorDetails()); - } + @Test + void testNestedNotFirst() { + BlueTestResult result = getResult("Nested with not first"); + String helper = """ + Should Be Equal ${MESSAGE} Hello, world! + Should Be Equal ${MESSAGE} Hello, world! + My failed Keyword + The real failed keyword + Fail Really fails!"""; + assertEquals(helper, result.getErrorStackTrace()); + assertEquals("Really fails!", result.getErrorDetails()); + } - @Test - public void testEmptyMessage(){ - BlueTestResult result1 = getResult("Another Test"); - BlueTestResult result2 = getResult("My Test"); + @Test + void testEmptyMessage() { + BlueTestResult result1 = getResult("Another Test"); + BlueTestResult result2 = getResult("My Test"); - assertEquals("", result1.getErrorStackTrace()); - assertEquals("", result1.getErrorDetails()); - assertEquals("", result2.getErrorStackTrace()); - assertEquals("", result2.getErrorDetails()); - } + assertEquals("", result1.getErrorStackTrace()); + assertEquals("", result1.getErrorDetails()); + assertEquals("", result2.getErrorStackTrace()); + assertEquals("", result2.getErrorDetails()); + } - private BlueTestResult getResult(String filterCondition){ - BlueRobotTestResult.FactoryImpl factory = new BlueRobotTestResult.FactoryImpl(); - Result blueResult = factory.getBlueTestResults(mockBuild, mockReachable); - return StreamSupport.stream(blueResult.results.spliterator(), false) - .filter(element -> element.getName().equals(filterCondition)) - .toList().get(0); - } + private BlueTestResult getResult(String filterCondition) { + BlueRobotTestResult.FactoryImpl factory = new BlueRobotTestResult.FactoryImpl(); + Result blueResult = factory.getBlueTestResults(mockBuild, mockReachable); + return StreamSupport.stream(blueResult.results.spliterator(), false) + .filter(element -> element.getName().equals(filterCondition)) + .toList().get(0); + } } diff --git a/src/test/java/hudson/plugins/robot/graph/RobotGraphHelperTest.java b/src/test/java/hudson/plugins/robot/graph/RobotGraphHelperTest.java index 1606455..852602b 100644 --- a/src/test/java/hudson/plugins/robot/graph/RobotGraphHelperTest.java +++ b/src/test/java/hudson/plugins/robot/graph/RobotGraphHelperTest.java @@ -1,118 +1,129 @@ /* -* Copyright 2008-2014 Nokia Solutions and Networks Oy -* -* 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. -*/ + * Copyright 2008-2014 Nokia Solutions and Networks Oy + * + * 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 hudson.plugins.robot.graph; import hudson.model.FreeStyleBuild; import hudson.plugins.robot.RobotParser; import hudson.plugins.robot.model.RobotResult; -import junit.framework.TestCase; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.io.File; import java.util.GregorianCalendar; -import static org.mockito.Mockito.*; - -public class RobotGraphHelperTest extends TestCase { - - private static final String xLabelFormat = "#$build"; - - private RobotResult mockResult1; - private RobotResult mockResult2; - - protected void setUp() throws Exception { - super.setUp(); - - RobotParser.RobotParserCallable remoteOperation = new RobotParser.RobotParserCallable("output.xml", null, null); - RobotResult result = remoteOperation.invoke(new File(RobotGraphHelperTest.class.getResource("output.xml").toURI()).getParentFile(), null); - result.tally(null); - - // Mocked builds to play as owners of test results - FreeStyleBuild mockBuild1 = mock(FreeStyleBuild.class); - FreeStyleBuild mockBuild2 = mock(FreeStyleBuild.class); - when(mockBuild2.compareTo(mockBuild1)).thenReturn(1); - when(mockBuild1.compareTo(mockBuild2)).thenReturn(-1); - - // This is to pass hudson.util.Graph constructor - GregorianCalendar c = new GregorianCalendar(); - c.setTimeInMillis(0L); - when(mockBuild1.getTimestamp()).thenReturn(c); - when(mockBuild2.getTimestamp()).thenReturn(c); - when(mockBuild1.getTime()).thenReturn(c.getTime()); - when(mockBuild2.getTime()).thenReturn(c.getTime()); - when(mockBuild1.getDisplayName()).thenReturn("1.2.3"); - when(mockBuild2.getDisplayName()).thenReturn("3.2.1"); - - // set up some results chains - mockResult1 = spy(result); - doReturn(null).when(mockResult1).getPreviousResult(); - doReturn(mockBuild1).when(mockResult1).getOwner(); - - mockResult2 = spy(result); - doReturn(mockResult1).when(mockResult2).getPreviousResult(); - doReturn(mockBuild2).when(mockResult2).getOwner(); - } - - public void testShouldLimitResultsGraphDataSet() throws Exception { - RobotGraph limitedResultsGraph = RobotGraphHelper.createTestResultsGraphForTestObject( - mockResult2, false, false, false, false, xLabelFormat,1); - - assertEquals(1, limitedResultsGraph.getDataset().getColumnCount()); - } - - public void testShouldReturnAllResultsGraphDataIfNotLimited() throws Exception { - RobotGraph notlimitedResultsGraph = RobotGraphHelper.createTestResultsGraphForTestObject( - mockResult2, false, false, false, false, xLabelFormat,0); - - assertEquals(2, notlimitedResultsGraph.getDataset().getColumnCount()); - } - - public void testShouldReturnAllResultsGraphDataIfLimitIsBiggerThanDataAmount() throws Exception { - RobotGraph notlimitedResultsGraph = RobotGraphHelper.createTestResultsGraphForTestObject( - mockResult2, false, false, false, false, xLabelFormat,10); - - assertEquals(2, notlimitedResultsGraph.getDataset().getColumnCount()); - } - - public void testShouldShowCustomLabel() throws Exception { - RobotGraph customLabelGraph = RobotGraphHelper.createTestResultsGraphForTestObject( - mockResult2, false, false, false, false, "$display_name",0); - - assertEquals("3.2.1", customLabelGraph.getDataset().getColumnKey(0).toString()); - assertEquals("1.2.3", customLabelGraph.getDataset().getColumnKey(1).toString()); - } - - public void testShouldLimitDurationGraphDataSet() throws Exception { - RobotGraph limitedResultsGraph = RobotGraphHelper.createDurationGraphForTestObject( - mockResult2, false, 1,xLabelFormat,false); - - assertEquals(1, limitedResultsGraph.getDataset().getColumnCount()); - } - - public void testShouldReturnAllDurationGraphDataIfNotLimited() throws Exception { - RobotGraph notlimitedResultsGraph = RobotGraphHelper.createDurationGraphForTestObject( - mockResult2, false, 0, xLabelFormat,false); - - assertEquals(2, notlimitedResultsGraph.getDataset().getColumnCount()); - } - - public void testShouldReturnAllDurationDataIfLimitIsBiggerThanDataAmount() throws Exception { - RobotGraph notlimitedResultsGraph = RobotGraphHelper.createDurationGraphForTestObject( - mockResult2, false, 10, xLabelFormat,false); - - assertEquals(2, notlimitedResultsGraph.getDataset().getColumnCount()); - } +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.when; + +class RobotGraphHelperTest { + + private static final String xLabelFormat = "#$build"; + + private RobotResult mockResult1; + private RobotResult mockResult2; + + @BeforeEach + void setUp() throws Exception { + RobotParser.RobotParserCallable remoteOperation = new RobotParser.RobotParserCallable("output.xml", null, null); + RobotResult result = remoteOperation.invoke(new File(RobotGraphHelperTest.class.getResource("output.xml").toURI()).getParentFile(), null); + result.tally(null); + + // Mocked builds to play as owners of test results + FreeStyleBuild mockBuild1 = mock(FreeStyleBuild.class); + FreeStyleBuild mockBuild2 = mock(FreeStyleBuild.class); + when(mockBuild2.compareTo(mockBuild1)).thenReturn(1); + when(mockBuild1.compareTo(mockBuild2)).thenReturn(-1); + + // This is to pass hudson.util.Graph constructor + GregorianCalendar c = new GregorianCalendar(); + c.setTimeInMillis(0L); + when(mockBuild1.getTimestamp()).thenReturn(c); + when(mockBuild2.getTimestamp()).thenReturn(c); + when(mockBuild1.getTime()).thenReturn(c.getTime()); + when(mockBuild2.getTime()).thenReturn(c.getTime()); + when(mockBuild1.getDisplayName()).thenReturn("1.2.3"); + when(mockBuild2.getDisplayName()).thenReturn("3.2.1"); + + // set up some results chains + mockResult1 = spy(result); + doReturn(null).when(mockResult1).getPreviousResult(); + doReturn(mockBuild1).when(mockResult1).getOwner(); + + mockResult2 = spy(result); + doReturn(mockResult1).when(mockResult2).getPreviousResult(); + doReturn(mockBuild2).when(mockResult2).getOwner(); + } + + @Test + void testShouldLimitResultsGraphDataSet() { + RobotGraph limitedResultsGraph = RobotGraphHelper.createTestResultsGraphForTestObject( + mockResult2, false, false, false, false, xLabelFormat, 1); + + assertEquals(1, limitedResultsGraph.getDataset().getColumnCount()); + } + + @Test + void testShouldReturnAllResultsGraphDataIfNotLimited() { + RobotGraph notlimitedResultsGraph = RobotGraphHelper.createTestResultsGraphForTestObject( + mockResult2, false, false, false, false, xLabelFormat, 0); + + assertEquals(2, notlimitedResultsGraph.getDataset().getColumnCount()); + } + + @Test + void testShouldReturnAllResultsGraphDataIfLimitIsBiggerThanDataAmount() { + RobotGraph notlimitedResultsGraph = RobotGraphHelper.createTestResultsGraphForTestObject( + mockResult2, false, false, false, false, xLabelFormat, 10); + + assertEquals(2, notlimitedResultsGraph.getDataset().getColumnCount()); + } + + @Test + void testShouldShowCustomLabel() { + RobotGraph customLabelGraph = RobotGraphHelper.createTestResultsGraphForTestObject( + mockResult2, false, false, false, false, "$display_name", 0); + + assertEquals("3.2.1", customLabelGraph.getDataset().getColumnKey(0).toString()); + assertEquals("1.2.3", customLabelGraph.getDataset().getColumnKey(1).toString()); + } + + @Test + void testShouldLimitDurationGraphDataSet() { + RobotGraph limitedResultsGraph = RobotGraphHelper.createDurationGraphForTestObject( + mockResult2, false, 1, xLabelFormat, false); + + assertEquals(1, limitedResultsGraph.getDataset().getColumnCount()); + } + + @Test + void testShouldReturnAllDurationGraphDataIfNotLimited() { + RobotGraph notlimitedResultsGraph = RobotGraphHelper.createDurationGraphForTestObject( + mockResult2, false, 0, xLabelFormat, false); + + assertEquals(2, notlimitedResultsGraph.getDataset().getColumnCount()); + } + + @Test + void testShouldReturnAllDurationDataIfLimitIsBiggerThanDataAmount() { + RobotGraph notlimitedResultsGraph = RobotGraphHelper.createDurationGraphForTestObject( + mockResult2, false, 10, xLabelFormat, false); + + assertEquals(2, notlimitedResultsGraph.getDataset().getColumnCount()); + } } diff --git a/src/test/java/hudson/plugins/robot/model/RobotResultTest.java b/src/test/java/hudson/plugins/robot/model/RobotResultTest.java index d6e806c..5f480a6 100644 --- a/src/test/java/hudson/plugins/robot/model/RobotResultTest.java +++ b/src/test/java/hudson/plugins/robot/model/RobotResultTest.java @@ -1,341 +1,341 @@ /* -* Copyright 2008-2014 Nokia Solutions and Networks Oy -* -* 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. -*/ + * Copyright 2008-2014 Nokia Solutions and Networks Oy + * + * 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 hudson.plugins.robot.model; import hudson.plugins.robot.RobotParser; +import org.apache.commons.lang.StringUtils; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.jvnet.hudson.test.Issue; import java.io.File; import java.util.List; -import hudson.plugins.robot.RobotParserTest; -import org.apache.commons.lang.StringUtils; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; - -import static org.junit.Assert.*; - - -public class RobotResultTest { - - private RobotResult result; - - @Before - public void setUp() throws Exception { - RobotParser.RobotParserCallable remoteOperation = new RobotParser.RobotParserCallable("output.xml", null, null); - result = remoteOperation.invoke(new File(RobotSuiteResultTest.class.getResource("output.xml").toURI()).getParentFile(), null); - result.tally(null); - } - - @Test - public void testShouldParseTimeStamp(){ - assertEquals("20100629 11:08:54.230", result.getTimeStamp()); - } - - @Test - public void testShouldParseSuites(){ - RobotSuiteResult suite = result.getSuite("Othercases & Testcases"); - assertNotNull(suite); - } - - @Test - public void testShouldParseSuiteDescription(){ - RobotSuiteResult suite = result.getSuite("Othercases & Testcases"); - String desc = suite.getDescription(); - assertEquals("Exampledocumentation", desc); - } - - @Test - public void testShouldParseNestedSuites(){ - RobotSuiteResult suite = result.getSuite("Othercases & Testcases"); - RobotSuiteResult nestedSuite = suite.getSuite("Testcases"); - assertNotNull(nestedSuite); - } - - @Test - public void testShouldParseCases(){ - RobotSuiteResult suite = result.getSuite("Othercases & Testcases"); - RobotCaseResult caseResult = suite.getCase("Hello"); - assertNotNull(caseResult); - } - - @Test - public void testShouldParseCaseDescription(){ - RobotSuiteResult suite = result.getSuite("Othercases & Testcases"); - RobotCaseResult caseResult = suite.getCase("Hello"); - String desc = caseResult.getDescription(); - assertEquals("Test", desc); - } - - @Test - public void testShouldParseCasesInNestedSuites(){ - RobotSuiteResult suite = result.getSuite("Othercases & Testcases"); - RobotSuiteResult nestedSuite = suite.getSuite("Testcases"); - RobotCaseResult caseResult = nestedSuite.getCase("Failer"); - assertNotNull(caseResult); - } - - @Test - public void testShouldParseMultipleSameNamedSuites(){ - assertNotNull(result.getSuite("Somecases_1")); - } - - @Test - public void testShouldParseFailMessages(){ - RobotSuiteResult suite = result.getSuite("Othercases & Testcases"); - RobotSuiteResult childSuite = suite.getSuite("Othercases"); - RobotCaseResult caseResult = childSuite.getCase("Failer"); - String errorMsg = caseResult.getErrorMsg(); - assertEquals("Test failed miserably!", errorMsg.trim()); - } - - @Test - public void testShouldParseOverallCases(){ - assertEquals(22, result.getOverallTotal()); - } - - @Test - public void testShouldParseFailedCases(){ - assertEquals(10, result.getOverallFailed()); - } - - @Test - public void testShouldAcceptNoLogAndReport() throws Exception{ - RobotParser.RobotParserCallable remoteOperation = new RobotParser.RobotParserCallable("new_critical_output.xml", null, null); - result = remoteOperation.invoke(new File(RobotSuiteResultTest.class.getResource("new_critical_output.xml").toURI()).getParentFile(), null); - result.tally(null); - - assertFalse(result.getAllFailedCases().get(0).getHasLog()); - assertFalse(result.getAllFailedCases().get(0).getHasReport()); - } - - @Test - public void testShouldGetLogWhenAvailable() throws Exception{ - RobotParser.RobotParserCallable remoteOperation = new RobotParser.RobotParserCallable("new_critical_output.xml", "log.html", "report.html"); - result = remoteOperation.invoke(new File(RobotSuiteResultTest.class.getResource("new_critical_output.xml").toURI()).getParentFile(), null); - result.tally(null); - - assertTrue(result.getAllFailedCases().get(0).getHasLog()); - } - - @Test - public void testShouldGetLogAndReportInSuites() throws Exception{ - RobotParser.RobotParserCallable remoteOperation = new RobotParser.RobotParserCallable("output.xml", "log.html", "report.html"); - result = remoteOperation.invoke(new File(RobotSuiteResultTest.class.getResource("output.xml").toURI()).getParentFile(), null); - result.tally(null); - - RobotSuiteResult suite = result.getSuite("Othercases & Testcases"); - assertTrue(suite.getHasLog()); - assertTrue(suite.getHasReport()); - } - - @Test - public void testIdShouldBeEmptyWhenNotAvailable() throws Exception{ - RobotParser.RobotParserCallable remoteOperation = new RobotParser.RobotParserCallable("new_critical_output.xml", "log.html", null); - result = remoteOperation.invoke(new File(RobotSuiteResultTest.class.getResource("new_critical_output.xml").toURI()).getParentFile(), null); - result.tally(null); - - assertEquals("", result.getAllFailedCases().get(0).getId()); - } - - @Test - public void testShouldGetIdWhenAvailable() throws Exception{ - RobotParser.RobotParserCallable remoteOperation = new RobotParser.RobotParserCallable("teardown_fail.xml", "log.html", null); - result = remoteOperation.invoke(new File(RobotSuiteResultTest.class.getResource("teardown_fail.xml").toURI()).getParentFile(), null); - result.tally(null); - RobotSuiteResult suite = result.getSuite("Fail"); - RobotSuiteResult subSuite = suite.getSuite("Suite"); - RobotCaseResult caseResult = subSuite.getCase("Example test 2"); - - assertEquals("s1-s1-t2", caseResult.getId()); - } - - @Test - public void testShouldReturnAllFailedCases(){ - List failers = result.getAllFailedCases(); - assertEquals(10, failers.size()); - } - - @Test - public void testShouldReturnPackageName(){ - RobotSuiteResult suite = (RobotSuiteResult)result.findObjectById("Othercases & Testcases/Othercases/3rd level cases"); - assertEquals("Othercases & Testcases.Othercases.3rd level cases", suite.getRelativePackageName(result)); - } - - @Test - public void testShouldReturnSuiteById(){ - RobotSuiteResult suite = (RobotSuiteResult)result.findObjectById("Othercases & Testcases/Othercases/3rd level cases"); - assertEquals("3rd level cases", suite.getName()); - } - - @Test - public void testShouldReturnIdForSuite(){ - RobotSuiteResult suite = (RobotSuiteResult)result.findObjectById("Othercases & Testcases/Othercases/3rd level cases"); - assertEquals("Othercases%20&%20Testcases/Othercases/3rd%20level%20cases", suite.getRelativeId(result)); - } - - @Test - public void testShouldURLEncodeSpecialChars(){ - RobotCaseResult caseResult = (RobotCaseResult)result.findObjectById("Othercases & Testcases/Othercases/3rd level cases/Passing Test Case With !\"#€%&()=?`´*'^<>©@£$∞§|[]≈±:;.,"); - assertEquals("Othercases%20&%20Testcases/Othercases/3rd%20level%20cases/Passing%20Test%20Case%20With%20!%22%23%E2%82%AC%25&()=%3F%60%C2%B4*'%5E%3C%3E%C2%A9@%C2%A3$%E2%88%9E%C2%A7%7C%5B%5D%E2%89%88%C2%B1%3A%3B.,", caseResult.getRelativeId(result)); - } - - @Test - public void testShouldReturnCaseById(){ - RobotCaseResult caseResult = (RobotCaseResult)result.findObjectById("Othercases & Testcases/Othercases/3rd level cases/Hello3rd"); - assertEquals("Hello3rd", caseResult.getName()); - } - - @Test - public void testShouldReturnCaseTags(){ - RobotCaseResult caseResult = (RobotCaseResult)result.findObjectById("Othercases & Testcases/Othercases/3rd level cases/Hello3rd"); - String tags = StringUtils.join(caseResult.getTags(), ","); - assertEquals("tag1,tag2", tags); - } - - @Test - public void testShouldParseSplittedOutput() throws Exception { - RobotParser.RobotParserCallable remoteOperation = new RobotParser.RobotParserCallable("testfile.xml", null, null); - result = remoteOperation.invoke(new File(RobotSuiteResultTest.class.getResource("testfile.xml").toURI()).getParentFile(), null); - - RobotSuiteResult suite = result.getSuite("nestedSuites"); - RobotSuiteResult splittedSuite = suite.getSuite("subSuite"); - RobotSuiteResult splittedNestedSuite = splittedSuite.getSuite("Testcases"); - assertNotNull(splittedNestedSuite); - } - - @Test - public void testShouldParseSuiteTeardownFailures() throws Exception { - RobotParser.RobotParserCallable remoteOperation = new RobotParser.RobotParserCallable("teardown_fail.xml", null, null); - RobotResult res = remoteOperation.invoke(new File(RobotSuiteResultTest.class.getResource("teardown_fail.xml").toURI()).getParentFile(), null); - List failers = res.getAllFailedCases(); - assertEquals(3, failers.size()); - } - - @Test - public void testShouldHandleNameCollisions() throws Exception { - RobotParser.RobotParserCallable remoteOperation = new RobotParser.RobotParserCallable("collisions.xml", null, null); - RobotResult res = remoteOperation.invoke(new File(RobotSuiteResultTest.class.getResource("collisions.xml").toURI()).getParentFile(), null); - List failers = res.getAllFailedCases(); - assertEquals(4, failers.size()); - } - - @Test - public void testShouldParseWholeSuiteDuration() throws Exception { - RobotParser.RobotParserCallable remoteOperation = new RobotParser.RobotParserCallable("suite-setup-and-teardown.xml", null, null); - RobotResult res = remoteOperation.invoke(new File(RobotSuiteResultTest.class.getResource("suite-setup-and-teardown.xml").toURI()).getParentFile(), null); - res.tally(null); - assertEquals(10141, res.getDuration()); - } - - @Test - public void testShouldParseSkippedTests() throws Exception { - RobotParser.RobotParserCallable remoteOperation = new RobotParser.RobotParserCallable("robot4_skip.xml", null, null); - result = remoteOperation.invoke(new File(RobotSuiteResultTest.class.getResource("robot4_skip.xml").toURI()).getParentFile(), null); - result.tally(null); - assertEquals(6, result.getSkipped()); - } - - @Test - public void testShouldParsePassedFromRobot4() throws Exception { - RobotParser.RobotParserCallable remoteOperation = new RobotParser.RobotParserCallable("robot4_skip.xml", null, null); - result = remoteOperation.invoke(new File(RobotSuiteResultTest.class.getResource("robot4_skip.xml").toURI()).getParentFile(), null); - result.tally(null); - assertEquals(4, result.getPassed()); - assertEquals(66.6, result.getPassPercentage(), 0.1); - } - - @Test - public void testShouldParseFailedFromRobot4() throws Exception { - RobotParser.RobotParserCallable remoteOperation = new RobotParser.RobotParserCallable("robot4_skip.xml", null, null); - result = remoteOperation.invoke(new File(RobotSuiteResultTest.class.getResource("robot4_skip.xml").toURI()).getParentFile(), null); - result.tally(null); - assertEquals(2, result.getFailed()); - } - - @Test - public void testShouldParseTotalFromRobot4() throws Exception { - RobotParser.RobotParserCallable remoteOperation = new RobotParser.RobotParserCallable("robot4_skip.xml", null, null); - result = remoteOperation.invoke(new File(RobotSuiteResultTest.class.getResource("robot4_skip.xml").toURI()).getParentFile(), null); - result.tally(null); - assertEquals(12, result.getOverallTotal()); - } - - @Test - public void testShouldParseTagsFromRobot4() throws Exception { - RobotParser.RobotParserCallable remoteOperation = new RobotParser.RobotParserCallable("robot4_skip.xml", null, null); - result = remoteOperation.invoke(new File(RobotSuiteResultTest.class.getResource("robot4_skip.xml").toURI()).getParentFile(), null); - result.tally(null); - - RobotCaseResult caseResult = (RobotCaseResult)result.findObjectById("Skip/Test 8 Will Always Fail"); - String tags = StringUtils.join(caseResult.getTags(), ","); - assertEquals("fail,tag2,tag3", tags); - } - - @Test - public void testSuiteNameAttributeMightBeMissingInRobot4() throws Exception { - /** - * see more: https://issues.jenkins.io/browse/JENKINS-69807 - **/ - RobotParser.RobotParserCallable remoteOperation = new RobotParser.RobotParserCallable("robot4_empty_suite_name.xml", null, null); - result = remoteOperation.invoke(new File(RobotSuiteResultTest.class.getResource("robot4_empty_suite_name.xml").toURI()).getParentFile(), null); - - RobotSuiteResult r = result.getSuites().iterator().next(); - r = r.getChildSuites().iterator().next(); - RobotCaseResult caseResult = r.getCaseResults().iterator().next(); - - // passing null as `thisObject` should not matter, as the name resolving fails first - // due to getName() returning `null` - caseResult.getRelativePackageName(null); - } - - @Test - public void testCaseResultsShouldBeCorrectlySet() throws Exception { - File directory = new File(RobotParserTest.class.getResource("robot7").toURI()); - RobotParser.RobotParserCallable remoteOperation = new RobotParser.RobotParserCallable("inline_var_output.xml", null, null); - result = remoteOperation.invoke(directory, null); - result.tally(null); - - RobotSuiteResult suite = result.getSuite("Rf7"); - RobotCaseResult caseResult = suite.getCase("Test Inline Var"); - - // suite results - assertEquals(35.0, suite.getDuration(), 0.01); - - // case results - assertEquals("2023-11-13T15:33:07.168330", caseResult.getStarttime()); - assertEquals(0.001748, caseResult.getElapsedtime(), 0.01); - assertNull(caseResult.getEndtime()); - } - - @Test - public void testGetPassPercentageWithoutSkippedTests() throws Exception { - RobotParser.RobotParserCallable remoteOperation = new RobotParser.RobotParserCallable("robot4_skip.xml", null, null); - result = remoteOperation.invoke(new File(RobotSuiteResultTest.class.getResource("robot4_skip.xml").toURI()).getParentFile(), null); - result.tally(null); - - assertEquals(66.6, result.getPassPercentage(false), 0); - } - - @Test - public void testGetPassPercentageWithSkippedTests() throws Exception { - RobotParser.RobotParserCallable remoteOperation = new RobotParser.RobotParserCallable("robot4_skip.xml", null, null); - result = remoteOperation.invoke(new File(RobotSuiteResultTest.class.getResource("robot4_skip.xml").toURI()).getParentFile(), null); - result.tally(null); - - assertEquals(33.3, result.getPassPercentage(true), 0); - } +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + + +class RobotResultTest { + + private RobotResult result; + + @BeforeEach + void setUp() throws Exception { + RobotParser.RobotParserCallable remoteOperation = new RobotParser.RobotParserCallable("output.xml", null, null); + result = remoteOperation.invoke(new File(RobotSuiteResultTest.class.getResource("output.xml").toURI()).getParentFile(), null); + result.tally(null); + } + + @Test + void testShouldParseTimeStamp() { + assertEquals("20100629 11:08:54.230", result.getTimeStamp()); + } + + @Test + void testShouldParseSuites() { + RobotSuiteResult suite = result.getSuite("Othercases & Testcases"); + assertNotNull(suite); + } + + @Test + void testShouldParseSuiteDescription() { + RobotSuiteResult suite = result.getSuite("Othercases & Testcases"); + String desc = suite.getDescription(); + assertEquals("Exampledocumentation", desc); + } + + @Test + void testShouldParseNestedSuites() { + RobotSuiteResult suite = result.getSuite("Othercases & Testcases"); + RobotSuiteResult nestedSuite = suite.getSuite("Testcases"); + assertNotNull(nestedSuite); + } + + @Test + void testShouldParseCases() { + RobotSuiteResult suite = result.getSuite("Othercases & Testcases"); + RobotCaseResult caseResult = suite.getCase("Hello"); + assertNotNull(caseResult); + } + + @Test + void testShouldParseCaseDescription() { + RobotSuiteResult suite = result.getSuite("Othercases & Testcases"); + RobotCaseResult caseResult = suite.getCase("Hello"); + String desc = caseResult.getDescription(); + assertEquals("Test", desc); + } + + @Test + void testShouldParseCasesInNestedSuites() { + RobotSuiteResult suite = result.getSuite("Othercases & Testcases"); + RobotSuiteResult nestedSuite = suite.getSuite("Testcases"); + RobotCaseResult caseResult = nestedSuite.getCase("Failer"); + assertNotNull(caseResult); + } + + @Test + void testShouldParseMultipleSameNamedSuites() { + assertNotNull(result.getSuite("Somecases_1")); + } + + @Test + void testShouldParseFailMessages() { + RobotSuiteResult suite = result.getSuite("Othercases & Testcases"); + RobotSuiteResult childSuite = suite.getSuite("Othercases"); + RobotCaseResult caseResult = childSuite.getCase("Failer"); + String errorMsg = caseResult.getErrorMsg(); + assertEquals("Test failed miserably!", errorMsg.trim()); + } + + @Test + void testShouldParseOverallCases() { + assertEquals(22, result.getOverallTotal()); + } + + @Test + void testShouldParseFailedCases() { + assertEquals(10, result.getOverallFailed()); + } + + @Test + void testShouldAcceptNoLogAndReport() throws Exception { + RobotParser.RobotParserCallable remoteOperation = new RobotParser.RobotParserCallable("new_critical_output.xml", null, null); + result = remoteOperation.invoke(new File(RobotSuiteResultTest.class.getResource("new_critical_output.xml").toURI()).getParentFile(), null); + result.tally(null); + + assertFalse(result.getAllFailedCases().get(0).getHasLog()); + assertFalse(result.getAllFailedCases().get(0).getHasReport()); + } + + @Test + void testShouldGetLogWhenAvailable() throws Exception { + RobotParser.RobotParserCallable remoteOperation = new RobotParser.RobotParserCallable("new_critical_output.xml", "log.html", "report.html"); + result = remoteOperation.invoke(new File(RobotSuiteResultTest.class.getResource("new_critical_output.xml").toURI()).getParentFile(), null); + result.tally(null); + + assertTrue(result.getAllFailedCases().get(0).getHasLog()); + } + + @Test + void testShouldGetLogAndReportInSuites() throws Exception { + RobotParser.RobotParserCallable remoteOperation = new RobotParser.RobotParserCallable("output.xml", "log.html", "report.html"); + result = remoteOperation.invoke(new File(RobotSuiteResultTest.class.getResource("output.xml").toURI()).getParentFile(), null); + result.tally(null); + + RobotSuiteResult suite = result.getSuite("Othercases & Testcases"); + assertTrue(suite.getHasLog()); + assertTrue(suite.getHasReport()); + } + + @Test + void testIdShouldBeEmptyWhenNotAvailable() throws Exception { + RobotParser.RobotParserCallable remoteOperation = new RobotParser.RobotParserCallable("new_critical_output.xml", "log.html", null); + result = remoteOperation.invoke(new File(RobotSuiteResultTest.class.getResource("new_critical_output.xml").toURI()).getParentFile(), null); + result.tally(null); + + assertEquals("", result.getAllFailedCases().get(0).getId()); + } + + @Test + void testShouldGetIdWhenAvailable() throws Exception { + RobotParser.RobotParserCallable remoteOperation = new RobotParser.RobotParserCallable("teardown_fail.xml", "log.html", null); + result = remoteOperation.invoke(new File(RobotSuiteResultTest.class.getResource("teardown_fail.xml").toURI()).getParentFile(), null); + result.tally(null); + RobotSuiteResult suite = result.getSuite("Fail"); + RobotSuiteResult subSuite = suite.getSuite("Suite"); + RobotCaseResult caseResult = subSuite.getCase("Example test 2"); + + assertEquals("s1-s1-t2", caseResult.getId()); + } + + @Test + void testShouldReturnAllFailedCases() { + List failers = result.getAllFailedCases(); + assertEquals(10, failers.size()); + } + + @Test + void testShouldReturnPackageName() { + RobotSuiteResult suite = (RobotSuiteResult) result.findObjectById("Othercases & Testcases/Othercases/3rd level cases"); + assertEquals("Othercases & Testcases.Othercases.3rd level cases", suite.getRelativePackageName(result)); + } + + @Test + void testShouldReturnSuiteById() { + RobotSuiteResult suite = (RobotSuiteResult) result.findObjectById("Othercases & Testcases/Othercases/3rd level cases"); + assertEquals("3rd level cases", suite.getName()); + } + + @Test + void testShouldReturnIdForSuite() { + RobotSuiteResult suite = (RobotSuiteResult) result.findObjectById("Othercases & Testcases/Othercases/3rd level cases"); + assertEquals("Othercases%20&%20Testcases/Othercases/3rd%20level%20cases", suite.getRelativeId(result)); + } + + @Test + void testShouldURLEncodeSpecialChars() { + RobotCaseResult caseResult = (RobotCaseResult) result.findObjectById("Othercases & Testcases/Othercases/3rd level cases/Passing Test Case With !\"#€%&()=?`´*'^<>©@£$∞§|[]≈±:;.,"); + assertEquals("Othercases%20&%20Testcases/Othercases/3rd%20level%20cases/Passing%20Test%20Case%20With%20!%22%23%E2%82%AC%25&()=%3F%60%C2%B4*'%5E%3C%3E%C2%A9@%C2%A3$%E2%88%9E%C2%A7%7C%5B%5D%E2%89%88%C2%B1%3A%3B.,", caseResult.getRelativeId(result)); + } + + @Test + void testShouldReturnCaseById() { + RobotCaseResult caseResult = (RobotCaseResult) result.findObjectById("Othercases & Testcases/Othercases/3rd level cases/Hello3rd"); + assertEquals("Hello3rd", caseResult.getName()); + } + + @Test + void testShouldReturnCaseTags() { + RobotCaseResult caseResult = (RobotCaseResult) result.findObjectById("Othercases & Testcases/Othercases/3rd level cases/Hello3rd"); + String tags = StringUtils.join(caseResult.getTags(), ","); + assertEquals("tag1,tag2", tags); + } + + @Test + void testShouldParseSplittedOutput() throws Exception { + RobotParser.RobotParserCallable remoteOperation = new RobotParser.RobotParserCallable("testfile.xml", null, null); + result = remoteOperation.invoke(new File(RobotSuiteResultTest.class.getResource("testfile.xml").toURI()).getParentFile(), null); + + RobotSuiteResult suite = result.getSuite("nestedSuites"); + RobotSuiteResult splittedSuite = suite.getSuite("subSuite"); + RobotSuiteResult splittedNestedSuite = splittedSuite.getSuite("Testcases"); + assertNotNull(splittedNestedSuite); + } + + @Test + void testShouldParseSuiteTeardownFailures() throws Exception { + RobotParser.RobotParserCallable remoteOperation = new RobotParser.RobotParserCallable("teardown_fail.xml", null, null); + RobotResult res = remoteOperation.invoke(new File(RobotSuiteResultTest.class.getResource("teardown_fail.xml").toURI()).getParentFile(), null); + List failers = res.getAllFailedCases(); + assertEquals(3, failers.size()); + } + + @Test + void testShouldHandleNameCollisions() throws Exception { + RobotParser.RobotParserCallable remoteOperation = new RobotParser.RobotParserCallable("collisions.xml", null, null); + RobotResult res = remoteOperation.invoke(new File(RobotSuiteResultTest.class.getResource("collisions.xml").toURI()).getParentFile(), null); + List failers = res.getAllFailedCases(); + assertEquals(4, failers.size()); + } + + @Test + void testShouldParseWholeSuiteDuration() throws Exception { + RobotParser.RobotParserCallable remoteOperation = new RobotParser.RobotParserCallable("suite-setup-and-teardown.xml", null, null); + RobotResult res = remoteOperation.invoke(new File(RobotSuiteResultTest.class.getResource("suite-setup-and-teardown.xml").toURI()).getParentFile(), null); + res.tally(null); + assertEquals(10141, res.getDuration()); + } + + @Test + void testShouldParseSkippedTests() throws Exception { + RobotParser.RobotParserCallable remoteOperation = new RobotParser.RobotParserCallable("robot4_skip.xml", null, null); + result = remoteOperation.invoke(new File(RobotSuiteResultTest.class.getResource("robot4_skip.xml").toURI()).getParentFile(), null); + result.tally(null); + assertEquals(6, result.getSkipped()); + } + + @Test + void testShouldParsePassedFromRobot4() throws Exception { + RobotParser.RobotParserCallable remoteOperation = new RobotParser.RobotParserCallable("robot4_skip.xml", null, null); + result = remoteOperation.invoke(new File(RobotSuiteResultTest.class.getResource("robot4_skip.xml").toURI()).getParentFile(), null); + result.tally(null); + assertEquals(4, result.getPassed()); + assertEquals(66.6, result.getPassPercentage(), 0.1); + } + + @Test + void testShouldParseFailedFromRobot4() throws Exception { + RobotParser.RobotParserCallable remoteOperation = new RobotParser.RobotParserCallable("robot4_skip.xml", null, null); + result = remoteOperation.invoke(new File(RobotSuiteResultTest.class.getResource("robot4_skip.xml").toURI()).getParentFile(), null); + result.tally(null); + assertEquals(2, result.getFailed()); + } + + @Test + void testShouldParseTotalFromRobot4() throws Exception { + RobotParser.RobotParserCallable remoteOperation = new RobotParser.RobotParserCallable("robot4_skip.xml", null, null); + result = remoteOperation.invoke(new File(RobotSuiteResultTest.class.getResource("robot4_skip.xml").toURI()).getParentFile(), null); + result.tally(null); + assertEquals(12, result.getOverallTotal()); + } + + @Test + void testShouldParseTagsFromRobot4() throws Exception { + RobotParser.RobotParserCallable remoteOperation = new RobotParser.RobotParserCallable("robot4_skip.xml", null, null); + result = remoteOperation.invoke(new File(RobotSuiteResultTest.class.getResource("robot4_skip.xml").toURI()).getParentFile(), null); + result.tally(null); + + RobotCaseResult caseResult = (RobotCaseResult) result.findObjectById("Skip/Test 8 Will Always Fail"); + String tags = StringUtils.join(caseResult.getTags(), ","); + assertEquals("fail,tag2,tag3", tags); + } + + @Test + @Issue("JENKINS-69807") + void testSuiteNameAttributeMightBeMissingInRobot4() throws Exception { + RobotParser.RobotParserCallable remoteOperation = new RobotParser.RobotParserCallable("robot4_empty_suite_name.xml", null, null); + result = remoteOperation.invoke(new File(RobotSuiteResultTest.class.getResource("robot4_empty_suite_name.xml").toURI()).getParentFile(), null); + + RobotSuiteResult r = result.getSuites().iterator().next(); + r = r.getChildSuites().iterator().next(); + RobotCaseResult caseResult = r.getCaseResults().iterator().next(); + + // passing null as `thisObject` should not matter, as the name resolving fails first + // due to getName() returning `null` + caseResult.getRelativePackageName(null); + } + + @Test + void testCaseResultsShouldBeCorrectlySet() throws Exception { + File directory = new File(RobotResultTest.class.getResource("../robot7").toURI()); + RobotParser.RobotParserCallable remoteOperation = new RobotParser.RobotParserCallable("inline_var_output.xml", null, null); + result = remoteOperation.invoke(directory, null); + result.tally(null); + + RobotSuiteResult suite = result.getSuite("Rf7"); + RobotCaseResult caseResult = suite.getCase("Test Inline Var"); + + // suite results + assertEquals(35.0, suite.getDuration(), 0.01); + + // case results + assertEquals("2023-11-13T15:33:07.168330", caseResult.getStarttime()); + assertEquals(0.001748, caseResult.getElapsedtime(), 0.01); + assertNull(caseResult.getEndtime()); + } + + @Test + void testGetPassPercentageWithoutSkippedTests() throws Exception { + RobotParser.RobotParserCallable remoteOperation = new RobotParser.RobotParserCallable("robot4_skip.xml", null, null); + result = remoteOperation.invoke(new File(RobotSuiteResultTest.class.getResource("robot4_skip.xml").toURI()).getParentFile(), null); + result.tally(null); + + assertEquals(66.6, result.getPassPercentage(false), 0); + } + + @Test + void testGetPassPercentageWithSkippedTests() throws Exception { + RobotParser.RobotParserCallable remoteOperation = new RobotParser.RobotParserCallable("robot4_skip.xml", null, null); + result = remoteOperation.invoke(new File(RobotSuiteResultTest.class.getResource("robot4_skip.xml").toURI()).getParentFile(), null); + result.tally(null); + + assertEquals(33.3, result.getPassPercentage(true), 0); + } } diff --git a/src/test/java/hudson/plugins/robot/model/RobotSuiteResultTest.java b/src/test/java/hudson/plugins/robot/model/RobotSuiteResultTest.java index 5928351..4d751f9 100644 --- a/src/test/java/hudson/plugins/robot/model/RobotSuiteResultTest.java +++ b/src/test/java/hudson/plugins/robot/model/RobotSuiteResultTest.java @@ -1,98 +1,96 @@ /* -* Copyright 2008-2014 Nokia Solutions and Networks Oy -* -* 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. -*/ + * Copyright 2008-2014 Nokia Solutions and Networks Oy + * + * 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 hudson.plugins.robot.model; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; - -import org.dom4j.DocumentException; -import org.junit.Test; - - -public class RobotSuiteResultTest { - - - @Test - public void shouldAcceptMultipleSuitesAsChildren(){ - RobotSuiteResult result = new RobotSuiteResult(); - - //Robot sibling suites should have unique names by definition (directories / files in file system) - RobotSuiteResult child = new RobotSuiteResult(); - child.setName("child"); - RobotSuiteResult child2 = new RobotSuiteResult(); - child2.setName("child2"); - - result.addChild(child); - result.addChild(child2); - - assertEquals(2, result.getChildSuites().size()); - } - - @Test - public void shouldReturnEmptyCollectionIfNoChildren(){ - RobotSuiteResult result = new RobotSuiteResult(); - assertNotNull("Return value was null", result.getChildSuites()); - assertEquals("Collection was not empty", 0, result.getChildSuites().size()); - } - - @Test - public void shouldReturnChildSuiteByName(){ - RobotSuiteResult result = new RobotSuiteResult(); - RobotSuiteResult child = new RobotSuiteResult(); - child.setName("child"); - result.addChild(child); - - assertEquals(child, result.getSuite("child")); - } - - @Test - public void shouldReturnTestCaseByName(){ - RobotSuiteResult result = new RobotSuiteResult(); - RobotCaseResult caseResult = new RobotCaseResult(); - caseResult.setName("case1"); - - result.addCaseResult(caseResult); - assertEquals(caseResult, result.getCase("case1")); - } - - @Test - public void shouldReturnNullIfNoParent() throws DocumentException { - RobotSuiteResult rootResult = new RobotSuiteResult(); - assertNull(rootResult.getParent()); - } - - @Test - public void shouldAcceptMultipleCaseResults() { - RobotSuiteResult result = new RobotSuiteResult(); - RobotCaseResult caseResult = new RobotCaseResult(); - caseResult.setName("case1"); - RobotCaseResult caseResult2 = new RobotCaseResult(); - caseResult2.setName("case2"); - - result.addCaseResult(caseResult); - result.addCaseResult(caseResult2); - - assertEquals(2, result.getCaseResults().size()); - } - - @Test - public void shouldReturnEmptyCollectionIfNoTestCases() throws DocumentException { - RobotSuiteResult result = new RobotSuiteResult(); - assertNotNull("Return value was null", result.getCaseResults()); - assertEquals("Collection was not empty", 0, result.getCaseResults().size()); - } +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; + + +class RobotSuiteResultTest { + + @Test + void shouldAcceptMultipleSuitesAsChildren() { + RobotSuiteResult result = new RobotSuiteResult(); + + //Robot sibling suites should have unique names by definition (directories / files in file system) + RobotSuiteResult child = new RobotSuiteResult(); + child.setName("child"); + RobotSuiteResult child2 = new RobotSuiteResult(); + child2.setName("child2"); + + result.addChild(child); + result.addChild(child2); + + assertEquals(2, result.getChildSuites().size()); + } + + @Test + void shouldReturnEmptyCollectionIfNoChildren() { + RobotSuiteResult result = new RobotSuiteResult(); + assertNotNull(result.getChildSuites(), "Return value was null"); + assertEquals(0, result.getChildSuites().size(), "Collection was not empty"); + } + + @Test + void shouldReturnChildSuiteByName() { + RobotSuiteResult result = new RobotSuiteResult(); + RobotSuiteResult child = new RobotSuiteResult(); + child.setName("child"); + result.addChild(child); + + assertEquals(child, result.getSuite("child")); + } + + @Test + void shouldReturnTestCaseByName() { + RobotSuiteResult result = new RobotSuiteResult(); + RobotCaseResult caseResult = new RobotCaseResult(); + caseResult.setName("case1"); + + result.addCaseResult(caseResult); + assertEquals(caseResult, result.getCase("case1")); + } + + @Test + void shouldReturnNullIfNoParent() { + RobotSuiteResult rootResult = new RobotSuiteResult(); + assertNull(rootResult.getParent()); + } + + @Test + void shouldAcceptMultipleCaseResults() { + RobotSuiteResult result = new RobotSuiteResult(); + RobotCaseResult caseResult = new RobotCaseResult(); + caseResult.setName("case1"); + RobotCaseResult caseResult2 = new RobotCaseResult(); + caseResult2.setName("case2"); + + result.addCaseResult(caseResult); + result.addCaseResult(caseResult2); + + assertEquals(2, result.getCaseResults().size()); + } + + @Test + void shouldReturnEmptyCollectionIfNoTestCases() { + RobotSuiteResult result = new RobotSuiteResult(); + assertNotNull(result.getCaseResults(), "Return value was null"); + assertEquals(0, result.getCaseResults().size(), "Collection was not empty"); + } } diff --git a/src/test/java/hudson/plugins/robot/tokens/RobotFailTokenMacroTest.java b/src/test/java/hudson/plugins/robot/tokens/RobotFailTokenMacroTest.java index acb8710..f71df5b 100644 --- a/src/test/java/hudson/plugins/robot/tokens/RobotFailTokenMacroTest.java +++ b/src/test/java/hudson/plugins/robot/tokens/RobotFailTokenMacroTest.java @@ -4,37 +4,42 @@ import hudson.model.TaskListener; import hudson.plugins.robot.RobotBuildAction; import hudson.plugins.robot.model.RobotResult; -import junit.framework.TestCase; -import org.jenkinsci.plugins.tokenmacro.MacroEvaluationException; -import org.mockito.Mockito; - -import java.io.IOException; - -public class RobotFailTokenMacroTest extends TestCase { - - private static final String macroName = "ROBOT_FAILED"; - private RobotFailTokenMacro token; - private AbstractBuild build; - private TaskListener listener; - - public void setUp(){ - token = new RobotFailTokenMacro(); - build = Mockito.mock(AbstractBuild.class); - listener = Mockito.mock(TaskListener.class); - - RobotBuildAction action = Mockito.mock(RobotBuildAction.class); - RobotResult result = Mockito.mock(RobotResult.class); - - Mockito.when(result.getOverallFailed()).thenReturn(6L); - Mockito.when(action.getResult()).thenReturn(result); - Mockito.when(build.getAction(RobotBuildAction.class)).thenReturn(action); - } - - public void testAcceptsName(){ - assertTrue(token.acceptsMacroName(macroName)); - } - - public void testTokenConversionWithAll() throws MacroEvaluationException, IOException, InterruptedException{ - assertEquals("6",token.evaluate(build, listener, macroName)); - } +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +class RobotFailTokenMacroTest { + + private static final String macroName = "ROBOT_FAILED"; + private RobotFailTokenMacro token; + private AbstractBuild build; + private TaskListener listener; + + @BeforeEach + void setUp() { + token = new RobotFailTokenMacro(); + build = mock(AbstractBuild.class); + listener = mock(TaskListener.class); + + RobotBuildAction action = mock(RobotBuildAction.class); + RobotResult result = mock(RobotResult.class); + + when(result.getOverallFailed()).thenReturn(6L); + when(action.getResult()).thenReturn(result); + when(build.getAction(RobotBuildAction.class)).thenReturn(action); + } + + @Test + void testAcceptsName() { + assertTrue(token.acceptsMacroName(macroName)); + } + + @Test + void testTokenConversionWithAll() throws Exception { + assertEquals("6", token.evaluate(build, listener, macroName)); + } } diff --git a/src/test/java/hudson/plugins/robot/tokens/RobotFailedCasesTokenMacroTest.java b/src/test/java/hudson/plugins/robot/tokens/RobotFailedCasesTokenMacroTest.java index 39c6125..b97ed96 100644 --- a/src/test/java/hudson/plugins/robot/tokens/RobotFailedCasesTokenMacroTest.java +++ b/src/test/java/hudson/plugins/robot/tokens/RobotFailedCasesTokenMacroTest.java @@ -1,65 +1,70 @@ package hudson.plugins.robot.tokens; -import hudson.model.TaskListener; import hudson.model.AbstractBuild; +import hudson.model.TaskListener; import hudson.plugins.robot.RobotBuildAction; import hudson.plugins.robot.model.RobotCaseResult; import hudson.plugins.robot.model.RobotResult; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -import java.io.IOException; import java.util.ArrayList; import java.util.List; -import junit.framework.TestCase; - -import org.jenkinsci.plugins.tokenmacro.MacroEvaluationException; -import org.mockito.Mockito; - -public class RobotFailedCasesTokenMacroTest extends TestCase { - - private static final String macroName = "ROBOT_FAILEDCASES"; - - private RobotFailedCasesTokenMacro token; - private AbstractBuild build; - private TaskListener listener; - private RobotBuildAction action; - - public void setUp(){ - token = new RobotFailedCasesTokenMacro(); - build = Mockito.mock(AbstractBuild.class); - listener = Mockito.mock(TaskListener.class); - action = Mockito.mock(RobotBuildAction.class); - - RobotResult result = Mockito.mock(RobotResult.class); - - List failedList = new ArrayList<>(); - - RobotCaseResult case1 = Mockito.mock(RobotCaseResult.class); - Mockito.when(case1.getRelativePackageName(result)).thenReturn("Failcases.subcases.Failure1"); - Mockito.when(case1.getErrorMsg()).thenReturn("Case1 failed"); - - RobotCaseResult case2 = Mockito.mock(RobotCaseResult.class); - Mockito.when(case2.getRelativePackageName(result)).thenReturn("Morefails.Failure2"); - Mockito.when(case2.getErrorMsg()).thenReturn("Case2 failed"); - - failedList.add(case1); - failedList.add(case2); - - Mockito.when(result.getAllFailedCases()).thenReturn(failedList); - Mockito.when(action.getResult()).thenReturn(result); - Mockito.when(build.getAction(RobotBuildAction.class)).thenReturn(action); - } - - public void testAcceptsName(){ - assertTrue(new RobotFailedCasesTokenMacro().acceptsMacroName(macroName)); - } - - public void testTokenConversionWithoutMessages() throws MacroEvaluationException, IOException, InterruptedException{ - assertEquals("Failcases.subcases.Failure1\nMorefails.Failure2",token.evaluate(build, listener, macroName)); - } - - public void testTokenConversionWithMessages() throws MacroEvaluationException, IOException, InterruptedException{ - token.addErrorMessages = true; - assertEquals("Failcases.subcases.Failure1: Case1 failed\nMorefails.Failure2: Case2 failed",token.evaluate(build, listener, macroName)); - } +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +class RobotFailedCasesTokenMacroTest { + + private static final String macroName = "ROBOT_FAILEDCASES"; + + private RobotFailedCasesTokenMacro token; + private AbstractBuild build; + private TaskListener listener; + private RobotBuildAction action; + + @BeforeEach + void setUp() { + token = new RobotFailedCasesTokenMacro(); + build = mock(AbstractBuild.class); + listener = mock(TaskListener.class); + action = mock(RobotBuildAction.class); + + RobotResult result = mock(RobotResult.class); + + List failedList = new ArrayList<>(); + + RobotCaseResult case1 = mock(RobotCaseResult.class); + when(case1.getRelativePackageName(result)).thenReturn("Failcases.subcases.Failure1"); + when(case1.getErrorMsg()).thenReturn("Case1 failed"); + + RobotCaseResult case2 = mock(RobotCaseResult.class); + when(case2.getRelativePackageName(result)).thenReturn("Morefails.Failure2"); + when(case2.getErrorMsg()).thenReturn("Case2 failed"); + + failedList.add(case1); + failedList.add(case2); + + when(result.getAllFailedCases()).thenReturn(failedList); + when(action.getResult()).thenReturn(result); + when(build.getAction(RobotBuildAction.class)).thenReturn(action); + } + + @Test + void testAcceptsName() { + assertTrue(new RobotFailedCasesTokenMacro().acceptsMacroName(macroName)); + } + + @Test + void testTokenConversionWithoutMessages() throws Exception { + assertEquals("Failcases.subcases.Failure1\nMorefails.Failure2", token.evaluate(build, listener, macroName)); + } + + @Test + void testTokenConversionWithMessages() throws Exception { + token.addErrorMessages = true; + assertEquals("Failcases.subcases.Failure1: Case1 failed\nMorefails.Failure2: Case2 failed", token.evaluate(build, listener, macroName)); + } } diff --git a/src/test/java/hudson/plugins/robot/tokens/RobotPassPercentageTokenMacroTest.java b/src/test/java/hudson/plugins/robot/tokens/RobotPassPercentageTokenMacroTest.java index 4effdb7..9068e2e 100644 --- a/src/test/java/hudson/plugins/robot/tokens/RobotPassPercentageTokenMacroTest.java +++ b/src/test/java/hudson/plugins/robot/tokens/RobotPassPercentageTokenMacroTest.java @@ -1,46 +1,49 @@ package hudson.plugins.robot.tokens; -import hudson.model.TaskListener; import hudson.model.AbstractBuild; +import hudson.model.TaskListener; import hudson.plugins.robot.RobotBuildAction; import hudson.plugins.robot.model.RobotResult; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +class RobotPassPercentageTokenMacroTest { + + private static final String macroName = "ROBOT_PASSPERCENTAGE"; + + private RobotPassPercentageTokenMacro token; + private AbstractBuild build; + private TaskListener listener; + private RobotBuildAction action; + + @BeforeEach + void setUp() { + token = new RobotPassPercentageTokenMacro(); + build = mock(AbstractBuild.class); + listener = mock(TaskListener.class); + action = mock(RobotBuildAction.class); + + RobotResult result = mock(RobotResult.class); + + when(result.getPassPercentage(true)).thenReturn(55.0); + when(result.getPassPercentage(false)).thenReturn(41.0); + when(action.getResult()).thenReturn(result); + when(build.getAction(RobotBuildAction.class)).thenReturn(action); + } + + @Test + void testAcceptsName() { + assertTrue(new RobotPassPercentageTokenMacro().acceptsMacroName(macroName)); + } -import java.io.IOException; - -import junit.framework.TestCase; - -import org.jenkinsci.plugins.tokenmacro.MacroEvaluationException; -import org.mockito.Mockito; - -public class RobotPassPercentageTokenMacroTest extends TestCase { - - private static final String macroName = "ROBOT_PASSPERCENTAGE"; - - private RobotPassPercentageTokenMacro token; - private AbstractBuild build; - private TaskListener listener; - private RobotBuildAction action; - - public void setUp(){ - token = new RobotPassPercentageTokenMacro(); - build = Mockito.mock(AbstractBuild.class); - listener = Mockito.mock(TaskListener.class); - action = Mockito.mock(RobotBuildAction.class); - - RobotResult result = Mockito.mock(RobotResult.class); - - Mockito.when(result.getPassPercentage(true)).thenReturn(55.0); - Mockito.when(result.getPassPercentage(false)).thenReturn(41.0); - Mockito.when(action.getResult()).thenReturn(result); - Mockito.when(build.getAction(RobotBuildAction.class)).thenReturn(action); - } - - public void testAcceptsName(){ - assertTrue(new RobotPassPercentageTokenMacro().acceptsMacroName(macroName)); - } - - public void testTokenConversionWithAll() throws MacroEvaluationException, IOException, InterruptedException{ - token.countSkippedTests = false; - assertEquals("41.0",token.evaluate(build, listener, macroName)); - } + @Test + void testTokenConversionWithAll() throws Exception { + token.countSkippedTests = false; + assertEquals("41.0", token.evaluate(build, listener, macroName)); + } } diff --git a/src/test/java/hudson/plugins/robot/tokens/RobotPassRatioTokenMacroTest.java b/src/test/java/hudson/plugins/robot/tokens/RobotPassRatioTokenMacroTest.java index 633231e..558781b 100644 --- a/src/test/java/hudson/plugins/robot/tokens/RobotPassRatioTokenMacroTest.java +++ b/src/test/java/hudson/plugins/robot/tokens/RobotPassRatioTokenMacroTest.java @@ -1,43 +1,46 @@ package hudson.plugins.robot.tokens; -import hudson.model.TaskListener; import hudson.model.AbstractBuild; +import hudson.model.TaskListener; import hudson.plugins.robot.RobotBuildAction; import hudson.plugins.robot.model.RobotResult; - -import java.io.IOException; - -import junit.framework.TestCase; - -import org.jenkinsci.plugins.tokenmacro.MacroEvaluationException; -import org.mockito.Mockito; - -public class RobotPassRatioTokenMacroTest extends TestCase { - - private static final String macroName = "ROBOT_PASSRATIO"; - private RobotPassRatioTokenMacro token; - private AbstractBuild build; - private TaskListener listener; - - public void setUp(){ - token = new RobotPassRatioTokenMacro(); - build = Mockito.mock(AbstractBuild.class); - listener = Mockito.mock(TaskListener.class); - - RobotBuildAction action = Mockito.mock(RobotBuildAction.class); - RobotResult result = Mockito.mock(RobotResult.class); - - Mockito.when(result.getOverallPassed()).thenReturn(6L); - Mockito.when(result.getOverallTotal()).thenReturn(13L); - Mockito.when(action.getResult()).thenReturn(result); - Mockito.when(build.getAction(RobotBuildAction.class)).thenReturn(action); - } - - public void testAcceptsName(){ - assertTrue(new RobotPassRatioTokenMacro().acceptsMacroName(macroName)); - } - - public void testTokenConversionWithAll() throws MacroEvaluationException, IOException, InterruptedException{ - assertEquals("6 / 13",token.evaluate(build, listener, macroName)); - } +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +class RobotPassRatioTokenMacroTest { + + private static final String macroName = "ROBOT_PASSRATIO"; + private RobotPassRatioTokenMacro token; + private AbstractBuild build; + private TaskListener listener; + + @BeforeEach + void setUp() { + token = new RobotPassRatioTokenMacro(); + build = mock(AbstractBuild.class); + listener = mock(TaskListener.class); + + RobotBuildAction action = mock(RobotBuildAction.class); + RobotResult result = mock(RobotResult.class); + + when(result.getOverallPassed()).thenReturn(6L); + when(result.getOverallTotal()).thenReturn(13L); + when(action.getResult()).thenReturn(result); + when(build.getAction(RobotBuildAction.class)).thenReturn(action); + } + + @Test + void testAcceptsName() { + assertTrue(new RobotPassRatioTokenMacro().acceptsMacroName(macroName)); + } + + @Test + void testTokenConversionWithAll() throws Exception { + assertEquals("6 / 13", token.evaluate(build, listener, macroName)); + } } diff --git a/src/test/java/hudson/plugins/robot/tokens/RobotPassTokenMacroTest.java b/src/test/java/hudson/plugins/robot/tokens/RobotPassTokenMacroTest.java index e9dcc84..83dc51a 100644 --- a/src/test/java/hudson/plugins/robot/tokens/RobotPassTokenMacroTest.java +++ b/src/test/java/hudson/plugins/robot/tokens/RobotPassTokenMacroTest.java @@ -4,37 +4,42 @@ import hudson.model.TaskListener; import hudson.plugins.robot.RobotBuildAction; import hudson.plugins.robot.model.RobotResult; -import junit.framework.TestCase; -import org.jenkinsci.plugins.tokenmacro.MacroEvaluationException; -import org.mockito.Mockito; - -import java.io.IOException; - -public class RobotPassTokenMacroTest extends TestCase { - - private static final String macroName = "ROBOT_PASSED"; - private RobotPassTokenMacro token; - private AbstractBuild build; - private TaskListener listener; - - public void setUp(){ - token = new RobotPassTokenMacro(); - build = Mockito.mock(AbstractBuild.class); - listener = Mockito.mock(TaskListener.class); - - RobotBuildAction action = Mockito.mock(RobotBuildAction.class); - RobotResult result = Mockito.mock(RobotResult.class); - - Mockito.when(result.getOverallPassed()).thenReturn(6L); - Mockito.when(action.getResult()).thenReturn(result); - Mockito.when(build.getAction(RobotBuildAction.class)).thenReturn(action); - } - - public void testAcceptsName(){ - assertTrue(token.acceptsMacroName(macroName)); - } - - public void testTokenConversionWithAll() throws MacroEvaluationException, IOException, InterruptedException{ - assertEquals("6",token.evaluate(build, listener, macroName)); - } +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +class RobotPassTokenMacroTest { + + private static final String macroName = "ROBOT_PASSED"; + private RobotPassTokenMacro token; + private AbstractBuild build; + private TaskListener listener; + + @BeforeEach + void setUp() { + token = new RobotPassTokenMacro(); + build = mock(AbstractBuild.class); + listener = mock(TaskListener.class); + + RobotBuildAction action = mock(RobotBuildAction.class); + RobotResult result = mock(RobotResult.class); + + when(result.getOverallPassed()).thenReturn(6L); + when(action.getResult()).thenReturn(result); + when(build.getAction(RobotBuildAction.class)).thenReturn(action); + } + + @Test + void testAcceptsName() { + assertTrue(token.acceptsMacroName(macroName)); + } + + @Test + void testTokenConversionWithAll() throws Exception { + assertEquals("6", token.evaluate(build, listener, macroName)); + } } diff --git a/src/test/java/hudson/plugins/robot/tokens/RobotReportLinkTokenMacroTest.java b/src/test/java/hudson/plugins/robot/tokens/RobotReportLinkTokenMacroTest.java index 2be567d..6b6904b 100644 --- a/src/test/java/hudson/plugins/robot/tokens/RobotReportLinkTokenMacroTest.java +++ b/src/test/java/hudson/plugins/robot/tokens/RobotReportLinkTokenMacroTest.java @@ -1,48 +1,52 @@ package hudson.plugins.robot.tokens; -import hudson.model.TaskListener; import hudson.model.AbstractBuild; +import hudson.model.TaskListener; import hudson.plugins.robot.RobotBuildAction; - -import java.io.IOException; - -import junit.framework.TestCase; - -import org.jenkinsci.plugins.tokenmacro.MacroEvaluationException; -import org.mockito.Mockito; - -public class RobotReportLinkTokenMacroTest extends TestCase { - - private static final String macroName = "ROBOT_REPORTLINK"; - - private RobotReportLinkTokenMacro token; - private AbstractBuild build; - private TaskListener listener; - private RobotBuildAction action; - - public void setUp(){ - token = new RobotReportLinkTokenMacro(); - build = Mockito.mock(AbstractBuild.class); - listener = Mockito.mock(TaskListener.class); - action = Mockito.mock(RobotBuildAction.class); - - Mockito.when(build.getUrl()).thenReturn("job/robotjob/1/"); - Mockito.when(action.getUrlName()).thenReturn("robot"); - Mockito.when(build.getAction(RobotBuildAction.class)).thenReturn(action); - - } - - public void testAcceptsName(){ - assertTrue(new RobotReportLinkTokenMacro().acceptsMacroName(macroName)); - } - - public void testTokenConversionWithoutReportLink() throws MacroEvaluationException, IOException, InterruptedException{ - assertEquals("job/robotjob/1/robot/report/",token.evaluate(build, listener, macroName)); - } - - public void testTokenConversionWithReportLink() throws MacroEvaluationException, IOException, InterruptedException{ - Mockito.when(action.getLogFileLink()).thenReturn("report.html"); - assertEquals("job/robotjob/1/robot/report/report.html", token.evaluate(build, listener, macroName)); - } +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +class RobotReportLinkTokenMacroTest { + + private static final String macroName = "ROBOT_REPORTLINK"; + + private RobotReportLinkTokenMacro token; + private AbstractBuild build; + private TaskListener listener; + private RobotBuildAction action; + + @BeforeEach + void setUp() { + token = new RobotReportLinkTokenMacro(); + build = mock(AbstractBuild.class); + listener = mock(TaskListener.class); + action = mock(RobotBuildAction.class); + + when(build.getUrl()).thenReturn("job/robotjob/1/"); + when(action.getUrlName()).thenReturn("robot"); + when(build.getAction(RobotBuildAction.class)).thenReturn(action); + + } + + @Test + void testAcceptsName() { + assertTrue(new RobotReportLinkTokenMacro().acceptsMacroName(macroName)); + } + + @Test + void testTokenConversionWithoutReportLink() throws Exception { + assertEquals("job/robotjob/1/robot/report/", token.evaluate(build, listener, macroName)); + } + + @Test + void testTokenConversionWithReportLink() throws Exception { + when(action.getLogFileLink()).thenReturn("report.html"); + assertEquals("job/robotjob/1/robot/report/report.html", token.evaluate(build, listener, macroName)); + } } diff --git a/src/test/java/hudson/plugins/robot/tokens/RobotTotalTokenMacroTest.java b/src/test/java/hudson/plugins/robot/tokens/RobotTotalTokenMacroTest.java index fa9d594..87b09b3 100644 --- a/src/test/java/hudson/plugins/robot/tokens/RobotTotalTokenMacroTest.java +++ b/src/test/java/hudson/plugins/robot/tokens/RobotTotalTokenMacroTest.java @@ -4,37 +4,42 @@ import hudson.model.TaskListener; import hudson.plugins.robot.RobotBuildAction; import hudson.plugins.robot.model.RobotResult; -import junit.framework.TestCase; -import org.jenkinsci.plugins.tokenmacro.MacroEvaluationException; -import org.mockito.Mockito; - -import java.io.IOException; - -public class RobotTotalTokenMacroTest extends TestCase { - - private static final String macroName = "ROBOT_TOTAL"; - private RobotTotalTokenMacro token; - private AbstractBuild build; - private TaskListener listener; - - public void setUp(){ - token = new RobotTotalTokenMacro(); - build = Mockito.mock(AbstractBuild.class); - listener = Mockito.mock(TaskListener.class); - - RobotBuildAction action = Mockito.mock(RobotBuildAction.class); - RobotResult result = Mockito.mock(RobotResult.class); - - Mockito.when(result.getOverallTotal()).thenReturn(6L); - Mockito.when(action.getResult()).thenReturn(result); - Mockito.when(build.getAction(RobotBuildAction.class)).thenReturn(action); - } - - public void testAcceptsName(){ - assertTrue(token.acceptsMacroName(macroName)); - } - - public void testTokenConversionWithAll() throws MacroEvaluationException, IOException, InterruptedException{ - assertEquals("6",token.evaluate(build, listener, macroName)); - } +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +class RobotTotalTokenMacroTest { + + private static final String macroName = "ROBOT_TOTAL"; + private RobotTotalTokenMacro token; + private AbstractBuild build; + private TaskListener listener; + + @BeforeEach + void setUp() { + token = new RobotTotalTokenMacro(); + build = mock(AbstractBuild.class); + listener = mock(TaskListener.class); + + RobotBuildAction action = mock(RobotBuildAction.class); + RobotResult result = mock(RobotResult.class); + + when(result.getOverallTotal()).thenReturn(6L); + when(action.getResult()).thenReturn(result); + when(build.getAction(RobotBuildAction.class)).thenReturn(action); + } + + @Test + void testAcceptsName() { + assertTrue(token.acceptsMacroName(macroName)); + } + + @Test + void testTokenConversionWithAll() throws Exception { + assertEquals("6", token.evaluate(build, listener, macroName)); + } }