generated from micronaut-projects/micronaut-project-template
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix MQTT with Jackson mqtt-core was based on serde-jackson which may be missing if the consuming project is using jackson. This change mirrors the fix for problem-json here micronaut-projects/micronaut-problem-json#293 That is, make the serde-api and jackson annotations api dependencies of this project in place of the serde-jackson dependency. I have an external reproducer, but I cannot get it to fail when included in this project... Closes #332 * Add tests
- Loading branch information
Showing
14 changed files
with
185 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
plugins { | ||
id("io.micronaut.library") | ||
id("io.micronaut.test-resources") | ||
} | ||
|
||
version = "0.1" | ||
group = "example.micronaut" | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
implementation(projects.micronautMqttv5) | ||
implementation(mn.micronaut.jackson.databind) | ||
runtimeOnly(mn.snakeyaml) | ||
runtimeOnly(mnLogging.logback.classic) | ||
|
||
testImplementation(libs.awaitility) | ||
} | ||
|
||
micronaut { | ||
version.set(libs.versions.micronaut.platform) | ||
testRuntime("junit5") | ||
processing { | ||
incremental(true) | ||
annotations("example.micronaut.*") | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
test-suite-jackson/src/main/java/example/micronaut/Odour.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright 2017-2024 original authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package example.micronaut; | ||
|
||
import io.micronaut.core.annotation.Introspected; | ||
|
||
@Introspected | ||
public class Odour { | ||
|
||
private final String name; | ||
|
||
public Odour(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
test-suite-jackson/src/main/java/example/micronaut/SmellListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright 2017-2024 original authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package example.micronaut; | ||
|
||
import io.micronaut.core.annotation.NonNull; | ||
import io.micronaut.mqtt.annotation.MqttSubscriber; | ||
import io.micronaut.mqtt.annotation.Topic; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
@MqttSubscriber | ||
public class SmellListener { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(SmellListener.class); | ||
private Odour smell; | ||
|
||
@Topic("house/livingroom/smell") | ||
public void receive(Odour data) { | ||
LOG.info("smell: {}", smell); | ||
smell = data; | ||
} | ||
|
||
@NonNull | ||
public String getSmell() { | ||
return smell == null ? "" : smell.getName(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#tag::mqtt[] | ||
mqtt: | ||
client: | ||
server-uri: tcp://${mqtt.host}:${mqtt.port} | ||
client-id: ${random.uuid} | ||
#end::mqtt[] | ||
#tag::test-resources[] | ||
test-resources: | ||
containers: | ||
mosquitto: | ||
image-name: eclipse-mosquitto | ||
hostnames: | ||
- mqtt.host | ||
exposed-ports: | ||
- mqtt.port: 1883 | ||
ro-fs-bind: | ||
- "src/test-resources/mosquitto.conf": /mosquitto/config/mosquitto.conf | ||
#end::test-resources[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<configuration> | ||
|
||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> | ||
<!-- encoders are assigned the type | ||
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default --> | ||
<encoder> | ||
<pattern>%cyan(%d{HH:mm:ss.SSS}) %gray([%thread]) %highlight(%-5level) %magenta(%logger{36}) - %msg%n</pattern> | ||
</encoder> | ||
</appender> | ||
|
||
<root level="info"> | ||
<appender-ref ref="STDOUT" /> | ||
</root> | ||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
persistence false | ||
allow_anonymous true | ||
connection_messages true | ||
log_type all | ||
listener 1883 |
38 changes: 38 additions & 0 deletions
38
test-suite-jackson/src/test/java/example/micronaut/SubscriptionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package example.micronaut; | ||
|
||
import io.micronaut.mqtt.annotation.Topic; | ||
import io.micronaut.mqtt.annotation.v5.MqttPublisher; | ||
import io.micronaut.test.extensions.junit5.annotation.MicronautTest; | ||
import jakarta.inject.Inject; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
import static org.awaitility.Awaitility.await; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
@MicronautTest | ||
class SubscriptionTest { | ||
|
||
@Inject | ||
SmellClient client; | ||
|
||
@Inject | ||
SmellListener listener; | ||
|
||
@Test | ||
void checkSubscriptionsAreReceived() { | ||
client.publishLivingroomSmell(new Odour("cheesy")); | ||
|
||
await() | ||
.atMost(5, TimeUnit.SECONDS) | ||
.untilAsserted(() -> assertEquals("cheesy", listener.getSmell())); | ||
} | ||
|
||
@MqttPublisher | ||
interface SmellClient { | ||
|
||
@Topic("house/livingroom/smell") | ||
void publishLivingroomSmell(Odour data); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters