TT#56467 - Migrate api-journals and api-topupvoucher

* Add warning system: throw warnings
	   whenever a variable is  wanted but
	   not present

	 * Migrate api-journals and api-topupvoucher

Change-Id: Iefb6f4f3ebe7d11f904d21a6d255e7940e8bb07a
changes/95/33795/6
Flaviu Mates 6 years ago
parent 16d34fa282
commit c280b171ba

@ -66,10 +66,97 @@
name: test api name 3 ${unique_id}
retain:
billingprofile_path3: header.location
billingprofile3_id: header.location
conditions:
is:
code: 201
#test item journal link
-
name: test item journal link
type: item
method: GET
path: /${billingprofile_path3}
retain:
billingprofile: body
perl_code: !!perl/code |
{
my ($retained) = @_;
$retained->{href} = $retained->{billingprofile}->{_links}->{'ngcp:journal'}->[0]->{href};
$retained->{expected_href} = '/api/billingprofiles/'.$retained->{billingprofile3_id}.'/journal/';
}
conditions:
is:
code: 200
ok:
'${billingprofile}._links': defined
'${billingprofile}._links.ngcp:journal': defined
'${href}': '${expected_href}'
#test journal options
-
name: test journal options
type: item
method: OPTIONS
path: '/${billingprofile_path3}/journal'
conditions:
is:
code: 200
ok:
options:
- GET
- HEAD
- OPTIONS
#test journal head
-
name: test journal head
type: item
method: HEAD
path: '/${billingprofile_path3}/journal'
conditions:
is:
code: 200
#TestJournalTopJournalItem
-
name: include TestJournalTopJournalItem
type: include
file: TestJournalTopJournalItem.yaml
perl_code: !!perl/code |
{
my ($retained) = @_;
$retained->{journal_link} = '/api/billingprofiles/' . $retained->{billingprofile3_id} . '/journal/recent';
$retained->{resource} = 'billingprofiles';
$retained->{item} = $retained->{billingprofile};
$retained->{operation} = 'create';
}
#test journal options
-
name: test journal options
type: item
method: OPTIONS
path: '/${journal_item_link}'
conditions:
is:
code: 200
ok:
options:
- GET
- HEAD
- OPTIONS
#test journal head
-
name: test journal head
type: item
method: HEAD
path: '/${journal_item_link}'
conditions:
is:
code: 200
#verify pagination
-
name: verify pagination
@ -246,6 +333,42 @@
is_deeply:
'${billingprofile}': ${new_billingprofile}
#test item journal link
-
name: test item journal link
type: item
method: GET
path: /${billingprofile_path1}
retain:
billingprofile: body
perl_code: !!perl/code |
{
my ($retained) = @_;
$retained->{href} = $retained->{billingprofile}->{_links}->{'ngcp:journal'}->[0]->{href};
$retained->{expected_href} = '/api/billingprofiles/'.$retained->{billingprofile}->{id}.'/journal/';
}
conditions:
is:
code: 200
ok:
'${billingprofile}._links': defined
'${billingprofile}._links.ngcp:journal': defined
'${href}': '${expected_href}'
#TestJournalTopJournalItem
-
name: include TestJournalTopJournalItem
type: include
file: TestJournalTopJournalItem.yaml
perl_code: !!perl/code |
{
my ($retained) = @_;
$retained->{journal_link} = '/api/billingprofiles/' . $retained->{billingprofile}->{id} . '/journal/recent';
$retained->{resource} = 'billingprofiles';
$retained->{item} = $retained->{billingprofile};
$retained->{operation} = 'update';
}
#PATCH billingprofile name
-
name: PATCH billingprofile name
@ -269,6 +392,55 @@
'${modified_billingprofile}._links.self.href': ${billingprofile_path1}
'${modified_billingprofile}._links.collection.href': /api/billingprofiles/
#test item journal link
-
name: test item journal link
type: item
method: GET
path: /${billingprofile_path1}
retain:
billingprofile: body
perl_code: !!perl/code |
{
my ($retained) = @_;
$retained->{href} = $retained->{billingprofile}->{_links}->{'ngcp:journal'}->[0]->{href};
$retained->{expected_href} = '/api/billingprofiles/'.$retained->{billingprofile}->{id}.'/journal/';
}
conditions:
is:
code: 200
ok:
'${billingprofile}._links': defined
'${billingprofile}._links.ngcp:journal': defined
'${href}': '${expected_href}'
#TestJournalTopJournalItem
-
name: include TestJournalTopJournalItem
type: include
file: TestJournalTopJournalItem.yaml
perl_code: !!perl/code |
{
my ($retained) = @_;
$retained->{journal_link} = '/api/billingprofiles/' . $retained->{billingprofile}->{id} . '/journal/recent';
$retained->{resource} = 'billingprofiles';
$retained->{item} = $retained->{billingprofile};
$retained->{operation} = 'update';
}
#test journal collection
-
name: test journal collection
type: pagination
skip: 1
method: GET
path: '${journal_collection_link}'
retain:
collection: body
conditions:
is:
code: 200
#check patch with undef reseller
-
name: check patch with undef reseller
@ -533,4 +705,44 @@
is:
code: 200
is_deeply:
'${peaktimes_special_billingprofile}': ${new_billingprofile}
'${peaktimes_special_billingprofile}': ${new_billingprofile}
#DELETE billingprofile
-
name: DELETE billingprofile
type: item
method: DELETE
path: '/${billingprofile_path2}'
conditions:
is:
code: 204
#DELETE billingprofile
-
name: DELETE billingprofile
type: item
method: DELETE
path: '/${billingprofile_path3}'
conditions:
is:
code: 204
#DELETE billingprofile
-
name: DELETE billingprofile
type: item
method: DELETE
path: '/${peaktimes_weekday_billingprofile_path}'
conditions:
is:
code: 204
#DELETE billingprofile
-
name: DELETE billingprofile
type: item
method: DELETE
path: '/${peaktimes_special_billingprofile_path}'
conditions:
is:
code: 204

