Search in sources :

Example 6 with JiraBean

use of com.seleniumtests.connectors.bugtracker.jira.JiraBean in project seleniumRobot by bhecquet.

the class TestJiraConnector method testCreateIssueMissingDetailedResultFile.

/**
 * Test the case where the detailed result file (.zip) is not present
 * @throws URISyntaxException
 */
@Test(groups = { "ut" })
public void testCreateIssueMissingDetailedResultFile() throws URISyntaxException {
    JiraConnector jiraConnector = new JiraConnector("http://foo/bar", PROJECT_KEY, "user", "password", jiraOptions);
    // simulate screenshot file not present
    detailedResult.delete();
    JiraBean jiraBean = new JiraBean(null, "issue 1", "issue 1 descr", "P1", "Bug", null, null, null, null, Arrays.asList(), detailedResult, new HashMap<>(), new ArrayList<>());
    jiraConnector.createIssue(jiraBean);
    // check attachments (screenshots) have not been added  because screenshot file was not available
    verify(issueRestClient, never()).addAttachments(eq(new URI("http://foo/bar/i/1/attachments")), any(File.class));
}
Also used : JiraBean(com.seleniumtests.connectors.bugtracker.jira.JiraBean) JiraConnector(com.seleniumtests.connectors.bugtracker.jira.JiraConnector) URI(java.net.URI) File(java.io.File) Test(org.testng.annotations.Test) MockitoTest(com.seleniumtests.MockitoTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 7 with JiraBean

use of com.seleniumtests.connectors.bugtracker.jira.JiraBean in project seleniumRobot by bhecquet.

the class TestJiraConnector method testCreateIssueWithWrongComponent.

/**
 * Test issue creation with bad component name. No error raised
 * @throws URISyntaxException
 */
@Test(groups = { "ut" })
public void testCreateIssueWithWrongComponent() throws URISyntaxException {
    ArgumentCaptor<IssueInput> issueArgument = ArgumentCaptor.forClass(IssueInput.class);
    JiraConnector jiraConnector = new JiraConnector("http://foo/bar", PROJECT_KEY, "user", "password", jiraOptions);
    JiraBean jiraBean = new JiraBean(null, "issue 1", "issue 1 descr", "", "Bug", "", null, "", "", new ArrayList<>(), null, new HashMap<>(), Arrays.asList("unknown"));
    jiraConnector.createIssue(jiraBean);
    verify(issueRestClient).createIssue(issueArgument.capture());
    // check unknown component has not been added, but no error
    IssueInput issueInput = ((IssueInput) issueArgument.getValue());
    Assert.assertEquals(ImmutableList.copyOf(((Iterable<ComplexIssueInputFieldValue>) (issueInput.getField("components").getValue()))).size(), 0);
}
Also used : IssueInput(com.atlassian.jira.rest.client.api.domain.input.IssueInput) OptionalIterable(com.atlassian.jira.rest.client.api.OptionalIterable) JiraBean(com.seleniumtests.connectors.bugtracker.jira.JiraBean) JiraConnector(com.seleniumtests.connectors.bugtracker.jira.JiraConnector) Test(org.testng.annotations.Test) MockitoTest(com.seleniumtests.MockitoTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 8 with JiraBean

use of com.seleniumtests.connectors.bugtracker.jira.JiraBean in project seleniumRobot by bhecquet.

the class TestJiraConnector method testCreateJiraBeanWithOrigin.

/**
 * Create a new jira bean with all parameters
 * @throws Exception
 */
@Test(groups = { "ut" })
public void testCreateJiraBeanWithOrigin() throws Exception {
    jiraOptions.put("priority", "P1");
    jiraOptions.put("assignee", "me");
    jiraOptions.put("reporter", "you");
    jiraOptions.put("jira.issueType", "Bug");
    jiraOptions.put("jira.components", "comp1,comp2");
    jiraOptions.put("jira.field.foo", "bar");
    SeleniumTestsContextManager.getThreadContext().setStartedBy("http://foo/bar/job/1");
    JiraConnector jiraConnector = new JiraConnector("http://foo/bar", PROJECT_KEY, "user", "password", jiraOptions);
    IssueBean issueBean = jiraConnector.createIssueBean("[Selenium][selenium][DEV][ngName] test myTest KO", "testCreateJiraBean", "some description", Arrays.asList(step1, step2, stepEnd), jiraOptions);
    Assert.assertTrue(issueBean instanceof JiraBean);
    JiraBean jiraBean = (JiraBean) issueBean;
    Assert.assertEquals(jiraBean.getAssignee(), "me");
    // check only step2 is seen as a failed step
    // detailed result is not provided because 'startedBy' is set
    Assert.assertEquals(jiraBean.getDescription(), "*Test:* testCreateJiraBean\n" + "*Description:* some description\n" + "*Started by:* http://foo/bar/job/1\n" + "*Error step #1 (step 2):* *{color:#de350b}java.lang.NullPointerException: Error clicking{color}*\n" + "h2. Steps in error\n" + "* *Step 1: step 2*\n" + "{code:java}Step step 2\n" + "  - action1\n" + "  - action2{code}\n" + "\n" + "h2. Last logs\n" + "{code:java}Step Test end{code}\n" + "\n" + "h2. Associated screenshots\n" + "!N-A_0-2_Test_end--123456.png|thumbnail!\n" + "!N-A_0-2_Test_end--123456.png|thumbnail!\n");
    Assert.assertEquals(jiraBean.getSummary(), "[Selenium][selenium][DEV][ngName] test myTest KO");
    Assert.assertEquals(jiraBean.getReporter(), "you");
    Assert.assertEquals(jiraBean.getTestName(), "testCreateJiraBean");
    // screenshots from the last step
    Assert.assertEquals(jiraBean.getScreenShots(), Arrays.asList(screenshot, screenshot));
    Assert.assertEquals(jiraBean.getTestStep(), step2);
    Assert.assertEquals(jiraBean.getDateTime().getDayOfMonth(), ZonedDateTime.now().plusHours(3).getDayOfMonth());
    Assert.assertEquals(jiraBean.getComponents(), Arrays.asList("comp1", "comp2"));
    Assert.assertEquals(jiraBean.getIssueType(), "Bug");
    Assert.assertEquals(jiraBean.getPriority(), "P1");
    Assert.assertEquals(jiraBean.getCustomFields().get("foo"), "bar");
    // detailed result is not provided because 'startedBy' is set
    Assert.assertNull(jiraBean.getDetailedResult());
    // not inistialized by default
    Assert.assertNull(jiraBean.getId());
}
Also used : IssueBean(com.seleniumtests.connectors.bugtracker.IssueBean) JiraBean(com.seleniumtests.connectors.bugtracker.jira.JiraBean) JiraConnector(com.seleniumtests.connectors.bugtracker.jira.JiraConnector) Test(org.testng.annotations.Test) MockitoTest(com.seleniumtests.MockitoTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 9 with JiraBean

use of com.seleniumtests.connectors.bugtracker.jira.JiraBean in project seleniumRobot by bhecquet.

the class TestBugTrackerReporter method testIssueIsRecordedInReports.

/**
 * Check that when Jira is created / present, a link is available in report
 * We check in HTML report, but, it is the same for XML report (Here, we do not check that Perfreport works correctly)
 * @throws Exception
 */
@Test(groups = { "it" })
public void testIssueIsRecordedInReports() throws Exception {
    try {
        System.setProperty(SeleniumTestsContext.BUGTRACKER_TYPE, "jira");
        System.setProperty(SeleniumTestsContext.BUGTRACKER_URL, "http://localhost:1234");
        System.setProperty(SeleniumTestsContext.BUGTRACKER_PROJECT, "Project");
        System.setProperty(SeleniumTestsContext.BUGTRACKER_USER, "jira");
        System.setProperty(SeleniumTestsContext.BUGTRACKER_PASSWORD, "jira");
        System.setProperty("bugtracker.reporter", "me");
        System.setProperty("bugtracker.assignee", "you");
        System.setProperty("bugtracker.jira.field.application", "app");
        JiraBean jiraBean = new JiraBean("JIRA-1234", "summary", "description", "Bug", "P1");
        jiraBean.setAccessUrl("http://jira.server.com/browse/JIRA-1234");
        jiraBean.setDate("2021-01-06T15:18+01:00");
        ZonedDateTime creationDate = ZonedDateTime.now();
        jiraBean.setCreationDate(creationDate);
        when(jiraConnector.createIssue(eq("core"), eq("DEV"), anyString(), eq("testInError"), contains("Test 'testInError' failed"), any(), any())).thenReturn(jiraBean);
        executeSubTest(1, new String[] { "com.seleniumtests.it.stubclasses.StubTestClassForTestManager" }, ParallelMode.METHODS, new String[] { "testInError" });
        // check content of summary report file
        String mainReportContent = readSummaryFile();
        Assert.assertTrue(mainReportContent.matches(String.format(".*<td class=\"info\"><a href=\"http://jira.server.com/browse/JIRA-1234\">JIRA-1234</a></td><td class=\"info\">%s</td>.*", jiraBean.getCreationDate().replace("+", "\\+"))));
        String detailedReportContent = readTestMethodResultFile("testInError");
        Assert.assertTrue(detailedReportContent.contains("<th>Issue</th><td><a href=\"http://jira.server.com/browse/JIRA-1234\">JIRA-1234</a></td>"));
        Assert.assertTrue(detailedReportContent.contains(String.format("<th>Issue date</th><td>%s</td>", jiraBean.getCreationDate())));
    } finally {
        System.clearProperty(SeleniumTestsContext.BUGTRACKER_TYPE);
        System.clearProperty(SeleniumTestsContext.BUGTRACKER_PROJECT);
        System.clearProperty(SeleniumTestsContext.BUGTRACKER_URL);
        System.clearProperty(SeleniumTestsContext.BUGTRACKER_USER);
        System.clearProperty(SeleniumTestsContext.BUGTRACKER_PASSWORD);
        System.clearProperty("bugtracker.reporter");
        System.clearProperty("bugtracker.assignee");
        System.clearProperty("bugtracker.jira.field.application");
    }
}
Also used : ZonedDateTime(java.time.ZonedDateTime) JiraBean(com.seleniumtests.connectors.bugtracker.jira.JiraBean) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 10 with JiraBean

use of com.seleniumtests.connectors.bugtracker.jira.JiraBean in project seleniumRobot by bhecquet.

the class TestBugTrackerReporter method testIssueIsRecordedInReportsNoURL.

/**
 * Check that when Jira is created / present, without hyperlink, the issue name is present
 * @throws Exception
 */
@Test(groups = { "it" })
public void testIssueIsRecordedInReportsNoURL() throws Exception {
    try {
        System.setProperty(SeleniumTestsContext.BUGTRACKER_TYPE, "jira");
        System.setProperty(SeleniumTestsContext.BUGTRACKER_URL, "http://localhost:1234");
        System.setProperty(SeleniumTestsContext.BUGTRACKER_PROJECT, "Project");
        System.setProperty(SeleniumTestsContext.BUGTRACKER_USER, "jira");
        System.setProperty(SeleniumTestsContext.BUGTRACKER_PASSWORD, "jira");
        System.setProperty("bugtracker.reporter", "me");
        System.setProperty("bugtracker.assignee", "you");
        System.setProperty("bugtracker.jira.field.application", "app");
        JiraBean jiraBean = new JiraBean("JIRA-1234", "summary", "description", "Bug", "P1");
        jiraBean.setDate("2021-01-06T15:18+01:00");
        ZonedDateTime creationDate = ZonedDateTime.now();
        jiraBean.setCreationDate(creationDate);
        when(jiraConnector.createIssue(eq("core"), eq("DEV"), anyString(), eq("testInError"), contains("Test 'testInError' failed"), any(), any())).thenReturn(jiraBean);
        executeSubTest(1, new String[] { "com.seleniumtests.it.stubclasses.StubTestClassForTestManager" }, ParallelMode.METHODS, new String[] { "testInError" });
        // check content of summary report file
        String mainReportContent = readSummaryFile();
        Assert.assertTrue(mainReportContent.matches(String.format(".*<td class=\"info\">JIRA-1234</td><td class=\"info\">%s</td>.*", jiraBean.getCreationDate().replace("+", "\\+"))));
        String detailedReportContent = readTestMethodResultFile("testInError");
        Assert.assertTrue(detailedReportContent.contains("<th>Issue</th><td>JIRA-1234</td>"));
        Assert.assertTrue(detailedReportContent.contains(String.format("<th>Issue date</th><td>%s</td>", jiraBean.getCreationDate())));
    } finally {
        System.clearProperty(SeleniumTestsContext.BUGTRACKER_TYPE);
        System.clearProperty(SeleniumTestsContext.BUGTRACKER_PROJECT);
        System.clearProperty(SeleniumTestsContext.BUGTRACKER_URL);
        System.clearProperty(SeleniumTestsContext.BUGTRACKER_USER);
        System.clearProperty(SeleniumTestsContext.BUGTRACKER_PASSWORD);
        System.clearProperty("bugtracker.reporter");
        System.clearProperty("bugtracker.assignee");
        System.clearProperty("bugtracker.jira.field.application");
    }
}
Also used : ZonedDateTime(java.time.ZonedDateTime) JiraBean(com.seleniumtests.connectors.bugtracker.jira.JiraBean) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

JiraBean (com.seleniumtests.connectors.bugtracker.jira.JiraBean)24 Test (org.testng.annotations.Test)23 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)20 JiraConnector (com.seleniumtests.connectors.bugtracker.jira.JiraConnector)19 MockitoTest (com.seleniumtests.MockitoTest)18 File (java.io.File)8 IssueBean (com.seleniumtests.connectors.bugtracker.IssueBean)6 HashMap (java.util.HashMap)6 URI (java.net.URI)5 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)5 OptionalIterable (com.atlassian.jira.rest.client.api.OptionalIterable)4 IssueInput (com.atlassian.jira.rest.client.api.domain.input.IssueInput)4 ComplexIssueInputFieldValue (com.atlassian.jira.rest.client.api.domain.input.ComplexIssueInputFieldValue)3 GenericTest (com.seleniumtests.GenericTest)3 ZonedDateTime (java.time.ZonedDateTime)3 SearchResult (com.atlassian.jira.rest.client.api.domain.SearchResult)2 DateTime (org.joda.time.DateTime)1