Author: ivol37 at gmail.com
Date: Wed Jan  5 14:32:06 2011
New Revision: 564

Log:
[AMDATU-244] Added fallback for the case that the test category is still 
present (in which case it is removed first). This should prevent the test to 
fail for this reason (being that the work directory is not removed properly).

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/service/GadgetManagementServiceImpl.java
   trunk/amdatu-opensocial/shindig/pom.xml
   
trunk/amdatu-opensocial/shindig/src/main/java/org/amdatu/opensocial/shindig/GadgetStore.java
   
trunk/amdatu-opensocial/shindig/src/main/java/org/amdatu/opensocial/shindig/persistence/GadgetStoreImpl.java
   trunk/integration-tests/pom.xml
   
trunk/integration-tests/src/test/java/org/amdatu/test/integration/tests/GadgetManagementServiceTest.java

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
 Wed Jan  5 14:32:06 2011
@@ -22,7 +22,7 @@
 /**
  * This service provides CRUD operations on all gadgets definitions available 
in the gadget store. The gadget
  * store provides the set of all gadgets that can be added to the dashboard 
and holds basic gadget configurations
- * like gadget URL and oAuth keys and secrets. The gadget definition is 
represented by a GadgetDefinition, which 
+ * like gadget URL and oAuth keys and secrets. The gadget definition is 
represented by a GadgetDefinition, which
  * is based as input/output parameters of the CRUD operations.
  * Note that store in fact only stores references to gadgets, the actual 
gadget configuration is off course
  * managed by the gadget itself.
@@ -35,27 +35,35 @@
      * @return <code>true</code> if adding the gadget definition to the store 
succeeded, <code>false</code> otherwise.
      */
     boolean addGadget(GadgetDefinition gadget);
-    
+
     /**
      * Returns a list of all Gadget URLs available in the gadget store.
      * @return list of all Gadget URLs available in the gadget store.
      */
     GadgetDefinition[] getGadgets();
-    
+
     /**
      * Adds a new gadget category.
      * @param category gadget category to add
      * @return true if the category was added, false otherwise
      */
     boolean addCategory(GadgetCategory category);
-    
+
     /**
      * Retrieves a gadget category by its id.
      * @param categoryId The id of the category to retrieve
      * @return The gadget category
      */
     GadgetCategory getCategory(String categoryId);
