Search in sources :

Example 1 with IMimeType

use of org.pentaho.platform.api.mimetype.IMimeType in project pentaho-platform by pentaho.

the class DefaultRepositoryVersioningManagerTest method setUp.

@Before
public void setUp() {
    IPlatformMimeResolver platformMimeResolver = mock(IPlatformMimeResolver.class);
    IMimeType mimeTypeMockFullTrue = mock(IMimeType.class);
    IMimeType mimeTypeMockPartialTrue = mock(IMimeType.class);
    IMimeType mimeTypeMockFalse = mock(IMimeType.class);
    when(mimeTypeMockFullTrue.isVersionEnabled()).thenReturn(true);
    when(mimeTypeMockFullTrue.isVersionCommentEnabled()).thenReturn(true);
    when(mimeTypeMockPartialTrue.isVersionEnabled()).thenReturn(true);
    when(mimeTypeMockPartialTrue.isVersionCommentEnabled()).thenReturn(false);
    when(mimeTypeMockFalse.isVersionEnabled()).thenReturn(false);
    when(mimeTypeMockFalse.isVersionCommentEnabled()).thenReturn(true);
    when(platformMimeResolver.resolveMimeTypeForFileName(FULL_VERSIONING_PATH)).thenReturn(mimeTypeMockFullTrue);
    when(platformMimeResolver.resolveMimeTypeForFileName(PART_VERSIONING_PATH)).thenReturn(mimeTypeMockPartialTrue);
    when(platformMimeResolver.resolveMimeTypeForFileName(NO_VERSIONING_PATH)).thenReturn(mimeTypeMockFalse);
    defaultRepositoryVersionManagerFullTrue.setMasterVersioning(true);
    defaultRepositoryVersionManagerFullTrue.setMasterVersionComments(true);
    defaultRepositoryVersionManagerFullTrue.setPlatformMimeResolver(platformMimeResolver);
    defaultRepositoryVersionManagerPartialTrue.setMasterVersioning(true);
    defaultRepositoryVersionManagerPartialTrue.setMasterVersionComments(false);
    defaultRepositoryVersionManagerPartialTrue.setPlatformMimeResolver(platformMimeResolver);
    defaultRepositoryVersionManagerFalse.setMasterVersioning(false);
    defaultRepositoryVersionManagerFalse.setMasterVersionComments(true);
    defaultRepositoryVersionManagerFalse.setPlatformMimeResolver(platformMimeResolver);
}
Also used : IMimeType(org.pentaho.platform.api.mimetype.IMimeType) IPlatformMimeResolver(org.pentaho.platform.api.mimetype.IPlatformMimeResolver) Before(org.junit.Before)

Example 2 with IMimeType

use of org.pentaho.platform.api.mimetype.IMimeType in project pentaho-platform by pentaho.

the class PlatformImporterTest method testMatchingMimeAndHandler.

@Test
public void testMatchingMimeAndHandler() throws Exception {
    List<IMimeType> mimeList = Collections.singletonList((IMimeType) new MimeType("text/xmi+xml", "xmi"));
    IPlatformImportHandler mockImportHandler = mock(IPlatformImportHandler.class);
    when(mockImportHandler.getMimeTypes()).thenReturn(mimeList);
    List<IPlatformImportHandler> handlers = Collections.singletonList(mockImportHandler);
    NameBaseMimeResolver nameResolver = new NameBaseMimeResolver();
    PentahoSystem.registerObject(nameResolver);
    // mock logger to prevent npe
    IRepositoryImportLogger importLogger = new Log4JRepositoryImportLogger();
    PentahoPlatformImporter importer = new PentahoPlatformImporter(handlers, new DefaultRepositoryContentConverterHandler(new HashMap<String, Converter>()));
    importer.setRepositoryImportLogger(importLogger);
    FileInputStream in = new FileInputStream(new File(TestResourceLocation.TEST_RESOURCES + "/ImportTest/steel-wheels.xmi"));
    // With custom domain id
    final IPlatformImportBundle bundle1 = (new RepositoryFileImportBundle.Builder().input(in).charSet("UTF-8").hidden(false).mime("text/xmi+xml").name("steel-wheels.xmi").comment("Test Metadata Import").withParam("domain-id", "parameterized-domain-id")).build();
    importer.importFile(bundle1);
    verify(mockImportHandler, times(1)).importFile(bundle1);
}
Also used : HashMap(java.util.HashMap) IRepositoryImportLogger(org.pentaho.platform.plugin.services.importexport.IRepositoryImportLogger) IMimeType(org.pentaho.platform.api.mimetype.IMimeType) MimeType(org.pentaho.platform.core.mimetype.MimeType) FileInputStream(java.io.FileInputStream) IPlatformImportBundle(org.pentaho.platform.api.repository2.unified.IPlatformImportBundle) IMimeType(org.pentaho.platform.api.mimetype.IMimeType) Log4JRepositoryImportLogger(org.pentaho.platform.plugin.services.importexport.Log4JRepositoryImportLogger) File(java.io.File) Test(org.junit.Test)

