forked from apache/incubator-kie-kogito-serverless-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[KOGITO-1316] Travel Agency Openshift scenario (apache#221)
Implemented scenario when Visa is not needed. Other scenario will be delivered as another PR. Signed-off-by: Karel Suta <[email protected]>
- Loading branch information
1 parent
30728a1
commit a5c4bba
Showing
8 changed files
with
303 additions
and
0 deletions.
There are no files selected for viewing
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,44 @@ | ||
@quarkus | ||
@cr | ||
Feature: Deploy Travel agency service and verify its functionality | ||
|
||
Background: | ||
Given Namespace is created | ||
And Kogito Operator is deployed with Infinispan and Kafka operators | ||
And "CR" install Kogito Data Index with 1 replicas | ||
And "CR" deploy service from example file "travelapp-kogito-travel-agency.yaml" | ||
And Kogito application "kogito-travel-agency" has 1 pods running within 10 minutes | ||
And HTTP GET request on service "kogito-travel-agency" with path "travels" is successful within 1 minutes | ||
|
||
Scenario: Travel application without required Visa | ||
When Start "travels" process on service "kogito-travel-agency" with body: | ||
"""json | ||
{ | ||
"traveller" : { | ||
"firstName" : "John6", | ||
"lastName" : "Doe", | ||
"email" : "[email protected]", | ||
"nationality" : "American", | ||
"address" : { | ||
"street" : "main street", | ||
"city" : "Boston", | ||
"zipCode" : "10005", | ||
"country" : "US" | ||
} | ||
}, | ||
"trip" : { | ||
"city" : "New York", | ||
"country" : "US", | ||
"begin" : "2019-12-10T00:00:00.000+02:00", | ||
"end" : "2019-12-15T00:00:00.000+02:00" | ||
} | ||
} | ||
""" | ||
And Service "kogito-travel-agency" contains 1 instance of process with name "travels" | ||
And Service "kogito-travel-agency" contains 1 task of process with name "travels" and task name "ConfirmTravel" | ||
And Complete "ConfirmTravel" task on service "kogito-travel-agency" and process with name "travels" with body: | ||
"""json | ||
{} | ||
""" | ||
|
||
Then Service "kogito-travel-agency" contains 0 instances of process with name "travels" |
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
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,27 @@ | ||
// Copyright 2020 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 framework | ||
|
||
// StartProcess starts new process instance | ||
func StartProcess(namespace, routeURI, processName, bodyFormat, bodyContent string) (err error) { | ||
_, err = ExecuteHTTPRequest(namespace, "POST", routeURI, processName, bodyFormat, bodyContent) | ||
return | ||
} | ||
|
||
// GetProcessInstances retrieves process instance of process name | ||
func GetProcessInstances(namespace, routeURI, processName string) (foundProcessInstances []map[string]interface{}, err error) { | ||
err = ExecuteHTTPRequestWithUnmarshalledResponse(namespace, "GET", routeURI, processName, "", "", &foundProcessInstances) | ||
return | ||
} |
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,27 @@ | ||
// Copyright 2020 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 framework | ||
|
||
// GetTasks retrieves tasks of specific process instance | ||
func GetTasks(namespace, routeURI, processName, processInstanceID string) (foundTasks map[string]string, err error) { | ||
err = ExecuteHTTPRequestWithUnmarshalledResponse(namespace, "GET", routeURI, processName+"/"+processInstanceID+"/tasks", "", "", &foundTasks) | ||
return | ||
} | ||
|
||
// CompleteTask completes task | ||
func CompleteTask(namespace, routeURI, processName, processInstanceID, taskName, taskID, bodyFormat, bodyContent string) (err error) { | ||
_, err = ExecuteHTTPRequest(namespace, "POST", routeURI, processName+"/"+processInstanceID+"/"+taskName+"/"+taskID, bodyFormat, bodyContent) | ||
return | ||
} |
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
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
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,58 @@ | ||
// Copyright 2020 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 steps | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/cucumber/godog" | ||
"github.com/cucumber/godog/gherkin" | ||
"github.com/kiegroup/kogito-cloud-operator/test/framework" | ||
) | ||
|
||
// registerProcessSteps register all process steps | ||
func registerProcessSteps(s *godog.Suite, data *Data) { | ||
s.Step(`^Start "([^"]*)" process on service "([^"]*)" with body:$`, data.startProcessOnService) | ||
s.Step(`^Service "([^"]*)" contains (\d+) (?:instance|instances) of process with name "([^"]*)"$`, data.serviceContainsInstancesOfProcess) | ||
} | ||
|
||
func (data *Data) startProcessOnService(processName, serviceName string, body *gherkin.DocString) error { | ||
routeURI, err := framework.WaitAndRetrieveRouteURI(data.Namespace, serviceName) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = framework.StartProcess(data.Namespace, routeURI, processName, body.ContentType, body.Content) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
func (data *Data) serviceContainsInstancesOfProcess(serviceName string, processInstances int, processName string) error { | ||
routeURI, err := framework.WaitAndRetrieveRouteURI(data.Namespace, serviceName) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
foundProcessInstances, err := framework.GetProcessInstances(data.Namespace, routeURI, processName) | ||
if err != nil { | ||
return err | ||
} | ||
if len(foundProcessInstances) != processInstances { | ||
return fmt.Errorf("expected %d of process instances, but got %d", processInstances, len(foundProcessInstances)) | ||
} | ||
return nil | ||
} |
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,111 @@ | ||
// Copyright 2020 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 steps | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/cucumber/godog" | ||
"github.com/cucumber/godog/gherkin" | ||
"github.com/kiegroup/kogito-cloud-operator/test/framework" | ||
) | ||
|
||
// registerTaskSteps register all task steps | ||
func registerTaskSteps(s *godog.Suite, data *Data) { | ||
s.Step(`^Service "([^"]*)" contains (\d+) (?:task|tasks) of process with name "([^"]*)" and task name "([^"]*)"$`, data.serviceContainsTasksOfProcessWithNameAndTaskName) | ||
s.Step(`^Complete "([^"]*)" task on service "([^"]*)" and process with name "([^"]*)" with body:$`, data.completeTaskOnServiceAndProcessWithName) | ||
} | ||
|
||
func (data *Data) serviceContainsTasksOfProcessWithNameAndTaskName(serviceName string, numberOfTasks int, processName, taskName string) error { | ||
routeURI, err := framework.WaitAndRetrieveRouteURI(data.Namespace, serviceName) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// We assume that one process instance is available, can be refactored if more flexibility needed | ||
foundProcessInstances, err := framework.GetProcessInstances(data.Namespace, routeURI, processName) | ||
if err != nil { | ||
return err | ||
} | ||
if len(foundProcessInstances) == 0 { | ||
return fmt.Errorf("no process instance found, expected one instance") | ||
} | ||
if len(foundProcessInstances) > 1 { | ||
return fmt.Errorf("too many process instances found, expected one instance, but found %d instances", len(foundProcessInstances)) | ||
} | ||
|
||
// We assume that only tasks with specified name exist, can be refactored if more flexibility needed | ||
processInstanceID := foundProcessInstances[0]["id"].(string) | ||
foundTasks, err := framework.GetTasks(data.Namespace, routeURI, processName, processInstanceID) | ||
if err != nil { | ||
return err | ||
} | ||
for _, foundTaskName := range foundTasks { | ||
if taskName != foundTaskName { | ||
return fmt.Errorf("found unexpected task name %s", foundTaskName) | ||
} | ||
} | ||
if len(foundTasks) < numberOfTasks { | ||
return fmt.Errorf("not enough tasks found, expected at least %d tasks, but found just %d tasks", numberOfTasks, len(foundTasks)) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (data *Data) completeTaskOnServiceAndProcessWithName(taskName, serviceName, processName string, body *gherkin.DocString) error { | ||
routeURI, err := framework.WaitAndRetrieveRouteURI(data.Namespace, serviceName) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// We assume that one process instance is available, can be refactored if more flexibility needed | ||
foundProcessInstances, err := framework.GetProcessInstances(data.Namespace, routeURI, processName) | ||
if err != nil { | ||
return err | ||
} | ||
if len(foundProcessInstances) == 0 { | ||
return fmt.Errorf("no process instance found, expected one instance") | ||
} | ||
if len(foundProcessInstances) > 1 { | ||
return fmt.Errorf("too many process instances found, expected one instance, but found %d instances", len(foundProcessInstances)) | ||
} | ||
|
||
processInstanceID := foundProcessInstances[0]["id"].(string) | ||
foundTasks, err := framework.GetTasks(data.Namespace, routeURI, processName, processInstanceID) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
taskID, exists := getTaskID(foundTasks, taskName) | ||
if !exists { | ||
return fmt.Errorf("task with name %s not found", taskName) | ||
} | ||
|
||
err = framework.CompleteTask(data.Namespace, routeURI, processName, processInstanceID, taskName, taskID, body.ContentType, body.Content) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
// getTaskID Returns task id of the task with name searchedTaskName and flag is the task with such name exists in tasks map | ||
func getTaskID(tasks map[string]string, searchedTaskName string) (string, bool) { | ||
for taskID, taskName := range tasks { | ||
if taskName == searchedTaskName { | ||
return taskID, true | ||
} | ||
} | ||
return "", false | ||
} |