Skip to content

Commit

Permalink
test(rule): add test for maximum rule name length
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewazores committed Jan 6, 2025
1 parent 443c9c0 commit bfa4d74
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/test/java/io/cryostat/rules/RulesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.Matchers.*;

import java.util.Arrays;

import io.cryostat.AbstractTransactionalTestBase;

import io.quarkus.test.common.http.TestHTTPEndpoint;
Expand All @@ -30,6 +32,8 @@
import jakarta.transaction.Transactional;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.mockito.Mockito;

@QuarkusTest
Expand Down Expand Up @@ -244,6 +248,20 @@ public void testCreateThrowsWhenBodyNull() {
.statusCode(400);
}

@ParameterizedTest
@ValueSource(ints = {1, 16, 64, 128, 256})
public void testCreateThrowsWhenNameTooLong(int len) {
char[] c = new char[len];
Arrays.fill(c, 'a');
rule.put("name", new String(c));
final int limit = 255;
given().body(rule.toString())
.contentType(ContentType.JSON)
.post()
.then()
.statusCode(len <= limit ? 201 : 400);
}

@Test
public void testCreateThrowsWhenMandatoryFieldsUnspecified() {
var badRule = new JsonObject();
Expand Down

0 comments on commit bfa4d74

Please sign in to comment.