/cta-flowcontrol

Primary LanguageJavaScriptOtherNOASSERTION

cta-flowcontrol

Build Status Coverage Status codecov

Flow Control Modules for Compass Test Automation, One of Libraries in CTA-OSS Framework

General Overview

cta-flowcontrol is one of the most important libraries in CTA-OSS Framework. It controls how the application operate.

Overview

There are 3 modules in this library.

  • Cement

  • CementHelper

  • Context

Guidelines

We aim to give you brief guidelines here.

  1. Cement
  2. CementHelper
  3. Context
  4. Examples
'use strict';

const FlowControl = require('cta-flowcontrol');

1. Cement

Cement aims to construct, initialize, and start bricks with tools using Cement's Constructor and Configuration.

1.1 Constructor

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.

1.2 Configuration

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",
  },
};

back to top

2. CementHelper

CementHelper provides the supportive functionalities within the Brick.

2.1 require(path)

class SampleBrick extends Brick {
  process(context) {
    const sampleModule = this.cementHelper.require("sample-module");
    ...
  }
}

CementHelper's require() is equivalent to require(). It loads a module.

2.2 createContext(data, events)

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

2.3 publish(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

back to top

3. Context

Context contains information about nature and payload.

3.1 publish()

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.

back to top

4. Examples

4.1 Brick Example

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',
          },
        },
      ],
    },
  ],
};

4.2 Tool Example

const tool = {
  name: 'logger',
  module: 'cta-logger',
  properties: {
    level: 'verbose',
  },
  scope: 'all',
  order: 1,
};

4.3 Data as Context Creation Example

const data = {
  nature: {
    type: 'executions',
    quality: 'commandLine',
  },
  payload: {
    executionId: execution.id,
  },
};

const otherContext = this.cementHelper.createContext(data, ['operate', 'error']);

back to top


To Do