rave-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jc...@apache.org
Subject svn commit: r1130698 - in /incubator/rave/trunk/rave-portal: ./ src/main/java/org/apache/rave/provider/opensocial/repository/ src/main/java/org/apache/rave/provider/opensocial/repository/impl/ src/main/java/org/apache/rave/provider/opensocial/service/ ...
Date Thu, 02 Jun 2011 18:02:59 GMT
Author: jcian
Date: Thu Jun  2 18:02:58 2011
New Revision: 1130698

URL: http://svn.apache.org/viewvc?rev=1130698&view=rev
Log:
Progress on client side support for saving user preferences (RAVE-27) -- this gets us the
metadata we need on the client side to build a dynamic form to collect the user prefs and
send them back to our REST API on the backend to be persisted.  Note that this same metadata
can/will also be used to prime the Shindig common container cache so that it doesnt need to
call for gadget metadata on every page load.  Also note that we'll want to put a caching layer
in the service layer at some point in the future since gadget metadata doesnt change very
often. 

https://issues.apache.org/jira/browse/RAVE-27

Added:
    incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/provider/opensocial/repository/
    incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/provider/opensocial/repository/GadgetMetadataRepository.java
    incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/provider/opensocial/repository/impl/
    incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/provider/opensocial/repository/impl/ShindigGadgetMetadataRepository.java
    incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/provider/opensocial/service/
    incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/provider/opensocial/service/OpenSocialService.java
    incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/provider/opensocial/service/impl/
    incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/provider/opensocial/service/impl/DefaultOpenSocialService.java
    incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/provider/opensocial/repository/
    incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/provider/opensocial/repository/ShindigGadgetMetadataRepositoryTest.java
    incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/provider/opensocial/service/
    incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/provider/opensocial/service/OpenSocialServiceTest.java
Modified:
    incubator/rave/trunk/rave-portal/pom.xml
    incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/provider/opensocial/web/renderer/OpenSocialWidgetRenderer.java
    incubator/rave/trunk/rave-portal/src/main/webapp/WEB-INF/applicationContext.xml
    incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/web/renderer/RenderServiceIntegrationTest.java
    incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/provider/opensocial/web/renderer/OpenSocialWidgetRendererTest.java

Modified: incubator/rave/trunk/rave-portal/pom.xml
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/pom.xml?rev=1130698&r1=1130697&r2=1130698&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/pom.xml (original)
+++ incubator/rave/trunk/rave-portal/pom.xml Thu Jun  2 18:02:58 2011
@@ -125,6 +125,13 @@ if needed you can specify it on the comm
 			<version>1.8.1</version>
 		</dependency>
 
+        <!-- JSON Support -->
+        <dependency>
+            <groupId>org.json</groupId>
+            <artifactId>json</artifactId>
+            <version>20090211</version>
+        </dependency>
+
         <!--Persistence-->
         <dependency>
             <groupId>org.apache.openjpa</groupId>

Added: incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/provider/opensocial/repository/GadgetMetadataRepository.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/provider/opensocial/repository/GadgetMetadataRepository.java?rev=1130698&view=auto
==============================================================================
--- incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/provider/opensocial/repository/GadgetMetadataRepository.java
(added)
+++ incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/provider/opensocial/repository/GadgetMetadataRepository.java
Thu Jun  2 18:02:58 2011
@@ -0,0 +1,30 @@
+/*
+ * 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.
+ */
+
+package org.apache.rave.provider.opensocial.repository;
+
+public interface GadgetMetadataRepository {
+    /**
+     * Fetches gadget metadata for the specified gadget URL.
+     *
+     * @param gadgetUrl The gadget to fetch metadata for.
+     * @return The raw JSON response from the Shindig metadata RPC call.
+     */
+    public String getGadgetMetadata(String gadgetUrl);
+}
\ No newline at end of file

