Fix #1554: Fix post_locationWithDifferentService_200_ok in LocationResourceTest (#1590)

This commit is contained in:
Alberto Miorin 2021-12-07 04:14:33 +01:00 committed by GitHub
parent 8621ee3fa0
commit 31353afc24
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 13 deletions

View File

@ -109,7 +109,7 @@ public class LocationResource {
@GET @GET
@Operation(summary = "List locations", tags = "locations", @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 " + "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.", "entries in the list using `limit` and `before` or `after` query params.",
responses = {@ApiResponse(responseCode = "200", description = "List of locations", responses = {@ApiResponse(responseCode = "200", description = "List of locations",
@ -122,7 +122,7 @@ public class LocationResource {
@QueryParam("fields") String fieldsParam, @QueryParam("fields") String fieldsParam,
@Parameter(description = "Filter locations by prefix of the FQN", @Parameter(description = "Filter locations by prefix of the FQN",
schema = @Schema(type = "string", example = "s3://bucket/folder1")) schema = @Schema(type = "string", example = "s3://bucket/folder1"))
@QueryParam("fqnPrefix") String fqnPrefixParam, @QueryParam("service") String serviceParam,
@Parameter(description = "Limit the number locations returned. " + @Parameter(description = "Limit the number locations returned. " +
"(1 to 1000000, default = 10)") "(1 to 1000000, default = 10)")
@DefaultValue("10") @DefaultValue("10")
@ -141,9 +141,9 @@ public class LocationResource {
ResultList<Location> locations; ResultList<Location> locations;
if (before != null) { // Reverse paging 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 } 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)); locations.getData().forEach(l -> addHref(uriInfo, l));
return locations; return locations;

View File

@ -30,6 +30,7 @@ import org.openmetadata.catalog.resources.services.StorageServiceResourceTest;
import org.openmetadata.catalog.type.EntityReference; import org.openmetadata.catalog.type.EntityReference;
import org.openmetadata.catalog.type.StorageServiceType; import org.openmetadata.catalog.type.StorageServiceType;
import org.openmetadata.catalog.util.EntityInterface; import org.openmetadata.catalog.util.EntityInterface;
import org.openmetadata.catalog.util.ResultList;
import org.openmetadata.catalog.util.TestUtils; import org.openmetadata.catalog.util.TestUtils;
import javax.ws.rs.client.WebTarget; import javax.ws.rs.client.WebTarget;
@ -39,6 +40,7 @@ import java.net.URISyntaxException;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
@ -82,12 +84,14 @@ public class LocationResourceTest extends EntityResourceTest<Location> {
} }
@Override @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); return create(name).withDescription(description).withOwner(owner);
} }
@Override @Override
public void validateCreatedEntity(Location location, Object request, Map<String, String> authHeaders) throws HttpResponseException { public void validateCreatedEntity(Location location, Object request, Map<String, String> authHeaders)
throws HttpResponseException {
CreateLocation createRequest = (CreateLocation) request; CreateLocation createRequest = (CreateLocation) request;
validateCommonEntityFields(getEntityInterface(location), createRequest.getDescription(), validateCommonEntityFields(getEntityInterface(location), createRequest.getDescription(),
TestUtils.getPrincipal(authHeaders), createRequest.getOwner()); TestUtils.getPrincipal(authHeaders), createRequest.getOwner());
@ -103,12 +107,14 @@ public class LocationResourceTest extends EntityResourceTest<Location> {
} }
@Override @Override
public void validateUpdatedEntity(Location location, Object request, Map<String, String> authHeaders) throws HttpResponseException { public void validateUpdatedEntity(Location location, Object request, Map<String, String> authHeaders)
throws HttpResponseException {
validateCreatedEntity(location, request, authHeaders); validateCreatedEntity(location, request, authHeaders);
} }
@Override @Override
public void compareEntities(Location expected, Location patched, Map<String, String> authHeaders) throws HttpResponseException { public void compareEntities(Location expected, Location patched, Map<String, String> authHeaders)
throws HttpResponseException {
validateCommonEntityFields(getEntityInterface(patched), expected.getDescription(), validateCommonEntityFields(getEntityInterface(patched), expected.getDescription(),
TestUtils.getPrincipal(authHeaders), expected.getOwner()); TestUtils.getPrincipal(authHeaders), expected.getOwner());
// Entity specific validation // Entity specific validation
@ -242,11 +248,12 @@ public class LocationResourceTest extends EntityResourceTest<Location> {
for (EntityReference service : differentServices) { for (EntityReference service : differentServices) {
createAndCheckEntity(create(test).withService(service), adminAuthHeaders()); createAndCheckEntity(create(test).withService(service), adminAuthHeaders());
// List locations by filtering on service name and ensure right locations are returned in the response // List locations by filtering on service name and ensure right locations are returned
// LocationList list = listLocations("service", service.getName(), adminAuthHeaders()); Map<String, String> queryParams = new HashMap<>(){{put("service", service.getName());}};
// for (Location location : list.getData()) { ResultList<Location> list = listEntities(queryParams, adminAuthHeaders());
// assertEquals(service.getName(), location.getService().getName()); for (Location location : list.getData()) {
// } assertEquals(service.getName(), location.getService().getName());
}
} }
} }