@ -0,0 +1,128 @@
---
#create Lnp Provider
-
name: create Lnp Provider
type: item
method: POST
path: /api/lnpcarriers/
header:
Content-Type: application/json
content:
name: test_lnp_carrier_${unique_id}
prefix: test${unique_id}
conditions:
is:
code: 201
retain:
lnp_provider_path: header.location
lnp_provider_id: header.location
#get Lnp Provider
-
name: GET Lnp Provider
type: item
method: GET
path: '/${lnp_provider_path}'
retain:
lnp_provider: body
conditions:
is:
code: 200
#create Lnp Number
-
name: create Lnp Number
type: item
method: POST
path: /api/lnpnumbers/
header:
Content-Type: application/json
content:
carrier_id: ${lnp_provider_id}
number: 123${unique_id}
conditions:
is:
code: 201
retain:
lnp_number_path1: header.location
#get Lnp Number
-
name: GET Lnp Number
type: item
method: GET
path: '/${lnp_number_path1}'
retain:
lnp_nubmer1: body
conditions:
is:
code: 200
#create Lnp Number
-
name: create Lnp Number
type: item
method: POST
path: /api/lnpnumbers/
header:
Content-Type: application/json
content:
carrier_id: ${lnp_provider_id}
number: 456${unique_id}
conditions:
is:
code: 201
retain:
lnp_number_path2: header.location
#get Lnp Number
-
name: GET Lnp Number
type: item
method: GET
path: '/${lnp_number_path2}'
retain:
lnp_nubmer2: body
conditions:
is:
code: 200
#DELETE Lnp Number
-
name: DELETE Lnp Number
type: item
method: DELETE
path: '/${lnp_number_path1}'
conditions:
is:
code: 204
#get Lnp Number
-
name: GET Lnp Number
type: item
method: GET
path: '/${lnp_number_path1}'
conditions:
is:
code: 404
#DELETE Lnp Number
-
name: DELETE Lnp Number
type: item
method: DELETE
path: '/${lnp_number_path2}'
conditions:
is:
code: 204
#get Lnp Number
-
name: GET Lnp Number
type: item
method: GET
path: '/${lnp_number_path2}'
conditions:
is:
code: 404

