Search in sources :

Example 41 with Folder

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

the class FolderManagerTest method shouldCloneFolderWithMetadataEntities.

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
public void shouldCloneFolderWithMetadataEntities() {
    Folder sourceFolder = new Folder();
    sourceFolder.setName(FOLDER_TO_CLONE);
    folderManager.create(sourceFolder);
    Map<String, PipeConfValue> metadata = new HashMap<>();
    metadata.put(DATA_KEY_1, new PipeConfValue(DATA_TYPE_1, DATA_VALUE_1));
    MetadataClass metadataClass = metadataEntityManager.createMetadataClass(TEST_NAME);
    MetadataEntityVO metadataEntity = new MetadataEntityVO();
    metadataEntity.setParentId(sourceFolder.getId());
    metadataEntity.setClassName(metadataClass.getName());
    metadataEntity.setClassId(metadataClass.getId());
    metadataEntity.setData(metadata);
    metadataEntity.setEntityName(TEST_NAME);
    MetadataEntity expectedMetadata = metadataEntityManager.updateMetadataEntity(metadataEntity);
    Folder childSourceFolder = new Folder();
    childSourceFolder.setName(CHILD_FOLDER_TO_CLONE);
    childSourceFolder.setParentId(sourceFolder.getId());
    folderManager.create(childSourceFolder);
    metadataEntity.setParentId(childSourceFolder.getId());
    metadataEntityManager.updateMetadataEntity(metadataEntity);
    Folder destinationFolder = new Folder();
    destinationFolder.setName(TEST_NAME);
    folderManager.create(destinationFolder);
    folderManager.cloneFolder(sourceFolder.getId(), destinationFolder.getId(), TEST_CLONE_PREFIX);
    destinationFolder = folderManager.loadByNameOrId(TEST_NAME);
    destinationFolder = folderManager.load(destinationFolder.getId());
    Folder clonedFolder = destinationFolder.getChildFolders().get(0);
    MetadataEntity clonedMetadata = metadataEntityManager.loadMetadataEntityByClassNameAndFolderId(clonedFolder.getId(), metadataClass.getName()).get(0);
    assertMetadataEntity(expectedMetadata, clonedMetadata);
    Folder clonedChildFolder = clonedFolder.getChildFolders().get(0);
    clonedMetadata = metadataEntityManager.loadMetadataEntityByClassNameAndFolderId(clonedChildFolder.getId(), metadataClass.getName()).get(0);
    assertMetadataEntity(expectedMetadata, clonedMetadata);
}
Also used : MetadataEntity(com.epam.pipeline.entity.metadata.MetadataEntity) MetadataClass(com.epam.pipeline.entity.metadata.MetadataClass) HashMap(java.util.HashMap) PipeConfValue(com.epam.pipeline.entity.metadata.PipeConfValue) PasswordGenerator.generateRandomString(com.epam.pipeline.utils.PasswordGenerator.generateRandomString) Folder(com.epam.pipeline.entity.pipeline.Folder) MetadataEntityVO(com.epam.pipeline.controller.vo.metadata.MetadataEntityVO) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 42 with Folder

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

