Search in sources :

Example 6 with CustomConfigurations

use of com.sequenceiq.cloudbreak.domain.CustomConfigurations in project cloudbreak by hortonworks.

the class CustomConfigurationsToCustomConfigurationsDetailsConverterTest method testConvert.

@Test
void testConvert() {
    CustomConfigurations customConfigurations = new CustomConfigurations();
    customConfigurations.setId(1L);
    customConfigurations.setName("test-name");
    customConfigurations.setConfigurations(Sets.newHashSet(new CustomConfigurationProperty("property1", "value1", null, "service1"), new CustomConfigurationProperty("property2", "value2", "role2", "service2"), new CustomConfigurationProperty("property3", "value3", null, "service3"), new CustomConfigurationProperty("property4", "value4", "role4", "service4")));
    customConfigurations.setRuntimeVersion("test-runtime-version");
    CustomConfigurationsDetails customConfigurationsDetails = underTest.convert(customConfigurations);
    assertThat(customConfigurationsDetails).isNotNull();
    assertThat(customConfigurationsDetails.getCustomConfigurationsName()).isEqualTo("test-name");
    assertThat(customConfigurationsDetails.getId()).isEqualTo(1L);
    assertThat(customConfigurationsDetails.getRuntimeVersion()).isEqualTo("test-runtime-version");
    assertThat(customConfigurationsDetails.getRoles()).hasSameElementsAs(Lists.newArrayList("role2", "role4"));
    assertThat(customConfigurationsDetails.getServices()).hasSameElementsAs(Lists.newArrayList("service1", "service2", "service3", "service4"));
}
Also used : CustomConfigurationProperty(com.sequenceiq.cloudbreak.domain.CustomConfigurationProperty) CustomConfigurations(com.sequenceiq.cloudbreak.domain.CustomConfigurations) CustomConfigurationsDetails(com.sequenceiq.cloudbreak.structuredevent.event.CustomConfigurationsDetails) Test(org.junit.jupiter.api.Test)

Example 7 with CustomConfigurations

use of com.sequenceiq.cloudbreak.domain.CustomConfigurations in project cloudbreak by hortonworks.

the class CustomConfigurationsServiceTest method testIfCustomConfigsAreRetrievedByCrn.

@Test
void testIfCustomConfigsAreRetrievedByCrn() {
    when(customConfigurationsRepository.findByCrn(TEST_CRN_1)).thenReturn(Optional.of(customConfigurations));
    CustomConfigurations returnedValue = underTest.getByNameOrCrn(NameOrCrn.ofCrn(TEST_CRN_1));
    assertEquals(customConfigurations, returnedValue);
    verify(customConfigurationsRepository).findByCrn(TEST_CRN_1);
}
Also used : CustomConfigurations(com.sequenceiq.cloudbreak.domain.CustomConfigurations) Test(org.junit.jupiter.api.Test)

Example 8 with CustomConfigurations

use of com.sequenceiq.cloudbreak.domain.CustomConfigurations in project cloudbreak by hortonworks.

the class CustomConfigurationsServiceTest method testIfCustomConfigsAreRetrievedByName.

@Test
void testIfCustomConfigsAreRetrievedByName() {
    when(customConfigurationsRepository.findByNameAndAccountId(TEST_NAME, TEST_ACCOUNT_ID_1)).thenReturn(Optional.of(customConfigurations));
    ThreadBasedUserCrnProvider.doAs(TEST_USER_CRN_1, () -> {
        CustomConfigurations returnedValue = underTest.getByNameOrCrn(NameOrCrn.ofName(TEST_NAME));
        assertEquals(customConfigurations, returnedValue);
        assertThrows(NotFoundException.class, () -> underTest.getByNameOrCrn(NameOrCrn.ofName("not a valid name")));
        verify(customConfigurationsRepository).findByNameAndAccountId(TEST_NAME, TEST_ACCOUNT_ID_1);
    });
}
Also used : CustomConfigurations(com.sequenceiq.cloudbreak.domain.CustomConfigurations) Test(org.junit.jupiter.api.Test)

Example 9 with CustomConfigurations

use of com.sequenceiq.cloudbreak.domain.CustomConfigurations in project cloudbreak by hortonworks.

the class CustomConfigurationsToCustomConfigurationsV4ResponseConverterTest method testConvertResponseContainsCorrectCustomConfigsProperties.

