This is an automated email from the ASF dual-hosted git repository.

borinquenkid pushed a commit to branch 8.0.x-hibernate7-dev
in repository https://gitbox.apache.org/repos/asf/grails-core.git

commit 4ddb0f42f0fa5d8cf45955cd8f9ac79c39422e42
Author: Walter Duque de Estrada <[email protected]>
AuthorDate: Tue Mar 10 20:26:02 2026 -0500

    hibernate 7 GroovyChangeSpec
---
 .../GroovyDiffToChangeLogCommandStep.groovy        |   6 +-
 .../GroovyDiffToChangeLogCommandStepSpec.groovy    | 108 +++++++++++++++++++++
 2 files changed, 113 insertions(+), 1 deletion(-)

diff --git 
a/grails-data-hibernate7/dbmigration/src/main/groovy/org/grails/plugins/databasemigration/liquibase/GroovyDiffToChangeLogCommandStep.groovy
 
b/grails-data-hibernate7/dbmigration/src/main/groovy/org/grails/plugins/databasemigration/liquibase/GroovyDiffToChangeLogCommandStep.groovy
index a226fa5c29..f9c46a7fbe 100644
--- 
a/grails-data-hibernate7/dbmigration/src/main/groovy/org/grails/plugins/databasemigration/liquibase/GroovyDiffToChangeLogCommandStep.groovy
+++ 
b/grails-data-hibernate7/dbmigration/src/main/groovy/org/grails/plugins/databasemigration/liquibase/GroovyDiffToChangeLogCommandStep.groovy
@@ -48,7 +48,7 @@ class GroovyDiffToChangeLogCommandStep extends 
DiffChangelogCommandStep {
 
         InternalSnapshotCommandStep.logUnsupportedDatabase(referenceDatabase, 
this.getClass())
 
-        DiffCommandStep diffCommandStep = new DiffCommandStep()
+        DiffCommandStep diffCommandStep = createDiffCommandStep()
 
         DiffResult diffResult = 
diffCommandStep.createDiffResult(resultsBuilder)
 
@@ -79,4 +79,8 @@ class GroovyDiffToChangeLogCommandStep extends 
DiffChangelogCommandStep {
         return new String[][] { COMMAND_NAME }
     }
 
+    protected static DiffCommandStep createDiffCommandStep() {
+        return new DiffCommandStep()
+    }
+
 }
diff --git 
a/grails-data-hibernate7/dbmigration/src/test/groovy/org/grails/plugins/databasemigration/liquibase/GroovyDiffToChangeLogCommandStepSpec.groovy
 
