mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-09-25 17:04:54 +00:00
Fixing test failures due to code merge
This commit is contained in:
parent
589067265f
commit
aa83f7b1ad
@ -68,9 +68,11 @@ import java.io.UnsupportedEncodingException;
|
||||
import java.security.GeneralSecurityException;
|
||||
import java.text.ParseException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
@Path("operations/v1/ingestion")
|
||||
@ -79,18 +81,22 @@ import java.util.UUID;
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@Collection(name = "ingestion")
|
||||
public class IngestionResource {
|
||||
public static final String INGESTION_COLLECTION_PATH = "operations/v1/ingestion/";
|
||||
public static final String COLLECTION_PATH = "operations/v1/ingestion/";
|
||||
private final IngestionRepository dao;
|
||||
private final CatalogAuthorizer authorizer;
|
||||
private AirflowRESTClient airflowRESTClient;
|
||||
private CatalogApplicationConfig config;
|
||||
|
||||
public static void addHref(UriInfo uriInfo, EntityReference ref) {
|
||||
ref.withHref(RestUtil.getHref(uriInfo, INGESTION_COLLECTION_PATH, ref.getId()));
|
||||
ref.withHref(RestUtil.getHref(uriInfo, COLLECTION_PATH, ref.getId()));
|
||||
}
|
||||
|
||||
public static List<Ingestion> addHref(UriInfo uriInfo, List<Ingestion> ingestions) {
|
||||
Optional.ofNullable(ingestions).orElse(Collections.emptyList()).forEach(i -> addHref(uriInfo, i));
|
||||
return ingestions;
|
||||
}
|
||||
|
||||
public static Ingestion addHref(UriInfo uriInfo, Ingestion ingestion) {
|
||||
ingestion.setHref(RestUtil.getHref(uriInfo, INGESTION_COLLECTION_PATH, ingestion.getId()));
|
||||
Entity.withHref(uriInfo, ingestion.getOwner());
|
||||
Entity.withHref(uriInfo, ingestion.getService());
|
||||
return ingestion;
|
||||
@ -162,6 +168,7 @@ public class IngestionResource {
|
||||
} else { // Forward paging or first page
|
||||
ingestions = dao.listAfter(uriInfo, fields, null, limitParam, after);
|
||||
}
|
||||
addHref(uriInfo, ingestions.getData());
|
||||
return ingestions;
|
||||
}
|
||||
|
||||
@ -198,7 +205,7 @@ public class IngestionResource {
|
||||
schema = @Schema(type = "string", example = FIELDS))
|
||||
@QueryParam("fields") String fieldsParam) throws IOException, ParseException {
|
||||
Fields fields = new Fields(FIELD_LIST, fieldsParam);
|
||||
return dao.get(uriInfo, id, fields);
|
||||
return addHref(uriInfo, dao.get(uriInfo, id, fields));
|
||||
}
|
||||
|
||||
@GET
|
||||
@ -238,7 +245,7 @@ public class IngestionResource {
|
||||
schema = @Schema(type = "string", example = FIELDS))
|
||||
@QueryParam("fields") String fieldsParam) throws IOException, ParseException {
|
||||
Fields fields = new Fields(FIELD_LIST, fieldsParam);
|
||||
return dao.getByName(uriInfo, fqn, fields);
|
||||
return addHref(uriInfo, dao.getByName(uriInfo, fqn, fields));
|
||||
}
|
||||
|
||||
|
||||
@ -257,7 +264,7 @@ public class IngestionResource {
|
||||
Ingestion ingestion = getIngestion(securityContext, create);
|
||||
deploy(ingestion);
|
||||
// write to db only when the deployment is successful
|
||||
ingestion = dao.create(uriInfo, ingestion);
|
||||
ingestion = addHref(uriInfo, dao.create(uriInfo, ingestion));
|
||||
return Response.created(ingestion.getHref()).entity(ingestion).build();
|
||||
}
|
||||
|
||||
@ -282,7 +289,8 @@ public class IngestionResource {
|
||||
Ingestion ingestion = dao.get(uriInfo, id, fields);
|
||||
SecurityUtil.checkAdminRoleOrPermissions(authorizer, securityContext,
|
||||
dao.getOwnerReference(ingestion));
|
||||
return dao.patch(uriInfo, UUID.fromString(id), securityContext.getUserPrincipal().getName(), patch);
|
||||
ingestion = dao.patch(uriInfo, UUID.fromString(id), securityContext.getUserPrincipal().getName(), patch);
|
||||
return addHref(uriInfo, ingestion);
|
||||
}
|
||||
|
||||
@PUT
|
||||
@ -301,6 +309,7 @@ public class IngestionResource {
|
||||
deploy(ingestion);
|
||||
// write to db only when the deployment is successful
|
||||
PutResponse<Ingestion> response = dao.createOrUpdate(uriInfo, ingestion);
|
||||
addHref(uriInfo, response.getEntity());
|
||||
return response.toResponse();
|
||||
}
|
||||
|
||||
@ -319,7 +328,7 @@ public class IngestionResource {
|
||||
Fields fields = new Fields(FIELD_LIST, "");
|
||||
Ingestion ingestion = dao.get(uriInfo, id, fields);
|
||||
airflowRESTClient.runPipeline(ingestion.getName());
|
||||
return dao.get(uriInfo, id, fields);
|
||||
return addHref(uriInfo, dao.get(uriInfo, id, fields));
|
||||
}
|
||||
|
||||
|
||||
|
@ -636,7 +636,13 @@ public abstract class EntityResourceTest<T> extends CatalogApplicationTest {
|
||||
T getEntity = getEntity(entityInterface.getId(), authHeaders);
|
||||
validateUpdatedEntity(getEntity, request, authHeaders);
|
||||
validateChangeDescription(getEntity, updateType, changeDescription);
|
||||
validateChangeEvents(entityInterface, updateType, authHeaders);
|
||||
|
||||
// Check if the entity change events are record
|
||||
if (updateType != NO_CHANGE) {
|
||||
EventType expectedEventType = updateType == UpdateType.CREATED ?
|
||||
EventType.ENTITY_CREATED : EventType.ENTITY_UPDATED;
|
||||
validateChangeEvents(entityInterface, expectedEventType, authHeaders);
|
||||
}
|
||||
return updated;
|
||||
}
|
||||
|
||||
@ -718,7 +724,12 @@ public abstract class EntityResourceTest<T> extends CatalogApplicationTest {
|
||||
}
|
||||
}
|
||||
|
||||
protected final void validateChangeEvents(EntityInterface<T> entityInterface, UpdateType updateType,
|
||||
/**
|
||||
* This method validates the change event created after POST, PUT, and PATCH operations
|
||||
* and ensures entityCreate, entityUpdated, and entityDeleted change events are created in the system with
|
||||
* valid date.
|
||||
*/
|
||||
protected final void validateChangeEvents(EntityInterface<T> entityInterface, EventType expectedEventType,
|
||||
Map<String, String> authHeaders) throws IOException {
|
||||
ResultList<ChangeEvent> changeEvents = getChangeEvents(entityName, entityName, null,
|
||||
entityInterface.getUpdatedAt(), authHeaders);
|
||||
@ -727,6 +738,7 @@ public abstract class EntityResourceTest<T> extends CatalogApplicationTest {
|
||||
|
||||
// Top most changeEvent corresponds to the update
|
||||
ChangeEvent changeEvent = changeEvents.getData().get(0);
|
||||
assertEquals(expectedEventType, changeEvent.getEventType());
|
||||
|
||||
assertEquals(changeEvent.getDateTime().getTime(), entityInterface.getUpdatedAt().getTime());
|
||||
assertEquals(changeEvent.getEntityId(), entityInterface.getId());
|
||||
@ -734,13 +746,15 @@ public abstract class EntityResourceTest<T> extends CatalogApplicationTest {
|
||||
assertEquals(changeEvent.getUserName(), entityInterface.getUpdatedBy());
|
||||
assertEquals(changeEvent.getEntityType(), entityName);
|
||||
|
||||
if (updateType == UpdateType.CREATED) {
|
||||
if (expectedEventType == EventType.ENTITY_CREATED) {
|
||||
assertEquals(changeEvent.getEventType(), EventType.ENTITY_CREATED);
|
||||
assertEquals(changeEvent.getPreviousVersion(), 0.1);
|
||||
assertNull(changeEvent.getChangeDescription());
|
||||
compareEntities(entityInterface.getEntity(),
|
||||
JsonUtils.readValue((String)changeEvent.getEntity(), entityClass), authHeaders);
|
||||
} else if (updateType == MINOR_UPDATE) {
|
||||
} else if (expectedEventType == EventType.ENTITY_UPDATED) {
|
||||
// TODO
|
||||
} else if (expectedEventType == EventType.ENTITY_DELETED) {
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user