use of com.epam.pipeline.entity.contextual.ContextualPreference in project cloud-pipeline by epam.
the class ContextualPreferenceManagerTest method deleteShouldReturnDeletedPreference.
@Test
public void deleteShouldReturnDeletedPreference() {
final ContextualPreference preference = new ContextualPreference(NAME, VALUE, toolResource);
when(contextualPreferenceDao.load(eq(NAME), eq(toolResource))).thenReturn(Optional.of(preference));
final ContextualPreference deletedPreference = manager.delete(NAME, toolResource);
assertThat(deletedPreference, is(preference));
}
use of com.epam.pipeline.entity.contextual.ContextualPreference in project cloud-pipeline by epam.
the class ContextualPreferenceManagerTest method upsertShouldFailIfPreferenceTypeDiffersWithExistingPreferencesWithTheSameName.
@Test
public void upsertShouldFailIfPreferenceTypeDiffersWithExistingPreferencesWithTheSameName() {
final ContextualPreferenceExternalResource anotherResource = new ContextualPreferenceExternalResource(LEVEL, ANOTHER_TOOL_ID);
final ContextualPreferenceVO preferenceVO = new ContextualPreferenceVO(NAME, VALUE, TYPE, toolResource);
final ContextualPreference preference = new ContextualPreference(NAME, VALUE, TYPE, toolResource);
when(contextualPreferenceHandler.isValid(eq(preference))).thenReturn(true);
when(contextualPreferenceDao.load(eq(preference.getName()))).thenReturn(Collections.singletonList(new ContextualPreference(NAME, VALUE, ANOTHER_TYPE, anotherResource)));
assertThrows(IllegalArgumentException.class, () -> manager.upsert(preferenceVO));
}
use of com.epam.pipeline.entity.contextual.ContextualPreference in project cloud-pipeline by epam.
the class ContextualPreferenceManagerTest method upsertShouldSavePreference.
@Test
public void upsertShouldSavePreference() {
final ContextualPreferenceVO preferenceVO = new ContextualPreferenceVO(NAME, VALUE, TYPE, toolResource);
final ContextualPreference preference = new ContextualPreference(NAME, VALUE, TYPE, toolResource);
when(contextualPreferenceHandler.isValid(eq(preference))).thenReturn(true);
manager.upsert(preferenceVO);
verify(contextualPreferenceDao).upsert(eq(preference));
}
use of com.epam.pipeline.entity.contextual.ContextualPreference in project cloud-pipeline by epam.
the class ContextualPreferenceManagerTest method searchShouldSearchPreferenceWithResourceConstructedFromCurrentUserByAuthorizedUserId.
@Test
public void searchShouldSearchPreferenceWithResourceConstructedFromCurrentUserByAuthorizedUserId() {
final ContextualPreferenceExternalResource userResource = new ContextualPreferenceExternalResource(ContextualPreferenceLevel.USER, USER.getId().toString());
final ContextualPreference preference = new ContextualPreference(NAME, VALUE, toolResource);
when(contextualPreferenceHandler.search(eq(NAMES), any())).thenReturn(Optional.of(preference));
when(authManager.getCurrentUser()).thenReturn(USER_WITHOUT_ROLES);
when(userManager.loadUserById(eq(USER_WITHOUT_ROLES.getId()))).thenReturn(USER);
final ContextualPreference searchedPreference = manager.search(NAMES, toolResource);
assertThat(searchedPreference, is(preference));
verify(contextualPreferenceHandler).search(eq(NAMES), argThat(hasItem(userResource)));
}
use of com.epam.pipeline.entity.contextual.ContextualPreference in project cloud-pipeline by epam.
the class AbstractDaoContextualPreferenceHandlerTest method searchShouldDelegateExecutionToTheNextHandlerIfNoneOfThePreferencesExist.
@Test
public void searchShouldDelegateExecutionToTheNextHandlerIfNoneOfThePreferencesExist() {
final List<ContextualPreferenceExternalResource> resources = Collections.singletonList(resource);
final ContextualPreference preference = new ContextualPreference(NAME, VALUE, resource);
when(contextualPreferenceDao.load(eq(NAME), eq(resource))).thenReturn(Optional.empty());
when(contextualPreferenceDao.load(eq(ANOTHER_NAME), eq(resource))).thenReturn(Optional.empty());
when(nextHandler.search(eq(SEVERAL_NAMES), eq(resources))).thenReturn(Optional.of(preference));
final Optional<ContextualPreference> searchedPreference = handler().search(SEVERAL_NAMES, resources);
assertTrue(searchedPreference.isPresent());
assertThat(searchedPreference.get(), is(preference));
verify(contextualPreferenceDao).load(eq(NAME), eq(resource));
verify(contextualPreferenceDao).load(eq(ANOTHER_NAME), eq(resource));
verify(nextHandler).search(eq(SEVERAL_NAMES), eq(resources));
}
Aggregations