Skip to content
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: 2 additions & 2 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ jobs:

steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Set up JDK 11
- name: Set up JDK 21
uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5.2.0
with:
distribution: 'zulu'
java-version: '11'
java-version: '21'
- name: Build and test with Maven
run: mvn checkstyle:check javadoc:javadoc test package
- name: Get branch name or tag
Expand Down
40 changes: 19 additions & 21 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
</licenses>
<developers>
<developer>
<name>Johannes Renner</name>
<email>jrenner@suse.com</email>
<name>Johannes Hahn</name>
<email>johannes.hahn@suse.com</email>
<url>https://github.com/renner</url>
</developer>
<developer>
Expand All @@ -38,20 +38,18 @@
<build>
<plugins>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.13</version>
<groupId>org.sonatype.central</groupId>
<artifactId>central-publishing-maven-plugin</artifactId>
<version>0.10.0</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>false</autoReleaseAfterClose>
<publishingServerId>central</publishingServerId>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>3.2.4</version>
<version>3.2.8</version>
<executions>
<execution>
<id>sign-artifacts</id>
Expand All @@ -65,7 +63,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.3.1</version>
<version>3.4.0</version>
<executions>
<execution>
<id>attach-sources</id>
Expand All @@ -78,15 +76,15 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
<version>3.15.0</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.6.3</version>
<version>3.12.0</version>
<configuration>
<source>11</source>
</configuration>
Expand All @@ -102,12 +100,12 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.3.1</version>
<version>3.6.0</version>
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>8.29</version>
<version>13.3.0</version>
</dependency>
</dependencies>
<configuration>
Expand All @@ -122,7 +120,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.2.5</version>
<version>3.5.5</version>
</plugin>
</plugins>
</build>
Expand All @@ -135,7 +133,7 @@
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpasyncclient</artifactId>
<version>4.1.3</version>
<version>4.1.5</version>
</dependency>
<dependency>
<groupId>jakarta.websocket</groupId>
Expand All @@ -152,25 +150,25 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.tomakehurst</groupId>
<groupId>org.wiremock</groupId>
<artifactId>wiremock</artifactId>
<version>2.5.1</version>
<version>3.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
<version>1.7.12</version>
<version>2.0.17</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish.tyrus</groupId>
<artifactId>tyrus-container-grizzly-server</artifactId>
<version>2.2.0</version>
<version>2.2.2</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/suse/salt/netapi/calls/modules/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ private Config() { }
*/
public static LocalCall<String> get(String key) {
return new LocalCall<>(
"config.get",
Optional.of(Arrays.asList(key)),
Optional.empty(),
new TypeToken<String>() { });
"config.get",
Optional.of(Arrays.asList(key)),
Optional.empty(),
new TypeToken<String>() { });
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static LocalCall<Map<String, Object>> setValue(String key, String value,
args.put("val", value);
destructive.ifPresent(dest -> { args.put("destructive", dest); });
return new LocalCall<>("grains.setval", Optional.empty(), Optional.of(args),
new TypeToken<Map<String, Object>>() { });
new TypeToken<Map<String, Object>>() { });
}

public static LocalCall<Map<String, Object>> setValues(Map<String, Object> grains, Optional<Boolean> destructive) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,6 @@ public static LocalCall<Map<String, Map<String, Object>>> list(boolean show_all)
args.put("show_all", show_all);
args.put("return_yaml", false);
return new LocalCall<>("schedule.list", Optional.empty(), Optional.of(args),
new TypeToken<Map<String, Map<String, Object>>>(){});
new TypeToken<Map<String, Map<String, Object>>>(){});
}
}
10 changes: 5 additions & 5 deletions src/main/java/com/suse/salt/netapi/calls/modules/Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,23 @@ public class Test {

private static final LocalCall<Boolean> PING =
new LocalCall<>("test.ping", Optional.empty(), Optional.empty(),
new TypeToken<Boolean>(){});
new TypeToken<Boolean>(){});

