import static com.google.common.base.Preconditions.checkArgument;
import static org.sonar.server.organization.OrganizationCreation.NewOrganization.newOrganizationBuilder;
+import static org.sonar.server.organization.OrganizationValidation.KEY_MAX_LENGTH;
import static org.sonar.server.organization.ws.OrganizationsWsSupport.PARAM_KEY;
import static org.sonar.server.ws.WsUtils.writeProtobuf;
action.createParam(PARAM_KEY)
.setRequired(false)
+ .setMaximumLength(KEY_MAX_LENGTH)
.setDescription("Key of the organization. <br />" +
"The key is unique to the whole SonarQube. <br/>" +
"When not specified, the key is computed from the name. <br />" +
import org.sonarqube.ws.Organizations;
import static org.sonar.core.util.Protobuf.setNullable;
+import static org.sonar.server.organization.OrganizationValidation.DESCRIPTION_MAX_LENGTH;
+import static org.sonar.server.organization.OrganizationValidation.NAME_MAX_LENGTH;
+import static org.sonar.server.organization.OrganizationValidation.URL_MAX_LENGTH;
/**
* Factorizes code and constants between Organization WS's actions.
void addOrganizationDetailsParams(WebService.NewAction action, boolean isNameRequired) {
action.createParam(PARAM_NAME)
.setRequired(isNameRequired)
+ .setMaximumLength(NAME_MAX_LENGTH)
.setDescription("Name of the organization. <br />" +
"It must be between 2 and 64 chars longs.")
.setExampleValue("Foo Company");
action.createParam(PARAM_DESCRIPTION)
.setRequired(false)
+ .setMaximumLength(DESCRIPTION_MAX_LENGTH)
.setDescription("Description of the organization.<br/> It must be less than 256 chars long.")
.setExampleValue("The Foo company produces quality software for Bar.");
action.createParam(PARAM_URL)
.setRequired(false)
+ .setMaximumLength(URL_MAX_LENGTH)
.setDescription("URL of the organization.<br/> It must be less than 256 chars long.")
.setExampleValue("https://www.foo.com");
action.createParam(PARAM_AVATAR_URL)
.setRequired(false)
+ .setMaximumLength(URL_MAX_LENGTH)
.setDescription("URL of the organization avatar.<br/> It must be less than 256 chars long.")
.setExampleValue("https://www.foo.com/foo.png");
}
logInAsSystemAdministrator();
expectedException.expect(IllegalArgumentException.class);
- expectedException.expectMessage("Name '" + STRING_65_CHARS_LONG + "' must be at most 64 chars long");
+ expectedException.expectMessage("'name' length (65) is longer than the maximum authorized (64)");
executeRequest(STRING_65_CHARS_LONG);
}
String key = STRING_65_CHARS_LONG.substring(0, 33);
expectedException.expect(IllegalArgumentException.class);
- expectedException.expectMessage("Key '" + key + "' must be at most 32 chars long");
+ expectedException.expectMessage("'key' length (33) is longer than the maximum authorized (32)");
executeRequest("foo", key);
}
logInAsSystemAdministrator();
expectedException.expect(IllegalArgumentException.class);
- expectedException.expectMessage("Description '" + STRING_257_CHARS_LONG + "' must be at most 256 chars long");
+ expectedException.expectMessage("'description' length (257) is longer than the maximum authorized (256)");
executeRequest("foo", "bar", STRING_257_CHARS_LONG, null, null);
}
logInAsSystemAdministrator();
expectedException.expect(IllegalArgumentException.class);
- expectedException.expectMessage("Url '" + STRING_257_CHARS_LONG + "' must be at most 256 chars long");
+ expectedException.expectMessage("'url' length (257) is longer than the maximum authorized (256)");
executeRequest("foo", "bar", null, STRING_257_CHARS_LONG, null);
}
logInAsSystemAdministrator();
expectedException.expect(IllegalArgumentException.class);
- expectedException.expectMessage("Avatar '" + STRING_257_CHARS_LONG + "' must be at most 256 chars long");
+ expectedException.expectMessage("'avatar' length (257) is longer than the maximum authorized (256)");
executeRequest("foo", "bar", null, null, STRING_257_CHARS_LONG);
}
userSession.logIn();
expectedException.expect(IllegalArgumentException.class);
- expectedException.expectMessage("Name '" + STRING_65_CHARS_LONG + "' must be at most 64 chars long");
+ expectedException.expectMessage("'name' length (65) is longer than the maximum authorized (64)");
+
executeKeyRequest(SOME_KEY, STRING_65_CHARS_LONG);
}
userSession.logIn();
expectedException.expect(IllegalArgumentException.class);
- expectedException.expectMessage("Description '" + STRING_257_CHARS_LONG + "' must be at most 256 chars long");
+ expectedException.expectMessage("'description' length (257) is longer than the maximum authorized (256)");
executeKeyRequest(SOME_KEY, "bar", STRING_257_CHARS_LONG, null, null);
}
userSession.logIn();
expectedException.expect(IllegalArgumentException.class);
- expectedException.expectMessage("Url '" + STRING_257_CHARS_LONG + "' must be at most 256 chars long");
+ expectedException.expectMessage("'url' length (257) is longer than the maximum authorized (256)");
executeKeyRequest(SOME_KEY, "bar", null, STRING_257_CHARS_LONG, null);
}
userSession.logIn();
expectedException.expect(IllegalArgumentException.class);
- expectedException.expectMessage("Avatar '" + STRING_257_CHARS_LONG + "' must be at most 256 chars long");
+ expectedException.expectMessage("'avatar' length (257) is longer than the maximum authorized (256)");
executeKeyRequest(SOME_KEY, "bar", null, null, STRING_257_CHARS_LONG);
}