@ -0,0 +1,142 @@
---
#get a subscriber for testing
-
name: get a subscriber for testing
type: item
method: GET
path: '/api/subscribers/?page=1&rows=1&order_by=id&order_by_direction=desc'
retain:
subscriber: body
perl_code: !!perl/code |
{
my ($retained) = @_;
my $subscriber = $retained->{subscriber}->{'_embedded'}->{'ngcp:subscribers'}->[0];
$retained->{subscriber} = $subscriber;
$retained->{subscriber_id} = $subscriber->{id};
}
conditions:
is:
code: 200
ok:
'${subscriber}.id': defined
#get Subscriber Preferences
-
name: GET Subscriber Preferences
type: item
method: GET
path: '/api/subscriberpreferences/${subscriber_id}'
retain:
subscriberpreferences: body
conditions:
is:
code: 200
#get Subscriber Preferencedefs
-
name: GET Subscriber Preferencedefs
type: item
method: GET
path: '/api/subscriberpreferencedefs'
retain:
defs: body
conditions:
is:
code: 200
#put Subscriber Preferences
-
name: PUT Subscriber Preferences
type: item
method: PUT
path: '/api/subscriberpreferences/${subscriber_id}'
header:
Content-Type: application/json
Prefer: return=representation
content: '${subscriberpreferences}'
conditions:
is:
code: 200
#get Subscriber Preferences
-
name: GET Subscriber Preferences
type: item
method: GET
path: '/api/subscriberpreferences/${subscriber_id}'
retain:
subscriberpreferences: body
conditions:
is:
code: 200
#get a domain for testing
-
name: get a domain for testing
type: item
method: GET
path: '/api/domains/?page=1&rows=1&order_by=id&order_by_direction=desc'
retain:
domain: body
perl_code: !!perl/code |
{
my ($retained) = @_;
my $domain = $retained->{domain}->{'_embedded'}->{'ngcp:domains'}->[0];
$retained->{domain} = $domain;
$retained->{domain_id} = $domain->{id};
}
conditions:
is:
code: 200
ok:
'${domain}.id': defined
#get domain Preferences
-
name: GET domain Preferences
type: item
method: GET
path: '/api/domainpreferences/${domain_id}'
retain:
domainpreferences: body
conditions:
is:
code: 200
#get domain Preferencedefs
-
name: GET domain Preferencedefs
type: item
method: GET
path: '/api/domainpreferencedefs'
retain:
defs: body
conditions:
is:
code: 200
#put domain Preferences
-
name: PUT domain Preferences
type: item
method: PUT
path: '/api/domainpreferences/${domain_id}'
header:
Content-Type: application/json
Prefer: return=representation
content: '${domainpreferences}'
conditions:
is:
code: 200
#get domain Preferences
-
name: GET domain Preferences
type: item
method: GET
path: '/api/domainpreferences/${domain_id}'
retain:
domainpreferences: body
conditions:
is:
code: 200

