From 0588b32c2932bd04bf91d4f796d5c2b5044a3677 Mon Sep 17 00:00:00 2001 From: Eden Zimbelman Date: Wed, 17 Dec 2025 11:31:06 -0800 Subject: [PATCH 1/5] test: include unit tests to confirm listeners acknowledge events --- .gitignore | 1 + README.md | 24 +++++++------ .../CustomStepButtonActionListenerTest.java | 32 +++++++++++++++++ .../functions/SampleStepListenerTest.java | 34 +++++++++++++++++++ 4 files changed, 80 insertions(+), 11 deletions(-) create mode 100644 src/test/java/listeners/actions/CustomStepButtonActionListenerTest.java create mode 100644 src/test/java/listeners/functions/SampleStepListenerTest.java diff --git a/.gitignore b/.gitignore index 201337d..ceab5b9 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ .idea/ .env artifacts/ +bin src/main/webapp/WEB-INF/classes/ src/main/webapp/WEB-INF/lib/ *.iml diff --git a/README.md b/README.md index e2b978a..8ca27de 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Bolt for Java Custom Step Template This is a Bolt for Java template app used to build custom steps for use in -[Workflow Builder](https://api.slack.com/start#workflow-builder). +[Workflow Builder](https://docs.slack.dev/workflows/workflow-builder/). ## Setup @@ -22,9 +22,9 @@ tooling, and resources created to help developers build and grow. 1. Open [https://api.slack.com/apps/new](https://api.slack.com/apps/new) and choose "From an app manifest" 2. Choose the workspace you want to install the application to -3. Copy the contents of [manifest.json](./manifest.json) into the text box that says `*Paste your manifest code here*` (within the JSON tab) and click *Next* -4. Review the configuration and click *Create* -5. Click *Install to Workspace* and *Allow* on the screen that follows. You'll then be redirected to the App Configuration dashboard. +3. Copy the contents of [manifest.json](./manifest.json) into the text box that says `*Paste your manifest code here*` (within the JSON tab) and click _Next_ +4. Review the configuration and click _Create_ +5. Click _Install to Workspace_ and _Allow_ on the screen that follows. You'll then be redirected to the App Configuration dashboard. #### Environment Variables @@ -43,16 +43,17 @@ export SLACK_APP_TOKEN= ```zsh # Clone this project onto your machine -git clone https://github.com/WilliamBergamin/bolt-java-custom-step-template.git +git clone https://github.com/slack-samples/bolt-java-custom-step-template.git # Change into this project directory -cd bolt-java-template +cd bolt-java-custom-step-template ``` #### Maven: Run Ensure [maven](https://maven.apache.org/index.html) is installed on your local environment. -* We recommend using [brew to install Maven on macOS](https://formulae.brew.sh/formula/maven) + +- We recommend using [brew to install Maven on macOS](https://formulae.brew.sh/formula/maven) ```zsh # Install the dependencies and compile @@ -68,14 +69,15 @@ mvn clean test mvn clean compile exec:java -Dexec.mainClass="Main" ``` -**NOTE**: If you chose to use Maven as your build tool you can remove the `builde.gradle` file from this project. +**NOTE**: If you chose to use Maven as your build tool you can remove the `build.gradle` file from this project. ------- +--- #### Gradle: Run Ensure [gradle](https://gradle.org/) is installed on your local environment. -* We recommend using [brew to install Gradle on macOS](https://formulae.brew.sh/formula/gradle) + +- We recommend using [brew to install Gradle on macOS](https://formulae.brew.sh/formula/gradle) ```zsh # Run tests @@ -93,7 +95,7 @@ gradle run ## Using Steps in Workflow Builder With your server running, the `Sample step` is now ready for use in -[Workflow Builder](https://api.slack.com/start#workflow-builder)! Add it as a +[Workflow Builder](https://docs.slack.dev/workflows/workflow-builder/)! Add it as a custom step in a new or existing workflow, then run the workflow while your app is running. diff --git a/src/test/java/listeners/actions/CustomStepButtonActionListenerTest.java b/src/test/java/listeners/actions/CustomStepButtonActionListenerTest.java new file mode 100644 index 0000000..10dd6c0 --- /dev/null +++ b/src/test/java/listeners/actions/CustomStepButtonActionListenerTest.java @@ -0,0 +1,32 @@ +package listeners.actions; + +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.mockito.Mockito.*; + +import com.slack.api.bolt.App; +import com.slack.api.bolt.context.builtin.ActionContext; +import com.slack.api.bolt.request.builtin.BlockActionRequest; +import com.slack.api.methods.SlackApiException; +import java.io.IOException; +import org.junit.jupiter.api.Test; + +public class CustomStepButtonActionListenerTest { + + @Test + public void testApply() throws IOException, SlackApiException { + // Given + var app = new App(); + var reqMock = mock(BlockActionRequest.class); + var ctxMock = mock(ActionContext.class); + + when(ctxMock.ack()).thenReturn(mock(com.slack.api.bolt.response.Response.class)); + + // When + var customStepButtonActionListener = new CustomStepButtonActionListener(app); + var res = customStepButtonActionListener.apply(reqMock, ctxMock); + + // Then + verify(ctxMock).ack(); + assertNotNull(res); + } +} diff --git a/src/test/java/listeners/functions/SampleStepListenerTest.java b/src/test/java/listeners/functions/SampleStepListenerTest.java new file mode 100644 index 0000000..04d3ad0 --- /dev/null +++ b/src/test/java/listeners/functions/SampleStepListenerTest.java @@ -0,0 +1,34 @@ +package listeners.functions; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.Mockito.*; + +import com.slack.api.app_backend.events.payload.EventsApiPayload; +import com.slack.api.bolt.App; +import com.slack.api.bolt.context.builtin.EventContext; +import com.slack.api.bolt.response.Response; +import com.slack.api.model.event.FunctionExecutedEvent; +import org.junit.jupiter.api.Test; + +public class SampleStepListenerTest { + + @Test + public void testApply() { + // Given + var plMock = (EventsApiPayload) mock(EventsApiPayload.class); + var ctxMock = mock(EventContext.class); + + var responseMock = mock(Response.class); + when(responseMock.getStatusCode()).thenReturn(200); + when(ctxMock.ack()).thenReturn(responseMock); + + // When + var app = new App(); + var sampleStepListener = new SampleStepListener(app); + var res = sampleStepListener.apply(plMock, ctxMock); + + // Then + verify(ctxMock).ack(); + assertEquals(res.getStatusCode(), 200); + } +} From 5d9cb118c9d1cb4faf2cf9ca98223e60c45720ad Mon Sep 17 00:00:00 2001 From: Eden Zimbelman Date: Wed, 17 Dec 2025 11:36:31 -0800 Subject: [PATCH 2/5] style: use a trailing slash for directories ignored --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index ceab5b9..312a64f 100644 --- a/.gitignore +++ b/.gitignore @@ -7,7 +7,7 @@ .idea/ .env artifacts/ -bin +bin/ src/main/webapp/WEB-INF/classes/ src/main/webapp/WEB-INF/lib/ *.iml From 57de7cacafa4ba4619ebb7860450eeb8dd0aba8c Mon Sep 17 00:00:00 2001 From: Eden Zimbelman Date: Wed, 17 Dec 2025 11:49:24 -0800 Subject: [PATCH 3/5] ci: complete all jobs in a matrix regardless of failures prior --- .github/workflows/gradle.yml | 1 + .github/workflows/mvn.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 97eb5e7..ebce907 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -9,6 +9,7 @@ jobs: gradle: runs-on: ubuntu-latest strategy: + fail-fast: false matrix: java-version: - 17 diff --git a/.github/workflows/mvn.yml b/.github/workflows/mvn.yml index 2107716..bab3fbc 100644 --- a/.github/workflows/mvn.yml +++ b/.github/workflows/mvn.yml @@ -9,6 +9,7 @@ jobs: mvn: runs-on: ubuntu-latest strategy: + fail-fast: false matrix: java-version: - 17 From d677c65af68a18a8b8c000606f57c310bc8339ad Mon Sep 17 00:00:00 2001 From: Eden Zimbelman Date: Wed, 17 Dec 2025 12:00:09 -0800 Subject: [PATCH 4/5] build: update to java version 17 for gradle builds --- build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index ef0caf4..898c9c2 100644 --- a/build.gradle +++ b/build.gradle @@ -4,8 +4,8 @@ plugins { } java { - sourceCompatibility = JavaVersion.VERSION_11 - targetCompatibility = JavaVersion.VERSION_11 + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 } repositories { From 719c450466cb8f09b8e6191edc43b81184e43cb6 Mon Sep 17 00:00:00 2001 From: Eden Zimbelman Date: Wed, 17 Dec 2025 12:09:08 -0800 Subject: [PATCH 5/5] build: use current leading spaces formatting settings --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 898c9c2..6baf188 100644 --- a/build.gradle +++ b/build.gradle @@ -43,7 +43,7 @@ spotless { format 'misc', { target '*.gradle', '.gitignore' trimTrailingWhitespace() - indentWithTabs(4) + leadingSpacesToTabs(4) endWithNewline() } java {