the class FolderTemplateManagerTest method createFolderFromTemplateTest.

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
@WithMockUser(username = TEST_USER)
public void createFolderFromTemplateTest() throws IOException {
    Map<String, PipeConfValue> metadata = new HashMap<>();
    metadata.put(DATA_KEY_1, new PipeConfValue(DATA_TYPE_1, DATA_VALUE_1));
    DataStorageWithMetadataVO dataStorageVO = new DataStorageWithMetadataVO();
    dataStorageVO.setName(DATASTORAGE_NAME_1);
    dataStorageVO.setType(DataStorageType.S3);
    dataStorageVO.setPath(TEST_PATH);
    dataStorageVO.setMetadata(metadata);
    PermissionVO permissionVO = new PermissionVO();
    permissionVO.setMask(AclPermission.READ.getMask());
    permissionVO.setUserName(TEST_ROLE);
    permissionVO.setPrincipal(false);
    FolderTemplate childFolderTemplate1 = FolderTemplate.builder().name(CHILD_TEMPLATE_FOLDER_NAME_1).build();
    FolderTemplate folderTemplate = FolderTemplate.builder().name(TEMPLATE_FOLDER_NAME).datastorages(Stream.of(dataStorageVO).collect(Collectors.toList())).children(Stream.of(childFolderTemplate1).collect(Collectors.toList())).metadata(metadata).permissions(Stream.of(permissionVO).collect(Collectors.toList())).build();
    Folder folder = new Folder();
    folder.setName(TEMPLATE_FOLDER_NAME);
    folderTemplateManager.createFolderFromTemplate(folder, folderTemplate);
    Folder savedRootFolder = folderManager.loadByNameOrId(TEMPLATE_FOLDER_NAME);
    savedRootFolder = folderManager.load(savedRootFolder.getId());
    Assert.assertNotNull(savedRootFolder);
    Long rootFolderId = savedRootFolder.getId();
    List<EntityVO> metadataEntries = Collections.singletonList(new EntityVO(rootFolderId, AclClass.FOLDER));
    Assert.assertEquals(metadata, metadataManager.listMetadataItems(metadataEntries).get(0).getData());
    AbstractDataStorage clonedDataStorage = savedRootFolder.getStorages().get(0);
    clonedDataStorage = dataStorageManager.load(clonedDataStorage.getId());
    Assert.assertTrue(clonedDataStorage.getName().startsWith(DATASTORAGE_NAME_1));
    Assert.assertTrue(clonedDataStorage.getPath().startsWith(TEST_PATH));
    metadataEntries = Collections.singletonList(new EntityVO(clonedDataStorage.getId(), AclClass.DATA_STORAGE));
    Assert.assertEquals(metadata, metadataManager.listMetadataItems(metadataEntries).get(0).getData());
    List<AclPermissionEntry> rootFolderPermissions = permissionManager.getPermissions(rootFolderId, AclClass.FOLDER).getPermissions();
    Assert.assertEquals(1, rootFolderPermissions.size());
    AclPermissionEntry actualPermission = rootFolderPermissions.get(0);
    Assert.assertEquals(permissionVO.getMask(), actualPermission.getMask());
    Assert.assertEquals(permissionVO.getPrincipal(), actualPermission.getSid().isPrincipal());
    Assert.assertEquals(permissionVO.getUserName(), actualPermission.getSid().getName());
    Folder savedChildFolder = folderManager.loadByNameOrId(TEMPLATE_FOLDER_NAME + "/" + CHILD_TEMPLATE_FOLDER_NAME_1);
    Assert.assertNotNull(savedChildFolder);
    Assert.assertEquals(rootFolderId, savedChildFolder.getParentId());
}
Also used : HashMap(java.util.HashMap) FolderTemplate(com.epam.pipeline.entity.templates.FolderTemplate) Folder(com.epam.pipeline.entity.pipeline.Folder) EntityVO(com.epam.pipeline.controller.vo.EntityVO) AbstractDataStorage(com.epam.pipeline.entity.datastorage.AbstractDataStorage) PipeConfValue(com.epam.pipeline.entity.metadata.PipeConfValue) AclPermissionEntry(com.epam.pipeline.entity.security.acl.AclPermissionEntry) DataStorageWithMetadataVO(com.epam.pipeline.controller.vo.data.storage.DataStorageWithMetadataVO) PermissionVO(com.epam.pipeline.controller.vo.PermissionVO) WithMockUser(org.springframework.security.test.context.support.WithMockUser) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 43 with Folder

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

the class FolderLoaderTest method shouldLoadFolder.

