Skip to content

Commit 3ecb2bc

Browse files
committed
HBX-3080: Refactor the Gradle integration tests to factor out common code
- Make class 'RunSqlTest' extend 'TestTemplate' - Rename 'setGradleCommandToExecute' to 'setGradleTaskToExecute' Signed-off-by: Koen Aers <[email protected]>
1 parent a7b1763 commit 3ecb2bc

File tree

4 files changed

+26
-33
lines changed

4 files changed

+26
-33
lines changed

gradle/plugin/src/functionalTest/java/org/hibernate/tool/gradle/GenerateJavaTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class GenerateJavaTest extends TestTemplate {
3232

3333
@BeforeEach
3434
public void beforeEach() {
35-
setGradleCommandToExecute("generateJava");
35+
setGradleTaskToPerform("generateJava");
3636
setDatabaseCreationScript(new String[] {
3737
"create table PERSON (ID int not null, NAME varchar(20), primary key (ID))"
3838
});

gradle/plugin/src/functionalTest/java/org/hibernate/tool/gradle/RunSqlTest.java

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,43 +17,34 @@
1717
*/
1818
package org.hibernate.tool.gradle;
1919

20+
import static org.junit.jupiter.api.Assertions.assertNotNull;
21+
import static org.junit.jupiter.api.Assertions.assertNull;
2022
import static org.junit.jupiter.api.Assertions.assertTrue;
2123

22-
import java.io.File;
23-
import java.io.IOException;
24-
25-
import org.gradle.testkit.runner.BuildResult;
26-
import org.hibernate.tool.gradle.test.func.utils.FuncTestConstants;
27-
import org.hibernate.tool.gradle.test.func.utils.FuncTestTemplate;
24+
import org.hibernate.tool.it.gradle.TestTemplate;
25+
import org.junit.jupiter.api.BeforeEach;
2826
import org.junit.jupiter.api.Test;
2927

30-
class RunSqlTest extends FuncTestTemplate implements FuncTestConstants {
28+
class RunSqlTest extends TestTemplate {
3129

32-
private static final String BUILD_FILE_HIBERNATE_TOOLS_SECTION =
30+
private static final String HIBERNATE_TOOLS_EXTENSION_SECTION =
3331
"hibernateTools {\n" +
3432
" sqlToRun = 'create table foo (id int not null primary key, baz varchar(256))'\n" +
35-
" hibernateProperties = 'foo.bar'" +
3633
"}\n";
3734

38-
@Override
39-
public String getBuildFileHibernateToolsSection() {
40-
return BUILD_FILE_HIBERNATE_TOOLS_SECTION;
41-
}
42-
43-
@Override
44-
public String getHibernatePropertiesFileName() {
45-
return "foo.bar";
35+
@BeforeEach
36+
public void beforeEach() {
37+
setGradleTaskToPerform("runSql");
4638
}
4739

48-
@Test
49-
void testRunSql() throws IOException {
50-
performTask("runSql", false);
40+
@Test
41+
void testRunSql() throws Exception {
42+
setHibernateToolsExtensionSection(HIBERNATE_TOOLS_EXTENSION_SECTION);
43+
assertNull(getDatabaseFile());
44+
createProjectAndExecuteGradleCommand();
45+
assertTrue(getBuildResult().getOutput().contains("Running SQL: create table foo (id int not null primary key, baz varchar(256))"));
46+
assertNotNull(getDatabaseFile());
47+
assertTrue(getDatabaseFile().exists());
5148
}
5249

53-
@Override
54-
protected void verifyBuild(BuildResult buildResult) {
55-
assertTrue(buildResult.getOutput().contains("Running SQL: create table foo (id int not null primary key, baz varchar(256))"));
56-
assertTrue(new File(projectDir, DATABASE_FOLDER_NAME + "/" + DATABASE_FILE_NAME).exists());
57-
}
58-
5950
}

gradle/plugin/src/functionalTest/java/org/hibernate/tool/gradle/TutorialTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class TutorialTest extends TestTemplate {
1414

1515
@BeforeEach
1616
public void beforeEach() {
17-
setGradleCommandToExecute("generateJava");
17+
setGradleTaskToPerform("generateJava");
1818
setDatabaseCreationScript(new String[] {
1919
"create table PERSON (ID int not null, NAME varchar(20), primary key (ID))"
2020
});

gradle/plugin/src/functionalTest/java/org/hibernate/tool/it/gradle/TestTemplate.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ public class TestTemplate {
2828

2929
private String[] databaseCreationScript;
3030
private String hibernateToolsExtensionSection;
31-
private String gradleCommandToExecute;
31+
private String gradleTaskToPerform;
32+
private BuildResult buildResult;
3233

3334
protected File getProjectDir() { return projectDir; }
3435
protected File getGradlePropertiesFile() { return gradlePropertiesFile; }
@@ -41,16 +42,17 @@ public class TestTemplate {
4142
protected void setDatabaseCreationScript(String[] script) { databaseCreationScript = script; }
4243
protected String getHibernateToolsExtensionSection() { return hibernateToolsExtensionSection; }
4344
protected void setHibernateToolsExtensionSection(String s) { hibernateToolsExtensionSection = s; }
44-
protected String getGradleCommandToExecute() { return gradleCommandToExecute; }
45-
protected void setGradleCommandToExecute(String command) { gradleCommandToExecute = command; }
45+
protected String getGradleTaskToPerform() { return gradleTaskToPerform; }
46+
protected void setGradleTaskToPerform(String command) { gradleTaskToPerform = command; }
47+
protected BuildResult getBuildResult() { return buildResult; }
4648

4749
protected void executeGradleCommand(String ... gradleCommandLine) {
4850
GradleRunner runner = GradleRunner.create();
4951
runner.withArguments(gradleCommandLine);
5052
runner.forwardOutput();
5153
runner.withPluginClasspath();
5254
runner.withProjectDir(getProjectDir());
53-
BuildResult buildResult = runner.build();
55+
buildResult = runner.build();
5456
assertTrue(buildResult.getOutput().contains("BUILD SUCCESSFUL"));
5557
}
5658

@@ -64,7 +66,7 @@ protected void createProject() throws Exception {
6466

6567
protected void createProjectAndExecuteGradleCommand() throws Exception {
6668
createProject();
67-
executeGradleCommand(getGradleCommandToExecute());
69+
executeGradleCommand(getGradleTaskToPerform());
6870
}
6971

7072
protected void initGradleProject() throws Exception {

0 commit comments

Comments
 (0)