org.gradle.testkit.runner.GradleRunner Java Examples

The following examples show how to use org.gradle.testkit.runner.GradleRunner. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CuriostackRootPluginTest.java    From curiostack with MIT License 6 votes vote down vote up
@Test
void pomNotManaged() throws Exception {
  assertThat(
          GradleRunner.create()
              .withProjectDir(projectDir.toFile())
              .withArguments(":java-library1:generatePomFileForMavenPublication")
              .withPluginClasspath())
      .builds()
      .tasksDidSucceed(":java-library1:generatePomFileForMavenPublication");

  var soup =
      Jsoup.parse(
          Files.readString(
              projectDir.resolve("java-library1/build/publications/maven/pom-default.xml")));
  assertThat(soup.select("dependencyManagement")).isEmpty();
  assertThat(soup.select("dependency"))
      .hasSize(3)
      .allSatisfy(
          dependency -> {
            assertThat(dependency.selectFirst("groupId").text()).isNotEmpty();
            assertThat(dependency.selectFirst("artifactId").text()).isNotEmpty();
            assertThat(dependency.selectFirst("version").text()).isNotEmpty();
          });
}
 
Example #2
Source File: SourceContextPluginIntegrationTest.java    From app-gradle-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateSourceContext() throws IOException {
  setUpTestProject();
  GradleRunner.create()
      .withProjectDir(testProjectDir.getRoot())
      .withPluginClasspath()
      .withArguments(":assemble")
      .build();

  String commitHash = "9a282640c4a91769d328bbf23e8d8b2b5dcbbb5b";

  File sourceContextFile =
      new File(
          testProjectDir.getRoot(),
          "build/exploded-"
              + testProjectDir.getRoot().getName() // this is project.name
              + "/WEB-INF/classes/source-context.json");
  Assert.assertTrue(
      sourceContextFile.getAbsolutePath() + " is missing", sourceContextFile.exists());
  Assert.assertTrue(
      com.google.common.io.Files.asCharSource(sourceContextFile, Charsets.UTF_8)
          .read()
          .contains(commitHash));
}
 
Example #3
Source File: SourceContextPluginTest.java    From app-gradle-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateSourceContextViaAssemble_taskTree() throws IOException {
  setUpTestProject();
  BuildResult buildResult =
      GradleRunner.create()
          .withProjectDir(testProjectDir.getRoot())
          .withPluginClasspath()
          .withArguments("assemble", "--dry-run")
          .build();

  final List<String> expected =
      Arrays.asList(
          ":_createSourceContext",
          ":compileJava",
          ":processResources",
          ":classes",
          ":war",
          ":explodeWar",
          ":assemble");

  Assert.assertEquals(expected, BuildResultFilter.extractTasks(buildResult));
}
 
Example #4
Source File: ModulePluginSmokeTest.java    From gradle-modules-plugin with MIT License 6 votes vote down vote up
void doSmokeTestRunStartScripts(String gradleVersion, String projectName) {
    var result = GradleRunner.create()
            .withProjectDir(new File(projectName + "/"))
            .withPluginClasspath(pluginClasspath)
            .withGradleVersion(gradleVersion)
            .withArguments("-c", "smoke_test_settings.gradle", "clean", ":greeter.startscripts:installDist", "--info", "--stacktrace")
            .forwardOutput()
            .build();

    assertTasksSuccessful(result, "greeter.startscripts", "installDist");

    String binDir = projectName + "/greeter.startscripts/build/install/demo/bin";
    SmokeTestAppContext ctx = SmokeTestAppContext.ofAliceAndBobAtHome(Path.of(binDir));

    assertEquals("MainDemo: welcome home, Alice and Bob!", ctx.getAppOutput("demo"));
    assertEquals("Demo1: welcome home, Alice and Bob!", ctx.getAppOutput("demo1"));
    assertEquals("Demo2: welcome home, Alice and Bob!", ctx.getAppOutput("demo2"));
}
 
