-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e5fd51e
commit 662ac2f
Showing
1 changed file
with
90 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import "package:test/test.dart"; | ||
import "package:wampproto/messages.dart" as msg; | ||
import "package:wampproto/serializers.dart"; | ||
|
||
import "package:xconn/exports.dart"; | ||
|
||
void main() { | ||
const testProcedure = "io.xconn.test_procedure"; | ||
const testTopic = "io.xconn.test_topic"; | ||
|
||
var callee = LocalBaseSession(1, "realm1", "john", "anonymous", JSONSerializer()); | ||
var caller = LocalBaseSession(2, "realm1", "wick", "anonymous", JSONSerializer()); | ||
|
||
var router = Router() | ||
..addRealm("realm1") | ||
..attachClient(callee) | ||
..attachClient(caller); | ||
|
||
late int registrationID; | ||
|
||
test("register", () async { | ||
var registerMsg = msg.Register(3, testProcedure); | ||
await router.receiveMessage(callee, registerMsg); | ||
|
||
var registered = await callee.receiveMessage(); | ||
expect(registered, isA<msg.Registered>()); | ||
|
||
registrationID = (registered as msg.Registered).registrationID; | ||
}); | ||
|
||
test("call", () async { | ||
var callMsg = msg.Call(4, testProcedure); | ||
await router.receiveMessage(caller, callMsg); | ||
|
||
var invocation = await callee.receiveMessage(); | ||
expect(invocation, isA<msg.Invocation>()); | ||
|
||
var requestID = (invocation as msg.Invocation).requestID; | ||
var yieldMsg = msg.Yield(requestID); | ||
await router.receiveMessage(callee, yieldMsg); | ||
|
||
var result = await caller.receiveMessage(); | ||
expect(result, isA<msg.Result>()); | ||
}); | ||
|
||
test("unregister", () async { | ||
var unregisterMsg = msg.UnRegister(5, registrationID); | ||
await router.receiveMessage(callee, unregisterMsg); | ||
|
||
var unregistered = await callee.receiveMessage(); | ||
expect(unregistered, isA<msg.UnRegistered>()); | ||
}); | ||
|
||
late int subscriptionID; | ||
|
||
test("subscribe", () async { | ||
var subscribeMsg = msg.Subscribe(6, testTopic); | ||
await router.receiveMessage(callee, subscribeMsg); | ||
|
||
var subscribed = await callee.receiveMessage(); | ||
expect(subscribed, isA<msg.Subscribed>()); | ||
|
||
subscriptionID = (subscribed as msg.Subscribed).subscriptionID; | ||
}); | ||
|
||
test("publish", () async { | ||
var publish = msg.Publish(7, testTopic); | ||
await router.receiveMessage(caller, publish); | ||
|
||
var event = await callee.receiveMessage(); | ||
expect(event, isA<msg.Event>()); | ||
|
||
var publishAck = msg.Publish(8, testTopic, options: {"acknowledge": true}); | ||
await router.receiveMessage(caller, publishAck); | ||
|
||
var eventAck = await callee.receiveMessage(); | ||
expect(eventAck, isA<msg.Event>()); | ||
|
||
var published = await caller.receiveMessage(); | ||
expect(published, isA<msg.Published>()); | ||
}); | ||
|
||
test("unsubscribe", () async { | ||
var unsubscribeMsg = msg.UnSubscribe(9, subscriptionID); | ||
await router.receiveMessage(callee, unsubscribeMsg); | ||
|
||
var unsubscribed = await callee.receiveMessage(); | ||
expect(unsubscribed, isA<msg.UnSubscribed>()); | ||
}); | ||
} |