|
1 |
| -import {TestBed} from '@angular/core/testing'; |
2 | 1 | import {TopicMatcher} from './topic-matcher';
|
3 | 2 |
|
4 | 3 | describe('SolaceMessageClient', () => {
|
5 | 4 |
|
6 |
| - let testee: TopicMatcher; |
7 |
| - beforeEach(() => { |
8 |
| - TestBed.configureTestingModule({ |
9 |
| - providers: [ |
10 |
| - TopicMatcher, |
11 |
| - ], |
12 |
| - }); |
13 |
| - testee = TestBed.inject(TopicMatcher); |
14 |
| - }); |
15 |
| - |
16 |
| - it('should not match a `null` topic', () => { |
17 |
| - expect(testee.matchesSubscriptionTopic(null, 'a/b/c')).toBeFalse(); |
| 5 | + it('should not match a `undefined` topic', () => { |
| 6 | + expect(new TopicMatcher('a/b/c').matches(undefined)).toBeFalse(); |
18 | 7 | });
|
19 | 8 |
|
20 | 9 | it('should not match an empty topic', () => {
|
21 |
| - expect(testee.matchesSubscriptionTopic('', 'a/b/c')).toBeFalse(); |
| 10 | + expect(new TopicMatcher('a/b/c').matches('')).toBeFalse(); |
22 | 11 | });
|
23 | 12 |
|
24 | 13 | it('should match when publishing a message to the exact topic \'a\'', () => {
|
25 |
| - expect(testee.matchesSubscriptionTopic('a', 'a')).toBeTrue(); |
| 14 | + expect(new TopicMatcher('a').matches('a')).toBeTrue(); |
| 15 | + }); |
| 16 | + |
| 17 | + it('should match when publishing a message to the topic with #share and #noexport', () => { |
| 18 | + expect(new TopicMatcher('#share/sharename/a').matches('a')).toBeTrue(); |
| 19 | + expect(new TopicMatcher('#share/sharename/a').matches('b')).toBeFalse(); |
| 20 | + |
| 21 | + expect(new TopicMatcher('#noexport/a').matches('a')).toBeTrue(); |
| 22 | + expect(new TopicMatcher('#noexport/a').matches('b')).toBeFalse(); |
| 23 | + |
| 24 | + expect(new TopicMatcher('#noexport/#share/sharename/a').matches('a')).toBeTrue(); |
| 25 | + expect(new TopicMatcher('#noexport/#share/sharename/a').matches('b')).toBeFalse(); |
| 26 | + |
| 27 | + expect(new TopicMatcher('#share/sharename/a/*/b').matches('a/x/b')).toBeTrue(); |
| 28 | + expect(new TopicMatcher('#share/sharename/a/*/b').matches('a/x/c')).toBeFalse(); |
| 29 | + |
| 30 | + expect(new TopicMatcher('#noexport/a/*/b').matches('a/x/b')).toBeTrue(); |
| 31 | + expect(new TopicMatcher('#noexport/a/*/b').matches('a/x/c')).toBeFalse(); |
| 32 | + |
| 33 | + expect(new TopicMatcher('#noexport/#share/sharename/a/*/b').matches('a/x/b')).toBeTrue(); |
| 34 | + expect(new TopicMatcher('#noexport/#share/sharename/a/*/b').matches('a/x/c')).toBeFalse(); |
| 35 | + |
| 36 | + expect(new TopicMatcher('#share/sharename/a/>').matches('a/x/b/z')).toBeTrue(); |
| 37 | + expect(new TopicMatcher('#share/sharename/a/>').matches('b/x/b/z')).toBeFalse(); |
| 38 | + |
| 39 | + expect(new TopicMatcher('#noexport/a/>').matches('a/x/b/z')).toBeTrue(); |
| 40 | + expect(new TopicMatcher('#noexport/a/>').matches('b/x/b/z')).toBeFalse(); |
| 41 | + |
| 42 | + expect(new TopicMatcher('#noexport/#share/sharename/a/>').matches('a/x/b/z')).toBeTrue(); |
| 43 | + expect(new TopicMatcher('#noexport/#share/sharename/a/b').matches('a/c')).toBeFalse(); |
26 | 44 | });
|
27 | 45 |
|
28 | 46 | it('should match when publishing a message to the exact topic \'a/b\'', () => {
|
29 |
| - expect(testee.matchesSubscriptionTopic('a/b', 'a/b')).toBeTrue(); |
| 47 | + expect(new TopicMatcher('a/b').matches('a/b')).toBeTrue(); |
30 | 48 | });
|
31 | 49 |
|
32 | 50 | it('should match when publishing a message to the exact topic \'a/b/c\'', () => {
|
33 |
| - expect(testee.matchesSubscriptionTopic('a/b/c', 'a/b/c')).toBeTrue(); |
| 51 | + expect(new TopicMatcher('a/b/c').matches('a/b/c')).toBeTrue(); |
34 | 52 | });
|
35 | 53 |
|
36 | 54 | it('should not match the subscription topic \'a/b/c\' when published to the topic \'a\'', () => {
|
37 |
| - expect(testee.matchesSubscriptionTopic('a', 'a/b/c')).toBeFalse(); |
| 55 | + expect(new TopicMatcher('a/b/c').matches('a')).toBeFalse(); |
38 | 56 | });
|
39 | 57 |
|
40 | 58 | it('should not match the subscription topic \'a/b/c\' when published to the topic \'a/b\'', () => {
|
41 |
| - expect(testee.matchesSubscriptionTopic('a/b', 'a/b/c')).toBeFalse(); |
| 59 | + expect(new TopicMatcher('a/b/c').matches('a/b')).toBeFalse(); |
42 | 60 | });
|
43 | 61 |
|
44 | 62 | it('should not match the subscription topic \'a/b/c\' when published to the topic \'a/b/c/d\'', () => {
|
45 |
| - expect(testee.matchesSubscriptionTopic('a/b/c/d', 'a/b/c')).toBeFalse(); |
| 63 | + expect(new TopicMatcher('a/b/c').matches('a/b/c/d')).toBeFalse(); |
46 | 64 | });
|
47 | 65 |
|
48 | 66 | it('should fulfill examples at https://docs.solace.com/PubSub-Basics/Wildcard-Charaters-Topic-Subs.htm', () => {
|
49 |
| - expect(testee.matchesSubscriptionTopic('animals/domestic/cats', 'animals/domestic/*')).toBeTrue(); |
50 |
| - expect(testee.matchesSubscriptionTopic('animals/domestic/dogs', 'animals/domestic/*')).toBeTrue(); |
51 |
| - expect(testee.matchesSubscriptionTopic('animals/domestic/dogs/beagles', 'animals/domestic/*')).toBeFalse(); |
52 |
| - |
53 |
| - expect(testee.matchesSubscriptionTopic('animals/domestic/cats/persian', 'animals/*/cats/*')).toBeTrue(); |
54 |
| - expect(testee.matchesSubscriptionTopic('animals/wild/cats/leopard', 'animals/*/cats/*')).toBeTrue(); |
55 |
| - expect(testee.matchesSubscriptionTopic('animals/domestic/cats/persian/grey', 'animals/*/cats/*')).toBeFalse(); |
56 |
| - expect(testee.matchesSubscriptionTopic('animals/domestic/dogs/beagles', 'animals/*/cats/*')).toBeFalse(); |
57 |
| - |
58 |
| - expect(testee.matchesSubscriptionTopic('animals/domestic/dog', 'animals/domestic/dog*')).toBeTrue(); |
59 |
| - expect(testee.matchesSubscriptionTopic('animals/domestic/doggy', 'animals/domestic/dog*')).toBeTrue(); |
60 |
| - expect(testee.matchesSubscriptionTopic('animals/domestic/dog/beagle', 'animals/domestic/dog*')).toBeFalse(); |
61 |
| - expect(testee.matchesSubscriptionTopic('animals/domestic/cat', 'animals/domestic/dog*')).toBeFalse(); |
62 |
| - |
63 |
| - expect(testee.matchesSubscriptionTopic('animals/domestic/cats', 'animals/domestic/>')).toBeTrue(); |
64 |
| - expect(testee.matchesSubscriptionTopic('animals/domestic/dogs/beagles', 'animals/domestic/>')).toBeTrue(); |
65 |
| - expect(testee.matchesSubscriptionTopic('animals', 'animals/domestic/>')).toBeFalse(); |
66 |
| - expect(testee.matchesSubscriptionTopic('animals', 'animals/domestic')).toBeFalse(); |
67 |
| - expect(testee.matchesSubscriptionTopic('animals', 'animals/Domestic')).toBeFalse(); |
68 |
| - |
69 |
| - expect(testee.matchesSubscriptionTopic('animals/domestic/cats/tabby/grey', 'animals/*/cats/>')).toBeTrue(); |
70 |
| - expect(testee.matchesSubscriptionTopic('animals/wild/cats/leopard', 'animals/*/cats/>')).toBeTrue(); |
71 |
| - expect(testee.matchesSubscriptionTopic('animals/domestic/dogs/beagles', 'animals/*/cats/>')).toBeFalse(); |
72 |
| - |
73 |
| - expect(testee.matchesSubscriptionTopic('my/test/topic', 'my/test/*')).toBeTrue(); |
74 |
| - expect(testee.matchesSubscriptionTopic('My/Test/Topic', 'my/test/*')).toBeFalse(); |
75 |
| - expect(testee.matchesSubscriptionTopic('my/test', 'my/test/*')).toBeFalse(); |
76 |
| - |
77 |
| - expect(testee.matchesSubscriptionTopic('animals/red/wild', 'animals/red*/wild')).toBeTrue(); |
78 |
| - expect(testee.matchesSubscriptionTopic('animals/reddish/wild', 'animals/red*/wild')).toBeTrue(); |
79 |
| - |
80 |
| - expect(testee.matchesSubscriptionTopic('animals/*bro', 'animals/*bro')).toBeTrue(); |
81 |
| - expect(testee.matchesSubscriptionTopic('animals/bro', 'animals/*bro')).toBeFalse(); |
82 |
| - expect(testee.matchesSubscriptionTopic('animals/xbro', 'animals/*bro')).toBeFalse(); |
83 |
| - |
84 |
| - expect(testee.matchesSubscriptionTopic('animals/br*wn', 'animals/br*wn')).toBeTrue(); |
85 |
| - expect(testee.matchesSubscriptionTopic('animals/brown', 'animals/br*wn')).toBeFalse(); |
86 |
| - expect(testee.matchesSubscriptionTopic('animals/brwn', 'animals/br*wn')).toBeFalse(); |
87 |
| - expect(testee.matchesSubscriptionTopic('animals/brOOwn', 'animals/br*wn')).toBeFalse(); |
| 67 | + expect(new TopicMatcher('animals/domestic/*').matches('animals/domestic/cats')).toBeTrue(); |
| 68 | + expect(new TopicMatcher('animals/domestic/*').matches('animals/domestic/dogs')).toBeTrue(); |
| 69 | + expect(new TopicMatcher('animals/domestic/*').matches('animals/domestic/dogs/beagles')).toBeFalse(); |
| 70 | + |
| 71 | + expect(new TopicMatcher('animals/*/cats/*').matches('animals/domestic/cats/persian')).toBeTrue(); |
| 72 | + expect(new TopicMatcher('animals/*/cats/*').matches('animals/wild/cats/leopard')).toBeTrue(); |
| 73 | + expect(new TopicMatcher('animals/*/cats/*').matches('animals/domestic/cats/persian/grey')).toBeFalse(); |
| 74 | + expect(new TopicMatcher('animals/*/cats/*').matches('animals/domestic/dogs/beagles')).toBeFalse(); |
| 75 | + |
| 76 | + expect(new TopicMatcher('animals/domestic/dog*').matches('animals/domestic/dog')).toBeTrue(); |
| 77 | + expect(new TopicMatcher('animals/domestic/dog*').matches('animals/domestic/doggy')).toBeTrue(); |
| 78 | + expect(new TopicMatcher('animals/domestic/dog*').matches('animals/domestic/dog/beagle')).toBeFalse(); |
| 79 | + expect(new TopicMatcher('animals/domestic/dog*').matches('animals/domestic/cat')).toBeFalse(); |
| 80 | + |
| 81 | + expect(new TopicMatcher('animals/domestic/>').matches('animals/domestic/cats')).toBeTrue(); |
| 82 | + expect(new TopicMatcher('animals/domestic/>').matches('animals/domestic/dogs/beagles')).toBeTrue(); |
| 83 | + expect(new TopicMatcher('animals/domestic/>').matches('animals')).toBeFalse(); |
| 84 | + expect(new TopicMatcher('animals/domestic').matches('animals')).toBeFalse(); |
| 85 | + expect(new TopicMatcher('animals/Domestic').matches('animals')).toBeFalse(); |
| 86 | + |
| 87 | + expect(new TopicMatcher('animals/*/cats/>').matches('animals/domestic/cats/tabby/grey')).toBeTrue(); |
| 88 | + expect(new TopicMatcher('animals/*/cats/>').matches('animals/wild/cats/leopard')).toBeTrue(); |
| 89 | + expect(new TopicMatcher('animals/*/cats/>').matches('animals/domestic/dogs/beagles')).toBeFalse(); |
| 90 | + |
| 91 | + expect(new TopicMatcher('my/test/*').matches('my/test/topic')).toBeTrue(); |
| 92 | + expect(new TopicMatcher('my/test/*').matches('My/Test/Topic')).toBeFalse(); |
| 93 | + expect(new TopicMatcher('my/test/*').matches('my/test')).toBeFalse(); |
| 94 | + |
| 95 | + expect(new TopicMatcher('animals/red*/wild').matches('animals/red/wild')).toBeTrue(); |
| 96 | + expect(new TopicMatcher('animals/red*/wild').matches('animals/reddish/wild')).toBeTrue(); |
| 97 | + |
| 98 | + expect(new TopicMatcher('animals/*bro').matches('animals/*bro')).toBeTrue(); |
| 99 | + expect(new TopicMatcher('animals/*bro').matches('animals/bro')).toBeFalse(); |
| 100 | + expect(new TopicMatcher('animals/*bro').matches('animals/xbro')).toBeFalse(); |
| 101 | + |
| 102 | + expect(new TopicMatcher('animals/br*wn').matches('animals/br*wn')).toBeTrue(); |
| 103 | + expect(new TopicMatcher('animals/br*wn').matches('animals/brown')).toBeFalse(); |
| 104 | + expect(new TopicMatcher('animals/br*wn').matches('animals/brwn')).toBeFalse(); |
| 105 | + expect(new TopicMatcher('animals/br*wn').matches('animals/brOOwn')).toBeFalse(); |
88 | 106 | });
|
89 | 107 | });
|
0 commit comments