Added tests for Bindings resolver to specifically target failing conditions. Now to fix those failures....

This commit is contained in:
Jim Cowart 2013-03-02 16:32:57 -05:00
parent 51a244c210
commit a2db8ab2d7
6 changed files with 455 additions and 72 deletions

View file

@ -5,14 +5,11 @@
"/": "./"
}
},
"anvil.jshint" : {
"all": true
},
"output": {
"full": "lib",
"partial": {
"**/lib/postal.*" : [ "example/standard/js", "example/amd/js/libs/postal" ]
}
},
"dependencies": [ "anvil.http", "anvil.uglify", "anvil.jshint" ]
"dependencies": [ "anvil.uglify" ]
}

View file

@ -212,7 +212,7 @@
var pattern = ("^" + binding.replace( /\./g, "\\." ) // escape actual periods
.replace( /\*/g, "[A-Z,a-z,0-9]*" ) // asterisks match any alpha-numeric 'word'
.replace( /#/g, ".*" ) + "$") // hash matches 'n' # of words (+ optional on start/end of topic)
.replace( "\\..*$", "(\\..*)*$" ) // fix end of topic matching on hash wildcards
.replace( "\\..*$", "(\\..*)*$" ) // fix end of topic matching on hash wildcards
.replace( "^.*\\.", "^(.*\\.)*" ); // fix beginning of topic matching on hash wildcards
var rgx = new RegExp( pattern );
var result = rgx.test( topic );

2
lib/postal.min.js vendored

File diff suppressed because one or more lines are too long

View file

@ -1,75 +1,459 @@
describe( "amqpBindingsResolver", function () {
describe( "When calling compare", function () {
describe( "With topic Top.Middle.Bottom and binding Top.Middle.Bottom", function () {
var result = bindingsResolver.compare( "Top.Middle.Bottom", "Top.Middle.Bottom" ),
cached = bindingsResolver.cache["Top.Middle.Bottom"]["Top.Middle.Bottom"];
it( "Result should be true", function () {
expect( result ).to.be.ok();
beforeEach(function(){
bindingsResolver.reset();
});
describe("With '*' wildcards", function(){
// Passing matches
describe( "With topic Top.Middle.Bottom and binding *.Middle.Bottom", function () {
var result = bindingsResolver.compare( "*.Middle.Bottom", "Top.Middle.Bottom" ),
cached = bindingsResolver.cache["Top.Middle.Bottom"]["*.Middle.Bottom"];
it( "Result should be true", function () {
expect( result ).to.be.ok();
} );
it( "Should create a resolver cache entry", function () {
expect( cached ).to.be.ok();
} );
} );
it( "Should create a resolver cache entry", function () {
expect( cached ).to.be.ok();
describe( "With topic Top.Middle.Bottom and binding Top.*.Bottom", function () {
var result = bindingsResolver.compare( "Top.*.Bottom", "Top.Middle.Bottom" ),
cached = bindingsResolver.cache["Top.Middle.Bottom"]["Top.*.Bottom"];
it( "Result should be true", function () {
expect( result ).to.be.ok();
} );
it( "Should create a resolver cache entry", function () {
expect( cached ).to.be.ok();
} );
} );
} );
describe( "With topic Top.Middle.Bottom and binding Top.#.Bottom", function () {
var result = bindingsResolver.compare( "Top.#.Bottom", "Top.Middle.Bottom" ),
cached = bindingsResolver.cache["Top.Middle.Bottom"]["Top.#.Bottom"];
it( "Result should be true", function () {
expect( result ).to.be.ok();
describe( "With topic Top.Middle.Bottom and binding Top.Middle.*", function () {
var result = bindingsResolver.compare( "Top.Middle.*", "Top.Middle.Bottom" ),
cached = bindingsResolver.cache["Top.Middle.Bottom"]["Top.Middle.*"];
it( "Result should be true", function () {
expect( result ).to.be.ok();
} );
it( "Should create a resolver cache entry", function () {
expect( cached ).to.be.ok();
} );
} );
it( "Should create a resolver cache entry", function () {
expect( cached ).to.be.ok();
describe( "With topic Top.Middle.Bottom and binding Top.*.*", function () {
var result = bindingsResolver.compare( "Top.*.*", "Top.Middle.Bottom" ),
cached = bindingsResolver.cache["Top.Middle.Bottom"]["Top.*.*"];
it( "Result should be true", function () {
expect( result ).to.be.ok();
} );
it( "Should create a resolver cache entry", function () {
expect( cached ).to.be.ok();
} );
} );
} );
describe( "With topic Top.Middle.SubMiddle.Bottom and binding Top.#.Bottom", function () {
var result = bindingsResolver.compare( "Top.#.Bottom", "Top.Middle.SubMiddle.Bottom" ),
cached = bindingsResolver.cache["Top.Middle.SubMiddle.Bottom"]["Top.#.Bottom"];
it( "Result should be true", function () {
expect( result ).to.be.ok();
} );
it( "Should create a resolver cache entry", function () {
expect( cached ).to.be.ok();
} );
} );
describe( "With topic Top.SubTop.Middle.SubMiddle.Bottom and binding Top.#.Bottom", function () {
var result = bindingsResolver.compare( "Top.#.Bottom", "Top.SubTop.Middle.SubMiddle.Bottom" ),
cached = bindingsResolver.cache["Top.SubTop.Middle.SubMiddle.Bottom"]["Top.#.Bottom"];
it( "Result should be true", function () {
expect( result ).to.be.ok();
} );
it( "Should create a resolver cache entry", function () {
expect( cached ).to.be.ok();
} );
} );
describe( "With topic Top.Middle.Bottom and binding Top.*.Bottom", function () {
var result = bindingsResolver.compare( "Top.*.Bottom", "Top.Middle.Bottom" ),
cached = bindingsResolver.cache["Top.Middle.Bottom"]["Top.*.Bottom"];
it( "Result should be true", function () {
expect( result ).to.be.ok();
describe( "With topic Top.Middle.Bottom and binding Top.*.*", function () {
var result = bindingsResolver.compare( "*.*.Bottom", "Top.Middle.Bottom" ),
cached = bindingsResolver.cache["Top.Middle.Bottom"]["*.*.Bottom"];
it( "Result should be true", function () {
expect( result ).to.be.ok();
} );
it( "Should create a resolver cache entry", function () {
expect( cached ).to.be.ok();
} );
} );
it( "Should create a resolver cache entry", function () {
expect( cached ).to.be.ok();
describe( "With topic Top.Middle.Bottom and binding *.Middle.*", function () {
var result = bindingsResolver.compare( "*.Middle.*", "Top.Middle.Bottom" ),
cached = bindingsResolver.cache["Top.Middle.Bottom"]["*.Middle.*"];
it( "Result should be true", function () {
expect( result ).to.be.ok();
} );
it( "Should create a resolver cache entry", function () {
expect( cached ).to.be.ok();
} );
} );
} );
describe( "With topic Top.Middle.SubMiddle.Bottom and binding Top.*.Bottom", function () {
var result = bindingsResolver.compare( "Top.*.Bottom", "Top.Middle.SubMiddle.Bottom" ),
cached = bindingsResolver.cache["Top.Middle.SubMiddle.Bottom"]["Top.*.Bottom"];
it( "Result should be false", function () {
expect( result ).to.not.be.ok()
} );
it( "Should *not* create a resolver cache entry", function () {
expect( cached ).to.not.be.ok()
} );
} );
describe( "With topic Top.Middle.Bottom and binding #.*.Bottom", function () {
var result = bindingsResolver.compare( "#.*.Bottom", "Top.Middle.Bottom" ),
cached = bindingsResolver.cache["Top.Middle.Bottom"]["#.*.Bottom"];
it( "Result should be true", function () {
expect( result ).to.be.ok();
describe( "With topic Top.Middle.Bottom and binding *.*.*", function () {
var result = bindingsResolver.compare( "*.*.*", "Top.Middle.Bottom" ),
cached = bindingsResolver.cache["Top.Middle.Bottom"]["*.*.*"];
it( "Result should be true", function () {
expect( result ).to.be.ok();
} );
it( "Should create a resolver cache entry", function () {
expect( cached ).to.be.ok();
} );
} );
it( "Should create a resolver cache entry", function () {
expect( cached ).to.be.ok();
// Failing Matches
describe( "With topic Top.Middle.SubMiddle.Bottom and binding *.Middle.Bottom", function () {
var result = bindingsResolver.compare( "*.Middle.Bottom", "Top.Middle.SubMiddle.Bottom" ),
cached = bindingsResolver.cache["Top.Middle.SubMiddle.Bottom"] && bindingsResolver.cache["Top.Middle.SubMiddle.Bottom"]["*.Middle.Bottom"];
it( "Result should be false", function () {
expect( result ).to.not.be.ok()
} );
it( "Should *not* create a resolver cache entry", function () {
expect( cached ).to.not.be.ok()
} );
} );
} );
describe( "With topic Top.Middle.SubMiddle.Bottom and binding Top.*.Bottom", function () {
var result = bindingsResolver.compare( "Top.*.Bottom", "Top.Middle.SubMiddle.Bottom" ),
cached = bindingsResolver.cache["Top.Middle.SubMiddle.Bottom"] && bindingsResolver.cache["Top.Middle.SubMiddle.Bottom"]["Top.*.Bottom"];
it( "Result should be false", function () {
expect( result ).to.not.be.ok()
} );
it( "Should *not* create a resolver cache entry", function () {
expect( cached ).to.not.be.ok()
} );
} );
describe( "With topic Top.Middle.SubMiddle.Bottom and binding Top.Middle.*", function () {
var result = bindingsResolver.compare( "Top.Middle.*", "Top.Middle.SubMiddle.Bottom" ),
cached = bindingsResolver.cache["Top.Middle.SubMiddle.Bottom"] && bindingsResolver.cache["Top.Middle.SubMiddle.Bottom"]["Top.Middle.*"];
it( "Result should be false", function () {
expect( result ).to.not.be.ok();
} );
it( "Should *not* create a resolver cache entry", function () {
expect( cached ).to.not.be.ok();
} );
} );
describe( "With topic Top.Middle.SubMiddle.Bottom and binding Top.*.*", function () {
var result = bindingsResolver.compare( "Top.*.*", "Top.Middle.SubMiddle.Bottom" ),
cached = bindingsResolver.cache["Top.Middle.SubMiddle.Bottom"] && bindingsResolver.cache["Top.Middle.SubMiddle.Bottom"]["Top.*.*"];
it( "Result should be false", function () {
expect( result ).to.not.be.ok();
} );
it( "Should *not* create a resolver cache entry", function () {
expect( cached ).to.not.be.ok();
} );
} );
describe( "With topic Top.Middle.SubMiddle.Bottom and binding Top.*.*", function () {
var result = bindingsResolver.compare( "*.*.Bottom", "Top.Middle.SubMiddle.Bottom" ),
cached = bindingsResolver.cache["Top.Middle.SubMiddle.Bottom"] && bindingsResolver.cache["Top.Middle.SubMiddle.Bottom"]["*.*.Bottom"];
it( "Result should be false", function () {
expect( result ).to.not.be.ok();
} );
it( "Should *not* create a resolver cache entry", function () {
expect( cached ).to.not.be.ok();
} );
} );
describe( "With topic Top.Middle.SubMiddle.Bottom and binding *.Middle.*", function () {
var result = bindingsResolver.compare( "*.Middle.*", "Top.Middle.SubMiddle.Bottom" ),
cached = bindingsResolver.cache["Top.Middle.SubMiddle.Bottom"] && bindingsResolver.cache["Top.Middle.SubMiddle.Bottom"]["*.Middle.*"];
it( "Result should be false", function () {
expect( result ).to.not.be.ok();
} );
it( "Should *not* create a resolver cache entry", function () {
expect( cached ).to.not.be.ok();
} );
} );
describe( "With topic Top.Middle.SubMiddle.Bottom and binding *.*.*", function () {
var result = bindingsResolver.compare( "*.*.*", "Top.Middle.SubMiddle.Bottom" ),
cached = bindingsResolver.cache["Top.Middle.SubMiddle.Bottom"] && bindingsResolver.cache["Top.Middle.SubMiddle.Bottom"]["*.*.*"];
it( "Result should be false", function () {
expect( result ).to.not.be.ok();
} );
it( "Should *not* create a resolver cache entry", function () {
expect( cached ).to.not.be.ok();
} );
} );
});
describe("With '#' wildcards", function(){
// Passing matches
// # at beginning of binding
describe( "With topic Top.Middle.Bottom and binding #.Middle.Bottom", function () {
var result = bindingsResolver.compare( "#.Middle.Bottom", "Top.Middle.Bottom" ),
cached = bindingsResolver.cache["Top.Middle.Bottom"]["#.Middle.Bottom"];
it( "Result should be true", function () {
expect( result ).to.be.ok();
} );
it( "Should create a resolver cache entry", function () {
expect( cached ).to.be.ok();
} );
} );
describe( "With topic Top.SubTop.Middle.Bottom and binding #.Middle.Bottom", function () {
var result = bindingsResolver.compare( "#.Middle.Bottom", "Top.SubTop.Middle.Bottom" ),
cached = bindingsResolver.cache["Top.SubTop.Middle.Bottom"]["#.Middle.Bottom"];
it( "Result should be true", function () {
expect( result ).to.be.ok();
} );
it( "Should create a resolver cache entry", function () {
expect( cached ).to.be.ok();
} );
} );
describe( "With topic Middle.Bottom and binding #.Middle.Bottom", function () {
var result = bindingsResolver.compare( "#.Middle.Bottom", "Middle.Bottom" ),
cached = bindingsResolver.cache["Middle.Bottom"]["#.Middle.Bottom"];
it( "Result should be true", function () {
expect( result ).to.be.ok();
} );
it( "Should create a resolver cache entry", function () {
expect( cached ).to.be.ok();
} );
} );
// # in middle of binding
describe( "With topic Top.Middle.Bottom and binding Top.#.Bottom", function () {
var result = bindingsResolver.compare( "Top.#.Bottom", "Top.Middle.Bottom" ),
cached = bindingsResolver.cache["Top.Middle.Bottom"]["Top.#.Bottom"];
it( "Result should be true", function () {
expect( result ).to.be.ok();
} );
it( "Should create a resolver cache entry", function () {
expect( cached ).to.be.ok();
} );
} );
describe( "With topic Top.Middle.SubMiddle.Bottom and binding Top.#.Bottom", function () {
var result = bindingsResolver.compare( "Top.#.Bottom", "Top.Middle.SubMiddle.Bottom" ),
cached = bindingsResolver.cache["Top.Middle.SubMiddle.Bottom"]["Top.#.Bottom"];
it( "Result should be true", function () {
expect( result ).to.be.ok();
} );
it( "Should create a resolver cache entry", function () {
expect( cached ).to.be.ok();
} );
} );
describe( "With topic Top.SubTop.Middle.SubMiddle.Bottom and binding Top.#.Bottom", function () {
var result = bindingsResolver.compare( "Top.#.Bottom", "Top.SubTop.Middle.SubMiddle.Bottom" ),
cached = bindingsResolver.cache["Top.SubTop.Middle.SubMiddle.Bottom"]["Top.#.Bottom"];
it( "Result should be true", function () {
expect( result ).to.be.ok();
} );
it( "Should create a resolver cache entry", function () {
expect( cached ).to.be.ok();
} );
} );
describe( "With topic Top.Bottom and binding Top.#.Bottom", function () {
var result = bindingsResolver.compare( "Top.#.Bottom", "Top.Bottom" ),
cached = bindingsResolver.cache["Top.Bottom"] && bindingsResolver.cache["Top.Bottom"]["Top.#.Bottom"];
it( "Result should be true", function () {
expect( result ).to.be.ok();
} );
it( "Should create a resolver cache entry", function () {
expect( cached ).to.be.ok();
} );
} );
// # at end of binding
describe( "With topic Top.Middle.Bottom and binding Top.Middle.#", function () {
var result = bindingsResolver.compare( "Top.Middle.#", "Top.Middle.Bottom" ),
cached = bindingsResolver.cache["Top.Middle.Bottom"]["Top.Middle.#"];
it( "Result should be true", function () {
expect( result ).to.be.ok();
} );
it( "Should create a resolver cache entry", function () {
expect( cached ).to.be.ok();
} );
} );
describe( "With topic Top.SubTop.Middle.Bottom and binding Top.SubTop.#", function () {
var result = bindingsResolver.compare( "Top.SubTop.#", "Top.SubTop.Middle.Bottom" ),
cached = bindingsResolver.cache["Top.SubTop.Middle.Bottom"]["Top.SubTop.#"];
it( "Result should be true", function () {
expect( result ).to.be.ok();
} );
it( "Should create a resolver cache entry", function () {
expect( cached ).to.be.ok();
} );
} );
describe( "With topic Middle.Bottom and binding Middle.#", function () {
var result = bindingsResolver.compare( "Middle.#", "Middle.Bottom" ),
cached = bindingsResolver.cache["Middle.Bottom"]["Middle.#"];
it( "Result should be true", function () {
expect( result ).to.be.ok();
} );
it( "Should create a resolver cache entry", function () {
expect( cached ).to.be.ok();
} );
} );
// Failing matches
// # at beginning of binding
describe( "With topic Top.Middle.SubMiddle.Bottom and binding #.Middle.Bottom", function () {
var result = bindingsResolver.compare( "#.Middle.Bottom", "Top.Middle.SubMiddle.Bottom" ),
cached = bindingsResolver.cache["Top.Middle.SubMiddle.Bottom"] && bindingsResolver.cache["Top.Middle.SubMiddle.Bottom"]["#.Middle.Bottom"];
it( "Result should be false", function () {
expect( result ).to.not.be.ok();
} );
it( "Should *not* create a resolver cache entry", function () {
expect( cached ).to.not.be.ok();
} );
} );
describe( "With topic Top.SubTop.Middle.SubMiddle.Bottom and binding #.Middle.Bottom", function () {
var result = bindingsResolver.compare( "#.Middle.Bottom", "Top.SubTop.Middle.SubMiddle.Bottom" ),
cached = bindingsResolver.cache["Top.SubTop.Middle.SubMiddle.Bottom"] && bindingsResolver.cache["Top.SubTop.Middle.SubMiddle.Bottom"]["#.Middle.Bottom"];
it( "Result should be false", function () {
expect( result ).to.not.be.ok();
} );
it( "Should *not* create a resolver cache entry", function () {
expect( cached ).to.not.be.ok();
} );
} );
describe( "With topic Middle.Bottom and binding #.Middle.SubMiddle.Bottom", function () {
var result = bindingsResolver.compare( "#.Middle.Bottom", "Middle.SubMiddle.Bottom" ),
cached = bindingsResolver.cache["Middle.SubMiddle.Bottom"] && bindingsResolver.cache["Middle.SubMiddle.Bottom"]["#.Middle.Bottom"];
it( "Result should be false", function () {
expect( result ).to.not.be.ok();
} );
it( "Should *not* create a resolver cache entry", function () {
expect( cached ).to.not.be.ok();
} );
} );
// # in middle of binding
describe( "With topic Top.Middle.Bottom and binding Top.SubTop.#.Bottom", function () {
var result = bindingsResolver.compare( "Top.SubTop.#.Bottom", "Top.Middle.Bottom" ),
cached = bindingsResolver.cache["Top.Middle.Bottom"] && bindingsResolver.cache["Top.Middle.Bottom"]["Top.SubTop.#.Bottom"];
it( "Result should be false", function () {
expect( result ).to.not.be.ok();
} );
it( "Should *not* create a resolver cache entry", function () {
expect( cached ).to.not.be.ok();
} );
} );
describe( "With topic Top.Middle.SubMiddle.Bottom.SubBottom and binding Top.#.Bottom", function () {
var result = bindingsResolver.compare( "Top.#.Bottom", "Top.Middle.SubMiddle.Bottom.SubBottom" ),
cached = bindingsResolver.cache["Top.Middle.SubMiddle.Bottom.SubBottom"] && bindingsResolver.cache["Top.Middle.SubMiddle.Bottom.SubBottom"]["Top.#.Bottom"];
it( "Result should be false", function () {
expect( result ).to.not.be.ok();
} );
it( "Should *not* create a resolver cache entry", function () {
expect( cached ).to.not.be.ok();
} );
} );
describe( "With topic Top.SubTop.Middle.SubMiddle.Bottom and binding Top.#.Middle.Bottom", function () {
var result = bindingsResolver.compare( "Top.#.Middle.Bottom", "Top.SubTop.Middle.SubMiddle.Bottom" ),
cached = bindingsResolver.cache["Top.SubTop.Middle.SubMiddle.Bottom"] && bindingsResolver.cache["Top.SubTop.Middle.SubMiddle.Bottom"]["Top.#.Middle.Bottom"];
it( "Result should be false", function () {
expect( result ).to.not.be.ok();
} );
it( "Should *not* create a resolver cache entry", function () {
expect( cached ).to.not.be.ok();
} );
} );
describe( "With topic Top.SubTop.Bottom and binding SubTop.#.Bottom", function () {
var result = bindingsResolver.compare( "SubTop.#.Bottom", "Top.SubTop.Bottom" ),
cached = bindingsResolver.cache["Top.SubTop.Bottom"] && bindingsResolver.cache["Top.SubTop.Bottom"]["SubTop.#.Bottom"];
it( "Result should be false", function () {
expect( result ).to.not.be.ok();
} );
it( "Should *not* create a resolver cache entry", function () {
expect( cached ).to.not.be.ok();
} );
} );
// # at end of binding
describe( "With topic Top.Bottom and binding Top.Middle.#", function () {
var result = bindingsResolver.compare( "Top.Middle.#", "Top.Bottom" ),
cached = bindingsResolver.cache["Top.Bottom"] && bindingsResolver.cache["Top.Bottom"]["Top.Middle.#"];
it( "Result should be false", function () {
expect( result ).to.not.be.ok();
} );
it( "Should *not* create a resolver cache entry", function () {
expect( cached ).to.not.be.ok();
} );
} );
describe( "With topic Top.Middle.Bottom and binding Top.SubTop.#", function () {
var result = bindingsResolver.compare( "Top.SubTop.#", "Top.Middle.Bottom" ),
cached = bindingsResolver.cache["Top.Middle.Bottom"] && bindingsResolver.cache["Top.Middle.Bottom"]["Top.SubTop.#"];
it( "Result should be false", function () {
expect( result ).to.not.be.ok();
} );
it( "Should *not* create a resolver cache entry", function () {
expect( cached ).to.not.be.ok();
} );
} );
describe( "With topic Bottom and binding Middle.#", function () {
var result = bindingsResolver.compare( "Middle.#", "Bottom" ),
cached = bindingsResolver.cache["Bottom"] && bindingsResolver.cache["Bottom"]["Middle.#"];
it( "Result should be false", function () {
expect( result ).to.not.be.ok();
} );
it( "Should *not* create a resolver cache entry", function () {
expect( cached ).to.not.be.ok();
} );
} );
});
describe("With both '#' and '*' wildcards", function(){
// Passing matches
describe( "With topic Top.Middle.Bottom and binding #.*.Bottom", function () {
var result = bindingsResolver.compare( "#.*.Bottom", "Top.Middle.Bottom" ),
cached = bindingsResolver.cache["Top.Middle.Bottom"]["#.*.Bottom"];
it( "Result should be true", function () {
expect( result ).to.be.ok();
} );
it( "Should create a resolver cache entry", function () {
expect( cached ).to.be.ok();
} );
} );
describe( "With topic Top.Middle.SubMiddle.Bottom and binding #.*.Bottom", function () {
var result = bindingsResolver.compare( "#.*.Bottom", "Top.Middle.SubMiddle.Bottom" ),
cached = bindingsResolver.cache["Top.Middle.SubMiddle.Bottom"]["#.*.Bottom"];
it( "Result should be true", function () {
expect( result ).to.be.ok();
} );
it( "Should create a resolver cache entry", function () {
expect( cached ).to.be.ok();
} );
} );
describe( "With topic Top.Bottom and binding #.*.Bottom", function () {
var result = bindingsResolver.compare( "#.*.Bottom", "Top.Bottom" ),
cached = bindingsResolver.cache["Top.Bottom"]["#.*.Bottom"];
it( "Result should be true", function () {
expect( result ).to.be.ok();
} );
it( "Should create a resolver cache entry", function () {
expect( cached ).to.be.ok();
} );
} );
describe( "With topic Top.Bottom and binding *.#.Bottom", function () {
var result = bindingsResolver.compare( "*.#.Bottom", "Top.Bottom" ),
cached = bindingsResolver.cache["Top.Bottom"] && bindingsResolver.cache["Top.Bottom"]["*.#.Bottom"];
it( "Result should be true", function () {
expect( result ).to.be.ok();
} );
it( "Should create a resolver cache entry", function () {
expect( cached ).to.be.ok();
} );
} );
// Failing matches
describe( "With topic Bottom and binding #.*.Bottom", function () {
var result = bindingsResolver.compare( "#.*.Bottom", "Bottom" ),
cached = bindingsResolver.cache["Bottom"] && bindingsResolver.cache["Bottom"]["#.*.Bottom"];
it( "Result should be false", function () {
expect( result ).to.not.be.ok();
} );
it( "Should *not* create a resolver cache entry", function () {
expect( cached ).to.not.be.ok();
} );
} );
describe( "With topic Top.Middle.SubMiddle.Bottom and binding Top.Middle.SubMiddle.#.*.Bottom", function () {
var result = bindingsResolver.compare( "Top.Middle.SubMiddle.#.*.Bottom", "Top.Middle.SubMiddle.Bottom" ),
cached = bindingsResolver.cache["Top.Middle.SubMiddle.Bottom"] && bindingsResolver.cache["Top.Middle.SubMiddle.Bottom"]["Top.Middle.SubMiddle.#.*.Bottom"];
it( "Result should be false", function () {
expect( result ).to.not.be.ok();
} );
it( "Should *not* create a resolver cache entry", function () {
expect( cached ).to.not.be.ok();
} );
} );
describe( "With topic Top.Bottom and binding #.*.Middle.Bottom", function () {
var result = bindingsResolver.compare( "#.*.Middle.Bottom", "Top.Bottom" ),
cached = bindingsResolver.cache["Top.Bottom"] && bindingsResolver.cache["Top.Bottom"]["#.*.Middle.Bottom"];
it( "Result should be false", function () {
expect( result ).to.not.be.ok();
} );
it( "Should *not* create a resolver cache entry", function () {
expect( cached ).to.not.be.ok();
} );
} );
});
describe("With plain string matching", function() {
describe( "With topic Top.Middle.Bottom and binding Top.Middle.Bottom", function () {
var result = bindingsResolver.compare( "Top.Middle.Bottom", "Top.Middle.Bottom" ),
cached = bindingsResolver.cache["Top.Middle.Bottom"]["Top.Middle.Bottom"];
it( "Result should be true", function () {
expect( result ).to.be.ok();
} );
it( "Should create a resolver cache entry", function () {
expect( cached ).to.be.ok();
} );
} );
describe( "With topic 'Topic' and binding 'Topic'", function () {
var result = bindingsResolver.compare( "Topic", "Topic" ),
cached = bindingsResolver.cache["Topic"]["Topic"];
it( "Result should be true", function () {
expect( result ).to.be.ok();
} );
it( "Should create a resolver cache entry", function () {
expect( cached ).to.be.ok();
} );
} );
});
} );
} );

View file

@ -23,13 +23,15 @@
<script type="text/javascript" src="../src/AmqpBindingsResolver.js"></script>
<script type="text/javascript" src="../src/LocalBus.js"></script>
<script type="text/javascript" src="../src/Api.js"></script>
<!--
<script type="text/javascript" src="DistinctPredicate.spec.js"></script>
<script type="text/javascript" src="ConsecutiveDistinctPredicate.spec.js"></script>
<script type="text/javascript" src="ChannelDefinition.spec.js"></script>
<script type="text/javascript" src="SubscriptionDefinition.spec.js"></script>
<script type="text/javascript" src="AmqpBindingsResolver.spec.js"></script>
-->
<script type="text/javascript" src="AmqpBindingsResolver.spec.js"></script><!--
<script type="text/javascript" src="Postal.spec.js"></script>
<script type="text/javascript" src="linkedChannels.spec.js"></script>
<script type="text/javascript" src="linkedChannels.spec.js"></script>-->
<script type="text/javascript">
mocha.run();
</script>

View file

@ -8,7 +8,7 @@ var bindingsResolver = {
var pattern = ("^" + binding.replace( /\./g, "\\." ) // escape actual periods
.replace( /\*/g, "[A-Z,a-z,0-9]*" ) // asterisks match any alpha-numeric 'word'
.replace( /#/g, ".*" ) + "$") // hash matches 'n' # of words (+ optional on start/end of topic)
.replace( "\\..*$", "(\\..*)*$" ) // fix end of topic matching on hash wildcards
.replace( "\\..*$", "(\\..*)*$" ) // fix end of topic matching on hash wildcards
.replace( "^.*\\.", "^(.*\\.)*" ); // fix beginning of topic matching on hash wildcards
var rgx = new RegExp( pattern );
var result = rgx.test( topic );