@ -119,6 +119,92 @@
- PATCH
- DELETE
#test item journal link
-
name: test item journal link
type: item
method: GET
path: /${system_contact_path1}
retain:
system_contact: body
perl_code: !!perl/code |
{
my ($retained) = @_;
$retained->{href} = $retained->{system_contact}->{_links}->{'ngcp:journal'}->[0]->{href};
$retained->{expected_href} = '/api/systemcontacts/'.$retained->{system_contact}->{id}.'/journal/';
}
conditions:
is:
code: 200
ok:
'${system_contact}._links': defined
'${system_contact}._links.ngcp:journal': defined
'${href}': '${expected_href}'
#test journal options
-
name: test journal options
type: item
method: OPTIONS
path: '/${system_contact_path1}/journal'
conditions:
is:
code: 200
ok:
options:
- GET
- HEAD
- OPTIONS
#test journal head
-
name: test journal head
type: item
method: HEAD
path: '/${system_contact_path1}/journal'
conditions:
is:
code: 200
#TestJournalTopJournalItem
-
name: include TestJournalTopJournalItem
type: include
file: TestJournalTopJournalItem.yaml
perl_code: !!perl/code |
{
my ($retained) = @_;
$retained->{journal_link} = '/api/systemcontacts/' . $retained->{system_contact}->{id} . '/journal/recent';
$retained->{resource} = 'systemcontacts';
$retained->{item} = $retained->{system_contact};
$retained->{operation} = 'create';
}
#test journal options
-
name: test journal options
type: item
method: OPTIONS
path: '/${journal_item_link}'
conditions:
is:
code: 200
ok:
options:
- GET
- HEAD
- OPTIONS
#test journal head
-
name: test journal head
type: item
method: HEAD
path: '/${journal_item_link}'
conditions:
is:
code: 200
#get systemcontact
-
name: GET systemcontact
@ -197,6 +283,42 @@
is:
code: 200
#test item journal link
-
name: test item journal link
type: item
method: GET
path: /${system_contact_path3}
retain:
system_contact: body
perl_code: !!perl/code |
{
my ($retained) = @_;
$retained->{href} = $retained->{system_contact}->{_links}->{'ngcp:journal'}->[0]->{href};
$retained->{expected_href} = '/api/systemcontacts/'.$retained->{system_contact}->{id}.'/journal/';
}
conditions:
is:
code: 200
ok:
'${system_contact}._links': defined
'${system_contact}._links.ngcp:journal': defined
'${href}': '${expected_href}'
#TestJournalTopJournalItem
-
name: include TestJournalTopJournalItem
type: include
file: TestJournalTopJournalItem.yaml
perl_code: !!perl/code |
{
my ($retained) = @_;
$retained->{journal_link} = '/api/systemcontacts/' . $retained->{system_contact}->{id} . '/journal/recent';
$retained->{resource} = 'system_contacts';
$retained->{item} = $retained->{system_contact};
$retained->{operation} = 'update';
}
#get systemcontact
-
name: GET systemcontact
@ -270,11 +392,47 @@
path: /firstname
value: patchedfirst
retain:
patched_reseller: body
patched_system_contact: body
conditions:
is:
code: 200
'${patched_system_contact}.firstname': 'patchedfirst'
#test item journal link
-
name: test item journal link
type: item
method: GET
path: /${system_contact_path3}
retain:
system_contact: body
perl_code: !!perl/code |
{
my ($retained) = @_;
$retained->{href} = $retained->{system_contact}->{_links}->{'ngcp:journal'}->[0]->{href};
$retained->{expected_href} = '/api/systemcontacts/'.$retained->{system_contact}->{id}.'/journal/';
}
conditions:
is:
code: 200
'${patched_reseller}.firstname': 'patchedfirst'
ok:
'${system_contact}._links': defined
'${system_contact}._links.ngcp:journal': defined
'${href}': '${expected_href}'
#TestJournalTopJournalItem
-
name: include TestJournalTopJournalItem
type: include
file: TestJournalTopJournalItem.yaml
perl_code: !!perl/code |
{
my ($retained) = @_;
$retained->{journal_link} = '/api/systemcontacts/' . $retained->{system_contact}->{id} . '/journal/recent';
$retained->{resource} = 'system_contacts';
$retained->{item} = $retained->{system_contact};
$retained->{operation} = 'update';
}
#PATCH systemcontact with undef name
-
@ -291,12 +449,12 @@
path: /firstname
value: null
retain:
patched_reseller: body
patched_system_contact: body
conditions:
is:
code: 200
ok:
'${patched_reseller}.firstname': undefined
'${patched_system_contact}.firstname': undefined
#PATCH systemcontact with no emil
-
@ -312,8 +470,6 @@
op: replace
path: /email
value: null
retain:
patched_reseller: body
conditions:
is:
code: 422
@ -348,6 +504,34 @@
is:
code: 204
#TestJournalTopJournalItem
-
name: include TestJournalTopJournalItem
type: include
file: TestJournalTopJournalItem.yaml
perl_code: !!perl/code |
{
my ($retained) = @_;
$retained->{journal_link} = '/api/systemcontacts/' . $retained->{patched_system_contact}->{id} . '/journal/recent';
$retained->{resource} = 'system_contacts';
$retained->{item} = $retained->{patched_system_contact};
$retained->{operation} = 'delete';
}
#test journal collection
-
name: test journal collection
type: pagination
skip: 1
method: GET
path: '${journal_collection_link}'
retain:
collection: body
conditions:
is:
code: 200
#create domain
-
name: create domain