private static final LocalCall<String> MISSING_FUNC =
new LocalCall<>("test.missing_func", Optional.empty(), Optional.empty(),
new TypeToken<String>(){});
new TypeToken<String>(){});

private static final LocalCall<VersionInformation> VERSIONS_INFORMATION =
new LocalCall<>("test.versions_information", Optional.empty(), Optional.empty(),
new TypeToken<VersionInformation>(){});
new TypeToken<VersionInformation>(){});

private static final LocalCall<ModuleReport> MODULE_REPORT =
new LocalCall<>("test.module_report", Optional.empty(), Optional.empty(),
new TypeToken<ModuleReport>(){});
new TypeToken<ModuleReport>(){});

private static final LocalCall<Map<String, String>> PROVIDERS =
new LocalCall<>("test.providers", Optional.empty(), Optional.empty(),
new TypeToken<Map<String, String>>(){});
new TypeToken<Map<String, String>>(){});

/**
* Availability report of all execution modules
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ private Minions() {

private static final WheelCall<List<String>> CONNECTED =
new WheelCall<>("minions.connected", Optional.empty(),
new TypeToken<List<String>>(){});
new TypeToken<List<String>>(){});

public static WheelCall<List<String>> connected() {
return CONNECTED;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ public AuthModule getModule() {
@Override
public String toString() {
return "PasswordAuth(username = " + username +
", password = <REDACTED>, authModule = " + module.getValue() + ")";
", password = <REDACTED>, authModule = " + module.getValue() + ")";
}
}
176 changes: 88 additions & 88 deletions src/test/java/com/suse/salt/netapi/calls/runner/EventTest.java
Original file line number Diff line number Diff line change
@@ -1,88 +1,88 @@
package com.suse.salt.netapi.calls.runner;
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
import static com.github.tomakehurst.wiremock.client.WireMock.any;
import static com.github.tomakehurst.wiremock.client.WireMock.equalTo;
import static com.github.tomakehurst.wiremock.client.WireMock.equalToJson;
import static com.github.tomakehurst.wiremock.client.WireMock.postRequestedFor;
import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching;
import static com.github.tomakehurst.wiremock.client.WireMock.verify;
import static org.junit.Assert.assertTrue;
import com.github.tomakehurst.wiremock.junit.WireMockRule;
import com.suse.salt.netapi.calls.modules.SaltUtilTest;
import com.suse.salt.netapi.client.SaltClient;
import com.suse.salt.netapi.client.impl.HttpAsyncClientImpl;
import com.suse.salt.netapi.datatypes.AuthMethod;
import com.suse.salt.netapi.datatypes.Token;
import com.suse.salt.netapi.utils.ClientUtils;
import com.suse.salt.netapi.utils.TestUtils;
import org.apache.http.impl.nio.client.CloseableHttpAsyncClient;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URI;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
/**
* Tests for salt.runners.event
*/
public class EventTest {
private static final int MOCK_HTTP_PORT = 8888;
static final String JSON_EVENT_SEND_REQUEST = ClientUtils.streamToString(
SaltUtilTest.class.getResourceAsStream("/runner/event_send_request.json"));
static final String JSON_EVENT_SEND_RESPONSE = ClientUtils.streamToString(
SaltUtilTest.class.getResourceAsStream("/runner/event_send_response.json"));
@Rule
public WireMockRule wireMockRule = new WireMockRule(MOCK_HTTP_PORT);
static final AuthMethod AUTH = new AuthMethod(new Token());
private SaltClient client;
private CloseableHttpAsyncClient closeableHttpAsyncClient;
@Before
public void init() {
URI uri = URI.create("http://localhost:" + MOCK_HTTP_PORT);
closeableHttpAsyncClient = TestUtils.defaultClient();
client = new SaltClient(uri, new HttpAsyncClientImpl(closeableHttpAsyncClient));
}
@After
public void cleanup() throws IOException {
closeableHttpAsyncClient.close();
}
@Test
public void testEventSend() {
stubFor(any(urlMatching("/"))
.willReturn(aResponse().withStatus(HttpURLConnection.HTTP_OK)
.withHeader("Content-Type", "application/json")
.withBody(JSON_EVENT_SEND_RESPONSE)));
Map<String, Object> data = new HashMap<>();
data.put("foo", "bar");
data.put("some-value", 2);
boolean success = Event.send("my/custom/event", Optional.of(data))
.callSync(client, AUTH).toCompletableFuture().join().result().get();
assertTrue(success);
verify(1, postRequestedFor(urlEqualTo("/"))
.withHeader("Accept", equalTo("application/json"))
.withHeader("Content-Type", equalTo("application/json; charset=UTF-8"))
.withRequestBody(equalToJson(JSON_EVENT_SEND_REQUEST)));
}
}
package com.suse.salt.netapi.calls.runner;