Example #5
Source File: ServiceCompareTaskTest.java    From java-client-api with Apache License 2.0 6 votes vote down vote up
@Test
public void testCommandLineCheckTwoArg() throws IOException {
    initTestEnv();

    StringBuilder buildText = new StringBuilder()
            .append("plugins {\n")
            .append("  id 'com.marklogic.ml-development-tools'\n")
            .append("}\n");
    writeBuildFile(buildText);

    BuildResult result = GradleRunner
            .create()
            .withProjectDir(testDir.getRoot())
            .withPluginClasspath()
            .withArguments(
                    "-PcustomSeviceDeclarationFile="+testEnv.customServiceDir.getPath()+"/service.json",
                "-PbaseSeviceDeclarationFile="+testEnv.baseServiceDir.getPath()+"/service.json",
                    "checkCustomService"
            )
            .withDebug(true)
            .build();

    assertTrue("two argument command failed", result.getOutput().contains("BUILD SUCCESSFUL"));

    testEnv.buildFile.delete();
}
 
Example #6
Source File: ModulePluginSmokeTest.java    From gradle-modules-plugin with MIT License 6 votes vote down vote up
void doSmokeTestJunit5(String gradleVersion, String junitVersionPair) {
    var junitVersionParts = junitVersionPair.split("/");
    var junitVersionProperty = String.format("-PjUnitVersion=%s", junitVersionParts[0]);
    var junitPlatformVersionProperty = String.format("-PjUnitPlatformVersion=%s", junitVersionParts[1]);
    var result = GradleRunner.create()
            .withProjectDir(new File("test-project/"))
            .withPluginClasspath(pluginClasspath)
            .withGradleVersion(gradleVersion)
            .withArguments("-c", "smoke_test_settings.gradle", junitVersionProperty, junitPlatformVersionProperty, "clean", "build", "run", "--stacktrace")
            .forwardOutput()
            .build();

    assertTasksSuccessful(result, "greeter.api", "build");
    assertTasksSuccessful(result, "greeter.provider", "build");
    assertTasksSuccessful(result, "greeter.provider.test", "build");
    assertTasksSuccessful(result, "greeter.runner", "build", "run");
}
 
Example #7
Source File: ModulePluginSmokeTest.java    From gradle-modules-plugin with MIT License 6 votes vote down vote up
void doSmokeTestRun(String gradleVersion, String projectName) {
    var writer = new StringWriter(256);
    var result = GradleRunner.create()
            .withProjectDir(new File(projectName + "/"))
            .withPluginClasspath(pluginClasspath)
            .withGradleVersion(gradleVersion)
            .withArguments("-q", "-c", "smoke_test_settings.gradle", "clean", ":greeter.runner:run", "--args", "aaa bbb")
            .forwardStdOutput(writer)
            .forwardStdError(writer)
            .build();

    assertTasksSuccessful(result, "greeter.runner", "run");

    var lines = writer.toString().lines().collect(Collectors.toList());
    assertEquals("args: [aaa, bbb]", lines.get(0));
    assertEquals("greeter.sender: gradle-modules-plugin", lines.get(1));
    assertEquals("welcome", lines.get(2));
}
 
Example #8
Source File: SwaggerHubDownloadTest.java    From swaggerhub-gradle-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void testSwaggerHubDownloadTask() throws IOException {
    outputFile = testProjectDir.getRoot().toString() + "/testAPI.json";
    String downloadTask = "swaggerhubDownload";

    String buildFileContent = "plugins { id 'io.swagger.swaggerhub' }\n" +
            downloadTask + " {\n" +
            "    api \'PetStoreAPI\'\n" +
            "    owner \'jsfrench\'\n" +
            "    version \'1.0.0\'\n" +
            "    outputFile \'" + outputFile + "\'\n" +
            "}";

    writeFile(buildFile, buildFileContent);

    BuildResult result = GradleRunner.create()
            .withPluginClasspath()
            .withProjectDir(testProjectDir.getRoot())
            .withArguments(downloadTask, "--stacktrace")
            .build();

    assertEquals(SUCCESS, result.task(":" + downloadTask).getOutcome());
    assertTrue(new File(outputFile).exists());
}
 
