Author: lryan
Date: Wed Mar 18 23:41:15 2009
New Revision: 755785

URL: http://svn.apache.org/viewvc?rev=755785&view=rev
Log:
More missing osapi files. Sorry Bob

Added:
    incubator/shindig/trunk/features/bin/
    incubator/shindig/trunk/features/bin/runner.sh
    
incubator/shindig/trunk/features/src/test/javascript/features/osapi.activities/
    
incubator/shindig/trunk/features/src/test/javascript/features/osapi.activities/activitiestest.js
    incubator/shindig/trunk/features/src/test/javascript/features/osapi.appdata/
    
incubator/shindig/trunk/features/src/test/javascript/features/osapi.appdata/appdatatest.js
    incubator/shindig/trunk/features/src/test/javascript/features/osapi.base/
    
incubator/shindig/trunk/features/src/test/javascript/features/osapi.base/batchtest.js
    incubator/shindig/trunk/features/src/test/javascript/features/osapi.people/
    
incubator/shindig/trunk/features/src/test/javascript/features/osapi.people/peopletest.js

Added: incubator/shindig/trunk/features/bin/runner.sh
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/features/bin/runner.sh?rev=755785&view=auto
==============================================================================
--- incubator/shindig/trunk/features/bin/runner.sh (added)
+++ incubator/shindig/trunk/features/bin/runner.sh Wed Mar 18 23:41:15 2009
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+# This script is designed to be run from the features module root directory.
+# It's very simple; feel free to make it more robust.
+
+java -cp ./bin/js.jar org.mozilla.javascript.tools.shell.Main 
src/test/javascript/features/alltests.js BatchTest ActivitiesTest PeopleTest 
AppdataTest

Added: 
incubator/shindig/trunk/features/src/test/javascript/features/osapi.activities/activitiestest.js
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/features/src/test/javascript/features/osapi.activities/activitiestest.js?rev=755785&view=auto
==============================================================================
--- 
incubator/shindig/trunk/features/src/test/javascript/features/osapi.activities/activitiestest.js
 (added)
+++ 
incubator/shindig/trunk/features/src/test/javascript/features/osapi.activities/activitiestest.js
 Wed Mar 18 23:41:15 2009
