Author: ivol37 at gmail.com
Date: Mon Nov 15 15:48:01 2010
New Revision: 427

Log:
[AMDATU-162] Added remove method to gadget management service and added 
corresponding integration test. While creating the integration test it appeared 
that there was a dependency problem with the ShindigRegistrationService which 
was independent from all other services. This included gadgets, which obviously 
depend on the availability of a gadget container. For that reason added those 
dependencies.

Added:
   
trunk/amdatu-opensocial/shindig/src/main/java/org/amdatu/opensocial/shindig/ShindigService.java
   
trunk/integration-tests/src/test/java/org/amdatu/test/integration/tests/GadgetManagementServiceTest.java
Modified:
   
trunk/amdatu-authorization/login-gadget/src/main/java/org/amdatu/authorization/login/gadget/osgi/Activator.java
   
trunk/amdatu-example/course-gadget/src/main/java/org/amdatu/example/course/gadget/osgi/Activator.java
   
trunk/amdatu-example/friends-gadget/src/main/java/org/amdatu/example/friends/gadget/osgi/Activator.java
   trunk/amdatu-opensocial/dashboard/pom.xml
   
trunk/amdatu-opensocial/dashboard/src/main/java/org/amdatu/opensocial/dashboard/osgi/Activator.java
   
trunk/amdatu-opensocial/gadgetmanagement/src/main/java/org/amdatu/opensocial/gadgetmanagement/GadgetManagement.java
   
trunk/amdatu-opensocial/gadgetmanagement/src/main/java/org/amdatu/opensocial/gadgetmanagement/service/GadgetManagementServiceImpl.java
   
trunk/amdatu-opensocial/profile/src/main/java/org/amdatu/opensocial/profile/osgi/Activator.java
   
trunk/amdatu-opensocial/shindig/src/main/java/org/amdatu/opensocial/shindig/GadgetStore.java
   
trunk/amdatu-opensocial/shindig/src/main/java/org/amdatu/opensocial/shindig/osgi/Activator.java
   
trunk/amdatu-opensocial/shindig/src/main/java/org/amdatu/opensocial/shindig/persistence/GadgetStoreImpl.java
   
trunk/amdatu-opensocial/shindig/src/main/java/org/amdatu/opensocial/shindig/service/ShindigRegistrationServiceImpl.java
   
trunk/amdatu-semanticweb/sparqlendpoint/src/main/java/org/amdatu/semanticweb/sparqlendpoint/Activator.java
   trunk/integration-tests/pom.xml
   
trunk/integration-tests/src/test/java/org/amdatu/test/integration/base/IntegrationTestBase.java

Modified: 
trunk/amdatu-authorization/login-gadget/src/main/java/org/amdatu/authorization/login/gadget/osgi/Activator.java
==============================================================================
--- 
trunk/amdatu-authorization/login-gadget/src/main/java/org/amdatu/authorization/login/gadget/osgi/Activator.java
     (original)
+++ 
trunk/amdatu-authorization/login-gadget/src/main/java/org/amdatu/authorization/login/gadget/osgi/Activator.java
     Mon Nov 15 15:48:01 2010
@@ -17,6 +17,7 @@
 package org.amdatu.authorization.login.gadget.osgi;
 
 import org.amdatu.opensocial.gadgetmanagement.GadgetManagement;
+import org.amdatu.opensocial.shindig.ShindigService;
 import org.amdatu.authorization.login.gadget.service.LoginGadgetImpl;
 import org.amdatu.authorization.login.service.LoginService;
 import org.amdatu.web.httpcontext.HttpContextServiceFactory;
@@ -47,6 +48,7 @@
             
.add(createServiceDependency().setService(GadgetManagement.class).setRequired(true))
             
.add(createServiceDependency().setService(HttpContextServiceFactory.class).setRequired(true))
             
.add(createServiceDependency().setService(LoginService.class).setRequired(true))
+            
.add(createServiceDependency().setService(ShindigService.class).setRequired(true))
             .add(createConfigurationDependency().setPid(LoginGadgetImpl.PID)));
     }
 

Modified: 
trunk/amdatu-example/course-gadget/src/main/java/org/amdatu/example/course/gadget/osgi/Activator.java
==============================================================================
--- 
trunk/amdatu-example/course-gadget/src/main/java/org/amdatu/example/course/gadget/osgi/Activator.java
       (original)
