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