Skip to content

Commit

Permalink
Merge pull request #74 from The-Huginn/issue-67
Browse files Browse the repository at this point in the history
Require only partial intersection between components
  • Loading branch information
xstefank authored Mar 7, 2024
2 parents ef553a8 + 39e986c commit f641ffd
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/main/java/org/jboss/set/draw/entities/Participant.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import io.smallrye.mutiny.tuples.Tuple2;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
Expand Down Expand Up @@ -53,8 +54,9 @@ private Tuple2<Integer, Set<String>> getProjectComponents(String project) {

public boolean isAssignable(Issue issue) {
Tuple2<Integer, Set<String>> issuesComponentsKey = getProjectComponents(issue.getProject());
List<String> components = issue.getComponents();
boolean betweenComponents = issuesComponentsKey.getItem2() == null ||
issuesComponentsKey.getItem2().containsAll(issue.getComponents());
!issuesComponentsKey.getItem2().stream().filter(components::contains).toList().isEmpty();
boolean canAssignIssue = assignableIssues == null || assignableIssues > 0;
return issuesComponentsKey.getItem1() != 0 && betweenComponents && canAssignIssue;
}
Expand Down
86 changes: 85 additions & 1 deletion src/test/java/org/jboss/set/draw/LotteryDrawingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ protected List<com.atlassian.jira.rest.client.api.domain.Issue> setupIssues() {
new IssueWrapper("Issue", 1L, "WFLY", IssueStatus.NEW, Set.of("Documentation")),
new IssueWrapper("Issue", 2L, "RESTEASY", IssueStatus.NEW, Set.of("Logging")),
new IssueWrapper("Issue", 3L, "WELD", IssueStatus.NEW, Set.of("Logging")),
new IssueWrapper("Issue", 4L, "WELD", IssueStatus.NEW, Set.of("Logging")));
new IssueWrapper("Issue", 4L, "WELD", IssueStatus.NEW, Set.of("Logging", "Documentation")));
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
Expand Down Expand Up @@ -281,4 +281,88 @@ public void testAssigningMaximumIssues() throws Exception {
assertEquals(1, sent.size());
assertEquals(Lottery.createEmailText(email, List.of(ourIssues.get(2))), sent.get(0).getText());
}

@Test
public void testAssigningPartialComponentsHitFromConfig() throws Exception {
String email = "[email protected]";
String configFile = """
delay: P14D
participants:
- email: %s
maxIssues: 5
projects:
- project: WELD
components: [Logging]
maxIssues: 2""".formatted(email);

LotteryConfig testLotteryConfig = objectMapper.readValue(configFile, LotteryConfig.class);
when(lotteryConfigProducer.getLotteryConfig()).thenReturn(testLotteryConfig);

StringWriter sw = new StringWriter();
CommandLine cmd = new CommandLine(app);
cmd.setOut(new PrintWriter(sw));

int exitCode = cmd.execute();
assertEquals(0, exitCode);

List<Mail> sent = mailbox.getMailsSentTo(email);
assertEquals(1, sent.size());
assertEquals(Lottery.createEmailText(email, List.of(ourIssues.get(2), ourIssues.get(3))), sent.get(0).getText());
}

@Test
public void testAssigningPartialComponentsHitFromIssue() throws Exception {
String email = "[email protected]";
String configFile = """
delay: P14D
participants:
- email: %s
maxIssues: 5
projects:
- project: WELD
components: [Logging, Documentation]
maxIssues: 2""".formatted(email);

LotteryConfig testLotteryConfig = objectMapper.readValue(configFile, LotteryConfig.class);
when(lotteryConfigProducer.getLotteryConfig()).thenReturn(testLotteryConfig);

StringWriter sw = new StringWriter();
CommandLine cmd = new CommandLine(app);
cmd.setOut(new PrintWriter(sw));

int exitCode = cmd.execute();
assertEquals(0, exitCode);

List<Mail> sent = mailbox.getMailsSentTo(email);
assertEquals(1, sent.size());
assertEquals(Lottery.createEmailText(email, List.of(ourIssues.get(2), ourIssues.get(3))), sent.get(0).getText());
}

@Test
public void testAssigningWithNoPartialComponentsHit() throws Exception {
String email = "[email protected]";
String configFile = """
delay: P14D
participants:
- email: %s
maxIssues: 5
projects:
- project: WELD
components: [Documentation]
maxIssues: 2""".formatted(email);

LotteryConfig testLotteryConfig = objectMapper.readValue(configFile, LotteryConfig.class);
when(lotteryConfigProducer.getLotteryConfig()).thenReturn(testLotteryConfig);

StringWriter sw = new StringWriter();
CommandLine cmd = new CommandLine(app);
cmd.setOut(new PrintWriter(sw));

int exitCode = cmd.execute();
assertEquals(0, exitCode);

List<Mail> sent = mailbox.getMailsSentTo(email);
assertEquals(1, sent.size());
assertEquals(Lottery.createEmailText(email, List.of(ourIssues.get(3))), sent.get(0).getText());
}
}

0 comments on commit f641ffd

Please sign in to comment.