-    
+
+    /**
+     * Removes a gadget category.
+     * @param category The category to remove (only id is required)
+     * @return true if the category was removed successfully, false if no 
category was removed since it
+     * didn't exist or an internal error occurred.
+     */
+    boolean removeCategory(GadgetCategory category);
+
     /**
      * 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.

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
      Wed Jan  5 14:32:06 2011
@@ -676,6 +676,13 @@
         return false;
     }
 
+    public boolean removeCategory(GadgetCategory category) {
+        if (m_gadgetStore.getCategory(category.getId()) != null) {
+            return m_gadgetStore.removeCategory(category);
+        }
+        return false;
+    }
+
     public GadgetCategory getCategory(String categoryId) {
         return m_gadgetStore.getCategory(categoryId);
     }

Modified: trunk/amdatu-opensocial/shindig/pom.xml
==============================================================================
--- trunk/amdatu-opensocial/shindig/pom.xml     (original)
+++ trunk/amdatu-opensocial/shindig/pom.xml     Wed Jan  5 14:32:06 2011
@@ -12,7 +12,7 @@
   <packaging>bundle</packaging>
   <name>Amdatu Open Social - Apache Shindig Application</name>
   <description>This bundle includes the Apache Shindig libraries and exports 
the opensocial API as OSGi services</description>
-  
+
   <dependencies>
     <!-- Shindig Dependencies -->
     <dependency>
@@ -39,8 +39,8 @@
            <groupId>xerces</groupId>
            <artifactId>xmlParserAPIs</artifactId>
          </exclusion>
-      </exclusions>      
-    </dependency>   
+      </exclusions>
+    </dependency>
     <dependency>
       <groupId>org.apache.shindig</groupId>
       <artifactId>shindig-social-api</artifactId>
@@ -52,7 +52,7 @@
            <groupId>xerces</groupId>
            <artifactId>xmlParserAPIs</artifactId>
          </exclusion>
-      </exclusions>      
+      </exclusions>
     </dependency>
     <dependency>
       <groupId>org.apache.shindig</groupId>
@@ -65,7 +65,7 @@
            <groupId>xerces</groupId>
            <artifactId>xmlParserAPIs</artifactId>
          </exclusion>
-      </exclusions>      
+      </exclusions>
     </dependency>
     <dependency>
       <groupId>org.apache.shindig</groupId>
@@ -78,14 +78,14 @@
            <groupId>xerces</groupId>
            <artifactId>xmlParserAPIs</artifactId>
          </exclusion>
-      </exclusions>      
+      </exclusions>
     </dependency>
     <dependency>
       <groupId>org.slf4j</groupId>
       <artifactId>slf4j-api</artifactId>
       <version>1.5.6</version>
       <scope>compile</scope>
-    </dependency>     
+    </dependency>
     <dependency>
       <groupId>org.slf4j</groupId>
       <artifactId>slf4j-jdk14</artifactId>
@@ -97,13 +97,13 @@
       <artifactId>commons-logging</artifactId>
       <version>1.1.1</version>
       <scope>compile</scope>
-    </dependency>    
+    </dependency>
     <dependency>
       <groupId>javax.servlet</groupId>
       <artifactId>servlet-api</artifactId>
       <version>2.5</version>
       <scope>provided</scope>
-    </dependency>   
+    </dependency>
     <dependency>
       <groupId>org.ops4j</groupId>
       <artifactId>peaberry</artifactId>
@@ -115,18 +115,18 @@
       <artifactId>httpcontext</artifactId>
       <scope>provided</scope>
       <type>bundle</type>
-    </dependency>   
+    </dependency>
     <dependency>
       <groupId>org.amdatu.libraries</groupId>
       <artifactId>utilities</artifactId>
       <scope>compile</scope>
-    </dependency> 
+    </dependency>
     <dependency>
       <groupId>org.amdatu.cassandra</groupId>
       <artifactId>persistencemanager</artifactId>
       <scope>provided</scope>
       <type>bundle</type>
-    </dependency> 
+    </dependency>
     <dependency>
       <groupId>org.amdatu.cassandra</groupId>
       <artifactId>listener</artifactId>
@@ -138,11 +138,11 @@
       <artifactId>org.apache.felix.http.bundle</artifactId>
       <version>${org.apache.felix.http.version}</version>
       <scope>provided</scope>
-    </dependency>    
+    </dependency>
   </dependencies>
-  
+
   <build>
-    <resources>  
+    <resources>
       <resource>
         <directory>src/main/resources</directory>
         <filtering>true</filtering>
@@ -150,7 +150,7 @@
           <include>**/*.properties</include>
           <include>**/*.json</include>
         </includes>
-      </resource> 
+      </resource>
       <resource>
         <directory>src/main/resources</directory>
         <filtering>false</filtering>
@@ -158,9 +158,9 @@
           <exclude>**/*.properties</exclude>
           <exclude>**/*.json</exclude>
         </excludes>
-      </resource> 
-    </resources>    
-              
+      </resource>
+    </resources>
+
     <plugins>
       <plugin>
         <groupId>org.apache.felix</groupId>
@@ -168,8 +168,8 @@
         <configuration>
           <instructions>
             
<Bundle-Activator>org.amdatu.opensocial.shindig.osgi.Activator</Bundle-Activator>
-            <Bundle-SymbolicName>org.amdatu.core.shindig</Bundle-SymbolicName>
-            <Embed-Dependency>*;scope=compile</Embed-Dependency>       
+            
<Bundle-SymbolicName>org.amdatu.opensocial.shindig</Bundle-SymbolicName>
+            <Embed-Dependency>*;scope=compile</Embed-Dependency>
             <Embed-Transitive>true</Embed-Transitive>
             <Import-Package>
               <!--!javax.swing.*,-->
@@ -207,7 +207,7 @@
           </instructions>
         </configuration>
       </plugin>
-      
+
     </plugins>
-  </build> 
+  </build>
 </project>

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
        Wed Jan  5 14:32:06 2011
@@ -25,7 +25,7 @@
     // ColumnFamily's for gadget store
     final String CF_GADGET = "Gadget";
     final String CF_GADGETCATEGORY = "GadgetCategory";
-    
+
     /**
      * Adds a gadget to the gadget store. If an entry with the same gadget URL 
already exists,
      * it is overwritten by this gadget definition.
@@ -33,30 +33,43 @@
      * @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, 
+     * 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);
-    
+
+    /**
+     * Adds a new gadget category to the gadget store.
+     * @param category The category to add. The id and name of this category 
may not be null.
+     * @return true if the category was successfully added, false if it was 
not created since it
+     * already existed or an internal error occurred.
+     */
+    boolean addCategory(GadgetCategory category);
+
+    /**
+     * Removes a gadget category from the gadget store.
+     * @param category The category to remove. The id of this category may not 
be null.
+     * @return true if the category was successfully removed, false if it was 
not removed because
+     * no such category exists or an internal error occurred.
+     */
+    boolean removeCategory(GadgetCategory category);
+
     GadgetDefinition[] getGadgets();
