Skip to content

Commit 0fd1d0d

Browse files
author
Chris Wiechmann
authored
Merge branch 'develop' into proxy-support
2 parents 332d2b5 + b2e799a commit 0fd1d0d

4 files changed

Lines changed: 84 additions & 11 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
88
### Fixed
99
- Created BE-API response was parsing the response wrong. This could lead to an issue, if the API contains a createdOn field. (See issue [#112](https://github.com/Axway-API-Management-Plus/apim-cli/issues/112))
1010
- Unicode API-Name was not shown correctly in the Backend-API overview (See issue [#113](https://github.com/Axway-API-Management-Plus/apim-cli/issues/113))
11+
- Application-Subscription not restored, when API is Republished to be updated (See issue [#114](https://github.com/Axway-API-Management-Plus/apim-cli/issues/114))
1112

1213
## [1.3.0] 2020-11-10
1314
### Added

modules/apis/src/main/java/com/axway/apim/apiimport/actions/RepublishToUpdateAPI.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
package com.axway.apim.apiimport.actions;
22

3+
import java.util.ArrayList;
4+
35
import org.slf4j.Logger;
46
import org.slf4j.LoggerFactory;
57

68
import com.axway.apim.adapter.APIStatusManager;
79
import com.axway.apim.api.API;
10+
import com.axway.apim.api.model.Organization;
11+
import com.axway.apim.api.model.apps.ClientApplication;
812
import com.axway.apim.apiimport.APIChangeState;
13+
import com.axway.apim.lib.CoreParameters;
14+
import com.axway.apim.lib.CoreParameters.Mode;
915
import com.axway.apim.lib.errorHandling.AppException;
1016

1117
public class RepublishToUpdateAPI {
@@ -16,6 +22,21 @@ public void execute(APIChangeState changes) throws AppException {
1622

1723
API actualAPI = changes.getActualAPI();
1824

25+
Mode clientAppsMode = CoreParameters.getInstance().getClientAppsMode();
26+
Mode clientOrgsMode = CoreParameters.getInstance().getClientOrgsMode();
27+
// Get existing Orgs and Apps, as they will be lost when the API gets unpublished
28+
if(clientAppsMode==Mode.add && actualAPI.getApplications()!=null && changes.getDesiredAPI().getApplications()!=null) {
29+
changes.getDesiredAPI().getApplications().addAll(actualAPI.getApplications());
30+
// Reset the applications to have them re-created
31+
actualAPI.setApplications(new ArrayList<ClientApplication>());
32+
}
33+
if(clientOrgsMode==Mode.add && actualAPI.getClientOrganizations()!=null && changes.getDesiredAPI().getClientOrganizations()!=null) {
34+
// Take over existing organizations
35+
changes.getDesiredAPI().getClientOrganizations().addAll(actualAPI.getClientOrganizations());
36+
// Delete them, so that they are re-created
37+
actualAPI.setClientOrganizations(new ArrayList<Organization>());
38+
}
39+
1940
// 1. Create BE- and FE-API (API-Proxy) / Including updating all belonging props!
2041
// This also includes all CONFIGURED application subscriptions and client-orgs
2142
// But not potentially existing Subscriptions or manually created Client-Orgs

modules/apis/src/test/java/com/axway/apim/test/applications/ApplicationSubscriptionTestIT.java

Lines changed: 61 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public void run(@Optional @CitrusResource TestContext context) throws IOExceptio
5858
createVariable("extClientId", RandomNumberFunction.getRandomNumber(15, true));
5959
createVariable("app2Name", "Test-SubApp 2 ${apiNumber}");
6060
http(builder -> builder.client("apiManager").send().post("/applications").header("Content-Type", "application/json")
61-
.payload("{\"name\":\"${app2Name}\",\"apis\":[],\"organizationId\":\"${orgId}\"}"));
61+
.payload("{\"name\":\"${app2Name}\",\"apis\":[],\"organizationId\":\"${orgId2}\"}"));
6262

6363
http(builder -> builder.client("apiManager").receive().response(HttpStatus.CREATED).messageType(MessageType.JSON)
6464
.extractFromPayload("$.id", "consumingTestApp2Id")
@@ -77,7 +77,7 @@ public void run(@Optional @CitrusResource TestContext context) throws IOExceptio
7777
// ############## Creating Test-Application 3 #################
7878
createVariable("app3Name", "Test-SubApp 3 ${apiNumber}");
7979
http(builder -> builder.client("apiManager").send().post("/applications").header("Content-Type", "application/json")
80-
.payload("{\"name\":\"${app3Name}\",\"apis\":[],\"organizationId\":\"${orgId}\"}"));
80+
.payload("{\"name\":\"${app3Name}\",\"apis\":[],\"organizationId\":\"${orgId2}\"}"));
8181

8282
http(builder -> builder.client("apiManager").receive().response(HttpStatus.CREATED).messageType(MessageType.JSON)
8383
.extractFromPayload("$.id", "consumingTestApp3Id")
@@ -91,6 +91,7 @@ public void run(@Optional @CitrusResource TestContext context) throws IOExceptio
9191
createVariable(ImportTestAction.API_CONFIG, "/com/axway/apim/test/files/applications/1_api-with-1-org-some-apps.json");
9292
createVariable("state", "published");
9393
createVariable("orgName", "${orgName}");
94+
createVariable("version", "1.0.0");
9495
createVariable("expectedReturnCode", "0");
9596
swaggerImport.doExecute(context);
9697

@@ -104,6 +105,13 @@ public void run(@Optional @CitrusResource TestContext context) throws IOExceptio
104105

105106
echo("####### API has been created with ID: '${apiId}' #######");
106107

108+
echo("####### Validate API with ID: '${apiId}' is granted to Org2: ${orgName2} (${orgId2}) #######");
109+
http(builder -> builder.client("apiManager").send().get("/organizations/${orgId2}/apis").header("Content-Type", "application/json"));
110+
111+
http(builder -> builder.client("apiManager").receive().response(HttpStatus.OK).messageType(MessageType.JSON)
112+
.validate("$.[?(@.apiId=='${apiId}')].state", "approved")
113+
.validate("$.[?(@.apiId=='${apiId}')].enabled", "true"));
114+
107115
echo("####### Validate created application 3 has an active subscription to the API (Based on the name) #######");
108116
http(builder -> builder.client("apiManager").send().get("/applications/${consumingTestApp3Id}/apis").header("Content-Type", "application/json"));
109117

@@ -139,8 +147,50 @@ public void run(@Optional @CitrusResource TestContext context) throws IOExceptio
139147
.validate("$.[?(@.path=='${apiPath}')].name", "${apiName}")
140148
.validate("$.[?(@.path=='${apiPath}')].id", "${apiId}")); // Must be the same API-ID as before!
141149

150+
echo("####### Changing FE-API Settings only for: '${apiName}' - Mode: Unpublish/Publish and make sure subscriptions stay #######");
151+
createVariable(ImportTestAction.API_DEFINITION, "/com/axway/apim/test/files/basic/petstore.json");
152+
createVariable(ImportTestAction.API_CONFIG, "/com/axway/apim/test/files/applications/1_api-with-1-org-some-apps.json");
153+
createVariable("state", "published");
154+
createVariable("orgName", "${orgName}");
155+
createVariable("version", "2.0.0");
156+
createVariable("expectedReturnCode", "0");
157+
swaggerImport.doExecute(context);
158+
159+
echo("####### Validate API: '${apiName}' has been reconfigured (Unpublich/Publish) and appscriptions are recreated #######");
160+
http(builder -> builder.client("apiManager").send().get("/proxies/${apiId}").header("Content-Type", "application/json"));
161+
162+
http(builder -> builder.client("apiManager").receive().response(HttpStatus.OK).messageType(MessageType.JSON)
163+
.validate("$.[?(@.id=='${apiId}')].name", "${apiName}")
164+
.validate("$.[?(@.id=='${apiId}')].state", "published"));
165+
166+
echo("####### Validate Re-Puslished API with ID: '${apiId}' is still granted to Org2: ${orgName2} (${orgId2}) #######");
167+
http(builder -> builder.client("apiManager").send().get("/organizations/${orgId2}/apis").header("Content-Type", "application/json"));
168+
169+
http(builder -> builder.client("apiManager").receive().response(HttpStatus.OK).messageType(MessageType.JSON)
170+
.validate("$.[?(@.apiId=='${apiId}')].state", "approved")
171+
.validate("$.[?(@.apiId=='${apiId}')].enabled", "true"));
172+
173+
echo("####### Validate Application 3 still has an active subscription to the API (Based on the name) #######");
174+
http(builder -> builder.client("apiManager").send().get("/applications/${consumingTestApp3Id}/apis").header("Content-Type", "application/json"));
175+
176+
http(builder -> builder.client("apiManager").receive().response(HttpStatus.OK).messageType(MessageType.JSON)
177+
.validate("$.*.apiId", "${apiId}"));
178+
179+
echo("####### Validate Application 1 still has an active subscription to the API (based on the API-Key) #######");
180+
http(builder -> builder.client("apiManager").send().get("/applications/${consumingTestApp1Id}/apis").header("Content-Type", "application/json"));
181+
182+
http(builder -> builder.client("apiManager").receive().response(HttpStatus.OK).messageType(MessageType.JSON)
183+
.validate("$.*.apiId", "${apiId}"));
184+
185+
echo("####### Validate Application 2 still has an active subscription to the API (based on the Ext-Client-Id) #######");
186+
http(builder -> builder.client("apiManager").send().get("/applications/${consumingTestApp2Id}/apis")
187+
.header("Content-Type", "application/json"));
188+
189+
http(builder -> builder.client("apiManager").receive().response(HttpStatus.OK).messageType(MessageType.JSON)
190+
.validate("$.*.apiId", "${apiId}"));
191+
142192
echo("####### Re-Importing same API: '${apiName}' - Without applications subscriptions and mode replace #######");
143-
createVariable(ImportTestAction.API_DEFINITION, "/com/axway/apim/test/files/basic/petstore2.json");
193+
createVariable(ImportTestAction.API_DEFINITION, "/com/axway/apim/test/files/basic/petstore.json");
144194
createVariable(ImportTestAction.API_CONFIG, "/com/axway/apim/test/files/basic/4_flexible-status-config.json");
145195
createVariable("state", "published");
146196
createVariable("orgName", "${orgName}");
@@ -203,23 +253,24 @@ public void run(@Optional @CitrusResource TestContext context) throws IOExceptio
203253

204254
echo("####### API has been RE-CREATED with ID: '${newApiId}' #######");
205255

206-
echo("####### Validate created application 3 STILL has an active subscription to the API (Based on the name) #######");
207-
http(builder -> builder.client("apiManager").send().get("/applications/${consumingTestApp3Id}/apis").header("Content-Type", "application/json"));
256+
echo("####### Validate Application 1 STILL has an active subscription to the API (based on the API-Key) #######");
257+
http(builder -> builder.client("apiManager").send().get("/applications/${consumingTestApp1Id}/apis").header("Content-Type", "application/json"));
208258

209259
http(builder -> builder.client("apiManager").receive().response(HttpStatus.OK).messageType(MessageType.JSON)
210260
.validate("$.*.apiId", "${newApiId}"));
211261

212-
echo("####### Validate Application 1 STILL has an active subscription to the API (based on the API-Key) #######");
213-
http(builder -> builder.client("apiManager").send().get("/applications/${consumingTestApp1Id}/apis").header("Content-Type", "application/json"));
262+
// As the apps 3 & 2 now belong to a different organization the org-admin cannot see / re-subscribe them
263+
/*
264+
echo("####### Validate created application 3 STILL has an active subscription to the API (Based on the name) #######");
265+
http(builder -> builder.client("apiManager").send().get("/applications/${consumingTestApp3Id}/apis").header("Content-Type", "application/json"));
214266
215267
http(builder -> builder.client("apiManager").receive().response(HttpStatus.OK).messageType(MessageType.JSON)
216268
.validate("$.*.apiId", "${newApiId}"));
217-
218-
echo("####### Validate Application 2 STILL has an active subscription to the API (based on the Ext-Client-Id) #######");
269+
echo("####### Validate Application 2 STILL has an active subscription to the API (based on the Ext-Client-Id) #######");
219270
http(builder -> builder.client("apiManager").send().get("/applications/${consumingTestApp2Id}/apis")
220271
.header("Content-Type", "application/json"));
221272
222273
http(builder -> builder.client("apiManager").receive().response(HttpStatus.OK).messageType(MessageType.JSON)
223-
.validate("$.*.apiId", "${newApiId}"));
274+
.validate("$.*.apiId", "${newApiId}")); */
224275
}
225276
}

modules/apis/src/test/resources/com/axway/apim/test/files/applications/1_api-with-1-org-some-apps.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name":"${apiName}",
33
"path":"${apiPath}",
44
"state":"${state}",
5-
"version":"1.0.1",
5+
"version":"${version}",
66
"organization":"API Development ${orgNumber}",
77
"clientOrganizations":[
88
"${orgName2}"

0 commit comments

Comments
 (0)