Search in sources :

Example 6 with TagsV4Response

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.tags.TagsV4Response in project cloudbreak by hortonworks.

the class StackToStackV4ResponseConverter method getTags.

private TagsV4Response getTags(Json tag) {
    try {
        if (tag != null && tag.getValue() != null) {
            StackTags stackTag = tag.get(StackTags.class);
            return stackTagsToTagsV4ResponseConverter.convert(stackTag);
        }
    } catch (Exception e) {
        LOGGER.info("Failed to convert dynamic tags.", e);
    }
    TagsV4Response response = new TagsV4Response();
    response.setApplication(new HashMap<>());
    response.setDefaults(new HashMap<>());
    response.setUserDefined(new HashMap<>());
    return response;
}
Also used : StackTags(com.sequenceiq.cloudbreak.cloud.model.StackTags) TagsV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.tags.TagsV4Response) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)

Example 7 with TagsV4Response

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.tags.TagsV4Response in project cloudbreak by hortonworks.

the class TagsUtilTest method verifyCreatorWithCdpCrnButTestContextHasAltusCrn.

@Test
void verifyCreatorWithCdpCrnButTestContextHasAltusCrn() {
    DistroXTestDto testDto = new DistroXTestDto(mock(TestContext.class));
    StackV4Response response = new StackV4Response();
    TagsV4Response tags = new TagsV4Response();
    tags.setUserDefined(Map.of(TagsUtil.TEST_NAME_TAG, TEST_NAME));
    tags.setDefaults(DEFAULT_TAGS);
    response.setTags(tags);
    testDto.setResponse(response);
    when(testContext.getActingUserCrn()).thenReturn(Crn.fromString("crn:altus:iam:us-west-1:qe-gcp:user:cloudbreak-qe@hortonworks.com"));
    when(gcpLabelUtil.transformLabelKeyOrValue(anyString())).thenReturn(CLOUDERA_CREATOR_RESOURCE_NAME_TAG_KEY);
    assertThatCode(() -> underTest.verifyTags(testDto, testContext)).doesNotThrowAnyException();
}
Also used : StackV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response) DistroXTestDto(com.sequenceiq.it.cloudbreak.dto.distrox.DistroXTestDto) MockedTestContext(com.sequenceiq.it.cloudbreak.context.MockedTestContext) TestContext(com.sequenceiq.it.cloudbreak.context.TestContext) TagsV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.tags.TagsV4Response) Test(org.testng.annotations.Test)

Example 8 with TagsV4Response

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.tags.TagsV4Response in project cloudbreak by hortonworks.

the class TagsUtilTest method verifyTagsShouldFailAbstractTestDtoDoesNotHaveAllNeededTags.

@Test
void verifyTagsShouldFailAbstractTestDtoDoesNotHaveAllNeededTags() {
    DistroXTestDto testDto = new DistroXTestDto(mock(TestContext.class));
    StackV4Response response = new StackV4Response();
    TagsV4Response tags = new TagsV4Response();
    tags.setUserDefined(Map.of(TagsUtil.TEST_NAME_TAG, TEST_NAME));
    Map<String, String> defaultTags = new HashMap<>(DEFAULT_TAGS);
    defaultTags.remove("owner");
    tags.setDefaults(defaultTags);
    response.setTags(tags);
    testDto.setResponse(response);
    String expectedMsg = String.format(TagsUtil.TAG_VALUE_IS_NULL_FAILURE_PATTERN, OWNER_TAG_KEY);
    assertThatThrownBy(() -> underTest.verifyTags(testDto, testContext)).hasMessageContaining(expectedMsg).matches(e -> !e.getMessage().contains(TagsUtil.MISSING_TEST_NAME_TAG_MESSAGE)).matches(e -> defaultTags.keySet().stream().noneMatch(tag -> e.getMessage().contains(tag)));
}
Also used : Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) HashMap(java.util.HashMap) Test(org.testng.annotations.Test) GcpLabelUtil(com.sequenceiq.cloudbreak.cloud.gcp.util.GcpLabelUtil) CloudPlatform(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) AbstractTestDto(com.sequenceiq.it.cloudbreak.dto.AbstractTestDto) Map(java.util.Map) TagsV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.tags.TagsV4Response) StackV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response) SdxTestDto(com.sequenceiq.it.cloudbreak.dto.sdx.SdxTestDto) MockedTestContext(com.sequenceiq.it.cloudbreak.context.MockedTestContext) TestContext(com.sequenceiq.it.cloudbreak.context.TestContext) CloudbreakTestDto(com.sequenceiq.it.cloudbreak.dto.CloudbreakTestDto) BeforeMethod(org.testng.annotations.BeforeMethod) ReflectionTestUtils(org.springframework.test.util.ReflectionTestUtils) Mockito.when(org.mockito.Mockito.when) Crn(com.sequenceiq.cloudbreak.auth.crn.Crn) DistroXTestDto(com.sequenceiq.it.cloudbreak.dto.distrox.DistroXTestDto) SdxClusterRequest(com.sequenceiq.sdx.api.model.SdxClusterRequest) Mockito(org.mockito.Mockito) Optional(java.util.Optional) Assertions.assertThatCode(org.assertj.core.api.Assertions.assertThatCode) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Mockito.mock(org.mockito.Mockito.mock) StackV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response) DistroXTestDto(com.sequenceiq.it.cloudbreak.dto.distrox.DistroXTestDto) HashMap(java.util.HashMap) MockedTestContext(com.sequenceiq.it.cloudbreak.context.MockedTestContext) TestContext(com.sequenceiq.it.cloudbreak.context.TestContext) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) TagsV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.tags.TagsV4Response) Test(org.testng.annotations.Test)