Example #9
Source File: CurioGenericCiPluginTest.java    From curiostack with MIT License 6 votes vote down vote up
@Test
void ciIsMaster() {
  assertThat(
          GradleRunner.create()
              .withProjectDir(projectDir)
              .withArguments("continuousBuild")
              .withEnvironment(ImmutableMap.of("CI", "true", "CI_MASTER", "true"))
              .withPluginClasspath())
      .builds()
      .satisfies(
          onlyDidRun(
              ":library1:jar",
              ":library1:build",
              ":library2:jar",
              ":library2:build",
              ":server1:build",
              ":server1:jib",
              ":server1:deployAlpha",
              ":server2:build",
              ":server2:jib",
              ":server2:deployAlpha",
              ":staticsite1:deployAlpha"));
}
 
Example #10
Source File: AppEngineStandardPluginIntegrationTest.java    From app-gradle-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void testDeploy()
    throws CloudSdkNotFoundException, IOException, ProcessHandlerException,
        UnsupportedOsException {
  BuildResult buildResult =
      GradleRunner.create()
          .withProjectDir(testProjectDir.getRoot())
          .withPluginClasspath()
          .withArguments("appengineDeploy", "--stacktrace")
          .build();

  Assert.assertThat(
      buildResult.getOutput(),
      CoreMatchers.containsString("Deployed service [standard-project]"));

  deleteProject();
}
 
Example #11
Source File: EndpointProxiesGenTaskTest.java    From java-client-api with Apache License 2.0 6 votes vote down vote up
@Test
public void testCommandLineInit() throws IOException {
  initTestEnv();

  StringBuilder buildText = new StringBuilder()
    .append("plugins {\n")
    .append("  id 'com.marklogic.ml-development-tools'\n")
    .append("}\n");
  writeBuildFile(buildText);

  BuildResult result = GradleRunner
      .create()
      .withProjectDir(testDir.getRoot())
      .withPluginClasspath()
      .withArguments(
          "-PserviceDeclarationFile="+testEnv.serviceDir.getPath()+"/service.json",
          "-PjavaBaseDirectory="+testEnv.javaBaseDir.getPath(),
          "generateEndpointProxies"
         )
      .withDebug(true)
      .build();
  assertTrue("command line did not generate "+testEnv.outClass.getPath(), testEnv.outClass.exists());

  testEnv.buildFile.delete();
  testEnv.outClass.delete();
}
 
Example #12
Source File: ModuleInitTaskTest.java    From java-client-api with Apache License 2.0 6 votes vote down vote up
public void runTaskInitTest(File apiFile, String modExtension, File buildFile, File outDir) throws IOException {
  StringBuilder buildText = new StringBuilder()
    .append("plugins {\n")
    .append("  id 'com.marklogic.ml-development-tools'\n")
    .append("}\n")
    .append("task initModuleTest(type: com.marklogic.client.tools.gradle.ModuleInitTask) {\n")
    .append("  endpointDeclarationFile = '"+apiFile.getPath()+"'\n")
    .append("  moduleExtension         = '"+modExtension+"'\n")
    .append("}\n");
  writeBuildFile(buildText);

  BuildResult result = GradleRunner
      .create()
      .withProjectDir(testDir.getRoot())
      .withPluginClasspath()
      .withArguments("initModuleTest")
      .withDebug(true)
      .build();
  File modFile = new File(outDir, testEnv.baseName + "." + modExtension);
  assertTrue("task init did not generate "+modFile.getPath(), modFile.exists());

  buildFile.delete();
  modFile.delete();
}
 
Example #13
Source File: CuriostackRootPluginTest.java    From curiostack with MIT License 6 votes vote down vote up
@Test
// This test is slow since it runs yarn, just run locally for now.
@DisabledIfEnvironmentVariable(named = "CI", matches = "true")
void updatesResolutions() {
  assertThat(
          GradleRunner.create()
              .withProjectDir(projectDir.toFile())
              .withArguments(":checkNodeResolutions")
              .withPluginClasspath())
      .fails()
      .tasksDidRun(":checkNodeResolutions");

  assertThat(
          GradleRunner.create()
              .withProjectDir(projectDir.toFile())
              .withArguments(":updateNodeResolutions")
              .withPluginClasspath())
      .builds()
      .tasksDidSucceed(":updateNodeResolutions");
}
 
