diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2016-08-30 15:50:56 +0200 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2016-09-01 15:05:22 +0200 |
commit | a9dcddb21deaa014255d8bff601515bbdbdf20ff (patch) | |
tree | 4e66ddcf76bfec436de037c3a0c2ed1fd3d83fac /sonar-ws | |
parent | 53d54475d4edde73635a1871e067b4cabf6f60ea (diff) | |
download | sonarqube-a9dcddb21deaa014255d8bff601515bbdbdf20ff.tar.gz sonarqube-a9dcddb21deaa014255d8bff601515bbdbdf20ff.zip |
SONAR-8039 Create /api/licenses/list to return licenses with metadata
Diffstat (limited to 'sonar-ws')
4 files changed, 173 insertions, 0 deletions
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/license/LicensesService.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/license/LicensesService.java new file mode 100644 index 00000000000..93fb452ac0d --- /dev/null +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/license/LicensesService.java @@ -0,0 +1,41 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonarqube.ws.client.license; + +import org.sonarqube.ws.Licenses.ListWsResponse; +import org.sonarqube.ws.client.BaseService; +import org.sonarqube.ws.client.GetRequest; +import org.sonarqube.ws.client.WsConnector; + +import static org.sonarqube.ws.client.license.LicensesWsParameters.ACTION_LIST; +import static org.sonarqube.ws.client.license.LicensesWsParameters.CONTROLLER_SETTINGS; + +public class LicensesService extends BaseService { + + public LicensesService(WsConnector wsConnector) { + super(wsConnector, CONTROLLER_SETTINGS); + } + + public ListWsResponse list() { + GetRequest getRequest = new GetRequest(path(ACTION_LIST)); + return call(getRequest, ListWsResponse.parser()); + } + +} diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/license/LicensesWsParameters.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/license/LicensesWsParameters.java new file mode 100644 index 00000000000..a035f684519 --- /dev/null +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/license/LicensesWsParameters.java @@ -0,0 +1,32 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +package org.sonarqube.ws.client.license; + +public class LicensesWsParameters { + public static final String CONTROLLER_SETTINGS = "api/licenses"; + + public static final String ACTION_LIST = "list"; + + private LicensesWsParameters() { + // Only static stuff + } + +} diff --git a/sonar-ws/src/main/protobuf/ws-licenses.proto b/sonar-ws/src/main/protobuf/ws-licenses.proto new file mode 100644 index 00000000000..77f1002ffba --- /dev/null +++ b/sonar-ws/src/main/protobuf/ws-licenses.proto @@ -0,0 +1,51 @@ +// SonarQube, open source software quality management tool. +// Copyright (C) 2008-2015 SonarSource +// mailto:contact AT sonarsource DOT com +// +// SonarQube is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// SonarQube is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// 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"; + +package sonarqube.ws.licenses; + +option java_package = "org.sonarqube.ws"; +option java_outer_classname = "Licenses"; +option optimize_for = SPEED; + +// Response of GET api/licenses/list +message ListWsResponse { + repeated License licenses = 1; +} + +message License { + optional string key = 1; + optional string value = 2; + optional string product = 3; + optional string organization = 4; + optional string expiration = 5; + optional string serverId = 6; + optional string type = 7; + optional AdditionalProperties additionalProperties = 8; + optional bool invalidProduct = 9; + optional bool invalidExpiration = 10; + optional bool invalidServerId = 11; +} + +message AdditionalProperties { + map<string, string> additionalProperties = 1; +} + + + diff --git a/sonar-ws/src/test/java/org/sonarqube/ws/client/license/LicensesServiceTest.java b/sonar-ws/src/test/java/org/sonarqube/ws/client/license/LicensesServiceTest.java new file mode 100644 index 00000000000..8b305df0514 --- /dev/null +++ b/sonar-ws/src/test/java/org/sonarqube/ws/client/license/LicensesServiceTest.java @@ -0,0 +1,49 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +package org.sonarqube.ws.client.license; + +import org.junit.Rule; +import org.junit.Test; +import org.sonarqube.ws.Licenses.ListWsResponse; +import org.sonarqube.ws.client.GetRequest; +import org.sonarqube.ws.client.ServiceTester; +import org.sonarqube.ws.client.WsConnector; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; + +public class LicensesServiceTest { + + @Rule + public ServiceTester<LicensesService> serviceTester = new ServiceTester<>(new LicensesService(mock(WsConnector.class))); + + private LicensesService underTest = serviceTester.getInstanceUnderTest(); + + @Test + public void list_definitions() { + underTest.list(); + GetRequest getRequest = serviceTester.getGetRequest(); + + assertThat(serviceTester.getGetParser()).isSameAs(ListWsResponse.parser()); + serviceTester.assertThat(getRequest).andNoOtherParam(); + } + +} |