Return-Path: X-Original-To: apmail-manifoldcf-commits-archive@www.apache.org Delivered-To: apmail-manifoldcf-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 6ED70FC99 for ; Sat, 23 Mar 2013 08:28:07 +0000 (UTC) Received: (qmail 73313 invoked by uid 500); 23 Mar 2013 08:28:07 -0000 Delivered-To: apmail-manifoldcf-commits-archive@manifoldcf.apache.org Received: (qmail 73213 invoked by uid 500); 23 Mar 2013 08:28:04 -0000 Mailing-List: contact commits-help@manifoldcf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@manifoldcf.apache.org Delivered-To: mailing list commits@manifoldcf.apache.org Received: (qmail 73195 invoked by uid 99); 23 Mar 2013 08:28:03 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 23 Mar 2013 08:28:03 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 23 Mar 2013 08:28:02 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 1EFEF23888FE; Sat, 23 Mar 2013 08:27:42 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1460117 - /manifoldcf/integration/elasticsearch/trunk/src/test/java/org/apache/manifoldcf/elasticsearch/MCFAuthorizerTest.java Date: Sat, 23 Mar 2013 08:27:42 -0000 To: commits@manifoldcf.apache.org From: kwright@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20130323082742.1EFEF23888FE@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: kwright Date: Sat Mar 23 08:27:41 2013 New Revision: 1460117 URL: http://svn.apache.org/r1460117 Log: Add index creation code to test. Modified: manifoldcf/integration/elasticsearch/trunk/src/test/java/org/apache/manifoldcf/elasticsearch/MCFAuthorizerTest.java Modified: manifoldcf/integration/elasticsearch/trunk/src/test/java/org/apache/manifoldcf/elasticsearch/MCFAuthorizerTest.java URL: http://svn.apache.org/viewvc/manifoldcf/integration/elasticsearch/trunk/src/test/java/org/apache/manifoldcf/elasticsearch/MCFAuthorizerTest.java?rev=1460117&r1=1460116&r2=1460117&view=diff ============================================================================== --- manifoldcf/integration/elasticsearch/trunk/src/test/java/org/apache/manifoldcf/elasticsearch/MCFAuthorizerTest.java (original) +++ manifoldcf/integration/elasticsearch/trunk/src/test/java/org/apache/manifoldcf/elasticsearch/MCFAuthorizerTest.java Sat Mar 23 08:27:41 2013 @@ -23,6 +23,8 @@ import org.elasticsearch.common.settings import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.network.NetworkUtils; import org.elasticsearch.common.unit.TimeValue; +import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.node.Node; @@ -41,6 +43,8 @@ import javax.servlet.http.HttpServletRes import java.io.IOException; import java.util.Map; import java.util.HashMap; +import java.util.List; +import java.util.ArrayList; import static org.elasticsearch.client.Requests.*; import static org.elasticsearch.index.query.QueryBuilders.*; @@ -73,18 +77,58 @@ public class MCFAuthorizerTest } @BeforeClass - public void startNodes() { + public void startNodes() throws IOException { startNode("server", nodeSettings()); client = getClient(); + createIndex(); } - protected void createIndex() { + protected void createIndex() + throws IOException { try { client.admin().indices().prepareDelete("test").execute().actionGet(); } catch (Exception e) { // ignore } + + // Question: We need the equivalent of default field values. How do we set that in ElasticSearch? + // MHL client.admin().indices().create(createIndexRequest("test")).actionGet(); + // | share | document + // |--------------|-------------- + // | allow | deny | allow | deny + // ------------+-------+------+-------+------ + // da12 | | | 1, 2 | + // ------------+-------+------+-------+------ + // da13-dd3 | | | 1,3 | 3 + // ------------+-------+------+-------+------ + // sa123-sd13 | 1,2,3 | 1, 3 | | + // ------------+-------+------+-------+------ + // sa3-sd1-da23| 3 | 1 | 2,3 | + // ------------+-------+------+-------+------ + // notoken | | | | + // ------------+-------+------+-------+------ + // + addDoc("id", "da12", + "allow_token_document", "token1", + "allow_token_document", "token2"); + addDoc("id", "da13-dd3", + "allow_token_document", "token1", + "allow_token_document", "token3", + "deny_token_document", "token3"); + addDoc("id", "sa123-sd13", + "allow_token_share", "token1", + "allow_token_share", "token2", + "allow_token_share", "token3", + "deny_token_share", "token1", + "deny_token_share", "token3"); + addDoc("id", "sa3-sd1-da23", + "allow_token_document", "token2", + "allow_token_document", "token3", + "allow_token_share", "token3", + "deny_token_share", "token1"); + addDoc("id", "notoken"); + commit(); } protected Settings nodeSettings() { @@ -95,6 +139,21 @@ public class MCFAuthorizerTest return "test"; } + protected void addDoc(String id, String docID, + String... argPairs) + throws IOException + { + client.prepareIndex().setIndex("test") + .setType("type1").setId(id) + .setSource(source(id,argPairs)) + .setRefresh(true).execute().actionGet(); + } + + protected void commit() + { + client.admin().indices().prepareRefresh("test").execute().actionGet(); + } + @AfterClass public void closeNodes() { client.close(); @@ -105,6 +164,37 @@ public class MCFAuthorizerTest return client("server"); } + private static XContentBuilder source(String id, String... argPairs) throws IOException { + XContentBuilder builder = XContentFactory.jsonBuilder() + .startObject() + .startObject("type1").field("id", id); + + Map> allValues = new HashMap>(); + + int pairCount = argPairs.length >> 1; + for (int i = 0; i < pairCount; i++) + { + String fieldName = argPairs[i*2]; + String fieldValue = argPairs[i*2+1]; + List values = allValues.get(fieldName); + if (values == null) + { + values = new ArrayList(); + allValues.put(fieldName,values); + } + values.add(fieldValue); + } + + for (String fieldName : allValues.keySet()) + { + builder.field(fieldName, allValues.get(fieldName).toArray(new String[0])); + } + + builder.endObject() + .endObject(); + return builder; + } + static class MockMCFAuthorityService { Server server;