Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Interoperablity tests for RPC messages #111

Merged
merged 7 commits into from
Jul 3, 2024
Merged
57 changes: 57 additions & 0 deletions test/interoptests/messages/invocation_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import "package:collection/collection.dart";
import "package:pinenacl/encoding.dart";
import "package:test/test.dart";

import "package:wampproto/messages.dart";
import "package:wampproto/serializers.dart";

import "../helper.dart";

void main() {
group("Invocation", () {
const equality = DeepCollectionEquality();

bool isEqual(Invocation msg1, Invocation msg2) =>
msg1.requestID == msg2.requestID &&
msg1.registrationID == msg2.registrationID &&
equality.equals(msg1.details, msg2.details) &&
equality.equals(msg1.args, msg2.args) &&
equality.equals(msg1.kwargs, msg2.kwargs);

test("JSONSerializer", () async {
var msg = Invocation(1, 1);
var command = "message invocation ${msg.requestID} ${msg.registrationID} --serializer json";

var output = await runCommand(command);

var jsonSerializer = JSONSerializer();
var message = jsonSerializer.deserialize(output) as Invocation;
expect(isEqual(message, msg), true);
});

test("CBORSerializer", () async {
var msg = Invocation(1, 1, args: ["abc"]);
var command = "message invocation ${msg.requestID} ${msg.registrationID} abc --serializer cbor --output hex";

var output = await runCommand(command);
var outputBytes = Base16Encoder.instance.decode(output.trim());

var cborSerializer = CBORSerializer();
var message = cborSerializer.deserialize(outputBytes) as Invocation;
expect(isEqual(message, msg), true);
});

test("MsgPackSerializer", () async {
var msg = Invocation(1, 1, args: ["abc"], kwargs: {"a": 1});
var command =
"message invocation ${msg.requestID} ${msg.registrationID} abc -k a=1 --serializer msgpack --output hex";

var output = await runCommand(command);
var outputBytes = Base16Encoder.instance.decode(output.trim());

var msgPackSerializer = MsgPackSerializer();
var message = msgPackSerializer.deserialize(outputBytes) as Invocation;
expect(isEqual(message, msg), true);
});
});
}
53 changes: 53 additions & 0 deletions test/interoptests/messages/register_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import "package:collection/collection.dart";
import "package:pinenacl/encoding.dart";
import "package:test/test.dart";

import "package:wampproto/messages.dart";
import "package:wampproto/serializers.dart";

import "../helper.dart";

void main() {
group("Register", () {
const equality = DeepCollectionEquality();
const testProcedure = "io.xconn.test";

bool isEqual(Register msg1, Register msg2) =>
msg1.requestID == msg2.requestID && msg1.uri == msg2.uri && equality.equals(msg1.options, msg2.options);

test("JSONSerializer", () async {
var msg = Register(1, testProcedure);
var command = "message register ${msg.requestID} ${msg.uri} --serializer json";

var output = await runCommand(command);

var jsonSerializer = JSONSerializer();
var message = jsonSerializer.deserialize(output) as Register;
expect(isEqual(message, msg), true);
});

test("CBORSerializer", () async {
var msg = Register(1, testProcedure);
var command = "message register ${msg.requestID} ${msg.uri} --serializer cbor --output hex";

var output = await runCommand(command);
var outputBytes = Base16Encoder.instance.decode(output.trim());

var cborSerializer = CBORSerializer();
var message = cborSerializer.deserialize(outputBytes) as Register;
expect(isEqual(message, msg), true);
});

test("MsgPackSerializer", () async {
var msg = Register(1, testProcedure, options: {"a": 1});
var command = "message register ${msg.requestID} ${msg.uri} -o a=1 --serializer msgpack --output hex";

var output = await runCommand(command);
var outputBytes = Base16Encoder.instance.decode(output.trim());

var msgPackSerializer = MsgPackSerializer();
var message = msgPackSerializer.deserialize(outputBytes) as Register;
expect(isEqual(message, msg), true);
});
});
}
49 changes: 49 additions & 0 deletions test/interoptests/messages/registered_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import "package:pinenacl/encoding.dart";
import "package:test/test.dart";

import "package:wampproto/messages.dart";
import "package:wampproto/serializers.dart";

import "../helper.dart";

