Skip to content

7 Common services

AlyonaRybakova edited this page Aug 1, 2019 · 1 revision

7 Common services

Sailfish uses Services in order to communicate with the system under test or any other external application. Services are usually provided as a part of a plugin, but a few dummy ones are provided with SF itself.

Services are typically responsible for:

  1. Setting up a connection with an external app (e.g. system under test);

  2. Maintaining a connection;

  3. Converting messages from an app’s native protocol to the SF representation;

The user can manage SF Services via Environment page. Please refer to 5.1 Environment Page section.

SF services can be accessed from a test script using actions. To check the Test Actions, please refer to section 6.1.

7.1 Integration with DBMS

It’s possible to execute custom SQL queries from the test script. To do that, you need a service that supports the DB_Query action.

The test script should contain:

#action - DB_Query

#message_type – HashMap

  • The query should be specified in the ‘DB_QUERY’ field;
  • The query should be written using native SQL dialect for the target DBMS.

Fields from the returned result set can be used via field reference syntax (${<message>.<field>}. Field names will correspond to the ones specified in the SQL SELECT statement.

If you want to pass some variables from a test script as query arguments, you need to:

  1. Define the required variables as “static variables”, e.g. “AdminName”;

  2. Pass the values to a DB_QUERY action by referencing static variables in the corresponding columns like this: “%{AdminName}” ;

  3. Reference the passed values from the SQL code via this syntax: ‘@{<custom field name>}’, e.g. @{USER_NAME}.

Below is an example of using a DB query in a script.

#description #reference #service_name #action #static_value #static_type
define admin name AdminName SetStatic JoeTheAdmin String
#description #reference #service_name #action DB_QUERY USER_ID USER_NAME
first query firstResultSet DB_connection DB_Query SELECT USER_ID FROM USER_LIST WHERE USER_NAME = ‘@{USER_NAME}' %{AdminName}
second query secondResultSet DB_connection DB_Query SELECT GROUP_NAME FROM GROUP_LIST WHERE ADMIN_ID = '@{USER_ID}’ ${firstResultSet:USER_ID}

The USER_ID field that was obtained from a database can be referenced later with this statement: ${firstResultSet:USER_ID}.

Note: To work with an object-oriented BD, you need to have a jar with a jdbc driver as a plugin library.

The service settings are below.

E.g. Service settings to connect to MySQL server:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<serviceDescription>    
<type>ORACLE-DB-Client</type>
<name>Service_name</name> 
<serviceHandlerClassName>com.exactprosystems.testtools.services.CollectorServiceHandler</serviceHandlerClassName> 
<oracleClientSettings> 
<expectedTimeOfStarting>2000</expectedTimeOfStarting> 
<waitingTimeBeforeStarting>0</waitingTimeBeforeStarting> 
<idleTimeout>1000</idleTimeout> 
<jdbcDriver>org.mariadb.jdbc.Driver</jdbcDriver> - applicable jdbc driver (e.g. for mariadb).
<password>Password</password> - password to connect to DB.
<url>jdbc:mariadb://<host>[:<port>]/<databaseName></url> - url to connect to DB where the host address, port and DB name should be specified. 
<username>User</username> - user to connect to DB.
</oracleClientSettings>
</serviceDescription> 

E.g. Service settings to connect to Oracle server:

<serviceDescription>
<type>ORACLE_DB_Client</type>
<name>Service_name</name>
<serviceHandlerClassName>com.exactprosystems.testtools.services.CollectorServiceHandler</serviceHandlerClassName>
<oracleClientSettings>
<expectedTimeOfStarting>2000</expectedTimeOfStarting>
<performDump>false</performDump>
<waitingTimeBeforeStarting>0</waitingTimeBeforeStarting>
<idleTimeout>1000</idleTimeout>
<jdbcDriver>oracle.jdbc.driver.OracleDriver</jdbcDriver>
<password>Password</password>
<url>jdbc:oracle:thin:@host:port/DB_name</url>
<username>User</username>
</oracleClientSettings>
</serviceDescription>

E.g. Service settings to connect to Microsoft SQL server:

<serviceDescription>
<type>ORACLE-DB-Client</type>
<name>Service_name</name>
<serviceHandlerClassName>com.exactprosystems.testtools.services.CollectorServiceHandler</serviceHandlerClassName>
<oracleClientSettings>
<expectedTimeOfStarting>2000</expectedTimeOfStarting>
<waitingTimeBeforeStarting>0</waitingTimeBeforeStarting>
<idleTimeout>1000</idleTimeout>
<jdbcDriver>com.microsoft.sqlserver.jdbc.SQLServerDriver</jdbcDriver>
<password>Password</password>
<url>jdbc:sqlserver://host:password;databaseName=<DB_name>;</url>
<username>User</username>
</oracleClientSettings>
</serviceDescription>