incubator-wookie-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From scot...@apache.org
Subject svn commit: r1154295 - in /incubator/wookie/trunk/src-tests/org/apache/wookie/tests: beans/ conformance/ features/ flatpack/ functional/
Date Fri, 05 Aug 2011 16:24:17 GMT
Author: scottbw
Date: Fri Aug  5 16:24:17 2011
New Revision: 1154295

URL: http://svn.apache.org/viewvc?rev=1154295&view=rev
Log:
Improved the code comments in many of the unit tests, and removed individual developer credits from class javadoc. Also got rid of trapping of exceptions in test cases - instead just let them be thrown so we can debug it in the console.

Modified:
    incubator/wookie/trunk/src-tests/org/apache/wookie/tests/beans/AbstractPersistenceTest.java
    incubator/wookie/trunk/src-tests/org/apache/wookie/tests/beans/JPAPersistenceTest.java
    incubator/wookie/trunk/src-tests/org/apache/wookie/tests/conformance/AbstractFunctionalConformanceTest.java
    incubator/wookie/trunk/src-tests/org/apache/wookie/tests/conformance/PackagingAndConfiguration.java
    incubator/wookie/trunk/src-tests/org/apache/wookie/tests/features/FeaturesTest.java
    incubator/wookie/trunk/src-tests/org/apache/wookie/tests/flatpack/FlatpackFactoryTest.java
    incubator/wookie/trunk/src-tests/org/apache/wookie/tests/flatpack/PreferenceMock.java
    incubator/wookie/trunk/src-tests/org/apache/wookie/tests/flatpack/WidgetInstanceMock.java
    incubator/wookie/trunk/src-tests/org/apache/wookie/tests/functional/ApiKeyControllerTest.java
    incubator/wookie/trunk/src-tests/org/apache/wookie/tests/functional/FlatpackControllerTest.java

Modified: incubator/wookie/trunk/src-tests/org/apache/wookie/tests/beans/AbstractPersistenceTest.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src-tests/org/apache/wookie/tests/beans/AbstractPersistenceTest.java?rev=1154295&r1=1154294&r2=1154295&view=diff
==============================================================================
--- incubator/wookie/trunk/src-tests/org/apache/wookie/tests/beans/AbstractPersistenceTest.java (original)
+++ incubator/wookie/trunk/src-tests/org/apache/wookie/tests/beans/AbstractPersistenceTest.java Fri Aug  5 16:24:17 2011
@@ -67,43 +67,69 @@ public abstract class AbstractPersistenc
         }
         logger.info("Run test");
         
+        //
         // allocate and begin persistence manager transaction
+        //
         IPersistenceManager persistenceManager = PersistenceManagerFactory.getPersistenceManager();
         persistenceManager.begin();
 
-        // test generic findAll methods
+        //
+        // test findAll method for IWidget
+        //
         IWidget [] allWidgets = persistenceManager.findAll(IWidget.class);
         assertNotNull(allWidgets);
         assertEquals(1, allWidgets.length);
+        
+        //
+        // test findAll method for IWidgetDefault
+        //
         IWidgetDefault [] allWidgetDefaults = persistenceManager.findAll(IWidgetDefault.class);
         assertNotNull(allWidgetDefaults);
         assertEquals(1, allWidgetDefaults.length);
+        
+        //
+        // test findAll method for IWidgetService
+        //
         IWidgetService [] widgetServices = persistenceManager.findAll(IWidgetService.class);
         assertNotNull(widgetServices);
         assertEquals(5, widgetServices.length);
 
-        // test generic findById methods
+        //
+        // test findById  for IWidget
+        //
         Object widgetId = allWidgets[0].getId();
         IWidget widgetById = persistenceManager.findById(IWidget.class, widgetId);
         assertNotNull(widgetById);
         assertEquals(allWidgets[0], widgetById);
+        
+        //
+        // test findById  for IWidgetDefault
+        //
         Object widgetDefaultId = allWidgetDefaults[0].getId();
         IWidgetDefault widgetDefaultById = persistenceManager.findById(IWidgetDefault.class, widgetDefaultId);
         assertNotNull(widgetDefaultById);
         assertEquals(allWidgetDefaults[0], widgetDefaultById);
 
-        // test generic findByValue methods
+        //
+        // test findByValue method for IWidget
+        //
         String widgetGuid = allWidgets[0].getGuid();
         IWidget [] widgetsByValue = persistenceManager.findByValue(IWidget.class, "guid", widgetGuid);
         assertNotNull(widgetsByValue);
         assertEquals(1, widgetsByValue.length);
         assertEquals(allWidgets[0], widgetsByValue[0]);
+        
+        //
+        // test findByValue method for IWidgetDefault
+        //
         IWidgetDefault [] widgetDefaultsByValue = persistenceManager.findByValue(IWidgetDefault.class, "widget", widgetById);
         assertNotNull(widgetDefaultsByValue);
         assertEquals(1, widgetDefaultsByValue.length);
         assertEquals(allWidgetDefaults[0], widgetDefaultsByValue[0]);
         
-        // test generic findByValues methods
+        //
+        // test findByValues methods for IWidget
+        //
         Map<String,Object> values = new HashMap<String,Object>();
         values.put("height", allWidgets[0].getHeight());
         values.put("width", allWidgets[0].getWidth());
@@ -113,7 +139,9 @@ public abstract class AbstractPersistenc
         assertEquals(1, widgetsByValues.length);
         assertEquals(allWidgets[0], widgetsByValues[0]);
         
+        //
         // test custom widget query methods
+        //
         IWidget widgetByGuid = persistenceManager.findWidgetByGuid(widgetGuid);
         assertNotNull(widgetByGuid);
         assertEquals(allWidgets[0], widgetByGuid);
@@ -126,23 +154,43 @@ public abstract class AbstractPersistenc
         assertEquals(1, widgetsByType.length);
         assertEquals(allWidgets[0], widgetsByType[0]);
         
+        //
         // rollback and close persistence manager transaction
+        //
         persistenceManager.rollback();
         PersistenceManagerFactory.closePersistenceManager();
         
+        //
         // allocate and begin persistence manager transaction
+        //
         persistenceManager = PersistenceManagerFactory.getPersistenceManager();
         persistenceManager.begin();
 
-        // create widget instance
+        //
+        // Get the first existing API key
+        // and first existing Widget to use as the basis of a  
+        // new Widget Instance
+        //
         IApiKey [] apiKeys = persistenceManager.findAll(IApiKey.class);
         String apiKey = apiKeys[0].getValue();
         IWidget [] widgets = persistenceManager.findAll(IWidget.class);
         IWidget widget = widgets[0];        
         widgetGuid = widget.getGuid();
+        
+        //
+        // check that the Widget Instance does not yet exist
+        //
         IWidgetInstance widgetInstance = persistenceManager.findWidgetInstanceByGuid(apiKey, "test", "test-shared-data-key", widgetGuid);
         assertNull(widgetInstance);
+        
+        //
+        // Create the Widget Instance
+        //
         widgetInstance = persistenceManager.newInstance(IWidgetInstance.class);
+        
+        //
+        // Set some properties, including preferences
+        //
         widgetInstance.setApiKey(apiKey);
         widgetInstance.setWidget(widget);
         widgetInstance.setIdKey("test");
@@ -157,9 +205,14 @@ public abstract class AbstractPersistenc
         widgetInstancePreference.setDvalue("test-shared-data-key");
         widgetInstancePreference.setReadOnly(true);
         widgetInstance.getPreferences().add(widgetInstancePreference);
+        //
+        // Save the widget instance
+        //
         persistenceManager.save(widgetInstance);
 
-        // create participant
+        //
+        // create a participant
+        //
         IParticipant participant = persistenceManager.newInstance(IParticipant.class);
         //participant.setWidget(widget);
         participant.setSharedDataKey("test-shared-data-key");
@@ -168,7 +221,9 @@ public abstract class AbstractPersistenc
         participant.setParticipantThumbnailUrl("");
         persistenceManager.save(participant);
 
+        //
         // create access request
+        //
         IAccessRequest accessRequest = persistenceManager.newInstance(IAccessRequest.class);
         accessRequest.setOrigin("localhost");
         accessRequest.setSubdomains(false);
@@ -176,15 +231,21 @@ public abstract class AbstractPersistenc
         accessRequest.setWidget(widget);
         persistenceManager.save(accessRequest);
 
+        //
         // commit and close persistence manager transaction
+        //
         persistenceManager.commit();
         PersistenceManagerFactory.closePersistenceManager();
 
+        //
         // allocate and begin persistence manager transaction
