diff options
author | Simon Brandhof <simon.brandhof@gmail.com> | 2013-05-27 22:01:34 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@gmail.com> | 2013-05-27 22:17:38 +0200 |
commit | 0ae60c2fce29179bc60b4c0f2c731b21d1516c4f (patch) | |
tree | 7ea16fc786e34ea200334fa74b06d7a646c3bdc6 /sonar-core | |
parent | 43c9839354d12e4a25642511c1adcbbc50813331 (diff) | |
download | sonarqube-0ae60c2fce29179bc60b4c0f2c731b21d1516c4f.tar.gz sonarqube-0ae60c2fce29179bc60b4c0f2c731b21d1516c4f.zip |
SONAR-3755 move and delete some classes related to issues
Diffstat (limited to 'sonar-core')
6 files changed, 0 insertions, 740 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/review/ReviewDto.java b/sonar-core/src/main/java/org/sonar/core/review/ReviewDto.java deleted file mode 100644 index 31472263aff..00000000000 --- a/sonar-core/src/main/java/org/sonar/core/review/ReviewDto.java +++ /dev/null @@ -1,255 +0,0 @@ -/* - * 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.core.review; - -import com.google.common.base.Preconditions; -import org.apache.commons.lang.builder.ToStringBuilder; -import org.apache.commons.lang.builder.ToStringStyle; - -import javax.annotation.Nullable; -import java.util.Date; - -/** - * @since 2.13 - */ -public final class ReviewDto { - - public static final String STATUS_OPEN = "OPEN"; - public static final String STATUS_REOPENED = "REOPENED"; - public static final String STATUS_RESOLVED = "RESOLVED"; - public static final String STATUS_CLOSED = "CLOSED"; - - public static final String RESOLUTION_FALSE_POSITIVE = "FALSE-POSITIVE"; - public static final String RESOLUTION_FIXED = "FIXED"; - - private Long id; - private Integer userId; - private Long assigneeId; - private String title; - private String status; - private String resolution; - private Integer violationPermanentId; - private Integer projectId; - private Integer resourceId; - private Integer line; - private Date createdAt; - private Date updatedAt; - private String severity; - private Integer ruleId; - private boolean manualViolation; - private boolean manualSeverity; - private Integer actionPlanId; - private String data; - - public Long getId() { - return id; - } - - public ReviewDto setId(Long id) { - this.id = id; - return this; - } - - public Integer getUserId() { - return userId; - } - - public ReviewDto setUserId(Integer userId) { - this.userId = userId; - return this; - } - - public Long getAssigneeId() { - return assigneeId; - } - - public ReviewDto setAssigneeId(@Nullable Long assigneeId) { - this.assigneeId = assigneeId; - return this; - } - - public String getTitle() { - return title; - } - - public ReviewDto setTitle(String title) { - this.title = title; - return this; - } - - public String getStatus() { - return status; - } - - public ReviewDto setStatus(@Nullable String status) { - this.status = status; - return this; - } - - public String getResolution() { - return resolution; - } - - public ReviewDto setResolution(@Nullable String resolution) { - this.resolution = resolution; - return this; - } - - public Integer getViolationPermanentId() { - return violationPermanentId; - } - - public ReviewDto setViolationPermanentId(Integer violationPermanentId) { - this.violationPermanentId = violationPermanentId; - return this; - } - - public Integer getProjectId() { - return projectId; - } - - public ReviewDto setProjectId(Integer projectId) { - this.projectId = projectId; - return this; - } - - public Integer getResourceId() { - return resourceId; - } - - public ReviewDto setResourceId(Integer resourceId) { - this.resourceId = resourceId; - return this; - } - - public Integer getLine() { - return line; - } - - public ReviewDto setLine(@Nullable Integer line) { - this.line = line; - return this; - } - - public Date getCreatedAt() { - return createdAt; - } - - public ReviewDto setCreatedAt(Date createdAt) { - this.createdAt = createdAt; - return this; - } - - public Date getUpdatedAt() { - return updatedAt; - } - - public ReviewDto setUpdatedAt(Date updatedAt) { - this.updatedAt = updatedAt; - return this; - } - - public String getSeverity() { - return severity; - } - - public ReviewDto setSeverity(@Nullable String severity) { - this.severity = severity; - return this; - } - - public Integer getRuleId() { - return ruleId; - } - - public ReviewDto setRuleId(Integer ruleId) { - this.ruleId = ruleId; - return this; - } - - public boolean getManualViolation() { - return manualViolation; - } - - public boolean isManualViolation() { - return manualViolation; - } - - public ReviewDto setManualViolation(boolean b) { - this.manualViolation = b; - return this; - } - - public boolean getManualSeverity() { - return manualSeverity; - } - - public ReviewDto setManualSeverity(boolean b) { - this.manualSeverity = b; - return this; - } - - public boolean isManualSeverity() { - return manualSeverity; - } - - public Integer getActionPlanId() { - return actionPlanId; - } - - public ReviewDto setActionPlanId(@Nullable Integer i) { - this.actionPlanId = i; - return this; - } - - public String getData() { - return data; - } - - public ReviewDto setData(String s) { - Preconditions.checkArgument(s == null || s.length() <= 4000, - "Review data must not exceed 4000 characters: " + s); - this.data = s; - return this; - } - - @Override - public String toString() { - return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE); - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - - ReviewDto reviewDto = (ReviewDto) o; - return !(id != null ? !id.equals(reviewDto.id) : reviewDto.id != null); - } - - @Override - public int hashCode() { - return id != null ? id.hashCode() : 0; - } -} diff --git a/sonar-core/src/main/java/org/sonar/core/workflow/ImmutableReview.java b/sonar-core/src/main/java/org/sonar/core/workflow/ImmutableReview.java deleted file mode 100644 index baa08226a6e..00000000000 --- a/sonar-core/src/main/java/org/sonar/core/workflow/ImmutableReview.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * 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.core.workflow; - -import com.google.common.collect.ImmutableMap; -import org.sonar.api.workflow.Review; -import org.sonar.api.workflow.internal.DefaultReview; - -import java.util.Map; - -public final class ImmutableReview implements Review { - private final Long violationId; - private final Long reviewId; - private final String ruleRepositoryKey; - private final String ruleKey; - private final String ruleName; - private final Long line; - private final boolean switchedOff; - private final boolean manual; - private final String message; - private final String status; - private final String resolution; - private final String severity; - private final Map<String, String> properties; - - /** - * Warning : implementation is still mutable. - */ - public ImmutableReview(DefaultReview review) { - this.line = review.getLine(); - this.manual = review.isManual(); - this.message = review.getMessage(); - this.properties = ImmutableMap.copyOf(review.getProperties()); - this.resolution = review.getResolution(); - this.reviewId = review.getReviewId(); - this.ruleKey = review.getRuleKey(); - this.ruleRepositoryKey = review.getRuleRepositoryKey(); - this.ruleName = review.getRuleName(); - this.severity = review.getSeverity(); - this.status = review.getStatus(); - this.switchedOff = review.isSwitchedOff(); - this.violationId = review.getViolationId(); - } - - public Long getViolationId() { - return violationId; - } - - public Long getReviewId() { - return reviewId; - } - - public String getRuleName() { - return ruleName; - } - - public String getRuleRepositoryKey() { - return ruleRepositoryKey; - } - - public String getRuleKey() { - return ruleKey; - } - - public Long getLine() { - return line; - } - - public boolean isSwitchedOff() { - return switchedOff; - } - - public boolean isManual() { - return manual; - } - - public String getMessage() { - return message; - } - - public String getStatus() { - return status; - } - - public String getResolution() { - return resolution; - } - - public String getSeverity() { - return severity; - } - - public Map<String, String> getProperties() { - return properties; - } -} diff --git a/sonar-core/src/main/java/org/sonar/core/workflow/ReviewStore.java b/sonar-core/src/main/java/org/sonar/core/workflow/ReviewStore.java deleted file mode 100644 index 500169553a0..00000000000 --- a/sonar-core/src/main/java/org/sonar/core/workflow/ReviewStore.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * 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.core.workflow; - -import org.sonar.api.config.Settings; -import org.sonar.api.workflow.internal.DefaultReview; -import java.util.List; - -public interface ReviewStore { - void store(DefaultReview review); - - void completeProjectSettings(Long projectId, Settings settings, List<String> propertyKeys); -} diff --git a/sonar-core/src/main/java/org/sonar/core/workflow/WorkflowEngine.java b/sonar-core/src/main/java/org/sonar/core/workflow/WorkflowEngine.java deleted file mode 100644 index 6560eb881cc..00000000000 --- a/sonar-core/src/main/java/org/sonar/core/workflow/WorkflowEngine.java +++ /dev/null @@ -1,141 +0,0 @@ -/* - * 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.core.workflow; - -import com.google.common.base.Preconditions; -import com.google.common.base.Strings; -import com.google.common.collect.ArrayListMultimap; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ListMultimap; -import com.google.common.collect.Lists; -import org.sonar.api.ServerComponent; -import org.sonar.api.config.Settings; -import org.sonar.api.workflow.Review; -import org.sonar.api.workflow.WorkflowContext; -import org.sonar.api.workflow.condition.Condition; -import org.sonar.api.workflow.function.Function; -import org.sonar.api.workflow.internal.DefaultReview; -import org.sonar.api.workflow.internal.DefaultWorkflow; -import org.sonar.api.workflow.internal.DefaultWorkflowContext; -import org.sonar.api.workflow.screen.Screen; - -import javax.annotation.Nullable; -import java.util.List; -import java.util.Map; - -public class WorkflowEngine implements ServerComponent { - - private final DefaultWorkflow workflow; - private final ReviewStore store; - private final Settings settings; - - public WorkflowEngine(DefaultWorkflow workflow, ReviewStore store, Settings settings) { - this.workflow = workflow; - this.store = store; - this.settings = settings; - } - - /** - * @return non-null list of screens per review#violationId - */ - public ListMultimap<Long, Screen> listAvailableScreens(DefaultReview[] reviews, DefaultWorkflowContext context, boolean verifyConditions) { - ListMultimap<Long, Screen> result = ArrayListMultimap.create(); - - completeProjectSettings(context); - - for (Map.Entry<String, Screen> entry : workflow.getScreensByCommand().entrySet()) { - String commandKey = entry.getKey(); - if (!verifyConditions || verifyConditionsQuietly(null, context, workflow.getContextConditions(commandKey))) { - for (DefaultReview review : reviews) { - if (!verifyConditions || verifyConditionsQuietly(review, context, workflow.getReviewConditions(commandKey))) { - result.put(review.getViolationId(), entry.getValue()); - } - } - } - } - return result; - } - - public List<Screen> listAvailableScreens(Review review, DefaultWorkflowContext context, boolean verifyConditions) { - List<Screen> result = Lists.newArrayList(); - completeProjectSettings(context); - for (Map.Entry<String, Screen> entry : workflow.getScreensByCommand().entrySet()) { - String commandKey = entry.getKey(); - if (!verifyConditions || verifyConditionsQuietly(review, context, workflow.getConditions(commandKey))) { - result.add(entry.getValue()); - - } - } - return result; - } - - /** - * @return the optional (nullable) screen associated to the command - */ - public Screen getScreen(String commandKey) { - return workflow.getScreen(commandKey); - } - - public void execute(String commandKey, DefaultReview review, DefaultWorkflowContext context, Map<String, String> parameters) { - Preconditions.checkArgument(!Strings.isNullOrEmpty(commandKey), "Missing command"); - Preconditions.checkArgument(workflow.hasCommand(commandKey), "Unknown command: " + commandKey); - - completeProjectSettings(context); - - verifyConditions(review, context, workflow.getConditions(commandKey)); - - Map<String, String> immutableParameters = ImmutableMap.copyOf(parameters); - - // TODO execute functions are change state before functions that consume state (like "create-jira-issue") - Review initialReview = new ImmutableReview(review); - for (Function function : workflow.getFunctions(commandKey)) { - function.doExecute(review, initialReview, context, immutableParameters); - } - - // should it be extracted to a core function ? - store.store(review); - - // TODO notify listeners - } - - private boolean verifyConditionsQuietly(@Nullable Review review, WorkflowContext context, List<Condition> conditions) { - for (Condition condition : conditions) { - if (!condition.doVerify(review, context)) { - return false; - } - } - return true; - } - - private void verifyConditions(@Nullable Review review, WorkflowContext context, List<Condition> conditions) { - for (Condition condition : conditions) { - if (!condition.doVerify(review, context)) { - throw new IllegalStateException("Condition is not respected: " + condition.toString()); - } - } - } - - private void completeProjectSettings(DefaultWorkflowContext context) { - Settings projectSettings = new Settings(settings); - List<String> propertyKeys = workflow.getProjectPropertyKeys(); - store.completeProjectSettings(context.getProjectId(), projectSettings, propertyKeys); - context.setSettings(projectSettings); - } -} diff --git a/sonar-core/src/main/java/org/sonar/core/workflow/package-info.java b/sonar-core/src/main/java/org/sonar/core/workflow/package-info.java deleted file mode 100644 index 0a0eb1d00d4..00000000000 --- a/sonar-core/src/main/java/org/sonar/core/workflow/package-info.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * 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. - */ -@ParametersAreNonnullByDefault -package org.sonar.core.workflow; - -import javax.annotation.ParametersAreNonnullByDefault;
\ No newline at end of file diff --git a/sonar-core/src/test/java/org/sonar/core/workflow/WorkflowEngineTest.java b/sonar-core/src/test/java/org/sonar/core/workflow/WorkflowEngineTest.java deleted file mode 100644 index c9f7f79bb2b..00000000000 --- a/sonar-core/src/test/java/org/sonar/core/workflow/WorkflowEngineTest.java +++ /dev/null @@ -1,178 +0,0 @@ -/* - * 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.core.workflow; - -import com.google.common.collect.ListMultimap; -import com.google.common.collect.Maps; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.sonar.api.config.Settings; -import org.sonar.api.workflow.internal.DefaultWorkflow; -import org.sonar.api.workflow.Review; -import org.sonar.api.workflow.WorkflowContext; -import org.sonar.api.workflow.condition.Condition; -import org.sonar.api.workflow.condition.HasProjectPropertyCondition; -import org.sonar.api.workflow.function.Function; -import org.sonar.api.workflow.internal.DefaultReview; -import org.sonar.api.workflow.internal.DefaultWorkflowContext; -import org.sonar.api.workflow.screen.CommentScreen; -import org.sonar.api.workflow.screen.Screen; -import org.sonar.core.workflow.ImmutableReview; -import org.sonar.core.workflow.ReviewStore; -import org.sonar.core.workflow.WorkflowEngine; - -import java.util.List; -import java.util.Map; - -import static org.fest.assertions.Assertions.assertThat; -import static org.junit.matchers.JUnitMatchers.hasItem; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.*; - -public class WorkflowEngineTest { - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - @Test - public void listAvailableScreensForReview_empty() { - WorkflowEngine engine = new WorkflowEngine(new DefaultWorkflow(), mock(ReviewStore.class), new Settings()); - List<Screen> screens = engine.listAvailableScreens(new DefaultReview(), new DefaultWorkflowContext(), true); - assertThat(screens).isEmpty(); - } - - @Test - public void listAvailableScreensForReview() { - DefaultWorkflow workflow = new DefaultWorkflow(); - workflow.addCommand("command-without-screen"); - workflow.addCommand("resolve"); - CommentScreen screen = new CommentScreen(); - workflow.setScreen("resolve", screen); - - WorkflowEngine engine = new WorkflowEngine(workflow, mock(ReviewStore.class), new Settings()); - List<Screen> screens = engine.listAvailableScreens(new DefaultReview(), new DefaultWorkflowContext(), true); - assertThat(screens).containsExactly(screen); - } - - @Test - public void listAvailableScreensForReview_verify_conditions() { - DefaultWorkflow workflow = new DefaultWorkflow(); - workflow.addCommand("resolve"); - Condition condition = mock(Condition.class); - when(condition.doVerify(any(Review.class), any(WorkflowContext.class))).thenReturn(false); - workflow.addCondition("resolve", condition); - workflow.setScreen("resolve", new CommentScreen()); - - WorkflowEngine engine = new WorkflowEngine(workflow, mock(ReviewStore.class), new Settings()); - DefaultReview review = new DefaultReview(); - DefaultWorkflowContext context = new DefaultWorkflowContext(); - assertThat(engine.listAvailableScreens(review, context, true)).isEmpty(); - - verify(condition).doVerify(review, context); - } - - @Test - public void listAvailableScreensForReviews_empty() { - WorkflowEngine engine = new WorkflowEngine(new DefaultWorkflow(), mock(ReviewStore.class), new Settings()); - ListMultimap<Long, Screen> screens = engine.listAvailableScreens( - new DefaultReview[]{new DefaultReview().setViolationId(1000L), new DefaultReview().setViolationId(2000L)}, - new DefaultWorkflowContext(), true); - assertThat(screens.size()).isEqualTo(0); - } - - @Test - public void listAvailableScreensForReviews() { - DefaultWorkflow workflow = new DefaultWorkflow(); - workflow.addCommand("command-without-screen"); - workflow.addCommand("resolve"); - CommentScreen screen = new CommentScreen(); - workflow.setScreen("resolve", screen); - WorkflowEngine engine = new WorkflowEngine(workflow, mock(ReviewStore.class), new Settings()); - ListMultimap<Long, Screen> screens = engine.listAvailableScreens( - new DefaultReview[]{new DefaultReview().setViolationId(1000L), new DefaultReview().setViolationId(2000L)}, - new DefaultWorkflowContext(), true); - assertThat(screens.size()).isEqualTo(2); - assertThat(screens.get(1000L)).containsExactly(screen); - assertThat(screens.get(2000L)).containsExactly(screen); - } - - @Test - public void listAvailableScreensForReviews_load_project_properties() { - DefaultWorkflow workflow = new DefaultWorkflow(); - workflow.addCommand("resolve"); - workflow.addCondition("resolve", new HasProjectPropertyCondition("foo")); - - ReviewStore store = mock(ReviewStore.class); - WorkflowEngine engine = new WorkflowEngine(workflow, store, new Settings()); - - engine.listAvailableScreens( - new DefaultReview[]{new DefaultReview().setViolationId(1000L), new DefaultReview().setViolationId(2000L)}, - new DefaultWorkflowContext().setProjectId(300L), - true); - - verify(store).completeProjectSettings(eq(300L), any(Settings.class), (List<String>) argThat(hasItem("foo"))); - } - - @Test - public void execute_conditions_pass() { - DefaultWorkflow workflow = new DefaultWorkflow(); - workflow.addCommand("resolve"); - workflow.addCondition("resolve", new HasProjectPropertyCondition("foo")); - Function function = mock(Function.class); - workflow.addFunction("resolve", function); - - ReviewStore store = mock(ReviewStore.class); - Settings settings = new Settings(); - settings.setProperty("foo", "bar"); - WorkflowEngine engine = new WorkflowEngine(workflow, store, settings); - - DefaultReview review = new DefaultReview().setViolationId(1000L); - Map<String, String> parameters = Maps.newHashMap(); - DefaultWorkflowContext context = new DefaultWorkflowContext().setProjectId(300L); - - engine.execute("resolve", review, context, parameters); - - verify(store).completeProjectSettings(eq(300L), any(Settings.class), (List<String>) argThat(hasItem("foo"))); - verify(function).doExecute(eq(review), any(ImmutableReview.class), eq(context), eq(parameters)); - } - - @Test - public void execute_fail_if_conditions_dont_pass() { - thrown.expect(IllegalStateException.class); - thrown.expectMessage("Condition is not respected: Property foo must be set"); - - DefaultWorkflow workflow = new DefaultWorkflow(); - workflow.addCommand("resolve"); - workflow.addCondition("resolve", new HasProjectPropertyCondition("foo")); - Function function = mock(Function.class); - workflow.addFunction("resolve", function); - - ReviewStore store = mock(ReviewStore.class); - Settings settings = new Settings();// missing property 'foo' - WorkflowEngine engine = new WorkflowEngine(workflow, store, settings); - - DefaultReview review = new DefaultReview().setViolationId(1000L); - Map<String, String> parameters = Maps.newHashMap(); - DefaultWorkflowContext context = new DefaultWorkflowContext().setProjectId(300L); - - engine.execute("resolve", review, context, parameters); - } -} |