Skip to content

Commit b2edf0c

Browse files
Merge pull request #318 from cap-java/editLinkTests
Edit and copy link tests
2 parents d204513 + ef158dd commit b2edf0c

File tree

5 files changed

+1646
-0
lines changed

5 files changed

+1646
-0
lines changed

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

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,55 @@ public String openAttachment(
764764
}
765765
}
766766

767+
public String editLink(
768+
String appUrl,
769+
String entityName,
770+
String facetName,
771+
String entityID,
772+
String ID,
773+
String linkUrl)
774+
throws IOException {
775+
776+
String url =
777+
"https://"
778+
+ appUrl
779+
+ "/odata/v4/"
780+
+ serviceName
781+
+ "/"
782+
+ entityName
783+
+ "(ID="
784+
+ entityID
785+
+ ",IsActiveEntity=false)/"
786+
+ facetName
787+
+ "(up__ID="
788+
+ entityID
789+
+ ",ID="
790+
+ ID
791+
+ ",IsActiveEntity=false)/"
792+
+ serviceName
793+
+ ".editLink";
794+
795+
MediaType mediaType = MediaType.parse("application/json");
796+
797+
String jsonPayload = "{" + "\"url\": \"" + linkUrl + "\"" + "}";
798+
799+
RequestBody body = RequestBody.create(mediaType, jsonPayload);
800+
801+
Request request =
802+
new Request.Builder().url(url).post(body).addHeader("Authorization", token).build();
803+
804+
try (Response response = httpClient.newCall(request).execute()) {
805+
if (!response.isSuccessful()) {
806+
throw new IOException(
807+
"Could not edit link: " + response.code() + " - " + response.body().string());
808+
}
809+
return "Link edited successfully";
810+
} catch (IOException e) {
811+
System.out.println("Error while editing link: " + e.getMessage());
812+
throw new IOException(e);
813+
}
814+
}
815+
767816
public Map<String, Object> fetchMetadata(
768817
String appUrl, String entityName, String facetName, String entityID, String ID)
769818
throws IOException {
@@ -805,6 +854,47 @@ public Map<String, Object> fetchMetadata(
805854
}
806855
}
807856

