Search in sources :

Example 11 with Preference

use of com.epam.pipeline.entity.preference.Preference in project cloud-pipeline by epam.

the class PreferenceManagerTest method castToObjectTest.

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Throwable.class)
public void castToObjectTest() {
    Preference preference = new Preference(NAME, OBJECT, GROUP, "", PreferenceType.OBJECT, true);
    preferenceManager.update(Collections.singletonList(preference));
    Map<String, Object> load = preferenceManager.getObjectPreference(NAME);
    Assert.assertEquals("first", load.get("name"));
    Assert.assertEquals(1, ((Map<String, Object>) load.get("object")).get("param1"));
    Assert.assertEquals(2, ((Map<String, Object>) load.get("object")).get("param2"));
}
Also used : Preference(com.epam.pipeline.entity.preference.Preference) Test(org.junit.Test) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 12 with Preference

use of com.epam.pipeline.entity.preference.Preference in project cloud-pipeline by epam.

the class PreferenceManagerTest method castExceptionTest.

@Test(expected = IllegalArgumentException.class)
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Throwable.class)
public void castExceptionTest() {
    Preference preference = new Preference(NAME, "1", GROUP, "", PreferenceType.STRING, true);
    preferenceManager.update(Collections.singletonList(preference));
    preferenceManager.getIntPreference(NAME);
}
Also used : Preference(com.epam.pipeline.entity.preference.Preference) Test(org.junit.Test) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 13 with Preference

use of com.epam.pipeline.entity.preference.Preference in project cloud-pipeline by epam.

the class AwsRegionManagerTest method createShouldSetCorsRulesToDefaultValueIfMissing.

@Test
public void createShouldSetCorsRulesToDefaultValueIfMissing() {
    final String corsRulesAsString = "[{" + "\"id\":\"id1\"," + "\"allowedOrigins\":[\"origin1\",\"origin2\"]," + "\"maxAgeSeconds\":0" + "},{" + "\"id\":\"id2\"," + "\"maxAgeSeconds\":0," + "\"allowedHeaders\":[\"header1\"]" + "}]";
    Preference corsPolicy = new Preference();
    corsPolicy.setValue(corsRulesAsString);
    doReturn(Optional.of(corsPolicy)).when(preferenceManager).load(eq(SystemPreferences.DATA_STORAGE_CORS_POLICY.getKey()));
    final AwsRegionVO regionVO = getAwsRegionVoBuilder().policy(EMPTY_POLICY).kmsKeyId(KMS_KEY_ID).kmsKeyArn(KMS_KEY_ARN).awsRegionName(VALID_REGION_ID).isDefault(false).build();
    awsRegionManager.create(regionVO);
    final ArgumentCaptor<AwsRegion> regionCaptor = ArgumentCaptor.forClass(AwsRegion.class);
    verify(awsRegionDao).create(regionCaptor.capture());
    final AwsRegion actualRegion = regionCaptor.getValue();
    assertThat(actualRegion.getCorsRules(), is(corsRulesAsString));
}
Also used : AwsRegion(com.epam.pipeline.entity.region.AwsRegion) Preference(com.epam.pipeline.entity.preference.Preference) Matchers.isEmptyOrNullString(org.hamcrest.Matchers.isEmptyOrNullString) AwsRegionVO(com.epam.pipeline.controller.vo.AwsRegionVO) Test(org.junit.Test)

Example 14 with Preference

use of com.epam.pipeline.entity.preference.Preference in project cloud-pipeline by epam.

the class UtilsManagerTest method testGetSystemParameters.

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Throwable.class)
public void testGetSystemParameters() throws IOException {
    File parametersJson = context.getResource("classpath:templates/default_parameters.json").getFile();
    Preference pref = SystemPreferences.LAUNCH_SYSTEM_PARAMETERS.toPreference();
    pref.setValue(Files.readAllLines(parametersJson.toPath()).stream().collect(Collectors.joining()));
    preferenceManager.update(Collections.singletonList(pref));
    List<DefaultSystemParameter> params = utilsManager.getSystemParameters();
    Assert.assertFalse(params.isEmpty());
}
Also used : DefaultSystemParameter(com.epam.pipeline.entity.utils.DefaultSystemParameter) Preference(com.epam.pipeline.entity.preference.Preference) File(java.io.File) Test(org.junit.Test) AbstractManagerTest(com.epam.pipeline.manager.AbstractManagerTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 15 with Preference

use of com.epam.pipeline.entity.preference.Preference in project cloud-pipeline by epam.

the class PreferenceDaoTest method testCRUDPreference.

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
public void testCRUDPreference() {
    Preference savedPreference = preferenceDao.upsertPreference(preference);
    assertNotNull(savedPreference);
    assertEquals(preference, savedPreference);
    preferenceDao.upsertPreference(preference2);
    String newValue = "new value";
    String newDescription = "new description";
    String newGroup = "new group";
    PreferenceType newType = PreferenceType.FLOAT;
    preference.setValue(newValue);
    preference.setDescription(newDescription);
    preference.setPreferenceGroup(newGroup);
    preference.setType(newType);
    Preference updatedPreference = preferenceDao.upsertPreference(preference);
    assertEquals(preference, updatedPreference);
    Preference loadedByName = preferenceDao.loadPreferenceByName(TEST_NAME);
    assertEquals(preference, loadedByName);
    assertEquals(updatedPreference, loadedByName);
    Preference loadedPref2 = preferenceDao.loadPreferenceByName(preference2.getName());
    assertNotNull(loadedPref2);
    assertEquals(TEST_VALUE_2, loadedPref2.getValue());
    List<Preference> preferenceList = preferenceDao.loadAllPreferences();
    assertEquals(2, preferenceList.size());
    preferenceDao.deletePreference(savedPreference.getName());
    assertNull(preferenceDao.loadPreferenceByName(savedPreference.getName()));
}
Also used : Preference(com.epam.pipeline.entity.preference.Preference) PreferenceType(com.epam.pipeline.entity.preference.PreferenceType) Test(org.junit.Test) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Preference (com.epam.pipeline.entity.preference.Preference)27 Test (org.junit.Test)20 Transactional (org.springframework.transaction.annotation.Transactional)17 AbstractSpringTest (com.epam.pipeline.AbstractSpringTest)11 AbstractManagerTest (com.epam.pipeline.manager.AbstractManagerTest)5 Before (org.junit.Before)5 DataStorageVO (com.epam.pipeline.controller.vo.DataStorageVO)3 AwsRegionVO (com.epam.pipeline.controller.vo.AwsRegionVO)2 Attachment (com.epam.pipeline.entity.issue.Attachment)2 AwsRegion (com.epam.pipeline.entity.region.AwsRegion)2 ObjectPreference (com.epam.pipeline.manager.preference.AbstractSystemPreference.ObjectPreference)2 PreferenceManager (com.epam.pipeline.manager.preference.PreferenceManager)2 SystemPreferences (com.epam.pipeline.manager.preference.SystemPreferences)2 Matchers.isEmptyOrNullString (org.hamcrest.Matchers.isEmptyOrNullString)2 MessageHelper (com.epam.pipeline.common.MessageHelper)1 EntityVO (com.epam.pipeline.controller.vo.EntityVO)1 PreferenceDao (com.epam.pipeline.dao.preference.PreferenceDao)1 AbstractDataStorage (com.epam.pipeline.entity.datastorage.AbstractDataStorage)1 DataStorageFile (com.epam.pipeline.entity.datastorage.DataStorageFile)1 DataStorageStreamingContent (com.epam.pipeline.entity.datastorage.DataStorageStreamingContent)1