Search in sources :

Example 71 with BuildResult

use of org.gradle.testkit.runner.BuildResult in project cayenne by apache.

the class DbImportIT method simpleDbTaskSuccess.

@Test
public void simpleDbTaskSuccess() throws Exception {
    String dbUrl = prepareDerbyDatabase("test_map_db");
    File dataMap = new File(projectDir.getAbsolutePath() + "/datamap.map.xml");
    assertFalse(dataMap.exists());
    GradleRunner runner = createRunner("dbimport_simple_db", "cdbimport", "--info", "-PdbUrl=" + dbUrl);
    BuildResult result = runner.build();
    assertNotNull(result.task(":cdbimport"));
    assertEquals(TaskOutcome.SUCCESS, result.task(":cdbimport").getOutcome());
    assertTrue(dataMap.exists());
    // Check few lines from reverse engineering output
    assertTrue(result.getOutput().contains("Table: APP.PAINTING"));
    assertTrue(result.getOutput().contains("Db Relationship : toOne  (EXHIBIT.GALLERY_ID, GALLERY.GALLERY_ID)"));
    assertTrue(result.getOutput().contains("Db Relationship : toMany (GALLERY.GALLERY_ID, PAINTING.GALLERY_ID)"));
    assertTrue(result.getOutput().contains("Create Table         ARTIST"));
    assertFalse(result.getOutput().contains("Create Table         PAINTING1"));
    assertTrue(result.getOutput().contains("Skip relation: '.APP.ARTIST.ARTIST_ID <- .APP.PAINTING1.ARTIST_ID # 1'"));
    assertTrue(result.getOutput().contains("Migration Complete Successfully."));
}
Also used : BuildResult(org.gradle.testkit.runner.BuildResult) GradleRunner(org.gradle.testkit.runner.GradleRunner) File(java.io.File) Test(org.junit.Test)

Example 72 with BuildResult

use of org.gradle.testkit.runner.BuildResult in project cayenne by apache.

the class DbImportIT method withProjectTaskSuccess.

@Test
public void withProjectTaskSuccess() throws Exception {
    String dbUrl = prepareDerbyDatabase("test_project_db");
    File dataMap = new File(projectDir.getAbsolutePath() + "/datamap.map.xml");
    assertFalse(dataMap.exists());
    File project = new File(projectDir.getAbsolutePath() + "/cayenne-project.xml");
    assertFalse(project.exists());
    GradleRunner runner = createRunner("dbimport_with_project", "cdbimport", "--info", "-PdbUrl=" + dbUrl);
    BuildResult result = runner.build();
    assertNotNull(result.task(":cdbimport"));
    assertEquals(TaskOutcome.SUCCESS, result.task(":cdbimport").getOutcome());
    assertTrue(dataMap.isFile());
    assertTrue(project.isFile());
    // Check few lines from reverse engineering output
    assertTrue(result.getOutput().contains("Table: APP.PAINTING"));
    assertTrue(result.getOutput().contains("Db Relationship : toOne  (EXHIBIT.GALLERY_ID, GALLERY.GALLERY_ID)"));
    assertTrue(result.getOutput().contains("Db Relationship : toMany (GALLERY.GALLERY_ID, PAINTING.GALLERY_ID)"));
    assertTrue(result.getOutput().contains("Create Table         ARTIST"));
    assertFalse(result.getOutput().contains("Create Table         PAINTING1"));
    assertTrue(result.getOutput().contains("Skip relation: '.APP.ARTIST.ARTIST_ID <- .APP.PAINTING1.ARTIST_ID # 1'"));
    assertTrue(result.getOutput().contains("Migration Complete Successfully."));
}
Also used : BuildResult(org.gradle.testkit.runner.BuildResult) GradleRunner(org.gradle.testkit.runner.GradleRunner) File(java.io.File) Test(org.junit.Test)

Example 73 with BuildResult

use of org.gradle.testkit.runner.BuildResult in project cayenne by apache.

the class DbGenerateTaskIT method notConfiguredTaskFailure.