@Test
void testConvertResponseContainsCorrectCustomConfigsProperties() {
    Set<CustomConfigurationPropertyParameters> properties = customConfigurations.getConfigurations().stream().map(c -> customConfigurationPropertyConverter.convertToResponseJson(c)).collect(Collectors.toSet());
    CustomConfigurationsV4Response response = underTest.convert(customConfigurations);
    Set<CustomConfigurationPropertyParameters> result = response.getConfigurations();
    assertEquals(properties, result);
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) InjectMocks(org.mockito.InjectMocks) BeforeEach(org.junit.jupiter.api.BeforeEach) Mock(org.mockito.Mock) Collection(java.util.Collection) CustomConfigurations(com.sequenceiq.cloudbreak.domain.CustomConfigurations) Set(java.util.Set) Mockito.when(org.mockito.Mockito.when) Collectors(java.util.stream.Collectors) CollectionUtils(org.apache.commons.collections4.CollectionUtils) Sets(com.google.common.collect.Sets) Test(org.junit.jupiter.api.Test) MockitoAnnotations(org.mockito.MockitoAnnotations) CustomConfigurationsV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.responses.CustomConfigurationsV4Response) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) CustomConfigurationProperty(com.sequenceiq.cloudbreak.domain.CustomConfigurationProperty) CustomConfigurationPropertyParameters(com.sequenceiq.cloudbreak.api.model.CustomConfigurationPropertyParameters) CustomConfigurationPropertyParameters(com.sequenceiq.cloudbreak.api.model.CustomConfigurationPropertyParameters) CustomConfigurationsV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.responses.CustomConfigurationsV4Response) Test(org.junit.jupiter.api.Test)

Example 10 with CustomConfigurations

use of com.sequenceiq.cloudbreak.domain.CustomConfigurations in project cloudbreak by hortonworks.

the class CustomConfigurationsV4RequestToCustomConfigurationsConverterTest method testConvert.

@Test
void testConvert() {
    property.setName("property1");
    property.setValue("value1");
    property.setRoleType("role1");
    property.setServiceType("service1");
    request.setName("test");
    request.setConfigurations(Set.of(property));
    request.setRuntimeVersion("7.2.8");
    when(customConfigurationPropertyConverter.convertFromRequestJson(any(CustomConfigurationPropertyParameters.class))).thenReturn(new CustomConfigurationProperty("property1", "value1", "role1", "service1"));
    when(customConfigurationPropertyConverter.convertToResponseJson(any(CustomConfigurationProperty.class))).thenReturn(property);
    CustomConfigurations result = underTest.convert(request);
    assertEquals(request.getName(), result.getName());
    assertEquals(request.getConfigurations(), result.getConfigurations().stream().map(c -> customConfigurationPropertyConverter.convertToResponseJson(c)).collect(Collectors.toSet()));
    assertEquals(request.getRuntimeVersion(), result.getRuntimeVersion());
}
Also used : CustomConfigurationProperty(com.sequenceiq.cloudbreak.domain.CustomConfigurationProperty) CustomConfigurations(com.sequenceiq.cloudbreak.domain.CustomConfigurations) CustomConfigurationPropertyParameters(com.sequenceiq.cloudbreak.api.model.CustomConfigurationPropertyParameters) Test(org.junit.jupiter.api.Test)

Aggregations

CustomConfigurations (com.sequenceiq.cloudbreak.domain.CustomConfigurations)15 Test (org.junit.jupiter.api.Test)9 CustomConfigurationProperty (com.sequenceiq.cloudbreak.domain.CustomConfigurationProperty)4 CustomConfigurationsDetails (com.sequenceiq.cloudbreak.structuredevent.event.CustomConfigurationsDetails)3 CustomConfigurationPropertyParameters (com.sequenceiq.cloudbreak.api.model.CustomConfigurationPropertyParameters)2 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)2 Collection (java.util.Collection)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 Sets (com.google.common.collect.Sets)1 AuthorizationResourceType (com.sequenceiq.authorization.resource.AuthorizationResourceType)1 CompositeAuthResourcePropertyProvider (com.sequenceiq.authorization.service.CompositeAuthResourcePropertyProvider)1 OwnerAssignmentService (com.sequenceiq.authorization.service.OwnerAssignmentService)1 NameOrCrn (com.sequenceiq.cloudbreak.api.endpoint.v4.dto.NameOrCrn)1 CustomConfigurationsV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.responses.CustomConfigurationsV4Response)1 ThreadBasedUserCrnProvider (com.sequenceiq.cloudbreak.auth.ThreadBasedUserCrnProvider)1 Crn (com.sequenceiq.cloudbreak.auth.crn.Crn)1 CrnResourceDescriptor (com.sequenceiq.cloudbreak.auth.crn.CrnResourceDescriptor)1 RegionAwareCrnGenerator (com.sequenceiq.cloudbreak.auth.crn.RegionAwareCrnGenerator)1 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)1