Search in sources :

Example 6 with CampaignFolder

use of com.seleniumtests.connectors.tms.squash.entities.CampaignFolder 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 7 with CampaignFolder

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

the class TestCampaign method testCreateCampaignWithFolder.

@Test(groups = { "ut" })
public void testCreateCampaignWithFolder() {
    HttpRequestWithBody postRequest = (HttpRequestWithBody) createServerMock("POST", "/campaigns", 200, "{" + "  \"_type\" : \"campaign\"," + "  \"id\" : 332," + "  \"name\" : \"Campaign Test\"," + "  \"reference\" : \"ABCD\"," + "  \"description\" : \"<p>Sed eget rhoncus sapien. Nam et pulvinar nisi. su Do</p>\"," + "  \"status\" : \"PLANNED\"," + "  \"project\" : {" + "    \"_type\" : \"project\"," + "    \"id\" : 44," + "    \"_links\" : {" + "      \"self\" : {" + "        \"href\" : \"http://localhost:8080/api/rest/latest/projects/44\"" + "      }" + "    }" + "  }," + "  \"path\" : \"/sample project/campaign folder/Campaign Test\"," + "  \"parent\" : {" + "    \"_type\" : \"campaign-folder\"," + "    \"id\" : 7," + "    \"_links\" : {" + "      \"self\" : {" + "        \"href\" : \"http://localhost:8080/api/rest/latest/campaign-folders/7\"" + "      }" + "    }" + "  }," + "  \"created_by\" : \"admin\"," + "  \"created_on\" : \"2017-06-15T10:00:00.000+0000\"," + "  \"last_modified_by\" : \"admin\"," + "  \"last_modified_on\" : \"2017-06-15T10:00:00.000+0000\"," + "  \"scheduled_start_date\" : \"2021-08-31T10:00:00.000+0000\"," + "  \"scheduled_end_date\" : \"2031-09-29T10:00:00.000+0000\"," + "  \"actual_start_date\" : \"2034-09-29T10:00:00.000+0000\"," + "  \"actual_end_date\" : \"2035-09-29T10:00:00.000+0000\"," + "  \"actual_start_auto\" : false," + "  \"actual_end_auto\" : false," + "  \"custom_fields\" : [ {" + "    \"code\" : \"CUF_A\"," + "    \"label\" : \"Cuf A\"," + "    \"value\" : \"value of A\"" + "  }, {" + "    \"code\" : \"CUF_B\"," + "    \"label\" : \"Cuf B\"," + "    \"value\" : \"value of B\"" + "  } ]," + "  \"iterations\" : [ ]," + "  \"test_plan\" : [ ]," + "  \"attachments\" : [ ]," + "  \"_links\" : {" + "    \"self\" : {" + "      \"href\" : \"http://localhost:8080/api/rest/latest/campaigns/332\"" + "    }" + "  }" + "}", "request");
    CampaignFolder campaignFolder = new CampaignFolder("http://localhost:8080/api/rest/latest/campaign-folders/7", 7, "folder", project, null);
    Campaign.create(project, "myCampaign", campaignFolder);
    verify(postRequest).body(new JSONObject("{\"_type\":\"campaign\",\"name\":\"myCampaign\",\"status\":\"PLANNED\",\"parent\":{\"id\":7,\"_type\":\"campaign-folder\"}}"));
}
Also used : JSONObject(kong.unirest.json.JSONObject) HttpRequestWithBody(kong.unirest.HttpRequestWithBody) CampaignFolder(com.seleniumtests.connectors.tms.squash.entities.CampaignFolder) Test(org.testng.annotations.Test) ConnectorsTest(com.seleniumtests.ConnectorsTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 8 with CampaignFolder

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

the class TestCampaignFolder method testFromJsonWithProject.

@Test(groups = { "ut" })
public void testFromJsonWithProject() {
    JSONObject json = new JSONObject();
    json.put("_type", "campaign-folder");
    json.put("id", 1);
    json.put("name", "foo");
    json.put("_links", new JSONObject("{\"self\" : {" + "          \"href\" : \"http://localhost:8080/api/rest/latest/campaign-folder/1\"" + "        }}"));
    json.put("project", new JSONObject("{\r\n" + "    \"_type\" : \"project\",\r\n" + "    \"id\" : 10,\r\n" + "    \"name\" : \"Mangrove\",\r\n" + "    \"_links\" : {\r\n" + "      \"self\" : {\r\n" + "        \"href\" : \"http://localhost:8080/api/rest/latest/project/10\"\r\n" + "      }\r\n" + "    }}"));
    CampaignFolder campaignFolder = CampaignFolder.fromJson(json);
    Assert.assertEquals(campaignFolder.getId(), 1);
    Assert.assertEquals(campaignFolder.getName(), "foo");
    Assert.assertEquals(campaignFolder.getUrl(), "http://localhost:8080/api/rest/latest/campaign-folder/1");
    Assert.assertTrue(campaignFolder.getProject() instanceof Project);
    Assert.assertEquals(campaignFolder.getProject().getId(), 10);
}
Also used : Project(com.seleniumtests.connectors.tms.squash.entities.Project) JSONObject(kong.unirest.json.JSONObject) CampaignFolder(com.seleniumtests.connectors.tms.squash.entities.CampaignFolder) Test(org.testng.annotations.Test) ConnectorsTest(com.seleniumtests.ConnectorsTest)

Example 9 with CampaignFolder

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

the class TestCampaignFolder method testFromJsonParentFolder.

@Test(groups = { "ut" })
public void testFromJsonParentFolder() {
    JSONObject json = new JSONObject();
    json.put("_type", "campaign-folder");
    json.put("id", 1);
    json.put("name", "foo");
    json.put("_links", new JSONObject("{\"self\" : {" + "          \"href\" : \"http://localhost:8080/api/rest/latest/campaign-folder/1\"" + "        }}"));
    json.put("parent", new JSONObject("{\r\n" + "    \"_type\" : \"campaign-folder\",\r\n" + "    \"id\" : 10,\r\n" + "    \"name\" : \"Mangrove\",\r\n" + "    \"_links\" : {\r\n" + "      \"self\" : {\r\n" + "        \"href\" : \"http://localhost:8080/api/rest/latest/campaign-folder/10\"\r\n" + "      }\r\n" + "    }}"));
    CampaignFolder campaignFolder = CampaignFolder.fromJson(json);
    Assert.assertEquals(campaignFolder.getId(), 1);
    Assert.assertEquals(campaignFolder.getName(), "foo");
    Assert.assertEquals(campaignFolder.getUrl(), "http://localhost:8080/api/rest/latest/campaign-folder/1");
    Assert.assertTrue(campaignFolder.getParent() instanceof CampaignFolder);
    Assert.assertEquals(campaignFolder.getParent().getId(), 10);
}
Also used : JSONObject(kong.unirest.json.JSONObject) CampaignFolder(com.seleniumtests.connectors.tms.squash.entities.CampaignFolder) Test(org.testng.annotations.Test) ConnectorsTest(com.seleniumtests.ConnectorsTest)

Example 10 with CampaignFolder

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

the class TestCampaignFolder method testFromJsonParentIsProject.

@Test(groups = { "ut" })
public void testFromJsonParentIsProject() {
    JSONObject json = new JSONObject();
    json.put("_type", "campaign-folder");
    json.put("id", 1);
    json.put("name", "foo");
    json.put("_links", new JSONObject("{\"self\" : {" + "          \"href\" : \"http://localhost:8080/api/rest/latest/campaign-folder/1\"" + "        }}"));
    json.put("parent", new JSONObject("{\r\n" + "    \"_type\" : \"project\",\r\n" + "    \"id\" : 10,\r\n" + "    \"name\" : \"Mangrove\",\r\n" + "    \"_links\" : {\r\n" + "      \"self\" : {\r\n" + "        \"href\" : \"http://localhost:8080/api/rest/latest/project/10\"\r\n" + "      }\r\n" + "    }}"));
    CampaignFolder campaignFolder = CampaignFolder.fromJson(json);
    Assert.assertEquals(campaignFolder.getId(), 1);
    Assert.assertEquals(campaignFolder.getName(), "foo");
    Assert.assertEquals(campaignFolder.getUrl(), "http://localhost:8080/api/rest/latest/campaign-folder/1");
    Assert.assertTrue(campaignFolder.getParent() instanceof Project);
    Assert.assertEquals(campaignFolder.getParent().getId(), 10);
}
Also used : Project(com.seleniumtests.connectors.tms.squash.entities.Project) JSONObject(kong.unirest.json.JSONObject) CampaignFolder(com.seleniumtests.connectors.tms.squash.entities.CampaignFolder) Test(org.testng.annotations.Test) ConnectorsTest(com.seleniumtests.ConnectorsTest)

Aggregations

CampaignFolder (com.seleniumtests.connectors.tms.squash.entities.CampaignFolder)10 ConnectorsTest (com.seleniumtests.ConnectorsTest)9 Test (org.testng.annotations.Test)9 JSONObject (kong.unirest.json.JSONObject)8 Project (com.seleniumtests.connectors.tms.squash.entities.Project)3 HttpRequestWithBody (kong.unirest.HttpRequestWithBody)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 Campaign (com.seleniumtests.connectors.tms.squash.entities.Campaign)1 RequestBodyEntity (kong.unirest.RequestBodyEntity)1