@ -0,0 +1,493 @@
---
#create a Customer Contact
-
name: create a Customer Contact
type: item
method: POST
path: '/api/customercontacts/'
header:
Content-Type: application/json
content:
firstname: 'cust_contact_first'
lastname: 'cust_contact_last'
email: 'cust_contact@custcontact.invalid'
reseller_id: 1
conditions:
is:
code: 201
retain:
customer_contact_path: header.location
customer_contact_id: header.location
#get CustomerContact
-
name: check CustomerContact
type: item
method: GET
path: '/${customer_contact_path}'
retain:
customer_contact: body
conditions:
is:
code: 200
#create a Domain
-
name: create a Domain
type: item
method: POST
path: /api/domains/
header:
Content-Type: application/json
content:
domain: test${unique_id}.example.org
reseller_id: 1
conditions:
is:
code: 201
retain:
domain_path: header.location
domain_id: header.location
#get Domain
-
name: check Domain
type: item
method: GET
path: '/${domain_path}'
retain:
domain: body
conditions:
is:
code: 200
#create billingprofile
-
name: create billingprofile
type: item
method: POST
path: '/api/billingprofiles/'
header:
Content-Type: application/json
content:
reseller_id: 1
handle: test_profile_${unique_id}
name: test profile ${unique_id}
retain:
billingprofile_id: header.location
conditions:
is:
code: 201
#get billingprofile
-
name: get billingprofile
type: item
method: GET
path: '/api/billingprofiles/${billingprofile_id}'
retain:
billingprofile: body
conditions:
is:
code: 200
#create Customer
-
name: include create Customer
type: include
file: CreateCustomer.yaml
perl_code: !!perl/code |
{
my ($retained) = @_;
$retained->{customer_content} = {
status => 'active',
contact_id => $retained->{customer_contact_id},
billing_profile_id => $retained->{billingprofile_id},
type => 'sipaccount',
max_subscribers => undef,
external_id => undef
};
}
#create Subscriber
-
name: include create Subscriber
type: include
file: CreateSubscriber.yaml
perl_code: !!perl/code |
{
my ($retained) = @_;
my $cc = 800;
my $ac = '1';
my $sn = $retained->{unique_id};
$retained->{customer_id} = $retained->{customer}->{id};
$retained->{subscriber_content} = {
primary_number => { cc => $cc, ac => $ac, sn => $sn },
domain_id => $retained->{domain_id},
username => 'subscriber_' . '1' . '_'.$retained->{unique_id},
password => 'subscriber_password',
customer_id => $retained->{customer_id},
};
}
#create voucher
-
name: create voucher
type: item
method: POST
path: '/api/vouchers/'
header:
Content-Type: application/json
content:
amount: 1000.0
code: test_voucher_1${unique_id}
customer_id: ${customer_id}
reseller_id: 1
valid_until: '2037-01-01 00:00:00'
retain:
voucher_path1: header.location
conditions:
is:
code: 201
#get Voucher
-
name: get Voucher
type: item
method: GET
path: '${voucher_path1}'
retain:
voucher1: body
perl_code: !!perl/code |
{
my ($retained) = @_;
$retained->{voucher1_code} = $retained->{voucher1}->{code};
}
conditions:
is:
code: 200
#create voucher
-
name: create voucher
type: item
method: POST
path: '/api/vouchers/'
header:
Content-Type: application/json
content:
amount: 1000.0
code: test_voucher_2${unique_id}
customer_id: ${customer_id}
reseller_id: 1
valid_until: '2010-01-01 00:00:00'
retain:
voucher_path2: header.location
conditions:
is:
code: 201
#get Voucher
-
name: get Voucher
type: item
method: GET
path: '${voucher_path2}'
retain:
voucher2: body
perl_code: !!perl/code |
{
my ($retained) = @_;
$retained->{voucher2_code} = $retained->{voucher2}->{code};
$retained->{subscriber_id} = $retained->{subscriber}->{id};
}
conditions:
is:
code: 200
#perform topup cash
-
name: perform topup cash
type: item
method: POST
path: '/api/topupcash/'
header:
Content-Type: application/json
content:
amount: 0.5
package_id: null
subscriber_id: invalid
request_token: 1${unique_id}
conditions:
is:
code: 422
#check topuplog
-
name: check topuplog
type: item
method: GET
path: '/api/topuplogs/?page=1&rows=10&order_by_direction=asc&order_by=timestamp&request_token=1${unique_id}'
retain:
topuplogs_result: body
perl_code: !!perl/code |
{
my ($retained) = @_;
$retained->{topuplogs} = $retained->{topuplogs_result}->{_embedded}->{'ngcp:topuplogs'}->[0];
$retained->{expected_token} = "1$retained->{unique_id}";
$retained->{expected_outcome} = 'failed';
}
conditions:
is:
'${topuplogs}.request_token': '${expected_token}'
'${topuplogs}.outcome': '${expected_outcome}'
like:
'${topuplogs}.message': "Validation failed. field='subscriber_id'"
#perform topup cash
-
name: perform topup cash
type: item
method: POST
path: '/api/topupcash/'
header:
Content-Type: application/json
content:
amount: 'invalid_amount'
package_id: null
subscriber_id: ${subscriber_id}
request_token: 2${unique_id}
conditions:
is:
code: 422
#check topuplog
-
name: check topuplog
type: item
method: GET
path: '/api/topuplogs/?page=1&rows=10&order_by_direction=asc&order_by=timestamp&request_token=2${unique_id}'
retain:
topuplogs_result: body
perl_code: !!perl/code |
{
my ($retained) = @_;
$retained->{topuplogs} = $retained->{topuplogs_result}->{_embedded}->{'ngcp:topuplogs'}->[0];
$retained->{expected_token} = "2$retained->{unique_id}";
$retained->{expected_outcome} = 'failed';
}
conditions:
is:
'${topuplogs}.request_token': '${expected_token}'
'${topuplogs}.outcome': '${expected_outcome}'
like:
'${topuplogs}.message': "Value cannot be converted to money"
#perform topup cash
-
name: perform topup cash
type: item
method: POST
path: '/api/topupcash/'
header:
Content-Type: application/json
content:
amount: 50
package_id:
id : invalid
subscriber_id: ${subscriber_id}
request_token: 3${unique_id}
conditions:
is:
code: 422
#check topuplog
-
name: check topuplog
type: item
method: GET
path: '/api/topuplogs/?page=1&rows=10&order_by_direction=asc&order_by=timestamp&request_token=3${unique_id}'
retain:
topuplogs_result: body
perl_code: !!perl/code |
{
my ($retained) = @_;
$retained->{topuplogs} = $retained->{topuplogs_result}->{_embedded}->{'ngcp:topuplogs'}->[0];
$retained->{expected_token} = "3$retained->{unique_id}";
$retained->{expected_outcome} = 'failed';
}
conditions:
is:
'${topuplogs}.request_token': '${expected_token}'
'${topuplogs}.outcome': '${expected_outcome}'
like:
'${topuplogs}.message': "Validation failed. field='package_id'"
#perform topup voucher
-
name: perform topup voucher
type: item
method: POST
path: '/api/topupvouchers/'
header:
Content-Type: application/json
content:
code: invalid
subscriber_id: ${subscriber_id}
request_token: 4${unique_id}
conditions:
is:
code: 422
#check topuplog
-
name: check topuplog
type: item
method: GET
path: '/api/topuplogs/?page=1&rows=10&order_by_direction=asc&order_by=timestamp&request_token=4${unique_id}'
retain:
topuplogs_result: body
perl_code: !!perl/code |
{
my ($retained) = @_;
$retained->{topuplogs} = $retained->{topuplogs_result}->{_embedded}->{'ngcp:topuplogs'}->[0];
$retained->{expected_token} = "4$retained->{unique_id}";
$retained->{expected_outcome} = 'failed';
$retained->{long_request_token} = 'a' x 256;
$retained->{expected_request_token} = substr($retained->{long_request_token},0,255);
}
conditions:
is:
'${topuplogs}.request_token': '${expected_token}'
'${topuplogs}.outcome': '${expected_outcome}'
like:
'${topuplogs}.message': "Invalid voucher code 'invalid'"
#perform topup voucher
-
name: perform topup voucher
type: item
method: POST
path: '/api/topupvouchers/'
header:
Content-Type: application/json
content:
code: ${voucher1_code}
subscriber_id: ${subscriber_id}
request_token: ${long_request_token}
conditions:
is:
code: 422
#check topuplog
-
name: check topuplog
type: item
method: GET
path: '/api/topuplogs/?page=1&rows=10&order_by_direction=asc&order_by=timestamp&request_token=${expected_request_token}'
retain:
topuplogs_result: body
perl_code: !!perl/code |
{
my ($retained) = @_;
$retained->{topuplogs} = $retained->{topuplogs_result}->{_embedded}->{'ngcp:topuplogs'}->[0];
}
conditions:
is:
'${topuplogs}.request_token': '${expected_request_token}'
'${topuplogs}.outcome': 'failed'
like:
'${topuplogs}.message': "Validation failed. field='request_token'"
#perform topup voucher
-
name: perform topup voucher
type: item
method: POST
path: '/api/topupvouchers/'
header:
Content-Type: application/json
content:
code: ${voucher1_code}
subscriber_id: ${subscriber_id}
request_token: 5${unique_id}
conditions:
is:
code: 204
#perform same topup voucher
-
name: perform same topup voucher
type: item
method: POST
path: '/api/topupvouchers/'
header:
Content-Type: application/json
content:
code: ${voucher1_code}
subscriber_id: ${subscriber_id}
request_token: 6${unique_id}
conditions:
is:
code: 422
#check topuplog
-
name: check topuplog
type: item
method: GET
path: '/api/topuplogs/?page=1&rows=10&order_by_direction=asc&order_by=timestamp&request_token=6${unique_id}'
retain:
topuplogs_result: body
perl_code: !!perl/code |
{
my ($retained) = @_;
$retained->{topuplogs} = $retained->{topuplogs_result}->{_embedded}->{'ngcp:topuplogs'}->[0];
$retained->{expected_token} = "6$retained->{unique_id}";
}
conditions:
is:
'${topuplogs}.request_token': '${expected_token}'
'${topuplogs}.outcome': 'failed'
like:
'${topuplogs}.message': "already used"
#perform same topup voucher
-
name: perform same topup voucher
type: item
method: POST
path: '/api/topupvouchers/'
header:
Content-Type: application/json
content:
code: ${voucher2_code}
subscriber_id: ${subscriber_id}
request_token: 7${unique_id}
conditions:
is:
code: 422
#check topuplog
-
name: check topuplog
type: item
method: GET
path: '/api/topuplogs/?page=1&rows=10&order_by_direction=asc&order_by=timestamp&request_token=7${unique_id}'
retain:
topuplogs_result: body
perl_code: !!perl/code |
{
my ($retained) = @_;
$retained->{topuplogs} = $retained->{topuplogs_result}->{_embedded}->{'ngcp:topuplogs'}->[0];
$retained->{expected_token} = "7$retained->{unique_id}";
}
conditions:
is:
'${topuplogs}.request_token': '${expected_token}'
'${topuplogs}.outcome': 'failed'
like:
'${topuplogs}.message': "expired"

