refactored junk main test into junit test


git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@919371 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/sigil/common/osgi.test/.classpath b/sigil/common/osgi.test/.classpath
new file mode 100644
index 0000000..c9ffd60
--- /dev/null
+++ b/sigil/common/osgi.test/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" path="src"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+	<classpathentry kind="con" path="org.apache.felix.sigil.classpathContainer"/>
+	<classpathentry kind="output" path="build/classes"/>
+</classpath>
diff --git a/sigil/common/osgi.test/.project b/sigil/common/osgi.test/.project
new file mode 100644
index 0000000..a183385
--- /dev/null
+++ b/sigil/common/osgi.test/.project
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>org.apache.felix.sigil.common.osgi.test</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.apache.felix.sigil.eclipse.core.sigilBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.apache.felix.sigil.sigilnature</nature>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+	</natures>
+</projectDescription>
diff --git a/sigil/common/osgi.test/sigil.properties b/sigil/common/osgi.test/sigil.properties
new file mode 100644
index 0000000..36662f6
--- /dev/null
+++ b/sigil/common/osgi.test/sigil.properties
@@ -0,0 +1,16 @@
+
+# sigil project file, saved by plugin.
+
+-bundles: \
+	org.apache.felix.sigil.common.osgi.test, \
+
+-sourcedirs: \
+	src, \
+
+-fragment: \
+	org.apache.felix.sigil.common.osgi;version=0.9.0, \
+
+-imports: \
+	junit.framework;version=3.8.2, \
+
+# end
diff --git a/sigil/common/osgi.test/src/org/apache/felix/sigil/common/osgi/LDAPParserTest.java b/sigil/common/osgi.test/src/org/apache/felix/sigil/common/osgi/LDAPParserTest.java
new file mode 100644
index 0000000..f0720a3
--- /dev/null
+++ b/sigil/common/osgi.test/src/org/apache/felix/sigil/common/osgi/LDAPParserTest.java
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.felix.sigil.common.osgi;
+
+import junit.framework.TestCase;
+
+public class LDAPParserTest extends TestCase
+{
+    private static final SimpleTerm A_B = new SimpleTerm( "a", Ops.EQ, "b" );
+    private static final SimpleTerm C_D = new SimpleTerm( "c", Ops.EQ, "d" );
+    
+    public void testSimple() {
+        LDAPExpr expr = LDAPParser.parseExpression( "(a=b)" );
+        assertEquals( expr, A_B );
+    }
+
+    public void testSimpleWhiteSpace() {
+        LDAPExpr expr = LDAPParser.parseExpression( "  ( a = b )  " );
+        assertEquals( expr, A_B );
+    }
+    
+    public void testNot() {
+        LDAPExpr expr = LDAPParser.parseExpression( "(!(a=b))" );
+        assertEquals( expr, Not.apply(A_B));
+    }
+    
+    public void testAnd() {
+        LDAPExpr expr = LDAPParser.parseExpression( "(&(a=b)(c=d))" );
+        assertEquals( expr, And.apply(A_B, C_D) );
+    }
+    
+    public void testOr() {
+        LDAPExpr expr = LDAPParser.parseExpression( "(|(a=b)(c=d))" );
+        assertEquals( expr, Or.apply(A_B, C_D) );
+    }
+    
+    public void testParseException() {
+        try {
+            LDAPExpr expr = LDAPParser.parseExpression( ".(a=b)" );
+            fail( "Unexpectedly parsed invalid ldap expr " + expr);
+        }
+        catch (LDAPParseException e) {
+            // expected
+        }
+    }
+}
diff --git a/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/LDAPParser.java b/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/LDAPParser.java
index 11086dd..aa0056a 100644
--- a/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/LDAPParser.java
+++ b/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/LDAPParser.java
@@ -45,24 +45,6 @@
         return parser.parse( strExpr );
     }
 
-
-    public static void main( String[] args )
-    {
-        for ( String arg : args )
-        {
-            try
-            {
-                System.out.println( parseExpression( arg ) );
-            }
-            catch ( LDAPParseException e )
-            {
-                System.out.println( "Failed to parse " + arg );
-                e.printStackTrace();
-            }
-        }
-    }
-
-
     public LDAPExpr parse( String strExpr ) throws LDAPParseException
     {