use of com.sequenceiq.it.cloudbreak.dto.CloudbreakTestDto in project cloudbreak by hortonworks.
the class TestContext method awaitWithClient.
private <T extends CloudbreakTestDto, E extends Enum<E>> T awaitWithClient(T entity, Map<String, E> desiredStatuses, RunningParameter runningParameter, MicroserviceClient client) {
checkShutdown();
String key = getKeyForAwait(entity, entity.getClass(), runningParameter);
CloudbreakTestDto awaitEntity = get(key);
if (awaitEntity == null) {
awaitEntity = entity;
}
if (runningParameter.isWaitForFlow()) {
awaitForFlow(awaitEntity, runningParameter);
}
try {
resourceCrns.put(awaitEntity.getCrn(), awaitEntity);
LOGGER.info("Resource Crn: '{}' by '{}' has been put to resource Crns map.", awaitEntity.getCrn(), awaitEntity.getName());
} catch (IllegalStateException | NullPointerException e) {
LOGGER.info("Resource Crn is not available for: {}", awaitEntity.getName());
}
if (!getExceptionMap().isEmpty() && runningParameter.isSkipOnFail()) {
Log.await(LOGGER, String.format("Cloudbreak await should be skipped because of previous error. await [%s]", desiredStatuses));
} else {
resourceAwait.await(awaitEntity, desiredStatuses, getTestContext(), runningParameter, flowUtilSingleStatus.getPollingDurationOrTheDefault(runningParameter), maxRetry, maxRetryCount, client);
}
return entity;
}
use of com.sequenceiq.it.cloudbreak.dto.CloudbreakTestDto in project cloudbreak by hortonworks.
the class TestInvocationListener method afterInvocation.
/**
* Collects all the available test resources to a JSON file based on the:
* - Related test DTO: provides a resource name type (eg.: environmentName),
* - Test Context: provides the resource's unique name (eg.: aws-test-039df4d8aec04a61965).
*
* Resource files can be saved based on the test cases (eg.: resource_names_testCreateNewEnvironmentWithNewNetworkAndNoInternet);
* because of each test has it's own Test Context, that has been built by the Given test steps for that thread of test execution.
*/
@Override
public void afterInvocation(IInvokedMethod invokedMethod, ITestResult testResult) {
TestContext testContext;
JSONObject jsonObject = new JSONObject();
Object[] parameters = testResult.getParameters();
if (parameters == null || parameters.length == 0) {
LOGGER.warn("Test context could not be found because parameters array is empty in test result.");
return;
}
try {
testContext = (TestContext) parameters[0];
} catch (ClassCastException e) {
LOGGER.warn("Test context could not be casted from test result parameters.");
return;
}
List<CloudbreakTestDto> testDtos = new ArrayList<>(testContext.getResourceNames().values());
List<CloudbreakTestDto> orderedTestDtos = testDtos.stream().sorted(new CompareByOrder()).collect(Collectors.toList());
for (CloudbreakTestDto testDto : orderedTestDtos) {
try {
String resourceNameType = Optional.ofNullable(testDto.getResourceNameType()).orElse("");
if (!resourceNameType.trim().isEmpty()) {
if (jsonObject.has(resourceNameType)) {
List<String> resourceNames = new ArrayList<>();
try {
JSONArray resources = jsonObject.getJSONArray(resourceNameType);
for (int i = 0; i < resources.length(); i++) {
String resource = resources.getString(i);
resourceNames.add(resource);
}
} catch (JSONException e) {
String resource = jsonObject.getString(resourceNameType);
resourceNames.add(resource);
}
resourceNames.add(testDto.getName());
LOGGER.info("Created resource name array: '{}'.", resourceNames);
JSONArray resourceNameArray = new JSONArray(resourceNames);
jsonObject.put(resourceNameType, resourceNameArray);
} else {
jsonObject.put(resourceNameType, testDto.getName());
}
LOGGER.info("Put Resource Name: '{}' to JSON Object.", testDto.getName());
}
} catch (Exception e) {
LOGGER.info("Appending JSON object is failing, because of: {}", e.getMessage(), e);
}
}
if (jsonObject.length() != 0) {
String fileName = "resource_names_" + testContext.getTestMethodName().orElseGet(this::getDefaultFileNameTag) + ".json";
try {
Files.writeString(Paths.get(fileName), jsonObject.toString());
LOGGER.info("Resource file have been created with name: {} and content: {}.", fileName, jsonObject);
} catch (IOException e) {
LOGGER.info("Creating/Appending resource file throws exception: {}", e.getMessage(), e);
} catch (Exception e) {
LOGGER.info("Creating/Appending resource file is failing, because of: {}", e.getMessage(), e);
}
} else {
LOGGER.info("No resources found, no output file needs to be created.");
}
}
Aggregations