void main() {
group("Registered", () {
bool isEqual(Registered msg1, Registered msg2) =>
msg1.requestID == msg2.requestID && msg1.registrationID == msg2.registrationID;

test("JSONSerializer", () async {
var msg = Registered(1, 1);
var command = "message registered ${msg.requestID} ${msg.registrationID} --serializer json";

var output = await runCommand(command);

var jsonSerializer = JSONSerializer();
var message = jsonSerializer.deserialize(output) as Registered;
expect(isEqual(message, msg), true);
});

test("CBORSerializer", () async {
var msg = Registered(1, 1);
var command = "message registered ${msg.requestID} ${msg.registrationID} --serializer cbor --output hex";

var output = await runCommand(command);
var outputBytes = Base16Encoder.instance.decode(output.trim());

var cborSerializer = CBORSerializer();
var message = cborSerializer.deserialize(outputBytes) as Registered;
expect(isEqual(message, msg), true);
});

test("MsgPackSerializer", () async {
var msg = Registered(1, 1);
var command = "message registered ${msg.requestID} ${msg.registrationID} --serializer msgpack --output hex";

var output = await runCommand(command);
var outputBytes = Base16Encoder.instance.decode(output.trim());

var msgPackSerializer = MsgPackSerializer();
var message = msgPackSerializer.deserialize(outputBytes) as Registered;
expect(isEqual(message, msg), true);
});
});
}
55 changes: 55 additions & 0 deletions test/interoptests/messages/result_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import "package:collection/collection.dart";
import "package:pinenacl/encoding.dart";
import "package:test/test.dart";

import "package:wampproto/messages.dart";
import "package:wampproto/serializers.dart";

import "../helper.dart";

void main() {
group("Result", () {
const equality = DeepCollectionEquality();

bool isEqual(Result msg1, Result msg2) =>
msg1.requestID == msg2.requestID &&
equality.equals(msg1.details, msg2.details) &&
equality.equals(msg1.args, msg2.args) &&
equality.equals(msg1.kwargs, msg2.kwargs);

test("JSONSerializer", () async {
var msg = Result(1);
var command = "message result ${msg.requestID} --serializer json";

var output = await runCommand(command);

var jsonSerializer = JSONSerializer();
var message = jsonSerializer.deserialize(output) as Result;
expect(isEqual(message, msg), true);
});

test("CBORSerializer", () async {
var msg = Result(1, args: ["abc"]);
var command = "message result ${msg.requestID} abc --serializer cbor --output hex";

var output = await runCommand(command);
var outputBytes = Base16Encoder.instance.decode(output.trim());

var cborSerializer = CBORSerializer();
var message = cborSerializer.deserialize(outputBytes) as Result;
expect(isEqual(message, msg), true);
});

test("MsgPackSerializer", () async {
var msg = Result(1, details: {"abc": 1}, args: ["abc"], kwargs: {"a": 1});
var command = "message result ${msg.requestID} abc -d abc=1 -k a=1 --serializer msgpack --output hex";

var output = await runCommand(command);
var outputBytes = Base16Encoder.instance.decode(output.trim());

var msgPackSerializer = MsgPackSerializer();
var message = msgPackSerializer.deserialize(outputBytes) as Result;
expect(isEqual(message, msg), true);
});
});
}
49 changes: 49 additions & 0 deletions test/interoptests/messages/unregister_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import "package:pinenacl/encoding.dart";
import "package:test/test.dart";

import "package:wampproto/messages.dart";
import "package:wampproto/serializers.dart";

import "../helper.dart";