+++ 
trunk/amdatu-example/course-gadget/src/main/java/org/amdatu/example/course/gadget/osgi/Activator.java
       Mon Nov 15 15:48:01 2010
@@ -16,8 +16,9 @@
  */
 package org.amdatu.example.course.gadget.osgi;
 
-import org.amdatu.opensocial.gadgetmanagement.GadgetManagement;
 import org.amdatu.example.course.gadget.service.CourseGadgetServiceImpl;
+import org.amdatu.opensocial.gadgetmanagement.GadgetManagement;
+import org.amdatu.opensocial.shindig.ShindigService;
 import org.amdatu.web.httpcontext.HttpContextServiceFactory;
 import org.amdatu.web.httpcontext.ResourceProvider;
 import org.apache.felix.dm.Component;
@@ -45,6 +46,7 @@
                 
.add(createServiceDependency().setService(LogService.class).setRequired(true))
                 
.add(createServiceDependency().setService(GadgetManagement.class).setRequired(true))
                 
.add(createServiceDependency().setService(HttpContextServiceFactory.class).setRequired(true))
+                
.add(createServiceDependency().setService(ShindigService.class).setRequired(true))
                 
.add(createConfigurationDependency().setPid(CourseGadgetServiceImpl.PID));
         manager.add(friendsgadgetService);
     }

Modified: 
trunk/amdatu-example/friends-gadget/src/main/java/org/amdatu/example/friends/gadget/osgi/Activator.java
==============================================================================
--- 
trunk/amdatu-example/friends-gadget/src/main/java/org/amdatu/example/friends/gadget/osgi/Activator.java
     (original)
+++ 
trunk/amdatu-example/friends-gadget/src/main/java/org/amdatu/example/friends/gadget/osgi/Activator.java
     Mon Nov 15 15:48:01 2010
@@ -16,8 +16,9 @@
  */
 package org.amdatu.example.friends.gadget.osgi;
 
-import org.amdatu.opensocial.gadgetmanagement.GadgetManagement;
 import org.amdatu.example.friend.sgadget.service.FriendsGadgetServiceImpl;
+import org.amdatu.opensocial.gadgetmanagement.GadgetManagement;
+import org.amdatu.opensocial.shindig.ShindigService;
 import org.amdatu.web.httpcontext.HttpContextServiceFactory;
 import org.amdatu.web.httpcontext.ResourceProvider;
 import org.apache.felix.dm.Component;
@@ -47,6 +48,7 @@
                 
.add(createServiceDependency().setService(GadgetManagement.class).setRequired(true))
                 
.add(createServiceDependency().setService(HttpContextServiceFactory.class).setRequired(true))
                 
.add(createServiceDependency().setService(HttpService.class).setRequired(true))
+                
.add(createServiceDependency().setService(ShindigService.class).setRequired(true))
                 
.add(createConfigurationDependency().setPid(FriendsGadgetServiceImpl.PID));
         manager.add(friendsgadgetService);
     }

Modified: trunk/amdatu-opensocial/dashboard/pom.xml
==============================================================================
--- trunk/amdatu-opensocial/dashboard/pom.xml   (original)
+++ trunk/amdatu-opensocial/dashboard/pom.xml   Mon Nov 15 15:48:01 2010
@@ -20,6 +20,12 @@
       <scope>provided</scope>
       <type>bundle</type>
     </dependency>
+    <dependency>
+      <groupId>org.amdatu.opensocial</groupId>
+      <artifactId>shindig</artifactId>
+      <scope>provided</scope>
+      <type>bundle</type>
+    </dependency>    
   </dependencies>
   
   <build>

Modified: 
trunk/amdatu-opensocial/dashboard/src/main/java/org/amdatu/opensocial/dashboard/osgi/Activator.java
==============================================================================
--- 
trunk/amdatu-opensocial/dashboard/src/main/java/org/amdatu/opensocial/dashboard/osgi/Activator.java
 (original)
+++ 
trunk/amdatu-opensocial/dashboard/src/main/java/org/amdatu/opensocial/dashboard/osgi/Activator.java
 Mon Nov 15 15:48:01 2010