Added: incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/provider/opensocial/repository/impl/ShindigGadgetMetadataRepository.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/provider/opensocial/repository/impl/ShindigGadgetMetadataRepository.java?rev=1130698&view=auto
==============================================================================
--- incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/provider/opensocial/repository/impl/ShindigGadgetMetadataRepository.java
(added)
+++ incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/provider/opensocial/repository/impl/ShindigGadgetMetadataRepository.java
Thu Jun  2 18:02:58 2011
@@ -0,0 +1,96 @@
+/*
+ * 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.
+ */
+
+package org.apache.rave.provider.opensocial.repository.impl;
+
+import org.apache.rave.provider.opensocial.repository.GadgetMetadataRepository;
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Repository;
+import org.springframework.web.client.RestOperations;
+
+@Repository
+public class ShindigGadgetMetadataRepository implements GadgetMetadataRepository {
+    private static Logger logger = LoggerFactory.getLogger(ShindigGadgetMetadataRepository.class);
+
+    private RestOperations restOperations;
+    private String shindigUrl;
+
+    @Autowired
+    public ShindigGadgetMetadataRepository(@Qualifier(value = "jsonStringCompatibleRestTemplate")
RestOperations restOperations,
+                                           @Value("${portal.opensocial_engine.protocol}")
String shindigProtocol,
+                                           @Value("${portal.opensocial_engine.root}") String
shindigRoot) {
+        this.restOperations = restOperations;
+        this.shindigUrl = shindigProtocol + "://" + shindigRoot + "/rpc";
+    }
+
+    @Override
+    public String getGadgetMetadata(String gadgetUrl) {
+        //generate the json request to be sent to the shindig RPC service
+        JSONArray rpcArray = new JSONArray();
+        try {
+            JSONObject fetchMetadataRpcOperation = new JSONObject()
+                    .put("method", "gadgets.metadata")
+                    .put("id", "gadgets.metadata")
+                    .put("params", new JSONObject()
+                            .put("container", "default")
+
+                            .append("ids", gadgetUrl)
+
+                            .append("fields", "iframeUrl")
+                            .append("fields", "modulePrefs.*")
+                            .append("fields", "needsTokenRefresh")
+                            .append("fields", "userPrefs.*")
+                            .append("fields", "views.preferredHeight")
+                            .append("fields", "views.preferredWidth")
+                            .append("fields", "expireTimeMs")
+                            .append("fields", "responseTimeMs")
+
+                            .put("userId", "@viewer")
+                            .put("groupId", "@self")
+                    );
+
+            rpcArray.put(fetchMetadataRpcOperation);
+        } catch (JSONException e) {
+            logger.error("Error occurred while generating data for shindig metadata call:
" + e.getMessage(), e);
+            throw new IllegalArgumentException(e.getMessage(), e);
+        }
+
+        //convert the json object to a string
+        String postData = rpcArray.toString();
+        if (logger.isDebugEnabled()) {
+            logger.debug("requestContent: " + postData);
+        }
+
+        //fire off the request and get the raw JSON back as a string
+        String responseString = restOperations.postForObject(shindigUrl, postData, String.class);
+        if (logger.isDebugEnabled()) {
+            logger.debug("shindig metadata raw response: " + responseString);
+        }
+
+        //return the raw JSON
+        return responseString;
+    }
+}
\ No newline at end of file

Added: incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/provider/opensocial/service/OpenSocialService.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/provider/opensocial/service/OpenSocialService.java?rev=1130698&view=auto
==============================================================================
--- incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/provider/opensocial/service/OpenSocialService.java
(added)
+++ incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/provider/opensocial/service/OpenSocialService.java
Thu Jun  2 18:02:58 2011
@@ -0,0 +1,30 @@
+/*
+ * 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.
+ */
+
+package org.apache.rave.provider.opensocial.service;
+
+public interface OpenSocialService {
+    /**
+     * Fetches gadget metadata for the specified gadget URL.
+     *
+     * @param gadgetUrl The gadget to fetch metadata for.
+     * @return The raw JSON response from the Shindig metadata RPC call.
+     */
+    String getGadgetMetadata(String gadgetUrl);
+}
\ No newline at end of file

Added: incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/provider/opensocial/service/impl/DefaultOpenSocialService.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/provider/opensocial/service/impl/DefaultOpenSocialService.java?rev=1130698&view=auto
==============================================================================
--- incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/provider/opensocial/service/impl/DefaultOpenSocialService.java
(added)
+++ incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/provider/opensocial/service/impl/DefaultOpenSocialService.java
Thu Jun  2 18:02:58 2011
@@ -0,0 +1,41 @@
+/*
+ * 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.
+ */
+
+package org.apache.rave.provider.opensocial.service.impl;
+
+import org.apache.rave.provider.opensocial.repository.GadgetMetadataRepository;
+import org.apache.rave.provider.opensocial.service.OpenSocialService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Service
+public class DefaultOpenSocialService implements OpenSocialService {
+    private GadgetMetadataRepository gadgetMetadataRepository;
+
+    @Autowired
+    public DefaultOpenSocialService(GadgetMetadataRepository gadgetMetadataRepository) {
+        this.gadgetMetadataRepository = gadgetMetadataRepository;
+    }
+
+    @Override
+    public String getGadgetMetadata(String gadgetUrl) {
+        //TODO -- Add caching of gadget metadata in this service layer
+        return gadgetMetadataRepository.getGadgetMetadata(gadgetUrl);
+    }
+}
\ No newline at end of file

Modified: incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/provider/opensocial/web/renderer/OpenSocialWidgetRenderer.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/provider/opensocial/web/renderer/OpenSocialWidgetRenderer.java?rev=1130698&r1=1130697&r2=1130698&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/provider/opensocial/web/renderer/OpenSocialWidgetRenderer.java
(original)
+++ incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/provider/opensocial/web/renderer/OpenSocialWidgetRenderer.java
Thu Jun  2 18:02:58 2011
@@ -23,6 +23,8 @@ import org.apache.rave.exception.NotSupp
 import org.apache.rave.portal.model.RegionWidget;
 import org.apache.rave.portal.web.renderer.RegionWidgetRenderer;
 import org.apache.rave.provider.opensocial.Constants;
+import org.apache.rave.provider.opensocial.service.OpenSocialService;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
 /**
@@ -32,15 +34,22 @@ import org.springframework.stereotype.Co
  */
 @Component
 public class OpenSocialWidgetRenderer implements RegionWidgetRenderer {
+    private OpenSocialService openSocialService;
 
-	 //Note the widgets.push() call.  This defines the widget objects, which are
+    @Autowired
+    public OpenSocialWidgetRenderer(OpenSocialService openSocialService) {
+        this.openSocialService = openSocialService;
+    }
+
+    //Note the widgets.push() call.  This defines the widget objects, which are
     //added to the widgets[] array in home.jsp.   
     private static final String IFRAME_MARKUP = "<script type=\"text/javascript\">"
+
-                                                    "widgets.push({type: '%1$s'," +
-                                                                 " regionWidgetId: %2$s,"
+
-                                                                 " widgetUrl: '%3$s', " +
-                                                                 " userPrefs: {}});" +
-                                                "</script>";
+            "widgets.push({type: '%1$s'," +
+            " regionWidgetId: %2$s," +
+            " widgetUrl: '%3$s', " +
+            " metadata: %4$s," +
+            " userPrefs: {}});" +
+            "</script>";
 
     @Override
     public String getSupportedContext() {
@@ -49,6 +58,7 @@ public class OpenSocialWidgetRenderer im
 
     /**
      * Renders a {@link org.apache.rave.portal.model.RegionWidget} as HTML markup
+     *
      * @param item RegionWidget to render
      * @return valid HTML markup
      */
@@ -58,6 +68,8 @@ public class OpenSocialWidgetRenderer im
         if (!Constants.WIDGET_TYPE.equals(type)) {
             throw new NotSupportedException("Invalid widget type passed to renderer: " +
type);
         }
-        return String.format(IFRAME_MARKUP, Constants.WIDGET_TYPE, item.getId(), item.getWidget().getUrl());
+
+        return String.format(IFRAME_MARKUP, Constants.WIDGET_TYPE, item.getId(), item.getWidget().getUrl(),
+                openSocialService.getGadgetMetadata(item.getWidget().getUrl()));
     }
-}
+}
\ No newline at end of file

