|
7 | 7 | import static org.junit.jupiter.api.Assertions.assertTrue; |
8 | 8 | import static org.junit.jupiter.api.Assertions.fail; |
9 | 9 |
|
| 10 | +import com.fasterxml.jackson.databind.JsonNode; |
| 11 | +import com.fasterxml.jackson.databind.ObjectMapper; |
10 | 12 | import java.util.HashMap; |
11 | 13 | import java.util.List; |
12 | 14 | import java.util.Map; |
|
35 | 37 | import org.openmetadata.schema.type.Column; |
36 | 38 | import org.openmetadata.schema.type.ColumnDataType; |
37 | 39 | import org.openmetadata.schema.type.EntityHistory; |
| 40 | +import org.openmetadata.schema.type.EntityReference; |
38 | 41 | import org.openmetadata.schema.type.api.BulkOperationResult; |
39 | 42 | import org.openmetadata.schema.type.csv.CsvImportResult; |
40 | 43 | import org.openmetadata.sdk.client.OpenMetadataClient; |
41 | 44 | import org.openmetadata.sdk.exceptions.InvalidRequestException; |
42 | 45 | import org.openmetadata.sdk.fluent.Databases; |
43 | 46 | import org.openmetadata.sdk.models.ListParams; |
44 | 47 | import org.openmetadata.sdk.models.ListResponse; |
| 48 | +import org.openmetadata.sdk.network.HttpMethod; |
45 | 49 | import org.openmetadata.service.util.FullyQualifiedName; |
46 | 50 |
|
47 | 51 | /** |
@@ -1702,4 +1706,47 @@ void testRegexListDatabase_excludeMode(TestNamespace ns) { |
1702 | 1706 | databases.stream().noneMatch(d -> d.getName().startsWith("temp")), |
1703 | 1707 | "Excluded databases should not appear in results"); |
1704 | 1708 | } |
| 1709 | + |
| 1710 | + @Test |
| 1711 | + void test_listEntityHistoryByTimestamp_returnsServiceField(TestNamespace ns) throws Exception { |
| 1712 | + OpenMetadataClient client = SdkClients.adminClient(); |
| 1713 | + long startTs = System.currentTimeMillis(); |
| 1714 | + |
| 1715 | + CreateDatabase createRequest = createRequest(ns.prefix("history_service_field"), ns); |
| 1716 | + Database database = createEntity(createRequest); |
| 1717 | + |
| 1718 | + database.setDescription("Updated for history test - " + System.currentTimeMillis()); |
| 1719 | + patchEntity(database.getId().toString(), database); |
| 1720 | + |
| 1721 | + long endTs = System.currentTimeMillis(); |
| 1722 | + String basePath = getResourcePath() + "history"; |
| 1723 | + |
| 1724 | + String response = |
| 1725 | + client |
| 1726 | + .getHttpClient() |
| 1727 | + .executeForString( |
| 1728 | + HttpMethod.GET, |
| 1729 | + basePath + "?startTs=" + startTs + "&endTs=" + endTs + "&limit=10", |
| 1730 | + null); |
| 1731 | + |
| 1732 | + ObjectMapper mapper = new ObjectMapper(); |
| 1733 | + JsonNode result = mapper.readTree(response); |
| 1734 | + JsonNode data = result.get("data"); |
| 1735 | + |
| 1736 | + assertTrue(data.isArray(), "Data should be an array"); |
| 1737 | + assertTrue(data.size() > 0, "Should have at least one version in the time range"); |
| 1738 | + |
| 1739 | + for (JsonNode entityNode : data) { |
| 1740 | + assertTrue( |
| 1741 | + entityNode.has("service") && !entityNode.get("service").isNull(), |
| 1742 | + "Each database version must include the required 'service' field, but got: " |
| 1743 | + + entityNode); |
| 1744 | + |
| 1745 | + Database deserialized = mapper.treeToValue(entityNode, Database.class); |
| 1746 | + EntityReference service = deserialized.getService(); |
| 1747 | + assertNotNull(service, "Deserialized database must have a non-null service reference"); |
| 1748 | + assertNotNull(service.getId(), "Service reference must have an id"); |
| 1749 | + assertNotNull(service.getType(), "Service reference must have a type"); |
| 1750 | + } |
| 1751 | + } |
1705 | 1752 | } |
0 commit comments