├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ ├── config.yml │ └── feature_request.md ├── PULL_REQUEST_TEMPLATE.md └── workflows │ ├── check.yml │ └── publish.yml ├── .gitignore ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── HEADER ├── LICENSE ├── build.gradle.kts ├── buildSrc ├── build.gradle.kts ├── gradle.properties ├── settings.gradle.kts └── src │ └── main │ └── kotlin │ └── hivemq-testcontainer-module.gradle.kts ├── core ├── build.gradle.kts └── src │ ├── main │ └── java │ │ └── com │ │ └── hivemq │ │ └── testcontainer │ │ └── core │ │ ├── GradleHiveMQExtensionSupplier.java │ │ ├── HiveMQExtension.java │ │ ├── HiveMQTestContainerCore.java │ │ ├── MavenHiveMQExtensionSupplier.java │ │ ├── MultiLogMessageWaitStrategy.java │ │ └── PathUtil.java │ └── test │ └── java │ └── com │ └── hivemq │ └── testcontainer │ ├── core │ ├── HiveMQTestContainerCoreTest.java │ └── PathUtilTest.java │ └── util │ ├── MyExtension.java │ ├── MyExtensionWithSubclasses.java │ ├── PublishModifier.java │ └── TestPublishModifiedUtil.java ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── junit4 ├── build.gradle.kts └── src │ ├── main │ └── java │ │ └── com │ │ └── hivemq │ │ └── testcontainer │ │ └── junit4 │ │ └── HiveMQTestContainerRule.java │ └── test │ ├── java │ └── com │ │ └── hivemq │ │ └── testcontainer │ │ └── junit4 │ │ ├── ContainerWithControlCenterIT.java │ │ ├── ContainerWithCustomConfigIT.java │ │ ├── ContainerWithExtensionFromDirectoryIT.java │ │ ├── ContainerWithExtensionIT.java │ │ ├── ContainerWithExtensionSubclassIT.java │ │ ├── ContainerWithFileInExtensionHomeIT.java │ │ ├── ContainerWithFileInHomeIT.java │ │ ├── ContainerWithGradleExtensionIT.java │ │ ├── ContainerWithLicenseIT.java │ │ ├── ContainerWithMavenExtensionIT.java │ │ ├── ContainerWithoutPlatformExtensionsIT.java │ │ ├── CreateFileInCopiedDirectoryIT.java │ │ ├── CreateFileInExtensionDirectoryIT.java │ │ ├── DisableEnableExtensionFromDirectoryIT.java │ │ ├── DisableEnableExtensionIT.java │ │ └── DisableEnableMavenExtensionIT.java │ └── resources │ ├── additionalFile.txt │ ├── config.xml │ ├── gradle-extension │ ├── build.gradle │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ ├── settings.gradle │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── hivemq │ │ └── MyExtension.java │ ├── logback-test.xml │ ├── maven-extension │ ├── assembly.xml │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── hivemq │ │ │ └── MyExtension.java │ │ └── resources │ │ ├── META-INF │ │ └── services │ │ │ └── com.hivemq.extension.sdk.api.ExtensionMain │ │ └── hivemq-extension.xml │ ├── modifier-extension-wrong-name │ ├── hivemq-extension.xml │ └── modifier-extension-1.0-SNAPSHOT.jar │ ├── modifier-extension │ ├── hivemq-extension.xml │ └── modifier-extension-1.0-SNAPSHOT.jar │ ├── myExtensionLicense.elic │ └── myLicense.lic ├── junit5 ├── build.gradle.kts └── src │ ├── main │ └── java │ │ └── com │ │ └── hivemq │ │ └── testcontainer │ │ └── junit5 │ │ └── HiveMQTestContainerExtension.java │ └── test │ ├── java │ └── com │ │ └── hivemq │ │ └── testcontainer │ │ └── junit5 │ │ ├── ContainerWithControlCenterIT.java │ │ ├── ContainerWithCustomConfigIT.java │ │ ├── ContainerWithExtensionFromDirectoryIT.java │ │ ├── ContainerWithExtensionIT.java │ │ ├── ContainerWithExtensionSubclassIT.java │ │ ├── ContainerWithFileInExtensionHomeIT.java │ │ ├── ContainerWithFileInHomeIT.java │ │ ├── ContainerWithGradleExtensionIT.java │ │ ├── ContainerWithLicenseIT.java │ │ ├── ContainerWithMavenExtensionIT.java │ │ ├── ContainerWithoutPlatformExtensionsIT.java │ │ ├── CreateFileInCopiedDirectoryIT.java │ │ ├── CreateFileInExtensionDirectoryIT.java │ │ ├── DisableEnableExtensionFromDirectoryIT.java │ │ ├── DisableEnableExtensionIT.java │ │ └── DisableEnableMavenExtensionIT.java │ └── resources │ ├── additionalFile.txt │ ├── config.xml │ ├── gradle-extension │ ├── build.gradle │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ ├── settings.gradle │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── hivemq │ │ └── MyExtension.java │ ├── logback-test.xml │ ├── maven-extension │ ├── assembly.xml │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── hivemq │ │ │ └── MyExtension.java │ │ └── resources │ │ ├── META-INF │ │ └── services │ │ │ └── com.hivemq.extension.sdk.api.ExtensionMain │ │ └── hivemq-extension.xml │ ├── modifier-extension-wrong-name │ ├── hivemq-extension.xml │ └── modifier-extension-1.0-SNAPSHOT.jar │ ├── modifier-extension │ ├── hivemq-extension.xml │ └── modifier-extension-1.0-SNAPSHOT.jar │ ├── myExtensionLicense.elic │ └── myLicense.lic ├── readme.md └── settings.gradle.kts /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | ## Expected behavior 11 | 12 | ## Actual behavior 13 | 14 | ## To Reproduce 15 | ### Steps 16 | 17 | ### Reproducer code 18 | 19 | ## Details 20 | - Affected HiveMQ Testcontainer version(s): 21 | - Used JVM version: 22 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: true 2 | contact_links: 3 | - name: HiveMQ Community Forum 4 | url: https://community.hivemq.com/ 5 | about: Please ask and answer questions here. 6 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | ## Problem or use case 11 | 12 | ## Preferred solution or suggestions 13 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | **Motivation** 2 | 3 | Resolves # 4 | 5 | **Changes** 6 | -------------------------------------------------------------------------------- /.github/workflows/check.yml: -------------------------------------------------------------------------------- 1 | name: CI Check 2 | 3 | on: [ push ] 4 | 5 | jobs: 6 | check: 7 | runs-on: ubuntu-latest 8 | steps: 9 | - name: Checkout 10 | uses: actions/checkout@v2 11 | - name: Setup Java 12 | uses: actions/setup-java@v2 13 | with: 14 | distribution: 'adopt' 15 | java-version: '11' 16 | - name: Login to Docker Hub 17 | uses: docker/login-action@v1 18 | with: 19 | username: ${{ secrets.DOCKER_USERNAME }} 20 | password: ${{ secrets.DOCKER_TOKEN }} 21 | - name: Check 22 | run: ./gradlew check 23 | -------------------------------------------------------------------------------- /.github/workflows/publish.yml: -------------------------------------------------------------------------------- 1 | name: Publish to Maven Central 2 | 3 | on: 4 | release: 5 | types: [published] 6 | 7 | jobs: 8 | publish: 9 | environment: mavenCentralPublish 10 | runs-on: ubuntu-latest 11 | steps: 12 | - name: Checkout 13 | uses: actions/checkout@v2 14 | - name: Setup Java 15 | uses: actions/setup-java@v2 16 | with: 17 | distribution: 'adopt' 18 | java-version: '11' 19 | - name: Login to Docker Hub 20 | uses: docker/login-action@v1 21 | with: 22 | username: ${{ secrets.DOCKER_USERNAME }} 23 | password: ${{ secrets.DOCKER_TOKEN }} 24 | - name: Check 25 | run: ./gradlew check 26 | - name: Publish to Maven Central 27 | env: 28 | ORG_GRADLE_PROJECT_signKey: ${{ secrets.SIGN_KEY }} 29 | ORG_GRADLE_PROJECT_signKeyPass: ${{ secrets.SIGN_KEY_PASS }} 30 | ORG_GRADLE_PROJECT_sonatypeUsername: ${{ secrets.SONATYPE_USERNAME }} 31 | ORG_GRADLE_PROJECT_sonatypePassword: ${{ secrets.SONATYPE_PASSWORD }} 32 | run: ./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository 33 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | out/ 3 | build/ 4 | 5 | *.iml 6 | .idea/ 7 | 8 | .DS_Store 9 | .java-version 10 | target/ 11 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # HiveMQ Code of Conduct 2 | 3 | Please refer to our [HiveMQ Code of Conduct](https://github.com/hivemq/hivemq-community/blob/master/code-of-conduct.md). -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | ## Contributing to the HiveMQ Community Projects 4 | 5 | Welcome to the HiveMQ Community! Glad to see your interest in contributing to the HiveMQ Testcontainer. 6 | Please checkout our [Contribution Guide](https://github.com/hivemq/hivemq-community/blob/master/CONTRIBUTING.adoc) to 7 | make sure your contribution will be accepted by the HiveMQ team. 8 | 9 | For information on how the HiveMQ Community is organized and how contributions will be accepted please have a look at 10 | our [HiveMQ Community Repo](https://github.com/hivemq/hivemq-community). 11 | 12 | ## Contributing to HiveMQ Testcontainer 13 | 14 | ### External contributors 15 | 16 | If you would like to contribute code, do the following: 17 | - Fork the repository on GitHub 18 | - Open a pull request targeting the `develop` branch 19 | 20 | ### License 21 | 22 | By contributing your code, you agree to license your contribution under the terms of the 23 | [Apache License, Version 2.0](https://github.com/hivemq/hivemq-mqtt-client/blob/develop/LICENSE). 24 | 25 | All files must contain the license header from the 26 | [HEADER](https://github.com/hivemq/hivemq-testcontainer/blob/master/HEADER) file. 27 | 28 | ### Branching model 29 | 30 | - `master`: release branch, protected 31 | - `develop` is merged into `master` by creating a merge commit if a new version is released 32 | - The release is tagged with the version `vX.Y.Z` 33 | - `develop`: snapshot branch, protected 34 | - Contains features for the next release 35 | - Feature/bugfix/... branches are merged into `develop` by rebasing and merging 36 | - Every feature/bugfix/... will have its own branch 37 | - Branched off from `develop` 38 | - Pull request targeting the `develop` branch 39 | - Mandatory code review of the pull request 40 | 41 | ### Branching guidelines 42 | 43 | - Branch types: feature, bugfix, improvement, cleanup (same as the label of a corresponding GitHub Issue) 44 | - Branch names: 45 | - Starting with type: `feature/`, `bugfix/`, `improvement/`, `cleanup/` 46 | - \+ task: lower case, spaces replaced with `-` 47 | 48 | ### Commit guidelines 49 | 50 | - Commits should be as atomic as possible. 51 | - Commit messages should describe the changes clearly. 52 | - Commit messages should start with a capital letter for consistency. 53 | - Commit messages should avoid exceeding the line length limit. Instead use multiple lines, each describing one specific 54 | change. 55 | 56 | ### Code style guidelines 57 | 58 | The project uses Nullability annotations to avoid NullPointerExceptions: `@NotNull`, `@Nullable`. 59 | Every non-primitive parameter/return type/field should be annotated with one of them. -------------------------------------------------------------------------------- /HEADER: -------------------------------------------------------------------------------- 1 | Copyright 2020 HiveMQ and the HiveMQ Community 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. -------------------------------------------------------------------------------- /build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("io.github.gradle-nexus.publish-plugin") 3 | } 4 | 5 | group = "com.hivemq" 6 | description = "Testcontainers for testing HiveMQ Extensions and Java MQTT Applications." 7 | 8 | nexusPublishing { 9 | repositories { 10 | sonatype() 11 | } 12 | } -------------------------------------------------------------------------------- /buildSrc/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | `kotlin-dsl` 3 | } 4 | 5 | repositories { 6 | gradlePluginPortal() 7 | } 8 | 9 | dependencies { 10 | implementation("gradle.plugin.com.hierynomus.gradle.plugins:license-gradle-plugin:${property("license.version")}") 11 | implementation("gradle.plugin.com.github.sgtsilvio.gradle:gradle-utf8:${property("utf8.version")}") 12 | implementation("gradle.plugin.com.github.sgtsilvio.gradle:gradle-metadata:${property("metadata.version")}") 13 | implementation("gradle.plugin.com.github.sgtsilvio.gradle:gradle-javadoc-links:${property("javadoc-links.version")}") 14 | } -------------------------------------------------------------------------------- /buildSrc/gradle.properties: -------------------------------------------------------------------------------- 1 | license.version=0.16.1 2 | utf8.version=0.1.0 3 | metadata.version=0.3.0 4 | javadoc-links.version=0.4.1 -------------------------------------------------------------------------------- /buildSrc/settings.gradle.kts: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hivemq/hivemq-testcontainer/2604c1809302cd1763e36c3665fdfece661fdd88/buildSrc/settings.gradle.kts -------------------------------------------------------------------------------- /buildSrc/src/main/kotlin/hivemq-testcontainer-module.gradle.kts: -------------------------------------------------------------------------------- 1 | import org.gradle.api.tasks.testing.logging.TestExceptionFormat 2 | import org.gradle.api.tasks.testing.logging.TestLogEvent 3 | 4 | plugins { 5 | id("java-library") 6 | id("maven-publish") 7 | id("signing") 8 | id("com.github.hierynomus.license") 9 | id("com.github.sgtsilvio.gradle.utf8") 10 | id("com.github.sgtsilvio.gradle.metadata") 11 | id("com.github.sgtsilvio.gradle.javadoc-links") 12 | } 13 | 14 | group = "com.hivemq" 15 | 16 | metadata { 17 | organization { 18 | name.set("HiveMQ and the HiveMQ Community") 19 | url.set("https://www.hivemq.com/") 20 | } 21 | license { 22 | apache2() 23 | } 24 | developers { 25 | register("YW") { 26 | fullName.set("Yannick Weber") 27 | email.set("yannick.weber@hivemq.com") 28 | } 29 | } 30 | github { 31 | org.set("hivemq") 32 | repo.set("hivemq-testcontainer") 33 | issues() 34 | } 35 | } 36 | 37 | java { 38 | toolchain { 39 | languageVersion.set(JavaLanguageVersion.of(11)) 40 | } 41 | 42 | withJavadocJar() 43 | withSourcesJar() 44 | } 45 | 46 | tasks.compileJava { 47 | sourceCompatibility = "1.8" 48 | targetCompatibility = "1.8" 49 | } 50 | 51 | tasks.javadoc { 52 | exclude("**/internal/**") 53 | } 54 | 55 | repositories { 56 | mavenCentral() 57 | } 58 | 59 | dependencies { 60 | testImplementation("junit:junit:${property("junit4.version")}") 61 | testImplementation("org.junit.jupiter:junit-jupiter-api:${property("junit5.version")}") 62 | 63 | testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:${property("junit5.version")}") 64 | testRuntimeOnly("org.junit.vintage:junit-vintage-engine:${property("junit5.version")}") 65 | } 66 | 67 | tasks.test { 68 | useJUnitPlatform() 69 | testLogging { 70 | events = setOf(TestLogEvent.PASSED, TestLogEvent.FAILED) 71 | exceptionFormat = TestExceptionFormat.FULL 72 | } 73 | 74 | val outputCache = mutableListOf() 75 | addTestOutputListener { _, outputEvent -> 76 | outputCache.add(outputEvent.message) 77 | while (outputCache.size > 1000) { 78 | outputCache.removeAt(0) 79 | } 80 | } 81 | addTestListener(object : TestListener { 82 | override fun beforeSuite(suite: TestDescriptor) {} 83 | override fun afterSuite(suite: TestDescriptor, result: TestResult) {} 84 | override fun beforeTest(testDescriptor: TestDescriptor) = outputCache.clear() 85 | override fun afterTest(testDescriptor: TestDescriptor, result: TestResult) { 86 | if (result.resultType == TestResult.ResultType.FAILURE && outputCache.size > 0) { 87 | println() 88 | println(" Output of ${testDescriptor.className}.${testDescriptor.name}:") 89 | outputCache.forEach { print(" > $it") } 90 | } 91 | } 92 | }) 93 | } 94 | 95 | publishing { 96 | publications { 97 | register("maven") { 98 | from(components["java"]) 99 | } 100 | } 101 | } 102 | 103 | signing { 104 | val signKey: String? by project 105 | val signKeyPass: String? by project 106 | useInMemoryPgpKeys(signKey, signKeyPass) 107 | sign(publishing.publications["maven"]) 108 | } 109 | 110 | license { 111 | header = rootDir.resolve("HEADER") 112 | mapping("java", "SLASHSTAR_STYLE") 113 | } -------------------------------------------------------------------------------- /core/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("hivemq-testcontainer-module") 3 | } 4 | 5 | description = "Core API for testing HiveMQ Extensions and Java MQTT Applications." 6 | 7 | metadata { 8 | readableName.set("HiveMQ Testcontainer Core") 9 | } 10 | 11 | dependencies { 12 | api("org.testcontainers:testcontainers:${property("testcontainers.version")}") 13 | api("org.jetbrains:annotations:${property("annotations.version")}") 14 | 15 | implementation("org.apache.commons:commons-lang3:${property("commons-lang.version")}") 16 | implementation("com.google.guava:guava:${property("guava.version")}") 17 | implementation("commons-io:commons-io:${property("commons-io.version")}") 18 | implementation("org.javassist:javassist:${property("javassist.version")}") 19 | implementation("org.jboss.shrinkwrap:shrinkwrap-api:${property("shrinkwrap.version")}") 20 | implementation("org.jboss.shrinkwrap:shrinkwrap-impl-base:${property("shrinkwrap.version")}") 21 | implementation("net.lingala.zip4j:zip4j:${property("zip4j.version")}") 22 | 23 | /* This dependency needs to be explicitly added, because shrinkwrap-resolver-api-maven-embedded 24 | and shrinkwrap-resolver-impl-maven-embedded depend on different versions of it. 25 | This would lead to issues when the HiveMQ Testcontainer is included in maven projects. */ 26 | implementation("org.codehaus.plexus:plexus-utils:3.2.1") 27 | implementation("org.jboss.shrinkwrap.resolver:shrinkwrap-resolver-api-maven-embedded:${property("shrinkwrap-resolver.version")}") { 28 | exclude("org.codehouse.plexus", "plexus-utils") 29 | } 30 | runtimeOnly("org.jboss.shrinkwrap.resolver:shrinkwrap-resolver-impl-maven-embedded:${property("shrinkwrap-resolver.version")}") { 31 | exclude("org.codehouse.plexus", "plexus-utils") 32 | } 33 | 34 | compileOnly("com.hivemq:hivemq-extension-sdk:${property("hivemq-extension-sdk.version")}") 35 | 36 | testImplementation("com.hivemq:hivemq-extension-sdk:${property("hivemq-extension-sdk.version")}") 37 | testImplementation("com.hivemq:hivemq-mqtt-client:${property("hivemq-mqtt-client.version")}") 38 | } 39 | -------------------------------------------------------------------------------- /core/src/main/java/com/hivemq/testcontainer/core/HiveMQExtension.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 HiveMQ and the HiveMQ Community 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hivemq.testcontainer.core; 17 | 18 | import com.google.common.collect.ImmutableList; 19 | import com.hivemq.extension.sdk.api.ExtensionMain; 20 | import org.jetbrains.annotations.NotNull; 21 | import org.jetbrains.annotations.Nullable; 22 | 23 | /** 24 | * @author Yannick Weber 25 | */ 26 | public class HiveMQExtension { 27 | 28 | private final @NotNull String id; 29 | private final @NotNull String name; 30 | private final @NotNull String version; 31 | private final int priority; 32 | private final int startPriority; 33 | private final boolean disabledOnStartup; 34 | private final @NotNull Class mainClass; 35 | private final @NotNull ImmutableList> additionalClasses; 36 | 37 | private HiveMQExtension( 38 | final @NotNull String id, 39 | final @NotNull String name, 40 | final @NotNull String version, 41 | final int priority, 42 | final int startPriority, 43 | final boolean disabledOnStartup, 44 | final @NotNull Class mainClass, 45 | final @NotNull ImmutableList> additionalClasses) { 46 | 47 | this.id = id; 48 | this.name = name; 49 | this.version = version; 50 | this.priority = priority; 51 | this.startPriority = startPriority; 52 | this.disabledOnStartup = disabledOnStartup; 53 | this.mainClass = mainClass; 54 | this.additionalClasses = additionalClasses; 55 | } 56 | 57 | public @NotNull String getId() { 58 | return id; 59 | } 60 | 61 | public @NotNull String getName() { 62 | return name; 63 | } 64 | 65 | public @NotNull String getVersion() { 66 | return version; 67 | } 68 | 69 | public int getPriority() { 70 | return priority; 71 | } 72 | 73 | public int getStartPriority() { 74 | return startPriority; 75 | } 76 | 77 | public boolean isDisabledOnStartup() { 78 | return disabledOnStartup; 79 | } 80 | 81 | public @NotNull Class getMainClass() { 82 | return mainClass; 83 | } 84 | 85 | public @NotNull ImmutableList> getAdditionalClasses() { 86 | return additionalClasses; 87 | } 88 | 89 | public static @NotNull Builder builder() { 90 | return new Builder(); 91 | } 92 | 93 | public static final class Builder { 94 | private @Nullable String id; 95 | private @Nullable String name; 96 | private @Nullable String version; 97 | private int priority = 0; 98 | private int startPriority = 0; 99 | private boolean disabledOnStartup = false; 100 | private @Nullable Class mainClass; 101 | private final @NotNull ImmutableList.Builder> additionalClassesBuilder = ImmutableList.builder(); 102 | 103 | public HiveMQExtension build() { 104 | if (id == null || id.isEmpty()) { 105 | throw new IllegalArgumentException("extension id must not be null or empty"); 106 | } 107 | if (name == null || name.isEmpty()) { 108 | throw new IllegalArgumentException("extension name must not be null or empty"); 109 | } 110 | if (version == null || version.isEmpty()) { 111 | throw new IllegalArgumentException("extension version must not be null or empty"); 112 | } 113 | if (mainClass == null) { 114 | throw new IllegalArgumentException("extension main class must not be null"); 115 | } 116 | return new HiveMQExtension( 117 | id, 118 | name, 119 | version, 120 | priority, 121 | startPriority, 122 | disabledOnStartup, 123 | mainClass, 124 | additionalClassesBuilder.build() 125 | ); 126 | } 127 | 128 | public @NotNull Builder id(final @NotNull String id) { 129 | this.id = id; 130 | return this; 131 | } 132 | 133 | public @NotNull Builder name(final @NotNull String name) { 134 | this.name = name; 135 | return this; 136 | } 137 | 138 | public @NotNull Builder version(final @NotNull String version) { 139 | this.version = version; 140 | return this; 141 | } 142 | 143 | public @NotNull Builder priority(final int priority) { 144 | this.priority = priority; 145 | return this; 146 | } 147 | 148 | public @NotNull Builder startPriority(final int startPriority) { 149 | this.startPriority = startPriority; 150 | return this; 151 | } 152 | 153 | public @NotNull Builder disabledOnStartup(final boolean disabledOnStartup) { 154 | this.disabledOnStartup = disabledOnStartup; 155 | return this; 156 | } 157 | 158 | public @NotNull Builder mainClass(final @NotNull Class mainClass) { 159 | this.mainClass = mainClass; 160 | return this; 161 | } 162 | 163 | public @NotNull Builder addAdditionalClass(final @NotNull Class clazz) { 164 | this.additionalClassesBuilder.add(clazz); 165 | return this; 166 | } 167 | } 168 | } 169 | -------------------------------------------------------------------------------- /core/src/main/java/com/hivemq/testcontainer/core/MavenHiveMQExtensionSupplier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 HiveMQ and the HiveMQ Community 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hivemq.testcontainer.core; 17 | 18 | import net.lingala.zip4j.ZipFile; 19 | import org.jboss.shrinkwrap.resolver.api.maven.embedded.BuiltProject; 20 | import org.jboss.shrinkwrap.resolver.api.maven.embedded.EmbeddedMaven; 21 | import org.jboss.shrinkwrap.resolver.api.maven.embedded.pom.equipped.PomEquippedEmbeddedMaven; 22 | import org.jetbrains.annotations.NotNull; 23 | import org.testcontainers.utility.MountableFile; 24 | 25 | import java.io.File; 26 | import java.nio.file.Files; 27 | import java.nio.file.Path; 28 | import java.util.Properties; 29 | import java.util.function.Supplier; 30 | 31 | /** 32 | * This class automates the process of packaging a HiveMQ extension from a maven project. 33 | * 34 | * @author Yannick Weber 35 | * @since 1.1.0 36 | */ 37 | public class MavenHiveMQExtensionSupplier implements Supplier { 38 | 39 | private final @NotNull String pomFile; 40 | private boolean quiet = false; 41 | private final @NotNull Properties properties = new Properties(); 42 | 43 | /** 44 | * This {@link Supplier} can be used if the current maven project is the HiveMQ Extension to supply. 45 | * It uses the pom.xml file of the current maven project. 46 | * 47 | * @return a {@link MavenHiveMQExtensionSupplier} for the current maven project 48 | * @since 1.1.0 49 | */ 50 | public static @NotNull MavenHiveMQExtensionSupplier direct() { 51 | return new MavenHiveMQExtensionSupplier("pom.xml"); 52 | } 53 | 54 | /** 55 | * Creates a Maven HiveMQ extension {@link Supplier}. 56 | * 57 | * @param pomFile the path of the pom.xml of the HiveMQ extension to supply. 58 | * @since 1.1.0 59 | */ 60 | public MavenHiveMQExtensionSupplier(final @NotNull String pomFile) { 61 | this.pomFile = pomFile; 62 | } 63 | 64 | /** 65 | * Packages the HiveMQ extension, copies it to a temporary directory and returns the directory as a {@link File}. 66 | * 67 | * @return the {@link File} of the packaged HiveMQ extension 68 | * @since 1.1.0 69 | */ 70 | @Override 71 | public @NotNull MountableFile get() { 72 | final PomEquippedEmbeddedMaven embeddedMaven = EmbeddedMaven.forProject(pomFile); 73 | embeddedMaven 74 | .setGoals("package") 75 | .setQuiet(quiet) 76 | .setBatchMode(true); 77 | embeddedMaven.setProperties(properties); 78 | final BuiltProject aPackage = embeddedMaven.build(); 79 | final File targetDirectory = aPackage.getTargetDirectory(); 80 | final String version = aPackage.getModel().getVersion(); 81 | final String artifactId = aPackage.getModel().getArtifactId(); 82 | 83 | final ZipFile zipFile = new ZipFile(new File(targetDirectory, artifactId + "-" + version + "-distribution.zip")); 84 | 85 | try { 86 | final Path tempDirectory = Files.createTempDirectory(""); 87 | zipFile.extractAll(tempDirectory.toString()); 88 | return MountableFile.forHostPath(tempDirectory.resolve(artifactId)); 89 | } catch (final Exception e) { 90 | throw new RuntimeException(e); 91 | } 92 | } 93 | 94 | /** 95 | * Suppress stdout of the maven build. 96 | * 97 | * @return self 98 | */ 99 | public @NotNull MavenHiveMQExtensionSupplier quiet() { 100 | this.quiet = true; 101 | return this; 102 | } 103 | 104 | /** 105 | * Add a custom property for the maven packaging. 106 | * 107 | * @param key the name of the property 108 | * @param value the value of the property 109 | * @return self 110 | */ 111 | public @NotNull MavenHiveMQExtensionSupplier addProperty(final @NotNull String key, final @NotNull String value) { 112 | properties.put(key, value); 113 | return this; 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /core/src/main/java/com/hivemq/testcontainer/core/MultiLogMessageWaitStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 HiveMQ and the HiveMQ Community 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hivemq.testcontainer.core; 17 | 18 | import org.jetbrains.annotations.NotNull; 19 | import org.testcontainers.DockerClientFactory; 20 | import org.testcontainers.containers.ContainerLaunchException; 21 | import org.testcontainers.containers.output.OutputFrame; 22 | import org.testcontainers.containers.output.WaitingConsumer; 23 | import org.testcontainers.containers.wait.strategy.AbstractWaitStrategy; 24 | import org.testcontainers.utility.LogUtils; 25 | 26 | import java.util.Map; 27 | import java.util.concurrent.ConcurrentHashMap; 28 | import java.util.concurrent.TimeUnit; 29 | import java.util.concurrent.TimeoutException; 30 | import java.util.function.Predicate; 31 | 32 | /** 33 | * This is a wait strategy to wait for multiple log patterns. 34 | * The wait strategy will continue when every log pattern is matched at least once. 35 | * 36 | * @author Yannick Weber 37 | * @since 1.2.0 38 | */ 39 | class MultiLogMessageWaitStrategy extends AbstractWaitStrategy { 40 | 41 | private final @NotNull ConcurrentHashMap regexes = new ConcurrentHashMap<>(); 42 | 43 | @Override 44 | protected void waitUntilReady() { 45 | WaitingConsumer waitingConsumer = new WaitingConsumer(); 46 | LogUtils.followOutput(DockerClientFactory.instance().client(), waitStrategyTarget.getContainerId(), waitingConsumer); 47 | 48 | Predicate waitPredicate = outputFrame -> { 49 | if (regexes.isEmpty()) { 50 | return true; 51 | } 52 | regexes.entrySet().forEach(stringBooleanEntry -> { 53 | final boolean matched = outputFrame.getUtf8String().matches("(?s)" + stringBooleanEntry.getKey()); 54 | if (matched) { 55 | stringBooleanEntry.setValue(true); 56 | } 57 | }); 58 | return regexes.values().stream().reduce(Boolean::logicalAnd).orElse(true); 59 | }; 60 | 61 | try { 62 | waitingConsumer.waitUntil(waitPredicate, startupTimeout.getSeconds(), TimeUnit.SECONDS, 1); 63 | } catch (TimeoutException e) { 64 | throw new ContainerLaunchException("Timed out waiting for log output matching '" + regexes + "'"); 65 | } 66 | } 67 | 68 | public @NotNull MultiLogMessageWaitStrategy withRegEx(final @NotNull String regEx) { 69 | regexes.put(regEx, false); 70 | return this; 71 | } 72 | 73 | public @NotNull MultiLogMessageWaitStrategy reset() { 74 | for (final Map.Entry stringBooleanEntry : regexes.entrySet()) { 75 | stringBooleanEntry.setValue(false); 76 | } 77 | return this; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /core/src/main/java/com/hivemq/testcontainer/core/PathUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 HiveMQ and the HiveMQ Community 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hivemq.testcontainer.core; 17 | 18 | import org.jetbrains.annotations.NotNull; 19 | 20 | /** 21 | * @author Yannick Weber 22 | */ 23 | class PathUtil { 24 | 25 | static @NotNull String preparePath(@NotNull String pathInExtensionHome) { 26 | if ("/".equals(pathInExtensionHome) || pathInExtensionHome.isEmpty()) { 27 | return "/"; 28 | } 29 | if (!pathInExtensionHome.startsWith("/")) { 30 | pathInExtensionHome = "/" + pathInExtensionHome; 31 | } 32 | if (!pathInExtensionHome.endsWith("/")) { 33 | pathInExtensionHome += "/"; 34 | } 35 | return pathInExtensionHome; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /core/src/test/java/com/hivemq/testcontainer/core/HiveMQTestContainerCoreTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 HiveMQ and the HiveMQ Community 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hivemq.testcontainer.core; 17 | 18 | import org.jetbrains.annotations.NotNull; 19 | import org.junit.jupiter.api.Test; 20 | import org.junit.jupiter.api.io.TempDir; 21 | import org.testcontainers.containers.ContainerLaunchException; 22 | import org.testcontainers.utility.MountableFile; 23 | 24 | import java.io.File; 25 | import java.io.IOException; 26 | 27 | import static org.junit.jupiter.api.Assertions.assertThrows; 28 | import static org.junit.jupiter.api.Assertions.assertTrue; 29 | 30 | /** 31 | * @author Yannick Weber 32 | */ 33 | @SuppressWarnings("rawtypes") 34 | class HiveMQTestContainerCoreTest { 35 | 36 | final @NotNull HiveMQTestContainerCore container = new HiveMQTestContainerCore(); 37 | 38 | @TempDir 39 | File tempDir; 40 | 41 | @Test 42 | void withExtension_fileDoesNotExist_Exception() { 43 | final MountableFile mountableFile = MountableFile.forHostPath("/this/does/not/exist"); 44 | assertThrows(ContainerLaunchException.class, () -> container.withExtension(mountableFile)); 45 | } 46 | 47 | @Test 48 | void withExtension_fileNoDirectory_Exception() throws IOException { 49 | final File extension = new File(tempDir, "extension"); 50 | assertTrue(extension.createNewFile()); 51 | final MountableFile mountableFile = MountableFile.forHostPath(extension.getAbsolutePath()); 52 | assertThrows(ContainerLaunchException.class, () -> container.withExtension(mountableFile)); 53 | } 54 | 55 | @Test 56 | void withLicense_fileDoesNotExist_Exception() { 57 | final MountableFile mountableFile = MountableFile.forHostPath("/this/does/not/exist"); 58 | assertThrows(ContainerLaunchException.class, () -> container.withLicense(mountableFile)); 59 | } 60 | 61 | @Test 62 | void withExtension_fileEndingWrong_Exception() throws IOException { 63 | final File extension = new File(tempDir, "extension.wrong"); 64 | assertTrue(extension.createNewFile()); 65 | final MountableFile mountableFile = MountableFile.forHostPath(extension.getAbsolutePath()); 66 | assertThrows(ContainerLaunchException.class, () -> container.withLicense(mountableFile)); 67 | } 68 | 69 | @Test 70 | void withHiveMQConfig_fileDoesNotExist_Exception() { 71 | final MountableFile mountableFile = MountableFile.forHostPath("/this/does/not/exist"); 72 | assertThrows(ContainerLaunchException.class, () -> container.withHiveMQConfig(mountableFile)); 73 | } 74 | 75 | @Test 76 | void withFileInHomeFolder_withPath_fileDoesNotExist_Exception() { 77 | final MountableFile mountableFile = MountableFile.forHostPath("/this/does/not/exist"); 78 | assertThrows(ContainerLaunchException.class, () -> container.withFileInHomeFolder(mountableFile, "some/path")); 79 | } 80 | 81 | @Test 82 | void withFileInHomeFolder_fileDoesNotExist_Exception() { 83 | final MountableFile mountableFile = MountableFile.forHostPath("/this/does/not/exist"); 84 | assertThrows(ContainerLaunchException.class, () -> container.withFileInHomeFolder(mountableFile)); 85 | } 86 | 87 | @Test 88 | void withFileInExtensionHomeFolder_withPath_fileDoesNotExist_Exception() { 89 | final MountableFile mountableFile = MountableFile.forHostPath("/this/does/not/exist"); 90 | assertThrows(ContainerLaunchException.class, () -> container.withFileInExtensionHomeFolder(mountableFile, "my-extension", "some/path")); 91 | } 92 | 93 | @Test 94 | void withFileInExtensionHomeFolder_fileDoesNotExist_Exception() { 95 | final MountableFile mountableFile = MountableFile.forHostPath("/this/does/not/exist"); 96 | assertThrows(ContainerLaunchException.class, () -> container.withFileInExtensionHomeFolder(mountableFile, "my-extension")); 97 | } 98 | } -------------------------------------------------------------------------------- /core/src/test/java/com/hivemq/testcontainer/core/PathUtilTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 HiveMQ and the HiveMQ Community 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hivemq.testcontainer.core; 17 | 18 | import org.junit.jupiter.api.Test; 19 | 20 | import static org.junit.jupiter.api.Assertions.assertEquals; 21 | 22 | class PathUtilTest { 23 | 24 | @Test 25 | void test_empty_String() { 26 | assertEquals("/", PathUtil.preparePath("")); 27 | } 28 | 29 | @Test 30 | void test_only_delimiter() { 31 | assertEquals("/", PathUtil.preparePath("/")); 32 | } 33 | 34 | @Test 35 | void test_no_delimiter() { 36 | assertEquals("/path/", PathUtil.preparePath("path")); 37 | } 38 | 39 | @Test 40 | void test_delimiter_at_end() { 41 | assertEquals("/path/", PathUtil.preparePath("path/")); 42 | } 43 | 44 | @Test 45 | void test_delimiter_at_beginning() { 46 | assertEquals("/path/", PathUtil.preparePath("/path")); 47 | } 48 | } -------------------------------------------------------------------------------- /core/src/test/java/com/hivemq/testcontainer/util/MyExtension.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 HiveMQ and the HiveMQ Community 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hivemq.testcontainer.util; 17 | 18 | import com.hivemq.extension.sdk.api.ExtensionMain; 19 | import org.jetbrains.annotations.NotNull; 20 | import com.hivemq.extension.sdk.api.interceptor.publish.PublishInboundInterceptor; 21 | import com.hivemq.extension.sdk.api.parameter.ExtensionStartInput; 22 | import com.hivemq.extension.sdk.api.parameter.ExtensionStartOutput; 23 | import com.hivemq.extension.sdk.api.parameter.ExtensionStopInput; 24 | import com.hivemq.extension.sdk.api.parameter.ExtensionStopOutput; 25 | import com.hivemq.extension.sdk.api.services.Services; 26 | import com.hivemq.extension.sdk.api.services.intializer.ClientInitializer; 27 | 28 | import java.nio.ByteBuffer; 29 | import java.nio.charset.StandardCharsets; 30 | 31 | /** 32 | * @author Yannick Weber 33 | */ 34 | @SuppressWarnings("CodeBlock2Expr") 35 | public class MyExtension implements ExtensionMain { 36 | 37 | @Override 38 | public void extensionStart(final @NotNull ExtensionStartInput extensionStartInput, final @NotNull ExtensionStartOutput extensionStartOutput) { 39 | 40 | final PublishInboundInterceptor publishInboundInterceptor = (publishInboundInput, publishInboundOutput) -> { 41 | publishInboundOutput.getPublishPacket().setPayload(ByteBuffer.wrap("modified".getBytes(StandardCharsets.UTF_8))); 42 | }; 43 | 44 | final ClientInitializer clientInitializer = (initializerInput, clientContext) -> { 45 | clientContext.addPublishInboundInterceptor(publishInboundInterceptor); 46 | }; 47 | 48 | Services.initializerRegistry().setClientInitializer(clientInitializer); 49 | } 50 | 51 | @Override 52 | public void extensionStop(final @NotNull ExtensionStopInput extensionStopInput, final @NotNull ExtensionStopOutput extensionStopOutput) { 53 | 54 | } 55 | } -------------------------------------------------------------------------------- /core/src/test/java/com/hivemq/testcontainer/util/MyExtensionWithSubclasses.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 HiveMQ and the HiveMQ Community 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hivemq.testcontainer.util; 17 | 18 | import com.hivemq.extension.sdk.api.ExtensionMain; 19 | import org.jetbrains.annotations.NotNull; 20 | import com.hivemq.extension.sdk.api.parameter.ExtensionStartInput; 21 | import com.hivemq.extension.sdk.api.parameter.ExtensionStartOutput; 22 | import com.hivemq.extension.sdk.api.parameter.ExtensionStopInput; 23 | import com.hivemq.extension.sdk.api.parameter.ExtensionStopOutput; 24 | import com.hivemq.extension.sdk.api.services.Services; 25 | import com.hivemq.extension.sdk.api.services.intializer.ClientInitializer; 26 | 27 | /** 28 | * @author Yannick Weber 29 | */ 30 | public class MyExtensionWithSubclasses implements ExtensionMain { 31 | 32 | @Override 33 | public void extensionStart(final @NotNull ExtensionStartInput extensionStartInput, final @NotNull ExtensionStartOutput extensionStartOutput) { 34 | 35 | final ClientInitializer clientInitializer = (initializerInput, clientContext) -> clientContext.addPublishInboundInterceptor(new PublishModifier()); 36 | 37 | Services.initializerRegistry().setClientInitializer(clientInitializer); 38 | } 39 | 40 | @Override 41 | public void extensionStop(final @NotNull ExtensionStopInput extensionStopInput, final @NotNull ExtensionStopOutput extensionStopOutput) { 42 | 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /core/src/test/java/com/hivemq/testcontainer/util/PublishModifier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 HiveMQ and the HiveMQ Community 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hivemq.testcontainer.util; 17 | 18 | import org.jetbrains.annotations.NotNull; 19 | import com.hivemq.extension.sdk.api.interceptor.publish.PublishInboundInterceptor; 20 | import com.hivemq.extension.sdk.api.interceptor.publish.parameter.PublishInboundInput; 21 | import com.hivemq.extension.sdk.api.interceptor.publish.parameter.PublishInboundOutput; 22 | 23 | import java.nio.ByteBuffer; 24 | import java.nio.charset.StandardCharsets; 25 | 26 | /** 27 | * @author Yannick Weber 28 | */ 29 | public class PublishModifier implements PublishInboundInterceptor { 30 | @Override 31 | public void onInboundPublish(final @NotNull PublishInboundInput publishInboundInput, final @NotNull PublishInboundOutput publishInboundOutput) { 32 | publishInboundOutput.getPublishPacket().setPayload(ByteBuffer.wrap("modified".getBytes(StandardCharsets.UTF_8))); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /core/src/test/java/com/hivemq/testcontainer/util/TestPublishModifiedUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 HiveMQ and the HiveMQ Community 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hivemq.testcontainer.util; 17 | 18 | import com.hivemq.client.mqtt.MqttGlobalPublishFilter; 19 | import com.hivemq.client.mqtt.mqtt5.Mqtt5BlockingClient; 20 | import com.hivemq.client.mqtt.mqtt5.Mqtt5Client; 21 | 22 | import java.nio.charset.StandardCharsets; 23 | import java.util.Arrays; 24 | import java.util.concurrent.CompletableFuture; 25 | import java.util.concurrent.ExecutionException; 26 | 27 | public class TestPublishModifiedUtil { 28 | 29 | public static void testPublishModified(final int mqttPort) throws InterruptedException, ExecutionException { 30 | final CompletableFuture publishReceived = new CompletableFuture<>(); 31 | 32 | final Mqtt5BlockingClient publisher = Mqtt5Client.builder() 33 | .serverPort(mqttPort) 34 | .identifier("publisher") 35 | .buildBlocking(); 36 | publisher.connect(); 37 | 38 | final Mqtt5BlockingClient subscriber = Mqtt5Client.builder() 39 | .serverPort(mqttPort) 40 | .identifier("subscriber") 41 | .buildBlocking(); 42 | subscriber.connect(); 43 | subscriber.subscribeWith().topicFilter("test/topic").send(); 44 | subscriber.toAsync().publishes(MqttGlobalPublishFilter.ALL, publish -> { 45 | if (Arrays.equals(publish.getPayloadAsBytes(), "modified".getBytes(StandardCharsets.UTF_8))) { 46 | publishReceived.complete(null); 47 | } else { 48 | publishReceived.completeExceptionally(new IllegalArgumentException("unexpected payload: " + new String(publish.getPayloadAsBytes()))); 49 | } 50 | }); 51 | 52 | publisher.publishWith().topic("test/topic").payload("unmodified".getBytes(StandardCharsets.UTF_8)).send(); 53 | 54 | try { 55 | publishReceived.get(); 56 | } finally { 57 | publisher.disconnect(); 58 | subscriber.disconnect(); 59 | } 60 | } 61 | 62 | 63 | } 64 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | version=2.0.0 2 | # 3 | # main dependencies 4 | # 5 | testcontainers.version=1.16.0 6 | hivemq-extension-sdk.version=4.4.4 7 | junit4.version=4.13.2 8 | junit5.version=5.7.2 9 | annotations.version=22.0.0 10 | commons-lang.version=3.12.0 11 | commons-io.version=2.11.0 12 | guava.version=30.1.1-jre 13 | javassist.version=3.28.0-GA 14 | shrinkwrap.version=1.2.6 15 | shrinkwrap-resolver.version=3.1.4 16 | zip4j.version=2.9.0 17 | # 18 | # test dependencies 19 | # 20 | hivemq-mqtt-client.version=1.2.2 21 | httpclient.version=4.5.13 22 | logback.version=1.2.3 23 | # 24 | # plugins 25 | # 26 | plugin.nexus-publish.version=1.1.0 -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hivemq/hivemq-testcontainer/2604c1809302cd1763e36c3665fdfece661fdd88/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.1.1-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # 4 | # Copyright 2015 the original author or authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | ## 21 | ## Gradle start up script for UN*X 22 | ## 23 | ############################################################################## 24 | 25 | # Attempt to set APP_HOME 26 | # Resolve links: $0 may be a link 27 | PRG="$0" 28 | # Need this for relative symlinks. 29 | while [ -h "$PRG" ] ; do 30 | ls=`ls -ld "$PRG"` 31 | link=`expr "$ls" : '.*-> \(.*\)$'` 32 | if expr "$link" : '/.*' > /dev/null; then 33 | PRG="$link" 34 | else 35 | PRG=`dirname "$PRG"`"/$link" 36 | fi 37 | done 38 | SAVED="`pwd`" 39 | cd "`dirname \"$PRG\"`/" >/dev/null 40 | APP_HOME="`pwd -P`" 41 | cd "$SAVED" >/dev/null 42 | 43 | APP_NAME="Gradle" 44 | APP_BASE_NAME=`basename "$0"` 45 | 46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 48 | 49 | # Use the maximum available, or set MAX_FD != -1 to use that value. 50 | MAX_FD="maximum" 51 | 52 | warn () { 53 | echo "$*" 54 | } 55 | 56 | die () { 57 | echo 58 | echo "$*" 59 | echo 60 | exit 1 61 | } 62 | 63 | # OS specific support (must be 'true' or 'false'). 64 | cygwin=false 65 | msys=false 66 | darwin=false 67 | nonstop=false 68 | case "`uname`" in 69 | CYGWIN* ) 70 | cygwin=true 71 | ;; 72 | Darwin* ) 73 | darwin=true 74 | ;; 75 | MSYS* | MINGW* ) 76 | msys=true 77 | ;; 78 | NONSTOP* ) 79 | nonstop=true 80 | ;; 81 | esac 82 | 83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 84 | 85 | 86 | # Determine the Java command to use to start the JVM. 87 | if [ -n "$JAVA_HOME" ] ; then 88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 89 | # IBM's JDK on AIX uses strange locations for the executables 90 | JAVACMD="$JAVA_HOME/jre/sh/java" 91 | else 92 | JAVACMD="$JAVA_HOME/bin/java" 93 | fi 94 | if [ ! -x "$JAVACMD" ] ; then 95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 96 | 97 | Please set the JAVA_HOME variable in your environment to match the 98 | location of your Java installation." 99 | fi 100 | else 101 | JAVACMD="java" 102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 103 | 104 | Please set the JAVA_HOME variable in your environment to match the 105 | location of your Java installation." 106 | fi 107 | 108 | # Increase the maximum file descriptors if we can. 109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 110 | MAX_FD_LIMIT=`ulimit -H -n` 111 | if [ $? -eq 0 ] ; then 112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 113 | MAX_FD="$MAX_FD_LIMIT" 114 | fi 115 | ulimit -n $MAX_FD 116 | if [ $? -ne 0 ] ; then 117 | warn "Could not set maximum file descriptor limit: $MAX_FD" 118 | fi 119 | else 120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 121 | fi 122 | fi 123 | 124 | # For Darwin, add options to specify how the application appears in the dock 125 | if $darwin; then 126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 127 | fi 128 | 129 | # For Cygwin or MSYS, switch paths to Windows format before running java 130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then 131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 133 | 134 | JAVACMD=`cygpath --unix "$JAVACMD"` 135 | 136 | # We build the pattern for arguments to be converted via cygpath 137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 138 | SEP="" 139 | for dir in $ROOTDIRSRAW ; do 140 | ROOTDIRS="$ROOTDIRS$SEP$dir" 141 | SEP="|" 142 | done 143 | OURCYGPATTERN="(^($ROOTDIRS))" 144 | # Add a user-defined pattern to the cygpath arguments 145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 147 | fi 148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 149 | i=0 150 | for arg in "$@" ; do 151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 153 | 154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 156 | else 157 | eval `echo args$i`="\"$arg\"" 158 | fi 159 | i=`expr $i + 1` 160 | done 161 | case $i in 162 | 0) set -- ;; 163 | 1) set -- "$args0" ;; 164 | 2) set -- "$args0" "$args1" ;; 165 | 3) set -- "$args0" "$args1" "$args2" ;; 166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;; 167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 172 | esac 173 | fi 174 | 175 | # Escape application args 176 | save () { 177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 178 | echo " " 179 | } 180 | APP_ARGS=`save "$@"` 181 | 182 | # Collect all arguments for the java command, following the shell quoting and substitution rules 183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 184 | 185 | exec "$JAVACMD" "$@" 186 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /junit4/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("hivemq-testcontainer-module") 3 | } 4 | 5 | description = "JUnit 4 API for testing HiveMQ Extensions and Java MQTT Applications." 6 | 7 | metadata { 8 | readableName.set("HiveMQ Testcontainer JUnit4") 9 | } 10 | 11 | dependencies { 12 | api(project(":hivemq-testcontainer-core")) 13 | 14 | compileOnly("junit:junit:${property("junit4.version")}") 15 | compileOnly("com.hivemq:hivemq-extension-sdk:${property("hivemq-extension-sdk.version")}") 16 | 17 | testImplementation(project(":hivemq-testcontainer-core").dependencyProject.sourceSets.test.get().output) 18 | testImplementation("com.hivemq:hivemq-extension-sdk:${property("hivemq-extension-sdk.version")}") 19 | testImplementation("com.hivemq:hivemq-mqtt-client:${property("hivemq-mqtt-client.version")}") 20 | testImplementation("org.apache.httpcomponents:httpclient:${property("httpclient.version")}") 21 | testImplementation("ch.qos.logback:logback-classic:${property("logback.version")}") 22 | } 23 | -------------------------------------------------------------------------------- /junit4/src/main/java/com/hivemq/testcontainer/junit4/HiveMQTestContainerRule.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 HiveMQ and the HiveMQ Community 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hivemq.testcontainer.junit4; 17 | 18 | import com.hivemq.testcontainer.core.HiveMQTestContainerCore; 19 | import org.jetbrains.annotations.NotNull; 20 | import org.testcontainers.utility.DockerImageName; 21 | 22 | /** 23 | * @author Yannick Weber 24 | */ 25 | public class HiveMQTestContainerRule extends HiveMQTestContainerCore { 26 | 27 | public HiveMQTestContainerRule() { 28 | super(); 29 | } 30 | 31 | public HiveMQTestContainerRule(final @NotNull DockerImageName dockerImageName) { 32 | super(dockerImageName); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /junit4/src/test/java/com/hivemq/testcontainer/junit4/ContainerWithControlCenterIT.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 HiveMQ and the HiveMQ Community 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hivemq.testcontainer.junit4; 17 | 18 | import org.apache.http.client.methods.HttpGet; 19 | import org.apache.http.client.methods.HttpUriRequest; 20 | import org.apache.http.impl.client.CloseableHttpClient; 21 | import org.apache.http.impl.client.HttpClientBuilder; 22 | import org.junit.Test; 23 | import org.testcontainers.utility.DockerImageName; 24 | 25 | public class ContainerWithControlCenterIT { 26 | 27 | public static final int CONTROL_CENTER_PORT = 8080; 28 | 29 | @Test(timeout = 200_000) 30 | public void test() throws Exception { 31 | final HiveMQTestContainerRule rule = 32 | new HiveMQTestContainerRule(DockerImageName.parse("hivemq/hivemq4").withTag("latest")) 33 | .withControlCenter(); 34 | 35 | rule.start(); 36 | 37 | final CloseableHttpClient httpClient = HttpClientBuilder.create().build(); 38 | final HttpUriRequest request = new HttpGet("http://localhost:" + rule.getMappedPort(CONTROL_CENTER_PORT)); 39 | httpClient.execute(request); 40 | 41 | rule.stop(); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /junit4/src/test/java/com/hivemq/testcontainer/junit4/ContainerWithCustomConfigIT.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 HiveMQ and the HiveMQ Community 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hivemq.testcontainer.junit4; 17 | 18 | import com.hivemq.client.mqtt.datatypes.MqttQos; 19 | import com.hivemq.client.mqtt.exceptions.MqttSessionExpiredException; 20 | import com.hivemq.client.mqtt.mqtt5.Mqtt5BlockingClient; 21 | import com.hivemq.client.mqtt.mqtt5.Mqtt5Client; 22 | import org.junit.Test; 23 | import org.testcontainers.utility.DockerImageName; 24 | import org.testcontainers.utility.MountableFile; 25 | 26 | import static org.junit.jupiter.api.Assertions.assertThrows; 27 | 28 | /** 29 | * @author Yannick Weber 30 | */ 31 | public class ContainerWithCustomConfigIT { 32 | 33 | @Test(timeout = 200_000) 34 | public void test() throws Exception { 35 | final HiveMQTestContainerRule rule = new HiveMQTestContainerRule(DockerImageName.parse("hivemq/hivemq4").withTag("latest")) 36 | .withHiveMQConfig(MountableFile.forClasspathResource("/config.xml")); 37 | 38 | rule.start(); 39 | 40 | final Mqtt5BlockingClient publisher = Mqtt5Client.builder() 41 | .identifier("publisher") 42 | .serverPort(rule.getMqttPort()) 43 | .buildBlocking(); 44 | 45 | publisher.connect(); 46 | 47 | assertThrows(MqttSessionExpiredException.class, () -> { 48 | // this should fail since only QoS 0 is allowed by the configuration 49 | publisher.publishWith() 50 | .topic("test/topic") 51 | .qos(MqttQos.EXACTLY_ONCE) 52 | .send(); 53 | }); 54 | 55 | rule.stop(); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /junit4/src/test/java/com/hivemq/testcontainer/junit4/ContainerWithExtensionFromDirectoryIT.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 HiveMQ and the HiveMQ Community 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hivemq.testcontainer.junit4; 17 | 18 | import com.hivemq.testcontainer.util.TestPublishModifiedUtil; 19 | import org.junit.Test; 20 | import org.slf4j.event.Level; 21 | import org.testcontainers.utility.MountableFile; 22 | 23 | /** 24 | * @author Yannick Weber 25 | */ 26 | public class ContainerWithExtensionFromDirectoryIT { 27 | 28 | @Test(timeout = 200_000) 29 | public void test() throws Exception { 30 | final HiveMQTestContainerRule rule = 31 | new HiveMQTestContainerRule() 32 | .withExtension(MountableFile.forClasspathResource("/modifier-extension")) 33 | .waitForExtension("Modifier Extension") 34 | .withLogLevel(Level.DEBUG); 35 | 36 | rule.start(); 37 | TestPublishModifiedUtil.testPublishModified(rule.getMqttPort()); 38 | rule.stop(); 39 | } 40 | 41 | @Test(timeout = 200_000) 42 | public void test_wrongDirectoryName() throws Exception { 43 | final HiveMQTestContainerRule rule = 44 | new HiveMQTestContainerRule() 45 | .withExtension(MountableFile.forClasspathResource("/modifier-extension-wrong-name")) 46 | .waitForExtension("Modifier Extension") 47 | .withLogLevel(Level.DEBUG); 48 | 49 | rule.start(); 50 | TestPublishModifiedUtil.testPublishModified(rule.getMqttPort()); 51 | rule.stop(); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /junit4/src/test/java/com/hivemq/testcontainer/junit4/ContainerWithExtensionIT.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 HiveMQ and the HiveMQ Community 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hivemq.testcontainer.junit4; 17 | 18 | import com.hivemq.testcontainer.core.HiveMQExtension; 19 | import com.hivemq.testcontainer.util.MyExtension; 20 | import com.hivemq.testcontainer.util.TestPublishModifiedUtil; 21 | import org.junit.Test; 22 | 23 | /** 24 | * @author Yannick Weber 25 | */ 26 | public class ContainerWithExtensionIT { 27 | 28 | @Test(timeout = 200_000) 29 | public void test() throws Exception { 30 | final HiveMQExtension hiveMQExtension = HiveMQExtension.builder() 31 | .id("extension-1") 32 | .name("my-extension") 33 | .version("1.0") 34 | .mainClass(MyExtension.class).build(); 35 | 36 | final HiveMQTestContainerRule rule = 37 | new HiveMQTestContainerRule() 38 | .waitForExtension(hiveMQExtension) 39 | .withExtension(hiveMQExtension); 40 | 41 | rule.start(); 42 | TestPublishModifiedUtil.testPublishModified(rule.getMqttPort()); 43 | rule.stop(); 44 | 45 | rule.start(); 46 | TestPublishModifiedUtil.testPublishModified(rule.getMqttPort()); 47 | rule.stop(); 48 | 49 | rule.start(); 50 | TestPublishModifiedUtil.testPublishModified(rule.getMqttPort()); 51 | rule.stop(); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /junit4/src/test/java/com/hivemq/testcontainer/junit4/ContainerWithExtensionSubclassIT.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 HiveMQ and the HiveMQ Community 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hivemq.testcontainer.junit4; 17 | 18 | import com.hivemq.testcontainer.core.HiveMQExtension; 19 | import com.hivemq.testcontainer.util.MyExtensionWithSubclasses; 20 | import com.hivemq.testcontainer.util.TestPublishModifiedUtil; 21 | import org.junit.Test; 22 | import org.slf4j.event.Level; 23 | 24 | /** 25 | * @author Yannick Weber 26 | */ 27 | public class ContainerWithExtensionSubclassIT { 28 | 29 | @Test(timeout = 200_000) 30 | public void test() throws Exception { 31 | final HiveMQExtension hiveMQExtension = HiveMQExtension.builder() 32 | .id("extension-1") 33 | .name("my-extension") 34 | .version("1.0") 35 | .priority(100) 36 | .startPriority(1000) 37 | .mainClass(MyExtensionWithSubclasses.class).build(); 38 | 39 | final HiveMQTestContainerRule rule = 40 | new HiveMQTestContainerRule() 41 | .withExtension(hiveMQExtension) 42 | .withLogLevel(Level.DEBUG); 43 | 44 | rule.start(); 45 | TestPublishModifiedUtil.testPublishModified(rule.getMqttPort()); 46 | rule.stop(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /junit4/src/test/java/com/hivemq/testcontainer/junit4/ContainerWithFileInExtensionHomeIT.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 HiveMQ and the HiveMQ Community 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hivemq.testcontainer.junit4; 17 | 18 | import com.hivemq.extension.sdk.api.ExtensionMain; 19 | import com.hivemq.extension.sdk.api.interceptor.publish.PublishInboundInterceptor; 20 | import com.hivemq.extension.sdk.api.parameter.ExtensionStartInput; 21 | import com.hivemq.extension.sdk.api.parameter.ExtensionStartOutput; 22 | import com.hivemq.extension.sdk.api.parameter.ExtensionStopInput; 23 | import com.hivemq.extension.sdk.api.parameter.ExtensionStopOutput; 24 | import com.hivemq.extension.sdk.api.services.Services; 25 | import com.hivemq.extension.sdk.api.services.intializer.ClientInitializer; 26 | import com.hivemq.testcontainer.core.HiveMQExtension; 27 | import com.hivemq.testcontainer.util.TestPublishModifiedUtil; 28 | import org.jetbrains.annotations.NotNull; 29 | import org.junit.Test; 30 | import org.testcontainers.utility.MountableFile; 31 | 32 | import java.io.File; 33 | import java.nio.ByteBuffer; 34 | import java.nio.charset.StandardCharsets; 35 | 36 | /** 37 | * @author Yannick Weber 38 | */ 39 | public class ContainerWithFileInExtensionHomeIT { 40 | 41 | @Test(timeout = 200_000) 42 | public void test() throws Exception { 43 | final HiveMQExtension hiveMQExtension = HiveMQExtension.builder() 44 | .id("extension-1") 45 | .name("my-extension") 46 | .version("1.0") 47 | .mainClass(FileCheckerExtension.class).build(); 48 | 49 | final HiveMQTestContainerRule rule = 50 | new HiveMQTestContainerRule() 51 | .withExtension(hiveMQExtension) 52 | .waitForExtension(hiveMQExtension) 53 | .withFileInExtensionHomeFolder( 54 | MountableFile.forClasspathResource("/additionalFile.txt"), 55 | "extension-1", 56 | "/additionalFiles/"); 57 | 58 | rule.start(); 59 | TestPublishModifiedUtil.testPublishModified(rule.getMqttPort()); 60 | rule.stop(); 61 | } 62 | 63 | public static class FileCheckerExtension implements ExtensionMain { 64 | 65 | @Override 66 | public void extensionStart(@NotNull ExtensionStartInput extensionStartInput, @NotNull ExtensionStartOutput extensionStartOutput) { 67 | 68 | final PublishInboundInterceptor publishInboundInterceptor = (publishInboundInput, publishInboundOutput) -> { 69 | 70 | final File extensionHomeFolder = extensionStartInput.getExtensionInformation().getExtensionHomeFolder(); 71 | 72 | final File additionalFile = new File(extensionHomeFolder, "additionalFiles/additionalFile.txt"); 73 | 74 | if (additionalFile.exists()) { 75 | publishInboundOutput.getPublishPacket().setPayload(ByteBuffer.wrap("modified".getBytes(StandardCharsets.UTF_8))); 76 | } 77 | }; 78 | 79 | final ClientInitializer clientInitializer = (initializerInput, clientContext) -> clientContext.addPublishInboundInterceptor(publishInboundInterceptor); 80 | 81 | Services.initializerRegistry().setClientInitializer(clientInitializer); 82 | } 83 | 84 | @Override 85 | public void extensionStop(@NotNull ExtensionStopInput extensionStopInput, @NotNull ExtensionStopOutput extensionStopOutput) { 86 | 87 | } 88 | } 89 | 90 | } 91 | -------------------------------------------------------------------------------- /junit4/src/test/java/com/hivemq/testcontainer/junit4/ContainerWithFileInHomeIT.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 HiveMQ and the HiveMQ Community 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hivemq.testcontainer.junit4; 17 | 18 | import com.hivemq.extension.sdk.api.ExtensionMain; 19 | import com.hivemq.extension.sdk.api.interceptor.publish.PublishInboundInterceptor; 20 | import com.hivemq.extension.sdk.api.parameter.ExtensionStartInput; 21 | import com.hivemq.extension.sdk.api.parameter.ExtensionStartOutput; 22 | import com.hivemq.extension.sdk.api.parameter.ExtensionStopInput; 23 | import com.hivemq.extension.sdk.api.parameter.ExtensionStopOutput; 24 | import com.hivemq.extension.sdk.api.services.Services; 25 | import com.hivemq.extension.sdk.api.services.intializer.ClientInitializer; 26 | import com.hivemq.testcontainer.core.HiveMQExtension; 27 | import com.hivemq.testcontainer.util.TestPublishModifiedUtil; 28 | import org.jetbrains.annotations.NotNull; 29 | import org.junit.Test; 30 | import org.testcontainers.utility.MountableFile; 31 | 32 | import java.io.File; 33 | import java.nio.ByteBuffer; 34 | import java.nio.charset.StandardCharsets; 35 | 36 | /** 37 | * @author Yannick Weber 38 | */ 39 | public class ContainerWithFileInHomeIT { 40 | 41 | @Test(timeout = 200_000) 42 | public void test() throws Exception { 43 | final HiveMQExtension hiveMQExtension = HiveMQExtension.builder() 44 | .id("extension-1") 45 | .name("my-extension") 46 | .version("1.0") 47 | .mainClass(FileCheckerExtension.class).build(); 48 | 49 | final HiveMQTestContainerRule rule = 50 | new HiveMQTestContainerRule() 51 | .withExtension(hiveMQExtension) 52 | .waitForExtension(hiveMQExtension) 53 | .withFileInHomeFolder(MountableFile.forClasspathResource("/additionalFile.txt"), "/additionalFiles/"); 54 | 55 | rule.start(); 56 | TestPublishModifiedUtil.testPublishModified(rule.getMqttPort()); 57 | rule.stop(); 58 | } 59 | 60 | public static class FileCheckerExtension implements ExtensionMain { 61 | 62 | @Override 63 | public void extensionStart(@NotNull ExtensionStartInput extensionStartInput, @NotNull ExtensionStartOutput extensionStartOutput) { 64 | 65 | final PublishInboundInterceptor publishInboundInterceptor = (publishInboundInput, publishInboundOutput) -> { 66 | 67 | final File homeFolder = extensionStartInput.getServerInformation().getHomeFolder(); 68 | 69 | final File additionalFile = new File(homeFolder, "additionalFiles/additionalFile.txt"); 70 | 71 | if (additionalFile.exists()) { 72 | publishInboundOutput.getPublishPacket().setPayload(ByteBuffer.wrap("modified".getBytes(StandardCharsets.UTF_8))); 73 | } 74 | }; 75 | 76 | final ClientInitializer clientInitializer = (initializerInput, clientContext) -> clientContext.addPublishInboundInterceptor(publishInboundInterceptor); 77 | 78 | Services.initializerRegistry().setClientInitializer(clientInitializer); 79 | } 80 | 81 | @Override 82 | public void extensionStop(@NotNull ExtensionStopInput extensionStopInput, @NotNull ExtensionStopOutput extensionStopOutput) { 83 | 84 | } 85 | } 86 | 87 | } 88 | -------------------------------------------------------------------------------- /junit4/src/test/java/com/hivemq/testcontainer/junit4/ContainerWithGradleExtensionIT.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 HiveMQ and the HiveMQ Community 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hivemq.testcontainer.junit4; 17 | 18 | import com.hivemq.testcontainer.core.GradleHiveMQExtensionSupplier; 19 | import com.hivemq.testcontainer.util.TestPublishModifiedUtil; 20 | import org.junit.Test; 21 | import org.testcontainers.utility.MountableFile; 22 | 23 | import java.io.File; 24 | 25 | /** 26 | * @author Yannick Weber 27 | * @since 1.3.0 28 | */ 29 | public class ContainerWithGradleExtensionIT { 30 | 31 | @Test(timeout = 200_000) 32 | public void test() throws Exception { 33 | final MountableFile gradleExtension = new GradleHiveMQExtensionSupplier( 34 | new File(getClass().getResource("/gradle-extension").toURI())) 35 | .get(); 36 | 37 | final HiveMQTestContainerRule container = new HiveMQTestContainerRule() 38 | .waitForExtension("Gradle Extension") 39 | .withExtension(gradleExtension); 40 | 41 | container.start(); 42 | TestPublishModifiedUtil.testPublishModified(container.getMqttPort()); 43 | container.stop(); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /junit4/src/test/java/com/hivemq/testcontainer/junit4/ContainerWithLicenseIT.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 HiveMQ and the HiveMQ Community 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hivemq.testcontainer.junit4; 17 | 18 | import com.hivemq.extension.sdk.api.ExtensionMain; 19 | import com.hivemq.extension.sdk.api.interceptor.publish.PublishInboundInterceptor; 20 | import com.hivemq.extension.sdk.api.parameter.ExtensionStartInput; 21 | import com.hivemq.extension.sdk.api.parameter.ExtensionStartOutput; 22 | import com.hivemq.extension.sdk.api.parameter.ExtensionStopInput; 23 | import com.hivemq.extension.sdk.api.parameter.ExtensionStopOutput; 24 | import com.hivemq.extension.sdk.api.services.Services; 25 | import com.hivemq.extension.sdk.api.services.intializer.ClientInitializer; 26 | import com.hivemq.testcontainer.core.HiveMQExtension; 27 | import com.hivemq.testcontainer.util.TestPublishModifiedUtil; 28 | import org.jetbrains.annotations.NotNull; 29 | import org.junit.Test; 30 | import org.testcontainers.utility.MountableFile; 31 | 32 | import java.io.File; 33 | import java.nio.ByteBuffer; 34 | import java.nio.charset.StandardCharsets; 35 | 36 | /** 37 | * @author Yannick Weber 38 | */ 39 | public class ContainerWithLicenseIT { 40 | 41 | @Test(timeout = 200_000) 42 | public void test() throws Exception { 43 | final HiveMQExtension hiveMQExtension = HiveMQExtension.builder() 44 | .id("extension-1") 45 | .name("my-extension") 46 | .version("1.0") 47 | .mainClass(LicenceCheckerExtension.class).build(); 48 | 49 | final HiveMQTestContainerRule rule = 50 | new HiveMQTestContainerRule() 51 | .withExtension(hiveMQExtension) 52 | .waitForExtension(hiveMQExtension) 53 | .withLicense(MountableFile.forClasspathResource("/myLicense.lic")) 54 | .withLicense(MountableFile.forClasspathResource("/myExtensionLicense.elic")); 55 | 56 | rule.start(); 57 | TestPublishModifiedUtil.testPublishModified(rule.getMqttPort()); 58 | rule.stop(); 59 | } 60 | 61 | @SuppressWarnings("CodeBlock2Expr") 62 | public static class LicenceCheckerExtension implements ExtensionMain { 63 | 64 | @Override 65 | public void extensionStart(@NotNull ExtensionStartInput extensionStartInput, @NotNull ExtensionStartOutput extensionStartOutput) { 66 | 67 | final PublishInboundInterceptor publishInboundInterceptor = (publishInboundInput, publishInboundOutput) -> { 68 | 69 | final File homeFolder = extensionStartInput.getServerInformation().getHomeFolder(); 70 | final File myLicence = new File(homeFolder, "license/myLicense.lic"); 71 | final File myExtensionLicence = new File(homeFolder, "license/myExtensionLicense.elic"); 72 | 73 | if (myLicence.exists() && myExtensionLicence.exists()) { 74 | publishInboundOutput.getPublishPacket().setPayload(ByteBuffer.wrap("modified".getBytes(StandardCharsets.UTF_8))); 75 | } 76 | }; 77 | 78 | final ClientInitializer clientInitializer = (initializerInput, clientContext) -> { 79 | clientContext.addPublishInboundInterceptor(publishInboundInterceptor); 80 | }; 81 | 82 | Services.initializerRegistry().setClientInitializer(clientInitializer); 83 | } 84 | 85 | @Override 86 | public void extensionStop(@NotNull ExtensionStopInput extensionStopInput, @NotNull ExtensionStopOutput extensionStopOutput) { 87 | 88 | } 89 | } 90 | 91 | } 92 | -------------------------------------------------------------------------------- /junit4/src/test/java/com/hivemq/testcontainer/junit4/ContainerWithMavenExtensionIT.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 HiveMQ and the HiveMQ Community 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hivemq.testcontainer.junit4; 17 | 18 | import com.hivemq.testcontainer.core.MavenHiveMQExtensionSupplier; 19 | import com.hivemq.testcontainer.util.TestPublishModifiedUtil; 20 | import org.junit.Test; 21 | import org.testcontainers.utility.MountableFile; 22 | 23 | /** 24 | * @author Yannick Weber 25 | */ 26 | public class ContainerWithMavenExtensionIT { 27 | 28 | @Test(timeout = 200_000) 29 | public void test() throws Exception { 30 | final MountableFile mavenExtension = new MavenHiveMQExtensionSupplier( 31 | getClass().getResource("/maven-extension/pom.xml").getPath()) 32 | .addProperty("HIVEMQ_GROUP_ID", "com.hivemq") 33 | .addProperty("HIVEMQ_EXTENSION_SDK", "hivemq-extension-sdk") 34 | .addProperty("HIVEMQ_EXTENSION_SDK_VERSION", "4.3.0") 35 | .quiet() 36 | .get(); 37 | 38 | final HiveMQTestContainerRule rule = new HiveMQTestContainerRule() 39 | .waitForExtension("Maven Extension") 40 | .withExtension(mavenExtension); 41 | 42 | rule.start(); 43 | TestPublishModifiedUtil.testPublishModified(rule.getMqttPort()); 44 | rule.stop(); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /junit4/src/test/java/com/hivemq/testcontainer/junit4/ContainerWithoutPlatformExtensionsIT.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 HiveMQ and the HiveMQ Community 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hivemq.testcontainer.junit4; 17 | 18 | import com.hivemq.client.mqtt.MqttClient; 19 | import com.hivemq.client.mqtt.MqttGlobalPublishFilter; 20 | import com.hivemq.client.mqtt.mqtt5.Mqtt5BlockingClient; 21 | import com.hivemq.client.mqtt.mqtt5.message.publish.Mqtt5Publish; 22 | import com.hivemq.extension.sdk.api.ExtensionMain; 23 | import com.hivemq.extension.sdk.api.auth.SimpleAuthenticator; 24 | import com.hivemq.extension.sdk.api.parameter.ExtensionStartInput; 25 | import com.hivemq.extension.sdk.api.parameter.ExtensionStartOutput; 26 | import com.hivemq.extension.sdk.api.parameter.ExtensionStopInput; 27 | import com.hivemq.extension.sdk.api.parameter.ExtensionStopOutput; 28 | import com.hivemq.extension.sdk.api.services.Services; 29 | import com.hivemq.extension.sdk.api.services.builder.Builders; 30 | import com.hivemq.testcontainer.core.HiveMQExtension; 31 | import org.jetbrains.annotations.NotNull; 32 | import org.junit.Test; 33 | import org.testcontainers.utility.DockerImageName; 34 | 35 | import java.io.File; 36 | import java.nio.ByteBuffer; 37 | import java.nio.charset.StandardCharsets; 38 | import java.util.Arrays; 39 | import java.util.stream.Collectors; 40 | 41 | import static org.junit.jupiter.api.Assertions.assertFalse; 42 | import static org.junit.jupiter.api.Assertions.assertTrue; 43 | 44 | /** 45 | * @author Yannick Weber 46 | */ 47 | public class ContainerWithoutPlatformExtensionsIT { 48 | 49 | private final @NotNull HiveMQExtension hiveMQExtension = HiveMQExtension.builder() 50 | .name("MyExtension") 51 | .id("my-extension") 52 | .version("1.0.0") 53 | .mainClass(CheckerExtension.class).build(); 54 | 55 | 56 | @Test(timeout = 200_000) 57 | public void removeAllPlatformExtensions() throws InterruptedException { 58 | 59 | final HiveMQTestContainerRule container = new HiveMQTestContainerRule(DockerImageName.parse("hivemq/hivemq4").withTag("latest")) 60 | .withExtension(hiveMQExtension) 61 | .waitForExtension(hiveMQExtension) 62 | .withoutPrepackagedExtensions(); 63 | 64 | container.start(); 65 | 66 | final Mqtt5BlockingClient client = MqttClient.builder() 67 | .serverPort(container.getMqttPort()) 68 | .useMqttVersion5() 69 | .buildBlocking(); 70 | 71 | client.connect(); 72 | final Mqtt5BlockingClient.Mqtt5Publishes publishes = client.publishes(MqttGlobalPublishFilter.ALL); 73 | client.subscribeWith().topicFilter("extensions").send(); 74 | 75 | final Mqtt5Publish receive = publishes.receive(); 76 | assertTrue(receive.getPayload().isPresent()); 77 | final String extensionInfo = new String(receive.getPayloadAsBytes()); 78 | 79 | assertFalse(extensionInfo.contains("hivemq-allow-all-extension")); 80 | assertFalse(extensionInfo.contains("hivemq-kafka-extension")); 81 | assertFalse(extensionInfo.contains("hivemq-bridge-extension")); 82 | assertFalse(extensionInfo.contains("hivemq-enterprise-security-extension")); 83 | 84 | container.stop(); 85 | } 86 | 87 | @Test(timeout = 200_000) 88 | public void removeKafkaExtension() throws InterruptedException { 89 | 90 | final HiveMQTestContainerRule container = new HiveMQTestContainerRule(DockerImageName.parse("hivemq/hivemq4").withTag("latest")) 91 | .withExtension(hiveMQExtension) 92 | .waitForExtension(hiveMQExtension) 93 | .withoutPrepackagedExtensions("hivemq-kafka-extension"); 94 | 95 | container.start(); 96 | 97 | final Mqtt5BlockingClient client = MqttClient.builder() 98 | .serverPort(container.getMqttPort()) 99 | .useMqttVersion5() 100 | .buildBlocking(); 101 | 102 | client.connect(); 103 | final Mqtt5BlockingClient.Mqtt5Publishes publishes = client.publishes(MqttGlobalPublishFilter.ALL); 104 | client.subscribeWith().topicFilter("extensions").send(); 105 | 106 | final Mqtt5Publish receive = publishes.receive(); 107 | assertTrue(receive.getPayload().isPresent()); 108 | final String extensionInfo = new String(receive.getPayloadAsBytes()); 109 | 110 | assertTrue(extensionInfo.contains("hivemq-allow-all-extension")); 111 | assertFalse(extensionInfo.contains("hivemq-kafka-extension")); 112 | assertTrue(extensionInfo.contains("hivemq-bridge-extension")); 113 | assertTrue(extensionInfo.contains("hivemq-enterprise-security-extension")); 114 | 115 | container.stop(); 116 | } 117 | 118 | public static class CheckerExtension implements ExtensionMain { 119 | 120 | @Override 121 | public void extensionStart( 122 | final @NotNull ExtensionStartInput extensionStartInput, 123 | final @NotNull ExtensionStartOutput extensionStartOutput) { 124 | 125 | final String extensionFolders = Arrays.stream(extensionStartInput.getServerInformation().getExtensionsFolder().listFiles()) 126 | .filter(File::isDirectory) 127 | .map(File::getName) 128 | .collect(Collectors.joining("\n")); 129 | 130 | final byte[] bytes = extensionFolders.getBytes(StandardCharsets.UTF_8); 131 | Services.publishService().publish(Builders.publish() 132 | .topic("extensions") 133 | .retain(true) 134 | .payload(ByteBuffer.wrap(bytes)) 135 | .build()); 136 | 137 | Services.securityRegistry().setAuthenticatorProvider(authenticatorProviderInput -> 138 | (SimpleAuthenticator) (simpleAuthInput, simpleAuthOutput) -> 139 | simpleAuthOutput.authenticateSuccessfully()); 140 | 141 | } 142 | 143 | @Override 144 | public void extensionStop( 145 | final @NotNull ExtensionStopInput extensionStopInput, 146 | final @NotNull ExtensionStopOutput extensionStopOutput) { 147 | 148 | } 149 | } 150 | } 151 | -------------------------------------------------------------------------------- /junit4/src/test/java/com/hivemq/testcontainer/junit4/CreateFileInCopiedDirectoryIT.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 HiveMQ and the HiveMQ Community 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hivemq.testcontainer.junit4; 17 | 18 | import com.hivemq.extension.sdk.api.ExtensionMain; 19 | import com.hivemq.extension.sdk.api.interceptor.publish.PublishInboundInterceptor; 20 | import com.hivemq.extension.sdk.api.parameter.ExtensionStartInput; 21 | import com.hivemq.extension.sdk.api.parameter.ExtensionStartOutput; 22 | import com.hivemq.extension.sdk.api.parameter.ExtensionStopInput; 23 | import com.hivemq.extension.sdk.api.parameter.ExtensionStopOutput; 24 | import com.hivemq.extension.sdk.api.services.Services; 25 | import com.hivemq.extension.sdk.api.services.intializer.ClientInitializer; 26 | import com.hivemq.testcontainer.core.HiveMQExtension; 27 | import com.hivemq.testcontainer.util.TestPublishModifiedUtil; 28 | import org.jetbrains.annotations.NotNull; 29 | import org.junit.Test; 30 | import org.testcontainers.utility.MountableFile; 31 | 32 | import java.io.File; 33 | import java.io.IOException; 34 | import java.nio.ByteBuffer; 35 | import java.nio.charset.StandardCharsets; 36 | import java.nio.file.Files; 37 | 38 | import static org.junit.jupiter.api.Assertions.assertTrue; 39 | 40 | /** 41 | * @author Yannick Weber 42 | */ 43 | public class CreateFileInCopiedDirectoryIT { 44 | 45 | private @NotNull MountableFile createDirectory() throws IOException { 46 | final File directory = new File(Files.createTempDirectory("").toFile(), "directory"); 47 | assertTrue(directory.mkdir()); 48 | final File subdirectory = new File(directory, "sub-directory"); 49 | assertTrue(subdirectory.mkdir()); 50 | return MountableFile.forHostPath(directory.getPath()); 51 | } 52 | 53 | @Test(timeout = 200_000) 54 | public void test() throws Exception { 55 | final HiveMQExtension hiveMQExtension = HiveMQExtension.builder() 56 | .id("extension-1") 57 | .name("my-extension") 58 | .version("1.0") 59 | .mainClass(FileCreatorExtension.class).build(); 60 | 61 | final HiveMQTestContainerRule rule = 62 | new HiveMQTestContainerRule() 63 | .withExtension(hiveMQExtension) 64 | .waitForExtension(hiveMQExtension) 65 | .withFileInHomeFolder(createDirectory()); 66 | 67 | rule.start(); 68 | TestPublishModifiedUtil.testPublishModified(rule.getMqttPort()); 69 | rule.stop(); 70 | } 71 | 72 | public static class FileCreatorExtension implements ExtensionMain { 73 | 74 | @Override 75 | public void extensionStart(@NotNull ExtensionStartInput extensionStartInput, @NotNull ExtensionStartOutput extensionStartOutput) { 76 | 77 | final PublishInboundInterceptor publishInboundInterceptor = (publishInboundInput, publishInboundOutput) -> { 78 | 79 | final File homeFolder = extensionStartInput.getServerInformation().getHomeFolder(); 80 | 81 | final File dir = new File(homeFolder, "directory"); 82 | final File dirFile = new File(dir, "file.txt"); 83 | final File subDir = new File(dir, "sub-directory"); 84 | final File subDirFile = new File(subDir, "file.txt"); 85 | 86 | try { 87 | if (dirFile.createNewFile() && subDirFile.createNewFile()) { 88 | publishInboundOutput.getPublishPacket().setPayload(ByteBuffer.wrap("modified".getBytes(StandardCharsets.UTF_8))); 89 | } 90 | } catch (IOException e) { 91 | e.printStackTrace(); 92 | } 93 | }; 94 | 95 | final ClientInitializer clientInitializer = (initializerInput, clientContext) -> clientContext.addPublishInboundInterceptor(publishInboundInterceptor); 96 | 97 | Services.initializerRegistry().setClientInitializer(clientInitializer); 98 | } 99 | 100 | @Override 101 | public void extensionStop(@NotNull ExtensionStopInput extensionStopInput, @NotNull ExtensionStopOutput extensionStopOutput) { 102 | 103 | } 104 | } 105 | 106 | } 107 | -------------------------------------------------------------------------------- /junit4/src/test/java/com/hivemq/testcontainer/junit4/CreateFileInExtensionDirectoryIT.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 HiveMQ and the HiveMQ Community 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hivemq.testcontainer.junit4; 17 | 18 | import com.hivemq.extension.sdk.api.ExtensionMain; 19 | import com.hivemq.extension.sdk.api.interceptor.publish.PublishInboundInterceptor; 20 | import com.hivemq.extension.sdk.api.parameter.ExtensionStartInput; 21 | import com.hivemq.extension.sdk.api.parameter.ExtensionStartOutput; 22 | import com.hivemq.extension.sdk.api.parameter.ExtensionStopInput; 23 | import com.hivemq.extension.sdk.api.parameter.ExtensionStopOutput; 24 | import com.hivemq.extension.sdk.api.services.Services; 25 | import com.hivemq.extension.sdk.api.services.intializer.ClientInitializer; 26 | import com.hivemq.testcontainer.core.HiveMQExtension; 27 | import com.hivemq.testcontainer.util.TestPublishModifiedUtil; 28 | import org.jetbrains.annotations.NotNull; 29 | import org.junit.Test; 30 | 31 | import java.io.File; 32 | import java.io.IOException; 33 | import java.nio.ByteBuffer; 34 | import java.nio.charset.StandardCharsets; 35 | 36 | /** 37 | * @author Yannick Weber 38 | */ 39 | public class CreateFileInExtensionDirectoryIT { 40 | 41 | @Test(timeout = 200_000) 42 | public void test() throws Exception { 43 | final HiveMQExtension hiveMQExtension = HiveMQExtension.builder() 44 | .id("extension-1") 45 | .name("my-extension") 46 | .version("1.0") 47 | .mainClass(FileCreatorExtension.class).build(); 48 | 49 | final HiveMQTestContainerRule rule = 50 | new HiveMQTestContainerRule() 51 | .waitForExtension(hiveMQExtension) 52 | .withExtension(hiveMQExtension); 53 | rule.start(); 54 | TestPublishModifiedUtil.testPublishModified(rule.getMqttPort()); 55 | rule.stop(); 56 | } 57 | 58 | public static class FileCreatorExtension implements ExtensionMain { 59 | 60 | @Override 61 | public void extensionStart(@NotNull ExtensionStartInput extensionStartInput, @NotNull ExtensionStartOutput extensionStartOutput) { 62 | 63 | final PublishInboundInterceptor publishInboundInterceptor = (publishInboundInput, publishInboundOutput) -> { 64 | 65 | final File extensionHomeFolder = extensionStartInput.getExtensionInformation().getExtensionHomeFolder(); 66 | 67 | final File file = new File(extensionHomeFolder, "myfile.txt"); 68 | try { 69 | if (file.createNewFile()) { 70 | publishInboundOutput.getPublishPacket().setPayload(ByteBuffer.wrap("modified".getBytes(StandardCharsets.UTF_8))); 71 | } 72 | } catch (IOException e) { 73 | e.printStackTrace(); 74 | } 75 | }; 76 | 77 | final ClientInitializer clientInitializer = (initializerInput, clientContext) -> clientContext.addPublishInboundInterceptor(publishInboundInterceptor); 78 | 79 | Services.initializerRegistry().setClientInitializer(clientInitializer); 80 | } 81 | 82 | @Override 83 | public void extensionStop(@NotNull ExtensionStopInput extensionStopInput, @NotNull ExtensionStopOutput extensionStopOutput) { 84 | 85 | } 86 | } 87 | 88 | } 89 | -------------------------------------------------------------------------------- /junit4/src/test/java/com/hivemq/testcontainer/junit4/DisableEnableExtensionFromDirectoryIT.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 HiveMQ and the HiveMQ Community 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hivemq.testcontainer.junit4; 17 | 18 | import com.hivemq.testcontainer.util.TestPublishModifiedUtil; 19 | import org.junit.Test; 20 | import org.slf4j.event.Level; 21 | import org.testcontainers.utility.DockerImageName; 22 | import org.testcontainers.utility.MountableFile; 23 | 24 | import java.util.concurrent.ExecutionException; 25 | 26 | import static org.junit.jupiter.api.Assertions.assertThrows; 27 | 28 | /** 29 | * @author Yannick Weber 30 | */ 31 | public class DisableEnableExtensionFromDirectoryIT { 32 | 33 | @Test(timeout = 200_000) 34 | public void test() throws Exception { 35 | final HiveMQTestContainerRule rule = 36 | new HiveMQTestContainerRule(DockerImageName.parse("hivemq/hivemq4").withTag("latest")) 37 | .withExtension(MountableFile.forClasspathResource("/modifier-extension")) 38 | .waitForExtension("Modifier Extension") 39 | .withLogLevel(Level.DEBUG); 40 | 41 | rule.start(); 42 | 43 | TestPublishModifiedUtil.testPublishModified(rule.getMqttPort()); 44 | rule.disableExtension("Modifier Extension", "modifier-extension"); 45 | assertThrows(ExecutionException.class, () -> TestPublishModifiedUtil.testPublishModified(rule.getMqttPort())); 46 | rule.enableExtension("Modifier Extension", "modifier-extension"); 47 | TestPublishModifiedUtil.testPublishModified(rule.getMqttPort()); 48 | 49 | rule.stop(); 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /junit4/src/test/java/com/hivemq/testcontainer/junit4/DisableEnableExtensionIT.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 HiveMQ and the HiveMQ Community 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hivemq.testcontainer.junit4; 17 | 18 | import com.hivemq.testcontainer.core.HiveMQExtension; 19 | import com.hivemq.testcontainer.util.MyExtension; 20 | import com.hivemq.testcontainer.util.TestPublishModifiedUtil; 21 | import org.jetbrains.annotations.NotNull; 22 | import org.junit.Test; 23 | import org.testcontainers.utility.DockerImageName; 24 | 25 | import java.util.concurrent.ExecutionException; 26 | 27 | import static org.junit.jupiter.api.Assertions.assertThrows; 28 | 29 | /** 30 | * @author Yannick Weber 31 | */ 32 | public class DisableEnableExtensionIT { 33 | 34 | private final @NotNull HiveMQExtension hiveMQExtension = HiveMQExtension.builder() 35 | .id("extension-1") 36 | .name("my-extension") 37 | .version("1.0") 38 | .disabledOnStartup(true) 39 | .mainClass(MyExtension.class).build(); 40 | 41 | @Test(timeout = 200_000) 42 | public void test() throws Exception { 43 | 44 | final HiveMQTestContainerRule rule = 45 | new HiveMQTestContainerRule(DockerImageName.parse("hivemq/hivemq4").withTag("latest")) 46 | .withExtension(hiveMQExtension); 47 | 48 | rule.start(); 49 | 50 | assertThrows(ExecutionException.class, () -> TestPublishModifiedUtil.testPublishModified(rule.getMqttPort())); 51 | rule.enableExtension(hiveMQExtension); 52 | TestPublishModifiedUtil.testPublishModified(rule.getMqttPort()); 53 | rule.disableExtension(hiveMQExtension); 54 | assertThrows(ExecutionException.class, () -> TestPublishModifiedUtil.testPublishModified(rule.getMqttPort())); 55 | rule.enableExtension(hiveMQExtension); 56 | TestPublishModifiedUtil.testPublishModified(rule.getMqttPort()); 57 | 58 | rule.stop(); 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /junit4/src/test/java/com/hivemq/testcontainer/junit4/DisableEnableMavenExtensionIT.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 HiveMQ and the HiveMQ Community 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hivemq.testcontainer.junit4; 17 | 18 | import com.hivemq.testcontainer.core.MavenHiveMQExtensionSupplier; 19 | import com.hivemq.testcontainer.util.TestPublishModifiedUtil; 20 | import org.junit.Test; 21 | import org.testcontainers.utility.DockerImageName; 22 | import org.testcontainers.utility.MountableFile; 23 | 24 | import java.util.concurrent.ExecutionException; 25 | 26 | import static org.junit.jupiter.api.Assertions.assertThrows; 27 | 28 | /** 29 | * @author Yannick Weber 30 | */ 31 | public class DisableEnableMavenExtensionIT { 32 | 33 | @Test(timeout = 200_000) 34 | public void test() throws Exception { 35 | final MountableFile extensionDir = new MavenHiveMQExtensionSupplier( 36 | getClass().getResource("/maven-extension/pom.xml").getPath()) 37 | .addProperty("HIVEMQ_GROUP_ID", "com.hivemq") 38 | .addProperty("HIVEMQ_EXTENSION_SDK", "hivemq-extension-sdk") 39 | .addProperty("HIVEMQ_EXTENSION_SDK_VERSION", "4.3.0") 40 | .quiet() 41 | .get(); 42 | 43 | final HiveMQTestContainerRule rule = 44 | new HiveMQTestContainerRule(DockerImageName.parse("hivemq/hivemq4").withTag("latest")) 45 | .waitForExtension("Maven Extension") 46 | .withExtension(extensionDir); 47 | 48 | rule.start(); 49 | TestPublishModifiedUtil.testPublishModified(rule.getMqttPort()); 50 | rule.disableExtension("Maven Extension", "maven-extension"); 51 | assertThrows(ExecutionException.class, () -> TestPublishModifiedUtil.testPublishModified(rule.getMqttPort())); 52 | rule.enableExtension("Maven Extension", "maven-extension"); 53 | TestPublishModifiedUtil.testPublishModified(rule.getMqttPort()); 54 | rule.stop(); 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /junit4/src/test/resources/additionalFile.txt: -------------------------------------------------------------------------------- 1 | ==== 2 | Copyright 2020 HiveMQ and the HiveMQ Community 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | ==== 16 | 17 | -------------------------------------------------------------------------------- /junit4/src/test/resources/config.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 21 | 22 | 23 | 1883 24 | 0.0.0.0 25 | 26 | 27 | 28 | 29 | 0 30 | 31 | 32 | -------------------------------------------------------------------------------- /junit4/src/test/resources/gradle-extension/build.gradle: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 HiveMQ and the HiveMQ Community 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | plugins { 17 | id 'java' 18 | id 'com.hivemq.extension' 19 | } 20 | 21 | group 'org.example' 22 | version '1.0.0' 23 | 24 | hivemqExtension { 25 | name = 'Gradle Extension' 26 | author = 'Example Org' 27 | priority = 0 28 | startPriority = 1000 29 | mainClass = 'com.hivemq.MyExtension' 30 | sdkVersion = '4.4.1' 31 | } 32 | 33 | -------------------------------------------------------------------------------- /junit4/src/test/resources/gradle-extension/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hivemq/hivemq-testcontainer/2604c1809302cd1763e36c3665fdfece661fdd88/junit4/src/test/resources/gradle-extension/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /junit4/src/test/resources/gradle-extension/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2020 HiveMQ and the HiveMQ Community 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | distributionBase=GRADLE_USER_HOME 18 | distributionPath=wrapper/dists 19 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.1.1-bin.zip 20 | zipStoreBase=GRADLE_USER_HOME 21 | zipStorePath=wrapper/dists 22 | -------------------------------------------------------------------------------- /junit4/src/test/resources/gradle-extension/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # 4 | # Copyright 2015 the original author or authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | ## 21 | ## Gradle start up script for UN*X 22 | ## 23 | ############################################################################## 24 | 25 | # Attempt to set APP_HOME 26 | # Resolve links: $0 may be a link 27 | PRG="$0" 28 | # Need this for relative symlinks. 29 | while [ -h "$PRG" ] ; do 30 | ls=`ls -ld "$PRG"` 31 | link=`expr "$ls" : '.*-> \(.*\)$'` 32 | if expr "$link" : '/.*' > /dev/null; then 33 | PRG="$link" 34 | else 35 | PRG=`dirname "$PRG"`"/$link" 36 | fi 37 | done 38 | SAVED="`pwd`" 39 | cd "`dirname \"$PRG\"`/" >/dev/null 40 | APP_HOME="`pwd -P`" 41 | cd "$SAVED" >/dev/null 42 | 43 | APP_NAME="Gradle" 44 | APP_BASE_NAME=`basename "$0"` 45 | 46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 48 | 49 | # Use the maximum available, or set MAX_FD != -1 to use that value. 50 | MAX_FD="maximum" 51 | 52 | warn () { 53 | echo "$*" 54 | } 55 | 56 | die () { 57 | echo 58 | echo "$*" 59 | echo 60 | exit 1 61 | } 62 | 63 | # OS specific support (must be 'true' or 'false'). 64 | cygwin=false 65 | msys=false 66 | darwin=false 67 | nonstop=false 68 | case "`uname`" in 69 | CYGWIN* ) 70 | cygwin=true 71 | ;; 72 | Darwin* ) 73 | darwin=true 74 | ;; 75 | MSYS* | MINGW* ) 76 | msys=true 77 | ;; 78 | NONSTOP* ) 79 | nonstop=true 80 | ;; 81 | esac 82 | 83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 84 | 85 | 86 | # Determine the Java command to use to start the JVM. 87 | if [ -n "$JAVA_HOME" ] ; then 88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 89 | # IBM's JDK on AIX uses strange locations for the executables 90 | JAVACMD="$JAVA_HOME/jre/sh/java" 91 | else 92 | JAVACMD="$JAVA_HOME/bin/java" 93 | fi 94 | if [ ! -x "$JAVACMD" ] ; then 95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 96 | 97 | Please set the JAVA_HOME variable in your environment to match the 98 | location of your Java installation." 99 | fi 100 | else 101 | JAVACMD="java" 102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 103 | 104 | Please set the JAVA_HOME variable in your environment to match the 105 | location of your Java installation." 106 | fi 107 | 108 | # Increase the maximum file descriptors if we can. 109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 110 | MAX_FD_LIMIT=`ulimit -H -n` 111 | if [ $? -eq 0 ] ; then 112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 113 | MAX_FD="$MAX_FD_LIMIT" 114 | fi 115 | ulimit -n $MAX_FD 116 | if [ $? -ne 0 ] ; then 117 | warn "Could not set maximum file descriptor limit: $MAX_FD" 118 | fi 119 | else 120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 121 | fi 122 | fi 123 | 124 | # For Darwin, add options to specify how the application appears in the dock 125 | if $darwin; then 126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 127 | fi 128 | 129 | # For Cygwin or MSYS, switch paths to Windows format before running java 130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then 131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 133 | 134 | JAVACMD=`cygpath --unix "$JAVACMD"` 135 | 136 | # We build the pattern for arguments to be converted via cygpath 137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 138 | SEP="" 139 | for dir in $ROOTDIRSRAW ; do 140 | ROOTDIRS="$ROOTDIRS$SEP$dir" 141 | SEP="|" 142 | done 143 | OURCYGPATTERN="(^($ROOTDIRS))" 144 | # Add a user-defined pattern to the cygpath arguments 145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 147 | fi 148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 149 | i=0 150 | for arg in "$@" ; do 151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 153 | 154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 156 | else 157 | eval `echo args$i`="\"$arg\"" 158 | fi 159 | i=`expr $i + 1` 160 | done 161 | case $i in 162 | 0) set -- ;; 163 | 1) set -- "$args0" ;; 164 | 2) set -- "$args0" "$args1" ;; 165 | 3) set -- "$args0" "$args1" "$args2" ;; 166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;; 167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 172 | esac 173 | fi 174 | 175 | # Escape application args 176 | save () { 177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 178 | echo " " 179 | } 180 | APP_ARGS=`save "$@"` 181 | 182 | # Collect all arguments for the java command, following the shell quoting and substitution rules 183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 184 | 185 | exec "$JAVACMD" "$@" 186 | -------------------------------------------------------------------------------- /junit4/src/test/resources/gradle-extension/gradlew.bat: -------------------------------------------------------------------------------- 1 | @REM 2 | @REM Copyright 2020 HiveMQ and the HiveMQ Community 3 | @REM 4 | @REM Licensed under the Apache License, Version 2.0 (the "License"); 5 | @REM you may not use this file except in compliance with the License. 6 | @REM You may obtain a copy of the License at 7 | @REM 8 | @REM http://www.apache.org/licenses/LICENSE-2.0 9 | @REM 10 | @REM Unless required by applicable law or agreed to in writing, software 11 | @REM distributed under the License is distributed on an "AS IS" BASIS, 12 | @REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @REM See the License for the specific language governing permissions and 14 | @REM limitations under the License. 15 | @REM 16 | 17 | @rem 18 | @rem Copyright 2015 the original author or authors. 19 | @rem 20 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 21 | @rem you may not use this file except in compliance with the License. 22 | @rem You may obtain a copy of the License at 23 | @rem 24 | @rem https://www.apache.org/licenses/LICENSE-2.0 25 | @rem 26 | @rem Unless required by applicable law or agreed to in writing, software 27 | @rem distributed under the License is distributed on an "AS IS" BASIS, 28 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 29 | @rem See the License for the specific language governing permissions and 30 | @rem limitations under the License. 31 | @rem 32 | 33 | @if "%DEBUG%" == "" @echo off 34 | @rem ########################################################################## 35 | @rem 36 | @rem Gradle startup script for Windows 37 | @rem 38 | @rem ########################################################################## 39 | 40 | @rem Set local scope for the variables with windows NT shell 41 | if "%OS%"=="Windows_NT" setlocal 42 | 43 | set DIRNAME=%~dp0 44 | if "%DIRNAME%" == "" set DIRNAME=. 45 | set APP_BASE_NAME=%~n0 46 | set APP_HOME=%DIRNAME% 47 | 48 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 49 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 50 | 51 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 52 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 53 | 54 | @rem Find java.exe 55 | if defined JAVA_HOME goto findJavaFromJavaHome 56 | 57 | set JAVA_EXE=java.exe 58 | %JAVA_EXE% -version >NUL 2>&1 59 | if "%ERRORLEVEL%" == "0" goto execute 60 | 61 | echo. 62 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 63 | echo. 64 | echo Please set the JAVA_HOME variable in your environment to match the 65 | echo location of your Java installation. 66 | 67 | goto fail 68 | 69 | :findJavaFromJavaHome 70 | set JAVA_HOME=%JAVA_HOME:"=% 71 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 72 | 73 | if exist "%JAVA_EXE%" goto execute 74 | 75 | echo. 76 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 77 | echo. 78 | echo Please set the JAVA_HOME variable in your environment to match the 79 | echo location of your Java installation. 80 | 81 | goto fail 82 | 83 | :execute 84 | @rem Setup the command line 85 | 86 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 87 | 88 | 89 | @rem Execute Gradle 90 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 91 | 92 | :end 93 | @rem End local scope for the variables with windows NT shell 94 | if "%ERRORLEVEL%"=="0" goto mainEnd 95 | 96 | :fail 97 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 98 | rem the _cmd.exe /c_ return code! 99 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 100 | exit /b 1 101 | 102 | :mainEnd 103 | if "%OS%"=="Windows_NT" endlocal 104 | 105 | :omega 106 | -------------------------------------------------------------------------------- /junit4/src/test/resources/gradle-extension/settings.gradle: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 HiveMQ and the HiveMQ Community 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | pluginManagement { 17 | plugins { 18 | id 'com.hivemq.extension' version '2.0.0' 19 | } 20 | } 21 | rootProject.name = 'gradle-extension' -------------------------------------------------------------------------------- /junit4/src/test/resources/gradle-extension/src/main/java/com/hivemq/MyExtension.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 HiveMQ and the HiveMQ Community 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq; 18 | 19 | import com.hivemq.extension.sdk.api.ExtensionMain; 20 | import com.hivemq.extension.sdk.api.annotations.NotNull; 21 | import com.hivemq.extension.sdk.api.events.EventRegistry; 22 | import com.hivemq.extension.sdk.api.interceptor.publish.PublishInboundInterceptor; 23 | import com.hivemq.extension.sdk.api.parameter.*; 24 | import com.hivemq.extension.sdk.api.services.Services; 25 | import com.hivemq.extension.sdk.api.services.intializer.ClientInitializer; 26 | import org.slf4j.Logger; 27 | import org.slf4j.LoggerFactory; 28 | 29 | import java.nio.ByteBuffer; 30 | import java.nio.charset.StandardCharsets; 31 | 32 | /** 33 | * @author Yannick Weber 34 | */ 35 | @SuppressWarnings("CodeBlock2Expr") 36 | public class MyExtension implements ExtensionMain { 37 | 38 | @Override 39 | public void extensionStart(final @NotNull ExtensionStartInput extensionStartInput, final @NotNull ExtensionStartOutput extensionStartOutput) { 40 | 41 | final PublishInboundInterceptor publishInboundInterceptor = (publishInboundInput, publishInboundOutput) -> { 42 | publishInboundOutput.getPublishPacket().setPayload(ByteBuffer.wrap("modified".getBytes(StandardCharsets.UTF_8))); 43 | }; 44 | 45 | final ClientInitializer clientInitializer = (initializerInput, clientContext) -> { 46 | clientContext.addPublishInboundInterceptor(publishInboundInterceptor); 47 | }; 48 | 49 | Services.initializerRegistry().setClientInitializer(clientInitializer); 50 | } 51 | 52 | @Override 53 | public void extensionStop(final @NotNull ExtensionStopInput extensionStopInput, final @NotNull ExtensionStopOutput extensionStopOutput) { 54 | 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /junit4/src/test/resources/logback-test.xml: -------------------------------------------------------------------------------- 1 | 18 | 19 | 20 | 21 | 22 | %-30(%d %level)- %msg%n%ex 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /junit4/src/test/resources/maven-extension/assembly.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 22 | distribution 23 | 24 | zip 25 | 26 | 27 | 28 | src/main/resources/hivemq-extension.xml 29 | /${artifactId}/ 30 | true 31 | 32 | 33 | target/${artifactId}-${version}.jar 34 | ${artifactId}-${version}.jar 35 | /${artifactId}/ 36 | 37 | 38 | false 39 | -------------------------------------------------------------------------------- /junit4/src/test/resources/maven-extension/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 21 | 4.0.0 22 | 23 | com.hivemq 24 | maven-extension 25 | 1.0.0 26 | 27 | 28 | Maven Extension 29 | HiveMQ GmbH 30 | 31 | 32 | 33 | 34 | ${HIVEMQ_GROUP_ID} 35 | ${HIVEMQ_EXTENSION_SDK} 36 | ${HIVEMQ_EXTENSION_SDK_VERSION} 37 | 38 | 39 | 40 | 41 | 42 | 43 | org.apache.maven.plugins 44 | maven-compiler-plugin 45 | 3.8.0 46 | 47 | 11 48 | 11 49 | 50 | 51 | 52 | org.apache.maven.plugins 53 | maven-shade-plugin 54 | 3.1.1 55 | 56 | 57 | package 58 | 59 | shade 60 | 61 | 62 | 63 | 64 | com.hivemq:hivemq-extension-sdk 65 | org.slf4j:* 66 | ch.qos.logback:* 67 | javax.servlet:* 68 | 69 | 70 | 71 | 72 | *:* 73 | 74 | META-INF/*.SF 75 | META-INF/*.DSA 76 | META-INF/*.RSA 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | maven-assembly-plugin 86 | 87 | 88 | assembly 89 | package 90 | 91 | single 92 | 93 | 94 | 95 | assembly.xml 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | -------------------------------------------------------------------------------- /junit4/src/test/resources/maven-extension/src/main/java/com/hivemq/MyExtension.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 HiveMQ and the HiveMQ Community 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq; 18 | 19 | import com.hivemq.extension.sdk.api.ExtensionMain; 20 | import com.hivemq.extension.sdk.api.annotations.NotNull; 21 | import com.hivemq.extension.sdk.api.events.EventRegistry; 22 | import com.hivemq.extension.sdk.api.interceptor.publish.PublishInboundInterceptor; 23 | import com.hivemq.extension.sdk.api.parameter.*; 24 | import com.hivemq.extension.sdk.api.services.Services; 25 | import com.hivemq.extension.sdk.api.services.intializer.ClientInitializer; 26 | import org.slf4j.Logger; 27 | import org.slf4j.LoggerFactory; 28 | 29 | import java.nio.ByteBuffer; 30 | import java.nio.charset.StandardCharsets; 31 | 32 | /** 33 | * @author Yannick Weber 34 | */ 35 | @SuppressWarnings("CodeBlock2Expr") 36 | public class MyExtension implements ExtensionMain { 37 | 38 | @Override 39 | public void extensionStart(final @NotNull ExtensionStartInput extensionStartInput, final @NotNull ExtensionStartOutput extensionStartOutput) { 40 | 41 | final PublishInboundInterceptor publishInboundInterceptor = (publishInboundInput, publishInboundOutput) -> { 42 | publishInboundOutput.getPublishPacket().setPayload(ByteBuffer.wrap("modified".getBytes(StandardCharsets.UTF_8))); 43 | }; 44 | 45 | final ClientInitializer clientInitializer = (initializerInput, clientContext) -> { 46 | clientContext.addPublishInboundInterceptor(publishInboundInterceptor); 47 | }; 48 | 49 | Services.initializerRegistry().setClientInitializer(clientInitializer); 50 | } 51 | 52 | @Override 53 | public void extensionStop(final @NotNull ExtensionStopInput extensionStopInput, final @NotNull ExtensionStopOutput extensionStopOutput) { 54 | 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /junit4/src/test/resources/maven-extension/src/main/resources/META-INF/services/com.hivemq.extension.sdk.api.ExtensionMain: -------------------------------------------------------------------------------- 1 | com.hivemq.MyExtension -------------------------------------------------------------------------------- /junit4/src/test/resources/maven-extension/src/main/resources/hivemq-extension.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | ${artifactId} 21 | ${version} 22 | ${extension.name} 23 | ${extension.author} 24 | 1000 25 | 26 | -------------------------------------------------------------------------------- /junit4/src/test/resources/modifier-extension-wrong-name/hivemq-extension.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | modifier-extension 21 | 1.0-SNAPSHOT 22 | Modifier Extension 23 | HiveMQ GmbH 24 | 1000 25 | 26 | -------------------------------------------------------------------------------- /junit4/src/test/resources/modifier-extension-wrong-name/modifier-extension-1.0-SNAPSHOT.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hivemq/hivemq-testcontainer/2604c1809302cd1763e36c3665fdfece661fdd88/junit4/src/test/resources/modifier-extension-wrong-name/modifier-extension-1.0-SNAPSHOT.jar -------------------------------------------------------------------------------- /junit4/src/test/resources/modifier-extension/hivemq-extension.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | modifier-extension 21 | 1.0-SNAPSHOT 22 | Modifier Extension 23 | HiveMQ GmbH 24 | 1000 25 | 26 | -------------------------------------------------------------------------------- /junit4/src/test/resources/modifier-extension/modifier-extension-1.0-SNAPSHOT.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hivemq/hivemq-testcontainer/2604c1809302cd1763e36c3665fdfece661fdd88/junit4/src/test/resources/modifier-extension/modifier-extension-1.0-SNAPSHOT.jar -------------------------------------------------------------------------------- /junit4/src/test/resources/myExtensionLicense.elic: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hivemq/hivemq-testcontainer/2604c1809302cd1763e36c3665fdfece661fdd88/junit4/src/test/resources/myExtensionLicense.elic -------------------------------------------------------------------------------- /junit4/src/test/resources/myLicense.lic: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hivemq/hivemq-testcontainer/2604c1809302cd1763e36c3665fdfece661fdd88/junit4/src/test/resources/myLicense.lic -------------------------------------------------------------------------------- /junit5/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("hivemq-testcontainer-module") 3 | } 4 | 5 | description = "JUnit 5 API for testing HiveMQ Extensions and Java MQTT Applications." 6 | 7 | metadata { 8 | readableName.set("HiveMQ Testcontainer JUnit5") 9 | } 10 | 11 | dependencies { 12 | api(project(":hivemq-testcontainer-core")) 13 | 14 | compileOnly("org.junit.jupiter:junit-jupiter-api:${property("junit5.version")}") 15 | compileOnly("com.hivemq:hivemq-extension-sdk:${property("hivemq-extension-sdk.version")}") 16 | 17 | testImplementation(project(":hivemq-testcontainer-core").dependencyProject.sourceSets.test.get().output) 18 | testImplementation("com.hivemq:hivemq-extension-sdk:${property("hivemq-extension-sdk.version")}") 19 | testImplementation("com.hivemq:hivemq-mqtt-client:${property("hivemq-mqtt-client.version")}") 20 | testImplementation("org.apache.httpcomponents:httpclient:${property("httpclient.version")}") 21 | testImplementation("ch.qos.logback:logback-classic:${property("logback.version")}") 22 | } 23 | -------------------------------------------------------------------------------- /junit5/src/main/java/com/hivemq/testcontainer/junit5/HiveMQTestContainerExtension.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 HiveMQ and the HiveMQ Community 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hivemq.testcontainer.junit5; 17 | 18 | import com.hivemq.testcontainer.core.HiveMQTestContainerCore; 19 | import org.jetbrains.annotations.NotNull; 20 | import org.jetbrains.annotations.Nullable; 21 | import org.junit.jupiter.api.extension.AfterEachCallback; 22 | import org.junit.jupiter.api.extension.BeforeEachCallback; 23 | import org.junit.jupiter.api.extension.ExtensionContext; 24 | import org.testcontainers.utility.DockerImageName; 25 | 26 | /** 27 | * @author Yannick Weber 28 | */ 29 | public class HiveMQTestContainerExtension extends HiveMQTestContainerCore implements BeforeEachCallback, AfterEachCallback { 30 | 31 | public HiveMQTestContainerExtension() { 32 | super(); 33 | } 34 | 35 | public HiveMQTestContainerExtension(final @NotNull DockerImageName dockerImageName) { 36 | super(dockerImageName); 37 | } 38 | 39 | @Override 40 | public void beforeEach(final @Nullable ExtensionContext context) { 41 | start(); 42 | } 43 | 44 | @Override 45 | public void afterEach(final @Nullable ExtensionContext context) { 46 | stop(); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /junit5/src/test/java/com/hivemq/testcontainer/junit5/ContainerWithControlCenterIT.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 HiveMQ and the HiveMQ Community 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hivemq.testcontainer.junit5; 17 | 18 | import org.apache.http.client.methods.HttpGet; 19 | import org.apache.http.client.methods.HttpUriRequest; 20 | import org.apache.http.impl.client.CloseableHttpClient; 21 | import org.apache.http.impl.client.HttpClientBuilder; 22 | import org.junit.jupiter.api.Test; 23 | import org.junit.jupiter.api.Timeout; 24 | import org.testcontainers.utility.DockerImageName; 25 | 26 | import java.util.concurrent.TimeUnit; 27 | 28 | public class ContainerWithControlCenterIT { 29 | 30 | public static final int CONTROL_CENTER_PORT = 8080; 31 | 32 | @Test 33 | @Timeout(value = 3, unit = TimeUnit.MINUTES) 34 | public void test() throws Exception { 35 | 36 | final HiveMQTestContainerExtension extension = 37 | new HiveMQTestContainerExtension(DockerImageName.parse("hivemq/hivemq4").withTag("latest")) 38 | .withControlCenter(); 39 | 40 | extension.beforeEach(null); 41 | 42 | final CloseableHttpClient httpClient = HttpClientBuilder.create().build(); 43 | final HttpUriRequest request = new HttpGet("http://localhost:" + extension.getMappedPort(CONTROL_CENTER_PORT)); 44 | httpClient.execute(request); 45 | 46 | extension.afterEach(null); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /junit5/src/test/java/com/hivemq/testcontainer/junit5/ContainerWithCustomConfigIT.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 HiveMQ and the HiveMQ Community 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hivemq.testcontainer.junit5; 17 | 18 | import com.hivemq.client.mqtt.datatypes.MqttQos; 19 | import com.hivemq.client.mqtt.exceptions.MqttSessionExpiredException; 20 | import com.hivemq.client.mqtt.mqtt5.Mqtt5BlockingClient; 21 | import com.hivemq.client.mqtt.mqtt5.Mqtt5Client; 22 | import org.junit.jupiter.api.Test; 23 | import org.junit.jupiter.api.Timeout; 24 | import org.testcontainers.utility.DockerImageName; 25 | import org.testcontainers.utility.MountableFile; 26 | 27 | import java.util.concurrent.TimeUnit; 28 | 29 | import static org.junit.jupiter.api.Assertions.assertThrows; 30 | 31 | /** 32 | * @author Yannick Weber 33 | */ 34 | public class ContainerWithCustomConfigIT { 35 | 36 | @Test 37 | @Timeout(value = 3, unit = TimeUnit.MINUTES) 38 | void test() throws Exception { 39 | final HiveMQTestContainerExtension extension = new HiveMQTestContainerExtension(DockerImageName.parse("hivemq/hivemq4").withTag("latest")) 40 | .withHiveMQConfig(MountableFile.forClasspathResource("/config.xml")); 41 | 42 | extension.beforeEach(null); 43 | 44 | final Mqtt5BlockingClient publisher = Mqtt5Client.builder() 45 | .identifier("publisher") 46 | .serverPort(extension.getMqttPort()) 47 | .buildBlocking(); 48 | 49 | publisher.connect(); 50 | 51 | assertThrows(MqttSessionExpiredException.class, () -> { 52 | // this should fail since only QoS 0 is allowed by the configuration 53 | publisher.publishWith() 54 | .topic("test/topic") 55 | .qos(MqttQos.EXACTLY_ONCE) 56 | .send(); 57 | }); 58 | 59 | extension.afterEach(null); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /junit5/src/test/java/com/hivemq/testcontainer/junit5/ContainerWithExtensionFromDirectoryIT.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 HiveMQ and the HiveMQ Community 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hivemq.testcontainer.junit5; 17 | 18 | import com.hivemq.testcontainer.util.TestPublishModifiedUtil; 19 | import org.junit.jupiter.api.Test; 20 | import org.junit.jupiter.api.Timeout; 21 | import org.slf4j.event.Level; 22 | import org.testcontainers.utility.MountableFile; 23 | 24 | import java.util.concurrent.TimeUnit; 25 | 26 | /** 27 | * @author Yannick Weber 28 | */ 29 | public class ContainerWithExtensionFromDirectoryIT { 30 | 31 | @Test 32 | @Timeout(value = 3, unit = TimeUnit.MINUTES) 33 | void test() throws Exception { 34 | final HiveMQTestContainerExtension extension = 35 | new HiveMQTestContainerExtension() 36 | .withExtension(MountableFile.forClasspathResource("/modifier-extension")) 37 | .waitForExtension("Modifier Extension") 38 | .withLogLevel(Level.DEBUG); 39 | 40 | extension.beforeEach(null); 41 | TestPublishModifiedUtil.testPublishModified(extension.getMqttPort()); 42 | extension.afterEach(null); 43 | } 44 | 45 | @Test 46 | @Timeout(value = 3, unit = TimeUnit.MINUTES) 47 | void test_wrongDirectoryName() throws Exception { 48 | final HiveMQTestContainerExtension extension = 49 | new HiveMQTestContainerExtension() 50 | .withExtension(MountableFile.forClasspathResource("/modifier-extension-wrong-name")) 51 | .waitForExtension("Modifier Extension") 52 | .withLogLevel(Level.DEBUG); 53 | 54 | extension.beforeEach(null); 55 | TestPublishModifiedUtil.testPublishModified(extension.getMqttPort()); 56 | extension.afterEach(null); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /junit5/src/test/java/com/hivemq/testcontainer/junit5/ContainerWithExtensionIT.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 HiveMQ and the HiveMQ Community 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hivemq.testcontainer.junit5; 17 | 18 | import com.hivemq.testcontainer.core.HiveMQExtension; 19 | import com.hivemq.testcontainer.util.MyExtension; 20 | import com.hivemq.testcontainer.util.TestPublishModifiedUtil; 21 | import org.junit.jupiter.api.Test; 22 | import org.junit.jupiter.api.Timeout; 23 | 24 | import java.util.concurrent.TimeUnit; 25 | 26 | /** 27 | * @author Yannick Weber 28 | */ 29 | public class ContainerWithExtensionIT { 30 | 31 | @Test 32 | @Timeout(value = 3, unit = TimeUnit.MINUTES) 33 | void test() throws Exception { 34 | final HiveMQExtension hiveMQExtension = HiveMQExtension.builder() 35 | .id("extension-1") 36 | .name("my-extension") 37 | .version("1.0") 38 | .mainClass(MyExtension.class).build(); 39 | 40 | final HiveMQTestContainerExtension extension = 41 | new HiveMQTestContainerExtension() 42 | .waitForExtension(hiveMQExtension) 43 | .withExtension(hiveMQExtension); 44 | 45 | extension.beforeEach(null); 46 | TestPublishModifiedUtil.testPublishModified(extension.getMqttPort()); 47 | extension.afterEach(null); 48 | 49 | extension.beforeEach(null); 50 | TestPublishModifiedUtil.testPublishModified(extension.getMqttPort()); 51 | extension.afterEach(null); 52 | 53 | extension.beforeEach(null); 54 | TestPublishModifiedUtil.testPublishModified(extension.getMqttPort()); 55 | extension.afterEach(null); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /junit5/src/test/java/com/hivemq/testcontainer/junit5/ContainerWithExtensionSubclassIT.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 HiveMQ and the HiveMQ Community 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hivemq.testcontainer.junit5; 17 | 18 | import com.hivemq.testcontainer.core.HiveMQExtension; 19 | import com.hivemq.testcontainer.util.MyExtensionWithSubclasses; 20 | import com.hivemq.testcontainer.util.TestPublishModifiedUtil; 21 | import org.junit.jupiter.api.Test; 22 | import org.junit.jupiter.api.Timeout; 23 | import org.slf4j.event.Level; 24 | 25 | import java.util.concurrent.TimeUnit; 26 | 27 | /** 28 | * @author Yannick Weber 29 | */ 30 | public class ContainerWithExtensionSubclassIT { 31 | 32 | @Test 33 | @Timeout(value = 3, unit = TimeUnit.MINUTES) 34 | void test() throws Exception { 35 | final HiveMQExtension hiveMQExtension = HiveMQExtension.builder() 36 | .id("extension-1") 37 | .name("my-extension") 38 | .version("1.0") 39 | .mainClass(MyExtensionWithSubclasses.class).build(); 40 | 41 | final HiveMQTestContainerExtension extension = 42 | new HiveMQTestContainerExtension() 43 | .waitForExtension(hiveMQExtension) 44 | .withExtension(hiveMQExtension) 45 | .withLogLevel(Level.DEBUG); 46 | 47 | extension.beforeEach(null); 48 | TestPublishModifiedUtil.testPublishModified(extension.getMqttPort()); 49 | extension.afterEach(null); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /junit5/src/test/java/com/hivemq/testcontainer/junit5/ContainerWithFileInExtensionHomeIT.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 HiveMQ and the HiveMQ Community 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hivemq.testcontainer.junit5; 17 | 18 | import com.hivemq.extension.sdk.api.ExtensionMain; 19 | import com.hivemq.extension.sdk.api.interceptor.publish.PublishInboundInterceptor; 20 | import com.hivemq.extension.sdk.api.parameter.ExtensionStartInput; 21 | import com.hivemq.extension.sdk.api.parameter.ExtensionStartOutput; 22 | import com.hivemq.extension.sdk.api.parameter.ExtensionStopInput; 23 | import com.hivemq.extension.sdk.api.parameter.ExtensionStopOutput; 24 | import com.hivemq.extension.sdk.api.services.Services; 25 | import com.hivemq.extension.sdk.api.services.intializer.ClientInitializer; 26 | import com.hivemq.testcontainer.core.HiveMQExtension; 27 | import com.hivemq.testcontainer.util.TestPublishModifiedUtil; 28 | import org.jetbrains.annotations.NotNull; 29 | import org.junit.jupiter.api.Test; 30 | import org.junit.jupiter.api.Timeout; 31 | import org.testcontainers.utility.MountableFile; 32 | 33 | import java.io.File; 34 | import java.nio.ByteBuffer; 35 | import java.nio.charset.StandardCharsets; 36 | import java.util.concurrent.TimeUnit; 37 | 38 | /** 39 | * @author Yannick Weber 40 | */ 41 | public class ContainerWithFileInExtensionHomeIT { 42 | 43 | 44 | @Test 45 | @Timeout(value = 3, unit = TimeUnit.MINUTES) 46 | void test() throws Exception { 47 | final HiveMQExtension hiveMQExtension = HiveMQExtension.builder() 48 | .id("extension-1") 49 | .name("my-extension") 50 | .version("1.0") 51 | .mainClass(FileCheckerExtension.class).build(); 52 | 53 | final HiveMQTestContainerExtension extension = 54 | new HiveMQTestContainerExtension() 55 | .withExtension(hiveMQExtension) 56 | .waitForExtension(hiveMQExtension) 57 | .withFileInExtensionHomeFolder( 58 | MountableFile.forClasspathResource("/additionalFile.txt"), 59 | "extension-1", 60 | "/additionalFiles/"); 61 | 62 | extension.beforeEach(null); 63 | TestPublishModifiedUtil.testPublishModified(extension.getMqttPort()); 64 | extension.afterEach(null); 65 | } 66 | 67 | public static class FileCheckerExtension implements ExtensionMain { 68 | 69 | @Override 70 | public void extensionStart(@NotNull ExtensionStartInput extensionStartInput, @NotNull ExtensionStartOutput extensionStartOutput) { 71 | 72 | final PublishInboundInterceptor publishInboundInterceptor = (publishInboundInput, publishInboundOutput) -> { 73 | 74 | final File extensionHomeFolder = extensionStartInput.getExtensionInformation().getExtensionHomeFolder(); 75 | 76 | final File additionalFile = new File(extensionHomeFolder, "additionalFiles/additionalFile.txt"); 77 | 78 | if (additionalFile.exists()) { 79 | publishInboundOutput.getPublishPacket().setPayload(ByteBuffer.wrap("modified".getBytes(StandardCharsets.UTF_8))); 80 | } 81 | }; 82 | 83 | final ClientInitializer clientInitializer = (initializerInput, clientContext) -> clientContext.addPublishInboundInterceptor(publishInboundInterceptor); 84 | 85 | Services.initializerRegistry().setClientInitializer(clientInitializer); 86 | } 87 | 88 | @Override 89 | public void extensionStop(@NotNull ExtensionStopInput extensionStopInput, @NotNull ExtensionStopOutput extensionStopOutput) { 90 | 91 | } 92 | } 93 | 94 | } 95 | -------------------------------------------------------------------------------- /junit5/src/test/java/com/hivemq/testcontainer/junit5/ContainerWithFileInHomeIT.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 HiveMQ and the HiveMQ Community 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hivemq.testcontainer.junit5; 17 | 18 | import com.hivemq.extension.sdk.api.ExtensionMain; 19 | import com.hivemq.extension.sdk.api.interceptor.publish.PublishInboundInterceptor; 20 | import com.hivemq.extension.sdk.api.parameter.ExtensionStartInput; 21 | import com.hivemq.extension.sdk.api.parameter.ExtensionStartOutput; 22 | import com.hivemq.extension.sdk.api.parameter.ExtensionStopInput; 23 | import com.hivemq.extension.sdk.api.parameter.ExtensionStopOutput; 24 | import com.hivemq.extension.sdk.api.services.Services; 25 | import com.hivemq.extension.sdk.api.services.intializer.ClientInitializer; 26 | import com.hivemq.testcontainer.core.HiveMQExtension; 27 | import com.hivemq.testcontainer.util.TestPublishModifiedUtil; 28 | import org.jetbrains.annotations.NotNull; 29 | import org.junit.jupiter.api.Test; 30 | import org.junit.jupiter.api.Timeout; 31 | import org.testcontainers.utility.MountableFile; 32 | 33 | import java.io.File; 34 | import java.nio.ByteBuffer; 35 | import java.nio.charset.StandardCharsets; 36 | import java.util.concurrent.TimeUnit; 37 | 38 | /** 39 | * @author Yannick Weber 40 | */ 41 | public class ContainerWithFileInHomeIT { 42 | 43 | @Test 44 | @Timeout(value = 3, unit = TimeUnit.MINUTES) 45 | void test() throws Exception { 46 | final HiveMQExtension hiveMQExtension = HiveMQExtension.builder() 47 | .id("extension-1") 48 | .name("my-extension") 49 | .version("1.0") 50 | .mainClass(FileCheckerExtension.class).build(); 51 | 52 | final HiveMQTestContainerExtension extension = 53 | new HiveMQTestContainerExtension() 54 | .withExtension(hiveMQExtension) 55 | .waitForExtension(hiveMQExtension) 56 | .withFileInHomeFolder(MountableFile.forClasspathResource("/additionalFile.txt"), 57 | "/additionalFiles/"); 58 | 59 | extension.beforeEach(null); 60 | TestPublishModifiedUtil.testPublishModified(extension.getMqttPort()); 61 | extension.afterEach(null); 62 | } 63 | 64 | public static class FileCheckerExtension implements ExtensionMain { 65 | 66 | @Override 67 | public void extensionStart(@NotNull ExtensionStartInput extensionStartInput, @NotNull ExtensionStartOutput extensionStartOutput) { 68 | 69 | final PublishInboundInterceptor publishInboundInterceptor = (publishInboundInput, publishInboundOutput) -> { 70 | 71 | final File homeFolder = extensionStartInput.getServerInformation().getHomeFolder(); 72 | 73 | final File additionalFile = new File(homeFolder, "additionalFiles/additionalFile.txt"); 74 | 75 | if (additionalFile.exists()) { 76 | publishInboundOutput.getPublishPacket().setPayload(ByteBuffer.wrap("modified".getBytes(StandardCharsets.UTF_8))); 77 | } 78 | }; 79 | 80 | final ClientInitializer clientInitializer = (initializerInput, clientContext) -> clientContext.addPublishInboundInterceptor(publishInboundInterceptor); 81 | 82 | Services.initializerRegistry().setClientInitializer(clientInitializer); 83 | } 84 | 85 | @Override 86 | public void extensionStop(@NotNull ExtensionStopInput extensionStopInput, @NotNull ExtensionStopOutput extensionStopOutput) { 87 | 88 | } 89 | } 90 | 91 | } 92 | -------------------------------------------------------------------------------- /junit5/src/test/java/com/hivemq/testcontainer/junit5/ContainerWithGradleExtensionIT.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 HiveMQ and the HiveMQ Community 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hivemq.testcontainer.junit5; 17 | 18 | import com.hivemq.testcontainer.core.GradleHiveMQExtensionSupplier; 19 | import com.hivemq.testcontainer.util.TestPublishModifiedUtil; 20 | import org.junit.jupiter.api.Test; 21 | import org.junit.jupiter.api.Timeout; 22 | import org.testcontainers.utility.MountableFile; 23 | 24 | import java.io.File; 25 | import java.util.concurrent.TimeUnit; 26 | 27 | /** 28 | * @author Yannick Weber 29 | * @since 1.3.0 30 | */ 31 | public class ContainerWithGradleExtensionIT { 32 | 33 | @Test 34 | @Timeout(value = 3, unit = TimeUnit.MINUTES) 35 | public void test() throws Exception { 36 | final MountableFile gradleExtension = new GradleHiveMQExtensionSupplier( 37 | new File(getClass().getResource("/gradle-extension").toURI())) 38 | .get(); 39 | 40 | final HiveMQTestContainerExtension container = new HiveMQTestContainerExtension() 41 | .waitForExtension("Gradle Extension") 42 | .withExtension(gradleExtension); 43 | 44 | container.beforeEach(null); 45 | TestPublishModifiedUtil.testPublishModified(container.getMqttPort()); 46 | container.afterEach(null); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /junit5/src/test/java/com/hivemq/testcontainer/junit5/ContainerWithLicenseIT.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 HiveMQ and the HiveMQ Community 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hivemq.testcontainer.junit5; 17 | 18 | import com.hivemq.extension.sdk.api.ExtensionMain; 19 | import com.hivemq.extension.sdk.api.interceptor.publish.PublishInboundInterceptor; 20 | import com.hivemq.extension.sdk.api.parameter.ExtensionStartInput; 21 | import com.hivemq.extension.sdk.api.parameter.ExtensionStartOutput; 22 | import com.hivemq.extension.sdk.api.parameter.ExtensionStopInput; 23 | import com.hivemq.extension.sdk.api.parameter.ExtensionStopOutput; 24 | import com.hivemq.extension.sdk.api.services.Services; 25 | import com.hivemq.extension.sdk.api.services.intializer.ClientInitializer; 26 | import com.hivemq.testcontainer.core.HiveMQExtension; 27 | import com.hivemq.testcontainer.util.TestPublishModifiedUtil; 28 | import org.jetbrains.annotations.NotNull; 29 | import org.junit.jupiter.api.Test; 30 | import org.junit.jupiter.api.Timeout; 31 | import org.testcontainers.utility.MountableFile; 32 | 33 | import java.io.File; 34 | import java.nio.ByteBuffer; 35 | import java.nio.charset.StandardCharsets; 36 | import java.util.concurrent.TimeUnit; 37 | 38 | /** 39 | * @author Yannick Weber 40 | */ 41 | public class ContainerWithLicenseIT { 42 | 43 | @Test 44 | @Timeout(value = 3, unit = TimeUnit.MINUTES) 45 | void test() throws Exception { 46 | final HiveMQExtension hiveMQExtension = HiveMQExtension.builder() 47 | .id("extension-1") 48 | .name("my-extension") 49 | .version("1.0") 50 | .mainClass(LicenceCheckerExtension.class).build(); 51 | 52 | final HiveMQTestContainerExtension extension = 53 | new HiveMQTestContainerExtension() 54 | .withExtension(hiveMQExtension) 55 | .waitForExtension(hiveMQExtension) 56 | .withLicense(MountableFile.forClasspathResource("/myLicense.lic")) 57 | .withLicense(MountableFile.forClasspathResource("/myExtensionLicense.elic")); 58 | 59 | extension.beforeEach(null); 60 | TestPublishModifiedUtil.testPublishModified(extension.getMqttPort()); 61 | extension.afterEach(null); 62 | } 63 | 64 | @SuppressWarnings("CodeBlock2Expr") 65 | public static class LicenceCheckerExtension implements ExtensionMain { 66 | 67 | @Override 68 | public void extensionStart(@NotNull ExtensionStartInput extensionStartInput, @NotNull ExtensionStartOutput extensionStartOutput) { 69 | 70 | final PublishInboundInterceptor publishInboundInterceptor = (publishInboundInput, publishInboundOutput) -> { 71 | 72 | final File homeFolder = extensionStartInput.getServerInformation().getHomeFolder(); 73 | final File myLicence = new File(homeFolder, "license/myLicense.lic"); 74 | final File myExtensionLicence = new File(homeFolder, "license/myExtensionLicense.elic"); 75 | 76 | if (myLicence.exists() && myExtensionLicence.exists()) { 77 | publishInboundOutput.getPublishPacket().setPayload(ByteBuffer.wrap("modified".getBytes(StandardCharsets.UTF_8))); 78 | } 79 | }; 80 | 81 | final ClientInitializer clientInitializer = (initializerInput, clientContext) -> { 82 | clientContext.addPublishInboundInterceptor(publishInboundInterceptor); 83 | }; 84 | 85 | Services.initializerRegistry().setClientInitializer(clientInitializer); 86 | } 87 | 88 | @Override 89 | public void extensionStop(@NotNull ExtensionStopInput extensionStopInput, @NotNull ExtensionStopOutput extensionStopOutput) { 90 | 91 | } 92 | } 93 | 94 | } 95 | -------------------------------------------------------------------------------- /junit5/src/test/java/com/hivemq/testcontainer/junit5/ContainerWithMavenExtensionIT.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 HiveMQ and the HiveMQ Community 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hivemq.testcontainer.junit5; 17 | 18 | import com.hivemq.testcontainer.core.MavenHiveMQExtensionSupplier; 19 | import com.hivemq.testcontainer.util.TestPublishModifiedUtil; 20 | import org.junit.jupiter.api.Test; 21 | import org.junit.jupiter.api.Timeout; 22 | import org.testcontainers.utility.MountableFile; 23 | 24 | import java.util.concurrent.TimeUnit; 25 | 26 | /** 27 | * @author Yannick Weber 28 | */ 29 | public class ContainerWithMavenExtensionIT { 30 | 31 | @Test 32 | @Timeout(value = 3, unit = TimeUnit.MINUTES) 33 | void test() throws Exception { 34 | final MountableFile mavenExtension = new MavenHiveMQExtensionSupplier( 35 | getClass().getResource("/maven-extension/pom.xml").getPath()) 36 | .addProperty("HIVEMQ_GROUP_ID", "com.hivemq") 37 | .addProperty("HIVEMQ_EXTENSION_SDK", "hivemq-extension-sdk") 38 | .addProperty("HIVEMQ_EXTENSION_SDK_VERSION", "4.3.0") 39 | .get(); 40 | 41 | final HiveMQTestContainerExtension extension = new HiveMQTestContainerExtension() 42 | .waitForExtension("Maven Extension") 43 | .withExtension(mavenExtension); 44 | 45 | extension.beforeEach(null); 46 | TestPublishModifiedUtil.testPublishModified(extension.getMqttPort()); 47 | extension.afterEach(null); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /junit5/src/test/java/com/hivemq/testcontainer/junit5/CreateFileInCopiedDirectoryIT.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 HiveMQ and the HiveMQ Community 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hivemq.testcontainer.junit5; 17 | 18 | import com.hivemq.extension.sdk.api.ExtensionMain; 19 | import com.hivemq.extension.sdk.api.interceptor.publish.PublishInboundInterceptor; 20 | import com.hivemq.extension.sdk.api.parameter.ExtensionStartInput; 21 | import com.hivemq.extension.sdk.api.parameter.ExtensionStartOutput; 22 | import com.hivemq.extension.sdk.api.parameter.ExtensionStopInput; 23 | import com.hivemq.extension.sdk.api.parameter.ExtensionStopOutput; 24 | import com.hivemq.extension.sdk.api.services.Services; 25 | import com.hivemq.extension.sdk.api.services.intializer.ClientInitializer; 26 | import com.hivemq.testcontainer.core.HiveMQExtension; 27 | import com.hivemq.testcontainer.util.TestPublishModifiedUtil; 28 | import org.jetbrains.annotations.NotNull; 29 | import org.junit.jupiter.api.Test; 30 | import org.junit.jupiter.api.Timeout; 31 | import org.testcontainers.utility.MountableFile; 32 | 33 | import java.io.File; 34 | import java.io.IOException; 35 | import java.nio.ByteBuffer; 36 | import java.nio.charset.StandardCharsets; 37 | import java.nio.file.Files; 38 | import java.util.concurrent.TimeUnit; 39 | 40 | import static org.junit.jupiter.api.Assertions.assertTrue; 41 | 42 | /** 43 | * @author Yannick Weber 44 | */ 45 | public class CreateFileInCopiedDirectoryIT { 46 | 47 | private @NotNull MountableFile createDirectory() throws IOException { 48 | final File directory = new File(Files.createTempDirectory("").toFile(), "directory"); 49 | assertTrue(directory.mkdir()); 50 | final File subdirectory = new File(directory, "sub-directory"); 51 | assertTrue(subdirectory.mkdir()); 52 | return MountableFile.forHostPath(directory.getPath()); 53 | } 54 | 55 | @Test 56 | @Timeout(value = 3, unit = TimeUnit.MINUTES) 57 | void test() throws Exception { 58 | final HiveMQExtension hiveMQExtension = HiveMQExtension.builder() 59 | .id("extension-1") 60 | .name("my-extension") 61 | .version("1.0") 62 | .mainClass(FileCreatorExtension.class).build(); 63 | 64 | final HiveMQTestContainerExtension extension = 65 | new HiveMQTestContainerExtension() 66 | .withExtension(hiveMQExtension) 67 | .waitForExtension(hiveMQExtension) 68 | .withFileInHomeFolder(createDirectory()); 69 | 70 | extension.beforeEach(null); 71 | TestPublishModifiedUtil.testPublishModified(extension.getMqttPort()); 72 | extension.afterEach(null); 73 | } 74 | 75 | public static class FileCreatorExtension implements ExtensionMain { 76 | 77 | @Override 78 | public void extensionStart(@NotNull ExtensionStartInput extensionStartInput, @NotNull ExtensionStartOutput extensionStartOutput) { 79 | 80 | final PublishInboundInterceptor publishInboundInterceptor = (publishInboundInput, publishInboundOutput) -> { 81 | 82 | final File homeFolder = extensionStartInput.getServerInformation().getHomeFolder(); 83 | 84 | final File dir = new File(homeFolder, "directory"); 85 | final File dirFile = new File(dir, "file.txt"); 86 | final File subDir = new File(dir, "sub-directory"); 87 | final File subDirFile = new File(subDir, "file.txt"); 88 | 89 | try { 90 | if (dirFile.createNewFile() && subDirFile.createNewFile()) { 91 | publishInboundOutput.getPublishPacket().setPayload(ByteBuffer.wrap("modified".getBytes(StandardCharsets.UTF_8))); 92 | } 93 | } catch (IOException e) { 94 | e.printStackTrace(); 95 | } 96 | }; 97 | 98 | final ClientInitializer clientInitializer = (initializerInput, clientContext) -> clientContext.addPublishInboundInterceptor(publishInboundInterceptor); 99 | 100 | Services.initializerRegistry().setClientInitializer(clientInitializer); 101 | } 102 | 103 | @Override 104 | public void extensionStop(@NotNull ExtensionStopInput extensionStopInput, @NotNull ExtensionStopOutput extensionStopOutput) { 105 | 106 | } 107 | } 108 | 109 | } 110 | -------------------------------------------------------------------------------- /junit5/src/test/java/com/hivemq/testcontainer/junit5/CreateFileInExtensionDirectoryIT.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 HiveMQ and the HiveMQ Community 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hivemq.testcontainer.junit5; 17 | 18 | import com.hivemq.extension.sdk.api.ExtensionMain; 19 | import com.hivemq.extension.sdk.api.interceptor.publish.PublishInboundInterceptor; 20 | import com.hivemq.extension.sdk.api.parameter.ExtensionStartInput; 21 | import com.hivemq.extension.sdk.api.parameter.ExtensionStartOutput; 22 | import com.hivemq.extension.sdk.api.parameter.ExtensionStopInput; 23 | import com.hivemq.extension.sdk.api.parameter.ExtensionStopOutput; 24 | import com.hivemq.extension.sdk.api.services.Services; 25 | import com.hivemq.extension.sdk.api.services.intializer.ClientInitializer; 26 | import com.hivemq.testcontainer.core.HiveMQExtension; 27 | import com.hivemq.testcontainer.util.TestPublishModifiedUtil; 28 | import org.jetbrains.annotations.NotNull; 29 | import org.junit.jupiter.api.Test; 30 | import org.junit.jupiter.api.Timeout; 31 | 32 | import java.io.File; 33 | import java.io.IOException; 34 | import java.nio.ByteBuffer; 35 | import java.nio.charset.StandardCharsets; 36 | import java.util.concurrent.TimeUnit; 37 | 38 | /** 39 | * @author Yannick Weber 40 | */ 41 | public class CreateFileInExtensionDirectoryIT { 42 | 43 | @Test 44 | @Timeout(value = 3, unit = TimeUnit.MINUTES) 45 | void test() throws Exception { 46 | final HiveMQExtension hiveMQExtension = HiveMQExtension.builder() 47 | .id("extension-1") 48 | .name("my-extension") 49 | .version("1.0") 50 | .mainClass(FileCreatorExtension.class).build(); 51 | 52 | final HiveMQTestContainerExtension extension = 53 | new HiveMQTestContainerExtension() 54 | .waitForExtension(hiveMQExtension) 55 | .withExtension(hiveMQExtension); 56 | extension.beforeEach(null); 57 | TestPublishModifiedUtil.testPublishModified(extension.getMqttPort()); 58 | extension.afterEach(null); 59 | } 60 | 61 | public static class FileCreatorExtension implements ExtensionMain { 62 | 63 | @Override 64 | public void extensionStart(@NotNull ExtensionStartInput extensionStartInput, @NotNull ExtensionStartOutput extensionStartOutput) { 65 | 66 | final PublishInboundInterceptor publishInboundInterceptor = (publishInboundInput, publishInboundOutput) -> { 67 | 68 | final File extensionHomeFolder = extensionStartInput.getExtensionInformation().getExtensionHomeFolder(); 69 | 70 | final File file = new File(extensionHomeFolder, "myfile.txt"); 71 | try { 72 | if (file.createNewFile()) { 73 | publishInboundOutput.getPublishPacket().setPayload(ByteBuffer.wrap("modified".getBytes(StandardCharsets.UTF_8))); 74 | } 75 | } catch (IOException e) { 76 | e.printStackTrace(); 77 | } 78 | }; 79 | 80 | final ClientInitializer clientInitializer = (initializerInput, clientContext) -> clientContext.addPublishInboundInterceptor(publishInboundInterceptor); 81 | 82 | Services.initializerRegistry().setClientInitializer(clientInitializer); 83 | } 84 | 85 | @Override 86 | public void extensionStop(@NotNull ExtensionStopInput extensionStopInput, @NotNull ExtensionStopOutput extensionStopOutput) { 87 | 88 | } 89 | } 90 | 91 | } 92 | -------------------------------------------------------------------------------- /junit5/src/test/java/com/hivemq/testcontainer/junit5/DisableEnableExtensionFromDirectoryIT.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 HiveMQ and the HiveMQ Community 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hivemq.testcontainer.junit5; 17 | 18 | import com.hivemq.testcontainer.util.TestPublishModifiedUtil; 19 | import org.junit.jupiter.api.Test; 20 | import org.junit.jupiter.api.Timeout; 21 | import org.slf4j.event.Level; 22 | import org.testcontainers.utility.DockerImageName; 23 | import org.testcontainers.utility.MountableFile; 24 | 25 | import java.util.concurrent.ExecutionException; 26 | import java.util.concurrent.TimeUnit; 27 | 28 | import static org.junit.jupiter.api.Assertions.assertThrows; 29 | 30 | /** 31 | * @author Yannick Weber 32 | */ 33 | public class DisableEnableExtensionFromDirectoryIT { 34 | 35 | @Test 36 | @Timeout(value = 3, unit = TimeUnit.MINUTES) 37 | void test() throws Exception { 38 | final HiveMQTestContainerExtension extension = 39 | new HiveMQTestContainerExtension(DockerImageName.parse("hivemq/hivemq4").withTag("latest")) 40 | .withExtension(MountableFile.forClasspathResource("/modifier-extension")) 41 | .waitForExtension("Modifier Extension") 42 | .withLogLevel(Level.DEBUG); 43 | 44 | extension.beforeEach(null); 45 | 46 | TestPublishModifiedUtil.testPublishModified(extension.getMqttPort()); 47 | extension.disableExtension("Modifier Extension", "modifier-extension"); 48 | assertThrows(ExecutionException.class, () -> TestPublishModifiedUtil.testPublishModified(extension.getMqttPort())); 49 | extension.enableExtension("Modifier Extension", "modifier-extension"); 50 | TestPublishModifiedUtil.testPublishModified(extension.getMqttPort()); 51 | 52 | extension.afterEach(null); 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /junit5/src/test/java/com/hivemq/testcontainer/junit5/DisableEnableExtensionIT.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 HiveMQ and the HiveMQ Community 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hivemq.testcontainer.junit5; 17 | 18 | import com.hivemq.testcontainer.core.HiveMQExtension; 19 | import com.hivemq.testcontainer.util.MyExtension; 20 | import com.hivemq.testcontainer.util.TestPublishModifiedUtil; 21 | import org.jetbrains.annotations.NotNull; 22 | import org.junit.jupiter.api.Test; 23 | import org.junit.jupiter.api.Timeout; 24 | import org.slf4j.event.Level; 25 | import org.testcontainers.utility.DockerImageName; 26 | 27 | import java.util.concurrent.ExecutionException; 28 | import java.util.concurrent.TimeUnit; 29 | 30 | import static org.junit.jupiter.api.Assertions.assertThrows; 31 | 32 | /** 33 | * @author Yannick Weber 34 | */ 35 | public class DisableEnableExtensionIT { 36 | 37 | private final @NotNull HiveMQExtension hiveMQExtension = HiveMQExtension.builder() 38 | .id("extension-1") 39 | .name("my-extension") 40 | .version("1.0") 41 | .disabledOnStartup(true) 42 | .mainClass(MyExtension.class).build(); 43 | 44 | @Test 45 | @Timeout(value = 3, unit = TimeUnit.MINUTES) 46 | void test() throws Exception { 47 | final HiveMQTestContainerExtension extension = 48 | new HiveMQTestContainerExtension(DockerImageName.parse("hivemq/hivemq4").withTag("latest")) 49 | .withExtension(hiveMQExtension) 50 | .withLogLevel(Level.DEBUG); 51 | 52 | extension.beforeEach(null); 53 | 54 | assertThrows(ExecutionException.class, () -> TestPublishModifiedUtil.testPublishModified(extension.getMqttPort())); 55 | extension.enableExtension(hiveMQExtension); 56 | TestPublishModifiedUtil.testPublishModified(extension.getMqttPort()); 57 | extension.disableExtension(hiveMQExtension); 58 | assertThrows(ExecutionException.class, () -> TestPublishModifiedUtil.testPublishModified(extension.getMqttPort())); 59 | extension.enableExtension(hiveMQExtension); 60 | TestPublishModifiedUtil.testPublishModified(extension.getMqttPort()); 61 | 62 | extension.afterEach(null); 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /junit5/src/test/java/com/hivemq/testcontainer/junit5/DisableEnableMavenExtensionIT.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 HiveMQ and the HiveMQ Community 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hivemq.testcontainer.junit5; 17 | 18 | import com.hivemq.testcontainer.core.MavenHiveMQExtensionSupplier; 19 | import com.hivemq.testcontainer.util.TestPublishModifiedUtil; 20 | import org.junit.jupiter.api.Test; 21 | import org.junit.jupiter.api.Timeout; 22 | import org.testcontainers.utility.DockerImageName; 23 | import org.testcontainers.utility.MountableFile; 24 | 25 | import java.util.concurrent.ExecutionException; 26 | import java.util.concurrent.TimeUnit; 27 | 28 | import static org.junit.jupiter.api.Assertions.assertThrows; 29 | 30 | /** 31 | * @author Yannick Weber 32 | */ 33 | public class DisableEnableMavenExtensionIT { 34 | 35 | @Test 36 | @Timeout(value = 3, unit = TimeUnit.MINUTES) 37 | void test() throws Exception { 38 | final MountableFile extensionDir = new MavenHiveMQExtensionSupplier( 39 | getClass().getResource("/maven-extension/pom.xml").getPath()) 40 | .addProperty("HIVEMQ_GROUP_ID", "com.hivemq") 41 | .addProperty("HIVEMQ_EXTENSION_SDK", "hivemq-extension-sdk") 42 | .addProperty("HIVEMQ_EXTENSION_SDK_VERSION", "4.3.0") 43 | .quiet() 44 | .get(); 45 | 46 | final HiveMQTestContainerExtension extension = 47 | new HiveMQTestContainerExtension(DockerImageName.parse("hivemq/hivemq4").withTag("latest")) 48 | .waitForExtension("Maven Extension") 49 | .withExtension(extensionDir); 50 | 51 | extension.beforeEach(null); 52 | TestPublishModifiedUtil.testPublishModified(extension.getMqttPort()); 53 | extension.disableExtension("Maven Extension", "maven-extension"); 54 | assertThrows(ExecutionException.class, () -> TestPublishModifiedUtil.testPublishModified(extension.getMqttPort())); 55 | extension.enableExtension("Maven Extension", "maven-extension"); 56 | TestPublishModifiedUtil.testPublishModified(extension.getMqttPort()); 57 | extension.afterEach(null); 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /junit5/src/test/resources/additionalFile.txt: -------------------------------------------------------------------------------- 1 | ==== 2 | Copyright 2020 HiveMQ and the HiveMQ Community 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | ==== 16 | 17 | -------------------------------------------------------------------------------- /junit5/src/test/resources/config.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 21 | 22 | 23 | 1883 24 | 0.0.0.0 25 | 26 | 27 | 28 | 29 | 0 30 | 31 | 32 | -------------------------------------------------------------------------------- /junit5/src/test/resources/gradle-extension/build.gradle: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 HiveMQ and the HiveMQ Community 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | plugins { 17 | id 'java' 18 | id 'com.hivemq.extension' 19 | } 20 | 21 | group 'org.example' 22 | version '1.0.0' 23 | 24 | hivemqExtension { 25 | name = 'Gradle Extension' 26 | author = 'Example Org' 27 | priority = 0 28 | startPriority = 1000 29 | mainClass = 'com.hivemq.MyExtension' 30 | sdkVersion = '4.4.1' 31 | } 32 | 33 | -------------------------------------------------------------------------------- /junit5/src/test/resources/gradle-extension/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hivemq/hivemq-testcontainer/2604c1809302cd1763e36c3665fdfece661fdd88/junit5/src/test/resources/gradle-extension/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /junit5/src/test/resources/gradle-extension/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2020 HiveMQ and the HiveMQ Community 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | distributionBase=GRADLE_USER_HOME 18 | distributionPath=wrapper/dists 19 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.1.1-bin.zip 20 | zipStoreBase=GRADLE_USER_HOME 21 | zipStorePath=wrapper/dists 22 | -------------------------------------------------------------------------------- /junit5/src/test/resources/gradle-extension/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # 4 | # Copyright 2015 the original author or authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | ## 21 | ## Gradle start up script for UN*X 22 | ## 23 | ############################################################################## 24 | 25 | # Attempt to set APP_HOME 26 | # Resolve links: $0 may be a link 27 | PRG="$0" 28 | # Need this for relative symlinks. 29 | while [ -h "$PRG" ] ; do 30 | ls=`ls -ld "$PRG"` 31 | link=`expr "$ls" : '.*-> \(.*\)$'` 32 | if expr "$link" : '/.*' > /dev/null; then 33 | PRG="$link" 34 | else 35 | PRG=`dirname "$PRG"`"/$link" 36 | fi 37 | done 38 | SAVED="`pwd`" 39 | cd "`dirname \"$PRG\"`/" >/dev/null 40 | APP_HOME="`pwd -P`" 41 | cd "$SAVED" >/dev/null 42 | 43 | APP_NAME="Gradle" 44 | APP_BASE_NAME=`basename "$0"` 45 | 46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 48 | 49 | # Use the maximum available, or set MAX_FD != -1 to use that value. 50 | MAX_FD="maximum" 51 | 52 | warn () { 53 | echo "$*" 54 | } 55 | 56 | die () { 57 | echo 58 | echo "$*" 59 | echo 60 | exit 1 61 | } 62 | 63 | # OS specific support (must be 'true' or 'false'). 64 | cygwin=false 65 | msys=false 66 | darwin=false 67 | nonstop=false 68 | case "`uname`" in 69 | CYGWIN* ) 70 | cygwin=true 71 | ;; 72 | Darwin* ) 73 | darwin=true 74 | ;; 75 | MSYS* | MINGW* ) 76 | msys=true 77 | ;; 78 | NONSTOP* ) 79 | nonstop=true 80 | ;; 81 | esac 82 | 83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 84 | 85 | 86 | # Determine the Java command to use to start the JVM. 87 | if [ -n "$JAVA_HOME" ] ; then 88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 89 | # IBM's JDK on AIX uses strange locations for the executables 90 | JAVACMD="$JAVA_HOME/jre/sh/java" 91 | else 92 | JAVACMD="$JAVA_HOME/bin/java" 93 | fi 94 | if [ ! -x "$JAVACMD" ] ; then 95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 96 | 97 | Please set the JAVA_HOME variable in your environment to match the 98 | location of your Java installation." 99 | fi 100 | else 101 | JAVACMD="java" 102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 103 | 104 | Please set the JAVA_HOME variable in your environment to match the 105 | location of your Java installation." 106 | fi 107 | 108 | # Increase the maximum file descriptors if we can. 109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 110 | MAX_FD_LIMIT=`ulimit -H -n` 111 | if [ $? -eq 0 ] ; then 112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 113 | MAX_FD="$MAX_FD_LIMIT" 114 | fi 115 | ulimit -n $MAX_FD 116 | if [ $? -ne 0 ] ; then 117 | warn "Could not set maximum file descriptor limit: $MAX_FD" 118 | fi 119 | else 120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 121 | fi 122 | fi 123 | 124 | # For Darwin, add options to specify how the application appears in the dock 125 | if $darwin; then 126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 127 | fi 128 | 129 | # For Cygwin or MSYS, switch paths to Windows format before running java 130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then 131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 133 | 134 | JAVACMD=`cygpath --unix "$JAVACMD"` 135 | 136 | # We build the pattern for arguments to be converted via cygpath 137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 138 | SEP="" 139 | for dir in $ROOTDIRSRAW ; do 140 | ROOTDIRS="$ROOTDIRS$SEP$dir" 141 | SEP="|" 142 | done 143 | OURCYGPATTERN="(^($ROOTDIRS))" 144 | # Add a user-defined pattern to the cygpath arguments 145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 147 | fi 148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 149 | i=0 150 | for arg in "$@" ; do 151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 153 | 154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 156 | else 157 | eval `echo args$i`="\"$arg\"" 158 | fi 159 | i=`expr $i + 1` 160 | done 161 | case $i in 162 | 0) set -- ;; 163 | 1) set -- "$args0" ;; 164 | 2) set -- "$args0" "$args1" ;; 165 | 3) set -- "$args0" "$args1" "$args2" ;; 166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;; 167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 172 | esac 173 | fi 174 | 175 | # Escape application args 176 | save () { 177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 178 | echo " " 179 | } 180 | APP_ARGS=`save "$@"` 181 | 182 | # Collect all arguments for the java command, following the shell quoting and substitution rules 183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 184 | 185 | exec "$JAVACMD" "$@" 186 | -------------------------------------------------------------------------------- /junit5/src/test/resources/gradle-extension/gradlew.bat: -------------------------------------------------------------------------------- 1 | @REM 2 | @REM Copyright 2020 HiveMQ and the HiveMQ Community 3 | @REM 4 | @REM Licensed under the Apache License, Version 2.0 (the "License"); 5 | @REM you may not use this file except in compliance with the License. 6 | @REM You may obtain a copy of the License at 7 | @REM 8 | @REM http://www.apache.org/licenses/LICENSE-2.0 9 | @REM 10 | @REM Unless required by applicable law or agreed to in writing, software 11 | @REM distributed under the License is distributed on an "AS IS" BASIS, 12 | @REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @REM See the License for the specific language governing permissions and 14 | @REM limitations under the License. 15 | @REM 16 | 17 | @rem 18 | @rem Copyright 2015 the original author or authors. 19 | @rem 20 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 21 | @rem you may not use this file except in compliance with the License. 22 | @rem You may obtain a copy of the License at 23 | @rem 24 | @rem https://www.apache.org/licenses/LICENSE-2.0 25 | @rem 26 | @rem Unless required by applicable law or agreed to in writing, software 27 | @rem distributed under the License is distributed on an "AS IS" BASIS, 28 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 29 | @rem See the License for the specific language governing permissions and 30 | @rem limitations under the License. 31 | @rem 32 | 33 | @if "%DEBUG%" == "" @echo off 34 | @rem ########################################################################## 35 | @rem 36 | @rem Gradle startup script for Windows 37 | @rem 38 | @rem ########################################################################## 39 | 40 | @rem Set local scope for the variables with windows NT shell 41 | if "%OS%"=="Windows_NT" setlocal 42 | 43 | set DIRNAME=%~dp0 44 | if "%DIRNAME%" == "" set DIRNAME=. 45 | set APP_BASE_NAME=%~n0 46 | set APP_HOME=%DIRNAME% 47 | 48 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 49 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 50 | 51 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 52 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 53 | 54 | @rem Find java.exe 55 | if defined JAVA_HOME goto findJavaFromJavaHome 56 | 57 | set JAVA_EXE=java.exe 58 | %JAVA_EXE% -version >NUL 2>&1 59 | if "%ERRORLEVEL%" == "0" goto execute 60 | 61 | echo. 62 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 63 | echo. 64 | echo Please set the JAVA_HOME variable in your environment to match the 65 | echo location of your Java installation. 66 | 67 | goto fail 68 | 69 | :findJavaFromJavaHome 70 | set JAVA_HOME=%JAVA_HOME:"=% 71 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 72 | 73 | if exist "%JAVA_EXE%" goto execute 74 | 75 | echo. 76 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 77 | echo. 78 | echo Please set the JAVA_HOME variable in your environment to match the 79 | echo location of your Java installation. 80 | 81 | goto fail 82 | 83 | :execute 84 | @rem Setup the command line 85 | 86 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 87 | 88 | 89 | @rem Execute Gradle 90 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 91 | 92 | :end 93 | @rem End local scope for the variables with windows NT shell 94 | if "%ERRORLEVEL%"=="0" goto mainEnd 95 | 96 | :fail 97 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 98 | rem the _cmd.exe /c_ return code! 99 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 100 | exit /b 1 101 | 102 | :mainEnd 103 | if "%OS%"=="Windows_NT" endlocal 104 | 105 | :omega 106 | -------------------------------------------------------------------------------- /junit5/src/test/resources/gradle-extension/settings.gradle: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 HiveMQ and the HiveMQ Community 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | pluginManagement { 17 | plugins { 18 | id 'com.hivemq.extension' version '2.0.0' 19 | } 20 | } 21 | rootProject.name = 'gradle-extension' -------------------------------------------------------------------------------- /junit5/src/test/resources/gradle-extension/src/main/java/com/hivemq/MyExtension.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 HiveMQ and the HiveMQ Community 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq; 18 | 19 | import com.hivemq.extension.sdk.api.ExtensionMain; 20 | import com.hivemq.extension.sdk.api.annotations.NotNull; 21 | import com.hivemq.extension.sdk.api.events.EventRegistry; 22 | import com.hivemq.extension.sdk.api.interceptor.publish.PublishInboundInterceptor; 23 | import com.hivemq.extension.sdk.api.parameter.*; 24 | import com.hivemq.extension.sdk.api.services.Services; 25 | import com.hivemq.extension.sdk.api.services.intializer.ClientInitializer; 26 | import org.slf4j.Logger; 27 | import org.slf4j.LoggerFactory; 28 | 29 | import java.nio.ByteBuffer; 30 | import java.nio.charset.StandardCharsets; 31 | 32 | /** 33 | * @author Yannick Weber 34 | */ 35 | @SuppressWarnings("CodeBlock2Expr") 36 | public class MyExtension implements ExtensionMain { 37 | 38 | @Override 39 | public void extensionStart(final @NotNull ExtensionStartInput extensionStartInput, final @NotNull ExtensionStartOutput extensionStartOutput) { 40 | 41 | final PublishInboundInterceptor publishInboundInterceptor = (publishInboundInput, publishInboundOutput) -> { 42 | publishInboundOutput.getPublishPacket().setPayload(ByteBuffer.wrap("modified".getBytes(StandardCharsets.UTF_8))); 43 | }; 44 | 45 | final ClientInitializer clientInitializer = (initializerInput, clientContext) -> { 46 | clientContext.addPublishInboundInterceptor(publishInboundInterceptor); 47 | }; 48 | 49 | Services.initializerRegistry().setClientInitializer(clientInitializer); 50 | } 51 | 52 | @Override 53 | public void extensionStop(final @NotNull ExtensionStopInput extensionStopInput, final @NotNull ExtensionStopOutput extensionStopOutput) { 54 | 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /junit5/src/test/resources/logback-test.xml: -------------------------------------------------------------------------------- 1 | 18 | 19 | 20 | 21 | 22 | %-30(%d %level)- %msg%n%ex 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /junit5/src/test/resources/maven-extension/assembly.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 22 | distribution 23 | 24 | zip 25 | 26 | 27 | 28 | src/main/resources/hivemq-extension.xml 29 | /${artifactId}/ 30 | true 31 | 32 | 33 | target/${artifactId}-${version}.jar 34 | ${artifactId}-${version}.jar 35 | /${artifactId}/ 36 | 37 | 38 | false 39 | -------------------------------------------------------------------------------- /junit5/src/test/resources/maven-extension/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 21 | 4.0.0 22 | 23 | com.hivemq 24 | maven-extension 25 | 1.0.0 26 | 27 | 28 | Maven Extension 29 | HiveMQ GmbH 30 | 31 | 32 | 33 | 34 | com.hivemq 35 | hivemq-extension-sdk 36 | 4.3.0 37 | 38 | 39 | 40 | 41 | 42 | 43 | org.apache.maven.plugins 44 | maven-compiler-plugin 45 | 3.8.0 46 | 47 | 11 48 | 11 49 | 50 | 51 | 52 | org.apache.maven.plugins 53 | maven-shade-plugin 54 | 3.1.1 55 | 56 | 57 | package 58 | 59 | shade 60 | 61 | 62 | 63 | 64 | com.hivemq:hivemq-extension-sdk 65 | org.slf4j:* 66 | ch.qos.logback:* 67 | javax.servlet:* 68 | 69 | 70 | 71 | 72 | *:* 73 | 74 | META-INF/*.SF 75 | META-INF/*.DSA 76 | META-INF/*.RSA 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | maven-assembly-plugin 86 | 87 | 88 | assembly 89 | package 90 | 91 | single 92 | 93 | 94 | 95 | assembly.xml 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | -------------------------------------------------------------------------------- /junit5/src/test/resources/maven-extension/src/main/java/com/hivemq/MyExtension.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 HiveMQ and the HiveMQ Community 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq; 18 | 19 | import com.hivemq.extension.sdk.api.ExtensionMain; 20 | import com.hivemq.extension.sdk.api.annotations.NotNull; 21 | import com.hivemq.extension.sdk.api.events.EventRegistry; 22 | import com.hivemq.extension.sdk.api.interceptor.publish.PublishInboundInterceptor; 23 | import com.hivemq.extension.sdk.api.parameter.*; 24 | import com.hivemq.extension.sdk.api.services.Services; 25 | import com.hivemq.extension.sdk.api.services.intializer.ClientInitializer; 26 | import org.slf4j.Logger; 27 | import org.slf4j.LoggerFactory; 28 | 29 | import java.nio.ByteBuffer; 30 | import java.nio.charset.StandardCharsets; 31 | 32 | /** 33 | * @author Yannick Weber 34 | */ 35 | @SuppressWarnings("CodeBlock2Expr") 36 | public class MyExtension implements ExtensionMain { 37 | 38 | @Override 39 | public void extensionStart(final @NotNull ExtensionStartInput extensionStartInput, final @NotNull ExtensionStartOutput extensionStartOutput) { 40 | 41 | final PublishInboundInterceptor publishInboundInterceptor = (publishInboundInput, publishInboundOutput) -> { 42 | publishInboundOutput.getPublishPacket().setPayload(ByteBuffer.wrap("modified".getBytes(StandardCharsets.UTF_8))); 43 | }; 44 | 45 | final ClientInitializer clientInitializer = (initializerInput, clientContext) -> { 46 | clientContext.addPublishInboundInterceptor(publishInboundInterceptor); 47 | }; 48 | 49 | Services.initializerRegistry().setClientInitializer(clientInitializer); 50 | } 51 | 52 | @Override 53 | public void extensionStop(final @NotNull ExtensionStopInput extensionStopInput, final @NotNull ExtensionStopOutput extensionStopOutput) { 54 | 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /junit5/src/test/resources/maven-extension/src/main/resources/META-INF/services/com.hivemq.extension.sdk.api.ExtensionMain: -------------------------------------------------------------------------------- 1 | com.hivemq.MyExtension -------------------------------------------------------------------------------- /junit5/src/test/resources/maven-extension/src/main/resources/hivemq-extension.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | ${artifactId} 21 | ${version} 22 | ${extension.name} 23 | ${extension.author} 24 | 1000 25 | 26 | -------------------------------------------------------------------------------- /junit5/src/test/resources/modifier-extension-wrong-name/hivemq-extension.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | modifier-extension 21 | 1.0-SNAPSHOT 22 | Modifier Extension 23 | HiveMQ GmbH 24 | 1000 25 | 26 | -------------------------------------------------------------------------------- /junit5/src/test/resources/modifier-extension-wrong-name/modifier-extension-1.0-SNAPSHOT.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hivemq/hivemq-testcontainer/2604c1809302cd1763e36c3665fdfece661fdd88/junit5/src/test/resources/modifier-extension-wrong-name/modifier-extension-1.0-SNAPSHOT.jar -------------------------------------------------------------------------------- /junit5/src/test/resources/modifier-extension/hivemq-extension.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | modifier-extension 21 | 1.0-SNAPSHOT 22 | Modifier Extension 23 | HiveMQ GmbH 24 | 1000 25 | 26 | -------------------------------------------------------------------------------- /junit5/src/test/resources/modifier-extension/modifier-extension-1.0-SNAPSHOT.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hivemq/hivemq-testcontainer/2604c1809302cd1763e36c3665fdfece661fdd88/junit5/src/test/resources/modifier-extension/modifier-extension-1.0-SNAPSHOT.jar -------------------------------------------------------------------------------- /junit5/src/test/resources/myExtensionLicense.elic: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hivemq/hivemq-testcontainer/2604c1809302cd1763e36c3665fdfece661fdd88/junit5/src/test/resources/myExtensionLicense.elic -------------------------------------------------------------------------------- /junit5/src/test/resources/myLicense.lic: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hivemq/hivemq-testcontainer/2604c1809302cd1763e36c3665fdfece661fdd88/junit5/src/test/resources/myLicense.lic -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # HiveMQ Test Container 2 | 3 | ⚠️ Deprecated ⚠️ 4 | 5 | NOTE: This module has moved to 6 | the [testcontainers-java](https://github.com/testcontainers/testcontainers-java/tree/master/modules/hivemq) project as 7 | of testcontainers 1.17.0. For more information see the [official documentation](https://www.testcontainers.org/modules/hivemq/). 8 | -------------------------------------------------------------------------------- /settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "hivemq-testcontainer" 2 | 3 | for (module in listOf("core", "junit4", "junit5")) { 4 | include("${rootProject.name}-$module") 5 | project(":${rootProject.name}-$module").projectDir = file(module) 6 | } 7 | 8 | pluginManagement { 9 | plugins { 10 | id("io.github.gradle-nexus.publish-plugin") version "${extra["plugin.nexus-publish.version"]}" 11 | } 12 | } --------------------------------------------------------------------------------