@ -0,0 +1,37 @@
---
#check recent journalitem request
-
name: check recent journalitem request
type: item
method: GET
path: /${journal_link}
retain:
journal: body
perl_code: !!perl/code |
{
my ($retained) = @_;
$retained->{links} = $retained->{journal}->{_links}->{'ngcp:'.$retained->{resource}};
$retained->{href_resource} = ref $retained->{journal}->{_links}->{'ngcp:'.$retained->{resource}} eq 'ARRAY'
? $retained->{journal}->{_links}->{'ngcp:'.$retained->{resource}}->[0]->{href}
: $retained->{journal}->{_links}->{'ngcp:'.$retained->{resource}}->{href};
$retained->{expected_href_resource} = '/api/'.$retained->{resource}.'/'.$retained->{item}->{id};
delete $retained->{item}->{_links};
$retained->{journal_item_link} = '/api/'. $retained->{resource} . '/' . $retained->{item}->{id} . '/journal/'.$retained->{journal}->{id};
}
conditions:
is:
code: 200
ok:
'${journal}.operation': '${operation}'
'${journal}.id': defined
'${journal}.operation': defined
'${journal}.username': defined
'${journal}.timestamp': defined
'${journal}.content': defined
'${journal}._links': defined
'${journal}._links.self': defined
'${journal}._links.collection': defined
'${links}': defined
'${href_resource}': '${expected_href_resource}'
is_deeply:
'${journal}.content': '${item}'

