Class QuarkusDevModeTest

  • 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, org.junit.jupiter.api.extension.TestInstanceFactory

    public class QuarkusDevModeTest
    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, org.junit.jupiter.api.extension.TestInstanceFactory
    A test extension for black-box testing of Quarkus development mode in extensions.

    Intended for use by extension developers testing their extension functionality in dev mode.

    Note that unlike QuarkusUnitTest:

    • Tests run in black-box mode: the classloader of test methods does not give access to the running Quarkus application, so things like CDI will not work. You should define REST endpoints that perform the actions you want to simulate in your tests, and call those REST endpoints in your tests using e.g. RestAssured.
    • Each test method will run in a clean deployment. This is necessary to prevent undefined behaviour by making sure the deployment starts in a clean state for each test.
    • Tests do not run with LaunchMode.TEST but rather with LaunchMode.DEVELOPMENT. This is necessary to ensure dev mode is tested correctly. A side effect of this is that the tests will run on port 8080 by default instead of port 8081.
    • Field Detail

      • OPEN_OPTIONS

        public static final OpenOption[] OPEN_OPTIONS
    • Constructor Detail

      • QuarkusDevModeTest

        public QuarkusDevModeTest()
    • Method Detail

      • getArchiveProducer

        public Supplier<org.jboss.shrinkwrap.api.spec.JavaArchive> getArchiveProducer()
      • setArchiveProducer

        public QuarkusDevModeTest setArchiveProducer​(Supplier<org.jboss.shrinkwrap.api.spec.JavaArchive> archiveProducer)
      • withApplicationRoot

        public QuarkusDevModeTest withApplicationRoot​(Consumer<org.jboss.shrinkwrap.api.spec.JavaArchive> applicationRootConsumer)
        Customize the application root.
        Parameters:
        applicationRootConsumer -
        Returns:
        self
      • withEmptyApplication

        public QuarkusDevModeTest withEmptyApplication()
        Use an empty application for the test
        Returns:
        self
      • setTestArchiveProducer

        public QuarkusDevModeTest setTestArchiveProducer​(Supplier<org.jboss.shrinkwrap.api.spec.JavaArchive> testArchiveProducer)
      • withTestArchive

        public QuarkusDevModeTest withTestArchive​(Consumer<org.jboss.shrinkwrap.api.spec.JavaArchive> testArchiveConsumer)
        Customize the application root.
        Parameters:
        applicationRootConsumer -
        Returns:
        self
      • clearLogRecords

        public void clearLogRecords()
      • createTestInstance

        public Object createTestInstance​(org.junit.jupiter.api.extension.TestInstanceFactoryContext factoryContext,
                                         org.junit.jupiter.api.extension.ExtensionContext extensionContext)
                                  throws org.junit.jupiter.api.extension.TestInstantiationException
        Specified by:
        createTestInstance in interface org.junit.jupiter.api.extension.TestInstanceFactory
        Throws:
        org.junit.jupiter.api.extension.TestInstantiationException
      • beforeAll

        public void beforeAll​(org.junit.jupiter.api.extension.ExtensionContext context)
                       throws Exception
        Specified by:
        beforeAll in interface org.junit.jupiter.api.extension.BeforeAllCallback
        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
      • afterAll

        public void afterAll​(org.junit.jupiter.api.extension.ExtensionContext context)
                      throws Exception
        Specified by:
        afterAll in interface org.junit.jupiter.api.extension.AfterAllCallback
        Throws:
        Exception
      • 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
      • modifySourceFile

        public void modifySourceFile​(String sourceFile,
                                     Function<String,​String> mutator)
        Modifies a source file.
        Parameters:
        sourceFile - The unqualified name of the source file to modify
        mutator - A function that will modify the source code
      • modifyFile

        public void modifyFile​(String file,
                               Function<String,​String> mutator)
        Modifies a file
        Parameters:
        file - file path relative to the project's sources parent dir (`src/main` for Maven)
        mutator - A function that will modify the file
      • modifySourceFile

        public void modifySourceFile​(Class<?> sourceFile,
                                     Function<String,​String> mutator)
        Modifies a source file.
        Parameters:
        sourceFile - The Class corresponding to the source file to modify
        mutator - A function that will modify the source code
      • modifyTestSourceFile

        public void modifyTestSourceFile​(Class<?> sourceFile,
                                         Function<String,​String> mutator)
        Modifies a source file.
        Parameters:
        sourceFile - The Class corresponding to the source file to modify
        mutator - A function that will modify the source code
      • addSourceFile

        public void addSourceFile​(Class<?> sourceFile)
        Adds the source file that corresponds to the given class to the deployment
        Parameters:
        sourceFile -
      • getCommandLineArgs

        public String[] getCommandLineArgs()
      • modifyResourceFile

        public void modifyResourceFile​(String path,
                                       Function<String,​String> mutator)
        Adds or overwrites a resource file with the given data. The path is an absolute path into to the deployment resources directory
      • modifyTestResourceFile

        public void modifyTestResourceFile​(String path,
                                           Function<String,​String> mutator)
        Adds or overwrites a resource file with the given data. The path is an absolute path into to the deployment resources directory
      • addResourceFile

        public void addResourceFile​(String path,
                                    byte[] data)
        Adds or overwrites a resource file with the given data. The path is an absolute path into to the deployment resources directory
      • deleteResourceFile

        public void deleteResourceFile​(String path)
        Deletes a resource file. The path is an absolute path into to the deployment resources directory
      • addResourceFile

        public void addResourceFile​(String path,
                                    String data)
        Adds or overwrites a resource file with the given data encoded into UTF-8. The path is an absolute path into to the deployment resources directory
      • isAllowFailedStart

        public boolean isAllowFailedStart()
      • setAllowFailedStart

        public QuarkusDevModeTest setAllowFailedStart​(boolean allowFailedStart)