Search in sources :

Example 66 with IUnifiedRepository

use of org.pentaho.platform.api.repository2.unified.IUnifiedRepository in project pentaho-platform by pentaho.

the class LocaleImportHandlerTest method initLocaleHandler.

private IUnifiedRepository initLocaleHandler(RepositoryFileImportBundle importBundle) {
    IUnifiedRepository unifiedRepository = mock(IUnifiedRepository.class);
    when(unifiedRepository.getFile(importBundle.getPath())).thenReturn(importBundle.getFile());
    LocaleImportHandler localeHandler = (LocaleImportHandler) importer.getHandlers().get(importBundle.getMimeType());
    ReflectionTestUtils.setField(localeHandler, "unifiedRepository", unifiedRepository);
    return unifiedRepository;
}
Also used : IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository)

Example 67 with IUnifiedRepository

use of org.pentaho.platform.api.repository2.unified.IUnifiedRepository in project pentaho-platform by pentaho.

the class LocaleImportHandlerTest method testInValidImportIndexLocaleFile.

@Test
public void testInValidImportIndexLocaleFile() {
    String localeContent = "<index><name>%name</name><description>%description</description><icon>samples.png</icon><visible>true</visible><display-type>icons</display-type></index>";
    RepositoryFileImportBundle importBundle = createBundle(localeContent, "index.xml");
    IUnifiedRepository unifiedRepository = initLocaleHandler(importBundle);
    try {
        importer.importFile(importBundle);
        verify(unifiedRepository, times(1)).getFile(anyString());
        verify(unifiedRepository, times(1)).getChildren(anyInt());
        verify(unifiedRepository, never()).setLocalePropertiesForFile(any(RepositoryFile.class), anyString(), any(Properties.class));
    } catch (PlatformImportException e) {
        fail(e.getMessage());
    }
}
Also used : RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) Matchers.anyString(org.mockito.Matchers.anyString) Properties(java.util.Properties) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository) Test(org.junit.Test)

Example 68 with IUnifiedRepository

use of org.pentaho.platform.api.repository2.unified.IUnifiedRepository in project pentaho-platform by pentaho.

the class MDXBaseComponentTest method shouldUseUnifiedRepositoryWhenCheckingFileExistence.

@Test
@SuppressWarnings("unchecked")
public void shouldUseUnifiedRepositoryWhenCheckingFileExistence() throws ObjectFactoryException {
    PentahoSystem.registerPrimaryObjectFactory(objFactory);
    PentahoSessionHolder.setSession(session);
    IUnifiedRepository repository = mock(IUnifiedRepository.class);
    when(objFactory.objectDefined("IUnifiedRepository")).thenReturn(true);
    when(objFactory.get(any(Class.class), eq("IUnifiedRepository"), any(IPentahoSession.class))).thenReturn(repository);
    doCallRealMethod().when(mdxBaseComponent).fileExistsInRepository(anyString());
    RepositoryFile file = mock(RepositoryFile.class);
    doReturn(file).when(repository).getFile("fileNameExisting");
    doReturn(null).when(repository).getFile("fileNameNonExisting");
    // checking bad file name for pentaho repository, e.g. windows os file names
    doThrow(new UnifiedRepositoryException()).when(repository).getFile("fileNameBad");
    boolean fileExists = mdxBaseComponent.fileExistsInRepository("fileNameExisting");
    assertTrue(fileExists);
    boolean fileDoesNotExist = mdxBaseComponent.fileExistsInRepository("fileNameNonExisting");
    assertFalse(fileDoesNotExist);
    boolean fileBad = mdxBaseComponent.fileExistsInRepository("fileNameBad");
    assertFalse(fileBad);
}
Also used : IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) UnifiedRepositoryException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository) Test(org.junit.Test)

Example 69 with IUnifiedRepository

use of org.pentaho.platform.api.repository2.unified.IUnifiedRepository in project pentaho-platform by pentaho.

the class MondrianCatalogHelper_Mondrian_2229_Test method prepareResultForMondrian2229Tests.

private String prepareResultForMondrian2229Tests(boolean isUseLegacyDbName) {
    MondrianCatalogHelper helper = new MondrianCatalogHelper(isUseLegacyDbName);
    MondrianCatalogHelper helperSpy = spy(helper);
    IUnifiedRepository unifiedRepositoryMock = mock(IUnifiedRepository.class);
    RepositoryFile repositoryFileMock = mock(RepositoryFile.class);
    when(unifiedRepositoryMock.getFile(any(String.class))).thenReturn(repositoryFileMock);
    String contextPathStub = "Stub";
    doReturn(contextPathStub).when(helperSpy).contextPathFromRequestContextHolder();
    doNothing().when(helperSpy).appendCatalogsSection(any(IUnifiedRepository.class), anyString(), any(RepositoryFile.class), any(StringBuffer.class));
    return helperSpy.generateInMemoryDatasourcesXml(unifiedRepositoryMock);
}
Also used : RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) StringContains.containsString(org.hamcrest.core.StringContains.containsString) Matchers.anyString(org.mockito.Matchers.anyString) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository)

Example 70 with IUnifiedRepository

use of org.pentaho.platform.api.repository2.unified.IUnifiedRepository 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

IUnifiedRepository (org.pentaho.platform.api.repository2.unified.IUnifiedRepository)88 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)61 Test (org.junit.Test)51 Matchers.anyString (org.mockito.Matchers.anyString)37 ArrayList (java.util.ArrayList)18 List (java.util.List)10 StringObjectId (org.pentaho.di.repository.StringObjectId)10 Serializable (java.io.Serializable)9 DatabaseDialectService (org.pentaho.database.service.DatabaseDialectService)7 RepositoryFileTree (org.pentaho.platform.api.repository2.unified.RepositoryFileTree)7 DataNode (org.pentaho.platform.api.repository2.unified.data.node.DataNode)7 InputStream (java.io.InputStream)6 JobMeta (org.pentaho.di.job.JobMeta)6 SimpleRepositoryFileData (org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData)6 FileSystemBackedUnifiedRepository (org.pentaho.platform.repository2.unified.fs.FileSystemBackedUnifiedRepository)6 HashMap (java.util.HashMap)5 ObjectId (org.pentaho.di.repository.ObjectId)5 IDatasourceMgmtService (org.pentaho.platform.api.repository.datasource.IDatasourceMgmtService)5 Properties (java.util.Properties)4 Log (org.apache.commons.logging.Log)4