Index: src/test/java/org/apache/jackrabbit/core/query/JoinTest.java
===================================================================
--- src/test/java/org/apache/jackrabbit/core/query/JoinTest.java	(revision 1082945)
+++ src/test/java/org/apache/jackrabbit/core/query/JoinTest.java	(working copy)
@@ -16,11 +16,10 @@
  */
 package org.apache.jackrabbit.core.query;
 
+import static javax.jcr.query.Query.JCR_SQL2;
 import javax.jcr.Node;
 import javax.jcr.PropertyType;
 import javax.jcr.nodetype.NodeType;
-import javax.jcr.query.Query;
-import javax.jcr.query.QueryResult;
 
 /**
  * Test case for JOIN queries with JCR_SQL2
@@ -62,25 +61,27 @@
      * href="https://issues.apache.org/jira/browse/JCR-2718">JCR-2718</a>
      */
     public void testMultiValuedReferenceJoin() throws Exception {
-        String join = "SELECT a.*, b.*" + " FROM [nt:base] AS a"
-                + " INNER JOIN [nt:base] AS b ON a.[jcr:uuid] = b.testref";
-        checkResult(qm.createQuery(join, Query.JCR_SQL2).execute(), 2);
+        StringBuilder join = new StringBuilder();
+        join.append(" SELECT a.*, b.* ");
+        join.append("  FROM [nt:base] AS a ");
+        join.append("  INNER JOIN [nt:base] AS b ON a.[jcr:uuid] = b.testref ");
+        checkResult(qm.createQuery(join.toString(), JCR_SQL2).execute(), 2);
     }
 
     /**
+     * Test INNER JOIN with OR condition
+     * 
      * Test case for <a
      * href="https://issues.apache.org/jira/browse/JCR-2852">JCR-2852</a>
      */
     public void testJoinWithOR() throws Exception {
-
-        String join = "SELECT a.*, b.*"
-                + " FROM [nt:base] AS a"
-                + " INNER JOIN [nt:base] AS b ON a.[jcr:uuid] = b.testref WHERE "
-                + "a.[jcr:primaryType] IS NOT NULL OR b.[jcr:primaryType] IS NOT NULL";
-
-        Query q = qm.createQuery(join, Query.JCR_SQL2);
-        QueryResult result = q.execute();
-        checkResult(result, 2);
+        StringBuilder join = new StringBuilder();
+        join.append(" SELECT a.*, b.* ");
+        join.append("  FROM [nt:base] AS a ");
+        join.append("  INNER JOIN [nt:base] AS b ON a.[jcr:uuid] = b.testref ");
+        join.append(" WHERE ");
+        join.append(" a.[jcr:primaryType] IS NOT NULL OR b.[jcr:primaryType] IS NOT NULL ");
+        checkResult(qm.createQuery(join.toString(), JCR_SQL2).execute(), 2);
     }
 
     /**
@@ -88,25 +89,27 @@
      * href="https://issues.apache.org/jira/browse/JCR-2852">JCR-2852</a> <br>
      * <p>
      * Test inspired by <a
-     * href="http://markmail.org/message/gee5yyygozestsml">this discussion</a>
+     * href="http://markmail.org/message/gee5yyygozestsml">this discussion</a>:
+     * 
+     * <pre>
+     * WHERE
+     * ( (ISSAMENODE(projects,
+     * '/repository/projects/U970f5509-54de-46d8-88bd-bc1a94ab85eb')))
+     * AND
+     * ( ( ISDESCENDANTNODE( projects, '/repository/projects') AND
+     * eventclassassociations.active = true )
+     * or
+     * ( ISDESCENDANTNODE( projects, '/repository/template') )
+     * )
+     * AND ((NAME(parentRelationshipStatus) = 'parentRelationshipStatus'))
+     * </pre>
      */
     public void testMegaJoin() throws Exception {
-
-        // WHERE
-        // ( (ISSAMENODE(projects,
-        // '/repository/projects/U970f5509-54de-46d8-88bd-bc1a94ab85eb')))
-        // AND
-        // ( ( ISDESCENDANTNODE( projects, '/repository/projects') AND
-        // eventclassassociations.active = true )
-        // or
-        // ( ISDESCENDANTNODE( projects, '/repository/template') )
-        // )
-        // AND ((NAME(parentRelationshipStatus) = 'parentRelationshipStatus'))
-
-        StringBuilder join = new StringBuilder(
-                "SELECT a.*, b.* FROM [nt:base] AS a");
+        StringBuilder join = new StringBuilder();
+        join.append(" SELECT a.*, b.* ");
+        join.append("  FROM [nt:base] AS a ");
         join.append("  INNER JOIN [nt:base] AS b ON a.[jcr:uuid] = b.testref ");
-        join.append("  WHERE  ");
+        join.append(" WHERE ");
         join.append("  ISSAMENODE(b, '/testroot/jointest/node3') ");
         join.append("  AND ");
         join.append("  ( ");
@@ -120,10 +123,23 @@
         join.append("  ) ");
         join.append("  AND ");
         join.append(" (NAME(b) = 'node3') ");
-
-        Query q = qm.createQuery(join.toString(), Query.JCR_SQL2);
-        QueryResult result = q.execute();
-        checkResult(result, 2);
+        checkResult(qm.createQuery(join.toString(), JCR_SQL2).execute(), 2);
     }
 
+    /**
+     * Test OUTER JOIN
+     * 
+     * Test case for <a
+     * href="https://issues.apache.org/jira/browse/JCR-2852">JCR-2852</a>
+     * 
+     */
+    public void testOuterJoinWithOR() throws Exception {
+        StringBuilder join = new StringBuilder();
+        join.append(" SELECT a.*, b.* ");
+        join.append("  FROM [nt:base] AS a ");
+        join.append("  LEFT OUTER JOIN [nt:base] AS b ON a.[jcr:uuid] = b.testref ");
+        join.append(" WHERE ");
+        join.append("  ISDESCENDANTNODE(a, '/testroot/jointest') ");
+        checkResult(qm.createQuery(join.toString(), JCR_SQL2).execute(), 3);
+    }
 }
