private static void validateMaximumLength(String key, WebService.Param definition, String valueOrDefault) { Integer maximumLength = definition.maximumLength(); if (maximumLength == null) { return; } int valueLength = valueOrDefault.length(); checkArgument(valueLength <= maximumLength, "'%s' length (%s) is longer than the maximum authorized (%s)", key, valueLength, maximumLength); }
assertThat(project.maximumLength()).isEqualTo(400);
private static void writeParam(JsonWriter writer, WebService.Param param) { writer.beginObject(); writer.prop("key", param.key()); writer.prop("description", param.description()); writer.prop("since", param.since()); writer.prop("required", param.isRequired()); writer.prop("internal", param.isInternal()); writer.prop("defaultValue", param.defaultValue()); writer.prop("exampleValue", param.exampleValue()); writer.prop("deprecatedSince", param.deprecatedSince()); writer.prop("deprecatedKey", param.deprecatedKey()); writer.prop("deprecatedKeySince", param.deprecatedKeySince()); writer.prop("maxValuesAllowed", param.maxValuesAllowed()); ofNullable(param.possibleValues()).ifPresent(possibleValues -> writer.name("possibleValues").beginArray().values(possibleValues).endArray()); ofNullable(param.maximumLength()).ifPresent(maximumLength -> writer.prop("maximumLength", maximumLength)); ofNullable(param.minimumLength()).ifPresent(minimumLength -> writer.prop("minimumLength", minimumLength)); ofNullable(param.maximumValue()).ifPresent(maximumValue -> writer.prop("maximumValue", maximumValue)); writer.endObject(); }
private static void writeParam(JsonWriter writer, WebService.Param param) { writer.beginObject(); writer.prop("key", param.key()); writer.prop("description", param.description()); writer.prop("since", param.since()); writer.prop("required", param.isRequired()); writer.prop("internal", param.isInternal()); writer.prop("defaultValue", param.defaultValue()); writer.prop("exampleValue", param.exampleValue()); writer.prop("deprecatedSince", param.deprecatedSince()); writer.prop("deprecatedKey", param.deprecatedKey()); writer.prop("deprecatedKeySince", param.deprecatedKeySince()); writer.prop("maxValuesAllowed", param.maxValuesAllowed()); ofNullable(param.possibleValues()).ifPresent(possibleValues -> writer.name("possibleValues").beginArray().values(possibleValues).endArray()); ofNullable(param.maximumLength()).ifPresent(maximumLength -> writer.prop("maximumLength", maximumLength)); ofNullable(param.minimumLength()).ifPresent(minimumLength -> writer.prop("minimumLength", minimumLength)); ofNullable(param.maximumValue()).ifPresent(maximumValue -> writer.prop("maximumValue", maximumValue)); writer.endObject(); }
private static void validateMaximumLength(String key, WebService.Param definition, String valueOrDefault) { Integer maximumLength = definition.maximumLength(); if (maximumLength == null) { return; } int valueLength = valueOrDefault.length(); checkArgument(valueLength <= maximumLength, "'%s' length (%s) is longer than the maximum authorized (%s)", key, valueLength, maximumLength); }
.matches(param -> "Foo Company".equals(param.exampleValue())) .matches(param -> param.minimumLength().equals(1)) .matches(param -> param.maximumLength().equals(255)) .matches(param -> param.description() != null); assertThat(action.param("key")) .matches(param -> "foo-company".equals(param.exampleValue())) .matches(param -> param.minimumLength().equals(1)) .matches(param -> param.maximumLength().equals(255)) .matches(param -> param.description() != null); assertThat(action.param("description"))
.matches(param -> "Foo Company".equals(param.exampleValue())) .matches(param -> param.minimumLength().equals(1)) .matches(param -> param.maximumLength().equals(255)) .matches(param -> param.description() != null); assertThat(action.param("description"))
@Test public void param_with_maximum_length() { ((WebService) context -> { NewController newController = context.createController("api/custom_measures"); NewAction create = newDefaultAction(newController, "create"); create.createParam("string_value") .setMaximumLength(24); newController.done(); }).define(context); WebService.Action action = context.controller("api/custom_measures").action("create"); assertThat(action.param("string_value").maximumLength()).isEqualTo(24); }