Add PrologIT.java to test Prolog rules.

Only trivial existence and default tests for now.

Change-Id: Ifff5cd36c85b9344079357f1c281175185ff74a6
diff --git a/BUILD b/BUILD
index c567c29..90957b5 100644
--- a/BUILD
+++ b/BUILD
@@ -41,6 +41,7 @@
   tags = ['findowners'],
   deps = PLUGIN_DEPS + [
     ':find-owners-lib',
+    ':find-owners-prolog-rules',
     '//gerrit-acceptance-framework:lib',
   ],
 )
diff --git a/src/test/java/com/googlesource/gerrit/plugins/findowners/PrologIT.java b/src/test/java/com/googlesource/gerrit/plugins/findowners/PrologIT.java
new file mode 100644
index 0000000..c095112
--- /dev/null
+++ b/src/test/java/com/googlesource/gerrit/plugins/findowners/PrologIT.java
@@ -0,0 +1,97 @@
+// Copyright (C) 2017 The Android Open Source Project
+//
+// Licensed 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 com.googlesource.gerrit.plugins.findowners;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import com.google.gerrit.acceptance.GitUtil;
+import com.google.gerrit.acceptance.LightweightPluginDaemonTest;
+import com.google.gerrit.acceptance.PushOneCommit;
+import com.google.gerrit.acceptance.Sandboxed;
+import com.google.gerrit.acceptance.TestPlugin;
+import com.google.gerrit.reviewdb.client.RefNames;
+import find_owners.PRED_add_may_label_2;
+import find_owners.PRED_check_owner_approval_2;
+import find_owners.PRED_remove_may_label_2;
+import find_owners.PRED_remove_need_label_2;
+import find_owners.PRED_submit_filter_2;
+import find_owners.PRED_submit_filter_3;
+import find_owners.PRED_submit_rule_1;
+import find_owners.PRED_submit_rule_2;
+import org.eclipse.jgit.revwalk.RevCommit;
+import org.junit.Test;
+
+/** Test existence of compiled find-owners plugin Prolog predicates. */
+@TestPlugin(name = "find-owners", sysModule = "com.googlesource.gerrit.plugins.findowners.Module")
+public class PrologIT extends LightweightPluginDaemonTest {
+  // This class now only tests existence of compiled Prolog predicates.
+  // Later we can test the functionality of the predicates.
+
+  @Test
+  public void predefinedPredicateTest() throws Exception {
+    Object term = new PRED_check_owner_approval_2(null, null, null);
+    assertThat(term).isNotNull();
+  }
+
+  @Test
+  public void compiledPredicateTest() throws Exception {
+    Object term = new PRED_submit_rule_1(null, null);
+    assertThat(term).isNotNull();
+    term = new PRED_submit_rule_2(null, null, null);
+    assertThat(term).isNotNull();
+    term = new PRED_submit_filter_2(null, null, null);
+    assertThat(term).isNotNull();
+    term = new PRED_submit_filter_3(null, null, null, null);
+    assertThat(term).isNotNull();
+    term = new PRED_add_may_label_2(null, null, null);
+    assertThat(term).isNotNull();
+    term = new PRED_remove_may_label_2(null, null, null);
+    assertThat(term).isNotNull();
+    term = new PRED_remove_need_label_2(null, null, null);
+    assertThat(term).isNotNull();
+  }
+
+  @Sandboxed
+  @Test
+  public void submitRuleTest() throws Exception {
+    RevCommit oldHead = getRemoteHead();
+    GitUtil.fetch(testRepo, RefNames.REFS_CONFIG + ":config");
+    testRepo.reset("config");
+    PushOneCommit push =
+        pushFactory.create(
+            db,
+            admin.getIdent(),
+            testRepo,
+            "Configure",
+            "rules.pl",
+            "submit_rule(submit(R)) :- \n"
+                + "gerrit:default_submit(S0),\n"
+                + "find_owners:submit_rule(S1),\n"
+                + "find_owners:submit_filter(S1, S2), !,\n"
+                + "S1 = S2,\n" // find_owners:submit_filter does nothing
+                + "S0 \\= S1,\n" // find_owners:submit_rule adds 'may(_)'
+                + "find_owners:remove_may_label(S1, S3),\n"
+                + "S0 = S3,\n" // find_owners:submit_rule only adds 'may(_)'
+                + "gerrit:commit_author(A), \n"
+                + "R = label('Code-Review', ok(A)).\n");
+    push.to(RefNames.REFS_CONFIG);
+    testRepo.reset(oldHead);
+    oldHead = getRemoteHead();
+    PushOneCommit.Result result =
+        pushFactory.create(db, user.getIdent(), testRepo).to("refs/for/master");
+    testRepo.reset(oldHead);
+    gApi.changes().id(result.getChangeId()).current().submit();
+  }
+}