Search in sources :

Example 6 with Campaign

use of com.seleniumtests.connectors.tms.squash.entities.Campaign in project seleniumRobot by bhecquet.

the class TestSquashTMApi method testCreateUnexistingCampaign.

@Test(groups = { "ut" })
public void testCreateUnexistingCampaign() {
    PowerMockito.when(Project.getAll()).thenReturn(Arrays.asList(project1, project2));
    doReturn(Arrays.asList(campaign1, campaign2)).when(project1).getCampaigns();
    Campaign myCampaign = new Campaign("http://localhost:4321/campaigns/3", 3, "mycampaign");
    PowerMockito.when(Campaign.create(project1, "mycampaign", null)).thenReturn(myCampaign);
    SquashTMApi api = new SquashTMApi("http://localhost:4321", "user", "password", "project1");
    Campaign newCampaign = api.createCampaign("mycampaign", null);
    Assert.assertEquals(newCampaign, myCampaign);
    // check campaign creation has been called
    PowerMockito.verifyStatic(Campaign.class);
    Campaign.create(project1, "mycampaign", null);
    // check no folder has been created
    PowerMockito.verifyStatic(CampaignFolder.class, never());
    CampaignFolder.create(eq(project1), any(), anyString());
}
Also used : Campaign(com.seleniumtests.connectors.tms.squash.entities.Campaign) SquashTMApi(com.seleniumtests.connectors.tms.squash.SquashTMApi) Test(org.testng.annotations.Test) ConnectorsTest(com.seleniumtests.ConnectorsTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 7 with Campaign

use of com.seleniumtests.connectors.tms.squash.entities.Campaign in project seleniumRobot by bhecquet.

the class TestSquashTMConnector method testRecordResultTestInError.

@Test(groups = { "ut" })
public void testRecordResultTestInError(ITestContext testContext) {
    JSONObject connect = new JSONObject();
    connect.put(SquashTMConnector.TMS_SERVER_URL, "http://myServer");
    connect.put(SquashTMConnector.TMS_PROJECT, "project");
    connect.put(SquashTMConnector.TMS_USER, "user");
    connect.put(SquashTMConnector.TMS_PASSWORD, "password");
    SquashTMConnector squash = spy(new SquashTMConnector());
    squash.init(connect);
    doReturn(api).when(squash).getApi();
    CustomAttribute testIdAttr = new CustomAttribute() {

        @Override
        public Class<? extends Annotation> annotationType() {
            return null;
        }

        @Override
        public String[] values() {
            return new String[] { "1" };
        }

        @Override
        public String name() {
            return "testId";
        }
    };
    // customize test result so that it has attributes
    when(testResult.getMethod()).thenReturn(testMethod);
    when(testResult.isSuccess()).thenReturn(false);
    when(testResult.getStatus()).thenReturn(2);
    when(testResult.getName()).thenReturn("MyTest");
    when(testResult.getTestContext()).thenReturn(testContext);
    when(testResult.getParameters()).thenReturn(new Object[] {});
    when(testResult.getAttribute("testContext")).thenReturn(SeleniumTestsContextManager.getThreadContext());
    when(testMethod.getAttributes()).thenReturn(new CustomAttribute[] { testIdAttr });
    when(api.createCampaign(anyString(), anyString())).thenReturn(campaign);
    when(api.createIteration(any(Campaign.class), anyString())).thenReturn(iteration);
    when(api.addTestCaseInIteration(iteration, 1)).thenReturn(iterationTestPlanItem);
    squash.recordResult(testResult);
    // check we call all necessary API methods to record the result
    verify(api).createCampaign("Selenium " + testContext.getName(), "");
    verify(api).createIteration(campaign, SeleniumTestsContextManager.getThreadContext().getApplicationVersion());
    verify(api).addTestCaseInIteration(iteration, 1);
    verify(api).setExecutionResult(iterationTestPlanItem, ExecutionStatus.FAILURE);
}
Also used : Campaign(com.seleniumtests.connectors.tms.squash.entities.Campaign) JSONObject(org.json.JSONObject) CustomAttribute(org.testng.annotations.CustomAttribute) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) SquashTMConnector(com.seleniumtests.connectors.tms.squash.SquashTMConnector) Test(org.testng.annotations.Test) MockitoTest(com.seleniumtests.MockitoTest)

Example 8 with Campaign

use of com.seleniumtests.connectors.tms.squash.entities.Campaign in project seleniumRobot by bhecquet.

the class TestSquashTMApi method testDoNotCreateExistingCampaign.

/**
 * Check that we do not recreate a campaign if it already exist
 */
