Search in sources :

Example 16 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 17 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)

Example 18 with ContextualPreferenceExternalResource

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

the class SystemPreferenceHandlerTest method searchShouldDelegateExecutionToTheNextHandlerIfPreferenceDoesNotExist.

@Test
public void searchShouldDelegateExecutionToTheNextHandlerIfPreferenceDoesNotExist() {
    final ContextualPreference preference = new ContextualPreference(NAME, VALUE, resource);
    final List<ContextualPreferenceExternalResource> resources = Collections.emptyList();
    when(preferenceManager.load(eq(NAME))).thenReturn(Optional.empty());
    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(preferenceManager).load(eq(NAME));
    verify(nextHandler).search(eq(SINGLE_NAME), eq(resources));
}
Also used : ContextualPreference(com.epam.pipeline.entity.contextual.ContextualPreference) ContextualPreferenceExternalResource(com.epam.pipeline.entity.contextual.ContextualPreferenceExternalResource) Test(org.junit.Test)

Example 19 with ContextualPreferenceExternalResource

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

the class ArrayContextualPreferenceReducerTest method reduceShouldReturnPreferenceWithMergedValue.

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

Example 20 with ContextualPreferenceExternalResource

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

the class ArrayContextualPreferenceReducerTest method reduceShouldReturnPreferenceWithoutCreatedDateAndResource.

@Test
public void reduceShouldReturnPreferenceWithoutCreatedDateAndResource() {
    final ContextualPreferenceExternalResource resource = new ContextualPreferenceExternalResource(LEVEL, RESOURCE_ID);
    final ContextualPreference preference1 = new ContextualPreference(NAME, VALUE_1, resource);
    final ContextualPreference preference2 = new ContextualPreference(NAME, VALUE_2, resource);
    final List<ContextualPreference> preferences = Arrays.asList(preference1, preference2);
    final Optional<ContextualPreference> reducedPreference = reducer.reduce(preferences);
    assertTrue(reducedPreference.isPresent());
    assertThat(reducedPreference.get().getCreatedDate(), is(nullValue()));
    assertThat(reducedPreference.get().getResource(), is(nullValue()));
}
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