Search in sources :

Example 46 with ContextualPreference

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

the class InstanceOfferManagerUnitTest method isPriceTypeAllowedShouldReturnResultIfResourceIsNull.

@Test
public void isPriceTypeAllowedShouldReturnResultIfResourceIsNull() {
    when(contextualPreferenceManager.search(eq(PRICE_TYPES_PREFERENCES), eq(null))).thenReturn(new ContextualPreference(ALLOWED_PRICE_TYPES_PREFERENCE, SPOT_AND_ON_DEMAND_TYPES));
    assertTrue(instanceOfferManager.isPriceTypeAllowed(SPOT, null));
    verify(contextualPreferenceManager).search(eq(PRICE_TYPES_PREFERENCES), eq(null));
}
Also used : ContextualPreference(com.epam.pipeline.entity.contextual.ContextualPreference) Test(org.junit.Test)

Example 47 with ContextualPreference

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

the class InstanceOfferManagerUnitTest method isPriceTypeAllowedShouldReturnFalseIfGivenPriceTypeDoesNotEqualToAnyOfTheAllowedPriceTypes.

@Test
public void isPriceTypeAllowedShouldReturnFalseIfGivenPriceTypeDoesNotEqualToAnyOfTheAllowedPriceTypes() {
    when(contextualPreferenceManager.search(eq(PRICE_TYPES_PREFERENCES), eq(TOOL_RESOURCE))).thenReturn(new ContextualPreference(ALLOWED_PRICE_TYPES_PREFERENCE, ON_DEMAND));
    assertFalse(instanceOfferManager.isPriceTypeAllowed(SPOT, TOOL_RESOURCE));
    verify(contextualPreferenceManager).search(eq(PRICE_TYPES_PREFERENCES), eq(TOOL_RESOURCE));
}
Also used : ContextualPreference(com.epam.pipeline.entity.contextual.ContextualPreference) Test(org.junit.Test)

Example 48 with ContextualPreference

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

the class InstanceOfferManagerUnitTest method isPriceTypeAllowedShouldReturnTrueIfGivenPriceTypeEqualsToOneOfTheAllowedPriceTypes.

@Test
public void isPriceTypeAllowedShouldReturnTrueIfGivenPriceTypeEqualsToOneOfTheAllowedPriceTypes() {
    when(contextualPreferenceManager.search(eq(PRICE_TYPES_PREFERENCES), eq(TOOL_RESOURCE))).thenReturn(new ContextualPreference(ALLOWED_PRICE_TYPES_PREFERENCE, SPOT_AND_ON_DEMAND_TYPES));
    assertTrue(instanceOfferManager.isPriceTypeAllowed(SPOT, TOOL_RESOURCE));
    verify(contextualPreferenceManager).search(eq(PRICE_TYPES_PREFERENCES), eq(TOOL_RESOURCE));
}
Also used : ContextualPreference(com.epam.pipeline.entity.contextual.ContextualPreference) Test(org.junit.Test)

Example 49 with ContextualPreference

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

the class InstanceOfferManagerUnitTest method isToolInstanceAllowedReturnResultIfResourceIsNull.

@Test
public void isToolInstanceAllowedReturnResultIfResourceIsNull() {
    when(contextualPreferenceManager.search(eq(DOCKER_INSTANCE_TYPES_PREFERENCES), eq(null))).thenReturn(new ContextualPreference(ALLOWED_DOCKER_INSTANCE_TYPES_PREFERENCE, M4_M5_PATTERNS));
    assertTrue(instanceOfferManager.isToolInstanceAllowed(M4_LARGE, null));
    verify(contextualPreferenceManager).search(eq(DOCKER_INSTANCE_TYPES_PREFERENCES), eq(null));
}
Also used : ContextualPreference(com.epam.pipeline.entity.contextual.ContextualPreference) Test(org.junit.Test)

Example 50 with ContextualPreference

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

the class ContextualPreferenceManagerTest method searchShouldSearchPreferenceWithResourcesConstructedFromCurrentUserRoles.

@Test
public void searchShouldSearchPreferenceWithResourcesConstructedFromCurrentUserRoles() {
    final ContextualPreferenceExternalResource firstRoleResource = new ContextualPreferenceExternalResource(ContextualPreferenceLevel.ROLE, ROLE_1.getId().toString());
    final ContextualPreferenceExternalResource secondRoleResource = new ContextualPreferenceExternalResource(ContextualPreferenceLevel.ROLE, ROLE_2.getId().toString());
    final ContextualPreference preference = new ContextualPreference(NAME, VALUE, toolResource);
    when(contextualPreferenceHandler.search(eq(NAMES), any())).thenReturn(Optional.of(preference));
    when(authManager.getCurrentUser()).thenReturn(USER_WITHOUT_ROLES);
    when(userManager.loadUserById(eq(USER_WITHOUT_ROLES.getId()))).thenReturn(USER);
    final ContextualPreference searchedPreference = manager.search(NAMES, toolResource);
    assertThat(searchedPreference, is(preference));
    verify(contextualPreferenceHandler).search(eq(NAMES), argThat(hasItems(firstRoleResource, secondRoleResource)));
}
Also used : ContextualPreferenceExternalResource(com.epam.pipeline.entity.contextual.ContextualPreferenceExternalResource) ContextualPreference(com.epam.pipeline.entity.contextual.ContextualPreference) Test(org.junit.Test)

Aggregations

ContextualPreference (com.epam.pipeline.entity.contextual.ContextualPreference)72 Test (org.junit.Test)67 ContextualPreferenceExternalResource (com.epam.pipeline.entity.contextual.ContextualPreferenceExternalResource)35 AbstractSpringTest (com.epam.pipeline.AbstractSpringTest)10 ContextualPreferenceVO (com.epam.pipeline.controller.vo.ContextualPreferenceVO)4 AllowedInstanceAndPriceTypes (com.epam.pipeline.entity.cluster.AllowedInstanceAndPriceTypes)2 InstanceType (com.epam.pipeline.entity.cluster.InstanceType)2 Transactional (org.springframework.transaction.annotation.Transactional)2 MessageConstants (com.epam.pipeline.common.MessageConstants)1 MessageHelper (com.epam.pipeline.common.MessageHelper)1 Tool (com.epam.pipeline.entity.pipeline.Tool)1 PipelineUser (com.epam.pipeline.entity.user.PipelineUser)1 Role (com.epam.pipeline.entity.user.Role)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 RequiredArgsConstructor (lombok.RequiredArgsConstructor)1 Slf4j (lombok.extern.slf4j.Slf4j)1