-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(solace-message-client): support subscriptions with #share and #no…
…export For more information, refer to: - https://docs.solace.com/Messaging/Direct-Msg/Direct-Messages.htm - https://docs.solace.com/Messaging/No-Export.htm
- Loading branch information
1 parent
7449afb
commit fa161bc
Showing
4 changed files
with
111 additions
and
79 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
136 changes: 77 additions & 59 deletions
136
projects/solace-message-client/src/lib/topic-matcher.spec.ts
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 |
---|---|---|
@@ -1,89 +1,107 @@ | ||
import {TestBed} from '@angular/core/testing'; | ||
import {TopicMatcher} from './topic-matcher'; | ||
|
||
describe('SolaceMessageClient', () => { | ||
|
||
let testee: TopicMatcher; | ||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
providers: [ | ||
TopicMatcher, | ||
], | ||
}); | ||
testee = TestBed.inject(TopicMatcher); | ||
}); | ||
|
||
it('should not match a `null` topic', () => { | ||
expect(testee.matchesSubscriptionTopic(null, 'a/b/c')).toBeFalse(); | ||
it('should not match a `undefined` topic', () => { | ||
expect(new TopicMatcher('a/b/c').matches(undefined)).toBeFalse(); | ||
}); | ||
|
||
it('should not match an empty topic', () => { | ||
expect(testee.matchesSubscriptionTopic('', 'a/b/c')).toBeFalse(); | ||
expect(new TopicMatcher('a/b/c').matches('')).toBeFalse(); | ||
}); | ||
|
||
it('should match when publishing a message to the exact topic \'a\'', () => { | ||
expect(testee.matchesSubscriptionTopic('a', 'a')).toBeTrue(); | ||
expect(new TopicMatcher('a').matches('a')).toBeTrue(); | ||
}); | ||
|
||
it('should match when publishing a message to the topic with #share and #noexport', () => { | ||
expect(new TopicMatcher('#share/sharename/a').matches('a')).toBeTrue(); | ||
expect(new TopicMatcher('#share/sharename/a').matches('b')).toBeFalse(); | ||
|
||
expect(new TopicMatcher('#noexport/a').matches('a')).toBeTrue(); | ||
expect(new TopicMatcher('#noexport/a').matches('b')).toBeFalse(); | ||
|
||
expect(new TopicMatcher('#noexport/#share/sharename/a').matches('a')).toBeTrue(); | ||
expect(new TopicMatcher('#noexport/#share/sharename/a').matches('b')).toBeFalse(); | ||
|
||
expect(new TopicMatcher('#share/sharename/a/*/b').matches('a/x/b')).toBeTrue(); | ||
expect(new TopicMatcher('#share/sharename/a/*/b').matches('a/x/c')).toBeFalse(); | ||
|
||
expect(new TopicMatcher('#noexport/a/*/b').matches('a/x/b')).toBeTrue(); | ||
expect(new TopicMatcher('#noexport/a/*/b').matches('a/x/c')).toBeFalse(); | ||
|
||
expect(new TopicMatcher('#noexport/#share/sharename/a/*/b').matches('a/x/b')).toBeTrue(); | ||
expect(new TopicMatcher('#noexport/#share/sharename/a/*/b').matches('a/x/c')).toBeFalse(); | ||
|
||
expect(new TopicMatcher('#share/sharename/a/>').matches('a/x/b/z')).toBeTrue(); | ||
expect(new TopicMatcher('#share/sharename/a/>').matches('b/x/b/z')).toBeFalse(); | ||
|
||
expect(new TopicMatcher('#noexport/a/>').matches('a/x/b/z')).toBeTrue(); | ||
expect(new TopicMatcher('#noexport/a/>').matches('b/x/b/z')).toBeFalse(); | ||
|
||
expect(new TopicMatcher('#noexport/#share/sharename/a/>').matches('a/x/b/z')).toBeTrue(); | ||
expect(new TopicMatcher('#noexport/#share/sharename/a/b').matches('a/c')).toBeFalse(); | ||
}); | ||
|
||
it('should match when publishing a message to the exact topic \'a/b\'', () => { | ||
expect(testee.matchesSubscriptionTopic('a/b', 'a/b')).toBeTrue(); | ||
expect(new TopicMatcher('a/b').matches('a/b')).toBeTrue(); | ||
}); | ||
|
||
it('should match when publishing a message to the exact topic \'a/b/c\'', () => { | ||
expect(testee.matchesSubscriptionTopic('a/b/c', 'a/b/c')).toBeTrue(); | ||
expect(new TopicMatcher('a/b/c').matches('a/b/c')).toBeTrue(); | ||
}); | ||
|
||
it('should not match the subscription topic \'a/b/c\' when published to the topic \'a\'', () => { | ||
expect(testee.matchesSubscriptionTopic('a', 'a/b/c')).toBeFalse(); | ||
expect(new TopicMatcher('a/b/c').matches('a')).toBeFalse(); | ||
}); | ||
|
||
it('should not match the subscription topic \'a/b/c\' when published to the topic \'a/b\'', () => { | ||
expect(testee.matchesSubscriptionTopic('a/b', 'a/b/c')).toBeFalse(); | ||
expect(new TopicMatcher('a/b/c').matches('a/b')).toBeFalse(); | ||
}); | ||
|
||
it('should not match the subscription topic \'a/b/c\' when published to the topic \'a/b/c/d\'', () => { | ||
expect(testee.matchesSubscriptionTopic('a/b/c/d', 'a/b/c')).toBeFalse(); | ||
expect(new TopicMatcher('a/b/c').matches('a/b/c/d')).toBeFalse(); | ||
}); | ||
|
||
it('should fulfill examples at https://docs.solace.com/PubSub-Basics/Wildcard-Charaters-Topic-Subs.htm', () => { | ||
expect(testee.matchesSubscriptionTopic('animals/domestic/cats', 'animals/domestic/*')).toBeTrue(); | ||
expect(testee.matchesSubscriptionTopic('animals/domestic/dogs', 'animals/domestic/*')).toBeTrue(); | ||
expect(testee.matchesSubscriptionTopic('animals/domestic/dogs/beagles', 'animals/domestic/*')).toBeFalse(); | ||
|
||
expect(testee.matchesSubscriptionTopic('animals/domestic/cats/persian', 'animals/*/cats/*')).toBeTrue(); | ||
expect(testee.matchesSubscriptionTopic('animals/wild/cats/leopard', 'animals/*/cats/*')).toBeTrue(); | ||
expect(testee.matchesSubscriptionTopic('animals/domestic/cats/persian/grey', 'animals/*/cats/*')).toBeFalse(); | ||
expect(testee.matchesSubscriptionTopic('animals/domestic/dogs/beagles', 'animals/*/cats/*')).toBeFalse(); | ||
|
||
expect(testee.matchesSubscriptionTopic('animals/domestic/dog', 'animals/domestic/dog*')).toBeTrue(); | ||
expect(testee.matchesSubscriptionTopic('animals/domestic/doggy', 'animals/domestic/dog*')).toBeTrue(); | ||
expect(testee.matchesSubscriptionTopic('animals/domestic/dog/beagle', 'animals/domestic/dog*')).toBeFalse(); | ||
expect(testee.matchesSubscriptionTopic('animals/domestic/cat', 'animals/domestic/dog*')).toBeFalse(); | ||
|
||
expect(testee.matchesSubscriptionTopic('animals/domestic/cats', 'animals/domestic/>')).toBeTrue(); | ||
expect(testee.matchesSubscriptionTopic('animals/domestic/dogs/beagles', 'animals/domestic/>')).toBeTrue(); | ||
expect(testee.matchesSubscriptionTopic('animals', 'animals/domestic/>')).toBeFalse(); | ||
expect(testee.matchesSubscriptionTopic('animals', 'animals/domestic')).toBeFalse(); | ||
expect(testee.matchesSubscriptionTopic('animals', 'animals/Domestic')).toBeFalse(); | ||
|
||
expect(testee.matchesSubscriptionTopic('animals/domestic/cats/tabby/grey', 'animals/*/cats/>')).toBeTrue(); | ||
expect(testee.matchesSubscriptionTopic('animals/wild/cats/leopard', 'animals/*/cats/>')).toBeTrue(); | ||
expect(testee.matchesSubscriptionTopic('animals/domestic/dogs/beagles', 'animals/*/cats/>')).toBeFalse(); | ||
|
||
expect(testee.matchesSubscriptionTopic('my/test/topic', 'my/test/*')).toBeTrue(); | ||
expect(testee.matchesSubscriptionTopic('My/Test/Topic', 'my/test/*')).toBeFalse(); | ||
expect(testee.matchesSubscriptionTopic('my/test', 'my/test/*')).toBeFalse(); | ||
|
||
expect(testee.matchesSubscriptionTopic('animals/red/wild', 'animals/red*/wild')).toBeTrue(); | ||
expect(testee.matchesSubscriptionTopic('animals/reddish/wild', 'animals/red*/wild')).toBeTrue(); | ||
|
||
expect(testee.matchesSubscriptionTopic('animals/*bro', 'animals/*bro')).toBeTrue(); | ||
expect(testee.matchesSubscriptionTopic('animals/bro', 'animals/*bro')).toBeFalse(); | ||
expect(testee.matchesSubscriptionTopic('animals/xbro', 'animals/*bro')).toBeFalse(); | ||
|
||
expect(testee.matchesSubscriptionTopic('animals/br*wn', 'animals/br*wn')).toBeTrue(); | ||
expect(testee.matchesSubscriptionTopic('animals/brown', 'animals/br*wn')).toBeFalse(); | ||
expect(testee.matchesSubscriptionTopic('animals/brwn', 'animals/br*wn')).toBeFalse(); | ||
expect(testee.matchesSubscriptionTopic('animals/brOOwn', 'animals/br*wn')).toBeFalse(); | ||
expect(new TopicMatcher('animals/domestic/*').matches('animals/domestic/cats')).toBeTrue(); | ||
expect(new TopicMatcher('animals/domestic/*').matches('animals/domestic/dogs')).toBeTrue(); | ||
expect(new TopicMatcher('animals/domestic/*').matches('animals/domestic/dogs/beagles')).toBeFalse(); | ||
|
||
expect(new TopicMatcher('animals/*/cats/*').matches('animals/domestic/cats/persian')).toBeTrue(); | ||
expect(new TopicMatcher('animals/*/cats/*').matches('animals/wild/cats/leopard')).toBeTrue(); | ||
expect(new TopicMatcher('animals/*/cats/*').matches('animals/domestic/cats/persian/grey')).toBeFalse(); | ||
expect(new TopicMatcher('animals/*/cats/*').matches('animals/domestic/dogs/beagles')).toBeFalse(); | ||
|
||
expect(new TopicMatcher('animals/domestic/dog*').matches('animals/domestic/dog')).toBeTrue(); | ||
expect(new TopicMatcher('animals/domestic/dog*').matches('animals/domestic/doggy')).toBeTrue(); | ||
expect(new TopicMatcher('animals/domestic/dog*').matches('animals/domestic/dog/beagle')).toBeFalse(); | ||
expect(new TopicMatcher('animals/domestic/dog*').matches('animals/domestic/cat')).toBeFalse(); | ||
|
||
expect(new TopicMatcher('animals/domestic/>').matches('animals/domestic/cats')).toBeTrue(); | ||
expect(new TopicMatcher('animals/domestic/>').matches('animals/domestic/dogs/beagles')).toBeTrue(); | ||
expect(new TopicMatcher('animals/domestic/>').matches('animals')).toBeFalse(); | ||
expect(new TopicMatcher('animals/domestic').matches('animals')).toBeFalse(); | ||
expect(new TopicMatcher('animals/Domestic').matches('animals')).toBeFalse(); | ||
|
||
expect(new TopicMatcher('animals/*/cats/>').matches('animals/domestic/cats/tabby/grey')).toBeTrue(); | ||
expect(new TopicMatcher('animals/*/cats/>').matches('animals/wild/cats/leopard')).toBeTrue(); | ||
expect(new TopicMatcher('animals/*/cats/>').matches('animals/domestic/dogs/beagles')).toBeFalse(); | ||
|
||
expect(new TopicMatcher('my/test/*').matches('my/test/topic')).toBeTrue(); | ||
expect(new TopicMatcher('my/test/*').matches('My/Test/Topic')).toBeFalse(); | ||
expect(new TopicMatcher('my/test/*').matches('my/test')).toBeFalse(); | ||
|
||
expect(new TopicMatcher('animals/red*/wild').matches('animals/red/wild')).toBeTrue(); | ||
expect(new TopicMatcher('animals/red*/wild').matches('animals/reddish/wild')).toBeTrue(); | ||
|
||
expect(new TopicMatcher('animals/*bro').matches('animals/*bro')).toBeTrue(); | ||
expect(new TopicMatcher('animals/*bro').matches('animals/bro')).toBeFalse(); | ||
expect(new TopicMatcher('animals/*bro').matches('animals/xbro')).toBeFalse(); | ||
|
||
expect(new TopicMatcher('animals/br*wn').matches('animals/br*wn')).toBeTrue(); | ||
expect(new TopicMatcher('animals/br*wn').matches('animals/brown')).toBeFalse(); | ||
expect(new TopicMatcher('animals/br*wn').matches('animals/brwn')).toBeFalse(); | ||
expect(new TopicMatcher('animals/br*wn').matches('animals/brOOwn')).toBeFalse(); | ||
}); | ||
}); |
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
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