11package com .axway .apim .test .quota ;
22
3- import org .springframework .beans .factory .annotation .Autowired ;
3+ import java .io .IOException ;
4+
45import org .springframework .http .HttpStatus ;
6+ import org .testng .annotations .Optional ;
7+ import org .testng .annotations .Parameters ;
58import org .testng .annotations .Test ;
69
10+ import com .axway .apim .lib .errorHandling .AppException ;
711import com .axway .apim .test .ImportTestAction ;
12+ import com .consol .citrus .annotations .CitrusResource ;
813import com .consol .citrus .annotations .CitrusTest ;
9- import com .consol .citrus .dsl .testng .TestNGCitrusTestDesigner ;
14+ import com .consol .citrus .context .TestContext ;
15+ import com .consol .citrus .dsl .testng .TestNGCitrusTestRunner ;
1016import com .consol .citrus .functions .core .RandomNumberFunction ;
1117import com .consol .citrus .message .MessageType ;
1218
1319@ Test
14- public class ValidateAppQuotaStaysTestIT extends TestNGCitrusTestDesigner {
15-
16- @ Autowired
20+ public class ValidateAppQuotaStaysTestIT extends TestNGCitrusTestRunner {
21+
1722 private ImportTestAction swaggerImport ;
1823
1924 @ CitrusTest
20- public void run () {
25+ @ Test @ Parameters ("context" )
26+ public void run (@ Optional @ CitrusResource TestContext context ) throws IOException , AppException , InterruptedException {
27+ swaggerImport = new ImportTestAction ();
28+
2129 description ("Validates potentially configured application quota stay after re-importing an API." );
2230
2331 variable ("apiNumber" , RandomNumberFunction .getRandomNumber (3 , true ));
@@ -26,19 +34,12 @@ public void run() {
2634
2735 createVariable ("appName" , "Test App with quota ${apiNumber}" );
2836 echo ("####### Creating test a application: '${appName}' used to configure some sample quotas #######" );
29- http ().client ("apiManager" )
30- .send ()
31- .post ("/applications" )
32- .name ("orgCreatedRequest" )
33- .header ("Content-Type" , "application/json" )
34- .payload ("{\" name\" :\" ${appName}\" ,\" apis\" :[],\" organizationId\" :\" ${orgId}\" }" );
37+ http (builder -> builder .client ("apiManager" ).send ().post ("/applications" ).name ("orgCreatedRequest" ) .header ("Content-Type" , "application/json" )
38+ .payload ("{\" name\" :\" ${appName}\" ,\" apis\" :[],\" organizationId\" :\" ${orgId}\" }" ));
3539
36- http ().client ("apiManager" )
37- .receive ()
38- .response (HttpStatus .CREATED )
39- .messageType (MessageType .JSON )
40+ http (builder -> builder .client ("apiManager" ).receive ().response (HttpStatus .CREATED ).messageType (MessageType .JSON )
4041 .extractFromPayload ("$.id" , "consumingTestAppId" )
41- .extractFromPayload ("$.name" , "consumingTestAppName" );
42+ .extractFromPayload ("$.name" , "consumingTestAppName" )) ;
4243
4344 echo ("####### Importing API: '${apiName}' on path: '${apiPath}' for the first time #######" );
4445 createVariable (ImportTestAction .API_DEFINITION , "/com/axway/apim/test/files/basic/petstore.json" );
@@ -48,27 +49,23 @@ public void run() {
4849 createVariable ("applicationPeriod" , "hour" );
4950 createVariable ("systemPeriod" , "day" );
5051 createVariable ("ignoreQuotas" , "true" );
51- action ( swaggerImport );
52+ swaggerImport . doExecute ( context );
5253
5354 echo ("####### Validate API: '${apiName}' has a been imported #######" );
54- http () .client ("apiManager" ).send ().get ("/proxies" ).name ("api" ).header ("Content-Type" , "application/json" );
55+ http (builder -> builder .client ("apiManager" ).send ().get ("/proxies" ).name ("api" ).header ("Content-Type" , "application/json" ) );
5556
56- http ().client ("apiManager" )
57- .receive ()
58- .response (HttpStatus .OK )
59- .messageType (MessageType .JSON )
57+ http (builder -> builder .client ("apiManager" ).receive ().response (HttpStatus .OK ).messageType (MessageType .JSON )
6058 .validate ("$.[?(@.path=='${apiPath}')].name" , "${apiName}" )
6159 .validate ("$.[?(@.path=='${apiPath}')].state" , "published" )
62- .extractFromPayload ("$.[?(@.path=='${apiPath}')].id" , "apiId" );
60+ .extractFromPayload ("$.[?(@.path=='${apiPath}')].id" , "apiId" )) ;
6361
6462 echo ("####### Get the operations/methods for the created API #######" );
65- http () .client ("apiManager" ).send ().get ("/proxies/${apiId}/operations" ).header ("Content-Type" , "application/json" );
63+ http (builder -> builder .client ("apiManager" ).send ().get ("/proxies/${apiId}/operations" ).header ("Content-Type" , "application/json" ) );
6664
67- http () .client ("apiManager" ).receive ().response (HttpStatus .OK ).messageType (MessageType .JSON ).extractFromPayload ("$.[?(@.name=='updatePetWithForm')].id" , "testMethodId" );
65+ http (builder -> builder .client ("apiManager" ).receive ().response (HttpStatus .OK ).messageType (MessageType .JSON ).extractFromPayload ("$.[?(@.name=='updatePetWithForm')].id" , "testMethodId" ) );
6866
6967 echo ("####### Configure some Application-Quota for the imported API #######" );
70- http ().client ("apiManager" )
71- .send ()
68+ http (builder -> builder .client ("apiManager" ).send ()
7269 .post ("/applications/${consumingTestAppId}/quota" )
7370 .name ("createQuotaRequest" )
7471 .header ("Content-Type" , "application/json" )
@@ -78,7 +75,7 @@ public void run() {
7875 + "{\" api\" :\" *\" ,\" method\" :\" *\" ,\" type\" :\" throttle\" ,\" config\" :{\" period\" :\" hour\" ,\" per\" :1,\" messages\" :1000}}, "
7976 + "{\" api\" :\" ${apiId}\" ,\" method\" :\" ${testMethodId}\" ,\" type\" :\" throttle\" ,\" config\" :{\" period\" :\" day\" ,\" per\" :2,\" messages\" :100000}} "
8077 + "],"
81- + "\" system\" :false}" );
78+ + "\" system\" :false}" )) ;
8279
8380 echo ("####### Enforce Re-Creation of API - Application quotas must stay #######" );
8481 createVariable (ImportTestAction .API_DEFINITION , "/com/axway/apim/test/files/basic/petstore2.json" );
@@ -89,32 +86,26 @@ public void run() {
8986 createVariable ("systemPeriod" , "day" );
9087 createVariable ("ignoreQuotas" , "true" );
9188 createVariable ("enforce" , "true" );
92- action ( swaggerImport );
89+ swaggerImport . doExecute ( context );
9390
9491 echo ("####### The API has been updated - Reload the the API-ID #######" );
95- http () .client ("apiManager" ).send ().get ("/proxies" ).header ("Content-Type" , "application/json" );
92+ http (builder -> builder .client ("apiManager" ).send ().get ("/proxies" ).header ("Content-Type" , "application/json" ) );
9693
97- http ().client ("apiManager" )
98- .receive ()
99- .response (HttpStatus .OK )
100- .messageType (MessageType .JSON )
94+ http (builder -> builder .client ("apiManager" ).receive ().response (HttpStatus .OK ).messageType (MessageType .JSON )
10195 .validate ("$.[?(@.path=='${apiPath}')].name" , "${apiName}" )
10296 .validate ("$.[?(@.path=='${apiPath}')].state" , "published" )
103- .extractFromPayload ("$.[?(@.path=='${apiPath}')].id" , "newApiId" );
97+ .extractFromPayload ("$.[?(@.path=='${apiPath}')].id" , "newApiId" )) ;
10498
10599 echo ("####### And reload the first methodId as we need it for validation #######" );
106- http () .client ("apiManager" ).send ().get ("/proxies/${newApiId}/operations" ).header ("Content-Type" , "application/json" );
107- http () .client ("apiManager" ).receive ().response (HttpStatus .OK ).messageType (MessageType .JSON ).extractFromPayload ("$.[?(@.name=='updatePetWithForm')].id" , "newTestMethodId" );
100+ http (builder -> builder .client ("apiManager" ).send ().get ("/proxies/${newApiId}/operations" ).header ("Content-Type" , "application/json" ) );
101+ http (builder -> builder .client ("apiManager" ).receive ().response (HttpStatus .OK ).messageType (MessageType .JSON ).extractFromPayload ("$.[?(@.name=='updatePetWithForm')].id" , "newTestMethodId" ) );
108102
109103 echo ("####### Load the application quota and validate it is still present #######" );
110104 echo ("####### newApiId: '${newApiId}' #######" );
111105 echo ("####### newTestMethodId: '${newTestMethodId}' #######" );
112- http () .client ("apiManager" ).send ().get ("/applications/${consumingTestAppId}/quota" );
106+ http (builder -> builder .client ("apiManager" ).send ().get ("/applications/${consumingTestAppId}/quota" ) );
113107
114- http ().client ("apiManager" )
115- .receive ()
116- .response (HttpStatus .OK )
117- .messageType (MessageType .JSON )
108+ http (builder -> builder .client ("apiManager" ).receive ().response (HttpStatus .OK ).messageType (MessageType .JSON )
118109 .validate ("$.type" , "APPLICATION" )
119110 // First validate the "All methods" quota is still there
120111 .validate ("$.restrictions.[?(@.api=='*')].type" , "throttle" )
@@ -130,6 +121,6 @@ public void run() {
130121 .validate ("$.restrictions.[?(@.api=='${newApiId}' && @.method=='${newTestMethodId}')].type" , "throttle" )
131122 //.validate("$.restrictions.[?(@.api=='${newApiId}' && @.method=='${newTestMethodId}')].config.period", "day")
132123 .validate ("$.restrictions.[?(@.api=='${newApiId}' && @.method=='${newTestMethodId}')].config.per" , "2" )
133- .validate ("$.restrictions.[?(@.api=='${newApiId}' && @.method=='${newTestMethodId}')].config.messages" , "100000" );
124+ .validate ("$.restrictions.[?(@.api=='${newApiId}' && @.method=='${newTestMethodId}')].config.messages" , "100000" )) ;
134125 }
135126}
0 commit comments