Search in sources :

Example 11 with MetadataClass

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

the class MetadataUploadManagerTest method prepareRequiredEntities.

private Folder prepareRequiredEntities() {
    when(authManager.getAuthorizedUser()).thenReturn("user");
    Folder folder = createFolder();
    MetadataClass participantClass = entityManager.createMetadataClass(MetadataFileBuilder.PARTICIPANT_CLASS_NAME);
    MetadataClass pairClass = entityManager.createMetadataClass(MetadataFileBuilder.PAIR_CLASS_NAME);
    entityManager.updateMetadataEntity(createEntityVO(folder.getId(), participantClass.getId(), MetadataFileBuilder.PARTICIPANT1_ID));
    entityManager.updateMetadataEntity(createEntityVO(folder.getId(), participantClass.getId(), MetadataFileBuilder.PARTICIPANT2_ID));
    entityManager.updateMetadataEntity(createEntityVO(folder.getId(), pairClass.getId(), MetadataFileBuilder.PAIR1_ID));
    entityManager.updateMetadataEntity(createEntityVO(folder.getId(), pairClass.getId(), MetadataFileBuilder.PAIR2_ID));
    return folder;
}
Also used : MetadataClass(com.epam.pipeline.entity.metadata.MetadataClass) Folder(com.epam.pipeline.entity.pipeline.Folder)

Example 12 with MetadataClass

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

the class MetadataUploadManagerTest method testUpdateUpload.

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
public void testUpdateUpload() throws IOException {
    Folder folder = prepareRequiredEntities();
    MetadataClass sampleClass = entityManager.createMetadataClass(MetadataFileBuilder.SAMPLE_CLASS_NAME);
    MetadataEntity existingSample = entityManager.updateMetadataEntity(createEntityVO(folder.getId(), sampleClass.getId(), MetadataFileBuilder.SAMPLE1_ID));
    try (InputStream inputStream = MetadataFileBuilder.prepareInputData(MetadataParsingUtils.TAB_DELIMITER)) {
        List<MetadataEntity> entities = uploadManager.uploadFromFile(folder.getId(), new MockMultipartFile(TEST_TAB_FILE, TEST_TAB_FILE, null, inputStream));
        assertEquals(2, entities.size());
        assertTrue(entities.stream().allMatch(e -> e.getId() != null));
        assertTrue(entities.stream().filter(e -> e.getExternalId().equals(MetadataFileBuilder.SAMPLE1_ID)).findAny().orElseThrow(AssertionError::new).getId().equals(existingSample.getId()));
    }
}
Also used : MockMultipartFile(org.springframework.mock.web.MockMultipartFile) Arrays(java.util.Arrays) MetadataEntityVO(com.epam.pipeline.controller.vo.metadata.MetadataEntityVO) SpyBean(org.springframework.boot.test.mock.mockito.SpyBean) FolderManager(com.epam.pipeline.manager.pipeline.FolderManager) MetadataParsingUtils(com.epam.pipeline.manager.utils.MetadataParsingUtils) com.epam.pipeline.manager.metadata.parser(com.epam.pipeline.manager.metadata.parser) Assert.assertTrue(org.junit.Assert.assertTrue) Autowired(org.springframework.beans.factory.annotation.Autowired) IOException(java.io.IOException) MetadataReadingException(com.epam.pipeline.exception.MetadataReadingException) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest) MockMultipartFile(org.springframework.mock.web.MockMultipartFile) List(java.util.List) Folder(com.epam.pipeline.entity.pipeline.Folder) MetadataEntity(com.epam.pipeline.entity.metadata.MetadataEntity) Propagation(org.springframework.transaction.annotation.Propagation) AuthManager(com.epam.pipeline.manager.security.AuthManager) MetadataClass(com.epam.pipeline.entity.metadata.MetadataClass) Assert.assertEquals(org.junit.Assert.assertEquals) InputStream(java.io.InputStream) Transactional(org.springframework.transaction.annotation.Transactional) MetadataEntity(com.epam.pipeline.entity.metadata.MetadataEntity) MetadataClass(com.epam.pipeline.entity.metadata.MetadataClass) InputStream(java.io.InputStream) Folder(com.epam.pipeline.entity.pipeline.Folder) Test(org.junit.Test) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 13 with MetadataClass

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

