use of com.hp.octane.integrations.executor.TestToRunData in project octane-ci-java-sdk by MicroFocus.
the class TestExecutionServiceImpl method convertLinksToJson.
private String convertLinksToJson(List<Entity> links) throws JsonProcessingException {
TestToRunDataCollection collection = new TestToRunDataCollection();
for (Entity link : links) {
TestToRunData data = new TestToRunData();
Entity test = (Entity) link.getField("test");
data.setPackageName(test.getStringValue(EntityConstants.AutomatedTest.PACKAGE_FIELD));
data.setClassName(test.getStringValue(EntityConstants.AutomatedTest.CLASS_NAME_FIELD));
data.setTestName(test.getStringValue(EntityConstants.AutomatedTest.NAME_FIELD));
if (test.containsFieldAndValue("automation_identifier")) {
data.addParameters(CucumberJVMConverter.FEATURE_FILE_PATH, test.getStringValue("automation_identifier"));
}
if (test.containsFieldAndValue("external_test_id")) {
data.addParameters("external_test_id", test.getStringValue("external_test_id"));
}
if (test.containsFieldAndValue("data_table")) {
data.addParameters(CucumberJVMConverter.FEATURE_FILE_PATH, link.getEntityValue("data_table").getStringValue("relative_path"));
}
if (test.containsFieldAndValue(EntityConstants.TestSuiteLinkToTest.EXECUTION_PARAMETERS_FIELD)) {
String[] parts = link.getStringValue(EntityConstants.TestSuiteLinkToTest.EXECUTION_PARAMETERS_FIELD).split("[\n;]");
for (String part : parts) {
String myPart = part.trim();
int splitterIndex = myPart.indexOf('=');
if (myPart.isEmpty() || myPart.startsWith("#") || splitterIndex == -1) {
continue;
}
String name = myPart.substring(0, splitterIndex).trim();
String value = myPart.substring(splitterIndex + 1).trim();
data.addParameters(name, value);
}
}
collection.getTestsToRun().add(data);
}
final ObjectMapper objectMapper = new ObjectMapper();
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
return objectMapper.writeValueAsString(collection);
}
use of com.hp.octane.integrations.executor.TestToRunData in project octane-ci-java-sdk by MicroFocus.
the class MfUftConverter method convertToMtbxContent.
public String convertToMtbxContent(List<TestToRunData> tests, String workingDir, Map<String, String> globalParameters) {
tests = tests.stream().filter(testToRunData -> testToRunData.getParameter(TESTING_TOOL_TYPE_PARAMETER) == null).collect(Collectors.toList());
if (CollectionUtils.isEmpty(tests)) {
return "";
}
boolean addGlobalParameters = isAddGlobalParameters(globalParameters);
try {
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
Document doc = docBuilder.newDocument();
Element rootElement = doc.createElement("Mtbx");
doc.appendChild(rootElement);
for (TestToRunData test : tests) {
Element testElement = doc.createElement("Test");
String packageAndTestName = (SdkStringUtils.isNotEmpty(test.getPackageName()) ? test.getPackageName() + SdkConstants.FileSystem.WINDOWS_PATH_SPLITTER : "") + test.getTestName();
testElement.setAttribute("name", packageAndTestName);
String path = workingDir + (SdkStringUtils.isEmpty(test.getPackageName()) ? "" : SdkConstants.FileSystem.WINDOWS_PATH_SPLITTER + test.getPackageName()) + SdkConstants.FileSystem.WINDOWS_PATH_SPLITTER + test.getTestName();
testElement.setAttribute("path", path);
// add parameters
test.getParameters().forEach((paramKey, paramValue) -> {
if (DATA_TABLE_PARAMETER.equals(paramKey) || ITERATIONS_PARAMETER.equals(paramKey) || MBT_DATA.equals(paramKey)) {
// skip, will be handled later
} else {
if (INNER_RUN_ID_PARAMETER.equals(paramKey)) {
if (!addGlobalParameters) {
return;
}
}
addParameterToTestElement(doc, testElement, paramKey, paramValue);
}
});
if (addGlobalParameters) {
globalParameters.entrySet().stream().filter(p -> !p.getKey().equals(SdkConstants.JobParameters.ADD_GLOBAL_PARAMETERS_TO_TESTS_PARAM)).forEach(entry -> addParameterToTestElement(doc, testElement, entry.getKey(), entry.getValue()));
}
// add data table
String dataTable = test.getParameter(DATA_TABLE_PARAMETER);
if (SdkStringUtils.isNotEmpty(dataTable)) {
Element dataTableElement = doc.createElement("DataTable");
dataTableElement.setAttribute("path", workingDir + SdkConstants.FileSystem.WINDOWS_PATH_SPLITTER + dataTable);
testElement.appendChild(dataTableElement);
}
// add iterations
String iterations = test.getParameter(ITERATIONS_PARAMETER);
if (SdkStringUtils.isNotEmpty(iterations)) {
String[] parts = iterations.split(",");
Element iterationElement = doc.createElement("Iterations");
iterationElement.setAttribute("mode", parts[0].trim());
if (parts.length >= 3) {
iterationElement.setAttribute("start", parts[1].trim());
iterationElement.setAttribute("end", parts[2].trim());
}
testElement.appendChild(iterationElement);
}
rootElement.appendChild(testElement);
}
TransformerFactory tf = TransformerFactory.newInstance();
Transformer transformer = tf.newTransformer();
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
StringWriter writer = new StringWriter();
transformer.transform(new DOMSource(doc), new StreamResult(writer));
return writer.toString();
} catch (ParserConfigurationException | TransformerException e) {
String msg = "Failed to build MTBX content : " + e.getMessage();
logger.error(msg);
throw new RuntimeException(msg);
}
}
use of com.hp.octane.integrations.executor.TestToRunData in project octane-ci-java-sdk by MicroFocus.
the class MfMBTConverter method handleMBTModel.
private void handleMBTModel(List<TestToRunData> tests, String checkoutFolder, Map<String, String> globalParameters) {
// replace test name if required
for (TestToRunData data : tests) {
data.setTestName(encodeTestNameIfRequired(data.getTestName()));
}
mbtTests = new ArrayList<>();
int order = 1;
for (TestToRunData data : tests) {
String mbtDataRaw = data.getParameter(MBT_DATA);
MbtData mbtData;
if (MBT_DATA_NOT_INCLUDED.equals(mbtDataRaw)) {
throw new RuntimeException("Failed to fetch mbt data for test " + data.getTestName());
}
try {
String raw = new String(Base64.getDecoder().decode(mbtDataRaw), StandardCharsets.UTF_8);
mbtData = DTOFactory.getInstance().dtoFromJson(raw, MbtData.class);
if (mbtData.getTestingToolType().equals(TestingToolType.UFT)) {
// advance package name only for uft tests. it is not relevant for codeless tests
data.setPackageName("_" + order++);
}
} catch (Exception e) {
String msg = "Failed to decode test action data " + data.getTestName() + " : " + e.getMessage();
logger.error(msg);
throw new RuntimeException(msg);
}
if (mbtData.getTestingToolType().equals(TestingToolType.UFT)) {
convertUftTest(checkoutFolder, data, mbtData);
} else {
convertCodelessTest(data, mbtData);
}
}
}
use of com.hp.octane.integrations.executor.TestToRunData in project octane-ci-java-sdk by MicroFocus.
the class MfMBTConverter method handleMbtDataRetrieval.
private void handleMbtDataRetrieval(List<TestToRunData> tests, Map<String, String> globalParameters) {
if (shouldRetrieveMbtData(tests)) {
OctaneClient octaneClient = OctaneSDK.getClientByInstanceId(globalParameters.get(OCTANE_CONFIG_ID_PARAMETER_NAME));
OctaneConfiguration octaneConfig = octaneClient.getConfigurationService().getConfiguration();
String url = octaneConfig.getUrl() + "/api" + "/shared_spaces/" + octaneConfig.getSharedSpace() + "/workspaces/" + globalParameters.get(OCTANE_WORKSPACE_PARAMETER_NAME) + "/suite_runs/" + globalParameters.get(SUITE_RUN_ID_PARAMETER_NAME) + "/get_suite_data";
Map<String, String> headers = new HashMap<>();
headers.put(ACCEPT_HEADER, ContentType.APPLICATION_JSON.getMimeType());
headers.put(OctaneRestClient.CLIENT_TYPE_HEADER, OctaneRestClient.CLIENT_TYPE_VALUE);
OctaneRequest request = DTOFactory.getInstance().newDTO(OctaneRequest.class).setMethod(HttpMethod.GET).setHeaders(headers).setUrl(url);
try {
OctaneResponse octaneResponse = octaneClient.getRestService().obtainOctaneRestClient().execute(request);
if (octaneResponse != null && octaneResponse.getStatus() == HttpStatus.SC_OK) {
Map<String, String> parsedResponse = parseSuiteRunDataJson(octaneResponse.getBody());
if (parsedResponse != null) {
for (TestToRunData test : tests) {
String runID = test.getParameter(INNER_RUN_ID_PARAMETER);
test.addParameters(MBT_DATA, parsedResponse.get(runID));
}
}
} else {
logger.error("Failed to get response {}", (octaneResponse != null ? octaneResponse.getStatus() : "(null)"));
return;
}
} catch (IOException e) {
logger.error("Failed to get response ", e);
return;
}
}
}
use of com.hp.octane.integrations.executor.TestToRunData in project octane-ci-java-sdk by MicroFocus.
the class CucumberJVMConverter method convertInternal.
@Override
protected String convertInternal(List<TestToRunData> data, String executionDirectory, Map<String, String> globalParameters) {
StringBuilder sb = new StringBuilder();
String classJoiner = "";
for (TestToRunData testData : data) {
String featureFilePath = getFeatureFilePath(testData);
if (featureFilePath != null && !featureFilePath.isEmpty()) {
sb.append(classJoiner);
sb.append("'");
sb.append(featureFilePath);
sb.append("'");
classJoiner = " ";
}
}
return sb.toString();
}
Aggregations