Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SONAR-10345 Add Webhooks creation ws
- Loading branch information
Showing
13 changed files
with
525 additions
and
18 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
server/sonar-db-dao/src/main/java/org/sonar/db/webhook/WebhookTesting.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,49 @@ | ||
/* | ||
* SonarQube | ||
* Copyright (C) 2009-2018 SonarSource SA | ||
* mailto:info 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.sonar.db.webhook; | ||
|
||
import java.util.Calendar; | ||
|
||
import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric; | ||
|
||
public class WebhookTesting { | ||
|
||
private WebhookTesting() { | ||
// only statics | ||
} | ||
|
||
public static WebhookDto newWebhookDtoForProject(String projectUuid) { | ||
return getWebhookDto() | ||
.setProjectUuid(projectUuid); | ||
} | ||
|
||
public static WebhookDto newWebhookDtoForOrganization(String organizationUuid) { | ||
return getWebhookDto() | ||
.setOrganizationUuid(organizationUuid); | ||
} | ||
|
||
private static WebhookDto getWebhookDto() { | ||
return new WebhookDto() | ||
.setUuid(randomAlphanumeric(40)) | ||
.setName(randomAlphanumeric(64)) | ||
.setUrl("https://www.random-site/" + randomAlphanumeric(256)) | ||
.setCreatedAt(Calendar.getInstance().getTimeInMillis()); | ||
} | ||
} |
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
48 changes: 48 additions & 0 deletions
48
server/sonar-db-dao/src/test/java/org/sonar/db/webhook/WebhookDbTester.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,48 @@ | ||
/* | ||
* SonarQube | ||
* Copyright (C) 2009-2018 SonarSource SA | ||
* mailto:info 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.sonar.db.webhook; | ||
|
||
import org.sonar.db.DbSession; | ||
import org.sonar.db.DbTester; | ||
|
||
public class WebhookDbTester { | ||
|
||
private final DbTester dbTester; | ||
|
||
public WebhookDbTester(DbTester dbTester) { | ||
this.dbTester = dbTester; | ||
} | ||
|
||
public WebhookDto insertForOrganizationUuid(String organizationUuid) { | ||
return insert(WebhookTesting.newWebhookDtoForOrganization(organizationUuid)); | ||
} | ||
|
||
public WebhookDto insertWebhookForProjectUuid(String projectUuid) { | ||
return insert(WebhookTesting.newWebhookDtoForProject(projectUuid)); | ||
} | ||
|
||
public WebhookDto insert(WebhookDto dto) { | ||
DbSession dbSession = dbTester.getSession(); | ||
dbTester.getDbClient().webhookDao().insert(dbSession, dto); | ||
dbSession.commit(); | ||
return dto; | ||
} | ||
|
||
} |
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
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
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
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
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
7 changes: 7 additions & 0 deletions
7
...r/sonar-server/src/main/resources/org/sonar/server/webhook/ws/example-webhook-create.json
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,7 @@ | ||
{ | ||
"webhook": { | ||
"key": "uuid", | ||
"name": "my-webhook", | ||
"url": "https://www.my-webhook-listener.com/sonar" | ||
} | ||
} |
Oops, something went wrong.