Search in sources :

Example 1 with TestCaseDescription

use of com.sequenceiq.it.cloudbreak.context.TestCaseDescription in project cloudbreak by hortonworks.

the class MultiThreadTenantTest method collectTestCaseDescription.

private TestCaseDescription collectTestCaseDescription(MockedTestContext testContext, Method method, Object[] params) {
    Description declaredAnnotation = method.getDeclaredAnnotation(Description.class);
    TestCaseDescription testCaseDescription = null;
    if (declaredAnnotation != null) {
        testCaseDescription = new TestCaseDescriptionBuilder().given(declaredAnnotation.given()).when(declaredAnnotation.when()).then(declaredAnnotation.then());
        testContext.addDescription(testCaseDescription);
    } else if (method.getParameters().length == params.length) {
        Parameter[] parameters = method.getParameters();
        for (int i = 1; i < parameters.length; i++) {
            if (parameters[i].getAnnotation(Description.class) != null) {
                Object param = params[i];
                if (!(param instanceof TestCaseDescription)) {
                    throw new IllegalArgumentException("The param annotated with @Description but the type is should be " + TestCaseDescription.class.getSimpleName());
                }
                testCaseDescription = (TestCaseDescription) param;
                testContext.addDescription(testCaseDescription);
                break;
            }
        }
    }
    return Optional.ofNullable(testCaseDescription).filter(d -> !Strings.isNullOrEmpty(d.getValue())).orElseThrow(() -> new TestCaseDescriptionMissingException(method.getName()));
}
Also used : ImageCatalogTestClient(com.sequenceiq.it.cloudbreak.client.ImageCatalogTestClient) FreeIpaTestDto(com.sequenceiq.it.cloudbreak.dto.freeipa.FreeIpaTestDto) LoggerFactory(org.slf4j.LoggerFactory) Test(org.testng.annotations.Test) AfterMethod(org.testng.annotations.AfterMethod) IntegrationTestConfiguration(com.sequenceiq.it.config.IntegrationTestConfiguration) Description(com.sequenceiq.it.cloudbreak.context.Description) EnvironmentNetworkTestDto(com.sequenceiq.it.cloudbreak.dto.environment.EnvironmentNetworkTestDto) Map(java.util.Map) ThreadLocalProfiles(com.sequenceiq.it.cloudbreak.mock.ThreadLocalProfiles) TestCaseDescription(com.sequenceiq.it.cloudbreak.context.TestCaseDescription) Method(java.lang.reflect.Method) AbstractTestNGSpringContextTests(org.springframework.test.context.testng.AbstractTestNGSpringContextTests) MockedTestContext(com.sequenceiq.it.cloudbreak.context.MockedTestContext) TestCaseDescriptionMissingException(com.sequenceiq.it.cloudbreak.exception.TestCaseDescriptionMissingException) BeforeMethod(org.testng.annotations.BeforeMethod) Status(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status) DistroXTestClient(com.sequenceiq.it.cloudbreak.client.DistroXTestClient) Optional(java.util.Optional) EnvironmentStatus(com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentStatus) BlueprintTestDto(com.sequenceiq.it.cloudbreak.dto.blueprint.BlueprintTestDto) SdxClusterStatusResponse(com.sequenceiq.sdx.api.model.SdxClusterStatusResponse) ImageCatalogTestDto(com.sequenceiq.it.cloudbreak.dto.imagecatalog.ImageCatalogTestDto) ImageCatalogCreateRetryAction(com.sequenceiq.it.cloudbreak.action.v4.imagecatalog.ImageCatalogCreateRetryAction) CredentialTestDto(com.sequenceiq.it.cloudbreak.dto.credential.CredentialTestDto) DataProvider(org.testng.annotations.DataProvider) TracerAutoConfiguration(io.opentracing.contrib.spring.tracer.configuration.TracerAutoConfiguration) ITestResult(org.testng.ITestResult) TestCaseDescriptionBuilder(com.sequenceiq.it.cloudbreak.context.TestCaseDescription.TestCaseDescriptionBuilder) Inject(javax.inject.Inject) SdxInternalTestDto(com.sequenceiq.it.cloudbreak.dto.sdx.SdxInternalTestDto) Strings(com.google.common.base.Strings) ConfigFileApplicationContextInitializer(org.springframework.boot.test.context.ConfigFileApplicationContextInitializer) Parameter(java.lang.reflect.Parameter) CredentialTestClient(com.sequenceiq.it.cloudbreak.client.CredentialTestClient) ResourcePropertyProvider(com.sequenceiq.it.cloudbreak.ResourcePropertyProvider) AfterClass(org.testng.annotations.AfterClass) BlueprintTestClient(com.sequenceiq.it.cloudbreak.client.BlueprintTestClient) Logger(org.slf4j.Logger) TestContext(com.sequenceiq.it.cloudbreak.context.TestContext) BeansException(org.springframework.beans.BeansException) SdxTestClient(com.sequenceiq.it.cloudbreak.client.SdxTestClient) DistroXTestDto(com.sequenceiq.it.cloudbreak.dto.distrox.DistroXTestDto) FreeIpaTestClient(com.sequenceiq.it.cloudbreak.client.FreeIpaTestClient) EnvironmentTestClient(com.sequenceiq.it.cloudbreak.client.EnvironmentTestClient) EnvironmentTestDto(com.sequenceiq.it.cloudbreak.dto.environment.EnvironmentTestDto) CloudbreakActor(com.sequenceiq.it.cloudbreak.actor.CloudbreakActor) MDC(org.slf4j.MDC) ContextConfiguration(org.springframework.test.context.ContextConfiguration) TestCaseDescriptionMissingException(com.sequenceiq.it.cloudbreak.exception.TestCaseDescriptionMissingException) Description(com.sequenceiq.it.cloudbreak.context.Description) TestCaseDescription(com.sequenceiq.it.cloudbreak.context.TestCaseDescription) TestCaseDescriptionBuilder(com.sequenceiq.it.cloudbreak.context.TestCaseDescription.TestCaseDescriptionBuilder) TestCaseDescription(com.sequenceiq.it.cloudbreak.context.TestCaseDescription)

