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
1 change: 1 addition & 0 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ jobs:
gradle:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
java-version:
- 17
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/mvn.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ jobs:
mvn:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
java-version:
- 17
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
.idea/
.env
artifacts/
bin/
src/main/webapp/WEB-INF/classes/
src/main/webapp/WEB-INF/lib/
*.iml
Expand Down
24 changes: 13 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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

Expand All @@ -43,16 +43,17 @@ export SLACK_APP_TOKEN=<your-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
Expand All @@ -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
Expand All @@ -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.

Expand Down
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ plugins {
}

java {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}

repositories {
Expand Down Expand Up @@ -43,7 +43,7 @@ spotless {
format 'misc', {
target '*.gradle', '.gitignore'
trimTrailingWhitespace()
indentWithTabs(4)
leadingSpacesToTabs(4)
endWithNewline()
}
java {
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
34 changes: 34 additions & 0 deletions src/test/java/listeners/functions/SampleStepListenerTest.java
Original file line number Diff line number Diff line change
@@ -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<FunctionExecutedEvent>) 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);
}
}