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;
}
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());
}
}
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);
}
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);
}
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);
}
Aggregations