Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
30 changed files
with
1,456 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
...ekeeper/src/test/java/org/openjdk/skara/bots/bridgekeeper/BridgekeeperBotFactoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package org.openjdk.skara.bots.bridgekeeper; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.openjdk.skara.json.JWCC; | ||
import org.openjdk.skara.test.TestBotFactory; | ||
import org.openjdk.skara.test.TestHostedRepository; | ||
|
||
import java.time.Duration; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class BridgekeeperBotFactoryTest { | ||
@Test | ||
public void testCreate() { | ||
String jsonString = """ | ||
{ | ||
"mirrors": [ | ||
"mirror1", | ||
"mirror2", | ||
"mirror3" | ||
], | ||
"data": [ | ||
"data1", | ||
"data2", | ||
"data3" | ||
], | ||
"pruned": { | ||
"pruned1": { | ||
"maxage": "P1D" | ||
}, | ||
"pruned2": { | ||
"maxage": "PT48H" | ||
}, | ||
"pruned3": { | ||
"maxage": "PT4320M" | ||
} | ||
} | ||
} | ||
"""; | ||
var jsonConfig = JWCC.parse(jsonString).asObject(); | ||
|
||
var pruned1 = new TestHostedRepository("pruned1"); | ||
var pruned2 = new TestHostedRepository("pruned2"); | ||
var pruned3 = new TestHostedRepository("pruned3"); | ||
var testBotFactory = TestBotFactory.newBuilder() | ||
.addHostedRepository("mirror1", new TestHostedRepository("mirror1")) | ||
.addHostedRepository("mirror2", new TestHostedRepository("mirror2")) | ||
.addHostedRepository("mirror3", new TestHostedRepository("mirror3")) | ||
.addHostedRepository("data1", new TestHostedRepository("data1")) | ||
.addHostedRepository("data2", new TestHostedRepository("data2")) | ||
.addHostedRepository("data3", new TestHostedRepository("data3")) | ||
.addHostedRepository("pruned1", pruned1) | ||
.addHostedRepository("pruned2", pruned2) | ||
.addHostedRepository("pruned3", pruned3) | ||
.build(); | ||
|
||
var bots = testBotFactory.createBots(BridgekeeperBotFactory.NAME, jsonConfig); | ||
assertEquals(7, bots.size()); | ||
|
||
var mirrorPullRequestCloserBots = bots.stream() | ||
.filter(e -> e.getClass().equals(PullRequestCloserBot.class)) | ||
.filter(e -> ((PullRequestCloserBot) e).getType().equals(PullRequestCloserBot.Type.MIRROR)) | ||
.toList(); | ||
var dataPullRequestCloserBots = bots.stream() | ||
.filter(e -> e.getClass().equals(PullRequestCloserBot.class)) | ||
.filter(e -> ((PullRequestCloserBot) e).getType().equals(PullRequestCloserBot.Type.DATA)) | ||
.toList(); | ||
var pullRequestPrunerBots = bots.stream() | ||
.filter(e -> e.getClass().equals(PullRequestPrunerBot.class)) | ||
.toList(); | ||
|
||
// A mirror pullRequestCloserBot for every configured mirror repository | ||
assertEquals(3, mirrorPullRequestCloserBots.size()); | ||
// A data pullRequestCloserBot for every configured data repository | ||
assertEquals(3, dataPullRequestCloserBots.size()); | ||
// One pullRequestPrunerBot for all configured pruned repository | ||
assertEquals(1, pullRequestPrunerBots.size()); | ||
|
||
// Check whether each bot is combined with the correct repo | ||
assertEquals("PullRequestCloserBot@mirror1", mirrorPullRequestCloserBots.get(0).toString()); | ||
assertEquals("PullRequestCloserBot@mirror2", mirrorPullRequestCloserBots.get(1).toString()); | ||
assertEquals("PullRequestCloserBot@mirror3", mirrorPullRequestCloserBots.get(2).toString()); | ||
assertEquals("PullRequestCloserBot@data1", dataPullRequestCloserBots.get(0).toString()); | ||
assertEquals("PullRequestCloserBot@data2", dataPullRequestCloserBots.get(1).toString()); | ||
assertEquals("PullRequestCloserBot@data3", dataPullRequestCloserBots.get(2).toString()); | ||
|
||
var pullRequestPrunerBot = (PullRequestPrunerBot) pullRequestPrunerBots.get(0); | ||
assertEquals("PullRequestPrunerBot", pullRequestPrunerBot.toString()); | ||
var maxAges = pullRequestPrunerBot.getMaxAges(); | ||
assertEquals(Duration.ofDays(1), maxAges.get(pruned1)); | ||
assertEquals(Duration.ofDays(2), maxAges.get(pruned2)); | ||
assertEquals(Duration.ofDays(3), maxAges.get(pruned3)); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
.../censussync/src/test/java/org/openjdk/skara/bots/censussync/CensusSyncBotFactoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package org.openjdk.skara.bots.censussync; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.openjdk.skara.json.JWCC; | ||
import org.openjdk.skara.test.TestBotFactory; | ||
import org.openjdk.skara.test.TestHostedRepository; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
class CensusSyncBotFactoryTest { | ||
@Test | ||
void testCreate() { | ||
String jsonString = """ | ||
{ | ||
"sync": [ | ||
{ | ||
"method": "unify", | ||
"from": "from1", | ||
"to": "to1", | ||
"version": 1 | ||
}, | ||
{ | ||
"method": "split", | ||
"from": "https://test.org/test.xml", | ||
"to": "to2", | ||
"version": 2 | ||
} | ||
] | ||
} | ||
"""; | ||
var jsonConfig = JWCC.parse(jsonString).asObject(); | ||
|
||
var testBotFactory = TestBotFactory.newBuilder() | ||
.addHostedRepository("from1", new TestHostedRepository("from1")) | ||
.addHostedRepository("to1", new TestHostedRepository("to1")) | ||
.addHostedRepository("to2", new TestHostedRepository("to2")) | ||
.build(); | ||
|
||
var bots = testBotFactory.createBots(CensusSyncBotFactory.NAME, jsonConfig); | ||
assertEquals(2, bots.size()); | ||
|
||
var censusSyncUnifyBots = bots.stream().filter(e -> e.getClass().equals(CensusSyncUnifyBot.class)).toList(); | ||
var censusSyncSplitBots = bots.stream().filter(e -> e.getClass().equals(CensusSyncSplitBot.class)).toList(); | ||
|
||
assertEquals(1, censusSyncUnifyBots.size()); | ||
assertEquals(1, censusSyncSplitBots.size()); | ||
|
||
assertEquals("CensusSyncUnifyBot(from1->to1@1)", censusSyncUnifyBots.get(0).toString()); | ||
assertEquals("CensusSyncSplitBot(https://test.org/test.xml->to2@2)", censusSyncSplitBots.get(0).toString()); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
bots/checkout/src/test/java/org/openjdk/skara/bots/checkout/CheckoutBotFactoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package org.openjdk.skara.bots.checkout; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.openjdk.skara.json.JWCC; | ||
import org.openjdk.skara.test.TestBotFactory; | ||
import org.openjdk.skara.test.TestHostedRepository; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
class CheckoutBotFactoryTest { | ||
@Test | ||
public void testCreate() { | ||
String jsonString = """ | ||
{ | ||
"marks": { | ||
"repo": "mark", | ||
"author": "test_author <test_author@test.com>" | ||
}, | ||
"repositories": [ | ||
{ | ||
"from": { | ||
"repo": "from1", | ||
"branch": "master" | ||
}, | ||
"to": "to1" | ||
}, | ||
{ | ||
"from": { | ||
"repo": "from2", | ||
"branch": "dev" | ||
}, | ||
"to": "to2" | ||
} | ||
] | ||
} | ||
"""; | ||
var jsonConfig = JWCC.parse(jsonString).asObject(); | ||
|
||
var testBotFactory = TestBotFactory.newBuilder() | ||
.addHostedRepository("mark", new TestHostedRepository("mark")) | ||
.addHostedRepository("from1", new TestHostedRepository("from1")) | ||
.addHostedRepository("from2", new TestHostedRepository("from2")) | ||
.build(); | ||
|
||
var bots = testBotFactory.createBots(CheckoutBotFactory.NAME, jsonConfig); | ||
// A checkoutBot for every configured repository | ||
assertEquals(2, bots.size()); | ||
|
||
assertEquals("CheckoutBot(from1:master, to1)", bots.get(0).toString()); | ||
assertEquals("CheckoutBot(from2:dev, to2)", bots.get(1).toString()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
bots/csr/src/test/java/org/openjdk/skara/bots/csr/CSRBotFactoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package org.openjdk.skara.bots.csr; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.openjdk.skara.json.*; | ||
import org.openjdk.skara.test.*; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class CSRBotFactoryTest { | ||
@Test | ||
public void testCreate() { | ||
String jsonString = """ | ||
{ | ||
"projects": [ | ||
{ | ||
"repository": "repo1", | ||
"issues": "test_bugs/TEST" | ||
}, | ||
{ | ||
"repository": "repo2", | ||
"issues": "test_bugs/TEST" | ||
}, | ||
{ | ||
"repository": "repo3", | ||
"issues": "test_bugs/TEST2" | ||
} | ||
] | ||
} | ||
"""; | ||
var jsonConfig = JWCC.parse(jsonString).asObject(); | ||
|
||
var testBotFactory = TestBotFactory.newBuilder() | ||
.addHostedRepository("repo1", new TestHostedRepository("repo1")) | ||
.addHostedRepository("repo2", new TestHostedRepository("repo2")) | ||
.addHostedRepository("repo3", new TestHostedRepository("repo3")) | ||
.addIssueProject("test_bugs/TEST", new TestIssueProject(null, "TEST")) | ||
.addIssueProject("test_bugs/TEST2", new TestIssueProject(null, "TEST2")) | ||
.build(); | ||
|
||
var bots = testBotFactory.createBots(CSRBotFactory.NAME, jsonConfig); | ||
assertEquals(5, bots.size()); | ||
|
||
var csrPullRequestBots = bots.stream().filter(e -> e.getClass().equals(CSRPullRequestBot.class)).toList(); | ||
var csrIssueBots = bots.stream().filter(e -> e.getClass().equals(CSRIssueBot.class)).toList(); | ||
|
||
// A CSRPullRequestBot for every configured repository | ||
assertEquals(3, csrPullRequestBots.size()); | ||
// A CSRIssueBot for each unique IssueProject | ||
assertEquals(2, csrIssueBots.size()); | ||
|
||
var CSRPullRequestBot1 = (CSRPullRequestBot) csrPullRequestBots.get(0); | ||
var CSRPullRequestBot2 = (CSRPullRequestBot) csrPullRequestBots.get(1); | ||
var CSRPullRequestBot3 = (CSRPullRequestBot) csrPullRequestBots.get(2); | ||
assertEquals("CSRPullRequestBot@repo1", CSRPullRequestBot1.toString()); | ||
assertEquals("CSRPullRequestBot@repo2", CSRPullRequestBot2.toString()); | ||
assertEquals("CSRPullRequestBot@repo3", CSRPullRequestBot3.toString()); | ||
assertEquals("TEST", CSRPullRequestBot1.getProject().name()); | ||
assertEquals("TEST", CSRPullRequestBot2.getProject().name()); | ||
assertEquals("TEST2", CSRPullRequestBot3.getProject().name()); | ||
|
||
for (var bot : csrIssueBots) { | ||
CSRIssueBot csrIssueBot = (CSRIssueBot) bot; | ||
if (csrIssueBot.toString().equals("CSRIssueBot@TEST")) { | ||
assertEquals(2, csrIssueBot.repositories().size()); | ||
} else if (csrIssueBot.toString().equals("CSRIssueBot@TEST2")) { | ||
assertEquals(1, csrIssueBot.repositories().size()); | ||
} else { | ||
throw new RuntimeException("This CSRIssueBot is not expected"); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
bots/forward/src/test/java/org/openjdk/skara/bots/forward/ForwardBotFactoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package org.openjdk.skara.bots.forward; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.openjdk.skara.json.JWCC; | ||
import org.openjdk.skara.test.TemporaryDirectory; | ||
import org.openjdk.skara.test.TestBotFactory; | ||
import org.openjdk.skara.test.TestHostedRepository; | ||
|
||
import java.util.Comparator; | ||
import java.util.Objects; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
class ForwardBotFactoryTest { | ||
@Test | ||
public void testCreate() { | ||
try (var tempFolder = new TemporaryDirectory()) { | ||
String jsonString = """ | ||
{ | ||
"repositories": { | ||
"repo1": { | ||
"from": "from1:master", | ||
"to": "to1:master" | ||
}, | ||
"repo2": { | ||
"from": "from2:dev", | ||
"to": "to2:test" | ||
} | ||
} | ||
} | ||
"""; | ||
var jsonConfig = JWCC.parse(jsonString).asObject(); | ||
|
||
var testBotFactory = TestBotFactory.newBuilder() | ||
.addHostedRepository("from1", new TestHostedRepository("from1")) | ||
.addHostedRepository("from2", new TestHostedRepository("from2")) | ||
.addHostedRepository("to1", new TestHostedRepository("to1")) | ||
.addHostedRepository("to2", new TestHostedRepository("to2")) | ||
.storagePath(tempFolder.path().resolve("storage")) | ||
.build(); | ||
|
||
var bots = testBotFactory.createBots(ForwardBotFactory.NAME, jsonConfig); | ||
bots = bots.stream().sorted(Comparator.comparing(Objects::toString)).toList(); | ||
//A forwardBot for every configured repo | ||
assertEquals(2, bots.size()); | ||
|
||
assertEquals("ForwardBot@(from1:master-> to1:master)", bots.get(0).toString()); | ||
assertEquals("ForwardBot@(from2:dev-> to2:test)", bots.get(1).toString()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
481f311
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review
Issues