Search in sources :

Example 16 with GradleRunner

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

the class DbImportIT method emptyDbTaskWithDependency.

@Test
public void emptyDbTaskWithDependency() throws Exception {
    // create empty db to avoid problems on Java 11
    prepareDerbyDatabase("empty_db");
    GradleRunner runner = createRunner("dbimport-with-project-dependency", "cdbimport", "--info");
    BuildResult result = runner.build();
    assertNotNull(result.task(":cdbimport"));
    assertEquals(TaskOutcome.SUCCESS, result.task(":cdbimport").getOutcome());
    File dataMap = new File(projectDir.getAbsolutePath() + "/datamap.map.xml");
    assertTrue(dataMap.exists());
    assertTrue(result.getOutput().contains("Detected changes: No changes to import."));
}
Also used : BuildResult(org.gradle.testkit.runner.BuildResult) GradleRunner(org.gradle.testkit.runner.GradleRunner) File(java.io.File) Test(org.junit.Test)

Example 17 with GradleRunner

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

the class DbImportIT method excludeRelDbTaskSuccess.

@Test
public void excludeRelDbTaskSuccess() throws Exception {
    String dbUrl = prepareDerbyDatabase("exclude_Table");
    File dataMap = new File(projectDir.getAbsolutePath() + "/datamap.map.xml");
    assertFalse(dataMap.exists());
    GradleRunner runner = createRunner("dbimport_excludeRel", "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: SCHEMA_01.TEST1"));
    assertTrue(result.getOutput().contains("Table: SCHEMA_01.TEST2"));
}
Also used : BuildResult(org.gradle.testkit.runner.BuildResult) GradleRunner(org.gradle.testkit.runner.GradleRunner) File(java.io.File) Test(org.junit.Test)

Example 18 with GradleRunner

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

the class CgenTaskIT method cgenWithConfigInDm.

@Test
public void cgenWithConfigInDm() throws Exception {
    GradleRunner runner = createRunner("cgen_with_config", "cgen", "-PdataMap=cgen_with_config.map.xml");
    BuildResult result = runner.forwardOutput().build();
    String generatedDirectoryPath = projectDir.getAbsolutePath() + "/customDirectory1/";
    String generatedClassPath = generatedDirectoryPath + "ObjEntity1.txt";
    String datamap = generatedDirectoryPath + "CgenMap.txt";
    String notIncludedEntity = generatedDirectoryPath + "ObjEntity.txt";
    String notIncludedEmbeddable = generatedDirectoryPath + "Embeddable.txt";
    Path generatedClass = Paths.get(generatedClassPath);
    Path generatedDataMap = Paths.get(datamap);
    Path generatedNotIncludedEntity = Paths.get(notIncludedEntity);
    Path generatedNotIncludedEmbeddable = Paths.get(notIncludedEmbeddable);
    assertTrue(Files.exists(generatedClass));
    assertFalse(Files.exists(generatedDataMap));
    assertFalse(Files.exists(generatedNotIncludedEmbeddable));
    assertFalse(Files.exists(generatedNotIncludedEntity));
    assertEquals(TaskOutcome.SUCCESS, result.task(":cgen").getOutcome());
}
Also used : Path(java.nio.file.Path) BuildResult(org.gradle.testkit.runner.BuildResult) GradleRunner(org.gradle.testkit.runner.GradleRunner) Test(org.junit.Test)

Example 19 with GradleRunner

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

the class CgenTaskIT method testReplaceDatamapMode.

@Test
public void testReplaceDatamapMode() throws Exception {
    GradleRunner runner = createRunner("cgen_replaceDatamapMode", "cgen", "-PdataMap=cgenMap.map.xml");
    BuildResult result = runner.forwardOutput().build();
    String generatedDirectoryPath = projectDir.getAbsolutePath() + "/customDirectory/";
    String notIncludedEntity = generatedDirectoryPath + "ObjEntity.txt";
    Path generatedNotIncludedEntity = Paths.get(notIncludedEntity);
    assertFalse(Files.exists(generatedNotIncludedEntity));
    String notIncludedEntity1 = generatedDirectoryPath + "ObjEntity1.txt";
    Path generatedNotIncludedEntity1 = Paths.get(notIncludedEntity1);
    assertFalse(Files.exists(generatedNotIncludedEntity1));
    String notIncludedEmbeddable = generatedDirectoryPath + "Embeddable.txt";
    Path generatedNotIncludedEmbeddable = Paths.get(notIncludedEmbeddable);
    assertFalse(Files.exists(generatedNotIncludedEmbeddable));
    String includedDataMap = generatedDirectoryPath + "CgenMap.txt";
    Path generatedIncludedDataMap = Paths.get(includedDataMap);
    assertTrue(Files.exists(generatedIncludedDataMap));
    String includedSuperDataMap = generatedDirectoryPath + "auto/_CgenMap.txt";
    Path generatedIncludedSuperDataMap = Paths.get(includedSuperDataMap);
    assertTrue(Files.exists(generatedIncludedSuperDataMap));
    assertEquals(TaskOutcome.SUCCESS, result.task(":cgen").getOutcome());
}
Also used : Path(java.nio.file.Path) BuildResult(org.gradle.testkit.runner.BuildResult) GradleRunner(org.gradle.testkit.runner.GradleRunner) Test(org.junit.Test)

Example 20 with GradleRunner

use of org.gradle.testkit.runner.GradleRunner in project liferay-blade-samples by liferay.

the class GradleRunnerUtil method executeGradleRunner.

public static BuildTask executeGradleRunner(File projectDir, String... taskPath) {
    GradleRunner runner = GradleRunner.create().withProjectDir(projectDir);
    GradleRunner runnerWithArguments = runner.withArguments(taskPath);
    BuildResult buildResult = runnerWithArguments.build();
    BuildTask buildtask = null;
    for (BuildTask task : buildResult.getTasks()) {
        if (task.getPath().endsWith(taskPath[taskPath.length - 1])) {
            buildtask = task;
            break;
        }
    }
    return buildtask;
}
Also used : BuildResult(org.gradle.testkit.runner.BuildResult) BuildTask(org.gradle.testkit.runner.BuildTask) GradleRunner(org.gradle.testkit.runner.GradleRunner)

Aggregations

GradleRunner (org.gradle.testkit.runner.GradleRunner)20 BuildResult (org.gradle.testkit.runner.BuildResult)17 Test (org.junit.Test)15 File (java.io.File)8 Path (java.nio.file.Path)3 WireMockServer (com.github.tomakehurst.wiremock.WireMockServer)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 JarFile (java.util.jar.JarFile)1 BuildTask (org.gradle.testkit.runner.BuildTask)1