-    
+
     GadgetCategory getCategory(String categoryId);
-    
-    boolean addCategory(GadgetCategory category);
-    
     GadgetCategory[] getCategories();
-    
+
     Map<String, Integer> getCategoryCount() throws CassandraException;
-    
+
     Map<String, String> getGadgetCategories() throws CassandraException;
-    
+
     BasicOAuthStoreConsumerKeyAndSecret getDefaultKey();
-    
-    
+
+
 }

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
        Wed Jan  5 14:32:06 2011
@@ -81,7 +81,7 @@
         // Load the default private and public key
         loadDefaultKey();
     }
-    
+
     public void start() {
         m_logService.log(LogService.LOG_DEBUG, "Service " + 
this.getClass().getName() + " is now available");
     }
@@ -102,12 +102,12 @@
             String privateKey = 
BasicOAuthStore.convertFromOpenSsl(IOUtils.toString(is));
             String publicKey = DEFAULT_OAUTH_PUBLIC_KEY;
             m_defaultKey =
-                    new BasicOAuthStoreConsumerKeyAndSecret(null, privateKey, 
KeyType.RSA_PRIVATE, publicKey, null);
+                new BasicOAuthStoreConsumerKeyAndSecret(null, privateKey, 
KeyType.RSA_PRIVATE, publicKey, null);
             if (m_defaultKey == null) {
                 m_logService.log(LogService.LOG_WARNING, "Couldn't load OAuth 
signing key.  To create a key, run:\n"
-                        + "  openssl req -newkey rsa:1024 -days 365 -nodes 
-x509 -keyout testkey.pem \n"
-                        + "     -out testkey.pem -subj '/CN=mytestkey'\n"
-                        + "  openssl pkcs8 -in testkey.pem -out oauthkey.pem 
-topk8 -nocrypt -outform PEM\n");
+                    + "  openssl req -newkey rsa:1024 -days 365 -nodes -x509 
-keyout testkey.pem \n"
+                    + "     -out testkey.pem -subj '/CN=mytestkey'\n"
+                    + "  openssl pkcs8 -in testkey.pem -out oauthkey.pem 
-topk8 -nocrypt -outform PEM\n");
             }
         } catch (Throwable t) {
             m_logService.log(LogService.LOG_ERROR, "Couldn't load oAuth 
private key", t);
@@ -129,7 +129,7 @@
 
             m_pm.setStringValue(CF_GADGET, rowKey, SC_BASIC, C_GADGETURL, 
gadget.getUrl());
             m_pm.setStringValue(CF_GADGET, rowKey, SC_BASIC, C_DEFAULTVISIBLE, 
new Boolean(gadget.isDefaultVisible())
-                    .toString());
+            .toString());
             m_pm.setStringValue(CF_GADGET, rowKey, SC_BASIC, C_CATEGORY, 
gadget.getCategory().getId());
             m_pm.setStringValue(CF_GADGET, rowKey, SC_BASIC, C_CALLBACKURL, 
gadget.getCallbackUrl());
             m_pm.setStringValue(CF_GADGET, rowKey, SC_BASIC, C_SERVICENAME, 
gadget.getServiceName());
@@ -155,9 +155,9 @@
                 String categoryId = m_pm.getStringValue(CF_GADGET, 
rows.get(i), SC_BASIC, C_CATEGORY);
                 GadgetCategory category = getCategory(categoryId);
                 boolean defaultVisible =
-                        "true"
-                                
.equalsIgnoreCase(m_pm.getStringValue(CF_GADGET, rows.get(i), SC_BASIC,
-                                        C_DEFAULTVISIBLE));
+                    "true"
+                    .equalsIgnoreCase(m_pm.getStringValue(CF_GADGET, 
rows.get(i), SC_BASIC,
+                        C_DEFAULTVISIBLE));
                 if (category != null) {
                     gadgets[i] = new GadgetDefinition(url, category, 
defaultVisible);
                 } else {
@@ -188,7 +188,7 @@
                 return true;
             } else {
                 m_logService.log(LogService.LOG_ERROR, "Could not add category 
'" + category.getId()
-                        + "'. Category with this identifier already exists");
+                    + "'. Category with this identifier already exists");
                 return false;
             }
 