Example #14
Source File: FunctionalDownloadTest.java    From gradle-download-task with Apache License 2.0 6 votes vote down vote up
/**
 * Create a gradle runner to test against
 * @param parameters the download parameters
 * @return the runner
 * @throws IOException if the build file could not be created
 */
protected GradleRunner createRunner(Parameters parameters) throws IOException {
    return createRunnerWithBuildFile(
        "plugins { id 'de.undercouch.download' }\n" +
        "task downloadTask(type: Download) {\n" +
            "src(" + parameters.src + ")\n" +
            "dest " + parameters.dest + "\n" +
            "overwrite " + parameters.overwrite + "\n" +
            "onlyIfModified " + parameters.onlyIfModified + "\n" +
            "compress " + parameters.compress + "\n" +
            "quiet " + parameters.quiet + "\n" +
            "useETag " + parameters.useETag + "\n" +
        "}\n" +
        "task processTask {\n" +
            "inputs.files files(downloadTask)\n" +
            "doLast {\n" +
                "assert !inputs.files.isEmpty()\n" +
                "inputs.files.each { f -> assert f.isFile() }\n" +
            "}\n" +
        "}\n");
}
 
Example #15
Source File: ModuleInitTaskTest.java    From java-client-api with Apache License 2.0 6 votes vote down vote up
public void runCommandLineInitTest(File apiFile, String modExtension, File buildFile, File outDir) throws IOException {
  StringBuilder buildText = new StringBuilder()
    .append("plugins {\n")
    .append("  id 'com.marklogic.ml-development-tools'\n")
    .append("}\n");
  writeBuildFile(buildText);

  BuildResult result = GradleRunner
      .create()
      .withProjectDir(testDir.getRoot())
      .withPluginClasspath()
      .withArguments(
          "-PendpointDeclarationFile="+apiFile.getPath(),
          "-PmoduleExtension="+modExtension,
          "initializeModule"
      )
      .withDebug(true)
      .build();
  File modFile = new File(outDir, testEnv.baseName + "." + modExtension);
  assertTrue("command line did not generate "+modFile.getPath(), modFile.exists());

  buildFile.delete();
  modFile.delete();
}
 
Example #16
Source File: StaticSitePluginTest.java    From curiostack with MIT License 6 votes vote down vote up
@Test
void normal() {
  assertThat(
          GradleRunner.create()
              .withProjectDir(projectDir.toFile())
              .withArguments("build", "--stacktrace")
              .withEnvironment(ImmutableMap.of())
              .withPluginClasspath())
      .builds()
      .tasksDidSucceed(":site1:buildSite", ":site2:buildSite", ":portal:mergeSite");

  assertThat(projectDir.resolve("portal/build/site/index.html"))
      .hasSameContentAs(projectDir.resolve("portal/src/index.html"));
  assertThat(projectDir.resolve("portal/build/site/index.js"))
      .hasSameContentAs(projectDir.resolve("portal/src/index.js"));
  assertThat(projectDir.resolve("portal/build/site/site1/index.html"))
      .hasSameContentAs(projectDir.resolve("site1/build/site/index.html"));
  assertThat(projectDir.resolve("portal/build/site/site2/index.html"))
      .hasSameContentAs(projectDir.resolve("site2/build/customout/index.html"));
}
 
Example #17
Source File: CurioGenericCiPluginTest.java    From curiostack with MIT License 6 votes vote down vote up
@Test
void ciNotMaster() {
  assertThat(
          GradleRunner.create()
              .withProjectDir(projectDir)
              .withArguments("continuousBuild")
              .withEnvironment(ImmutableMap.of("CI", "true"))
              .withPluginClasspath())
      .builds()
      .satisfies(
          onlyDidRun(
              ":library1:jar",
              ":library1:build",
              ":library2:jar",
              ":library2:build",
              ":server1:build",
              ":server2:build"));
}
 
