diff --git a/lib/bindings/http/receiver_binary_0_2.js b/lib/bindings/http/receiver_binary_0_2.js index 0d0c269..023392f 100644 --- a/lib/bindings/http/receiver_binary_0_2.js +++ b/lib/bindings/http/receiver_binary_0_2.js @@ -76,12 +76,15 @@ Receiver.prototype.parse = function(payload, headers) { if(headers[header]){ var setter_name = setter_reflections[header].name; var parser_fn = setter_reflections[header].parser; - console.log(typeof parser_fn(headers[header])); + // invoke the setter function cloudevent[setter_name](parser_fn(headers[header])); } } + // Sets the data + cloudevent.data(payload); + // Checks the event spec cloudevent.format(); diff --git a/test/bindings/http/receiver_binary_0_2_tests.js b/test/bindings/http/receiver_binary_0_2_tests.js index 123ebcf..5a6364b 100644 --- a/test/bindings/http/receiver_binary_0_2_tests.js +++ b/test/bindings/http/receiver_binary_0_2_tests.js @@ -143,6 +143,140 @@ describe("HTTP Transport Binding Binary Receiver 0.2", () => { var actual = receiver.parse(payload, attributes); // assert + expect(actual.getType()) + .to.equal("type"); + }); + + it("Cloudevent contains 'specversion'", () => { + // setup + var payload = { + "data" : "dataString" + }; + var attributes = { + "ce-type" : "type", + "ce-specversion" : "0.2", + "ce-source" : "source", + "ce-id" : "id", + "ce-time" : "2019-06-16T11:42:00Z", + "ce-schemaurl" : "http://schema.registry/v1" + }; + + // act + var actual = receiver.parse(payload, attributes); + + // assert + expect(actual.getSpecversion()) + .to.equal("0.2"); + }); + + it("Cloudevent contains 'source'", () => { + // setup + var payload = { + "data" : "dataString" + }; + var attributes = { + "ce-type" : "type", + "ce-specversion" : "0.2", + "ce-source" : "/source", + "ce-id" : "id", + "ce-time" : "2019-06-16T11:42:00Z", + "ce-schemaurl" : "http://schema.registry/v1" + }; + + // act + var actual = receiver.parse(payload, attributes); + + // assert + expect(actual.getSource()) + .to.equal("/source"); + }); + + it("Cloudevent contains 'id'", () => { + // setup + var payload = { + "data" : "dataString" + }; + var attributes = { + "ce-type" : "type", + "ce-specversion" : "0.2", + "ce-source" : "/source", + "ce-id" : "id", + "ce-time" : "2019-06-16T11:42:00Z", + "ce-schemaurl" : "http://schema.registry/v1" + }; + + // act + var actual = receiver.parse(payload, attributes); + + // assert + expect(actual.getId()) + .to.equal("id"); + }); + + it("Cloudevent contains 'time'", () => { + // setup + var payload = { + "data" : "dataString" + }; + var attributes = { + "ce-type" : "type", + "ce-specversion" : "0.2", + "ce-source" : "/source", + "ce-id" : "id", + "ce-time" : "2019-06-16T11:42:00.000Z", + "ce-schemaurl" : "http://schema.registry/v1" + }; + + // act + var actual = receiver.parse(payload, attributes); + + // assert + expect(actual.getTime()) + .to.equal("2019-06-16T11:42:00.000Z"); + }); + + it("Cloudevent contains 'schemaurl'", () => { + // setup + var payload = { + "data" : "dataString" + }; + var attributes = { + "ce-type" : "type", + "ce-specversion" : "0.2", + "ce-source" : "/source", + "ce-id" : "id", + "ce-time" : "2019-06-16T11:42:00Z", + "ce-schemaurl" : "http://schema.registry/v1" + }; + + // act + var actual = receiver.parse(payload, attributes); + + // assert + expect(actual.getSchemaurl()) + .to.equal("http://schema.registry/v1"); + }); + + it("Cloudevent contains 'data'", () => { + // setup + var payload = { + "data" : "dataString" + }; + var attributes = { + "ce-type" : "type", + "ce-specversion" : "0.2", + "ce-source" : "/source", + "ce-id" : "id", + "ce-time" : "2019-06-16T11:42:00Z", + "ce-schemaurl" : "http://schema.registry/v1" + }; + + // act + var actual = receiver.parse(payload, attributes); + + // assert + expect(actual.getData()) + .to.deep.equal(payload); }); it("No error when all attributes are in place", () => { @@ -154,7 +288,9 @@ describe("HTTP Transport Binding Binary Receiver 0.2", () => { "ce-type" : "type", "ce-specversion" : "0.2", "ce-source" : "source", - "ce-id" : "id" + "ce-id" : "id", + "ce-time" : "2019-06-16T11:42:00Z", + "ce-schemaurl" : "http://schema.registry/v1" }; // act