Search in sources :

Example 11 with ContextualPreferenceExternalResource

use of com.epam.pipeline.entity.contextual.ContextualPreferenceExternalResource 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));
}
Also used : ContextualPreferenceExternalResource(com.epam.pipeline.entity.contextual.ContextualPreferenceExternalResource) ContextualPreference(com.epam.pipeline.entity.contextual.ContextualPreference) Test(org.junit.Test)

Example 12 with ContextualPreferenceExternalResource

use of com.epam.pipeline.entity.contextual.ContextualPreferenceExternalResource 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));
}
Also used : ContextualPreferenceExternalResource(com.epam.pipeline.entity.contextual.ContextualPreferenceExternalResource) ContextualPreference(com.epam.pipeline.entity.contextual.ContextualPreference) Test(org.junit.Test)

Example 13 with ContextualPreferenceExternalResource

use of com.epam.pipeline.entity.contextual.ContextualPreferenceExternalResource 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));
}
Also used : ContextualPreferenceExternalResource(com.epam.pipeline.entity.contextual.ContextualPreferenceExternalResource) ContextualPreference(com.epam.pipeline.entity.contextual.ContextualPreference) Test(org.junit.Test)

Example 14 with ContextualPreferenceExternalResource

use of com.epam.pipeline.entity.contextual.ContextualPreferenceExternalResource 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));
}
Also used : ContextualPreferenceExternalResource(com.epam.pipeline.entity.contextual.ContextualPreferenceExternalResource) ContextualPreference(com.epam.pipeline.entity.contextual.ContextualPreference) Test(org.junit.Test)

Example 15 with ContextualPreferenceExternalResource

use of com.epam.pipeline.entity.contextual.ContextualPreferenceExternalResource 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());
}
Also used : ContextualPreferenceExternalResource(com.epam.pipeline.entity.contextual.ContextualPreferenceExternalResource) ContextualPreference(com.epam.pipeline.entity.contextual.ContextualPreference) Test(org.junit.Test)

Aggregations

ContextualPreferenceExternalResource (com.epam.pipeline.entity.contextual.ContextualPreferenceExternalResource)40 Test (org.junit.Test)37 ContextualPreference (com.epam.pipeline.entity.contextual.ContextualPreference)35 AbstractSpringTest (com.epam.pipeline.AbstractSpringTest)10 ContextualPreferenceVO (com.epam.pipeline.controller.vo.ContextualPreferenceVO)3 AllowedInstanceAndPriceTypes (com.epam.pipeline.entity.cluster.AllowedInstanceAndPriceTypes)1 InstanceType (com.epam.pipeline.entity.cluster.InstanceType)1 Tool (com.epam.pipeline.entity.pipeline.Tool)1