-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
simple restassured tests; they need more edge cases added
- Loading branch information
Javier Ochoa
committed
Dec 5, 2024
1 parent
47aea2c
commit d41a7f5
Showing
5 changed files
with
430 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
155 changes: 155 additions & 0 deletions
155
src/test/java/com/redhat/composer/api/AssistantAdminApiAssistantTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
package com.redhat.composer.api; | ||
|
||
import com.redhat.composer.model.request.AssistantCreationRequest; | ||
import io.quarkus.test.common.http.TestHTTPEndpoint; | ||
import io.quarkus.test.junit.QuarkusTest; | ||
import io.restassured.http.ContentType; | ||
import jakarta.ws.rs.core.Response; | ||
import org.bson.types.ObjectId; | ||
import org.hamcrest.Matchers; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.MethodOrderer; | ||
import org.junit.jupiter.api.Order; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.TestMethodOrder; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static org.hamcrest.Matchers.emptyArray; | ||
import static org.hamcrest.Matchers.hasEntry; | ||
import static org.hamcrest.Matchers.hasItem; | ||
import static org.hamcrest.Matchers.not; | ||
import static org.hamcrest.Matchers.notNullValue; | ||
|
||
@QuarkusTest | ||
@TestHTTPEndpoint(AssistantAdminApi.class) | ||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class) | ||
class AssistantAdminApiAssistantTest { | ||
|
||
private static AssistantCreationRequest assistantCreationRequest; | ||
|
||
@BeforeAll | ||
public static void beforeAll() { | ||
assistantCreationRequest = new AssistantCreationRequest(); | ||
assistantCreationRequest.setName("assistant"); | ||
assistantCreationRequest.setDescription("Assistant X"); | ||
} | ||
|
||
@Test | ||
@Order(10) | ||
public void createAsssitantShouldSucceed() { | ||
|
||
|
||
String llmConnectionId = given() | ||
.contentType(ContentType.JSON) | ||
.and() | ||
.body(""" | ||
{ | ||
"name":"conn1", | ||
"description": "Llm Connection" | ||
} | ||
""") | ||
.when() | ||
.post("/llm") | ||
.then() | ||
.extract() | ||
.path("id"); | ||
|
||
|
||
assistantCreationRequest.setLlmConnectionId(llmConnectionId); | ||
|
||
String assistantHexStringId = given() | ||
.contentType(ContentType.JSON) | ||
.and() | ||
.body(assistantCreationRequest) | ||
.when() | ||
.post() | ||
.then() | ||
.assertThat() | ||
.body("id", notNullValue()) | ||
.statusCode( | ||
Response.Status.OK.getStatusCode()) | ||
.extract() | ||
.path("id"); | ||
|
||
assistantCreationRequest.setId(assistantHexStringId); | ||
} | ||
|
||
|
||
@Test | ||
@Order(20) | ||
public void retrieveAsssitants() { | ||
given() | ||
.contentType(ContentType.JSON) | ||
.and() | ||
.when() | ||
.get() | ||
.then() | ||
.assertThat() | ||
.body("$", Matchers.is(not(emptyArray()))) | ||
.and() | ||
.body("", hasItem(hasEntry("id", assistantCreationRequest.getId()))) | ||
.statusCode( | ||
Response.Status.OK.getStatusCode()); | ||
} | ||
|
||
|
||
@Test | ||
@Order(30) | ||
public void retrieveSpecificAsssitant() { | ||
given() | ||
.contentType(ContentType.JSON) | ||
.and() | ||
.when() | ||
.pathParams("assistantId", assistantCreationRequest.getId()) | ||
.get("/{assistantId}") | ||
.then() | ||
.assertThat() | ||
.body("", hasEntry("id", assistantCreationRequest.getId())) | ||
.statusCode( | ||
Response.Status.OK.getStatusCode()); | ||
} | ||
|
||
|
||
@Test | ||
@Order(35) | ||
public void noyExistingAsssitant() { | ||
given() | ||
.contentType(ContentType.JSON) | ||
.and() | ||
.when() | ||
.pathParams("assistantId", new ObjectId().toHexString()) | ||
.get("/{assistantId}") | ||
.then() | ||
.assertThat() | ||
.statusCode( | ||
Response.Status.NOT_FOUND.getStatusCode()); | ||
} | ||
|
||
@Test | ||
@Order(40) | ||
public void deleteAsssitant() { | ||
given() | ||
.contentType(ContentType.JSON) | ||
.and() | ||
.when() | ||
.pathParams("assistantId", assistantCreationRequest.getId()) | ||
.delete("/{assistantId}") | ||
.then() | ||
.assertThat() | ||
.statusCode( | ||
Response.Status.NO_CONTENT.getStatusCode()); | ||
|
||
given() | ||
.contentType(ContentType.JSON) | ||
.and() | ||
.when() | ||
.pathParams("assistantId", assistantCreationRequest.getId()) | ||
.get("/{assistantId}") | ||
.then() | ||
.assertThat() | ||
.statusCode( | ||
Response.Status.NOT_FOUND.getStatusCode()); | ||
} | ||
|
||
|
||
} |
135 changes: 135 additions & 0 deletions
135
src/test/java/com/redhat/composer/api/AssistantAdminApiLlmConnectionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
package com.redhat.composer.api; | ||
|
||
import com.redhat.composer.model.mongo.LlmConnectionEntity; | ||
import io.quarkus.test.common.http.TestHTTPEndpoint; | ||
import io.quarkus.test.junit.QuarkusTest; | ||
import io.restassured.http.ContentType; | ||
import jakarta.ws.rs.core.Response; | ||
import org.bson.types.ObjectId; | ||
import org.hamcrest.Matchers; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.MethodOrderer; | ||
import org.junit.jupiter.api.Order; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.TestMethodOrder; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static org.hamcrest.Matchers.emptyArray; | ||
import static org.hamcrest.Matchers.hasEntry; | ||
import static org.hamcrest.Matchers.hasItem; | ||
import static org.hamcrest.Matchers.not; | ||
import static org.hamcrest.Matchers.notNullValue; | ||
|
||
@QuarkusTest | ||
@TestHTTPEndpoint(AssistantAdminApi.class) | ||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class) | ||
class AssistantAdminApiLlmConnectionTest { | ||
|
||
private static LlmConnectionEntity llmConnectionEntity; | ||
|
||
@BeforeAll | ||
public static void beforeAll() { | ||
llmConnectionEntity = new LlmConnectionEntity(); | ||
llmConnectionEntity.setName("llm_name"); | ||
llmConnectionEntity.setDescription("LLM Connection X"); | ||
} | ||
|
||
@Test | ||
@Order(10) | ||
public void createLlmConnectionShouldSucceed() { | ||
String hexStringId = given() | ||
.contentType(ContentType.JSON) | ||
.and() | ||
.body(llmConnectionEntity) | ||
.when() | ||
.post("/llm") | ||
.then() | ||
.assertThat() | ||
.body("id", notNullValue()) | ||
.statusCode( | ||
Response.Status.OK.getStatusCode()) | ||
.extract() | ||
.path("id"); | ||
|
||
llmConnectionEntity.id = new ObjectId(hexStringId); | ||
} | ||
|
||
|
||
@Test | ||
@Order(20) | ||
public void retrieveLlmConnections() { | ||
given() | ||
.contentType(ContentType.JSON) | ||
.and() | ||
.when() | ||
.get("/llm") | ||
.then() | ||
.assertThat() | ||
.body("$", Matchers.is(not(emptyArray()))) | ||
.and() | ||
.body("", hasItem(hasEntry("id", llmConnectionEntity.id.toHexString()))) | ||
.statusCode( | ||
Response.Status.OK.getStatusCode()); | ||
} | ||
|
||
|
||
@Test | ||
@Order(30) | ||
public void retrieveSpecificLlmConnection() { | ||
given() | ||
.contentType(ContentType.JSON) | ||
.and() | ||
.when() | ||
.pathParams("llmConnectionId", llmConnectionEntity.id.toHexString()) | ||
.get("/llm/{llmConnectionId}") | ||
.then() | ||
.assertThat() | ||
.body("", hasEntry("id", llmConnectionEntity.id.toHexString())) | ||
.statusCode( | ||
Response.Status.OK.getStatusCode()); | ||
} | ||
|
||
|
||
@Test | ||
@Order(35) | ||
public void noyExistingLlmConnection() { | ||
given() | ||
.contentType(ContentType.JSON) | ||
.and() | ||
.when() | ||
.pathParams("llmConnectionId", new ObjectId().toHexString()) | ||
.get("/llm/{llmConnectionId}") | ||
.then() | ||
.assertThat() | ||
.statusCode( | ||
Response.Status.NOT_FOUND.getStatusCode()); | ||
} | ||
|
||
@Test | ||
@Order(40) | ||
public void deleteLlmConnection() { | ||
given() | ||
.contentType(ContentType.JSON) | ||
.and() | ||
.when() | ||
.pathParams("llmConnectionId", llmConnectionEntity.id.toHexString()) | ||
.delete("/llm/{llmConnectionId}") | ||
.then() | ||
.assertThat() | ||
.statusCode( | ||
Response.Status.NO_CONTENT.getStatusCode()); | ||
|
||
given() | ||
.contentType(ContentType.JSON) | ||
.and() | ||
.when() | ||
.pathParams("llmConnectionId", llmConnectionEntity.id.toHexString()) | ||
.get("/llm/{llmConnectionId}") | ||
.then() | ||
.assertThat() | ||
.statusCode( | ||
Response.Status.NOT_FOUND.getStatusCode()); | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.