Example 2 with TestCaseDescription

use of com.sequenceiq.it.cloudbreak.context.TestCaseDescription in project cloudbreak by hortonworks.

the class AbstractMinimalTest method collectTestCaseDescription.

private TestCaseDescription collectTestCaseDescription(TestContext testContext, Method method, Object[] params) {
    Description declaredAnnotation = method.getDeclaredAnnotation(Description.class);
    TestCaseDescription testCaseDescription = null;
    if (declaredAnnotation != null) {
        testCaseDescription = new TestCaseDescriptionBuilder().given(declaredAnnotation.given()).when(declaredAnnotation.when()).then(declaredAnnotation.then());
        testContext.addDescription(testCaseDescription);
    } else if (method.getParameters().length == params.length) {
        Parameter[] parameters = method.getParameters();
        for (int i = 1; i < parameters.length; i++) {
            if (parameters[i].getAnnotation(Description.class) != null) {
                Object param = params[i];
                if (!(param instanceof TestCaseDescription)) {
                    throw new IllegalArgumentException("The param annotated with @Description but the type is should be " + TestCaseDescription.class.getSimpleName());
                }
                testCaseDescription = (TestCaseDescription) param;
                testContext.addDescription(testCaseDescription);
                break;
            }
        }
    }
    return Optional.ofNullable(testCaseDescription).filter(d -> !Strings.isNullOrEmpty(d.getValue())).orElseThrow(() -> new TestCaseDescriptionMissingException(method.getName()));
}
Also used : BeforeSuite(org.testng.annotations.BeforeSuite) DataProvider(org.testng.annotations.DataProvider) E2ETestContext(com.sequenceiq.it.cloudbreak.context.E2ETestContext) LoggerFactory(org.slf4j.LoggerFactory) AfterMethod(org.testng.annotations.AfterMethod) TracerAutoConfiguration(io.opentracing.contrib.spring.tracer.configuration.TracerAutoConfiguration) ITestResult(org.testng.ITestResult) IntegrationTestConfiguration(com.sequenceiq.it.config.IntegrationTestConfiguration) Description(com.sequenceiq.it.cloudbreak.context.Description) TestCaseDescriptionBuilder(com.sequenceiq.it.cloudbreak.context.TestCaseDescription.TestCaseDescriptionBuilder) AuditBeanConfig(com.sequenceiq.it.config.AuditBeanConfig) LongStringGeneratorUtil(com.sequenceiq.it.util.LongStringGeneratorUtil) Inject(javax.inject.Inject) Value(org.springframework.beans.factory.annotation.Value) Strings(com.google.common.base.Strings) ConfigFileApplicationContextInitializer(org.springframework.boot.test.context.ConfigFileApplicationContextInitializer) Parameter(java.lang.reflect.Parameter) Map(java.util.Map) PurgeGarbageService(com.sequenceiq.it.cloudbreak.context.PurgeGarbageService) CommonCloudProperties(com.sequenceiq.it.cloudbreak.cloud.v4.CommonCloudProperties) ThreadLocalProfiles(com.sequenceiq.it.cloudbreak.mock.ThreadLocalProfiles) TestCaseDescription(com.sequenceiq.it.cloudbreak.context.TestCaseDescription) Method(java.lang.reflect.Method) MeasuredTestContext.createMeasuredTestContext(com.sequenceiq.it.cloudbreak.context.MeasuredTestContext.createMeasuredTestContext) AbstractTestNGSpringContextTests(org.springframework.test.context.testng.AbstractTestNGSpringContextTests) ResourcePropertyProvider(com.sequenceiq.it.cloudbreak.ResourcePropertyProvider) MeasuredTestContext(com.sequenceiq.it.cloudbreak.context.MeasuredTestContext) AfterClass(org.testng.annotations.AfterClass) MockedTestContext(com.sequenceiq.it.cloudbreak.context.MockedTestContext) Logger(org.slf4j.Logger) TestContext(com.sequenceiq.it.cloudbreak.context.TestContext) TestCaseDescriptionMissingException(com.sequenceiq.it.cloudbreak.exception.TestCaseDescriptionMissingException) ITestContext(org.testng.ITestContext) BeforeClass(org.testng.annotations.BeforeClass) BeforeMethod(org.testng.annotations.BeforeMethod) Status(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status) BeansException(org.springframework.beans.BeansException) CommonClusterManagerProperties(com.sequenceiq.it.cloudbreak.cloud.v4.CommonClusterManagerProperties) MDC(org.slf4j.MDC) ContextConfiguration(org.springframework.test.context.ContextConfiguration) Optional(java.util.Optional) TestCaseDescriptionMissingException(com.sequenceiq.it.cloudbreak.exception.TestCaseDescriptionMissingException) Description(com.sequenceiq.it.cloudbreak.context.Description) TestCaseDescription(com.sequenceiq.it.cloudbreak.context.TestCaseDescription) TestCaseDescriptionBuilder(com.sequenceiq.it.cloudbreak.context.TestCaseDescription.TestCaseDescriptionBuilder) TestCaseDescription(com.sequenceiq.it.cloudbreak.context.TestCaseDescription)