Example 9 with TagsV4Response

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.tags.TagsV4Response in project cloudbreak by hortonworks.

the class TagsUtilTest method verifyCreatorAsGcpLabelTransformedValue.

@Test
void verifyCreatorAsGcpLabelTransformedValue() {
    DistroXTestDto testDto = new DistroXTestDto(mock(TestContext.class));
    StackV4Response response = new StackV4Response();
    TagsV4Response tags = new TagsV4Response();
    tags.setUserDefined(Map.of(TagsUtil.TEST_NAME_TAG, TEST_NAME));
    Map<String, String> defaultTags = new HashMap<>(DEFAULT_TAGS);
    defaultTags.put(CLOUDERA_CREATOR_RESOURCE_NAME_TAG_KEY, ACTING_USER_CRN);
    tags.setDefaults(defaultTags);
    response.setTags(tags);
    testDto.setResponse(response);
    when(gcpLabelUtil.transformLabelKeyOrValue(anyString())).thenReturn(CLOUDERA_CREATOR_RESOURCE_NAME_TAG_KEY);
    assertThatCode(() -> underTest.verifyTags(testDto, testContext)).doesNotThrowAnyException();
}
Also used : StackV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response) DistroXTestDto(com.sequenceiq.it.cloudbreak.dto.distrox.DistroXTestDto) HashMap(java.util.HashMap) MockedTestContext(com.sequenceiq.it.cloudbreak.context.MockedTestContext) TestContext(com.sequenceiq.it.cloudbreak.context.TestContext) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) TagsV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.tags.TagsV4Response) Test(org.testng.annotations.Test)

Aggregations

TagsV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.tags.TagsV4Response)9 StackV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response)6 MockedTestContext (com.sequenceiq.it.cloudbreak.context.MockedTestContext)6 TestContext (com.sequenceiq.it.cloudbreak.context.TestContext)6 DistroXTestDto (com.sequenceiq.it.cloudbreak.dto.distrox.DistroXTestDto)6 Test (org.testng.annotations.Test)6 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 HashMap (java.util.HashMap)3 StackTags (com.sequenceiq.cloudbreak.cloud.model.StackTags)2 Crn (com.sequenceiq.cloudbreak.auth.crn.Crn)1 GcpLabelUtil (com.sequenceiq.cloudbreak.cloud.gcp.util.GcpLabelUtil)1 CloudbreakServiceException (com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)1 CloudPlatform (com.sequenceiq.cloudbreak.common.mappable.CloudPlatform)1 CloudbreakImageNotFoundException (com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException)1 AbstractTestDto (com.sequenceiq.it.cloudbreak.dto.AbstractTestDto)1 CloudbreakTestDto (com.sequenceiq.it.cloudbreak.dto.CloudbreakTestDto)1 SdxTestDto (com.sequenceiq.it.cloudbreak.dto.sdx.SdxTestDto)1 SdxClusterRequest (com.sequenceiq.sdx.api.model.SdxClusterRequest)1 Map (java.util.Map)1 Optional (java.util.Optional)1