Skip to content

Commit b479808

Browse files
author
Chris Wiechmann
committed
Merge branch 'develop' into test-with-7.7-20200130
2 parents f38c202 + 1d56ca7 commit b479808

5 files changed

Lines changed: 74 additions & 91 deletions

File tree

modules/api-import/src/main/java/com/axway/apim/APIImportApp.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ public static int importAPI(String args[]) {
9090
APIChangeState changes = new APIChangeState(actualAPI, desiredAPI);
9191
new APIImportManager().applyChanges(changes);
9292
APIPropertiesExport.getInstance().store();
93-
LOG.info("Successfully replicated API: "+desiredAPI.getName()+" ("+desiredAPI.getId()+") into API-Manager");
9493
return 0;
9594
} catch (AppException ap) {
9695
APIPropertiesExport.getInstance().store(); // Try to create it, even

modules/api-import/src/test/java/com/axway/apim/test/quota/APIBasicQuotaTestIT.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class APIBasicQuotaTestIT extends TestNGCitrusTestRunner {
2424

2525
@CitrusTest
2626
@Test @Parameters("context")
27-
public void run(@Optional @CitrusResource TestContext context) throws IOException, AppException {
27+
public void run(@Optional @CitrusResource TestContext context) throws IOException, AppException, InterruptedException {
2828
swaggerImport = new ImportTestAction();
2929
description("Import an API containing a quota definition");
3030

@@ -53,8 +53,10 @@ public void run(@Optional @CitrusResource TestContext context) throws IOExceptio
5353
.extractFromPayload("$.[?(@.path=='${apiPath}')].id", "apiId"));
5454

5555
echo("####### Check System-Quotas have been setup as configured #######");
56+
echo("####### ############ Sleep 5 seconds ##################### #######");
57+
Thread.sleep(5000);
5658
http(builder -> builder.client("apiManager").send().get("/quotas/00000000-0000-0000-0000-000000000000").header("Content-Type", "application/json"));
57-
59+
Thread.sleep(5000);
5860
http(builder -> builder.client("apiManager").receive().response(HttpStatus.OK).messageType(MessageType.JSON)
5961
.validate("$.restrictions.[?(@.api=='${apiId}')].type", "throttle")
6062
.validate("$.restrictions.[?(@.api=='${apiId}')].method", "*")
Lines changed: 26 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,31 @@
11
package com.axway.apim.test.quota;
22

3-
import org.springframework.beans.factory.annotation.Autowired;
3+
import java.io.IOException;
4+
45
import org.springframework.http.HttpStatus;
6+
import org.testng.annotations.Optional;
7+
import org.testng.annotations.Parameters;
58
import org.testng.annotations.Test;
69

7-
import com.axway.apim.adapter.APIManagerAdapter;
10+
import com.axway.apim.lib.errorHandling.AppException;
811
import com.axway.apim.test.ImportTestAction;
12+
import com.consol.citrus.annotations.CitrusResource;
913
import com.consol.citrus.annotations.CitrusTest;
10-
import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;
14+
import com.consol.citrus.context.TestContext;
15+
import com.consol.citrus.dsl.testng.TestNGCitrusTestRunner;
1116
import com.consol.citrus.functions.core.RandomNumberFunction;
1217
import com.consol.citrus.message.MessageType;
1318

1419
@Test
15-
public class AppOrSystemQuotaOnlyTestIT extends TestNGCitrusTestDesigner {
20+
public class AppOrSystemQuotaOnlyTestIT extends TestNGCitrusTestRunner {
1621

17-
@Autowired
1822
private ImportTestAction swaggerImport;
1923

2024
@CitrusTest
21-
public void run() throws InterruptedException {
25+
@Test @Parameters("context")
26+
public void run(@Optional @CitrusResource TestContext context) throws IOException, AppException, InterruptedException {
27+
swaggerImport = new ImportTestAction();
28+
2229
description("Validates quota is set when only System- or Application-Quota is configured (see bug #55)");
2330

2431
variable("apiNumber", RandomNumberFunction.getRandomNumber(3, true));
@@ -33,69 +40,48 @@ public void run() throws InterruptedException {
3340
createVariable("expectedReturnCode", "0");
3441
createVariable("systemPeriod", "hour");
3542
createVariable("messages", "345");
36-
action(swaggerImport);
43+
swaggerImport.doExecute(context);
3744

3845
echo("####### Validate API: '${apiName}' has a been imported including System-Quota #######");
39-
http().client("apiManager")
40-
.send()
41-
.get("/proxies")
42-
.name("api")
43-
.header("Content-Type", "application/json");
46+
http(builder -> builder.client("apiManager").send().get("/proxies").name("api").header("Content-Type", "application/json"));
4447

45-
http().client("apiManager")
46-
.receive()
47-
.response(HttpStatus.OK)
48-
.messageType(MessageType.JSON)
48+
http(builder -> builder.client("apiManager").receive().response(HttpStatus.OK).messageType(MessageType.JSON)
4949
.validate("$.[?(@.path=='${apiPath}')].name", "${apiName}")
5050
.validate("$.[?(@.path=='${apiPath}')].state", "published")
51-
.extractFromPayload("$.[?(@.path=='${apiPath}')].id", "apiId");
51+
.extractFromPayload("$.[?(@.path=='${apiPath}')].id", "apiId"));
5252

5353
echo("####### Check System-Quotas have been setup as configured #######");
5454
echo("####### ############ Sleep 5 seconds ##################### #######");
5555
Thread.sleep(5000);
56-
http().client("apiManager")
57-
.send()
58-
.get("/quotas/00000000-0000-0000-0000-000000000000")
59-
.name("api")
60-
.header("Content-Type", "application/json");
56+
http(builder -> builder.client("apiManager").send().get("/quotas/00000000-0000-0000-0000-000000000000").name("api").header("Content-Type", "application/json"));
6157
Thread.sleep(5000);
62-
http().client("apiManager")
63-
.receive()
64-
.response(HttpStatus.OK)
65-
.messageType(MessageType.JSON)
58+
59+
http(builder -> builder.client("apiManager").receive().response(HttpStatus.OK).messageType(MessageType.JSON)
6660
.validate("$.restrictions.[?(@.api=='${apiId}')].type", "throttle")
6761
.validate("$.restrictions.[?(@.api=='${apiId}')].method", "*")
6862
.validate("$.restrictions.[?(@.api=='${apiId}')].config.messages", "345")
6963
//.validate("$.restrictions.[?(@.api=='${apiId}')].config.period", "hour")
70-
.validate("$.restrictions.[?(@.api=='${apiId}')].config.per", "5");
64+
.validate("$.restrictions.[?(@.api=='${apiId}')].config.per", "5"));
7165

7266
echo("####### Importing API: '${apiName}' on path: '${apiPath}' with Appliction-Quota only #######");
7367
createVariable(ImportTestAction.API_DEFINITION, "/com/axway/apim/test/files/basic/petstore.json");
7468
createVariable(ImportTestAction.API_CONFIG, "/com/axway/apim/test/files/quota/4_api-with-app-quota-only2.json");
7569
createVariable("state", "published");
7670
createVariable("expectedReturnCode", "0");
7771
createVariable("applicationPeriod", "day");
78-
action(swaggerImport);
72+
swaggerImport.doExecute(context);
7973

8074
echo("####### Check Application-Quotas have been setup as configured #######");
8175
echo("####### ############ Sleep 5 seconds ##################### #######");
8276
Thread.sleep(5000);
83-
http().client("apiManager")
84-
.send()
85-
.get("/quotas/00000000-0000-0000-0000-000000000001")
86-
.name("api")
87-
.header("Content-Type", "application/json");
77+
http(builder -> builder.client("apiManager").send().get("/quotas/00000000-0000-0000-0000-000000000001").name("api") .header("Content-Type", "application/json"));
8878
Thread.sleep(5000);
89-
http().client("apiManager")
90-
.receive()
91-
.response(HttpStatus.OK)
92-
.messageType(MessageType.JSON)
79+
http(builder -> builder.client("apiManager").receive().response(HttpStatus.OK).messageType(MessageType.JSON)
9380
.validate("$.restrictions.[?(@.api=='${apiId}')].type", "throttlemb")
9481
.validate("$.restrictions.[?(@.api=='${apiId}')].method", "*")
9582
.validate("$.restrictions.[?(@.api=='${apiId}')].config.mb", "787")
96-
// Disabled, as the API-Manager sometime doesn't return the period information immediately.
97-
//.validate("$.restrictions.[?(@.api=='${apiId}')].config.period", "day")
98-
.validate("$.restrictions.[?(@.api=='${apiId}')].config.per", "4");
83+
.validate("$.restrictions.[?(@.api=='${apiId}')].config.period", "day")
84+
.validate("$.restrictions.[?(@.api=='${apiId}')].config.per", "4"));
9985

10086
}
10187
}

modules/api-import/src/test/java/com/axway/apim/test/quota/QuotaModeReplaceTestIT.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,10 @@ public void run(@Optional @CitrusResource TestContext context) throws IOExceptio
8989
swaggerImport.doExecute(context);
9090

9191
echo("####### Check Application-Quotas have been setup as configured #######");
92-
if(APIManagerAdapter.hasAPIManagerVersion("7.7.20200130")) {
93-
echo("####### ############ Sleep 5 seconds ##################### #######");
94-
Thread.sleep(5000); // Starting with this version, we need to wait a few milliseconds, otherwise the REST-API doesn't return the complete set of quotas
95-
}
92+
echo("####### ############ Sleep 5 seconds ##################### #######");
93+
Thread.sleep(5000);
9694
http(builder -> builder.client("apiManager").send().get("/quotas/"+APIManagerAdapter.APPLICATION_DEFAULT_QUOTA).header("Content-Type", "application/json"));
95+
Thread.sleep(5000);
9796

9897
http(builder -> builder.client("apiManager").receive().response(HttpStatus.OK).messageType(MessageType.JSON)
9998
// The method specific quotas must be have been removed
@@ -106,7 +105,10 @@ public void run(@Optional @CitrusResource TestContext context) throws IOExceptio
106105
.validate("$.restrictions.[?(@.api=='${apiId}' && @.method=='*'&& @.type=='throttlemb')].config.per", "1"));
107106

108107
echo("####### Check that only the configured quota remains and previouls configured are removed #######");
108+
echo("####### ############ Sleep 5 seconds ##################### #######");
109+
Thread.sleep(5000);
109110
http(builder -> builder.client("apiManager").send().get("/quotas/"+APIManagerAdapter.SYSTEM_API_QUOTA).header("Content-Type", "application/json"));
111+
Thread.sleep(5000);
110112

111113
http(builder -> builder.client("apiManager").receive().response(HttpStatus.OK).messageType(MessageType.JSON)
112114
// The method specific quotas must be have been removed
@@ -137,7 +139,10 @@ public void run(@Optional @CitrusResource TestContext context) throws IOExceptio
137139
swaggerImport.doExecute(context);
138140

139141
echo("####### Check System-Quotas have been updated #######");
142+
echo("####### ############ Sleep 5 seconds ##################### #######");
143+
Thread.sleep(5000);
140144
http(builder -> builder.client("apiManager").send().get("/quotas/00000000-0000-0000-0000-000000000000").header("Content-Type", "application/json"));
145+
Thread.sleep(5000);
141146

142147
http(builder -> builder.client("apiManager").receive().response(HttpStatus.OK).messageType(MessageType.JSON)
143148
.validate("$.restrictions.[?(@.api=='${apiId}')].type", "throttle")
Lines changed: 35 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,31 @@
11
package com.axway.apim.test.quota;
22

3-
import org.springframework.beans.factory.annotation.Autowired;
3+
import java.io.IOException;
4+
45
import org.springframework.http.HttpStatus;
6+
import org.testng.annotations.Optional;
7+
import org.testng.annotations.Parameters;
58
import org.testng.annotations.Test;
69

10+
import com.axway.apim.lib.errorHandling.AppException;
711
import com.axway.apim.test.ImportTestAction;
12+
import com.consol.citrus.annotations.CitrusResource;
813
import 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;
1016
import com.consol.citrus.functions.core.RandomNumberFunction;
1117
import 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

Comments
 (0)