Skip to content

Commit a15263b

Browse files
author
Chris Wiechmann
authored
Merge pull request #30 from Axway-API-Management-Plus/yaml-swagger-file-support
Add YAML swagger file support
2 parents cf658f0 + 7114f94 commit a15263b

30 files changed

Lines changed: 360 additions & 74 deletions

modules/api-import/src/test/java/com/axway/apim/test/applications/AppSubscriptionUnpublishedTestIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ public void run() {
160160
echo("####### Trigger a Re-Create of the API: '${apiName}' - Subscription must stay #######");
161161
createVariable(ImportTestAction.API_DEFINITION, "/com/axway/apim/test/files/basic/petstore2.json");
162162
createVariable(ImportTestAction.API_CONFIG, "/com/axway/apim/test/files/basic/minimal-config.json");
163-
createVariable("status", "unpublished");
163+
createVariable("state", "unpublished");
164164
createVariable("expectedReturnCode", "0");
165165
action(swaggerImport);
166166

modules/api-import/src/test/java/com/axway/apim/test/basic/NoAPIDefinitionConfiguredIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public void run(@Optional @CitrusResource TestContext context) throws IOExceptio
3333
echo("####### Calling the tool with a Non-Admin-User. #######");
3434
createVariable(ImportTestAction.API_DEFINITION, "");
3535
createVariable(ImportTestAction.API_CONFIG, "/com/axway/apim/test/files/basic/minimal-config.json");
36-
createVariable("status", "unpublished");
36+
createVariable("state", "unpublished");
3737
createVariable("expectedReturnCode", String.valueOf(ErrorCode.NO_API_DEFINITION_CONFIGURED.getCode()));
3838
swaggerImport.doExecute(context);
3939
}

modules/api-import/src/test/java/com/axway/apim/test/basic/SwaggerFromFileInConfigurationTestIT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public void run(@Optional @CitrusResource TestContext context) throws IOExceptio
3737
createVariable(ImportTestAction.API_DEFINITION, "");
3838
createVariable(ImportTestAction.API_CONFIG, "/com/axway/apim/test/files/basic/minimal-config-with-api-definition.json");
3939
createVariable("testAPIDefinition","./src/test/resources/com/axway/apim/test/files/basic/petstore.json");
40-
createVariable("status", "unpublished");
40+
createVariable("state", "unpublished");
4141
createVariable("expectedReturnCode", "0");
4242
swaggerImport.doExecute(context);
4343

@@ -53,7 +53,7 @@ public void run(@Optional @CitrusResource TestContext context) throws IOExceptio
5353
createVariable(ImportTestAction.API_DEFINITION, "");
5454
createVariable(ImportTestAction.API_CONFIG, "/com/axway/apim/test/files/basic/minimal-config-with-api-definition.json");
5555
createVariable("testAPIDefinition","./src/test/resources/com/axway/apim/test/files/basic/petstore.json");
56-
createVariable("status", "unpublished");
56+
createVariable("state", "unpublished");
5757
createVariable("expectedReturnCode", "10");
5858
swaggerImport.doExecute(context);
5959
}

modules/api-import/src/test/java/com/axway/apim/test/basic/SwaggerFromURLDirectTestIT.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public void run(@Optional @CitrusResource TestContext context) throws IOExceptio
3636
echo("####### Importing API: '${apiName}' on path: '${apiPath}' for the first time from URL #######");
3737
createVariable(ImportTestAction.API_DEFINITION, "https://petstore.swagger.io/v2/swagger.json");
3838
createVariable(ImportTestAction.API_CONFIG, "/com/axway/apim/test/files/basic/minimal-config.json");
39-
createVariable("status", "unpublished");
39+
createVariable("state", "unpublished");
4040
createVariable("expectedReturnCode", "0");
4141
swaggerImport.doExecute(context);
4242

@@ -51,21 +51,21 @@ public void run(@Optional @CitrusResource TestContext context) throws IOExceptio
5151
echo("####### Re-Import API from URL without a change #######");
5252
createVariable(ImportTestAction.API_DEFINITION, "https://petstore.swagger.io/v2/swagger.json");
5353
createVariable(ImportTestAction.API_CONFIG, "/com/axway/apim/test/files/basic/minimal-config.json");
54-
createVariable("status", "unpublished");
54+
createVariable("state", "unpublished");
5555
createVariable("expectedReturnCode", "10");
5656
swaggerImport.doExecute(context);
5757

