Search in sources :

Example 71 with TestFailException

use of com.sequenceiq.it.cloudbreak.exception.TestFailException in project cloudbreak by hortonworks.

the class WaitFailedChecker method refresh.

@Override
public void refresh(T waitObject) {
    try {
        waitObject.fetchData();
        failed = false;
    } catch (NotFoundException e) {
        LOGGER.warn("No {} found with name: {}", waitObject.getClass().getSimpleName(), waitObject.getName(), e);
        failed = true;
    } catch (Exception e) {
        LOGGER.error("Failed to get {} status or statusReason: {}", waitObject.getClass().getSimpleName(), e.getMessage(), e);
        throw new TestFailException("Failed to get " + waitObject.getClass().getSimpleName() + " status or statusReason", e);
    }
}
Also used : TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) NotFoundException(javax.ws.rs.NotFoundException) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) NotFoundException(javax.ws.rs.NotFoundException)

Example 72 with TestFailException

use of com.sequenceiq.it.cloudbreak.exception.TestFailException in project cloudbreak by hortonworks.

the class FreeIpaFindUsersAction method action.

public FreeIpaTestDto action(TestContext testContext, FreeIpaTestDto testDto, FreeIpaClient client) throws Exception {
    CheckUsersV1Request checkUsersRequest = new CheckUsersV1Request();
    checkUsersRequest.setEnvironmentCrn(testDto.getResponse().getEnvironmentCrn());
    checkUsersRequest.setUsers(users);
    Log.when(LOGGER, format(" Checking users [%s] are present at environment '%s'", users, testDto.getResponse().getEnvironmentCrn()));
    Log.whenJson(LOGGER, format(" FreeIpa '%s' find users request:%n ", testDto.getResponse().getCrn()), checkUsersRequest);
    if (expectedPresence) {
        if (!client.getDefaultClient().getClientTestV1Endpoint().checkUsers(checkUsersRequest).getResult()) {
            throw new TestFailException("Given freeipa users cannot be found, please check FMS logs for details!");
        }
        LOGGER.info(format(" Users [%s] are present at environment '%s'", users, testDto.getResponse().getEnvironmentCrn()));
        Log.when(LOGGER, format(" Users [%s] are present at environment '%s'", users, testDto.getResponse().getEnvironmentCrn()));
    } else {
        if (client.getDefaultClient().getClientTestV1Endpoint().checkUsers(checkUsersRequest).getResult()) {
            throw new TestFailException("Given freeipa users have been found, please check FMS logs for details!");
        }
        LOGGER.info(format(" Users [%s] have been removed successfully from environment '%s'", users, testDto.getResponse().getEnvironmentCrn()));
        Log.when(LOGGER, format(" Users [%s] have been removed successfully from environment '%s'", users, testDto.getResponse().getEnvironmentCrn()));
    }
    return testDto;
}
Also used : TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) CheckUsersV1Request(com.sequenceiq.freeipa.api.v1.freeipa.test.model.CheckUsersV1Request)

Example 73 with TestFailException

use of com.sequenceiq.it.cloudbreak.exception.TestFailException in project cloudbreak by hortonworks.

the class AbstractUmsAction method action.

@Override
public U action(TestContext testContext, U testDto, UmsClient client) throws Exception {
    Exception umsActionException = null;
    int retries = 0;
    int maxRetry = 10;
    long pollingInterval = 7000;
    while (retries <= maxRetry) {
        try {
            return umsAction(testContext, testDto, client);
        } catch (Exception e) {
            umsActionException = e;
            Thread.sleep(pollingInterval);
            retries++;
        }
    }
    if (umsActionException != null) {
        throw new TestFailException(String.format("EXCEEDING UMS ACTION MAX. RETRY (%s) ::: UMS action has been failed, because of: %s%n", retries, umsActionException.getMessage()), umsActionException);
    } else {
        throw new TestFailException(String.format("EXCEEDING UMS ACTION MAX. RETRY (%s) ::: UMS action has been failed!", retries));
    }
}
Also used : TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException)

Example 74 with TestFailException

use of com.sequenceiq.it.cloudbreak.exception.TestFailException in project cloudbreak by hortonworks.

the class TestContext method exceptionValidation.