+        //
         persistenceManager = PersistenceManagerFactory.getPersistenceManager();
         persistenceManager.begin();
         
-        // test custom widget instance query methods
+        //
+        // Get the widget instance created in the previous transaction via its "service context" (category)
+        // 
         apiKeys = persistenceManager.findAll(IApiKey.class);
         apiKey = apiKeys[0].getValue();
         widgets = persistenceManager.findAll(IWidget.class);
@@ -193,40 +254,64 @@ public abstract class AbstractPersistenc
         IWidgetInstance widgetInstance0 = persistenceManager.findWidgetInstance(apiKey, "test", "test-shared-data-key", serviceContext);
         assertNotNull(widgetInstance0);
         widgetGuid = widget.getGuid();
+        
+        //
+        // Get the widget instance created in the previous transaction via "widget GUID"
+        //
         IWidgetInstance widgetInstance1 = persistenceManager.findWidgetInstanceByGuid(apiKey, "test", "test-shared-data-key", widgetGuid);
         assertNotNull(widgetInstance1);
         assertEquals(widgetInstance0, widgetInstance1);
+        
+        //
+        // Get the widget instance created in the previous transaction via instance_idkey
+        //
         IWidgetInstance widgetInstance2 = persistenceManager.findWidgetInstanceByIdKey("test");
         assertNotNull(widgetInstance2);
         assertEquals(widgetInstance0, widgetInstance2);
         
-        // test custom participant query methods
+        //
+        // Get the participant created in the previous transaction by widget instance
+        //
         IParticipant [] participants = persistenceManager.findParticipants(widgetInstance0);
         assertNotNull(participants);
         assertEquals(1, participants.length);
+        
+        //
+        // Get the participant created in the previous transaction by finding the viewer
+        //
         participant = persistenceManager.findParticipantViewer(widgetInstance0);
         assertNotNull(participant);
         assertEquals(participants[0], participant);
         
-        
+        //
+        // Get the access request created in the previous transaction
+        //
         IAccessRequest [] accessRequests = persistenceManager.findAll(IAccessRequest.class);
         assertNotNull(accessRequests);
         assertEquals(1, accessRequests.length);
         
-        // delete test objects
+        //
+        // delete all the test objects
+        //
         persistenceManager.delete(widgetInstance0);
         persistenceManager.delete(participant);
         persistenceManager.delete(accessRequests);
         
+        //
         // commit and close persistence manager transaction
+        //
         persistenceManager.commit();
         PersistenceManagerFactory.closePersistenceManager();
 
+        //
         // allocate and begin persistence manager transaction
+        //
         persistenceManager = PersistenceManagerFactory.getPersistenceManager();
         persistenceManager.begin();
         
+        //
         // verify test deletes
+        //
         IWidgetInstance [] widgetInstances = persistenceManager.findAll(IWidgetInstance.class);
         assertNotNull(widgetInstances);
         assertEquals(0, widgetInstances.length);
@@ -234,7 +319,9 @@ public abstract class AbstractPersistenc
         assertNotNull(participants);
         assertEquals(0, participants.length);
         
+        //
         // rollback and close persistence manager transaction
+        //
         persistenceManager.rollback();
         PersistenceManagerFactory.closePersistenceManager();
 

Modified: incubator/wookie/trunk/src-tests/org/apache/wookie/tests/beans/JPAPersistenceTest.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src-tests/org/apache/wookie/tests/beans/JPAPersistenceTest.java?rev=1154295&r1=1154294&r2=1154295&view=diff
==============================================================================
--- incubator/wookie/trunk/src-tests/org/apache/wookie/tests/beans/JPAPersistenceTest.java (original)
+++ incubator/wookie/trunk/src-tests/org/apache/wookie/tests/beans/JPAPersistenceTest.java Fri Aug  5 16:24:17 2011
@@ -73,7 +73,9 @@ public class JPAPersistenceTest extends 
     {
         logger.info("JPA set up test");
 
+        //
         // load database configuration from environment
+        //
         String testDatabaseDir = (System.getProperty("user.dir")+"/build/test-database").replace(File.separatorChar, '/');
         dbUser = getSystemProperty(DB_USER_PROPERTY_NAME, "java");
         dbPassword = getSystemProperty(DB_PASSWORD_PROPERTY_NAME, "java");
@@ -81,30 +83,42 @@ public class JPAPersistenceTest extends 
         dbUri = getSystemProperty(DB_URI_PROPERTY_NAME, "jdbc:derby:"+testDatabaseDir+"/widgetdb;create=true");
         dbType = getSystemProperty(DB_TYPE_PROPERTY_NAME, "derby");
         
+        //
         // load driver
+        //
         Class.forName(dbDriver);
         
+        //
         // test connection
+        //
         Connection conn = DriverManager.getConnection(dbUri, dbUser, dbPassword);
         conn.close();
         
+        //
         // construct pooling datasource
+        //
         connectionPool = new GenericObjectPool(null, 0, GenericObjectPool.WHEN_EXHAUSTED_GROW, 0, 5);
         ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(dbUri, dbUser, dbPassword);
         new PoolableConnectionFactory(connectionFactory, connectionPool, null, null, false, true);
         DataSource dataSource = new PoolingDataSource(connectionPool);            
         
+        //
         // create JNDI context
+        //
         rootContext = new InitialContext();
         Context namingContext = lookupOrCreateNamingContext(rootContext, "java:comp");
         namingContext = lookupOrCreateNamingContext(namingContext, "env");
         lookupOrCreateNamingContext(namingContext, "jdbc");
         
+        //
         // bind datasource to JNDI context
+        //
         rootContext.rebind(JPAPersistenceManager.WIDGET_DATABASE_JNDI_DATASOURCE_FULL_NAME, dataSource);
 
+        //
         // initialize persistence manager factory and persistence manager;
         // truncate and initialize persistent store
+        //
         Configuration configuration = new PropertiesConfiguration();
         configuration.setProperty(PersistenceManagerFactory.PERSISTENCE_MANAGER_CLASS_NAME_PROPERTY_NAME, JPAPersistenceManager.class.getName());
         configuration.setProperty(PersistenceManagerFactory.PERSISTENCE_MANAGER_INITIALIZE_STORE_PROPERTY_NAME, "true");
@@ -113,6 +127,10 @@ public class JPAPersistenceTest extends 
         PersistenceManagerFactory.initialize(configuration);
 
         logger.info("JPA test set up");
+        
+        //
+        // This tells the abstract persistence test case we are ready to run 
+        //
         configured = true;
     }
 
