Skip to content

Commit

Permalink
Add Unit Test Cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Amoncy authored and carlesarnal committed Sep 8, 2023
1 parent 107d5ff commit 7b66678
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,53 @@ public void testDefaultGroup() throws Exception {
.body("openapi", not(equalTo("3.0.2")))
.body("info.title", not(equalTo("Empty API")));
}

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

//Test Rule type null
Rule nullType = new Rule();
nullType.setType(null);
nullType.setConfig("TestConfig");
given()
.when()
.pathParam("groupId", "testCreateArtifactRule")
.pathParam("artifactId", "testCreateArtifactRule/EmptyAPI/1")
.body(nullType)
.post("/registry/v2/groups/{groupId}/artifacts/{artifactId/rules}")
.then()
.statusCode(400);

//Test Rule config null
Rule nullConfig = new Rule();
nullConfig.setType(RuleType.VALIDITY);
nullConfig.setConfig(null);
given()
.when()
.pathParam("groupId", "testCreateArtifactRule")
.pathParam("artifactId", "testCreateArtifactRule/EmptyAPI/1")
.body(nullConfig)
.post("/registry/v2/groups/{groupId}/artifacts/{artifactId/rules}")
.then()
.statusCode(400);

//Test Rule config null
Rule emptyConfig = new Rule();
emptyConfig.setType(RuleType.VALIDITY);
emptyConfig.setConfig("");
given()
.when()
.pathParam("groupId", "testCreateArtifactRule")
.pathParam("artifactId", "testCreateArtifactRule/EmptyAPI/1")
.body(emptyConfig)
.post("/registry/v2/groups/{groupId}/artifacts/{artifactId/rules}")
.then()
.statusCode(400);

}

@Test
public void testUpdateArtifactOwner() throws Exception {
Expand Down
41 changes: 41 additions & 0 deletions app/src/test/java/io/apicurio/registry/rbac/AdminResourceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,47 @@ public void testGlobalRulesEndpoint() {
.statusCode(200)
.body(anything());
}

@Test
public void testCreateGlobalRule() throws Exception
{
//Test Rule type null
Rule nullType = new Rule();
nullType.setType(null);
nullType.setConfig("TestConfig");
given()
.when()
.contentType(CT_JSON)
.body(nullType)
.post("/registry/v2/admin/rules")
.then()
.statusCode(400);

//Test Rule config null
Rule nullConfig = new Rule();
nullConfig.setType(RuleType.VALIDITY);
nullConfig.setConfig(null);
given()
.when()
.contentType(CT_JSON)
.body(nullConfig)
.post("/registry/v2/admin/rules")
.then()
.statusCode(400);

//Test Rule config null
Rule emptyConfig = new Rule();
emptyConfig.setType(RuleType.VALIDITY);
emptyConfig.setConfig("");
given()
.when()
.contentType(CT_JSON)
.body(emptyConfig)
.post("/registry/v2/admin/rules")
.then()
.statusCode(400);

}

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

0 comments on commit 7b66678

Please sign in to comment.