Skip to content

Commit

Permalink
Add test for map getter in clients
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Widdis <[email protected]>
  • Loading branch information
dbwiddis committed Jun 14, 2024
1 parent 411550d commit e63e98f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
import org.opensearch.common.settings.Settings;
import org.opensearch.common.unit.TimeValue;
import org.opensearch.common.util.concurrent.OpenSearchExecutors;
import org.opensearch.common.xcontent.XContentHelper;
import org.opensearch.common.xcontent.json.JsonXContent;
import org.opensearch.core.action.ActionListener;
import org.opensearch.core.action.ActionResponse;
import org.opensearch.core.xcontent.NamedXContentRegistry;
Expand Down Expand Up @@ -143,7 +145,9 @@ public void testGetDataObject() throws IOException {
GetResponse getResponse = mock(GetResponse.class);
when(getResponse.isExists()).thenReturn(true);
when(getResponse.getId()).thenReturn(TEST_ID);
when(getResponse.getSourceAsString()).thenReturn(testDataObject.toJson());
String json = testDataObject.toJson();
when(getResponse.getSourceAsString()).thenReturn(json);
when(getResponse.getSource()).thenReturn(XContentHelper.convertToMap(JsonXContent.jsonXContent, json, false));
@SuppressWarnings("unchecked")
ActionFuture<GetResponse> future = mock(ActionFuture.class);
when(mockedClient.get(any(GetRequest.class))).thenReturn(future);
Expand All @@ -158,6 +162,7 @@ public void testGetDataObject() throws IOException {
verify(mockedClient, times(1)).get(requestCaptor.capture());
assertEquals(TEST_INDEX, requestCaptor.getValue().index());
assertEquals(TEST_ID, response.id());
assertEquals("foo", response.source().get("data"));
assertTrue(response.parser().isPresent());
XContentParser parser = response.parser().get();
ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ public void testGetDataObject() throws IOException {

assertEquals(TEST_INDEX, getRequestCaptor.getValue().index());
assertEquals(TEST_ID, response.id());
assertEquals("foo", response.source().get("data"));
assertTrue(response.parser().isPresent());
XContentParser parser = response.parser().get();
ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser);
Expand Down

0 comments on commit e63e98f

Please sign in to comment.