@@ -17,6 +17,7 @@
 package org.amdatu.opensocial.dashboard.osgi;
 
 import org.amdatu.opensocial.dashboard.service.DashboardServiceImpl;
+import org.amdatu.opensocial.shindig.ShindigService;
 import org.amdatu.web.httpcontext.HttpContextServiceFactory;
 import org.amdatu.web.httpcontext.ResourceProvider;
 import org.apache.felix.dm.DependencyActivatorBase;
@@ -44,6 +45,7 @@
                 .setImplementation(DashboardServiceImpl.class)
                 
.add(createServiceDependency().setService(LogService.class).setRequired(true))
                 
.add(createServiceDependency().setService(HttpContextServiceFactory.class).setRequired(true))
+                
.add(createServiceDependency().setService(ShindigService.class).setRequired(true))
                 
.add(createServiceDependency().setService(HttpService.class).setRequired(true)));
     }
 

Modified: 
trunk/amdatu-opensocial/gadgetmanagement/src/main/java/org/amdatu/opensocial/gadgetmanagement/GadgetManagement.java
==============================================================================
--- 
trunk/amdatu-opensocial/gadgetmanagement/src/main/java/org/amdatu/opensocial/gadgetmanagement/GadgetManagement.java
 (original)
+++ 
trunk/amdatu-opensocial/gadgetmanagement/src/main/java/org/amdatu/opensocial/gadgetmanagement/GadgetManagement.java
 Mon Nov 15 15:48:01 2010
@@ -55,4 +55,11 @@
      * @return The gadget category
      */
     GadgetCategory getCategory(String categoryId);
+    
+    /**
+     * Removes a gadget from the gadget store.
+     * @param gadget The gadget to remove. Only the URL property is used to 
find the gadget to remove.
+     * @return <code>true</code> if removing the gagdget succeeded, 
<code>false</code> otherwise
+     */
+    boolean removeGadget(GadgetDefinition gadget);
 }

Modified: 
trunk/amdatu-opensocial/gadgetmanagement/src/main/java/org/amdatu/opensocial/gadgetmanagement/service/GadgetManagementServiceImpl.java
==============================================================================
--- 
trunk/amdatu-opensocial/gadgetmanagement/src/main/java/org/amdatu/opensocial/gadgetmanagement/service/GadgetManagementServiceImpl.java
      (original)
+++ 
trunk/amdatu-opensocial/gadgetmanagement/src/main/java/org/amdatu/opensocial/gadgetmanagement/service/GadgetManagementServiceImpl.java
      Mon Nov 15 15:48:01 2010
@@ -143,6 +143,11 @@
     public boolean addGadget(GadgetDefinition gadget) {
         return m_gadgetStore.addGadget(gadget);
     }
+    
+    // Removes a gadget from the store
+    public boolean removeGadget(GadgetDefinition gadget) {
+        return m_gadgetStore.removeGadget(gadget);
+    }
 
     public GadgetDefinition[] getGadgets() {
         return m_gadgetStore.getGadgets();

Modified: 
trunk/amdatu-opensocial/profile/src/main/java/org/amdatu/opensocial/profile/osgi/Activator.java
==============================================================================
--- 
trunk/amdatu-opensocial/profile/src/main/java/org/amdatu/opensocial/profile/osgi/Activator.java
     (original)
+++ 
trunk/amdatu-opensocial/profile/src/main/java/org/amdatu/opensocial/profile/osgi/Activator.java
     Mon Nov 15 15:48:01 2010
@@ -21,6 +21,7 @@
 import org.amdatu.opensocial.profile.PersonService;
 import org.amdatu.opensocial.profile.service.FriendColumnFamilyProvider;
 import org.amdatu.opensocial.profile.service.PersonServiceImpl;
+import org.amdatu.opensocial.shindig.ShindigService;
 import org.apache.felix.dm.DependencyActivatorBase;
 import org.apache.felix.dm.DependencyManager;
 import org.osgi.framework.BundleContext;
@@ -45,6 +46,7 @@
                 .setInterface(new String[]{PersonService.class.getName(), 
org.apache.shindig.social.opensocial.spi.PersonService.class.getName()}, null)
                 
.add(createServiceDependency().setService(LogService.class).setRequired(true))
                 
.add(createServiceDependency().setService(ColumnFamilyAvailable.class, 
filter).setRequired(true))
+                
.add(createServiceDependency().setService(ShindigService.class).setRequired(true))
                 
.add(createServiceDependency().setService(UserAdmin.class).setRequired(true)));
     }
     

