Search in sources :

Example 11 with GradleRunner

use of org.gradle.testkit.runner.GradleRunner 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 12 with GradleRunner

use of org.gradle.testkit.runner.GradleRunner 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 13 with GradleRunner

use of org.gradle.testkit.runner.GradleRunner 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)

Example 14 with GradleRunner

use of org.gradle.testkit.runner.GradleRunner in project crnk-framework by crnk-project.

the class GradleDeltaspikeTest method test.

@Test
public void test() throws IOException {
    testFolder.create();
    root = testFolder.getRoot();
    saveFile("test_build.gradle", "build.gradle");
    saveFile("test_settings.gradle", "settings.gradle");
    saveFile("META-INF/beans.xml", "src/main/resources/META-INF/beans.xml");
    saveFile("TestModuleProducer.template", "src/main/java/io/crnk/gen/typescript/TestModuleProducer.java");
    GradleRunner runner = GradleRunner.create();
    runner = runner.withPluginClasspath();
    // List<File> files = Arrays.asList(new File("C:\\projects\\oss\\crnk-framework\\crnk-gen-typescript\\build\\classes\\main"));
    runner = runner.withProjectDir(root);
    // TODO move to assembleTypescript once ngrx-json-api released
    runner = runner.withArguments("generateTypescript");
    BuildResult build = runner.build();
    System.out.println(build.getOutput());
}
Also used : BuildResult(org.gradle.testkit.runner.BuildResult) GradleRunner(org.gradle.testkit.runner.GradleRunner) Test(org.junit.Test)

Example 15 with GradleRunner

use of org.gradle.testkit.runner.GradleRunner in project spring-boot by spring-projects.

the class GradleBuild method prepareRunner.

public GradleRunner prepareRunner(String... arguments) throws IOException {
    this.scriptProperties.put("bootVersion", getBootVersion());
    this.scriptProperties.put("dependencyManagementPluginVersion", getDependencyManagementPluginVersion());
    copyTransformedScript(this.script, new File(this.projectDir, "build" + this.dsl.getExtension()));
    if (this.settings != null) {
        copyTransformedScript(this.settings, new File(this.projectDir, "settings.gradle"));
    }
    File repository = new File("src/test/resources/repository");
    if (repository.exists()) {
        FileSystemUtils.copyRecursively(repository, new File(this.projectDir, "repository"));
    }
    GradleRunner gradleRunner = GradleRunner.create().withProjectDir(this.projectDir).withPluginClasspath(pluginClasspath());
    if (this.dsl != Dsl.KOTLIN && !this.configurationCache) {
        // see https://github.com/gradle/gradle/issues/6862
        gradleRunner.withDebug(true);
    }
    if (this.gradleVersion != null) {
        gradleRunner.withGradleVersion(this.gradleVersion);
    }
    gradleRunner.withTestKitDir(getTestKitDir());
    List<String> allArguments = new ArrayList<>();
    allArguments.add("-PbootVersion=" + getBootVersion());
    allArguments.add("--stacktrace");
    allArguments.addAll(Arrays.asList(arguments));
    allArguments.add("--warning-mode");
    allArguments.add("all");
    if (this.configurationCache) {
        allArguments.add("--configuration-cache");
    }
    return gradleRunner.withArguments(allArguments);
}
Also used : GradleRunner(org.gradle.testkit.runner.GradleRunner) ArrayList(java.util.ArrayList) JarFile(java.util.jar.JarFile) File(java.io.File)

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