@ -87,6 +87,13 @@ sub process_test{
DEBUG( "In test '".$test->{name}."'" );
return if ( $test->{skip} );
if ( !$self->_variables_available( $retained, $test ) ) {
my $warning = "Warning: Required variable not found for test: $test->{name}.\n";
WARN( $warning );
print $warning;
push @{$test_case_result->{warnings}}, $warning;
return;
}
if ( $test->{type} eq 'include' ) {
if ( $test->{perl_code} ){
@ -134,6 +141,13 @@ sub process_test{
$test_case_result->{success} = 0;
$test_case_result->{error_count} += scalar @{$tests_result->{errors}};
}
if ( $tests_result->{warnings} && scalar @{$tests_result->{warnings}} ) {
my @warnings = @{$tests_result->{warnings}};
WARN( @warnings );
print @warnings;
push @{$test_case_result->{warnings}}, @warnings;
return;
}
}
}
elsif ( $test->{type} eq 'batch' ) {
@ -250,12 +264,12 @@ sub _retrieve_from_composed_key {
sub _variables_available {
my( $self, $retained, $test ) = @_;
return 0 if ( $test->{path} =~ /\$\{(.*)\}/ && !$retained->{$1} );
return 0 if ( $test->{path} && $test->{path} =~ /\$\{(.*)\}/ && !$retained->{$1} );
# substitute variables in content
if ( $test->{content} && ref $test->{content} eq 'HASH' ) {
foreach my $content_key (keys %{$test->{content}}) {
return 0 if ( $test->{content}->{$content_key} =~ /\$\{(.*)\}/ && !$retained->{$1} );
return 0 if ( $test->{content}->{$content_key} && $test->{content}->{$content_key} =~ /\$\{(.*)\}/ && !$retained->{$1} );
}
}
return 1;

@ -112,6 +112,10 @@ sub run_tests {
if ( $check_param =~ /.+\..+/ ) {
my @splitted_values = split (/\./, $check_param);
my $check_value = $self->_retrieve_from_composed_key( $result, \@splitted_values, $retained );
# if ($check_value eq 'Not found') {
# push @{$tests_result->{warnings}}, "Warning: Required variable not found for test: $test_name.\n";
# return $tests_result;
# }
if ( $conditions->{$condition}->{$check_param} eq 'defined' ) {
DEBUG ( "Checking ok for defined" );
if ( ok(defined $check_value, $test_name) ) {
@ -202,6 +206,9 @@ sub _retrieve_from_composed_key {
return $body->{$splitted_values->[1]};
}
elsif ( $splitted_values->[0] =~ /\$\{(.*)\}/ ) {
if ( !defined $retained->{$1} ) {
return 'Not found';
}
my $value = $retained->{$1};
grep { $value = $value->{$splitted_values->[$_]} } (1..(scalar @$splitted_values - 1));
return $value;

@ -79,6 +79,9 @@ sub worker {
$exit_code = 1;
print $result->{error_count}." errors were found!\n";
}
if ( $result->{warnings} && scalar @{$result->{warnings}} > 0 ) {
print "Warnings were found!\n";
}
print "Tests for $test_file took $total_time seconds.\n\n";
}
return $exit_code;

Loading…
Cancel
Save