use of com.epam.pipeline.entity.contextual.ContextualPreference in project cloud-pipeline by epam.
the class UserContextualPreferenceHandlerTest method isValidShouldReturnTrueIfUserExists.
@Test
public void isValidShouldReturnTrueIfUserExists() {
final ContextualPreference preference = new ContextualPreference(NAME, VALUE, resource);
when(userDao.loadUserById(eq(Long.valueOf(RESOURCE_ID)))).thenReturn(new PipelineUser());
assertTrue(handler().isValid(preference));
}
use of com.epam.pipeline.entity.contextual.ContextualPreference in project cloud-pipeline by epam.
the class AbstractContextualPreferenceHandlerTest method isValidShouldDelegateExecutionToTheNextHandlerIfPreferenceLevelDoesNotSuitCurrentHandler.
@Test
public void isValidShouldDelegateExecutionToTheNextHandlerIfPreferenceLevelDoesNotSuitCurrentHandler() {
final ContextualPreference preference = new ContextualPreference(NAME, VALUE, notSuitableResource);
when(nextHandler.isValid(eq(preference))).thenReturn(true);
assertTrue(handler().isValid(preference));
verify(nextHandler).isValid(eq(preference));
}
use of com.epam.pipeline.entity.contextual.ContextualPreference in project cloud-pipeline by epam.
the class RoleContextualPreferenceHandlerTest method searchShouldReturnReducedPreferenceIfSeveralRolePreferencesExist.
@Test
public void searchShouldReturnReducedPreferenceIfSeveralRolePreferencesExist() {
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);
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.of(reducedPreference));
final Optional<ContextualPreference> searchedPreference = handler().search(SINGLE_NAME, resources);
assertTrue(searchedPreference.isPresent());
assertThat(searchedPreference.get(), is(reducedPreference));
verify(reducer).reduce(eq(preferences));
}
use of com.epam.pipeline.entity.contextual.ContextualPreference in project cloud-pipeline by epam.
the class ToolContextualPreferenceHandlerTest method isValidShouldReturnFalseIfToolDoesNotExist.
@Test
public void isValidShouldReturnFalseIfToolDoesNotExist() {
final ContextualPreference preference = new ContextualPreference(NAME, VALUE, resource);
when(toolDao.loadTool(eq(Long.valueOf(RESOURCE_ID)))).thenReturn(null);
assertFalse(handler().isValid(preference));
}
use of com.epam.pipeline.entity.contextual.ContextualPreference in project cloud-pipeline by epam.
the class ContextualPreferenceManager method delete.
/**
* Deletes contextual preference by the given preference parameters.
*
* @throws IllegalArgumentException if there is no preference with such parameters.
*/
@Transactional
public ContextualPreference delete(final String name, final ContextualPreferenceExternalResource resource) {
validateName(name);
validateResource(resource);
final ContextualPreference preference = load(name, resource);
contextualPreferenceDao.delete(name, resource);
return preference;
}
Aggregations