From 9def522ded07296e0cb5bf46eb491244ab54342b Mon Sep 17 00:00:00 2001 From: Mario David Date: Tue, 30 Oct 2018 22:10:38 +0100 Subject: [PATCH] updated to CUBA 6.10; resolved no result set bug in #23 (#24) --- build.gradle | 8 +- .../db/DbDiagnoseServiceBean.groovy | 29 +++++-- .../runtimediagnose/db/DbQueryParser.groovy | 43 ++++++++-- .../runtimediagnose/db/DbSqlExecutor.groovy | 37 +++++++++ ...SpecificationWithApplicationContext.groovy | 31 +++++-- .../db/DbDiagnoseServiceBeanSpec.groovy | 16 ++-- ...agnoseFileValidationServiceBeanSpec.groovy | 5 +- modules/core/web/META-INF/context.xml | 22 ++--- .../runtimediagnose/db/DbQueryResult.groovy | 4 + .../web/screens/console/ConsoleFrame.groovy | 9 +- ...SpecificationWithApplicationContext.groovy | 47 +++++++---- ...agnoseExecutionResultDatasourceSpec.groovy | 82 ++++++++++--------- 12 files changed, 232 insertions(+), 101 deletions(-) create mode 100644 modules/core/src/de/diedavids/cuba/runtimediagnose/db/DbSqlExecutor.groovy diff --git a/build.gradle b/build.gradle index ee58545..738ab6c 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ buildscript { - ext.cubaVersion = '6.9.3' + ext.cubaVersion = '6.10.2' repositories { mavenLocal() @@ -55,7 +55,7 @@ apply(plugin: 'cuba') cuba { artifact { group = 'de.diedavids.cuba.runtimediagnose' - version = "1.1.0" + version = "1.2.0" isSnapshot = false } tomcat { @@ -215,7 +215,9 @@ configure([globalModule, coreModule, guiModule, webModule]) { } configure(globalModule) { - task enhance(type: CubaEnhancing) + entitiesEnhancing { + main { enabled = true } + } jar { manifest { diff --git a/modules/core/src/de/diedavids/cuba/runtimediagnose/db/DbDiagnoseServiceBean.groovy b/modules/core/src/de/diedavids/cuba/runtimediagnose/db/DbDiagnoseServiceBean.groovy index 82ce3e2..62a9669 100644 --- a/modules/core/src/de/diedavids/cuba/runtimediagnose/db/DbDiagnoseServiceBean.groovy +++ b/modules/core/src/de/diedavids/cuba/runtimediagnose/db/DbDiagnoseServiceBean.groovy @@ -31,6 +31,9 @@ class DbDiagnoseServiceBean implements DbDiagnoseService { @Inject DbQueryParser dbQueryParser + @Inject + DbSqlExecutor dbSqlExecutor + @Inject TimeSource timeSource @@ -57,7 +60,8 @@ class DbDiagnoseServiceBean implements DbDiagnoseService { DbQueryResult dbQueryResult try { dbQueryResult = getQueryResult(diagnoseType, queryStatement, queryStatements) - diagnoseExecution.handleSuccessfulExecution(dbQueryResult.entities[0].toString()) + + diagnoseExecution.handleSuccessfulExecution(getResultMessage(dbQueryResult)) diagnoseExecutionLogService.logDiagnoseExecution(diagnoseExecution) } catch (Exception e) { dbQueryResult = selectResultFactory.createFromRows([]) @@ -68,20 +72,30 @@ class DbDiagnoseServiceBean implements DbDiagnoseService { dbQueryResult } + protected String getResultMessage(DbQueryResult dbQueryResult) { + String resultMessage = '' + if (dbQueryResult.empty) { + resultMessage = 'Execution successful' + } else { + resultMessage = dbQueryResult.entities[0].toString() + } + resultMessage + } + protected DbQueryResult getQueryResult(DiagnoseType diagnoseType, String queryStatement, Statements queryStatements) { - DbQueryResult sqlSelectResult + DbQueryResult dbQueryResult switch (diagnoseType) { case DiagnoseType.JPQL: - sqlSelectResult = executeJpqlStatement(queryStatement, queryStatements) + dbQueryResult = executeJpqlStatement(queryStatement, queryStatements) break case DiagnoseType.SQL: def sql = createSqlConnection(persistence.dataSource) - sqlSelectResult = executeSqlStatement(sql, queryStatement) + dbQueryResult = executeSqlStatement(sql, queryStatements) break default: throw new IllegalArgumentException('DiagnoseType is not supported (' + diagnoseType + ')') } - sqlSelectResult + dbQueryResult } protected DbQueryResult executeJpqlStatement(String queryStatement, Statements queryStatements) { @@ -97,9 +111,8 @@ class DbDiagnoseServiceBean implements DbDiagnoseService { } } - protected DbQueryResult executeSqlStatement(Sql sql, String queryString) { - def rows = sql.rows(queryString) - selectResultFactory.createFromRows(rows) + protected DbQueryResult executeSqlStatement(Sql sql, Statements queryStatements) { + dbSqlExecutor.executeStatement(sql, queryStatements.statements[0]) } private DiagnoseExecution createAdHocDiagnose(String sqlStatement, DiagnoseType diagnoseType) { diff --git a/modules/core/src/de/diedavids/cuba/runtimediagnose/db/DbQueryParser.groovy b/modules/core/src/de/diedavids/cuba/runtimediagnose/db/DbQueryParser.groovy index 5ce3d2b..8b8574d 100644 --- a/modules/core/src/de/diedavids/cuba/runtimediagnose/db/DbQueryParser.groovy +++ b/modules/core/src/de/diedavids/cuba/runtimediagnose/db/DbQueryParser.groovy @@ -10,6 +10,7 @@ import de.diedavids.cuba.runtimediagnose.SqlConsoleSecurityException import de.diedavids.cuba.runtimediagnose.diagnose.DiagnoseType import net.sf.jsqlparser.parser.CCJSqlParserUtil import net.sf.jsqlparser.statement.SetStatement +import net.sf.jsqlparser.statement.Statement import net.sf.jsqlparser.statement.Statements import net.sf.jsqlparser.statement.alter.Alter import net.sf.jsqlparser.statement.create.index.CreateIndex @@ -22,6 +23,7 @@ import net.sf.jsqlparser.statement.execute.Execute import net.sf.jsqlparser.statement.insert.Insert import net.sf.jsqlparser.statement.merge.Merge import net.sf.jsqlparser.statement.replace.Replace +import net.sf.jsqlparser.statement.select.Select import net.sf.jsqlparser.statement.truncate.Truncate import net.sf.jsqlparser.statement.update.Update import org.springframework.stereotype.Component @@ -38,6 +40,9 @@ class DbQueryParser { @Inject Messages messages + protected static final SELECT_OPERATIONS = [ + Select + ] protected static final EXECUTE_OPERATIONS = [ Execute, SetStatement ] @@ -86,26 +91,52 @@ class DbQueryParser { ScriptManagerUtilLazyHolder.DOMAIN_MODEL_INSTANCE } } + boolean containsDataManipulation(Statements statements) { containsIllegalOperation(statements, DATA_MANIPULATION_OPERATIONS) } + boolean isDataManipulation(Statement statement) { + containsIllegalOperation(statement, DATA_MANIPULATION_OPERATIONS) + } + + boolean containsSelect(Statements statements) { + containsIllegalOperation(statements, SELECT_OPERATIONS) + } + + boolean isSelect(Statement statement) { + containsIllegalOperation(statement, SELECT_OPERATIONS) + } boolean containsSchemaManipulation(Statements statements) { containsIllegalOperation(statements, SCHEMA_MANIPULATION_OPERATIONS) } + boolean isSchemaManipulation(Statement statement) { + containsIllegalOperation(statement, SCHEMA_MANIPULATION_OPERATIONS) + } boolean containsExecuteOperations(Statements statements) { containsIllegalOperation(statements, EXECUTE_OPERATIONS) } - protected boolean containsIllegalOperation(Statements statements, dataManipulationOperations) { + boolean isExecuteOperations(Statement statement) { + containsIllegalOperation(statement, EXECUTE_OPERATIONS) + } + + protected boolean containsIllegalOperation(Statements statements, List dataManipulationOperations) { + + def statementsResults = statements.statements.collect { Statement statement -> + containsIllegalOperation(statement, dataManipulationOperations) + } + + statementsResults.any { it } + } + + protected boolean containsIllegalOperation(Statement statement, List dataManipulationOperations) { def containsIllegalOperation = false - statements.statements.each { statement -> - dataManipulationOperations.each { operationClass -> - if (operationClass.isAssignableFrom(statement.class)) { - containsIllegalOperation = true - } + dataManipulationOperations.each { operationClass -> + if (operationClass.isAssignableFrom(statement.class)) { + containsIllegalOperation = true } } diff --git a/modules/core/src/de/diedavids/cuba/runtimediagnose/db/DbSqlExecutor.groovy b/modules/core/src/de/diedavids/cuba/runtimediagnose/db/DbSqlExecutor.groovy new file mode 100644 index 0000000..05c22b7 --- /dev/null +++ b/modules/core/src/de/diedavids/cuba/runtimediagnose/db/DbSqlExecutor.groovy @@ -0,0 +1,37 @@ +package de.diedavids.cuba.runtimediagnose.db + +import groovy.sql.Sql +import net.sf.jsqlparser.statement.Statement +import org.springframework.stereotype.Component + +import javax.inject.Inject + +@Component +class DbSqlExecutor { + + @Inject + DbQueryParser dbQueryParser + + @Inject + SqlSelectResultFactory selectResultFactory + + + DbQueryResult executeStatement(Sql sql, Statement sqlStatement) { + + def rows = [] + + def queryString = sqlStatement.toString() + + if (dbQueryParser.isSelect(sqlStatement)) { + rows = sql.rows(queryString) + } + else if (dbQueryParser.isDataManipulation(sqlStatement)) { + sql.executeUpdate(queryString) + } + else { + rows = sql.execute(queryString) + } + selectResultFactory.createFromRows(rows) + } + +} \ No newline at end of file diff --git a/modules/core/test/de/diedavids/cuba/runtimediagnose/SpecificationWithApplicationContext.groovy b/modules/core/test/de/diedavids/cuba/runtimediagnose/SpecificationWithApplicationContext.groovy index b498ef4..1808f76 100644 --- a/modules/core/test/de/diedavids/cuba/runtimediagnose/SpecificationWithApplicationContext.groovy +++ b/modules/core/test/de/diedavids/cuba/runtimediagnose/SpecificationWithApplicationContext.groovy @@ -1,6 +1,8 @@ package de.diedavids.cuba.runtimediagnose +import com.haulmont.cuba.core.global.BeanLocator import com.haulmont.cuba.core.global.Messages +import com.haulmont.cuba.core.global.Metadata import com.haulmont.cuba.core.global.UserSessionSource import com.haulmont.cuba.core.global.UuidSource import com.haulmont.cuba.core.sys.AppContext @@ -8,6 +10,7 @@ import org.springframework.context.ApplicationContext import spock.lang.Shared import spock.lang.Specification + class SpecificationWithApplicationContext extends Specification { @Shared @@ -19,9 +22,17 @@ class SpecificationWithApplicationContext extends Specification { UserSessionSource sessionSource @Shared UuidSource uuidSource + @Shared + BeanLocator beanLocator + @Shared + Metadata metadata def setup() { applicationContext = Mock() + beanLocator = Mock() + + applicationContext.getBean(BeanLocator.NAME,BeanLocator) >> beanLocator + initBeans() AppContext.Internals.applicationContext = applicationContext @@ -32,8 +43,9 @@ class SpecificationWithApplicationContext extends Specification { } private void initBeans() { - addDefaultBeans(beans) - mockGetBean(beans) + def allBeans = getBeans() + addDefaultBeans(allBeans) + mockGetBean(allBeans) } private void mockGetBean(Map beans) { @@ -41,22 +53,29 @@ class SpecificationWithApplicationContext extends Specification { Class clazz = bean.key Object instance = bean.value - applicationContext.getBean(clazz) >> instance + beanLocator.get(clazz) >> instance String name = clazz.NAME if (name) { - applicationContext.getBean(name) >> instance - applicationContext.getBean(name, clazz) >> instance + beanLocator.get(name) >> instance + beanLocator.get(name, clazz) >> instance } } } protected void addDefaultBeans(Map beansFromSpec) { + messages = Mock() sessionSource = Mock() uuidSource = Mock() + metadata = Mock() uuidSource.createUuid() >> UUID.randomUUID() - beansFromSpec.putAll([(Messages): messages, (UserSessionSource): sessionSource, (UuidSource): uuidSource]) + beansFromSpec.putAll([ + (Messages) : messages, + (UserSessionSource): sessionSource, + (UuidSource) : uuidSource, + (Metadata) : metadata, + ]) } Map getBeans() { diff --git a/modules/core/test/de/diedavids/cuba/runtimediagnose/db/DbDiagnoseServiceBeanSpec.groovy b/modules/core/test/de/diedavids/cuba/runtimediagnose/db/DbDiagnoseServiceBeanSpec.groovy index 663c1de..578f8f6 100644 --- a/modules/core/test/de/diedavids/cuba/runtimediagnose/db/DbDiagnoseServiceBeanSpec.groovy +++ b/modules/core/test/de/diedavids/cuba/runtimediagnose/db/DbDiagnoseServiceBeanSpec.groovy @@ -28,6 +28,7 @@ class DbDiagnoseServiceBeanSpec extends Specification { MockableDbDiagnoseServiceBean dbDiagnoseServiceBean DbQueryParser dbQueryParser + DbSqlExecutor dbSqlExecutor SqlSelectResultFactory selectResultFactory Transaction transaction Persistence persistence @@ -42,6 +43,10 @@ class DbDiagnoseServiceBeanSpec extends Specification { def setup() { dbQueryParser = Mock(DbQueryParser) selectResultFactory = Mock(SqlSelectResultFactory) + dbSqlExecutor = Mock(DbSqlExecutor) + + dbSqlExecutor.executeStatement(_,_) >> new DbQueryResult() + transaction = Mock(Transaction) persistence = Mock(Persistence) sql = Mock(Sql) { @@ -62,6 +67,7 @@ class DbDiagnoseServiceBeanSpec extends Specification { diagnoseExecutionFactory = Mock(DiagnoseExecutionFactory) dbDiagnoseServiceBean = new MockableDbDiagnoseServiceBean( dbQueryParser: dbQueryParser, + dbSqlExecutor: dbSqlExecutor, selectResultFactory: selectResultFactory, persistence: persistence, sql: sql, @@ -139,7 +145,7 @@ class DbDiagnoseServiceBeanSpec extends Specification { dbDiagnoseServiceBean.runSqlDiagnose(sqlString, DiagnoseType.SQL) then: - 1 * sql.rows(sqlString) + 1 * dbSqlExecutor.executeStatement(_, sqlStatement) >> new DbQueryResult() } def "runSqlDiagnose executes the jpql script if there is at least one result of the jpql parser"() { @@ -170,7 +176,7 @@ class DbDiagnoseServiceBeanSpec extends Specification { given: def sqlString = 'SELECT * FROM SEC_USER;' - and: "the db parser returns one db statement" + and: "the db parser returns no db statement" def statements = Mock(Statements) statements.getStatements() >> [] @@ -180,7 +186,7 @@ class DbDiagnoseServiceBeanSpec extends Specification { dbDiagnoseServiceBean.runSqlDiagnose(sqlString, DiagnoseType.SQL) then: - 0 * sql.rows(_) + 0 * dbSqlExecutor.executeStatement(_,_) } def "runSqlDiagnose executes no sql script if there is no result of the jpql parser"() { @@ -198,7 +204,7 @@ class DbDiagnoseServiceBeanSpec extends Specification { dbDiagnoseServiceBean.runSqlDiagnose(sqlString, DiagnoseType.JPQL) then: - 0 * sql.rows(_) + 0 * dbSqlExecutor.executeStatement(_,_) } def "runSqlDiagnose executes no jpql script if there is no result of the jpql parser"() { @@ -216,7 +222,7 @@ class DbDiagnoseServiceBeanSpec extends Specification { dbDiagnoseServiceBean.runSqlDiagnose(sqlString, DiagnoseType.JPQL) then: - 0 * sql.rows(_) + 0 * dbSqlExecutor.executeStatement(_,_) } def "runSqlDiagnose adds metainformation to the diagnoseExecution"() { diff --git a/modules/core/test/de/diedavids/cuba/runtimediagnose/diagnose/DiagnoseFileValidationServiceBeanSpec.groovy b/modules/core/test/de/diedavids/cuba/runtimediagnose/diagnose/DiagnoseFileValidationServiceBeanSpec.groovy index af9da7c..0698d21 100644 --- a/modules/core/test/de/diedavids/cuba/runtimediagnose/diagnose/DiagnoseFileValidationServiceBeanSpec.groovy +++ b/modules/core/test/de/diedavids/cuba/runtimediagnose/diagnose/DiagnoseFileValidationServiceBeanSpec.groovy @@ -1,6 +1,7 @@ package de.diedavids.cuba.runtimediagnose.diagnose import com.haulmont.cuba.core.global.BuildInfo +import com.haulmont.cuba.core.global.BuildInfo.Content import com.haulmont.cuba.core.global.Messages import com.haulmont.cuba.core.global.Metadata import com.haulmont.cuba.core.global.UuidSource @@ -13,7 +14,7 @@ class DiagnoseFileValidationServiceBeanSpec extends SpecificationWithApplication DiagnoseFileValidationService sut Metadata metadata BuildInfo buildInfo - BuildInfo.Content buildInfoContent + Content buildInfoContent @Override Map getBeans() { @@ -31,7 +32,7 @@ class DiagnoseFileValidationServiceBeanSpec extends SpecificationWithApplication buildInfo: buildInfo ) - buildInfoContent = Mock(BuildInfo.Content) + buildInfoContent = Mock(Content) buildInfo.getContent() >> buildInfoContent } diff --git a/modules/core/web/META-INF/context.xml b/modules/core/web/META-INF/context.xml index cf663f7..a0b8aa5 100644 --- a/modules/core/web/META-INF/context.xml +++ b/modules/core/web/META-INF/context.xml @@ -11,22 +11,13 @@ username="sa"/> - + diff --git a/modules/global/src/de/diedavids/cuba/runtimediagnose/db/DbQueryResult.groovy b/modules/global/src/de/diedavids/cuba/runtimediagnose/db/DbQueryResult.groovy index 7682c6f..9f0936f 100644 --- a/modules/global/src/de/diedavids/cuba/runtimediagnose/db/DbQueryResult.groovy +++ b/modules/global/src/de/diedavids/cuba/runtimediagnose/db/DbQueryResult.groovy @@ -10,6 +10,10 @@ class DbQueryResult implements Serializable { Collection entities = [] + boolean isEmpty() { + columns.empty && entities.empty + } + void addColumn(String column) { columns << column } diff --git a/modules/web/src/de/diedavids/cuba/runtimediagnose/web/screens/console/ConsoleFrame.groovy b/modules/web/src/de/diedavids/cuba/runtimediagnose/web/screens/console/ConsoleFrame.groovy index 3490c70..83169bc 100644 --- a/modules/web/src/de/diedavids/cuba/runtimediagnose/web/screens/console/ConsoleFrame.groovy +++ b/modules/web/src/de/diedavids/cuba/runtimediagnose/web/screens/console/ConsoleFrame.groovy @@ -65,8 +65,13 @@ class ConsoleFrame extends ConsoleWindow { void doRunConsole() { try { DbQueryResult result = dbDiagnoseService.runSqlDiagnose(console.value, diagnoseType) - ValueCollectionDatasourceImpl sqlResultDs = createDatasource(result) - createResultTable(sqlResultDs) + if (result.empty) { + showNotification(formatMessage('executionSuccessful'), Frame.NotificationType.TRAY) + } + else { + ValueCollectionDatasourceImpl sqlResultDs = createDatasource(result) + createResultTable(sqlResultDs) + } } catch (SqlConsoleSecurityException e) { showNotification(e.message, Frame.NotificationType.ERROR) diff --git a/modules/web/test/de/diedavids/cuba/runtimediagnose/web/screens/SpecificationWithApplicationContext.groovy b/modules/web/test/de/diedavids/cuba/runtimediagnose/web/screens/SpecificationWithApplicationContext.groovy index b4a4c97..e2b6385 100644 --- a/modules/web/test/de/diedavids/cuba/runtimediagnose/web/screens/SpecificationWithApplicationContext.groovy +++ b/modules/web/test/de/diedavids/cuba/runtimediagnose/web/screens/SpecificationWithApplicationContext.groovy @@ -1,6 +1,8 @@ package de.diedavids.cuba.runtimediagnose.web.screens +import com.haulmont.cuba.core.global.BeanLocator import com.haulmont.cuba.core.global.Messages +import com.haulmont.cuba.core.global.Metadata import com.haulmont.cuba.core.global.UserSessionSource import com.haulmont.cuba.core.global.UuidSource import com.haulmont.cuba.core.sys.AppContext @@ -19,22 +21,30 @@ class SpecificationWithApplicationContext extends Specification { UserSessionSource sessionSource @Shared UuidSource uuidSource + @Shared + BeanLocator beanLocator + @Shared + Metadata metadata def setup() { applicationContext = Mock() + beanLocator = Mock() + + applicationContext.getBean(BeanLocator.NAME,BeanLocator) >> beanLocator + initBeans() - AppContext.Internals.setApplicationContext(applicationContext) + AppContext.Internals.applicationContext = applicationContext } def cleanup() { - AppContext.Internals.setApplicationContext(null) + AppContext.Internals.applicationContext = null } private void initBeans() { - Map beansFromSpec = getBeans() - addDefaultBeans(beansFromSpec) - mockGetBean(beansFromSpec) + def allBeans = getBeans() + addDefaultBeans(allBeans) + mockGetBean(allBeans) } private void mockGetBean(Map beans) { @@ -42,32 +52,33 @@ class SpecificationWithApplicationContext extends Specification { Class clazz = bean.key Object instance = bean.value - applicationContext.getBean(clazz) >> instance - - try { - String name = clazz.NAME - if (name) { - applicationContext.getBean(name) >> instance - applicationContext.getBean(name, clazz) >> instance - } - } - catch(MissingPropertyException e) { - e.printStackTrace() + beanLocator.get(clazz) >> instance + String name = clazz.NAME + if (name) { + beanLocator.get(name) >> instance + beanLocator.get(name, clazz) >> instance } } } protected void addDefaultBeans(Map beansFromSpec) { + messages = Mock() sessionSource = Mock() uuidSource = Mock() + metadata = Mock() uuidSource.createUuid() >> UUID.randomUUID() - beansFromSpec.putAll([(Messages): messages, (UserSessionSource): sessionSource, (UuidSource): uuidSource]) + beansFromSpec.putAll([ + (Messages) : messages, + (UserSessionSource): sessionSource, + (UuidSource) : uuidSource, + (Metadata) : metadata, + ]) } Map getBeans() { [:] } -} +} \ No newline at end of file diff --git a/modules/web/test/de/diedavids/cuba/runtimediagnose/web/screens/wizard/DiagnoseExecutionResultDatasourceSpec.groovy b/modules/web/test/de/diedavids/cuba/runtimediagnose/web/screens/wizard/DiagnoseExecutionResultDatasourceSpec.groovy index dcaa3e2..c0deee3 100644 --- a/modules/web/test/de/diedavids/cuba/runtimediagnose/web/screens/wizard/DiagnoseExecutionResultDatasourceSpec.groovy +++ b/modules/web/test/de/diedavids/cuba/runtimediagnose/web/screens/wizard/DiagnoseExecutionResultDatasourceSpec.groovy @@ -2,51 +2,53 @@ package de.diedavids.cuba.runtimediagnose.web.screens.wizard import com.haulmont.cuba.client.ClientConfig import com.haulmont.cuba.core.global.Configuration +import com.haulmont.cuba.core.global.UserSessionSource import de.diedavids.cuba.runtimediagnose.diagnose.DiagnoseExecution -import de.diedavids.cuba.runtimediagnose.diagnose.DiagnoseFileValidationService import de.diedavids.cuba.runtimediagnose.diagnose.DiagnoseWizardResultService import de.diedavids.cuba.runtimediagnose.web.screens.SpecificationWithApplicationContext import de.diedavids.cuba.runtimediagnose.wizard.DiagnoseWizardResult -import spock.lang.Specification class DiagnoseExecutionResultDatasourceSpec extends SpecificationWithApplicationContext { - DiagnoseExecutionResultDatasource sut - private DiagnoseWizardResultService diagnoseWizardResultService - private Configuration configuration - - @Override - Map getBeans() { - diagnoseWizardResultService = Mock(DiagnoseWizardResultService) - configuration = Mock(Configuration) - def clientConfig = Mock(ClientConfig) - configuration.getConfig(ClientConfig) >> clientConfig - [ - (DiagnoseWizardResultService): diagnoseWizardResultService, - (Configuration) : configuration - ] - } - - def setup() { - sut = new DiagnoseExecutionResultDatasource() - } - - def "getEntities returns an empty list if the diagnose param is not set"() { - given: - diagnoseWizardResultService.createResultsForDiagnose(_) >> [] - expect: - !sut.getEntities([:]) - } - - def "getEntities delegates to the diagnoseWizardResultService"() { - given: - def diagnoseExecution = new DiagnoseExecution() - def expectedResult = [new DiagnoseWizardResult()] - - and: - diagnoseWizardResultService.createResultsForDiagnose(diagnoseExecution) >> expectedResult - - expect: - sut.getEntities([diagnose: diagnoseExecution]) == expectedResult - } + DiagnoseExecutionResultDatasource sut + DiagnoseWizardResultService diagnoseWizardResultService + Configuration configuration + + @Override + Map getBeans() { + diagnoseWizardResultService = Mock(DiagnoseWizardResultService) + configuration = Mock(Configuration) + def clientConfig = Mock(ClientConfig) + def userSessionSource = Mock(UserSessionSource) + + configuration.getConfig(ClientConfig) >> clientConfig + [ + (DiagnoseWizardResultService): diagnoseWizardResultService, + (Configuration) : configuration, + (UserSessionSource) : userSessionSource + ] + } + + def setup() { + sut = new DiagnoseExecutionResultDatasource() + } + + def "getEntities returns an empty list if the diagnose param is not set"() { + given: + diagnoseWizardResultService.createResultsForDiagnose(_) >> [] + expect: + !sut.getEntities([:]) + } + + def "getEntities delegates to the diagnoseWizardResultService"() { + given: + def diagnoseExecution = new DiagnoseExecution() + def expectedResult = [new DiagnoseWizardResult()] + + and: + diagnoseWizardResultService.createResultsForDiagnose(diagnoseExecution) >> expectedResult + + expect: + sut.getEntities([diagnose: diagnoseExecution]) == expectedResult + } }