use of com.seleniumtests.customexception.ScenarioException in project seleniumRobot by bhecquet.
the class CampaignFolder method create.
public static CampaignFolder create(Project project, CampaignFolder parent, String campaignFolderName) {
try {
JSONObject body = new JSONObject();
body.put(FIELD_TYPE, TYPE_CAMPAIGN_FOLDER);
body.put(FIELD_NAME, campaignFolderName);
if (parent != null) {
body.put(FIELD_PARENT, parent.asJson());
} else {
body.put(FIELD_PARENT, project.asJson());
}
JSONObject json = getJSonResponse(buildPostRequest(apiRootUrl + CAMPAIGN_FOLDER_URL).body(body));
return CampaignFolder.fromJson(json);
} catch (UnirestException e) {
throw new ScenarioException(String.format("Cannot create campaign %s", campaignFolderName), e);
}
}
use of com.seleniumtests.customexception.ScenarioException in project seleniumRobot by bhecquet.
the class Iteration method create.
public static Iteration create(Campaign campaign, String iterationName) {
try {
JSONObject body = new JSONObject();
body.put(FIELD_TYPE, TYPE_ITERATION);
body.put(FIELD_NAME, iterationName);
JSONObject parent = new JSONObject();
parent.put(FIELD_ID, campaign.id);
parent.put(FIELD_TYPE, TYPE_CAMPAIGN);
body.put(FIELD_PARENT, parent);
JSONObject json = getJSonResponse(buildPostRequest(String.format(apiRootUrl + ITERATIONS_URL, campaign.id)).body(body));
return fromJson(json);
} catch (UnirestException e) {
throw new ScenarioException(String.format("Cannot create campaign %s", iterationName), e);
}
}
use of com.seleniumtests.customexception.ScenarioException in project seleniumRobot by bhecquet.
the class Iteration method getAllTestCases.
public List<IterationTestPlanItem> getAllTestCases() {
try {
JSONObject json = getPagedJSonResponse(buildGetRequest(apiRootUrl + String.format(IterationTestPlanItem.TEST_PLAN_ITEM_URL, id)));
List<IterationTestPlanItem> testPlanItems = new ArrayList<>();
if (json.has(FIELD_EMBEDDED)) {
for (JSONObject tpiJson : (List<JSONObject>) json.getJSONObject(FIELD_EMBEDDED).getJSONArray("test-plan").toList()) {
testPlanItems.add(IterationTestPlanItem.fromJson(tpiJson));
}
}
return testPlanItems;
} catch (UnirestException e) {
throw new ScenarioException("Cannot get all test cases", e);
}
}
use of com.seleniumtests.customexception.ScenarioException in project seleniumRobot by bhecquet.
the class Project method getCampaigns.
public List<Campaign> getCampaigns() {
try {
JSONObject json = getPagedJSonResponse(buildGetRequest(url + CAMPAIGNS_URL));
List<Campaign> campaigns = new ArrayList<>();
if (json.has(FIELD_EMBEDDED)) {
for (JSONObject folderJson : (List<JSONObject>) json.getJSONObject(FIELD_EMBEDDED).getJSONArray(FIELD_CAMPAIGNS).toList()) {
campaigns.add(Campaign.fromJson(folderJson));
}
}
return campaigns;
} catch (UnirestException e) {
throw new ScenarioException(String.format("Cannot get list of campaigns for project %s", name));
}
}
use of com.seleniumtests.customexception.ScenarioException in project seleniumRobot by bhecquet.
the class ExcelHelper method readSheet.
public List<Map<String, String>> readSheet(Sheet sheet, boolean headerPresent, FormulaEvaluator formulaEvaluator, DataFormatter dataFormatter) {
List<Map<String, String>> content = new ArrayList<>();
int firstRow = sheet.getFirstRowNum();
int lastRow = sheet.getLastRowNum();
int firstColumn = 100000;
int lastColumn = 0;
Row headerRow = sheet.getRow(firstRow);
List<String> headers = new ArrayList<>();
// sheet is empty
if (headerRow == null) {
return null;
}
for (Cell cell : headerRow) {
firstColumn = Math.min(cell.getColumnIndex(), firstColumn);
lastColumn = Math.max(cell.getColumnIndex(), lastColumn);
if (headerPresent) {
headers.add(readCell(formulaEvaluator, dataFormatter, cell));
} else {
headers.add(Integer.toString(cell.getColumnIndex()));
}
}
firstRow = headerPresent ? firstRow + 1 : firstRow;
int colIdx = 0;
for (int rowIdx = firstRow; rowIdx <= lastRow; rowIdx++) {
try {
Row row = sheet.getRow(rowIdx);
if (row == null) {
// nothing has been written in cell, it's null
continue;
}
int empytCells = 0;
Map<String, String> rowContent = new HashMap<>();
for (colIdx = firstColumn; colIdx <= lastColumn; colIdx++) {
Cell cell = row.getCell(colIdx);
if (cell == null) {
// cell is empty, it's never been used
rowContent.put(headers.get(colIdx), "");
empytCells++;
} else {
String cellContent = readCell(formulaEvaluator, dataFormatter, cell);
if (cellContent != null && cellContent.isEmpty()) {
empytCells++;
}
rowContent.put(headers.get(colIdx), cellContent);
}
}
if (empytCells < rowContent.size()) {
content.add(rowContent);
}
} catch (Exception e) {
throw new ScenarioException(String.format("problem reading Excel sheet %s, line %d, column %d", sheet.getSheetName(), rowIdx + 1, colIdx + 1), e);
}
}
return content;
}
Aggregations