Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 89 additions & 1 deletion sdm/src/test/java/integration/com/sap/cds/sdm/Api.java
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public String deleteEntityDraft(String appUrl, String entityName, String entityI
System.out.println("Delete entity failed. Error : " + response.body().string());
throw new IOException("Could not delete entity");
}
return "Entity Deleted";
return "Entity Draft Deleted";
} catch (IOException e) {
System.out.println("Could not delete entity : " + e);
}
Expand Down Expand Up @@ -676,6 +676,94 @@ public String copyAttachment(
}
}

public String createLink(
String appUrl,
String entityName,
String facetName,
String entityID,
String linkName,
String linkUrl)
throws IOException {
String url =
"https://"
+ appUrl
+ "/odata/v4/"
+ serviceName
+ "/"
+ entityName
+ "(ID="
+ entityID
+ ",IsActiveEntity=false)/"
+ facetName
+ "/"
+ serviceName
+ ".createLink";

MediaType mediaType = MediaType.parse("application/json");

String jsonPayload =
"{" + "\"name\": \"" + linkName + "\"," + "\"url\": \"" + linkUrl + "\"" + "}";

RequestBody body = RequestBody.create(mediaType, jsonPayload);

Request request =
new Request.Builder().url(url).post(body).addHeader("Authorization", token).build();

try (Response response = httpClient.newCall(request).execute()) {
if (!response.isSuccessful()) {
throw new IOException(
"Could not create link: " + response.code() + " - " + response.body().string());
}
return "Link created successfully";
} catch (IOException e) {
System.out.println("Error while creating link: " + e.getMessage());
throw new IOException(e);
}
}

public String openAttachment(
String appUrl, String entityName, String facetName, String entityID, String ID)
throws IOException {
String url =
"https://"
+ appUrl
+ "/odata/v4/"
+ serviceName
+ "/Books(ID="
+ entityID
+ ",IsActiveEntity=true)"
+ "/"
+ facetName
+ "(up__ID="
+ entityID
+ ",ID="
+ ID
+ ",IsActiveEntity=true)"
+ "/"
+ serviceName
+ ".openAttachment";

MediaType mediaType = MediaType.parse("application/json");

String jsonPayload = "{}";

RequestBody body = RequestBody.create(mediaType, jsonPayload);

Request request =
new Request.Builder().url(url).post(body).addHeader("Authorization", token).build();

try (Response response = httpClient.newCall(request).execute()) {
if (!response.isSuccessful()) {
throw new IOException(
"Could not open attachment: " + response.code() + " - " + response.body().string());
}
return "Attachment opened successfully";
} catch (IOException e) {
System.out.println("Error while opening attachment: " + e.getMessage());
throw new IOException(e);
}
}

public Map<String, Object> fetchMetadata(
String appUrl, String entityName, String facetName, String entityID, String ID)
throws IOException {
Expand Down
13 changes: 13 additions & 0 deletions sdm/src/test/java/integration/com/sap/cds/sdm/ApiInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,18 @@ public Map<String, Object> fetchMetadata(
public List<Map<String, Object>> fetchEntityMetadata(
String appUrl, String entityName, String facetName, String entityID) throws IOException;

public String createLink(
String appUrl,
String entityName,
String facetName,
String entityID,
String linkName,
String linkUrl)
throws IOException;

public String openAttachment(
String appUrl, String entityName, String facetName, String entityID, String ID)
throws IOException;

String deleteEntityDraft(String appUrl, String entityName, String entityID);
}
87 changes: 81 additions & 6 deletions sdm/src/test/java/integration/com/sap/cds/sdm/ApiMT.java
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public String deleteEntityDraft(String appUrl, String entityName, String entityI
System.out.println("Delete entity failed. Error : " + response.body().string());
throw new IOException("Could not delete entity");
}
return "Entity Deleted";
return "Entity Draft Deleted";
} catch (IOException e) {
System.out.println("Could not delete entity : " + e);
}
Expand Down Expand Up @@ -505,11 +505,6 @@ public String renameAttachment(

try (Response renameResponse = httpClient.newCall(request).execute()) {
if (renameResponse.code() != 200) {
System.out.println(
"Rename Attachment failed in the "
+ facetName
+ " section. Error : "
+ renameResponse.body().string());
throw new IOException("Attachment was not renamed in section: " + facetName);
}
return "Renamed";
Expand Down Expand Up @@ -640,6 +635,86 @@ public String copyAttachment(
}
}

public String createLink(
String appUrl,
String entityName,
String facetName,
String entityID,
String linkName,
String linkUrl)
throws IOException {
String url =
"https://"
+ appUrl
+ "/api/admin/"
+ entityName
+ "(ID="
+ entityID
+ ",IsActiveEntity=false)/"
+ facetName
+ "/"
+ "AdminService.createLink";

MediaType mediaType = MediaType.parse("application/json");

String jsonPayload =
"{" + "\"name\": \"" + linkName + "\"," + "\"url\": \"" + linkUrl + "\"" + "}";

RequestBody body = RequestBody.create(mediaType, jsonPayload);

Request request =
new Request.Builder().url(url).post(body).addHeader("Authorization", token).build();

try (Response response = httpClient.newCall(request).execute()) {
if (!response.isSuccessful()) {
throw new IOException(
"Could not create link: " + response.code() + " - " + response.body().string());
}
return "Link created successfully";
}
}

public String openAttachment(
String appUrl, String entityName, String facetName, String entityID, String ID)
throws IOException {
String url =
"https://"
+ appUrl
+ "/api/admin/"
+ entityName
+ "(ID="
+ entityID
+ ",IsActiveEntity=true)/"
+ facetName
+ "(up__ID="
+ entityID
+ ",ID="
+ ID
+ ",IsActiveEntity=true)"
+ "/"
+ "AdminService.openAttachment";

MediaType mediaType = MediaType.parse("application/json");

String jsonPayload = "{}";

RequestBody body = RequestBody.create(mediaType, jsonPayload);

Request request =
new Request.Builder().url(url).post(body).addHeader("Authorization", token).build();

try (Response response = httpClient.newCall(request).execute()) {
if (!response.isSuccessful()) {
throw new IOException(
"Could not open attachment: " + response.code() + " - " + response.body().string());
}
return "Attachment opened successfully";
} catch (IOException e) {
System.out.println("Error while opening attachment: " + e.getMessage());
throw new IOException(e);
}
}

public Map<String, Object> fetchMetadata(
String appUrl, String entityName, String facetName, String entityID, String ID)
throws IOException {
Expand Down
Loading
Loading