Class QuarkusCodestartTest

  • All Implemented Interfaces:
    org.junit.jupiter.api.extension.AfterAllCallback, org.junit.jupiter.api.extension.AfterEachCallback, org.junit.jupiter.api.extension.BeforeAllCallback, org.junit.jupiter.api.extension.BeforeEachCallback, org.junit.jupiter.api.extension.Extension

    public class QuarkusCodestartTest
    extends Object
    implements org.junit.jupiter.api.extension.BeforeAllCallback, org.junit.jupiter.api.extension.AfterAllCallback, org.junit.jupiter.api.extension.BeforeEachCallback, org.junit.jupiter.api.extension.AfterEachCallback
    This extension helps test a Quarkus extension codestart. It provides a way to test:
    • the generated project content (with immutable mocked data) using snapshot testing
    • the generated project build/run (with real data) with helpers to run the build

    Before all tests, the extension will generate Quarkus projects in the specified languages with the given codestart, with mocked data and with real data.
    You can find those generated project in `target/quarkus-codestart-test`.
    You can open the `real-data` ones in your IDE or play with them using the terminal.
    Running those tests is the easiest way to iterate on your extension codestart dev
    • Method Detail

      • beforeAll

        public void beforeAll​(org.junit.jupiter.api.extension.ExtensionContext extensionContext)
                       throws Exception
        Specified by:
        beforeAll in interface org.junit.jupiter.api.extension.BeforeAllCallback
        Throws:
        Exception
      • getExtensionsCatalog

        public io.quarkus.registry.catalog.ExtensionCatalog getExtensionsCatalog()
      • buildAllProjects

        public void buildAllProjects()
                              throws IOException
        This will run the build on all generated projects (with real data)
        Throws:
        IOException
      • checkGeneratedSource

        public void checkGeneratedSource​(String className)
                                  throws Throwable
        Check that the given full qualified className is valid in all generated projects (with fake data)

        See checkGeneratedSource(Language language, String className)
        Parameters:
        className - the full qualified className (using `org.acme.ClassName` also works, it will be replaced by the project package name)
        Throws:
        Throwable
      • checkGeneratedTestSource

        public void checkGeneratedTestSource​(String className)
                                      throws Throwable
        Check that the given full qualified test className is valid in all generated projects (with fake data)

        See checkGeneratedSource(Language language, String className)
        Parameters:
        className - the full qualified test class name (using `org.acme.ClassName` also works, it will be replaced by the project package name)
        Throws:
        Throwable
      • checkGeneratedSource

        public org.assertj.core.api.AbstractPathAssert<?> checkGeneratedSource​(QuarkusCodestartCatalog.Language language,
                                                                               String className)
                                                                        throws Throwable
        It will validate (compare and check package name) the class against the snapshots in all the projects for the given language
        Parameters:
        language - the language to check
        className - the full qualified className (using `org.acme.ClassName` also works, it will be replaced by the project package name)
        Returns:
        Throws:
        Throwable
      • checkGeneratedTestSource

        public org.assertj.core.api.AbstractPathAssert<?> checkGeneratedTestSource​(QuarkusCodestartCatalog.Language language,
                                                                                   String className)
                                                                            throws Throwable
        It will validate (compare and check package name) the test class against the snapshots in all the projects for the given language
        Parameters:
        language - the language to check
        className - the full qualified test className (using `org.acme.ClassName` also works, it will be replaced by the project package name)
        Returns:
        Throws:
        Throwable
      • assertThatGeneratedFile

        public org.assertj.core.api.AbstractPathAssert<?> assertThatGeneratedFile​(QuarkusCodestartCatalog.Language language,
                                                                                  String fileRelativePath)
                                                                           throws Throwable
        Get a PathAssert on a generated mocked file for a specific language

        Very usefull to check if a file contains a specific String:
        Example:
        codestartTest.assertThatGeneratedFile(JAVA, "README.md").satisfies(checkContains("./mvnw compile quarkus:dev -Dquarkus.args='Quarky"));
        Parameters:
        language - the language
        fileRelativePath - the relative path for the file in the generated project
        Returns:
        the PathAssert
        Throws:
        Throwable
      • assertThatGeneratedTreeMatchSnapshots

        public org.assertj.core.api.ListAssert<String> assertThatGeneratedTreeMatchSnapshots​(QuarkusCodestartCatalog.Language language)
                                                                                      throws Throwable
        This let you compare the project file structure (tree) for a specific language against its snapshot
        Parameters:
        language - the language
        Returns:
        the ListAssert
        Throws:
        Throwable
      • assertThatGeneratedTreeMatchSnapshots

        public org.assertj.core.api.ListAssert<String> assertThatGeneratedTreeMatchSnapshots​(QuarkusCodestartCatalog.Language language,
                                                                                             String dirRelativePath)
                                                                                      throws Throwable
        see {link #assertThatGeneratedTreeMatchSnapshots(Language language)} but for a specific sub directory
        Parameters:
        language - the language
        dirRelativePath - the sub directory
        Returns:
        the ListAssert
        Throws:
        Throwable
      • afterAll

        public void afterAll​(org.junit.jupiter.api.extension.ExtensionContext extensionContext)
                      throws Exception
        Specified by:
        afterAll in interface org.junit.jupiter.api.extension.AfterAllCallback
        Throws:
        Exception
      • getCodestartsResourceLoaders

        protected List<ResourceLoader> getCodestartsResourceLoaders()
      • afterEach

        public void afterEach​(org.junit.jupiter.api.extension.ExtensionContext extensionContext)
                       throws Exception
        Specified by:
        afterEach in interface org.junit.jupiter.api.extension.AfterEachCallback
        Throws:
        Exception
      • beforeEach

        public void beforeEach​(org.junit.jupiter.api.extension.ExtensionContext extensionContext)
                        throws Exception
        Specified by:
        beforeEach in interface org.junit.jupiter.api.extension.BeforeEachCallback
        Throws:
        Exception