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

Implement patch API for datasources #2273

Merged
merged 22 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fix test and jacoco passing
Signed-off-by: Derek Ho <[email protected]>
  • Loading branch information
derek-ho committed Oct 13, 2023
commit 721c64fc0958c064f85dfb870318de963bf43aad
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.when;
import static org.opensearch.sql.analysis.DataSourceSchemaIdentifierNameResolver.DEFAULT_DATASOURCE_NAME;
import static org.opensearch.sql.datasources.utils.XContentParserUtils.DESCRIPTION_FIELD;
import static org.opensearch.sql.datasources.utils.XContentParserUtils.NAME_FIELD;
import static org.opensearch.sql.datasources.utils.XContentParserUtils.*;

import com.google.common.collect.ImmutableMap;
import java.util.ArrayList;
Expand Down Expand Up @@ -307,7 +306,20 @@ void testPatchDefaultDataSource() {
void testPatchDataSourceSuccessCase() {
// Tests that patch underlying implementation is to call update
Map<String, Object> dataSourceData =
new HashMap<>(Map.of(NAME_FIELD, "testDS", DESCRIPTION_FIELD, "test"));
new HashMap<>(
Map.of(
NAME_FIELD,
"testDS",
DESCRIPTION_FIELD,
"test",
CONNECTOR_FIELD,
"PROMETHEUS",
ALLOWED_ROLES_FIELD,
new ArrayList<>(),
PROPERTIES_FIELD,
Map.of(),
RESULT_INDEX_FIELD,
""));
DataSourceMetadata getData =
metadata("testDS", DataSourceType.OPENSEARCH, Collections.emptyList(), ImmutableMap.of());
when(dataSourceMetadataStorage.getDataSourceMetadata("testDS"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,26 +58,39 @@ public void testToDataSourceMetadataFromJson() {
@Test
public void testToMapFromJson() {
Map<String, Object> dataSourceData =
new HashMap<>(
Map.of(
NAME_FIELD,
"test_DS",
DESCRIPTION_FIELD,
"test",
ALLOWED_ROLES_FIELD,
new ArrayList<>(),
PROPERTIES_FIELD,
Map.of(),
CONNECTOR_FIELD,
"PROMETHEUS",
RESULT_INDEX_FIELD,
""));
Map.of(
NAME_FIELD,
"test_DS",
DESCRIPTION_FIELD,
"test",
ALLOWED_ROLES_FIELD,
new ArrayList<>(),
PROPERTIES_FIELD,
Map.of(),
CONNECTOR_FIELD,
"PROMETHEUS",
RESULT_INDEX_FIELD,
"");

Map<String, Object> dataSourceDataConnectorRemoved =
Map.of(
NAME_FIELD,
"test_DS",
DESCRIPTION_FIELD,
"test",
ALLOWED_ROLES_FIELD,
new ArrayList<>(),
PROPERTIES_FIELD,
Map.of(),
RESULT_INDEX_FIELD,
"");

Gson gson = new Gson();
String json = gson.toJson(dataSourceData);

Map<String, Object> parsedData = XContentParserUtils.toMap(json);

Assertions.assertEquals(parsedData, dataSourceData);
Assertions.assertEquals(parsedData, dataSourceDataConnectorRemoved);
Assertions.assertEquals("test", parsedData.get(DESCRIPTION_FIELD));
}

Expand Down Expand Up @@ -151,4 +164,21 @@ public void testToDataSourceMetadataFromJsonUsingUnknownObject() {
});
Assertions.assertEquals("Unknown field: test", exception.getMessage());
}

@SneakyThrows
@Test
public void testToMapFromJsonUsingUnknownObject() {
HashMap<String, String> hashMap = new HashMap<>();
hashMap.put("test", "test");
Gson gson = new Gson();
String json = gson.toJson(hashMap);

IllegalArgumentException exception =
assertThrows(
IllegalArgumentException.class,
() -> {
XContentParserUtils.toMap(json);
});
Assertions.assertEquals("Unknown field: test", exception.getMessage());
}
}
Loading