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());
}
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());
}
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);
});
}
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));
}
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));
}
Aggregations