Modified: 
trunk/amdatu-opensocial/shindig/src/main/java/org/amdatu/opensocial/shindig/GadgetStore.java
==============================================================================
--- 
trunk/amdatu-opensocial/shindig/src/main/java/org/amdatu/opensocial/shindig/GadgetStore.java
        (original)
+++ 
trunk/amdatu-opensocial/shindig/src/main/java/org/amdatu/opensocial/shindig/GadgetStore.java
        Mon Nov 15 15:48:01 2010
@@ -27,12 +27,23 @@
     final String CF_GADGETCATEGORY = "GadgetCategory";
     
     /**
-     * Adds a gadget to the store
-     * @param gadget
-     * @return
+     * Adds a gadget to the gadget store. If an entry with the same gadget URL 
already exists,
+     * it is overwritten by this gadget definition.
+     * @param gadget The definition of the gadget to add
+     * @return <code>true</code> if adding the gadget succeeded, 
<code>false</code> otherwise
      */
     boolean addGadget(GadgetDefinition gadget);
     
+    /**
+     * Removes the gadget from the gadget store with the same URL as defined 
by the gadget
+     * definition. If no gadget was contained by the gadget store that matches 
this URL, 
+     * false is returned. If the gadget was removed, true is returned.
+     * @param gadget The definition of he gadget to remove
+     * @return <code>false</code> if the gadget removal failed or no gadget 
with the specified
+     * URL exists.
+     */
+    boolean removeGadget(GadgetDefinition gadget);
+    
     GadgetDefinition[] getGadgets();
     
     GadgetCategory getCategory(String categoryId);
@@ -46,4 +57,6 @@
     Map<String, String> getGadgetCategories() throws CassandraException;
     
     BasicOAuthStoreConsumerKeyAndSecret getDefaultKey();
+    
+    
 }

Added: 
trunk/amdatu-opensocial/shindig/src/main/java/org/amdatu/opensocial/shindig/ShindigService.java
==============================================================================
--- (empty file)
+++ 
trunk/amdatu-opensocial/shindig/src/main/java/org/amdatu/opensocial/shindig/ShindigService.java
     Mon Nov 15 15:48:01 2010
@@ -0,0 +1,26 @@
+/*
+    Copyright (C) 2010 Amdatu.org
+
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.amdatu.opensocial.shindig;
+
+/**
+ * This interface represents the Shindig application. It sole purpose is to 
facilitate creating 
+ * service dependencies on the availability of the Shindig application. For 
that reason it has no
+ * methods.
+ * @author ivol
+ */
+public interface ShindigService {
+}

Modified: 
trunk/amdatu-opensocial/shindig/src/main/java/org/amdatu/opensocial/shindig/osgi/Activator.java
==============================================================================
--- 
trunk/amdatu-opensocial/shindig/src/main/java/org/amdatu/opensocial/shindig/osgi/Activator.java
     (original)
+++ 
trunk/amdatu-opensocial/shindig/src/main/java/org/amdatu/opensocial/shindig/osgi/Activator.java
     Mon Nov 15 15:48:01 2010
@@ -19,10 +19,9 @@
 import org.amdatu.core.cassandra.listener.ColumnFamilyAvailable;
 import org.amdatu.core.cassandra.listener.ColumnFamilyProvider;
 import 
org.amdatu.core.cassandra.persistencemanager.CassandraPersistenceManager;
-import org.amdatu.web.httpcontext.HttpContextServiceFactory;
-import org.amdatu.web.httpcontext.ResourceProvider;
 import org.amdatu.opensocial.shindig.GadgetStore;
 import org.amdatu.opensocial.shindig.OAuthModule;
+import org.amdatu.opensocial.shindig.ShindigService;
 import org.amdatu.opensocial.shindig.SocialApiModule;
 import org.amdatu.opensocial.shindig.module.ConfigurationAdminGuiceModule;
 import org.amdatu.opensocial.shindig.module.OAuthModuleImpl;
