Search in sources :

Example 1 with ContextualPreferenceExternalResource

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

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

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

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

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

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