Search in sources :

Example 36 with Folder

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

the class FolderManagerTest method testGetProjectFolderFromProjectTree.

@Test
public void testGetProjectFolderFromProjectTree() {
    Map<String, PipeConfValue> data = new HashMap<>();
    data.put(DATA_KEY_1, new PipeConfValue(DATA_TYPE_1, DATA_VALUE_1));
    Map<String, PipeConfValue> dataWithIndicator = new HashMap<>();
    dataWithIndicator.put(DATA_KEY_1, new PipeConfValue(DATA_TYPE_1, PROJECT_INDICATOR_VALUE));
    FolderWithMetadata folder = initFolderWithMetadata(new FolderWithMetadata(), 1L, "folder", null, data);
    FolderWithMetadata folder1 = initFolderWithMetadata(new FolderWithMetadata(), 2L, "folder1", folder.getId(), dataWithIndicator);
    FolderWithMetadata folder2 = initFolderWithMetadata(new FolderWithMetadata(), 3L, "folder2", folder1.getId(), data);
    Map<Long, FolderWithMetadata> folders = new HashMap<>();
    folders.put(folder.getId(), folder);
    folders.put(folder1.getId(), folder1);
    folders.put(folder2.getId(), folder2);
    Set<Pair<String, String>> indicators = new HashSet<>();
    indicators.add(new ImmutablePair<>(DATA_KEY_1, PROJECT_INDICATOR_VALUE));
    // case: single indicator
    Folder actualFolder = folderManager.getProjectFolder(folders, folder2.getId(), indicators);
    assertEquals(folder1.getId(), actualFolder.getId());
    assertEquals(folder1.getName(), actualFolder.getName());
    assertEquals(folder1.getParentId(), actualFolder.getParentId());
    assertEquals(folder1.getOwner(), actualFolder.getOwner());
    // case: several indicators
    indicators.add(new ImmutablePair<>(PROJECT_INDICATOR_VALUE, DATA_KEY_1));
    dataWithIndicator = new HashMap<>();
    dataWithIndicator.put(PROJECT_INDICATOR_VALUE, new PipeConfValue(DATA_TYPE_1, DATA_KEY_1));
    folder2.setData(dataWithIndicator);
    folders.put(folder2.getId(), folder2);
    actualFolder = folderManager.getProjectFolder(folders, folder2.getId(), indicators);
    assertEquals(folder2.getId(), actualFolder.getId());
    assertEquals(folder2.getName(), actualFolder.getName());
    assertEquals(folder2.getParentId(), actualFolder.getParentId());
    assertEquals(folder2.getOwner(), actualFolder.getOwner());
    // case: no matches (null parent)
    folder1.setData(data);
    folder2.setData(data);
    folders.put(folder1.getId(), folder1);
    folders.put(folder2.getId(), folder2);
    actualFolder = folderManager.getProjectFolder(folders, folder2.getId(), indicators);
    assertNull(actualFolder);
    // case: no matches (no null parent)
    folders.remove(folder.getId());
    actualFolder = folderManager.getProjectFolder(folders, folder2.getId(), indicators);
    assertNull(actualFolder);
}
Also used : HashMap(java.util.HashMap) PasswordGenerator.generateRandomString(com.epam.pipeline.utils.PasswordGenerator.generateRandomString) Folder(com.epam.pipeline.entity.pipeline.Folder) FolderWithMetadata(com.epam.pipeline.entity.metadata.FolderWithMetadata) PipeConfValue(com.epam.pipeline.entity.metadata.PipeConfValue) Pair(org.apache.commons.lang3.tuple.Pair) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) HashSet(java.util.HashSet) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest) Test(org.junit.Test)

Example 37 with Folder

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

the class FolderManagerTest method setUp.

@Before
public void setUp() throws Exception {
    awsRegionManager.create(AwsRegionVO.builder().name("US").awsRegionName("us-east-1").isDefault(true).build());
    doReturn(new MockS3Helper()).when(storageProviderManager).getS3Helper(any());
    folder = new Folder();
    folder.setName(TEST_NAME);
    subFolder = new Folder();
    subFolder.setName(TEST_NAME_1);
    MockitoAnnotations.initMocks(this);
    when(gitManagerMock.getPipelineRevisions(any(Pipeline.class), any(Long.class))).thenReturn(Collections.emptyList());
    pipelineManager.setGitManager(gitManagerMock);
}
Also used : Folder(com.epam.pipeline.entity.pipeline.Folder) MockS3Helper(com.epam.pipeline.manager.MockS3Helper) Pipeline(com.epam.pipeline.entity.pipeline.Pipeline) Before(org.junit.Before)

Example 38 with Folder

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

the class FolderManagerTest method deleteFolder.

