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));
}
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));
}
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));
}
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));
}
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)));
}
Aggregations