aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2012-07-11 20:29:18 +0200
committerSimon Brandhof <simon.brandhof@gmail.com>2012-07-11 20:29:35 +0200
commit3869be4f9026d8b677a98041d7591586e35b2942 (patch)
treec07539ed52b22af0592caeeacdc37b1f38f03b76 /sonar-plugin-api
parentaceadd9dd9a7b835ce67c505013f090f06ebe642 (diff)
downloadsonarqube-3869be4f9026d8b677a98041d7591586e35b2942.tar.gz
sonarqube-3869be4f9026d8b677a98041d7591586e35b2942.zip
SONAR-3646 API : new extension point to be notified on user creation
Diffstat (limited to 'sonar-plugin-api')
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/platform/NewUserHandler.java91
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/platform/NewUserHandlerTest.java48
2 files changed, 139 insertions, 0 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/platform/NewUserHandler.java b/sonar-plugin-api/src/main/java/org/sonar/api/platform/NewUserHandler.java
new file mode 100644
index 00000000000..833c68d7dea
--- /dev/null
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/platform/NewUserHandler.java
@@ -0,0 +1,91 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.api.platform;
+
+import com.google.common.base.Preconditions;
+import org.sonar.api.ServerExtension;
+
+import javax.annotation.Nullable;
+
+/**
+ * @since 3.2
+ */
+public interface NewUserHandler extends ServerExtension {
+
+ public static final class Context {
+ private String login;
+ private String name;
+ private String email;
+
+ private Context(String login, String name, @Nullable String email) {
+ Preconditions.checkNotNull(login);
+ Preconditions.checkNotNull(name);
+ this.login = login;
+ this.name = name;
+ this.email = email;
+ }
+
+ public String getLogin() {
+ return login;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getEmail() {
+ return email;
+ }
+
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ public static final class Builder {
+ private String login;
+ private String name;
+ private String email;
+
+ private Builder() {
+ }
+
+ public Builder setLogin(String s) {
+ this.login = s;
+ return this;
+ }
+
+ public Builder setName(String s) {
+ this.name = s;
+ return this;
+ }
+
+ public Builder setEmail(@Nullable String s) {
+ this.email = s;
+ return this;
+ }
+
+ public Context build() {
+ return new Context(login, name, email);
+ }
+ }
+ }
+
+ void doOnNewUser(Context context);
+}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/platform/NewUserHandlerTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/platform/NewUserHandlerTest.java
new file mode 100644
index 00000000000..e5cc3a477a7
--- /dev/null
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/platform/NewUserHandlerTest.java
@@ -0,0 +1,48 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.api.platform;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class NewUserHandlerTest {
+
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ @Test
+ public void build_context() {
+ NewUserHandler.Context context = NewUserHandler.Context.builder().setLogin("marius").setName("Marius").setEmail("marius@lesbronzes.fr").build();
+
+ assertThat(context.getLogin()).isEqualTo("marius");
+ assertThat(context.getName()).isEqualTo("Marius");
+ assertThat(context.getEmail()).isEqualTo("marius@lesbronzes.fr");
+ }
+
+ @Test
+ public void login_is_mandatory() {
+ thrown.expect(NullPointerException.class);
+
+ NewUserHandler.Context.builder().setName("Marius").build();
+ }
+}