Example 3 with IMimeType

use of org.pentaho.platform.api.mimetype.IMimeType in project pentaho-platform by pentaho.

the class RepositoryFileImportFileHandlerTest method setup.

private void setup(String mimeTypeName, String extension, String path, String fileName, boolean folder) {
    List<String> extensions = Arrays.asList(extension);
    IMimeType mimeType = new MimeType(mimeTypeName, extensions);
    mimeType.setConverter(mock(Converter.class));
    List<IMimeType> mimeTypeList = Arrays.asList(mimeType);
    NameBaseMimeResolver mimeResolver = new NameBaseMimeResolver();
    mimeResolver.addMimeType(mimeType);
    SolutionFileImportHelper.testMimeResolver = mimeResolver;
    userProvider = new UserProvider();
    mockRepository = new MockUnifiedRepository(userProvider);
    fileHandler = new RepositoryFileImportFileHandler(mimeTypeList);
    fileHandler.setRepository(mockRepository);
    fileHandler.setDefaultAclHandler(new DefaultAclHandler());
    fileHandler.setKnownExtensions(Arrays.asList("prpt"));
    IPlatformImporter mockPlatformImporter = mock(IPlatformImporter.class);
    when(mockPlatformImporter.getRepositoryImportLogger()).thenReturn(new Log4JRepositoryImportLogger());
    ImportSession.iPlatformImporter = mockPlatformImporter;
    importSession = fileHandler.getImportSession();
    importSession.initialize();
    mockBundle = mock(RepositoryFileImportBundle.class);
    when(mockBundle.getPath()).thenReturn(path);
    when(mockBundle.getName()).thenReturn(fileName);
    when(mockBundle.getMimeType()).thenReturn(mimeTypeName);
    when(mockBundle.isFolder()).thenReturn(folder);
}
Also used : MockUnifiedRepository(org.pentaho.test.platform.repository2.unified.MockUnifiedRepository) IMimeType(org.pentaho.platform.api.mimetype.IMimeType) MimeType(org.pentaho.platform.core.mimetype.MimeType) IMimeType(org.pentaho.platform.api.mimetype.IMimeType) IRepositoryDefaultAclHandler(org.pentaho.platform.api.repository2.unified.IRepositoryDefaultAclHandler) ICurrentUserProvider(org.pentaho.test.platform.repository2.unified.MockUnifiedRepository.ICurrentUserProvider) Log4JRepositoryImportLogger(org.pentaho.platform.plugin.services.importexport.Log4JRepositoryImportLogger) Converter(org.pentaho.platform.api.repository2.unified.Converter)

Example 4 with IMimeType

use of org.pentaho.platform.api.mimetype.IMimeType in project pentaho-platform by pentaho.

the class LocaleImportHandlerTest method setUp.

