Skip to content

Commit 6275b50

Browse files
author
Chris Wiechmann
committed
#112 Now using jsonNode.get instead of jsonNode.findPath to select returned
fields. By wrongly using findPath a different createdOn field was taken from the response.
1 parent dc62e0c commit 6275b50

4 files changed

Lines changed: 231 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/)
55
and this project adheres to [Semantic Versioning](http://semver.org/).
66

7+
## [Unreleased]
8+
### Fixed
9+
- 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))
10+
711
## [1.3.0] 2020-11-10
812
### Added
913
- Search for APIs based on configured Inbound- and Outbound-Security (See issue [#86](https://github.com/Axway-API-Management-Plus/apim-cli/issues/86))

modules/apim-adapter/src/main/java/com/axway/apim/adapter/apis/APIManagerAPIAdapter.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -718,9 +718,9 @@ public API importBackendAPI(API api) throws AppException {
718718
jsonNode = importFromSwagger(api);
719719
}
720720
API createdAPI = new APIBaseDefinition();
721-
createdAPI.setApiId(jsonNode.findPath("id").asText());
722-
createdAPI.setName(jsonNode.findPath("name").asText());
723-
createdAPI.setCreatedOn(Long.parseLong(jsonNode.findPath("createdOn").asText()));
721+
createdAPI.setApiId(jsonNode.get("id").asText());
722+
createdAPI.setName(jsonNode.get("name").asText());
723+
createdAPI.setCreatedOn(Long.parseLong(jsonNode.get("createdOn").asText()));
724724
return createdAPI;
725725
} catch (Exception e) {
726726
throw new AppException("Can't import definition / Create BE-API.", ErrorCode.CANT_CREATE_BE_API, e);
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.axway.apim.model;
2+
3+
import java.io.IOException;
4+
5+
import org.testng.Assert;
6+
import org.testng.annotations.Test;
7+
8+
import com.axway.apim.api.API;
9+
import com.axway.apim.api.APIBaseDefinition;
10+
import com.fasterxml.jackson.core.JsonParseException;
11+
import com.fasterxml.jackson.databind.JsonMappingException;
12+
import com.fasterxml.jackson.databind.JsonNode;
13+
import com.fasterxml.jackson.databind.ObjectMapper;
14+
15+
public class BEAPICreatedResponseTest {
16+
17+
private static final String testPackage = "com/axway/apim/model/";
18+
19+
ObjectMapper mapper = new ObjectMapper();
20+
21+
@Test
22+
public void parseResponseHavingCreatedOn() throws JsonParseException, JsonMappingException, IOException {
23+
JsonNode jsonNode = mapper.readTree(this.getClass().getClassLoader().getResourceAsStream(testPackage + "BEAPICreatedWithCreatedOn.json"));
24+
API createdAPI = new APIBaseDefinition();
25+
createdAPI.setApiId(jsonNode.get("id").asText());
26+
createdAPI.setName(jsonNode.get("name").asText());
27+
createdAPI.setName(jsonNode.get("description").asText());
28+
29+
createdAPI.setCreatedOn(Long.parseLong(jsonNode.get("createdOn").asText()));
30+
31+
Assert.assertEquals(new Long("1605099396581"), createdAPI.getCreatedOn());
32+
// Tests if the Unicode-Description is parsed without giving a encoding
33+
Assert.assertEquals("提供銀行身份認證整合 Axway APIM OAuth Authorization Code Grant Flow\n", jsonNode.get("description").asText());
34+
}
35+
}

0 commit comments

Comments
 (0)