Search in sources :

Example 21 with ContextualPreferenceExternalResource

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

the class RoleContextualPreferenceHandlerTest method searchShouldDelegateExecutionToTheNextHandlerIfPreferencesReducingReturnsEmptyOptional.

@Test
public void searchShouldDelegateExecutionToTheNextHandlerIfPreferencesReducingReturnsEmptyOptional() {
    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 preference = new ContextualPreference(NAME, VALUE, role1Resource);
    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.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(reducer).reduce(eq(preferences));
    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 22 with ContextualPreferenceExternalResource

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

the class RoleContextualPreferenceHandlerTest method searchShouldLoadPreferencesBySingleNameEvenIfSeveralNamesAndSeveralRolesAreGiven.

@Test
public void searchShouldLoadPreferencesBySingleNameEvenIfSeveralNamesAndSeveralRolesAreGiven() {
    final List<ContextualPreferenceExternalResource> resources = Arrays.asList(role1Resource, role2Resource);
    final ContextualPreference preference1 = new ContextualPreference(NAME, VALUE, role1Resource);
    final List<ContextualPreference> preferences = Collections.singletonList(preference1);
    when(contextualPreferenceDao.load(eq(NAME), eq(role1Resource))).thenReturn(Optional.of(preference1));
    when(contextualPreferenceDao.load(eq(NAME), eq(role2Resource))).thenReturn(Optional.empty());
    when(reducer.reduce(eq(preferences))).thenReturn(Optional.of(preference1));
    final Optional<ContextualPreference> searchedPreference = handler().search(SEVERAL_NAMES, resources);
    assertTrue(searchedPreference.isPresent());
    assertThat(searchedPreference.get(), is(preference1));
    verify(reducer).reduce(eq(preferences));
    verify(contextualPreferenceDao).load(eq(NAME), eq(role1Resource));
    verify(contextualPreferenceDao).load(eq(NAME), eq(role2Resource));
    verify(contextualPreferenceDao, times(0)).load(eq(ANOTHER_NAME), eq(role1Resource));
    verify(contextualPreferenceDao, times(0)).load(eq(ANOTHER_NAME), eq(role2Resource));
}
Also used : ContextualPreferenceExternalResource(com.epam.pipeline.entity.contextual.ContextualPreferenceExternalResource) ContextualPreference(com.epam.pipeline.entity.contextual.ContextualPreference) Test(org.junit.Test)

Example 23 with ContextualPreferenceExternalResource

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

the class RoleContextualPreferenceHandlerTest method searchShouldReturnReducedPreferenceFoundByAnotherNameIfThereIsNoPreferencesWithTheFirstName.

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

Example 24 with ContextualPreferenceExternalResource

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

the class RoleContextualPreferenceHandlerTest method searchShouldDelegateExecutionToTheNextHandlerIfNoneOfPreferencesExist.

@Test
public void searchShouldDelegateExecutionToTheNextHandlerIfNoneOfPreferencesExist() {
    final List<ContextualPreferenceExternalResource> resources = Arrays.asList(role1Resource, role2Resource);
    final ContextualPreference preference = new ContextualPreference(NAME, VALUE, role1Resource);
    when(contextualPreferenceDao.load(any(), any())).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(contextualPreferenceDao).load(eq(NAME), eq(role1Resource));
    verify(contextualPreferenceDao).load(eq(NAME), eq(role2Resource));
    verify(contextualPreferenceDao).load(eq(ANOTHER_NAME), eq(role1Resource));
    verify(contextualPreferenceDao).load(eq(ANOTHER_NAME), eq(role2Resource));
}
Also used : ContextualPreferenceExternalResource(com.epam.pipeline.entity.contextual.ContextualPreferenceExternalResource) ContextualPreference(com.epam.pipeline.entity.contextual.ContextualPreference) Test(org.junit.Test)

Example 25 with ContextualPreferenceExternalResource

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

the class InstanceOfferManager method getAllowedInstanceAndPriceTypes.

/**
 * Returns allowed instance and price types for a current user.
 *
 * @param toolId Optional tool id. If specified than allowed instance and price types will be bounded for a
 *               specific tool.
 */
public AllowedInstanceAndPriceTypes getAllowedInstanceAndPriceTypes(final String toolId) {
    final ContextualPreferenceExternalResource resource = toolId != null ? new ContextualPreferenceExternalResource(ContextualPreferenceLevel.TOOL, toolId) : null;
    final List<InstanceType> instanceTypes = getAllInstanceTypes();
    final List<InstanceType> allowedInstanceTypes = getAllowedInstanceTypes(instanceTypes, resource, SystemPreferences.CLUSTER_ALLOWED_INSTANCE_TYPES);
    final List<InstanceType> allowedInstanceDockerTypes = getAllowedInstanceTypes(instanceTypes, resource, SystemPreferences.CLUSTER_ALLOWED_INSTANCE_TYPES_DOCKER, SystemPreferences.CLUSTER_ALLOWED_INSTANCE_TYPES);
    final List<String> allowedPriceTypes = getContextualPreferenceValueAsList(resource, SystemPreferences.CLUSTER_ALLOWED_PRICE_TYPES);
    return new AllowedInstanceAndPriceTypes(allowedInstanceTypes, allowedInstanceDockerTypes, allowedPriceTypes);
}
Also used : ContextualPreferenceExternalResource(com.epam.pipeline.entity.contextual.ContextualPreferenceExternalResource) AllowedInstanceAndPriceTypes(com.epam.pipeline.entity.cluster.AllowedInstanceAndPriceTypes) InstanceType(com.epam.pipeline.entity.cluster.InstanceType)

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