Example #18
Source File: CuriostackRootPluginTest.java    From curiostack with MIT License 6 votes vote down vote up
@Test
void updatesWrapper() throws Exception {
  assertThat(
          GradleRunner.create()
              .withProjectDir(projectDir.toFile())
              .withArguments("wrapper")
              .withPluginClasspath())
      .builds()
      .tasksDidSucceed(":wrapper", ":curioUpdateWrapper");

  assertThat(Files.readAllLines(projectDir.resolve("gradlew")))
      .contains(". ./gradle/get-jdk.sh");
  assertThat(projectDir.resolve("gradle/get-jdk.sh"))
      .hasContent(
          Resources.toString(
              Resources.getResource("gradle-wrapper/rendered-get-jdk.sh"),
              StandardCharsets.UTF_8));
}
 
Example #19
Source File: ServiceCompareTaskTest.java    From java-client-api with Apache License 2.0 6 votes vote down vote up
@Test
public void testTaskCheckTwoArg() throws IOException {
    initTestEnv();

    StringBuilder buildText = new StringBuilder()
            .append("plugins {\n")
            .append("  id 'com.marklogic.ml-development-tools'\n")
            .append("}\n")
            .append("task serviceCompareTest(type: com.marklogic.client.tools.gradle.ServiceCompareTask) {\n")
            .append("  customSeviceDeclarationFile  = '"+testEnv.customServiceDir.getPath()+"/service.json'\n")
            .append("  baseSeviceDeclarationFile   = '"+testEnv.baseServiceDir.getPath()+"/service.json'\n")
            .append("}\n");
    writeBuildFile(buildText);

    BuildResult result = GradleRunner
            .create()
            .withProjectDir(testDir.getRoot())
            .withPluginClasspath()
            .withArguments("serviceCompareTest")
            .withDebug(true)
            .build();

    assertTrue("two argument task failed", result.getOutput().contains("BUILD SUCCESSFUL"));

    testEnv.buildFile.delete();
}
 
Example #20
Source File: ServiceCompareTaskTest.java    From java-client-api with Apache License 2.0 6 votes vote down vote up
@Test
public void testCommandLineCheckOneArg() throws IOException {
    initTestEnv();

    StringBuilder buildText = new StringBuilder()
            .append("plugins {\n")
            .append("  id 'com.marklogic.ml-development-tools'\n")
            .append("}\n");
    writeBuildFile(buildText);

    BuildResult result = GradleRunner
            .create()
            .withProjectDir(testDir.getRoot())
            .withPluginClasspath()
            .withArguments(
                    "-PcustomSeviceDeclarationFile="+testEnv.customServiceDir.getPath()+"/service.json",
                    "checkCustomService"
            )
            .withDebug(true)
            .build();

    assertTrue("one argument command failed", result.getOutput().contains("BUILD SUCCESSFUL"));

    testEnv.buildFile.delete();
}
 
Example #21
Source File: CurioGenericCiPluginTest.java    From curiostack with MIT License 5 votes vote down vote up
@Test
void ciIsMaster() {
  assertThat(
          GradleRunner.create()
              .withProjectDir(projectDir)
              .withArguments("continuousBuild")
              .withEnvironment(ImmutableMap.of("CI", "true", "CI_MASTER", "true"))
              .withPluginClasspath())
      .builds()
      .tasksDidNotRun(ALL_TASKS);
}
 
Example #22
Source File: CurioGenericCiPluginTest.java    From curiostack with MIT License 5 votes vote down vote up
@Test
void ciIsMaster() {
  assertThat(
          GradleRunner.create()
              .withProjectDir(projectDir)
              .withArguments("continuousBuild")
              .withEnvironment(ImmutableMap.of("CI", "true", "CI_MASTER", "true"))
              .withPluginClasspath())
      .builds()
      .satisfies(onlyDidRun(":staticsite1:deployAlpha"));
}
 
