import org.sonar.api.issue.Issue;
-import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
-import java.util.Map;
-
/**
* @since 3.6
*/
interface Context {
Issue issue();
- @CheckForNull
- Map<String, String> parameters();
-
Context setAttribute(String key, @Nullable String value);
Context addComment(@Nullable String text);
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 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.
+ */
+package org.sonar.api.issue.condition;
+
+import com.google.common.annotations.Beta;
+import com.google.common.base.Preconditions;
+import com.google.common.base.Strings;
+import org.sonar.api.issue.Issue;
+
+/**
+ * @since 3.1
+ */
+@Beta
+public final class HasIssuePropertyCondition implements Condition {
+
+ private final String propertyKey;
+
+ public HasIssuePropertyCondition(String propertyKey) {
+ Preconditions.checkArgument(!Strings.isNullOrEmpty(propertyKey));
+ this.propertyKey = propertyKey;
+ }
+
+ public String getPropertyKey() {
+ return propertyKey;
+ }
+
+ @Override
+ public boolean matches(Issue issue) {
+ return !Strings.isNullOrEmpty(issue.attributes().get(propertyKey));
+ }
+}
@Override
public void execute(Context context) {
- context.addComment(context.parameters().get("text"));
+ context.addComment("New comment!");
}
}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 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.
+ */
+package org.sonar.api.issue.condition;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.sonar.api.issue.internal.DefaultIssue;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class HasIssuePropertyConditionTest {
+
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ DefaultIssue issue = new DefaultIssue();
+
+ @Test
+ public void should_match() {
+ HasIssuePropertyCondition condition = new HasIssuePropertyCondition("foo");
+
+ assertThat(condition.matches(issue)).isFalse();
+ assertThat(condition.matches(issue.setAttribute("foo", ""))).isFalse();
+ assertThat(condition.matches(issue.setAttribute("foo", "bar"))).isTrue();
+ }
+
+ @Test
+ public void should_get_property_key() {
+ HasIssuePropertyCondition condition = new HasIssuePropertyCondition("foo");
+ assertThat(condition.getPropertyKey()).isEqualTo("foo");
+ }
+
+ @Test
+ public void shoul_fail_if_null_property() {
+ thrown.expect(IllegalArgumentException.class);
+ new HasIssuePropertyCondition(null);
+ }
+
+ @Test
+ public void should_fail_if_empty_property() {
+ thrown.expect(IllegalArgumentException.class);
+ new HasIssuePropertyCondition("");
+ }
+
+}
import org.sonar.server.user.UserSession;
import javax.annotation.Nullable;
-
import java.util.Date;
import java.util.List;
-import java.util.Map;
import static com.google.common.collect.Lists.newArrayList;
}));
}
- public Issue execute(String issueKey, String actionKey, UserSession userSession, Map<String, String> parameters) {
+ public Issue execute(String issueKey, String actionKey, UserSession userSession) {
Preconditions.checkArgument(!Strings.isNullOrEmpty(actionKey), "Missing action");
IssueQueryResult queryResult = loadIssue(issueKey);
}
IssueChangeContext changeContext = IssueChangeContext.createUser(new Date(), userSession.login());
- FunctionContext functionContext = new FunctionContext(updater, issue, parameters, changeContext);
+ FunctionContext functionContext = new FunctionContext(updater, issue, changeContext);
for (Function function : action.functions()) {
function.execute(functionContext);
}
static class FunctionContext implements Function.Context {
private final DefaultIssue issue;
- private final Map<String, String> parameters;
private final IssueUpdater updater;
private final IssueChangeContext changeContext;
- FunctionContext(IssueUpdater updater, DefaultIssue issue, Map<String, String> parameters, IssueChangeContext changeContext) {
+ FunctionContext(IssueUpdater updater, DefaultIssue issue, IssueChangeContext changeContext) {
this.updater = updater;
this.issue = issue;
- this.parameters = parameters;
this.changeContext = changeContext;
}
return issue;
}
- @Override
- public Map<String, String> parameters() {
- return parameters;
- }
-
@Override
public Function.Context setAttribute(String key, @Nullable String value) {
updater.setAttribute(issue, key, value, changeContext);
import org.sonar.server.util.RubyUtils;
import javax.annotation.Nullable;
-
import java.util.Collection;
import java.util.Date;
import java.util.List;
return result;
}
- public Issue executeAction(String issueKey, String actionKey, Map<String, String> parameters) {
- return actionService.execute(issueKey, actionKey, UserSession.get(), parameters);
+ public Issue executeAction(String issueKey, String actionKey) {
+ return actionService.execute(issueKey, actionKey, UserSession.get());
}
public List<Action> listActions(String issueKey){
verify_post_request
require_parameters :issue, :actionKey
- issue = Internal.issues.executeAction(params[:issue], params[:actionKey], params)
+ issue = Internal.issues.executeAction(params[:issue], params[:actionKey])
if issue
render :json => jsonp({
:issue => Issue.to_hash(issue)
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 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.
+ */
+
+package org.sonar.server.issue;
+
+import org.junit.Before;
+import org.sonar.core.issue.IssueUpdater;
+import org.sonar.core.issue.db.IssueStorage;
+
+import static org.mockito.Mockito.mock;
+
+public class ActionServiceTest {
+
+ private ActionService actionService;
+
+ private DefaultIssueFinder finder = mock(DefaultIssueFinder.class);
+ private IssueStorage issueStorage = mock(IssueStorage.class);
+ private IssueUpdater updater = mock(IssueUpdater.class);
+ private DefaultActions actions = mock(DefaultActions.class);
+
+ @Before
+ public void before(){
+
+ }
+}