You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by ko...@apache.org on 2015/02/23 11:11:27 UTC
[20/41] olingo-odata4-js git commit: [OLINGO-541] Move the odatajs
branch one directory up
http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/503b4417/odatajs/tests/store-indexeddb-tests.js
----------------------------------------------------------------------
diff --git a/odatajs/tests/store-indexeddb-tests.js b/odatajs/tests/store-indexeddb-tests.js
deleted file mode 100644
index 47690a4..0000000
--- a/odatajs/tests/store-indexeddb-tests.js
+++ /dev/null
@@ -1,262 +0,0 @@
-/*
- * 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.
- */
-
-// store-indexeddb-tests.js
-
-(function (window, undefined) {
- // DATAJS INTERNAL START
- var unexpectedSuccess = function (key, value) {
- djstest.fail("Unexpected call to success handler: key = " + key + ", value = " + value);
- djstest.done();
- };
-
- var unexpectedError = function (e) {
- djstest.fail("Unexpected call to error handler: " + djstest.toString(e));
- djstest.done();
- };
-
- var storeCounter = 0;
- var storeName = "test";
-
- var getNextStoreName = function () {
- storeCounter++;
- return getCurrentStoreName();
- };
-
- var getCurrentStoreName = function(){
- return storeName + storeCounter;
- };
-
- var oldWindowOnError;
-
- if (djstest.indexedDB) {
- module("Unit", {
- setup: function () {
- djstest.wait(function (done) {
- djstest.cleanStoreOnIndexedDb([{ name: getNextStoreName() }], done);
- });
-
- // FireFox 7.0.1 bubbles an error event when there is an IndexedDB error, even when the error has been handled graciously.
- // This is a work around to keep QUnit from reporting false failures in IndexedDB negative tests.
- oldWindowOnError = window.onerror;
- window.onerror = null;
- },
- teardown: function () {
- var store = this.store;
- if (store) {
- store.close();
- }
-
- djstest.wait(function (done) {
- djstest.cleanStoreOnIndexedDb([store], done);
- });
-
-
- // Restore QUnit's onerror handler.
- window.onerror = oldWindowOnError;
- }
- });
-
- djstest.addTest(function testIndexedDBStoreConstructor() {
- var store = this.store = window.odatajs.store.IndexedDBStore.create(getCurrentStoreName());
- djstest.assertAreEqual(store.name, getCurrentStoreName());
- djstest.assertAreEqual(store.mechanism, "indexeddb");
- djstest.done();
- });
-
- djstest.addTest(function testIndexedDBStoreAddGet() {
- var store = this.store = window.odatajs.store.IndexedDBStore.create(getCurrentStoreName());
- store.add("key", "value", function (key, value) {
- djstest.assertAreEqual(key, "key");
- djstest.assertAreEqual(value, "value");
- store.read("key", function (key, value) {
- djstest.assertAreEqual(key, "key");
- djstest.assertAreEqual(value, "value");
- djstest.done();
- }, unexpectedError);
- }, unexpectedError);
- });
-
- djstest.addTest(function testIndexedDBStoreAddUpdateGet() {
- var store = this.store = window.odatajs.store.IndexedDBStore.create(getCurrentStoreName());
- store.add("key", "value", function (key, value) {
- store.update("key", "value2", function (key, value) {
- djstest.assertAreEqual(key, "key");
- djstest.assertAreEqual(value, "value2");
- store.read("key", function (key, value) {
- djstest.assertAreEqual(key, "key");
- djstest.assertAreEqual(value, "value2");
- djstest.done();
- }, unexpectedError);
- }, unexpectedError);
- }, unexpectedError);
- });
-
- djstest.addTest(function testIndexedDBStoreAddOrUpdateGet() {
- var store = this.store = window.odatajs.store.IndexedDBStore.create(getCurrentStoreName());
- store.addOrUpdate("key", "value", function (key, value) {
- djstest.assertAreEqual(key, "key");
- djstest.assertAreEqual(value, "value");
- store.addOrUpdate("key", "value2", function (key, value) {
- djstest.assertAreEqual(key, "key");
- djstest.assertAreEqual(value, "value2");
- store.read("key", function (key, value) {
- djstest.assertAreEqual(key, "key");
- djstest.assertAreEqual(value, "value2");
- djstest.done();
- }, unexpectedError);
- }, unexpectedError);
- }, unexpectedError);
- });
-
- djstest.addTest(function testIndexedDBStoreAddRemoveContains() {
- var store = this.store = window.odatajs.store.IndexedDBStore.create(getCurrentStoreName());
- store.add("key", "value", function (key, value) {
- store.contains("key", function (result) {
- djstest.assert(result);
- store.remove("key", function () {
- djstest.pass("key removed");
- store.contains("key", function (result) {
- djstest.assert(!result);
- djstest.done();
- }, unexpectedError);
- }, unexpectedError);
- }, unexpectedError);
- }, unexpectedError);
- });
-
- djstest.addTest(function testIndexedDBStoreAddConsecutiveGetAllKeys() {
- var store = this.store = window.odatajs.store.IndexedDBStore.create(getCurrentStoreName());
- store.add("key", "value", function (key, value) {
- store.add("key2", "value2", function (key, value) {
- store.add("key3", "value3", function (key, value) {
- store.getAllKeys(function (keys) {
- djstest.assertAreEqualDeep(keys, ["key", "key2", "key3"]);
- djstest.done();
- }, unexpectedError);
- }, unexpectedError);
- }, unexpectedError);
- }, unexpectedError);
- });
-
- djstest.addTest(function testIndexedDBStoreAddArrayClear() {
- var addedKeys = ["key", "key2", "key3"];
- var addedValues = ["value", "value2", "value3"];
- var store = this.store = window.odatajs.store.IndexedDBStore.create(getCurrentStoreName());
- store.add(addedKeys, addedValues, function (keys, values) {
- djstest.assertAreEqualDeep(keys, addedKeys);
- djstest.assertAreEqualDeep(values, addedValues);
- store.clear(function () {
- store.getAllKeys(function (keys) {
- djstest.assertAreEqualDeep(keys, []);
- djstest.done();
- }, unexpectedError);
- }, unexpectedError);
- }, unexpectedError);
- });
-
- djstest.addTest(function testIndexedDBStoreAddArrayUpdateArrayGetArray() {
- var addedKeys = ["key", "key2", "key3"];
- var addedValues = ["value", "value2", "value3"];
- var store = this.store = window.odatajs.store.IndexedDBStore.create(getCurrentStoreName());
- store.add(addedKeys, addedValues, function (keys, values) {
- djstest.assertAreEqualDeep(keys, addedKeys);
- djstest.assertAreEqualDeep(values, addedValues);
- var updatedKeys = ["key", "key3"];
- var updatedValues = ["newValue", "newValue3"];
- store.update(updatedKeys, updatedValues, function (keys, values) {
- djstest.assertAreEqualDeep(keys, updatedKeys);
- djstest.assertAreEqualDeep(values, updatedValues);
- store.read(addedKeys, function (keys, values) {
- djstest.assertAreEqualDeep(keys, ["key", "key2", "key3"]);
- djstest.assertAreEqualDeep(values, ["newValue", "value2", "newValue3"]);
- djstest.done();
- }, unexpectedError);
- }, unexpectedError);
- }, unexpectedError);
- });
-
- djstest.addTest(function testIndexedDBStoreAddOrUpdateArrayGetArray() {
- var expectedKeys = ["key", "key2", "key3"];
- var expectedValues = ["value", "value2", "value3"];
- var store = this.store = window.odatajs.store.IndexedDBStore.create(getCurrentStoreName());
- store.add("key2", "value", function (key, value) {
- store.addOrUpdate(expectedKeys, expectedValues, function (keys, values) {
- djstest.assertAreEqualDeep(keys, expectedKeys);
- djstest.assertAreEqualDeep(values, expectedValues);
- store.read(keys, function (keys, values) {
- djstest.assertAreEqualDeep(values, expectedValues);
- djstest.done();
- }, unexpectedError);
- }, unexpectedError);
- }, unexpectedError);
- });
-
- djstest.addTest(function testIndexedDBStoreAddDuplicate() {
- var store = this.store = window.odatajs.store.IndexedDBStore.create(getCurrentStoreName());
- store.add("key", "value", function (key, value) {
- store.add("key", "value2", unexpectedSuccess, function (err) {
- djstest.pass("Error callback called as expected");
- djstest.done();
- });
- }, unexpectedError);
- });
-
- djstest.addTest(function testIndexedDBStoreAddArrayDuplicate() {
- var store = this.store = window.odatajs.store.IndexedDBStore.create(getCurrentStoreName());
- store.add(["key", "key2", "key"], ["value", "value2", "value3"], unexpectedSuccess, function (err) {
- djstest.pass("Error callback called as expected");
- djstest.done();
- });
- });
-
- djstest.addTest(function testIndexedDBStoreGetArrayNonExistent() {
- var store = this.store = window.odatajs.store.IndexedDBStore.create(getCurrentStoreName());
- store.add("key", "value", function (key, value) {
- store.read(["key", "badkey"], function (keys, values) {
- djstest.assertAreEqualDeep(keys, ["key", "badkey"]);
- djstest.assertAreEqualDeep(values, ["value", undefined]);
- djstest.done();
- }, unexpectedError);
- });
- });
-
- djstest.addTest(function testIndexedDBStoreUpdateNonExistent() {
- var store = this.store = window.odatajs.store.IndexedDBStore.create(getCurrentStoreName());
- store.update("badkey", "badvalue", unexpectedSuccess, function (err) {
- djstest.pass("Error callback called as expected");
- djstest.done();
- });
- });
-
- djstest.addTest(function testIndexedDBStoreUpdateArrayNonExistent() {
- var store = this.store = window.odatajs.store.IndexedDBStore.create(getCurrentStoreName());
- store.add("key", "value", function (key, value) {
- store.update(["key", "badkey"], ["value", "badvalue"], unexpectedSuccess, function (err) {
- djstest.pass("Error callback called as expected");
- store.read("key", function (key, value) {
- djstest.assertAreEqual(value, "value", "value was not changed");
- djstest.done();
- }), unexpectedError;
- });
- }, unexpectedError);
- });
- }
- // DATAJS INTERNAL END
-})(this);
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/503b4417/odatajs/tests/store-tests.js
----------------------------------------------------------------------
diff --git a/odatajs/tests/store-tests.js b/odatajs/tests/store-tests.js
deleted file mode 100644
index 48169c3..0000000
--- a/odatajs/tests/store-tests.js
+++ /dev/null
@@ -1,705 +0,0 @@
-/*
- * 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) {
-
- var cleanDomStorage = function () {
- /** Cleans all the data saved in the browser's DOM Storage.
- */
- if (window.localStorage) {
- window.localStorage.clear();
- }
- };
-
- var cleanMemoryStorage = function () {
- /** Clean memory storage is a no op.
- */
- };
-
- var cleanIndexedDbStorage = function () {
- var stores = this.stores;
- $.each(stores, function (_, store) {
- store.close();
- });
-
- djstest.wait(function (done) {
- djstest.cleanStoreOnIndexedDb(stores, done);
- });
- };
-
- var canCreateMemoryStore = function () {
- /** Checks whether memory storage is supported by the browser.
- * @returns {boolean} True
- */
- return true;
- };
-
- var canCreateDomStore = function () {
- /** Checks whether Web Storage (DOM Storage) is supported by the browser.
- * @returns {boolean} True if DOM Storage is supported by the browser; false otherwise.
- */
- return !!window.localStorage;
- };
-
- var canCreateIndexedDb = function () {
- /** Checks whether Web Storage (DOM Storage) is supported by the browser.
- * @returns {Boolean} True if IndexedDB is supported by the browser, false otherwise.
- */
- return !!djstest.indexedDB;
- };
-
- var canCreateStore = function (mechanism) {
- /** Determines whether a particular mechanism is supported by the browser.
- * @param {String} mechanism - Mechanism name.
- * @returns {Boolean} True if the mechanism is supported by the browser; otherwise false.
- */
- var implementation = mechanismImplementations[mechanism];
- return implementation && implementation.canCreate();
- }
- var makeUnexpectedErrorHandler = function (fail) {
- return function (err) {
- djstest.fail("error: " + err.name + " -- message: " + err.message);
- fail();
- };
- };
-
- var testJobDone = function (succeeded) {
- if (!succeeded) {
- djstest.fail("Job completed but some of the functions it called failed");
- }
- djstest.done();
- };
-
- var mechanismImplementations = {
- indexeddb: { factory: odatajs.IndexedDBStore, canCreate: canCreateIndexedDb, cleanup: cleanIndexedDbStorage },
- dom: { factory: odatajs.DomStore, canCreate: canCreateDomStore, cleanup: cleanDomStorage },
- memory: { factory: odatajs.MemoryStore, canCreate: canCreateMemoryStore, cleanup: cleanMemoryStorage }
- };
-
- var oldWindowOnError;
-
- for (var mechanism in mechanismImplementations) {
- module("Unit", {
- mechanism: mechanism,
- createStore: function (name) {
- var store = odatajs.store.createStore(name + "_" + this.mechanism, this.mechanism);
- this.stores.push(store);
- return store;
- },
- setup: function () {
- this.stores = [];
- mechanismImplementations[this.mechanism].cleanup.call(this);
-
- // FireFox 7.0.1 bubbles an error event when there is an IndexedDB error, even when the error has been handled graciously.
- // This is a work around to keep QUnit from reporting false failures in IndexedDB negative tests.
- if (this.mechanism === "indexeddb") {
- oldWindowOnError = window.onerror;
- window.onerror = null;
- }
- },
- teardown: function () {
- mechanismImplementations[this.mechanism].cleanup.call(this);
- this.stores = [];
-
- // Restore QUnit's onerror handler.
- if (this.mechanism === "indexeddb") {
- window.onerror = oldWindowOnError;
- }
- }
- });
-
- if (!canCreateStore(mechanism)) {
- djstest.addTest(function (mechanism) {
- djstest.expectException(function () {
- mechanismImplemenatations[mechanism].factory.create("my horrible not working store");
- });
- djstest.done();
- }, "Local storage mechanism " + mechanism + " not supported by this browser", mechanism);
- } else {
-
- djstest.addTest(function storeAddTest(mechanism) {
- var tuples = [
- { key: "null", value: null },
- { key: "undefined", value: undefined },
- { key: "number", value: 12345.678 },
- { key: "string", value: "String value" },
- { key: "date", value: new Date() },
- { key: "object", value: { p1: 1234, nested: { p1: "a", p2: "b"}} },
- { key: "array", value: [1, 2, 3, 4, 5] },
- { key: "key1", value: "some value" },
- { key: "key1", value: "this should fail", error: true },
- { key: ["key", "key2"], value: ["value", "value2"], error: mechanism !== "indexeddb" },
- { key: ["key6", "key7", "key6"], value: ["value", "value2", "value3"], error: true }
- ];
-
- var store = this.createStore("store1");
- var job = new djstest.Job();
-
- $.each(tuples, function (_, tuple) {
- job.queue(function task(success, fail) {
-
- var unexpectedError = makeUnexpectedErrorHandler(fail);
- djstest.log("running task");
-
- store.add(tuple.key, tuple.value,
- function (key, value) {
- djstest.assertAreEqual(key, tuple.key, "Keys match for " + mechanism + " - key = " + key.toString());
- djstest.assertAreEqualDeep(value, tuple.value, "Values match for " + mechanism + " - key = " + key.toString());
-
- job.queueNext(function (success, fail) {
- store.read(tuple.key, function (key, value) {
- djstest.assertAreEqualDeep(value, tuple.value, "Key: " + key + " is present in the store");
- success();
- }, makeUnexpectedErrorHandler(fail));
- });
- success();
- },
- function (err) {
- if (!tuple.error) {
- unexpectedError(err);
- } else {
- djstest.pass("error handler was called as expected");
- success();
- }
- });
- });
- });
-
- job.run(function (succeeded) {
- store.close();
- testJobDone(succeeded);
- });
-
- }, "Store Add Test with mechanism " + mechanism, mechanism);
-
- djstest.addTest(function storeAddOrUpdateTest(mechanism) {
- var tuples = [
- { key: "null", value: null },
- { key: "undefined", value: undefined },
- { key: "number", value: 12345.678 },
- { key: "string", value: "String value" },
- { key: "date", value: new Date() },
- { key: "object", value: { p1: 1234, nested: { p1: "a", p2: "b"}} },
- { key: "array", value: [1, 2, 3, 4, 5] },
- { key: "key1", value: "some value" },
- { key: "key1", value: "this should not fail" },
- { key: ["key", "key2", "key3"], value: ["value", "value2", "value3"], error: mechanism !== "indexeddb" },
- { key: ["key", "key2", "key3"], value: ["value4", "value5", "value6"], error: mechanism !== "indexeddb" },
- { key: "key1", value: 456 }
- ];
-
- var store = this.createStore("store2");
- var job = new djstest.Job();
-
- $.each(tuples, function (_, tuple) {
- job.queue(function (success, fail) {
-
- var unexpectedError = makeUnexpectedErrorHandler(fail);
-
- store.addOrUpdate(tuple.key, tuple.value,
- function (key, value) {
- djstest.assert(!tuple.error, "success should be called");
- djstest.assertAreEqual(key, tuple.key, "Keys match");
- djstest.assertAreEqualDeep(value, tuple.value, "Values match");
-
- store.read(tuple.key, function (key, value) {
- djstest.assertAreEqual(key, tuple.key, "Keys match");
- djstest.assertAreEqualDeep(value, tuple.value, "Values match");
- success();
- }, unexpectedError);
- },
- function (err) {
- if (!tuple.error) {
- unexpectedError(err);
- } else {
- djstest.pass("error handler was called as expected");
- success();
- }
- });
- });
- });
-
- job.run(function (succeeded) {
- store.close();
- testJobDone(succeeded);
- });
- }, "Store Add or Update Test with mechanism " + mechanism, mechanism);
-
- djstest.addTest(function storeContainsTest(mechanism) {
- var store = this.createStore("store3");
- var job = new djstest.Job();
-
- job.queue(function (success, fail) {
- store.add("Key1", "Some value", success, makeUnexpectedErrorHandler(fail));
- });
-
- job.queue(function (success, fail) {
- store.contains("Key1", function (contained) {
- djstest.assert(contained, "Key is present in the store");
- success();
- }, makeUnexpectedErrorHandler(fail));
- });
-
- job.queue(function (success, fail) {
- store.contains("Key2", function (contained) {
- djstest.assert(!contained, "Key is not present in the store");
- success();
- }, makeUnexpectedErrorHandler(fail));
- });
-
- job.run(function (succeeded) {
- store.close();
- testJobDone(succeeded);
- });
-
- }, "Store Contains Test with mechanism " + mechanism, mechanism);
-
- djstest.addTest(function storeGetAllKeysTest(mechanism) {
- var store = this.createStore("store4");
- var store2 = this.createStore("store4_1");
-
- var expectedKeys = [];
- var job = new djstest.Job();
-
- var i;
- for (i = 1; i <= 20; i++) {
- (function (i) {
- job.queue(function (success, fail) {
- store.add(i.toString(), "value" + i, success, makeUnexpectedErrorHandler(fail));
- });
-
- job.queue(function (success, fail) {
- store2.add((i + 20).toString(), "value" + (i + 20), success, makeUnexpectedErrorHandler(fail));
- });
- })(i);
-
- expectedKeys.push(i.toString());
- }
-
- job.queue(function (success, fail) {
- store.getAllKeys(function (keys) {
- expectedKeys.sort();
- keys.sort();
- djstest.assertAreEqualDeep(keys, expectedKeys, "All expected keys where returned");
- success();
- }, makeUnexpectedErrorHandler(fail));
- });
-
- job.run(function (succeeded) {
- store.close();
- store2.close();
- testJobDone(succeeded);
- });
- }, "Store Get All Keys Test with mechanism " + mechanism, mechanism);
-
- djstest.addTest(function storeReadTest(mechanism) {
- var tuples = [
- { key: "null", value: null },
- { key: "undefined", value: undefined },
- { key: "number", value: 12345.678 },
- { key: "string", value: "String value" },
- { key: "date", value: new Date() },
- { key: "dateOffset", value: (function () {
- var d = new Date();
- d.__type = "Edm.DateTimeOffset";
- d.__offset = "+03:30";
- return d;
- })()
- },
- { key: "complexDate", value: (function () {
- var d = new Date();
- d.nestedDate = new Date();
- d.nestedDate.__type = "Edm.DateTimeOffset";
- d.nestedDate.__offset = "+03:30";
- return d;
- })()
- },
- { key: "object", value: { p1: 1234, nested: { p1: "a", p2: "b", p3: new Date()}} },
- { key: "array", value: [1, 2, 3, 4, 5] }
- ];
-
- var store = this.createStore("store5");
- var job = new djstest.Job();
-
- $.each(tuples, function (_, tuple) {
- job.queue(function (success, fail) {
- store.add(tuple.key, tuple.value,
- function () {
- job.queue(function (success, fail) {
- store.read(tuple.key, function (key, value) {
- djstest.assertAreEqual(key, tuple.key, "Keys match");
- djstest.assertAreEqualDeep(value, tuple.value, "Values match");
- success();
- }, makeUnexpectedErrorHandler(fail));
- });
- success();
- },
- function (err) {
- if (!tuple.error) {
- djstest.fail(err.message);
- fail();
- } else {
- djstest.pass("error handler was called as expected");
- success();
- }
- });
- });
- });
-
- job.queue(function (success, fail) {
- store.read("Unknown key", function (key, value) {
- djstest.assertAreEqual(value, undefined, "Store get returns undefined for keys that do not exist in the store");
- success();
- }, makeUnexpectedErrorHandler(fail));
- });
-
- job.run(function (succeeded) {
- store.close();
- testJobDone(succeeded);
- });
-
- }, "Store Read Test with mechanism " + mechanism, mechanism);
-
- djstest.addTest(function storeReadArrayTest(mechanism) {
- var makeError = function (success, fail) {
- return function (err) {
- if (mechanism !== "indexeddb") {
- djstest.pass("Error callback called as expected");
- success();
- } else {
- djstest.fail(err.message);
- fail();
- }
- };
- };
-
- var store = this.createStore("store6");
- var job = new djstest.Job();
-
- job.queue(function (success, fail) {
- store.add(["key", "key2", "key3"], ["value", "value2", "value3"], success, makeError(success, fail));
- });
-
- job.queue(function (success, fail) {
- store.read(["key", "key2", "key3"], function (keys, values) {
- djstest.assertAreEqualDeep(keys, ["key", "key2", "key3"]);
- djstest.assertAreEqualDeep(values, ["value", "value2", "value3"]);
- success();
- }, makeError(success, fail));
- });
-
- job.queue(function (success, fail) {
- store.read(["key", "badkey"], function (keys, values) {
- djstest.assertAreEqualDeep(keys, ["key", "badkey"]);
- djstest.assertAreEqualDeep(values, ["value", undefined]);
- success();
- }, makeError(success, fail));
- });
-
- job.run(function (succeeded) {
- store.close();
- testJobDone(succeeded);
- });
- }, "Store Read Array Test with mechanism " + mechanism, mechanism);
-
- djstest.addTest(function storeRemoveTest(mechanism) {
- var store = this.createStore("store7");
- var job = new djstest.Job();
-
- job.queue(function (success, fail) {
- store.add("Key1", "Some value", success, makeUnexpectedErrorHandler(fail));
- });
-
- job.queue(function (success, fail) {
- store.add("Key2", "Some value", success, makeUnexpectedErrorHandler(fail));
- });
-
- job.queue(function (success, fail) {
- store.remove("Key1", function () {
- djstest.pass("Key1 was removed from the store")
- success();
- }, makeUnexpectedErrorHandler(fail));
- });
-
- job.queue(function (success, fail) {
- store.contains("Key1", function (contained) {
- djstest.assert(!contained, "Key1 is not present in the store");
- success();
- }, makeUnexpectedErrorHandler(fail));
- });
-
- job.queue(function (success, fail) {
- store.remove("Key that has never been added", function () {
- djstest.pass('"Key that has never been added" was removed from the store');
- success();
- }, makeUnexpectedErrorHandler(fail));
- });
-
- job.queue(function (success, fail) {
- store.contains("Key2", function (contained) {
- djstest.assert(contained, "Key2 is present in the store");
- success();
- }, makeUnexpectedErrorHandler(fail));
- });
-
- job.run(function (succeeded) {
- store.close();
- testJobDone(succeeded);
- });
- }, "Store Remove Test with mechanism " + mechanism, mechanism);
-
- djstest.addTest(function storeUpdateTest(mechanism) {
- var store = this.createStore("store8");
-
- var startKey = "Key1";
- var startValue = "start value";
- var updateKey = "Key2";
- var updatedValue = "updated value";
-
- var job = new djstest.Job();
-
- job.queue(function (success, fail) {
- store.add(startKey, startValue, success, makeUnexpectedErrorHandler(fail));
- });
-
- job.queue(function (success, fail) {
- store.add(updateKey, startValue, success, makeUnexpectedErrorHandler(fail));
- });
-
- job.queue(function (success, fail) {
- store.update(updateKey, updatedValue, function (key, value) {
- djstest.assertAreEqual(key, updateKey, "Updated keys match");
- djstest.assertAreEqualDeep(value, updatedValue, "Updated values match");
- success();
- }, makeUnexpectedErrorHandler(fail));
- });
-
- job.queue(function (success, fail) {
- store.read(updateKey, function (key, value) {
- djstest.assertAreEqual(key, updateKey, "Updated keys match after get");
- djstest.assertAreEqualDeep(value, updatedValue, "Updated values match after get");
- success();
- }, makeUnexpectedErrorHandler(fail));
- });
-
- job.queue(function (success, fail) {
- store.read(startKey, function (key, value) {
- djstest.assertAreEqual(key, startKey, "Non updated keys match after get");
- djstest.assertAreEqualDeep(value, startValue, "Non updated values match after get");
- success();
- }, makeUnexpectedErrorHandler(fail));
- });
-
- job.run(function (succeeded) {
- store.close();
- testJobDone(succeeded);
- });
- }, "Store Update Test with mechanism " + mechanism, mechanism);
-
- djstest.addTest(function storeClearTest(mechanism) {
- var store = this.createStore("store9");
- var store2 = this.createStore("store9_1");
-
- var job = new djstest.Job();
- job.queue(function (success, fail) {
- store.add("Key1", "value in store", success, makeUnexpectedErrorHandler(fail));
- });
-
- job.queue(function (success, fail) {
- store.add("Key2", "value in store", success, makeUnexpectedErrorHandler(fail));
- });
-
- job.queue(function (success, fail) {
- store.add("Key3", "value in store", success, makeUnexpectedErrorHandler(fail));
- });
-
- job.queue(function (success, fail) {
- store2.add("Key1", "value in store2", success, makeUnexpectedErrorHandler(fail));
- });
-
- job.queue(function (success, fail) {
- store.clear(function () {
- djstest.pass("Store was cleared");
- success();
- }, makeUnexpectedErrorHandler(fail));
- });
-
- job.queue(function (success, fail) {
- store.contains("Key1", function (contained) {
- djstest.assert(!contained, "Key1 was removed from store");
- success();
- }, makeUnexpectedErrorHandler(fail));
- });
-
- job.queue(function (success, fail) {
- store2.contains("Key1", function (contained) {
- djstest.assert(contained, "Key1 still exists in store 2");
- success();
- }, makeUnexpectedErrorHandler(fail));
- });
-
- job.run(function (succeeded) {
- store.close();
- store2.close();
- testJobDone(succeeded);
- });
- }, "Store Clear Test with mechanism " + mechanism, mechanism);
-
- djstest.addTest(function storeUpdateNonExistentTest(mechanism) {
- var store = this.createStore("store10");
- var job = new djstest.Job();
-
- job.queue(function (success, fail) {
- store.add("key", "value", success, makeUnexpectedErrorHandler(fail));
- });
-
- job.queue(function (success, fail) {
- store.update("badKey", "new value",
- function () {
- djstest.fail("Sucess handler called when not expected");
- fail();
- },
- function (err) {
- djstest.pass("Error callback called as expexted");
- success();
- });
- });
-
- job.queue(function (success, fail) {
- store.update(["key", "badkey"], ["value", "badvalue"],
- function () {
- djstest.fail("Sucess handler called when not expected");
- fail();
- },
- function (err) {
- djstest.pass("Error callback called as expected");
- success();
- });
- });
-
- job.queue(function (success, fail) {
- store.read("key", function (key, value) {
- djstest.assertAreEqual(value, "value", "value was not changed");
- success();
- }, makeUnexpectedErrorHandler(fail));
- });
-
- job.run(function (succeeded) {
- store.close();
- testJobDone(succeeded);
- });
- }, "Store Update Non-Existent Test with mechanism " + mechanism, mechanism);
-
- djstest.addTest(function storeUpdateArrayTest(mechanism) {
- var makeError = function (success, fail) {
- return function (err) {
- if (mechanism !== "indexeddb") {
- djstest.pass("Error callback called as expected");
- success();
- } else {
- djstest.fail(err.message);
- fail();
- }
- };
- };
-
- var store = this.createStore("store11");
- var job = new djstest.Job();
-
- job.queue(function (success, fail) {
- store.add(["key", "key2"], ["value1", "value2"], success, makeError(success, fail));
- });
-
- job.queue(function (success, fail) {
- store.update(["key", "key2"], ["value1", "value4"], success, makeError(success, fail));
- });
-
- job.queue(function (success, fail) {
- store.read(["key", "key2"], function (key, value) {
- djstest.assertAreEqualDeep(value, ["value1", "value4"], "value was not changed");
- success();
- }, makeError(success, fail));
- });
-
- job.run(function (succeeded) {
- store.close();
- testJobDone(succeeded);
- });
- }, "Store Update Array Test with mechanism " + mechanism, mechanism);
- }
- }
-
- module("Unit");
-
- djstest.addTest(function CreateStoreTest() {
- var defaultExpected = canCreateDomStore() ? "dom" : "memory";
- var tests = [
- { mechanism: "dom", exception: !canCreateDomStore(), expected: "dom" },
- { mechanism: "memory", exception: false, expected: "memory" },
- { mechanism: "", exception: false, expected: defaultExpected },
- { mechanism: null, exception: false, expected: defaultExpected },
- { mechanism: "unknown", exception: true }
- ];
-
- var i, len;
- for (i = 0, len = tests.length; i < len; i++) {
- try {
- var test = tests[i];
- var store = odatajs.store.createStore("testStore" + i, tests[i].mechanism);
-
- if (!test.exception) {
- djstest.assertAreEqual(store.mechanism, test.expected, "Created store of the expected mechanism");
- } else {
- djstest.fail("Didn't get the expected exception");
- }
- }
- catch (e) {
- djstest.assert(test.exception, "Expected exception");
- }
- }
- djstest.done();
- });
-
- djstest.addTest(function CreateBestStoreTest() {
- var bestMechanism;
-
- for (var name in mechanismImplementations) {
- if (!bestMechanism && canCreateStore(name) && name !== "indexeddb") {
- bestMechanism = name;
- }
- }
-
- if (bestMechanism) {
- var tests = [
- "best",
- undefined
- ];
-
- for (var i in tests) {
- var store = odatajs.store.createStore("best store ever " + i, tests[i]);
- djstest.assertAreEqual(store.mechanism, bestMechanism, "Mechanisms match");
- }
- } else {
- djstest.pass("This browser doesn't support any of the implemented local storage mechanisms");
- }
- djstest.done();
- });
-
-})(this);
http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/503b4417/odatajs/tests/test-list.js
----------------------------------------------------------------------
diff --git a/odatajs/tests/test-list.js b/odatajs/tests/test-list.js
deleted file mode 100644
index 3a69064..0000000
--- a/odatajs/tests/test-list.js
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * 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.
- */
-
-// Test list for datajs tests
-
-function getAllTestFiles() {
- return [
- "odata-qunit-tests.htm"
- ];
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/503b4417/odatajs/tests/test-manager.html
----------------------------------------------------------------------
diff --git a/odatajs/tests/test-manager.html b/odatajs/tests/test-manager.html
deleted file mode 100644
index 290f161..0000000
--- a/odatajs/tests/test-manager.html
+++ /dev/null
@@ -1,108 +0,0 @@
-<!--
-/*
- * 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 XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml">
-<head>
- <title>datajs test manager</title>
- <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.5.1.js"></script>
- <script type="text/javascript" src="test-list.js"></script>
- <script type="text/javascript">
- var serviceRoot = "./common/TestLogger.svc/";
- $(function () {
- $(getAllTestFiles()).each(function () {
- $("#pages").append("<input type='checkbox' name='page' value='" + this + "' checked />" + this + "<br />");
- });
- refreshActiveRuns();
- });
-
- var createTestRun = function (form) {
- $.getJSON(serviceRoot + "CreateTestRun", function (data) {
- var testRunId = data.d;
-
- // Build pages list
- var pages = [];
- $(form).find("input[name='page']:checked").each(function () {
- pages.push(this.value);
- });
-
- var firstPage = pages[0];
- pages.shift();
-
- $.get(serviceRoot + "MarkInProgress?testRunId=" + testRunId, function () {
- $.get(serviceRoot + "SetTestNamePrefix?testRunId=" + testRunId + "&prefix=" + $("#browser").val() + "-", function () {
- var renderLinks = function () {
- $("#runLink").attr("href", firstPage + "?testRunId=" + testRunId);
- $("#runLink").text(testRunId);
- $("#resultsLink").attr("href", serviceRoot + "GetTestRunResults?testRunId=" + testRunId);
- $("#resultsLink").text(testRunId);
- refreshActiveRuns();
- };
-
- if (pages.length > 0) {
- $.get(serviceRoot + "AddTestPages?testRunId=" + testRunId + "&pages=" + pages.join(","), renderLinks);
- }
- else {
- renderLinks();
- }
- });
- });
- });
- };
-
- var refreshActiveRuns = function () {
- $("#activeRuns").empty();
- $.getJSON(serviceRoot + "GetActiveTestRuns", function (data) {
- if (data.d.length === 0) {
- $("#activeRuns").text("There are no active runs");
- } else {
- $.each(data.d, function (_, id) {
- $("#activeRuns").append("<a href='" + serviceRoot + "GetTestRunResults?testRunId=" + id + "'>" + id + "</a><br />");
- })
- };
- });
- };
- </script>
-</head>
-<body>
- <h1>datajs test manager</h1>
- <table style="width:100%"><tr><td style="vertical-align:top">
- <h4>1. Create Test Run</h4>
- <form onsubmit="createTestRun(this); return false;">
- <div>Pages</div>
- <div id="pages"></div>
- <br />
- <div>Browser: <input type="text" id="browser" /></div>
- <br />
- <input type="submit" value="Create Test Run" />
- </form>
-
- <h4>2. Run Tests</h4>
- Test Run ID: <a id="runLink"></a>
-
- <h4>3. View Results</h4>
- Test Run ID: <a id="resultsLink"></a>
-
- </td><td style="vertical-align:top">
- <h4>Active Runs <input type="button" value="Refresh" onclick="refreshActiveRuns()" /></h4>
- <div id="activeRuns"></div>
- </td></tr></table>
-</body>
-</html>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/503b4417/package.json
----------------------------------------------------------------------
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..6c782bf
--- /dev/null
+++ b/package.json
@@ -0,0 +1,47 @@
+{
+ "name": "odatajs",
+ "version": "4.0.0",
+ "postfix": "beta-01",
+ "releaseCandidate": "",
+ "title": "Olingo OData Client for JavaScript",
+ "description": "the Olingo OData Client for JavaScript library is a new cross-browser JavaScript library that enables data-centric web applications by leveraging modern protocols such as JSON and OData and HTML5-enabled browser features. It's designed to be small, fast and easy to use.",
+ "homepage": "http://olingo.apache.org",
+ "main": "index-node.js",
+ "main-browser": "index.js",
+ "repository": {
+ "type": "git",
+ "url": "http://git-wip-us.apache.org/repos/asf/olingo-odata4-js.git"
+ },
+ "engines": {
+ "node": ">= 0.10.0"
+ },
+ "contributors": [
+ {
+ "name": "Bing Li",
+ "email": "bingl@apache.org"
+ },
+ {
+ "name": "Sven Kobler-Morris",
+ "email": "koblers@apache.org"
+ },
+ {
+ "name": "Challen He",
+ "email": "challenh@apache.org"
+ }
+ ],
+ "scripts": {
+ "preinstall": "npm --prefix ./grunt-config/custom-tasks/rat install"
+ },
+ "devDependencies": {
+ "grunt": "^0.4.5",
+ "grunt-connect-proxy": "^0.1.10",
+ "grunt-contrib-clean": "^0.6.0",
+ "grunt-contrib-compress": "^0.10.0",
+ "grunt-contrib-copy": "^0.5.0",
+ "grunt-contrib-uglify": "^0.4.0",
+ "grunt-curl": "^2.0.2",
+ "grunt-jsdoc": "^0.5.6",
+ "grunt-nuget": "^0.1.3",
+ "xmldom": "^0.1.19"
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/503b4417/packages.config
----------------------------------------------------------------------
diff --git a/packages.config b/packages.config
new file mode 100644
index 0000000..9e7480b
--- /dev/null
+++ b/packages.config
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8"?>
+<packages>
+ <package id="Microsoft.OData.Client" version="6.5.0" targetFramework="net40" />
+ <package id="Microsoft.OData.Core" version="6.5.0" targetFramework="net40" />
+ <package id="Microsoft.OData.Edm" version="6.5.0" targetFramework="net40" />
+ <package id="Microsoft.Spatial" version="6.5.0" targetFramework="net40" />
+</packages>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/503b4417/src/index-browser.js
----------------------------------------------------------------------
diff --git a/src/index-browser.js b/src/index-browser.js
new file mode 100644
index 0000000..6301acf
--- /dev/null
+++ b/src/index-browser.js
@@ -0,0 +1,36 @@
+/*1
+ * 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.
+ */
+
+// version information
+exports.version = { major: 4, minor: 0, build: 0 };
+
+// core stuff, always needed
+exports.deferred = require('./lib/deferred.js');
+exports.utils = require('./lib/utils.js');
+
+// only needed for xml metadata
+exports.xml = require('./lib/xml.js');
+
+// only need in browser case
+exports.oData = require('./lib/odata.js');
+exports.store = require('./lib/store.js');
+exports.cache = require('./lib/cache.js');
+
+
+
http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/503b4417/src/index-node.js
----------------------------------------------------------------------
diff --git a/src/index-node.js b/src/index-node.js
new file mode 100644
index 0000000..85aea5b
--- /dev/null
+++ b/src/index-node.js
@@ -0,0 +1,47 @@
+/*
+ * 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.
+ */
+
+var odatajs = {};
+
+odatajs.version = {
+ major: 4,
+ minor: 0,
+ build: 0
+};
+
+// core stuff, alway needed
+odatajs.deferred = require('./lib/deferred.js');
+odatajs.utils = require('./lib/utils.js');
+
+// only neede for xml metadata
+odatajs.xml = require('./lib/xml.js');
+
+// only need in browser case
+odatajs.oData = require('./lib/odata.js');
+odatajs.store = require('./lib/store.js');
+odatajs.cache = require('./lib/cache.js');
+
+if (typeof window !== 'undefined') {
+ //expose to browsers window object
+ window.odatajs = odatajs;
+} else {
+ //expose in commonjs style
+ odatajs.node = "node";
+ module.exports = odatajs;
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/503b4417/src/index.js
----------------------------------------------------------------------
diff --git a/src/index.js b/src/index.js
new file mode 100644
index 0000000..d939da2
--- /dev/null
+++ b/src/index.js
@@ -0,0 +1,52 @@
+/*
+ * 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.
+ */
+
+//console.log('main starting');
+//var a = require('./a.js');
+//var b = require('./b.js');
+//console.log('in main, a.done=%j, b.done=%j', a.done, b.done);
+
+var odatajs = {};
+
+odatajs.version = {
+ major: 4,
+ minor: 0,
+ build: 0
+};
+
+// core stuff, alway needed
+odatajs.deferred = require('./lib/deferred.js');
+odatajs.utils = require('./lib/utils.js');
+
+// only neede for xml metadata
+odatajs.xml = require('./lib/ext/xml.js');
+
+// only need in browser case
+odatajs.oData = require('./lib/odata.js');
+odatajs.store = require('./lib/store.js');
+odatajs.cache = require('./lib/cache.js');
+
+if (typeof window !== 'undefined') {
+ //expose to browsers window object
+ window.odatajs = odatajs;
+} else {
+ //expose in commonjs style
+ odatajs.node = "node";
+ module.exports = odatajs;
+}