Search in sources :

Example 6 with Preference

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

the class DataStorageManagerTest method testGenerateSharedURLForSharedStorage.

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void testGenerateSharedURLForSharedStorage() {
    Preference preference = SystemPreferences.BASE_API_SHARED.toPreference();
    preference.setValue(SHARED_BASE_URL_TEMPLATE);
    preferenceManager.update(Collections.singletonList(preference));
    DataStorageVO storageVO = ObjectCreatorUtils.constructDataStorageVO(NAME, DESCRIPTION, DataStorageType.S3, PATH, STS_DURATION, LTS_DURATION, WITHOUT_PARENT_ID, TEST_MOUNT_POINT, TEST_MOUNT_OPTIONS);
    storageVO.setShared(true);
    AbstractDataStorage saved = storageManager.create(storageVO, false, false, false);
    String url = storageManager.generateSharedUrlForStorage(saved.getId());
    Assert.assertEquals(SHARED_BASE_URL + saved.getId(), url);
}
Also used : AbstractDataStorage(com.epam.pipeline.entity.datastorage.AbstractDataStorage) Preference(com.epam.pipeline.entity.preference.Preference) DataStorageVO(com.epam.pipeline.controller.vo.DataStorageVO) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 7 with Preference

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

the class AttachmentFileManagerTest method setUp.

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    attachmentFileManager = new AttachmentFileManager(dataStorageManager, preferenceManager, attachmentManager, messageHelper, authManager);
    Preference systemDataStorage = SystemPreferences.DATA_STORAGE_SYSTEM_DATA_STORAGE_NAME.toPreference();
    systemDataStorage.setName(TEST_SYSTEM_DATA_STORAGE);
    when(preferenceManager.getPreference(SystemPreferences.DATA_STORAGE_SYSTEM_DATA_STORAGE_NAME)).thenReturn(TEST_SYSTEM_DATA_STORAGE);
    when(dataStorageManager.loadByNameOrId(TEST_SYSTEM_DATA_STORAGE)).thenReturn(testSystemDataStorage);
    when(dataStorageManager.createDataStorageFile(Mockito.eq(1L), Mockito.anyString(), Mockito.anyString(), Mockito.any(InputStream.class))).then((Answer<DataStorageFile>) invocation -> {
        String path = invocation.getArgumentAt(1, String.class);
        String name = invocation.getArgumentAt(2, String.class);
        DataStorageFile file = new DataStorageFile();
        file.setPath(path + "/" + name);
        return file;
    });
    when(attachmentManager.load(Mockito.anyLong())).thenAnswer(invocation -> {
        Attachment attachment = new Attachment();
        attachment.setId(invocation.getArgumentAt(0, Long.class));
        attachment.setName(TEST_ATTACHMENT_NAME);
        attachment.setPath(TEST_ATTACHMENT_PATH);
        return attachment;
    });
    DataStorageStreamingContent content = new DataStorageStreamingContent(new ByteArrayInputStream(new byte[] { 1 }), TEST_ATTACHMENT_NAME);
    when(dataStorageManager.getStreamingContent(testSystemDataStorage.getId(), TEST_ATTACHMENT_PATH, null)).thenReturn(content);
    when(authManager.getAuthorizedUser()).thenReturn(TEST_USER);
}
Also used : PreferenceManager(com.epam.pipeline.manager.preference.PreferenceManager) Mock(org.mockito.Mock) SystemPreferences(com.epam.pipeline.manager.preference.SystemPreferences) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Attachment(com.epam.pipeline.entity.issue.Attachment) Mockito.verify(org.mockito.Mockito.verify) DataStorageFile(com.epam.pipeline.entity.datastorage.DataStorageFile) Mockito(org.mockito.Mockito) MockitoAnnotations(org.mockito.MockitoAnnotations) Answer(org.mockito.stubbing.Answer) ArgumentCaptor(org.mockito.ArgumentCaptor) ByteArrayInputStream(java.io.ByteArrayInputStream) MessageHelper(com.epam.pipeline.common.MessageHelper) DataStorageStreamingContent(com.epam.pipeline.entity.datastorage.DataStorageStreamingContent) Matchers.eq(org.mockito.Matchers.eq) Preference(com.epam.pipeline.entity.preference.Preference) S3bucketDataStorage(com.epam.pipeline.entity.datastorage.aws.S3bucketDataStorage) AuthManager(com.epam.pipeline.manager.security.AuthManager) Assert(org.junit.Assert) DataStorageManager(com.epam.pipeline.manager.datastorage.DataStorageManager) InputStream(java.io.InputStream) Before(org.junit.Before) DataStorageFile(com.epam.pipeline.entity.datastorage.DataStorageFile) Preference(com.epam.pipeline.entity.preference.Preference) DataStorageStreamingContent(com.epam.pipeline.entity.datastorage.DataStorageStreamingContent) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Attachment(com.epam.pipeline.entity.issue.Attachment) Before(org.junit.Before)

Example 8 with Preference

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

the class PipelineRunManagerTest method testRunCmdFailed.

/**
 * Tests that Aspect will deny PipelineRunManager::runCmd method execution
 */
@Test(expected = ToolExecutionDeniedException.class)
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Throwable.class)
public void testRunCmdFailed() {
    PipelineStart startVO = new PipelineStart();
    preferenceManager.update(Arrays.asList(new Preference(SystemPreferences.DOCKER_SECURITY_TOOL_POLICY_DENY_NOT_SCANNED.getKey(), Boolean.toString(true))));
    startVO.setDockerImage(TEST_IMAGE);
    pipelineRunManager.runCmd(startVO);
}
Also used : Preference(com.epam.pipeline.entity.preference.Preference) PipelineStart(com.epam.pipeline.entity.pipeline.run.PipelineStart) AbstractManagerTest(com.epam.pipeline.manager.AbstractManagerTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 9 with Preference

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

the class PreferenceManagerTest method fetchTest.

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Throwable.class)
public void fetchTest() {
    Preference preference = new Preference(NAME, VALUE, GROUP, "", PreferenceType.STRING, true);
    preferenceManager.update(Collections.singletonList(preference));
    Preference load = preferenceManager.load(NAME).get();
    String fetch = preferenceManager.getStringPreference(NAME);
    Assert.assertEquals(fetch, load.getValue());
    preference.setValue(NEW_VALUE);
    preferenceManager.update(Collections.singletonList(preference));
    load = preferenceManager.load(NAME).get();
    fetch = preferenceManager.getStringPreference(NAME);
    Assert.assertEquals(fetch, load.getValue());
}
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 10 with Preference

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

the class PreferenceManagerTest method deleteTest.

@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Throwable.class)
public void deleteTest() {
    Preference preference = new Preference(NAME, VALUE, GROUP, "", PreferenceType.STRING, true);
    preferenceManager.update(Collections.singletonList(preference));
    String load = preferenceManager.getStringPreference(NAME);
    Assert.assertEquals(VALUE, load);
    preferenceManager.delete(NAME);
    Assert.assertNull(preferenceManager.getStringPreference(NAME));
}
Also used : Preference(com.epam.pipeline.entity.preference.Preference) 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