Skip to content

Commit

Permalink
MINOR - Validate basic suites do have basicEntityRef (#19763)
Browse files Browse the repository at this point in the history
* MINOR - Validate basic suites do have basicEntityRef

* add test
  • Loading branch information
pmbrull committed Feb 12, 2025
1 parent 61c8ce1 commit 31f5813
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public void setFields(TestSuite entity, EntityUtil.Fields fields) {

@Override
public void setInheritedFields(TestSuite testSuite, EntityUtil.Fields fields) {
if (Boolean.TRUE.equals(testSuite.getBasic())) {
if (Boolean.TRUE.equals(testSuite.getBasic()) && testSuite.getBasicEntityReference() != null) {
Table table =
Entity.getEntity(
TABLE, testSuite.getBasicEntityReference().getId(), "owners,domain", ALL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ public class TestSuiteResource extends EntityResource<TestSuite, TestSuiteReposi
"Cannot delete logical test suite. To delete logical test suite, use DELETE /v1/dataQuality/testSuites/<...>";
public static final String NON_BASIC_TEST_SUITE_DELETION_ERROR =
"Cannot delete executable test suite. To delete executable test suite, use DELETE /v1/dataQuality/testSuites/basic/<...>";
public static final String BASIC_TEST_SUITE_WITHOUT_REF_ERROR =
"Cannot create a basic test suite without the BasicEntityReference field informed.";

static final String FIELDS = "owners,tests,summary";
static final String SEARCH_FIELDS_EXCLUDE = "table,database,databaseSchema,service";
Expand Down Expand Up @@ -583,6 +585,9 @@ public Response createExecutable(
@Context HttpServletResponse response,
@Valid CreateTestSuite create) {
TestSuite testSuite = getTestSuite(create, securityContext.getUserPrincipal().getName());
if (testSuite.getBasicEntityReference() == null) {
throw new IllegalArgumentException(BASIC_TEST_SUITE_WITHOUT_REF_ERROR);
}
testSuite.setBasic(true);
// Set the deprecation header based on draft specification from IETF
// https://datatracker.ietf.org/doc/html/draft-ietf-httpapi-deprecation-header-02
Expand Down Expand Up @@ -613,6 +618,9 @@ public Response createBasic(
@Context HttpServletResponse response,
@Valid CreateTestSuite create) {
TestSuite testSuite = getTestSuite(create, securityContext.getUserPrincipal().getName());
if (testSuite.getBasicEntityReference() == null) {
throw new IllegalArgumentException(BASIC_TEST_SUITE_WITHOUT_REF_ERROR);
}
testSuite.setBasic(true);
return create(uriInfo, securityContext, testSuite);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ private void setParentRelationships(Map<String, Object> doc, TestCase testCase)
}
TestSuite testSuite = Entity.getEntityOrNull(testSuiteEntityReference, "", Include.ALL);
EntityReference entityReference = testSuite.getBasicEntityReference();
TestSuiteIndex.addTestSuiteParentEntityRelations(entityReference, doc);
if (entityReference != null) {
TestSuiteIndex.addTestSuiteParentEntityRelations(entityReference, doc);
}
}

public static Map<String, Float> getFields() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ private void setParentRelationships(Map<String, Object> doc) {
TestSuite testSuite = Entity.getEntityOrNull(testCase.getTestSuite(), "", Include.ALL);
if (testSuite == null) return;
doc.put("testSuite", testSuite.getEntityReference());
TestSuiteIndex.addTestSuiteParentEntityRelations(testSuite.getBasicEntityReference(), doc);
if (testSuite.getBasicEntityReference() != null) {
TestSuiteIndex.addTestSuiteParentEntityRelations(testSuite.getBasicEntityReference(), doc);
}
}

public static Map<String, Float> getFields() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,15 @@ void put_testCaseResults_200() throws IOException, ParseException {
assertEquals(true, deletedTestSuite.getDeleted());
}

@Test
void create_basicTestSuiteWithoutRef(TestInfo test) {
CreateTestSuite createTestSuite = createRequest(test);
assertResponse(
() -> createBasicEmptySuite(createTestSuite, ADMIN_AUTH_HEADERS),
BAD_REQUEST,
"Cannot create a basic test suite without the BasicEntityReference field informed.");
}

@Test
void list_testSuitesIncludeEmpty_200(TestInfo test) throws IOException {
List<CreateTestSuite> testSuites = new ArrayList<>();
Expand Down Expand Up @@ -834,6 +843,12 @@ public TestSuite createBasicTestSuite(
return TestUtils.post(target, createTestSuite, TestSuite.class, authHeaders);
}

public TestSuite createBasicEmptySuite(
CreateTestSuite createTestSuite, Map<String, String> authHeaders) throws IOException {
WebTarget target = getResource("dataQuality/testSuites/basic");
return TestUtils.post(target, createTestSuite, TestSuite.class, authHeaders);
}

public void addTestCasesToLogicalTestSuite(TestSuite testSuite, List<UUID> testCaseIds)
throws IOException {
WebTarget target = getResource("dataQuality/testCases/logicalTestCases");
Expand Down

0 comments on commit 31f5813

Please sign in to comment.