@@ -200,6 +200,26 @@
         return false;
     }
 
+    public boolean removeCategory(GadgetCategory category) {
+        try {
+            m_cassandraLock.readLock().lock();
+            if (m_pm.exists(CF_GADGETCATEGORY, category.getId())) {
+                m_pm.deleteRow(CF_GADGETCATEGORY, category.getId());
+                return true;
+            } else {
+                m_logService.log(LogService.LOG_ERROR, "Could not remove 
category '" + category.getId()
+                    + "'. Category with this identifier does not exist");
+                return false;
+            }
+
+        } catch (CassandraException e) {
+            m_logService.log(LogService.LOG_ERROR, "Could not remove gadget 
category", e);
+        } finally {
+            m_cassandraLock.readLock().unlock();
+        }
+        return false;
+    }
+
     public GadgetCategory[] getCategories() {
         try {
             m_cassandraLock.readLock().lock();
@@ -261,7 +281,7 @@
                 return new GadgetCategory(categoryId, catName);
             } else {
                 m_logService.log(LogService.LOG_INFO, "Could not find category 
'" + categoryId
-                        + "'. Category with this identifier does not exist.");
+                    + "'. Category with this identifier does not exist.");
                 return null;
             }
 
@@ -272,7 +292,7 @@
         }
         return null;
     }