Modified: incubator/rave/trunk/rave-portal/src/main/webapp/WEB-INF/applicationContext.xml
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/main/webapp/WEB-INF/applicationContext.xml?rev=1130698&r1=1130697&r2=1130698&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/src/main/webapp/WEB-INF/applicationContext.xml (original)
+++ incubator/rave/trunk/rave-portal/src/main/webapp/WEB-INF/applicationContext.xml Thu Jun
 2 18:02:58 2011
@@ -22,10 +22,20 @@
 <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:context="http://www.springframework.org/schema/context"
-       xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:tx="http://www.springframework.org/schema/tx"
-       xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
-        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
-        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
+       xmlns:mvc="http://www.springframework.org/schema/mvc"
+       xmlns:tx="http://www.springframework.org/schema/tx"
+       xmlns:oxm="http://www.springframework.org/schema/oxm"
+       xmlns:p="http://www.springframework.org/schema/p"
+       xmlns:util="http://www.springframework.org/schema/util"
+       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
+        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
+        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
+        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
+        http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm-3.0.xsd
+        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd">
+
+    <!-- make the the portal.properties props available to autowire injectors -->
+    <context:property-placeholder location="classpath:portal.properties"/>
 
     <context:component-scan base-package="org.apache.rave" annotation-config="true" />
 