@@ -34,6 +33,8 @@
 import org.amdatu.opensocial.shindig.service.GuiceInjectorService;
 import org.amdatu.opensocial.shindig.service.GuiceInjectorServiceImpl;
 import org.amdatu.opensocial.shindig.service.ShindigRegistrationServiceImpl;
+import org.amdatu.web.httpcontext.HttpContextServiceFactory;
+import org.amdatu.web.httpcontext.ResourceProvider;
 import org.apache.felix.dm.DependencyActivatorBase;
 import org.apache.felix.dm.DependencyManager;
 import org.apache.shindig.gadgets.oauth.OAuthStore;
@@ -129,7 +130,7 @@
         manager.add( 
                 createComponent()
                 .setImplementation(ShindigRegistrationServiceImpl.class)
-                .setInterface(ResourceProvider.class.getName(), null)
+                .setInterface(new String[]{ResourceProvider.class.getName(), 
ShindigService.class.getName()}, null)
                 
.add(createServiceDependency().setService(LogService.class).setRequired(true))
                 
.add(createServiceDependency().setService(GuiceInjectorService.class).setRequired(true))
                 
.add(createServiceDependency().setService(SocialApiModule.class).setRequired(true))

Modified: 
trunk/amdatu-opensocial/shindig/src/main/java/org/amdatu/opensocial/shindig/persistence/GadgetStoreImpl.java
==============================================================================
--- 
trunk/amdatu-opensocial/shindig/src/main/java/org/amdatu/opensocial/shindig/persistence/GadgetStoreImpl.java
        (original)
+++ 
trunk/amdatu-opensocial/shindig/src/main/java/org/amdatu/opensocial/shindig/persistence/GadgetStoreImpl.java
        Mon Nov 15 15:48:01 2010
@@ -268,6 +268,20 @@
         }
         return null;
     }
