Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/run tests on java 21 #399

Merged
merged 3 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ application {

java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(11))
languageVersion.set(JavaLanguageVersion.of(21))
}
}

Expand Down Expand Up @@ -232,7 +232,6 @@ testing {

val test by getting(JvmTestSuite::class) {
dependencies {
implementation(libs.junit.systemExit)
implementation(libs.mockito)
implementation(libs.okhttp.mockWebserver)
}
Expand All @@ -244,7 +243,6 @@ testing {
dependencies {
implementation(libs.awaitility)
implementation(libs.hivemq.testcontainer.junit5)
implementation(libs.junit.systemExit)
implementation(libs.mockito)
implementation(libs.testcontainers)

Expand Down
2 changes: 0 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ jsr305 = "3.0.2"
junit-jupiter = "5.10.2"
junit-pioneer = "2.2.0"
junit-platformLauncher = "1.10.2"
junit-systemExit = "1.1.2"
mockito = "5.10.0"
netty = "4.1.107.Final"
okhttp = "4.12.0"
Expand Down Expand Up @@ -57,7 +56,6 @@ jsr305 = { module = "com.google.code.findbugs:jsr305", version.ref = "jsr305" }
junit-jupiter = { module = "org.junit.jupiter:junit-jupiter", version.ref = "junit-jupiter" }
junit-pioneer = { module = "org.junit-pioneer:junit-pioneer", version.ref = "junit-pioneer" }
junit-platformLauncher = { module = "org.junit.platform:junit-platform-launcher", version.ref = "junit-platformLauncher" }
junit-systemExit = { module = "com.ginsberg:junit5-system-exit", version.ref = "junit-systemExit" }
mockito = { module = "org.mockito:mockito-core", version.ref = "mockito" }
netty-codec-http = { module = "io.netty:netty-codec-http", version.ref = "netty" }
netty-handler = { module = "io.netty:netty-handler", version.ref = "netty" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package com.hivemq.cli.commands.cli;

import com.ginsberg.junit.exit.ExpectSystemExitWithStatus;
import com.hivemq.cli.MqttCLIMain;
import com.hivemq.cli.utils.TestLoggerUtils;
import com.hivemq.testcontainer.junit5.HiveMQTestContainerExtension;
Expand All @@ -28,6 +27,8 @@
import org.junit.jupiter.api.Test;
import org.testcontainers.utility.DockerImageName;

import static org.junit.jupiter.api.Assertions.assertEquals;

@Disabled("Tests are only used to check output")
class TestBrokerCommandDefaultIT {

Expand All @@ -50,26 +51,23 @@ static void afterAll() {
}

@Test
@ExpectSystemExitWithStatus(0)
void mqtt3_failed_connect() {
MqttCLIMain.main("test", "-V", "3");
assertEquals(0, MqttCLIMain.mainWithExitCode("test", "-V", "3"));
}

@Test
@ExpectSystemExitWithStatus(0)
void mqtt5_failed_connect() {
MqttCLIMain.main("test", "-V", "5");
assertEquals(0, MqttCLIMain.mainWithExitCode("test", "-V", "5"));
}

@Test
@ExpectSystemExitWithStatus(0)
void mqtt3_features() {
MqttCLIMain.main("test", "-V", "3", "-p", String.valueOf(hivemq.getMqttPort()));
assertEquals(0, MqttCLIMain.mainWithExitCode("test", "-V", "3", "-p", String.valueOf(hivemq.getMqttPort())));
}

@Test
@ExpectSystemExitWithStatus(0)
void mqtt5_features() {
MqttCLIMain.main("test", "-V", "5", "-a", "-p", String.valueOf(hivemq.getMqttPort()));
assertEquals(0,
MqttCLIMain.mainWithExitCode("test", "-V", "5", "-a", "-p", String.valueOf(hivemq.getMqttPort())));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package com.hivemq.cli.commands.cli;

import com.ginsberg.junit.exit.ExpectSystemExitWithStatus;
import com.hivemq.cli.MqttCLIMain;
import com.hivemq.cli.utils.TestLoggerUtils;
import com.hivemq.testcontainer.junit5.HiveMQTestContainerExtension;
Expand All @@ -29,6 +28,8 @@
import org.testcontainers.utility.DockerImageName;
import org.testcontainers.utility.MountableFile;

import static org.junit.jupiter.api.Assertions.assertEquals;

@Disabled("Tests are only used to check output")
class TestBrokerCommandQos0IT {

Expand All @@ -52,14 +53,12 @@ static void afterAll() {
}

@Test
@ExpectSystemExitWithStatus(0)
void qos0_restricted_mqtt3_features() {
MqttCLIMain.main("test", "-V", "3", "-p", String.valueOf(hivemq.getMqttPort()));
assertEquals(0, MqttCLIMain.mainWithExitCode("test", "-V", "3", "-p", String.valueOf(hivemq.getMqttPort())));
}

@Test
@ExpectSystemExitWithStatus(0)
void qos0_restricted_mqtt5_features() {
MqttCLIMain.main("test", "-V", "3", "-p", String.valueOf(hivemq.getMqttPort()));
assertEquals(0, MqttCLIMain.mainWithExitCode("test", "-V", "3", "-p", String.valueOf(hivemq.getMqttPort())));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package com.hivemq.cli.commands.cli;

import com.ginsberg.junit.exit.ExpectSystemExitWithStatus;
import com.hivemq.cli.MqttCLIMain;
import com.hivemq.cli.utils.TestLoggerUtils;
import com.hivemq.testcontainer.junit5.HiveMQTestContainerExtension;
Expand All @@ -29,6 +28,8 @@
import org.testcontainers.utility.DockerImageName;
import org.testcontainers.utility.MountableFile;

import static org.junit.jupiter.api.Assertions.assertEquals;

@Disabled("Tests are only used to check output")
class TestBrokerCommandQos1IT {

Expand All @@ -52,14 +53,13 @@ static void afterAll() {
}

@Test
@ExpectSystemExitWithStatus(0)
void qos1_restricted_mqtt3_features() {
MqttCLIMain.main("test", "-V", "3", "-p", String.valueOf(hivemq.getMqttPort()));
assertEquals(0, MqttCLIMain.mainWithExitCode("test", "-V", "3", "-p", String.valueOf(hivemq.getMqttPort())));
}

@Test
@ExpectSystemExitWithStatus(0)
void qos1_restricted_mqtt5_features() {
MqttCLIMain.main("test", "-V", "5", "-a", "-p", String.valueOf(hivemq.getMqttPort()));
assertEquals(0,
MqttCLIMain.mainWithExitCode("test", "-V", "5", "-a", "-p", String.valueOf(hivemq.getMqttPort())));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package com.hivemq.cli.commands.cli;

import com.ginsberg.junit.exit.ExpectSystemExitWithStatus;
import com.hivemq.cli.MqttCLIMain;
import com.hivemq.cli.utils.TestLoggerUtils;
import com.hivemq.testcontainer.junit5.HiveMQTestContainerExtension;
Expand All @@ -29,6 +28,8 @@
import org.testcontainers.utility.DockerImageName;
import org.testcontainers.utility.MountableFile;

import static org.junit.jupiter.api.Assertions.assertEquals;

@Disabled("Tests are only used to check output")
class TestBrokerCommandRestrictedIT {

Expand All @@ -52,14 +53,13 @@ static void afterAll() {
}

@Test
@ExpectSystemExitWithStatus(0)
void restricted_mqtt3_features() {
MqttCLIMain.main("test", "-V", "3", "-p", String.valueOf(hivemq.getMqttPort()));
assertEquals(0, MqttCLIMain.mainWithExitCode("test", "-V", "3", "-p", String.valueOf(hivemq.getMqttPort())));
}

@Test
@ExpectSystemExitWithStatus(0)
void restricted_mqtt5_features() {
MqttCLIMain.main("test", "-V", "5", "-a", "-p", String.valueOf(hivemq.getMqttPort()));
assertEquals(0,
MqttCLIMain.mainWithExitCode("test", "-V", "5", "-a", "-p", String.valueOf(hivemq.getMqttPort())));
}
}
13 changes: 7 additions & 6 deletions src/main/java/com/hivemq/cli/MqttCLIMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ public class MqttCLIMain {
public static @Nullable MqttCLI MQTT_CLI = null;

public static void main(final @NotNull String... args) {
System.exit(mainWithExitCode(args));
}

public static int mainWithExitCode(final @NotNull String... args) {

Security.setProperty("crypto.policy", "unlimited");

Expand All @@ -50,20 +54,17 @@ public static void main(final @NotNull String... args) {
defaultCLIProperties.init();
} catch (final Exception e) {
System.err.println(e.getMessage());
System.exit(1);
return 1;
}

if (args.length == 0) {
System.out.println(commandLine.getUsageMessage());
System.exit(0);
return 0;
}

Runtime.getRuntime().addShutdownHook(new DisconnectAllClientsTask());

final int exitCode = commandLine.execute(args);

System.exit(exitCode);

return commandLine.execute(args);
}

private static class DisconnectAllClientsTask extends Thread {
Expand Down
15 changes: 6 additions & 9 deletions src/test/java/com/hivemq/cli/MqttCLIMainTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
*/
package com.hivemq.cli;

import com.ginsberg.junit.exit.ExpectSystemExitWithStatus;
import com.hivemq.cli.utils.TestLoggerUtils;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

class MqttCLIMainTest {

@BeforeEach
Expand All @@ -34,26 +35,22 @@ void tearDown() {
}

@Test
@ExpectSystemExitWithStatus(0)
void mqtt_command() {
MqttCLIMain.main();
assertEquals(0, MqttCLIMain.mainWithExitCode());
}

@Test
@ExpectSystemExitWithStatus(0)
void hivemq_command() {
MqttCLIMain.main("hivemq");
assertEquals(0, MqttCLIMain.mainWithExitCode("hivemq"));
}

@Test
@ExpectSystemExitWithStatus(0)
void hivemq_export_command() {
MqttCLIMain.main("hivemq", "export");
assertEquals(0, MqttCLIMain.mainWithExitCode("hivemq", "export"));
}

@Test
@ExpectSystemExitWithStatus(0)
void hivemq_export_clients_help_command() {
MqttCLIMain.main("hivemq", "export", "clients", "-h");
assertEquals(0, MqttCLIMain.mainWithExitCode("hivemq", "export", "clients", "-h"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
package com.hivemq.cli.commands.hivemq.behaviorpolicy;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.hivemq.cli.commands.hivemq.datahub.OutputFormatter;
import com.hivemq.cli.openapi.ApiException;
import com.hivemq.cli.openapi.hivemq.DataHubBehaviorPoliciesApi;
import com.hivemq.cli.rest.HiveMQRestService;
import com.hivemq.cli.utils.TestLoggerUtils;
import com.hivemq.cli.utils.json.OffsetDateTimeSerializer;
import org.jetbrains.annotations.NotNull;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand All @@ -30,6 +32,7 @@
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.time.OffsetDateTime;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
Expand All @@ -42,7 +45,8 @@
public class BehaviorPolicyCreateCommandTest {

private final @NotNull HiveMQRestService hiveMQRestService = mock();
private final @NotNull Gson gson = new Gson();
private final @NotNull Gson gson =
new GsonBuilder().registerTypeAdapter(OffsetDateTime.class, new OffsetDateTimeSerializer()).create();
private final @NotNull OutputFormatter outputFormatter = mock();
private final @NotNull DataHubBehaviorPoliciesApi behaviorPoliciesApi = mock();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
package com.hivemq.cli.commands.hivemq.behaviorpolicy;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.hivemq.cli.commands.hivemq.datahub.OutputFormatter;
import com.hivemq.cli.openapi.ApiException;
import com.hivemq.cli.openapi.hivemq.DataHubBehaviorPoliciesApi;
import com.hivemq.cli.rest.HiveMQRestService;
import com.hivemq.cli.utils.TestLoggerUtils;
import com.hivemq.cli.utils.json.OffsetDateTimeSerializer;
import org.jetbrains.annotations.NotNull;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand All @@ -30,6 +32,7 @@
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.time.OffsetDateTime;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
Expand All @@ -42,7 +45,8 @@
public class BehaviorPolicyUpdateCommandTest {

private final @NotNull HiveMQRestService hiveMQRestService = mock();
private final @NotNull Gson gson = new Gson();
private final @NotNull Gson gson =
new GsonBuilder().registerTypeAdapter(OffsetDateTime.class, new OffsetDateTimeSerializer()).create();
private final @NotNull OutputFormatter outputFormatter = mock();
private final @NotNull DataHubBehaviorPoliciesApi behaviorPoliciesApi = mock(DataHubBehaviorPoliciesApi.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
package com.hivemq.cli.commands.hivemq.datapolicy;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.hivemq.cli.commands.hivemq.datahub.OutputFormatter;
import com.hivemq.cli.openapi.ApiException;
import com.hivemq.cli.openapi.hivemq.DataHubDataPoliciesApi;
import com.hivemq.cli.rest.HiveMQRestService;
import com.hivemq.cli.utils.TestLoggerUtils;
import com.hivemq.cli.utils.json.OffsetDateTimeSerializer;
import org.jetbrains.annotations.NotNull;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand All @@ -30,6 +32,7 @@
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.time.OffsetDateTime;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
Expand All @@ -42,7 +45,8 @@
public class DataPolicyCreateCommandTest {

private final @NotNull HiveMQRestService hiveMQRestService = mock();
private final @NotNull Gson gson = new Gson();
private final @NotNull Gson gson =
new GsonBuilder().registerTypeAdapter(OffsetDateTime.class, new OffsetDateTimeSerializer()).create();
private final @NotNull OutputFormatter outputFormatter = mock();
private final @NotNull DataHubDataPoliciesApi policiesApi = mock();

Expand Down
Loading
Loading