@@ -124,38 +142,56 @@ public class JPAPersistenceTest extends 
     @After
     public void tearDownPerTest() throws Exception
     {
+        //
+        // This tells the abstract persistence test case not to run the JPA tests
+        //
         configured = false;
         logger.info("JPA tear down test");
 
+        //
         // terminate persistence manager factory
+        //
         PersistenceManagerFactory.terminate();
 
+        //
         // unbind datasource from JNDI context
+        //
         rootContext.unbind(JPAPersistenceManager.WIDGET_DATABASE_JNDI_DATASOURCE_FULL_NAME);
         
+        //
         // shutdown datasource pool
+        //
         connectionPool.close();
         
+        //
         // special shutdown handling for derby
+        //
         if (dbDriver.equals("org.apache.derby.jdbc.EmbeddedDriver") && dbUri.startsWith("jdbc:derby:") && dbType.equals("derby"))
         {
+            //
             // derby shutdown connection
+            //
             String shutdownDBUri = dbUri;
             int parametersIndex = shutdownDBUri.indexOf(";");
-            if (parametersIndex != -1)
-            {
+            if (parametersIndex != -1) {
                 shutdownDBUri = shutdownDBUri.substring(0, parametersIndex);
             }
             shutdownDBUri += ";shutdown=true";
-            try
-            {
+            //
+            // Try to connect to the database - if we can, throw an exception that
+            // the shutdown hasn't worked.
+            //
+            try {
                 DriverManager.getConnection(shutdownDBUri, dbUser, dbPassword);
                 throw new SQLException("Derby database not shutdown");
-            }
-            catch (SQLException sqle)
-            {
-                if (!sqle.getSQLState().equals("08006") && !sqle.getSQLState().equals("XJ015"))
-                {
+            } catch (SQLException sqle) {
+                //
+                // Check that we have the correct shutdown code - either 08006 which
+                // is the code for a single database shutdown, or XJ015 which means
+                // the whole Derby instance has shutdown successfully. If not, we
+                // throw the exception.
+                //
+                if (!sqle.getSQLState().equals("08006") && !sqle.getSQLState().equals("XJ015")) {
                     throw sqle;
                 }
             }

Modified: incubator/wookie/trunk/src-tests/org/apache/wookie/tests/conformance/AbstractFunctionalConformanceTest.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src-tests/org/apache/wookie/tests/conformance/AbstractFunctionalConformanceTest.java?rev=1154295&r1=1154294&r2=1154295&view=diff
==============================================================================
--- incubator/wookie/trunk/src-tests/org/apache/wookie/tests/conformance/AbstractFunctionalConformanceTest.java (original)
+++ incubator/wookie/trunk/src-tests/org/apache/wookie/tests/conformance/AbstractFunctionalConformanceTest.java Fri Aug  5 16:24:17 2011
@@ -32,7 +32,12 @@ import org.junit.BeforeClass;
 
 /**
  * Abstract superclass for conformance tests including utility functions
- * for working with widgets and outputting results
+ * for working with widgets and outputting results. This is used for generating
+ * HTML output for "eyeball tests" where the developer wants to scan the results
+ * of instantiating widgets, for example the W3C Test Cases which present a green
+ * "PASS" or red "FAIL" output based on runtime behaviour.
+ * 
+ * FIXME there is some duplication in the methods here that could be rationalized.
  */
 public abstract class AbstractFunctionalConformanceTest extends
 AbstractControllerTest {
@@ -51,6 +56,14 @@ AbstractControllerTest {
 	}
 
 	//// Utility methods
+	
+	/**
+	 * Execute the test for the given widget; upload the widget,
+	 * create an instance of it, obtain the URL for it, generate 
+	 * an iframe for it, and add it to the HTML output for the test
+	 * 
+	 * @param widget the widget to test
+	 */
 	protected static void doTest(String widget){
 		String url;
 		try {
@@ -61,6 +74,11 @@ AbstractControllerTest {
 		}
 	}
 
+	/**
+	 * Create an output <iframe> for an instance 
+	 * of the specified widget
+	 * @param widgetId the widget to instantiate and output
+	 */
 	protected static void outputInstance(String widgetId){
 		String url;
 		String response = instantiateWidget(widgetId);
@@ -68,6 +86,13 @@ AbstractControllerTest {
 		html += "<iframe src=\""+url+"\"></iframe>";
 	}
 
+	/**
+	 * Upload a widget, create an instance of it, and return the URL for the instance
+	 * 
+	 * @param widgetfname the widget to upload
+	 * @return the URL to access an instance of the uploaded widget
+	 * @throws IOException
+	 */
 	protected static String getWidgetUrl(String widgetfname) throws IOException{
 		WidgetUploader.uploadWidget(widgetfname);
 		Element widget = WidgetUploader.getLastWidget();
@@ -75,13 +100,25 @@ AbstractControllerTest {
 		return getStartFile(response);
 	}
 
+	/**
+	 * Create an instance of the specified widget
+	 * @param widget the widget to create an instance of
+	 * @return the id of the widget instance that was created
+	 */
 	protected static String instantiateWidget(Element widget){
 		return instantiateWidget(widget.getAttributeValue("identifier"));	
 	}
 
+	/**
+	 * Create an instance of the specified widget
+	 * @param identifier the identifier of the widget to create an instance of
+	 * @return the XML representation of the widget instance as a String
+	 */
 	protected static String instantiateWidget(String identifier){
 		String response = null;
+		//
 		// instantiate widget and parse results
+		//
 		try {
 			HttpClient client = new HttpClient();
 			PostMethod post = new PostMethod(TEST_INSTANCES_SERVICE_URL_VALID);
@@ -96,6 +133,11 @@ AbstractControllerTest {
 		return response;		
 	}
 
+	/**
+	 * Get the URL of a widget instance from the XML representation
+	 * @param response the XML returned from a request to create a new widget instance
+	 * @return the URL of the instance, as a String
+	 */
 	protected static String getStartFile(String response){
 		SAXBuilder builder = new SAXBuilder();
 		Reader in = new StringReader(response);

Modified: incubator/wookie/trunk/src-tests/org/apache/wookie/tests/conformance/PackagingAndConfiguration.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src-tests/org/apache/wookie/tests/conformance/PackagingAndConfiguration.java?rev=1154295&r1=1154294&r2=1154295&view=diff
==============================================================================
--- incubator/wookie/trunk/src-tests/org/apache/wookie/tests/conformance/PackagingAndConfiguration.java (original)
+++ incubator/wookie/trunk/src-tests/org/apache/wookie/tests/conformance/PackagingAndConfiguration.java Fri Aug  5 16:24:17 2011
@@ -39,9 +39,6 @@ import org.junit.Test;
  * For more information see http://dev.w3.org/2006/waf/widgets/test-suite/index.html
  * 
  * Note that in order to run the Feature tests, a ServerFeature named "feature:a9bb79c1" must be set up in the DB
- * 
- * @author scott
- *
  */
 public class PackagingAndConfiguration extends AbstractFunctionalConformanceTest {
 	// 1 files

Modified: incubator/wookie/trunk/src-tests/org/apache/wookie/tests/features/FeaturesTest.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src-tests/org/apache/wookie/tests/features/FeaturesTest.java?rev=1154295&r1=1154294&r2=1154295&view=diff
==============================================================================
--- incubator/wookie/trunk/src-tests/org/apache/wookie/tests/features/FeaturesTest.java (original)
+++ incubator/wookie/trunk/src-tests/org/apache/wookie/tests/features/FeaturesTest.java Fri Aug  5 16:24:17 2011
@@ -27,11 +27,20 @@ import org.apache.wookie.feature.Feature
 import org.junit.Test;
 
 /**
- *
+ * Tests the Features capability by loading and parsing various
+ * test feature.xml files, and checking the mechanism for iterating
+ * over feature folders
  */
 public class FeaturesTest {
   
+  /**
+   * The location of the test data folder
+   */
   private static final String testDataFolder = "src-tests/org/apache/wookie/tests/features/";
+  
+  /**
+   * Base path for feature resources
+   */
   private static final String basePath = "/test";
   
   /**
@@ -104,7 +113,7 @@ public class FeaturesTest {
 
   
   /**
-   * Loads features from the test folder, ignoring everrything
+   * Loads features from the test folder, ignoring everything
    * that isn't a folder that contains a "features.xml" file
    */
   @Test

Modified: incubator/wookie/trunk/src-tests/org/apache/wookie/tests/flatpack/FlatpackFactoryTest.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src-tests/org/apache/wookie/tests/flatpack/FlatpackFactoryTest.java?rev=1154295&r1=1154294&r2=1154295&view=diff
==============================================================================
--- incubator/wookie/trunk/src-tests/org/apache/wookie/tests/flatpack/FlatpackFactoryTest.java (original)
+++ incubator/wookie/trunk/src-tests/org/apache/wookie/tests/flatpack/FlatpackFactoryTest.java Fri Aug  5 16:24:17 2011
@@ -41,7 +41,7 @@ public class FlatpackFactoryTest {
 	static File output;
 	static File flatpack;
 	
-	/*
+	/**
 	 * Create some temporary folders
 	 */
 	@BeforeClass
@@ -52,8 +52,8 @@ public class FlatpackFactoryTest {
 		Features.loadFeatures(new File("features"), "/wookie/features");
 	}
 	
-	/*
-	 * Setup temporary folders before using
+	/**
+	 * Setup temporary folders before each test
 	 */
 	@Before
 	public void setupEach(){
@@ -64,8 +64,8 @@ public class FlatpackFactoryTest {
 		flatpack.mkdir();
 	}
 	
-	/*
-	 * Delete temporary folders
+	/**
+	 * Delete temporary folders after tests have been completed
 	 */
 	@AfterClass
 	public static void tearDown(){
@@ -74,6 +74,11 @@ public class FlatpackFactoryTest {
 		flatpack.delete();
 	}
 	
+	/**
+	 * Tests that the factory throws an exception if no widget instance
+	 * is specified
+	 * @throws Exception
+	 */
 	@Test(expected=Exception.class)
 	public void testNoInstance() throws Exception{
 		FlatpackFactory flatfac = new FlatpackFactory(null);
@@ -88,21 +93,29 @@ public class FlatpackFactoryTest {
 	 */
 	@Test
 	public void createBasicFlatpackUsingDefaults() throws Exception{
+	  //
 		// upload a new widget to test with
+	  //
 		W3CWidgetFactory fac = getFactory();
 		File testWidget = new File("build/widgets/bubbles.wgt");
 		fac.parse(testWidget);
 		download = fac.getUnzippedWidgetDirectory(); //download is where we unzipped the widget
 		
+		//
 		// Create an instance of it
+		//
 		IWidgetInstance instance = new WidgetInstanceMock();
 		
+		//
 		// Flatpack it
+		//
 		FlatpackFactory flatfac = new FlatpackFactory(instance);
 		flatfac.setInputWidget(testWidget); // this is the original .wgt
 		File file = flatfac.pack(); // Get the new .wgt file
 	
+		//
 		// Test it works!
+		//
 		System.out.println(file.getAbsolutePath());
 		W3CWidget fpWidget = fac.parse(file);
 		assertNotNull(fpWidget);
@@ -115,23 +128,31 @@ public class FlatpackFactoryTest {
 	 */
 	@Test
 	public void createBasicFlatpack() throws Exception{
+	  //
 		// upload a new widget to test with
+	  //
 		W3CWidgetFactory fac = getFactory();
 		File testWidget = new File("build/widgets/bubbles.wgt");
 		fac.parse(testWidget);
 		download = fac.getUnzippedWidgetDirectory(); //download is where we unzipped the widget
 		
+		//
 		// Create an instance of it
+		//
 		IWidgetInstance instance = new WidgetInstanceMock();
 		
+		//
 		// Flatpack it
+		//
 		FlatpackFactory flatfac = new FlatpackFactory(instance);
 		flatfac.setParser(fac);
 		flatfac.setInputWidget(testWidget); // this is the original .wgt
 		flatfac.setFlatpackFolder(flatpack); // flatpack is our new temp folder. This would probably be "/flatpack" or similar in deployment
 		File file = flatfac.pack(); // Get the new .wgt file
 	
+		//
 		// Test it works!
+		//
 		System.out.println(file.getAbsolutePath());
 		W3CWidget fpWidget = fac.parse(file);
 		assertNotNull(fpWidget);
@@ -145,26 +166,42 @@ public class FlatpackFactoryTest {
    */
   @Test
   public void createFeatureFlatpackUsingDefaults() throws Exception{
+    
+    //
     // upload a new widget to test with
+    //
     W3CWidgetFactory fac = getFactory();
     fac.setFeatures(Features.getFeatureNames());
     File testWidget = new File("build/widgets/freeder.wgt");
     fac.parse(testWidget);
-    download = fac.getUnzippedWidgetDirectory(); //download is where we unzipped the widget
     
+    //
+    //download is where we unzipped the widget
+    //
+    download = fac.getUnzippedWidgetDirectory(); 
+    
+    //
     // Create an instance of it
+    //
     IWidgetInstance instance = new WidgetInstanceMock();
     
+    //
     // Flatpack it
+    //
     FlatpackFactory flatfac = new FlatpackFactory(instance);
     flatfac.setInputWidget(testWidget); // this is the original .wgt
     File file = flatfac.pack(); // Get the new .wgt file
   
+    //
     // Test it works!
+    //
     System.out.println("createFeatureFlatpackUsingDefaults: "+file.getAbsolutePath());
     W3CWidget fpWidget = fac.parse(file);
     assertNotNull(fpWidget);
+    
+    //
     // The JQM feature should have been removed from config.xml
+    //
     assertEquals(0, fpWidget.getFeatures().size());
     
   }
@@ -176,13 +213,17 @@ public class FlatpackFactoryTest {
 	@Test
 	public void createFlatpackWithPreferences() throws Exception{
 		
+	  //
 		// upload a new widget to test with
+	  //
 		W3CWidgetFactory fac = getFactory();
 		File testWidget = new File("build/widgets/bubbles.wgt");
 		fac.parse(testWidget);
 		download = fac.getUnzippedWidgetDirectory(); //download is where we unzipped the widget
 		
+		//
 		// Create an instance of it
+		//
 		IWidgetInstance instance = new WidgetInstanceMock();
 		ArrayList<IPreference> prefs = new ArrayList<IPreference>();
 		IPreference pref = new PreferenceMock();
@@ -192,14 +233,18 @@ public class FlatpackFactoryTest {
 		prefs.add(pref);
 		instance.setPreferences(prefs);
 		
+		//
 		// Flatpack it
+		//
 		FlatpackFactory flatfac = new FlatpackFactory(instance);
 		flatfac.setParser(fac);
 		flatfac.setInputWidget(testWidget); // this is the original .wgt
 		flatfac.setFlatpackFolder(flatpack); // flatpack is our new temp folder. This would probably be "/flatpack" or similar in deployment
 		File file = flatfac.pack(); // Get the new .wgt file
 	
+		//
 		// Test it works!
+		//
 		System.out.println(file.getAbsolutePath());
 		W3CWidget fpWidget = fac.parse(file);
 		assertEquals("hiScore", fpWidget.getPrefences().get(0).getName());
@@ -216,14 +261,18 @@ public class FlatpackFactoryTest {
 	@Test
 	public void createFlatpackWithPreferences2() throws Exception{
 		
+	  //
 		// upload a new widget to test with
+	  //
 		W3CWidgetFactory fac = getFactory();
 		fac.setFeatures(Features.getFeatureNames());
 		File testWidget = new File("build/widgets/simplechat.wgt");
 		fac.parse(testWidget);
 		download = fac.getUnzippedWidgetDirectory(); //download is where we unzipped the widget
 		
+		//
 		// Create an instance of it
+		//
 		IWidgetInstance instance = new WidgetInstanceMock();
 		ArrayList<IPreference> prefs = new ArrayList<IPreference>();
 		IPreference pref = new PreferenceMock();
@@ -233,14 +282,18 @@ public class FlatpackFactoryTest {
 		prefs.add(pref);
 		instance.setPreferences(prefs);
 		
+		//
 		// Flatpack it
+		//
 		FlatpackFactory flatfac = new FlatpackFactory(instance);
 		flatfac.setParser(fac);
 		flatfac.setInputWidget(testWidget); // this is the original .wgt
 		flatfac.setFlatpackFolder(flatpack); // flatpack is our new temp folder. This would probably be "/flatpack" or similar in deployment
 		File file = flatfac.pack(); // Get the new .wgt file
 	
+		//
 		// Test it works!
+		//
 		System.out.println(file.getAbsolutePath());
 		W3CWidget fpWidget = fac.parse(file);
 		assertEquals("moderator", fpWidget.getPrefences().get(0).getName());
@@ -248,7 +301,7 @@ public class FlatpackFactoryTest {
 		assertEquals(1,fpWidget.getPrefences().size());
 	}
 
-	/*
+	/**
 	 * Construct a standard W3CWidgetFactory for testing
 	 */
 	private W3CWidgetFactory getFactory() throws Exception{

Modified: incubator/wookie/trunk/src-tests/org/apache/wookie/tests/flatpack/PreferenceMock.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src-tests/org/apache/wookie/tests/flatpack/PreferenceMock.java?rev=1154295&r1=1154294&r2=1154295&view=diff
==============================================================================
--- incubator/wookie/trunk/src-tests/org/apache/wookie/tests/flatpack/PreferenceMock.java (original)
+++ incubator/wookie/trunk/src-tests/org/apache/wookie/tests/flatpack/PreferenceMock.java Fri Aug  5 16:24:17 2011
@@ -17,8 +17,6 @@ import org.apache.wookie.beans.IPreferen
 
 /**
  * Mock used for testing preferences
- * @author scottbw@apache.org
- *
  */
 public class PreferenceMock implements IPreference {
 	

Modified: incubator/wookie/trunk/src-tests/org/apache/wookie/tests/flatpack/WidgetInstanceMock.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src-tests/org/apache/wookie/tests/flatpack/WidgetInstanceMock.java?rev=1154295&r1=1154294&r2=1154295&view=diff
==============================================================================
--- incubator/wookie/trunk/src-tests/org/apache/wookie/tests/flatpack/WidgetInstanceMock.java (original)
+++ incubator/wookie/trunk/src-tests/org/apache/wookie/tests/flatpack/WidgetInstanceMock.java Fri Aug  5 16:24:17 2011
@@ -24,7 +24,6 @@ import org.apache.wookie.beans.IWidgetIn
 
 /**
  * Mock used for simulating a Widget Instance in tests
- * @author scottbw@apache.org
  */
 public class WidgetInstanceMock implements IWidgetInstance {
 	
@@ -155,7 +154,6 @@ public class WidgetInstanceMock implemen
 	 * @see org.apache.wookie.beans.IWidgetInstance#getNonce()
 	 */
 	public String getNonce() {
-		// TODO Auto-generated method stub
 		return null;
 	}
 
@@ -163,8 +161,6 @@ public class WidgetInstanceMock implemen
 	 * @see org.apache.wookie.beans.IWidgetInstance#setNonce(java.lang.String)
 	 */
 	public void setNonce(String nonce) {
-		// TODO Auto-generated method stub
-
 	}
 
 	/* (non-Javadoc)
@@ -185,7 +181,6 @@ public class WidgetInstanceMock implemen
 	 * @see org.apache.wookie.beans.IWidgetInstance#isUpdated()
 	 */
 	public boolean isUpdated() {
-		// TODO Auto-generated method stub
 		return false;
 	}
 
@@ -193,8 +188,6 @@ public class WidgetInstanceMock implemen
 	 * @see org.apache.wookie.beans.IWidgetInstance#setUpdated(boolean)
 	 */
 	public void setUpdated(boolean updated) {
-		// TODO Auto-generated method stub
-
 	}
 
 	/* (non-Javadoc)
@@ -215,7 +208,6 @@ public class WidgetInstanceMock implemen
 	 * @see org.apache.wookie.beans.IWidgetInstance#isLocked()
 	 */
 	public boolean isLocked() {
-		// TODO Auto-generated method stub
 		return false;
 	}
 
@@ -223,8 +215,6 @@ public class WidgetInstanceMock implemen
 	 * @see org.apache.wookie.beans.IWidgetInstance#setLocked(boolean)
 	 */
 	public void setLocked(boolean locked) {
-		// TODO Auto-generated method stub
-
 	}
 
 	/* (non-Javadoc)
@@ -246,7 +236,6 @@ public class WidgetInstanceMock implemen
 	 * @see org.apache.wookie.beans.IWidgetInstance#getTokens()
 	 */
 	public Collection<IToken> getTokens() {
-		// TODO Auto-generated method stub
 		return null;
 	}
 
@@ -254,8 +243,6 @@ public class WidgetInstanceMock implemen
 	 * @see org.apache.wookie.beans.IWidgetInstance#setTokens(java.util.Collection)
 	 */
 	public void setTokens(Collection<IToken> tokens) {
-		// TODO Auto-generated method stub
-
 	}
 
 	/* (non-Javadoc)

Modified: incubator/wookie/trunk/src-tests/org/apache/wookie/tests/functional/ApiKeyControllerTest.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src-tests/org/apache/wookie/tests/functional/ApiKeyControllerTest.java?rev=1154295&r1=1154294&r2=1154295&view=diff
==============================================================================
--- incubator/wookie/trunk/src-tests/org/apache/wookie/tests/functional/ApiKeyControllerTest.java (original)
+++ incubator/wookie/trunk/src-tests/org/apache/wookie/tests/functional/ApiKeyControllerTest.java Fri Aug  5 16:24:17 2011
@@ -20,15 +20,18 @@ package org.apache.wookie.tests.function
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+
+import java.io.IOException;
 
 import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpException;
 import org.apache.commons.httpclient.methods.DeleteMethod;
 import org.apache.commons.httpclient.methods.GetMethod;
 import org.apache.commons.httpclient.methods.PostMethod;
 import org.apache.commons.httpclient.methods.PutMethod;
 import org.jdom.Document;
 import org.jdom.Element;
+import org.jdom.JDOMException;
 import org.jdom.input.SAXBuilder;
 import org.junit.Ignore;
 import org.junit.Test;
@@ -38,291 +41,298 @@ import org.junit.Test;
  */
 public class ApiKeyControllerTest extends AbstractControllerTest {
 
-  private static final String APIKEY_SERVICE_LOCATION_VALID = TEST_SERVER_LOCATION+"keys";
+  private static final String APIKEY_SERVICE_LOCATION_VALID = TEST_SERVER_LOCATION  + "keys";
 
+  /**
+   * Attempt to get the list of API keys without having authenticated first
+   * 
+   * @throws IOException
+   * @throws HttpException
+   */
   @Test
-  public void getEntriesUnauthorized(){
-    try {
-      HttpClient client = new HttpClient();
-      GetMethod get = new GetMethod(APIKEY_SERVICE_LOCATION_VALID);
-      client.executeMethod(get);
-      int code = get.getStatusCode();
-      assertEquals(401, code);
-    }
-    catch (Exception e) {
-      e.printStackTrace();
-      fail("get failed");
-    }
+  public void getEntriesUnauthorized() throws HttpException, IOException {
+    HttpClient client = new HttpClient();
+    GetMethod get = new GetMethod(APIKEY_SERVICE_LOCATION_VALID);
+    client.executeMethod(get);
+    int code = get.getStatusCode();
+    assertEquals(401, code);
   }
 
+  /**
+   * Get the set of API keys using default admin credentials
+   * 
+   * @throws IOException
+   * @throws HttpException
+   */
   @Test
-  public void getKeys(){
-    try {
-      HttpClient client = new HttpClient();
-      GetMethod get = new GetMethod(APIKEY_SERVICE_LOCATION_VALID);
-      setAuthenticationCredentials(client);
-      client.executeMethod(get);
-      int code = get.getStatusCode();
-      assertEquals(200, code);
-    }
-    catch (Exception e) {
-      e.printStackTrace();
-      fail("get failed");
-    }
+  public void getKeys() throws HttpException, IOException {
+    HttpClient client = new HttpClient();
+    GetMethod get = new GetMethod(APIKEY_SERVICE_LOCATION_VALID);
+    setAuthenticationCredentials(client);
+    client.executeMethod(get);
+    int code = get.getStatusCode();
+    assertEquals(200, code);
   }
 
+  /**
+   * Add a new key
+   * 
+   * @throws IOException
+   * @throws HttpException
+   */
   @Test
-  public void addKey(){
-    try {
-      HttpClient client = new HttpClient();
-      PostMethod post = new PostMethod(APIKEY_SERVICE_LOCATION_VALID);
-      setAuthenticationCredentials(client);
-      post.setParameter("apikey", "TEST_KEY");
-      post.setParameter("email", "test@incubator.apache.org");
-      client.executeMethod(post);
-      int code = post.getStatusCode();
-      assertEquals(201, code);
-    }
-    catch (Exception e) {
-      e.printStackTrace();
-      fail("post failed");
-    } 
-    try {
-      HttpClient client = new HttpClient();
-      GetMethod get = new GetMethod(APIKEY_SERVICE_LOCATION_VALID);
-      setAuthenticationCredentials(client);
-      client.executeMethod(get);
-      int code = get.getStatusCode();
-      assertEquals(200, code);
-      assertTrue(get.getResponseBodyAsString().contains("TEST_KEY"));
-    }
-    catch (Exception e) {
-      e.printStackTrace();
-      fail("get failed");
-    }
+  public void addKey() throws HttpException, IOException {
+    
+    //
+    // POST a new API key
+    //
+    HttpClient client = new HttpClient();
+    PostMethod post = new PostMethod(APIKEY_SERVICE_LOCATION_VALID);
+    setAuthenticationCredentials(client);
+    post.setParameter("apikey", "TEST_KEY");
+    post.setParameter("email", "test@incubator.apache.org");
+    client.executeMethod(post);
+    int code = post.getStatusCode();
+    assertEquals(201, code);
+    
+    //
+    // Test that the set of API keys includes the one we just POSTed
+    //
+    client = new HttpClient();
+    GetMethod get = new GetMethod(APIKEY_SERVICE_LOCATION_VALID);
+    setAuthenticationCredentials(client);
+    client.executeMethod(get);
+    code = get.getStatusCode();
+    assertEquals(200, code);
+    assertTrue(get.getResponseBodyAsString().contains("TEST_KEY"));
   }
 
+  /**
+   * Remove a key
+   * 
+   * @throws IOException
+   * @throws JDOMException
+   */
   @Test
-  public void removeKey(){
+  public void removeKey() throws JDOMException, IOException {
     String id = null;
-    try {
-      HttpClient client = new HttpClient();
-      GetMethod get = new GetMethod(APIKEY_SERVICE_LOCATION_VALID);
-      setAuthenticationCredentials(client);
-      client.executeMethod(get);
-      int code = get.getStatusCode();
-      assertEquals(200, code);
-      assertTrue(get.getResponseBodyAsString().contains("TEST_KEY"));
-      // Get the ID
-      Document doc = new SAXBuilder().build(get.getResponseBodyAsStream());
-      for (Object key: doc.getRootElement().getChildren()){
-        Element keyElement = (Element)key;
-        if (keyElement.getAttributeValue("value").equals("TEST_KEY")){
-          id = keyElement.getAttributeValue("id");
-        }
+
+    //
+    // Create a new API key
+    //
+    HttpClient client = new HttpClient();
+    GetMethod get = new GetMethod(APIKEY_SERVICE_LOCATION_VALID);
+    setAuthenticationCredentials(client);
+    client.executeMethod(get);
+    int code = get.getStatusCode();
+    assertEquals(200, code);
+    assertTrue(get.getResponseBodyAsString().contains("TEST_KEY"));
+
+    //
+    // Get the ID of the key we created
+    //
+    Document doc = new SAXBuilder().build(get.getResponseBodyAsStream());
+    for (Object key : doc.getRootElement().getChildren()) {
+      Element keyElement = (Element) key;
+      if (keyElement.getAttributeValue("value").equals("TEST_KEY")) {
+        id = keyElement.getAttributeValue("id");
       }
     }
-    catch (Exception e) {
-      e.printStackTrace();
-      fail("get failed");
-    }
-    try {
-      HttpClient client = new HttpClient();
-      DeleteMethod del = new DeleteMethod(APIKEY_SERVICE_LOCATION_VALID+"/"+id);
-      setAuthenticationCredentials(client);
-      client.executeMethod(del);
-      int code = del.getStatusCode();
-      assertEquals(200, code);
-    }
-    catch (Exception e) {
-      e.printStackTrace();
-      fail("delete failed");
-    }
-    try {
-      HttpClient client = new HttpClient();
-      GetMethod get = new GetMethod(APIKEY_SERVICE_LOCATION_VALID);
-      get.setRequestHeader("Content-type", "application/json");
-      setAuthenticationCredentials(client);
-      client.executeMethod(get);
-      int code = get.getStatusCode();
-      assertEquals(200, code);
-      System.out.println(get.getResponseBodyAsString());
-      assertFalse(get.getResponseBodyAsString().contains("TEST_KEY"));
-    }
-    catch (Exception e) {
-      e.printStackTrace();
-      fail("get failed");
-    }
+
+    //
+    // Delete the API key
+    //
+    client = new HttpClient();
+    DeleteMethod del = new DeleteMethod(APIKEY_SERVICE_LOCATION_VALID + "/"  + id);
+    setAuthenticationCredentials(client);
+    client.executeMethod(del);
+    code = del.getStatusCode();
+    assertEquals(200, code);
+
+    //
+    // Check that the key was deleted
+    //
+    client = new HttpClient();
+    get = new GetMethod(APIKEY_SERVICE_LOCATION_VALID);
+    get.setRequestHeader("Content-type", "application/json");
+    setAuthenticationCredentials(client);
+    client.executeMethod(get);
+    code = get.getStatusCode();
+    assertEquals(200, code);
+    System.out.println(get.getResponseBodyAsString());
+    assertFalse(get.getResponseBodyAsString().contains("TEST_KEY"));
+
   }
 
+  /**
+   * Try to remove a non-existant API key
+   * 
+   * @throws HttpException
+   * @throws IOException
+   */
   @Test
-  public void removeNonExistantEntry(){
-    try {
-      HttpClient client = new HttpClient();
-      DeleteMethod del = new DeleteMethod(APIKEY_SERVICE_LOCATION_VALID+"/99999999");
-      setAuthenticationCredentials(client);
-      client.executeMethod(del);
-      int code = del.getStatusCode();
-      assertEquals(404, code);
-    }
-    catch (Exception e) {
-      e.printStackTrace();
-      fail("delete failed");
-    } 
+  public void removeNonExistantEntry() throws HttpException, IOException {
+    HttpClient client = new HttpClient();
+    DeleteMethod del = new DeleteMethod(APIKEY_SERVICE_LOCATION_VALID
+        + "/99999999");
+    setAuthenticationCredentials(client);
+    client.executeMethod(del);
+    int code = del.getStatusCode();
+    assertEquals(404, code);
   }
 
+  /**
+   * Create an API key with missing parameters
+   * 
+   * @throws IOException
+   * @throws HttpException
+   */
   @Test
-  public void addEntryNoEmailOrValue(){
-    try {
-      HttpClient client = new HttpClient();
-      PostMethod post = new PostMethod(APIKEY_SERVICE_LOCATION_VALID);
-      setAuthenticationCredentials(client);
-      client.executeMethod(post);
-      int code = post.getStatusCode();
-      assertEquals(400, code);
-    }
-    catch (Exception e) {
-      e.printStackTrace();
-      fail("post failed");
-    } 
+  public void addEntryNoEmailOrValue() throws HttpException, IOException {
+    HttpClient client = new HttpClient();
+    PostMethod post = new PostMethod(APIKEY_SERVICE_LOCATION_VALID);
+    setAuthenticationCredentials(client);
+    client.executeMethod(post);
+    int code = post.getStatusCode();
+    assertEquals(400, code);
   }
 
+  /**
+   * Try to create a new API key that duplicates an existing one
+   * 
+   * @throws IOException
+   * @throws HttpException
+   */
   @Test
-  public void addDuplicateEntry(){
-    try {
-      HttpClient client = new HttpClient();
-      PostMethod post = new PostMethod(APIKEY_SERVICE_LOCATION_VALID);
-      setAuthenticationCredentials(client);
-      post.setParameter("apikey", "DUPLICATION_TEST");
-      post.setParameter("email", "test@127.0.0.1");
-      client.executeMethod(post);
-      int code = post.getStatusCode();
-      assertEquals(201, code);
-      client.executeMethod(post);
-      code = post.getStatusCode();
-      assertEquals(409, code);
-    }
-    catch (Exception e) {
-      e.printStackTrace();
-      fail("post failed");
-    }
+  public void addDuplicateEntry() throws HttpException, IOException {
+    //
+    // Create an API key
+    //
+    HttpClient client = new HttpClient();
+    PostMethod post = new PostMethod(APIKEY_SERVICE_LOCATION_VALID);
+    setAuthenticationCredentials(client);
+    post.setParameter("apikey", "DUPLICATION_TEST");
+    post.setParameter("email", "test@127.0.0.1");
+    client.executeMethod(post);
+    int code = post.getStatusCode();
+    assertEquals(201, code);
+    
+    //
+    // Replay the POST
+    //
+    client.executeMethod(post);
+    code = post.getStatusCode();
+    assertEquals(409, code);
   }
 
+  /**
+   * Complex test for migrating an API key. This test is disabled as there are
+   * issues implementing this functionality - for now, migration has been
+   * disabled in the REST API.
+   * 
+   * @throws IOException
+   * @throws HttpException
+   * @throws JDOMException
+   */
   @Test
   @Ignore
-  public void migrateAPIKey(){
-    
+  public void migrateAPIKey() throws HttpException, IOException, JDOMException {
+
     String keyId = null;
+    
+    //
     // Create a new key
-    try {
-      HttpClient client = new HttpClient();
-      PostMethod post = new PostMethod(APIKEY_SERVICE_LOCATION_VALID);
-      setAuthenticationCredentials(client);
-      post.setParameter("apikey", "MIGRATION_TEST_KEY_1");
-      post.setParameter("email", "test@incubator.apache.org");
-      client.executeMethod(post);
-      int code = post.getStatusCode();
-      assertEquals(201, code);
-
-      GetMethod get = new GetMethod(APIKEY_SERVICE_LOCATION_VALID);
-      setAuthenticationCredentials(client);
-      client.executeMethod(get);
-
-      // Get the ID
-      Document doc = new SAXBuilder().build(get.getResponseBodyAsStream());
-      for (Object key: doc.getRootElement().getChildren()){
-        Element keyElement = (Element)key;
-        if (keyElement.getAttributeValue("value").equals("MIGRATION_TEST_KEY_1")){
-          keyId = keyElement.getAttributeValue("id");
-        }
+    //
+    HttpClient client = new HttpClient();
+    PostMethod post = new PostMethod(APIKEY_SERVICE_LOCATION_VALID);
+    setAuthenticationCredentials(client);
+    post.setParameter("apikey", "MIGRATION_TEST_KEY_1");
+    post.setParameter("email", "test@incubator.apache.org");
+    client.executeMethod(post);
+    int code = post.getStatusCode();
+    assertEquals(201, code);
+    
+    //
+    // Get the ID
+    //
+    GetMethod get = new GetMethod(APIKEY_SERVICE_LOCATION_VALID);
+    setAuthenticationCredentials(client);
+    client.executeMethod(get);
+    Document doc = new SAXBuilder().build(get.getResponseBodyAsStream());
+    for (Object key : doc.getRootElement().getChildren()) {
+      Element keyElement = (Element) key;
+      if (keyElement.getAttributeValue("value").equals("MIGRATION_TEST_KEY_1")) {
+        keyId = keyElement.getAttributeValue("id");
       }
     }
-    catch (Exception e) {
-      e.printStackTrace();
-      fail("get failed");
-    }
 
+    //
     // Create a widget instance
-    String instance_id_key =  null;
-    try {
-      HttpClient client = new HttpClient();
-      PostMethod post = new PostMethod(TEST_INSTANCES_SERVICE_URL_VALID);
-      post.setQueryString("api_key=MIGRATION_TEST_KEY_1&widgetid="+WIDGET_ID_VALID+"&userid=test&shareddatakey=migration_test");
-      client.executeMethod(post);
-      int code = post.getStatusCode();
-      String response = post.getResponseBodyAsString();
-      instance_id_key = post.getResponseBodyAsString().substring(response.indexOf("<identifier>")+12, response.indexOf("</identifier>"));
-      assertEquals(201,code);
-      post.releaseConnection();
-    }
-    catch (Exception e) {
-      e.printStackTrace();
-      fail("post failed");
-    }
+    //
+    String instance_id_key = null;
+    client = new HttpClient();
+    post = new PostMethod(TEST_INSTANCES_SERVICE_URL_VALID);
+    post.setQueryString("api_key=MIGRATION_TEST_KEY_1&widgetid="
+        + WIDGET_ID_VALID + "&userid=test&shareddatakey=migration_test");
+    client.executeMethod(post);
+    code = post.getStatusCode();
+    String response = post.getResponseBodyAsString();
+    instance_id_key = post.getResponseBodyAsString().substring(
+        response.indexOf("<identifier>") + 12,
+        response.indexOf("</identifier>"));
+    assertEquals(201, code);
+    post.releaseConnection();
 
+    //
     // Set participant
-    try {
-      HttpClient client = new HttpClient();
-      PostMethod post = new PostMethod(TEST_PARTICIPANTS_SERVICE_URL_VALID);
-      post.setQueryString("api_key=MIGRATION_TEST_KEY_1&widgetid="+WIDGET_ID_VALID+"&userid=test&shareddatakey=migration_test&participant_id=1&participant_display_name=bob&participant_thumbnail_url=http://www.test.org");
-      client.executeMethod(post);
-      int code = post.getStatusCode();
-      assertEquals(201,code);
-      post.releaseConnection();
-    }
-    catch (Exception e) {
-      e.printStackTrace();
-      fail("post failed");
-    }
+    //
+    client = new HttpClient();
+    post = new PostMethod(TEST_PARTICIPANTS_SERVICE_URL_VALID);
+    post.setQueryString("api_key=MIGRATION_TEST_KEY_1&widgetid="
+        + WIDGET_ID_VALID
+        + "&userid=test&shareddatakey=migration_test&participant_id=1&participant_display_name=bob&participant_thumbnail_url=http://www.test.org");
+    client.executeMethod(post);
+    code = post.getStatusCode();
+    assertEquals(201, code);
+    post.releaseConnection();
 
+    //
     // Migrate key
-    try {
-      HttpClient client = new HttpClient();
-      PutMethod put = new PutMethod(APIKEY_SERVICE_LOCATION_VALID+"/"+keyId);
-      put.setQueryString("apikey=MIGRATION_TEST_KEY_2&email=test@127.0.0.1");
-      setAuthenticationCredentials(client);
-      client.executeMethod(put);
-      int code = put.getStatusCode();
-      assertEquals(200,code);
-      put.releaseConnection();
-    }
-    catch (Exception e) {
-      e.printStackTrace();
-      fail("post failed");
-    }
+    //
+    client = new HttpClient();
+    PutMethod put = new PutMethod(APIKEY_SERVICE_LOCATION_VALID + "/" + keyId);
+    put.setQueryString("apikey=MIGRATION_TEST_KEY_2&email=test@127.0.0.1");
+    setAuthenticationCredentials(client);
+    client.executeMethod(put);
+    code = put.getStatusCode();
+    assertEquals(200, code);
+    put.releaseConnection();
 
+    //
     // Get instance again using the new key - should be 200 not 201
-    try {
-      HttpClient client = new HttpClient();
-      PostMethod post = new PostMethod(TEST_INSTANCES_SERVICE_URL_VALID);
-      post.setQueryString("api_key=MIGRATION_TEST_KEY_2&widgetid="+WIDGET_ID_VALID+"&userid=test&shareddatakey=migration_test");
-      client.executeMethod(post);
-      int code = post.getStatusCode();
-      assertEquals(200,code);
-      post.releaseConnection();
-    }
-    catch (Exception e) {
-      e.printStackTrace();
-      fail("post failed");
-    }
+    //
+    client = new HttpClient();
+    post = new PostMethod(TEST_INSTANCES_SERVICE_URL_VALID);
+    post.setQueryString("api_key=MIGRATION_TEST_KEY_2&widgetid="
+        + WIDGET_ID_VALID + "&userid=test&shareddatakey=migration_test");
+    client.executeMethod(post);
+    code = post.getStatusCode();
+    assertEquals(200, code);
+    post.releaseConnection();
 
+    //
     // Get participant
-    try {
-      HttpClient client = new HttpClient();
-      GetMethod get = new GetMethod(TEST_PARTICIPANTS_SERVICE_URL_VALID);
-      get.setQueryString("api_key=MIGRATION_TEST_KEY_2&id_key="+instance_id_key);
-      client.executeMethod(get);
-      int code = get.getStatusCode();
-      assertEquals(200,code);
-      String response = get.getResponseBodyAsString();
-      assertTrue(response.contains("<participant id=\"1\" display_name=\"bob\" thumbnail_url=\"http://www.test.org\" />"));
-      get.releaseConnection();
-  }
-  catch (Exception e) {
-    e.printStackTrace();
-    fail("get failed");
-  }
-
+    //
+    client = new HttpClient();
+    get = new GetMethod(TEST_PARTICIPANTS_SERVICE_URL_VALID);
+    get.setQueryString("api_key=MIGRATION_TEST_KEY_2&id_key=" + instance_id_key);
+    client.executeMethod(get);
+    code = get.getStatusCode();
+    assertEquals(200, code);
+    response = get.getResponseBodyAsString();
+    assertTrue(response
+        .contains("<participant id=\"1\" display_name=\"bob\" thumbnail_url=\"http://www.test.org\" />"));
+    get.releaseConnection();
 
   }
 }

Modified: incubator/wookie/trunk/src-tests/org/apache/wookie/tests/functional/FlatpackControllerTest.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src-tests/org/apache/wookie/tests/functional/FlatpackControllerTest.java?rev=1154295&r1=1154294&r2=1154295&view=diff
==============================================================================
--- incubator/wookie/trunk/src-tests/org/apache/wookie/tests/functional/FlatpackControllerTest.java (original)
+++ incubator/wookie/trunk/src-tests/org/apache/wookie/tests/functional/FlatpackControllerTest.java Fri Aug  5 16:24:17 2011
@@ -14,8 +14,6 @@
 package org.apache.wookie.tests.functional;
 
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
-
 
 import java.io.IOException;
 
@@ -26,118 +24,165 @@ import org.apache.commons.httpclient.met
 import org.junit.BeforeClass;
 import org.junit.Test;
 
-
+/**
+ * Test cases for the flatpack feature. These tests try to pack and export
+ * widget instances and then verify that they were exported correctly
+ */
 public class FlatpackControllerTest extends AbstractControllerTest {
-	
-	private static final String TEST_FLATPACK_SERVICE_URL_VALID = TEST_SERVER_LOCATION+"flatpack";
-	private static final String TEST_EXPORT_SERVICE_URL_VALID = TEST_SERVER_LOCATION+"export";
-	private static final String TEST_WIDGET_ID_JQM = "http://wookie.apache.org/widgets/freeder";
-	private static String test_id_key = "";
-	
-	@BeforeClass
-	public static void setup() throws HttpException, IOException{
-        HttpClient client = new HttpClient();
-        PostMethod post = new PostMethod(TEST_INSTANCES_SERVICE_URL_VALID);
-        post.setQueryString("api_key="+API_KEY_VALID+"&widgetid="+WIDGET_ID_VALID+"&userid=FPtest&shareddatakey=test");
-        client.executeMethod(post);
-        test_id_key = post.getResponseBodyAsString().substring(post.getResponseBodyAsString().indexOf("<identifier>")+12,post.getResponseBodyAsString().indexOf("</identifier>"));
-        post.releaseConnection();
-        
-        post = new PostMethod(TEST_INSTANCES_SERVICE_URL_VALID);
-        post.setQueryString("api_key="+API_KEY_VALID+"&widgetid="+TEST_WIDGET_ID_JQM+"&userid=FPtest&shareddatakey=test");
-        client.executeMethod(post);
-        post.releaseConnection();
-	}
-	
-	// Test that you can't get a directory listing of exported widgets
-	@Test
-	public void sniff(){
-		try {
-	        HttpClient client = new HttpClient();
-	        GetMethod get = new GetMethod(TEST_EXPORT_SERVICE_URL_VALID);
-	        client.executeMethod(get);
-	        int code = get.getStatusCode();
-	        if (code != 404){
-	        	String html = get.getResponseBodyAsString();
-	        	System.out.println(html);
-	        	assertEquals(html.length(), 0);
-	        }
-	    }
-	    catch (Exception e) {
-	    	e.printStackTrace();
-	    	fail("post failed");
-	    }
-	}
-	
-	@Test
-	public void getPack(){
-	    try {
-	        HttpClient client = new HttpClient();
-	        PostMethod post = new PostMethod(TEST_FLATPACK_SERVICE_URL_VALID);
-	        post.setQueryString("api_key="+API_KEY_VALID+"&widgetid="+WIDGET_ID_VALID+"&userid=FPtest&shareddatakey=test");
-	        client.executeMethod(post);
-	        int code = post.getStatusCode();
-	        assertEquals(200,code);
-	        String url = post.getResponseBodyAsString();
-	        post.releaseConnection();
-	        
-	        // Now lets try to download it!
-	        GetMethod get = new GetMethod(url);
-	        client.executeMethod(get);
-	        code = get.getStatusCode();
-	        assertEquals(200, code);
-	    }
-	    catch (Exception e) {
-	    	e.printStackTrace();
-	    	fail("post failed");
-	    }
-	}
-	
-	 @Test
-	  public void getPackUsingResourceId(){
-	      try {
-	          HttpClient client = new HttpClient();
-	          PostMethod post = new PostMethod(TEST_FLATPACK_SERVICE_URL_VALID+"/"+test_id_key);
-	          post.setQueryString("api_key="+API_KEY_VALID);
-	          client.executeMethod(post);
-	          int code = post.getStatusCode();
-	          assertEquals(200,code);
-	          String url = post.getResponseBodyAsString();
-	          post.releaseConnection();
-	          
-	          // Now lets try to download it!
-	          GetMethod get = new GetMethod(url);
-	          client.executeMethod(get);
-	          code = get.getStatusCode();
-	          assertEquals(200, code);
-	      }
-	      catch (Exception e) {
-	        e.printStackTrace();
-	        fail("post failed");
-	      }
-	  }
-	 
-	  @Test
-	  public void getPackUsingFlattenedFeature(){
-	      try {
-	          HttpClient client = new HttpClient();
-	          PostMethod post = new PostMethod(TEST_FLATPACK_SERVICE_URL_VALID);
-	          post.setQueryString("api_key="+API_KEY_VALID+"&widgetid="+TEST_WIDGET_ID_JQM+"&userid=FPtest&shareddatakey=test");
-	          client.executeMethod(post);
-	          int code = post.getStatusCode();
-	          assertEquals(200,code);
-	          String url = post.getResponseBodyAsString();
-	          post.releaseConnection();
-	          
-	          // Now lets try to download it!
-	          GetMethod get = new GetMethod(url);
-	          client.executeMethod(get);
-	          code = get.getStatusCode();
-	          assertEquals(200, code);
-	      }
-	      catch (Exception e) {
-	        e.printStackTrace();
-	        fail("post failed");
-	      }
-	  }
+
+  private static final String TEST_FLATPACK_SERVICE_URL_VALID = TEST_SERVER_LOCATION
+      + "flatpack";
+  private static final String TEST_EXPORT_SERVICE_URL_VALID = TEST_SERVER_LOCATION
+      + "export";
+  private static final String TEST_WIDGET_ID_JQM = "http://wookie.apache.org/widgets/freeder";
+  private static String test_id_key = "";
+
+  /**
+   * Create widget instances to use for testing purposes
+   * 
+   * @throws HttpException
+   * @throws IOException
+   */
+  @BeforeClass
+  public static void setup() throws HttpException, IOException {
+
+    //
+    // Create basic widget test instance
+    //
+    HttpClient client = new HttpClient();
+    PostMethod post = new PostMethod(TEST_INSTANCES_SERVICE_URL_VALID);
+    post.setQueryString("api_key=" + API_KEY_VALID + "&widgetid="
+        + WIDGET_ID_VALID + "&userid=FPtest&shareddatakey=test");
+    client.executeMethod(post);
+    test_id_key = post.getResponseBodyAsString().substring(
+        post.getResponseBodyAsString().indexOf("<identifier>") + 12,
+        post.getResponseBodyAsString().indexOf("</identifier>"));
+    post.releaseConnection();
+
+    //
+    // Create a test instance of a widget that uses JQuery Mobile as a feature
+    //
+    post = new PostMethod(TEST_INSTANCES_SERVICE_URL_VALID);
+    post.setQueryString("api_key=" + API_KEY_VALID + "&widgetid="
+        + TEST_WIDGET_ID_JQM + "&userid=FPtest&shareddatakey=test");
+    client.executeMethod(post);
+    post.releaseConnection();
+  }
+
+  /**
+   * Test that you can't get a directory listing of exported widgets
+   * 
+   * @throws IOException
+   * @throws HttpException
+   */
+  @Test
+  public void sniff() throws HttpException, IOException {
+    HttpClient client = new HttpClient();
+    GetMethod get = new GetMethod(TEST_EXPORT_SERVICE_URL_VALID);
+    client.executeMethod(get);
+    int code = get.getStatusCode();
+    if (code != 404) {
+      String html = get.getResponseBodyAsString();
+      System.out.println(html);
+      assertEquals(html.length(), 0);
+    }
+
+  }
+
+  /**
+   * Tests exporting a simple widget instance
+   * 
+   * @throws IOException
+   * @throws HttpException
+   */
+  @Test
+  public void getPack() throws HttpException, IOException {
+
+    //
+    // Create the export package
+    //
+    HttpClient client = new HttpClient();
+    PostMethod post = new PostMethod(TEST_FLATPACK_SERVICE_URL_VALID);
+    post.setQueryString("api_key=" + API_KEY_VALID + "&widgetid="
+        + WIDGET_ID_VALID + "&userid=FPtest&shareddatakey=test");
+    client.executeMethod(post);
+    int code = post.getStatusCode();
+    assertEquals(200, code);
+    String url = post.getResponseBodyAsString();
+    post.releaseConnection();
+
+    //
+    // Now lets try to download it!
+    //
+    GetMethod get = new GetMethod(url);
+    client.executeMethod(get);
+    code = get.getStatusCode();
+    assertEquals(200, code);
+  }
+
+  /**
+   * Create an export using a more RESTful pattern
+   * 
+   * @throws IOException
+   * @throws HttpException
+   */
+  @Test
+  public void getPackUsingResourceId() throws HttpException, IOException {
+
+    //
+    // Create the export package
+    //
+    HttpClient client = new HttpClient();
+    PostMethod post = new PostMethod(TEST_FLATPACK_SERVICE_URL_VALID + "/"
+        + test_id_key);
+    post.setQueryString("api_key=" + API_KEY_VALID);
+    client.executeMethod(post);
+    int code = post.getStatusCode();
+    assertEquals(200, code);
+    String url = post.getResponseBodyAsString();
+    post.releaseConnection();
+
+    //
+    // Now lets try to download it!
+    //
+    GetMethod get = new GetMethod(url);
+    client.executeMethod(get);
+    code = get.getStatusCode();
+    assertEquals(200, code);
+  }
+
+  /**
+   * Tests that "flattening" works when exporting a widget instance. This means
+   * that features like JQuery Mobile are replaced by directly including their
+   * scripts within the exported package, removing the <feature> element from
+   * config.xml
+   * 
+   * @throws IOException
+   * @throws HttpException
+   */
+  @Test
+  public void getPackUsingFlattenedFeature() throws HttpException, IOException {
+
+    //
+    // Create the export package
+    //
+    HttpClient client = new HttpClient();
+    PostMethod post = new PostMethod(TEST_FLATPACK_SERVICE_URL_VALID);
+    post.setQueryString("api_key=" + API_KEY_VALID + "&widgetid="
+        + TEST_WIDGET_ID_JQM + "&userid=FPtest&shareddatakey=test");
+    client.executeMethod(post);
+    int code = post.getStatusCode();
+    assertEquals(200, code);
+    String url = post.getResponseBodyAsString();
+    post.releaseConnection();
+
+    //
+    // Now lets try to download it!
+    //
+    GetMethod get = new GetMethod(url);
+    client.executeMethod(get);
+    code = get.getStatusCode();
+    assertEquals(200, code);
+
+  }
 }



Mime
View raw message