Search in sources :

Example 26 with ContextualPreference

use of com.epam.pipeline.entity.contextual.ContextualPreference in project cloud-pipeline by epam.

the class RoleContextualPreferenceHandlerTest method searchShouldDelegateExecutionToTheNextHandlerIfPreferencesReducingReturnsEmptyOptional.

@Test
public void searchShouldDelegateExecutionToTheNextHandlerIfPreferencesReducingReturnsEmptyOptional() {
    final ContextualPreference preference1 = new ContextualPreference(NAME, VALUE, role1Resource);
    final ContextualPreference preference2 = new ContextualPreference(NAME, VALUE, role2Resource);
    final List<ContextualPreference> preferences = Arrays.asList(preference1, preference2);
    final ContextualPreference preference = new ContextualPreference(NAME, VALUE, role1Resource);
    final List<ContextualPreferenceExternalResource> resources = Arrays.asList(role1Resource, role2Resource);
    when(contextualPreferenceDao.load(eq(preference1.getName()), eq(role1Resource))).thenReturn(Optional.of(preference1));
    when(contextualPreferenceDao.load(eq(preference2.getName()), eq(role2Resource))).thenReturn(Optional.of(preference2));
    when(reducer.reduce(eq(preferences))).thenReturn(Optional.empty());
    when(nextHandler.search(eq(SINGLE_NAME), eq(resources))).thenReturn(Optional.of(preference));
    final Optional<ContextualPreference> searchedPreference = handler().search(SINGLE_NAME, resources);
    assertTrue(searchedPreference.isPresent());
    assertThat(searchedPreference.get(), is(preference));
    verify(reducer).reduce(eq(preferences));
    verify(nextHandler).search(eq(SINGLE_NAME), eq(resources));
}
Also used : ContextualPreference(com.epam.pipeline.entity.contextual.ContextualPreference) ContextualPreferenceExternalResource(com.epam.pipeline.entity.contextual.ContextualPreferenceExternalResource) Test(org.junit.Test)

Example 27 with ContextualPreference

use of com.epam.pipeline.entity.contextual.ContextualPreference in project cloud-pipeline by epam.

the class RoleContextualPreferenceHandlerTest method searchShouldLoadPreferencesBySingleNameEvenIfSeveralNamesAndSeveralRolesAreGiven.

@Test
public void searchShouldLoadPreferencesBySingleNameEvenIfSeveralNamesAndSeveralRolesAreGiven() {
    final List<ContextualPreferenceExternalResource> resources = Arrays.asList(role1Resource, role2Resource);
    final ContextualPreference preference1 = new ContextualPreference(NAME, VALUE, role1Resource);
    final List<ContextualPreference> preferences = Collections.singletonList(preference1);
    when(contextualPreferenceDao.load(eq(NAME), eq(role1Resource))).thenReturn(Optional.of(preference1));
    when(contextualPreferenceDao.load(eq(NAME), eq(role2Resource))).thenReturn(Optional.empty());
    when(reducer.reduce(eq(preferences))).thenReturn(Optional.of(preference1));
    final Optional<ContextualPreference> searchedPreference = handler().search(SEVERAL_NAMES, resources);
    assertTrue(searchedPreference.isPresent());
    assertThat(searchedPreference.get(), is(preference1));
    verify(reducer).reduce(eq(preferences));
    verify(contextualPreferenceDao).load(eq(NAME), eq(role1Resource));
    verify(contextualPreferenceDao).load(eq(NAME), eq(role2Resource));
    verify(contextualPreferenceDao, times(0)).load(eq(ANOTHER_NAME), eq(role1Resource));
    verify(contextualPreferenceDao, times(0)).load(eq(ANOTHER_NAME), eq(role2Resource));
}
Also used : ContextualPreferenceExternalResource(com.epam.pipeline.entity.contextual.ContextualPreferenceExternalResource) ContextualPreference(com.epam.pipeline.entity.contextual.ContextualPreference) Test(org.junit.Test)

Example 28 with ContextualPreference

use of com.epam.pipeline.entity.contextual.ContextualPreference in project cloud-pipeline by epam.

the class RoleContextualPreferenceHandlerTest method isValidShouldReturnFalseIfRoleDoesNotExist.

@Test
public void isValidShouldReturnFalseIfRoleDoesNotExist() {
    final ContextualPreference preference = new ContextualPreference(NAME, VALUE, role1Resource);
    when(roleDao.loadRole(eq(Long.valueOf(role1Resource.getResourceId())))).thenReturn(Optional.empty());
    assertFalse(handler().isValid(preference));
}
Also used : ContextualPreference(com.epam.pipeline.entity.contextual.ContextualPreference) Test(org.junit.Test)

