mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-08-11 02:26:49 +00:00
Fix #789 Make assertResponse shorter in Chart and Dashboard tests
This commit is contained in:
parent
1cf0c54dde
commit
d15ffd8daf
@ -31,11 +31,10 @@ import org.openmetadata.catalog.entity.services.DashboardService;
|
|||||||
import org.openmetadata.catalog.entity.teams.Team;
|
import org.openmetadata.catalog.entity.teams.Team;
|
||||||
import org.openmetadata.catalog.entity.teams.User;
|
import org.openmetadata.catalog.entity.teams.User;
|
||||||
import org.openmetadata.catalog.exception.CatalogExceptionMessage;
|
import org.openmetadata.catalog.exception.CatalogExceptionMessage;
|
||||||
|
import org.openmetadata.catalog.resources.charts.ChartResource.ChartList;
|
||||||
import org.openmetadata.catalog.resources.services.DashboardServiceResourceTest;
|
import org.openmetadata.catalog.resources.services.DashboardServiceResourceTest;
|
||||||
import org.openmetadata.catalog.resources.tags.TagResourceTest;
|
|
||||||
import org.openmetadata.catalog.resources.teams.TeamResourceTest;
|
import org.openmetadata.catalog.resources.teams.TeamResourceTest;
|
||||||
import org.openmetadata.catalog.resources.teams.UserResourceTest;
|
import org.openmetadata.catalog.resources.teams.UserResourceTest;
|
||||||
import org.openmetadata.catalog.resources.charts.ChartResource.ChartList;
|
|
||||||
import org.openmetadata.catalog.type.ChartType;
|
import org.openmetadata.catalog.type.ChartType;
|
||||||
import org.openmetadata.catalog.type.EntityReference;
|
import org.openmetadata.catalog.type.EntityReference;
|
||||||
import org.openmetadata.catalog.type.TagLabel;
|
import org.openmetadata.catalog.type.TagLabel;
|
||||||
@ -51,13 +50,10 @@ import javax.ws.rs.client.WebTarget;
|
|||||||
import javax.ws.rs.core.Response.Status;
|
import javax.ws.rs.core.Response.Status;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import static java.util.Collections.singletonList;
|
|
||||||
import static javax.ws.rs.core.Response.Status.BAD_REQUEST;
|
import static javax.ws.rs.core.Response.Status.BAD_REQUEST;
|
||||||
import static javax.ws.rs.core.Response.Status.CONFLICT;
|
import static javax.ws.rs.core.Response.Status.CONFLICT;
|
||||||
import static javax.ws.rs.core.Response.Status.CREATED;
|
import static javax.ws.rs.core.Response.Status.CREATED;
|
||||||
@ -70,6 +66,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
|
|||||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
import static org.openmetadata.catalog.exception.CatalogExceptionMessage.ENTITY_ALREADY_EXISTS;
|
||||||
import static org.openmetadata.catalog.exception.CatalogExceptionMessage.entityNotFound;
|
import static org.openmetadata.catalog.exception.CatalogExceptionMessage.entityNotFound;
|
||||||
import static org.openmetadata.catalog.exception.CatalogExceptionMessage.readOnlyAttribute;
|
import static org.openmetadata.catalog.exception.CatalogExceptionMessage.readOnlyAttribute;
|
||||||
import static org.openmetadata.catalog.util.TestUtils.LONG_ENTITY_NAME;
|
import static org.openmetadata.catalog.util.TestUtils.LONG_ENTITY_NAME;
|
||||||
@ -116,18 +113,15 @@ public class ChartResourceTest extends CatalogApplicationTest {
|
|||||||
public void post_chartWithLongName_400_badRequest(TestInfo test) {
|
public void post_chartWithLongName_400_badRequest(TestInfo test) {
|
||||||
// Create chart with mandatory name field empty
|
// Create chart with mandatory name field empty
|
||||||
CreateChart create = create(test).withName(LONG_ENTITY_NAME);
|
CreateChart create = create(test).withName(LONG_ENTITY_NAME);
|
||||||
HttpResponseException exception = assertThrows(HttpResponseException.class, () ->
|
assertResponse(() -> createChart(create, adminAuthHeaders()),
|
||||||
createChart(create, adminAuthHeaders()));
|
BAD_REQUEST, "[name size must be between 1 and 64]");
|
||||||
assertResponse(exception, BAD_REQUEST, "[name size must be between 1 and 64]");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void post_chartAlreadyExists_409_conflict(TestInfo test) throws HttpResponseException {
|
public void post_chartAlreadyExists_409_conflict(TestInfo test) throws HttpResponseException {
|
||||||
CreateChart create = create(test);
|
CreateChart create = create(test);
|
||||||
createChart(create, adminAuthHeaders());
|
createChart(create, adminAuthHeaders());
|
||||||
HttpResponseException exception = assertThrows(HttpResponseException.class, () ->
|
assertResponse(() -> createChart(create, adminAuthHeaders()), CONFLICT, ENTITY_ALREADY_EXISTS);
|
||||||
createChart(create, adminAuthHeaders()));
|
|
||||||
assertResponse(exception, CONFLICT, CatalogExceptionMessage.ENTITY_ALREADY_EXISTS);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -153,26 +147,19 @@ public class ChartResourceTest extends CatalogApplicationTest {
|
|||||||
@Test
|
@Test
|
||||||
public void post_chart_as_non_admin_401(TestInfo test) {
|
public void post_chart_as_non_admin_401(TestInfo test) {
|
||||||
CreateChart create = create(test);
|
CreateChart create = create(test);
|
||||||
HttpResponseException exception = assertThrows(HttpResponseException.class, () ->
|
assertResponse(() -> createChart(create, authHeaders("test@open-metadata.org")),
|
||||||
createChart(create, authHeaders("test@open-metadata.org")));
|
FORBIDDEN, "Principal: CatalogPrincipal{name='test'} is not admin");
|
||||||
assertResponse(exception, FORBIDDEN, "Principal: CatalogPrincipal{name='test'} is not admin");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void post_chartWithoutRequiredFields_4xx(TestInfo test) {
|
public void post_chartWithoutRequiredFields_4xx(TestInfo test) {
|
||||||
HttpResponseException exception = assertThrows(HttpResponseException.class, () ->
|
assertResponse(() -> createChart(create(test).withName(null), adminAuthHeaders()), BAD_REQUEST,
|
||||||
createChart(create(test).withName(null), adminAuthHeaders()));
|
"[name must not be null]");
|
||||||
assertResponse(exception, BAD_REQUEST, "[name must not be null]");
|
assertResponse(() -> createChart(create(test).withName(LONG_ENTITY_NAME), adminAuthHeaders()), BAD_REQUEST,
|
||||||
|
"[name size must be between 1 and 64]");
|
||||||
exception = assertThrows(HttpResponseException.class, () ->
|
|
||||||
createChart(create(test).withName(LONG_ENTITY_NAME), adminAuthHeaders()));
|
|
||||||
assertResponse(exception, BAD_REQUEST, "[name size must be between 1 and 64]");
|
|
||||||
|
|
||||||
// Service is required field
|
// Service is required field
|
||||||
exception = assertThrows(HttpResponseException.class, () ->
|
assertResponse(() -> createChart(create(test).withService(null), adminAuthHeaders()), BAD_REQUEST,
|
||||||
createChart(create(test).withService(null), adminAuthHeaders()));
|
"[service must not be null]");
|
||||||
assertResponse(exception, BAD_REQUEST, "[service must not be null]");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -189,9 +176,8 @@ public class ChartResourceTest extends CatalogApplicationTest {
|
|||||||
public void post_chartWithNonExistentOwner_4xx(TestInfo test) {
|
public void post_chartWithNonExistentOwner_4xx(TestInfo test) {
|
||||||
EntityReference owner = new EntityReference().withId(NON_EXISTENT_ENTITY).withType("user");
|
EntityReference owner = new EntityReference().withId(NON_EXISTENT_ENTITY).withType("user");
|
||||||
CreateChart create = create(test).withOwner(owner);
|
CreateChart create = create(test).withOwner(owner);
|
||||||
HttpResponseException exception = assertThrows(HttpResponseException.class, () ->
|
assertResponse(() -> createChart(create, adminAuthHeaders()), NOT_FOUND,
|
||||||
createChart(create, adminAuthHeaders()));
|
entityNotFound("User", NON_EXISTENT_ENTITY));
|
||||||
assertResponse(exception, NOT_FOUND, entityNotFound("User", NON_EXISTENT_ENTITY));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -213,25 +199,21 @@ public class ChartResourceTest extends CatalogApplicationTest {
|
|||||||
@Test
|
@Test
|
||||||
public void get_chartListWithInvalidLimitOffset_4xx() {
|
public void get_chartListWithInvalidLimitOffset_4xx() {
|
||||||
// Limit must be >= 1 and <= 1000,000
|
// Limit must be >= 1 and <= 1000,000
|
||||||
HttpResponseException exception = assertThrows(HttpResponseException.class, ()
|
assertResponse(() -> listCharts(null, null, -1, null, null, adminAuthHeaders()),
|
||||||
-> listCharts(null, null, -1, null, null, adminAuthHeaders()));
|
BAD_REQUEST, "[query param limit must be greater than or equal to 1]");
|
||||||
assertResponse(exception, BAD_REQUEST, "[query param limit must be greater than or equal to 1]");
|
|
||||||
|
|
||||||
exception = assertThrows(HttpResponseException.class, ()
|
assertResponse(() ->listCharts(null, null, 0, null, null, adminAuthHeaders()),
|
||||||
-> listCharts(null, null, 0, null, null, adminAuthHeaders()));
|
BAD_REQUEST, "[query param limit must be greater than or equal to 1]");
|
||||||
assertResponse(exception, BAD_REQUEST, "[query param limit must be greater than or equal to 1]");
|
|
||||||
|
|
||||||
exception = assertThrows(HttpResponseException.class, ()
|
assertResponse(() -> listCharts(null, null, 1000001, null, null, adminAuthHeaders()),
|
||||||
-> listCharts(null, null, 1000001, null, null, adminAuthHeaders()));
|
BAD_REQUEST, "[query param limit must be less than or equal to 1000000]");
|
||||||
assertResponse(exception, BAD_REQUEST, "[query param limit must be less than or equal to 1000000]");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void get_chartListWithInvalidPaginationCursors_4xx() {
|
public void get_chartListWithInvalidPaginationCursors_4xx() {
|
||||||
// Passing both before and after cursors is invalid
|
// Passing both before and after cursors is invalid
|
||||||
HttpResponseException exception = assertThrows(HttpResponseException.class, ()
|
assertResponse(() -> listCharts(null, null, 1, "", "", adminAuthHeaders()),
|
||||||
-> listCharts(null, null, 1, "", "", adminAuthHeaders()));
|
BAD_REQUEST, "Only one of before or after query parameter allowed");
|
||||||
assertResponse(exception, BAD_REQUEST, "Only one of before or after query parameter allowed");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -374,9 +356,7 @@ public class ChartResourceTest extends CatalogApplicationTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void get_nonExistentChart_404_notFound() {
|
public void get_nonExistentChart_404_notFound() {
|
||||||
HttpResponseException exception = assertThrows(HttpResponseException.class, () ->
|
assertResponse(() -> getChart(NON_EXISTENT_ENTITY, adminAuthHeaders()), NOT_FOUND,
|
||||||
getChart(NON_EXISTENT_ENTITY, adminAuthHeaders()));
|
|
||||||
assertResponse(exception, NOT_FOUND,
|
|
||||||
entityNotFound(Entity.CHART, NON_EXISTENT_ENTITY));
|
entityNotFound(Entity.CHART, NON_EXISTENT_ENTITY));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -430,15 +410,13 @@ public class ChartResourceTest extends CatalogApplicationTest {
|
|||||||
UUID chartId = chart.getId();
|
UUID chartId = chart.getId();
|
||||||
String chartJson = JsonUtils.pojoToJson(chart);
|
String chartJson = JsonUtils.pojoToJson(chart);
|
||||||
chart.setId(UUID.randomUUID());
|
chart.setId(UUID.randomUUID());
|
||||||
HttpResponseException exception = assertThrows(HttpResponseException.class, () ->
|
assertResponse(() -> patchChart(chartId, chartJson, chart, adminAuthHeaders()),
|
||||||
patchChart(chartId, chartJson, chart, adminAuthHeaders()));
|
BAD_REQUEST, readOnlyAttribute(Entity.CHART, "id"));
|
||||||
assertResponse(exception, BAD_REQUEST, readOnlyAttribute(Entity.CHART, "id"));
|
|
||||||
|
|
||||||
// ID can't be deleted
|
// ID can't be deleted
|
||||||
chart.setId(null);
|
chart.setId(null);
|
||||||
exception = assertThrows(HttpResponseException.class, () ->
|
assertResponse(() -> patchChart(chartId, chartJson, chart, adminAuthHeaders()), BAD_REQUEST,
|
||||||
patchChart(chartId, chartJson, chart, adminAuthHeaders()));
|
readOnlyAttribute(Entity.CHART, "id"));
|
||||||
assertResponse(exception, BAD_REQUEST, readOnlyAttribute(Entity.CHART, "id"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -447,15 +425,13 @@ public class ChartResourceTest extends CatalogApplicationTest {
|
|||||||
Chart chart = createChart(create(test), adminAuthHeaders());
|
Chart chart = createChart(create(test), adminAuthHeaders());
|
||||||
String chartJson = JsonUtils.pojoToJson(chart);
|
String chartJson = JsonUtils.pojoToJson(chart);
|
||||||
chart.setName("newName");
|
chart.setName("newName");
|
||||||
HttpResponseException exception = assertThrows(HttpResponseException.class, () ->
|
assertResponse(() -> patchChart(chartJson, chart, adminAuthHeaders()), BAD_REQUEST,
|
||||||
patchChart(chartJson, chart, adminAuthHeaders()));
|
readOnlyAttribute(Entity.CHART, "name"));
|
||||||
assertResponse(exception, BAD_REQUEST, readOnlyAttribute(Entity.CHART, "name"));
|
|
||||||
|
|
||||||
// Name can't be removed
|
// Name can't be removed
|
||||||
chart.setName(null);
|
chart.setName(null);
|
||||||
exception = assertThrows(HttpResponseException.class, () ->
|
assertResponse(() -> patchChart(chartJson, chart, adminAuthHeaders()), BAD_REQUEST,
|
||||||
patchChart(chartJson, chart, adminAuthHeaders()));
|
readOnlyAttribute(Entity.CHART, "name"));
|
||||||
assertResponse(exception, BAD_REQUEST, readOnlyAttribute(Entity.CHART, "name"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -466,15 +442,13 @@ public class ChartResourceTest extends CatalogApplicationTest {
|
|||||||
|
|
||||||
String chartJson = JsonUtils.pojoToJson(chart);
|
String chartJson = JsonUtils.pojoToJson(chart);
|
||||||
chart.setService(LOOKER_REFERENCE);
|
chart.setService(LOOKER_REFERENCE);
|
||||||
HttpResponseException exception = assertThrows(HttpResponseException.class, () ->
|
assertResponse(() -> patchChart(chartJson, chart, adminAuthHeaders()), BAD_REQUEST,
|
||||||
patchChart(chartJson, chart, adminAuthHeaders()));
|
readOnlyAttribute(Entity.CHART, "service"));
|
||||||
assertResponse(exception, BAD_REQUEST, readOnlyAttribute(Entity.CHART, "service"));
|
|
||||||
|
|
||||||
// Service relationship can't be removed
|
// Service relationship can't be removed
|
||||||
chart.setService(null);
|
chart.setService(null);
|
||||||
exception = assertThrows(HttpResponseException.class, () ->
|
assertResponse(() -> patchChart(chartJson, chart, adminAuthHeaders()), BAD_REQUEST,
|
||||||
patchChart(chartJson, chart, adminAuthHeaders()));
|
readOnlyAttribute(Entity.CHART, "service"));
|
||||||
assertResponse(exception, BAD_REQUEST, readOnlyAttribute(Entity.CHART, "service"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -513,22 +487,19 @@ public class ChartResourceTest extends CatalogApplicationTest {
|
|||||||
Chart chart = createAndCheckChart(create(test), adminAuthHeaders());
|
Chart chart = createAndCheckChart(create(test), adminAuthHeaders());
|
||||||
|
|
||||||
// Add non existent user as follower to the chart
|
// Add non existent user as follower to the chart
|
||||||
HttpResponseException exception = assertThrows(HttpResponseException.class, () ->
|
assertResponse(() -> addAndCheckFollower(chart, NON_EXISTENT_ENTITY, CREATED, 1, adminAuthHeaders()),
|
||||||
addAndCheckFollower(chart, NON_EXISTENT_ENTITY, CREATED, 1, adminAuthHeaders()));
|
NOT_FOUND, CatalogExceptionMessage.entityNotFound("User", NON_EXISTENT_ENTITY));
|
||||||
assertResponse(exception, NOT_FOUND, CatalogExceptionMessage.entityNotFound("User", NON_EXISTENT_ENTITY));
|
|
||||||
|
|
||||||
// Delete non existent user as follower to the chart
|
// Delete non existent user as follower to the chart
|
||||||
exception = assertThrows(HttpResponseException.class, () ->
|
assertResponse(() -> deleteAndCheckFollower(chart, NON_EXISTENT_ENTITY, 1, adminAuthHeaders()),
|
||||||
deleteAndCheckFollower(chart, NON_EXISTENT_ENTITY, 1, adminAuthHeaders()));
|
NOT_FOUND, CatalogExceptionMessage.entityNotFound("User", NON_EXISTENT_ENTITY));
|
||||||
assertResponse(exception, NOT_FOUND, CatalogExceptionMessage.entityNotFound("User", NON_EXISTENT_ENTITY));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void delete_nonExistentChart_404() {
|
public void delete_nonExistentChart_404() {
|
||||||
HttpResponseException exception = assertThrows(HttpResponseException.class, () ->
|
assertResponse(() -> deleteChart(NON_EXISTENT_ENTITY, adminAuthHeaders()), NOT_FOUND,
|
||||||
deleteChart(NON_EXISTENT_ENTITY, adminAuthHeaders()));
|
entityNotFound(Entity.CHART, NON_EXISTENT_ENTITY));
|
||||||
assertResponse(exception, NOT_FOUND, entityNotFound(Entity.CHART, NON_EXISTENT_ENTITY));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Chart createAndCheckChart(CreateChart create,
|
public static Chart createAndCheckChart(CreateChart create,
|
||||||
@ -709,8 +680,7 @@ public class ChartResourceTest extends CatalogApplicationTest {
|
|||||||
TestUtils.delete(getResource("charts/" + id), authHeaders);
|
TestUtils.delete(getResource("charts/" + id), authHeaders);
|
||||||
|
|
||||||
// Ensure deleted chart does not exist
|
// Ensure deleted chart does not exist
|
||||||
HttpResponseException exception = assertThrows(HttpResponseException.class, () -> getChart(id, authHeaders));
|
assertResponse(() -> getChart(id, authHeaders), NOT_FOUND, entityNotFound(Entity.CHART, id));
|
||||||
assertResponse(exception, NOT_FOUND, entityNotFound(Entity.CHART, id));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getChartName(TestInfo test) {
|
public static String getChartName(TestInfo test) {
|
||||||
|
@ -67,6 +67,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
|
|||||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
import static org.openmetadata.catalog.exception.CatalogExceptionMessage.ENTITY_ALREADY_EXISTS;
|
||||||
import static org.openmetadata.catalog.exception.CatalogExceptionMessage.entityNotFound;
|
import static org.openmetadata.catalog.exception.CatalogExceptionMessage.entityNotFound;
|
||||||
import static org.openmetadata.catalog.exception.CatalogExceptionMessage.readOnlyAttribute;
|
import static org.openmetadata.catalog.exception.CatalogExceptionMessage.readOnlyAttribute;
|
||||||
import static org.openmetadata.catalog.util.TestUtils.adminAuthHeaders;
|
import static org.openmetadata.catalog.util.TestUtils.adminAuthHeaders;
|
||||||
@ -121,27 +122,23 @@ public class DashboardResourceTest extends CatalogApplicationTest {
|
|||||||
public void post_dashboardWithLongName_400_badRequest(TestInfo test) {
|
public void post_dashboardWithLongName_400_badRequest(TestInfo test) {
|
||||||
// Create dashboard with mandatory name field empty
|
// Create dashboard with mandatory name field empty
|
||||||
CreateDashboard create = create(test).withName(TestUtils.LONG_ENTITY_NAME);
|
CreateDashboard create = create(test).withName(TestUtils.LONG_ENTITY_NAME);
|
||||||
HttpResponseException exception = assertThrows(HttpResponseException.class, () ->
|
assertResponse(() -> createDashboard(create, adminAuthHeaders()), BAD_REQUEST,
|
||||||
createDashboard(create, adminAuthHeaders()));
|
"[name size must be between 1 and 64]");
|
||||||
assertResponse(exception, BAD_REQUEST, "[name size must be between 1 and 64]");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void post_DashboardWithoutName_400_badRequest(TestInfo test) {
|
public void post_DashboardWithoutName_400_badRequest(TestInfo test) {
|
||||||
// Create Dashboard with mandatory name field empty
|
// Create Dashboard with mandatory name field empty
|
||||||
CreateDashboard create = create(test).withName("");
|
CreateDashboard create = create(test).withName("");
|
||||||
HttpResponseException exception = assertThrows(HttpResponseException.class, () ->
|
assertResponse(() -> createDashboard(create, adminAuthHeaders()), BAD_REQUEST,
|
||||||
createDashboard(create, adminAuthHeaders()));
|
"[name size must be between 1 and 64]");
|
||||||
assertResponse(exception, BAD_REQUEST, "[name size must be between 1 and 64]");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void post_DashboardAlreadyExists_409_conflict(TestInfo test) throws HttpResponseException {
|
public void post_DashboardAlreadyExists_409_conflict(TestInfo test) throws HttpResponseException {
|
||||||
CreateDashboard create = create(test);
|
CreateDashboard create = create(test);
|
||||||
createDashboard(create, adminAuthHeaders());
|
createDashboard(create, adminAuthHeaders());
|
||||||
HttpResponseException exception = assertThrows(HttpResponseException.class, () ->
|
assertResponse(() -> createDashboard(create, adminAuthHeaders()), CONFLICT, ENTITY_ALREADY_EXISTS);
|
||||||
createDashboard(create, adminAuthHeaders()));
|
|
||||||
assertResponse(exception, CONFLICT, CatalogExceptionMessage.ENTITY_ALREADY_EXISTS);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -172,17 +169,15 @@ public class DashboardResourceTest extends CatalogApplicationTest {
|
|||||||
@Test
|
@Test
|
||||||
public void post_Dashboard_as_non_admin_401(TestInfo test) {
|
public void post_Dashboard_as_non_admin_401(TestInfo test) {
|
||||||
CreateDashboard create = create(test);
|
CreateDashboard create = create(test);
|
||||||
HttpResponseException exception = assertThrows(HttpResponseException.class, () ->
|
assertResponse(() -> createDashboard(create, authHeaders("test@open-metadata.org")), FORBIDDEN,
|
||||||
createDashboard(create, authHeaders("test@open-metadata.org")));
|
"Principal: CatalogPrincipal{name='test'} is not admin");
|
||||||
assertResponse(exception, FORBIDDEN, "Principal: CatalogPrincipal{name='test'} is not admin");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void post_DashboardWithoutRequiredService_4xx(TestInfo test) {
|
public void post_DashboardWithoutRequiredService_4xx(TestInfo test) {
|
||||||
CreateDashboard create = create(test).withService(null);
|
CreateDashboard create = create(test).withService(null);
|
||||||
HttpResponseException exception = assertThrows(HttpResponseException.class, () ->
|
TestUtils.assertResponseContains(() -> createDashboard(create, adminAuthHeaders()), BAD_REQUEST,
|
||||||
createDashboard(create, adminAuthHeaders()));
|
"service must not be null");
|
||||||
TestUtils.assertResponseContains(exception, BAD_REQUEST, "service must not be null");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -209,9 +204,8 @@ public class DashboardResourceTest extends CatalogApplicationTest {
|
|||||||
public void post_DashboardWithNonExistentOwner_4xx(TestInfo test) {
|
public void post_DashboardWithNonExistentOwner_4xx(TestInfo test) {
|
||||||
EntityReference owner = new EntityReference().withId(TestUtils.NON_EXISTENT_ENTITY).withType("user");
|
EntityReference owner = new EntityReference().withId(TestUtils.NON_EXISTENT_ENTITY).withType("user");
|
||||||
CreateDashboard create = create(test).withOwner(owner);
|
CreateDashboard create = create(test).withOwner(owner);
|
||||||
HttpResponseException exception = assertThrows(HttpResponseException.class, () ->
|
assertResponse(() -> createDashboard(create, adminAuthHeaders()), NOT_FOUND,
|
||||||
createDashboard(create, adminAuthHeaders()));
|
entityNotFound("User", TestUtils.NON_EXISTENT_ENTITY));
|
||||||
assertResponse(exception, NOT_FOUND, entityNotFound("User", TestUtils.NON_EXISTENT_ENTITY));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -233,25 +227,21 @@ public class DashboardResourceTest extends CatalogApplicationTest {
|
|||||||
@Test
|
@Test
|
||||||
public void get_DashboardListWithInvalidLimitOffset_4xx() {
|
public void get_DashboardListWithInvalidLimitOffset_4xx() {
|
||||||
// Limit must be >= 1 and <= 1000,000
|
// Limit must be >= 1 and <= 1000,000
|
||||||
HttpResponseException exception = assertThrows(HttpResponseException.class, ()
|
assertResponse(() -> listDashboards(null, null, -1, null, null, adminAuthHeaders()),
|
||||||
-> listDashboards(null, null, -1, null, null, adminAuthHeaders()));
|
BAD_REQUEST, "[query param limit must be greater than or equal to 1]");
|
||||||
assertResponse(exception, BAD_REQUEST, "[query param limit must be greater than or equal to 1]");
|
|
||||||
|
|
||||||
exception = assertThrows(HttpResponseException.class, ()
|
assertResponse(() -> listDashboards(null, null, 0, null, null, adminAuthHeaders()),
|
||||||
-> listDashboards(null, null, 0, null, null, adminAuthHeaders()));
|
BAD_REQUEST, "[query param limit must be greater than or equal to 1]");
|
||||||
assertResponse(exception, BAD_REQUEST, "[query param limit must be greater than or equal to 1]");
|
|
||||||
|
|
||||||
exception = assertThrows(HttpResponseException.class, ()
|
assertResponse(() -> listDashboards(null, null, 1000001, null, null, adminAuthHeaders()),
|
||||||
-> listDashboards(null, null, 1000001, null, null, adminAuthHeaders()));
|
BAD_REQUEST, "[query param limit must be less than or equal to 1000000]");
|
||||||
assertResponse(exception, BAD_REQUEST, "[query param limit must be less than or equal to 1000000]");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void get_DashboardListWithInvalidPaginationCursors_4xx() {
|
public void get_DashboardListWithInvalidPaginationCursors_4xx() {
|
||||||
// Passing both before and after cursors is invalid
|
// Passing both before and after cursors is invalid
|
||||||
HttpResponseException exception = assertThrows(HttpResponseException.class, ()
|
assertResponse(() -> listDashboards(null, null, 1, "", "", adminAuthHeaders()),
|
||||||
-> listDashboards(null, null, 1, "", "", adminAuthHeaders()));
|
BAD_REQUEST, "Only one of before or after query parameter allowed");
|
||||||
assertResponse(exception, BAD_REQUEST, "Only one of before or after query parameter allowed");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -424,9 +414,7 @@ public class DashboardResourceTest extends CatalogApplicationTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void get_nonExistentDashboard_404_notFound() {
|
public void get_nonExistentDashboard_404_notFound() {
|
||||||
HttpResponseException exception = assertThrows(HttpResponseException.class, () ->
|
assertResponse(() -> getDashboard(TestUtils.NON_EXISTENT_ENTITY, adminAuthHeaders()), NOT_FOUND,
|
||||||
getDashboard(TestUtils.NON_EXISTENT_ENTITY, adminAuthHeaders()));
|
|
||||||
assertResponse(exception, NOT_FOUND,
|
|
||||||
entityNotFound(Entity.DASHBOARD, TestUtils.NON_EXISTENT_ENTITY));
|
entityNotFound(Entity.DASHBOARD, TestUtils.NON_EXISTENT_ENTITY));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -481,15 +469,13 @@ public class DashboardResourceTest extends CatalogApplicationTest {
|
|||||||
UUID dashboardId = dashboard.getId();
|
UUID dashboardId = dashboard.getId();
|
||||||
String dashboardJson = JsonUtils.pojoToJson(dashboard);
|
String dashboardJson = JsonUtils.pojoToJson(dashboard);
|
||||||
dashboard.setId(UUID.randomUUID());
|
dashboard.setId(UUID.randomUUID());
|
||||||
HttpResponseException exception = assertThrows(HttpResponseException.class, () ->
|
assertResponse(() -> patchDashboard(dashboardId, dashboardJson, dashboard, adminAuthHeaders()), BAD_REQUEST,
|
||||||
patchDashboard(dashboardId, dashboardJson, dashboard, adminAuthHeaders()));
|
readOnlyAttribute(Entity.DASHBOARD, "id"));
|
||||||
assertResponse(exception, BAD_REQUEST, readOnlyAttribute(Entity.DASHBOARD, "id"));
|
|
||||||
|
|
||||||
// ID can't be deleted
|
// ID can't be deleted
|
||||||
dashboard.setId(null);
|
dashboard.setId(null);
|
||||||
exception = assertThrows(HttpResponseException.class, () ->
|
assertResponse(() -> patchDashboard(dashboardId, dashboardJson, dashboard, adminAuthHeaders()), BAD_REQUEST,
|
||||||
patchDashboard(dashboardId, dashboardJson, dashboard, adminAuthHeaders()));
|
readOnlyAttribute(Entity.DASHBOARD, "id"));
|
||||||
assertResponse(exception, BAD_REQUEST, readOnlyAttribute(Entity.DASHBOARD, "id"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -498,15 +484,13 @@ public class DashboardResourceTest extends CatalogApplicationTest {
|
|||||||
Dashboard dashboard = createDashboard(create(test), adminAuthHeaders());
|
Dashboard dashboard = createDashboard(create(test), adminAuthHeaders());
|
||||||
String dashboardJson = JsonUtils.pojoToJson(dashboard);
|
String dashboardJson = JsonUtils.pojoToJson(dashboard);
|
||||||
dashboard.setName("newName");
|
dashboard.setName("newName");
|
||||||
HttpResponseException exception = assertThrows(HttpResponseException.class, () ->
|
assertResponse(() -> patchDashboard(dashboardJson, dashboard, adminAuthHeaders()), BAD_REQUEST,
|
||||||
patchDashboard(dashboardJson, dashboard, adminAuthHeaders()));
|
readOnlyAttribute(Entity.DASHBOARD, "name"));
|
||||||
assertResponse(exception, BAD_REQUEST, readOnlyAttribute(Entity.DASHBOARD, "name"));
|
|
||||||
|
|
||||||
// Name can't be removed
|
// Name can't be removed
|
||||||
dashboard.setName(null);
|
dashboard.setName(null);
|
||||||
exception = assertThrows(HttpResponseException.class, () ->
|
assertResponse(() -> patchDashboard(dashboardJson, dashboard, adminAuthHeaders()), BAD_REQUEST,
|
||||||
patchDashboard(dashboardJson, dashboard, adminAuthHeaders()));
|
readOnlyAttribute(Entity.DASHBOARD, "name"));
|
||||||
assertResponse(exception, BAD_REQUEST, readOnlyAttribute(Entity.DASHBOARD, "name"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -517,15 +501,13 @@ public class DashboardResourceTest extends CatalogApplicationTest {
|
|||||||
|
|
||||||
String dashboardJson = JsonUtils.pojoToJson(dashboard);
|
String dashboardJson = JsonUtils.pojoToJson(dashboard);
|
||||||
dashboard.setService(LOOKER_REFERENCE);
|
dashboard.setService(LOOKER_REFERENCE);
|
||||||
HttpResponseException exception = assertThrows(HttpResponseException.class, () ->
|
assertResponse(() -> patchDashboard(dashboardJson, dashboard, adminAuthHeaders()), BAD_REQUEST,
|
||||||
patchDashboard(dashboardJson, dashboard, adminAuthHeaders()));
|
readOnlyAttribute(Entity.DASHBOARD, "service"));
|
||||||
assertResponse(exception, BAD_REQUEST, readOnlyAttribute(Entity.DASHBOARD, "service"));
|
|
||||||
|
|
||||||
// Service relationship can't be removed
|
// Service relationship can't be removed
|
||||||
dashboard.setService(null);
|
dashboard.setService(null);
|
||||||
exception = assertThrows(HttpResponseException.class, () ->
|
assertResponse(() -> patchDashboard(dashboardJson, dashboard, adminAuthHeaders()), BAD_REQUEST,
|
||||||
patchDashboard(dashboardJson, dashboard, adminAuthHeaders()));
|
readOnlyAttribute(Entity.DASHBOARD, "service"));
|
||||||
assertResponse(exception, BAD_REQUEST, readOnlyAttribute(Entity.DASHBOARD, "service"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO listing tables test:1
|
// TODO listing tables test:1
|
||||||
@ -544,9 +526,8 @@ public class DashboardResourceTest extends CatalogApplicationTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void delete_nonExistentDashboard_404() {
|
public void delete_nonExistentDashboard_404() {
|
||||||
HttpResponseException exception = assertThrows(HttpResponseException.class, () ->
|
assertResponse(() -> deleteDashboard(TestUtils.NON_EXISTENT_ENTITY, adminAuthHeaders()), NOT_FOUND,
|
||||||
deleteDashboard(TestUtils.NON_EXISTENT_ENTITY, adminAuthHeaders()));
|
entityNotFound(Entity.DASHBOARD, TestUtils.NON_EXISTENT_ENTITY));
|
||||||
assertResponse(exception, NOT_FOUND, entityNotFound(Entity.DASHBOARD, TestUtils.NON_EXISTENT_ENTITY));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Dashboard createAndCheckDashboard(CreateDashboard create,
|
public static Dashboard createAndCheckDashboard(CreateDashboard create,
|
||||||
@ -781,8 +762,7 @@ public class DashboardResourceTest extends CatalogApplicationTest {
|
|||||||
TestUtils.delete(getResource("dashboards/" + id), authHeaders);
|
TestUtils.delete(getResource("dashboards/" + id), authHeaders);
|
||||||
|
|
||||||
// Ensure deleted Dashboard does not exist
|
// Ensure deleted Dashboard does not exist
|
||||||
HttpResponseException exception = assertThrows(HttpResponseException.class, () -> getDashboard(id, authHeaders));
|
assertResponse(() -> getDashboard(id, authHeaders), NOT_FOUND, entityNotFound(Entity.DASHBOARD, id));
|
||||||
assertResponse(exception, NOT_FOUND, entityNotFound(Entity.DASHBOARD, id));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getDashboardName(TestInfo test) {
|
public static String getDashboardName(TestInfo test) {
|
||||||
|
@ -108,9 +108,8 @@ public class DatabaseResourceTest extends CatalogApplicationTest {
|
|||||||
public void post_databaseWithLongName_400_badRequest(TestInfo test) {
|
public void post_databaseWithLongName_400_badRequest(TestInfo test) {
|
||||||
// Create database with mandatory name field empty
|
// Create database with mandatory name field empty
|
||||||
CreateDatabase create = create(test).withName(TestUtils.LONG_ENTITY_NAME);
|
CreateDatabase create = create(test).withName(TestUtils.LONG_ENTITY_NAME);
|
||||||
HttpResponseException exception = assertThrows(HttpResponseException.class, () ->
|
assertResponse(() -> createDatabase(create, adminAuthHeaders()), BAD_REQUEST,
|
||||||
createDatabase(create, adminAuthHeaders()));
|
"[name size must be between 1 and 64]");
|
||||||
assertResponse(exception, BAD_REQUEST, "[name size must be between 1 and 64]");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -16,13 +16,14 @@
|
|||||||
|
|
||||||
package org.openmetadata.catalog.util;
|
package org.openmetadata.catalog.util;
|
||||||
|
|
||||||
|
import org.apache.http.client.HttpResponseException;
|
||||||
|
import org.eclipse.jetty.http.HttpStatus;
|
||||||
|
import org.junit.jupiter.api.function.Executable;
|
||||||
import org.openmetadata.catalog.resources.databases.TableResourceTest.TagLabelComparator;
|
import org.openmetadata.catalog.resources.databases.TableResourceTest.TagLabelComparator;
|
||||||
import org.openmetadata.catalog.resources.tags.TagResourceTest;
|
import org.openmetadata.catalog.resources.tags.TagResourceTest;
|
||||||
import org.openmetadata.catalog.security.CatalogOpenIdAuthorizationRequestFilter;
|
import org.openmetadata.catalog.security.CatalogOpenIdAuthorizationRequestFilter;
|
||||||
import org.openmetadata.catalog.type.EntityReference;
|
import org.openmetadata.catalog.type.EntityReference;
|
||||||
import org.openmetadata.catalog.type.JdbcInfo;
|
import org.openmetadata.catalog.type.JdbcInfo;
|
||||||
import org.apache.http.client.HttpResponseException;
|
|
||||||
import org.eclipse.jetty.http.HttpStatus;
|
|
||||||
import org.openmetadata.catalog.type.TagLabel;
|
import org.openmetadata.catalog.type.TagLabel;
|
||||||
|
|
||||||
import javax.json.JsonObject;
|
import javax.json.JsonObject;
|
||||||
@ -47,6 +48,7 @@ import java.util.stream.Collectors;
|
|||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public final class TestUtils {
|
public final class TestUtils {
|
||||||
@ -111,6 +113,20 @@ public final class TestUtils {
|
|||||||
return response.readEntity(clz);
|
return response.readEntity(clz);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void assertResponse(Executable executable, Response.Status expectedStatus, String expectedReason) {
|
||||||
|
HttpResponseException exception = assertThrows(HttpResponseException.class, executable);
|
||||||
|
assertEquals(expectedStatus.getStatusCode(), exception.getStatusCode());
|
||||||
|
assertEquals(expectedReason, exception.getReasonPhrase());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void assertResponseContains(Executable executable, Response.Status expectedStatus,
|
||||||
|
String expectedReason) {
|
||||||
|
HttpResponseException exception = assertThrows(HttpResponseException.class, executable);
|
||||||
|
assertEquals(expectedStatus.getStatusCode(), exception.getStatusCode());
|
||||||
|
assertTrue(exception.getReasonPhrase().contains(expectedReason),
|
||||||
|
expectedReason + " not in actual " + exception.getReasonPhrase());
|
||||||
|
}
|
||||||
|
|
||||||
public static void assertResponse(HttpResponseException exception, Status expectedCode, String expectedReason) {
|
public static void assertResponse(HttpResponseException exception, Status expectedCode, String expectedReason) {
|
||||||
assertEquals(expectedCode.getStatusCode(), exception.getStatusCode());
|
assertEquals(expectedCode.getStatusCode(), exception.getStatusCode());
|
||||||
assertEquals(expectedReason, exception.getReasonPhrase());
|
assertEquals(expectedReason, exception.getReasonPhrase());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user