Skip to content

Commit

Permalink
feat: bump SDK to 0.3.0 (#21)
Browse files Browse the repository at this point in the history
* bumps SDK to 0.3.0
* adds error codes
* adds BPMN Error handling to element template
* adjusts validation annotations from `jakarta.validation` to `javax.validation`
  • Loading branch information
tmetzke authored Nov 15, 2022
1 parent c7a6556 commit 998c409
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 7 deletions.
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>

<!-- 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");
}
}

0 comments on commit 998c409

Please sign in to comment.