void main() {
group("UnRegister", () {
bool isEqual(UnRegister msg1, UnRegister msg2) =>
msg1.requestID == msg2.requestID && msg1.registrationID == msg2.registrationID;

test("JSONSerializer", () async {
var msg = UnRegister(1, 1);
var command = "message unregister ${msg.requestID} ${msg.registrationID} --serializer json";

var output = await runCommand(command);

var jsonSerializer = JSONSerializer();
var message = jsonSerializer.deserialize(output) as UnRegister;
expect(isEqual(message, msg), true);
});

test("CBORSerializer", () async {
var msg = UnRegister(1, 1);
var command = "message unregister ${msg.requestID} ${msg.registrationID} --serializer cbor --output hex";

var output = await runCommand(command);
var outputBytes = Base16Encoder.instance.decode(output.trim());

var cborSerializer = CBORSerializer();
var message = cborSerializer.deserialize(outputBytes) as UnRegister;
expect(isEqual(message, msg), true);
});

test("MsgPackSerializer", () async {
var msg = UnRegister(1, 1);
var command = "message unregister ${msg.requestID} ${msg.registrationID} --serializer msgpack --output hex";

var output = await runCommand(command);
var outputBytes = Base16Encoder.instance.decode(output.trim());

var msgPackSerializer = MsgPackSerializer();
var message = msgPackSerializer.deserialize(outputBytes) as UnRegister;
expect(isEqual(message, msg), true);
});
});
}
48 changes: 48 additions & 0 deletions test/interoptests/messages/unregistered_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import "package:pinenacl/encoding.dart";
import "package:test/test.dart";

import "package:wampproto/messages.dart";
import "package:wampproto/serializers.dart";

import "../helper.dart";

void main() {
group("UnRegistered", () {
bool isEqual(UnRegistered msg1, UnRegistered msg2) => msg1.requestID == msg2.requestID;

test("JSONSerializer", () async {
var msg = UnRegistered(1);
var command = "message unregistered ${msg.requestID} --serializer json";

var output = await runCommand(command);

var jsonSerializer = JSONSerializer();
var message = jsonSerializer.deserialize(output) as UnRegistered;
expect(isEqual(message, msg), true);
});

test("CBORSerializer", () async {
var msg = UnRegistered(1);
var command = "message unregistered ${msg.requestID} --serializer cbor --output hex";

var output = await runCommand(command);
var outputBytes = Base16Encoder.instance.decode(output.trim());

var cborSerializer = CBORSerializer();
var message = cborSerializer.deserialize(outputBytes) as UnRegistered;
expect(isEqual(message, msg), true);
});

test("MsgPackSerializer", () async {
var msg = UnRegistered(1);
var command = "message unregistered ${msg.requestID} --serializer msgpack --output hex";

var output = await runCommand(command);
var outputBytes = Base16Encoder.instance.decode(output.trim());

var msgPackSerializer = MsgPackSerializer();
var message = msgPackSerializer.deserialize(outputBytes) as UnRegistered;
expect(isEqual(message, msg), true);
});
});
}
55 changes: 55 additions & 0 deletions test/interoptests/messages/yield_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import "package:collection/collection.dart";
import "package:pinenacl/encoding.dart";
import "package:test/test.dart";

import "package:wampproto/messages.dart";
import "package:wampproto/serializers.dart";

import "../helper.dart";

void main() {
group("Yield", () {
const equality = DeepCollectionEquality();

bool isEqual(Yield msg1, Yield msg2) =>
msg1.requestID == msg2.requestID &&
equality.equals(msg1.options, msg2.options) &&
equality.equals(msg1.args, msg2.args) &&
equality.equals(msg1.kwargs, msg2.kwargs);

test("JSONSerializer", () async {
var msg = Yield(1);
var command = "message yield ${msg.requestID} --serializer json";

var output = await runCommand(command);

var jsonSerializer = JSONSerializer();
var message = jsonSerializer.deserialize(output) as Yield;
expect(isEqual(message, msg), true);
});

test("CBORSerializer", () async {
var msg = Yield(1, args: ["abc"]);
var command = "message yield ${msg.requestID} abc --serializer cbor --output hex";

var output = await runCommand(command);
var outputBytes = Base16Encoder.instance.decode(output.trim());

var cborSerializer = CBORSerializer();
var message = cborSerializer.deserialize(outputBytes) as Yield;
expect(isEqual(message, msg), true);
});

test("MsgPackSerializer", () async {
var msg = Yield(1, options: {"abc": 1}, args: ["abc"], kwargs: {"a": 1});
var command = "message yield ${msg.requestID} abc -o abc=1 -k a=1 --serializer msgpack --output hex";

var output = await runCommand(command);
var outputBytes = Base16Encoder.instance.decode(output.trim());

var msgPackSerializer = MsgPackSerializer();
var message = msgPackSerializer.deserialize(outputBytes) as Yield;
expect(isEqual(message, msg), true);
});
});
}