@Test
void shouldLoadFolder() throws EntityNotFoundException {
    Folder expectedFolder = new Folder(1L);
    expectedFolder.setName(TEST_NAME);
    expectedFolder.setParentId(1L);
    expectedFolder.setOwner(TEST_NAME);
    FolderLoader loader = new FolderLoader(apiClient);
    when(apiClient.loadPipelineFolder(anyLong())).thenReturn(expectedFolder);
    Optional<EntityContainer<Folder>> container = loader.loadEntity(1L);
    EntityContainer<Folder> folderEntityContainer = container.orElseThrow(AssertionError::new);
    Folder actualFolder = folderEntityContainer.getEntity();
    assertNotNull(actualFolder);
    assertEquals(expectedFolder.getName(), actualFolder.getName());
    assertEquals(expectedFolder.getId(), actualFolder.getId());
    assertEquals(expectedFolder.getParentId(), actualFolder.getParentId());
    verifyPipelineUser(folderEntityContainer.getOwner());
    verifyPermissions(PERMISSIONS_CONTAINER_WITH_OWNER, folderEntityContainer.getPermissions());
    verifyMetadata(EXPECTED_METADATA, new ArrayList<>(folderEntityContainer.getMetadata().values()));
}
Also used : EntityContainer(com.epam.pipeline.elasticsearchagent.model.EntityContainer) Folder(com.epam.pipeline.entity.pipeline.Folder) Test(org.junit.jupiter.api.Test)

Example 44 with Folder

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

the class MetadataEntityLoaderTest method shouldLoadMetadataEntityTest.

@Test
void shouldLoadMetadataEntityTest() throws EntityNotFoundException {
    MetadataClass metadataClass = new MetadataClass(1L, "Sample");
    MetadataEntity expectedMetadataEntity = new MetadataEntity();
    expectedMetadataEntity.setClassEntity(metadataClass);
    expectedMetadataEntity.setId(1L);
    expectedMetadataEntity.setExternalId("external");
    expectedMetadataEntity.setParent(new Folder(1L));
    expectedMetadataEntity.setName(TEST_NAME);
    expectedMetadataEntity.setOwner(TEST_NAME);
    expectedMetadataEntity.setData(Collections.singletonMap(TEST_KEY, new PipeConfValue("string", TEST_VALUE)));
    MetadataEntityLoader metadataEntityLoader = new MetadataEntityLoader(apiClient);
    when(apiClient.loadMetadataEntity(anyLong())).thenReturn(expectedMetadataEntity);
    Optional<EntityContainer<MetadataEntity>> container = metadataEntityLoader.loadEntity(1L);
    EntityContainer<MetadataEntity> metadataEntityContainer = container.orElseThrow(AssertionError::new);
    MetadataEntity actualMetadataEntity = metadataEntityContainer.getEntity();
    assertNotNull(actualMetadataEntity);
    verifyMetadataEntity(expectedMetadataEntity, actualMetadataEntity);
    verifyPermissions(PERMISSIONS_CONTAINER_WITH_OWNER, metadataEntityContainer.getPermissions());
    verifyMetadata(EXPECTED_METADATA, new ArrayList<>(metadataEntityContainer.getMetadata().values()));
}
Also used : LoaderVerificationUtils.verifyMetadataEntity(com.epam.pipeline.elasticsearchagent.LoaderVerificationUtils.verifyMetadataEntity) MetadataEntity(com.epam.pipeline.entity.metadata.MetadataEntity) MetadataClass(com.epam.pipeline.entity.metadata.MetadataClass) PipeConfValue(com.epam.pipeline.entity.metadata.PipeConfValue) EntityContainer(com.epam.pipeline.elasticsearchagent.model.EntityContainer) Folder(com.epam.pipeline.entity.pipeline.Folder) Test(org.junit.jupiter.api.Test)

Example 45 with Folder

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

the class FolderMapperTest method shouldMapFolder.

@Test
void shouldMapFolder() throws IOException {
    FolderMapper mapper = new FolderMapper();
    Folder folder = new Folder(1L);
    folder.setName(TEST_NAME);
    folder.setParentId(1L);
    EntityContainer<Folder> container = EntityContainer.<Folder>builder().entity(folder).owner(USER).metadata(METADATA).permissions(PERMISSIONS_CONTAINER).build();
    XContentBuilder contentBuilder = mapper.map(container);
    verifyFolder(folder, contentBuilder);
    verifyPipelineUser(USER, contentBuilder);
    verifyPermissions(PERMISSIONS_CONTAINER, contentBuilder);
    verifyMetadata(EXPECTED_METADATA, contentBuilder);
}
Also used : MapperVerificationUtils.verifyFolder(com.epam.pipeline.elasticsearchagent.MapperVerificationUtils.verifyFolder) Folder(com.epam.pipeline.entity.pipeline.Folder) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) Test(org.junit.jupiter.api.Test)

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