Skip to content

Commit 396f506

Browse files
author
Chris Wiechmann
committed
New unit test based on BerlinGroup API - Fixed implementation
#40
1 parent fad00e8 commit 396f506

5 files changed

Lines changed: 13730 additions & 6 deletions

File tree

modules/api-import/src/test/java/com/axway/apim/api/definition/APISpecificationOpenAPI3xTest.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import org.testng.annotations.BeforeClass;
1010
import org.testng.annotations.Test;
1111

12+
import com.axway.apim.adapter.APIManagerAdapter;
1213
import com.axway.apim.api.definition.APISpecification;
1314
import com.axway.apim.api.definition.APISpecificationFactory;
1415
import com.axway.apim.lib.CommandParameters;
@@ -17,12 +18,14 @@
1718
import com.fasterxml.jackson.databind.JsonNode;
1819
import com.fasterxml.jackson.databind.ObjectMapper;
1920
import com.fasterxml.jackson.databind.node.ArrayNode;
21+
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
2022

2123
public class APISpecificationOpenAPI3xTest {
2224

2325
private static final String testPackage = "/com/axway/apim/api/definition";
2426

2527
ObjectMapper mapper = new ObjectMapper();
28+
ObjectMapper ymlMapper = new ObjectMapper(new YAMLFactory());
2629

2730
@BeforeClass
2831
private void initTestIndicator() {
@@ -35,7 +38,7 @@ private void initTestIndicator() {
3538
public void backendHostAndBasePath() throws AppException, IOException {
3639

3740
byte[] content = getSwaggerContent(testPackage + "/openapi30.json");
38-
APISpecification apiDefinition = APISpecificationFactory.getAPISpecification(content, "teststore.json", "https://myhost.customer.com:8767/api/v1/myAPI", "TesAPI");
41+
APISpecification apiDefinition = APISpecificationFactory.getAPISpecification(content, "teststore.json", "https://myhost.customer.com:8767/api/v1/myAPI", "TestAPI");
3942

4043
// Check if the Swagger-File has been changed
4144
Assert.assertTrue(apiDefinition instanceof OAS3xSpecification);
@@ -44,6 +47,19 @@ public void backendHostAndBasePath() throws AppException, IOException {
4447
Assert.assertEquals( ((ArrayNode) swagger.get("servers")).get(0).get("url").asText(), "https://myhost.customer.com:8767/api/v1/myAPI");
4548
}
4649

50+
@Test
51+
public void testBerlinGroupYAM_API() throws AppException, IOException {
52+
APIManagerAdapter.apiManagerVersion="7.7.0";
53+
byte[] content = getSwaggerContent(testPackage + "/psd2-api_1.3.6_errata20200327.yaml");
54+
APISpecification apiDefinition = APISpecificationFactory.getAPISpecification(content, "teststore.json", "https://myhost.customer.com:8767/api/v1/myAPI", "TestAPI");
55+
56+
// Check if the Swagger-File has been changed
57+
Assert.assertTrue(apiDefinition instanceof OAS3xSpecification);
58+
JsonNode swagger = ymlMapper.readTree(apiDefinition.getApiSpecificationContent());
59+
Assert.assertEquals( ((ArrayNode) swagger.get("servers")).size(), 1, "Expected to get only one server url");
60+
Assert.assertEquals( ((ArrayNode) swagger.get("servers")).get(0).get("url").asText(), "https://myhost.customer.com:8767/api/v1/myAPI");
61+
}
62+
4763

4864
private byte[] getSwaggerContent(String swaggerFile) throws AppException {
4965
try {

0 commit comments

Comments
 (0)