Skip to content

Commit

Permalink
[KOGITO-7294] Integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
fjtirado committed Sep 14, 2022
1 parent be58769 commit e512f66
Show file tree
Hide file tree
Showing 6 changed files with 205 additions and 1 deletion.
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));
}

}
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;
}
}
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);
}
}
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
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
}
]
}
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)));
}
}

0 comments on commit e512f66

Please sign in to comment.