Example 29 with ContextualPreference

use of com.epam.pipeline.entity.contextual.ContextualPreference in project cloud-pipeline by epam.

the class RoleContextualPreferenceHandlerTest method isValidShouldReturnTrueIfRoleExists.

@Test
public void isValidShouldReturnTrueIfRoleExists() {
    final ContextualPreference preference = new ContextualPreference(NAME, VALUE, role1Resource);
    when(roleDao.loadRole(eq(Long.valueOf(role1Resource.getResourceId())))).thenReturn(Optional.of(new Role()));
    assertTrue(handler().isValid(preference));
}
Also used : Role(com.epam.pipeline.entity.user.Role) ContextualPreference(com.epam.pipeline.entity.contextual.ContextualPreference) Test(org.junit.Test)

Example 30 with ContextualPreference

use of com.epam.pipeline.entity.contextual.ContextualPreference in project cloud-pipeline by epam.

the class RoleContextualPreferenceHandlerTest method searchShouldReturnReducedPreferenceFoundByAnotherNameIfThereIsNoPreferencesWithTheFirstName.

@Test
public void searchShouldReturnReducedPreferenceFoundByAnotherNameIfThereIsNoPreferencesWithTheFirstName() {
    final ContextualPreference preference1 = new ContextualPreference(NAME, VALUE, role1Resource);
    final ContextualPreference preference2 = new ContextualPreference(NAME, VALUE, role2Resource);
    final List<ContextualPreference> preferences = Arrays.asList(preference1, preference2);
    final ContextualPreference reducedPreference = new ContextualPreference(NAME, VALUE, preference1.getResource());
    final List<ContextualPreferenceExternalResource> resources = Arrays.asList(role1Resource, role2Resource);
    when(contextualPreferenceDao.load(eq(NAME), eq(role1Resource))).thenReturn(Optional.empty());
    when(contextualPreferenceDao.load(eq(NAME), eq(role2Resource))).thenReturn(Optional.empty());
    when(contextualPreferenceDao.load(eq(ANOTHER_NAME), eq(role1Resource))).thenReturn(Optional.of(preference1));
    when(contextualPreferenceDao.load(eq(ANOTHER_NAME), eq(role2Resource))).thenReturn(Optional.of(preference2));
    when(reducer.reduce(eq(preferences))).thenReturn(Optional.of(reducedPreference));
    final Optional<ContextualPreference> searchedPreference = handler().search(SEVERAL_NAMES, resources);
    assertTrue(searchedPreference.isPresent());
    assertThat(searchedPreference.get(), is(reducedPreference));
    verify(reducer).reduce(eq(preferences));
    verify(contextualPreferenceDao).load(eq(NAME), eq(role1Resource));
    verify(contextualPreferenceDao).load(eq(NAME), eq(role2Resource));
    verify(contextualPreferenceDao).load(eq(ANOTHER_NAME), eq(role1Resource));
    verify(contextualPreferenceDao).load(eq(ANOTHER_NAME), eq(role2Resource));
}
Also used : ContextualPreference(com.epam.pipeline.entity.contextual.ContextualPreference) ContextualPreferenceExternalResource(com.epam.pipeline.entity.contextual.ContextualPreferenceExternalResource) Test(org.junit.Test)

Aggregations

ContextualPreference (com.epam.pipeline.entity.contextual.ContextualPreference)72 Test (org.junit.Test)67 ContextualPreferenceExternalResource (com.epam.pipeline.entity.contextual.ContextualPreferenceExternalResource)35 AbstractSpringTest (com.epam.pipeline.AbstractSpringTest)10 ContextualPreferenceVO (com.epam.pipeline.controller.vo.ContextualPreferenceVO)4 AllowedInstanceAndPriceTypes (com.epam.pipeline.entity.cluster.AllowedInstanceAndPriceTypes)2 InstanceType (com.epam.pipeline.entity.cluster.InstanceType)2 Transactional (org.springframework.transaction.annotation.Transactional)2 MessageConstants (com.epam.pipeline.common.MessageConstants)1 MessageHelper (com.epam.pipeline.common.MessageHelper)1 Tool (com.epam.pipeline.entity.pipeline.Tool)1 PipelineUser (com.epam.pipeline.entity.user.PipelineUser)1 Role (com.epam.pipeline.entity.user.Role)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 RequiredArgsConstructor (lombok.RequiredArgsConstructor)1 Slf4j (lombok.extern.slf4j.Slf4j)1