Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unit test #42

Merged
merged 19 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/
public class ArtifactUnitTest extends WireMockTestServer {
@Test
void testGetArtifact() {
void getArtifacts() {
wireMockServer.stubFor(
get(urlPathEqualTo("/lm/artifacts"))
.withHeader("AI-Resource-Group", equalTo("default"))
Expand Down Expand Up @@ -50,7 +50,7 @@ void testGetArtifact() {

final AiArtifactList artifactList =
new ArtifactApi(getClient(destination)).artifactQuery("default");
assertThat(artifactList).isNotNull();

assertThat(artifactList.getCount()).isEqualTo(1);
assertThat(artifactList.getResources().size()).isEqualTo(1);
AiArtifact artifact = artifactList.getResources().get(0);
Expand All @@ -65,7 +65,7 @@ void testGetArtifact() {
}

@Test
void testPostArtifact() {
void postArtifact() {
wireMockServer.stubFor(
post(urlPathEqualTo("/lm/artifacts"))
.withHeader("AI-Resource-Group", equalTo("default"))
Expand All @@ -91,9 +91,46 @@ void testPostArtifact() {
.description("dataset for aicore training");
final AiArtifactCreationResponse artifact =
new ArtifactApi(getClient(destination)).artifactCreate("default", artifactPostData);
assertThat(artifact).isNotNull();

assertThat(artifact.getId()).isEqualTo("1a84bb38-4a84-4d12-a5aa-300ae7d33fb4");
assertThat(artifact.getMessage()).isEqualTo("AiArtifact acknowledged");
assertThat(artifact.getUrl()).isEqualTo("ai://default/spam/data");
}

@Test
void getArtifactById() {
wireMockServer.stubFor(
get(urlPathEqualTo("/lm/artifacts/777dea85-e9b1-4a7b-9bea-14769b977633"))
.withHeader("AI-Resource-Group", equalTo("default"))
.willReturn(
aResponse()
.withHeader("content-type", "application/json")
.withBody(
"""
{
"createdAt": "2024-08-23T09:13:21Z",
"description": "",
"id": "777dea85-e9b1-4a7b-9bea-14769b977633",
"kind": "other",
"modifiedAt": "2024-08-23T09:13:21Z",
"name": "test",
"scenarioId": "orchestration",
"url": "https://file-examples.com/wp-content/storage/2017/10/file-sample_150kB.pdf"
}
""")));

AiArtifact artifact =
new ArtifactApi(getClient(destination))
.artifactGet("default", "777dea85-e9b1-4a7b-9bea-14769b977633");

assertThat(artifact.getCreatedAt()).isEqualTo("2024-08-23T09:13:21Z");
assertThat(artifact.getDescription()).isEqualTo("");
assertThat(artifact.getId()).isEqualTo("777dea85-e9b1-4a7b-9bea-14769b977633");
assertThat(artifact.getKind()).isEqualTo(AiArtifact.KindEnum.OTHER);
assertThat(artifact.getModifiedAt()).isEqualTo("2024-08-23T09:13:21Z");
assertThat(artifact.getName()).isEqualTo("test");
assertThat(artifact.getScenarioId()).isEqualTo("orchestration");
assertThat(artifact.getUrl())
.isEqualTo("https://file-examples.com/wp-content/storage/2017/10/file-sample_150kB.pdf");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*/
public class ConfigurationUnitTest extends WireMockTestServer {
@Test
void testGetConfigurations() {
void getConfigurations() {
wireMockServer.stubFor(
get(urlPathEqualTo("/lm/configurations"))
.withHeader("AI-Resource-Group", equalTo("default"))
Expand Down Expand Up @@ -75,7 +75,7 @@ void testGetConfigurations() {
}

@Test
void testPostConfiguration() {
void postConfiguration() {
wireMockServer.stubFor(
post(urlPathEqualTo("/lm/configurations"))
.withHeader("AI-Resource-Group", equalTo("default"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import static com.github.tomakehurst.wiremock.client.WireMock.patch;
import static com.github.tomakehurst.wiremock.client.WireMock.patchRequestedFor;
import static com.github.tomakehurst.wiremock.client.WireMock.post;
import static com.github.tomakehurst.wiremock.client.WireMock.postRequestedFor;
import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
import static com.sap.ai.sdk.core.Core.getClient;
import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -19,6 +20,7 @@
import com.sap.ai.sdk.core.client.model.AiDeploymentList;
import com.sap.ai.sdk.core.client.model.AiDeploymentModificationRequest;
import com.sap.ai.sdk.core.client.model.AiDeploymentModificationResponse;
import com.sap.ai.sdk.core.client.model.AiDeploymentResponseWithDetails;
import com.sap.ai.sdk.core.client.model.AiDeploymentStatus;
import com.sap.ai.sdk.core.client.model.AiDeploymentTargetStatus;
import com.sap.ai.sdk.core.client.model.AiExecutionStatus;
Expand All @@ -31,7 +33,7 @@
*/
public class DeploymentUnitTest extends WireMockTestServer {
@Test
void testGetDeployments() {
void getDeployments() {
CharlesDuboisSAP marked this conversation as resolved.
Show resolved Hide resolved
wireMockServer.stubFor(
get(urlPathEqualTo("/lm/deployments"))
.withHeader("AI-Resource-Group", equalTo("default"))
Expand Down Expand Up @@ -100,7 +102,7 @@ void testGetDeployments() {
}

@Test
void testPostAiDeployment() {
void postAiDeployment() {
wireMockServer.stubFor(
post(urlPathEqualTo("/lm/deployments"))
.withHeader("AI-Resource-Group", equalTo("default"))
Expand Down Expand Up @@ -129,10 +131,21 @@ void testPostAiDeployment() {
assertThat(deployment.getId()).isEqualTo("d5b764fe55b3e87c");
assertThat(deployment.getMessage()).isEqualTo("AiDeployment scheduled.");
assertThat(deployment.getStatus()).isEqualTo(AiExecutionStatus.UNKNOWN);

wireMockServer.verify(
postRequestedFor(urlPathEqualTo("/lm/deployments"))
.withHeader("AI-Resource-Group", equalTo("default"))
.withRequestBody(
equalToJson(
"""
{
"configurationId" : "7652a231-ba9b-4fcc-b473-2c355cb21b61"
}
""")));
}

@Test
void testPatchAiDeployment() {
void patchAiDeployment() {
wireMockServer.stubFor(
patch(urlPathEqualTo("/lm/deployments/d19b998f347341aa"))
.willReturn(
Expand Down Expand Up @@ -170,7 +183,7 @@ void testPatchAiDeployment() {
}

@Test
void testDeleteAiDeployment() {
void deleteAiDeployment() {
wireMockServer.stubFor(
delete(urlPathEqualTo("/lm/deployments/d5b764fe55b3e87c"))
.withHeader("AI-Resource-Group", equalTo("default"))
Expand All @@ -195,4 +208,61 @@ void testDeleteAiDeployment() {
// cloudSdkCustomFields
CharlesDuboisSAP marked this conversation as resolved.
Show resolved Hide resolved
assertThat(deployment.getCustomField("targetStatus")).isEqualTo("DELETED");
}

@Test
void getDeploymentById() {
wireMockServer.stubFor(
get(urlPathEqualTo("/lm/deployments/db1d64d9f06be467"))
.withHeader("AI-Resource-Group", equalTo("default"))
.willReturn(
aResponse()
.withStatus(HttpStatus.SC_OK)
.withHeader("content-type", "application/json")
.withBody(
"""
{
"configurationId": "dd80625e-ad86-426a-b1a7-1494c083428f",
"configurationName": "orchestration",
"createdAt": "2024-08-05T16:17:29Z",
"deploymentUrl": "https://api.ai.intprod-eu12.eu-central-1.aws.ml.hana.ondemand.com/v2/inference/deployments/db1d64d9f06be467",
"details": {
"resources": {
"backend_details": {}
},
"scaling": {
"backend_details": {}
}
},
"id": "db1d64d9f06be467",
"lastOperation": "CREATE",
"latestRunningConfigurationId": "dd80625e-ad86-426a-b1a7-1494c083428f",
"modifiedAt": "2024-08-26T12:43:18Z",
"scenarioId": "orchestration",
"startTime": "2024-08-05T16:18:41Z",
"status": "RUNNING",
"submissionTime": "2024-08-05T16:17:40Z",
"targetStatus": "RUNNING"
}
""")));
final AiDeploymentResponseWithDetails deployment =
new DeploymentApi(getClient(destination)).deploymentGet("default", "db1d64d9f06be467");

assertThat(deployment.getConfigurationId()).isEqualTo("dd80625e-ad86-426a-b1a7-1494c083428f");
assertThat(deployment.getConfigurationName()).isEqualTo("orchestration");
assertThat(deployment.getCreatedAt()).isEqualTo("2024-08-05T16:17:29Z");
assertThat(deployment.getDeploymentUrl())
.isEqualTo(
"https://api.ai.intprod-eu12.eu-central-1.aws.ml.hana.ondemand.com/v2/inference/deployments/db1d64d9f06be467");
assertThat(deployment.getId()).isEqualTo("db1d64d9f06be467");
CharlesDuboisSAP marked this conversation as resolved.
Show resolved Hide resolved
assertThat(deployment.getLastOperation())
.isEqualTo(AiDeploymentResponseWithDetails.LastOperationEnum.CREATE);
assertThat(deployment.getLatestRunningConfigurationId())
.isEqualTo("dd80625e-ad86-426a-b1a7-1494c083428f");
assertThat(deployment.getModifiedAt()).isEqualTo("2024-08-26T12:43:18Z");
assertThat(deployment.getStartTime()).isEqualTo("2024-08-05T16:18:41Z");
assertThat(deployment.getStatus()).isEqualTo(AiDeploymentStatus.RUNNING);
assertThat(deployment.getSubmissionTime()).isEqualTo("2024-08-05T16:17:40Z");
assertThat(deployment.getTargetStatus())
.isEqualTo(AiDeploymentResponseWithDetails.TargetStatusEnum.RUNNING);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*/
public class ExecutionUnitTest extends WireMockTestServer {
@Test
void testGetExecutions() {
void getExecutions() {
wireMockServer.stubFor(
get(urlPathEqualTo("/lm/executions"))
.withHeader("AI-Resource-Group", equalTo("default"))
Expand Down Expand Up @@ -90,7 +90,7 @@ void testGetExecutions() {
}

@Test
void testPostExecution() {
void postExecution() {
wireMockServer.stubFor(
post(urlPathEqualTo("/lm/executions"))
.withHeader("AI-Resource-Group", equalTo("default"))
Expand All @@ -117,4 +117,7 @@ void testPostExecution() {
assertThat(execution.getMessage()).isEqualTo("AiExecution acknowledged");
assertThat(execution.getCustomField("url")).isEqualTo("ai://default/eab289226fe981da");
}

@Test
void getExecutionById() {}
rpanackal marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

import com.sap.ai.sdk.core.client.model.AiScenario;
import com.sap.ai.sdk.core.client.model.AiScenarioList;
import com.sap.ai.sdk.core.client.model.AiVersion;
import com.sap.ai.sdk.core.client.model.AiVersionList;
import org.apache.hc.core5.http.HttpStatus;
import org.junit.jupiter.api.Test;

Expand All @@ -18,7 +20,7 @@
*/
public class ScenarioUnitTest extends WireMockTestServer {
@Test
void testGetScenarios() {
void getScenarios() {
wireMockServer.stubFor(
get(urlPathEqualTo("/lm/scenarios"))
.withHeader("AI-Resource-Group", equalTo("default"))
Expand Down Expand Up @@ -60,4 +62,41 @@ void testGetScenarios() {
assertThat(scenario.getLabels().get(0).getValue()).isEqualTo("true");
assertThat(scenario.getModifiedAt()).isEqualTo("2024-05-08T08:41:23+00:00");
}

@Test
void getScenarioVersions() {
wireMockServer.stubFor(
get(urlPathEqualTo("/lm/scenarios/foundation-models/versions"))
.withHeader("AI-Resource-Group", equalTo("default"))
.willReturn(
aResponse()
.withHeader("content-type", "application/json")
.withStatus(HttpStatus.SC_OK)
.withBody(
"""
{
"count": 1,
"resources": [
{
"createdAt": "2024-05-08T08:41:23+00:00",
"id": "0.0.1",
"modifiedAt": "2024-05-08T08:41:23+00:00",
"scenarioId": "foundation-models"
}
]
}
""")));

AiVersionList versionList =
new ScenarioApi(getClient(destination))
.scenarioQueryVersions("default", "foundation-models");
assertThat(versionList.getCount()).isEqualTo(1);
assertThat(versionList.getResources().size()).isEqualTo(1);

AiVersion version = versionList.getResources().get(0);
assertThat(version.getCreatedAt()).isEqualTo("2024-05-08T08:41:23+00:00");
assertThat(version.getId()).isEqualTo("0.0.1");
assertThat(version.getModifiedAt()).isEqualTo("2024-05-08T08:41:23+00:00");
assertThat(version.getScenarioId()).isEqualTo("foundation-models");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Application {
* @param args Command line arguments.
*/
public static void main(final String[] args) {

CharlesDuboisSAP marked this conversation as resolved.
Show resolved Hide resolved
SpringApplication.run(Application.class, args);
}
}