Browse Source

SONAR-8575 Use proto3 in api/settings

Using proto3 allows to use oneof in order to enforce the fact that only one of value, values or fieldValues is set
tags/6.3-RC1
Julien Lancelot 7 years ago
parent
commit
d3eb8f8c09

+ 10
- 5
server/sonar-server/src/test/java/org/sonar/server/setting/ws/ListDefinitionsActionTest.java View File

@@ -57,6 +57,11 @@ import static org.sonar.api.web.UserRole.USER;
import static org.sonar.core.permission.GlobalPermissions.SYSTEM_ADMIN;
import static org.sonar.db.component.ComponentTesting.newProjectDto;
import static org.sonarqube.ws.MediaTypes.JSON;
import static org.sonarqube.ws.Settings.Definition.CategoryOneOfCase.CATEGORYONEOF_NOT_SET;
import static org.sonarqube.ws.Settings.Definition.DefaultValueOneOfCase.DEFAULTVALUEONEOF_NOT_SET;
import static org.sonarqube.ws.Settings.Definition.DeprecatedKeyOneOfCase.DEPRECATEDKEYONEOF_NOT_SET;
import static org.sonarqube.ws.Settings.Definition.NameOneOfCase.NAMEONEOF_NOT_SET;
import static org.sonarqube.ws.Settings.Definition.SubCategoryOneOfCase.SUBCATEGORYONEOF_NOT_SET;
import static org.sonarqube.ws.Settings.Type.BOOLEAN;
import static org.sonarqube.ws.Settings.Type.LICENSE;
import static org.sonarqube.ws.Settings.Type.PROPERTY_SET;
@@ -130,14 +135,14 @@ public class ListDefinitionsActionTest {
Settings.Definition definition = result.getDefinitions(0);
assertThat(definition.getKey()).isEqualTo("foo");
assertThat(definition.getType()).isEqualTo(STRING);
assertThat(definition.hasName()).isFalse();
assertThat(definition.hasCategory()).isFalse();
assertThat(definition.hasSubCategory()).isFalse();
assertThat(definition.hasDefaultValue()).isFalse();
assertThat(definition.getNameOneOfCase()).isEqualTo(NAMEONEOF_NOT_SET);
assertThat(definition.getCategoryOneOfCase()).isEqualTo(CATEGORYONEOF_NOT_SET);
assertThat(definition.getSubCategoryOneOfCase()).isEqualTo(SUBCATEGORYONEOF_NOT_SET);
assertThat(definition.getDefaultValueOneOfCase()).isEqualTo(DEFAULTVALUEONEOF_NOT_SET);
assertThat(definition.getMultiValues()).isFalse();
assertThat(definition.getOptionsCount()).isZero();
assertThat(definition.getFieldsCount()).isZero();
assertThat(definition.hasDeprecatedKey()).isFalse();
assertThat(definition.getDeprecatedKeyOneOfCase()).isEqualTo(DEPRECATEDKEYONEOF_NOT_SET);
}

@Test

+ 4
- 13
server/sonar-server/src/test/java/org/sonar/server/setting/ws/ValuesActionTest.java View File

@@ -62,6 +62,7 @@ import static org.sonar.db.component.ComponentTesting.newProjectDto;
import static org.sonar.db.property.PropertyTesting.newComponentPropertyDto;
import static org.sonar.db.property.PropertyTesting.newGlobalPropertyDto;
import static org.sonarqube.ws.MediaTypes.JSON;
import static org.sonarqube.ws.Settings.Setting.ParentValueOneOfCase.PARENTVALUEONEOF_NOT_SET;

