Search in sources :

Example 1 with ContextualPreference

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

the class ContextualPreferenceDaoTest method upsertShouldSetCreatedDateWhileCreatingPreference.

@Test
public void upsertShouldSetCreatedDateWhileCreatingPreference() {
    final ContextualPreferenceExternalResource resource = new ContextualPreferenceExternalResource(LEVEL, RESOURCE_ID);
    contextualPreferenceDao.upsert(new ContextualPreference(NAME, VALUE, resource));
    final Optional<ContextualPreference> loadedPreference = contextualPreferenceDao.load(NAME, resource);
    assertTrue(loadedPreference.isPresent());
    assertNotNull(loadedPreference.get().getCreatedDate());
}
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 2 with ContextualPreference

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

the class ContextualPreferenceDaoTest method loadShouldReturnEmptyOptionalIfPreferenceDoesNotExist.

@Test
public void loadShouldReturnEmptyOptionalIfPreferenceDoesNotExist() {
    final ContextualPreferenceExternalResource resource = new ContextualPreferenceExternalResource(LEVEL, RESOURCE_ID);
    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 3 with ContextualPreference

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

the class ContextualPreferenceDaoTest method upsertShouldFailIfPreferenceHasEmptyFields.

@Test
public void upsertShouldFailIfPreferenceHasEmptyFields() {
    assertThrows(() -> {
        final ContextualPreference preferenceWithoutName = new ContextualPreference(null, VALUE, new ContextualPreferenceExternalResource(LEVEL, RESOURCE_ID));
        contextualPreferenceDao.upsert(preferenceWithoutName);
    });
    assertThrows(() -> {
        final ContextualPreference preferenceWithoutValue = new ContextualPreference(NAME, null, new ContextualPreferenceExternalResource(LEVEL, RESOURCE_ID));
        contextualPreferenceDao.upsert(preferenceWithoutValue);
    });
    assertThrows(() -> {
        final ContextualPreference preferenceWithoutType = new ContextualPreference(NAME, VALUE, null, new ContextualPreferenceExternalResource(LEVEL, RESOURCE_ID));
        contextualPreferenceDao.upsert(preferenceWithoutType);
    });
    assertThrows(() -> {
        final ContextualPreference preferenceWithoutType = new ContextualPreference(NAME, VALUE, PreferenceType.STRING, null);
        contextualPreferenceDao.upsert(preferenceWithoutType);
    });
    assertThrows(() -> {
        final ContextualPreference preferenceWithoutResourceLevel = new ContextualPreference(NAME, VALUE, new ContextualPreferenceExternalResource(null, RESOURCE_ID));
        contextualPreferenceDao.upsert(preferenceWithoutResourceLevel);
    });
    assertThrows(() -> {
        final ContextualPreference preferenceWithoutResourceId = new ContextualPreference(NAME, VALUE, new ContextualPreferenceExternalResource(LEVEL, null));
        contextualPreferenceDao.upsert(preferenceWithoutResourceId);
    });
}
Also used : ContextualPreference(com.epam.pipeline.entity.contextual.ContextualPreference) ContextualPreferenceExternalResource(com.epam.pipeline.entity.contextual.ContextualPreferenceExternalResource) Test(org.junit.Test) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest)

Example 4 with ContextualPreference

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

the class ContextualPreferenceDaoTest method upsertShouldUpdatePreferenceIfItAlreadyExists.

@Test
public void upsertShouldUpdatePreferenceIfItAlreadyExists() {
    final ContextualPreferenceExternalResource resource = new ContextualPreferenceExternalResource(LEVEL, RESOURCE_ID);
    final ContextualPreference preference = new ContextualPreference(NAME, VALUE, resource);
    contextualPreferenceDao.upsert(preference);
    contextualPreferenceDao.upsert(preference.withValue(ANOTHER_VALUE));
    final Optional<ContextualPreference> loadedPreference = contextualPreferenceDao.load(NAME, resource);
    assertTrue(loadedPreference.isPresent());
    assertThat(loadedPreference.get().getValue(), is(ANOTHER_VALUE));
}
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 5 with ContextualPreference

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

the class ContextualPreferenceDaoTest method loadShouldReturnAllPreferencesWithTheGivenName.

@Test
public void loadShouldReturnAllPreferencesWithTheGivenName() {
    final ContextualPreference preference1 = contextualPreferenceDao.upsert(new ContextualPreference(NAME, VALUE, new ContextualPreferenceExternalResource(LEVEL, RESOURCE_ID)));
    final ContextualPreference preference2 = contextualPreferenceDao.upsert(new ContextualPreference(NAME, VALUE, new ContextualPreferenceExternalResource(LEVEL, ANOTHER_RESOURCE_ID)));
    final ContextualPreference preference3 = contextualPreferenceDao.upsert(new ContextualPreference(NAME, VALUE, new ContextualPreferenceExternalResource(ANOTHER_LEVEL, ANOTHER_RESOURCE_ID)));
    contextualPreferenceDao.upsert(new ContextualPreference(ANOTHER_NAME, VALUE, new ContextualPreferenceExternalResource(ANOTHER_LEVEL, ANOTHER_RESOURCE_ID)));
    final List<ContextualPreference> loadedPreferences = contextualPreferenceDao.load(NAME);
    assertThat(loadedPreferences, containsInAnyOrder(preference1, preference2, preference3));
}
Also used : ContextualPreference(com.epam.pipeline.entity.contextual.ContextualPreference) ContextualPreferenceExternalResource(com.epam.pipeline.entity.contextual.ContextualPreferenceExternalResource) Test(org.junit.Test) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest)

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