use of com.epam.pipeline.entity.contextual.ContextualPreference in project cloud-pipeline by epam.
the class ContextualPreferenceDaoTest method upsertShouldUpdateCreatedDateWhileUpdatingPreference.
@Test
public void upsertShouldUpdateCreatedDateWhileUpdatingPreference() {
final ContextualPreferenceExternalResource resource = new ContextualPreferenceExternalResource(LEVEL, RESOURCE_ID);
final ContextualPreference preference = new ContextualPreference(NAME, VALUE, resource);
final ContextualPreference oldPreference = contextualPreferenceDao.upsert(preference);
contextualPreferenceDao.upsert(oldPreference.withValue(ANOTHER_VALUE));
final Optional<ContextualPreference> loadedPreference = contextualPreferenceDao.load(NAME, resource);
assertTrue(loadedPreference.isPresent());
assertThat(loadedPreference.get().getCreatedDate(), is(not(oldPreference.getCreatedDate())));
}
use of com.epam.pipeline.entity.contextual.ContextualPreference in project cloud-pipeline by epam.
the class InstanceOfferManagerUnitTest method isToolInstanceAllowedShouldReturnTrueIfInstanceTypeMatchesOneOfTheAllowedPatterns.
@Test
public void isToolInstanceAllowedShouldReturnTrueIfInstanceTypeMatchesOneOfTheAllowedPatterns() {
when(contextualPreferenceManager.search(eq(DOCKER_INSTANCE_TYPES_PREFERENCES), eq(TOOL_RESOURCE))).thenReturn(new ContextualPreference(ALLOWED_DOCKER_INSTANCE_TYPES_PREFERENCE, M4_M5_PATTERNS));
assertTrue(instanceOfferManager.isToolInstanceAllowed(M4_LARGE, TOOL_RESOURCE));
verify(contextualPreferenceManager).search(eq(DOCKER_INSTANCE_TYPES_PREFERENCES), eq(TOOL_RESOURCE));
}
use of com.epam.pipeline.entity.contextual.ContextualPreference in project cloud-pipeline by epam.
the class InstanceOfferManagerUnitTest method isInstanceAllowedShouldReturnTrueIfInstanceTypeMatchesOneOfTheAllowedPatterns.
@Test
public void isInstanceAllowedShouldReturnTrueIfInstanceTypeMatchesOneOfTheAllowedPatterns() {
when(contextualPreferenceManager.search(eq(INSTANCE_TYPES_PREFERENCES), eq(null))).thenReturn(new ContextualPreference(ALLOWED_INSTANCE_TYPES_PREFERENCE, M4_M5_PATTERNS));
assertTrue(instanceOfferManager.isInstanceAllowed(M4_LARGE));
verify(contextualPreferenceManager).search(eq(INSTANCE_TYPES_PREFERENCES), eq(null));
}
use of com.epam.pipeline.entity.contextual.ContextualPreference in project cloud-pipeline by epam.
the class InstanceOfferManagerUnitTest method isInstanceAllowedShouldReturnFalseIfInstanceTypeDoesNotMatchAnyOfTheAllowedPatterns.
@Test
public void isInstanceAllowedShouldReturnFalseIfInstanceTypeDoesNotMatchAnyOfTheAllowedPatterns() {
when(contextualPreferenceManager.search(eq(INSTANCE_TYPES_PREFERENCES), eq(null))).thenReturn(new ContextualPreference(ALLOWED_INSTANCE_TYPES_PREFERENCE, M4_M5_PATTERNS));
assertFalse(instanceOfferManager.isInstanceAllowed(T2_LARGE));
verify(contextualPreferenceManager).search(eq(INSTANCE_TYPES_PREFERENCES), eq(null));
}
use of com.epam.pipeline.entity.contextual.ContextualPreference in project cloud-pipeline by epam.
the class InstanceOfferManagerUnitTest method getAllowedInstanceAndPriceTypesShouldSearchPreferencesIfToolIdIsNull.
@Test
public void getAllowedInstanceAndPriceTypesShouldSearchPreferencesIfToolIdIsNull() {
final List<String> allowedPriceTypes = Arrays.asList(SPOT, ON_DEMAND);
final List<InstanceType> allInstanceTypes = Arrays.asList(m4InstanceType, m5InstanceType, t2InstanceType);
final List<InstanceType> allowedInstanceTypes = Arrays.asList(m4InstanceType, m5InstanceType);
final List<InstanceType> allowedInstanceDockerTypes = Collections.singletonList(m4InstanceType);
when(contextualPreferenceManager.search(eq(INSTANCE_TYPES_PREFERENCES), eq(null))).thenReturn(new ContextualPreference(ALLOWED_INSTANCE_TYPES_PREFERENCE, M4_M5_PATTERNS));
when(contextualPreferenceManager.search(eq(Arrays.asList(ALLOWED_DOCKER_INSTANCE_TYPES_PREFERENCE, ALLOWED_INSTANCE_TYPES_PREFERENCE)), eq(null))).thenReturn(new ContextualPreference(ALLOWED_DOCKER_INSTANCE_TYPES_PREFERENCE, M4_PATTERN));
when(contextualPreferenceManager.search(eq(Collections.singletonList(ALLOWED_PRICE_TYPES_PREFERENCE)), eq(null))).thenReturn(new ContextualPreference(ALLOWED_PRICE_TYPES_PREFERENCE, SPOT_AND_ON_DEMAND_TYPES));
when(instanceOfferDao.loadInstanceTypes(any())).thenReturn(allInstanceTypes);
final AllowedInstanceAndPriceTypes allowedInstanceAndPriceTypes = instanceOfferManager.getAllowedInstanceAndPriceTypes(null);
assertThat(allowedInstanceAndPriceTypes.getAllowedInstanceTypes(), is(allowedInstanceTypes));
assertThat(allowedInstanceAndPriceTypes.getAllowedInstanceDockerTypes(), is(allowedInstanceDockerTypes));
assertThat(allowedInstanceAndPriceTypes.getAllowedPriceTypes(), is(allowedPriceTypes));
}
Aggregations