Example #23
Source File: FunctionalTestBase.java    From gradle-download-task with Apache License 2.0 5 votes vote down vote up
/**
 * Create a gradle runner using the given build file
 * @param buildFile the build file
 * @return the gradle runner
 * @throws IOException if the build file could not written to disk
 */
protected GradleRunner createRunnerWithBuildFile(String buildFile) throws IOException {
    FileUtils.writeStringToFile(this.buildFile, buildFile, StandardCharsets.UTF_8);

    writePropertiesFile();
    GradleRunner runner = GradleRunner.create()
        .withPluginClasspath()
        .withProjectDir(testProjectDir.getRoot());
    if (gradleVersion != null) {
        runner = runner.withGradleVersion(gradleVersion);
    }
    return runner;
}
 
Example #24
Source File: UnMockTaskTest.java    From unmock-plugin with Apache License 2.0 5 votes vote down vote up
private GradleRunner newGradleRunner() {
    return GradleRunner.create()
                       //.forwardOutput()
                       .withProjectDir(testProjectDir.getRoot())
                       .withPluginClasspath()
                       .withArguments("unMock");
}
 
Example #25
Source File: CurioGenericCiPluginTest.java    From curiostack with MIT License 5 votes vote down vote up
@Test
void ciIsMaster() {
  assertThat(
          GradleRunner.create()
              .withProjectDir(projectDir)
              .withArguments("continuousBuild")
              .withEnvironment(ImmutableMap.of("CI", "true", "CI_MASTER", "true"))
              .withPluginClasspath())
      .builds()
      .tasksDidNotRun(ALL_TASKS);
}
 
Example #26
Source File: CurioGenericCiPluginTest.java    From curiostack with MIT License 5 votes vote down vote up
@Test
void ciNotMaster() {
  assertThat(
          GradleRunner.create()
              .withProjectDir(projectDir)
              .withArguments("continuousBuild")
              .withEnvironment(ImmutableMap.of("CI", "true"))
              .withPluginClasspath())
      .builds()
      .satisfies(onlyDidRun(":library1:jar", ":server2:build"));
}
 
Example #27
Source File: ReportTaskTest.java    From lightning with MIT License 5 votes vote down vote up
@Test
public void runReport() {
    BuildResult result = GradleRunner.create()
            .withProjectDir(new File("src/integrationTest/resources/build/complete"))
            .withArguments(":report")
            .withPluginClasspath()
            .build();

    assertThat(result.task(":report").getOutcome(), is(SUCCESS));
    assertThat(taskOutputContainsFileContent("/results/expected/report.txt", result), is(true));
}
 
Example #28
Source File: CurioGenericCiPluginTest.java    From curiostack with MIT License 5 votes vote down vote up
@Test
void ciIsMaster() {
  assertThat(
          GradleRunner.create()
              .withProjectDir(projectDir)
              .withArguments("continuousBuild")
              .withEnvironment(ImmutableMap.of("CI", "true", "CI_MASTER", "true"))
              .withPluginClasspath())
      .builds()
      .satisfies(onlyDidRun(":library2:jar", ":library2:build"));
}
 
Example #29
Source File: CurioGenericCiPluginTest.java    From curiostack with MIT License 5 votes vote down vote up
@Test
void ciNotMaster() {
  assertThat(
          GradleRunner.create()
              .withProjectDir(projectDir)
              .withArguments("continuousBuild")
              .withEnvironment(ImmutableMap.of("CI", "true"))
              .withPluginClasspath())
      .builds()
      .tasksDidNotRun(ALL_TASKS);
}
 
Example #30
Source File: CurioGenericCiPluginTest.java    From curiostack with MIT License 5 votes vote down vote up
@Test
void ciIsMaster() {
  assertThat(
          GradleRunner.create()
              .withProjectDir(projectDir)
              .withArguments("continuousBuild")
              .withEnvironment(ImmutableMap.of("CI", "true", "CI_MASTER", "true"))
              .withPluginClasspath())
      .builds()
      .satisfies(onlyDidRun(":server1:build", ":server1:jib", ":server1:deployAlpha"));
}