-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SONAR-8100 add IT for organizations Web Services
- Loading branch information
Showing
2 changed files
with
151 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
147 changes: 147 additions & 0 deletions
147
it/it-tests/src/test/java/it/organization/OrganizationIt.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
/* | ||
* 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 it.organization; | ||
|
||
import com.sonar.orchestrator.Orchestrator; | ||
import it.Category3Suite; | ||
import java.util.List; | ||
import org.junit.ClassRule; | ||
import org.junit.Test; | ||
import org.sonarqube.ws.Organizations; | ||
import org.sonarqube.ws.client.organization.CreateWsRequest; | ||
import org.sonarqube.ws.client.organization.OrganizationService; | ||
import org.sonarqube.ws.client.organization.SearchWsRequest; | ||
import org.sonarqube.ws.client.organization.UpdateWsRequest; | ||
import util.ItUtils; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class OrganizationIt { | ||
private static final String NAME = "Foo Company"; | ||
private static final String KEY = "foo-company"; | ||
private static final String DESCRIPTION = "the description of Foo company"; | ||
private static final String URL = "https://www.foo.fr"; | ||
private static final String AVATAR_URL = "https://www.foo.fr/corporate_logo.png"; | ||
|
||
@ClassRule | ||
public static Orchestrator orchestrator = Category3Suite.ORCHESTRATOR; | ||
|
||
private OrganizationService anonymousOrganizationService = ItUtils.newWsClient(orchestrator).organizations(); | ||
private OrganizationService adminOrganizationService = ItUtils.newAdminWsClient(orchestrator).organizations(); | ||
|
||
@Test | ||
public void create_update_delete_an_organization() {; | ||
verifyNoSearchResult(); | ||
|
||
Organizations.Organization createdOrganization = adminOrganizationService.create(new CreateWsRequest.Builder() | ||
.setName(NAME) | ||
.setKey(KEY) | ||
.setDescription(DESCRIPTION) | ||
.setUrl(URL) | ||
.setAvatar(AVATAR_URL) | ||
.build()) | ||
.getOrganization(); | ||
assertThat(createdOrganization.getId()).isNotNull(); | ||
assertThat(createdOrganization.getName()).isEqualTo(NAME); | ||
assertThat(createdOrganization.getKey()).isEqualTo(KEY); | ||
assertThat(createdOrganization.getDescription()).isEqualTo(DESCRIPTION); | ||
assertThat(createdOrganization.getUrl()).isEqualTo(URL); | ||
assertThat(createdOrganization.getAvatar()).isEqualTo(AVATAR_URL); | ||
|
||
verifySingleSearchResult(createdOrganization, NAME, DESCRIPTION, URL, AVATAR_URL); | ||
|
||
// update by id | ||
adminOrganizationService.update(new UpdateWsRequest.Builder() | ||
.setId(createdOrganization.getId()) | ||
.setName("new name") | ||
.setDescription("new description") | ||
.setUrl("new url") | ||
.setAvatar("new avatar url") | ||
.build()); | ||
verifySingleSearchResult(createdOrganization, "new name", "new description", "new url", "new avatar url"); | ||
|
||
// update by key | ||
adminOrganizationService.update(new UpdateWsRequest.Builder() | ||
.setId(createdOrganization.getId()) | ||
.setName("new name 2") | ||
.setDescription("new description 2") | ||
.setUrl("new url 2") | ||
.setAvatar("new avatar url 2") | ||
.build()); | ||
verifySingleSearchResult(createdOrganization, "new name 2", "new description 2", "new url 2", "new avatar url 2"); | ||
|
||
// remove optional fields | ||
adminOrganizationService.update(new UpdateWsRequest.Builder() | ||
.setId(createdOrganization.getId()) | ||
.setName("new name 3") | ||
.build()); | ||
verifySingleSearchResult(createdOrganization, "new name 3", null, null, null); | ||
|
||
// delete by uuid | ||
adminOrganizationService.delete(createdOrganization.getId(), null); | ||
verifyNoSearchResult(); | ||
} | ||
|
||
@Test | ||
public void create_generates_key_from_name() { | ||
// create organization without key | ||
String name = "Foo Company to keyize"; | ||
Organizations.Organization createdOrganization = adminOrganizationService.create(new CreateWsRequest.Builder() | ||
.setName(name) | ||
.build()) | ||
.getOrganization(); | ||
assertThat(createdOrganization.getKey()).isEqualTo("foo-company-to-keyize"); | ||
verifySingleSearchResult(createdOrganization, name, null, null, null); | ||
|
||
// delete by key | ||
adminOrganizationService.delete(null, createdOrganization.getKey()); | ||
verifyNoSearchResult(); | ||
} | ||
|
||
private void verifyNoSearchResult() { | ||
Organizations.SearchWsResponse searchWsResponse = anonymousOrganizationService.search(new SearchWsRequest.Builder().build()); | ||
assertThat(searchWsResponse.getOrganizationsList()).isEmpty(); | ||
} | ||
|
||
private void verifySingleSearchResult(Organizations.Organization createdOrganization, String name, String description, String url, | ||
String avatarUrl) { | ||
List<Organizations.Organization> organizations = anonymousOrganizationService.search(new SearchWsRequest.Builder().build()).getOrganizationsList(); | ||
assertThat(organizations).hasSize(1); | ||
Organizations.Organization searchedOrganization = organizations.get(0); | ||
assertThat(searchedOrganization.getId()).isEqualTo(createdOrganization.getId()); | ||
assertThat(searchedOrganization.getKey()).isEqualTo(createdOrganization.getKey()); | ||
assertThat(searchedOrganization.getName()).isEqualTo(name); | ||
if (description == null) { | ||
assertThat(searchedOrganization.hasDescription()).isFalse(); | ||
} else { | ||
assertThat(searchedOrganization.getDescription()).isEqualTo(description); | ||
} | ||
if (url == null) { | ||
assertThat(searchedOrganization.hasUrl()).isFalse(); | ||
} else { | ||
assertThat(searchedOrganization.getUrl()).isEqualTo(url); | ||
} | ||
if (avatarUrl == null) { | ||
assertThat(searchedOrganization.hasAvatar()).isFalse(); | ||
} else { | ||
assertThat(searchedOrganization.getAvatar()).isEqualTo(avatarUrl); | ||
} | ||
} | ||
} |