@@ -0,0 +1,237 @@
+/*
+ * 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 ActivitiesTest(name) {
+  TestCase.call(this, name);
+};
+
+ActivitiesTest.inherits(TestCase);
+
+ActivitiesTest.prototype.setUp = function() {
+  shindig = shindig || {};
+  shindig.auth = {};
+  shindig.auth.getSecurityToken = function() {
+    return 'dsjk452487sdf7sdf865%&^*&^8cjhsdf';
+  };
+
+  gadgets.config.init({ "osapi.base" : {
+      "rpcUrl" : "http://%host%/social"}
+  });
+};
+
+ActivitiesTest.prototype.tearDown = function() {
+  shindig.auth = undefined;
+};
+
+ActivitiesTest.prototype.testJsonBuilding = function() {
+  var getFn = osapi.activities.get({ userId : '@viewer', groupId : '@self'});
+  this.assertRequestPropertiesForService(getFn);
+
+  var expectedJson = [{ method : 'activities.get',
+    params : {
+      groupId : '@self',
+      userId : ['@viewer'],
+      appId : '@app'
+    }
+  }];
+  this.assertEquals('Json for request params should match', expectedJson, 
getFn.json());
+
+  var argsInCallToMakeNonProxiedRequest;
+  var oldMakeRequest = gadgets.io.makeNonProxiedRequest;
+  try {
+
+    gadgets.io.makeNonProxiedRequest = function(url, callback, params, 
contentType) {
+      argsInCallToMakeNonProxiedRequest = { url : url, 
+                 callback :callback, 
+                 params :params, 
+                 contentType : contentType};
+    };
+
+    getFn.execute(function() {});
+    this.assertArgsToMakeNonProxiedRequest(argsInCallToMakeNonProxiedRequest, 
expectedJson);
+  } finally {
+    gadgets.io.makeNonProxiedRequest = oldMakeRequest;
+  }
+};
+
+ActivitiesTest.prototype.testGetViewerActivities = function() {
+  var that = this;
+  var getVieweractivitiesFn = osapi.activities.get({ userId : '@viewer', 
groupId : '@self'});
+  this.assertRequestPropertiesForService(getVieweractivitiesFn);
+
+  var expectedJson = [{ method : "activities.get",
+    params : { userId : ['@viewer'],
+      groupId : '@self',
+      appId : '@app'
+    }
+  }];
+  this.assertEquals("Json for request params should match", expectedJson,
+      getVieweractivitiesFn.json());
+
+   var mockActivityResult = { data :
+      [{data: 
+      {list: 
+         [{title:"yellow",userId:"john.doe",id:"1",body:"what a color!"}], 
+         totalResults :1, startIndex:0}}], 
+         errors : []};
+
+  var inspectableCallback = makeInspectableCallback(function (response) {
+    that.assertTrue("callback from execute should have gotten a response", 
response);
+    that.assertFalse("should not be an error in callback response", 
response.error);
+    that.assertEquals("Should have one entry", 1, response.length);
+    that.assertEquals("Should match title of activity", "yellow", 
response[0].title);
+  });
+
+
+  var oldMakeRequest = gadgets.io.makeNonProxiedRequest;
+  try {
+    gadgets.io.makeNonProxiedRequest = function(url, callback2, params, 
contentType) {
+      callback2(mockActivityResult);
+    };
+    getVieweractivitiesFn.execute(inspectableCallback.callback);
+    this.assertTrue("should have called the callback", 
inspectableCallback.wasCalled());
+  } finally {
+    gadgets.io.makeNonProxiedHttpRequest = oldMakeRequest;
+  }
+};
+
+ActivitiesTest.prototype.testGetEmptyActivitiesUsesDefaults = function() {
+  var that = this;
+  var getVieweractivitiesFn = osapi.activities.get();
+  this.assertRequestPropertiesForService(getVieweractivitiesFn);
+
+  var expectedJson = [{ method : "activities.get",
+    params : { userId : ['@viewer'],
+      groupId : '@self',
+      appId : '@app'
+    }
+  }];
+  this.assertEquals("Json for request params should match", expectedJson,
+      getVieweractivitiesFn.json());
+
+   var mockActivityResult = { data :
+      [{data: 
+      {list: 
+         [{title:"yellow",userId:"john.doe",id:"1",body:"what a color!"}],
+         totalResults :1, startIndex:0}}], 
+         errors : []};
+
+  var inspectableCallback = makeInspectableCallback(function (response) {
+    that.assertTrue("callback from execute should have gotten a response", 
response);
+    that.assertFalse("should not be an error in callback response", 
response.error);
+    that.assertEquals("Should have one entry", 1, response.length);
+    that.assertEquals("Should match title of activity", "yellow", 
response[0].title);
+  });
+
+  var oldMakeRequest = gadgets.io.makeNonProxiedRequest;
+  try {
+    gadgets.io.makeNonProxiedRequest = function(url, callback2, params, 
contentType) {
+      callback2(mockActivityResult);
+    };
+    getVieweractivitiesFn.execute(inspectableCallback.callback);
+    this.assertTrue("should have called the callback", 
inspectableCallback.wasCalled());
+  } finally {
+    gadgets.io.makeNonProxiedHttpRequest = oldMakeRequest;
+  }
+};
+
+ActivitiesTest.prototype.testGetViewerFriendsActivities = function() {
+  var that = this;
+  var getViewerFriendActivitiesFn = osapi.activities.get({ userId : '@viewer',
+    groupId : '@friends'});
+  this.assertRequestPropertiesForService(getViewerFriendActivitiesFn);
+
+  var expectedJson = [{ method : "activities.get",
+    params : { userId : ['@viewer'],
+      groupId : '@friends',
+      appId : '@app'}
+  }];
+  this.assertEquals("Json for request params should match", expectedJson,
+      getViewerFriendActivitiesFn.json());
+
+  var mockActivitiesResult = { data :
+      [{data: 
+      {list: 
+         [{title:"yellow",userId:"john.doe",id:"1",body:"what a color!"}, 
+          {title:"Your New Activity",id:"1234396143857", body:"Blah Blah"}],
+          totalResults:2,startIndex:0}}],
+          errors : []};
+
+  var inspectableCallback = makeInspectableCallback(function (response) {
+    that.assertTrue("callback from execute should have gotten a response", 
response);
+    that.assertFalse("should not be an error in callback response", 
response.error);
+    that.assertEquals("Should have two activities", 2, response.length);
+    that.assertEquals("Should match title of activity", "yellow", 
response[0].title);
+    that.assertEquals("Should match title of activity", "Your New Activity", 
response[1].title);
+  });
+
+  var oldMakeRequest = gadgets.io.makeNonProxiedRequest;
+  try {
+    gadgets.io.makeNonProxiedRequest = function(url, callback2, params, 
contentType) {
+      callback2(mockActivitiesResult);
+    };
+    getViewerFriendActivitiesFn.execute(inspectableCallback.callback);
+    this.assertTrue("should have called the callback", 
inspectableCallback.wasCalled());
+  } finally {
+    gadgets.io.makeNonProxiedHttpRequest = oldMakeRequest;
+  }
+};
+
+ActivitiesTest.prototype.testCreateActivity = function() {
+  var that = this;
+  var createActivityFn = osapi.activities.create({ userId : '@viewer',
+    activity : { title : "New Activity", body : "Blah blah blah." }});
+  this.assertRequestPropertiesForService(createActivityFn);
+
+  var expectedJson = [{ method : "activities.create",
+    params : { userId : ['@viewer'],
+      groupId : '@self',
+      appId : '@app',
+      activity : { title : "New Activity", body : "Blah blah blah."}}
+  }];
+  this.assertEquals("Json for request params should match", expectedJson,
+      createActivityFn.json());
+
+  var mockActivityResult = { data : [{data: {}}], errors : []};
+
+  var inspectableCallback = makeInspectableCallback(function (response) {
+    that.assertTrue("callback from execute should have gotten a response", 
response);
+    that.assertFalse("should not be an error in callback response", 
response.error);
+    that.assertEquals("Should have no activities", undefined, response.length);
+  });
+
+  var oldMakeRequest = gadgets.io.makeNonProxiedRequest;
+  try {
+    gadgets.io.makeNonProxiedRequest = function(url, callback2, params, 
contentType) {
+      callback2(mockActivityResult);
+    };
+    createActivityFn.execute(inspectableCallback.callback);
+    this.assertTrue("should have called the callback", 
inspectableCallback.wasCalled());
+  } finally {
+    gadgets.io.makeNonProxiedHttpRequest = oldMakeRequest;
+  }
+
+};
+
+
+function ActivitiesTestSuite() {
+  TestSuite.call(this, 'ActivitiesTestSuite');
+  this.addTestSuite(ActivitiesTest);
+}
+
+ActivitiesTestSuite.inherits(TestSuite);

Added: 
incubator/shindig/trunk/features/src/test/javascript/features/osapi.appdata/appdatatest.js
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/features/src/test/javascript/features/osapi.appdata/appdatatest.js?rev=755785&view=auto
==============================================================================
--- 
incubator/shindig/trunk/features/src/test/javascript/features/osapi.appdata/appdatatest.js
 (added)
+++ 
incubator/shindig/trunk/features/src/test/javascript/features/osapi.appdata/appdatatest.js
 Wed Mar 18 23:41:15 2009
@@ -0,0 +1,191 @@
+/*
+ * 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 AppdataTest(name) {
+  TestCase.call(this, name);
+};
+
+AppdataTest.inherits(TestCase);
+
+AppdataTest.prototype.setUp = function() {
+  shindig = shindig || {};
+  shindig.auth = {};
+  shindig.auth.getSecurityToken = function() {
+    return 'dsjk452487sdf7sdf865%&^*&^8cjhsdf';
+  };
+
+  gadgets.config.init({ "osapi.base" : {
+      "rpcUrl" : "http://%host%/social"}
+  });
+};
+
+AppdataTest.prototype.tearDown = function() {
+  shindig.auth = undefined;
+};
+
+AppdataTest.prototype.testJsonBuilding = function() {
+  var getFn = osapi.appdata.get({ userId : '@viewer', keys : ['nonexistent']});
+  this.assertRequestPropertiesForService(getFn);
+
+  var expectedJson = [{ method : 'appdata.get',
+    params : {
+      groupId : '@self',
+      userId : ['@viewer'],
+      appId : '@app',
+      fields : ['nonexistent']
+    }
+  }];
+  this.assertEquals('Json for request params should match', expectedJson, 
getFn.json());
+
+  var argsInCallToMakeNonProxiedRequest;
+  var oldMakeRequest = gadgets.io.makeNonProxiedRequest;
+  try {
+
+    gadgets.io.makeNonProxiedRequest = function(url, callback, params, 
contentType) {
+      argsInCallToMakeNonProxiedRequest = { url : url, callback : callback, 
params : params,
+        contentType : contentType};
+    };
+
+    getFn.execute(function() {});
+    this.assertArgsToMakeNonProxiedRequest(argsInCallToMakeNonProxiedRequest, 
expectedJson);
+  } finally {
+    gadgets.io.makeNonProxiedRequest = oldMakeRequest;
+  }
+};
+
+AppdataTest.prototype.testGetAppdata = function() {
+  var that = this;
+  var getAppdata = osapi.appdata.get({ userId : '@viewer', keys : ['gift']});
+  this.assertRequestPropertiesForService(getAppdata);
+
+  var expectedJson = [{ method : "appdata.get",
+    params : { userId : ['@viewer'],
+      groupId : '@self',
+      appId : '@app',
+      fields : ['gift']}
+  }];
+  this.assertEquals("Json for request params should match", expectedJson, 
getAppdata.json());
+
+   var mockActivityResult = { data :    
+      [{data:
+        {"john.doe":{"gift":"Ferrari"}}}],
+     errors : []};
+
+  var inspectableCallback = makeInspectableCallback(function (response) {
+    that.assertTrue("callback from execute should have gotten a response", 
response);
+    that.assertFalse("should not be an error in callback response", 
response.error);
+    var entry = response["john.doe"];
+    that.assertTrue("Should have an entry for userid", entry)
+    that.assertEquals("Should match appdata set", 'Ferrari', entry["gift"]);
+  });
+
+  var oldMakeRequest = gadgets.io.makeNonProxiedRequest;
+  try {
+    gadgets.io.makeNonProxiedRequest = function(url, callback2, params, 
contentType) {
+      callback2(mockActivityResult);
+    };
+    getAppdata.execute(inspectableCallback.callback);
+    this.assertTrue("should have called the callback", 
inspectableCallback.wasCalled());
+  } finally {
+    gadgets.io.makeNonProxiedHttpRequest = oldMakeRequest;
+  }
+};
+
+AppdataTest.prototype.testDeleteAppdata = function() {
+  var that = this;
+  var getAppdata = osapi.appdata.deleteData({ userId : '@viewer', keys : 
['gift']});
+  this.assertRequestPropertiesForService(getAppdata);
+
+  var expectedJson = [{ method : "appdata.delete",
+    params : { userId : ['@viewer'],
+      groupId : '@self',
+      appId : '@app', 
+      fields : ['gift']}
+  }];
+  this.assertEquals("Json for request params should match", expectedJson, 
getAppdata.json());
+
+  var mockAppdataResult = { data :
+      [{data: 
+        {}}],
+    errors : []};
+
+  var inspectableCallback = makeInspectableCallback(function (response) {
+    that.assertTrue("callback from execute should have gotten a response", 
response);
+    that.assertFalse("should not be an error in callback response", 
response.error);
+    that.assertEquals("Should have no appdata", undefined, response.length);
+  });
+
+  var oldMakeRequest = gadgets.io.makeNonProxiedRequest;
+  try {
+    gadgets.io.makeNonProxiedRequest = function(url, callback2, params, 
contentType) {
+      callback2(mockAppdataResult);
+    };
+    getAppdata.execute(inspectableCallback.callback);
+    this.assertTrue("should have called the callback", 
inspectableCallback.wasCalled());
+  } finally {
+    gadgets.io.makeNonProxiedHttpRequest = oldMakeRequest;
+  }
+
+};
+
+AppdataTest.prototype.testUpdate = function() {
+  var that = this;
+  var createActivityFn = osapi.appdata.update({ userId : '@viewer',
+    data: {gifts: 'Ferrari'}});
+  this.assertRequestPropertiesForService(createActivityFn);
+
+  var expectedJson = [{ method : "appdata.update",
+    params : { userId : ['@viewer'],
+      groupId : '@self',
+      appId : '@app',
+      data: {gifts: 'Ferrari'},
+      fields:[]}
+  }];
+  this.assertEquals("Json for request params should match", expectedJson, 
createActivityFn.json());
+
+  var mockActivityResult = { data :
+      [{data:
+        {}}],
+    errors : []};
+
+  var inspectableCallback = makeInspectableCallback(function (response) {
+    that.assertTrue("callback from execute should have gotten a response", 
response);
+    that.assertFalse("should not be an error in callback response", 
response.error);
+    that.assertEquals("Should have no appdata", undefined, response.length);
+  });
+
+  var oldMakeRequest = gadgets.io.makeNonProxiedRequest;
+  try {
+    gadgets.io.makeNonProxiedRequest = function(url, callback2, params, 
contentType) {
+      callback2(mockActivityResult);
+    };
+    createActivityFn.execute(inspectableCallback.callback);
+    this.assertTrue("should have called the callback", 
inspectableCallback.wasCalled());
+  } finally {
+    gadgets.io.makeNonProxiedHttpRequest = oldMakeRequest;
+  }
+
+};
+
+
+function AppdataTestSuite() {
+  TestSuite.call(this, 'AppdataTestSuite');
+  this.addTestSuite(AppdataTest);
+}
+
+AppdataTestSuite.inherits(TestSuite);

Added: 
incubator/shindig/trunk/features/src/test/javascript/features/osapi.base/batchtest.js
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/features/src/test/javascript/features/osapi.base/batchtest.js?rev=755785&view=auto
==============================================================================
--- 
incubator/shindig/trunk/features/src/test/javascript/features/osapi.base/batchtest.js
 (added)
+++ 
incubator/shindig/trunk/features/src/test/javascript/features/osapi.base/batchtest.js
 Wed Mar 18 23:41:15 2009
@@ -0,0 +1,167 @@
+/*
+ * 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 BatchTest(name) {
+  TestCase.call(this, name);
+};
+
+BatchTest.inherits(TestCase);
+
+BatchTest.prototype.setUp = function() {
+  shindig = shindig || {};
+  shindig.auth = {};
+  shindig.auth.getSecurityToken =  function() {
+    return 'dsjk452487sdf7sdf865%&^*&^8cjhsdf';
+  };
+
+   gadgets.config.init({ "osapi.base" : {
+      "rpcUrl" : "http://%host%/social"}
+  });
+};
+
+BatchTest.prototype.tearDown = function() {
+  shindig.auth = undefined;
+};
+
+BatchTest.prototype.testAddAndExecuteOneRequests = function() {
+  var batch = osapi.newBatch();
+  this.assertBatchMembers(batch);
+
+  batch.add('friends', osapi.people.getViewerFriends());
+
+  var expectedJson = [{method:"people.get",params:
+    {userId:["@viewer"],groupId:"@friends",fields:["id","displayName"]},
+      id:"friends"}
+    ];
+
+  var argsInCallToMakeNonProxiedRequest;
+  var oldMakeRequest = gadgets.io.makeNonProxiedRequest;
+  try {
+    gadgets.io.makeNonProxiedRequest = function(url, callback, params, 
contentType) {
+      argsInCallToMakeNonProxiedRequest = { url : url, callback : callback, 
params : params,
+        contentType : contentType};
+    };
+    batch.execute(function() {});
+    this.assertArgsToMakeNonProxiedRequest(argsInCallToMakeNonProxiedRequest, 
expectedJson);
+  } finally {
+    gadgets.io.makeNonProxiedRequest = oldMakeRequest;
+  }
+};
+
+BatchTest.prototype.testAddAndExecuteTwoRequests = function() {
+  var batch = osapi.newBatch();
+  this.assertBatchMembers(batch);
+
+  batch.add('friends', osapi.people.getViewerFriends()).
+      add('activities', osapi.activities.get());
+
+  var expectedJson = [{method:"people.get",params:
+    {userId:["@viewer"],groupId:"@friends",fields:["id","displayName"]},
+      id:"friends"},
+    {method:"activities.get",params:
+      {userId:["@viewer"],groupId:"@self",appId:"@app"},id:"activities"}
+    ];
+
+  var argsInCallToMakeNonProxiedRequest;
+  var oldMakeRequest = gadgets.io.makeNonProxiedRequest;
+  try {
+    gadgets.io.makeNonProxiedRequest = function(url, callback, params, 
contentType) {
+      argsInCallToMakeNonProxiedRequest = { url : url, callback : callback, 
params : params,
+        contentType : contentType};
+    };
+    batch.execute(function() {});
+    this.assertArgsToMakeNonProxiedRequest(argsInCallToMakeNonProxiedRequest, 
expectedJson);
+  } finally {
+    gadgets.io.makeNonProxiedRequest = oldMakeRequest;
+  }
+};
+
+BatchTest.prototype.testAddAndExecuteMixedJsonAndMakeRequest = function() {
+  var that = this;
+  var batch = osapi.newBatch();
+  this.assertBatchMembers(batch);
+
+  batch.add('friends', osapi.people.getViewerFriends()).
+      add('makerequest', osapi.makeRequest('http://www.google.com', {}));
+
+  var expectedJson = [{method:"people.get",params:
+    {userId:["@viewer"],groupId:"@friends",fields:["id","displayName"]},
+      id:"friends"}];
+
+  var argsInCallToMakeNonProxiedRequest, argsInCallToMakeRequest;
+  var oldMakeNonProxiedRequest = gadgets.io.makeNonProxiedRequest;
+  var oldMakeRequest = gadgets.io.makeRequest;
+  
+  try {
+    gadgets.io.makeNonProxiedRequest = function(url, callback, params, 
contentType) {
+      argsInCallToMakeNonProxiedRequest = { url : url, callback : callback, 
params : params,
+        contentType : contentType};
+    };
+    gadgets.io.makeRequest = function(url, makeRequestCallback, options) {
+      argsInCallToMakeRequest = { url : url, callback : makeRequestCallback, 
options : options};
+    };
+
+    batch.execute(function(data) {
+      that.assertTrue("There is a response", data);
+    });
+
+    this.assertArgsToMakeNonProxiedRequest(argsInCallToMakeNonProxiedRequest, 
expectedJson);
+    this.assertArgsToMakeRequest(argsInCallToMakeRequest);
+  } finally {
+    gadgets.io.makeNonProxiedRequest = oldMakeNonProxiedRequest;
+    gadgets.io.makeRequest = oldMakeRequest;
+  }
+};
+
+BatchTest.prototype.testEmptyBatch = function() {
+  var batch = osapi.newBatch();
+  this.assertBatchMembers(batch);
+
+  var oldTimeout = window.setTimeout;
+  try {
+    window.setTimeout = function(fn, time) { fn.call()};
+
+    var that = this;
+    batch.execute(function(data) {
+      that.assertTrue("Data should be returned", data);
+      that.assertTrue("Data should be empty", data.length === undefined);
+    });
+  } finally {
+    window.setTimeout = oldTimeout;
+  }
+};
+
+/**
+ * Checks to see if generated batch function has the correct members. 
+ *
+ * @param fn (Function) The function which should have these properties
+ */
+BatchTest.prototype.assertBatchMembers = function(fn) {
+  this.assertTrue('Should have produced a batch', fn !== undefined);
+  this.assertTrue('Should have an execute method', fn.execute);
+  this.assertTrue('Should have an add method', fn.add);
+};
+
+
+
+function BatchTestSuite() {
+  TestSuite.call(this, 'BatchTestSuite');
+  this.addTestSuite(BatchTest);
+}
+
+BatchTestSuite.inherits(TestSuite);

