Search in sources :

Example 31 with ContextualPreferenceExternalResource

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

the class ContextualPreferenceManagerTest method upsertShouldFailIfPreferenceHasEmptyFields.

@Test
public void upsertShouldFailIfPreferenceHasEmptyFields() {
    when(contextualPreferenceHandler.isValid(any())).thenReturn(true);
    assertThrows(IllegalArgumentException.class, () -> manager.upsert(new ContextualPreferenceVO(null, VALUE, TYPE, toolResource)));
    assertThrows(IllegalArgumentException.class, () -> manager.upsert(new ContextualPreferenceVO(NAME, null, TYPE, toolResource)));
    assertThrows(IllegalArgumentException.class, () -> manager.upsert(new ContextualPreferenceVO(NAME, VALUE, null, toolResource)));
    assertThrows(IllegalArgumentException.class, () -> manager.upsert(new ContextualPreferenceVO(NAME, VALUE, TYPE, new ContextualPreferenceExternalResource(null, TOOL_ID))));
    assertThrows(IllegalArgumentException.class, () -> manager.upsert(new ContextualPreferenceVO(NAME, VALUE, TYPE, new ContextualPreferenceExternalResource(LEVEL, null))));
}
Also used : ContextualPreferenceExternalResource(com.epam.pipeline.entity.contextual.ContextualPreferenceExternalResource) ContextualPreferenceVO(com.epam.pipeline.controller.vo.ContextualPreferenceVO) Test(org.junit.Test)

Example 32 with ContextualPreferenceExternalResource

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

the class ContextualPreferenceManagerTest method upsertShouldFailIfPreferenceTypeDiffersWithExistingPreferencesWithTheSameName.

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

Example 33 with ContextualPreferenceExternalResource

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

the class ContextualPreferenceManagerTest method searchShouldSearchPreferenceWithResourceConstructedFromCurrentUserByAuthorizedUserId.

@Test
public void searchShouldSearchPreferenceWithResourceConstructedFromCurrentUserByAuthorizedUserId() {
    final ContextualPreferenceExternalResource userResource = new ContextualPreferenceExternalResource(ContextualPreferenceLevel.USER, USER.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(hasItem(userResource)));
}
Also used : ContextualPreferenceExternalResource(com.epam.pipeline.entity.contextual.ContextualPreferenceExternalResource) ContextualPreference(com.epam.pipeline.entity.contextual.ContextualPreference) Test(org.junit.Test)

Example 34 with ContextualPreferenceExternalResource

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

the class AbstractDaoContextualPreferenceHandlerTest method searchShouldDelegateExecutionToTheNextHandlerIfNoneOfThePreferencesExist.

@Test
public void searchShouldDelegateExecutionToTheNextHandlerIfNoneOfThePreferencesExist() {
    final List<ContextualPreferenceExternalResource> resources = Collections.singletonList(resource);
    final ContextualPreference preference = new ContextualPreference(NAME, VALUE, resource);
    when(contextualPreferenceDao.load(eq(NAME), eq(resource))).thenReturn(Optional.empty());
    when(contextualPreferenceDao.load(eq(ANOTHER_NAME), eq(resource))).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(resource));
    verify(contextualPreferenceDao).load(eq(ANOTHER_NAME), eq(resource));
    verify(nextHandler).search(eq(SEVERAL_NAMES), eq(resources));
}
Also used : ContextualPreferenceExternalResource(com.epam.pipeline.entity.contextual.ContextualPreferenceExternalResource) ContextualPreference(com.epam.pipeline.entity.contextual.ContextualPreference) Test(org.junit.Test)

Example 35 with ContextualPreferenceExternalResource

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

the class DefaultContextualPreferenceReducerTest method reduceShouldReturnEmptyOptionalIfThereIsNoReducerForTheGivenPreference.

@Test
public void reduceShouldReturnEmptyOptionalIfThereIsNoReducerForTheGivenPreference() {
    final ContextualPreferenceExternalResource resource = new ContextualPreferenceExternalResource(LEVEL, RESOURCE_ID);
    final ContextualPreference preference1 = new ContextualPreference(ANOTHER_PREFERENCE, VALUE_1, resource);
    final ContextualPreference preference2 = new ContextualPreference(ANOTHER_PREFERENCE, VALUE_2, resource);
    final List<ContextualPreference> preferences = Arrays.asList(preference1, preference2);
    final Optional<ContextualPreference> reducedPreference = reducer.reduce(preferences);
    assertFalse(reducedPreference.isPresent());
}
Also used : ContextualPreferenceExternalResource(com.epam.pipeline.entity.contextual.ContextualPreferenceExternalResource) ContextualPreference(com.epam.pipeline.entity.contextual.ContextualPreference) Test(org.junit.Test)

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