http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/4621d41c/JSLib/tests/odata-json-tests.js ---------------------------------------------------------------------- diff --git a/JSLib/tests/odata-json-tests.js b/JSLib/tests/odata-json-tests.js deleted file mode 100644 index f86e86f..0000000 --- a/JSLib/tests/odata-json-tests.js +++ /dev/null @@ -1,888 +0,0 @@ -/// <reference path="../src/odata-net.js" /> -/// <reference path="../src/odata.js" /> -/// <reference path="../common/djstestfx.js" /> - -// odata-tests.js - -(function (window, undefined) { - - // DATAJS INTERNAL START - djstest.addTest(function isArrayTest() { - djstest.assert(odatajs.isArray([])); - djstest.assert(odatajs.isArray([1, 2])); - djstest.assert(!odatajs.isArray({})); - djstest.assert(!odatajs.isArray("1,2,3,4")); - djstest.assert(!odatajs.isArray()); - djstest.assert(!odatajs.isArray(null)); - djstest.done(); - }); - - djstest.addTest(function jsonParserTest() { - var tests = [ - { context: { response: { requestUri: "http://base.org" }, dataServiceVersion: "4.0" }, expected: {} }, - { context: { response: { requestUri: "http://base.org" }, dataServiceVersion: "4.0" }, - expected: { - "@odata.context": "http://foo/OData.svc/$metadata", - value: [ - { - name: "Products", - kind: "EntitySet", - url: "Products" - }, - { - name: "ProductDetails", - kind: "EntitySet", - url: "ProductDetails" - } - ] - } - }, - { context: { response: { requestUri: "http://base.org" }, dataServiceVersion: "4.0" }, - expected: { - value: [ - { - name: "Products", - kind: "EntitySet", - url: "http://foo/OData.svc/Products" - }, - { - name: "ProductDetails", - kind: "EntitySet", - url: "http://foo/OData.svc/ProductDetails" - } - ] - } - }, - { context: { response: { requestUri: "http://base.org" }, dataServiceVersion: "4.0" }, expected: { "@odata.context": "http://foo/OData.svc/$metadata#Products(0)/Name", value: "Bread"} }, - { context: { response: { requestUri: "http://base.org" }, dataServiceVersion: "4.0" }, - expected: { - "@odata.context": "http://foo/OData.svc/$metadata#Products", - value: [ - { - "@odata.type": "#ODataDemo.Product", - "@odata.id": "http://foo/OData.svc/Products(0)", - "@odata.editLink": "Products(0)", - "[email protected]": "Products(0)/Categories", - "[email protected]": "Products(0)/Categories/$ref", - "[email protected]": "Products(0)/Supplier", - "[email protected]": "Products(0)/Supplier/$ref", - "[email protected]": "Products(0)/ProductDetail", - "[email protected]": "Products(0)/ProductDetail/$ref", - ID: 0, - Name: "Bread", - Description: "Whole grain bread", - "[email protected]": "#DateTimeOffset", - ReleaseDate: "1992-01-01T00:00:00Z", - DiscontinuedDate: null, - "[email protected]": "#Int16", - Rating: 4, - Price: 2.5 - }] - } - }, - { context: { response: { requestUri: "http://base.org" }, dataServiceVersion: "4.0" }, - expected: { - "@odata.context": "http://foo/OData.svc/$metadata#Products", - value: [ - { - ID: 0, - Name: "Bread", - Description: "Whole grain bread", - ReleaseDate: "1992-01-01T00:00:00Z", - DiscontinuedDate: null, - Rating: 4, - Price: 2.5 - }] - } - }, - { context: { response: { requestUri: "http://base.org" }, dataServiceVersion: "4.0" }, - expected: { - value: [ - { - ID: 0, - Name: "Bread", - Description: "Whole grain bread", - ReleaseDate: "1992-01-01T00:00:00Z", - DiscontinuedDate: null, - Rating: 4, - Price: 2.5 - }] - } - }, - { context: { response: { requestUri: "http://base.org" }, dataServiceVersion: "4.0" }, - expected: { - "@odata.context": "http://foo/OData.svc/$metadata#Products/$entry", - "@odata.type": "#ODataDemo.Product", - "@odata.id": "http://foo/OData.svc/Products(0)", - "@odata.editLink": "Products(0)", - "[email protected]": "Products(0)/Categories", - "[email protected]": "Products(0)/Categories/$ref", - "[email protected]": "Products(0)/Supplier", - "[email protected]": "Products(0)/Supplier/$ref", - "[email protected]": "Products(0)/ProductDetail", - "[email protected]": "Products(0)/ProductDetail/$ref", - ID: 0, - Name: "Bread", - Description: "Whole grain bread", - "[email protected]": "#DateTimeOffset", - ReleaseDate: "1992-01-01T00:00:00Z", - DiscontinuedDate: null, - "[email protected]": "#Int16", - Rating: 4, - Price: 2.5 - } - }, - { context: { response: { requestUri: "http://base.org" }, dataServiceVersion: "4.0" }, - expected: { - "@odata.context": "http://foo/OData.svc/$metadata#Products/$entry", - ID: 0, - Name: "Bread", - Description: "Whole grain bread", - ReleaseDate: "1992-01-01T00:00:00Z", - DiscontinuedDate: null, - Rating: 4, - Price: 2.5 - } - }, - { context: { response: { requestUri: "http://base.org" }, dataServiceVersion: "4.0" }, - expected: { - ID: 0, - Name: "Bread", - Description: "Whole grain bread", - ReleaseDate: "1992-01-01T00:00:00Z", - DiscontinuedDate: null, - Rating: 4, - Price: 2.5 - } - }, - { context: { response: { requestUri: "http://base.org" }, dataServiceVersion: "4.0" }, - expected: { - "@odata.context": "http://foo/$metadata#Customer(-10)/PrimaryContactInfo/AlternativeNames", - "@odata.type": "#Collection(String)", - value: [ - "ã°ããããºï¾ã½ãã¼ã½ã²ããã´ã½æ¹ä¹ï¾ããÑãã½çã¯Ñãã¹æ¹ç±Ð¯æ¬²ã¿ããã裹ã¼ããヲæ¹ãã²ä¹ã²åãï½", - "qckrnuruxcbhjfimnsykgfquffobcadpsaocixoeljhspxrhebkudppgndgcrlyvynqhbujrnvyxyymhnroemigogsqulvgallta", - "btsnhqrjqryqzgxducl", - "qbtlssjhunufmzdv", - "ããЯããã¹ã¼ããã»ï½åãã¼ä¹ãã²ãç±é»ãããã¿ã³æ¦ã¯ã½ã½ãã¾ãããã¼ãã²ã¿ãã¿ããå¼ã²ã¹å", - "vicqasfdkxsuyuzspjqunxpyfuhlxfhgfqnlcpdfivqnxqoothnfsbuykfguftgulgldnkkzufssbae", - "ä¹ã½ããããã¾ãÑï½ããЯã¾ã¾ã¿ãã¿ã²ç¸·ããï½ããã¼ã½", - "ã½ãã¿ããé»ã½ã¼ãã¼åï½ã½ãããã¡ã¾ã½ãï½ã¿ã¾å¼ãã¼ã¿ãï½ãºãã裹ããããヲãºãããåã", - "hssiiÃuamtctgqhglmusexyikhcsqctusonubxorssyizhyqpbtbdÃjnelxqttkhdalabibuqhiubtÃsptrmzelud", - "gbjssllxzzxkmÃppyyrhgmoeÃizlcmsuqqnvjÃudszevtfunflqzqcuubukypÃqjcix" - ] - } - } - ]; - - var i, len; - for (i = 0, len = tests.length; i < len; i++) { - var data = window.JSON.stringify(tests[i].expected); - var actual = OData.jsonParser(OData.jsonHandler, data, tests[i].context); - djstest.assertAreEqualDeep(actual, tests[i].expected, "test " + i + "didn't return the expected data"); - } - - djstest.done(); - }); - - djstest.addTest(function jsonSerializerTest() { - var tests = [ - { context: { response: { requestUri: "http://base.org" }, dataServiceVersion: "4.0" }, expected: { value: ""} }, - { context: { response: { requestUri: "http://base.org" }, dataServiceVersion: "4.0" }, expected: { value: []} }, - { context: { response: { requestUri: "http://base.org" }, dataServiceVersion: "4.0" }, - expected: { - ID: 0, - Name: "Bread", - Description: "Whole grain bread", - ReleaseDate: "1992-01-01T00:00:00Z", - DiscontinuedDate: null, - Rating: 4, - Price: 2.5 - } - }, - { context: { response: { requestUri: "http://base.org" }, dataServiceVersion: "4.0" }, - expected: { - value: [ - "ã°ããããºï¾ã½ãã¼ã½ã²ããã´ã½æ¹ä¹ï¾ããÑãã½çã¯Ñãã¹æ¹ç±Ð¯æ¬²ã¿ããã裹ã¼ããヲæ¹ãã²ä¹ã²åãï½", - "qckrnuruxcbhjfimnsykgfquffobcadpsaocixoeljhspxrhebkudppgndgcrlyvynqhbujrnvyxyymhnroemigogsqulvgallta", - "btsnhqrjqryqzgxducl", - "qbtlssjhunufmzdv", - "ããЯããã¹ã¼ããã»ï½åãã¼ä¹ãã²ãç±é»ãããã¿ã³æ¦ã¯ã½ã½ãã¾ãããã¼ãã²ã¿ãã¿ããå¼ã²ã¹å", - "vicqasfdkxsuyuzspjqunxpyfuhlxfhgfqnlcpdfivqnxqoothnfsbuykfguftgulgldnkkzufssbae", - "ä¹ã½ããããã¾ãÑï½ããЯã¾ã¾ã¿ãã¿ã²ç¸·ããï½ããã¼ã½", - "ã½ãã¿ããé»ã½ã¼ãã¼åï½ã½ãããã¡ã¾ã½ãï½ã¿ã¾å¼ãã¼ã¿ãï½ãºãã裹ããããヲãºãããåã", - "hssiiÃuamtctgqhglmusexyikhcsqctusonubxorssyizhyqpbtbdÃjnelxqttkhdalabibuqhiubtÃsptrmzelud", - "gbjssllxzzxkmÃppyyrhgmoeÃizlcmsuqqnvjÃudszevtfunflqzqcuubukypÃqjcix" - ] - } - }, - { context: { response: { requestUri: "http://base.org" }, dataServiceVersion: "4.0" }, - expected: { - "@odata.etag": "W/MjAxMy0wNS0yN1QxMTo1OFo=", - "@odata.type": "#DataJS.Tests.V4.Food", - "@odata.mediaEditLink": "http://base.org/$metadata#Foods/mediaEditLink", - "@odata.mediaReadLink": "http://base.org/$metadata#Foods/mediaReadLink", - "@odata.mediaContentType": "http://base.org/$metadata#Foods/mediaContentType", - "@odata.mediaEtag": "http://base.org/$metadata#Foods/mediaEtag", - ID: 0, - Name: "Bread", - Description: "Whole grain bread", - ReleaseDate: "1992-01-01T00:00:00Z", - DiscontinuedDate: null, - Rating: 4, - Price: 2.5 - }, - data: { - "@odata.context": "http://base.org/$metadata#Foods/$entity", - "@odata.id": "Foods(4)", - "@odata.etag": "W/MjAxMy0wNS0yN1QxMTo1OFo=", - "@odata.editLink": "Foods(0)", - "@odata.type": "#DataJS.Tests.V4.Food", - "@odata.mediaEditLink": "http://base.org/$metadata#Foods/mediaEditLink", - "@odata.mediaReadLink": "http://base.org/$metadata#Foods/mediaReadLink", - "@odata.mediaContentType": "http://base.org/$metadata#Foods/mediaContentType", - "@odata.mediaEtag": "http://base.org/$metadata#Foods/mediaEtag", - ID: 0, - Name: "Bread", - Description: "Whole grain bread", - ReleaseDate: "1992-01-01T00:00:00Z", - DiscontinuedDate: null, - Rating: 4, - Price: 2.5 - } - }, - { context: { response: { requestUri: "http://base.org" }, dataServiceVersion: "4.0" }, - expected: { - value : [{ - "@odata.etag": "W/MjAxMy0wNS0yN1QxMTo1OFo=", - "@odata.type": "#DataJS.Tests.V4.Food", - "@odata.mediaEditLink": "http://base.org/$metadata#Foods/mediaEditLink", - "@odata.mediaReadLink": "http://base.org/$metadata#Foods/mediaReadLink", - "@odata.mediaContentType": "http://base.org/$metadata#Foods/mediaContentType", - "@odata.mediaEtag": "http://base.org/$metadata#Foods/mediaEtag", - ID: 0, - ComplexInLayerOne: - { - "@odata.etag": "W/MjAxMy0wNS0yN1QxMTo1OFo=", - "@odata.type": "#DataJS.Tests.V4.Food", - "@odata.mediaEditLink": "http://base.org/$metadata#Foods/mediaEditLink/layer1", - "@odata.mediaReadLink": "http://base.org/$metadata#Foods/mediaReadLink/layer1", - "@odata.mediaContentType": "http://base.org/$metadata#Foods/mediaContentType/layer1", - "@odata.mediaEtag": "http://base.org/$metadata#Foods/mediaEtag/layer1", - ID: 1, - ComplexInLayerTwo: - { - "@odata.etag": "W/MjAxMy0wNS0yN1QxMTo1OFo=", - "@odata.type": "#DataJS.Tests.V4.Food", - "@odata.mediaEditLink": "http://base.org/$metadata#Foods/mediaEditLink/layer2", - "@odata.mediaReadLink": "http://base.org/$metadata#Foods/mediaReadLink/layer2", - "@odata.mediaContentType": "http://base.org/$metadata#Foods/mediaContentType/layer2", - "@odata.mediaEtag": "http://base.org/$metadata#Foods/mediaEtag/layer2", - ID: 2, - ComplexInLayerThreeList: [ - { - "@odata.etag": "W/MjAxMy0wNS0yN1QxMTo1OFo=", - "@odata.type": "#DataJS.Tests.V4.Food", - "@odata.mediaEditLink": "http://base.org/$metadata#Foods/mediaEditLink/layer3", - "@odata.mediaReadLink": "http://base.org/$metadata#Foods/mediaReadLink/layer3", - "@odata.mediaContentType": "http://base.org/$metadata#Foods/mediaContentType/layer3", - "@odata.mediaEtag": "http://base.org/$metadata#Foods/mediaEtag/layer3", - ID: 3, - Name: "BreadInLayer3", - Description: "Whole grain bread inLayer3", - ReleaseDate: "1992-01-01T00:00:00Z", - DiscontinuedDate: null, - Rating: 7, - Price: 5.5 - }, - { - "@odata.etag": "W/MjAxMy0wNS0yN1QxMTo1OFo=", - "@odata.type": "#DataJS.Tests.V4.Food", - "@odata.mediaEditLink": "http://base.org/$metadata#Foods/mediaEditLink/layer3", - "@odata.mediaReadLink": "http://base.org/$metadata#Foods/mediaReadLink/layer3", - "@odata.mediaContentType": "http://base.org/$metadata#Foods/mediaContentType/layer3", - "@odata.mediaEtag": "http://base.org/$metadata#Foods/mediaEtag/layer3", - ID: 3, - Name: "BreadInLayer3", - Description: "Whole grain bread inLayer3", - ReleaseDate: "1992-01-01T00:00:00Z", - DiscontinuedDate: null, - Rating: 7, - Price: 5.5 - }], - Name: "BreadInLayer2", - Description: "Whole grain bread inLayer2", - ReleaseDate: "1992-01-01T00:00:00Z", - DiscontinuedDate: null, - Rating: 6, - Price: 4.5 - }, - Name: ["BreadInLayer1", "BreadInLayer12", "BreadInLayer13"], - Description: "Whole grain bread inLayer1", - ReleaseDate: "1992-01-01T00:00:00Z", - DiscontinuedDate: null, - Rating: 5, - Price: 3.5 - }, - Name: "Bread", - Description: "Whole grain bread", - ReleaseDate: "1992-01-01T00:00:00Z", - DiscontinuedDate: null, - Rating: 4, - Price: 2.5 - }, - { - "@odata.etag": "W/MjAxMy0wNS0yN1QxMTo1OFo=", - "@odata.type": "#DataJS.Tests.V4.Food", - "@odata.mediaEditLink": "http://base.org/$metadata#Foods/mediaEditLink", - "@odata.mediaReadLink": "http://base.org/$metadata#Foods/mediaReadLink", - "@odata.mediaContentType": "http://base.org/$metadata#Foods/mediaContentType", - "@odata.mediaEtag": "http://base.org/$metadata#Foods/mediaEtag", - ID: 0, - ComplexInLayerOne: - { - "@odata.etag": "W/MjAxMy0wNS0yN1QxMTo1OFo=", - "@odata.type": "#DataJS.Tests.V4.Food", - "@odata.mediaEditLink": "http://base.org/$metadata#Foods/mediaEditLink/layer1", - "@odata.mediaReadLink": "http://base.org/$metadata#Foods/mediaReadLink/layer1", - "@odata.mediaContentType": "http://base.org/$metadata#Foods/mediaContentType/layer1", - "@odata.mediaEtag": "http://base.org/$metadata#Foods/mediaEtag/layer1", - ID: 1, - ComplexInLayerTwo: - { - "@odata.etag": "W/MjAxMy0wNS0yN1QxMTo1OFo=", - "@odata.type": "#DataJS.Tests.V4.Food", - "@odata.mediaEditLink": "http://base.org/$metadata#Foods/mediaEditLink/layer2", - "@odata.mediaReadLink": "http://base.org/$metadata#Foods/mediaReadLink/layer2", - "@odata.mediaContentType": "http://base.org/$metadata#Foods/mediaContentType/layer2", - "@odata.mediaEtag": "http://base.org/$metadata#Foods/mediaEtag/layer2", - ID: 2, - ComplexInLayerThreeList: [ - { - "@odata.etag": "W/MjAxMy0wNS0yN1QxMTo1OFo=", - "@odata.type": "#DataJS.Tests.V4.Food", - "@odata.mediaEditLink": "http://base.org/$metadata#Foods/mediaEditLink/layer3", - "@odata.mediaReadLink": "http://base.org/$metadata#Foods/mediaReadLink/layer3", - "@odata.mediaContentType": "http://base.org/$metadata#Foods/mediaContentType/layer3", - "@odata.mediaEtag": "http://base.org/$metadata#Foods/mediaEtag/layer3", - ID: 3, - Name: "BreadInLayer3", - Description: "Whole grain bread inLayer3", - ReleaseDate: "1992-01-01T00:00:00Z", - DiscontinuedDate: null, - Rating: 7, - Price: 5.5 - }, - { - "@odata.etag": "W/MjAxMy0wNS0yN1QxMTo1OFo=", - "@odata.type": "#DataJS.Tests.V4.Food", - "@odata.mediaEditLink": "http://base.org/$metadata#Foods/mediaEditLink/layer3", - "@odata.mediaReadLink": "http://base.org/$metadata#Foods/mediaReadLink/layer3", - "@odata.mediaContentType": "http://base.org/$metadata#Foods/mediaContentType/layer3", - "@odata.mediaEtag": "http://base.org/$metadata#Foods/mediaEtag/layer3", - ID: 3, - Name: "BreadInLayer3", - Description: "Whole grain bread inLayer3", - ReleaseDate: "1992-01-01T00:00:00Z", - DiscontinuedDate: null, - Rating: 7, - Price: 5.5 - }], - Name: "BreadInLayer2", - Description: "Whole grain bread inLayer2", - ReleaseDate: "1992-01-01T00:00:00Z", - DiscontinuedDate: null, - Rating: 6, - Price: 4.5 - }, - Name: ["BreadInLayer1", "BreadInLayer12", "BreadInLayer13"], - Description: "Whole grain bread inLayer1", - ReleaseDate: "1992-01-01T00:00:00Z", - DiscontinuedDate: null, - Rating: 5, - Price: 3.5 - }, - Name: "Bread", - Description: "Whole grain bread", - ReleaseDate: "1992-01-01T00:00:00Z", - DiscontinuedDate: null, - Rating: 4, - Price: 2.5 - }] - }, - data: { - "@odata.context": "http://base.org/$metadata#Foods/$entity", - "@odata.id": "Foods(4)", - "@odata.editLink": "Foods(0)", - value : [{ - "@odata.context": "http://base.org/$metadata#Foods/$entity", - "@odata.id": "Foods(4)", - "@odata.etag": "W/MjAxMy0wNS0yN1QxMTo1OFo=", - "@odata.editLink": "Foods(0)", - "@odata.type": "#DataJS.Tests.V4.Food", - "@odata.mediaEditLink": "http://base.org/$metadata#Foods/mediaEditLink", - "@odata.mediaReadLink": "http://base.org/$metadata#Foods/mediaReadLink", - "@odata.mediaContentType": "http://base.org/$metadata#Foods/mediaContentType", - "@odata.mediaEtag": "http://base.org/$metadata#Foods/mediaEtag", - ID: 0, - ComplexInLayerOne: - { - "@odata.context": "http://base.org/$metadata#Foods/$entity", - "@odata.id": "Foods(4)", - "@odata.etag": "W/MjAxMy0wNS0yN1QxMTo1OFo=", - "@odata.editLink": "Foods(0)", - "@odata.type": "#DataJS.Tests.V4.Food", - "@odata.mediaEditLink": "http://base.org/$metadata#Foods/mediaEditLink/layer1", - "@odata.mediaReadLink": "http://base.org/$metadata#Foods/mediaReadLink/layer1", - "@odata.mediaContentType": "http://base.org/$metadata#Foods/mediaContentType/layer1", - "@odata.mediaEtag": "http://base.org/$metadata#Foods/mediaEtag/layer1", - ID: 1, - ComplexInLayerTwo: - { - "@odata.context": "http://base.org/$metadata#Foods/$entity", - "@odata.id": "Foods(4)", - "@odata.etag": "W/MjAxMy0wNS0yN1QxMTo1OFo=", - "@odata.editLink": "Foods(0)", - "@odata.type": "#DataJS.Tests.V4.Food", - "@odata.mediaEditLink": "http://base.org/$metadata#Foods/mediaEditLink/layer2", - "@odata.mediaReadLink": "http://base.org/$metadata#Foods/mediaReadLink/layer2", - "@odata.mediaContentType": "http://base.org/$metadata#Foods/mediaContentType/layer2", - "@odata.mediaEtag": "http://base.org/$metadata#Foods/mediaEtag/layer2", - ID: 2, - ComplexInLayerThreeList: [ - { - "@odata.context": "http://base.org/$metadata#Foods/$entity", - "@odata.id": "Foods(4)", - "@odata.etag": "W/MjAxMy0wNS0yN1QxMTo1OFo=", - "@odata.editLink": "Foods(0)", - "@odata.type": "#DataJS.Tests.V4.Food", - "@odata.mediaEditLink": "http://base.org/$metadata#Foods/mediaEditLink/layer3", - "@odata.mediaReadLink": "http://base.org/$metadata#Foods/mediaReadLink/layer3", - "@odata.mediaContentType": "http://base.org/$metadata#Foods/mediaContentType/layer3", - "@odata.mediaEtag": "http://base.org/$metadata#Foods/mediaEtag/layer3", - ID: 3, - Name: "BreadInLayer3", - Description: "Whole grain bread inLayer3", - ReleaseDate: "1992-01-01T00:00:00Z", - DiscontinuedDate: null, - Rating: 7, - Price: 5.5 - }, - { - "@odata.context": "http://base.org/$metadata#Foods/$entity", - "@odata.id": "Foods(4)", - "@odata.etag": "W/MjAxMy0wNS0yN1QxMTo1OFo=", - "@odata.editLink": "Foods(0)", - "@odata.type": "#DataJS.Tests.V4.Food", - "@odata.mediaEditLink": "http://base.org/$metadata#Foods/mediaEditLink/layer3", - "@odata.mediaReadLink": "http://base.org/$metadata#Foods/mediaReadLink/layer3", - "@odata.mediaContentType": "http://base.org/$metadata#Foods/mediaContentType/layer3", - "@odata.mediaEtag": "http://base.org/$metadata#Foods/mediaEtag/layer3", - ID: 3, - Name: "BreadInLayer3", - Description: "Whole grain bread inLayer3", - ReleaseDate: "1992-01-01T00:00:00Z", - DiscontinuedDate: null, - Rating: 7, - Price: 5.5 - }], - Name: "BreadInLayer2", - Description: "Whole grain bread inLayer2", - ReleaseDate: "1992-01-01T00:00:00Z", - DiscontinuedDate: null, - Rating: 6, - Price: 4.5 - }, - Name: ["BreadInLayer1", "BreadInLayer12", "BreadInLayer13"], - Description: "Whole grain bread inLayer1", - ReleaseDate: "1992-01-01T00:00:00Z", - DiscontinuedDate: null, - Rating: 5, - Price: 3.5 - }, - Name: "Bread", - Description: "Whole grain bread", - ReleaseDate: "1992-01-01T00:00:00Z", - DiscontinuedDate: null, - Rating: 4, - Price: 2.5 - }, - { - "@odata.context": "http://base.org/$metadata#Foods/$entity", - "@odata.id": "Foods(4)", - "@odata.etag": "W/MjAxMy0wNS0yN1QxMTo1OFo=", - "@odata.editLink": "Foods(0)", - "@odata.type": "#DataJS.Tests.V4.Food", - "@odata.mediaEditLink": "http://base.org/$metadata#Foods/mediaEditLink", - "@odata.mediaReadLink": "http://base.org/$metadata#Foods/mediaReadLink", - "@odata.mediaContentType": "http://base.org/$metadata#Foods/mediaContentType", - "@odata.mediaEtag": "http://base.org/$metadata#Foods/mediaEtag", - ID: 0, - ComplexInLayerOne: - { - "@odata.context": "http://base.org/$metadata#Foods/$entity", - "@odata.id": "Foods(4)", - "@odata.etag": "W/MjAxMy0wNS0yN1QxMTo1OFo=", - "@odata.editLink": "Foods(0)", - "@odata.type": "#DataJS.Tests.V4.Food", - "@odata.mediaEditLink": "http://base.org/$metadata#Foods/mediaEditLink/layer1", - "@odata.mediaReadLink": "http://base.org/$metadata#Foods/mediaReadLink/layer1", - "@odata.mediaContentType": "http://base.org/$metadata#Foods/mediaContentType/layer1", - "@odata.mediaEtag": "http://base.org/$metadata#Foods/mediaEtag/layer1", - ID: 1, - ComplexInLayerTwo: - { - "@odata.context": "http://base.org/$metadata#Foods/$entity", - "@odata.id": "Foods(4)", - "@odata.etag": "W/MjAxMy0wNS0yN1QxMTo1OFo=", - "@odata.editLink": "Foods(0)", - "@odata.type": "#DataJS.Tests.V4.Food", - "@odata.mediaEditLink": "http://base.org/$metadata#Foods/mediaEditLink/layer2", - "@odata.mediaReadLink": "http://base.org/$metadata#Foods/mediaReadLink/layer2", - "@odata.mediaContentType": "http://base.org/$metadata#Foods/mediaContentType/layer2", - "@odata.mediaEtag": "http://base.org/$metadata#Foods/mediaEtag/layer2", - ID: 2, - ComplexInLayerThreeList: [ - { - "@odata.context": "http://base.org/$metadata#Foods/$entity", - "@odata.id": "Foods(4)", - "@odata.etag": "W/MjAxMy0wNS0yN1QxMTo1OFo=", - "@odata.editLink": "Foods(0)", - "@odata.type": "#DataJS.Tests.V4.Food", - "@odata.mediaEditLink": "http://base.org/$metadata#Foods/mediaEditLink/layer3", - "@odata.mediaReadLink": "http://base.org/$metadata#Foods/mediaReadLink/layer3", - "@odata.mediaContentType": "http://base.org/$metadata#Foods/mediaContentType/layer3", - "@odata.mediaEtag": "http://base.org/$metadata#Foods/mediaEtag/layer3", - ID: 3, - Name: "BreadInLayer3", - Description: "Whole grain bread inLayer3", - ReleaseDate: "1992-01-01T00:00:00Z", - DiscontinuedDate: null, - Rating: 7, - Price: 5.5 - }, - { - "@odata.context": "http://base.org/$metadata#Foods/$entity", - "@odata.id": "Foods(4)", - "@odata.etag": "W/MjAxMy0wNS0yN1QxMTo1OFo=", - "@odata.editLink": "Foods(0)", - "@odata.type": "#DataJS.Tests.V4.Food", - "@odata.mediaEditLink": "http://base.org/$metadata#Foods/mediaEditLink/layer3", - "@odata.mediaReadLink": "http://base.org/$metadata#Foods/mediaReadLink/layer3", - "@odata.mediaContentType": "http://base.org/$metadata#Foods/mediaContentType/layer3", - "@odata.mediaEtag": "http://base.org/$metadata#Foods/mediaEtag/layer3", - ID: 3, - Name: "BreadInLayer3", - Description: "Whole grain bread inLayer3", - ReleaseDate: "1992-01-01T00:00:00Z", - DiscontinuedDate: null, - Rating: 7, - Price: 5.5 - }], - Name: "BreadInLayer2", - Description: "Whole grain bread inLayer2", - ReleaseDate: "1992-01-01T00:00:00Z", - DiscontinuedDate: null, - Rating: 6, - Price: 4.5 - }, - Name: ["BreadInLayer1", "BreadInLayer12", "BreadInLayer13"], - Description: "Whole grain bread inLayer1", - ReleaseDate: "1992-01-01T00:00:00Z", - DiscontinuedDate: null, - Rating: 5, - Price: 3.5 - }, - Name: "Bread", - Description: "Whole grain bread", - ReleaseDate: "1992-01-01T00:00:00Z", - DiscontinuedDate: null, - Rating: 4, - Price: 2.5 - }] - } - }, - { context: { response: { requestUri: "http://base.org" }, dataServiceVersion: "4.0" }, - expected: { - "@odata.etag": "W/MjAxMy0wNS0yN1QxMTo1OFo=", - "@odata.type": "#DataJS.Tests.V4.Food", - "@odata.mediaEditLink": "http://base.org/$metadata#Foods/mediaEditLink", - "@odata.mediaReadLink": "http://base.org/$metadata#Foods/mediaReadLink", - "@odata.mediaContentType": "http://base.org/$metadata#Foods/mediaContentType", - "@odata.mediaEtag": "http://base.org/$metadata#Foods/mediaEtag", - ID: 0, - ComplexInLayerOne: - { - "@odata.etag": "W/MjAxMy0wNS0yN1QxMTo1OFo=", - "@odata.type": "#DataJS.Tests.V4.Food", - "@odata.mediaEditLink": "http://base.org/$metadata#Foods/mediaEditLink/layer1", - "@odata.mediaReadLink": "http://base.org/$metadata#Foods/mediaReadLink/layer1", - "@odata.mediaContentType": "http://base.org/$metadata#Foods/mediaContentType/layer1", - "@odata.mediaEtag": "http://base.org/$metadata#Foods/mediaEtag/layer1", - ID: 1, - ComplexInLayerTwo: - { - "@odata.etag": "W/MjAxMy0wNS0yN1QxMTo1OFo=", - "@odata.type": "#DataJS.Tests.V4.Food", - "@odata.mediaEditLink": "http://base.org/$metadata#Foods/mediaEditLink/layer2", - "@odata.mediaReadLink": "http://base.org/$metadata#Foods/mediaReadLink/layer2", - "@odata.mediaContentType": "http://base.org/$metadata#Foods/mediaContentType/layer2", - "@odata.mediaEtag": "http://base.org/$metadata#Foods/mediaEtag/layer2", - ID: 2, - ComplexInLayerThree: - { - "@odata.etag": "W/MjAxMy0wNS0yN1QxMTo1OFo=", - "@odata.type": "#DataJS.Tests.V4.Food", - "@odata.mediaEditLink": "http://base.org/$metadata#Foods/mediaEditLink/layer3", - "@odata.mediaReadLink": "http://base.org/$metadata#Foods/mediaReadLink/layer3", - "@odata.mediaContentType": "http://base.org/$metadata#Foods/mediaContentType/layer3", - "@odata.mediaEtag": "http://base.org/$metadata#Foods/mediaEtag/layer3", - ID: 3, - Name: "BreadInLayer3", - Description: "Whole grain bread inLayer3", - ReleaseDate: "1992-01-01T00:00:00Z", - DiscontinuedDate: null, - Rating: 7, - Price: 5.5 - }, - Name: "BreadInLayer2", - Description: "Whole grain bread inLayer2", - ReleaseDate: "1992-01-01T00:00:00Z", - DiscontinuedDate: null, - Rating: 6, - Price: 4.5 - }, - Name: "BreadInLayer1", - Description: "Whole grain bread inLayer1", - ReleaseDate: "1992-01-01T00:00:00Z", - DiscontinuedDate: null, - Rating: 5, - Price: 3.5 - }, - Name: "Bread", - Description: "Whole grain bread", - ReleaseDate: "1992-01-01T00:00:00Z", - DiscontinuedDate: null, - Rating: 4, - Price: 2.5 - }, - data: { - "@odata.context": "http://base.org/$metadata#Foods/$entity", - "@odata.id": "Foods(4)", - "@odata.etag": "W/MjAxMy0wNS0yN1QxMTo1OFo=", - "@odata.editLink": "Foods(0)", - "@odata.type": "#DataJS.Tests.V4.Food", - "@odata.mediaEditLink": "http://base.org/$metadata#Foods/mediaEditLink", - "@odata.mediaReadLink": "http://base.org/$metadata#Foods/mediaReadLink", - "@odata.mediaContentType": "http://base.org/$metadata#Foods/mediaContentType", - "@odata.mediaEtag": "http://base.org/$metadata#Foods/mediaEtag", - ID: 0, - ComplexInLayerOne: - { - "@odata.context": "http://base.org/$metadata#Foods/$entity", - "@odata.id": "Foods(4)", - "@odata.etag": "W/MjAxMy0wNS0yN1QxMTo1OFo=", - "@odata.editLink": "Foods(0)", - "@odata.type": "#DataJS.Tests.V4.Food", - "@odata.mediaEditLink": "http://base.org/$metadata#Foods/mediaEditLink/layer1", - "@odata.mediaReadLink": "http://base.org/$metadata#Foods/mediaReadLink/layer1", - "@odata.mediaContentType": "http://base.org/$metadata#Foods/mediaContentType/layer1", - "@odata.mediaEtag": "http://base.org/$metadata#Foods/mediaEtag/layer1", - ID: 1, - ComplexInLayerTwo: - { - "@odata.context": "http://base.org/$metadata#Foods/$entity", - "@odata.id": "Foods(4)", - "@odata.etag": "W/MjAxMy0wNS0yN1QxMTo1OFo=", - "@odata.editLink": "Foods(0)", - "@odata.type": "#DataJS.Tests.V4.Food", - "@odata.mediaEditLink": "http://base.org/$metadata#Foods/mediaEditLink/layer2", - "@odata.mediaReadLink": "http://base.org/$metadata#Foods/mediaReadLink/layer2", - "@odata.mediaContentType": "http://base.org/$metadata#Foods/mediaContentType/layer2", - "@odata.mediaEtag": "http://base.org/$metadata#Foods/mediaEtag/layer2", - ID: 2, - ComplexInLayerThree: - { - "@odata.context": "http://base.org/$metadata#Foods/$entity", - "@odata.id": "Foods(4)", - "@odata.etag": "W/MjAxMy0wNS0yN1QxMTo1OFo=", - "@odata.editLink": "Foods(0)", - "@odata.type": "#DataJS.Tests.V4.Food", - "@odata.mediaEditLink": "http://base.org/$metadata#Foods/mediaEditLink/layer3", - "@odata.mediaReadLink": "http://base.org/$metadata#Foods/mediaReadLink/layer3", - "@odata.mediaContentType": "http://base.org/$metadata#Foods/mediaContentType/layer3", - "@odata.mediaEtag": "http://base.org/$metadata#Foods/mediaEtag/layer3", - ID: 3, - Name: "BreadInLayer3", - Description: "Whole grain bread inLayer3", - ReleaseDate: "1992-01-01T00:00:00Z", - DiscontinuedDate: null, - Rating: 7, - Price: 5.5 - }, - Name: "BreadInLayer2", - Description: "Whole grain bread inLayer2", - ReleaseDate: "1992-01-01T00:00:00Z", - DiscontinuedDate: null, - Rating: 6, - Price: 4.5 - }, - Name: "BreadInLayer1", - Description: "Whole grain bread inLayer1", - ReleaseDate: "1992-01-01T00:00:00Z", - DiscontinuedDate: null, - Rating: 5, - Price: 3.5 - }, - Name: "Bread", - Description: "Whole grain bread", - ReleaseDate: "1992-01-01T00:00:00Z", - DiscontinuedDate: null, - Rating: 4, - Price: 2.5 - } - }, - { context: { response: { requestUri: "http://base.org" }, dataServiceVersion: "4.0" }, - expected: { - value: [{ - "@odata.etag": "W/MjAxMy0wNS0yN1QxMTo1OFo=", - "@odata.type": "#DataJS.Tests.V4.Food", - "@odata.mediaEditLink": "http://base.org/$metadata#Foods/mediaEditLink", - "@odata.mediaReadLink": "http://base.org/$metadata#Foods/mediaReadLink", - "@odata.mediaContentType": "http://base.org/$metadata#Foods/mediaContentType", - "@odata.mediaEtag": "http://base.org/$metadata#Foods/mediaEtag", - ID: 0, - Name: "Bread", - Description: "Whole grain bread", - ReleaseDate: "1992-01-01T00:00:00Z", - DiscontinuedDate: null, - Rating: 4, - Price: 2.5 - }, - { - "@odata.etag": "W/MjAxMy0wNS0yN1QxMTo1OFo=", - "@odata.type": "#DataJS.Tests.V4.Food", - "@odata.mediaEditLink": "http://base.org/$metadata#Foods/mediaEditLink2", - "@odata.mediaReadLink": "http://base.org/$metadata#Foods/mediaReadLink2", - "@odata.mediaContentType": "http://base.org/$metadata#Foods/mediaContentType2", - "@odata.mediaEtag": "http://base.org/$metadata#Foods/mediaEtag2", - ID: 1, - Name: "Bread", - Description: "Whole grain bread", - ReleaseDate: "1999-01-01T00:00:00Z", - DiscontinuedDate: null, - Rating: 6, - Price: 3.5 - }] - }, - data: { - value: [{ - "@odata.context": "http://base.org/$metadata#Foods/$entity", - "@odata.id": "Foods(4)", - "@odata.etag": "W/MjAxMy0wNS0yN1QxMTo1OFo=", - "@odata.editLink": "Foods(0)", - "@odata.type": "#DataJS.Tests.V4.Food", - "@odata.mediaEditLink": "http://base.org/$metadata#Foods/mediaEditLink", - "@odata.mediaReadLink": "http://base.org/$metadata#Foods/mediaReadLink", - "@odata.mediaContentType": "http://base.org/$metadata#Foods/mediaContentType", - "@odata.mediaEtag": "http://base.org/$metadata#Foods/mediaEtag", - ID: 0, - Name: "Bread", - Description: "Whole grain bread", - ReleaseDate: "1992-01-01T00:00:00Z", - DiscontinuedDate: null, - Rating: 4, - Price: 2.5 - }, - { - "@odata.context": "http://base.org/$metadata#Foods/$entity", - "@odata.id": "Foods(2)", - "@odata.etag": "W/MjAxMy0wNS0yN1QxMTo1OFo=", - "@odata.editLink": "Foods(2)", - "@odata.type": "#DataJS.Tests.V4.Food", - "@odata.mediaEditLink": "http://base.org/$metadata#Foods/mediaEditLink2", - "@odata.mediaReadLink": "http://base.org/$metadata#Foods/mediaReadLink2", - "@odata.mediaContentType": "http://base.org/$metadata#Foods/mediaContentType2", - "@odata.mediaEtag": "http://base.org/$metadata#Foods/mediaEtag2", - ID: 1, - Name: "Bread", - Description: "Whole grain bread", - ReleaseDate: "1999-01-01T00:00:00Z", - DiscontinuedDate: null, - Rating: 6, - Price: 3.5 - }] - } - } - ]; - var i, len; - for (i = 0, len = tests.length; i < len; i++) { - var data = tests[i].data ? tests[i].data : tests[i].expected; - var actual = OData.jsonSerializer(OData.jsonHandler, data, tests[i].context); - var expected = window.JSON.stringify(tests[i].expected); - djstest.assertAreEqualDeep(actual, expected, "test " + i + "didn't return the expected data"); - } - djstest.done(); - }); - - djstest.addTest(function normalizeHeadersReadTest() { - // Verifies that headers are normalized for reading. - // See issue at http://datajs.codeplex.com/workitem/148 - window.MockHttpClient.clear().addResponse("/foo", { - statusCode: 200, - body: { "@odata.context": "http://foo", value: [] }, - headers: { "unknown": "u", "Content-Encoding": "compress, gzip", "Content-Length": "8042", - "Content-Type": "application/json", "OData-Version": "4.0", "Etag": "Vetag", "Location": "foo", "OData-EntityId": "entityId", - "Preference-Applied": "prefered", "Retry-After": "retry" - } - }); - - odatajs.oData.read("/foo", function (data, response) { - // djstest.assertAreEqual(data.results.length, 2, "data.results.length has two entries"); - djstest.assertAreEqual(response.headers.unknown, "u", "u unmodified"); - djstest.assertAreEqual(response.headers["Content-Encoding"], "compress, gzip", "Content-Encoding available"); - djstest.assertAreEqual(response.headers["Content-Length"], "8042", "Content-Length available"); - djstest.assertAreEqual(response.headers["Content-Type"], "application/json", "Content-Type available"); - djstest.assertAreEqual(response.headers["ETag"], "Vetag", "Content-Type available"); - djstest.assertAreEqual(response.headers["Location"], "foo", "Content-Type available"); - djstest.assertAreEqual(response.headers["OData-EntityId"], "entityId", "OData-EntityId available"); - djstest.assertAreEqual(response.headers["Preference-Applied"], "prefered", "Preference-Applied available"); - djstest.assertAreEqual(response.headers["Retry-After"], "retry", "Retry available"); - djstest.assertAreEqual(response.headers["OData-Version"], "4.0", "OData-Version available"); - djstest.done(); - }, undefined, undefined, MockHttpClient); - }); - - djstest.addTest(function normalizeHeadersWriteTest() { - // Verifies that headers are normalized for writing. - // See issue at http://datajs.codeplex.com/workitem/148 - window.MockHttpClient.clear().addRequestVerifier("/foo", function (request) { - djstest.assertAreEqual(request.headers.Accept, "application/json", "Accept available"); - djstest.assertAreEqual(request.headers["Content-Type"], "application/json", "json found"); - djstest.assertAreEqual(request.headers["Content-Encoding"], "compress, gzip", "Content-Encoding available"); - djstest.assertAreEqual(request.headers["Content-Length"], "8042", "Content-Length available"); - djstest.assertAreEqual(request.headers["OData-Version"], "4.0", "OData-Version available"); - djstest.assertAreEqual(request.headers["Accept-Charset"], "Accept-Charset", "Accept-Charset available"); - djstest.assertAreEqual(request.headers["If-Match"], "true", "If-Match available"); - djstest.assertAreEqual(request.headers["If-None-Match"], "false", "If-None-Match available"); - djstest.assertAreEqual(request.headers["OData-Isolation"], "isolation", "OData-Isolation available"); - djstest.assertAreEqual(request.headers["OData-MaxVersion"], "4.0", "OData-MaxVersion available"); - djstest.assertAreEqual(request.headers["Prefer"], "prefer", "prefer available"); - djstest.done(); - }); - - var request = { - method: "POST", - requestUri: "/foo", - data: { value: 123 }, - headers: { "Accept": "application/json", "Content-Encoding": "compress, gzip", "Content-Length": "8042", "content-type": "application/json", "OData-Version": "4.0", - "accept-charset": "Accept-Charset", "if-match": "true", "if-none-match": "false", "odata-isolation": "isolation", - "odata-maxversion": "4.0", "prefer": "prefer" - } - }; - odatajs.oData.request(request, function (data) { - }, undefined, undefined, MockHttpClient); - }); - - // DATAJS INTERNAL END -})(this);
http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/4621d41c/JSLib/tests/odata-links-functional-tests.html ---------------------------------------------------------------------- diff --git a/JSLib/tests/odata-links-functional-tests.html b/JSLib/tests/odata-links-functional-tests.html deleted file mode 100644 index 95b0d36..0000000 --- a/JSLib/tests/odata-links-functional-tests.html +++ /dev/null @@ -1,44 +0,0 @@ -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> -<html> -<head> - <title>OData tests against local service</title> - <meta http-equiv="cache-control" content="no-cache"/> - <meta http-equiv="pragma" content="no-cache"/> - <meta http-equiv="expires" content="-1"/> - - <link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-1.10.0.css" type="text/css" /> - <script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/json2/20110223/json2.js"></script> - <script type="text/javascript" src="http://code.jquery.com/jquery-1.4.4.min.js"></script> - <script type="text/javascript" src="http://code.jquery.com/qunit/qunit-1.10.0.js"></script> - <script type="text/javascript" src="common/ODataReadOracle.js"></script> - <script type="text/javascript" src="common/TestSynchronizerClient.js"></script> - <script type="text/javascript"> - window.TestSynchronizer.init(QUnit); - </script> - - <script type="text/javascript" src="../src/datajs.js"></script> - <script type="text/javascript" src="../src/utils.js"></script> - <script type="text/javascript" src="../src/xml.js"></script> - - <script type="text/javascript" src="../src/odata-utils.js"></script> - <script type="text/javascript" src="../src/odata-handler.js"></script> - <script type="text/javascript" src="../src/odata-gml.js"></script> - <script type="text/javascript" src="../src/odata-xml.js"></script> - <script type="text/javascript" src="../src/odata-net.js"></script> - <script type="text/javascript" src="../src/odata-json-light.js"></script> - <script type="text/javascript" src="../src/odata-json.js"></script> - <script type="text/javascript" src="../src/odata-atom.js"></script> - <script type="text/javascript" src="../src/odata-metadata.js"></script> - <script type="text/javascript" src="../src/odata-batch.js"></script> - <script type="text/javascript" src="../src/odata.js"></script> - - <script type="text/javascript" src="common/djstest.js"></script> - <script type="text/javascript" src="odata-links-functional-tests.js"></script> -</head> -<body> - <h1 id="qunit-header">OData.Read tests against local in-memory service</h1> - <h2 id="qunit-banner"></h2> - <h2 id="qunit-userAgent"></h2> - <ol id="qunit-tests"></ol> -</body> -</html> http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/4621d41c/JSLib/tests/odata-links-functional-tests.js ---------------------------------------------------------------------- diff --git a/JSLib/tests/odata-links-functional-tests.js b/JSLib/tests/odata-links-functional-tests.js deleted file mode 100644 index 00ce591..0000000 --- a/JSLib/tests/odata-links-functional-tests.js +++ /dev/null @@ -1,232 +0,0 @@ -/// <reference path="common/djstest.js" /> -/// <reference path="../src/odata.js" /> -/// <reference path="common/ODataReadOracle.js" /> - -(function (window, undefined) { - var unexpectedErrorHandler = function (err) { - djstest.assert(false, "Unexpected call to error handler with error: " + djstest.toString(err)); - djstest.done(); - }; - - var uriRegEx = /^([^:/?#]+:)?(\/\/[^/?#]*)?([^?#:]+)?(\?[^#]*)?(#.*)?/; - var uriPartNames = ["scheme", "authority", "path", "query", "fragment"]; - - var getURIInfo = function (uri) { - /// <summary>Gets information about the components of the specified URI.</summary> - /// <param name="uri" type="String">URI to get information from.</param> - /// <returns type="Object"> - /// An object with an isAbsolute flag and part names (scheme, authority, etc.) if available. - /// </returns> - - var result = { isAbsolute: false }; - - if (uri) { - var matches = uriRegEx.exec(uri); - if (matches) { - var i, len; - for (i = 0, len = uriPartNames.length; i < len; i++) { - if (matches[i + 1]) { - result[uriPartNames[i]] = matches[i + 1]; - } - } - } - if (result.scheme) { - result.isAbsolute = true; - } - } - - return result; - }; - - var normalizeURI = function (uri, base) { - /// <summary>Normalizes a possibly relative URI with a base URI.</summary> - /// <param name="uri" type="String">URI to normalize, absolute or relative.</param> - /// <param name="base" type="String" mayBeNull="true">Base URI to compose with.</param> - /// <returns type="String">The composed URI if relative; the original one if absolute.</returns> - - if (!base) { - return uri; - } - - var uriInfo = getURIInfo(uri); - if (uriInfo.isAbsolute) { - return uri; - } - - var baseInfo = getURIInfo(base); - var normInfo = {}; - - if (uriInfo.authority) { - normInfo.authority = uriInfo.authority; - normInfo.path = uriInfo.path; - normInfo.query = uriInfo.query; - } else { - if (!uriInfo.path) { - normInfo.path = baseInfo.path; - normInfo.query = uriInfo.query || baseInfo.query; - } else { - if (uriInfo.path.charAt(0) === '/') { - normInfo.path = uriInfo.path; - } else { - normInfo.path = mergeUriPathWithBase(uriInfo, baseInfo); - } - - normInfo.query = uriInfo.query; - } - - normInfo.authority = baseInfo.authority; - } - - normInfo.scheme = baseInfo.scheme; - normInfo.fragment = uriInfo.fragment; - - return "".concat( - normInfo.scheme || "", - normInfo.authority || "", - normInfo.path || "", - normInfo.query || "", - normInfo.fragment || ""); - }; - - var mergeUriPathWithBase = function (uriInfo, baseInfo) { - /// <summary>Merges the path of a relative URI and a base URI.</summary> - /// <param name="uriInfo">URI component information for the relative URI.</param> - /// <param name="baseInfo">URI component information for the base URI.</param> - /// <returns type="String">A string with the merged path.</returns> - - var basePath = "/"; - if (baseInfo.path) { - var end = baseInfo.path.lastIndexOf("/"); - basePath = baseInfo.path.substring(0, end); - - if (basePath.charAt(basePath.length - 1) !== "/") { - basePath = basePath + "/"; - } - } - - return basePath + uriInfo.path; - }; - - var services = [ - "./endpoints/FoodStoreDataServiceV4.svc" - ]; - - var mimeTypes = [undefined, "application/json;odata.metadata=minimal"/*, "application/xml"*/]; - - var httpStatusCode = { - created: 201, - noContent: 204, - notFound: 404 - }; - - $.each(services, function (_, service) { - - var foodsFeed = service + "/Foods"; - var categoriesFeed = service + "/Categories"; - - var baseLinkUri = normalizeURI(service.substr(2), window.location.href); - - var newFoodLinks = { - "@odata.id": baseLinkUri + "/Foods" + "(1)" - }; - - var newCategoryLinks = { - "@odata.id": baseLinkUri + "/Categories" + "(2)" - }; - - - module("Functional", { - setup: function () { - djstest.wait(function (done) { - $.post(service + "/ResetData", done); - }); - } - }); - - var readLinksFeed = categoriesFeed + "(1)/Foods/$ref"; - var readLinksEntry = foodsFeed + "(0)/Category/$ref"; - - $.each(mimeTypes, function (_, mimeType) { - - var headers = mimeType ? { "Content-Type": mimeType, Accept: mimeType} : undefined; - - djstest.addTest(function readValidLinksFeedTests(params) { - djstest.assertsExpected(1); - odatajs.oData.read({ requestUri: params.linksFeed, headers: headers }, - function (data, response) { - window.ODataReadOracle.readLinksFeed(params.linksFeed, - function (expectedData) { - djstest.assertAreEqualDeep(data, expectedData, "Response data not same as expected"); - djstest.done(); - }, params.mimeType - ); - }, - unexpectedErrorHandler - ); - }, "Testing valid read of " + readLinksFeed + " with " + mimeType, { linksFeed: readLinksFeed, mimeType: mimeType }); - - djstest.addTest(function readValidLinksEntryTest(params) { - djstest.assertsExpected(1); - odatajs.oData.read({ requestUri: params.linksEntry, headers: headers }, - function (data, response) { - window.ODataReadOracle.readLinksEntry(params.linksEntry, - function (expectedData) { - djstest.assertAreEqualDeep(data, expectedData, "Response data not same as expected"); - djstest.done(); - }, params.mimeType - ); - }, - unexpectedErrorHandler - ); - }, "Testing valid read of " + readLinksEntry + " with " + mimeType, { linksEntry: readLinksEntry, mimeType: mimeType }); - - djstest.addTest(function addLinksEntityTest(mimeType) { - - var request = { - requestUri: foodsFeed + "(1)/Category/$ref", - method: "PUT", - headers: djstest.clone(headers), - data: newCategoryLinks - }; - - - odatajs.oData.request(request, function (data, response) { - var httpOperation = request.method + " " + request.requestUri; - djstest.assertAreEqual(response.statusCode, httpStatusCode.noContent, "Verify response code: " + httpOperation); - ODataReadOracle.readLinksEntry(request.requestUri, function (actualData) { - if (actualData && actualData["@odata.context"]) { - delete actualData["@odata.context"]; - } - - djstest.assertAreEqualDeep(actualData, request.data, "Verify new links entry against the request: " + httpOperation); - djstest.done(); - }); - }, unexpectedErrorHandler); - - }, "Add new links entity (mimeType = " + mimeType + " service = " + service + ")", mimeType); - - djstest.addTest(function addLinksFeedTest(mimeType) { - - var request = { - requestUri: categoriesFeed + "(2)/Foods/$ref", - method: "POST", - headers: djstest.clone(headers), - data: newFoodLinks - }; - - odatajs.oData.request(request, function (data, response) { - - var httpOperation = request.method + " " + request.requestUri; - djstest.assertAreEqual(response.statusCode, httpStatusCode.noContent, "Verify response code: " + httpOperation); - - odatajs.oData.read(request.requestUri, function (data, response) { - ODataReadOracle.readLinksFeed(request.requestUri, function (actualData) { - djstest.assertAreEqualDeep(actualData, response.data, "Verify updated links entry against the request: " + httpOperation); - djstest.done(); - }); - }); - }, unexpectedErrorHandler); - }, "Update entity (mimeType = " + mimeType + " service = " + service + ")", mimeType); - }); - }); -})(this); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/4621d41c/JSLib/tests/odata-metadata-awareness-functional-tests.html ---------------------------------------------------------------------- diff --git a/JSLib/tests/odata-metadata-awareness-functional-tests.html b/JSLib/tests/odata-metadata-awareness-functional-tests.html deleted file mode 100644 index 75fb2f2..0000000 --- a/JSLib/tests/odata-metadata-awareness-functional-tests.html +++ /dev/null @@ -1,43 +0,0 @@ -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> -<html> -<head> - <title>metadata awareness tests</title> - <meta http-equiv="cache-control" content="no-cache" /> - <meta http-equiv="pragma" content="no-cache" /> - <meta http-equiv="expires" content="-1" /> - <link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-1.10.0.css" type="text/css" /> - <script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/json2/20110223/json2.js"></script> - <script type="text/javascript" src="http://code.jquery.com/jquery-1.4.4.min.js"></script> - <script type="text/javascript" src="http://code.jquery.com/qunit/qunit-1.10.0.js"></script> - <script type="text/javascript" src="common/ODataReadOracle.js"></script> - <script type="text/javascript" src="common/TestSynchronizerClient.js"></script> - <script type="text/javascript"> - window.TestSynchronizer.init(QUnit); - </script> - - <script type="text/javascript" src="../src/datajs.js"></script> - <script type="text/javascript" src="../src/utils.js"></script> - <script type="text/javascript" src="../src/xml.js"></script> - - <script type="text/javascript" src="../src/odata-utils.js"></script> - <script type="text/javascript" src="../src/odata-handler.js"></script> - <script type="text/javascript" src="../src/odata-gml.js"></script> - <script type="text/javascript" src="../src/odata-xml.js"></script> - <script type="text/javascript" src="../src/odata-net.js"></script> - <script type="text/javascript" src="../src/odata-json-light.js"></script> - <script type="text/javascript" src="../src/odata-json.js"></script> - <script type="text/javascript" src="../src/odata-atom.js"></script> - <script type="text/javascript" src="../src/odata-metadata.js"></script> - <script type="text/javascript" src="../src/odata-batch.js"></script> - <script type="text/javascript" src="../src/odata.js"></script> - - <script type="text/javascript" src="common/djstest.js"></script> - <script type="text/javascript" src="odata-metadata-awareness-functional-tests.js"></script> -</head> -<body> - <h1 id="qunit-header">metadata awareness tests</h1> - <h2 id="qunit-banner"></h2> - <h2 id="qunit-userAgent"></h2> - <ol id="qunit-tests"></ol> -</body> -</html> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/4621d41c/JSLib/tests/odata-metadata-awareness-functional-tests.js ---------------------------------------------------------------------- diff --git a/JSLib/tests/odata-metadata-awareness-functional-tests.js b/JSLib/tests/odata-metadata-awareness-functional-tests.js deleted file mode 100644 index b40e703..0000000 --- a/JSLib/tests/odata-metadata-awareness-functional-tests.js +++ /dev/null @@ -1,227 +0,0 @@ -/// <reference path="common/djstest.js" /> -/// <reference path="../src/odata.js" /> -/// <reference path="common/ODataReadOracle.js" /> - -(function (window, undefined) { - var unexpectedErrorHandler = function (err) { - djstest.assert(false, "Unexpected call to error handler with error: " + djstest.toString(err)); - djstest.done(); - }; - - var service = "./endpoints/EpmDataService.svc"; - var metadataUri = service + "/$metadata"; - - var httpStatusCode = { - ok: 200, - created: 201, - noContent: 204 - }; - - var acceptHeaders = { Accept: "application/atom+xml" }; - var mimeHeaders = { "Content-Type": "application/atom+xml", Accept: "application/atom+xml" }; - var keepInContentVariations = [true, false]; - var feedUris = { "true": service + "/ReplicatedEntries", "false": service + "/MappedEntries" }; - var typeNames = { "true": "DataJS.Tests.ReplicatedEntry", "false": "DataJS.Tests.MappedEntry" }; - var selectProperties = ["Published", "Author", "CustomElement", "NestedElement1", "Published,Author,CustomElement,NestedElement1"]; - - var newEntry = { - UnmappedField: "Unmapped100", - Author: { - Email: "AuthorEmail100", - Name: "AuthorName100", - Uri: "http://www.example.com/AuthorUri100", - Contributor: { - Email: "ContributorEmail100", - Name: "ContributorName100", - Uri: "http://www.example.com/ContributorUri1000" - } - }, - Published: "2100-01-01T00:00:00-08:00", - Rights: "Rights100", - Summary: "<xmlElement xmlns=\"http://www.example.com/dummy\" attr=\"value100\">Summary100</xmlElement>", - Title: "Title<b>100</b>", - Updated: "2100-01-01T00:00:00-08:00", - CustomElement: "CustomElement100", - CustomAttribute: "CustomAttribute100", - NestedElement1: "NestedElement1_100", - NestedElement2: "NestedElement2_100", - CommonAttribute1: "CommonAttribute1_100", - CommonAttribute2: "CommonAttribute2_100", - Location: { - Lat: 1.23, - Long: 4.56 - } - }; - - var newSpecialValuesEntry = $.extend(true, {}, newEntry, { - Author: { - Email: null, - Name: "", - Uri: " ", - Contributor: { - Email: null, - Name: "", - Uri: " " - } - }, - Rights: null, - Summary: "", - Title: " ", - CustomElement: null, - NestedElement1: "", - NestedElement2: " ", - CustomAttribute: null, - CommonAttribute1: "", - CommonAttribute2: " " - }); - - var nullComplexTypeEntry = $.extend(true, {}, newEntry, { - Author: { Contributor: null }, - Location: null - }); - - var testEntries = [ - { data: newEntry, description: "entry" }, - { data: newSpecialValuesEntry, description: "entry containing null and empty string" }, - { data: nullComplexTypeEntry, description: "entry containing null complex type value" } - ]; - - var serviceMetadata; - var getMetadata = function (callback) { - /// <summary>Common function for tests to get and cache metadata, to reduce network calls made by tests</summary> - if (!serviceMetadata) { - odatajs.oData.read(metadataUri, function (metadata) { - serviceMetadata = metadata; - callback(metadata); - }, unexpectedErrorHandler, OData.metadataHandler); - } - else { - callback(serviceMetadata); - } - } - - module("Functional", { - setup: function () { - djstest.wait(function (done) { - $.post(service + "/ResetData", done); - }); - OData.defaultMetadata = []; - OData.jsonHandler.recognizeDates = false; - } - }); - - $.each(selectProperties, function (_, selectProperty) { - djstest.addTest(function getSelectPropertiesOnEntry(propertyToSelect) { - var entryUri = feedUris["true"] + "(0)?$select=" + propertyToSelect; - djstest.assertsExpected(2); - getMetadata(function (metadata) { - OData.defaultMetadata.push(metadata); - odatajs.oData.read({ requestUri: entryUri, headers: acceptHeaders }, function (data, response) { - djstest.assertAreEqual(response.statusCode, httpStatusCode.ok, "Verify response code"); - ODataReadOracle.readJson(entryUri, function (expectedData) { - djstest.assertWithoutMetadata(data, expectedData, "Verify data"); - djstest.done(); - }) - }, unexpectedErrorHandler); - }, unexpectedErrorHandler, OData.metadataHandler); - }, "GET with mapped properties selecting " + selectProperty + " with keepInContent = true", selectProperty); - }); - - $.each(keepInContentVariations, function (_, keepInContent) { - var feedUri = feedUris[keepInContent]; - - $.each(testEntries, function (entryIndex, testEntry) { - params = { - feedUri: feedUri, - testEntry: $.extend(true, {}, testEntry, { - data: { - "__metadata": { type: typeNames[keepInContent] } - } - }) - }; - - djstest.addTest(function getMappedEntry(params) { - var entryUri = params.feedUri + "(" + entryIndex + ")"; - djstest.assertsExpected(2); - getMetadata(function (metadata) { - OData.defaultMetadata.push(metadata); - odatajs.oData.read({ requestUri: entryUri, headers: acceptHeaders }, function (data, response) { - djstest.assertAreEqual(response.statusCode, httpStatusCode.ok, "Verify response code"); - ODataReadOracle.readJson(entryUri, function (expectedData) { - djstest.assertWithoutMetadata(data, expectedData, "Verify data"); - djstest.done(); - }) - }, unexpectedErrorHandler); - }, unexpectedErrorHandler, OData.metadataHandler); - }, "GET " + params.testEntry.description + " with mapped properties: keepInContent = " + keepInContent, params); - - djstest.addTest(function postMappedEntry(params) { - var postEntry = $.extend(true, {}, params.testEntry.data, { ID: 100 }); - djstest.assertsExpected(2); - getMetadata(function (metadata) { - odatajs.oData.request({ requestUri: params.feedUri, method: "POST", headers: djstest.clone(mimeHeaders), data: postEntry }, function (data, response) { - djstest.assertAreEqual(response.statusCode, httpStatusCode.created, "Verify response code"); - ODataReadOracle.readJson(feedUri + "(" + postEntry.ID + ")", function (actualData) { - djstest.assertWithoutMetadata(actualData, postEntry, "Verify new entry data against server"); - djstest.done(); - }) - }, unexpectedErrorHandler, undefined, undefined, metadata); - }, unexpectedErrorHandler, OData.metadataHandler); - }, "POST " + params.testEntry.description + " with mapped properties: keepInContent = " + keepInContent, params); - - djstest.addTest(function putMappedEntry(params) { - var entryUri = params.feedUri + "(0)"; - djstest.assertsExpected(2); - getMetadata(function (metadata) { - OData.defaultMetadata.push(metadata); - odatajs.oData.request({ requestUri: entryUri, method: "PUT", headers: djstest.clone(mimeHeaders), data: params.testEntry.data }, function (data, response) { - djstest.assertAreEqual(response.statusCode, httpStatusCode.noContent, "Verify response code"); - ODataReadOracle.readJson(entryUri, function (actualData) { - djstest.assertWithoutMetadata(actualData, $.extend({ ID: 0 }, params.testEntry.data), "Verify updated entry data against server"); - djstest.done(); - }) - }, unexpectedErrorHandler); - }, unexpectedErrorHandler, OData.metadataHandler); - }, "PUT " + params.testEntry.description + " with mapped properties: keepInContent = " + keepInContent, params); - }); - }); - - var descriptions = ["base type", "derived type"]; - $.each(descriptions, function (index, _) { - djstest.addTest(function getHierarchicalEntry(index) { - var entryUri = service + "/HierarchicalEntries(" + index + ")"; - djstest.assertsExpected(2); - getMetadata(function (metadata) { - odatajs.oData.read({ requestUri: entryUri, headers: acceptHeaders }, function (data, response) { - djstest.assertAreEqual(response.statusCode, httpStatusCode.ok, "Verify response code"); - ODataReadOracle.readJson(entryUri, function (expectedData) { - djstest.assertWithoutMetadata(data, expectedData, "Verify data"); - djstest.done(); - }) - }, unexpectedErrorHandler, undefined, undefined, metadata); - }, unexpectedErrorHandler, OData.metadataHandler); - }, "GET " + descriptions[index] + " with mapped properties: keepInContent = false", index); - }); - - $.each([false, true], function (_, recognizeDates) { - djstest.addTest(function readDateTimeWithMetadataTest(params) { - var foodStoreDataService = "./endpoints/FoodStoreDataServiceV4.svc"; - var specialDaysEndpoint = foodStoreDataService + "/SpecialDays"; - - djstest.assertsExpected(1); - OData.jsonHandler.recognizeDates = params.recognizeDates; - odatajs.oData.read(foodStoreDataService + "/$metadata", function (metadata) { - odatajs.oData.read({ requestUri: specialDaysEndpoint, headers: { Accept: params.accept} }, function (data, response) { - // Because our oracle isn't metadata aware, it is not 100% correct, so we will pass in recognizeDates = true - // in all cases and manually fix up the property that was incorrectly converted - window.ODataReadOracle.readFeed(specialDaysEndpoint, function (expectedData) { - // Fix up the string property that has a "date-like" string deliberately injected - expectedData.results[2].Name = "/Date(" + expectedData.results[2].Name.valueOf() + ")/"; - djstest.assertAreEqualDeep(data, expectedData, "Verify response data"); - djstest.done(); - }, params.accept, true); - }, unexpectedErrorHandler, undefined, undefined, metadata); - }, unexpectedErrorHandler, OData.metadataHandler); - }, "GET metadata-aware JSON dates with recognizeDates=" + recognizeDates, { recognizeDates: recognizeDates, accept: "application/json;odata.metadata=minimal" }); - }); -})(this);