5858
echo("####### Re-Import API from URL without a change #######");
5959
createVariable(ImportTestAction.API_DEFINITION, "sam/secret@https://petstore.swagger.io/v2/swagger.json");
6060
createVariable(ImportTestAction.API_CONFIG, "/com/axway/apim/test/files/basic/minimal-config.json");
61-
createVariable("status", "unpublished");
61+
createVariable("state", "unpublished");
6262
createVariable("expectedReturnCode", "10");
6363
swaggerImport.doExecute(context);
6464

6565
echo("####### Re-Import API from URL without a change #######");
6666
createVariable(ImportTestAction.API_DEFINITION, "http://petstore.swagger.io/v2/swagger.json");
6767
createVariable(ImportTestAction.API_CONFIG, "/com/axway/apim/test/files/basic/minimal-config.json");
68-
createVariable("status", "unpublished");
68+
createVariable("state", "unpublished");
6969
createVariable("expectedReturnCode", "10");
7070
swaggerImport.doExecute(context);
7171
}

modules/api-import/src/test/java/com/axway/apim/test/basic/SwaggerFromURLInConfigurationDirectTestIT.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public void run(@Optional @CitrusResource TestContext context) throws IOExceptio
3737
createVariable(ImportTestAction.API_DEFINITION, "");
3838
createVariable(ImportTestAction.API_CONFIG, "/com/axway/apim/test/files/basic/minimal-config-with-api-definition.json");
3939
createVariable("testAPIDefinition","https://petstore.swagger.io/v2/swagger.json");
40-
createVariable("status", "unpublished");
40+
createVariable("state", "unpublished");
4141
createVariable("expectedReturnCode", "0");
4242
swaggerImport.doExecute(context);
4343

@@ -53,22 +53,22 @@ public void run(@Optional @CitrusResource TestContext context) throws IOExceptio
5353
createVariable(ImportTestAction.API_DEFINITION, "");
5454
createVariable(ImportTestAction.API_CONFIG, "/com/axway/apim/test/files/basic/minimal-config-with-api-definition.json");
5555
createVariable("testAPIDefinition","https://petstore.swagger.io/v2/swagger.json");
56-
createVariable("status", "unpublished");
56+
createVariable("state", "unpublished");
5757
createVariable("expectedReturnCode", "10");
5858
swaggerImport.doExecute(context);
5959

6060
echo("####### Re-Import API from URL without a change #######");
6161
createVariable(ImportTestAction.API_DEFINITION, "");
6262
createVariable(ImportTestAction.API_CONFIG, "/com/axway/apim/test/files/basic/minimal-config-with-api-definition.json");
6363
createVariable("testAPIDefinition","https://petstore.swagger.io/v2/swagger.json");
64-
createVariable("status", "unpublished");
64+
createVariable("state", "unpublished");
6565
createVariable("expectedReturnCode", "10");
6666
swaggerImport.doExecute(context);
6767

6868
echo("####### Re-Import API from URL without a change #######");
6969
createVariable(ImportTestAction.API_DEFINITION, "http://petstore.swagger.io/v2/swagger.json");
7070
createVariable(ImportTestAction.API_CONFIG, "/com/axway/apim/test/files/basic/minimal-config.json");
71-
createVariable("status", "unpublished");
71+
createVariable("state", "unpublished");
7272
createVariable("expectedReturnCode", "10");
7373
swaggerImport.doExecute(context);
7474
}

modules/api-import/src/test/java/com/axway/apim/test/basic/SwaggerFromURLRefFileInConfigurationTestIT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public void run(@Optional @CitrusResource TestContext context) throws IOExceptio
3737
createVariable(ImportTestAction.API_DEFINITION, "");
3838
createVariable(ImportTestAction.API_CONFIG, "/com/axway/apim/test/files/basic/minimal-config-with-api-definition.json");
3939
createVariable("testAPIDefinition","./src/test/resources/com/axway/apim/test/files/basic/swagger-file-with-username.url");
40-
createVariable("status", "unpublished");
40+
createVariable("state", "unpublished");
4141
createVariable("expectedReturnCode", "0");
4242
swaggerImport.doExecute(context);
4343

@@ -53,7 +53,7 @@ public void run(@Optional @CitrusResource TestContext context) throws IOExceptio
5353
createVariable(ImportTestAction.API_DEFINITION, "");
5454
createVariable(ImportTestAction.API_CONFIG, "/com/axway/apim/test/files/basic/minimal-config-with-api-definition.json");
5555
createVariable("testAPIDefinition","./src/test/resources/com/axway/apim/test/files/basic/swagger-file-with-username.url");
56-
createVariable("status", "unpublished");
56+
createVariable("state", "unpublished");
5757
createVariable("expectedReturnCode", "10");
5858
swaggerImport.doExecute(context);
5959
}

