Skip to content

Commit

Permalink
#225 Improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dvoraka committed May 9, 2017
1 parent 6d1cbb5 commit e221591
Showing 1 changed file with 49 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ class ReplicationServiceHelperSpec extends Specification {

def "exists reply"() {
when:
ReplicationMessage request = helper.createExistsRequest(testFilename, testOwner, testId)
ReplicationMessage request = helper.createExistsRequest(
testFilename, testOwner, testId)
result = helper.createExistsReply(request, otherId)

then:
Expand All @@ -66,7 +67,8 @@ class ReplicationServiceHelperSpec extends Specification {

def "status OK reply"() {
when:
ReplicationMessage request = helper.createStatusRequest(testFilename, testOwner, testId)
ReplicationMessage request = helper.createStatusRequest(
testFilename, testOwner, testId)
result = helper.createOkStatusReply(request, otherId)

then:
Expand Down Expand Up @@ -112,7 +114,8 @@ class ReplicationServiceHelperSpec extends Specification {

def "lock success reply"() {
when:
ReplicationMessage request = helper.createLockRequest(testFilename, testOwner, testId, testSequence)
ReplicationMessage request = helper.createLockRequest(
testFilename, testOwner, testId, testSequence)
result = helper.createLockSuccessReply(request, otherId)

then:
Expand All @@ -124,6 +127,23 @@ class ReplicationServiceHelperSpec extends Specification {
result.getOwner() == testOwner
}

def "lock failed reply"() {
when:
ReplicationMessage request = helper.createLockRequest(
testFilename, testOwner, testId, testSequence)
result = helper.createLockFailReply(request, testSequence, otherId)

then:
checkReplyBase(result)
result.getCommand() == Command.LOCK
result.getReplicationStatus() == ReplicationStatus.FAILED

result.getSequence() == testSequence

result.getFilename() == testFilename
result.getOwner() == testOwner
}

def "unlock request"() {
when:
result = helper.createUnlockRequest(testFilename, testOwner, testId, testSequence)
Expand All @@ -134,6 +154,21 @@ class ReplicationServiceHelperSpec extends Specification {
result.getSequence() == testSequence
}

def "unlock success reply"() {
when:
ReplicationMessage request = helper.createUnlockRequest(
testFilename, testOwner, testId, testSequence)
result = helper.createUnlockSuccessReply(request, otherId)

then:
checkReplyBase(result)
result.getCommand() == Command.UNLOCK
result.getReplicationStatus() == ReplicationStatus.OK

result.getFilename() == testFilename
result.getOwner() == testOwner
}

def "sequence request"() {
when:
result = helper.createSequenceRequest(testId)
Expand All @@ -148,6 +183,17 @@ class ReplicationServiceHelperSpec extends Specification {
result.getToId() == null
}

def "sequence reply"() {
when:
ReplicationMessage request = helper.createSequenceRequest(testId)
result = helper.createSequenceReply(request, otherId, testSequence)

then:
checkReplyBase(result)
result.getCommand() == Command.SEQUENCE
result.getSequence() == testSequence
}

void checkRequestBase(ReplicationMessage message) {
assert message.getType() == MessageType.REPLICATION_SERVICE
assert message.getRouting() == MessageRouting.BROADCAST
Expand Down

0 comments on commit e221591

Please sign in to comment.