@Test
public void notConfiguredTaskFailure() throws Exception {
    GradleRunner runner = createRunner("cdbgen_failure", "cdbgen", "--info");
    BuildResult result = runner.buildAndFail();
    // NOTE: There will be no result for the task, as build will fail earlier because
    // datamap is required parameter that is validated directly by Gradle before task execution.
    // assertNotNull(result.task(":cdbgen"));
    // assertEquals(TaskOutcome.FAILED, result.task(":cdbgen").getOutcome());
    assertTrue(result.getOutput().contains("No datamap configured in task or in cayenne.defaultDataMap"));
}
Also used : BuildResult(org.gradle.testkit.runner.BuildResult) GradleRunner(org.gradle.testkit.runner.GradleRunner) Test(org.junit.Test)

Example 74 with BuildResult

use of org.gradle.testkit.runner.BuildResult in project cayenne by apache.

the class DbGenerateTaskIT method defaultConfigTaskSuccess.

@Test
public void defaultConfigTaskSuccess() throws Exception {
    String dbUrl = "jdbc:derby:build/testdb";
    GradleRunner runner = createRunner("cdbgen_simple", "cdbgen", "-PdbUrl=" + dbUrl, "-PdataMap=test_datamap.map.xml", "--info");
    BuildResult result = runner.build();
    assertNotNull(result.task(":cdbgen"));
    assertEquals(TaskOutcome.SUCCESS, result.task(":cdbgen").getOutcome());
    assertTrue(result.getOutput().contains("generator options - [dropTables: false, dropPK: false, createTables: true, createPK: true, createFK: true]"));
/* // check that DB is really created
        try (Connection connection = DriverManager.getConnection(dbUrl)) {
            try (ResultSet rs = connection.getMetaData()
                    .getTables(null, null, "artist", new String[]{"TABLE"})) {
                assertTrue(rs.next());
            }
        } */
}
Also used : BuildResult(org.gradle.testkit.runner.BuildResult) GradleRunner(org.gradle.testkit.runner.GradleRunner) Test(org.junit.Test)

Example 75 with BuildResult

use of org.gradle.testkit.runner.BuildResult in project cayenne by apache.

the class DbGenerateTaskIT method customConfigTaskSuccess.

@Test
public void customConfigTaskSuccess() throws Exception {
    GradleRunner runner = createRunner("cdbgen_custom", "customCdbgen", "-PdataMap=test_datamap.map.xml", "--info");
    BuildResult result = runner.build();
    assertNotNull(result.task(":customCdbgen"));
    assertEquals(TaskOutcome.SUCCESS, result.task(":customCdbgen").getOutcome());
    assertTrue(result.getOutput().contains("generator options - [dropTables: true, dropPK: true, createTables: false, createPK: false, createFK: false]"));
}
Also used : BuildResult(org.gradle.testkit.runner.BuildResult) GradleRunner(org.gradle.testkit.runner.GradleRunner) Test(org.junit.Test)

Aggregations

BuildResult (org.gradle.testkit.runner.BuildResult)143 File (java.io.File)62 TestTemplate (org.junit.jupiter.api.TestTemplate)60 Test (org.junit.Test)47 Test (org.junit.jupiter.api.Test)20 StringWriter (java.io.StringWriter)19 GradleRunner (org.gradle.testkit.runner.GradleRunner)17 Test (org.testng.annotations.Test)10 ImageReference (org.springframework.boot.buildpack.platform.docker.type.ImageReference)8 JarFile (java.util.jar.JarFile)7 ArrayList (java.util.ArrayList)6 List (java.util.List)6 TestHelpers.findFile (me.tatarka.TestHelpers.findFile)6 TestHelpers.writeFile (me.tatarka.TestHelpers.writeFile)6 ContainerConfig (com.github.dockerjava.api.model.ContainerConfig)5 FileWriter (java.io.FileWriter)5 IOException (java.io.IOException)5 PrintWriter (java.io.PrintWriter)5 Path (java.nio.file.Path)5 BufferedReader (java.io.BufferedReader)4