Skip to content

Commit bd3487a

Browse files
adding integration tests for changelog
1 parent e9e947e commit bd3487a

5 files changed

Lines changed: 959 additions & 0 deletions

File tree

sdm/src/test/java/integration/com/sap/cds/sdm/Api.java

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,4 +1034,62 @@ public List<Map<String, Object>> fetchEntityMetadataDraft(
10341034
}
10351035
}
10361036
}
1037+
1038+
public Map<String, Object> fetchChangelog(
1039+
String appUrl, String entityName, String facetName, String entityID, String ID)
1040+
throws IOException {
1041+
String url =
1042+
"https://"
1043+
+ appUrl
1044+
+ "/odata/v4/"
1045+
+ serviceName
1046+
+ "/"
1047+
+ entityName
1048+
+ "(ID="
1049+
+ entityID
1050+
+ ",IsActiveEntity=false)/"
1051+
+ facetName
1052+
+ "(up__ID="
1053+
+ entityID
1054+
+ ",ID="
1055+
+ ID
1056+
+ ",IsActiveEntity=false)/"
1057+
+ serviceName
1058+
+ ".changelog";
1059+
1060+
RequestBody body = RequestBody.create("{}", MediaType.parse("application/json"));
1061+
1062+
Request request =
1063+
new Request.Builder().url(url).addHeader("Authorization", token).post(body).build();
1064+
1065+
try (Response response = executeWithRetry(request)) {
1066+
if (response.isSuccessful() && response.body() != null) {
1067+
String responseBody = response.body().string();
1068+
@SuppressWarnings("unchecked")
1069+
Map<String, Object> changelogResponse = objectMapper.readValue(responseBody, Map.class);
1070+
1071+
// Check if response is wrapped in a "value" field containing a JSON string
1072+
if (changelogResponse.containsKey("value")) {
1073+
Object valueObj = changelogResponse.get("value");
1074+
if (valueObj instanceof String) {
1075+
// Parse the JSON string
1076+
@SuppressWarnings("unchecked")
1077+
Map<String, Object> actualResponse =
1078+
objectMapper.readValue((String) valueObj, Map.class);
1079+
return actualResponse;
1080+
}
1081+
}
1082+
1083+
return changelogResponse;
1084+
} else {
1085+
throw new IOException(
1086+
"Failed to fetch changelog: "
1087+
+ response.code()
1088+
+ " - "
1089+
+ (response.body() != null ? response.body().string() : "No response body"));
1090+
}
1091+
} catch (IOException e) {
1092+
throw new IOException("Error fetching changelog: " + e.getMessage(), e);
1093+
}
1094+
}
10371095
}

sdm/src/test/java/integration/com/sap/cds/sdm/ApiInterface.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,8 @@ public String openAttachment(
103103
throws IOException;
104104

105105
String deleteEntityDraft(String appUrl, String entityName, String entityID);
106+
107+
public Map<String, Object> fetchChangelog(
108+
String appUrl, String entityName, String facetName, String entityID, String ID)
109+
throws IOException;
106110
}

sdm/src/test/java/integration/com/sap/cds/sdm/ApiMT.java

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -974,4 +974,58 @@ public List<Map<String, Object>> fetchEntityMetadataDraft(
974974
}
975975
}
976976
}
977+
978+
public Map<String, Object> fetchChangelog(
979+
String appUrl, String entityName, String facetName, String entityID, String ID)
980+
throws IOException {
981+
String url =
982+
"https://"
983+
+ appUrl
984+
+ "/api/admin/"
985+
+ entityName
986+
+ "(ID="
987+
+ entityID
988+
+ ",IsActiveEntity=false)/"
989+
+ facetName
990+
+ "(up__ID="
991+
+ entityID
992+
+ ",ID="
993+
+ ID
994+
+ ",IsActiveEntity=false)/AdminService.changelog";
995+
996+
RequestBody body = RequestBody.create("{}", MediaType.parse("application/json"));
997+
998+
Request request =
999+
new Request.Builder().url(url).addHeader("Authorization", token).post(body).build();
1000+
1001+
try (Response response = executeWithRetry(request)) {
1002+
if (response.isSuccessful() && response.body() != null) {
1003+
String responseBody = response.body().string();
1004+
@SuppressWarnings("unchecked")
1005+
Map<String, Object> changelogResponse = objectMapper.readValue(responseBody, Map.class);
1006+
1007+
// Check if response is wrapped in a "value" field containing a JSON string
1008+
if (changelogResponse.containsKey("value")) {
1009+
Object valueObj = changelogResponse.get("value");
1010+
if (valueObj instanceof String) {
1011+
// Parse the JSON string
1012+
@SuppressWarnings("unchecked")
1013+
Map<String, Object> actualResponse =
1014+
objectMapper.readValue((String) valueObj, Map.class);
1015+
return actualResponse;
1016+
}
1017+
}
1018+
1019+
return changelogResponse;
1020+
} else {
1021+
throw new IOException(
1022+
"Failed to fetch changelog: "
1023+
+ response.code()
1024+
+ " - "
1025+
+ (response.body() != null ? response.body().string() : "No response body"));
1026+
}
1027+
} catch (IOException e) {
1028+
throw new IOException("Error fetching changelog: " + e.getMessage(), e);
1029+
}
1030+
}
9771031
}

0 commit comments

Comments
 (0)