modules/api-import/src/test/java/com/axway/apim/test/basic/SwaggerFromURLRefFileTestIT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public void run(@Optional @CitrusResource TestContext context) throws IOExceptio
3636
echo("####### Importing API: '${apiName}' on path: '${apiPath}' for the first time from URL #######");
3737
createVariable(ImportTestAction.API_DEFINITION, "/com/axway/apim/test/files/basic/swagger-file-with-username.url");
3838
createVariable(ImportTestAction.API_CONFIG, "/com/axway/apim/test/files/basic/minimal-config.json");
39-
createVariable("status", "unpublished");
39+
createVariable("state", "unpublished");
4040
createVariable("expectedReturnCode", "0");
4141
swaggerImport.doExecute(context);
4242

@@ -51,7 +51,7 @@ public void run(@Optional @CitrusResource TestContext context) throws IOExceptio
5151
echo("####### Re-Import API from URL without a change #######");
5252
createVariable(ImportTestAction.API_DEFINITION, "/com/axway/apim/test/files/basic/swagger-file-with-username.url");
5353
createVariable(ImportTestAction.API_CONFIG, "/com/axway/apim/test/files/basic/minimal-config.json");
54-
createVariable("status", "unpublished");
54+
createVariable("state", "unpublished");
5555
createVariable("expectedReturnCode", "10");
5656
swaggerImport.doExecute(context);
5757
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
package com.axway.apim.test.basic;
2+
3+
import java.io.IOException;
4+
5+
import org.springframework.http.HttpStatus;
6+
import org.testng.annotations.Optional;
7+
import org.testng.annotations.Parameters;
8+
import org.testng.annotations.Test;
9+
10+
import com.axway.apim.adapter.APIManagerAdapter;
11+
import com.axway.apim.lib.errorHandling.AppException;
12+
import com.axway.apim.test.ImportTestAction;
13+
import com.consol.citrus.annotations.CitrusResource;
14+
import com.consol.citrus.annotations.CitrusTest;
15+
import com.consol.citrus.context.TestContext;
16+
import com.consol.citrus.dsl.testng.TestNGCitrusTestRunner;
17+
import com.consol.citrus.functions.core.RandomNumberFunction;
18+
import com.consol.citrus.message.MessageType;
19+
20+
@Test
21+
public class YamlAPITestIT extends TestNGCitrusTestRunner {
22+
23+
private ImportTestAction swaggerImport;
24+
25+
@CitrusTest
26+
@Test @Parameters("context")
27+
public void run(@Optional @CitrusResource TestContext context) throws IOException, AppException {
28+
swaggerImport = new ImportTestAction();
29+
description("Import a YAML API and re-import it without any change. It must be detected, that no change happened.");
30+
31+
variable("apiNumber", RandomNumberFunction.getRandomNumber(3, true));
32+
variable("apiPath", "/yaml-my-no-change-${apiNumber}");
33+
variable("apiName", "YAML No-Change-${apiNumber}");
34+
35+
if(APIManagerAdapter.hasAPIManagerVersion("7.7")) {
36+
37+
echo("####### Importing YAML API: '${apiName}' on path: '${apiPath}' for the first time #######");
38+
createVariable(ImportTestAction.API_DEFINITION, "/com/axway/apim/test/files/basic/yaml-petstore.yaml");
39+
createVariable(ImportTestAction.API_CONFIG, "/com/axway/apim/test/files/basic/minimal-config.json");
40+
createVariable("state", "unpublished");
41+
createVariable("expectedReturnCode", "0");
42+
swaggerImport.doExecute(context);
43+
44+
echo("####### Validate API: '${apiName}' on path: '${apiPath}' has been imported #######");
45+
http(builder -> builder.client("apiManager").send().get("/proxies").header("Content-Type", "application/json"));
46+
47+
http(builder -> builder.client("apiManager").receive().response(HttpStatus.OK).messageType(MessageType.JSON)
48+
.validate("$.[?(@.path=='${apiPath}')].name", "${apiName}")
49+
.extractFromPayload("$.[?(@.path=='${apiPath}')].id", "apiId"));
50+
51+
echo("####### RE-Importing same API: '${apiName}' on path: '${apiPath}' without changes. Expecting failure with RC 99. #######");
52+
createVariable(ImportTestAction.API_DEFINITION, "/com/axway/apim/test/files/basic/yaml-petstore.yaml");
53+
createVariable(ImportTestAction.API_CONFIG, "/com/axway/apim/test/files/basic/minimal-config.json");
54+
createVariable("state", "unpublished");
55+
createVariable("expectedReturnCode", "10");
56+
swaggerImport.doExecute(context);
57+
58+
echo("####### Make sure, the API-ID hasn't changed #######");
59+
http(builder -> builder.client("apiManager").send().get("/proxies/${apiId}").header("Content-Type", "application/json"));
60+
61+
// Check the API is still exposed on the same path
62+
http(builder -> builder.client("apiManager").receive().response(HttpStatus.OK).messageType(MessageType.JSON)
63+
.validate("$.[?(@.path=='${apiPath}')].name", "${apiName}")
64+
.validate("$.[?(@.path=='${apiPath}')].id", "${apiId}")); // Must be the same API-ID as before!
65+
66+
echo("####### Adjust the backend base-path of API: '${apiName}' to path: '${apiPath}' #######");
67+
createVariable(ImportTestAction.API_DEFINITION, "/com/axway/apim/test/files/basic/yaml-petstore.yaml");
68+
createVariable(ImportTestAction.API_CONFIG, "/com/axway/apim/test/files/serviceprofile/2_backend_basepath_test.json");
69+
createVariable("backendBasepath", "https://swapi.co");
70+
createVariable("state", "unpublished");
71+
createVariable("expectedReturnCode", "0");
72+
swaggerImport.doExecute(context);
73+
74+
echo("####### Validate API: '${apiName}' on path: '${apiPath}' has the correct backendBasePath configured. #######");
75+
http(builder -> builder.client("apiManager").send().get("/proxies").name("api").header("Content-Type", "application/json"));
76+
77+
http(builder -> builder.client("apiManager").receive().response(HttpStatus.OK).messageType(MessageType.JSON)
78+
.validate("$.[?(@.path=='${apiPath}')].name", "${apiName}")
79+
.validate("$.[?(@.path=='${apiPath}')].state", "${state}")
80+
.validate("$.[?(@.path=='${apiPath}')].serviceProfiles._default.basePath", "${backendBasepath}"));
81+
} else {
82+
echo("####### Importing YAML API: '${apiName}' on path: '${apiPath}' for the first time #######");
83+
createVariable(ImportTestAction.API_DEFINITION, "/com/axway/apim/test/files/basic/yaml-petstore.yaml");
84+
createVariable(ImportTestAction.API_CONFIG, "/com/axway/apim/test/files/basic/minimal-config.json");
85+
createVariable("state", "unpublished");
86+
createVariable("expectedReturnCode", "75"); // Not supported in previous versions
87+
swaggerImport.doExecute(context);
88+
}
89+
}
90+
91+
}

