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:48 UTC
[41/51] [partial] rename folder /datajs into /odatajs. no file
modification.
http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/d5ec5557/datajs/tests-tmp/b-cache-tests.js
----------------------------------------------------------------------
diff --git a/datajs/tests-tmp/b-cache-tests.js b/datajs/tests-tmp/b-cache-tests.js
deleted file mode 100644
index 5b41123..0000000
--- a/datajs/tests-tmp/b-cache-tests.js
+++ /dev/null
@@ -1,1191 +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.
-*/
-
-(function (window, undefined) {
-
- module("cache-tests.js");
- var foodsFeed = "./endpoints/FoodStoreDataServiceV4.svc/Foods";
- var collectionSize = 16;
-
- var thenFailTest = function (err) {
- if (err && err.message) {
- djstest.fail(err.message);
- } else {
- djstest.fail("unexepected promise failure");
- }
-
- djstest.done();
- };
-
- djstest.addTest(function dataCacheCountTest() {
- var cache = odatajs.cache.createDataCache({ name: "cache", source: foodsFeed });
- cache.count().then(function (count) {
- djstest.assertAreEqual(count, collectionSize, "expected count for Foods");
- djstest.destroyCacheAndDone(cache);
- }, thenFailTest);
- });
-
- djstest.addTest(function dataCacheCountOnLocalTest() {
- var cache = odatajs.cache.createDataCache({ name: "cache", source: foodsFeed, pageSize: collectionSize + 10, mechanism: "memory" });
- cache.readRange(0, collectionSize + 10).then(function (data) {
- var expectedCount = data.value ? data.value.length : 0;
- cache.count().then(function (count) {
- djstest.assertAreEqual(count, expectedCount, "expected count for expectedCount");
- djstest.destroyCacheAndDone(cache);
- }, thenFailTest);
- }, thenFailTest);
- });
-
- djstest.addTest(function dataCacheCountAbortTest() {
- // Abort before completion.
- var cache = odatajs.cache.createDataCache({ name: "cache", source: foodsFeed });
- var item = cache.count().then(thenFailTest, function (err) {
- djstest.assertAreEqual(true, err.canceled, "err.aborted is true");
- djstest.destroyCacheAndDone(cache);
- }).cancel();
- });
-
- var createNewCache = function (options) {
-
- var thenSuccess = null;
-
- var resolved = false;
- var rejected = false;
-
- var args = null;
-
- this.then = function (success) {
- if (resolved) {
- success.apply(null, args);
- } else if (!rejected) {
- thenSuccess = success;
- }
- };
-
- var resolve = function (/*args*/) {
- resolved = true;
- args = arguments;
- if (thenSuccess) {
- thenSuccess.apply(null, arguments);
- }
- };
-
- var cache = odatajs.cache.createDataCache(options);
- cache.clear().then(function () {
- var newCache = odatajs.cache.createDataCache(options);
- resolve(newCache);
- }, function (err) {
- rejected = true;
- thenFailTest(err);
- });
-
- return this;
- };
-
- djstest.addTest(function dataCacheReadRangeSingleTest() {
- // Read a new range.
- var options = { name: "cache", source: foodsFeed, pageSize: 2 };
- createNewCache(options).
- then(function (cache) {
- cache.readRange(0, 1).
- then(function (data) {
- djstest.assertAreEqual(data.value.length, 1, "single item was read.");
- djstest.assertAreEqual(data.value[0].FoodID, 0, "food id is 0.");
- djstest.done();
- }, thenFailTest);
- }, thenFailTest);
- });
-
- djstest.addTest(function dataCacheReadRangeExactPageTest() {
- // Read exactly one page.
- var options = { name: "cache", source: foodsFeed, pageSize: 2 };
- createNewCache(options).
- then(function (cache) {
- cache.readRange(0, 2).
- then(function (data) {
- djstest.assertAreEqual(data.value.length, 2, "single item was read.");
- djstest.assertAreEqual(data.value[0].FoodID, 0, "first food id is 0.");
- djstest.assertAreEqual(data.value[1].FoodID, 1, "second food id is 1.");
- djstest.done();
- }, thenFailTest);
- }, thenFailTest);
- });
-
- djstest.addTest(function dataCacheReadRangeMultiplePageTest() {
- // Read multiple pages.
- var options = { name: "cache", source: foodsFeed, pageSize: 2 };
- createNewCache(options).
- then(function (cache) {
- cache.readRange(0, 3).
- then(function (data) {
- djstest.assertAreEqual(data.value.length, 3, "single item was read.");
- djstest.assertAreEqual(data.value[0].FoodID, 0, "first food id is 0.");
- djstest.assertAreEqual(data.value[1].FoodID, 1, "second food id is 1.");
- djstest.assertAreEqual(data.value[2].FoodID, 2, "third food id is 2.");
- djstest.done();
- }, thenFailTest);
- }, thenFailTest);
- });
-
- djstest.addTest(function dataCacheReadRangeSyncDelaysTest() {
- var options = { name: "cache", source: foodsFeed, pageSize: 2 };
- var counter = 0;
- createNewCache(options).
- then(function (cache) {
- cache.readRange(0, 1).
- then(function (data) {
- djstest.assertAreEqual(counter, 0, "counter is zero for first set of results");
- djstest.assertAreEqual(cache.stats.netReads, 1, "one request made to fulfill the readRange");
- counter++;
- cache.readRange(0, 1).
- then(function (data) {
- djstest.assertAreEqual(counter, 2, "counter is two because even sync results are delayed)");
- djstest.assertAreEqual(cache.stats.netReads, 1, "no additional requests since requested data is in cache");
- djstest.done();
- }, thenFailTest);
- djstest.assertAreEqual(counter, 1, "counter is one because readRange hasn't run (even if results are cached)");
- counter++;
- }, thenFailTest);
- }, thenFailTest);
- });
-
- djstest.addTest(function dataCacheReadRangesWithDestroyTest() {
- var options = { name: "cache", source: foodsFeed, pageSize: 2, prefetchSize: 0 };
- var counter = 0;
- createNewCache(options).then(function (cache) {
- cache.readRange(0, 1).then(function (data) {
- djstest.assertAreEqual(cache.stats.netReads, 1, "one request made to fulfill the readRange");
- cache.clear().then(function () {
- djstest.assertAreEqual(cache.stats.netReads, 0, "stats cleared in destroy");
- cache.readRange(0, 1).then(function (data) {
- djstest.assertAreEqual(cache.stats.netReads, 1, "request made after destroy to fulfill the readRange");
- djstest.done();
- }, thenFailTest);
- }, thenFailTest);
- }, thenFailTest);
- }, thenFailTest);
- });
-
- djstest.addTest(function dataCacheReadSimultaneousTest() {
- var options = { name: "cache", source: foodsFeed, pageSize: 2 };
- var counter = 0;
- var theCache;
- var checkDataAndCount = function (data) {
- djstest.assertAreEqual(data.value.length, 1, "Single item returned");
- djstest.assertAreEqual(data.value[0].FoodID, 0, "FoodId is set to zero for first item");
- djstest.assertAreEqual(theCache.stats.netReads, 1, "single theCache.stats.netReads");
- djstest.assert(theCache.stats.prefetches <= 1, "theCache.stats.prefetches <= 1 - no repetitions");
- counter++;
- if (counter === 3) {
- djstest.done();
- }
- };
-
- createNewCache(options).
- then(function (cache) {
- theCache = cache;
- cache.readRange(0, 1).then(checkDataAndCount, thenFailTest);
- cache.readRange(0, 1).then(checkDataAndCount, thenFailTest);
- cache.readRange(0, 1).then(checkDataAndCount, thenFailTest);
- }, thenFailTest);
- });
-
- djstest.addTest(function dataCacheMultipleClearTest() {
- var options = { name: "cache", source: foodsFeed, pageSize: 2 };
- var counter = 0;
- var checkCount = function (data) {
- djstest.assert(true, "clear then was called");
- counter++;
- if (counter === 3) {
- djstest.done();
- }
- };
-
- createNewCache(options).
- then(function (cache) {
- cache.readRange(0, 1).then(function () {
- cache.clear().then(checkCount, thenFailTest);
- cache.clear().then(checkCount, thenFailTest);
- cache.clear().then(checkCount, thenFailTest);
- }, thenFailTest);
- }, thenFailTest);
- });
-
- djstest.addTest(function dataCacheOnIdleIsFired() {
- var options = { name: "cache", source: foodsFeed, pageSize: 2, prefetchSize: 0 };
-
- createNewCache(options).
- then(function (cache) {
- var counter = 0;
- var clearSucceeded = false;
-
- var thenFailThisTest = function (err) {
- if (err && err.message) {
- djstest.fail(err.message);
- } else {
- djstest.fail("unexepected promise failure");
- }
- };
-
- cache.onidle = function () {
- counter++;
- djstest.assertAreEqual(counter, 1, "onidle was called 1 times");
- djstest.assert(clearSucceeded, "onidle was called after destroy");
- djstest.done();
- };
-
- cache.readRange(0, 1).then(null, thenFailThisTest);
- cache.readRange(0, 1).then(null, thenFailThisTest);
- cache.readRange(3, 4).then(function () {
- cache.readRange(5, 6).then(function () {
- cache.clear().then(function () {
- clearSucceeded = true;
- }, thenFailThisTest);
- }, thenFailThisTest);
- }, thenFailThisTest);
- }, thenFailTest);
- });
-
- djstest.addTest(function dataCacheOnIdleFiresOnErrorTest() {
-
- var errorResponse = false;
- var httpClient = {
- request: function (request, success, error) {
- var response = { statusCode: 200, headers: { "Content-Type": "application/json", "OData-Version": "4.0" }, body: JSON.stringify({ d: [1, 2] }) };
- if (!errorResponse) {
- errorResponse = true;
- setTimeout(function () {
- success(response);
- }, 0);
- } else {
- response.statusCode = 500;
- response.body = "bad response";
- setTimeout(function () {
- error({ message: "HTTP request failed", request: request, response: response });
- }, 0);
- }
- }
- };
-
- var options = { name: "cache", source: foodsFeed, pageSize: 2, prefetchSize: 0, httpClient: httpClient };
-
- createNewCache(options).
- then(function (cache) {
- var counter = 0;
- var errorHandlerCalled = false;
-
- var thenFailThisTest = function (err) {
- if (err && err.message) {
- if (errorResponse) {
- djstest.assertAreEqual(err.message, "HTTP request failed", "Error is the expected one");
- errorHandlerCalled = true;
- } else {
- djstest.fail(err.message);
- }
- } else {
- djstest.fail("unexepected promise failure");
- }
- };
-
- cache.onidle = function () {
- counter++;
- djstest.assertAreEqual(counter, 1, "onidle was called");
- djstest.assert(errorHandlerCalled, "error handler was called before onidle");
- cache.onidle = null;
- cache.clear().then(function () {
- djstest.done();
- }, thenFailTest);
- };
- cache.readRange(0, 2).then(function () {
- cache.readRange(2, 4).then(function () {
- djstest.fail("unexpected readRange success");
- }, thenFailThisTest);
- }, thenFailThisTest);
- }, thenFailTest);
- });
-
-
- djstest.addTest(function dataCacheOdataSourceNormalizedURITest() {
- var requestsMade = 0;
- var httpClient = {
- request: function (request, success, error) {
- var response = { statusCode: 200, headers: { "Content-Type": "application/json", "OData-Version": "4.0" }, body: JSON.stringify({ value: [1, 2] }) };
- if (requestsMade === 0) {
- djstest.pass("Cache made first request for data from the source");
- requestsMade++;
- } else {
- // In memory storage will make a second request from the new cache since two caches with the same name will coexist
- if (window.mozIndexedDB || window.localStorage || requestsMade > 1) {
- djstest.fail("Unexpected request to the source");
- } else {
- djstest.pass("In memory cache requested the data from the source");
- }
- }
- setTimeout(function () {
- success(response);
- }, 0);
- }
- };
-
- var options = { name: "cache", source: "http://exampleuri.com/my service.svc", pageSize: 2, prefetchSize: 0, httpClient: httpClient };
-
- createNewCache(options).
- then(function (cache) {
- cache.readRange(0, 2).then(function () {
- options.source = "HtTp://ExampleURI.cOm/my%20service.svc";
- var newCache = odatajs.cache.createDataCache(options);
- newCache.readRange(0, 2).then(function (data) {
- djstest.assertAreEqualDeep(data.value, [1, 2], "Got the expected data from the new cache instance");
- newCache.clear().then(function () {
- djstest.done();
- }, thenFailTest);
- }, thenFailTest);
- }, thenFailTest);
- }, thenFailTest);
- });
-
-
- djstest.addTest(function dataCachePrefetchAllTest() {
- var options = { name: "cache", source: foodsFeed, pageSize: 2, prefetchSize: -1 };
- var counter = 0;
- var theCache;
-
- var callback = function () {
- counter++;
- if (counter === 2) {
- djstest.assertAreEqual(1, theCache.stats.netReads, "single page to satisfy read (" + theCache.stats.netReads + ")");
- djstest.assert(theCache.stats.prefetches > 1, "theCache.stats.prefetches(" + theCache.stats.prefetches + ") > 1 - multiple prefetches");
- djstest.done();
- }
- };
-
- var checkDataAndCount = function (data) {
- djstest.assertAreEqual(data.value.length, 1, "Single item returned");
- djstest.assertAreEqual(data.value[0].FoodID, 0, "FoodId is set to zero for first item");
- djstest.assertAreEqual(1, theCache.stats.netReads, "single theCache.stats.netReads");
- djstest.assert(theCache.stats.prefetches <= 1, "theCache.stats.prefetches <= 1 - no repetitions");
- callback();
- };
-
- createNewCache(options).
- then(function (cache) {
- theCache = cache;
- cache.readRange(0, 1).then(checkDataAndCount, thenFailTest);
- cache.onidle = function () {
- djstest.log("onidle fired");
- callback();
- };
- }, thenFailTest);
- });
-
- djstest.addTest(function dataCacheReadRangeTakeMoreThanCollectionCountTest() {
- // Read multiple pages.
- var options = { name: "cache", source: foodsFeed, pageSize: 2 };
- createNewCache(options).
- then(function (cache) {
- cache.count().then(function (count) {
- cache.readRange(0, count + 1).
- then(function (data) {
- djstest.assertAreEqual(data.value.length, count, "all items in the collection were read.");
- cache.readRange(2, count + 1).
- then(function (data) {
- djstest.assertAreEqual(data.value.length, count - 2, "all requested in the collection were read.");
- djstest.assertAreEqual(data.value[0].FoodID, 2, "first read food id is 2.");
- djstest.done();
- }, thenFailTest);
- }, thenFailTest);
- }, thenFailTest);
- }, thenFailTest);
- });
-
- djstest.addTest(function dataCacheReadRangeSkipMoreThanCollectionCountTest() {
- // Read multiple pages.
- var options = { name: "cache", source: foodsFeed, pageSize: 2 };
- createNewCache(options).
- then(function (cache) {
- cache.count().then(function (count) {
- cache.readRange(count + 1, 5).
- then(function (data) {
- djstest.assertAreEqual(data.value.length, 0, "no items were read.");
- djstest.done();
- }, thenFailTest);
- }, thenFailTest);
- }, thenFailTest);
- });
-
- djstest.addTest(function dataCacheReadRangeTakeMoreThanPrefetchSizeTest() {
- // Read multiple pages.
- var options = { name: "cache", source: foodsFeed, pageSize: 2, prefetchSize: 1 };
- createNewCache(options).
- then(function (cache) {
- cache.readRange(0, 4).
- then(function (data) {
- djstest.assertAreEqual(data.value.length, 4, "all requested in the collection were read.");
- djstest.assertAreEqual(data.value[0].FoodID, 0, "first food id is 0.");
- djstest.assertAreEqual(data.value[1].FoodID, 1, "second food id is 1.");
- djstest.assertAreEqual(data.value[2].FoodID, 2, "third food id is 2.");
- djstest.assertAreEqual(data.value[3].FoodID, 3, "third food id is 3.");
- djstest.done();
- }, thenFailTest);
- }, thenFailTest);
- });
-
- djstest.addTest(function dataCacheRangeInvalidIndexAndCount() {
- var options = { name: "cache", source: foodsFeed, pageSize: 2, prefetchSize: 1 };
- var counter = 0;
-
- var thenFailSuccess = function () {
- djstest.fail("Call to success was unexpected");
- counter++;
- if (counter === tests.length) {
- djstest.done();
- }
- };
-
- var thenFailError = function () {
- djstest.fail("Call to error was unexpected");
- counter++;
- if (counter === tests.length) {
- djstest.done();
- }
- };
-
- var invalidValues = [-5, -1, null, undefined, NaN, Infinity, "5", "this is not a number"];
- var tests = [];
- $.each(invalidValues, function (_, value) {
- tests.push({ i: value, c: 0 });
- tests.push({ i: 0, c: value });
- tests.push({ i: value, c: value });
- });
-
- createNewCache(options).
- then(function (cache) {
- var i, len;
- for (i = 0, len = tests.length; i < len; i++) {
- var test = tests[i];
- try {
- cache.readRange(test.i, test.c).then(thenFailSuccess, thenFailTest);
- } catch (err) {
- djstest.pass("Expected exception was thrown: " + err.message);
- counter++;
- }
- }
- if (counter === tests.length) {
- djstest.done();
- }
- });
- });
-
-
- djstest.addTest(function cacheOptionsForCountTest() {
- var httpClient = {
- request: function (r, success, error) {
- window.setTimeout(function () {
- success({ data: "10" });
- }, 1);
- return null;
- }
- };
- var cache = odatajs.cache.createDataCache({
- name: "mem", mechanism: "memory", source: "http://www.example.org/service/",
- httpClient: httpClient
- });
- cache.count().then(function (count) {
- djstest.assertAreEqual(count, 10, "count value");
- djstest.done();
- }, djstest.failAndDoneCallback("failed to get count"));
- });
-
- djstest.addTest(function dataCacheDestoryStopsThePrefetcherTest() {
- var oldHttpClientRequest = window.odatajs.oData.net.defaultHttpClient.request;
- var prefetchCount = 0;
- var theCache;
-
- window.odatajs.oData.net.defaultHttpClient.request = function (request, success, error) {
- prefetchCount++;
- djstest.assert(prefetchCount <= 3, "Expected prefetch request");
- if (prefetchCount === 3) {
- theCache.clear().then(function () {
- djstest.assertAreEqual(prefetchCount, 3, "cache.clear() stopped the prefetcher");
- djstest.done();
- window.odatajs.oData.net.defaultHttpClient.request = oldHttpClientRequest;
- }, thenFailTest);
- return {
- abort: function () { }
- };
- }
- return oldHttpClientRequest(request, success, error);
- };
-
- try {
- var options = { name: "cache", source: foodsFeed, pageSize: 1, prefetchSize: -1 };
- createNewCache(options).then(function (cache) {
- theCache = cache;
- cache.readRange(0, 0).then(null, thenFailTest);
- });
- } catch (e) {
- window.odatajs.oData.net.defaultHttpClient.request = oldHttpClientRequest;
- djstest.fail("Exception thrown, prefetchSize: " + tests[count] + " error: " + e.message);
- djstest.done();
- }
- });
-
- djstest.addTest(function dataCacheFilterTest() {
- var options = { name: "cache", source: foodsFeed, pageSize: 3, prefetchSize: -1 };
- var counter = 0;
-
- var singleItemPredicate = function (data) {
- return data.FoodID === 2;
- };
-
- var multipleItemPredicate = function (data) {
- return data.FoodID % 2 === 1;
- };
-
- var noItemPredicate = function (data) {
- return data.Name === "something i would never eat";
- };
-
- var allItemPredicate = function (data) {
- return data.FoodID >= 0;
- };
-
- var doneAfterAllTests = function () {
- counter++;
- if (counter === tests.length) {
- djstest.done();
- }
- };
-
- var last = collectionSize - 1;
- var tests = [
- { index: 0, count: -5, predicate: singleItemPredicate }, // Single match in entire collection
- {index: 2, count: 1, predicate: singleItemPredicate }, // Single match, single count
- {index: 3, count: 1, predicate: singleItemPredicate }, // Single match skipped, i.e. no matches
- {index: 0, count: -1, predicate: multipleItemPredicate }, // Multiple matches in entire collection
- {index: 0, count: 5, predicate: multipleItemPredicate }, // Multiple matches, take partial
- {index: 3, count: 5, predicate: multipleItemPredicate }, // Multiple matches, skip/take partial
- {index: 7, count: 10, predicate: multipleItemPredicate }, // Multiple matches, skip partial, take past end of collection
- {index: 13, count: 4, predicate: allItemPredicate }, // All items match, skip/take partial
- {index: 0, count: 20, predicate: noItemPredicate }, // No matches
- {index: 0, count: 0, predicate: allItemPredicate }, // Zero count
- {index: -5, count: 1, predicate: allItemPredicate }, // Negative index
- {index: last + 1, count: 1, predicate: allItemPredicate }, // Index past end of collection
-
- {index: last, count: -5, predicate: singleItemPredicate, backwards: true }, // Single match in entire collection
- {index: 2, count: 1, predicate: singleItemPredicate, backwards: true }, // Single match, single count
- {index: 1, count: 1, predicate: singleItemPredicate, backwards: true }, // Single match skipped, i.e. no matches
- {index: last, count: -1, predicate: multipleItemPredicate, backwards: true }, // Multiple matches in entire collection
- {index: last, count: 6, predicate: multipleItemPredicate, backwards: true }, // Multiple matches, take partial
- {index: last - 3, count: 5, predicate: multipleItemPredicate, backwards: true }, // Multiple matches, skip/take partial
- {index: 13, count: 10, predicate: multipleItemPredicate, backwards: true }, // Multiple matches, skip partial, take past end of collection
- {index: 4, count: 13, predicate: allItemPredicate, backwards: true }, // All items match, skip/take partial
- {index: last, count: 20, predicate: noItemPredicate, backwards: true }, // No matches
- {index: 0, count: 0, predicate: allItemPredicate, backwards: true }, // Zero count
- {index: -5, count: 1, predicate: allItemPredicate, backwards: true }, // Negative index
- {index: last + 1, count: 1, predicate: allItemPredicate, backwards: true }, // Index past end of collection
-
- {index: "foo", count: 1, predicate: singleItemPredicate, exception: { message: "'index' must be a valid number.", index: NaN} },
- { index: 0, count: "foo", predicate: multipleItemPredicate, exception: { message: "'count' must be a valid number.", count: NaN} }
- ];
-
- var testDescription = function(test) {
- return "filter [" + test.index + ", " + test.count + " " + (test.backwards ? "back" : "forward") + "] for predicate " + test.predicate;
- };
-
- var filterErrorCallback = function (err) {
- if (err && err.message) {
- djstest.fail(err.message);
- } else {
- djstest.fail("unexpected promise failure");
- }
- doneAfterAllTests();
- };
-
- var removeSafariExceptionProperties = function (err) {
- /** Removes Safari-specific properties from an exception object
- * @param {Exception} err -The exception object to operate on
- * @returns {Exception} The original exception object with the Safari-specific properties removed
- */
- var safariProperties = ["line", "expressionBeginOffset", "expressionEndOffset", "sourceId", "sourceURL"];
-
- var result = {};
- $.each(err, function (property, value) {
- if ($.inArray(property, safariProperties) === -1) {
- result[property] = value;
- }
- });
-
- return result;
- };
-
- ODataVerifyReader.readJsonAcrossServerPages(foodsFeed, function (expectData) {
- $.each(tests, function (_, test) {
- createNewCache(options).then(function (cache) {
- try {
- var expectedResults = {};
- if (test.backwards) {
- cache.filterBack(test.index, test.count, test.predicate).then(function (results) {
- expectedResults = CacheVerifier.getExpectedFilterResults(expectData, test.index, test.count, test.predicate, test.backwards);
- djstest.assertAreEqualDeep(results, expectedResults, "results for " + testDescription(test));
- doneAfterAllTests();
- }, filterErrorCallback);
- } else {
- cache.filterForward(test.index, test.count, test.predicate).then(function (results) {
- expectedResults = CacheVerifier.getExpectedFilterResults(expectData, test.index, test.count, test.predicate, test.backwards);
- djstest.assertAreEqualDeep(results, expectedResults, "results for " + testDescription(test));
- doneAfterAllTests();
- }, filterErrorCallback);
- }
-
- if (test.exception) {
- djstest.fail("expected exception for " + testDescription(test));
- doneAfterAllTests();
- }
- } catch (err) {
- if (test.exception) {
- djstest.assertAreEqualDeep(removeSafariExceptionProperties(err), test.exception, "exception for " + testDescription(test));
- } else {
- djstest.fail("unexpected exception for " + testDescription(test) + ": " + djstest.toString(err));
- }
- doneAfterAllTests();
- }
- }, thenFailTest);
- });
- });
- });
-
- djstest.addTest(function createDataCacheTest() {
- var cache;
-
- // Verify the defaults.
- cache = odatajs.cache.createDataCache({ name: "name", source: "src" });
-
- djstest.assertAreEqual(cache.onidle, undefined, "onidle is undefined");
-
- // Verify specific values.
- cache = odatajs.cache.createDataCache({ name: "name", source: "src", cacheSize: 1, pageSize: 2, prefetchSize: 3, idle: 123 });
-
- djstest.assertAreEqual(cache.onidle, 123, "onidle is as specified");
-
- // Verify 0 pageSize
- djstest.expectException(function () {
- odatajs.cache.createDataCache({ name: "name", source: "src", cacheSize: 1, pageSize: 0, prefetchSize: 3, idle: 123 });
- }, "zero pageSize");
-
- // Verify negative pageSize
- djstest.expectException(function () {
- odatajs.cache.createDataCache({ name: "name", source: "src", cacheSize: 1, pageSize: -2, prefetchSize: 3, idle: 123 });
- }, "negative pageSize");
-
- // Verify NaN pageSize
- djstest.expectException(function () {
- cache = odatajs.cache.createDataCache({ name: "name", source: "src", cacheSize: 1, pageSize: "2", prefetchSize: 3, idle: 123 });
- }, "NaN pageSize");
-
- // Verify NaN cacheSize
- djstest.expectException(function () {
- cache = odatajs.cache.createDataCache({ name: "name", source: "src", cacheSize: "1", pageSize: 2, prefetchSize: 3, idle: 123 });
- }, "NaN cacheSize");
-
- // Verify NaN prefetchSize
- djstest.expectException(function () {
- cache = odatajs.cache.createDataCache({ name: "name", source: "src", cacheSize: 1, pageSize: 2, prefetchSize: "3", idle: 123 });
- }, "NaN prefetchSize");
-
- // Verify undefined name
- djstest.expectException(function () {
- odatajs.cache.createDataCache({ source: "src", cacheSize: 1, pageSize: 1, prefetchSize: 3, idle: 123 });
- }, "undefined name");
-
- // Verify null name
- djstest.expectException(function () {
- odatajs.cache.createDataCache({ name: null, source: "src", cacheSize: 1, pageSize: 1, prefetchSize: 3, idle: 123 });
- }, "null name");
-
- // Verify undefined source
- djstest.expectException(function () {
- odatajs.cache.createDataCache({ name: "name", cacheSize: 1, pageSize: 1, prefetchSize: 3, idle: 123 });
- }, "undefined source");
-
- djstest.done();
- });
-
- djstest.addTest(function createDataCacheWithSourceTest() {
- var cacheSource = {
- count: function (success) {
- djstest.pass("cacheSource.count was called");
- success(0);
- },
-
- read: function (index, count, success, error) {
- djstest.assertAreEqual(index, 0, "index is the expected one");
- djstest.assertAreEqual(count, 10, "test is the expected one");
- djstest.assert(success, "success is defined");
- djstest.assert(error, "error is defined");
- djstest.pass("cacheSource.read was called");
-
- setTimeout(function () {
- success([]);
- }, 0);
- }
- };
-
- var cache = odatajs.cache.createDataCache({ name: "name", source: cacheSource, mechanism: "memory", pageSize: 10 });
- cache.count().then(function () {
- cache.readRange(0, 5).then(function () {
- djstest.done();
- }, thenFailTest);
- }, thenFailTest);
- });
-
- djstest.addTest(function cacheInitializationFailTest() {
- // Tests various failure modes for cache initialization.
- var failures = ["read-settings", "write-settings", "v2"];
- var failureIndex = 0;
-
- var originalStore = odatajs.store.createStore;
- var restoreStore = function () {
- odatajs.store.createStore = originalStore;
- };
-
- var storeError = { message: "cacheInitializationFailTest error" };
- odatajs.store.createStore = function (name, mechanism) {
- return {
- addOrUpdate: function (key, value, successCallback, errorCallback) {
- if (failures[failureIndex] === "write-settings") {
- window.setTimeout(function () { errorCallback(storeError); }, 2);
- } else {
- djstest.fail("Error unaccounted for in addOrUpdate for " + failures[failureIndex]);
- window.setTimeout(function () { errorCallback(storeError); }, 2);
- }
- },
- read: function (key, successCallback, errorCallback) {
- if (failures[failureIndex] === "read-settings") {
- window.setTimeout(function () { errorCallback(storeError); }, 2);
- } else if (failures[failureIndex] === "v2") {
- window.setTimeout(function () {
- successCallback("K", { version: "2.0" });
- }, 2);
- } else if (failures[failureIndex] === "write-settings") {
- window.setTimeout(function () { successCallback(null, null); }, 2);
- } else {
- djstest.fail("Error unaccounted for read in " + failures[failureIndex]);
- window.setTimeout(function () { errorCallback(storeError); }, 2);
- }
- }
- };
- };
-
- var nextFailure = function () {
- djstest.log("Failure mode: " + failures[failureIndex]);
- var cache = odatajs.cache.createDataCache({ name: "name", source: "foo", mechanism: "memory", pageSize: 10 });
- try {
- // The first readRange should succeed, because the data cache isn't really initialized at this time.
- cache.readRange(1, 2).then(djstest.failAndDoneCallback("No function should succeed"), function (err) {
- djstest.expectException(function () {
- cache.readRange(1, 2);
- }, "readRange after store is invalidated");
-
- djstest.expectException(function () {
- cache.count();
- }, "count after store is invalidated");
-
- djstest.expectException(function () {
- cache.clear();
- }, "clear after store is invalidated");
-
- djstest.expectException(function () {
- cache.filterForward(1, 2);
- }, "filterForward after store is invalidated");
-
- djstest.expectException(function () {
- cache.filterBack(1, 2);
- }, "filterBack after store is invalidated");
-
- djstest.expectException(function () {
- cache.toObservable();
- }, "toObservable after store is invalidated");
-
- failureIndex++;
- if (failureIndex === failures.length) {
- restoreStore();
- djstest.done();
- } else {
- nextFailure();
- }
- });
- } catch (outerError) {
- djstest.fail("Unexpected failure for first .readRange: " + window.JSON.stringify(outerError));
- restoreStore();
- djstest.done();
- }
- };
-
- nextFailure();
- });
-
- djstest.addTest(function createDataCacheWithSourceCallsErrorTest() {
- var cacheSource = {
- count: function () {
- djstest.fail("cacheSource.count was called");
- },
-
- read: function (index, count, success, error) {
- setTimeout(function () {
- error({ message: "source error" });
- }, 0);
- }
- };
-
- var cache = odatajs.cache.createDataCache({ name: "name", source: cacheSource, mechanism: "memory", pageSize: 10 });
- cache.readRange(0, 5).then(function () {
- djstest.fail("unexpected call to then success");
- djstest.done();
- }, function (err) {
- djstest.assertAreEqual(err.message, "source error", "got the expected error");
- djstest.done();
- });
- });
-
- djstest.addTest(function toObservableMissingTest() {
- createNewCache({ name: "cache", source: "http://temp.org" }).then(function (cache) {
- var hiddenRx = window.Rx;
- try {
- window.Rx = null;
- var error = null;
- try {
- cache.toObservable();
- } catch (err) {
- error = err;
- }
-
- djstest.assert(error !== null, "error !== null");
- } finally {
- window.Rx = hiddenRx;
- }
-
- djstest.assert(error !== null, "error !== null");
- djstest.destroyCacheAndDone(cache);
- });
- });
-
- djstest.addTest(function toObservableSinglePageTest() {
- createNewCache({ name: "cache", source: foodsFeed }).then(function (cache) {
- var lastId = -1;
- cache.toObservable().subscribe(function (item) {
- djstest.assert(lastId < item.FoodID, "lastId < item.FoodID");
- lastId = item.FoodID;
- }, thenFailTest, function () {
- djstest.assert(lastId !== -1, "lastId !== -1");
- djstest.done();
- });
- });
- });
-
- djstest.addTest(function toObservableCaseSinglePageTest() {
- createNewCache({ name: "cache", source: foodsFeed }).then(function (cache) {
- var lastId = -1;
- cache.toObservable().subscribe(function (item) {
- djstest.assert(lastId < item.FoodID, "lastId < item.FoodID");
- lastId = item.FoodID;
- }, thenFailTest, function () {
- djstest.assert(lastId !== -1, "lastId !== -1");
- djstest.done();
- });
- });
- });
-
- djstest.addTest(function toObservableMultiplePageTest() {
- createNewCache({ name: "cache", source: foodsFeed, pageSize: 2 }).then(function (cache) {
- var lastId = -1;
- var callCount = 0;
- cache.toObservable().subscribe(function (item) {
- djstest.assert(lastId < item.FoodID, "lastId < item.FoodID");
- lastId = item.FoodID;
- callCount += 1;
- }, thenFailTest, function () {
- djstest.assert(lastId !== -1, "lastId !== -1");
- djstest.assert(callCount > 1, "callCount > 1");
- djstest.done();
- });
- });
- });
-
- djstest.addTest(function toObservableEarlyDisposeTest() {
- createNewCache({ name: "cache", source: foodsFeed, pageSize: 2 }).then(function (cache) {
- var lastId = -1;
- var callCount = 0;
- var complete = false;
- var observer = cache.toObservable().subscribe(function (item) {
- djstest.assert(complete === false, "complete === false");
- djstest.assert(lastId < item.FoodID, "lastId < item.FoodID");
- lastId = item.FoodID;
- callCount += 1;
- complete = true;
- observer.Dispose();
- djstest.done();
- }, thenFailTest);
- });
- });
-
- djstest.addTest(function toObservableFailureTest() {
- createNewCache({ name: "cache", source: foodsFeed, pageSize: 2 }).then(function (cache) {
- var lastId = -1;
- var complete = false;
- window.MockHttpClient.clear().addResponse("*", { statusCode: 500, body: "server error" });
- window.MockHttpClient.async = true;
- var savedClient = window.odatajs.oData.net.defaultHttpClient;
- window.odatajs.oData.net.defaultHttpClient = window.MockHttpClient;
- cache.toObservable().subscribe(function (item) {
- window.odatajs.oData.net.defaultHttpClient = savedClient;
- djstest.fail("Unexpected call to OnNext");
- }, function (err) {
- djstest.assert(complete === false, "complete === false");
- djstest.assert(err, "err defined");
- window.odatajs.oData.net.defaultHttpClient = savedClient;
- complete = true;
- djstest.done();
- }, function (complete) {
- djstest.fail("Unexpected call to complete. Error handler should be called.");
- window.odatajs.oData.net.defaultHttpClient = savedClient;
- complete = true;
- djstest.done();
- });
- });
- });
-
- // DATAJS INTERNAL START
-
- djstest.addTest(function createDeferredTest() {
- // Verify basic use of deferred object.
- var deferred = odatajs.deferred.createDeferred();
- deferred.then(function (val1, val2) {
- djstest.assertAreEqual(val1, 1, "val1 is as specified");
- djstest.assertAreEqual(val2, 2, "val2 is as specified");
- djstest.done();
- });
- deferred.resolve(1, 2);
- });
-
- djstest.addTest(function deferredThenTest() {
- // Verify then registration and chaining.
- var deferred = odatajs.deferred.createDeferred();
- deferred.then(function (val1, val2) {
- djstest.assertAreEqual(val1, 1, "val1 is as specified");
- djstest.assertAreEqual(val2, 2, "val2 is as specified");
- return "foo";
- }).then(function (foo) {
- // See Compatibility Note B in DjsDeferred remarks.
- djstest.assert(foo !== "foo", "argument for chained 'then' is *not* result of previous call");
- djstest.assert(foo === 1, "argument for chained 'then' is same as for previous call");
-
- var other = odatajs.deferred.createDeferred();
- other.then(null, function (err, msg) {
- djstest.assertAreEqual("error", err, "err is as specified");
- djstest.assertAreEqual("message", msg, "msg is as specified");
-
- }).then(null, function (err, msg) {
- djstest.log("chained errors are called");
-
- djstest.assertAreEqual("error", err, "err is as specified");
- djstest.assertAreEqual("message", msg, "msg is as specified");
-
- var multiple = odatajs.deferred.createDeferred();
- var count = 0;
-
- // See Compatibility Note A in DjsDeferred remarks.
- multiple.then(function () {
- djstest.assertAreEqual(count, 0, "first base registration fires as #0");
- count++;
- }).then(function () {
- djstest.assertAreEqual(count, 1, "first chained registration fires as #1");
- count++;
- });
-
- multiple.then(function () {
- djstest.assertAreEqual(count, 2, "second base registration fires as #2");
- count++;
- }).then(function () {
- djstest.assertAreEqual(count, 3, "second chained registration fires as #3");
- djstest.done();
- });
-
- multiple.resolve();
- });
- other.reject("error", "message");
- });
-
- deferred.resolve(1, 2);
- });
-
- djstest.addTest(function deferredResolveTest() {
- // Resolve with no arguments.
- var deferred = odatajs.deferred.createDeferred();
- deferred.then(function (arg) {
- djstest.assertAreEqual(arg, undefined, "resolve with no args shows up as undefined");
-
- // Resolve with no callbacks.
- var other = odatajs.deferred.createDeferred();
- other.resolve();
- djstest.done();
- });
-
- deferred.resolve();
- });
-
- djstest.addTest(function deferredRejectTest() {
- // Resolve with no arguments.
- var deferred = odatajs.deferred.createDeferred();
- deferred.then(null, function (arg) {
- djstest.assertAreEqual(arg, undefined, "reject with no args shows up as undefined");
-
- // Resolve with no callbacks.
- var other = odatajs.deferred.createDeferred();
- other.reject();
- djstest.done();
- });
-
- deferred.reject();
- });
-
- djstest.addTest(function estimateSizeTest() {
- var tests = [
- { i: null, e: 8 },
- { i: undefined, e: 8 },
- { i: 0, e: 8 },
- { i: "abc", e: 6 },
- { i: [1, 2, 3], e: 30 },
- { i: { a1: null, a2: undefined, a3: 5, a4: "ab", a5: { b1: 5, b2: 6} }, e: 72 },
- { i: {}, e: 0 }
- ];
-
- var i, len;
- for (i = 0, len = tests.length; i < len; i++) {
- var test = tests[i];
- djstest.assertAreEqual(odatajs.cache.estimateSize(test.i), test.e);
- }
- djstest.done();
- });
-
- djstest.addTest(function cacheOptionsTunnelTest() {
- var mockClient = window.MockHttpClient;
- var doneCalled = false;
-
- mockClient.clear().setAsync(true).addRequestVerifier("*", function (theRequest) {
- if (!doneCalled) {
- doneCalled = true;
- djstest.assertAreEqual(theRequest.user, "the-user", "theRequest.user");
- djstest.assertAreEqual(theRequest.password, "the-password", "theRequest.password");
- djstest.assertAreEqual(theRequest.enableJsonpCallback, false, "theRequest.enableJsonpCallback");
- djstest.assertAreEqual(theRequest.callbackParameterName, "p", "callbackParameterName");
- djstest.done();
- }
- });
-
- var cache = odatajs.cache.createDataCache({
- name: "cacheOptionsTunnel",
- source: "http://foo-bar/",
- user: "the-user",
- password: "the-password",
- enableJsonpCallback: false,
- callbackParameterName: "p",
- httpClient: mockClient
- });
-
- cache.readRange(0, 10).then(function (arr) {
- djstest.fail("unexpected callback into readRange in test cacheOptionsTunnelTest");
- if (!doneCalled) {
- doneCalled = true;
- djstest.done();
- }
- });
- });
-
- djstest.addTest(function dataCacheHandlesFullStoreTest() {
-
- var TestStore = function (name) {
- var that = new window.odatajs.store.MemoryStore(name);
- that.addOrUpdate = function (key, value, success, error) {
- if (key === "__settings") {
- window.setTimeout(function () {
- success(key, value);
- }, 0);
- } else {
- window.setTimeout(function () {
- error({ name: "QUOTA_EXCEEDED_ERR" });
- }, 0);
- }
- };
- return that;
- };
-
- TestStore.create = function (name) {
- return new TestStore(name);
- };
-
- TestStore.isSupported = function () {
- return true;
- };
-
- var cacheSource = {
- identifier: "testSource",
- count: function (success) {
- djstest.fail("cacheSource.count was called");
- success(5);
- },
- read: function (index, count, success, error) {
- djstest.assertAreEqual(index, 0, "index is the expected one");
- djstest.assertAreEqual(count, 5, "test is the expected one");
-
- setTimeout(function () {
- success({ value: [1, 2, 3, 4, 5] });
- }, 0);
- }
- };
-
- var originalCreateStore = window.odatajs.store.createStore;
-
- window.odatajs.store.createStore = function (name, mechanism) {
- return TestStore(name);
- };
-
- try {
- var cache = odatajs.cache.createDataCache({
- name: "cache",
- pageSize: 5,
- prefetchSize: 0,
- source: cacheSource,
- mechanism: "teststore"
- });
- } finally {
- window.odatajs.store.createStore = originalCreateStore;
- }
-
- cache.readRange(0, 5).then(function (data) {
- djstest.assertAreEqual(data.value.length, 5, "5 items were read.");
- cache.readRange(0, 5).then(function (data) {
- djstest.assertAreEqual(data.value.length, 5, "5 items were read.");
- djstest.done();
- }, thenFailTest);
- }, thenFailTest);
- });
-
- // DATAJS INTERNAL END
-})(this);
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/d5ec5557/datajs/tests-tmp/b-datajs-cache-large-collection-functional-tests.html
----------------------------------------------------------------------
diff --git a/datajs/tests-tmp/b-datajs-cache-large-collection-functional-tests.html b/datajs/tests-tmp/b-datajs-cache-large-collection-functional-tests.html
deleted file mode 100644
index a3820cb..0000000
--- a/datajs/tests-tmp/b-datajs-cache-large-collection-functional-tests.html
+++ /dev/null
@@ -1,53 +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.
- */
- -->
-<html>
-<head>
- <title>datajs.cache and datajs.store full local store 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/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="common/djstest-browser.js"></script>
- <script type="text/javascript" src="common/cacheVerifier.js"></script>
- <script type="text/javascript" src="common/observableHttpClient.js"></script>
- <!--<script type="text/javascript" src="common/ODataReadOracle.js"></script>-->
-
- <script type="text/javascript" src="b-datajs-cache-large-collection-functional-tests.js"></script>
-</head>
-<body>
- <h1 id="qunit-header">datajs.cache and datajs.store full local store 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/datajs/tests-tmp/b-datajs-cache-large-collection-functional-tests.js
----------------------------------------------------------------------
diff --git a/datajs/tests-tmp/b-datajs-cache-large-collection-functional-tests.js b/datajs/tests-tmp/b-datajs-cache-large-collection-functional-tests.js
deleted file mode 100644
index d09ae51..0000000
--- a/datajs/tests-tmp/b-datajs-cache-large-collection-functional-tests.js
+++ /dev/null
@@ -1,187 +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.
- */
-
-(function (window, undefined) {
- window.odatajs.oData.defaultHandler.accept = "application/json;q=0.9, */*;q=0.1";
- var largeCollectionFeed = "./endpoints/LargeCollectionService.svc/Customers";
- var itemsInCollection = 2 * 1024 * 1024;
-
- var cleanDomStorage = function (done) {
- /* Cleans all the data saved in the browser's DOM Storage. Needs to be called asynchronously in the
- * setup and teardown methods to be consistent with indexedDb's cleanup method.
- * @param {Function} done - Function to be called after DOM storage is cleared.
- */
- if (window.localStorage) {
- window.localStorage.clear();
- }
- done();
- };
-
- var cleanIndexedDb = function (done) {
- /** Cleans all the data saved in the browser's IndexedDb Storage.
- * @param {Function} done - Function to be called after DOM storage is cleared.
- */
- var caches = this.caches;
-
- djstest.cleanStoreOnIndexedDb(caches, done);
- };
-
- var makeUnexpectedErrorHandler = function () {
- return function (err) {
- djstest.assert(false, "Unexpected call to error handler with error: " + djstest.toString(err));
- };
- };
-
- var storageMechanisms = {
- indexeddb: { cleanup: cleanIndexedDb },
- dom: { cleanup: cleanDomStorage }
- };
-
- var cleanupAllStorage = function(done) {
- /** Cleans up all available storage mechanisms in the browser.
- * @param {Function} done - Function to be called by each cleanup function after storage is cleared.
- */
- var that = this;
- var storeCleanup = [];
-
- $.each(CacheVerifier.mechanisms, function(_, mechanism) {
- if (CacheVerifier.isMechanismAvailable(mechanism)) {
- storeCleanup.push(function(done) {
- if (storageMechanisms[mechanism]) {
- storageMechanisms[mechanism].cleanup.call(that, done);
- } else {
- done();
- }
- });
- }
- });
-
- djstest.asyncDo(storeCleanup, done);
- };
-
-
- module("Functional", {
- setup: function () {
- this.observableHttpClient = new ObservableHttpClient();
- window.odatajs.oData.net.defaultHttpClient = this.observableHttpClient;
- this.caches = [];
- var that = this;
-
- djstest.wait(function (done) {
- cleanupAllStorage.call(that, done);
- });
- },
-
- teardown: function () {
- window.odatajs.oData.net.defaultHttpClient = this.observableHttpClient.provider;
- var clearActions = [];
- var that = this;
-
- $.each(this.caches, function (_, cacheObject) {
- cacheObject.cache.onidle = undefined;
-
- clearActions.push(function (done) {
- cacheObject.cache.clear().then(function () {
- done();
- },
- function (err) {
- djstest.assert(false, "Unexpected call to error handler while attempting to clear with error: " + djstest.toString(err));
- });
- });
- });
-
- djstest.wait(function (done) {
- djstest.asyncDo(clearActions, function () {
- cleanupAllStorage.call(that, function () {
- that.caches = [];
- done();
- });
- });
- });
- }
- });
-
- $.each(["dom", "indexeddb"], function (_, mechanism) {
- if (CacheVerifier.isMechanismAvailable(mechanism)) {
- $.each([-1, 10 * 1024 * 1024, 1024 * 10248], function (_, cacheSize) {
- var prefetchParameters = { mechanism: mechanism, feed: largeCollectionFeed, skip: 0, take: 5, pageSize: 1024, prefetchSize: -1, cacheSize: cacheSize };
- djstest.addTest(function (params) {
-
- djstest.assertsExpected(3);
- var options = { name: "cache" + new Date().valueOf(), source: params.feed, pageSize: params.pageSize, prefetchSize: params.prefetchSize,
- mechanism: params.mechanism, cacheSize: params.cacheSize
- };
-
- var cache = odatajs.cache.createDataCache(options);
- this.caches.push({ name: options.name,
- cache: cache
- });
-
- cache.onidle = function () {
- djstest.assert(true, "onidle Called");
- djstest.done();
- };
-
- var cacheOracle = new CacheVerifier(params.feed, params.pageSize, itemsInCollection);
- var session = this.observableHttpClient.newSession();
-
- cache.readRange(params.skip, params.take).then(function (data) {
- var expectedRangeUrl = params.feed + "?$skip=" + params.skip + "&$top=" + params.take;
- cacheOracle.verifyRequests(session.requests, session.responses, params.skip, params.take, "largeCollection requests with prefetch", false, true);
- window.ODataReadOracle.readJsonAcrossServerPages(expectedRangeUrl, function (expectedData) {
- djstest.assertAreEqualDeep(data, expectedData, "Verify response data");
- });
- }, function (err) {
- makeUnexpectedErrorHandler(err)();
- });
- }, "readRange and prefetch all to fill store on " + prefetchParameters.mechanism + " with cacheSize=" + prefetchParameters.cacheSize, prefetchParameters, 600000);
-
- $.each([500, 1024 * 10 /*Test reduced from 100 to 10 to work around slow running script error in IE8 and Safari (bug 2200)*/], function (_, pageSize) {
- var largeReadParameters = { mechanism: mechanism, feed: largeCollectionFeed, skip: 0, take: 1024, pageSize: pageSize, prefetchSize: 0, cacheSize: cacheSize };
- djstest.addTest(function (params) {
-
- djstest.assertsExpected(2);
- var options = { name: "cache" + new Date().valueOf(), source: params.feed, pageSize: params.pageSize, prefetchSize: params.prefetchSize,
- mechanism: params.mechanism, cacheSize: params.cacheSize
- };
-
- var cache = odatajs.cache.createDataCache(options);
- this.caches.push({ name: options.name, cache: cache });
-
- var cacheOracle = new CacheVerifier(params.feed, params.pageSize, itemsInCollection);
- var session = this.observableHttpClient.newSession();
-
- cache.readRange(params.skip, params.take).then(function (data) {
- var expectedRangeUrl = params.feed + "?$skip=" + params.skip + "&$top=" + params.take;
- cacheOracle.verifyRequests(session.requests, session.responses, params.skip, params.take, "largeCollection requests without prefetch", false, false);
- window.ODataReadOracle.readJsonAcrossServerPages(expectedRangeUrl, function (expectedData) {
- djstest.assertAreEqualDeep(data, expectedData, "Verify response data");
- djstest.done();
- });
- }, function (err) {
- makeUnexpectedErrorHandler(err)();
- djstest.done();
- });
- }, "readRange of skip=" + largeReadParameters.skip + " take=" + largeReadParameters.take + " cacheSize=" + largeReadParameters.cacheSize + " and pageSize=" + largeReadParameters.pageSize +
- " to fill store on " + largeReadParameters.mechanism, largeReadParameters, 600000);
- });
- });
- }
- });
-})(window);
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/d5ec5557/datajs/tests-tmp/bn-odata-json-tests.js
----------------------------------------------------------------------
diff --git a/datajs/tests-tmp/bn-odata-json-tests.js b/datajs/tests-tmp/bn-odata-json-tests.js
deleted file mode 100644
index 3e306a5..0000000
--- a/datajs/tests-tmp/bn-odata-json-tests.js
+++ /dev/null
@@ -1,211 +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) {
- QUnit.module("odata-json-tests.js");
-
- djstest.addTest(function isArrayTest() {
- djstest.assert(window.odatajs.utils.isArray([]));
- djstest.assert(window.odatajs.utils.isArray([1, 2]));
- djstest.assert(!window.odatajs.utils.isArray({}));
- djstest.assert(!window.odatajs.utils.isArray("1,2,3,4"));
- djstest.assert(!window.odatajs.utils.isArray());
- djstest.assert(!window.odatajs.utils.isArray(null));
- djstest.done();
- });
-
- 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);
- };
-
-
- function createPointValue(geoKind) {
- return {
- edmType : geoKind+'Point', value : {
- type: "Point",
- coordinates: [1.0, 2.0],
- crs: {
- type: "Point",
- properties: {
- name: "EPSG:4326"
- }
- }
- }
- };
- }
-
- function createLineStringValue(geoKind) {
- return {
- edmType : geoKind+'LineString', value : {
- "type": "LineString",
- "coordinates": [ [100.0, 0.0], [101.0, 1.0] ],
- crs: {
- type: "LineString",
- properties: {
- name: "EPSG:4326"
- }
- }
- }
- };
- }
-
- function createPolygonValue(geoKind) {
- return {
- edmType : geoKind+'Polygon', 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"
- }
- }
- }
- };
- }
-
- function createMultiPointValue(geoKind) {
- return {
- edmType : geoKind+'MultiPoint', value : {
- "type": "MultiPoint",
- "coordinates": [ [100.0, 0.0], [101.0, 1.0] ],
- crs: {
- type: "MultiPoint",
- properties: {
- name: "EPSG:4326"
- }
- }
- }
- };
- }
-
- function createMultiLineStringValue(geoKind) {
- return {
- edmType : geoKind+'MultiLineString', 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"
- }
- }
- }
- };
- }
- function createMultiPolygonStringValue(geoKind) {
- return {
- edmType : geoKind+'MultiPolygon', 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"
- }
- }
- }
- };
- }
-
- function createWorkload(geoKind) {
- return [
- createPointValue(geoKind),
- createLineStringValue(geoKind),
- createPolygonValue(geoKind),
- createMultiPointValue(geoKind),
- createMultiLineStringValue(geoKind),
- createMultiPolygonStringValue(geoKind)
- ];
- }
-
- function checkGeoKind(geoKind, full) {
- var workload = createWorkload(geoKind);
- for ( var i = 0; i < workload.length; i++) {
- var item = workload[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
- };
- if (full) {
- verifyReadJsonLightDataMetadataFull(input, expected, item.edmType + " was read properly.", {});
- } else {
- verifyReadJsonLightDataMetadataMinimal(input, expected, item.edmType + " was read properly.", {});
- }
- }
-
- djstest.done();
- }
-
- djstest.addTest(function jsonReadGeometryFull() {
- checkGeoKind('Geometry',true);
- });
- djstest.addTest(function jsonReadGeometryMinimal() {
- checkGeoKind('Geometry',false);
- });
- djstest.addTest(function jsonReadGeographyFull() {
- checkGeoKind('Geography',true);
- });
- djstest.addTest(function jsonReadGeographyMinimal() {
- checkGeoKind('Geography',false);
- });
-
-})(window);
http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/d5ec5557/datajs/tests-tmp/common/ODataVerifiyReader.svc
----------------------------------------------------------------------
diff --git a/datajs/tests-tmp/common/ODataVerifiyReader.svc b/datajs/tests-tmp/common/ODataVerifiyReader.svc
deleted file mode 100644
index 101cf36..0000000
--- a/datajs/tests-tmp/common/ODataVerifiyReader.svc
+++ /dev/null
@@ -1,114 +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.
-*/
-
-<%@ ServiceHost Language="C#" Debug="true" Factory="System.ServiceModel.Activation.WebScriptServiceHostFactory"
- Service="DataJS.Tests.ODataVerifyReader" %>
-
-//uncomment this line to debug JSON serialization.
-//#define DEBUG_SERIALIZATION
-
-namespace DataJS.Tests
-{
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Net;
- using System.Runtime.Serialization;
- using System.ServiceModel;
- using System.ServiceModel.Activation;
- using System.ServiceModel.Syndication;
- using System.ServiceModel.Web;
- using System.Xml;
- using System.Xml.Linq;
- using Microsoft.Spatial;
- using Microsoft.OData.Core;
- using System.Web.Script.Serialization;
-
- /// <summary>
- /// Oracle for the OData.read library function
- /// </summary>
- [ServiceContract]
- [ServiceBehavior(IncludeExceptionDetailInFaults = true)]
- [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
- public class ODataVerifyReader
- {
- const string jsonlightMediaType = "application/json";
-
- /// <summary>
- /// Reads a URI that will return a metadata object
- /// </summary>
- /// <param name="url">The URL to send the request to</param>
- /// <returns>Stream of metadata in json light format</returns>
- [OperationContract]
- [WebGet]
- public Stream ReadMetadata(string url)
- {
- WebResponse response = WebRequest.Create(ResolveUri(url, UriKind.Absolute)).GetResponse();
- Dictionary<string, object> jsonObject = CsdlReader.ReadCsdl(new StreamReader(response.GetResponseStream()));
- return ReaderUtils.ConvertDictionarytoJsonlightStream(jsonObject);
- }
-
- /// <summary>
- /// Reads a URI that will get the Json response and return the stream
- /// </summary>
- /// <param name="url">URL of the entry</param>
- /// <param name="user">The username for basic authentication</param>
- /// <param name="password">The password for basic authentication</param>
- /// <returns>Stream of the Json response expected to be returned by OData.read</returns>
- [OperationContract]
- [WebGet(ResponseFormat = WebMessageFormat.Json)]
- public Stream ReadJson(string url, string mimeType, string user, string password)
- {
- if (mimeType == null)
- {
- mimeType = jsonlightMediaType + ";odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8";
- }
-
- HttpWebRequest request = (HttpWebRequest)ReaderUtils.CreateRequest(ResolveUri(url, UriKind.Absolute), user, password);
- request.Accept = mimeType;
- WebResponse response = request.GetResponse();
-
- return response.GetResponseStream();
- }
-
- /// <summary>
- /// Resolves the given url string to a URI
- /// </summary>
- /// <param name="url">The given URL string</param>
- /// <param name="urlKind">URI kind to resolve to</param>
- /// <returns>The resolved URI</returns>
- private static string ResolveUri(string url, UriKind uriKind)
- {
- Uri resolvedUri = new Uri(url, UriKind.RelativeOrAbsolute);
- if (!resolvedUri.IsAbsoluteUri)
- {
- // If the given URI is relative, then base it on the Referer URI
- Uri baseUri = new Uri(WebOperationContext.Current.IncomingRequest.Headers["Referer"]);
- resolvedUri = new Uri(baseUri, resolvedUri);
- if (uriKind == UriKind.Relative)
- {
- resolvedUri = baseUri.MakeRelativeUri(resolvedUri);
- }
- }
-
- return resolvedUri.ToString();
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/d5ec5557/datajs/tests-tmp/common/djstest-browser.js
----------------------------------------------------------------------
diff --git a/datajs/tests-tmp/common/djstest-browser.js b/datajs/tests-tmp/common/djstest-browser.js
deleted file mode 100644
index 14e5401..0000000
--- a/datajs/tests-tmp/common/djstest-browser.js
+++ /dev/null
@@ -1,142 +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.
- */
-
-
-// Because this code contains a init function to be useable directly inside the browser as well as in nodejs
-// we define the @namespace djstest here instead of the a @module name djstest
-
-/** Create namespace djstest in window.djstest when this file is loaded as java script by the browser
- * @namespace djstest
- */
-
-if (typeof window !== 'undefined') {
- //expose to browsers window object
- window.djstest = window.djstest || {};
- init(window.djstest);
-} else {
- //expose in commonjs style
- module.exports = init();
-}
-
-
-function init (parent) {
- djstest = parent || {};
-
- // Initialize indexedDB if the window object is available
- djstest.indexedDB = window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB || window.indexedDB;
-
- /** Cleans all the test data saved in the IndexedDb database.
- * @param {Array} storeNames - Array of store objects with a property that is the name of the store
- * @param {Function} done - Callback function
- */
- djstest.cleanStoreOnIndexedDb = function (storeObjects, done) {
- var IDBTransaction = window.IDBTransaction || window.webkitIDBTransaction || {};
-
- function deleteObjectStores(db) {
- for ( var i = 0 ; i < db.objectStoreNames.length ; i ++) {
- db.deleteObjectStore(db.objectStoreNames[i]);
- }
- }
- var job;
-
- if (djstest.indexedDB) {
- job = new djstest.Job();
- for ( var i = 0 ; i < storeObjects.length ; i ++) {
- storeObject = storeObjects[i];
- job.queue((function (storeObject) {
- return function (success, fail) {
- var dbname = "_datajs_" + storeObject.name;
- var request = djstest.indexedDB.open(dbname);
- request.onsuccess = function (event) {
- var db = request.result;
-
- if ("setVersion" in db) {
- var versionRequest = db.setVersion("0.1");
- versionRequest.onsuccess = function (event) {
- var transaction = versionRequest.transaction;
- transaction.oncomplete = function () {
- db.close();
- success();
- };
- deleteObjectStores(db);
- };
- versionRequest.onerror = function (e) {
- djstest.fail("Error on cleanup - code: " + e.code + " name: " + e.name + "message: " + message);
- fail();
- };
- return;
- }
-
- // new api cleanup
- db.close();
- var deleteRequest = djstest.indexedDB.deleteDatabase(dbname);
- deleteRequest.onsuccess = function (event) {
- djstest.log("djstest indexeddb cleanup - deleted database " + dbname);
- success();
- };
- deleteRequest.onerror = function (e) {
- djstest.fail("djstest indexeddb cleanup - error deleting database " + dbname);
- fail();
- };
- djstest.log("djstest indexeddb cleanup - requested deletion of database " + dbname);
- };
-
- request.onerror = function (e) {
- djstest.fail(e.code + ": " + e.message);
- };
- };
- })(storeObject));
- }
- }
-
- if (job) {
- job.run(function (succeeded) {
- if (!succeeded) {
- djstest.fail("cleanup job failed");
- }
- done();
- });
- }
- else {
- done();
- }
- };
-
-
- // Disable caching to ensure that every test-related AJAX request is actually being sent,
- // and set up a default error handler
- if (typeof window !== undefined) {
- $.ajaxSetup({
- cache: false,
- error: function (jqXHR, textStatus, errorThrown) {
- // Work around bug in IE-Mobile on Windows Phone 7
- if (jqXHR.status !== 1223) {
- var err = {
- status: jqXHR.status,
- statusText: jqXHR.statusText,
- responseText: jqXHR.responseText
- };
- djstest.fail("AJAX request failed with: " + djstest.toString(err));
- }
- djstest.done();
- }
- });
- }
- return djstest;
-}