### Question:
DSWDatasourceServiceImpl implements IDSWDatasourceService { public SerializedResultSet doPreview( String connectionName, String query, String previewLimit ) throws DatasourceServiceException { if ( !hasDataAccessPermission() ) { logger.error( Messages.getErrorString( "DatasourceServiceImpl.ERROR_0001_PERMISSION_DENIED" ) ); throw new DatasourceServiceException( Messages .getErrorString( "DatasourceServiceImpl.ERROR_0001_PERMISSION_DENIED" ) ); } SerializedResultSet returnResultSet; try { connectionName = UtilHtmlSanitizer.getInstance().safeEscapeHtml( connectionName ); executeQuery( connectionName, query, previewLimit ); returnResultSet = DatasourceServiceHelper.getSerializeableResultSet( connectionName, query, Integer.parseInt( previewLimit ), PentahoSessionHolder.getSession() ); } catch ( QueryValidationException e ) { throw new DatasourceServiceException( Messages.getErrorString( "DatasourceServiceImpl.ERROR_0009_QUERY_VALIDATION_FAILED", e.getLocalizedMessage() ), e ); } catch ( SqlQueriesNotSupportedException e ) { throw new DatasourceServiceException( e.getLocalizedMessage(), e ); } return returnResultSet; } DSWDatasourceServiceImpl();  DSWDatasourceServiceImpl( ConnectionServiceImpl connService ); boolean deleteLogicalModel( String domainId, String modelName ); SerializedResultSet doPreview( String connectionName, String query, String previewLimit ); boolean testDataSourceConnection( String connectionName ); BusinessData generateLogicalModel( String modelName, String connectionName, String dbType, String query,
                                            String previewLimit ); IMetadataDomainRepository getMetadataDomainRepository(); void setMetadataDomainRepository( IMetadataDomainRepository metadataDomainRepository ); boolean saveLogicalModel( Domain domain, boolean overwrite ); boolean hasPermission(); List<LogicalModelSummary> getLogicalModels( String context ); BusinessData loadBusinessData( String domainId, String modelId ); BogoPojo gwtWorkaround( BogoPojo pojo ); String serializeModelState( DatasourceDTO dto ); DatasourceDTO deSerializeModelState( String dtoStr ); List<String> listDatasourceNames(); @Override QueryDatasourceSummary generateQueryDomain( String name, String query, DatabaseConnection connection,
                                                     DatasourceDTO datasourceDTO ); void prepareForSerializaton( Domain domain ); String getDatasourceIllegalCharacters(); @Override GeoContext getGeoContext();  }### Answer:
@Test public void testDoPreview() throws DatasourceServiceException { doReturn( true ).when( dswService ).hasDataAccessPermission(); SerializedResultSet result = dswService.doPreview( CONNECTION_NAME, VALID_QUERY, PREVIEW_LIMIT ); try { verify( dswService ).executeQuery( "[connection &#25509;&#32154; &lt;;&gt;!@#$%^&amp;*()_-=+.,]", VALID_QUERY, PREVIEW_LIMIT ); } catch ( Exception e ) { e.printStackTrace(); } assertNotNull( result ); assertArrayEquals( columns, result.getColumns() ); assertArrayEquals( columnTypes, result.getColumnTypes() ); }