@Before
public void setUp() throws Exception {
    NameBaseMimeResolver nameResolver = new NameBaseMimeResolver();
    PentahoSystem.registerObject(nameResolver);
    IRepositoryContentConverterHandler converterHandler = new DefaultRepositoryContentConverterHandler(new HashMap<String, Converter>());
    List<IMimeType> localeMimeList = new ArrayList<IMimeType>();
    localeMimeList.add(new MimeType("text/locale", "locale"));
    nameResolver.addMimeType(new MimeType("text/prptMimeType", "prpt"));
    nameResolver.addMimeType(new MimeType("text/xactionMimeType", "xaction"));
    MimeType mimeType = new MimeType("text/xml", "xml");
    mimeType.setHidden(true);
    nameResolver.addMimeType(mimeType);
    mimeType = new MimeType("image/png", "png");
    mimeType.setHidden(true);
    nameResolver.addMimeType(mimeType);
    List<String> allowedArtifacts = new ArrayList<String>();
    allowedArtifacts.add("xaction");
    allowedArtifacts.add("url");
    LocaleImportHandler localeImportHandler = new LocaleImportHandler(localeMimeList, allowedArtifacts);
    LocaleImportHandler spylocaleImportHandler = spy(localeImportHandler);
    Log log = mock(Log.class);
    doReturn(log).when(spylocaleImportHandler).getLogger();
    List<IPlatformImportHandler> handlers = new ArrayList<IPlatformImportHandler>();
    handlers.add(spylocaleImportHandler);
    importer = new PentahoPlatformImporter(handlers, converterHandler);
    importer.setRepositoryImportLogger(new Log4JRepositoryImportLogger());
    localeFilesProcessor = new LocaleFilesProcessor();
}
Also used : Log(org.apache.commons.logging.Log) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) IMimeType(org.pentaho.platform.api.mimetype.IMimeType) MimeType(org.pentaho.platform.core.mimetype.MimeType) IRepositoryContentConverterHandler(org.pentaho.platform.api.repository2.unified.IRepositoryContentConverterHandler) IMimeType(org.pentaho.platform.api.mimetype.IMimeType) Log4JRepositoryImportLogger(org.pentaho.platform.plugin.services.importexport.Log4JRepositoryImportLogger) Converter(org.pentaho.platform.api.repository2.unified.Converter) Before(org.junit.Before)

Example 5 with IMimeType

use of org.pentaho.platform.api.mimetype.IMimeType in project pentaho-platform by pentaho.

the class MetadataImportHandlerIT method setUp.

@Before
public void setUp() throws Exception {
    // mock logger to prevent npe
    importLogger = new Log4JRepositoryImportLogger();
    context = new Mockery();
    metadataImporter = context.mock(IPentahoMetadataDomainRepositoryImporter.class);
    MicroPlatform microPlatform = new MicroPlatform();
    NameBaseMimeResolver nameResolver = new NameBaseMimeResolver();
    microPlatform.defineInstance(IPlatformMimeResolver.class, nameResolver);
    List<IMimeType> mimeList = new ArrayList<IMimeType>();
    mimeList.add(new MimeType("text/xmi+xml", "xmi"));
    metadataHandler = new MetadataImportHandler(mimeList, metadataImporter);
    handlers.add(metadataHandler);
    importer = new PentahoPlatformImporter(handlers, new DefaultRepositoryContentConverterHandler(new HashMap<String, Converter>()));
    importer.setRepositoryImportLogger(importLogger);
}
Also used : ArrayList(java.util.ArrayList) Mockery(org.jmock.Mockery) IMimeType(org.pentaho.platform.api.mimetype.IMimeType) MimeType(org.pentaho.platform.core.mimetype.MimeType) IPentahoMetadataDomainRepositoryImporter(org.pentaho.platform.plugin.services.metadata.IPentahoMetadataDomainRepositoryImporter) IMimeType(org.pentaho.platform.api.mimetype.IMimeType) Log4JRepositoryImportLogger(org.pentaho.platform.plugin.services.importexport.Log4JRepositoryImportLogger) MicroPlatform(org.pentaho.test.platform.engine.core.MicroPlatform) Converter(org.pentaho.platform.api.repository2.unified.Converter) Before(org.junit.Before)

Aggregations

IMimeType (org.pentaho.platform.api.mimetype.IMimeType)18 MimeType (org.pentaho.platform.core.mimetype.MimeType)12 ArrayList (java.util.ArrayList)8 Test (org.junit.Test)7 Log4JRepositoryImportLogger (org.pentaho.platform.plugin.services.importexport.Log4JRepositoryImportLogger)7 Before (org.junit.Before)6 Converter (org.pentaho.platform.api.repository2.unified.Converter)6 File (java.io.File)5 FileInputStream (java.io.FileInputStream)4 Log (org.apache.commons.logging.Log)3 IPlatformMimeResolver (org.pentaho.platform.api.mimetype.IPlatformMimeResolver)3 IPlatformImportBundle (org.pentaho.platform.api.repository2.unified.IPlatformImportBundle)3 IRepositoryContentConverterHandler (org.pentaho.platform.api.repository2.unified.IRepositoryContentConverterHandler)3 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)3 HashMap (java.util.HashMap)2 ZipFile (java.util.zip.ZipFile)2 Response (javax.ws.rs.core.Response)2 Mockery (org.jmock.Mockery)2 Matchers.anyString (org.mockito.Matchers.anyString)2 DataSourceWizardResource (org.pentaho.platform.dataaccess.datasource.api.resources.DataSourceWizardResource)2