Added: incubator/shindig/trunk/features/src/test/javascript/features/osapi/jsonrpctransporttest.js URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/features/src/test/javascript/features/osapi/jsonrpctransporttest.js?rev=782823&view=auto ============================================================================== --- incubator/shindig/trunk/features/src/test/javascript/features/osapi/jsonrpctransporttest.js (added) +++ incubator/shindig/trunk/features/src/test/javascript/features/osapi/jsonrpctransporttest.js Mon Jun 8 23:21:36 2009 @@ -0,0 +1,422 @@ +/* + * 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 JsonRpcTransportTest(name) { + TestCase.call(this, name); +}; + +JsonRpcTransportTest.inherits(TestCase); + +var lastXhr = {}; + +JsonRpcTransportTest.prototype.dummyXhr = function(url, callback, params, contentType) { + lastXhr.url = url; + lastXhr.callback = callback; + lastXhr.params = params; + lastXhr.contentType = contentType; + callback(lastXhr.result); +}; + + +JsonRpcTransportTest.prototype.setUp = function() { + shindig = shindig || {}; + shindig.auth = {}; + shindig.auth.getSecurityToken = function() { + return 'dsjk452487sdf7sdf865%&^*&^8cjhsdf'; + }; + + gadgets.io._makeNonProxiedRequest = gadgets.io.makeNonProxiedRequest; + gadgets.io.makeNonProxiedRequest = this.dummyXhr; + lastXhr = {}; + gadgets.config.init({ "osapi.services" : { + "http://%host%/social/rpc" : ["system.listMethods", "people.get", "activities.get", + "activities.create", "appdata.get", "appdata.update", "appdata.delete"] } + }); + + window._setTimeout = window.setTimeout; + window.setTimeout = function(fn, time) { fn.call()}; + +}; + +JsonRpcTransportTest.prototype.tearDown = function() { + shindig.auth = undefined; + gadgets.io.makeNonProxiedRequest = gadgets.io._makeNonProxiedRequest; + window.setTimeout = window._setTimeout; +}; + +JsonRpcTransportTest.prototype.testJsonBuilding = function() { + var getFn = osapi.activities.get({ userId : '@viewer', groupId : '@self'}); + this.assertRequestPropertiesForService(getFn); + + var expectedJson = [{ method : 'activities.get', id : "activities.get", + params : { + groupId : '@self', + userId : '@viewer' + } + }]; + + lastXhr.result = {data : [{ id : "activities.get", result : {}}], errors : []}; + + getFn.execute(function() {}); + this.assertArgsToMakeNonProxiedRequest(lastXhr, expectedJson); +}; + +JsonRpcTransportTest.prototype.testPluralGet = function() { + var getVieweractivitiesFn = osapi.activities.get({ userId : '@viewer', groupId : '@self'}); + this.assertRequestPropertiesForService(getVieweractivitiesFn); + + var expectedJson = [{ method : "activities.get", + id : "activities.get", + params : { userId : '@viewer', + groupId : '@self' + } + }]; + + lastXhr.result = { data : + [{id : "activities.get", + data: + {list: + [{title:"yellow",userId:"john.doe",id:"1",body:"what a color!"}], + totalResults :1, startIndex:0}}], + errors : []}; + + var that = this; + 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.list.length); + that.assertEquals("Should match title of activity", "yellow", response.list[0].title); + }); + + + getVieweractivitiesFn.execute(inspectableCallback.callback); + this.assertArgsToMakeNonProxiedRequest(lastXhr, expectedJson); + this.assertTrue("should have called the callback", inspectableCallback.wasCalled()); +}; + +JsonRpcTransportTest.prototype.testNoParamGetsUsesDefaults = function() { + var getVieweractivitiesFn = osapi.activities.get(); + this.assertRequestPropertiesForService(getVieweractivitiesFn); + + var expectedJson = [{ method : "activities.get", + id : "activities.get", + params : { userId : '@viewer', + groupId : '@self' + } + }]; + + lastXhr.result = { data : + [{id : "activities.get", + data: + {list: + [{title:"yellow",userId:"john.doe",id:"1",body:"what a color!"}], + totalResults :1, startIndex:0}}], + errors : []}; + + var that = this; + 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.list.length); + that.assertEquals("Should match title of activity", "yellow", response.list[0].title); + }); + + getVieweractivitiesFn.execute(inspectableCallback.callback); + this.assertArgsToMakeNonProxiedRequest(lastXhr, expectedJson); + this.assertTrue("should have called the callback", inspectableCallback.wasCalled()); +}; + +JsonRpcTransportTest.prototype.testNonDefaultGroupGet = function() { + var getViewerFriendActivitiesFn = osapi.activities.get({ userId : '@viewer', + groupId : '@friends'}); + this.assertRequestPropertiesForService(getViewerFriendActivitiesFn); + + var expectedJson = [{ method : "activities.get", + id : "activities.get", + params : { userId : '@viewer', + groupId : '@friends'} + }]; + + lastXhr.result = { data : + [{id : "activities.get", + 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 that = this; + 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.list.length); + that.assertEquals("Should match title of activity", "yellow", response.list[0].title); + that.assertEquals("Should match title of activity", "Your New Activity", + response.list[1].title); + }); + + getViewerFriendActivitiesFn.execute(inspectableCallback.callback); + this.assertArgsToMakeNonProxiedRequest(lastXhr, expectedJson); + this.assertTrue("should have called the callback", inspectableCallback.wasCalled()); +}; + +JsonRpcTransportTest.prototype.testCreate = function() { + var createActivityFn = osapi.activities.create({ userId : '@viewer', + activity : { title : "New Activity", body : "Blah blah blah." }}); + this.assertRequestPropertiesForService(createActivityFn); + + var expectedJson = [{ method : "activities.create", + id : "activities.create", + params : { userId : '@viewer', + groupId : '@self', + activity : { title : "New Activity", body : "Blah blah blah."}} + }]; + + lastXhr.result = { data : [{id : "activities.create", data: {}}], errors : []}; + + var that = this; + 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); + }); + + createActivityFn.execute(inspectableCallback.callback); + this.assertArgsToMakeNonProxiedRequest(lastXhr, expectedJson); + this.assertTrue("should have called the callback", inspectableCallback.wasCalled()); +}; + + +function JsonRpcTransportTestSuite() { + TestSuite.call(this, 'JsonRpcTransportTestSuite'); + this.addTestSuite(JsonRpcTransportTest); +} + +JsonRpcTransportTestSuite.inherits(TestSuite); +/* + * 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 JsonRpcTransportTest(name) { + TestCase.call(this, name); +}; + +JsonRpcTransportTest.inherits(TestCase); + +var lastXhr = {}; + +JsonRpcTransportTest.prototype.dummyXhr = function(url, callback, params, contentType) { + lastXhr.url = url; + lastXhr.callback = callback; + lastXhr.params = params; + lastXhr.contentType = contentType; + callback(lastXhr.result); +}; + + +JsonRpcTransportTest.prototype.setUp = function() { + shindig = shindig || {}; + shindig.auth = {}; + shindig.auth.getSecurityToken = function() { + return 'dsjk452487sdf7sdf865%&^*&^8cjhsdf'; + }; + + gadgets.io._makeNonProxiedRequest = gadgets.io.makeNonProxiedRequest; + gadgets.io.makeNonProxiedRequest = this.dummyXhr; + lastXhr = {}; + gadgets.config.init({ "osapi.services" : { + "http://%host%/social/rpc" : ["system.listMethods", "people.get", "activities.get", + "activities.create", "appdata.get", "appdata.update", "appdata.delete"] } + }); + + window._setTimeout = window.setTimeout; + window.setTimeout = function(fn, time) { fn.call()}; + +}; + +JsonRpcTransportTest.prototype.tearDown = function() { + shindig.auth = undefined; + gadgets.io.makeNonProxiedRequest = gadgets.io._makeNonProxiedRequest; + window.setTimeout = window._setTimeout; +}; + +JsonRpcTransportTest.prototype.testJsonBuilding = function() { + var getFn = osapi.activities.get({ userId : '@viewer', groupId : '@self'}); + this.assertRequestPropertiesForService(getFn); + + var expectedJson = [{ method : 'activities.get', id : "activities.get", + params : { + groupId : '@self', + userId : '@viewer' + } + }]; + + lastXhr.result = {data : [{ id : "activities.get", result : {}}], errors : []}; + + getFn.execute(function() {}); + this.assertArgsToMakeNonProxiedRequest(lastXhr, expectedJson); +}; + +JsonRpcTransportTest.prototype.testPluralGet = function() { + var getVieweractivitiesFn = osapi.activities.get({ userId : '@viewer', groupId : '@self'}); + this.assertRequestPropertiesForService(getVieweractivitiesFn); + + var expectedJson = [{ method : "activities.get", + id : "activities.get", + params : { userId : '@viewer', + groupId : '@self' + } + }]; + + lastXhr.result = { data : + [{id : "activities.get", + data: + {list: + [{title:"yellow",userId:"john.doe",id:"1",body:"what a color!"}], + totalResults :1, startIndex:0}}], + errors : []}; + + var that = this; + 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.list.length); + that.assertEquals("Should match title of activity", "yellow", response.list[0].title); + }); + + + getVieweractivitiesFn.execute(inspectableCallback.callback); + this.assertArgsToMakeNonProxiedRequest(lastXhr, expectedJson); + this.assertTrue("should have called the callback", inspectableCallback.wasCalled()); +}; + +JsonRpcTransportTest.prototype.testNoParamGetsUsesDefaults = function() { + var getVieweractivitiesFn = osapi.activities.get(); + this.assertRequestPropertiesForService(getVieweractivitiesFn); + + var expectedJson = [{ method : "activities.get", + id : "activities.get", + params : { userId : '@viewer', + groupId : '@self' + } + }]; + + lastXhr.result = { data : + [{id : "activities.get", + data: + {list: + [{title:"yellow",userId:"john.doe",id:"1",body:"what a color!"}], + totalResults :1, startIndex:0}}], + errors : []}; + + var that = this; + 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.list.length); + that.assertEquals("Should match title of activity", "yellow", response.list[0].title); + }); + + getVieweractivitiesFn.execute(inspectableCallback.callback); + this.assertArgsToMakeNonProxiedRequest(lastXhr, expectedJson); + this.assertTrue("should have called the callback", inspectableCallback.wasCalled()); +}; + +JsonRpcTransportTest.prototype.testNonDefaultGroupGet = function() { + var getViewerFriendActivitiesFn = osapi.activities.get({ userId : '@viewer', + groupId : '@friends'}); + this.assertRequestPropertiesForService(getViewerFriendActivitiesFn); + + var expectedJson = [{ method : "activities.get", + id : "activities.get", + params : { userId : '@viewer', + groupId : '@friends'} + }]; + + lastXhr.result = { data : + [{id : "activities.get", + 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 that = this; + 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.list.length); + that.assertEquals("Should match title of activity", "yellow", response.list[0].title); + that.assertEquals("Should match title of activity", "Your New Activity", + response.list[1].title); + }); + + getViewerFriendActivitiesFn.execute(inspectableCallback.callback); + this.assertArgsToMakeNonProxiedRequest(lastXhr, expectedJson); + this.assertTrue("should have called the callback", inspectableCallback.wasCalled()); +}; + +JsonRpcTransportTest.prototype.testCreate = function() { + var createActivityFn = osapi.activities.create({ userId : '@viewer', + activity : { title : "New Activity", body : "Blah blah blah." }}); + this.assertRequestPropertiesForService(createActivityFn); + + var expectedJson = [{ method : "activities.create", + id : "activities.create", + params : { userId : '@viewer', + groupId : '@self', + activity : { title : "New Activity", body : "Blah blah blah."}} + }]; + + lastXhr.result = { data : [{id : "activities.create", data: {}}], errors : []}; + + var that = this; + 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); + }); + + createActivityFn.execute(inspectableCallback.callback); + this.assertArgsToMakeNonProxiedRequest(lastXhr, expectedJson); + this.assertTrue("should have called the callback", inspectableCallback.wasCalled()); +}; + + +function JsonRpcTransportTestSuite() { + TestSuite.call(this, 'JsonRpcTransportTestSuite'); + this.addTestSuite(JsonRpcTransportTest); +} + +JsonRpcTransportTestSuite.inherits(TestSuite);
Modified: incubator/shindig/trunk/features/src/test/javascript/features/osapi/osapitest.js URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/features/src/test/javascript/features/osapi/osapitest.js?rev=782823&r1=782822&r2=782823&view=diff ============================================================================== --- incubator/shindig/trunk/features/src/test/javascript/features/osapi/osapitest.js (original) +++ incubator/shindig/trunk/features/src/test/javascript/features/osapi/osapitest.js Mon Jun 8 23:21:36 2009 @@ -22,70 +22,28 @@ OsapiTest.inherits(TestCase); OsapiTest.prototype.setUp = function() { - shindig = shindig || {}; - shindig.auth = {}; - shindig.auth.getSecurityToken = function() { - return 'dsjk452487sdf7sdf865%&^*&^8cjhsdf'; - }; - - OsapiTest.formerPeople = osapi.people; - osapi.people = undefined; - - gadgets.config.init({ "osapi.services" : { - "http://%host%/social/rpc" : ["system.listMethods", "people.get", "activities.get", - "activities.create", "appdata.get", "appdata.update", "appdata.delete"] } - }); - + window._setTimeout = window.setTimeout; + window.setTimeout = function() {}; }; OsapiTest.prototype.tearDown = function() { - shindig.auth = undefined; - if (OsapiTest.formerPeople) { - osapi.people = OsapiTest.formerPeople; - } + window.setTimeout = window._setTimeout; }; -function debug(obj) { - for (var o in obj) if (obj.hasOwnProperty(o)) { - java.lang.System.out.println(o + " = " + obj[o]); - debug(obj[o]); - } -} - -OsapiTest.prototype.testGen = function() { - var that = this; - var getViewerFn = osapi.people.get(); - that.assertTrue(getViewerFn !== undefined) -// debug(getViewerFn); - this.assertRequestPropertiesForService(getViewerFn); - var expectedJson = [{ method : "people.get", - params : { userId : ['@viewer'], - groupId : '@self' } }]; - 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; +OsapiTest.prototype.testCall = function() { + var transport = {}; + osapi._registerMethod("test.method", transport); + var transportCalled = false; + transport.execute = function(requests, callback) { + transportCalled = true; + callback([{id:"test.method",result:{a:"b"}}]); } + var callbackCalled = false; + osapi.test.method({}).execute(function(result) { + callbackCalled = true; + }); + this.assertTrue("osapi transport correctly called", transportCalled); + this.assertTrue("osapi callback correctly called", callbackCalled); }; Modified: incubator/shindig/trunk/features/src/test/javascript/features/osapi/peopletest.js URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/features/src/test/javascript/features/osapi/peopletest.js?rev=782823&r1=782822&r2=782823&view=diff ============================================================================== --- incubator/shindig/trunk/features/src/test/javascript/features/osapi/peopletest.js (original) +++ incubator/shindig/trunk/features/src/test/javascript/features/osapi/peopletest.js Mon Jun 8 23:21:36 2009 @@ -1,189 +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 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.formerPeople = osapi.people; - osapi.people = undefined; - - gadgets.config.init({"osapi.services" : { - "http://%host%/social/rpc" : ["system.listMethods", "people.get", "activities.get", - "activities.create", "appdata.get", "appdata.update", "appdata.delete"] } - }); - -}; - -PeopleTest.prototype.tearDown = function() { - shindig.auth = undefined; - if (PeopleTest.formerPeople) { - osapi.people = PeopleTest.formerPeople; - } -}; - -PeopleTest.prototype.testJsonBuilding = function() { - var getViewerFn = osapi.people.getViewer(); - this.assertRequestPropertiesForService(getViewerFn); - - var expectedJson = [ { method : 'people.get', params : { groupId : '@self', userId : [ '@viewer' ] } } ]; - 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'} }]; - 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' } }]; - 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'} }]; - 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); Modified: incubator/shindig/trunk/features/src/test/javascript/lib/testutils.js URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/features/src/test/javascript/lib/testutils.js?rev=782823&r1=782822&r2=782823&view=diff ============================================================================== --- incubator/shindig/trunk/features/src/test/javascript/lib/testutils.js (original) +++ incubator/shindig/trunk/features/src/test/javascript/lib/testutils.js Mon Jun 8 23:21:36 2009 @@ -24,7 +24,8 @@ TestCase.prototype.assertRequestPropertiesForService = function(fn) { this.assertTrue('Should have produced a result', fn); this.assertTrue('Should have an execute method', fn.execute); - this.assertTrue('Should have a json method', fn.json); + this.assertTrue('Should have a json-rpc method', !!fn.method); + this.assertTrue('Should have a json-rpc', fn.rpc); }; Modified: incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/render/DefaultServiceFetcher.java URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/render/DefaultServiceFetcher.java?rev=782823&r1=782822&r2=782823&view=diff ============================================================================== --- incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/render/DefaultServiceFetcher.java (original) +++ incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/render/DefaultServiceFetcher.java Mon Jun 8 23:21:36 2009 @@ -89,8 +89,10 @@ LinkedHashMultimap<String, String> endpointServices = LinkedHashMultimap.create(); // First check services directly declared in container config - Map<String, Object> declaredServices = containerConfig.getMap(container, OSAPI_SERVICES); - if (!declaredServices.isEmpty()) { + @SuppressWarnings("unchecked") + Map<String, Object> declaredServices = (Map<String, Object>) containerConfig.getMap(container, + GADGETS_FEATURES_CONFIG).get(OSAPI_SERVICES); + if (declaredServices != null) { for (Map.Entry<String, Object> entry : declaredServices.entrySet()) { @SuppressWarnings("unchecked") Iterable<String> entryValue = (Iterable<String>) entry.getValue(); Modified: incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/render/DefaultServiceFetcherTest.java URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/render/DefaultServiceFetcherTest.java?rev=782823&r1=782822&r2=782823&view=diff ============================================================================== --- incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/render/DefaultServiceFetcherTest.java (original) +++ incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/render/DefaultServiceFetcherTest.java Mon Jun 8 23:21:36 2009 @@ -69,7 +69,7 @@ for (String key : configuredServices.keySet()) { services.put(key, configuredServices.get(key)); } - container.put(DefaultServiceFetcher.OSAPI_SERVICES, services); + features.put(DefaultServiceFetcher.OSAPI_SERVICES, services); JSONObject endpoints = new JSONObject(); @@ -84,7 +84,9 @@ public void testReadConfigNoEndpoints() throws Exception { JSONObject config = createConfig(); - config.getJSONObject("default").remove(DefaultServiceFetcher.GADGETS_FEATURES_CONFIG); + config.getJSONObject("default"). + getJSONObject(DefaultServiceFetcher.GADGETS_FEATURES_CONFIG) + .remove(DefaultServiceFetcher.OSAPI_FEATURE_CONFIG); JsonContainerConfig containerConfig = new JsonContainerConfig(config, new Expressions(new Functions())); fetcher = new DefaultServiceFetcher(containerConfig, mockFetcher); Added: incubator/shindig/trunk/javascript/container/osapi.js URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/javascript/container/osapi.js?rev=782823&view=auto ============================================================================== --- incubator/shindig/trunk/javascript/container/osapi.js (added) +++ incubator/shindig/trunk/javascript/container/osapi.js Mon Jun 8 23:21:36 2009 @@ -0,0 +1,110 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + +/** + * @fileoverview Base OSAPI binding + */ + +var osapi = osapi || {}; + +/** + * Container-side binding for the gadgetsrpctransport used by osapi. Containers + * add services to the client-side osapi implementation by defining them in the osapi + * namespace + */ +if (gadgets && gadgets.rpc) { //Only define if gadgets rpc exists + + /** + * Dispatch a JSON-RPC batch request to services defined in the osapi namespace + * @param callbackId + * @param requests + */ + osapi._handleGadgetRpcMethod = function(requests) { + var responses = new Array(requests.length); + var callCount = 0; + var callback = this.callback; + var dummy = function(params, apiCallback) { + apiCallback({}); + }; + for (var i = 0; i < requests.length; i++) { + // Don't allow underscores in any part of the method name as a convention + // for restricted methods + var current = osapi; + if (requests[i].method.indexOf("_") == -1) { + var path = requests[i].method.split("."); + for (var j = 0; j < path.length; j++) { + if (current.hasOwnProperty(path[j])) { + current = current[path[j]]; + } else { + // No matching api + current = dummy; + break; + } + } + } else { + current = dummy; + } + + // Execute the call and latch the rpc callback until all + // complete + current(requests[i].params, function(i) { + return function(response) { + // Put back in json-rpc format + responses[i] = { id : requests[i].id, data : response}; + callCount++; + if (callCount == requests.length) { + callback(responses); + } + }; + }(i)); + } + }; + + /** + * Basic implementation of system.listMethods which can be used to introspect + * available services + * @param request + * @param callback + */ + osapi.container = {}; + osapi.container["listMethods"] = function(request, callback) { + var names = []; + recurseNames(osapi, "", 5, names) + callback(names); + }; + + /** + * Recurse the object paths to a limited depth + */ + function recurseNames(base, path, depth, accumulated) { + if (depth == 0) return; + for (var prop in base) if (base.hasOwnProperty(prop)) { + if (prop.indexOf("_") == -1) { + var type = typeof(base[prop]); + if (type == "function") { + accumulated.push(path + prop); + } else if (type == "object") { + recurseNames(base[prop], path + prop + ".", depth - 1, accumulated); + } + } + } + } + + // Register the osapi RPC dispatcher. + gadgets.rpc.register("osapi._handleGadgetRpcMethod", osapi._handleGadgetRpcMethod); +} \ No newline at end of file Modified: incubator/shindig/trunk/javascript/samplecontainer/examples/SocialHelloWorld.xml URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/javascript/samplecontainer/examples/SocialHelloWorld.xml?rev=782823&r1=782822&r2=782823&view=diff ============================================================================== --- incubator/shindig/trunk/javascript/samplecontainer/examples/SocialHelloWorld.xml (original) +++ incubator/shindig/trunk/javascript/samplecontainer/examples/SocialHelloWorld.xml Mon Jun 8 23:21:36 2009 @@ -77,7 +77,7 @@ var allPeople, viewerFriendData; function render(data) { var viewer = data.viewer; - allPeople = data.viewerFriends; + allPeople = data.viewerFriends.list; if (viewer) { allPeople.push(viewer); } Modified: incubator/shindig/trunk/javascript/samplecontainer/samplecontainer.html URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/javascript/samplecontainer/samplecontainer.html?rev=782823&r1=782822&r2=782823&view=diff ============================================================================== --- incubator/shindig/trunk/javascript/samplecontainer/samplecontainer.html (original) +++ incubator/shindig/trunk/javascript/samplecontainer/samplecontainer.html Mon Jun 8 23:21:36 2009 @@ -55,6 +55,7 @@ <script type="text/javascript" src="../container/cookies.js"></script> <script type="text/javascript" src="../container/util.js"></script> <script type="text/javascript" src="../container/gadgets.js"></script> +<script type="text/javascript" src="../container/osapi.js"></script> <script type="text/javascript" src="samplecontainer.js"></script> </head> Modified: incubator/shindig/trunk/javascript/samplecontainer/samplecontainer.js URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/javascript/samplecontainer/samplecontainer.js?rev=782823&r1=782822&r2=782823&view=diff ============================================================================== --- incubator/shindig/trunk/javascript/samplecontainer/samplecontainer.js (original) +++ incubator/shindig/trunk/javascript/samplecontainer/samplecontainer.js Mon Jun 8 23:21:36 2009 @@ -272,4 +272,20 @@ ); }; + osapi.messages = {}; + osapi.messages.requestSend = function(request, callback) { + alert("osapi.messages.requestSend called"); + callback({}); + }; + + osapi.requestShareApp = function(request, callback) { + alert("osapi.requestShareApp called"); + callback({}); + }; + + osapi.requestPermission = function(request, callback) { + alert("osapi.requestPermission called"); + callback({}); + }; + })(); Modified: incubator/shindig/trunk/site/src/site/xdoc/developers/features/index.xml URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/site/src/site/xdoc/developers/features/index.xml?rev=782823&r1=782822&r2=782823&view=diff ============================================================================== --- incubator/shindig/trunk/site/src/site/xdoc/developers/features/index.xml (original) +++ incubator/shindig/trunk/site/src/site/xdoc/developers/features/index.xml Mon Jun 8 23:21:36 2009 @@ -137,10 +137,6 @@ <td>Opensocial API.</td> </tr> <tr> - <td><a href="http://svn.apache.org/repos/asf/incubator/shindig/trunk/features/src/main/javascript/features/osapi.ui/feature.xml">osapi.ui/feature.xml</a></td> - <td>Opensocial UI API.</td> - </tr> - <tr> <td><a href="http://svn.apache.org/repos/asf/incubator/shindig/trunk/features/src/main/javascript/features/pubsub/feature.xml">pubsub/feature.xml</a></td> <td>Gadget-side PubSub library for gadget-to-gadget communication.</td> </tr>
