Search in sources :

Example 6 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 7 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 8 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)

Example 9 with ContextualPreferenceExternalResource

use of com.epam.pipeline.entity.contextual.ContextualPreferenceExternalResource in project cloud-pipeline by epam.

the class DefaultContextualPreferenceReducerTest method reduceShouldReturnReducedPreferenceIfThereIsReducerForTheGivenPreference.

@Test
public void reduceShouldReturnReducedPreferenceIfThereIsReducerForTheGivenPreference() {
    final ContextualPreferenceExternalResource resource = new ContextualPreferenceExternalResource(LEVEL, RESOURCE_ID);
    final ContextualPreference preference1 = new ContextualPreference(PREFERENCE_1, VALUE_1, resource);
    final ContextualPreference preference2 = new ContextualPreference(PREFERENCE_1, VALUE_2, resource);
    final ContextualPreference expectedPreference = new ContextualPreference(PREFERENCE_1, MERGED_VALUE, resource);
    final List<ContextualPreference> preferences = Arrays.asList(preference1, preference2);
    when(innerReducer.reduce(eq(preferences))).thenReturn(Optional.of(expectedPreference));
    final Optional<ContextualPreference> reducedPreference = reducer.reduce(preferences);
    assertTrue(reducedPreference.isPresent());
    assertThat(reducedPreference.get(), is(expectedPreference));
    verify(innerReducer).reduce(eq(preferences));
}
Also used : ContextualPreferenceExternalResource(com.epam.pipeline.entity.contextual.ContextualPreferenceExternalResource) ContextualPreference(com.epam.pipeline.entity.contextual.ContextualPreference) Test(org.junit.Test)

Example 10 with ContextualPreferenceExternalResource

use of com.epam.pipeline.entity.contextual.ContextualPreferenceExternalResource in project cloud-pipeline by epam.

the class DefaultContextualPreferenceReducerTest method reduceShouldReturnEmptyOptionalIfThereArePreferencesWithDifferentLevels.

@Test
public void reduceShouldReturnEmptyOptionalIfThereArePreferencesWithDifferentLevels() {
    final ContextualPreferenceExternalResource resource = new ContextualPreferenceExternalResource(LEVEL, RESOURCE_ID);
    final ContextualPreferenceExternalResource anotherResource = new ContextualPreferenceExternalResource(ANOTHER_LEVEL, RESOURCE_ID);
    final ContextualPreference preference1 = new ContextualPreference(PREFERENCE_1, VALUE_1, resource);
    final ContextualPreference preference2 = new ContextualPreference(PREFERENCE_1, VALUE_2, anotherResource);
    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