use of com.epam.pipeline.entity.contextual.ContextualPreference in project cloud-pipeline by epam.
the class AbstractDaoContextualPreferenceHandlerTest method searchShouldDelegateExecutionToTheNextHandlerIfNoResourceSuitsCurrentHandler.
@Test
public void searchShouldDelegateExecutionToTheNextHandlerIfNoResourceSuitsCurrentHandler() {
final List<ContextualPreferenceExternalResource> resources = Collections.singletonList(notSuitableResource);
final ContextualPreference preference = new ContextualPreference(NAME, VALUE, resource);
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(nextHandler).search(eq(SINGLE_NAME), eq(resources));
}
use of com.epam.pipeline.entity.contextual.ContextualPreference in project cloud-pipeline by epam.
the class AbstractDaoContextualPreferenceHandlerTest method searchShouldDelegateExecutionToTheNextHandlerIfThereIsSuitableResourceButPreferenceDoesNotExists.
@Test
public void searchShouldDelegateExecutionToTheNextHandlerIfThereIsSuitableResourceButPreferenceDoesNotExists() {
final List<ContextualPreferenceExternalResource> resources = Arrays.asList(resource, notSuitableResource);
when(contextualPreferenceDao.load(eq(NAME), eq(resource))).thenReturn(Optional.empty());
final ContextualPreference preference = new ContextualPreference(NAME, VALUE, resource);
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(contextualPreferenceDao).load(eq(NAME), eq(resource));
verify(nextHandler).search(eq(SINGLE_NAME), eq(resources));
}
use of com.epam.pipeline.entity.contextual.ContextualPreference in project cloud-pipeline by epam.
the class AbstractDaoContextualPreferenceHandlerTest method searchShouldLoadPreferenceByAnotherNameIfThereIsNoPreferenceWithTheFirstName.
@Test
public void searchShouldLoadPreferenceByAnotherNameIfThereIsNoPreferenceWithTheFirstName() {
final List<ContextualPreferenceExternalResource> resources = Collections.singletonList(resource);
final ContextualPreference anotherPreference = new ContextualPreference(ANOTHER_NAME, VALUE, resource);
when(contextualPreferenceDao.load(eq(NAME), eq(resource))).thenReturn(Optional.empty());
when(contextualPreferenceDao.load(eq(ANOTHER_NAME), eq(resource))).thenReturn(Optional.of(anotherPreference));
final Optional<ContextualPreference> searchedPreference = handler().search(SEVERAL_NAMES, resources);
assertTrue(searchedPreference.isPresent());
assertThat(searchedPreference.get(), is(anotherPreference));
verify(contextualPreferenceDao).load(eq(NAME), eq(resource));
verify(contextualPreferenceDao).load(eq(ANOTHER_NAME), eq(resource));
}
use of com.epam.pipeline.entity.contextual.ContextualPreference in project cloud-pipeline by epam.
the class AbstractDaoContextualPreferenceHandlerTest method searchShouldReturnPreferenceIfThereIsSuitableResourceAndPreferenceExists.
@Test
public void searchShouldReturnPreferenceIfThereIsSuitableResourceAndPreferenceExists() {
final List<ContextualPreferenceExternalResource> resources = Arrays.asList(resource, notSuitableResource);
final ContextualPreference preference = new ContextualPreference(NAME, VALUE, resource);
when(contextualPreferenceDao.load(eq(NAME), eq(resource))).thenReturn(Optional.of(preference));
final Optional<ContextualPreference> searchedPreference = handler().search(SINGLE_NAME, resources);
assertTrue(searchedPreference.isPresent());
assertThat(searchedPreference.get(), is(preference));
verify(contextualPreferenceDao).load(eq(NAME), eq(resource));
}
use of com.epam.pipeline.entity.contextual.ContextualPreference in project cloud-pipeline by epam.
the class DefaultContextualPreferenceReducerTest method reduceShouldReturnEmptyOptionalIfThereArePreferencesWithDifferentNames.
@Test
public void reduceShouldReturnEmptyOptionalIfThereArePreferencesWithDifferentNames() {
final ContextualPreferenceExternalResource resource = new ContextualPreferenceExternalResource(LEVEL, RESOURCE_ID);
final ContextualPreference preference1 = new ContextualPreference(PREFERENCE_1, VALUE_1, resource);
final ContextualPreference preference2 = new ContextualPreference(PREFERENCE_2, VALUE_2, resource);
final List<ContextualPreference> preferences = Arrays.asList(preference1, preference2);
final Optional<ContextualPreference> reducedPreference = reducer.reduce(preferences);
assertFalse(reducedPreference.isPresent());
}
Aggregations