Search in sources :

Example 36 with ContextualPreferenceExternalResource

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

the class DefaultContextualPreferenceReducerTest method reduceShouldReturnEmptyOptionalIfThereIsNoReducerForTheGivenPreference.

@Test
public void reduceShouldReturnEmptyOptionalIfThereIsNoReducerForTheGivenPreference() {
    final ContextualPreferenceExternalResource resource = new ContextualPreferenceExternalResource(LEVEL, RESOURCE_ID);
    final ContextualPreference preference1 = new ContextualPreference(ANOTHER_PREFERENCE, VALUE_1, resource);
    final ContextualPreference preference2 = new ContextualPreference(ANOTHER_PREFERENCE, 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 37 with ContextualPreferenceExternalResource

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

the class DefaultContextualPreferenceReducerTest method reduceShouldReturnEmptyOptionalIfThereArePreferencesWithDifferentTypes.

@Test
public void reduceShouldReturnEmptyOptionalIfThereArePreferencesWithDifferentTypes() {
    final ContextualPreferenceExternalResource resource = new ContextualPreferenceExternalResource(LEVEL, RESOURCE_ID);
    final ContextualPreference preference1 = new ContextualPreference(PREFERENCE_1, VALUE_1, PreferenceType.INTEGER, resource);
    final ContextualPreference preference2 = new ContextualPreference(PREFERENCE_1, VALUE_2, PreferenceType.STRING, 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 38 with ContextualPreferenceExternalResource

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

the class DefaultContextualPreferenceReducerTest method reduceShouldReturnThePreferenceIfSingletonListIsGiven.

@Test
public void reduceShouldReturnThePreferenceIfSingletonListIsGiven() {
    final ContextualPreferenceExternalResource resource = new ContextualPreferenceExternalResource(LEVEL, RESOURCE_ID);
    final ContextualPreference preference = new ContextualPreference(PREFERENCE_1, INSTANCE_TYPES, resource);
    final List<ContextualPreference> preferences = Collections.singletonList(preference);
    final Optional<ContextualPreference> reducedPreference = reducer.reduce(preferences);
    assertTrue(reducedPreference.isPresent());
    assertThat(reducedPreference.get(), is(preference));
}
Also used : ContextualPreferenceExternalResource(com.epam.pipeline.entity.contextual.ContextualPreferenceExternalResource) ContextualPreference(com.epam.pipeline.entity.contextual.ContextualPreference) Test(org.junit.Test)

Example 39 with ContextualPreferenceExternalResource

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

the class SystemPreferenceHandlerTest method searchShouldDelegateExecutionToTheNextHandlerIfNoneOfThePreferencesExist.

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

Example 40 with ContextualPreferenceExternalResource

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

the class RoleContextualPreferenceHandlerTest method searchShouldReturnReducedPreferenceIfSeveralRolePreferencesExist.

@Test
public void searchShouldReturnReducedPreferenceIfSeveralRolePreferencesExist() {
    final ContextualPreference preference1 = new ContextualPreference(NAME, VALUE, role1Resource);
    final ContextualPreference preference2 = new ContextualPreference(NAME, VALUE, role2Resource);
    final List<ContextualPreference> preferences = Arrays.asList(preference1, preference2);
    final ContextualPreference reducedPreference = new ContextualPreference(NAME, VALUE);
    final List<ContextualPreferenceExternalResource> resources = Arrays.asList(role1Resource, role2Resource);
    when(contextualPreferenceDao.load(eq(preference1.getName()), eq(role1Resource))).thenReturn(Optional.of(preference1));
    when(contextualPreferenceDao.load(eq(preference2.getName()), eq(role2Resource))).thenReturn(Optional.of(preference2));
    when(reducer.reduce(eq(preferences))).thenReturn(Optional.of(reducedPreference));
    final Optional<ContextualPreference> searchedPreference = handler().search(SINGLE_NAME, resources);
    assertTrue(searchedPreference.isPresent());
    assertThat(searchedPreference.get(), is(reducedPreference));
    verify(reducer).reduce(eq(preferences));
}
Also used : ContextualPreference(com.epam.pipeline.entity.contextual.ContextualPreference) ContextualPreferenceExternalResource(com.epam.pipeline.entity.contextual.ContextualPreferenceExternalResource) 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