message.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. module("Stomp Message");
  2. test("Send and receive a message", function() {
  3. var body = Math.random();
  4. var client = Stomp.client(TEST.url);
  5. client.debug = TEST.debug;
  6. client.connect(TEST.login, TEST.password,
  7. function() {
  8. client.subscribe(TEST.destination, function(message)
  9. {
  10. start();
  11. equals(message.body, body);
  12. client.disconnect();
  13. });
  14. client.send(TEST.destination, {}, body);
  15. });
  16. stop(TEST.timeout);
  17. });
  18. test("Send and receive a message with a JSON body", function() {
  19. var client = Stomp.client(TEST.url);
  20. var payload = {text: "hello", bool: true, value: Math.random()};
  21. client.connect(TEST.login, TEST.password,
  22. function() {
  23. client.subscribe(TEST.destination, function(message)
  24. {
  25. start();
  26. var res = JSON.parse(message.body);
  27. equals(res.text, payload.text);
  28. equals(res.bool, payload.bool);
  29. equals(res.value, payload.value);
  30. client.disconnect();
  31. });
  32. client.send(TEST.destination, {}, JSON.stringify(payload));
  33. });
  34. stop(TEST.timeout);
  35. });