MINOR - Validate basic suites do have basicEntityRef (#19763)

* MINOR - Validate basic suites do have basicEntityRef

* add test
This commit is contained in:
Pere Miquel Brull 2025-02-12 14:07:16 +01:00 committed by GitHub
parent e873ba0f1b
commit ede8108a5a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 31 additions and 4 deletions

View File

@ -127,7 +127,7 @@ public class TestSuiteRepository extends EntityRepository<TestSuite> {
@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);
@ -156,7 +156,7 @@ public class TestSuiteRepository extends EntityRepository<TestSuite> {
@Override
public EntityInterface getParentEntity(TestSuite entity, String fields) {
if (entity.getBasic()) {
if (entity.getBasic() && entity.getBasicEntityReference() != null) {
return Entity.getEntity(entity.getBasicEntityReference(), fields, ALL);
}
return null;

View File

@ -81,6 +81,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";
@ -566,6 +568,9 @@ public class TestSuiteResource extends EntityResource<TestSuite, TestSuiteReposi
@Valid CreateTestSuite create) {
TestSuite testSuite =
mapper.createToEntity(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
@ -598,6 +603,9 @@ public class TestSuiteResource extends EntityResource<TestSuite, TestSuiteReposi
@Valid CreateTestSuite create) {
TestSuite testSuite =
mapper.createToEntity(create, securityContext.getUserPrincipal().getName());
if (testSuite.getBasicEntityReference() == null) {
throw new IllegalArgumentException(BASIC_TEST_SUITE_WITHOUT_REF_ERROR);
}
testSuite.setBasic(true);
List<AuthRequest> authRequests = getAuthRequestsForPost(testSuite);
return create(uriInfo, securityContext, authRequests, AuthorizationLogic.ANY, testSuite);

View File

@ -70,8 +70,10 @@ public record TestCaseIndex(TestCase testCase) implements SearchIndex {
}
TestSuite testSuite = Entity.getEntityOrNull(testSuiteEntityReference, "", Include.ALL);
EntityReference entityReference = testSuite.getBasicEntityReference();
if (entityReference != null) {
TestSuiteIndex.addTestSuiteParentEntityRelations(entityReference, doc);
}
}
public static Map<String, Float> getFields() {
Map<String, Float> fields = SearchIndex.getDefaultFields();

View File

@ -65,8 +65,10 @@ public record TestCaseResolutionStatusIndex(TestCaseResolutionStatus testCaseRes
TestSuite testSuite = Entity.getEntityOrNull(testCase.getTestSuite(), "", Include.ALL);
if (testSuite == null) return;
doc.put("testSuite", testSuite.getEntityReference());
if (testSuite.getBasicEntityReference() != null) {
TestSuiteIndex.addTestSuiteParentEntityRelations(testSuite.getBasicEntityReference(), doc);
}
}
public static Map<String, Float> getFields() {
Map<String, Float> fields = new HashMap<>();

View File

@ -182,6 +182,15 @@ public class TestSuiteResourceTest extends EntityResourceTest<TestSuite, CreateT
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<>();
@ -834,6 +843,12 @@ public class TestSuiteResourceTest extends EntityResourceTest<TestSuite, CreateT
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");