Fix #329: Add more tests to Dashboard and Topic

This commit is contained in:
Suresh Srinivas 2021-08-27 17:05:49 -07:00
parent 21c87ad46d
commit b2237e54f3
2 changed files with 28 additions and 2 deletions

View File

@ -334,10 +334,19 @@ public abstract class DashboardRepository {
applyTags(dashboard);
}
private void updateChartRelationships(Dashboard dashboard) {
// Add relationship from dashboard to chart
private void updateChartRelationships(Dashboard dashboard) throws IOException {
String dashboardId = dashboard.getId().toString();
// Add relationship from dashboard to chart
if (dashboard.getCharts() != null) {
// Remove any existing charts associated with this dashboard
List<Chart> existingCharts = getCharts(dashboard);
if (existingCharts != null) {
for (Chart chart: existingCharts) {
relationshipDAO().delete(dashboardId, chart.getId().toString(), Relationship.CONTAINS.ordinal());
}
}
for (EntityReference chart : dashboard.getCharts()) {
relationshipDAO().insert(dashboardId, chart.getId().toString(), Entity.DASHBOARD, Entity.CHART,
Relationship.CONTAINS.ordinal());

View File

@ -384,6 +384,23 @@ public class DashboardResourceTest extends CatalogApplicationTest {
assertEquals("newDescription", dashboard.getDescription());
}
@Test
public void put_AddRemoveDashboardChartsUpdate_200(TestInfo test) throws HttpResponseException {
CreateDashboard request = create(test).withService(SUPERSET_REFERENCE).withDescription(null);
createAndCheckDashboard(request, adminAuthHeaders());
Dashboard dashboard = updateAndCheckDashboard(request
.withDescription("newDescription").withCharts(CHART_REFERENCES),
OK, adminAuthHeaders());
validateDashboardCharts(dashboard, CHART_REFERENCES);
// remove a chart
CHART_REFERENCES.remove(0);
dashboard = updateAndCheckDashboard(request
.withDescription("newDescription").withCharts(CHART_REFERENCES),
OK, adminAuthHeaders());
validateDashboardCharts(dashboard, CHART_REFERENCES);
}
@Test
public void get_nonExistentDashboard_404_notFound() {
HttpResponseException exception = assertThrows(HttpResponseException.class, () ->