subscription.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. var client = null;
  2. module("Stomp Subscription", {
  3. setup: function() {
  4. client = Stomp.client(TEST.url);
  5. client.debug = TEST.debug;
  6. },
  7. teardown: function() {
  8. client.disconnect();
  9. }
  10. });
  11. test("Should receive messages sent to destination after subscribing", 1, function() {
  12. var msg = 'Is anybody out there?';
  13. client.connect(TEST.login, TEST.password, function() {
  14. client.subscribe(TEST.destination, function(frame) {
  15. start();
  16. equals(frame.body, msg);
  17. });
  18. client.send(TEST.destination, {}, msg);
  19. });
  20. stop(TEST.timeout);
  21. });
  22. test("Should no longer receive messages after unsubscribing to destination", 1, function() {
  23. var msg1 = 'Calling all cars!',
  24. subscription1 = null,
  25. subscription2 = null;
  26. client.connect(TEST.login, TEST.password, function() {
  27. subscription1 = client.subscribe(TEST.destination, function(frame) {
  28. start();
  29. ok(false, 'Should not have received message!');
  30. });
  31. subscription2 = client.subscribe(TEST.destination, function(frame) {
  32. start();
  33. equals(frame.body, msg1);
  34. });
  35. subscription1.unsubscribe();
  36. client.send(TEST.destination, {}, msg1);
  37. });
  38. stop(TEST.timeout);
  39. });