use of com.hp.octane.integrations.dto.entities.Entity in project octane-ci-java-sdk by MicroFocus.
the class UftDiscoveryResultPreparerImpl method matchDiscoveryTestResultsWithOctaneForFullSync.
/**
* This method check whether discovered test are already exist on server, and instead of creation - those tests will be updated
* Go over discovered and octane tests
* 1.if test doesn't exist on octane - this is new test
* 2.if test exist
* 2.1 if test different from discovered - this is test for update
* 2.2 if tests are equal - skip test
* 3. all tests that are found in Octane but not discovered - those deleted tests and they will be turned to not executable
*
* @return true if there were changes comparing to discovered results
*/
private void matchDiscoveryTestResultsWithOctaneForFullSync(EntitiesService entitiesService, UftTestDiscoveryResult discoveryResult) {
Collection<String> additionalFields = SdkStringUtils.isNotEmpty(discoveryResult.getTestRunnerId()) ? Arrays.asList(EntityConstants.AutomatedTest.TEST_RUNNER_FIELD) : null;
Map<String, Entity> octaneTestsMap = getTestsFromServer(entitiesService, Long.parseLong(discoveryResult.getWorkspaceId()), Long.parseLong(discoveryResult.getScmRepositoryId()), true, null, additionalFields);
Map<String, Entity> octaneTestsMapWithoutScmRepository = getTestsFromServer(entitiesService, Long.parseLong(discoveryResult.getWorkspaceId()), Long.parseLong(discoveryResult.getScmRepositoryId()), false, null, additionalFields);
for (AutomatedTest discoveredTest : discoveryResult.getAllTests()) {
String key = createKey(discoveredTest.getPackage(), discoveredTest.getName());
Entity octaneTest = octaneTestsMap.remove(key);
Entity octaneTestWithoutScmRepository = octaneTestsMapWithoutScmRepository.remove(key);
if (octaneTest != null) {
// the only fields that might be different is description and executable
boolean testsEqual = checkTestEquals(discoveredTest, octaneTest, discoveryResult.getTestRunnerId());
if (!testsEqual) {
// if equal - skip
discoveredTest.setId(octaneTest.getId());
discoveredTest.setOctaneStatus(OctaneStatus.MODIFIED);
if (octaneTest.containsField(EntityConstants.AutomatedTest.TEST_RUNNER_FIELD) && octaneTest.getField(EntityConstants.AutomatedTest.TEST_RUNNER_FIELD) == null) {
discoveredTest.setMissingTestRunner(true);
}
} else {
discoveredTest.setOctaneStatus(OctaneStatus.NONE);
}
} else if (octaneTestWithoutScmRepository != null) {
// special handling - test were injected from pipeline,or created from other fork. need to update scm repository
discoveredTest.setId(octaneTestWithoutScmRepository.getId());
discoveredTest.setOctaneStatus(OctaneStatus.MODIFIED);
if (octaneTestWithoutScmRepository.containsField(EntityConstants.AutomatedTest.TEST_RUNNER_FIELD) && octaneTestWithoutScmRepository.getField(EntityConstants.AutomatedTest.TEST_RUNNER_FIELD) == null) {
discoveredTest.setMissingTestRunner(true);
}
discoveredTest.setMissingScmRepository(true);
}
// else do nothing, status of test should remain NEW
}
// go over executable tests that exist in Octane but not discovered and disable them
for (Entity octaneTest : octaneTestsMap.values()) {
boolean octaneExecutable = octaneTest.getBooleanValue(EntityConstants.AutomatedTest.EXECUTABLE_FIELD);
if (octaneExecutable) {
AutomatedTest test = new AutomatedTest();
discoveryResult.getAllTests().add(test);
test.setId(octaneTest.getId());
test.setExecutable(false);
test.setName(octaneTest.getName());
test.setPackage(octaneTest.getStringValue(EntityConstants.AutomatedTest.PACKAGE_FIELD));
test.setOctaneStatus(OctaneStatus.DELETED);
}
}
}
use of com.hp.octane.integrations.dto.entities.Entity in project octane-ci-java-sdk by MicroFocus.
the class TestExecutionServiceImpl method planSuiteRuns.
private List<Entity> planSuiteRuns(Long workspaceId, List<Long> suiteIds, Entity release, String suiteRunName) {
Map<Long, String> suiteNames = SdkStringUtils.isNotEmpty(suiteRunName) ? Collections.emptyMap() : this.validateAllSuiteIdsExistAndReturnSuiteNames(workspaceId, suiteIds);
Entity status = dtoFactory.newDTO(Entity.class).setType(EntityConstants.Lists.ENTITY_NAME).setId("list_node.run_native_status.planned");
List<Entity> suiteRuns = suiteIds.stream().map(suiteId -> {
Entity test = dtoFactory.newDTO(Entity.class).setType(EntityConstants.Test.ENTITY_NAME).setId(Long.toString(suiteId));
Entity suiteRun = dtoFactory.newDTO(Entity.class).setField(EntityConstants.Run.NAME_FIELD, SdkStringUtils.isNotEmpty(suiteRunName) ? suiteRunName : suiteNames.get(suiteId)).setField(EntityConstants.Run.SUBTYPE_FIELD, "run_suite").setField(EntityConstants.Run.RELEASE_FIELD, release).setField(EntityConstants.Run.TEST_FIELD, test).setField(EntityConstants.Run.NATIVE_STATUS_FIELD, status);
return suiteRun;
}).collect(Collectors.toList());
List<Entity> entities = entitiesService.postEntities(workspaceId, EntityConstants.Run.COLLECTION_NAME, suiteRuns, Arrays.asList(EntityConstants.Run.TEST_FIELD), Collections.singletonMap("is_atomic_creation", "true"));
return entities;
}
use of com.hp.octane.integrations.dto.entities.Entity 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.dto.entities.Entity in project octane-ci-java-sdk by MicroFocus.
the class SonarVulnerabilitiesServiceImpl method createClosedOctaneIssue.
private OctaneIssue createClosedOctaneIssue(String remoteId) {
Entity closedListNodeEntity = SSCToOctaneIssueUtil.createListNodeEntity(ISSUE_STATE_CLOSED);
OctaneIssueImpl octaneIssue = new OctaneIssueImpl();
octaneIssue.setRemoteId(remoteId);
octaneIssue.setState(closedListNodeEntity);
return octaneIssue;
}
use of com.hp.octane.integrations.dto.entities.Entity in project octane-ci-java-sdk by MicroFocus.
the class VulnerabilitiesGeneralUtils method createClosedOctaneIssue.
public static OctaneIssue createClosedOctaneIssue(String remoteId) {
Entity closedListNodeEntity = createListNodeEntity(OctaneIssueConsts.ISSUE_STATE_CLOSED);
OctaneIssueImpl octaneIssue = new OctaneIssueImpl();
octaneIssue.setRemoteId(remoteId);
octaneIssue.setState(closedListNodeEntity);
return octaneIssue;
}
Aggregations