integrated itest into the build and simplified Activator to not use human interaction

git-svn-id: https://svn.apache.org/repos/asf/incubator/felix/trunk@432331 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/examples/dictionaryservice.itest/pom.xml b/examples/dictionaryservice.itest/pom.xml
index 6b46c85..0942b9d 100644
--- a/examples/dictionaryservice.itest/pom.xml
+++ b/examples/dictionaryservice.itest/pom.xml
@@ -21,9 +21,38 @@
       <version>${pom.version}</version>
       <scope>provided</scope>
     </dependency>
+
+    <!-- Added to test exclusions: its not a bundle so we want to exclude it -->
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>3.8.1</version>
+      <scope>provided</scope>
+    </dependency>
+    
   </dependencies>
   <build>
     <plugins>
+    
+      <plugin>
+        <groupId>org.apache.felix.plugins</groupId>
+        <artifactId>maven-felix-plugin</artifactId>
+        <executions>
+          <execution>
+             <id>run</id>
+             <configuration>
+               <felixCacheDir>${basedir}/target/.felix</felixCacheDir>
+               <exclusions>
+                 <exclusion>junit:junit</exclusion>
+               </exclusions>
+             </configuration>
+             <goals>
+               <goal>run</goal>
+             </goals>
+          </execution>
+        </executions>
+      </plugin>
+    
       <plugin>
         <groupId>org.apache.felix.plugins</groupId>
         <artifactId>maven-osgi-plugin</artifactId>
diff --git a/examples/dictionaryservice.itest/src/main/java/org/apache/felix/examples/dictionaryservice/itest/Activator.java b/examples/dictionaryservice.itest/src/main/java/org/apache/felix/examples/dictionaryservice/itest/Activator.java
index 74b52f0..6aa733c 100644
--- a/examples/dictionaryservice.itest/src/main/java/org/apache/felix/examples/dictionaryservice/itest/Activator.java
+++ b/examples/dictionaryservice.itest/src/main/java/org/apache/felix/examples/dictionaryservice/itest/Activator.java
@@ -17,10 +17,6 @@
 package org.apache.felix.examples.dictionaryservice.itest;
 
 
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
-
 import org.apache.felix.examples.dictionaryservice.DictionaryService;
 
 import org.osgi.framework.BundleActivator;
@@ -29,14 +25,9 @@
 
 
 /**
- * This class implements a bundle that uses a dictionary service to check for
- * the proper spelling of a word by check for its existence in the dictionary.
- * This bundle uses the first service that it finds and does not monitor the
- * dynamic availability of the service (i.e., it does not listen for the arrival
- * or departure of dictionary services). When starting this bundle, the thread
- * calling the start() method is used to read words from standard input. You can
- * stop checking words by entering an empty line, but to start checking words
- * again you must stop and then restart the bundle.
+ * This Activator grabs a handle on a dictionary service to check for 
+ * correct operation of the dictionary while it is running inside felix.
+ * This is an integration test of the dictionaryservice bundle.
  * 
  * @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
  */
@@ -44,11 +35,8 @@
 {
     /**
      * Implements BundleActivator.start(). Queries for all available dictionary
-     * services. If none are found it simply prints a message and returns,
-     * otherwise it reads words from standard input and checks for their
-     * existence from the first dictionary that it finds. (NOTE: It is very bad
-     * practice to use the calling thread to perform a lengthy process like
-     * this; this is only done for the purpose of the tutorial.)
+     * services. If none are found it blows chunks, otherwise it checks for the
+     * existence of the words in the first dictionary that it finds.
      * 
      * @param context the framework context for the bundle.
      */
@@ -59,52 +47,38 @@
 
         if ( refs != null )
         {
-            try
-            {
-                System.out.println( "Enter a blank line to exit." );
-                BufferedReader in = new BufferedReader( new InputStreamReader( System.in ) );
-                String word = "";
-
-                // Loop endlessly.
-                while ( true )
-                {
-                    // Ask the user to enter a word.
-                    System.out.print( "Enter word: " );
-                    word = in.readLine();
-
-                    // If the user entered a blank line, then
-                    // exit the loop.
-                    if ( word.length() == 0 )
-                    {
-                        break;
-                    }
-
-                    // First, get a dictionary service and then check
-                    // if the word is correct.
-                    DictionaryService dictionary = ( DictionaryService ) context.getService( refs[0] );
-                    if ( dictionary.checkWord( word ) )
-                    {
-                        System.out.println( "Correct." );
-                    }
-                    else
-                    {
-                        System.out.println( "Incorrect." );
-                    }
-
-                    // Unget the dictionary service.
-                    context.ungetService( refs[0] );
-                }
-            }
-            catch ( IOException ex )
-            {
-            }
+            // First, get a dictionary service and then check if the word is correct.
+            DictionaryService dictionary = ( DictionaryService ) context.getService( refs[0] );
+            assertTrue( "welcome definition presence", dictionary.checkWord( "welcome" ) );
+            assertFalse( "blah definition absense", dictionary.checkWord( "blah" ) );
+            
+            // Unget the dictionary service.
+            context.ungetService( refs[0] );
         }
         else
         {
-            System.out.println( "Couldn't find any dictionary service..." );
+            throw new RuntimeException( "I need a dictionary service to test it properly." );
         }
     }
 
+    
+    public void assertTrue( String msg, boolean isTrue )
+    {
+        if ( ! isTrue )
+        {
+            throw new RuntimeException( msg + " expected to be true but was false." );
+        }
+    }
+    
+
+    public void assertFalse( String msg, boolean isFalse )
+    {
+        if ( isFalse )
+        {
+            throw new RuntimeException( msg + " expected to be false but was true." );
+        }
+    }
+    
 
     /**
      * Implements BundleActivator.stop(). Does nothing since the framework will
diff --git a/examples/pom.xml b/examples/pom.xml
index 439e82c..1500f9b 100644
--- a/examples/pom.xml
+++ b/examples/pom.xml
@@ -12,6 +12,7 @@
   <modules>
     <module>eventlistener</module>
     <module>dictionaryservice</module>
+    <module>dictionaryservice.itest</module>
     <module>frenchdictionary</module>
     <module>dictionaryclient</module>
     <module>dictionaryclient2</module>