### Question:
MetadataUploadManager { public List<MetadataEntity> uploadFromFile(Long parentId, MultipartFile file) { Assert.notNull(parentId, messageHelper.getMessage(MessageConstants.ERROR_PARAMETER_NULL_OR_EMPTY)); MetadataParsingResult parsedData = readFile(parentId, file); return metadataEntityManager.createAndUpdateEntities(parentId, parsedData); }  List<MetadataEntity> uploadFromFile(Long parentId, MultipartFile file);  }### Answer:
@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)); } }
@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())); } }
@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)); } }