diff --git a/src/test/scala/gitbucket/core/service/CommitStateServiceSpec.scala b/src/test/scala/gitbucket/core/service/CommitStateServiceSpec.scala deleted file mode 100644 index 5bc109f..0000000 --- a/src/test/scala/gitbucket/core/service/CommitStateServiceSpec.scala +++ /dev/null @@ -1,78 +0,0 @@ -package gitbucket.core.service - -import gitbucket.core.model._ -import gitbucket.core.model.Profile._ -import profile.simple._ - -import org.specs2.mutable.Specification - -import java.util.Date - - -class CommitStatusServiceSpec extends Specification with ServiceSpecBase with CommitStatusService - with RepositoryService with AccountService{ - val now = new java.util.Date() - val fixture1 = CommitStatus( - userName = "root", - repositoryName = "repo", - commitId = "0e97b8f59f7cdd709418bb59de53f741fd1c1bd7", - context = "jenkins/test", - creator = "tester", - state = CommitState.PENDING, - targetUrl = Some("http://example.com/target"), - description = Some("description"), - updatedDate = now, - registeredDate = now) - def findById(id: Int)(implicit s:Session) = CommitStatuses.filter(_.byPrimaryKey(id)).firstOption - def generateFixture1(tester:Account)(implicit s:Session) = createCommitStatus( - userName = fixture1.userName, - repositoryName = fixture1.repositoryName, - sha = fixture1.commitId, - context = fixture1.context, - state = fixture1.state, - targetUrl = fixture1.targetUrl, - description = fixture1.description, - creator = tester, - now = fixture1.registeredDate) - "CommitStatusService" should { - "createCommitState can insert and update" in { withTestDB { implicit session => - val tester = generateNewAccount(fixture1.creator) - createRepository(fixture1.repositoryName,fixture1.userName,None,false) - val id = generateFixture1(tester:Account) - getCommitStatus(fixture1.userName, fixture1.repositoryName, id) must_== - Some(fixture1.copy(commitStatusId=id)) - // other one can update - val tester2 = generateNewAccount("tester2") - val time2 = new java.util.Date(); - val id2 = createCommitStatus( - userName = fixture1.userName, - repositoryName = fixture1.repositoryName, - sha = fixture1.commitId, - context = fixture1.context, - state = CommitState.SUCCESS, - targetUrl = Some("http://example.com/target2"), - description = Some("description2"), - creator = tester2, - now = time2) - getCommitStatus(fixture1.userName, fixture1.repositoryName, id2) must_== Some(fixture1.copy( - commitStatusId = id, - creator = "tester2", - state = CommitState.SUCCESS, - targetUrl = Some("http://example.com/target2"), - description = Some("description2"), - updatedDate = time2)) - }} - "getCommitStatus can find by commitId and context" in { withTestDB { implicit session => - val tester = generateNewAccount(fixture1.creator) - createRepository(fixture1.repositoryName,fixture1.userName,None,false) - val id = generateFixture1(tester:Account) - getCommitStatus(fixture1.userName, fixture1.repositoryName, fixture1.commitId, fixture1.context) must_== Some(fixture1.copy(commitStatusId=id)) - }} - "getCommitStatus can find by commitStatusId" in { withTestDB { implicit session => - val tester = generateNewAccount(fixture1.creator) - createRepository(fixture1.repositoryName,fixture1.userName,None,false) - val id = generateFixture1(tester:Account) - getCommitStatus(fixture1.userName, fixture1.repositoryName, id) must_== Some(fixture1.copy(commitStatusId=id)) - }} - } -} \ No newline at end of file diff --git a/src/test/scala/gitbucket/core/service/CommitStatusServiceSpec.scala b/src/test/scala/gitbucket/core/service/CommitStatusServiceSpec.scala new file mode 100644 index 0000000..64eeb19 --- /dev/null +++ b/src/test/scala/gitbucket/core/service/CommitStatusServiceSpec.scala @@ -0,0 +1,74 @@ +package gitbucket.core.service + +import gitbucket.core.model._ +import gitbucket.core.model.Profile._ +import profile.simple._ +import org.scalatest.FunSuite + + +class CommitStatusServiceSpec extends FunSuite with ServiceSpecBase with CommitStatusService + with RepositoryService with AccountService{ + val now = new java.util.Date() + val fixture1 = CommitStatus( + userName = "root", + repositoryName = "repo", + commitId = "0e97b8f59f7cdd709418bb59de53f741fd1c1bd7", + context = "jenkins/test", + creator = "tester", + state = CommitState.PENDING, + targetUrl = Some("http://example.com/target"), + description = Some("description"), + updatedDate = now, + registeredDate = now) + def findById(id: Int)(implicit s:Session) = CommitStatuses.filter(_.byPrimaryKey(id)).firstOption + def generateFixture1(tester:Account)(implicit s:Session) = createCommitStatus( + userName = fixture1.userName, + repositoryName = fixture1.repositoryName, + sha = fixture1.commitId, + context = fixture1.context, + state = fixture1.state, + targetUrl = fixture1.targetUrl, + description = fixture1.description, + creator = tester, + now = fixture1.registeredDate) + test("createCommitState can insert and update") { withTestDB { implicit session => + val tester = generateNewAccount(fixture1.creator) + createRepository(fixture1.repositoryName,fixture1.userName,None,false) + val id = generateFixture1(tester:Account) + assert(getCommitStatus(fixture1.userName, fixture1.repositoryName, id) == Some(fixture1.copy(commitStatusId=id))) + // other one can update + val tester2 = generateNewAccount("tester2") + val time2 = new java.util.Date(); + val id2 = createCommitStatus( + userName = fixture1.userName, + repositoryName = fixture1.repositoryName, + sha = fixture1.commitId, + context = fixture1.context, + state = CommitState.SUCCESS, + targetUrl = Some("http://example.com/target2"), + description = Some("description2"), + creator = tester2, + now = time2) + assert(getCommitStatus(fixture1.userName, fixture1.repositoryName, id2) == Some(fixture1.copy( + commitStatusId = id, + creator = "tester2", + state = CommitState.SUCCESS, + targetUrl = Some("http://example.com/target2"), + description = Some("description2"), + updatedDate = time2))) + }} + + test("getCommitStatus can find by commitId and context") { withTestDB { implicit session => + val tester = generateNewAccount(fixture1.creator) + createRepository(fixture1.repositoryName,fixture1.userName,None,false) + val id = generateFixture1(tester:Account) + assert(getCommitStatus(fixture1.userName, fixture1.repositoryName, fixture1.commitId, fixture1.context) == Some(fixture1.copy(commitStatusId=id))) + }} + + test("getCommitStatus can find by commitStatusId") { withTestDB { implicit session => + val tester = generateNewAccount(fixture1.creator) + createRepository(fixture1.repositoryName,fixture1.userName,None,false) + val id = generateFixture1(tester:Account) + assert(getCommitStatus(fixture1.userName, fixture1.repositoryName, id) == Some(fixture1.copy(commitStatusId=id))) + }} +} \ No newline at end of file diff --git a/src/test/scala/gitbucket/core/service/IssuesServiceSpec.scala b/src/test/scala/gitbucket/core/service/IssuesServiceSpec.scala index f4d75bb..ec4e5fc 100644 --- a/src/test/scala/gitbucket/core/service/IssuesServiceSpec.scala +++ b/src/test/scala/gitbucket/core/service/IssuesServiceSpec.scala @@ -2,49 +2,44 @@ import gitbucket.core.model._ import gitbucket.core.service.IssuesService._ - -import org.specs2.mutable.Specification - -import java.util.Date +import org.scalatest.FunSuite -class IssuesServiceSpec extends Specification with ServiceSpecBase { - "IssuesService" should { - "getCommitStatues" in { withTestDB { implicit session => - val user1 = generateNewUserWithDBRepository("user1","repo1") +class IssuesServiceSpec extends FunSuite with ServiceSpecBase { + test("getCommitStatues") { withTestDB { implicit session => + val user1 = generateNewUserWithDBRepository("user1","repo1") - def getCommitStatues = dummyService.getCommitStatues(List(("user1","repo1",1),("user1","repo1",2))) + def getCommitStatues = dummyService.getCommitStatues(List(("user1","repo1",1),("user1","repo1",2))) - getCommitStatues must_== Map.empty + assert(getCommitStatues == Map.empty) - val now = new java.util.Date() - val issueId = generateNewIssue("user1","repo1") - issueId must_== 1 + val now = new java.util.Date() + val issueId = generateNewIssue("user1","repo1") + assert(issueId == 1) - getCommitStatues must_== Map.empty + assert(getCommitStatues == Map.empty) - val cs = dummyService.createCommitStatus("user1","repo1","shasha", "default", CommitState.SUCCESS, Some("http://exmple.com/ci"), Some("exampleService"), now, user1) + val cs = dummyService.createCommitStatus("user1","repo1","shasha", "default", CommitState.SUCCESS, Some("http://exmple.com/ci"), Some("exampleService"), now, user1) - getCommitStatues must_== Map.empty + assert(getCommitStatues == Map.empty) - val (is2, pr2) = generateNewPullRequest("user1/repo1/master","user1/repo1/feature1") - pr2.issueId must_== 2 + val (is2, pr2) = generateNewPullRequest("user1/repo1/master","user1/repo1/feature1") + assert(pr2.issueId == 2) - // if there are no statuses, state is none - getCommitStatues must_== Map.empty + // if there are no statuses, state is none + assert(getCommitStatues == Map.empty) - // if there is a status, state is that - val cs2 = dummyService.createCommitStatus("user1","repo1","feature1", "default", CommitState.SUCCESS, Some("http://exmple.com/ci"), Some("exampleService"), now, user1) - getCommitStatues must_== Map(("user1","repo1",2) -> CommitStatusInfo(1,1,Some("default"),Some(CommitState.SUCCESS),Some("http://exmple.com/ci"),Some("exampleService"))) + // if there is a status, state is that + val cs2 = dummyService.createCommitStatus("user1","repo1","feature1", "default", CommitState.SUCCESS, Some("http://exmple.com/ci"), Some("exampleService"), now, user1) + assert(getCommitStatues == Map(("user1","repo1",2) -> CommitStatusInfo(1,1,Some("default"),Some(CommitState.SUCCESS),Some("http://exmple.com/ci"),Some("exampleService")))) - // if there are two statuses, state is none - val cs3 = dummyService.createCommitStatus("user1","repo1","feature1", "pend", CommitState.PENDING, Some("http://exmple.com/ci"), Some("exampleService"), now, user1) - getCommitStatues must_== Map(("user1","repo1",2) -> CommitStatusInfo(2,1,None,None,None,None)) + // if there are two statuses, state is none + val cs3 = dummyService.createCommitStatus("user1","repo1","feature1", "pend", CommitState.PENDING, Some("http://exmple.com/ci"), Some("exampleService"), now, user1) + assert(getCommitStatues == Map(("user1","repo1",2) -> CommitStatusInfo(2,1,None,None,None,None))) - // get only statuses in query issues - val (is3, pr3) = generateNewPullRequest("user1/repo1/master","user1/repo1/feature3") - val cs4 = dummyService.createCommitStatus("user1","repo1","feature3", "none", CommitState.PENDING, None, None, now, user1) - getCommitStatues must_== Map(("user1","repo1",2) -> CommitStatusInfo(2,1,None,None,None,None)) - } } - } + // get only statuses in query issues + val (is3, pr3) = generateNewPullRequest("user1/repo1/master","user1/repo1/feature3") + val cs4 = dummyService.createCommitStatus("user1","repo1","feature3", "none", CommitState.PENDING, None, None, now, user1) + assert(getCommitStatues == Map(("user1","repo1",2) -> CommitStatusInfo(2,1,None,None,None,None))) + } } } \ No newline at end of file diff --git a/src/test/scala/gitbucket/core/service/LabelsServiceSpec.scala b/src/test/scala/gitbucket/core/service/LabelsServiceSpec.scala index 3a6ccc8..0141c5a 100644 --- a/src/test/scala/gitbucket/core/service/LabelsServiceSpec.scala +++ b/src/test/scala/gitbucket/core/service/LabelsServiceSpec.scala @@ -1,12 +1,11 @@ package gitbucket.core.service import gitbucket.core.model._ +import org.scalatest.FunSpec -import org.specs2.mutable.Specification - -class LabelsServiceSpec extends Specification with ServiceSpecBase { - "getLabels" should { - "be empty when not have any labels" in { withTestDB { implicit session => +class LabelsServiceSpec extends FunSpec with ServiceSpecBase { + describe("getLabels") { + it("should be empty when not have any labels") { withTestDB { implicit session => generateNewUserWithDBRepository("user1", "repo1") generateNewUserWithDBRepository("user1", "repo2") @@ -15,9 +14,9 @@ generateNewUserWithDBRepository("user2", "repo1") dummyService.createLabel("user2", "repo1", "label1", "000000") - dummyService.getLabels("user1", "repo1") must haveSize(0) + assert(dummyService.getLabels("user1", "repo1").isEmpty) }} - "return contained labels" in { withTestDB { implicit session => + it("should return contained labels") { withTestDB { implicit session => generateNewUserWithDBRepository("user1", "repo1") val labelId1 = dummyService.createLabel("user1", "repo1", "label1", "000000") val labelId2 = dummyService.createLabel("user1", "repo1", "label2", "ffffff") @@ -30,20 +29,22 @@ def getLabels = dummyService.getLabels("user1", "repo1") - getLabels must haveSize(2) - getLabels must_== List( + assert(getLabels.length == 2) + assert(getLabels == List( Label("user1", "repo1", labelId1, "label1", "000000"), Label("user1", "repo1", labelId2, "label2", "ffffff")) + ) }} } - "getLabel" should { - "return None when the label not exist" in { withTestDB { implicit session => + + describe("getLabel") { + it("should return None when the label not exist") { withTestDB { implicit session => generateNewUserWithDBRepository("user1", "repo1") - dummyService.getLabel("user1", "repo1", 1) must beNone - dummyService.getLabel("user1", "repo1", "label1") must beNone + assert(dummyService.getLabel("user1", "repo1", 1) == None) + assert(dummyService.getLabel("user1", "repo1", "label1") == None) }} - "return a label fetched by label id" in { withTestDB { implicit session => + it("should return a label fetched by label id") { withTestDB { implicit session => generateNewUserWithDBRepository("user1", "repo1") val labelId1 = dummyService.createLabel("user1", "repo1", "label1", "000000") dummyService.createLabel("user1", "repo1", "label2", "ffffff") @@ -55,9 +56,9 @@ dummyService.createLabel("user2", "repo1", "label1", "000000") def getLabel = dummyService.getLabel("user1", "repo1", labelId1) - getLabel must_== Some(Label("user1", "repo1", labelId1, "label1", "000000")) + assert(getLabel == Some(Label("user1", "repo1", labelId1, "label1", "000000"))) }} - "return a label fetched by label name" in { withTestDB { implicit session => + it("should return a label fetched by label name") { withTestDB { implicit session => generateNewUserWithDBRepository("user1", "repo1") val labelId1 = dummyService.createLabel("user1", "repo1", "label1", "000000") dummyService.createLabel("user1", "repo1", "label2", "ffffff") @@ -69,11 +70,11 @@ dummyService.createLabel("user2", "repo1", "label1", "000000") def getLabel = dummyService.getLabel("user1", "repo1", "label1") - getLabel must_== Some(Label("user1", "repo1", labelId1, "label1", "000000")) + getLabel == Some(Label("user1", "repo1", labelId1, "label1", "000000")) }} } - "createLabel" should { - "return accurate label id" in { withTestDB { implicit session => + describe("createLabel") { + it("should return accurate label id") { withTestDB { implicit session => generateNewUserWithDBRepository("user1", "repo1") generateNewUserWithDBRepository("user1", "repo2") generateNewUserWithDBRepository("user2", "repo1") @@ -81,13 +82,13 @@ dummyService.createLabel("user1", "repo2", "label1", "000000") dummyService.createLabel("user2", "repo1", "label1", "000000") val labelId = dummyService.createLabel("user1", "repo1", "label2", "000000") - labelId must_== 4 + assert(labelId == 4) def getLabel = dummyService.getLabel("user1", "repo1", labelId) - getLabel must_== Some(Label("user1", "repo1", labelId, "label2", "000000")) + assert(getLabel == Some(Label("user1", "repo1", labelId, "label2", "000000"))) }} } - "updateLabel" should { - "change target label" in { withTestDB { implicit session => + describe("updateLabel") { + it("should change target label") { withTestDB { implicit session => generateNewUserWithDBRepository("user1", "repo1") generateNewUserWithDBRepository("user1", "repo2") generateNewUserWithDBRepository("user2", "repo1") @@ -96,11 +97,11 @@ dummyService.createLabel("user2", "repo1", "label1", "000000") dummyService.updateLabel("user1", "repo1", labelId, "updated-label", "ffffff") def getLabel = dummyService.getLabel("user1", "repo1", labelId) - getLabel must_== Some(Label("user1", "repo1", labelId, "updated-label", "ffffff")) + assert(getLabel == Some(Label("user1", "repo1", labelId, "updated-label", "ffffff"))) }} } - "deleteLabel" should { - "remove target label" in { withTestDB { implicit session => + describe("deleteLabel") { + it("should remove target label") { withTestDB { implicit session => generateNewUserWithDBRepository("user1", "repo1") generateNewUserWithDBRepository("user1", "repo2") generateNewUserWithDBRepository("user2", "repo1") @@ -108,7 +109,7 @@ dummyService.createLabel("user1", "repo2", "label1", "000000") dummyService.createLabel("user2", "repo1", "label1", "000000") dummyService.deleteLabel("user1", "repo1", labelId) - dummyService.getLabel("user1", "repo1", labelId) must beNone + assert(dummyService.getLabel("user1", "repo1", labelId) == None) }} } } diff --git a/src/test/scala/gitbucket/core/service/MergeServiceSpec.scala b/src/test/scala/gitbucket/core/service/MergeServiceSpec.scala index 2bec6d1..68d4b7f 100644 --- a/src/test/scala/gitbucket/core/service/MergeServiceSpec.scala +++ b/src/test/scala/gitbucket/core/service/MergeServiceSpec.scala @@ -1,26 +1,17 @@ package gitbucket.core.service -import gitbucket.core.model._ -import gitbucket.core.util.JGitUtil import gitbucket.core.util.Directory._ -import gitbucket.core.util.Implicits._ import gitbucket.core.util.ControlUtil._ import gitbucket.core.util.GitSpecUtil._ -import org.apache.commons.io.FileUtils import org.eclipse.jgit.api.Git -import org.eclipse.jgit.dircache.DirCache import org.eclipse.jgit.lib._ import org.eclipse.jgit.revwalk._ -import org.eclipse.jgit.treewalk._ -import org.specs2.mutable.Specification +import org.scalatest.FunSpec import java.io.File -import java.nio.file._ -import java.util.Date -class MergeServiceSpec extends Specification { - sequential +class MergeServiceSpec extends FunSpec { val service = new MergeService{} val branch = "master" val issueId = 10 @@ -36,95 +27,95 @@ createFile(git, s"refs/heads/${branch}", "test.txt", "hoge2" ) createFile(git, s"refs/pull/${issueId}/head", "test.txt", "hoge4" ) } - "checkConflict, checkConflictCache" should { - "checkConflict false if not conflicted, and create cache" in { + describe("checkConflict, checkConflictCache") { + it("checkConflict false if not conflicted, and create cache") { val repo1Dir = initRepository("user1","repo1") - service.checkConflictCache("user1", "repo1", branch, issueId) mustEqual None + assert(service.checkConflictCache("user1", "repo1", branch, issueId) == None) val conflicted = service.checkConflict("user1", "repo1", branch, issueId) - service.checkConflictCache("user1", "repo1", branch, issueId) mustEqual Some(false) - conflicted mustEqual false + assert(service.checkConflictCache("user1", "repo1", branch, issueId) == Some(false)) + assert(conflicted == false) } - "checkConflict true if not conflicted, and create cache" in { + it("checkConflict true if not conflicted, and create cache") { val repo2Dir = initRepository("user1","repo2") using(Git.open(repo2Dir)){ git => createConfrict(git) } - service.checkConflictCache("user1", "repo2", branch, issueId) mustEqual None + assert(service.checkConflictCache("user1", "repo2", branch, issueId) == None) val conflicted = service.checkConflict("user1", "repo2", branch, issueId) - conflicted mustEqual true - service.checkConflictCache("user1", "repo2", branch, issueId) mustEqual Some(true) + assert(conflicted == true) + assert(service.checkConflictCache("user1", "repo2", branch, issueId) == Some(true)) } } - "checkConflictCache" should { - "merged cache invalid if origin branch moved" in { + describe("checkConflictCache") { + it("merged cache invalid if origin branch moved") { val repo3Dir = initRepository("user1","repo3") - service.checkConflict("user1", "repo3", branch, issueId) mustEqual false - service.checkConflictCache("user1", "repo3", branch, issueId) mustEqual Some(false) + assert(service.checkConflict("user1", "repo3", branch, issueId) == false) + assert(service.checkConflictCache("user1", "repo3", branch, issueId) == Some(false)) using(Git.open(repo3Dir)){ git => createFile(git, s"refs/heads/${branch}", "test.txt", "hoge2" ) } - service.checkConflictCache("user1", "repo3", branch, issueId) mustEqual None + assert(service.checkConflictCache("user1", "repo3", branch, issueId) == None) } - "merged cache invalid if request branch moved" in { + it("merged cache invalid if request branch moved") { val repo4Dir = initRepository("user1","repo4") - service.checkConflict("user1", "repo4", branch, issueId) mustEqual false - service.checkConflictCache("user1", "repo4", branch, issueId) mustEqual Some(false) + assert(service.checkConflict("user1", "repo4", branch, issueId) == false) + assert(service.checkConflictCache("user1", "repo4", branch, issueId) == Some(false)) using(Git.open(repo4Dir)){ git => createFile(git, s"refs/pull/${issueId}/head", "test.txt", "hoge4" ) } - service.checkConflictCache("user1", "repo4", branch, issueId) mustEqual None + assert(service.checkConflictCache("user1", "repo4", branch, issueId) == None) } - "merged cache invalid if origin branch moved" in { + it("should merged cache invalid if origin branch moved") { val repo5Dir = initRepository("user1","repo5") - service.checkConflict("user1", "repo5", branch, issueId) mustEqual false - service.checkConflictCache("user1", "repo5", branch, issueId) mustEqual Some(false) + assert(service.checkConflict("user1", "repo5", branch, issueId) == false) + assert(service.checkConflictCache("user1", "repo5", branch, issueId) == Some(false)) using(Git.open(repo5Dir)){ git => createFile(git, s"refs/heads/${branch}", "test.txt", "hoge2" ) } - service.checkConflictCache("user1", "repo5", branch, issueId) mustEqual None + assert(service.checkConflictCache("user1", "repo5", branch, issueId) == None) } - "conflicted cache invalid if request branch moved" in { + it("conflicted cache invalid if request branch moved") { val repo6Dir = initRepository("user1","repo6") using(Git.open(repo6Dir)){ git => createConfrict(git) } - service.checkConflict("user1", "repo6", branch, issueId) mustEqual true - service.checkConflictCache("user1", "repo6", branch, issueId) mustEqual Some(true) + assert(service.checkConflict("user1", "repo6", branch, issueId) == true) + assert(service.checkConflictCache("user1", "repo6", branch, issueId) == Some(true)) using(Git.open(repo6Dir)){ git => createFile(git, s"refs/pull/${issueId}/head", "test.txt", "hoge4" ) } - service.checkConflictCache("user1", "repo6", branch, issueId) mustEqual None + assert(service.checkConflictCache("user1", "repo6", branch, issueId) == None) } - "conflicted cache invalid if origin branch moved" in { + it("conflicted cache invalid if origin branch moved") { val repo7Dir = initRepository("user1","repo7") using(Git.open(repo7Dir)){ git => createConfrict(git) } - service.checkConflict("user1", "repo7", branch, issueId) mustEqual true - service.checkConflictCache("user1", "repo7", branch, issueId) mustEqual Some(true) + assert(service.checkConflict("user1", "repo7", branch, issueId) == true) + assert(service.checkConflictCache("user1", "repo7", branch, issueId) == Some(true)) using(Git.open(repo7Dir)){ git => createFile(git, s"refs/heads/${branch}", "test.txt", "hoge4" ) } - service.checkConflictCache("user1", "repo7", branch, issueId) mustEqual None + assert(service.checkConflictCache("user1", "repo7", branch, issueId) == None) } } - "mergePullRequest" should { - "can merge" in { + describe("mergePullRequest") { + it("can merge") { val repo8Dir = initRepository("user1","repo8") using(Git.open(repo8Dir)){ git => createFile(git, s"refs/pull/${issueId}/head", "test.txt", "hoge2" ) val committer = new PersonIdent("dummy2", "dummy2@example.com") - getFile(git, branch, "test.txt").content.get mustEqual "hoge" + assert(getFile(git, branch, "test.txt").content.get == "hoge") val requestBranchId = git.getRepository.resolve(s"refs/pull/${issueId}/head") val masterId = git.getRepository.resolve(branch) service.mergePullRequest(git, branch, issueId, "merged", committer) - val lastCommitId = git.getRepository.resolve(branch); + val lastCommitId = git.getRepository.resolve(branch) val commit = using(new RevWalk(git.getRepository))(_.parseCommit(lastCommitId)) - commit.getCommitterIdent() mustEqual committer - commit.getAuthorIdent() mustEqual committer - commit.getFullMessage() mustEqual "merged" - commit.getParents.toSet mustEqual Set( requestBranchId, masterId ) - getFile(git, branch, "test.txt").content.get mustEqual "hoge2" + assert(commit.getCommitterIdent() == committer) + assert(commit.getAuthorIdent() == committer) + assert(commit.getFullMessage() == "merged") + assert(commit.getParents.toSet == Set( requestBranchId, masterId )) + assert(getFile(git, branch, "test.txt").content.get == "hoge2") } } } diff --git a/src/test/scala/gitbucket/core/service/ProtectedBranchServiceSpec.scala b/src/test/scala/gitbucket/core/service/ProtectedBranchServiceSpec.scala index df19add..b839b60 100644 --- a/src/test/scala/gitbucket/core/service/ProtectedBranchServiceSpec.scala +++ b/src/test/scala/gitbucket/core/service/ProtectedBranchServiceSpec.scala @@ -1,134 +1,134 @@ package gitbucket.core.service import gitbucket.core.util.GitSpecUtil._ -import org.specs2.mutable.Specification import org.eclipse.jgit.transport.{ReceivePack, ReceiveCommand} import org.eclipse.jgit.lib.ObjectId import gitbucket.core.model.CommitState import gitbucket.core.service.ProtectedBranchService.{ProtectedBranchReceiveHook, ProtectedBranchInfo} import scalaz._, Scalaz._ +import org.scalatest.FunSpec -class ProtectedBranchServiceSpec extends Specification with ServiceSpecBase with ProtectedBranchService with CommitStatusService { +class ProtectedBranchServiceSpec extends FunSpec with ServiceSpecBase with ProtectedBranchService with CommitStatusService { val receiveHook = new ProtectedBranchReceiveHook() val now = new java.util.Date() val sha = "0c77148632618b59b6f70004e3084002be2b8804" val sha2 = "0c77148632618b59b6f70004e3084002be2b8805" - "getProtectedBranchInfo" should { - "empty is disabled" in { + describe("getProtectedBranchInfo") { + it("should empty is disabled") { withTestDB { implicit session => - getProtectedBranchInfo("user1", "repo1", "branch") must_== ProtectedBranchInfo.disabled("user1", "repo1") + assert(getProtectedBranchInfo("user1", "repo1", "branch") == ProtectedBranchInfo.disabled("user1", "repo1")) } } - "enable and update and disable" in { + it("should enable and update and disable") { withTestDB { implicit session => generateNewUserWithDBRepository("user1", "repo1") enableBranchProtection("user1", "repo1", "branch", false, Nil) - getProtectedBranchInfo("user1", "repo1", "branch") must_== ProtectedBranchInfo("user1", "repo1", true, Nil, false) + assert(getProtectedBranchInfo("user1", "repo1", "branch") == ProtectedBranchInfo("user1", "repo1", true, Nil, false)) enableBranchProtection("user1", "repo1", "branch", true, Seq("hoge","huge")) - getProtectedBranchInfo("user1", "repo1", "branch") must_== ProtectedBranchInfo("user1", "repo1", true, Seq("hoge","huge"), true) + assert(getProtectedBranchInfo("user1", "repo1", "branch") == ProtectedBranchInfo("user1", "repo1", true, Seq("hoge","huge"), true)) disableBranchProtection("user1", "repo1", "branch") - getProtectedBranchInfo("user1", "repo1", "branch") must_== ProtectedBranchInfo.disabled("user1", "repo1") + assert(getProtectedBranchInfo("user1", "repo1", "branch") == ProtectedBranchInfo.disabled("user1", "repo1")) } } - "empty contexts is no-include-administrators" in { + it("should empty contexts is no-include-administrators") { withTestDB { implicit session => generateNewUserWithDBRepository("user1", "repo1") enableBranchProtection("user1", "repo1", "branch", false, Nil) - getProtectedBranchInfo("user1", "repo1", "branch").includeAdministrators must_== false + assert(getProtectedBranchInfo("user1", "repo1", "branch").includeAdministrators == false) enableBranchProtection("user1", "repo1", "branch", true, Nil) - getProtectedBranchInfo("user1", "repo1", "branch").includeAdministrators must_== false + assert(getProtectedBranchInfo("user1", "repo1", "branch").includeAdministrators == false) } } - "getProtectedBranchList" in { + it("getProtectedBranchList") { withTestDB { implicit session => generateNewUserWithDBRepository("user1", "repo1") enableBranchProtection("user1", "repo1", "branch", false, Nil) enableBranchProtection("user1", "repo1", "branch2", false, Seq("fuga")) enableBranchProtection("user1", "repo1", "branch3", true, Seq("hoge")) - getProtectedBranchList("user1", "repo1").toSet must_== Set("branch", "branch2", "branch3") + assert(getProtectedBranchList("user1", "repo1").toSet == Set("branch", "branch2", "branch3")) } } - "getBranchProtectedReason on force push from admin" in { + it("getBranchProtectedReason on force push from admin") { withTestDB { implicit session => withTestRepository { git => val rp = new ReceivePack(git.getRepository) <| { _.setAllowNonFastForwards(true) } val rc = new ReceiveCommand(ObjectId.fromString(sha), ObjectId.fromString(sha2), "refs/heads/branch", ReceiveCommand.Type.UPDATE_NONFASTFORWARD) generateNewUserWithDBRepository("user1", "repo1") - receiveHook.preReceive("user1", "repo1", rp, rc, "user1") must_== None + assert(receiveHook.preReceive("user1", "repo1", rp, rc, "user1") == None) enableBranchProtection("user1", "repo1", "branch", false, Nil) - receiveHook.preReceive("user1", "repo1", rp, rc, "user1") must_== Some("Cannot force-push to a protected branch") + assert(receiveHook.preReceive("user1", "repo1", rp, rc, "user1") == Some("Cannot force-push to a protected branch")) } } } - "getBranchProtectedReason on force push from othre" in { + it("getBranchProtectedReason on force push from other") { withTestDB { implicit session => withTestRepository { git => val rp = new ReceivePack(git.getRepository) <| { _.setAllowNonFastForwards(true) } val rc = new ReceiveCommand(ObjectId.fromString(sha), ObjectId.fromString(sha2), "refs/heads/branch", ReceiveCommand.Type.UPDATE_NONFASTFORWARD) generateNewUserWithDBRepository("user1", "repo1") - receiveHook.preReceive("user1", "repo1", rp, rc, "user2") must_== None + assert(receiveHook.preReceive("user1", "repo1", rp, rc, "user2") == None) enableBranchProtection("user1", "repo1", "branch", false, Nil) - receiveHook.preReceive("user1", "repo1", rp, rc, "user2") must_== Some("Cannot force-push to a protected branch") + assert(receiveHook.preReceive("user1", "repo1", rp, rc, "user2") == Some("Cannot force-push to a protected branch")) } } } - "getBranchProtectedReason check status on push from othre" in { + it("getBranchProtectedReason check status on push from other") { withTestDB { implicit session => withTestRepository { git => val rp = new ReceivePack(git.getRepository) <| { _.setAllowNonFastForwards(false) } val rc = new ReceiveCommand(ObjectId.fromString(sha), ObjectId.fromString(sha2), "refs/heads/branch", ReceiveCommand.Type.UPDATE) val user1 = generateNewUserWithDBRepository("user1", "repo1") - receiveHook.preReceive("user1", "repo1", rp, rc, "user2") must_== None + assert(receiveHook.preReceive("user1", "repo1", rp, rc, "user2") == None) enableBranchProtection("user1", "repo1", "branch", false, Seq("must")) - receiveHook.preReceive("user1", "repo1", rp, rc, "user2") must_== Some("Required status check \"must\" is expected") + assert(receiveHook.preReceive("user1", "repo1", rp, rc, "user2") == Some("Required status check \"must\" is expected")) enableBranchProtection("user1", "repo1", "branch", false, Seq("must", "must2")) - receiveHook.preReceive("user1", "repo1", rp, rc, "user2") must_== Some("2 of 2 required status checks are expected") + assert(receiveHook.preReceive("user1", "repo1", rp, rc, "user2") == Some("2 of 2 required status checks are expected")) createCommitStatus("user1", "repo1", sha2, "context", CommitState.SUCCESS, None, None, now, user1) - receiveHook.preReceive("user1", "repo1", rp, rc, "user2") must_== Some("2 of 2 required status checks are expected") + assert(receiveHook.preReceive("user1", "repo1", rp, rc, "user2") == Some("2 of 2 required status checks are expected")) createCommitStatus("user1", "repo1", sha2, "must", CommitState.SUCCESS, None, None, now, user1) - receiveHook.preReceive("user1", "repo1", rp, rc, "user2") must_== Some("Required status check \"must2\" is expected") + assert(receiveHook.preReceive("user1", "repo1", rp, rc, "user2") == Some("Required status check \"must2\" is expected")) createCommitStatus("user1", "repo1", sha2, "must2", CommitState.SUCCESS, None, None, now, user1) - receiveHook.preReceive("user1", "repo1", rp, rc, "user2") must_== None + assert(receiveHook.preReceive("user1", "repo1", rp, rc, "user2") == None) } } } - "getBranchProtectedReason check status on push from admin" in { + it("getBranchProtectedReason check status on push from admin") { withTestDB { implicit session => withTestRepository { git => val rp = new ReceivePack(git.getRepository) <| { _.setAllowNonFastForwards(false) } val rc = new ReceiveCommand(ObjectId.fromString(sha), ObjectId.fromString(sha2), "refs/heads/branch", ReceiveCommand.Type.UPDATE) val user1 = generateNewUserWithDBRepository("user1", "repo1") - receiveHook.preReceive("user1", "repo1", rp, rc, "user1") must_== None + assert(receiveHook.preReceive("user1", "repo1", rp, rc, "user1") == None) enableBranchProtection("user1", "repo1", "branch", false, Seq("must")) - receiveHook.preReceive("user1", "repo1", rp, rc, "user1") must_== None + assert(receiveHook.preReceive("user1", "repo1", rp, rc, "user1") == None) enableBranchProtection("user1", "repo1", "branch", true, Seq("must")) - receiveHook.preReceive("user1", "repo1", rp, rc, "user1") must_== Some("Required status check \"must\" is expected") + assert(receiveHook.preReceive("user1", "repo1", rp, rc, "user1") == Some("Required status check \"must\" is expected")) enableBranchProtection("user1", "repo1", "branch", false, Seq("must", "must2")) - receiveHook.preReceive("user1", "repo1", rp, rc, "user1") must_== None + assert(receiveHook.preReceive("user1", "repo1", rp, rc, "user1") == None) enableBranchProtection("user1", "repo1", "branch", true, Seq("must", "must2")) - receiveHook.preReceive("user1", "repo1", rp, rc, "user1") must_== Some("2 of 2 required status checks are expected") + assert(receiveHook.preReceive("user1", "repo1", rp, rc, "user1") == Some("2 of 2 required status checks are expected")) createCommitStatus("user1", "repo1", sha2, "context", CommitState.SUCCESS, None, None, now, user1) - receiveHook.preReceive("user1", "repo1", rp, rc, "user1") must_== Some("2 of 2 required status checks are expected") + assert(receiveHook.preReceive("user1", "repo1", rp, rc, "user1") == Some("2 of 2 required status checks are expected")) createCommitStatus("user1", "repo1", sha2, "must", CommitState.SUCCESS, None, None, now, user1) - receiveHook.preReceive("user1", "repo1", rp, rc, "user1") must_== Some("Required status check \"must2\" is expected") + assert(receiveHook.preReceive("user1", "repo1", rp, rc, "user1") == Some("Required status check \"must2\" is expected")) createCommitStatus("user1", "repo1", sha2, "must2", CommitState.SUCCESS, None, None, now, user1) - receiveHook.preReceive("user1", "repo1", rp, rc, "user1") must_== None + assert(receiveHook.preReceive("user1", "repo1", rp, rc, "user1") == None) } } } } - "ProtectedBranchInfo" should { - "administrator is owner" in { + describe("ProtectedBranchInfo") { + it("administrator is owner") { withTestDB { implicit session => generateNewUserWithDBRepository("user1", "repo1") val x = ProtectedBranchInfo("user1", "repo1", true, Nil, false) - x.isAdministrator("user1") must_== true - x.isAdministrator("user2") must_== false + assert(x.isAdministrator("user1") == true) + assert(x.isAdministrator("user2") == false) } } - "administrator is manager" in { + it("administrator is manager") { withTestDB { implicit session => val x = ProtectedBranchInfo("grp1", "repo1", true, Nil, false) x.createGroup("grp1", None) @@ -137,49 +137,49 @@ generateNewAccount("user3") x.updateGroupMembers("grp1", List("user1"->true, "user2"->false)) - x.isAdministrator("user1") must_== true - x.isAdministrator("user2") must_== false - x.isAdministrator("user3") must_== false + assert(x.isAdministrator("user1") == true) + assert(x.isAdministrator("user2") == false) + assert(x.isAdministrator("user3") == false) } } - "unSuccessedContexts" in { + it("unSuccessedContexts") { withTestDB { implicit session => val user1 = generateNewUserWithDBRepository("user1", "repo1") val x = ProtectedBranchInfo("user1", "repo1", true, List("must"), false) - x.unSuccessedContexts(sha) must_== Set("must") + assert(x.unSuccessedContexts(sha) == Set("must")) createCommitStatus("user1", "repo1", sha, "context", CommitState.SUCCESS, None, None, now, user1) - x.unSuccessedContexts(sha) must_== Set("must") + assert(x.unSuccessedContexts(sha) == Set("must")) createCommitStatus("user1", "repo1", sha, "must", CommitState.ERROR, None, None, now, user1) - x.unSuccessedContexts(sha) must_== Set("must") + assert(x.unSuccessedContexts(sha) == Set("must")) createCommitStatus("user1", "repo1", sha, "must", CommitState.PENDING, None, None, now, user1) - x.unSuccessedContexts(sha) must_== Set("must") + assert(x.unSuccessedContexts(sha) == Set("must")) createCommitStatus("user1", "repo1", sha, "must", CommitState.FAILURE, None, None, now, user1) - x.unSuccessedContexts(sha) must_== Set("must") + assert(x.unSuccessedContexts(sha) == Set("must")) createCommitStatus("user1", "repo1", sha, "must", CommitState.SUCCESS, None, None, now, user1) - x.unSuccessedContexts(sha) must_== Set() + assert(x.unSuccessedContexts(sha) == Set()) } } - "unSuccessedContexts when empty" in { + it("unSuccessedContexts when empty") { withTestDB { implicit session => val user1 = generateNewUserWithDBRepository("user1", "repo1") val x = ProtectedBranchInfo("user1", "repo1", true, Nil, false) val sha = "0c77148632618b59b6f70004e3084002be2b8804" - x.unSuccessedContexts(sha) must_== Nil + assert(x.unSuccessedContexts(sha) == Set()) createCommitStatus("user1", "repo1", sha, "context", CommitState.SUCCESS, None, None, now, user1) - x.unSuccessedContexts(sha) must_== Nil + assert(x.unSuccessedContexts(sha) == Set()) } } - "if disabled, needStatusCheck is false" in { + it("if disabled, needStatusCheck is false") { withTestDB { implicit session => - ProtectedBranchInfo("user1", "repo1", false, Seq("must"), true).needStatusCheck("user1") must_== false + assert(ProtectedBranchInfo("user1", "repo1", false, Seq("must"), true).needStatusCheck("user1") == false) } } - "needStatusCheck includeAdministrators" in { + it("needStatusCheck includeAdministrators") { withTestDB { implicit session => - ProtectedBranchInfo("user1", "repo1", true, Seq("must"), false).needStatusCheck("user2") must_== true - ProtectedBranchInfo("user1", "repo1", true, Seq("must"), false).needStatusCheck("user1") must_== false - ProtectedBranchInfo("user1", "repo1", true, Seq("must"), true ).needStatusCheck("user2") must_== true - ProtectedBranchInfo("user1", "repo1", true, Seq("must"), true ).needStatusCheck("user1") must_== true + assert(ProtectedBranchInfo("user1", "repo1", true, Seq("must"), false).needStatusCheck("user2") == true) + assert(ProtectedBranchInfo("user1", "repo1", true, Seq("must"), false).needStatusCheck("user1") == false) + assert(ProtectedBranchInfo("user1", "repo1", true, Seq("must"), true ).needStatusCheck("user2") == true) + assert(ProtectedBranchInfo("user1", "repo1", true, Seq("must"), true ).needStatusCheck("user1") == true) } } } diff --git a/src/test/scala/gitbucket/core/service/PullRequestServiceSpec.scala b/src/test/scala/gitbucket/core/service/PullRequestServiceSpec.scala index e5741de..2127dbf 100644 --- a/src/test/scala/gitbucket/core/service/PullRequestServiceSpec.scala +++ b/src/test/scala/gitbucket/core/service/PullRequestServiceSpec.scala @@ -1,17 +1,17 @@ package gitbucket.core.service import gitbucket.core.model._ -import gitbucket.core.model.Profile._ +import org.scalatest.FunSpec -import org.specs2.mutable.Specification +class PullRequestServiceSpec extends FunSpec with ServiceSpecBase with PullRequestService with IssuesService { -class PullRequestServiceSpec extends Specification with ServiceSpecBase with PullRequestService with IssuesService { def swap(r: (Issue, PullRequest)) = (r._2 -> r._1) - "PullRequestService.getPullRequestFromBranch" should { - """ + + describe("PullRequestService.getPullRequestFromBranch") { + it("""should |return pull request if exists pull request from `branch` to `defaultBranch` and not closed. |return pull request if exists pull request from `branch` to othre branch and not closed. - |return None if all pull request is closed""".stripMargin.trim in { withTestDB { implicit se => + |return None if all pull request is closed""".stripMargin.trim) { withTestDB { implicit se => generateNewUserWithDBRepository("user1", "repo1") generateNewUserWithDBRepository("user1", "repo2") generateNewUserWithDBRepository("user2", "repo1") @@ -22,12 +22,12 @@ val r1 = swap(generateNewPullRequest("user1/repo1/master2", "user1/repo1/head1")) val r2 = swap(generateNewPullRequest("user1/repo1/master", "user1/repo1/head1")) val r3 = swap(generateNewPullRequest("user1/repo1/master4", "user1/repo1/head1")) - getPullRequestFromBranch("user1", "repo1", "head1", "master") must_== Some(r2) + assert(getPullRequestFromBranch("user1", "repo1", "head1", "master") == Some(r2)) updateClosed("user1", "repo1", r2._1.issueId, true) - getPullRequestFromBranch("user1", "repo1", "head1", "master").get must beOneOf(r1, r2) + assert(Seq(r1, r2).contains(getPullRequestFromBranch("user1", "repo1", "head1", "master").get)) updateClosed("user1", "repo1", r1._1.issueId, true) updateClosed("user1", "repo1", r3._1.issueId, true) - getPullRequestFromBranch("user1", "repo1", "head1", "master") must beNone + assert(getPullRequestFromBranch("user1", "repo1", "head1", "master") == None) } } } } \ No newline at end of file diff --git a/src/test/scala/gitbucket/core/service/RepositoryServiceSpec.scala b/src/test/scala/gitbucket/core/service/RepositoryServiceSpec.scala index 8f20f40..9a343bd 100644 --- a/src/test/scala/gitbucket/core/service/RepositoryServiceSpec.scala +++ b/src/test/scala/gitbucket/core/service/RepositoryServiceSpec.scala @@ -1,39 +1,33 @@ package gitbucket.core.service import gitbucket.core.model._ -import org.specs2.mutable.Specification +import org.scalatest.FunSuite +class RepositoryServiceSpec extends FunSuite with ServiceSpecBase with RepositoryService with AccountService{ + test("renameRepository can rename CommitState, ProtectedBranches") { withTestDB { implicit session => + val tester = generateNewAccount("tester") + createRepository("repo", "root", None, false) + val service = new CommitStatusService with ProtectedBranchService {} + val id = service.createCommitStatus( + userName = "root", + repositoryName = "repo", + sha = "0e97b8f59f7cdd709418bb59de53f741fd1c1bd7", + context = "jenkins/test", + state = CommitState.PENDING, + targetUrl = Some("http://example.com/target"), + description = Some("description"), + creator = tester, + now = new java.util.Date) -class RepositoryServiceSpec extends Specification with ServiceSpecBase with RepositoryService with AccountService{ - "RepositoryService" should { - "renameRepository can rename CommitState, ProtectedBranches" in { withTestDB { implicit session => - val tester = generateNewAccount("tester") - createRepository("repo","root",None,false) - val service = new CommitStatusService with ProtectedBranchService {} - val id = service.createCommitStatus( - userName = "root", - repositoryName = "repo", - sha = "0e97b8f59f7cdd709418bb59de53f741fd1c1bd7", - context = "jenkins/test", - state = CommitState.PENDING, - targetUrl = Some("http://example.com/target"), - description = Some("description"), - creator = tester, - now = new java.util.Date) - service.enableBranchProtection("root", "repo", "branch", true, Seq("must1", "must2")) - var orgPbi = service.getProtectedBranchInfo("root", "repo", "branch") - val org = service.getCommitStatus("root","repo", id).get + service.enableBranchProtection("root", "repo", "branch", true, Seq("must1", "must2")) - renameRepository("root","repo","tester","repo2") + val orgPbi = service.getProtectedBranchInfo("root", "repo", "branch") + val org = service.getCommitStatus("root","repo", id).get - val neo = service.getCommitStatus("tester","repo2", org.commitId, org.context).get - neo must_== - org.copy( - commitStatusId=neo.commitStatusId, - repositoryName="repo2", - userName="tester") - service.getProtectedBranchInfo("tester", "repo2", "branch") must_== - orgPbi.copy(owner="tester", repository="repo2") - }} - } + renameRepository("root","repo","tester","repo2") + + val neo = service.getCommitStatus("tester","repo2", org.commitId, org.context).get + assert(neo == org.copy(commitStatusId = neo.commitStatusId, repositoryName = "repo2", userName = "tester")) + assert(service.getProtectedBranchInfo("tester", "repo2", "branch") == orgPbi.copy(owner = "tester", repository = "repo2")) + }} } diff --git a/src/test/scala/gitbucket/core/service/WebHookServiceSpec.scala b/src/test/scala/gitbucket/core/service/WebHookServiceSpec.scala index 1b18c3b..4320dd5 100644 --- a/src/test/scala/gitbucket/core/service/WebHookServiceSpec.scala +++ b/src/test/scala/gitbucket/core/service/WebHookServiceSpec.scala @@ -1,76 +1,75 @@ package gitbucket.core.service -import org.specs2.mutable.Specification import gitbucket.core.model.WebHook +import org.scalatest.FunSuite -class WebHookServiceSpec extends Specification with ServiceSpecBase { +class WebHookServiceSpec extends FunSuite with ServiceSpecBase { lazy val service = new WebHookPullRequestService with AccountService with RepositoryService with PullRequestService with IssuesService - "WebHookPullRequestService.getPullRequestsByRequestForWebhook" should { - "find from request branch" in { withTestDB { implicit session => - val user1 = generateNewUserWithDBRepository("user1","repo1") - val user2 = generateNewUserWithDBRepository("user2","repo2") - val user3 = generateNewUserWithDBRepository("user3","repo3") - val issueUser = user("root") - val (issue1, pullreq1) = generateNewPullRequest("user1/repo1/master1", "user2/repo2/master2", loginUser="root") - val (issue3, pullreq3) = generateNewPullRequest("user3/repo3/master3", "user2/repo2/master2", loginUser="root") - val (issue32, pullreq32) = generateNewPullRequest("user3/repo3/master32", "user2/repo2/master2", loginUser="root") - generateNewPullRequest("user2/repo2/master2", "user1/repo1/master2") - service.addWebHook("user1", "repo1", "webhook1-1", Set(WebHook.PullRequest)) - service.addWebHook("user1", "repo1", "webhook1-2", Set(WebHook.PullRequest)) - service.addWebHook("user2", "repo2", "webhook2-1", Set(WebHook.PullRequest)) - service.addWebHook("user2", "repo2", "webhook2-2", Set(WebHook.PullRequest)) - service.addWebHook("user3", "repo3", "webhook3-1", Set(WebHook.PullRequest)) - service.addWebHook("user3", "repo3", "webhook3-2", Set(WebHook.PullRequest)) + test("WebHookPullRequestService.getPullRequestsByRequestForWebhook") { withTestDB { implicit session => + val user1 = generateNewUserWithDBRepository("user1","repo1") + val user2 = generateNewUserWithDBRepository("user2","repo2") + val user3 = generateNewUserWithDBRepository("user3","repo3") + val issueUser = user("root") + val (issue1, pullreq1) = generateNewPullRequest("user1/repo1/master1", "user2/repo2/master2", loginUser="root") + val (issue3, pullreq3) = generateNewPullRequest("user3/repo3/master3", "user2/repo2/master2", loginUser="root") + val (issue32, pullreq32) = generateNewPullRequest("user3/repo3/master32", "user2/repo2/master2", loginUser="root") + generateNewPullRequest("user2/repo2/master2", "user1/repo1/master2") + service.addWebHook("user1", "repo1", "webhook1-1", Set(WebHook.PullRequest)) + service.addWebHook("user1", "repo1", "webhook1-2", Set(WebHook.PullRequest)) + service.addWebHook("user2", "repo2", "webhook2-1", Set(WebHook.PullRequest)) + service.addWebHook("user2", "repo2", "webhook2-2", Set(WebHook.PullRequest)) + service.addWebHook("user3", "repo3", "webhook3-1", Set(WebHook.PullRequest)) + service.addWebHook("user3", "repo3", "webhook3-2", Set(WebHook.PullRequest)) - service.getPullRequestsByRequestForWebhook("user1","repo1","master1") must_== Map.empty + assert(service.getPullRequestsByRequestForWebhook("user1","repo1","master1") == Map.empty) - var r = service.getPullRequestsByRequestForWebhook("user2","repo2","master2").mapValues(_.map(_.url).toSet) + val r = service.getPullRequestsByRequestForWebhook("user2","repo2","master2").mapValues(_.map(_.url).toSet) - r.size must_== 3 - r((issue1, issueUser, pullreq1, user1, user2)) must_== Set("webhook1-1","webhook1-2") - r((issue3, issueUser, pullreq3, user3, user2)) must_== Set("webhook3-1","webhook3-2") - r((issue32, issueUser, pullreq32, user3, user2)) must_== Set("webhook3-1","webhook3-2") + assert(r.size == 3) + assert(r((issue1, issueUser, pullreq1, user1, user2)) == Set("webhook1-1","webhook1-2")) + assert(r((issue3, issueUser, pullreq3, user3, user2)) == Set("webhook3-1","webhook3-2")) + assert(r((issue32, issueUser, pullreq32, user3, user2)) == Set("webhook3-1","webhook3-2")) - // when closed, it not founds. - service.updateClosed("user1","repo1",issue1.issueId, true) + // when closed, it not founds. + service.updateClosed("user1","repo1",issue1.issueId, true) - var r2 = service.getPullRequestsByRequestForWebhook("user2","repo2","master2").mapValues(_.map(_.url).toSet) - r2.size must_== 2 - r2((issue3, issueUser, pullreq3, user3, user2)) must_== Set("webhook3-1","webhook3-2") - r2((issue32, issueUser, pullreq32, user3, user2)) must_== Set("webhook3-1","webhook3-2") - } } - } + val r2 = service.getPullRequestsByRequestForWebhook("user2","repo2","master2").mapValues(_.map(_.url).toSet) + assert(r2.size == 2) + assert(r2((issue3, issueUser, pullreq3, user3, user2)) == Set("webhook3-1","webhook3-2")) + assert(r2((issue32, issueUser, pullreq32, user3, user2)) == Set("webhook3-1","webhook3-2")) + } } - "add and get and update and delete" in { withTestDB { implicit session => + test("add and get and update and delete") { withTestDB { implicit session => val user1 = generateNewUserWithDBRepository("user1","repo1") service.addWebHook("user1", "repo1", "http://example.com", Set(WebHook.PullRequest)) - service.getWebHooks("user1", "repo1") must_== List((WebHook("user1","repo1","http://example.com"),Set(WebHook.PullRequest))) - service.getWebHook("user1", "repo1", "http://example.com") must_== Some((WebHook("user1","repo1","http://example.com"),Set(WebHook.PullRequest))) - service.getWebHooksByEvent("user1", "repo1", WebHook.PullRequest) must_== List((WebHook("user1","repo1","http://example.com"))) - service.getWebHooksByEvent("user1", "repo1", WebHook.Push) must_== Nil - service.getWebHook("user1", "repo1", "http://example.com2") must_== None - service.getWebHook("user2", "repo1", "http://example.com") must_== None - service.getWebHook("user1", "repo2", "http://example.com") must_== None + assert(service.getWebHooks("user1", "repo1") == List((WebHook("user1","repo1","http://example.com"),Set(WebHook.PullRequest)))) + assert(service.getWebHook("user1", "repo1", "http://example.com") == Some((WebHook("user1","repo1","http://example.com"),Set(WebHook.PullRequest)))) + assert(service.getWebHooksByEvent("user1", "repo1", WebHook.PullRequest) == List((WebHook("user1","repo1","http://example.com")))) + assert(service.getWebHooksByEvent("user1", "repo1", WebHook.Push) == Nil) + assert(service.getWebHook("user1", "repo1", "http://example.com2") == None) + assert(service.getWebHook("user2", "repo1", "http://example.com") == None) + assert(service.getWebHook("user1", "repo2", "http://example.com") == None) service.updateWebHook("user1", "repo1", "http://example.com", Set(WebHook.Push, WebHook.Issues)) - service.getWebHook("user1", "repo1", "http://example.com") must_== Some((WebHook("user1","repo1","http://example.com"),Set(WebHook.Push, WebHook.Issues))) - service.getWebHooksByEvent("user1", "repo1", WebHook.PullRequest) must_== Nil - service.getWebHooksByEvent("user1", "repo1", WebHook.Push) must_== List((WebHook("user1","repo1","http://example.com"))) + assert(service.getWebHook("user1", "repo1", "http://example.com") == Some((WebHook("user1","repo1","http://example.com"),Set(WebHook.Push, WebHook.Issues)))) + assert(service.getWebHooksByEvent("user1", "repo1", WebHook.PullRequest) == Nil) + assert(service.getWebHooksByEvent("user1", "repo1", WebHook.Push) == List((WebHook("user1","repo1","http://example.com")))) service.deleteWebHook("user1", "repo1", "http://example.com") - service.getWebHook("user1", "repo1", "http://example.com") must_== None + assert(service.getWebHook("user1", "repo1", "http://example.com") == None) } } - "getWebHooks, getWebHooksByEvent" in { withTestDB { implicit session => + + test("getWebHooks, getWebHooksByEvent") { withTestDB { implicit session => val user1 = generateNewUserWithDBRepository("user1","repo1") service.addWebHook("user1", "repo1", "http://example.com/1", Set(WebHook.PullRequest)) service.addWebHook("user1", "repo1", "http://example.com/2", Set(WebHook.Push)) service.addWebHook("user1", "repo1", "http://example.com/3", Set(WebHook.PullRequest,WebHook.Push)) - service.getWebHooks("user1", "repo1") must_== List( + assert(service.getWebHooks("user1", "repo1") == List( WebHook("user1","repo1","http://example.com/1")->Set(WebHook.PullRequest), WebHook("user1","repo1","http://example.com/2")->Set(WebHook.Push), - WebHook("user1","repo1","http://example.com/3")->Set(WebHook.PullRequest,WebHook.Push)) - service.getWebHooksByEvent("user1", "repo1", WebHook.PullRequest) must_== List( + WebHook("user1","repo1","http://example.com/3")->Set(WebHook.PullRequest,WebHook.Push))) + assert(service.getWebHooksByEvent("user1", "repo1", WebHook.PullRequest) == List( WebHook("user1","repo1","http://example.com/1"), - WebHook("user1","repo1","http://example.com/3")) + WebHook("user1","repo1","http://example.com/3"))) } } } \ No newline at end of file diff --git a/src/test/scala/gitbucket/core/util/StringUtilSpec.scala b/src/test/scala/gitbucket/core/util/StringUtilSpec.scala index 1ccc6ec..f5e850e 100644 --- a/src/test/scala/gitbucket/core/util/StringUtilSpec.scala +++ b/src/test/scala/gitbucket/core/util/StringUtilSpec.scala @@ -1,6 +1,5 @@ package gitbucket.core.util -//import org.specs2.mutable._ import org.scalatest.FunSpec class StringUtilSpec extends FunSpec { diff --git a/src/test/scala/gitbucket/core/view/HelpersSpec.scala b/src/test/scala/gitbucket/core/view/HelpersSpec.scala index 80d7eee..ee5ea0c 100644 --- a/src/test/scala/gitbucket/core/view/HelpersSpec.scala +++ b/src/test/scala/gitbucket/core/view/HelpersSpec.scala @@ -1,59 +1,59 @@ package gitbucket.core.view -import org.specs2.mutable._ +import org.scalatest.FunSpec -class HelpersSpec extends Specification { +class HelpersSpec extends FunSpec { import helpers._ - "detect and render links" should { + describe("detect and render links") { - "pass identical string when no link is present" in { + it("should pass identical string when no link is present") { val before = "Description" val after = detectAndRenderLinks(before).toString() - after mustEqual before + assert(after == before) } - "convert a single link" in { + it("should convert a single link") { val before = "http://example.com" val after = detectAndRenderLinks(before).toString() - after mustEqual """http://example.com""" + assert(after == """http://example.com""") } - "convert a single link within trailing text" in { + it("should convert a single link within trailing text") { val before = "Example Project. http://example.com" val after = detectAndRenderLinks(before).toString() - after mustEqual """Example Project. http://example.com""" + assert(after == """Example Project. http://example.com""") } - "convert a mulitple links within text" in { + it("should convert a mulitple links within text") { val before = "Example Project. http://example.com. (See also https://github.com/)" val after = detectAndRenderLinks(before).toString() - after mustEqual """Example Project. http://example.com. (See also https://github.com/)""" + assert(after == """Example Project. http://example.com. (See also https://github.com/)""") } - "properly escape html metacharacters" in { + it("should properly escape html metacharacters") { val before = "<>&" val after = detectAndRenderLinks(before).toString() - after mustEqual """<>&""" + assert(after == """<>&""") } - "escape html metacharacters adjacent to a link" in { + it("should escape html metacharacters adjacent to a link") { val before = "" val after = detectAndRenderLinks(before).toString() - after mustEqual """<http://example.com>""" + assert(after == """<http://example.com>""") } - "stop link recognition at a metacharacter" in { + it("should stop link recognition at a metacharacter") { val before = "http://exahttp://exa<mple.com""" + assert(after == """http://exa<mple.com""") } - "make sure there are no double quotes in the href attribute" in { + it("should make sure there are no double quotes in the href attribute") { val before = "http://exa\"mple.com" val after = detectAndRenderLinks(before).toString() - after mustEqual """http://exa"mple.com""" + assert(after == """http://exa"mple.com""") } } } diff --git a/src/test/scala/gitbucket/core/view/MarkdownSpec.scala b/src/test/scala/gitbucket/core/view/MarkdownSpec.scala index a2ec2e9..54e437c 100644 --- a/src/test/scala/gitbucket/core/view/MarkdownSpec.scala +++ b/src/test/scala/gitbucket/core/view/MarkdownSpec.scala @@ -1,92 +1,92 @@ package gitbucket.core.view -import org.specs2.mutable._ +import org.scalatest.FunSpec -class MarkdownSpec extends Specification { +class MarkdownSpec extends FunSpec { import Markdown._ - "generateAnchorName" should { - "convert whitespace characters to hyphens" in { + describe("generateAnchorName") { + it("should convert whitespace characters to hyphens") { val before = "foo bar baz" val after = generateAnchorName(before) - after mustEqual "foo-bar-baz" + assert(after == "foo-bar-baz") } - "normalize characters with diacritics" in { + it("should normalize characters with diacritics") { val before = "Dónde estará mi vida" val after = generateAnchorName(before) - after mustEqual "do%cc%81nde-estara%cc%81-mi-vida" + assert(after == "do%cc%81nde-estara%cc%81-mi-vida") } - "omit special characters" in { + it("should omit special characters") { val before = "foo!bar@baz>9000" val after = generateAnchorName(before) - after mustEqual "foo%21bar%40baz%3e9000" + assert(after == "foo%21bar%40baz%3e9000") } } - "escapeTaskList" should { - "convert '- [ ] ' to '* task: :'" in { + describe("escapeTaskList") { + it("should convert '- [ ] ' to '* task: :'") { val before = "- [ ] aaaa" val after = escapeTaskList(before) - after mustEqual "* task: : aaaa" + assert(after == "* task: : aaaa") } - "convert ' - [ ] ' to ' * task: :'" in { + it("should convert ' - [ ] ' to ' * task: :'") { val before = " - [ ] aaaa" val after = escapeTaskList(before) - after mustEqual " * task: : aaaa" + assert(after == " * task: : aaaa") } - "convert only first '- [ ] '" in { + it("should convert only first '- [ ] '") { val before = " - [ ] aaaa - [ ] bbb" val after = escapeTaskList(before) - after mustEqual " * task: : aaaa - [ ] bbb" + assert(after == " * task: : aaaa - [ ] bbb") } - "convert '- [x] ' to '* task:x:'" in { + it("should convert '- [x] ' to '* task:x:'") { val before = " - [x] aaaa" val after = escapeTaskList(before) - after mustEqual " * task:x: aaaa" + assert(after == " * task:x: aaaa") } - "convert multi lines" in { + it("should convert multi lines") { val before = """ tasks - [x] aaaa - [ ] bbb """ val after = escapeTaskList(before) - after mustEqual """ + assert(after == """ tasks * task:x: aaaa * task: : bbb -""" +""") } - "no convert if inserted before '- [ ] '" in { + it("should not convert if inserted before '- [ ] '") { val before = " a - [ ] aaaa" val after = escapeTaskList(before) - after mustEqual " a - [ ] aaaa" + assert(after == " a - [ ] aaaa") } - "no convert '- [] '" in { + it("should not convert '- [] '") { val before = " - [] aaaa" val after = escapeTaskList(before) - after mustEqual " - [] aaaa" + assert(after == " - [] aaaa") } - "no convert '- [ ]a'" in { + it("should not convert '- [ ]a'") { val before = " - [ ]a aaaa" val after = escapeTaskList(before) - after mustEqual " - [ ]a aaaa" + assert(after == " - [ ]a aaaa") } - "no convert '-[ ] '" in { + it("should not convert '-[ ] '") { val before = " -[ ] aaaa" val after = escapeTaskList(before) - after mustEqual " -[ ] aaaa" + assert(after == " -[ ] aaaa") } } }