Flow Control Modules for Compass Test Automation, One of Libraries in CTA-OSS Framework
cta-flowcontrol is one of the most important libraries in CTA-OSS Framework. It controls how the application operate.
There are 3 modules in this library.
-
Cement
-
CementHelper
-
Context
We aim to give you brief guidelines here.
'use strict';
const FlowControl = require('cta-flowcontrol');
Cement aims to construct, initialize, and start bricks with tools using Cement's Constructor and Configuration.
class Cement {
constructor(configuration, basedir) {
...
}
}
How to use it..
const Cement = FlowControl.Cement;
const config = require('./path/to/config');
const cement = new Cement(config);
When we use the new Cement(config), it will construct, initialize, and start bricks.
const config = {
name: string,
bricks: array,
tools: array,
properties: object,
};
- name defines the name of application
- bricks provides the array of bricks, see example
- tools provides the array of tools, see example
- properties provides application's properties
// Example of Cement's Configuration
const b1 = require("brick1");
const b2 = require("brick2");
const b3 = require("brick3");
const t1 = require("tool1");
const t2 = require("tool2");
const t3 = require("tool3");
const config = {
name: 'SampleApplication',
bricks: [b1, b2, b3],
tools: [t1, t2, t3],
properties: {
title: "sample title",
url: "http://192.0.0.1:8081",
},
};
CementHelper provides the supportive functionalities within the Brick.
class SampleBrick extends Brick {
process(context) {
const sampleModule = this.cementHelper.require("sample-module");
...
}
}
CementHelper's require() is equivalent to require(). It loads a module.
class SampleBrick extends Brick {
process(context) {
const data = {
nature: {
type: 'type',
quality: 'quality',
},
payload: { },
};
const otherContext = this.cementHelper.createContext(data, ['operate', 'error']);
...
}
}
CementHelper's createContext() provides a functionality to create context by providing data and events.
- data defines the provided data within context, see example
- nature consists of type and quality
- payload contains anything as payload
- events provides the array of authorized events names that are used via context
class SampleBrick extends Brick {
process(context) {
...
this.cementHelper.publish(otherContext);
...
}
}
CementHelper's publish() provides a functionality to publish context.
- data defines the provided data within context
- events provides the array of authorized events names that are used via context
Context contains information about nature and payload.
class SampleBrick extends Brick {
process(context) {
const data = {
nature: {
type: 'type',
quality: 'quality',
},
payload: { },
};
const otherContext = this.cementHelper.createContext(data, ['operate', 'error']);
otherContext.publish(); // equivalent to this.cementHelper.publish(otherContext);
...
}
}
Context's publish() is equivalent to CementHelper's publish(context). It publishes the context.
const brick = {
name: 'sample brick',
module: './lib/bricks/cta-sample-brick',
properties: {},
publish: [
{
topic: 'cta.execution',
data: [
{
nature: {
type: 'executions',
quality: 'commandLine',
},
},
{
nature: {
type: 'executions',
quality: 'cancel',
},
},
],
},
{
topic: 'cta.execution.result',
data: [
{
nature: {
type: 'results',
quality: 'execute',
},
},
],
},
{
topic: 'cta.execution.state',
data: [
{
nature: {
type: 'states',
quality: 'create',
},
},
],
},
],
subscribe: [
{
topic: 'cta.execution',
data: [
{
nature: {
type: 'executions',
quality: 'run',
},
},
{
nature: {
type: 'executions',
quality: 'cancel',
},
},
{
nature: {
type: 'executions',
quality: 'process',
},
},
],
},
],
};
const tool = {
name: 'logger',
module: 'cta-logger',
properties: {
level: 'verbose',
},
scope: 'all',
order: 1,
};
const data = {
nature: {
type: 'executions',
quality: 'commandLine',
},
payload: {
executionId: execution.id,
},
};
const otherContext = this.cementHelper.createContext(data, ['operate', 'error']);