Search in sources :

Example 11 with IMimeType

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

the class SolutionFileImportHelper method isInHiddenList.

public boolean isInHiddenList(String fileName) {
    boolean isInTheHiddenList = false;
    IMimeType mimeType = getMimeType(fileName);
    if (mimeType != null) {
        isInTheHiddenList = mimeType.isHidden();
    }
    return isInTheHiddenList;
}
Also used : IMimeType(org.pentaho.platform.api.mimetype.IMimeType)

Example 12 with IMimeType

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

the class LocaleFilesProcessorTest method testProcessLocaleFilesTwoLocaleFiles.

@Test
public void testProcessLocaleFilesTwoLocaleFiles() throws Exception {
    IRepositoryContentConverterHandler converterHandler = new DefaultRepositoryContentConverterHandler(new HashMap<String, Converter>());
    List<IMimeType> localeMimeList = new ArrayList<IMimeType>();
    localeMimeList.add(new MimeType("text/locale", "locale"));
    LocaleImportHandler localeImportHandler = new LocaleImportHandler(localeMimeList, null);
    LocaleImportHandler localeImportHandlerSpy = spy(localeImportHandler);
    Log log = mock(Log.class);
    doReturn(log).when(localeImportHandlerSpy).getLogger();
    String localeFileName = "SampleTransformationWithParameters";
    List<IPlatformImportHandler> handlers = new ArrayList<IPlatformImportHandler>();
    handlers.add(localeImportHandlerSpy);
    importer = new PentahoPlatformImporter(handlers, converterHandler);
    importer.setRepositoryImportLogger(new Log4JRepositoryImportLogger());
    localeFilesProcessor = new LocaleFilesProcessor();
    StringBuffer localePropertiesContent = new StringBuffer();
    localePropertiesContent.append("description=This runs a simple Kettle transformation filtering records from the Quandrant_Actuals sample data " + "table, and sending a Hello message to each position.\n");
    localePropertiesContent.append("name=1. Hello ETL");
    assertTrue(processIsLocalFile("SampleTransformation.properties", localePropertiesContent));
    StringBuffer localeContent = new StringBuffer();
    localeContent.append("file.title=" + localeFileName + "\n");
    localeContent.append("title=SampleTransformation\n");
    localeContent.append("file.description=");
    assertTrue(processIsLocalFile("SampleTransformation.xaction.locale", localeContent));
    localeFilesProcessor.processLocaleFiles(importer);
    // verify that in case of both .properties and .locale files are at input the only one proceeded is .locale
    Mockito.verify(localeImportHandlerSpy, times(1)).importFile(any(IPlatformImportBundle.class));
    ArgumentCaptor<IPlatformImportBundle> argument = ArgumentCaptor.forClass(IPlatformImportBundle.class);
    Mockito.verify(localeImportHandlerSpy).importFile(argument.capture());
    assertEquals(localeFileName, argument.getValue().getName());
}
Also used : Log(org.apache.commons.logging.Log) ArrayList(java.util.ArrayList) IMimeType(org.pentaho.platform.api.mimetype.IMimeType) MimeType(org.pentaho.platform.core.mimetype.MimeType) IPlatformImportBundle(org.pentaho.platform.api.repository2.unified.IPlatformImportBundle) 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) Test(org.junit.Test)

Example 13 with IMimeType

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

the class MetadataImportHandlerTest method setUp.

@Before
public void setUp() throws Exception {
    context = new Mockery();
    metadataImporter = context.mock(IPentahoMetadataDomainRepositoryImporter.class);
    List<IMimeType> mimeList = new ArrayList<IMimeType>();
    mimeList.add(new MimeType("text/xmi+xml", "xmi"));
    metadataHandler = new MetadataImportHandler(mimeList, metadataImporter);
}
Also used : IPentahoMetadataDomainRepositoryImporter(org.pentaho.platform.plugin.services.metadata.IPentahoMetadataDomainRepositoryImporter) IMimeType(org.pentaho.platform.api.mimetype.IMimeType) ArrayList(java.util.ArrayList) Mockery(org.jmock.Mockery) IMimeType(org.pentaho.platform.api.mimetype.IMimeType) MimeType(org.pentaho.platform.core.mimetype.MimeType) Before(org.junit.Before)

Example 14 with IMimeType

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

the class NameBaseMimeResolverTest method testResolveMimeTypeForFileName.

@Test
public void testResolveMimeTypeForFileName() {
    MimeType expectedMimeType = new MimeType("othertest/other-test-mime", "smt");
    IMimeType actualMimeType = resolver.resolveMimeTypeForFileName("test.smt");
    assertEquals(actualMimeType, expectedMimeType);
}
Also used : IMimeType(org.pentaho.platform.api.mimetype.IMimeType) MimeType(org.pentaho.platform.core.mimetype.MimeType) IMimeType(org.pentaho.platform.api.mimetype.IMimeType) Test(org.junit.Test)

Example 15 with IMimeType

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

the class PRPTImportHandlerTest method setUp.

@Before
public void setUp() throws ObjectFactoryException, IOException {
    final IPlatformMimeResolver resolver = mock(IPlatformMimeResolver.class);
    pentahoObjectFactory = mock(IPentahoObjectFactory.class);
    when(pentahoObjectFactory.objectDefined(anyString())).thenReturn(true);
    when(pentahoObjectFactory.get(eq(IPlatformMimeResolver.class), anyString(), any(IPentahoSession.class))).thenAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            return resolver;
        }
    });
    when(pentahoObjectFactory.get(eq(IPlatformImporter.class), anyString(), any(IPentahoSession.class))).thenAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            return importer;
        }
    });
    PentahoSystem.registerObjectFactory(pentahoObjectFactory);
    InputStream stream = new ByteArrayInputStream(SAMPLE_STREAM.getBytes());
    bundle = mock(RepositoryFileImportBundle.class);
    when(bundle.getName()).thenReturn(SAMPLE_NAME);
    when(bundle.getInputStream()).thenReturn(stream);
    Log logger = mock(Log.class);
    ImportSession session = mock(ImportSession.class);
    doReturn(logger).when(session).getLogger();
    IUnifiedRepository repository = mock(IUnifiedRepository.class);
    List<IMimeType> mimeTypes = Arrays.asList(mock(IMimeType.class));
    handler = spy(new PRPTImportHandler(mimeTypes));
    doReturn(session).when(handler).getImportSession();
    handler.setRepository(repository);
}
Also used : ImportSession(org.pentaho.platform.plugin.services.importexport.ImportSession) IPentahoObjectFactory(org.pentaho.platform.api.engine.IPentahoObjectFactory) Log(org.apache.commons.logging.Log) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) IMimeType(org.pentaho.platform.api.mimetype.IMimeType) IPlatformMimeResolver(org.pentaho.platform.api.mimetype.IPlatformMimeResolver) ByteArrayInputStream(java.io.ByteArrayInputStream) InvocationOnMock(org.mockito.invocation.InvocationOnMock) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository) 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