Skip to content

Commit

Permalink
- Fix integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
rathnapandi committed Dec 7, 2023
1 parent e261899 commit b910d9b
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ private void removeFromCache(String id, Type type) {
}

public void saveAPIAccess(List<APIAccess> apiAccess, AbstractEntity entity, Type type) throws AppException {
List<APIAccess> existingAPIAccess = getAPIAccess(entity, type);
List<APIAccess> existingAPIAccess = getAPIAccess(entity, type, true);
List<APIAccess> toBeRemovedAccesses = getMissingAPIAccesses(existingAPIAccess, apiAccess);
List<APIAccess> toBeAddedAccesses = getMissingAPIAccesses(apiAccess, existingAPIAccess);
for (APIAccess access : toBeRemovedAccesses) {
Expand Down Expand Up @@ -194,7 +194,7 @@ public void populateApiId(APIAccess apiAccess) throws AppException {
}

public void createAPIAccess(APIAccess apiAccess, AbstractEntity parentEntity, Type type) throws AppException {
List<APIAccess> existingAPIAccess = getAPIAccess(parentEntity, type);
List<APIAccess> existingAPIAccess = getAPIAccess(parentEntity, type, true);
if (existingAPIAccess != null && existingAPIAccess.contains(apiAccess)) {
apiAccess.setId(existingAPIAccess.get(0).getId());
return;
Expand Down Expand Up @@ -242,11 +242,6 @@ public void createAPIAccess(APIAccess apiAccess, AbstractEntity parentEntity, Ty
}

public void deleteAPIAccess(APIAccess apiAccess, AbstractEntity parentEntity, Type type) throws AppException {
List<APIAccess> existingAPIAccess = getAPIAccess(parentEntity, type);
// Nothing to delete
if (existingAPIAccess != null && !existingAPIAccess.contains(apiAccess)) {
return;
}
try {
URI uri = new URIBuilder(cmd.getAPIManagerURL()).setPath(cmd.getApiBasepath() + "/" + type + "/" + parentEntity.getId() + "/apis/" + apiAccess.getId()).build();
// Use an admin account for this request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,19 @@ public void run(@Optional @CitrusResource TestContext context) throws IOExceptio
http(builder -> builder.client("apiManager").receive().response(HttpStatus.CREATED).messageType(MessageType.JSON)
.extractFromPayload("$.id", "consumingTestApp1Id")
.extractFromPayload("$.name", "consumingTestApp1Name"));

echo("####### Created Test-Application 1: '${consumingTestApp1Name}' with id: '${consumingTestApp1Id}' #######");

http(builder -> builder.client("apiManager").send().post("/applications/${consumingTestApp1Id}/apikeys")
.header("Content-Type", "application/json")
.payload("{\"applicationId\":\"${consumingTestApp1Id}\",\"enabled\":\"true\"}"));

http(builder -> builder.client("apiManager").receive().response(HttpStatus.CREATED)
.messageType(MessageType.JSON)
.extractFromPayload("$.id", "consumingTestApp1ApiKey"));

echo("####### Generated API-Key: '${consumingTestApp1ApiKey}' for Test-Application 1: '${consumingTestApp1Name}' with id: '${consumingTestApp1Id}' #######");

// ############## Creating Test-Application 2 #################
createVariable("extClientId", RandomNumberFunction.getRandomNumber(15, true));
createVariable("app2Name", "Test-SubApp 2 ${apiNumber}");
Expand All @@ -58,17 +58,17 @@ public void run(@Optional @CitrusResource TestContext context) throws IOExceptio
http(builder -> builder.client("apiManager").receive().response(HttpStatus.CREATED).messageType(MessageType.JSON)
.extractFromPayload("$.id", "consumingTestApp2Id")
.extractFromPayload("$.name", "consumingTestApp2Name"));

echo("####### Created Test-Application 2: '${consumingTestApp2Name}' with id: '${consumingTestApp2Id}' #######");

http(builder -> builder.client("apiManager").send().post("/applications/${consumingTestApp2Id}/extclients").header("Content-Type", "application/json")
.payload("{\"clientId\":\"${extClientId}\",\"enabled\":\"true\"}"));

http(builder -> builder.client("apiManager").receive().response(HttpStatus.CREATED).messageType(MessageType.JSON)
.extractFromPayload("$.id", "consumingTestApp2ClientId"));

echo("####### Added an Ext-ClientID: '${extClientId}' to Test-Application 2: '${consumingTestApp2Name}' with id: '${consumingTestApp2Id}' #######");

// ############## Creating Test-Application 3 #################
createVariable("app3Name", "Test-SubApp 3 ${apiNumber}");
http(builder -> builder.client("apiManager").send().post("/applications").header("Content-Type", "application/json")
Expand All @@ -77,71 +77,71 @@ public void run(@Optional @CitrusResource TestContext context) throws IOExceptio
http(builder -> builder.client("apiManager").receive().response(HttpStatus.CREATED).messageType(MessageType.JSON)
.extractFromPayload("$.id", "consumingTestApp3Id")
.extractFromPayload("$.name", "consumingTestApp3Name"));

echo("####### Created Test-Application 3: '${consumingTestApp3Name}' with id: '${consumingTestApp3Id}' withouth App-Credentials #######");

echo("####### Importing API: '${apiName}' on path: '${apiPath}' for the first time #######");

createVariable(ImportTestAction.API_DEFINITION, "/com/axway/apim/test/files/basic/petstore.json");
createVariable(ImportTestAction.API_CONFIG, "/com/axway/apim/test/files/applications/1_api-with-1-org-some-apps.json");
createVariable("state", "published");
createVariable("orgName", "${orgName}");
createVariable("version", "1.0.0");
createVariable("expectedReturnCode", "0");
swaggerImport.doExecute(context);

echo("####### Validate API: '${apiName}' has been created #######");
http(builder -> builder.client("apiManager").send().get("/proxies").header("Content-Type", "application/json"));

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

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

echo("####### Validate API with ID: '${apiId}' is granted to Org2: ${orgName2} (${orgId2}) #######");
http(builder -> builder.client("apiManager").send().get("/organizations/${orgId2}/apis").header("Content-Type", "application/json"));

http(builder -> builder.client("apiManager").receive().response(HttpStatus.OK).messageType(MessageType.JSON)
.validate("$.[?(@.apiId=='${apiId}')].state", "approved")
.validate("$.[?(@.apiId=='${apiId}')].enabled", "true"));

echo("####### Validate created application 3 has an active subscription to the API (Based on the name) #######");
http(builder -> builder.client("apiManager").send().get("/applications/${consumingTestApp3Id}/apis").header("Content-Type", "application/json"));

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

echo("####### Validate Application 1 has an active subscription to the API (based on the API-Key) #######");
http(builder -> builder.client("apiManager").send().get("/applications/${consumingTestApp1Id}/apis").header("Content-Type", "application/json"));

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

echo("####### Validate Application 2 has an active subscription to the API (based on the Ext-Client-Id) #######");
http(builder -> builder.client("apiManager").send().get("/applications/${consumingTestApp2Id}/apis")
.header("Content-Type", "application/json"));

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

echo("####### Re-Importing same API: '${apiName}' - must result in No-Change #######");
createVariable(ImportTestAction.API_DEFINITION, "/com/axway/apim/test/files/basic/petstore.json");
createVariable(ImportTestAction.API_CONFIG, "/com/axway/apim/test/files/applications/1_api-with-1-org-some-apps.json");
createVariable("state", "published");
createVariable("orgName", "${orgName}");
createVariable("expectedReturnCode", "10");
swaggerImport.doExecute(context);

echo("####### Make sure, the API-ID hasn't changed #######");
http(builder -> builder.client("apiManager").send().get("/proxies/${apiId}").header("Content-Type", "application/json"));

// Check the API is still exposed on the same path
http(builder -> builder.client("apiManager").receive().response(HttpStatus.OK).messageType(MessageType.JSON)
.validate("$.[?(@.path=='${apiPath}')].name", "${apiName}")
.validate("$.[?(@.path=='${apiPath}')].id", "${apiId}")); // Must be the same API-ID as before!

echo("####### Changing FE-API Settings only for: '${apiName}' - Mode: Unpublish/Publish and make sure subscriptions stay #######");
createVariable(ImportTestAction.API_DEFINITION, "/com/axway/apim/test/files/basic/petstore.json");
createVariable(ImportTestAction.API_CONFIG, "/com/axway/apim/test/files/applications/1_api-with-1-org-some-apps.json");
Expand All @@ -150,40 +150,40 @@ public void run(@Optional @CitrusResource TestContext context) throws IOExceptio
createVariable("version", "2.0.0");
createVariable("expectedReturnCode", "0");
swaggerImport.doExecute(context);

echo("####### Validate API: '${apiName}' has been reconfigured (Unpublich/Publish) and appscriptions are recreated #######");
http(builder -> builder.client("apiManager").send().get("/proxies/${apiId}").header("Content-Type", "application/json"));

http(builder -> builder.client("apiManager").receive().response(HttpStatus.OK).messageType(MessageType.JSON)
.validate("$.[?(@.id=='${apiId}')].name", "${apiName}")
.validate("$.[?(@.id=='${apiId}')].state", "published"));

echo("####### Validate Re-Puslished API with ID: '${apiId}' is still granted to Org2: ${orgName2} (${orgId2}) #######");
http(builder -> builder.client("apiManager").send().get("/organizations/${orgId2}/apis").header("Content-Type", "application/json"));

http(builder -> builder.client("apiManager").receive().response(HttpStatus.OK).messageType(MessageType.JSON)
.validate("$.[?(@.apiId=='${apiId}')].state", "approved")
.validate("$.[?(@.apiId=='${apiId}')].enabled", "true"));

echo("####### Validate Application 3 still has an active subscription to the API (Based on the name) #######");
http(builder -> builder.client("apiManager").send().get("/applications/${consumingTestApp3Id}/apis").header("Content-Type", "application/json"));

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

echo("####### Validate Application 1 still has an active subscription to the API (based on the API-Key) #######");
http(builder -> builder.client("apiManager").send().get("/applications/${consumingTestApp1Id}/apis").header("Content-Type", "application/json"));

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

echo("####### Validate Application 2 still has an active subscription to the API (based on the Ext-Client-Id) #######");
http(builder -> builder.client("apiManager").send().get("/applications/${consumingTestApp2Id}/apis")
.header("Content-Type", "application/json"));

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

echo("####### Slightly modify the API: '${apiName}' - Without applications given in the config and mode add (which is the default) (See issue: #117) #######");
createVariable(ImportTestAction.API_DEFINITION, "/com/axway/apim/test/files/basic/petstore.json");
createVariable(ImportTestAction.API_CONFIG, "/com/axway/apim/test/files/basic/4_flexible-status-config.json");
Expand All @@ -193,29 +193,29 @@ public void run(@Optional @CitrusResource TestContext context) throws IOExceptio
createVariable("version", "3.0.0");
createVariable("expectedReturnCode", "0");
swaggerImport.doExecute(context);

echo("####### Validate previous application subscriptions have been restored after the API has been unpublished/updated/published #######");

echo("####### Validate Application 3 still has an active subscription to the API (Based on the name) #######");
http(builder -> builder.client("apiManager").send().get("/applications/${consumingTestApp3Id}/apis").header("Content-Type", "application/json"));

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

echo("####### Validate Application 1 still has an active subscription to the API (based on the API-Key) #######");
http(builder -> builder.client("apiManager").send().get("/applications/${consumingTestApp1Id}/apis").header("Content-Type", "application/json"));

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

echo("####### Validate Application 2 still has an active subscription to the API (based on the Ext-Client-Id) #######");
http(builder -> builder.client("apiManager").send().get("/applications/${consumingTestApp2Id}/apis")
.header("Content-Type", "application/json"));

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


echo("####### Re-Importing same API: '${apiName}' - Without applications subscriptions and mode replace #######");
createVariable(ImportTestAction.API_DEFINITION, "/com/axway/apim/test/files/basic/petstore.json");
createVariable(ImportTestAction.API_CONFIG, "/com/axway/apim/test/files/basic/4_flexible-status-config.json");
Expand All @@ -226,28 +226,28 @@ public void run(@Optional @CitrusResource TestContext context) throws IOExceptio
createVariable("clientAppsMode", String.valueOf(Mode.replace));
createVariable("expectedReturnCode", "0");
swaggerImport.doExecute(context);

echo("####### Validate API: '${apiName}' has been re-created and subscriptions has been removed #######");
http(builder -> builder.client("apiManager").send().get("/proxies").header("Content-Type", "application/json"));

http(builder -> builder.client("apiManager").receive().response(HttpStatus.OK).messageType(MessageType.JSON)
.validate("$.[?(@.path=='${apiPath}')].name", "${apiName}")
.validate("$.[?(@.path=='${apiPath}')].state", "published")
.extractFromPayload("$.[?(@.path=='${apiPath}')].id", "newApiId"));

echo("####### Validate the application no Access to this API #######");
http(builder -> builder.client("apiManager").send().get("/applications/${consumingTestApp1Id}/apis").header("Content-Type", "application/json"));
http(builder -> builder.client("apiManager").receive().response(HttpStatus.OK).messageType(MessageType.JSON)
.validate("$.*.apiId", "@assertThat(not(contains(${newApiId})))@"));

http(builder -> builder.client("apiManager").send().get("/applications/${consumingTestApp2Id}/apis").header("Content-Type", "application/json"));
http(builder -> builder.client("apiManager").receive().response(HttpStatus.OK).messageType(MessageType.JSON)
.validate("$.*.apiId", "@assertThat(not(contains(${newApiId})))@"));

http(builder -> builder.client("apiManager").send().get("/applications/${consumingTestApp3Id}/apis").header("Content-Type", "application/json"));
http(builder -> builder.client("apiManager").receive().response(HttpStatus.OK).messageType(MessageType.JSON)
.validate("$.*.apiId", "@assertThat(not(contains(${newApiId})))@"));

echo("####### Changing the state to unpublished #######");
createVariable(ImportTestAction.API_DEFINITION, "/com/axway/apim/test/files/basic/petstore.json");
createVariable(ImportTestAction.API_CONFIG, "/com/axway/apim/test/files/applications/1_api-with-1-org-some-apps.json");
Expand All @@ -257,7 +257,7 @@ public void run(@Optional @CitrusResource TestContext context) throws IOExceptio
createVariable("orgName", "${orgName}");
createVariable("expectedReturnCode", "0");
swaggerImport.doExecute(context);

echo("####### Re-Import the API forcing a re-creation with an ORG-ADMIN ONLY account, making sure App-Subscriptions a re-created #######");
createVariable(ImportTestAction.API_DEFINITION, "/com/axway/apim/test/files/basic/petstore2.json");
createVariable(ImportTestAction.API_CONFIG, "/com/axway/apim/test/files/applications/1_api-with-1-org-2-app.json");
Expand All @@ -268,36 +268,36 @@ public void run(@Optional @CitrusResource TestContext context) throws IOExceptio
createVariable("useApiAdmin", "false"); // We need to ignore any given admin account!
// We only provide two apps instead of three, but the existing third subscription must stay!
createVariable("testAppName1", "${consumingTestApp1Name}");
createVariable("testAppName2", "${consumingTestApp2Name}");
createVariable("testAppName2", "${consumingTestApp2Name}");
swaggerImport.doExecute(context);

echo("####### Validate API: '${apiName}' has been RE-CREATED #######");
http(builder -> builder.client("apiManager").send().get("/proxies").header("Content-Type", "application/json"));

http(builder -> builder.client("apiManager").receive().response(HttpStatus.OK).messageType(MessageType.JSON)
.validate("$.[?(@.path=='${apiPath}')].name", "${apiName}")
.validate("$.[?(@.path=='${apiPath}')].state", "unpublished")
.extractFromPayload("$.[?(@.path=='${apiPath}')].id", "newApiId"));

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

echo("####### Validate Application 1 STILL has an active subscription to the API (based on the API-Key) #######");
http(builder -> builder.client("apiManager").send().get("/applications/${consumingTestApp1Id}/apis").header("Content-Type", "application/json"));

http(builder -> builder.client("apiManager").receive().response(HttpStatus.OK).messageType(MessageType.JSON)
.validate("$.*.apiId", "${newApiId}"));
// As the apps 3 & 2 now belong to a different organization the org-admin cannot see / re-subscribe them
/*

// As the apps 3 & 2 now belong to a different organization the org-admin cannot see / re-subscribe them
/*
echo("####### Validate created application 3 STILL has an active subscription to the API (Based on the name) #######");
http(builder -> builder.client("apiManager").send().get("/applications/${consumingTestApp3Id}/apis").header("Content-Type", "application/json"));
http(builder -> builder.client("apiManager").receive().response(HttpStatus.OK).messageType(MessageType.JSON)
.validate("$.*.apiId", "${newApiId}"));
echo("####### Validate Application 2 STILL has an active subscription to the API (based on the Ext-Client-Id) #######");
http(builder -> builder.client("apiManager").send().get("/applications/${consumingTestApp2Id}/apis")
.header("Content-Type", "application/json"));
http(builder -> builder.client("apiManager").receive().response(HttpStatus.OK).messageType(MessageType.JSON)
.validate("$.*.apiId", "${newApiId}")); */
}
Expand Down

0 comments on commit b910d9b

Please sign in to comment.