@Test(groups = { "ut" })
public void testDoNotCreateExistingCampaign() {
    PowerMockito.when(Project.getAll()).thenReturn(Arrays.asList(project1, project2));
    doReturn(Arrays.asList(campaign1, campaign2)).when(project1).getCampaigns();
    SquashTMApi api = new SquashTMApi("http://localhost:4321", "user", "password", "project1");
    Campaign newCampaign = api.createCampaign("campaign1", "");
    Assert.assertEquals(newCampaign, campaign1);
    // check campaign creation has been called
    PowerMockito.verifyStatic(Campaign.class, never());
    Campaign.create(project1, "campaign1", null);
    // check no folder has been created
    PowerMockito.verifyStatic(CampaignFolder.class, never());
    CampaignFolder.create(eq(project1), any(), anyString());
}
Also used : SquashTMApi(com.seleniumtests.connectors.tms.squash.SquashTMApi) Campaign(com.seleniumtests.connectors.tms.squash.entities.Campaign) Test(org.testng.annotations.Test) ConnectorsTest(com.seleniumtests.ConnectorsTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 9 with Campaign

use of com.seleniumtests.connectors.tms.squash.entities.Campaign in project seleniumRobot by bhecquet.

the class SquashTMApi method createCampaign.

/**
 * Creates a campaign if it does not exist
 * @param project		project in which this campaign will be created
 * @param campaignName	name of the campaign to create
 * @param folder		folder to which campaign will be created
 */
public Campaign createCampaign(String campaignName, String folder) {
    if (folder == null) {
        folder = "";
    }
    List<CampaignFolder> campaignFolders = CampaignFolder.getAll();
    // create folder where campaign will be located
    CampaignFolder parentFolder = null;
    for (String folderName : folder.split("/")) {
        if (folderName.isEmpty()) {
            continue;
        }
        boolean folderExists = false;
        for (CampaignFolder existingFolder : campaignFolders) {
            if (existingFolder.getName().equals(folderName) && (existingFolder.getProject() == null || existingFolder.getProject() != null && existingFolder.getProject().getId() == currentProject.getId()) && (existingFolder.getParent() == null || parentFolder == null && existingFolder.getParent() != null && existingFolder.getParent() instanceof Project || (parentFolder != null && existingFolder.getParent() != null && existingFolder.getParent() instanceof CampaignFolder && existingFolder.getParent().getId() == parentFolder.getId()))) {
                folderExists = true;
                parentFolder = existingFolder;
                break;
            }
        }
        if (!folderExists) {
            parentFolder = CampaignFolder.create(currentProject, parentFolder, folderName);
        }
    }
    // do not create campaign if it exists
    for (Campaign campaign : currentProject.getCampaigns()) {
        if (campaign.getName().equals(campaignName)) {
            return campaign;
        }
    }
    return Campaign.create(currentProject, campaignName, parentFolder);
}
Also used : Project(com.seleniumtests.connectors.tms.squash.entities.Project) Campaign(com.seleniumtests.connectors.tms.squash.entities.Campaign) CampaignFolder(com.seleniumtests.connectors.tms.squash.entities.CampaignFolder)

Example 10 with Campaign

use of com.seleniumtests.connectors.tms.squash.entities.Campaign in project seleniumRobot by bhecquet.

the class SquashTMConnector method recordResult.

@Override
public void recordResult(ITestResult testResult) {
    try {
        SquashTMApi sapi = getApi();
        Integer testId = TestNGResultUtils.getTestCaseId(testResult);
        if (testId == null) {
            return;
        }
        Campaign campaign = sapi.createCampaign("Selenium " + testResult.getTestContext().getName(), "");
        Iteration iteration = sapi.createIteration(campaign, TestNGResultUtils.getSeleniumRobotTestContext(testResult).getApplicationVersion());
        IterationTestPlanItem tpi = sapi.addTestCaseInIteration(iteration, testId);
        if (testResult.isSuccess()) {
            sapi.setExecutionResult(tpi, ExecutionStatus.SUCCESS);
        } else if (testResult.getStatus() == 2) {
            // failed
            sapi.setExecutionResult(tpi, ExecutionStatus.FAILURE);
        } else {
            // skipped or other reason
            sapi.setExecutionResult(tpi, ExecutionStatus.BLOCKED);
        }
    } catch (Exception e) {
        logger.error(String.format("Could not record result for test method %s: %s", TestNGResultUtils.getTestName(testResult), e.getMessage()));
    }
}
Also used : Campaign(com.seleniumtests.connectors.tms.squash.entities.Campaign) IterationTestPlanItem(com.seleniumtests.connectors.tms.squash.entities.IterationTestPlanItem) Iteration(com.seleniumtests.connectors.tms.squash.entities.Iteration) ConfigurationException(com.seleniumtests.customexception.ConfigurationException)

Aggregations

Campaign (com.seleniumtests.connectors.tms.squash.entities.Campaign)20 Test (org.testng.annotations.Test)18 ConnectorsTest (com.seleniumtests.ConnectorsTest)11 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)11 SquashTMConnector (com.seleniumtests.connectors.tms.squash.SquashTMConnector)7 MockitoTest (com.seleniumtests.MockitoTest)6 JSONObject (org.json.JSONObject)6 SquashTMApi (com.seleniumtests.connectors.tms.squash.SquashTMApi)5 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)5 CustomAttribute (org.testng.annotations.CustomAttribute)5 Iteration (com.seleniumtests.connectors.tms.squash.entities.Iteration)4 Project (com.seleniumtests.connectors.tms.squash.entities.Project)3 GetRequest (kong.unirest.GetRequest)3 IterationTestPlanItem (com.seleniumtests.connectors.tms.squash.entities.IterationTestPlanItem)2 HttpResponse (kong.unirest.HttpResponse)2 JSONObject (kong.unirest.json.JSONObject)2 GenericTest (com.seleniumtests.GenericTest)1 CampaignFolder (com.seleniumtests.connectors.tms.squash.entities.CampaignFolder)1 ConfigurationException (com.seleniumtests.customexception.ConfigurationException)1 ScenarioException (com.seleniumtests.customexception.ScenarioException)1