-
Notifications
You must be signed in to change notification settings - Fork 225
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
205 additions
and
1 deletion.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
...-integration-test/src/main/java/org/kie/kogito/workflows/services/DummyRPCCustomType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright 2022 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.kie.kogito.workflows.services; | ||
|
||
import org.jbpm.ruleflow.core.RuleFlowNodeContainerFactory; | ||
import org.jbpm.ruleflow.core.factory.WorkItemNodeFactory; | ||
import org.kie.kogito.serverless.workflow.parser.ParserContext; | ||
import org.kie.kogito.serverless.workflow.parser.types.WorkItemTypeHandler; | ||
|
||
import io.serverlessworkflow.api.Workflow; | ||
import io.serverlessworkflow.api.functions.FunctionDefinition; | ||
|
||
import static org.kie.kogito.serverless.workflow.parser.FunctionTypeHandlerFactory.trimCustomOperation; | ||
import static org.kie.kogito.workflows.services.RPCCustomWorkItemHandler.NAME; | ||
import static org.kie.kogito.workflows.services.RPCCustomWorkItemHandler.OPERATION; | ||
|
||
public class DummyRPCCustomType extends WorkItemTypeHandler { | ||
|
||
@Override | ||
public String type() { | ||
return "rpc"; | ||
} | ||
|
||
@Override | ||
protected <T extends RuleFlowNodeContainerFactory<T, ?>> WorkItemNodeFactory<T> fillWorkItemHandler(Workflow workflow, | ||
ParserContext context, | ||
WorkItemNodeFactory<T> node, | ||
FunctionDefinition functionDef) { | ||
return node.workName(NAME).metaData(OPERATION, trimCustomOperation(functionDef)); | ||
} | ||
|
||
} |
48 changes: 48 additions & 0 deletions
48
...ration-test/src/main/java/org/kie/kogito/workflows/services/RPCCustomWorkItemHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright 2022 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.kie.kogito.workflows.services; | ||
|
||
import java.util.Iterator; | ||
import java.util.Map; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
|
||
import org.kie.kogito.internal.process.runtime.KogitoWorkItem; | ||
import org.kie.kogito.serverless.workflow.WorkflowWorkItemHandler; | ||
|
||
@ApplicationScoped | ||
public class RPCCustomWorkItemHandler extends WorkflowWorkItemHandler { | ||
|
||
public static final String NAME = "RPCCustomWorkItemHandler"; | ||
public static final String OPERATION = "operation"; | ||
|
||
@Override | ||
protected Object internalExecute(KogitoWorkItem workItem, Map<String, Object> parameters) { | ||
Iterator<?> iter = parameters.values().iterator(); | ||
Map<String, Object> metadata = workItem.getNodeInstance().getNode().getMetaData(); | ||
String operationId = (String) metadata.get(OPERATION); | ||
if (!"division".equals(operationId)) { | ||
throw new IllegalArgumentException("Operation " + operationId + " is not supported"); | ||
} | ||
return (Integer) iter.next() / (Integer) iter.next(); | ||
|
||
} | ||
|
||
@Override | ||
public String getName() { | ||
return NAME; | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...-test/src/main/java/org/kie/kogito/workflows/services/RPCCustomWorkItemHandlerConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright 2022 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.kie.kogito.workflows.services; | ||
|
||
import javax.annotation.PostConstruct; | ||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.inject.Inject; | ||
|
||
import org.kie.kogito.process.impl.CachedWorkItemHandlerConfig; | ||
|
||
@ApplicationScoped | ||
public class RPCCustomWorkItemHandlerConfig extends CachedWorkItemHandlerConfig { | ||
|
||
@Inject | ||
RPCCustomWorkItemHandler handler; | ||
|
||
@PostConstruct | ||
void init() { | ||
register(handler.getName(), handler); | ||
} | ||
} |
3 changes: 2 additions & 1 deletion
3
...resources/META-INF/services/org.kie.kogito.serverless.workflow.parser.FunctionTypeHandler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
org.kie.kogito.workflows.services.DummyAnsibleCustomType | ||
org.kie.kogito.workflows.services.DummyAnsibleCustomType | ||
org.kie.kogito.workflows.services.DummyRPCCustomType |
34 changes: 34 additions & 0 deletions
34
...quarkus-serverless-workflow-integration-test/src/main/resources/forEachCustomType.sw.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{ | ||
"id": "forEachCustomType", | ||
"version": "1.0", | ||
"name": "For each custom type", | ||
"description": "Test for each state with workitem handler", | ||
"start": "start", | ||
"functions": [ | ||
{ | ||
"name": "division", | ||
"type": "custom", | ||
"operation": "rpc:division" | ||
} | ||
], | ||
"states": [ { | ||
"name": "start", | ||
"type": "foreach", | ||
"iterationParam" : "item", | ||
"inputCollection": ".input", | ||
"outputCollection": ".output", | ||
"actions": [ | ||
{ | ||
"functionRef": { | ||
"refName": "division", | ||
"arguments": { | ||
"dividend": ".item", | ||
"divisor" : ".divisor" | ||
} | ||
} | ||
} | ||
], | ||
"end": true | ||
} | ||
] | ||
} |
42 changes: 42 additions & 0 deletions
42
...rkflow-integration-test/src/test/java/org/kie/kogito/quarkus/workflows/ForEachRestIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright 2021 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.kie.kogito.quarkus.workflows; | ||
|
||
import java.util.Arrays; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import io.quarkus.test.junit.QuarkusIntegrationTest; | ||
import io.restassured.http.ContentType; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static org.hamcrest.CoreMatchers.is; | ||
|
||
@QuarkusIntegrationTest | ||
class ForEachRestIT { | ||
|
||
@Test | ||
void testForEachRest() { | ||
given() | ||
.contentType(ContentType.JSON) | ||
.accept(ContentType.JSON) | ||
.body("{\"workflowdata\" : {\"input\" : [2,4,6,8,10], \"divisor\": 2}}").when() | ||
.post("/forEachCustomType") | ||
.then() | ||
.statusCode(201) | ||
.body("workflowdata.output", is(Arrays.asList(1, 2, 3, 4, 5))); | ||
} | ||
} |