You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by ch...@apache.org on 2014/08/28 05:48:12 UTC
[05/51] [partial] rename folder /datajs into /odatajs. no file
modification.
http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/d5ec5557/odatajs/tests/odata-json-parse-tests.html
----------------------------------------------------------------------
diff --git a/odatajs/tests/odata-json-parse-tests.html b/odatajs/tests/odata-json-parse-tests.html
new file mode 100644
index 0000000..57db067
--- /dev/null
+++ b/odatajs/tests/odata-json-parse-tests.html
@@ -0,0 +1,67 @@
+<!--
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+ -->
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
+<html>
+<!--
+Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
+modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+-->
+ <head>
+ <meta http-equiv="X-UA-Compatible" content="IE=Edge" />
+ <meta http-equiv="cache-control" content="no-cache" />
+ <meta http-equiv="pragma" content="no-cache" />
+ <meta http-equiv="expires" content="-1" />
+
+ <title>OData unit tests</title>
+ <link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-1.10.0.css" type="text/css" />
+
+ <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="http://cdnjs.cloudflare.com/ajax/libs/json2/20110223/json2.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="../build/odatajs-4.0.0-beta-01.js"></script>
+ <script type="text/javascript" src="common/common.js"></script>
+ <script type="text/javascript" src="common/djstest.js"></script>
+ <script type="text/javascript" src="odata-json-parse-tests.js"></script>
+ </head>
+ <body>
+ <h1 id="qunit-header">OData Unit 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/d5ec5557/odatajs/tests/odata-json-parse-tests.js
----------------------------------------------------------------------
diff --git a/odatajs/tests/odata-json-parse-tests.js b/odatajs/tests/odata-json-parse-tests.js
new file mode 100644
index 0000000..00f0ba2
--- /dev/null
+++ b/odatajs/tests/odata-json-parse-tests.js
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+// odata-tests.js
+(function (window, undefined) {
+ function errorFunc() {
+ djstest.fail('Errror');
+ }
+
+ function runWithMetadata(metaDatasuccess) {
+ var oHeaders = {
+ 'Accept': 'text/html,application/xhtml+xml,application/xml,application/json;odata.metadata=full',
+ "Odata-Version": "4.0",
+ "OData-MaxVersion": "4.0",
+ "Prefer": "odata.allow-entityreferences"
+ };
+ var metadataRequest =
+ {
+ headers: oHeaders,
+ //requestUri: "http://services.odata.org/OData/OData.svc/$metadata",
+ requestUri: "http://localhost:4002/tests/endpoints/FoodStoreDataServiceV4.svc/$metadata", //"http://localhost:6630/PrimitiveKeys.svc/$metadata",
+ data: null,
+ };
+ odatajs.oData.read(metadataRequest, metaDatasuccess, errorFunc,OData.metadataHandler);
+ }
+
+ djstest.addTest(function test1() {
+ var checkAll = function (metadata, input, expected) {
+ var info = window.odatajs.oData.json.createPayloadInfo({ "@odata.context" : input}, metadata);
+ djstest.assertAreEqual(info,expected, "Test context fragment: "+ input);
+ };
+
+ var checkLastTypeName = function (metadata, input, expectedKind, expectedLastTypeName) {
+ var info = window.odatajs.oData.json.createPayloadInfo({ "@odata.context" : input}, metadata);
+ djstest.assertAreEqual(info.detectedPayloadKind,expectedKind, "Test context fragment: "+ input);
+ djstest.assertAreEqual(info.typeName,expectedLastTypeName, "Test context fragment: "+ input);
+ };
+
+ var checkProjection = function (metadata, input, expectedKind, expectedLastTypeName, projection) {
+ var info = window.odatajs.oData.json.createPayloadInfo({ "@odata.context" : input}, metadata);
+ djstest.assertAreEqual(info.detectedPayloadKind,expectedKind, "Test context fragment: "+ input);
+ djstest.assertAreEqual(info.typeName,expectedLastTypeName, "Test context fragment: "+ input);
+ djstest.assertAreEqual(info.projection,projection, "Test context fragment: "+ input);
+ };
+
+ var checkKind = function (metadata, input, expected) {
+ var info = window.odatajs.oData.json.createPayloadInfo({ "@odata.context" : input}, metadata);
+ djstest.assertAreEqual(info.detectedPayloadKind,expected, "Test context fragment: "+ input);
+ };
+
+ var success = function(metadata){
+ //Chapter 10.1
+ checkKind(metadata, '#', 's');
+ //Chapter 10.2
+ checkLastTypeName(metadata, '#Foods', 'f', 'DataJS.Tests.V4.Food');
+ //Chapter 10.3
+ checkLastTypeName(metadata, '#Foods/$entity', 'e', 'DataJS.Tests.V4.Food');
+ //Chapter 10.4
+ //checkKind(metadata, '#Singleton', '');
+ //Chapter 10.5
+ checkLastTypeName(metadata, '#Foods/DataJS.Tests.V4.Food', 'f', 'DataJS.Tests.V4.Food');
+ //Chapter 10.6
+ checkLastTypeName(metadata, '#Foods/DataJS.Tests.V4.Food/$entity', 'e', 'DataJS.Tests.V4.Food');
+ //Chapter 10.7
+ checkProjection(metadata, '#Foods(FoodID,Name)', 'f', 'DataJS.Tests.V4.Food','FoodID,Name');
+ //Chapter 10.8
+ checkProjection(metadata, '#Foods(FoodID,Name)/$entity', 'e', 'DataJS.Tests.V4.Food','FoodID,Name');
+ //Chapter 10.9
+ checkProjection(metadata, '#Foods(FoodID,Name,Category,Category+(CategoryID,Name))', 'f',
+ 'DataJS.Tests.V4.Food','FoodID,Name,Category,Category+(CategoryID,Name)');
+ //Chapter 10.10
+ checkProjection(metadata, '#Foods(FoodID,Name,Category,Category+(CategoryID,Name))/$entity', 'e',
+ 'DataJS.Tests.V4.Food','FoodID,Name,Category,Category+(CategoryID,Name)');
+ //Chapter 10.11
+ checkKind(metadata, '#Collection($ref)', 'erls');
+ //Chapter 10.12
+ checkKind(metadata, '#$ref', 'erl');
+ //Chapter 10.13
+ checkKind(metadata, '#Foods(0)/Packaging', 'p', 'DataJS.Tests.V4.Package');
+ //Chapter 10.14
+ checkKind(metadata, '#Collection(Edm.String)', 'c', 'Edm.String');
+ //Chapter 10.15
+ checkKind(metadata, '#Edm.String', 'v');
+
+ checkKind(metadata, '#Edm.Null', 'v');
+ //TODO add tests for delta tokens
+ djstest.done();
+ };
+
+ runWithMetadata(success);
+ },'test createPayloadInfo');
+
+
+})(this);
http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/d5ec5557/odatajs/tests/odata-json-tests.js
----------------------------------------------------------------------
diff --git a/odatajs/tests/odata-json-tests.js b/odatajs/tests/odata-json-tests.js
new file mode 100644
index 0000000..7d30a7c
--- /dev/null
+++ b/odatajs/tests/odata-json-tests.js
@@ -0,0 +1,986 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+// odata-tests.js
+
+(function (window, undefined) {
+
+
+ djstest.addTest(function isArrayTest() {
+ console.log("hier-----------------------");
+ djstest.assert(odatajs.utils.isArray([]));
+ djstest.assert(odatajs.utils.isArray([1, 2]));
+ djstest.assert(!odatajs.utils.isArray({}));
+ djstest.assert(!odatajs.utils.isArray("1,2,3,4"));
+ djstest.assert(!odatajs.utils.isArray());
+ djstest.assert(!odatajs.utils.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)",
+ "Categories@odata.navigationLink": "Products(0)/Categories",
+ "Categories@odata.associationLink": "Products(0)/Categories/$ref",
+ "Supplier@odata.navigationLink": "Products(0)/Supplier",
+ "Supplier@odata.associationLink": "Products(0)/Supplier/$ref",
+ "ProductDetail@odata.navigationLink": "Products(0)/ProductDetail",
+ "ProductDetail@odata.associationLink": "Products(0)/ProductDetail/$ref",
+ ID: 0,
+ Name: "Bread",
+ Description: "Whole grain bread",
+ "ReleaseDate@odata.type": "#DateTimeOffset",
+ ReleaseDate: "1992-01-01T00:00:00Z",
+ DiscontinuedDate: null,
+ "Rating@odata.type": "#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)",
+ "Categories@odata.navigationLink": "Products(0)/Categories",
+ "Categories@odata.associationLink": "Products(0)/Categories/$ref",
+ "Supplier@odata.navigationLink": "Products(0)/Supplier",
+ "Supplier@odata.associationLink": "Products(0)/Supplier/$ref",
+ "ProductDetail@odata.navigationLink": "Products(0)/ProductDetail",
+ "ProductDetail@odata.associationLink": "Products(0)/ProductDetail/$ref",
+ ID: 0,
+ Name: "Bread",
+ Description: "Whole grain bread",
+ "ReleaseDate@odata.type": "#DateTimeOffset",
+ ReleaseDate: "1992-01-01T00:00:00Z",
+ DiscontinuedDate: null,
+ "Rating@odata.type": "#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: [
+ "グぁマせぺネソぁぼソひバたぴソ歹九ネボボяポソ畚クяせべ歹珱Я欲タハバミ裹ぼボをヲ歹んひ九ひ匚ぁa",
+ "qckrnuruxcbhjfimnsykgfquffobcadpsaocixoeljhspxrhebkudppgndgcrlyvynqhbujrnvyxyymhnroemigogsqulvgallta",
+ "btsnhqrjqryqzgxducl",
+ "qbtlssjhunufmzdv",
+ "ボんЯぜチべゼボボほa匚ミぼ九ぁひチ珱黑ミんぁタび暦クソソボゾんんあゼぞひタボタぜん弌ひべ匚",
+ "vicqasfdkxsuyuzspjqunxpyfuhlxfhgfqnlcpdfivqnxqoothnfsbuykfguftgulgldnkkzufssbae",
+ "九ソミせボぜゾボёaをぜЯまゾタぜタひ縷ダんaバたゼソ",
+ "ぽマタぁぁ黑ソゼミゼ匚zソダマぁァゾぽミaタゾ弌ミゼタそzぺポせ裹バポハハヲぺチあマ匚ミ",
+ "hssiißuamtctgqhglmusexyikhcsqctusonubxorssyizhyqpbtbdßjnelxqttkhdalabibuqhiubtßsptrmzelud",
+ "gbjssllxzzxkmßppyyrhgmoeßizlcmsuqqnvjßudszevtfunflqzqcuubukypßqjcix"
+ ]
+ }
+ }
+ ];
+
+ var i, len;
+ for (i = 0, len = tests.length; i < len; i++) {
+ var data = JSON.stringify(tests[i].expected);
+ var actual = window.odatajs.oData.json.jsonParser(window.odatajs.oData.json.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: [
+ "グぁマせぺネソぁぼソひバたぴソ歹九ネボボяポソ畚クяせべ歹珱Я欲タハバミ裹ぼボをヲ歹んひ九ひ匚ぁa",
+ "qckrnuruxcbhjfimnsykgfquffobcadpsaocixoeljhspxrhebkudppgndgcrlyvynqhbujrnvyxyymhnroemigogsqulvgallta",
+ "btsnhqrjqryqzgxducl",
+ "qbtlssjhunufmzdv",
+ "ボんЯぜチべゼボボほa匚ミぼ九ぁひチ珱黑ミんぁタび暦クソソボゾんんあゼぞひタボタぜん弌ひべ匚",
+ "vicqasfdkxsuyuzspjqunxpyfuhlxfhgfqnlcpdfivqnxqoothnfsbuykfguftgulgldnkkzufssbae",
+ "九ソミせボぜゾボёaをぜЯまゾタぜタひ縷ダんaバたゼソ",
+ "ぽマタぁぁ黑ソゼミゼ匚zソダマぁァゾぽミaタゾ弌ミゼタそzぺポせ裹バポハハヲぺチあマ匚ミ",
+ "hssiißuamtctgqhglmusexyikhcsqctusonubxorssyizhyqpbtbdßjnelxqttkhdalabibuqhiubtßsptrmzelud",
+ "gbjssllxzzxkmßppyyrhgmoeßizlcmsuqqnvjßudszevtfunflqzqcuubukypßqjcix"
+ ]
+ }
+ },
+ { context: { response: { requestUri: "http://base.org" }, dataServiceVersion: "4.0" },
+ expected: {
+ "@odata.id": "Foods(4)",
+ "@odata.type": "#DataJS.Tests.V4.Food",
+ 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: {
+ "@odata.id": "Foods(4)",
+ value : [{
+ "@odata.id": "Foods(4)",
+ "@odata.type": "#DataJS.Tests.V4.Food",
+ ID: 0,
+ ComplexInLayerOne:
+ {
+ "@odata.id": "Foods(4)",
+ "@odata.type": "#DataJS.Tests.V4.Food",
+ ID: 1,
+ ComplexInLayerTwo:
+ {
+ "@odata.id": "Foods(4)",
+ "@odata.type": "#DataJS.Tests.V4.Food",
+ ID: 2,
+ ComplexInLayerThreeList: [
+ {
+ "@odata.id": "Foods(4)",
+ "@odata.type": "#DataJS.Tests.V4.Food",
+ ID: 3,
+ Name: "BreadInLayer3",
+ Description: "Whole grain bread inLayer3",
+ ReleaseDate: "1992-01-01T00:00:00Z",
+ DiscontinuedDate: null,
+ Rating: 7,
+ Price: 5.5
+ },
+ {
+ "@odata.id": "Foods(4)",
+ "@odata.type": "#DataJS.Tests.V4.Food",
+ 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.id": "Foods(4)",
+ "@odata.type": "#DataJS.Tests.V4.Food",
+ ID: 0,
+ ComplexInLayerOne:
+ {
+ "@odata.id": "Foods(4)",
+ "@odata.type": "#DataJS.Tests.V4.Food",
+ ID: 1,
+ ComplexInLayerTwo:
+ {
+ "@odata.id": "Foods(4)",
+ "@odata.type": "#DataJS.Tests.V4.Food",
+ ID: 2,
+ ComplexInLayerThreeList: [
+ {
+ "@odata.id": "Foods(4)",
+ "@odata.type": "#DataJS.Tests.V4.Food",
+ ID: 3,
+ Name: "BreadInLayer3",
+ Description: "Whole grain bread inLayer3",
+ ReleaseDate: "1992-01-01T00:00:00Z",
+ DiscontinuedDate: null,
+ Rating: 7,
+ Price: 5.5
+ },
+ {
+ "@odata.id": "Foods(4)",
+ "@odata.type": "#DataJS.Tests.V4.Food",
+ 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.id": "Foods(4)",
+ "@odata.type": "#DataJS.Tests.V4.Food",
+ ID: 0,
+ ComplexInLayerOne:
+ {
+ "@odata.id": "Foods(4)",
+ "@odata.type": "#DataJS.Tests.V4.Food",
+ ID: 1,
+ ComplexInLayerTwo:
+ {
+ "@odata.id": "Foods(4)",
+ "@odata.type": "#DataJS.Tests.V4.Food",
+ ID: 2,
+ ComplexInLayerThree:
+ {
+ "@odata.id": "Foods(4)",
+ "@odata.type": "#DataJS.Tests.V4.Food",
+ 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.id": "Foods(4)",
+ "@odata.type": "#DataJS.Tests.V4.Food",
+ ID: 0,
+ Name: "Bread",
+ Description: "Whole grain bread",
+ ReleaseDate: "1992-01-01T00:00:00Z",
+ DiscontinuedDate: null,
+ Rating: 4,
+ Price: 2.5
+ },
+ {
+ "@odata.id": "Foods(2)",
+ "@odata.type": "#DataJS.Tests.V4.Food",
+ 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 = window.odatajs.oData.json.jsonSerializer(window.odatajs.oData.json.jsonHandler, data, tests[i].context);
+ var expected = 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
+ MockHttpClient.clear();
+
+ 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
+
+ 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);
+
+ });
+
+ var verifyReadJsonLightDataMetadataFull = function (input, expected, message, model) {
+ var response = {
+ headers: {
+ "Content-Type": "application/json;odata.metadata=full",
+ DataServiceVersion: "4.0"
+ },
+ body: JSON.stringify(input)
+ };
+
+ window.odatajs.oData.json.jsonHandler.read(response, { metadata: model });
+ djstest.assertAreEqualDeep(response.data, expected, message);
+ };
+
+
+ var verifyReadJsonLightDataMetadataMinimal= function (input, expected, message, model) {
+ var response = {
+ headers: {
+ "Content-Type": "application/json;odata.metadata=minimal",
+ DataServiceVersion: "4.0"
+ },
+ body: JSON.stringify(input)
+ };
+
+ window.odatajs.oData.json.jsonHandler.read(response, { metadata: model });
+ djstest.assertAreEqualDeep(response.data, expected, message);
+ };
+
+ var getPointValue = { edmType : 'GeographyPoint', value : {
+ type: "Point",
+ coordinates: [1.0, 2.0],
+ crs: {
+ type: "Point",
+ properties: {
+ name: "EPSG:4326"
+ }
+ }
+ }};
+
+ var getLineStringValue = { edmType : 'GeographyLineString', value : {
+ "type": "LineString",
+ "coordinates": [ [100.0, 0.0], [101.0, 1.0] ],
+ crs: {
+ type: "LineString",
+ properties: {
+ name: "EPSG:4326"
+ }
+ }
+ }};
+
+ var getPolygonValue = { edmType : 'GeographyPolygon', value : {
+ "type": "Polygon",
+ "coordinates": [
+ [ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0] ],
+ [ [100.2, 0.2], [100.8, 0.2], [100.8, 0.8], [100.2, 0.8], [100.2, 0.2] ]
+ ],
+ crs: {
+ type: "Polygon",
+ properties: {
+ name: "EPSG:4326"
+ }
+ }
+ }};
+
+ var getMultiPointValue = { edmType : 'GeographyMultiPoint', value : {
+ "type": "MultiPoint",
+ "coordinates": [ [100.0, 0.0], [101.0, 1.0] ],
+ crs: {
+ type: "MultiPoint",
+ properties: {
+ name: "EPSG:4326"
+ }
+ }
+ }};
+
+ var getMultiLineStringValue = { edmType : 'GeographyMultiLineString', value : {
+ "type": "MultiLineString",
+ "coordinates": [
+ [ [100.0, 0.0], [101.0, 1.0] ],
+ [ [102.0, 2.0], [103.0, 3.0] ]
+ ],
+ crs: {
+ type: "MultiLineString",
+ properties: {
+ name: "EPSG:4326"
+ }
+ }
+ }};
+ var getMultiPolygonStringValue = { edmType : 'GeographyMultiPolygon', value : {
+ "type": "MultiPolygon",
+ "coordinates": [
+ [[[102.0, 2.0], [103.0, 2.0], [103.0, 3.0], [102.0, 3.0], [102.0, 2.0]]],
+ [[[100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0]],
+ [[100.2, 0.2], [100.8, 0.2], [100.8, 0.8], [100.2, 0.8], [100.2, 0.2]]]
+ ],
+ crs: {
+ type: "MultiPolygon",
+ properties: {
+ name: "EPSG:4326"
+ }
+ }
+ }};
+
+ var getWorkload = [getPointValue, getLineStringValue, getPolygonValue, getMultiPointValue, getMultiLineStringValue, getMultiPolygonStringValue ];
+
+
+ djstest.addTest(function jsonReadGeometryPointFull() {
+
+ for ( var i = 0; i < getWorkload.length; i++) {
+ var item = getWorkload[i];
+ var input = {
+ "@odata.context": "http://someUri#Edm."+item.edmType,
+ "value@odata.type" : item.edmType,
+ value: item.value
+ };
+
+ var expected = {
+ "@odata.context": "http://someUri#Edm."+item.edmType,
+ "value@odata.type" : item.edmType,
+ value: item.value
+ };
+ verifyReadJsonLightDataMetadataFull(input, expected, "Json light top level primitive property was read properly.");
+ }
+
+ djstest.done();
+ });
+
+
+ djstest.addTest(function jsonReadGeometryPointMinimal() {
+ for ( var i = 0; i < getWorkload.length; i++) {
+ var item = getWorkload[i];
+ var input = {
+ "@odata.context": "http://someUri#Edm."+item.edmType,
+ value: item.value
+ };
+
+ var expected = {
+ "@odata.context": "http://someUri#Edm."+item.edmType,
+ value: item.value,
+ "value@odata.type" : item.edmType,
+ };
+
+ verifyReadJsonLightDataMetadataMinimal(input, expected, "Json light top level primitive property was read properly.", {});
+ }
+ djstest.done();
+ });
+
+})(this);
http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/d5ec5557/odatajs/tests/odata-links-functional-tests.html
----------------------------------------------------------------------
diff --git a/odatajs/tests/odata-links-functional-tests.html b/odatajs/tests/odata-links-functional-tests.html
new file mode 100644
index 0000000..21952d8
--- /dev/null
+++ b/odatajs/tests/odata-links-functional-tests.html
@@ -0,0 +1,49 @@
+<!--
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+*/
+-->
+<!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="../build/odatajs-4.0.0-beta-01.js"></script>
+ <script type="text/javascript" src="common/common.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/d5ec5557/odatajs/tests/odata-links-functional-tests.js
----------------------------------------------------------------------
diff --git a/odatajs/tests/odata-links-functional-tests.js b/odatajs/tests/odata-links-functional-tests.js
new file mode 100644
index 0000000..eb64ec0
--- /dev/null
+++ b/odatajs/tests/odata-links-functional-tests.js
@@ -0,0 +1,274 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+(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) {
+ /** Gets information about the components of the specified URI.
+ * @param {String} uri - URI to get information from.
+ * @returns {Object}
+ * An object with an isAbsolute flag and part names (scheme, authority, etc.) if available.
+ */
+
+ 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) {
+ /** Normalizes a possibly relative URI with a base URI.
+ * @param {String} uri - URI to normalize, absolute or relative.
+ * @param {String} base - Base URI to compose with (may be null)
+ * @returns {String} The composed URI if relative; the original one if absolute.
+ */
+
+ 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) {
+ /** Merges the path of a relative URI and a base URI.
+ * @param uriInfo - URI component information for the relative URI.
+ * @param baseInfo - URI component information for the base URI.
+ * @returns {String} A string with the merged path.
+ */
+
+ 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"];
+
+ 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 updateLinksEntityTest(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);
+
+ }, "Update links entity (mimeType = " + mimeType + " service = " + service + ")", mimeType);
+
+ djstest.addTest(function addDeleteLinksFeedTest(mimeType) {
+
+ var request = {
+ requestUri: categoriesFeed + "(2)/Foods/$ref",
+ method: "POST",
+ headers: djstest.clone(headers),
+ data: newFoodLinks
+ };
+
+ var deleteAndVerify = function (){
+
+ // delete by id
+ var deletionRequest = {
+ requestUri: categoriesFeed + "(2)/Foods/$ref?$id=" + newFoodLinks["@odata.id"],
+ method: "DELETE",
+ headers: djstest.clone(headers),
+ data: null
+ };
+
+ odatajs.oData.request(deletionRequest, function (data, response) {
+ var httpOperation = deletionRequest.method + " " + deletionRequest.requestUri;
+ djstest.assertAreEqual(response.statusCode, httpStatusCode.noContent, "Verify response code: " + httpOperation);
+
+ odatajs.oData.read(request.requestUri, function (data, response) {
+ var httpOperation = "Read " + request.requestUri;
+ djstest.assertAreEqual(0, response.data.value.length, "Verify links against the request: " + httpOperation);
+ djstest.done();
+ },unexpectedErrorHandler);
+ }, unexpectedErrorHandler);
+ };
+
+ // add
+ 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);
+ deleteAndVerify();
+ });
+ });
+ }, unexpectedErrorHandler);
+
+ }, "Add & Delete 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/d5ec5557/odatajs/tests/odata-metadata-awareness-functional-tests.html
----------------------------------------------------------------------
diff --git a/odatajs/tests/odata-metadata-awareness-functional-tests.html b/odatajs/tests/odata-metadata-awareness-functional-tests.html
new file mode 100644
index 0000000..fc5bb0b
--- /dev/null
+++ b/odatajs/tests/odata-metadata-awareness-functional-tests.html
@@ -0,0 +1,48 @@
+<!--
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+*/
+-->
+<!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="../build/odatajs-4.0.0-beta-01.js"></script>
+ <script type="text/javascript" src="common/common.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