Search in sources :

Example 6 with FileMeta

use of org.molgenis.data.file.model.FileMeta in project molgenis by molgenis.

the class FileMetaRepositoryDecoratorTest method testDeleteById.

@Test
public void testDeleteById() throws Exception {
    FileMeta fileMeta = getMockFileMeta("id");
    when(delegateRepository.findOneById("id")).thenReturn(fileMeta);
    fileMetaRepositoryDecorator.deleteById("id");
    verify(delegateRepository).deleteById("id");
    verify(fileStore).delete("id");
}
Also used : FileMeta(org.molgenis.data.file.model.FileMeta) Test(org.testng.annotations.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

Example 7 with FileMeta

use of org.molgenis.data.file.model.FileMeta in project molgenis by molgenis.

the class FileIngesterTest method ingest.

@Test
public void ingest() {
    when(fileStoreDownloadMock.downloadFile(url, identifier, entityTypeId + ".csv")).thenReturn(f);
    when(fileRepositoryCollectionFactoryMock.createFileRepositoryCollection(f)).thenReturn(fileRepositoryCollectionMock);
    when(importServiceFactoryMock.getImportService(f, fileRepositoryCollectionMock)).thenReturn(importServiceMock);
    when(importServiceMock.doImport(fileRepositoryCollectionMock, ADD_UPDATE_EXISTING, PACKAGE_DEFAULT)).thenReturn(report);
    when(progress.getJobExecution()).thenReturn(mock(FileIngestJobExecution.class));
    FileMeta fileMeta = fileIngester.ingest(entityTypeId, url, "CSV", identifier, progress);
    verify(dataService).add("sys_FileMeta", fileMeta);
}
Also used : FileIngestJobExecution(org.molgenis.file.ingest.meta.FileIngestJobExecution) FileMeta(org.molgenis.data.file.model.FileMeta) Test(org.testng.annotations.Test) AbstractMolgenisSpringTest(org.molgenis.data.AbstractMolgenisSpringTest)

Example 8 with FileMeta

use of org.molgenis.data.file.model.FileMeta in project molgenis by molgenis.

the class StyleServiceImpl method addStyle.

@Override
public Style addStyle(String styleId, String bootstrap3FileName, InputStream bootstrap3StyleData, String bootstrap4FileName, InputStream bootstrap4StyleData) throws MolgenisStyleException {
    if (dataService.getRepository(STYLE_SHEET).findOneById(styleId) != null) {
        throw new MolgenisStyleException(String.format("A style with the same identifier (%s) already exists", styleId));
    }
    StyleSheet styleSheet = styleSheetFactory.create(styleId);
    styleSheet.setName(styleId);
    FileMeta bootstrap3ThemeFileMeta = createStyleSheetFileMeta(bootstrap3FileName, bootstrap3StyleData);
    styleSheet.setBootstrap3Theme(bootstrap3ThemeFileMeta);
    // Setting the bootstrap 4 style is optional
    if (bootstrap4FileName != null && bootstrap4StyleData != null) {
        FileMeta bootstrap4ThemeFileMeta = createStyleSheetFileMeta(bootstrap4FileName, bootstrap4StyleData);
        styleSheet.setBootstrap4Theme(bootstrap4ThemeFileMeta);
    }
    dataService.add(STYLE_SHEET, styleSheet);
    return Style.createLocal(styleSheet.getName());
}
Also used : FileMeta(org.molgenis.data.file.model.FileMeta)

Example 9 with FileMeta

use of org.molgenis.data.file.model.FileMeta in project molgenis by molgenis.

the class RestServiceTest method toEntityFileValueValid.

@Test
public void toEntityFileValueValid() throws ParseException {
    String generatedId = "id";
    String downloadUriAsString = "http://somedownloaduri";
    ServletUriComponentsBuilder mockBuilder = mock(ServletUriComponentsBuilder.class);
    UriComponents downloadUri = mock(UriComponents.class);
    FileMeta fileMeta = mock(FileMeta.class);
    Attribute fileAttr = when(mock(Attribute.class).getName()).thenReturn("fileAttr").getMock();
    when(fileAttr.getDataType()).thenReturn(FILE);
    when(idGenerator.generateId()).thenReturn(generatedId);
    when(fileMetaFactory.create(generatedId)).thenReturn(fileMeta);
    when(mockBuilder.replacePath(anyString())).thenReturn(mockBuilder);
    when(mockBuilder.replaceQuery(null)).thenReturn(mockBuilder);
    when(downloadUri.toUriString()).thenReturn(downloadUriAsString);
    when(mockBuilder.build()).thenReturn(downloadUri);
    when(servletUriComponentsBuilderFactory.fromCurrentRequest()).thenReturn(mockBuilder);
    byte[] content = { 'a', 'b' };
    MockMultipartFile mockMultipartFile = new MockMultipartFile("name", "fileName", "contentType", content);
    assertEquals(restService.toEntityValue(fileAttr, mockMultipartFile, null), fileMeta);
}
Also used : MockMultipartFile(org.springframework.mock.web.MockMultipartFile) UriComponents(org.springframework.web.util.UriComponents) ServletUriComponentsBuilder(org.springframework.web.servlet.support.ServletUriComponentsBuilder) Attribute(org.molgenis.data.meta.model.Attribute) FileMeta(org.molgenis.data.file.model.FileMeta) Test(org.testng.annotations.Test)

Example 10 with FileMeta

use of org.molgenis.data.file.model.FileMeta in project molgenis by molgenis.

the class StyleServiceTest method getBootstrap4ThemeData.

@Test
public void getBootstrap4ThemeData() throws MolgenisStyleException {
    String styleName = "my-style";
    StyleSheet styleSheet = mock(StyleSheet.class);
    when(styleSheet.getId()).thenReturn(styleName);
    FileMeta fileMeta = mock(FileMeta.class);
    String fileId = "fileId";
    when(fileMeta.getId()).thenReturn(fileId);
    when(styleSheet.getBootstrap4Theme()).thenReturn(fileMeta);
    Query<StyleSheet> expectedQuery = new QueryImpl<StyleSheet>().eq(StyleSheetMetadata.NAME, styleName);
    when(dataService.findOne(STYLE_SHEET, expectedQuery, StyleSheet.class)).thenReturn(styleSheet);
    File styleFile = mock(File.class);
    String mockFilePath = "mock/file/path";
    when(styleFile.getPath()).thenReturn(mockFilePath);
    when(fileStore.getFile(fileId)).thenReturn(styleFile);
    BootstrapVersion version = BootstrapVersion.BOOTSTRAP_VERSION_4;
    FileSystemResource themeData = styleService.getThemeData(styleName, version);
    assertEquals(themeData.getPath(), mockFilePath);
}
Also used : FileSystemResource(org.springframework.core.io.FileSystemResource) File(java.io.File) FileMeta(org.molgenis.data.file.model.FileMeta) Test(org.testng.annotations.Test)

Aggregations

FileMeta (org.molgenis.data.file.model.FileMeta)32 Test (org.testng.annotations.Test)14 File (java.io.File)12 AbstractMockitoTest (org.molgenis.test.AbstractMockitoTest)6 Attribute (org.molgenis.data.meta.model.Attribute)5 Entity (org.molgenis.data.Entity)4 FileSystemResource (org.springframework.core.io.FileSystemResource)4 InputStream (java.io.InputStream)3 MolgenisDataException (org.molgenis.data.MolgenisDataException)3 EntityType (org.molgenis.data.meta.model.EntityType)3 IOException (java.io.IOException)2 Stream (java.util.stream.Stream)2 ZipFile (net.lingala.zip4j.core.ZipFile)2 ZipException (net.lingala.zip4j.exception.ZipException)2 Repository (org.molgenis.data.Repository)2 EntityImportReport (org.molgenis.data.importer.EntityImportReport)2 ImportService (org.molgenis.data.importer.ImportService)2 FileIngestJobExecution (org.molgenis.file.ingest.meta.FileIngestJobExecution)2 ServletUriComponentsBuilder (org.springframework.web.servlet.support.ServletUriComponentsBuilder)2 UriComponents (org.springframework.web.util.UriComponents)2