Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class GenerateJavaTest extends TestTemplate {

@BeforeEach
public void beforeEach() {
setGradleCommandToExecute("generateJava");
setGradleTaskToPerform("generateJava");
setDatabaseCreationScript(new String[] {
"create table PERSON (ID int not null, NAME varchar(20), primary key (ID))"
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,43 +17,34 @@
*/
package org.hibernate.tool.gradle;

import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.File;
import java.io.IOException;

import org.gradle.testkit.runner.BuildResult;
import org.hibernate.tool.gradle.test.func.utils.FuncTestConstants;
import org.hibernate.tool.gradle.test.func.utils.FuncTestTemplate;
import org.hibernate.tool.it.gradle.TestTemplate;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

class RunSqlTest extends FuncTestTemplate implements FuncTestConstants {
class RunSqlTest extends TestTemplate {

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

@Override
public String getBuildFileHibernateToolsSection() {
return BUILD_FILE_HIBERNATE_TOOLS_SECTION;
}

@Override
public String getHibernatePropertiesFileName() {
return "foo.bar";
@BeforeEach
public void beforeEach() {
setGradleTaskToPerform("runSql");
}

@Test
void testRunSql() throws IOException {
performTask("runSql", false);
@Test
void testRunSql() throws Exception {
setHibernateToolsExtensionSection(HIBERNATE_TOOLS_EXTENSION_SECTION);
assertNull(getDatabaseFile());
createProjectAndExecuteGradleCommand();
assertTrue(getBuildResult().getOutput().contains("Running SQL: create table foo (id int not null primary key, baz varchar(256))"));
assertNotNull(getDatabaseFile());
assertTrue(getDatabaseFile().exists());
}

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

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class TutorialTest extends TestTemplate {

@BeforeEach
public void beforeEach() {
setGradleCommandToExecute("generateJava");
setGradleTaskToPerform("generateJava");
setDatabaseCreationScript(new String[] {
"create table PERSON (ID int not null, NAME varchar(20), primary key (ID))"
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public class TestTemplate {

private String[] databaseCreationScript;
private String hibernateToolsExtensionSection;
private String gradleCommandToExecute;
private String gradleTaskToPerform;
private BuildResult buildResult;

protected File getProjectDir() { return projectDir; }
protected File getGradlePropertiesFile() { return gradlePropertiesFile; }
Expand All @@ -41,16 +42,17 @@ public class TestTemplate {
protected void setDatabaseCreationScript(String[] script) { databaseCreationScript = script; }
protected String getHibernateToolsExtensionSection() { return hibernateToolsExtensionSection; }
protected void setHibernateToolsExtensionSection(String s) { hibernateToolsExtensionSection = s; }
protected String getGradleCommandToExecute() { return gradleCommandToExecute; }
protected void setGradleCommandToExecute(String command) { gradleCommandToExecute = command; }
protected String getGradleTaskToPerform() { return gradleTaskToPerform; }
protected void setGradleTaskToPerform(String command) { gradleTaskToPerform = command; }
protected BuildResult getBuildResult() { return buildResult; }

protected void executeGradleCommand(String ... gradleCommandLine) {
GradleRunner runner = GradleRunner.create();
runner.withArguments(gradleCommandLine);
runner.forwardOutput();
runner.withPluginClasspath();
runner.withProjectDir(getProjectDir());
BuildResult buildResult = runner.build();
buildResult = runner.build();
assertTrue(buildResult.getOutput().contains("BUILD SUCCESSFUL"));
}

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

protected void createProjectAndExecuteGradleCommand() throws Exception {
createProject();
executeGradleCommand(getGradleCommandToExecute());
executeGradleCommand(getGradleTaskToPerform());
}

protected void initGradleProject() throws Exception {
Expand Down