From 31353afc2410fa2ec6e65a3a05c289d82e5621ef Mon Sep 17 00:00:00 2001 From: Alberto Miorin <32617+amiorin@users.noreply.github.com> Date: Tue, 7 Dec 2021 04:14:33 +0100 Subject: [PATCH] Fix #1554: Fix post_locationWithDifferentService_200_ok in LocationResourceTest (#1590) --- .../resources/locations/LocationResource.java | 8 +++--- .../locations/LocationResourceTest.java | 25 ++++++++++++------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/catalog-rest-service/src/main/java/org/openmetadata/catalog/resources/locations/LocationResource.java b/catalog-rest-service/src/main/java/org/openmetadata/catalog/resources/locations/LocationResource.java index 938f0ae642d..b901be9902b 100644 --- a/catalog-rest-service/src/main/java/org/openmetadata/catalog/resources/locations/LocationResource.java +++ b/catalog-rest-service/src/main/java/org/openmetadata/catalog/resources/locations/LocationResource.java @@ -109,7 +109,7 @@ public class LocationResource { @GET @Operation(summary = "List locations", tags = "locations", - description = "Get a list of locations, optionally filtered by `fqnPrefix`. Use `fields` " + + description = "Get a list of locations, optionally filtered by `service` it belongs to. Use `fields` " + "parameter to get only necessary fields. Use cursor-based pagination to limit the number " + "entries in the list using `limit` and `before` or `after` query params.", responses = {@ApiResponse(responseCode = "200", description = "List of locations", @@ -122,7 +122,7 @@ public class LocationResource { @QueryParam("fields") String fieldsParam, @Parameter(description = "Filter locations by prefix of the FQN", schema = @Schema(type = "string", example = "s3://bucket/folder1")) - @QueryParam("fqnPrefix") String fqnPrefixParam, + @QueryParam("service") String serviceParam, @Parameter(description = "Limit the number locations returned. " + "(1 to 1000000, default = 10)") @DefaultValue("10") @@ -141,9 +141,9 @@ public class LocationResource { ResultList locations; if (before != null) { // Reverse paging - locations = dao.listBefore(uriInfo, fields, fqnPrefixParam, limitParam, before); // Ask for one extra entry + locations = dao.listBefore(uriInfo, fields, serviceParam, limitParam, before); // Ask for one extra entry } else { // Forward paging or first page - locations = dao.listAfter(uriInfo, fields, fqnPrefixParam, limitParam, after); + locations = dao.listAfter(uriInfo, fields, serviceParam, limitParam, after); } locations.getData().forEach(l -> addHref(uriInfo, l)); return locations; diff --git a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/locations/LocationResourceTest.java b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/locations/LocationResourceTest.java index ae9e9bdd8bb..b48c2d6c2dd 100644 --- a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/locations/LocationResourceTest.java +++ b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/locations/LocationResourceTest.java @@ -30,6 +30,7 @@ import org.openmetadata.catalog.resources.services.StorageServiceResourceTest; import org.openmetadata.catalog.type.EntityReference; import org.openmetadata.catalog.type.StorageServiceType; import org.openmetadata.catalog.util.EntityInterface; +import org.openmetadata.catalog.util.ResultList; import org.openmetadata.catalog.util.TestUtils; import javax.ws.rs.client.WebTarget; @@ -39,6 +40,7 @@ import java.net.URISyntaxException; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; import java.util.Arrays; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.UUID; @@ -82,12 +84,14 @@ public class LocationResourceTest extends EntityResourceTest { } @Override - public Object createRequest(String name, String description, String displayName, EntityReference owner) throws URISyntaxException { + public Object createRequest(String name, String description, String displayName, EntityReference owner) + throws URISyntaxException { return create(name).withDescription(description).withOwner(owner); } @Override - public void validateCreatedEntity(Location location, Object request, Map authHeaders) throws HttpResponseException { + public void validateCreatedEntity(Location location, Object request, Map authHeaders) + throws HttpResponseException { CreateLocation createRequest = (CreateLocation) request; validateCommonEntityFields(getEntityInterface(location), createRequest.getDescription(), TestUtils.getPrincipal(authHeaders), createRequest.getOwner()); @@ -103,12 +107,14 @@ public class LocationResourceTest extends EntityResourceTest { } @Override - public void validateUpdatedEntity(Location location, Object request, Map authHeaders) throws HttpResponseException { + public void validateUpdatedEntity(Location location, Object request, Map authHeaders) + throws HttpResponseException { validateCreatedEntity(location, request, authHeaders); } @Override - public void compareEntities(Location expected, Location patched, Map authHeaders) throws HttpResponseException { + public void compareEntities(Location expected, Location patched, Map authHeaders) + throws HttpResponseException { validateCommonEntityFields(getEntityInterface(patched), expected.getDescription(), TestUtils.getPrincipal(authHeaders), expected.getOwner()); // Entity specific validation @@ -242,11 +248,12 @@ public class LocationResourceTest extends EntityResourceTest { for (EntityReference service : differentServices) { createAndCheckEntity(create(test).withService(service), adminAuthHeaders()); - // List locations by filtering on service name and ensure right locations are returned in the response -// LocationList list = listLocations("service", service.getName(), adminAuthHeaders()); -// for (Location location : list.getData()) { -// assertEquals(service.getName(), location.getService().getName()); -// } + // List locations by filtering on service name and ensure right locations are returned + Map queryParams = new HashMap<>(){{put("service", service.getName());}}; + ResultList list = listEntities(queryParams, adminAuthHeaders()); + for (Location location : list.getData()) { + assertEquals(service.getName(), location.getService().getName()); + } } }