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