You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rave.apache.org by mf...@apache.org on 2012/04/13 23:43:33 UTC

svn commit: r1325972 - in /rave/trunk/rave-portal-resources/src: main/webapp/script/rave.js main/webapp/script/rave_opensocial.js test/javascript/raveOpenSocialSpec.js test/javascript/raveSpec.js

Author: mfranklin
Date: Fri Apr 13 21:43:32 2012
New Revision: 1325972

URL: http://svn.apache.org/viewvc?rev=1325972&view=rev
Log:
Created an OpenAjax 2 Hub in rave and injected into common container (Suports RAVE-102)

Modified:
    rave/trunk/rave-portal-resources/src/main/webapp/script/rave.js
    rave/trunk/rave-portal-resources/src/main/webapp/script/rave_opensocial.js
    rave/trunk/rave-portal-resources/src/test/javascript/raveOpenSocialSpec.js
    rave/trunk/rave-portal-resources/src/test/javascript/raveSpec.js

Modified: rave/trunk/rave-portal-resources/src/main/webapp/script/rave.js
URL: http://svn.apache.org/viewvc/rave/trunk/rave-portal-resources/src/main/webapp/script/rave.js?rev=1325972&r1=1325971&r2=1325972&view=diff
==============================================================================
--- rave/trunk/rave-portal-resources/src/main/webapp/script/rave.js (original)
+++ rave/trunk/rave-portal-resources/src/main/webapp/script/rave.js Fri Apr 13 21:43:32 2012
@@ -21,6 +21,7 @@ var rave = rave || (function() {
     var widgetByIdMap = {};
     var context = "";
     var clientMessages = {};
+    var openAjaxHub;
 
     /**
      * Separate sub-namespace for isolating UI functions and state management
@@ -748,6 +749,26 @@ var rave = rave || (function() {
         }
     }
 
+    function getOpenAjaxHubInstance() {
+        if(typeof openAjaxHub == "undefined" || openAjaxHub == null) {
+            openAjaxHub = new OpenAjax.hub.ManagedHub({
+                onSubscribe: function(topic, container) {
+                    log(container.getClientID() + " subscribes to this topic '" + topic + "'");
+                    return true;
+                },
+                onUnsubscribe: function(topic, container) {
+                    log(container.getClientID() + " unsubscribes from this topic '" + topic + "'");
+                    return true;
+                },
+                onPublish: function(topic, data, pcont, scont) {
+                    log(pcont.getClientID() + " publishes '" + data + "' to topic '" + topic + "' subscribed by " + scont.getClientID());
+                    return true;
+                }
+            });
+        }
+        return openAjaxHub;
+    }
+
     function initializeWidgets(widgetsByRegionIdMap) {
         //We get the widget objects in a map keyed by region ID.  The code below converts that map into a flat array
         //of widgets with all the top widgets in each region first, then the seconds widgets in each region, then the
@@ -872,6 +893,16 @@ var rave = rave || (function() {
     }
 
     /**
+     * Logs to a console object if it exists
+     * @param message the message to log
+     */
+    function log(message) {
+        if(typeof console != "undefined" && console.log) {
+            console.log(message);
+        }
+    }
+
+    /**
      * Public API
      */
     return {
@@ -1081,6 +1112,18 @@ var rave = rave || (function() {
          * @param key
          * @param message
          */
-        addClientMessage: addClientMessage
+        addClientMessage: addClientMessage,
+
+        /**
+         * Gets the singleton Managed OpenAJAX 2.0 Hub
+         */
+        getManagedHub: getOpenAjaxHubInstance,
+
+        /**
+         * Logs a message to a central logging facility (console by default)
+         *
+         * @param message the message to log
+         */
+        log: log
     }
 })();

Modified: rave/trunk/rave-portal-resources/src/main/webapp/script/rave_opensocial.js
URL: http://svn.apache.org/viewvc/rave/trunk/rave-portal-resources/src/main/webapp/script/rave_opensocial.js?rev=1325972&r1=1325971&r2=1325972&view=diff
==============================================================================
--- rave/trunk/rave-portal-resources/src/main/webapp/script/rave_opensocial.js (original)
+++ rave/trunk/rave-portal-resources/src/main/webapp/script/rave_opensocial.js Fri Apr 13 21:43:32 2012
@@ -36,6 +36,9 @@ rave.opensocial = rave.opensocial || (fu
     function initOpenSocial() {
         initContainer();
         registerRpcHooks();
+        gadgets.pubsub2router.init({
+            hub: rave.getManagedHub()
+        })
     }
 
     function initContainer() {
@@ -50,7 +53,7 @@ rave.opensocial = rave.opensocial || (fu
      * Gets the container singleton or initializes if not instantiated
      */
     function getContainer() {
-        if (!container) {
+        if (typeof container == "undefined" || container == null) {
             initContainer();
         }
         return container;
@@ -71,7 +74,6 @@ rave.opensocial = rave.opensocial || (fu
         container.rpcRegister('set_title', setTitle);
         container.rpcRegister('requestNavigateTo', requestNavigateTo);
         container.rpcRegister('set_pref', setPref);
-        //container.rpcRegister('pubsub', null);
     }
 
     /**

Modified: rave/trunk/rave-portal-resources/src/test/javascript/raveOpenSocialSpec.js
URL: http://svn.apache.org/viewvc/rave/trunk/rave-portal-resources/src/test/javascript/raveOpenSocialSpec.js?rev=1325972&r1=1325971&r2=1325972&view=diff
==============================================================================
--- rave/trunk/rave-portal-resources/src/test/javascript/raveOpenSocialSpec.js (original)
+++ rave/trunk/rave-portal-resources/src/test/javascript/raveOpenSocialSpec.js Fri Apr 13 21:43:32 2012
@@ -44,13 +44,22 @@ describe("Rave OpenSocial", function() {
                 }
             }
         };
-        gadgets = {
-            util : {
-                escapeString : function(string) {
-                    return string;
+        gadgets = (function(){
+            var pubSubArgs;
+            return {
+                util : {
+                    escapeString : function(string) {
+                        return string;
+                    }
+                },
+                pubsub2router: {
+                    init : function(args) {
+                        pubSubArgs = args;
+                    },
+                    getArgs: function() {return pubSubArgs;}
+
                 }
-            }
-        };
+        }})();
 
     });
 
@@ -67,7 +76,6 @@ describe("Rave OpenSocial", function() {
 
         it("initializes the OpenSocial container machinery", function() {
             rave.opensocial.init();
-
             expect(container.args()[0]).toEqual("/rpc");
             expect(container.args()[1]).toEqual("1");
         });

Modified: rave/trunk/rave-portal-resources/src/test/javascript/raveSpec.js
URL: http://svn.apache.org/viewvc/rave/trunk/rave-portal-resources/src/test/javascript/raveSpec.js?rev=1325972&r1=1325971&r2=1325972&view=diff
==============================================================================
--- rave/trunk/rave-portal-resources/src/test/javascript/raveSpec.js (original)
+++ rave/trunk/rave-portal-resources/src/test/javascript/raveSpec.js Fri Apr 13 21:43:32 2012
@@ -651,4 +651,71 @@ describe("Rave", function() {
             expect(mockWidget.minimizeWasCalled).toEqual(true);             
         });                    
     });
+
+    describe("log", function(){
+
+        afterEach(function() {
+           if(typeof console != "undefined") {delete console;}
+        });
+
+        it("successfully logs", function(){
+            console = (function(){
+                var messages =[];
+
+                return {
+                    log: function(message) {
+                        messages.push(message);
+                    },
+
+                    getMessages: function() {return messages;}
+                }
+            })();
+            var mess = "boo";
+            rave.log(mess);
+            expect(console.getMessages().length).toEqual(1);
+            expect(console.getMessages()[0]).toEqual(mess);
+        });
+
+        it("does not error if console doesn't exist", function(){
+            rave.log("boo");
+            expect(true).toBeTruthy();
+        });
+
+        it("does not error if console.log doesn't exist", function(){
+            console = {};
+            rave.log("boo");
+            expect(true).toBeTruthy();
+        });
+    });
+
+    describe("getManagedHub", function(){
+       OpenAjax = (function(){
+           var cArgs;
+           return{
+               hub: {
+                   ManagedHub: function(args){
+                      cArgs=args;
+                      return {
+
+                      }
+                   },
+                   getArgs: function() {return cArgs;}
+               }
+           }
+       })();
+
+       it("returns a new instance of the managed hub", function(){
+           var hub = rave.getManagedHub();
+           expect(hub).toBeDefined();
+           var hub2 = rave.getManagedHub();
+           expect(hub).toBe(hub2);
+       });
+
+        it("initializes the hub properly", function(){
+            var args = OpenAjax.hub.getArgs();
+            expect(args.onSubscribe).toBeDefined();
+            expect(args.onUnsubscribe).toBeDefined();
+            expect(args.onPublish).toBeDefined();
+        });
+    });
 });
\ No newline at end of file