Aggregations

Strings (com.google.common.base.Strings)2 Status (com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status)2 ResourcePropertyProvider (com.sequenceiq.it.cloudbreak.ResourcePropertyProvider)2 Description (com.sequenceiq.it.cloudbreak.context.Description)2 MockedTestContext (com.sequenceiq.it.cloudbreak.context.MockedTestContext)2 TestCaseDescription (com.sequenceiq.it.cloudbreak.context.TestCaseDescription)2 TestCaseDescriptionBuilder (com.sequenceiq.it.cloudbreak.context.TestCaseDescription.TestCaseDescriptionBuilder)2 TestContext (com.sequenceiq.it.cloudbreak.context.TestContext)2 TestCaseDescriptionMissingException (com.sequenceiq.it.cloudbreak.exception.TestCaseDescriptionMissingException)2 ThreadLocalProfiles (com.sequenceiq.it.cloudbreak.mock.ThreadLocalProfiles)2 IntegrationTestConfiguration (com.sequenceiq.it.config.IntegrationTestConfiguration)2 TracerAutoConfiguration (io.opentracing.contrib.spring.tracer.configuration.TracerAutoConfiguration)2 Method (java.lang.reflect.Method)2 Parameter (java.lang.reflect.Parameter)2 Map (java.util.Map)2 Optional (java.util.Optional)2 Inject (javax.inject.Inject)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 MDC (org.slf4j.MDC)2