Added: 
incubator/shindig/trunk/features/src/test/javascript/features/osapi.people/peopletest.js
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/features/src/test/javascript/features/osapi.people/peopletest.js?rev=755785&view=auto
==============================================================================
--- 
incubator/shindig/trunk/features/src/test/javascript/features/osapi.people/peopletest.js
 (added)
+++ 
incubator/shindig/trunk/features/src/test/javascript/features/osapi.people/peopletest.js
 Wed Mar 18 23:41:15 2009
@@ -0,0 +1,185 @@
+/*
+ * 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 PeopleTest(name) {
+  TestCase.call(this, name);
+};
+
+PeopleTest.inherits(TestCase);
+
+PeopleTest.prototype.setUp = function() {
+  shindig = shindig || {};
+  shindig.auth = {};
+  shindig.auth.getSecurityToken = function() {
+    return 'dsjk452487sdf7sdf865%&^*&^8cjhsdf';
+  };
+
+};
+
+PeopleTest.prototype.tearDown = function() {
+  shindig.auth = undefined;
+};
+
+PeopleTest.prototype.testJsonBuilding = function() {
+  var getViewerFn = osapi.people.getViewer();
+  this.assertRequestPropertiesForService(getViewerFn);
+
+  var expectedJson = [{ method : 'people.get',
+    params : {
+      groupId : '@self',
+      userId : ['@viewer'],
+      fields : ['id', 'displayName'] } }];
+  this.assertEquals('Json for request params should match', expectedJson, 
getViewerFn.json());
+
+  var argsInCallToMakeNonProxiedRequest;
+  var oldMakeRequest = gadgets.io.makeNonProxiedRequest;
+  try {
+
+    gadgets.io.makeNonProxiedRequest = function(url, callback, params, 
contentType) {
+      argsInCallToMakeNonProxiedRequest = { url : url, callback : callback, 
params : params,
+        contentType : contentType};
+    };
+
+    getViewerFn.execute(function() {
+    });
+    this.assertArgsToMakeNonProxiedRequest(argsInCallToMakeNonProxiedRequest, 
expectedJson);
+  } finally {
+    gadgets.io.makeNonProxiedRequest = oldMakeRequest;
+  }
+};
+
+PeopleTest.prototype.testGetViewerResponse = function() {
+  var that = this;
+  var getViewerFn = osapi.people.getViewer();
+  this.assertRequestPropertiesForService(getViewerFn);
+
+  var expectedJson = [{ method : "people.get",
+    params : { userId : ['@viewer'],
+      groupId : '@self',
+      fields : ['id', 'displayName'] } }];
+  this.assertEquals("Json for request params should match", expectedJson, 
getViewerFn.json());
+
+  var mockPersonResult = { data : [{
+    data:{
+      id:'5551212',
+      isViewer:true, name:{familyName:"Evans",givenName:"Bob"}, isOwner:true, 
displayName:"Bob Evans"
+    }
+  }], errors : []};
+
+  var inspectableCallback = makeInspectableCallback(function (response) {
+    that.assertTrue("callback from execute should have gotten a response", 
response);
+    that.assertFalse("should not be an error in callback response", 
response.error);
+    that.assertEquals("Ids should match", "5551212", response.id);
+    that.assertEquals("Displayname should match", "Bob Evans", 
response.displayName);
+  });
+
+  var oldMakeRequest = gadgets.io.makeNonProxiedRequest;
+  try {
+    gadgets.io.makeNonProxiedRequest = function(url, callback2, params, 
contentType) {
+      callback2(mockPersonResult);
+    };
+    getViewerFn.execute(inspectableCallback.callback);
+    this.assertTrue("should have called the callback", 
inspectableCallback.wasCalled());
+  } finally {
+    gadgets.io.makeNonProxiedHttpRequest = oldMakeRequest;
+  }
+};
+
+PeopleTest.prototype.testGetViewerFriendsResponse = function() {
+  var that = this;
+  var getViewerFn = osapi.people.getViewerFriends();
+  this.assertRequestPropertiesForService(getViewerFn);
+
+  var expectedJson = [{ method : "people.get",
+    params : { userId : ['@viewer'],
+      groupId : '@friends',
+      fields : ['id', 'displayName'] } }];
+  this.assertEquals("Json for request params should match", expectedJson, 
getViewerFn.json());
+
+  var mockPeopleResult = { data :
+      [{data : {
+        startIndex:0,
+        totalResults:2,
+        list :
+            [ {id:"5551212", isViewer:false,
+                name:{formatted:"Bob Evans"}, isOwner:false, displayName:"Bob 
Evans"},
+              {id:"5551213", isViewer:false,
+                name : { formatted: "John Smith"}, isOwner:false, displayName 
: "John Smith"}]}}], errors : []};
+
+  var inspectableCallback = makeInspectableCallback(function (response) {
+    that.assertTrue("callback from execute should have gotten a response", 
response);
+    that.assertFalse("should not be an error in callback response", 
response.error);
+    that.assertEquals("DisplayName 1 should match", "Bob Evans", 
response[0].displayName);
+    that.assertEquals("DisplayName 2 should match", "John Smith", 
response[1].displayName);
+  });
+
+  var oldMakeRequest = gadgets.io.makeNonProxiedRequest;
+  try {
+    gadgets.io.makeNonProxiedRequest = function(url, callback2, params, 
contentType) {
+      callback2(mockPeopleResult);
+    };
+    getViewerFn.execute(inspectableCallback.callback);
+    this.assertTrue("should have called the callback", 
inspectableCallback.wasCalled());
+  } finally {
+    gadgets.io.makeNonProxiedHttpRequest = oldMakeRequest;
+  }
+
+};
+
+// test error states
+// response for badrequest, unknown person id
+//
+
+PeopleTest.prototype.testGetUnknownUserIdErrorResponse = function() {
+  var that = this;
+  var getViewerFn = osapi.people.get({ userId : 'fake.id'});
+  this.assertRequestPropertiesForService(getViewerFn);
+
+  var expectedJson = [{ method : "people.get",
+    params : { userId : ['fake.id'],
+      groupId : '@self',
+      fields : ['id', 'displayName'] } }];
+  this.assertEquals("Json for request params should match", expectedJson, 
getViewerFn.json());
+
+  var mockPersonResult = { data : [{"error":{"code":400,"message":"badRequest: 
Person not found"}}],
+    errors : []};
+
+  var inspectableCallback = makeInspectableCallback(function (response) {
+    that.assertTrue("callback from execute should have gotten a response", 
response);
+    that.assertTrue("should be an error in callback response", response.error);
+    that.assertEquals("Error code should match", "badRequest", 
response.error.code);
+    that.assertEquals("Error message should match", "badRequest: Person not 
found", response.error.message);
+  });
+
+  var oldMakeRequest = gadgets.io.makeNonProxiedRequest;
+  try {
+    gadgets.io.makeNonProxiedRequest = function(url, callback2, params, 
contentType) {
+      callback2(mockPersonResult);
+    };
+    getViewerFn.execute(inspectableCallback.callback);
+    this.assertTrue("should have called the callback", 
inspectableCallback.wasCalled());
+  } finally {
+    gadgets.io.makeNonProxiedHttpRequest = oldMakeRequest;
+  }
+};
+
+function PeopleTestSuite() {
+  TestSuite.call(this, 'PeopleTestSuite');
+  this.addTestSuite(PeopleTest);
+}
+
+PeopleTestSuite.inherits(TestSuite);


Reply via email to