Search in sources :

Example 66 with ContextualPreference

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

the class UserContextualPreferenceHandlerTest method isValidShouldReturnTrueIfUserExists.

@Test
public void isValidShouldReturnTrueIfUserExists() {
    final ContextualPreference preference = new ContextualPreference(NAME, VALUE, resource);
    when(userDao.loadUserById(eq(Long.valueOf(RESOURCE_ID)))).thenReturn(new PipelineUser());
    assertTrue(handler().isValid(preference));
}
Also used : PipelineUser(com.epam.pipeline.entity.user.PipelineUser) ContextualPreference(com.epam.pipeline.entity.contextual.ContextualPreference) Test(org.junit.Test)

Example 67 with ContextualPreference

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

the class AbstractContextualPreferenceHandlerTest method isValidShouldDelegateExecutionToTheNextHandlerIfPreferenceLevelDoesNotSuitCurrentHandler.

@Test
public void isValidShouldDelegateExecutionToTheNextHandlerIfPreferenceLevelDoesNotSuitCurrentHandler() {
    final ContextualPreference preference = new ContextualPreference(NAME, VALUE, notSuitableResource);
    when(nextHandler.isValid(eq(preference))).thenReturn(true);
    assertTrue(handler().isValid(preference));
    verify(nextHandler).isValid(eq(preference));
}
Also used : ContextualPreference(com.epam.pipeline.entity.contextual.ContextualPreference) Test(org.junit.Test)

Example 68 with ContextualPreference

use of com.epam.pipeline.entity.contextual.ContextualPreference 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)

Example 69 with ContextualPreference

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

the class ToolContextualPreferenceHandlerTest method isValidShouldReturnFalseIfToolDoesNotExist.

@Test
public void isValidShouldReturnFalseIfToolDoesNotExist() {
    final ContextualPreference preference = new ContextualPreference(NAME, VALUE, resource);
    when(toolDao.loadTool(eq(Long.valueOf(RESOURCE_ID)))).thenReturn(null);
    assertFalse(handler().isValid(preference));
}
Also used : ContextualPreference(com.epam.pipeline.entity.contextual.ContextualPreference) Test(org.junit.Test)

Example 70 with ContextualPreference

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

the class ContextualPreferenceManager method delete.

/**
 * Deletes contextual preference by the given preference parameters.
 *
 * @throws IllegalArgumentException if there is no preference with such parameters.
 */
@Transactional
public ContextualPreference delete(final String name, final ContextualPreferenceExternalResource resource) {
    validateName(name);
    validateResource(resource);
    final ContextualPreference preference = load(name, resource);
    contextualPreferenceDao.delete(name, resource);
    return preference;
}
Also used : ContextualPreference(com.epam.pipeline.entity.contextual.ContextualPreference) Transactional(org.springframework.transaction.annotation.Transactional)

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