Skip to content

Commit

Permalink
added unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
renjingxiao committed Aug 29, 2023
1 parent e60e082 commit bd602fd
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -258,14 +258,13 @@ public ArtifactOwner getArtifactOwner(String groupId, String artifactId) {
public void updateArtifactOwner(String groupId, String artifactId, ArtifactOwner data) {
requireParameter("groupId", groupId);
requireParameter("artifactId", artifactId);
requireParameter("data", data);

String owner = data.getOwner();
requireParameter("owner", owner);
if (owner.trim().isEmpty()) {
throw new MissingRequiredParameterException("owner");
if (data.getOwner().isEmpty()) {
throw new MissingRequiredParameterException("Missing required owner");
}

ArtifactOwnerDto dto = new ArtifactOwnerDto(owner);
ArtifactOwnerDto dto = new ArtifactOwnerDto(data.getOwner());
storage.updateArtifactOwner(defaultGroupIdToNull(groupId), artifactId, dto);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@

import io.apicurio.registry.AbstractResourceTestBase;
import io.apicurio.registry.rest.client.exception.RuleViolationException;
import io.apicurio.registry.rest.v2.beans.ArtifactOwner;
import io.apicurio.registry.rest.v2.beans.ArtifactMetaData;
import io.apicurio.registry.rest.v2.beans.ArtifactReference;
import io.apicurio.registry.rest.v2.beans.Comment;
Expand Down Expand Up @@ -178,6 +179,41 @@ public void testDefaultGroup() throws Exception {
.body("info.title", equalTo("Empty API"));
}

@Test
public void testUpdateArtifactOwner() throws Exception {
String oaiArtifactContent = resourceToString("openapi-empty.json");
createArtifact("testUpdateArtifactOwner", "testUpdateArtifactOwner/EmptyAPI/1",ArtifactType.OPENAPI, oaiArtifactContent);

ArtifactOwner artifactOwner = new ArtifactOwner("newOwner");

given()
.when()
.contentType(CT_JSON)
.pathParam("groupId", "testUpdateArtifactOwner")
.pathParam("artifactId", "testUpdateArtifactOwner/EmptyAPI/1")
.body(artifactOwner)
.put("/registry/v2/groups/{groupId}/artifacts/{artifactId}/owner")
.then()
.statusCode(204);
}

@Test
public void testUpdateEmptyArtifactOwner() throws Exception {
String oaiArtifactContent = resourceToString("openapi-empty.json");
createArtifact("testUpdateEmptyArtifactOwner", "testUpdateEmptyArtifactOwner/EmptyAPI/1",ArtifactType.OPENAPI, oaiArtifactContent);

ArtifactOwner artifactOwner = new ArtifactOwner("");

given()
.when()
.contentType(CT_JSON)
.pathParam("groupId", "testUpdateEmptyArtifactOwner")
.pathParam("artifactId", "testUpdateEmptyArtifactOwner/EmptyAPI/1")
.body(artifactOwner)
.put("/registry/v2/groups/{groupId}/artifacts/{artifactId}/owner")
.then()
.statusCode(400);
}

@Test
public void testMultipleGroups() throws Exception {
Expand Down

0 comments on commit bd602fd

Please sign in to comment.