private <E extends Exception> void exceptionValidation(Class<E> expectedException, Exception actualException, String entityKey, RunningParameter runningParameter, String stepKey) {
    if (!actualException.getClass().equals(expectedException)) {
        String message = String.format("Expected exception (%s) does not match with the actual exception (%s).", expectedException, actualException.getClass());
        getExceptionMap().put(stepKey, new TestFailException(message));
        LOGGER.error(message);
        htmlLoggerForExceptionValidation(message, stepKey);
    } else if (!isMessageEquals(actualException, runningParameter) || !isPayloadEquals(actualException, runningParameter)) {
        List<String> messages = new ArrayList<>();
        if (!isMessageEquals(actualException, runningParameter)) {
            messages.add(String.format("Expected exception message (%s) does not match with the actual exception message (%s).", runningParameter.getExpectedMessage(), ResponseUtil.getErrorMessage(actualException)));
        }
        if (!isPayloadEquals(actualException, runningParameter)) {
            messages.add(String.format("Expected exception payload (%s) does not match with the actual exception payload (%s).", runningParameter.getExpectedPayload(), ResponseUtil.getErrorPayload(actualException)));
        }
        String message = String.join("\n", messages);
        getExceptionMap().put(stepKey, new TestFailException(message));
        LOGGER.error(message);
        htmlLoggerForExceptionValidation(message, stepKey);
    } else {
        String message = String.format("Expected exception conditions have met, exception: %s, message: %s", expectedException, runningParameter.getExpectedMessage());
        getExceptionMap().remove(entityKey);
        LOGGER.info(message);
        htmlLoggerForExceptionValidation(message, stepKey);
    }
}
Also used : TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) List(java.util.List) ArrayList(java.util.ArrayList)

Example 75 with TestFailException

use of com.sequenceiq.it.cloudbreak.exception.TestFailException in project cloudbreak by hortonworks.

the class TestContext method thenException.

public <E extends Exception, T extends CloudbreakTestDto> T thenException(T entity, Class<? extends MicroserviceClient> clientClass, Assertion<T, ? extends MicroserviceClient> assertion, Class<E> expectedException, RunningParameter runningParameter) {
    checkShutdown();
    String key = getKey(assertion.getClass(), runningParameter);
    if (!getExceptionMap().isEmpty() && runningParameter.isSkipOnFail()) {
        LOGGER.info("Should be skipped because of previous error. when [{}]", key);
        return entity;
    }
    CloudbreakUser who = setActingUser(runningParameter);
    LOGGER.info("then exception {} action on {} by {}, name: {}", key, entity, who, entity.getName());
    Log.thenException(LOGGER, assertion.getClass().getSimpleName() + " exception assertion on " + entity + " by " + who);
    try {
        String message = String.format("Expected exception with message (%s) has not been thrown!", runningParameter.getExpectedMessage());
        CloudbreakTestDto cloudbreakTestDto = resourceNames.get(key);
        if (cloudbreakTestDto != null) {
            assertion.doAssertion(this, (T) cloudbreakTestDto, getMicroserviceClient(entity.getClass(), who.getAccessKey()));
        } else {
            assertion.doAssertion(this, entity, getMicroserviceClient(entity.getClass(), who.getAccessKey()));
        }
        getExceptionMap().put("thenException", new TestFailException(message));
        LOGGER.error(message);
        htmlLoggerForExceptionValidation(message, "thenException");
    } catch (Exception e) {
        exceptionValidation(expectedException, e, key, runningParameter, "thenException");
    }
    return entity;
}
Also used : CloudbreakTestDto(com.sequenceiq.it.cloudbreak.dto.CloudbreakTestDto) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) CloudbreakUser(com.sequenceiq.it.cloudbreak.actor.CloudbreakUser) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) BeansException(org.springframework.beans.BeansException)

Aggregations

TestFailException (com.sequenceiq.it.cloudbreak.exception.TestFailException)101 List (java.util.List)15 Inject (javax.inject.Inject)14 Map (java.util.Map)13 Description (com.sequenceiq.it.cloudbreak.context.Description)12 TestContext (com.sequenceiq.it.cloudbreak.context.TestContext)12 Logger (org.slf4j.Logger)12 LoggerFactory (org.slf4j.LoggerFactory)12 Test (org.testng.annotations.Test)12 DistroXTestDto (com.sequenceiq.it.cloudbreak.dto.distrox.DistroXTestDto)10 WebApplicationException (javax.ws.rs.WebApplicationException)10 Log (com.sequenceiq.it.cloudbreak.log.Log)9 String.format (java.lang.String.format)9 Collectors (java.util.stream.Collectors)9 FreeIpaTestDto (com.sequenceiq.it.cloudbreak.dto.freeipa.FreeIpaTestDto)8 SdxTestDto (com.sequenceiq.it.cloudbreak.dto.sdx.SdxTestDto)8 IOException (java.io.IOException)8 URISyntaxException (java.net.URISyntaxException)8 ArrayList (java.util.ArrayList)8 Set (java.util.Set)8