Search in sources :

Example 21 with ContextualPreference

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

the class ContextualPreferenceDaoTest method loadAllShouldReturnListOfAllPreferences.

@Test
public void loadAllShouldReturnListOfAllPreferences() {
    final ContextualPreferenceExternalResource resource = new ContextualPreferenceExternalResource(LEVEL, RESOURCE_ID);
    final ContextualPreference storedPreference1 = contextualPreferenceDao.upsert(new ContextualPreference(NAME, VALUE, resource));
    final ContextualPreference storedPreference2 = contextualPreferenceDao.upsert(new ContextualPreference(ANOTHER_NAME, ANOTHER_VALUE, resource));
    assertThat(contextualPreferenceDao.loadAll(), containsInAnyOrder(storedPreference1, storedPreference2));
}
Also used : ContextualPreferenceExternalResource(com.epam.pipeline.entity.contextual.ContextualPreferenceExternalResource) ContextualPreference(com.epam.pipeline.entity.contextual.ContextualPreference) Test(org.junit.Test) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest)

Example 22 with ContextualPreference

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

the class ContextualPreferenceDaoTest method deleteShouldRemovePreference.

@Test
public void deleteShouldRemovePreference() {
    final ContextualPreferenceExternalResource resource = new ContextualPreferenceExternalResource(LEVEL, RESOURCE_ID);
    contextualPreferenceDao.upsert(new ContextualPreference(NAME, VALUE, resource));
    contextualPreferenceDao.delete(NAME, resource);
    final Optional<ContextualPreference> loadedPreference = contextualPreferenceDao.load(NAME, resource);
    assertFalse(loadedPreference.isPresent());
}
Also used : ContextualPreferenceExternalResource(com.epam.pipeline.entity.contextual.ContextualPreferenceExternalResource) ContextualPreference(com.epam.pipeline.entity.contextual.ContextualPreference) Test(org.junit.Test) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest)

Example 23 with ContextualPreference

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

the class AbstractContextualPreferenceHandlerTest method isValidShouldReturnFalseIfPreferenceLevelDoesNotSuitCurrentHandlerAndThereIsNoNextHandler.

@Test
public void isValidShouldReturnFalseIfPreferenceLevelDoesNotSuitCurrentHandlerAndThereIsNoNextHandler() {
    final ContextualPreference preference = new ContextualPreference(NAME, VALUE, notSuitableResource);
    assertFalse(lastHandler().isValid(preference));
}
Also used : ContextualPreference(com.epam.pipeline.entity.contextual.ContextualPreference) Test(org.junit.Test)

Example 24 with ContextualPreference

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

the class ArrayContextualPreferenceReducerTest method reduceShouldReturnPreferenceWithMergedValue.

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

Example 25 with ContextualPreference

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

the class ArrayContextualPreferenceReducerTest method reduceShouldReturnPreferenceWithoutCreatedDateAndResource.

@Test
public void reduceShouldReturnPreferenceWithoutCreatedDateAndResource() {
    final ContextualPreferenceExternalResource resource = new ContextualPreferenceExternalResource(LEVEL, RESOURCE_ID);
    final ContextualPreference preference1 = new ContextualPreference(NAME, VALUE_1, resource);
    final ContextualPreference preference2 = new ContextualPreference(NAME, VALUE_2, resource);
    final List<ContextualPreference> preferences = Arrays.asList(preference1, preference2);
    final Optional<ContextualPreference> reducedPreference = reducer.reduce(preferences);
    assertTrue(reducedPreference.isPresent());
    assertThat(reducedPreference.get().getCreatedDate(), is(nullValue()));
    assertThat(reducedPreference.get().getResource(), is(nullValue()));
}
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