Skip to content

Commit

Permalink
Update validation messages
Browse files Browse the repository at this point in the history
  • Loading branch information
tvernum committed Jan 13, 2020
1 parent a02c11d commit fbfe58c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -422,15 +422,16 @@ private void validate() {
private static void validateLimits(String type, int maxNodes, int maxResourceUnits) {
if (LicenseType.isEnterprise(type)) {
if (maxResourceUnits == -1) {
throw new IllegalStateException("maxResourceUnits must be set for enterprise licenses");
throw new IllegalStateException("maxResourceUnits must be set for enterprise licenses (type=[" + type + "])");
} else if (maxNodes != -1) {
throw new IllegalStateException("maxNodes may not be set for enterprise licenses");
throw new IllegalStateException("maxNodes may not be set for enterprise licenses (type=[" + type + "])");
}
} else {
if (maxNodes == -1) {
throw new IllegalStateException("maxNodes has to be set");
} else if (maxResourceUnits != -1) {
throw new IllegalStateException("maxResourceUnits may only be set for enterprise licenses");
throw new IllegalStateException("maxResourceUnits may only be set for enterprise licenses (not permitted for type=[" +
type + "])");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,14 @@ public void testThatEnterpriseLicenseMayNotHaveMaxNodes() throws Exception {
.maxNodes(randomIntBetween(1, 50))
.maxResourceUnits(randomIntBetween(10, 500));
final IllegalStateException ex = expectThrows(IllegalStateException.class, builder::build);
assertThat(ex, TestMatchers.throwableWithMessage("maxNodes may not be set for enterprise licenses"));
assertThat(ex, TestMatchers.throwableWithMessage("maxNodes may not be set for enterprise licenses (type=[enterprise])"));
}

public void testThatEnterpriseLicenseMustHaveMaxResourceUnits() throws Exception {
License.Builder builder = randomLicense(License.LicenseType.ENTERPRISE)
.maxResourceUnits(-1);
final IllegalStateException ex = expectThrows(IllegalStateException.class, builder::build);
assertThat(ex, TestMatchers.throwableWithMessage("maxResourceUnits must be set for enterprise licenses"));
assertThat(ex, TestMatchers.throwableWithMessage("maxResourceUnits must be set for enterprise licenses (type=[enterprise])"));
}

public void testThatRegularLicensesMustHaveMaxNodes() throws Exception {
Expand All @@ -145,7 +145,8 @@ public void testThatRegularLicensesMayNotHaveMaxResourceUnits() throws Exception
.maxResourceUnits(randomIntBetween(10, 500))
.maxNodes(randomIntBetween(1, 50));
final IllegalStateException ex = expectThrows(IllegalStateException.class, builder::build);
assertThat(ex, TestMatchers.throwableWithMessage("maxResourceUnits may only be set for enterprise licenses"));
assertThat(ex, TestMatchers.throwableWithMessage("maxResourceUnits may only be set for enterprise licenses (not permitted " +
"for type=[" + type.getTypeName() + "])"));
}

public void testLicenseToAndFromXContentForEveryLicenseType() throws Exception {
Expand Down

0 comments on commit fbfe58c

Please sign in to comment.