the class MetadataUploadManagerTest method uploadingMetadataWithSeveralMultiValueFields.

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
public void uploadingMetadataWithSeveralMultiValueFields() throws IOException {
    Folder folder = prepareRequiredEntities();
    entityManager.createMetadataClass(MetadataFileBuilder.SAMPLE_CLASS_NAME);
    MetadataClass setClass = entityManager.createMetadataClass(MetadataFileBuilder.SET_CLASS_NAME);
    entityManager.updateMetadataEntity(createEntityVO(folder.getId(), setClass.getId(), MetadataFileBuilder.SET1_ID));
    entityManager.updateMetadataEntity(createEntityVO(folder.getId(), setClass.getId(), MetadataFileBuilder.SET2_ID));
    entityManager.updateMetadataEntity(createEntityVO(folder.getId(), setClass.getId(), MetadataFileBuilder.SET3_ID));
    List<String> lines = Arrays.asList(MetadataFileBuilder.MULTIVALUE_HEADER, MetadataFileBuilder.MULTIVALUE_LINE1, MetadataFileBuilder.MULTIVALUE_LINE2, MetadataFileBuilder.MULTIVALUE_LINE3);
    try (InputStream inputStream = MetadataFileBuilder.prepareInputData(MetadataParsingUtils.TAB_DELIMITER, lines)) {
        List<MetadataEntity> entities = uploadManager.uploadFromFile(folder.getId(), new MockMultipartFile(TEST_TAB_FILE, TEST_TAB_FILE, null, inputStream));
        assertEquals(1, entities.size());
        String expectedSetField = String.format("[\"%s\",\"%s\",\"%s\"]", MetadataFileBuilder.SET1_ID, MetadataFileBuilder.SET2_ID, MetadataFileBuilder.SET3_ID);
        String expectedPairField = String.format("[\"%s\",\"%s\"]", MetadataFileBuilder.PAIR1_ID, MetadataFileBuilder.PAIR2_ID);
        assertEquals(expectedSetField, entities.get(0).getData().get("sets").getValue());
        assertEquals(expectedPairField, entities.get(0).getData().get("pairs").getValue());
        assertTrue(entities.stream().allMatch(e -> e.getId() != null));
    }
}
Also used : MockMultipartFile(org.springframework.mock.web.MockMultipartFile) Arrays(java.util.Arrays) MetadataEntityVO(com.epam.pipeline.controller.vo.metadata.MetadataEntityVO) SpyBean(org.springframework.boot.test.mock.mockito.SpyBean) FolderManager(com.epam.pipeline.manager.pipeline.FolderManager) MetadataParsingUtils(com.epam.pipeline.manager.utils.MetadataParsingUtils) com.epam.pipeline.manager.metadata.parser(com.epam.pipeline.manager.metadata.parser) Assert.assertTrue(org.junit.Assert.assertTrue) Autowired(org.springframework.beans.factory.annotation.Autowired) IOException(java.io.IOException) MetadataReadingException(com.epam.pipeline.exception.MetadataReadingException) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest) MockMultipartFile(org.springframework.mock.web.MockMultipartFile) List(java.util.List) Folder(com.epam.pipeline.entity.pipeline.Folder) MetadataEntity(com.epam.pipeline.entity.metadata.MetadataEntity) Propagation(org.springframework.transaction.annotation.Propagation) AuthManager(com.epam.pipeline.manager.security.AuthManager) MetadataClass(com.epam.pipeline.entity.metadata.MetadataClass) Assert.assertEquals(org.junit.Assert.assertEquals) InputStream(java.io.InputStream) Transactional(org.springframework.transaction.annotation.Transactional) MetadataEntity(com.epam.pipeline.entity.metadata.MetadataEntity) MetadataClass(com.epam.pipeline.entity.metadata.MetadataClass) InputStream(java.io.InputStream) Folder(com.epam.pipeline.entity.pipeline.Folder) Test(org.junit.Test) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 14 with MetadataClass

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

the class MetadataEntityConverterTest method shouldFailIfFireCloudClassIsNull.

@Test(expected = IllegalArgumentException.class)
public void shouldFailIfFireCloudClassIsNull() {
    MetadataClass entityClass = new MetadataClass();
    entityClass.setName(PARTICIPANT_TYPE_NAME);
    Map<String, PipeConfValue> participantData = new HashMap<>();
    participantData.put(TEST_ARGUMENT1, new PipeConfValue(STRING_TYPE, TEST_VALUE_1));
    MetadataEntity participant = getEntity(entityClass, PARTICIPANT_ENTITY_ID1, participantData);
    MetadataEntityConverter.convert(Collections.singletonList(participant));
}
Also used : MetadataEntity(com.epam.pipeline.entity.metadata.MetadataEntity) MetadataClass(com.epam.pipeline.entity.metadata.MetadataClass) PipeConfValue(com.epam.pipeline.entity.metadata.PipeConfValue) Test(org.junit.Test)

Example 15 with MetadataClass

use of com.epam.pipeline.entity.metadata.MetadataClass 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)

Aggregations

MetadataClass (com.epam.pipeline.entity.metadata.MetadataClass)25 Folder (com.epam.pipeline.entity.pipeline.Folder)11 MetadataEntity (com.epam.pipeline.entity.metadata.MetadataEntity)10 Transactional (org.springframework.transaction.annotation.Transactional)10 Test (org.junit.Test)7 AbstractSpringTest (com.epam.pipeline.AbstractSpringTest)6 PipeConfValue (com.epam.pipeline.entity.metadata.PipeConfValue)5 MetadataEntityVO (com.epam.pipeline.controller.vo.metadata.MetadataEntityVO)3 MetadataReadingException (com.epam.pipeline.exception.MetadataReadingException)3 IOException (java.io.IOException)3 com.epam.pipeline.manager.metadata.parser (com.epam.pipeline.manager.metadata.parser)2 FolderManager (com.epam.pipeline.manager.pipeline.FolderManager)2 AuthManager (com.epam.pipeline.manager.security.AuthManager)2 MetadataParsingUtils (com.epam.pipeline.manager.utils.MetadataParsingUtils)2 InputStream (java.io.InputStream)2 Arrays (java.util.Arrays)2 List (java.util.List)2 Assert.assertEquals (org.junit.Assert.assertEquals)2 Assert.assertTrue (org.junit.Assert.assertTrue)2 Test (org.junit.jupiter.api.Test)2