@@ -66,4 +76,20 @@
             </map>
         </property>
     </bean>
-</beans>
+
+    <!-- A RestTemplate instance that can be used to call a web service which expects
Content-Type and Accept headers of
+    application/json with a pre-built string of JSON data. -->
+    <bean id="jsonStringCompatibleRestTemplate" class="org.springframework.web.client.RestTemplate">
+        <property name="messageConverters">
+            <list>
+                <bean class="org.springframework.http.converter.StringHttpMessageConverter">
+                    <property name="supportedMediaTypes">
+                        <list>
+                            <util:constant static-field="org.springframework.http.MediaType.APPLICATION_JSON"/>
+                        </list>
+                    </property>
+                </bean>
+            </list>
+        </property>
+    </bean>
+</beans>
\ No newline at end of file

Modified: incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/web/renderer/RenderServiceIntegrationTest.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/web/renderer/RenderServiceIntegrationTest.java?rev=1130698&r1=1130697&r2=1130698&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/web/renderer/RenderServiceIntegrationTest.java
(original)
+++ incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/web/renderer/RenderServiceIntegrationTest.java
Thu Jun  2 18:02:58 2011
@@ -22,22 +22,42 @@ package org.apache.rave.portal.web.rende
 
 import org.apache.rave.portal.model.RegionWidget;
 import org.apache.rave.portal.model.Widget;
+import org.apache.rave.provider.opensocial.repository.impl.ShindigGadgetMetadataRepository;
+import org.junit.Before;
+import org.junit.Ignore;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.test.context.ContextConfiguration;
 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.test.util.ReflectionTestUtils;
+import org.springframework.web.client.RestOperations;
 
+import static org.easymock.EasyMock.createNiceMock;
 import static org.hamcrest.CoreMatchers.*;
 import static org.junit.Assert.assertThat;
 
 @RunWith(SpringJUnit4ClassRunner.class)