import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
import static com.github.tomakehurst.wiremock.client.WireMock.any;
import static com.github.tomakehurst.wiremock.client.WireMock.equalTo;
import static com.github.tomakehurst.wiremock.client.WireMock.equalToJson;
import static com.github.tomakehurst.wiremock.client.WireMock.postRequestedFor;
import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching;
import static com.github.tomakehurst.wiremock.client.WireMock.verify;
import static org.junit.Assert.assertTrue;

import com.github.tomakehurst.wiremock.junit.WireMockRule;
import com.suse.salt.netapi.calls.modules.SaltUtilTest;
import com.suse.salt.netapi.client.SaltClient;
import com.suse.salt.netapi.client.impl.HttpAsyncClientImpl;
import com.suse.salt.netapi.datatypes.AuthMethod;
import com.suse.salt.netapi.datatypes.Token;
import com.suse.salt.netapi.utils.ClientUtils;
import com.suse.salt.netapi.utils.TestUtils;
import org.apache.http.impl.nio.client.CloseableHttpAsyncClient;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URI;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

/**
* Tests for salt.runners.event
*/
public class EventTest {

private static final int MOCK_HTTP_PORT = 8888;

static final String JSON_EVENT_SEND_REQUEST = ClientUtils.streamToString(
SaltUtilTest.class.getResourceAsStream("/runner/event_send_request.json"));
static final String JSON_EVENT_SEND_RESPONSE = ClientUtils.streamToString(
SaltUtilTest.class.getResourceAsStream("/runner/event_send_response.json"));

@Rule
public WireMockRule wireMockRule = new WireMockRule(MOCK_HTTP_PORT);

static final AuthMethod AUTH = new AuthMethod(new Token());

private SaltClient client;

private CloseableHttpAsyncClient closeableHttpAsyncClient;

@Before
public void init() {
URI uri = URI.create("http://localhost:" + MOCK_HTTP_PORT);
closeableHttpAsyncClient = TestUtils.defaultClient();
client = new SaltClient(uri, new HttpAsyncClientImpl(closeableHttpAsyncClient));
}

@After
public void cleanup() throws IOException {
closeableHttpAsyncClient.close();
}

@Test
public void testEventSend() {
stubFor(any(urlMatching("/"))
.willReturn(aResponse().withStatus(HttpURLConnection.HTTP_OK)
.withHeader("Content-Type", "application/json")
.withBody(JSON_EVENT_SEND_RESPONSE)));

Map<String, Object> data = new HashMap<>();
data.put("foo", "bar");
data.put("some-value", 2);

boolean success = Event.send("my/custom/event", Optional.of(data))
.callSync(client, AUTH).toCompletableFuture().join().result().get();

assertTrue(success);
verify(1, postRequestedFor(urlEqualTo("/"))
.withHeader("Accept", equalTo("application/json"))
.withHeader("Content-Type", equalTo("application/json; charset=UTF-8"))
.withRequestBody(equalToJson(JSON_EVENT_SEND_REQUEST)));
}
}
Loading