Skip to content

Commit 6b52780

Browse files
Merge pull request #422 from cap-java/neTests
Adding automation tests for nested entities
2 parents 218bf1f + 9581b6f commit 6b52780

4 files changed

Lines changed: 6693 additions & 13 deletions

File tree

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

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,28 @@ private Response executeWithRetry(Request request) throws IOException {
7474

7575
public String createEntityDraft(
7676
String appUrl, String entityName, String entityName2, String srvpath) {
77+
return createEntityDraft(appUrl, entityName, entityName2, srvpath, null);
78+
}
79+
80+
public String createEntityDraft(
81+
String appUrl, String entityName, String entityName2, String srvpath, String bookID) {
7782
MediaType mediaType = MediaType.parse("application/json");
7883

7984
// Creating the Entity (draft)
80-
RequestBody body =
81-
RequestBody.create(
82-
mediaType,
83-
"{\n \"title\": \"IntegrationTestEntity\",\n \""
84-
+ entityName2
85-
+ "\": {\n \"ID\": \"41cf82fb-94bf-4d62-9e45-fa25f959b5b0\",\n \"name\": \"Akshat\"\n }\n}");
85+
String jsonBody;
86+
if (bookID != null && !bookID.isEmpty()) {
87+
// Creating a Chapter within a Book
88+
jsonBody =
89+
"{\n \"title\": \"IntegrationTestEntity\",\n \"book_ID\": \"" + bookID + "\"\n}";
90+
} else {
91+
// Creating a Book or other entity
92+
jsonBody =
93+
"{\n \"title\": \"IntegrationTestEntity\",\n \""
94+
+ entityName2
95+
+ "\": {\n \"ID\": \"41cf82fb-94bf-4d62-9e45-fa25f959b5b0\",\n \"name\": \"Akshat\"\n }\n}";
96+
}
97+
98+
RequestBody body = RequestBody.create(mediaType, jsonBody);
8699

87100
Request request =
88101
new Request.Builder()
@@ -842,7 +855,9 @@ public String openAttachment(
842855
+ appUrl
843856
+ "/odata/v4/"
844857
+ serviceName
845-
+ "/Books(ID="
858+
+ "/"
859+
+ entityName
860+
+ "(ID="
846861
+ entityID
847862
+ ",IsActiveEntity=true)"
848863
+ "/"

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ public interface ApiInterface {
1010
public String createEntityDraft(
1111
String appUrl, String entityName, String entityName2, String srvpath);
1212

13+
public String createEntityDraft(
14+
String appUrl, String entityName, String entityName2, String srvpath, String bookID);
15+
1316
public String editEntityDraft(String appUrl, String entityName, String srvpath, String entityID);
1417

1518
public String saveEntityDraft(String appUrl, String entityName, String srvpath, String entityID);

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

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,28 @@ private Response executeWithRetry(Request request) throws IOException {
7373

7474
public String createEntityDraft(
7575
String appUrl, String entityName, String entityName2, String srvpath) {
76+
return createEntityDraft(appUrl, entityName, entityName2, srvpath, null);
77+
}
78+
79+
public String createEntityDraft(
80+
String appUrl, String entityName, String entityName2, String srvpath, String bookID) {
7681
MediaType mediaType = MediaType.parse("application/json");
7782

7883
// Creating the Entity (draft)
79-
RequestBody body =
80-
RequestBody.create(
81-
mediaType,
82-
"{\n \"title\": \"IntegrationTestEntity\",\n \""
83-
+ entityName2
84-
+ "\": {\n \"ID\": \"41cf82fb-94bf-4d62-9e45-fa25f959b5b0\",\n \"name\": \"Akshat\"\n }\n}");
84+
String jsonBody;
85+
if (bookID != null && !bookID.isEmpty()) {
86+
// Creating a Chapter within a Book
87+
jsonBody =
88+
"{\n \"title\": \"IntegrationTestEntity\",\n \"book_ID\": \"" + bookID + "\"\n}";
89+
} else {
90+
// Creating a Book or other entity
91+
jsonBody =
92+
"{\n \"title\": \"IntegrationTestEntity\",\n \""
93+
+ entityName2
94+
+ "\": {\n \"ID\": \"41cf82fb-94bf-4d62-9e45-fa25f959b5b0\",\n \"name\": \"Akshat\"\n }\n}";
95+
}
96+
97+
RequestBody body = RequestBody.create(mediaType, jsonBody);
8598

8699
Request request =
87100
new Request.Builder()

0 commit comments

Comments
 (0)