Poetry Client Behat Extension
, (*1)
Behat extension for the European Commission's Poetry Client., (*2)
Installation Using Docker Compose
Requirements:, (*3)
Copy docker-compose.yml.dist
into docker-compose.yml
., (*4)
You can make any alterations you need for your local Docker setup. However, the defaults should be enough to set the
project up. Note that there are mac specific settings available in the docker-compose.yml.dist
., (*5)
Run:, (*6)
$ docker-compose up -d
$ docker-compose exec web composer install
Setup
Load the Poetry context and configure the extension as shown below:, (*7)
default:
suites:
default:
contexts:
- 'EC\Behat\PoetryExtension\Context\PoetryContext'
extensions:
EC\Behat\PoetryExtension:
application:
base_url: 'http://local.dev' # Required: application base URL running Poetry Client library.
endpoint: '/my-endpoint' # Required: notification endpoint on your application.
The following extensive configuration allows you to further tweak the extension's behaviour:, (*8)
default:
suites:
default:
contexts:
- 'EC\Behat\PoetryExtension\Context\PoetryContext'
extensions:
EC\Behat\PoetryExtension:
application:
base_url: 'http://local.dev' # Required: application base URL running the Poetry Client library.
endpoint: '/my-endpoint' # Required: notification endpoint for your application.
service:
host: 'localhost' # Optional: host where mock Poetry service will be running, defaults to `localhost`.
port: '28080' # Optional: mock Poetry service port, defaults to `28080`.
endpoint: '/service' # Optional: mock Poetry service endpoint, defaults to `/service`.
wsdl: '/wsdl' # Optional: mock Poetry service WSDL endpoint, defaults to `/wsdl`.
username: 'username' # Optional: username used by the mock service to authenticate on your application, defaults to `username`.
password: 'password' # Optional: password used by the mock service to authenticate on your application, defaults to `password`.
Service parameters can be also overridden in your Behat scenarios (see below)., (*9)
Usage
All scenarios and/or features that wish to use the extension's steps will need to be tagged with @poetry
., (*10)
To instantiate test Poetry client with redefined settings use:, (*11)
Given the Poetry client uses the following settings:
"""
identifier.code: STSI
identifier.year: 2017
identifier.number: 40017
identifier.version: 0
identifier.part: 11
client.wsdl: http://my-client.eu/wsdl
notification.username: foo
notification.password: bar
"""
To send a raw XML notification message to the client endpoint use:, (*12)
When Poetry notifies the client with the following XML:
"""
<?xml version="1.0" encoding="UTF-8"?>
...
"""
Or, if you want to express the message in a withArray()
format, use:, (*13)
When Poetry notifies the client with the following "notification.translation_received" message:
"""
identifier:
code: "WEB"
year: "2017"
number: "40012"
...
"""
To setup test responses for the Poetry server use:, (*14)
Given Poetry will return the following XML response:
"""
<?xml version="1.0" encoding="utf-8"?><POETRY xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://intragate.ec.europa.eu/DGT/poetry_services/poetry.xsd">
<request communication="synchrone" id="WEB/2017/40029/0/0/TRA" type="status">
<demandeId>
<codeDemandeur>WEB</codeDemandeur>
<annee>2017</annee>
...
"""
Or, if you want to express the message in a withArray()
format, use:, (*15)
Given Poetry will return the following "response.status" message response:
"""
identifier:
code: WEB
year: 2017
number: 40029
version: 0
...
"""
Client responses can be asserted by using the following step:, (*16)
Then client response contains the following text:
| <codeDemandeur>WEB</codeDemandeur> |
| <annee>2017</annee> |
| <statusMessage>OK</statusMessage> |
Or, if you want to assert XML portions, use:, (*17)
And Poetry service received request should contain the following XML portion:
"""
<documentSource format="HTML" legiswrite="No">
<documentSourceName>content.html</documentSourceName>
<documentSourceFile>BASE64ENCODEDFILECONTENT</documentSourceFile>
<documentSourceLang lgCode="EN">
<documentSourceLangPages>1</documentSourceLangPages>
</documentSourceLang>
</documentSource>
"""
Application parameters can be overridden by using the following step:, (*18)
When Poetry service uses the following settings:
"""
username: foo
password: bar
"""
For more detailed examples please refer to the Poetry Behat Extension's tests features baring in mind that
steps beginning with Given the test application...
are only used to test the extension itself and, thus, not available
to the extension users., (*19)
Token replacement
Both Behat extension settings and current Poetry client settings can be used in Behat steps as replacement tokens.
The following tokens will be automatically replaced:, (*20)
- Behat extension settings in dot-notation prefixed by
!
, like !service.host
or !service.port
- Poetry client string settings in dot-notation prefixed by
!poetry.
, like !poetry.client.wsdl
.
Token replacements can be used as follow:, (*21)
And Poetry service received request should contain the following XML portion:
"""
<retour type="webService" action="UPDATE">
<retourUser>foo</retourUser>
<retourPassword>bar</retourPassword>
<retourAddress>!poetry.client.wsdl</retourAddress>
<retourPath>handle</retourPath>
</retour>
"""