-    
+
     public boolean removeGadget(GadgetDefinition gadget) {
         try {
             m_cassandraLock.writeLock().lock();

Modified: trunk/integration-tests/pom.xml
==============================================================================
--- trunk/integration-tests/pom.xml     (original)
+++ trunk/integration-tests/pom.xml     Wed Jan  5 14:32:06 2011
@@ -45,18 +45,6 @@
       <scope>test</scope>
     </dependency>
     <dependency>
-      <groupId>org.ops4j.pax.swissbox</groupId>
-      <artifactId>pax-swissbox-core</artifactId>
-      <version>${pax.swissbox.version}</version>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
-      <groupId>org.ops4j.base</groupId>
-      <artifactId>ops4j-base-lang</artifactId>
-      <version>1.2.2</version>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
       <groupId>org.amdatu.core.config</groupId>
       <artifactId>filebased</artifactId>
       <version>${platform.version}</version>

Modified: 
trunk/integration-tests/src/test/java/org/amdatu/test/integration/tests/GadgetManagementServiceTest.java
==============================================================================
--- 
trunk/integration-tests/src/test/java/org/amdatu/test/integration/tests/GadgetManagementServiceTest.java
    (original)
+++ 
trunk/integration-tests/src/test/java/org/amdatu/test/integration/tests/GadgetManagementServiceTest.java
    Wed Jan  5 14:32:06 2011
@@ -20,6 +20,8 @@
 
 import java.io.IOException;
 
+import org.amdatu.authentication.tokenprovider.TokenProvider;
+import org.amdatu.authorization.login.service.LoginService;
 import org.amdatu.opensocial.gadgetmanagement.GadgetManagement;
 import org.amdatu.opensocial.shindig.GadgetCategory;
 import org.amdatu.opensocial.shindig.GadgetDefinition;
@@ -37,6 +39,7 @@
 import org.ops4j.pax.exam.junit.JUnit4TestRunner;
 import org.osgi.framework.BundleException;
 import org.osgi.service.cm.ConfigurationAdmin;
+import org.osgi.service.log.LogService;
 
 /**
  * This class provides an integration test for testing the User Admin store.
@@ -45,10 +48,10 @@
  */
 @RunWith(JUnit4TestRunner.class)
 public class GadgetManagementServiceTest extends IntegrationTestBase {
- 
+    private volatile LogService m_logsService;
     private volatile GadgetManagement m_gadgetManagementService;
     private volatile ConfigurationAdmin m_configAdmin;
-    
+
     @Configuration
     public Option[] configure() {
         return super.configure();
@@ -57,17 +60,20 @@
     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 
+            // 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(ConfigurationAdmin.class))
+            
.add(manager.createServiceDependency().setService(ConfigurationAdmin.class).setRequired(true))
+            
.add(manager.createServiceDependency().setService(LogService.class).setRequired(true))
+            
.add(manager.createServiceDependency().setService(LoginService.class).setRequired(true))
+            
.add(manager.createServiceDependency().setService(TokenProvider.class).setRequired(true))
             
.add(manager.createServiceDependency().setService(GadgetManagement.class).setRequired(true))};
     }
-    
+
     protected Option provisionBundles() {
         return provision(
-               amdatuConfigTemplateManager(), // Required for placeholders in 
cassandra.yaml
+            amdatuConfigTemplateManager(), // Required for placeholders in 
cassandra.yaml
             amdatuCassandraApplication(),
             amdatuCassandraListener(),
             amdatuCassandraPersistenceManager(),
@@ -87,28 +93,33 @@
             amdatuMemTokenStore()
         );
     }
-    
-    @Before 
+
+    @Before
     public void initConfig() throws IOException, BundleException {
-       m_configAdmin = getService(ConfigurationAdmin.class);
-       
-       // Add cassandra and templates configs
-       ConfigProvider configProvider = new ConfigProvider();
-       configProvider.addCassandraConfig(m_configAdmin);
-       configProvider.addTemplateConfig(m_configAdmin);
-       configProvider.addShindigConfig(m_configAdmin);
+        m_configAdmin = getService(ConfigurationAdmin.class);
+
+        // Add cassandra and templates configs
+        ConfigProvider configProvider = new ConfigProvider();
+        configProvider.addCassandraConfig(m_configAdmin);
+        configProvider.addTemplateConfig(m_configAdmin);
+        configProvider.addShindigConfig(m_configAdmin);
     }
 
     @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");
+        if (m_gadgetManagementService.getCategory(category.getId()) != null) {
+            // If the test category already exists, remove it first
+            m_logsService.log(LogService.LOG_INFO, "Test category still 
exists, removing the category");
+            m_gadgetManagementService.removeCategory(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));
@@ -119,10 +130,10 @@
             }
         }
         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);

Reply via email to