MDXBaseComponent extends ComponentBase implements IDataComponent, IPreparedComponent { @VisibleForTesting boolean fileExistsInRepository( String catalog ) { try { IUnifiedRepository unifiedRepository = PentahoSystem.get( IUnifiedRepository.class, PentahoSessionHolder.getSession() ); return unifiedRepository.getFile( catalog ) != null; } catch ( UnifiedRepositoryException e ) { return false; } }  @Override abstract boolean validateSystemSettings(); @Override abstract Log getLogger(); IPentahoResultSet getResultSet(); @Override void done(); void dispose(); IPentahoConnection shareConnection(); IPentahoResultSet executePrepared( final Map preparedParams ); IPentahoConnection getDatasourceConnection(); @Override boolean init(); static final String FORMATTED_CELL_VALUES; }
@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" ); 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 ); }