Skip to content
This repository has been archived by the owner on Jun 19, 2024. It is now read-only.

Commit

Permalink
Merge branch 'master' of github.com:1and1/go-gchat-notifier-plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
sfuhrm committed Dec 11, 2023
2 parents c1e94a1 + 0ed80d5 commit 61a4ec8
Show file tree
Hide file tree
Showing 11 changed files with 78 additions and 79 deletions.
16 changes: 8 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>com.oneandone</groupId>
<artifactId>go-gchat-notifier</artifactId>
<version>0.5.9-SNAPSHOT</version>
<version>0.5.10-SNAPSHOT</version>

<name>GoCD GChat Notifier Plugin</name>
<description>GoCD plugin to send notifications to GChat when pipeline states change</description>
Expand Down Expand Up @@ -55,7 +55,7 @@
<dependency>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId>
<version>5.2.3</version>
<version>5.3</version>
</dependency>
<dependency>
<groupId>org.freemarker</groupId>
Expand All @@ -68,12 +68,6 @@
<version>${go.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
Expand All @@ -86,6 +80,12 @@
<version>9.4.53.v20231009</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.10.1</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.ionos.go.plugin.notifier.util.Helper;
import com.thoughtworks.go.plugin.api.logging.Logger;
import lombok.Getter;
import org.junit.Before;
import org.junit.jupiter.api.BeforeEach;

import java.io.IOException;
import java.util.Collections;
Expand All @@ -29,7 +29,7 @@ protected CommonTestBase() {
logger = Logger.getLoggerFor(getClass());
}

@Before
@BeforeEach
public void setupObjects() throws IOException {
this.gson = new Gson();
this.serverInfo = gson.fromJson(Helper.readResource("/serverInfo.json"), Map.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.thoughtworks.go.plugin.api.response.GoApiResponse;
import lombok.Getter;
import org.apache.hc.core5.http.HttpStatus;
import org.junit.Before;
import org.junit.jupiter.api.BeforeEach;

import java.io.IOException;
import java.util.Collections;
Expand All @@ -23,7 +23,7 @@ protected GoNotifierPluginBase() {
logger = Logger.getLoggerFor(getClass());
}

@Before
@BeforeEach
public void setupPlugin() {
this.goNotifierPlugin = new GoNotifierPlugin();
this.goNotifierPlugin.initializeGoApplicationAccessor(new GoApplicationAccessor() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,51 +4,51 @@
import com.ionos.go.plugin.notifier.util.Helper;
import com.thoughtworks.go.plugin.api.response.GoPluginApiResponse;
import org.apache.hc.core5.http.HttpStatus;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;

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


public class GoNotifierPluginStageStatusTest extends GoNotifierPluginBase {

private static EmbeddedHttpServer embeddedHttpServer;
private static int embeddedHttpPort;

@BeforeClass
@BeforeAll
public static void setUpLocalWebServer() {
embeddedHttpServer = new EmbeddedHttpServer().withServlet(GoogleMockServlet.class, "/gchat");
embeddedHttpServer.start();
embeddedHttpPort = embeddedHttpServer.getRunningPort();
}

@Before
@BeforeEach
public void setupConfig() {
getPluginSettings().put(Constants.PARAM_WEBHOOK_URL, "http://localhost:" + embeddedHttpPort + "/gchat");
getPluginSettings().put(Constants.PARAM_CONDITION, "true");
getPluginSettings().put(Constants.PARAM_TEMPLATE, "${stageStatus.pipeline.group}");
}

@Before
@BeforeEach
public void initServlet() {
GoogleMockServlet.reset();
GoogleMockServlet.setStatusToReturn(HttpStatus.SC_OK);
}

@AfterClass
@AfterAll
public static void stopLocalWebServer() {
embeddedHttpServer.stop();
}

@Test
public void testHandleStageStatusNoSendingConditionFalse() throws IOException {
void testHandleStageStatusNoSendingConditionFalse() throws IOException {
String stageStatusJson = Helper.readResource("/stageStatus.json");
getPluginSettings().put(Constants.PARAM_CONDITION, "false");

Expand All @@ -66,7 +66,7 @@ public void testHandleStageStatusNoSendingConditionFalse() throws IOException {
}

@Test
public void testHandleStageStatusGoodWeather() throws IOException {
void testHandleStageStatusGoodWeather() throws IOException {
String stageStatusJson = Helper.readResource("/stageStatus.json");

GoPluginApiResponse response = getGoNotifierPlugin().handle(
Expand All @@ -85,7 +85,7 @@ public void testHandleStageStatusGoodWeather() throws IOException {
}

@Test
public void testHandleStageStatusWithRemoteBadRequest() throws IOException {
void testHandleStageStatusWithRemoteBadRequest() throws IOException {
GoogleMockServlet.setStatusToReturn(HttpStatus.SC_BAD_REQUEST);
String stageStatusJson = Helper.readResource("/stageStatus.json");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,27 @@

import com.thoughtworks.go.plugin.api.response.GoPluginApiResponse;
import org.apache.hc.core5.http.HttpStatus;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import java.util.Collections;
import java.util.Map;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;


public class GoNotifierPluginTest extends GoNotifierPluginBase {

@Test
public void testPluginIdentifier() {
void testPluginIdentifier() {
assertEquals("notification", getGoNotifierPlugin().pluginIdentifier().getExtension());
assertTrue(getGoNotifierPlugin().pluginIdentifier().getSupportedExtensionVersions().contains("4.0"));
}

@Test
public void testHandleNotificationsInterestedIn() {
void testHandleNotificationsInterestedIn() {
// request get conf
GoPluginApiResponse response = getGoNotifierPlugin().handle(GoCdObjects.request(Constants.PLUGIN_NOTIFICATIONS_INTERESTED_IN, null));
assertNotNull(response);
Expand All @@ -32,26 +32,26 @@ public void testHandleNotificationsInterestedIn() {
}

@Test
public void testHandleGetView() {
void testHandleGetView() {
GoPluginApiResponse response = getGoNotifierPlugin().handle(GoCdObjects.request(Constants.PLUGIN_GET_VIEW, null));
assertNotNull(response);
assertEquals(HttpStatus.SC_OK, response.responseCode());
assertEquals(Collections.emptyMap(), response.responseHeaders());
assertFalse("needs to be non empty", response.responseBody().isEmpty());
assertFalse("needs to contain input html element", response.responseBody().contains("<input"));
assertFalse(response.responseBody().isEmpty(), "needs to be non empty");
assertFalse(response.responseBody().contains("<input"), "needs to contain input html element");
}

@Test
public void testHandleGetConfiguration() {
void testHandleGetConfiguration() {
GoPluginApiResponse response = getGoNotifierPlugin().handle(
GoCdObjects.request(Constants.PLUGIN_GET_CONFIGURATION, null));
assertNotNull(response);
assertEquals(HttpStatus.SC_OK, response.responseCode());
assertEquals(Collections.emptyMap(), response.responseHeaders());
Map<String, Object> map = getGson().fromJson(response.responseBody(), Map.class);
assertTrue("contains a config key", map.containsKey(Constants.PARAM_CONDITION));
assertTrue("contains a config key", map.containsKey(Constants.PARAM_TEMPLATE));
assertTrue("contains a config key", map.containsKey(Constants.PARAM_PROXY_URL));
assertTrue("contains a config key", map.containsKey(Constants.PARAM_WEBHOOK_URL));
assertTrue(map.containsKey(Constants.PARAM_CONDITION), "contains a config key");
assertTrue(map.containsKey(Constants.PARAM_TEMPLATE), "contains a config key");
assertTrue(map.containsKey(Constants.PARAM_PROXY_URL), "contains a config key");
assertTrue(map.containsKey(Constants.PARAM_WEBHOOK_URL), "contains a config key");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,28 @@
import com.ionos.go.plugin.notifier.message.outgoing.ValidateConfigurationResponse;
import com.thoughtworks.go.plugin.api.response.GoPluginApiResponse;
import org.apache.hc.core5.http.HttpStatus;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class GoNotifierPluginValidateConfigurationTest extends GoNotifierPluginBase {

private ValidateConfigurationRequest request;

@Before
@BeforeEach
public void setupTest() {
request = new ValidateConfigurationRequest();
}

@Test
public void testHandleValidateConfigurationWithBadRequest() {
void testHandleValidateConfigurationWithBadRequest() {
GoPluginApiResponse response = getGoNotifierPlugin().handle(
GoCdObjects.request(Constants.PLUGIN_VALIDATE_CONFIGURATION, getGson().toJson(request)));
assertNotNull(response);
Expand All @@ -34,7 +34,7 @@ public void testHandleValidateConfigurationWithBadRequest() {
}

@Test
public void testHandleValidateConfigurationWithGoodRequestMultipleErrors() {
void testHandleValidateConfigurationWithGoodRequestMultipleErrors() {
request.setPluginSettings(new HashMap<>());
GoPluginApiResponse response = getGoNotifierPlugin().handle(
GoCdObjects.request(Constants.PLUGIN_VALIDATE_CONFIGURATION, getGson().toJson(request)));
Expand All @@ -47,7 +47,7 @@ public void testHandleValidateConfigurationWithGoodRequestMultipleErrors() {
}

@Test
public void testHandleValidateConfigurationWithGoodRequestNoErrors() {
void testHandleValidateConfigurationWithGoodRequestNoErrors() {
Map<String, Map<String, String>> pluginSettings = newGoodPluginSettingsTemplate();
request.setPluginSettings(pluginSettings);
GoPluginApiResponse response = getGoNotifierPlugin().handle(
Expand All @@ -60,7 +60,7 @@ public void testHandleValidateConfigurationWithGoodRequestNoErrors() {
}

@Test
public void testHandleValidateConfigurationWithMalformedCondition() {
void testHandleValidateConfigurationWithMalformedCondition() {
Map<String, Map<String, String>> pluginSettings = newGoodPluginSettingsTemplate();
pluginSettings.put(Constants.PARAM_CONDITION, Collections.singletonMap(Constants.FIELD_VALUE, "${ error"));
request.setPluginSettings(pluginSettings);
Expand All @@ -75,7 +75,7 @@ public void testHandleValidateConfigurationWithMalformedCondition() {
}

@Test
public void testHandleValidateConfigurationWithMalformedTemplate() {
void testHandleValidateConfigurationWithMalformedTemplate() {
Map<String, Map<String, String>> pluginSettings = newGoodPluginSettingsTemplate();
pluginSettings.put(Constants.PARAM_TEMPLATE, Collections.singletonMap(Constants.FIELD_VALUE, "${ error"));
request.setPluginSettings(pluginSettings);
Expand All @@ -90,7 +90,7 @@ public void testHandleValidateConfigurationWithMalformedTemplate() {
}

@Test
public void testHandleValidateConfigurationWithTemplateAccessingUndefinedProperty() {
void testHandleValidateConfigurationWithTemplateAccessingUndefinedProperty() {
Map<String, Map<String, String>> pluginSettings = newGoodPluginSettingsTemplate();
pluginSettings.put(Constants.PARAM_TEMPLATE, Collections.singletonMap(Constants.FIELD_VALUE, "${ doesntexist.foobar }"));
request.setPluginSettings(pluginSettings);
Expand All @@ -105,7 +105,7 @@ public void testHandleValidateConfigurationWithTemplateAccessingUndefinedPropert
}

@Test
public void testHandleValidateConfigurationWithConditionAccessingUndefinedProperty() {
void testHandleValidateConfigurationWithConditionAccessingUndefinedProperty() {
Map<String, Map<String, String>> pluginSettings = newGoodPluginSettingsTemplate();
pluginSettings.put(Constants.PARAM_CONDITION, Collections.singletonMap(Constants.FIELD_VALUE, "${ doesntexist.foobar }"));
request.setPluginSettings(pluginSettings);
Expand All @@ -120,7 +120,7 @@ public void testHandleValidateConfigurationWithConditionAccessingUndefinedProper
}

@Test
public void testHandleValidateConfigurationWithConditionNotTrueOrFalse() {
void testHandleValidateConfigurationWithConditionNotTrueOrFalse() {
Map<String, Map<String, String>> pluginSettings = newGoodPluginSettingsTemplate();
pluginSettings.put(Constants.PARAM_CONDITION, Collections.singletonMap(Constants.FIELD_VALUE, "tralse"));
request.setPluginSettings(pluginSettings);
Expand All @@ -132,11 +132,11 @@ public void testHandleValidateConfigurationWithConditionNotTrueOrFalse() {
ValidateConfigurationResponse[] validateConfigurationResponses = getGson().fromJson(response.responseBody(), ValidateConfigurationResponse[].class);
assertEquals(1, validateConfigurationResponses.length);
assertEquals(Constants.PARAM_CONDITION, validateConfigurationResponses[0].getKey());
assertTrue("Should contain 'true or false'", validateConfigurationResponses[0].getMessage().contains("true or false"));
assertTrue(validateConfigurationResponses[0].getMessage().contains("true or false"), "Should contain 'true or false'");
}

@Test
public void testHandleValidateConfigurationWithMalformedProxyUrl() {
void testHandleValidateConfigurationWithMalformedProxyUrl() {
Map<String, Map<String, String>> pluginSettings = newGoodPluginSettingsTemplate();
pluginSettings.put(Constants.PARAM_PROXY_URL, Collections.singletonMap(Constants.FIELD_VALUE, "hppt://foo.bar"));
request.setPluginSettings(pluginSettings);
Expand All @@ -152,7 +152,7 @@ public void testHandleValidateConfigurationWithMalformedProxyUrl() {
}

@Test
public void testHandleValidateConfigurationWithMalformedWebhookUrl() {
void testHandleValidateConfigurationWithMalformedWebhookUrl() {
Map<String, Map<String, String>> pluginSettings = newGoodPluginSettingsTemplate();
pluginSettings.put(Constants.PARAM_WEBHOOK_URL, Collections.singletonMap(Constants.FIELD_VALUE, "hppt://foo.bar"));
request.setPluginSettings(pluginSettings);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@
import com.thoughtworks.go.plugin.api.request.GoPluginApiRequest;
import com.thoughtworks.go.plugin.api.response.GoPluginApiResponse;
import org.apache.hc.core5.http.HttpStatus;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import java.io.IOException;

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


public class StageStatusHandlerTest extends CommonTestBase {

@Test
public void testInit() {
void testInit() {
StageStatusHandler handler = new StageStatusHandler(getServerInfo(), getPluginSettings());
}

@Test
public void testHandle() throws IOException {
void testHandle() throws IOException {
String stageStatusJson = Helper.readResource("/stageStatus.json");
GoPluginApiRequest request = GoCdObjects.request(Constants.PLUGIN_STAGE_STATUS, stageStatusJson);
StageStatusHandler handler = new StageStatusHandler(getServerInfo(), getPluginSettings());
Expand Down
Loading

0 comments on commit 61a4ec8

Please sign in to comment.