modules/api-import/src/test/java/com/axway/apim/test/envProperties/UsingEnvironmentTestIT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public void run() {
2727
createVariable(ImportTestAction.API_DEFINITION, "");
2828
createVariable(ImportTestAction.API_CONFIG, "/com/axway/apim/test/files/basic/minimal-config-with-api-definition.json");
2929
createVariable("testAPIDefinition", "/com/axway/apim/test/files/basic/petstore.json");
30-
createVariable("status", "unpublished");
30+
createVariable("state", "unpublished");
3131
createVariable("stage", "localhost");
3232
createVariable("useEnvironmentOnly", "true");
3333
createVariable("expectedReturnCode", "0");
@@ -37,7 +37,7 @@ public void run() {
3737
createVariable(ImportTestAction.API_DEFINITION, "");
3838
createVariable(ImportTestAction.API_CONFIG, "/com/axway/apim/test/files/basic/minimal-config-with-api-definition.json");
3939
createVariable("testAPIDefinition", "/com/axway/apim/test/files/basic/petstore2.json");
40-
createVariable("status", "unpublished");
40+
createVariable("state", "unpublished");
4141
createVariable("stage", "localhost");
4242
createVariable("expectedReturnCode", "0");
4343
action(swaggerImport);

modules/api-import/src/test/java/com/axway/apim/test/rollback/RollbackTestIT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public void run(@Optional @CitrusResource TestContext context) throws IOExceptio
5959
echo("####### Create a valid API, which will be updated later, which then fails and must be rolled back #######");
6060
createVariable(ImportTestAction.API_DEFINITION, "/com/axway/apim/test/files/basic/petstore.json");
6161
createVariable(ImportTestAction.API_CONFIG, "/com/axway/apim/test/files/basic/minimal-config.json");
62-
createVariable("status", "published");
62+
createVariable("state", "published");
6363
createVariable("expectedReturnCode", "0"); // Must fail!
6464
swaggerImport.doExecute(context);
6565

@@ -68,7 +68,7 @@ public void run(@Optional @CitrusResource TestContext context) throws IOExceptio
6868

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

7474
// In Version 7.6.2 SP2 (only this version) the API-Manager is able to create a FE-API based on host: https://unknown.host.com:443 for any reason

0 commit comments

Comments
 (0)