Search in sources :

Example 66 with BuildResult

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

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

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

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

Example 70 with BuildResult

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

the class DbImportIT method emptyDbTaskSuccess.

@Test
public void emptyDbTaskSuccess() throws Exception {
    // create empty db to avoid problems on Java 11
    prepareDerbyDatabase("empty_db");
    GradleRunner runner = createRunner("dbimport_empty_db", "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)

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