857+
public Map<String, Object> fetchMetadataDraft(
858+
String appUrl, String entityName, String facetName, String entityID, String ID)
859+
throws IOException {
860+
// Construct the URL for fetching attachment metadata
861+
String url =
862+
"https://"
863+
+ appUrl
864+
+ "/odata/v4/"
865+
+ serviceName
866+
+ "/"
867+
+ entityName
868+
+ "_"
869+
+ facetName
870+
+ "(up__ID="
871+
+ entityID
872+
+ ",ID="
873+
+ ID
874+
+ ",IsActiveEntity=false)";
875+
876+
// Make a GET request to fetch the attachment metadata
877+
Request request =
878+
new Request.Builder().url(url).get().addHeader("Authorization", token).build();
879+
880+
try (Response response = httpClient.newCall(request).execute()) {
881+
if (response.code() != 200) {
882+
System.out.println("Response code: " + response.code());
883+
System.out.println(
884+
"Fetch metadata failed for "
885+
+ facetName
886+
+ " Section. Error: "
887+
+ response.body().string());
888+
throw new IOException("Could not fetch " + facetName + " metadata");
889+
} else {
890+
// Parse the JSON response to extract metadata
891+
return objectMapper.readValue(
892+
response.body().string(),
893+
new com.fasterxml.jackson.core.type.TypeReference<Map<String, Object>>() {});
894+
}
895+
}
896+
}
897+
808898
public List<Map<String, Object>> fetchEntityMetadata(
809899
String appUrl, String entityName, String facetName, String entityID) throws IOException {
810900

@@ -848,4 +938,48 @@ public List<Map<String, Object>> fetchEntityMetadata(
848938
}
849939
}
850940
}
941+
942+
public List<Map<String, Object>> fetchEntityMetadataDraft(
943+
String appUrl, String entityName, String facetName, String entityID) throws IOException {
944+
945+
// Construct the URL for fetching attachment metadata
946+
String url =
947+
"https://"
948+
+ appUrl
949+
+ "/odata/v4/"
950+
+ serviceName
951+
+ "/"
952+
+ entityName
953+
+ "(ID="
954+
+ entityID
955+
+ ",IsActiveEntity=false)/"
956+
+ facetName;
957+
958+
// Make a GET request to fetch the attachment metadata
959+
Request request =
960+
new Request.Builder().url(url).get().addHeader("Authorization", token).build();
961+
962+
try (Response response = httpClient.newCall(request).execute()) {
963+
if (response.code() != 200) {
964+
System.out.println("Response code: " + response.code());
965+
System.out.println(
966+
"Fetch metadata failed for "
967+
+ facetName
968+
+ " Section. Error: "
969+
+ response.body().string());
970+
throw new IOException("Could not fetch " + facetName + " metadata");
971+
} else {
972+
ObjectMapper objectMapper = new ObjectMapper();
973+
Map<String, Object> entityData =
974+
objectMapper.readValue(
975+
response.body().string(), new com.fasterxml.jackson.core.type.TypeReference<>() {});
976+
Object value = entityData.get("value");
977+
List<Map<String, Object>> result =
978+
objectMapper.convertValue(
979+
value,
980+
new com.fasterxml.jackson.core.type.TypeReference<List<Map<String, Object>>>() {});
981+
return result;
982+
}
983+
}
984+
}
851985
}

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,16 @@ public Map<String, Object> fetchMetadata(
7070
String appUrl, String entityName, String facetName, String entityID, String ID)
7171
throws IOException;
7272

73+
public Map<String, Object> fetchMetadataDraft(
74+
String appUrl, String entityName, String facetName, String entityID, String ID)
75+
throws IOException;
76+
7377
public List<Map<String, Object>> fetchEntityMetadata(
7478
String appUrl, String entityName, String facetName, String entityID) throws IOException;
7579

80+
public List<Map<String, Object>> fetchEntityMetadataDraft(
81+
String appUrl, String entityName, String facetName, String entityID) throws IOException;
82+
7683
public String createLink(
7784
String appUrl,
7885
String entityName,
@@ -82,6 +89,15 @@ public String createLink(
8289
String linkUrl)
8390
throws IOException;
8491

92+
public String editLink(
93+
String appUrl,
94+
String entityName,
95+
String facetName,
96+
String entityID,
97+
String ID,
98+
String linkUrl)
99+
throws IOException;
100+
85101
public String openAttachment(
86102
String appUrl, String entityName, String facetName, String entityID, String ID)
87103
throws IOException;

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

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,52 @@ public String createLink(
674674
}
675675
}
676676

677+
public String editLink(
678+
String appUrl,
679+
String entityName,
680+
String facetName,
681+
String entityID,
682+
String ID,
683+
String linkUrl)
684+
throws IOException {
685+
686+
String url =
687+
"https://"
688+
+ appUrl
689+
+ "/api/admin/"
690+
+ entityName
691+
+ "(ID="
692+
+ entityID
693+
+ ",IsActiveEntity=false)/"
694+
+ facetName
695+
+ "(up__ID="
696+
+ entityID
697+
+ ",ID="
698+
+ ID
699+
+ ",IsActiveEntity=false)/"
700+
+ "AdminService.editLink";
701+
702+
MediaType mediaType = MediaType.parse("application/json");
703+
704+
String jsonPayload = "{" + "\"url\": \"" + linkUrl + "\"" + "}";
705+
706+
RequestBody body = RequestBody.create(mediaType, jsonPayload);
707+
708+
Request request =
709+
new Request.Builder().url(url).post(body).addHeader("Authorization", token).build();
710+
711+
try (Response response = httpClient.newCall(request).execute()) {
712+
if (!response.isSuccessful()) {
713+
throw new IOException(
714+
"Could not edit link: " + response.code() + " - " + response.body().string());
715+
}
716+
return "Link edited successfully";
717+
} catch (IOException e) {
718+
System.out.println("Error while editing link: " + e.getMessage());
719+
throw new IOException(e);
720+
}
721+
}
722+
677723
public String openAttachment(
678724
String appUrl, String entityName, String facetName, String entityID, String ID)
679725
throws IOException {
@@ -754,6 +800,45 @@ public Map<String, Object> fetchMetadata(
754800
}
755801
}
756802

