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

feat: bump SDK to 0.3.0 #21

Merged
merged 6 commits into from
Nov 15, 2022
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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ provides more details on relocations.
}
```

### Error codes

| Code | Description |
| - | - |
| FAIL | Message starts with 'fail' (ignoring case) |

## Test locally

Run unit tests
Expand Down
15 changes: 15 additions & 0 deletions element-templates/template-connector.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
{
"id": "output",
"label": "Output Mapping"
},
{
"id": "errors",
"label": "Error Handling"
}
],
"properties": [
Expand Down Expand Up @@ -101,6 +105,17 @@
"type": "zeebe:taskHeader",
"key": "resultExpression"
}
},
{
"label": "Error Expression",
"description": "Expression to define BPMN Errors to throw",
"group": "errors",
"type": "Text",
"feel": "required",
"binding": {
"type": "zeebe:taskHeader",
"key": "errorExpression"
}
}
]
}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

<!-- connector SDK version -->
<version.connector-core>0.2.2</version.connector-core>
<version.connector-core>0.3.0</version.connector-core>
tmetzke marked this conversation as resolved.
Show resolved Hide resolved

<!-- external libraries -->
<version.assertj>3.23.1</version.assertj>
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/camunda/connector/Authentication.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package io.camunda.connector;

import io.camunda.connector.api.annotation.Secret;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.Pattern;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.Pattern;

import java.util.Objects;

Expand Down
7 changes: 6 additions & 1 deletion src/main/java/io/camunda/connector/MyConnectorFunction.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.camunda.connector;

import io.camunda.connector.api.annotation.OutboundConnector;
import io.camunda.connector.api.error.ConnectorException;
import io.camunda.connector.api.outbound.OutboundConnectorContext;
import io.camunda.connector.api.outbound.OutboundConnectorFunction;
import org.slf4j.Logger;
Expand All @@ -27,8 +28,12 @@ public Object execute(OutboundConnectorContext context) throws Exception {
private MyConnectorResult executeConnector(final MyConnectorRequest connectorRequest) {
// TODO: implement connector logic
LOGGER.info("Executing my connector with request {}", connectorRequest);
String message = connectorRequest.getMessage();
if (message != null && message.toLowerCase().startsWith("fail")) {
throw new ConnectorException("FAIL", "My property started with 'fail', was: " + message);
}
var result = new MyConnectorResult();
result.setMyProperty("Message received: " + connectorRequest.getMessage());
result.setMyProperty("Message received: " + message);
return result;
}
}
6 changes: 3 additions & 3 deletions src/main/java/io/camunda/connector/MyConnectorRequest.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package io.camunda.connector;

import io.camunda.connector.api.annotation.Secret;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;

import java.util.Objects;

Expand Down
24 changes: 24 additions & 0 deletions src/test/java/io/camunda/connector/MyFunctionTest.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package io.camunda.connector;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.catchThrowable;

import io.camunda.connector.api.error.ConnectorException;
import io.camunda.connector.test.outbound.OutboundConnectorContextBuilder;
import org.junit.jupiter.api.Test;

Expand All @@ -28,4 +30,26 @@ void shouldReturnReceivedMessageWhenExecute() throws Exception {
.extracting("myProperty")
.isEqualTo("Message received: Hello World!");
}

@Test
void shouldThrowWithErrorCodeWhenMessageStartsWithFail() {
// given
var input = new MyConnectorRequest();
var auth = new Authentication();
input.setMessage("Fail: unauthorized");
input.setAuthentication(auth);
auth.setToken("xobx-test");
auth.setUser("testuser");
var function = new MyConnectorFunction();
var context = OutboundConnectorContextBuilder.create()
.variables(input)
.build();
// when
var result = catchThrowable(() -> function.execute(context));
// then
assertThat(result)
.isInstanceOf(ConnectorException.class)
.hasMessageContaining("started with 'fail'")
.extracting("errorCode").isEqualTo("FAIL");
}
}