@Test(expected = IllegalArgumentException.class)
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
public void deleteFolder() throws Exception {
    folderManager.create(folder);
    Folder loaded = folderManager.load(folder.getId());
    assertNotNull(loaded);
    folderManager.delete(folder.getId());
    folderManager.load(folder.getId());
}
Also used : Folder(com.epam.pipeline.entity.pipeline.Folder) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 39 with Folder

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

the class FolderManagerTest method shouldCloneFolderTree.

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
public void shouldCloneFolderTree() {
    Folder sourceFolder = new Folder();
    sourceFolder.setName(FOLDER_TO_CLONE);
    folderManager.create(sourceFolder);
    Folder childSourceFolder = new Folder();
    childSourceFolder.setName(CHILD_FOLDER_TO_CLONE);
    childSourceFolder.setParentId(sourceFolder.getId());
    folderManager.create(childSourceFolder);
    Folder destinationFolder = new Folder();
    destinationFolder.setName(TEST_NAME);
    folderManager.create(destinationFolder);
    Folder clonedFolder = folderManager.cloneFolder(sourceFolder.getId(), destinationFolder.getId(), TEST_CLONE_PREFIX);
    assertTrue(CollectionUtils.isEmpty(clonedFolder.getChildFolders()));
    clonedFolder = folderManager.load(clonedFolder.getId());
    assertEquals(destinationFolder.getId(), clonedFolder.getParentId());
    assertNotNull(clonedFolder);
    assertTrue(clonedFolder.getName().startsWith(TEST_CLONE_PREFIX));
    Folder clonedChildFolder = clonedFolder.getChildFolders().get(0);
    assertNotNull(clonedChildFolder);
    assertEquals(CHILD_FOLDER_TO_CLONE, clonedChildFolder.getName());
}
Also used : Folder(com.epam.pipeline.entity.pipeline.Folder) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 40 with Folder

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

the class FolderManagerTest method testDataStorageCountInFolder.

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
public void testDataStorageCountInFolder() {
    Folder sourceFolder = generateFolder(null);
    Folder childFolderWithStorage1 = generateFolder(sourceFolder.getId());
    generateDataStorage(childFolderWithStorage1.getId());
    Folder childFolderWithoutStorage = generateFolder(childFolderWithStorage1.getId());
    Folder childFolderWithStorage2 = generateFolder(sourceFolder.getId());
    generateDataStorage(childFolderWithStorage2.getId());
    Folder childFolderWithStorage3 = generateFolder(childFolderWithStorage2.getId());
    generateDataStorage(childFolderWithStorage3.getId());
    generateDataStorage(childFolderWithStorage3.getId());
    assertEquals(4, folderManager.countDataStorages(folderManager.load(sourceFolder.getId())));
    assertEquals(0, folderManager.countDataStorages(folderManager.load(childFolderWithoutStorage.getId())));
    assertEquals(1, folderManager.countDataStorages(folderManager.load(childFolderWithStorage1.getId())));
    assertEquals(3, folderManager.countDataStorages(folderManager.load(childFolderWithStorage2.getId())));
    assertEquals(2, folderManager.countDataStorages(folderManager.load(childFolderWithStorage3.getId())));
}
Also used : Folder(com.epam.pipeline.entity.pipeline.Folder) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Folder (com.epam.pipeline.entity.pipeline.Folder)102 Transactional (org.springframework.transaction.annotation.Transactional)53 Test (org.junit.Test)52 AbstractSpringTest (com.epam.pipeline.AbstractSpringTest)48 EntityVO (com.epam.pipeline.controller.vo.EntityVO)14 AbstractDataStorage (com.epam.pipeline.entity.datastorage.AbstractDataStorage)14 Pipeline (com.epam.pipeline.entity.pipeline.Pipeline)14 MetadataClass (com.epam.pipeline.entity.metadata.MetadataClass)13 RunConfiguration (com.epam.pipeline.entity.configuration.RunConfiguration)11 MetadataEntity (com.epam.pipeline.entity.metadata.MetadataEntity)11 PipeConfValue (com.epam.pipeline.entity.metadata.PipeConfValue)10 AclClass (com.epam.pipeline.entity.security.acl.AclClass)10 Autowired (org.springframework.beans.factory.annotation.Autowired)8 Propagation (org.springframework.transaction.annotation.Propagation)8 MetadataEntityVO (com.epam.pipeline.controller.vo.metadata.MetadataEntityVO)7 PasswordGenerator.generateRandomString (com.epam.pipeline.utils.PasswordGenerator.generateRandomString)6 FolderWithMetadata (com.epam.pipeline.entity.metadata.FolderWithMetadata)5 DataStorageVO (com.epam.pipeline.controller.vo.DataStorageVO)4 AbstractManagerTest (com.epam.pipeline.manager.AbstractManagerTest)4 Collectors (java.util.stream.Collectors)4