803+
public Map<String, Object> fetchMetadataDraft(
804+
String appUrl, String entityName, String facetName, String entityID, String ID)
805+
throws IOException {
806+
// Construct the URL for fetching attachment metadata
807+
String url =
808+
"https://"
809+
+ appUrl
810+
+ "/api/admin/"
811+
+ entityName
812+
+ "_"
813+
+ facetName
814+
+ "(up__ID="
815+
+ entityID
816+
+ ",ID="
817+
+ ID
818+
+ ",IsActiveEntity=false)";
819+
820+
// Make a GET request to fetch the attachment metadata
821+
Request request =
822+
new Request.Builder().url(url).get().addHeader("Authorization", token).build();
823+
824+
try (Response response = httpClient.newCall(request).execute()) {
825+
if (response.code() != 200) {
826+
System.out.println("Response code: " + response.code());
827+
System.out.println(
828+
"Fetch metadata failed for "
829+
+ facetName
830+
+ " Section. Error: "
831+
+ response.body().string());
832+
throw new IOException("Could not fetch " + facetName + " metadata");
833+
} else {
834+
// Parse the JSON response to extract metadata
835+
return objectMapper.readValue(
836+
response.body().string(),
837+
new com.fasterxml.jackson.core.type.TypeReference<Map<String, Object>>() {});
838+
}
839+
}
840+
}
841+
757842
public List<Map<String, Object>> fetchEntityMetadata(
758843
String appUrl, String entityName, String facetName, String entityID) throws IOException {
759844

@@ -795,4 +880,46 @@ public List<Map<String, Object>> fetchEntityMetadata(
795880
}
796881
}
797882
}
883+
884+
public List<Map<String, Object>> fetchEntityMetadataDraft(
885+
String appUrl, String entityName, String facetName, String entityID) throws IOException {
886+
887+
// Construct the URL for fetching attachment metadata
888+
String url =
889+
"https://"
890+
+ appUrl
891+
+ "/api/admin/"
892+
+ entityName
893+
+ "(ID="
894+
+ entityID
895+
+ ",IsActiveEntity=false)/"
896+
+ facetName;
897+
898+
// Make a GET request to fetch the attachment metadata
899+
Request request =
900+
new Request.Builder().url(url).get().addHeader("Authorization", token).build();
901+
902+
try (Response response = httpClient.newCall(request).execute()) {
903+
if (response.code() != 200) {
904+
System.out.println("Response code: " + response.code());
905+
System.out.println(
906+
"Fetch metadata failed for "
907+
+ facetName
908+
+ " Section. Error: "
909+
+ response.body().string());
910+
throw new IOException("Could not fetch " + facetName + " metadata");
911+
} else {
912+
ObjectMapper objectMapper = new ObjectMapper();
913+
Map<String, Object> entityData =
914+
objectMapper.readValue(
915+
response.body().string(), new com.fasterxml.jackson.core.type.TypeReference<>() {});
916+
Object value = entityData.get("value");
917+
List<Map<String, Object>> result =
918+
objectMapper.convertValue(
919+
value,
920+
new com.fasterxml.jackson.core.type.TypeReference<List<Map<String, Object>>>() {});
921+
return result;
922+
}
923+
}
924+
}
798925
}

0 commit comments

Comments
 (0)