package org.sonar.server.issue;
+import com.google.common.base.Strings;
import org.sonar.api.ServerComponent;
import org.sonar.api.issue.Issue;
import org.sonar.api.issue.internal.DefaultIssue;
@Override
public boolean verify(Map<String, Object> properties, List<Issue> issues, UserSession userSession) {
- return true;
+ return comment(properties) != null;
}
@Override
}
private String comment(Map<String, Object> properties) {
- return (String) properties.get(COMMENT_PROPERTY);
+ String param = (String) properties.get(COMMENT_PROPERTY);
+ if (Strings.isNullOrEmpty(param)) {
+ throw new IllegalArgumentException("Missing parameter : '"+ COMMENT_PROPERTY +"'");
+ }
+ return param;
}
}
\ No newline at end of file
package org.sonar.server.issue;
+import com.google.common.base.Strings;
import org.sonar.api.ServerComponent;
import org.sonar.api.issue.Issue;
import org.sonar.api.issue.condition.IsUnResolved;
@Override
public boolean verify(Map<String, Object> properties, List<Issue> issues, UserSession userSession) {
- return true;
+ return severity(properties) != null;
}
@Override
}
private String severity(Map<String, Object> properties) {
- return (String) properties.get("severity");
+ String param = (String) properties.get("severity");
+ if (Strings.isNullOrEmpty(param)) {
+ throw new IllegalArgumentException("Missing parameter : 'severity'");
+ }
+ return param;
}
}
\ No newline at end of file
package org.sonar.server.issue;
+import com.google.common.base.Strings;
import org.sonar.api.ServerComponent;
import org.sonar.api.issue.Issue;
import org.sonar.api.issue.internal.DefaultIssue;
@Override
public boolean verify(Map<String, Object> properties, List<Issue> issues, UserSession userSession) {
- return true;
+ return transition(properties) != null;
}
@Override
}
private String transition(Map<String, Object> properties) {
- return (String) properties.get("transition");
+ String param = (String) properties.get("transition");
+ if (Strings.isNullOrEmpty(param)) {
+ throw new IllegalArgumentException("Missing parameter : 'transition'");
+ }
+ return param;
}
}
\ No newline at end of file
<%= message('issue.transition') -%>
</label>
<% transitions_by_issues.keys.each do |transition| %>
- <input type="radio" name="transition.transition" value="<%= transition -%>"
+ <input type="radio" name="do_transition.transition" value="<%= transition -%>"
onClick="addTransitionAction();"> <%= message("issue.transition.#{transition}") -%>
<span style="float:right;">(<%= message('issue_bulk_change.x_issues', :params => transitions_by_issues[transition].to_s) %>)</span><br/>
<% end %>
package org.sonar.server.issue;
+import com.google.common.collect.Lists;
import org.junit.Before;
import org.junit.Test;
import org.sonar.api.issue.Issue;
import org.sonar.api.issue.internal.DefaultIssue;
import org.sonar.api.issue.internal.IssueChangeContext;
import org.sonar.core.issue.IssueUpdater;
+import org.sonar.server.user.MockUserSession;
import java.util.Map;
import static com.google.common.collect.Maps.newHashMap;
import static org.fest.assertions.Assertions.assertThat;
+import static org.fest.assertions.Fail.fail;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.*;
verify(issueUpdater).addComment(eq(issue), eq(comment), any(IssueChangeContext.class));
}
+ @Test
+ public void should_verify_fail_if_parameter_not_found() {
+ Map<String, Object> properties = newHashMap();
+ properties.put("unknwown", "unknown value");
+ try {
+ action.verify(properties, Lists.<Issue>newArrayList(), MockUserSession.create());
+ fail();
+ } catch (Exception e) {
+ assertThat(e).isInstanceOf(IllegalArgumentException.class).hasMessage("Missing parameter : 'comment'");
+ }
+ verifyZeroInteractions(issueUpdater);
+ }
+
@Test
public void should_support_all_issues(){
assertThat(action.supports(new DefaultIssue().setResolution(null))).isTrue();
package org.sonar.server.issue;
+import com.google.common.collect.Lists;
import org.junit.Before;
import org.junit.Test;
import org.sonar.api.issue.Issue;
import org.sonar.api.issue.internal.DefaultIssue;
import org.sonar.api.issue.internal.IssueChangeContext;
import org.sonar.core.issue.IssueUpdater;
+import org.sonar.server.user.MockUserSession;
import java.util.Map;
import static com.google.common.collect.Maps.newHashMap;
import static org.fest.assertions.Assertions.assertThat;
+import static org.fest.assertions.Fail.fail;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.*;
verify(issueUpdater).setManualSeverity(eq(issue), eq(severity), any(IssueChangeContext.class));
}
+ @Test
+ public void should_verify_fail_if_parameter_not_found() {
+ Map<String, Object> properties = newHashMap();
+ properties.put("unknwown", "unknown value");
+ try {
+ action.verify(properties, Lists.<Issue>newArrayList(), MockUserSession.create());
+ fail();
+ } catch (Exception e) {
+ assertThat(e).isInstanceOf(IllegalArgumentException.class).hasMessage("Missing parameter : 'severity'");
+ }
+ verifyZeroInteractions(issueUpdater);
+ }
+
@Test
public void should_support_only_unresolved_issues(){
assertThat(action.supports(new DefaultIssue().setResolution(null))).isTrue();
package org.sonar.server.issue;
+import com.google.common.collect.Lists;
import org.junit.Before;
import org.junit.Test;
import org.sonar.api.issue.Issue;
import org.sonar.api.issue.internal.DefaultIssue;
import org.sonar.api.issue.internal.IssueChangeContext;
import org.sonar.core.issue.workflow.IssueWorkflow;
+import org.sonar.server.user.MockUserSession;
import java.util.Map;
import static com.google.common.collect.Maps.newHashMap;
import static org.fest.assertions.Assertions.assertThat;
+import static org.fest.assertions.Fail.fail;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.*;
verify(workflow).doTransition(eq(issue), eq(transition), any(IssueChangeContext.class));
}
+ @Test
+ public void should_verify_fail_if_parameter_not_found() {
+ String transition = "reopen";
+ Map<String, Object> properties = newHashMap();
+ properties.put("unknwown", transition);
+ try {
+ action.verify(properties, Lists.<Issue>newArrayList(), MockUserSession.create());
+ fail();
+ } catch (Exception e) {
+ assertThat(e).isInstanceOf(IllegalArgumentException.class).hasMessage("Missing parameter : 'transition'");
+ }
+ verifyZeroInteractions(workflow);
+ }
+
@Test
public void should_support_all_issues() {
assertThat(action.supports(new DefaultIssue().setResolution(null))).isTrue();