b/grails-data-hibernate7/dbmigration/src/test/groovy/org/grails/plugins/databasemigration/liquibase/GroovyDiffToChangeLogCommandStepSpec.groovy
new file mode 100644
index 0000000000..8b27135c6e
--- /dev/null
+++ 
b/grails-data-hibernate7/dbmigration/src/test/groovy/org/grails/plugins/databasemigration/liquibase/GroovyDiffToChangeLogCommandStepSpec.groovy
@@ -0,0 +1,108 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    https://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.grails.plugins.databasemigration.liquibase
+
+import liquibase.command.CommandResultsBuilder
+import liquibase.command.CommandScope
+import liquibase.command.core.DiffChangelogCommandStep
+import liquibase.command.core.DiffCommandStep
+import liquibase.command.core.helpers.DiffOutputControlCommandStep
+import liquibase.command.core.helpers.ReferenceDbUrlConnectionCommandStep
+import liquibase.database.Database
+import liquibase.database.ObjectQuotingStrategy
+import liquibase.diff.DiffResult
+import liquibase.diff.output.DiffOutputControl
+import liquibase.diff.output.changelog.DiffToChangeLog
+import liquibase.serializer.ChangeLogSerializer
+import spock.lang.Specification
+
+class GroovyDiffToChangeLogCommandStepSpec extends Specification {
+
+    GroovyDiffToChangeLogCommandStep step = new 
GroovyDiffToChangeLogCommandStep()
+    CommandResultsBuilder resultsBuilder = Mock()
+    CommandScope commandScope = Mock()
+    Database database = Mock()
+    DiffOutputControl diffOutputControl = Mock()
+    DiffResult diffResult = Mock()
+    DiffToChangeLog diffToChangeLog = Mock()
+    DiffCommandStep diffCommandStep = Mock()
+
+    def "defineCommandNames returns correct name"() {
+        expect:
+        step.defineCommandNames() == [['groovyDiffChangelog'] as String[]] as 
String[][]
+    }
+
+    def "run executes diff and prints groovy changelog"() {
+        given:
+        resultsBuilder.getCommandScope() >> commandScope
+        
commandScope.getArgumentValue(ReferenceDbUrlConnectionCommandStep.REFERENCE_DATABASE_ARG)
 >> database
+        
commandScope.getArgumentValue(DiffChangelogCommandStep.CHANGELOG_FILE_ARG) >> 
null
+        
+        
resultsBuilder.getResult(DiffOutputControlCommandStep.DIFF_OUTPUT_CONTROL.getName())
 >> diffOutputControl
+        
+        ByteArrayOutputStream baos = new ByteArrayOutputStream()
+        resultsBuilder.getOutputStream() >> baos
+
+        database.getObjectQuotingStrategy() >> ObjectQuotingStrategy.LEGACY
+
+        GroovyDiffToChangeLogCommandStep stepSpy = 
Spy(GroovyDiffToChangeLogCommandStep)
+        stepSpy.createDiffCommandStep() >> diffCommandStep
+        stepSpy.createDiffToChangeLogObject(diffResult, diffOutputControl, 
false) >> diffToChangeLog
+
+        when:
+        stepSpy.run(resultsBuilder)
+
+        then:
+        1 * diffCommandStep.createDiffResult(resultsBuilder) >> diffResult
+        
+        1 * 
database.setObjectQuotingStrategy(ObjectQuotingStrategy.QUOTE_ALL_OBJECTS)
+        
+        1 * diffToChangeLog.print(_ as PrintStream, _ as ChangeLogSerializer)
+        
+        1 * database.setObjectQuotingStrategy(ObjectQuotingStrategy.LEGACY)
+        1 * resultsBuilder.addResult('statusCode', 0)
+    }
+
+    def "run executes diff and prints to file if specified"() {
+        given:
+        resultsBuilder.getCommandScope() >> commandScope
+        
commandScope.getArgumentValue(ReferenceDbUrlConnectionCommandStep.REFERENCE_DATABASE_ARG)
 >> database
+        
commandScope.getArgumentValue(DiffChangelogCommandStep.CHANGELOG_FILE_ARG) >> 
'changelog.groovy'
+        
+        
resultsBuilder.getResult(DiffOutputControlCommandStep.DIFF_OUTPUT_CONTROL.getName())
 >> diffOutputControl
+        
+        resultsBuilder.getOutputStream() >> new ByteArrayOutputStream()
+
+        database.getObjectQuotingStrategy() >> ObjectQuotingStrategy.LEGACY
+
+        GroovyDiffToChangeLogCommandStep stepSpy = 
Spy(GroovyDiffToChangeLogCommandStep)
+        stepSpy.createDiffCommandStep() >> diffCommandStep
+        stepSpy.createDiffToChangeLogObject(diffResult, diffOutputControl, 
false) >> diffToChangeLog
+
+        when:
+        stepSpy.run(resultsBuilder)
+
+        then:
+        1 * diffCommandStep.createDiffResult(resultsBuilder) >> diffResult
+        
+        1 * diffToChangeLog.print('changelog.groovy', _ as ChangeLogSerializer)
+        
+        1 * resultsBuilder.addResult('statusCode', 0)
+    }
+}

Reply via email to