Search in sources :

Example 31 with ContextualPreference

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

the class RoleContextualPreferenceHandlerTest method searchShouldDelegateExecutionToTheNextHandlerIfNoneOfPreferencesExist.

@Test
public void searchShouldDelegateExecutionToTheNextHandlerIfNoneOfPreferencesExist() {
    final List<ContextualPreferenceExternalResource> resources = Arrays.asList(role1Resource, role2Resource);
    final ContextualPreference preference = new ContextualPreference(NAME, VALUE, role1Resource);
    when(contextualPreferenceDao.load(any(), any())).thenReturn(Optional.empty());
    when(nextHandler.search(eq(SEVERAL_NAMES), eq(resources))).thenReturn(Optional.of(preference));
    final Optional<ContextualPreference> searchedPreference = handler().search(SEVERAL_NAMES, resources);
    assertTrue(searchedPreference.isPresent());
    assertThat(searchedPreference.get(), is(preference));
    verify(contextualPreferenceDao).load(eq(NAME), eq(role1Resource));
    verify(contextualPreferenceDao).load(eq(NAME), eq(role2Resource));
    verify(contextualPreferenceDao).load(eq(ANOTHER_NAME), eq(role1Resource));
    verify(contextualPreferenceDao).load(eq(ANOTHER_NAME), eq(role2Resource));
}
Also used : ContextualPreferenceExternalResource(com.epam.pipeline.entity.contextual.ContextualPreferenceExternalResource) ContextualPreference(com.epam.pipeline.entity.contextual.ContextualPreference) Test(org.junit.Test)

Example 32 with ContextualPreference

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

the class ToolContextualPreferenceHandlerTest method isValidShouldReturnTrueIfToolExists.

@Test
public void isValidShouldReturnTrueIfToolExists() {
    final ContextualPreference preference = new ContextualPreference(NAME, VALUE, resource);
    when(toolDao.loadTool(eq(Long.valueOf(RESOURCE_ID)))).thenReturn(new Tool());
    assertTrue(handler().isValid(preference));
}
Also used : ContextualPreference(com.epam.pipeline.entity.contextual.ContextualPreference) Tool(com.epam.pipeline.entity.pipeline.Tool) Test(org.junit.Test)

Example 33 with ContextualPreference

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

the class ContextualPreferenceDao method upsert.

public ContextualPreference upsert(final ContextualPreference preference) {
    final ContextualPreference upsertingPreference = preference.withCreatedDate(DateUtils.now());
    getNamedParameterJdbcTemplate().update(insertContextualPreferenceQuery, ContextualPreferenceDao.Parameters.getParameters(upsertingPreference));
    return upsertingPreference;
}
Also used : ContextualPreference(com.epam.pipeline.entity.contextual.ContextualPreference)

Example 34 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 35 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)

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