public class ValuesActionTest {

@@ -105,8 +106,6 @@ public class ValuesActionTest {
Settings.Setting value = result.getSettings(0);
assertThat(value.getKey()).isEqualTo("foo");
assertThat(value.getValue()).isEqualTo("one");
assertThat(value.hasValues()).isFalse();
assertThat(value.hasFieldValues()).isFalse();
assertThat(value.getInherited()).isFalse();
}

@@ -129,15 +128,11 @@ public class ValuesActionTest {

Settings.Setting foo = result.getSettings(0);
assertThat(foo.getKey()).isEqualTo("default");
assertThat(foo.hasValue()).isFalse();
assertThat(foo.getValues().getValuesList()).containsOnly("one", "two");
assertThat(foo.hasFieldValues()).isFalse();

Settings.Setting bar = result.getSettings(1);
assertThat(bar.getKey()).isEqualTo("global");
assertThat(bar.hasValue()).isFalse();
assertThat(bar.getValues().getValuesList()).containsOnly("three", "four");
assertThat(bar.hasFieldValues()).isFalse();
}

@Test
@@ -171,8 +166,6 @@ public class ValuesActionTest {
assertThat(result.getSettingsList()).hasSize(1);
Settings.Setting value = result.getSettings(0);
assertThat(value.getKey()).isEqualTo("foo");
assertThat(value.hasValue()).isFalse();
assertThat(value.hasValues()).isFalse();
assertFieldValues(value, ImmutableMap.of("key", "key1", "size", "size1"), ImmutableMap.of("key", "key2"));
}

@@ -193,8 +186,6 @@ public class ValuesActionTest {
assertThat(result.getSettingsList()).hasSize(1);
Settings.Setting value = result.getSettings(0);
assertThat(value.getKey()).isEqualTo("foo");
assertThat(value.hasValue()).isFalse();
assertThat(value.hasValues()).isFalse();
assertFieldValues(value, ImmutableMap.of("key", "key1", "size", "size1"), ImmutableMap.of("key", "key2"));
}

@@ -707,7 +698,7 @@ public class ValuesActionTest {

private void assertParentValue(Settings.Setting setting, @Nullable String parentValue) {
if (parentValue == null) {
assertThat(setting.hasParentValue()).isFalse();
assertThat(setting.getParentValueOneOfCase()).isEqualTo(PARENTVALUEONEOF_NOT_SET);
} else {
assertThat(setting.getParentValue()).isEqualTo(parentValue);
}
@@ -715,7 +706,7 @@ public class ValuesActionTest {

private void assertParentValues(Settings.Setting setting, String... parentValues) {
if (parentValues.length == 0) {
assertThat(setting.hasParentValues()).isFalse();
assertThat(setting.getParentValueOneOfCase()).isEqualTo(PARENTVALUEONEOF_NOT_SET);
} else {
assertThat(setting.getParentValues().getValuesList()).containsOnly(parentValues);
}
@@ -723,7 +714,7 @@ public class ValuesActionTest {

private void assertParentFieldValues(Settings.Setting setting, Map<String, String>... fieldsValues) {
if (fieldsValues.length == 0) {
assertThat(setting.hasParentFieldValues()).isFalse();
assertThat(setting.getParentValueOneOfCase()).isEqualTo(PARENTVALUEONEOF_NOT_SET);
} else {
assertThat(setting.getParentFieldValues().getFieldValuesList()).hasSize(fieldsValues.length);
int index = 0;

+ 29
- 25
sonar-ws/src/main/protobuf/ws-settings.proto View File

@@ -16,7 +16,7 @@
// along with this program; if not, write to the Free Software Foundation,
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

syntax = "proto2";
syntax = "proto3";

package sonarqube.ws.settings;

@@ -31,38 +31,38 @@ message ListDefinitionsWsResponse {

// Response of GET api/settings/encrypt
message EncryptWsResponse {
optional string encryptedValue = 1;
string encryptedValue = 1;
}

// Response of GET api/settings/generate_secret_key
message GenerateSecretKeyWsResponse {
optional string secretKey = 1;
string secretKey = 1;
}

// Response of GET api/settings/check_secret_key
message CheckSecretKeyWsResponse {
optional bool secretKeyAvailable = 1;
bool secretKeyAvailable = 1;
}

message Definition {
optional string key = 1;
optional string name = 2;
optional string description = 3;
optional Type type = 4;
optional string category = 5;
optional string subCategory = 6;
optional string defaultValue = 7;
optional bool multiValues = 8;
string key = 1;
oneof nameOneOf {string name = 2;}
string description = 3;
Type type = 4;
oneof categoryOneOf {string category = 5;}
oneof subCategoryOneOf {string subCategory = 6;}
oneof defaultValueOneOf {string defaultValue = 7;}
bool multiValues = 8;
repeated string options = 9;
repeated Field fields = 10;
optional string deprecatedKey = 11;
oneof deprecatedKeyOneOf {string deprecatedKey = 11;}
}

message Field {
optional string key = 1;
optional string name = 2;
optional string description = 3;
optional Type type = 4;
string key = 1;
string name = 2;
string description = 3;
Type type = 4;
repeated string options = 5;
}

@@ -89,14 +89,18 @@ message ValuesWsResponse {
}

message Setting {
optional string key = 1;
optional string value = 2;
optional Values values = 3;
optional FieldValues fieldValues = 4;
optional bool inherited = 5;
optional string parentValue = 6;
optional Values parentValues = 7;
optional FieldValues parentFieldValues = 8;
string key = 1;
oneof valueOneOf {
string value = 2;
Values values = 3;
FieldValues fieldValues = 4;
}
bool inherited = 5;
oneof parentValueOneOf {
string parentValue = 6;
Values parentValues = 7;
FieldValues parentFieldValues = 8;
}
}

message Values {

Loading…
Cancel
Save