+    
+    public boolean removeGadget(GadgetDefinition gadget) {
+        try {
+            m_cassandraLock.writeLock().lock();
+            String rowKey = gadget.getUrl();
+            m_pm.deleteRow(CF_GADGET, rowKey);
+            return true;
+        } catch (CassandraException e) {
+            m_logService.log(LogService.LOG_ERROR, "Could not persist gadget 
definition", e);
+        } finally {
+            m_cassandraLock.writeLock().unlock();
+        }
+        return false;
+    }
 
     private GadgetDefinition[] orderGadgets(GadgetDefinition[] gadgets) {
         Comparator<GadgetDefinition> comparator = new 
Comparator<GadgetDefinition>() {

Modified: 
trunk/amdatu-opensocial/shindig/src/main/java/org/amdatu/opensocial/shindig/service/ShindigRegistrationServiceImpl.java
==============================================================================
--- 
trunk/amdatu-opensocial/shindig/src/main/java/org/amdatu/opensocial/shindig/service/ShindigRegistrationServiceImpl.java
     (original)
+++ 
trunk/amdatu-opensocial/shindig/src/main/java/org/amdatu/opensocial/shindig/service/ShindigRegistrationServiceImpl.java
     Mon Nov 15 15:48:01 2010
@@ -31,10 +31,11 @@
 import javax.servlet.Filter;
 import javax.servlet.Servlet;
 
-import org.amdatu.web.httpcontext.HttpContextServiceFactory;
-import org.amdatu.web.httpcontext.ResourceProvider;
+import org.amdatu.opensocial.shindig.ShindigService;
 import org.amdatu.opensocial.shindig.oauth.AmdatuOAuthServlet;
 import org.amdatu.opensocial.shindig.osgi.Activator;
+import org.amdatu.web.httpcontext.HttpContextServiceFactory;
+import org.amdatu.web.httpcontext.ResourceProvider;
 import org.apache.felix.dm.Component;
 import org.apache.felix.dm.DependencyManager;
 import org.apache.shindig.auth.AuthenticationServletFilter;
@@ -58,7 +59,7 @@
  * 
  * @author ivol
  */
-public class ShindigRegistrationServiceImpl implements ResourceProvider {
+public class ShindigRegistrationServiceImpl implements ShindigService, 
ResourceProvider {
 
     // Base URLs for filters, servlets and static resources
     private static final String GADGETS_BASE = "/gadgets";

Modified: 
trunk/amdatu-semanticweb/sparqlendpoint/src/main/java/org/amdatu/semanticweb/sparqlendpoint/Activator.java
==============================================================================
--- 
trunk/amdatu-semanticweb/sparqlendpoint/src/main/java/org/amdatu/semanticweb/sparqlendpoint/Activator.java
  (original)
+++ 
trunk/amdatu-semanticweb/sparqlendpoint/src/main/java/org/amdatu/semanticweb/sparqlendpoint/Activator.java
  Mon Nov 15 15:48:01 2010
@@ -17,6 +17,7 @@
 package org.amdatu.semanticweb.sparqlendpoint;
 
 import org.amdatu.opensocial.gadgetmanagement.GadgetManagement;
+import org.amdatu.opensocial.shindig.ShindigService;
 import org.amdatu.semanticweb.sparqlendpoint.service.SPARQLEndpointServiceImpl;
 import org.amdatu.web.httpcontext.HttpContextServiceFactory;
 import org.amdatu.web.httpcontext.ResourceProvider;
@@ -45,6 +46,7 @@
                 
.add(createServiceDependency().setService(GadgetManagement.class).setRequired(true))
                 
.add(createServiceDependency().setService(SesameService.class).setRequired(true))
                 
.add(createServiceDependency().setService(HttpContextServiceFactory.class).setRequired(true))
+                
.add(createServiceDependency().setService(ShindigService.class).setRequired(true))
                 
.add(createConfigurationDependency().setPid(SPARQLEndpointServiceImpl.PID)));
     }
 

Modified: trunk/integration-tests/pom.xml
==============================================================================
--- trunk/integration-tests/pom.xml     (original)
+++ trunk/integration-tests/pom.xml     Mon Nov 15 15:48:01 2010
@@ -84,7 +84,7 @@
         <version>${platform.version}</version>
         <scope>provided</scope>
         <type>bundle</type>
-      </dependency>
+      </dependency>    
     </dependencies>
   </dependencyManagement>
 
@@ -293,6 +293,18 @@
       <version>${pax.useradmin.version}</version>
       <scope>provided</scope>
     </dependency>
+      <dependency>
+        <groupId>org.amdatu.opensocial</groupId>
+        <artifactId>gadgetmanagement</artifactId>
+        <version>${platform.version}</version>
+        <scope>provided</scope>
+      </dependency>
+      <dependency>
+        <groupId>org.amdatu.authorization.login</groupId>
+        <artifactId>service</artifactId>
+        <version>${platform.version}</version>
+        <scope>provided</scope>
+      </dependency>  
   </dependencies>
 
   <build>

Modified: 
trunk/integration-tests/src/test/java/org/amdatu/test/integration/base/IntegrationTestBase.java
==============================================================================
--- 
trunk/integration-tests/src/test/java/org/amdatu/test/integration/base/IntegrationTestBase.java
     (original)
+++ 
trunk/integration-tests/src/test/java/org/amdatu/test/integration/base/IntegrationTestBase.java
     Mon Nov 15 15:48:01 2010
@@ -364,4 +364,16 @@
     protected static WrappedUrlProvisionOption commonsCodec() {
         return 
wrappedBundle(mavenBundle().groupId("commons-codec").artifactId("commons-codec"));
     }
+    
+    protected static MavenArtifactProvisionOption amdatuGadgetManagement() {
+        return 
mavenBundle().groupId("org.amdatu.opensocial").artifactId("gadgetmanagement").versionAsInProject();
+    }
+    
+    protected static MavenArtifactProvisionOption amdatuLogin() {
+        return 
mavenBundle().groupId("org.amdatu.authorization.login").artifactId("service").versionAsInProject();
+    }
+    
+    protected static MavenArtifactProvisionOption amdatuShindig() {
+        return 
mavenBundle().groupId("org.amdatu.opensocial").artifactId("shindig").versionAsInProject();
+    }
 }

Added: 
trunk/integration-tests/src/test/java/org/amdatu/test/integration/tests/GadgetManagementServiceTest.java
==============================================================================
--- (empty file)
+++ 
trunk/integration-tests/src/test/java/org/amdatu/test/integration/tests/GadgetManagementServiceTest.java
    Mon Nov 15 15:48:01 2010
@@ -0,0 +1,111 @@
+/*
+    Copyright (C) 2010 Amdatu.org
+
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.amdatu.test.integration.tests;
+
+import static org.ops4j.pax.exam.CoreOptions.provision;
+
+import org.amdatu.opensocial.gadgetmanagement.GadgetManagement;
+import org.amdatu.opensocial.shindig.GadgetCategory;
+import org.amdatu.opensocial.shindig.GadgetDefinition;
+import org.amdatu.opensocial.shindig.ShindigService;
+import org.amdatu.test.integration.base.IntegrationTestBase;
+import org.apache.felix.dm.Component;
+import org.apache.felix.dm.DependencyManager;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.Configuration;
+import org.ops4j.pax.exam.junit.JUnit4TestRunner;
+
+/**
+ * This class provides an integration test for testing the User Admin store.
+ *
+ * @author ivol
+ */
+ at RunWith(JUnit4TestRunner.class)
+public class GadgetManagementServiceTest extends IntegrationTestBase {
+ 
+    private GadgetManagement m_gadgetManagementService;
+
+    @Configuration
+    public Option[] configure() {
+        return super.configure();
+    }
+
+    protected Component[] getDependencies(DependencyManager manager) {
+        return new Component[] { manager.createComponent()
+            .setImplementation(this)
+            // We add the Shindig dependency just to make sure that the 
shindig bundle is not stopped 
+            // before this service finished initialization (since the 
integration test does not have a 
+            // direct dependency on it) which would result in a failure upon 
shutdown (IllegalStateException).
+            
.add(manager.createServiceDependency().setService(ShindigService.class).setRequired(true))
+            
.add(manager.createServiceDependency().setService(GadgetManagement.class).setRequired(true))};
+    }
+    
+    protected Option provisionBundles() {
+        return provision(
+            amdatuCassandraApplication(),
+            amdatuCassandraListener(),
+            amdatuCassandraPersistenceManager(),
+            felixHttpServiceJetty(),
+            paxUserAdmin(),
+            amdatuUserAdminCassandraStore(),
+            amdatuHttpContext(),
+            amdatuJaxRs(),
+            amdatuLogin(),
+            amdatuShindig(),
+            amdatuGadgetManagement()
+        );
+    }
+
+    @Test
+    public void testCRUD() throws Exception {
+        // First we create a test category and gadget, then we try to retrieve 
it
+        GadgetCategory category = new GadgetCategory("test", "Integration Test 
Category");
+        Assert.assertTrue("Could not add test category", 
m_gadgetManagementService.addCategory(category));
+        Assert.assertTrue("Could not retrieve created test category", 
m_gadgetManagementService.getCategory(category.getId()) != null);
+        
+        // Try to add the category twice, this should fail
+        Assert.assertFalse("Could add the same cagegory twice", 
m_gadgetManagementService.addCategory(category));
+        
+        // Now add a test gadget
+        GadgetDefinition gadget = new 
GadgetDefinition("http://this/is/a/dummy/url/that/does/not/exist/yet";, 
category, false);
+        Assert.assertTrue("Could not add test gadget", 
m_gadgetManagementService.addGadget(gadget));
+        boolean found = false;
+        for (GadgetDefinition g : m_gadgetManagementService.getGadgets()) {
+            if (g.getUrl().equals(gadget.getUrl())) {
+                found = true;
+            }
+        }
+        Assert.assertTrue("Could not retrieve created test gadget", found);
+        
+        // Try to add the gadget twice, this should succeed
+        Assert.assertTrue("Could not add the same gadget twice", 
m_gadgetManagementService.addGadget(gadget));
+        
+        int beforeCount = m_gadgetManagementService.getGadgets().length;
+        Assert.assertTrue("Could not remove gadget", 
m_gadgetManagementService.removeGadget(gadget));
+        Assert.assertTrue("Could not remove gadget", (beforeCount - 1) == 
m_gadgetManagementService.getGadgets().length);
+        found = false;
+        for (GadgetDefinition g : m_gadgetManagementService.getGadgets()) {
+            if (g.getUrl().equals(gadget.getUrl())) {
+                found = true;
+            }
+        }
+        Assert.assertFalse("Gadget removed but still present", found);
+    }
+}

Reply via email to