-@ContextConfiguration(locations={"file:src/main/webapp/WEB-INF/dataContext.xml", "file:src/main/webapp/WEB-INF/applicationContext.xml"})
+@ContextConfiguration(locations = {"file:src/main/webapp/WEB-INF/dataContext.xml", "file:src/main/webapp/WEB-INF/applicationContext.xml"})
 public class RenderServiceIntegrationTest {
 
     @Autowired
     private RenderService service;
 
+    @Autowired
+    private ShindigGadgetMetadataRepository metadataRepository;
+
+    private RestOperations restOperations;
+
+    @Before
+    public void setup() {
+        restOperations = createNiceMock(RestOperations.class);
+
+        //Replace the real restOperations instance with a mock -- otherwise the call for
gadget metadata would fail since
+        //we don't have a shindig server available to hit.
+        ReflectionTestUtils.setField(metadataRepository, "restOperations", restOperations);
+    }
+
     @Test
     public void supportedWidgets() {
         assertThat(service.getSupportedWidgetTypes().size(), is(equalTo(2)));

Added: incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/provider/opensocial/repository/ShindigGadgetMetadataRepositoryTest.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/provider/opensocial/repository/ShindigGadgetMetadataRepositoryTest.java?rev=1130698&view=auto
==============================================================================
--- incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/provider/opensocial/repository/ShindigGadgetMetadataRepositoryTest.java
(added)
+++ incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/provider/opensocial/repository/ShindigGadgetMetadataRepositoryTest.java
Thu Jun  2 18:02:58 2011
@@ -0,0 +1,72 @@
+/*
+ * 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.
+ */
+
+package org.apache.rave.provider.opensocial.repository;
+
+import org.apache.rave.provider.opensocial.repository.impl.ShindigGadgetMetadataRepository;
+import org.junit.Before;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.web.client.RestOperations;
+
+import static org.easymock.EasyMock.*;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.sameInstance;
+import static org.junit.Assert.assertThat;
+
+public class ShindigGadgetMetadataRepositoryTest {
+    private ShindigGadgetMetadataRepository gadgetMetadataRepository;
+    private RestOperations restOperations;
+
+    @Autowired
+    @Value("${portal.opensocial_engine.protocol}")
+    String shindigProtocol;
+
+    @Autowired
+    @Value("${portal.opensocial_engine.root}")
+    String shindigRoot;
+
+    private String shindigUrl;
+
+    private static final String VALID_GADGET_URL = "http://www.example.com/gadget.xml";
+    private static final String VALID_SHINDIG_METADATA_RPC_REQUEST = "[{\"id\":\"gadgets.metadata\","
+
+            "\"method\":\"gadgets.metadata\",\"params\":{\"groupId\":\"@self\"," +
+            "\"ids\":[\"http://www.example.com/gadget.xml\"],\"container\":\"default\",\"userId\":\"@viewer\","
+
+            "\"fields\":[\"iframeUrl\",\"modulePrefs.*\",\"needsTokenRefresh\",\"userPrefs.*\",\"views.preferredHeight\","
+
+            "\"views.preferredWidth\",\"expireTimeMs\",\"responseTimeMs\"]}}]";
+    private static final String VALID_METADATA = "metadata";
+
+    @Before
+    public void setup() {
+        restOperations = createNiceMock(RestOperations.class);
+        gadgetMetadataRepository = new ShindigGadgetMetadataRepository(restOperations, shindigProtocol,
shindigRoot);
+        shindigUrl = shindigProtocol + "://" + shindigRoot + "/rpc";
+    }
+
+    @Test
+    public void getGadgetMetadata() {
+        expect(restOperations.postForObject(shindigUrl, VALID_SHINDIG_METADATA_RPC_REQUEST,
String.class))
+                .andReturn(VALID_METADATA);
+        replay(restOperations);
+
+        String result = gadgetMetadataRepository.getGadgetMetadata(VALID_GADGET_URL);
+        assertThat(result, is(sameInstance(VALID_METADATA)));
+    }
+}

Added: incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/provider/opensocial/service/OpenSocialServiceTest.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/provider/opensocial/service/OpenSocialServiceTest.java?rev=1130698&view=auto
==============================================================================
--- incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/provider/opensocial/service/OpenSocialServiceTest.java
(added)
+++ incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/provider/opensocial/service/OpenSocialServiceTest.java
Thu Jun  2 18:02:58 2011
@@ -0,0 +1,53 @@
+/*
+ * 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.
+ */
+
+package org.apache.rave.provider.opensocial.service;
+
+import org.apache.rave.provider.opensocial.repository.GadgetMetadataRepository;
+import org.apache.rave.provider.opensocial.service.impl.DefaultOpenSocialService;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.easymock.EasyMock.*;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.sameInstance;
+import static org.junit.Assert.assertThat;
+
+public class OpenSocialServiceTest {
+    private OpenSocialService openSocialService;
+    private GadgetMetadataRepository gadgetMetadataRepository;
+
+    private static final String VALID_GADGET_URL = "http://example.com/gadgets/1";
+    private static final String VALID_METADATA = "metadata";
+
+    @Before
+    public void setup() {
+        gadgetMetadataRepository = createNiceMock(GadgetMetadataRepository.class);
+        openSocialService = new DefaultOpenSocialService(gadgetMetadataRepository);
+    }
+
+    @Test
+    public void getGadgetMetadata() {
+        expect(gadgetMetadataRepository.getGadgetMetadata(VALID_GADGET_URL)).andReturn(VALID_METADATA);
+        replay(gadgetMetadataRepository);
+
+        String result = openSocialService.getGadgetMetadata(VALID_GADGET_URL);
+        assertThat(result, is(sameInstance(VALID_METADATA)));
+    }
+}
\ No newline at end of file

Modified: incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/provider/opensocial/web/renderer/OpenSocialWidgetRendererTest.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/provider/opensocial/web/renderer/OpenSocialWidgetRendererTest.java?rev=1130698&r1=1130697&r2=1130698&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/provider/opensocial/web/renderer/OpenSocialWidgetRendererTest.java
(original)
+++ incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/provider/opensocial/web/renderer/OpenSocialWidgetRendererTest.java
Thu Jun  2 18:02:58 2011
@@ -24,22 +24,28 @@ import org.apache.rave.portal.model.Regi
 import org.apache.rave.portal.model.Widget;
 import org.apache.rave.portal.web.renderer.Renderer;
 import org.apache.rave.provider.opensocial.Constants;
+import org.apache.rave.provider.opensocial.service.OpenSocialService;
 import org.junit.Before;
 import org.junit.Test;
 
+import static org.easymock.EasyMock.createNiceMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
 import static org.hamcrest.CoreMatchers.equalTo;
 import static org.hamcrest.CoreMatchers.is;
 import static org.junit.Assert.assertThat;
 
-/**
- */
 public class OpenSocialWidgetRendererTest {
-
+    private OpenSocialService openSocialService;
     private Renderer<RegionWidget> renderer;
 
+    private static final String VALID_METADATA = "metadata";
+    private static final String VALID_GADGET_URL = "http://example.com/gadgets/1";
+
     @Before
     public void setup() {
-        renderer = new OpenSocialWidgetRenderer();
+        openSocialService = createNiceMock(OpenSocialService.class);
+        renderer = new OpenSocialWidgetRenderer(openSocialService);
     }
 
     @Test
@@ -49,9 +55,13 @@ public class OpenSocialWidgetRendererTes
 
     @Test
     public void render_valid() {
+        expect(openSocialService.getGadgetMetadata(VALID_GADGET_URL)).andReturn(VALID_METADATA);
+        replay(openSocialService);
+
         Widget w = new Widget();
+        w.setId(1L);
         w.setType(Constants.WIDGET_TYPE);
-        w.setUrl("http://example.com/gadgets/1");
+        w.setUrl(VALID_GADGET_URL);
         RegionWidget rw = new RegionWidget();
         rw.setId(1L);
         rw.setWidget(w);
@@ -60,6 +70,7 @@ public class OpenSocialWidgetRendererTes
         assertThat(result.matches(".*regionWidgetId[ ]*:[ ]*1,.*"), is(true));
         assertThat(result.matches(".*type[ ]*:[ ]*'OpenSocial',.*"), is(true));
         assertThat(result.matches(".*widgetUrl[ ]*:[ ]*'http://example.com/gadgets/1',.*"),
is(true));
+        assertThat(result.matches(".*metadata[ ]*:[ ]*" + VALID_METADATA + ",.*"), is(true));
     }
 
     @Test
@@ -73,6 +84,7 @@ public class OpenSocialWidgetRendererTes
         assertThat(result.matches(".*regionWidgetId[ ]*:[ ]*null,.*"), is(true));
         assertThat(result.matches(".*type[ ]*:[ ]*'OpenSocial',.*"), is(true));
         assertThat(result.matches(".*widgetUrl[ ]*:[ ]*'null',.*"), is(true));
+        assertThat(result.matches(".*metadata[ ]*:[ ]*null,.*"), is(true));
     }
 
     @Test(expected = NotSupportedException.class)
@@ -86,5 +98,4 @@ public class OpenSocialWidgetRendererTes
 
         renderer.render(rw);
     }
-
-}
+}
\ No newline at end of file



Mime
View raw message