### Question:
DataSourceWizardService extends DatasourceService { public Map<String, InputStream> doGetDSWFilesAsDownload( String dswId ) throws PentahoAccessControlException { if ( !canManageACL() ) { throw new PentahoAccessControlException(); } Map<String, InputStream> fileData = getMetadataFiles( dswId ); Domain domain = metadataDomainRepository.getDomain( dswId ); ModelerWorkspace model = createModelerWorkspace(); model.setDomain( domain ); LogicalModel logicalModel = model.getLogicalModel( ModelerPerspective.ANALYSIS ); if ( logicalModel == null ) { logicalModel = model.getLogicalModel( ModelerPerspective.REPORTING ); } if ( logicalModel.getProperty( MONDRIAN_CATALOG_REF ) != null ) { MondrianCatalogRepositoryHelper helper = createMondrianCatalogRepositoryHelper(); String catalogRef = (String) logicalModel.getProperty( MONDRIAN_CATALOG_REF ); fileData.putAll( helper.getModrianSchemaFiles( catalogRef ) ); parseMondrianSchemaNameWrapper( dswId, fileData ); } return fileData; } DataSourceWizardService(); Map<String, InputStream> doGetDSWFilesAsDownload( String dswId ); void removeDSW( String dswId ); List<String> getDSWDatasourceIds(); String publishDsw( String domainId, InputStream metadataFile, boolean overwrite, boolean checkConnection,
      RepositoryFileAclDto acl ); String publishDsw( String domainId, InputStream metadataFile, List<InputStream> localizeFiles, List<String> localizeFileNames,
      boolean overwrite, boolean checkConnection, RepositoryFileAclDto acl ); String publishDswFromTemp( String domainId,
      MetadataTempFilesListDto fileList,
      boolean overwrite,
      boolean checkConnection,
      RepositoryFileAclDto acl ); RepositoryFileAclDto getDSWAcl( String dswId ); void setDSWAcl( String dswId, RepositoryFileAclDto aclDto ); static final String METADATA_EXT; }### Answer:
@Test public void testDoGetDSWFilesAsDownload() throws Exception { Map<String, InputStream> mockFileData = mock( Map.class ); ModelerWorkspace mockModelerWorkspace = mock( ModelerWorkspace.class ); MondrianCatalogRepositoryHelper mockMondrianCatalogRepositoryHelper = mock( MondrianCatalogRepositoryHelper.class ); LogicalModel mockLogicalModel = mock( LogicalModel.class ); String mockObject = "not null"; String dswId = "dswId"; doReturn( true ).when( dataSourceWizardService ).canManageACL(); doReturn( mockFileData ).when( dataSourceWizardService ).getMetadataFiles( dswId ); doReturn( mockModelerWorkspace ).when( dataSourceWizardService ).createModelerWorkspace(); doReturn( null ).when( mockModelerWorkspace ).getLogicalModel( ModelerPerspective.ANALYSIS ); doReturn( mockLogicalModel ).when( mockModelerWorkspace ).getLogicalModel( ModelerPerspective.REPORTING ); doReturn( mockObject ).when( mockLogicalModel ).getProperty( "MondrianCatalogRef" ); doReturn( mockMondrianCatalogRepositoryHelper ).when( dataSourceWizardService ).createMondrianCatalogRepositoryHelper(); doNothing().when( dataSourceWizardService ).parseMondrianSchemaNameWrapper( dswId, mockFileData ); Map<String, InputStream> response = dataSourceWizardService.doGetDSWFilesAsDownload( "dswId" ); assertEquals( mockFileData, response ); verify( dataSourceWizardService, times( 1 ) ).doGetDSWFilesAsDownload( "dswId" ); }
@Test public void testDoGetDSWFilesAsDownloadError() throws Exception { Map<String, InputStream> mockFileData = mock( Map.class ); ModelerWorkspace mockModelerWorkspace = mock( ModelerWorkspace.class ); String dswId = "dswId"; doReturn( false ).when( dataSourceWizardService ).canManageACL(); try { Map<String, InputStream> response = dataSourceWizardService.doGetDSWFilesAsDownload( "dswId" ); fail(); } catch ( PentahoAccessControlException pace ) { } verify( dataSourceWizardService, times( 1 ) ).doGetDSWFilesAsDownload( "dswId" ); }