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));
}
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));
}
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));
}
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));
}
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));
}
Aggregations