-
-
Notifications
You must be signed in to change notification settings - Fork 481
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(pact-jvm-server): Add tests for ListServers handler
- Loading branch information
1 parent
ca29ef0
commit 21c9978
Showing
2 changed files
with
79 additions
and
2 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
pact-jvm-server/src/test/groovy/au/com/dius/pact/server/ListServersSpec.groovy
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,63 @@ | ||
package au.com.dius.pact.server | ||
|
||
import spock.lang.Specification | ||
import static scala.collection.JavaConverters.mapAsScalaMap | ||
|
||
class ListServersSpec extends Specification { | ||
def 'empty state'() { | ||
given: | ||
def state = [:] | ||
|
||
when: | ||
def result = ListServers.apply(mapAsScalaMap(state).toMap()) | ||
|
||
then: | ||
result.response().status == 200 | ||
result.response().body.valueAsString() == '{"ports": [], "paths": []}' | ||
} | ||
|
||
def 'with single Mock server'() { | ||
given: | ||
def state = [ | ||
'1234': Mock(StatefulMockProvider) | ||
] | ||
|
||
when: | ||
def result = ListServers.apply(mapAsScalaMap(state).toMap()) | ||
|
||
then: | ||
result.response().status == 200 | ||
result.response().body.valueAsString() == '{"ports": [1234], "paths": []}' | ||
} | ||
|
||
def 'with single Mock server with a path'() { | ||
given: | ||
def state = [ | ||
'/path': Mock(StatefulMockProvider) | ||
] | ||
|
||
when: | ||
def result = ListServers.apply(mapAsScalaMap(state).toMap()) | ||
|
||
then: | ||
result.response().status == 200 | ||
result.response().body.valueAsString() == '{"ports": [], "paths": ["/path"]}' | ||
} | ||
|
||
def 'with multiple Mock servers'() { | ||
given: | ||
def state = [ | ||
'1234': Mock(StatefulMockProvider), | ||
'/path': Mock(StatefulMockProvider), | ||
'8765': Mock(StatefulMockProvider), | ||
'/other-path': Mock(StatefulMockProvider) | ||
] | ||
|
||
when: | ||
def result = ListServers.apply(mapAsScalaMap(state).toMap()) | ||
|
||
then: | ||
result.response().status == 200 | ||
result.response().body.valueAsString() == '{"ports": [1234, 8765], "paths": ["/path", "/other-path"]}' | ||
} | ||
} |
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