Search in sources :

Example 1 with TestToRunDataCollection

use of com.hp.octane.integrations.executor.TestToRunDataCollection 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);
}
Also used : Entity(com.hp.octane.integrations.dto.entities.Entity) TestToRunDataCollection(com.hp.octane.integrations.executor.TestToRunDataCollection) TestToRunData(com.hp.octane.integrations.executor.TestToRunData) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Entity (com.hp.octane.integrations.dto.entities.Entity)1 TestToRunData (com.hp.octane.integrations.executor.TestToRunData)1 TestToRunDataCollection (com.hp.octane.integrations.executor.TestToRunDataCollection)1