Search in sources :

Example 1 with GradleRunner

use of org.gradle.testkit.runner.GradleRunner in project crate by crate.

the class JdkDownloadPluginFunctionalTest method runBuild.

private static void runBuild(String task, Consumer<BuildResult> assertions, String os, String arch, String vendor, String version) {
    var testKitDirPath = Paths.get(System.getProperty("user.dir"), "build", System.getProperty("user.name"));
    WireMockServer wireMock = new WireMockServer(0);
    try {
        wireMock.stubFor(head(urlEqualTo(urlPath(vendor, version, os, arch))).willReturn(aResponse().withStatus(200)));
        wireMock.stubFor(get(urlEqualTo(urlPath(vendor, version, os, arch))).willReturn(aResponse().withStatus(200).withBody(filebytes(vendor, version, os, arch))));
        wireMock.start();
        GradleRunner runner = GradleRunner.create().withDebug(true).withProjectDir(getTestKitProjectDir("jdk-download")).withTestKitDir(testKitDirPath.toFile()).withArguments(task, "-Dtests.jdk_vendor=" + vendor, "-Dtests.jdk_version=" + version, "-Dtests.jdk_repo=" + wireMock.baseUrl(), "-i").withPluginClasspath();
        BuildResult result = runner.build();
        assertions.accept(result);
    } catch (IOException e) {
        fail("cannot get artifacts from resources: " + e.getLocalizedMessage());
    } finally {
        wireMock.stop();
    }
}
Also used : BuildResult(org.gradle.testkit.runner.BuildResult) GradleRunner(org.gradle.testkit.runner.GradleRunner) IOException(java.io.IOException) WireMockServer(com.github.tomakehurst.wiremock.WireMockServer)

Example 2 with GradleRunner

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

the class CgenTaskIT method classGeneratingWithCustomConfigSuccess.

@Test
public void classGeneratingWithCustomConfigSuccess() throws Exception {
    GradleRunner runner = createRunner("cgen_custom_config", "cgen", "-PdataMap=test_datamap.map.xml");
    BuildResult result = runner.build();
    String generatedDirectoryPath = projectDir.getAbsolutePath() + "/customDirectory/org/example/cayenne/persistent/";
    String generatedClassPath = generatedDirectoryPath + "City.groovy";
    String excludedClassPath = generatedDirectoryPath + "Artist.groovy";
    String generatedParentClassPath = generatedDirectoryPath + "auto/_City.groovy";
    String excludedParentClassPath = generatedDirectoryPath + "auto/_Artist.groovy";
    File generatedClass = new File(generatedClassPath);
    File excludedClass = new File(excludedClassPath);
    File generatedParentClass = new File(generatedParentClassPath);
    File excludedParentClass = new File(excludedParentClassPath);
    assertTrue(generatedClass.exists());
    assertTrue(!excludedClass.exists());
    assertTrue(!excludedParentClass.exists());
    assertTrue(!generatedParentClass.exists());
    assertEquals(TaskOutcome.SUCCESS, result.task(":cgen").getOutcome());
}
Also used : BuildResult(org.gradle.testkit.runner.BuildResult) GradleRunner(org.gradle.testkit.runner.GradleRunner) File(java.io.File) Test(org.junit.Test)

Example 3 with GradleRunner

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

the class CgenTaskIT method testWithConfigsInDmAndPom.

@Test
public void testWithConfigsInDmAndPom() throws Exception {
    GradleRunner runner = createRunner("cgen_with_configs", "cgen", "-PdataMap=cgenMap.map.xml");
    BuildResult result = runner.forwardOutput().build();
    String generatedDirectoryPath = projectDir.getAbsolutePath() + "/customDirectory/";
    String generatedClassPath = generatedDirectoryPath + "ObjEntity.groovy";
    Path generatedClass = Paths.get(generatedClassPath);
    assertTrue(Files.exists(generatedClass));
    String notIncludedEntity = generatedDirectoryPath + "ObjEntity1.groovy";
    Path generatedNotIncludedEntity = Paths.get(notIncludedEntity);
    assertFalse(Files.exists(generatedNotIncludedEntity));
    String includedDataMap = generatedDirectoryPath + "CgenMap.groovy";
    Path generatedIncludedDataMap = Paths.get(includedDataMap);
    assertTrue(Files.exists(generatedIncludedDataMap));
    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 4 with GradleRunner

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

the class CgenTaskIT method classGeneratingWithDefaultConfigSuccess.

@Test
public void classGeneratingWithDefaultConfigSuccess() throws Exception {
    GradleRunner runner = createRunner("cgen_default_config", "cgen", "-PdataMap=test_datamap.map.xml");
    BuildResult result = runner.forwardOutput().build();
    String generatedDirectoryPath = projectDir.getAbsolutePath() + "/src/main/java/org/example/cayenne/persistent/";
    String generatedClassPath = generatedDirectoryPath + "City.java";
    String generatedParentClassPath = generatedDirectoryPath + "auto/_City.java";
    File generatedClass = new File(generatedClassPath);
    File generatedParentClass = new File(generatedParentClassPath);
    assertTrue(generatedClass.exists());
    assertTrue(generatedParentClass.exists());
    assertEquals(TaskOutcome.SUCCESS, result.task(":cgen").getOutcome());
}
Also used : BuildResult(org.gradle.testkit.runner.BuildResult) GradleRunner(org.gradle.testkit.runner.GradleRunner) File(java.io.File) Test(org.junit.Test)

Example 5 with GradleRunner

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

the class DbImportIT method notConfiguredTaskFailure.

@Test
public void notConfiguredTaskFailure() throws Exception {
    GradleRunner runner = createRunner("dbimport_failure", "cdbimport", "--info");
    BuildResult result = runner.buildAndFail();
    // new version of Gradle (4.3.1 as of 05/12/2017) seems not return task status, so ignore this
    // assertNotNull(result.task(":cdbimport"));
    // assertEquals(TaskOutcome.FAILED, result.task(":cdbimport").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)

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