Search in sources :

Example 51 with ContextualPreference

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

the class ContextualPreferenceManagerTest method searchShouldSearchPreferenceWithoutUserResourceIfNoUserIsAuthorized.

@Test
public void searchShouldSearchPreferenceWithoutUserResourceIfNoUserIsAuthorized() {
    final ContextualPreference preference = new ContextualPreference(NAME, VALUE, toolResource);
    when(contextualPreferenceHandler.search(eq(NAMES), any())).thenReturn(Optional.of(preference));
    when(authManager.getCurrentUser()).thenReturn(null);
    final ContextualPreference searchedPreference = manager.search(NAMES, toolResource);
    assertThat(searchedPreference, is(preference));
    verify(contextualPreferenceHandler).search(eq(NAMES), eq(Collections.singletonList(toolResource)));
}
Also used : ContextualPreference(com.epam.pipeline.entity.contextual.ContextualPreference) Test(org.junit.Test)

Example 52 with ContextualPreference

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

the class ContextualPreferenceManagerTest method upsertShouldFailIfPreferenceValueDoesNotSuitItsType.

@Test
public void upsertShouldFailIfPreferenceValueDoesNotSuitItsType() {
    final ContextualPreferenceVO preferenceVO = new ContextualPreferenceVO(NAME, VALUE, ANOTHER_TYPE, toolResource);
    final ContextualPreference preference = new ContextualPreference(NAME, VALUE, ANOTHER_TYPE, toolResource);
    when(contextualPreferenceHandler.isValid(eq(preference))).thenReturn(true);
    when(contextualPreferenceDao.load(eq(preference.getName()))).thenReturn(Collections.emptyList());
    assertThrows(IllegalArgumentException.class, () -> manager.upsert(preferenceVO));
}
Also used : ContextualPreference(com.epam.pipeline.entity.contextual.ContextualPreference) ContextualPreferenceVO(com.epam.pipeline.controller.vo.ContextualPreferenceVO) Test(org.junit.Test)

Example 53 with ContextualPreference

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

the class ContextualPreferenceManagerTest method loadAllShouldReturnAllPreferences.

@Test
public void loadAllShouldReturnAllPreferences() {
    final ContextualPreference preference1 = new ContextualPreference(NAME, VALUE, toolResource);
    final ContextualPreference preference2 = new ContextualPreference(ANOTHER_NAME, VALUE, toolResource);
    when(contextualPreferenceDao.loadAll()).thenReturn(Arrays.asList(preference1, preference2));
    assertThat(manager.loadAll(), containsInAnyOrder(preference1, preference2));
    verify(contextualPreferenceDao).loadAll();
}
Also used : ContextualPreference(com.epam.pipeline.entity.contextual.ContextualPreference) Test(org.junit.Test)

Example 54 with ContextualPreference

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

the class ContextualPreferenceManagerTest method loadShouldReturnPreferenceIfItExists.

@Test
public void loadShouldReturnPreferenceIfItExists() {
    final ContextualPreference preference = new ContextualPreference(NAME, VALUE, toolResource);
    when(contextualPreferenceDao.load(eq(NAME), eq(toolResource))).thenReturn(Optional.of(preference));
    final ContextualPreference loadedPreference = manager.load(NAME, toolResource);
    assertThat(loadedPreference, is(preference));
    verify(contextualPreferenceDao).load(eq(NAME), eq(toolResource));
}
Also used : ContextualPreference(com.epam.pipeline.entity.contextual.ContextualPreference) Test(org.junit.Test)

Example 55 with ContextualPreference

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

the class ContextualPreferenceManagerTest method searchShouldSearchPreferenceWithoutResourceConstructedFromTheRequestedResourceIfItIsNull.

@Test
public void searchShouldSearchPreferenceWithoutResourceConstructedFromTheRequestedResourceIfItIsNull() {
    final ContextualPreference preference = new ContextualPreference(NAME, VALUE);
    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, null);
    assertThat(searchedPreference, is(preference));
}
Also used : 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