Search in sources :

Example 11 with MetadataEntity

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

the class MetadataUploadManagerTest method testAllNewUpload.

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
public void testAllNewUpload() throws IOException {
    Folder folder = prepareRequiredEntities();
    when(authManager.isAdmin()).thenReturn(true);
    try (InputStream inputStream = MetadataFileBuilder.prepareInputData(MetadataParsingUtils.CSV_DELIMITER)) {
        List<MetadataEntity> entities = uploadManager.uploadFromFile(folder.getId(), new MockMultipartFile(TEST_CSV_FILE, TEST_CSV_FILE, null, inputStream));
        assertEquals(2, entities.size());
        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) 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 12 with MetadataEntity

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

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

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

the class MetadataEntityConverterTest method shouldFailIfParticipantSetWithoutParticipants.

@Test(expected = IllegalStateException.class)
public void shouldFailIfParticipantSetWithoutParticipants() {
    Map<String, PipeConfValue> participantSetData = new HashMap<>();
    participantSetData.put(TEST_ARGUMENT1, new PipeConfValue(STRING_TYPE, TEST_VALUE_2));
    MetadataEntity participantSet = getEntity(participantSetClass, "HCC_participants", participantSetData);
    MetadataEntityConverter.convert(Collections.singletonList(participantSet));
}
Also used : MetadataEntity(com.epam.pipeline.entity.metadata.MetadataEntity) PipeConfValue(com.epam.pipeline.entity.metadata.PipeConfValue) Test(org.junit.Test)

Example 15 with MetadataEntity

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

the class MetadataEntityConverterTest method shouldFailWithMissingColumnInData.

@Test(expected = IllegalStateException.class)
public void shouldFailWithMissingColumnInData() {
    Map<String, PipeConfValue> participantData1 = new HashMap<>();
    participantData1.put(TEST_ARGUMENT1, new PipeConfValue(STRING_TYPE, TEST_VALUE_1));
    participantData1.put(TEST_ARGUMENT2, new PipeConfValue(STRING_TYPE, "F"));
    MetadataEntity participant1 = getEntity(participantClass, PARTICIPANT_ENTITY_ID1, participantData1);
    Map<String, PipeConfValue> participantData2 = new HashMap<>();
    participantData2.put(TEST_ARGUMENT2, new PipeConfValue(STRING_TYPE, "M"));
    MetadataEntity participant2 = getEntity(participantClass, PARTICIPANT_ENTITY_ID2, participantData2);
    List<MetadataEntity> entities = new ArrayList<>();
    entities.add(participant1);
    entities.add(participant2);
    MetadataEntityConverter.convert(entities);
}
Also used : MetadataEntity(com.epam.pipeline.entity.metadata.MetadataEntity) PipeConfValue(com.epam.pipeline.entity.metadata.PipeConfValue) Test(org.junit.Test)

Aggregations

MetadataEntity (com.epam.pipeline.entity.metadata.MetadataEntity)48 PipeConfValue (com.epam.pipeline.entity.metadata.PipeConfValue)22 Test (org.junit.Test)22 Transactional (org.springframework.transaction.annotation.Transactional)14 MetadataClass (com.epam.pipeline.entity.metadata.MetadataClass)12 Folder (com.epam.pipeline.entity.pipeline.Folder)10 HashMap (java.util.HashMap)9 AbstractSpringTest (com.epam.pipeline.AbstractSpringTest)7 List (java.util.List)7 Map (java.util.Map)6 MetadataEntityVO (com.epam.pipeline.controller.vo.metadata.MetadataEntityVO)5 IOException (java.io.IOException)5 MetadataReadingException (com.epam.pipeline.exception.MetadataReadingException)4 FolderManager (com.epam.pipeline.manager.pipeline.FolderManager)4 InputStream (java.io.InputStream)4 ArrayList (java.util.ArrayList)4 Autowired (org.springframework.beans.factory.annotation.Autowired)4 Propagation (org.springframework.transaction.annotation.Propagation)4 AclClass (com.epam.pipeline.entity.security.acl.AclClass)3 com.epam.pipeline.manager.metadata.parser (com.epam.pipeline.manager.metadata.parser)3