Skip to content

Commit

Permalink
Addressing comments
Browse files Browse the repository at this point in the history
Used assertThrows and added promptTemplate with empty string in test_ToXContent to ensure well rounded testing of expected functionality

Signed-off-by: rithin-pullela-aws <[email protected]>
  • Loading branch information
rithin-pullela-aws committed Dec 18, 2024
1 parent 4e91ea6 commit 41325c4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ public void test_ToXContent() throws IOException {
.builder()
.conversationId("conversation id")
.origin("amazon bedrock")
.promptTemplate(" ")
.parentInteractionId("parant id")
.additionalInfo(Collections.singletonMap("suggestion", "new suggestion"))
.response("sample response")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,12 @@ public void testRestRequest_WithUnknownFields_Fails() throws IOException {
)
.build();

try {
CreateConversationRequest request = CreateConversationRequest.fromRestRequest(req);
fail("Expected IllegalArgumentException due to unknown field");
} catch (OpenSearchParseException e) {
assertEquals(e.getMessage(), "Invalid field [unknown_field] found in request body");
} catch (Exception e) {
fail("Expected OpenSearchParseException due to unknown field, got " + e.getClass().getName());
}
OpenSearchParseException exception = assertThrows(
"Expected OpenSearchParseException due to unknown field",
OpenSearchParseException.class,
() -> CreateConversationRequest.fromRestRequest(req)
);

assertEquals(exception.getMessage(), "Invalid field [unknown_field] found in request body");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -177,14 +177,13 @@ public void testRestRequest_WithUnknownFields_Fails() throws IOException {
.withContent(new BytesArray(gson.toJson(params)), MediaTypeRegistry.JSON)
.build();

try {
CreateInteractionRequest request = CreateInteractionRequest.fromRestRequest(rrequest);
fail("Expected IllegalArgumentException due to unknown field");
} catch (IllegalArgumentException e) {
assertEquals(e.getMessage(), "Invalid field [unknown_field] found in request body");
} catch (Exception e) {
fail("Expected IllegalArgumentException due to unknown field, got " + e.getClass().getName());
}
IllegalArgumentException exception = assertThrows(
"Expected IllegalArgumentException due to unknown field",
IllegalArgumentException.class,
() -> CreateInteractionRequest.fromRestRequest(rrequest)
);

assertEquals(exception.getMessage(), "Invalid field [unknown_field] found in request body");
}

public void testFromRestRequest_WithAllFieldsEmpty_Fails() throws IOException {
Expand All @@ -201,16 +200,16 @@ public void testFromRestRequest_WithAllFieldsEmpty_Fails() throws IOException {
.withContent(new BytesArray(gson.toJson(params)), MediaTypeRegistry.JSON)
.build();

try {
CreateInteractionRequest request = CreateInteractionRequest.fromRestRequest(rrequest);
fail("Expected IllegalArgumentException due to all fields empty");
} catch (IllegalArgumentException e) {
assertEquals(
e.getMessage(),
"At least one of the following parameters must be non-empty: input, prompt_template, response, origin, additional_info"
);
} catch (Exception e) {
fail("Expected IllegalArgumentException due to all fields empty, got " + e.getClass().getName());
}
IllegalArgumentException exception = assertThrows(
"Expected IllegalArgumentException due to all fields empty",
IllegalArgumentException.class,
() -> CreateInteractionRequest.fromRestRequest(rrequest)
);

assertEquals(
exception.getMessage(),
"At least one of the following parameters must be non-empty: input, prompt_template, response, origin, additional_info"
);

}
}

0 comments on commit 41325c4

Please sign in to comment.