You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@manifoldcf.apache.org by kw...@apache.org on 2014/01/09 01:38:23 UTC

svn commit: r1556684 - in /manifoldcf/branches/CONNECTORS-840/connectors/solr/connector/src/test/java/org/apache/manifoldcf/agents/output/solr: HttpPosterTest.java IngestThreadTest.java SolrConnectorTest.java

Author: kwright
Date: Thu Jan  9 00:38:23 2014
New Revision: 1556684

URL: http://svn.apache.org/r1556684
Log:
Reformat according to Apache standards

Modified:
    manifoldcf/branches/CONNECTORS-840/connectors/solr/connector/src/test/java/org/apache/manifoldcf/agents/output/solr/HttpPosterTest.java
    manifoldcf/branches/CONNECTORS-840/connectors/solr/connector/src/test/java/org/apache/manifoldcf/agents/output/solr/IngestThreadTest.java
    manifoldcf/branches/CONNECTORS-840/connectors/solr/connector/src/test/java/org/apache/manifoldcf/agents/output/solr/SolrConnectorTest.java

Modified: manifoldcf/branches/CONNECTORS-840/connectors/solr/connector/src/test/java/org/apache/manifoldcf/agents/output/solr/HttpPosterTest.java
URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-840/connectors/solr/connector/src/test/java/org/apache/manifoldcf/agents/output/solr/HttpPosterTest.java?rev=1556684&r1=1556683&r2=1556684&view=diff
==============================================================================
--- manifoldcf/branches/CONNECTORS-840/connectors/solr/connector/src/test/java/org/apache/manifoldcf/agents/output/solr/HttpPosterTest.java (original)
+++ manifoldcf/branches/CONNECTORS-840/connectors/solr/connector/src/test/java/org/apache/manifoldcf/agents/output/solr/HttpPosterTest.java Thu Jan  9 00:38:23 2014
@@ -16,23 +16,6 @@
  */
 package org.apache.manifoldcf.agents.output.solr;
 
-/**
- * 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.
- */
-
 import junit.framework.TestCase;
 import org.apache.log4j.Logger;
 import org.apache.manifoldcf.agents.interfaces.IOutputAddActivity;
@@ -67,172 +50,172 @@ import static org.powermock.api.mockito.
 @RunWith( PowerMockRunner.class )
 @PrepareForTest( { HttpPoster.class } )
 public class HttpPosterTest
-    extends TestCase
+  extends TestCase
 {
 
 
-    HttpPoster httpPosterToTest;
-
-    RepositoryDocument document;
+  HttpPoster httpPosterToTest;
 
-    IOutputAddActivity act;
+  RepositoryDocument document;
 
-    @Override
-    public void setUp()
-        throws Exception
-    {
-
-        httpPosterToTest = spy(new HttpPoster( "zkHost", "collection1", 5000, 500, "update", "removePath", "statusPath",
-                                 "allowAttributeName", "denyAttributeName", "idAttributeName",
-                                 "modifiedDateAttributeName", "createdDateAttributeName", "indexedDateAttributeName",
-                                 "fileNameAttributeName", "mimeTypeAttributeName", new Long( 5000 ), "true"));
-    }
+  IOutputAddActivity act;
 
-    /**
-     * Verify  the IndexPost Method create the correct IngestThread class
-     * @throws Exception
-     */
-    public void testIndexPost()
-        throws Exception
-    {
-        String[] shareAcls = new String[]{ "shareAcl1", "shareAcl2" };
-        String[] shareDenyAcls = new String[]{ "denyShareAcl1", "denyShareAcl2" };
-        String[] acls = new String[]{ "acl1", "acl2" };
-        String[] denyAcls = new String[]{ "denyAcl1", "denyAcl2" };
-
-        Logging.ingest = mock( Logger.class );
-        when( Logging.ingest.isDebugEnabled() ).thenReturn( false );
-        initRepositoryDocumentMock( shareAcls, shareDenyAcls, acls, denyAcls );
-
-        act = mock( IOutputAddActivity.class );
-        when(act.qualifyAccessToken( eq( "AuthorityString"), anyString() )).thenAnswer(new Answer<String>() {
-            @Override
-            public String answer(InvocationOnMock invocation) throws Throwable {
-                Object[] args = invocation.getArguments();
-                return (String) args[1];
-            }
-        });
-
-        Map<String, List<String>> sourceTargets = this.getMappingsMap();
-        Map<String, List<String>> streamParam = this.getArgumentsMap();
-
-        String commitWithin = "true";
-        HttpPoster.IngestThread mockIngestionThread=mock(HttpPoster.IngestThread.class);
-        Mockito.doThrow(new RuntimeException()).when( mockIngestionThread ).run();
-
-        whenNew( HttpPoster.IngestThread.class).withArguments("Document Id", document, streamParam, true, sourceTargets,shareAcls,
-                                                              shareDenyAcls, acls, denyAcls,commitWithin).thenReturn(mockIngestionThread);
-        httpPosterToTest.indexPost("Document Id", document, streamParam,
-                                    sourceTargets,true, "AuthorityString",act);
-
-        verifyNew(HttpPoster.IngestThread.class).withArguments("Document Id", document, streamParam, true, sourceTargets, shareAcls,
-                                                                 shareDenyAcls, acls, denyAcls, commitWithin );
-    }
-
-    private void initRepositoryDocumentMock( String[] shareAcls, String[] shareDenyAcls, String[] acls,
-                                             String[] denyAcls )
-        throws IOException
-    {
-        document = mock( RepositoryDocument.class );
-        List<String> fields = getFields();
-        Iterator<String> fieldsIterator = fields.iterator();
-        when( document.getFields() ).thenReturn( fieldsIterator );
-        when( document.getFieldAsStrings( "cm:description" ) ).thenReturn( new String[]{ "description" } );
-        when( document.getFieldAsStrings( "cm:name" ) ).thenReturn( new String[]{ "name" } );
-        when( document.getFieldAsStrings( "cm:title" ) ).thenReturn( new String[]{ "title" } );
-        when( document.getFieldAsStrings( "extraMetadata1" ) ).thenReturn( new String[]{ "value1" } );
-        when( document.getFieldAsStrings( "extraMetadata2" ) ).thenReturn( new String[]{ "value2" } );
-        when( document.getFieldAsStrings( "extraMetadata3" ) ).thenReturn( new String[]{ "value3" } );
-        when( document.getACL()).thenReturn(acls);
-        when( document.getShareACL()).thenReturn(shareAcls);
-        when( document.getShareDenyACL()).thenReturn( shareDenyAcls );
-        when( document.getDenyACL()).thenReturn(denyAcls);
-    }
-
-    /**
-     * inits the expected solr params for both the tests, in the first one we expect the extra params not to be present
-     * because they are not in the mappings
-     *
-     * @param test2
-     * @return
-     * @throws java.io.UnsupportedEncodingException
-     */
-    private ModifiableSolrParams initExpectedSolrParams( Boolean test2 )
-        throws UnsupportedEncodingException
-    {
-        ModifiableSolrParams expectedParams = new ModifiableSolrParams();
-        expectedParams.add( "literal.idAttributeName", "document id" );
-        expectedParams.add( "literal.allowAttributeNameshare", "shareAcl1" );
-        expectedParams.add( "literal.allowAttributeNameshare", "shareAcl2" );
-        expectedParams.add( "literal.denyAttributeNameshare", "denyShareAcl1" );
-        expectedParams.add( "literal.denyAttributeNameshare", "denyShareAcl2" );
-        expectedParams.add( "literal.allowAttributeNamedocument", "acl1" );
-        expectedParams.add( "literal.allowAttributeNamedocument", "acl2" );
-        expectedParams.add( "literal.denyAttributeNamedocument", "denyAcl1" );
-        expectedParams.add( "literal.denyAttributeNamedocument", "denyAcl2" );
-        expectedParams.add( "stream.type", "text/plain" );
-        expectedParams.add( "literal.cm_description_s", "description" );
-        expectedParams.add( "literal.cm_title_s", "title" );
-        expectedParams.add( "literal.cm_name_s", "name" );
-        if ( test2 )
-        {
-            expectedParams.add( "literal.extraMetadata1", "value1" );
-            expectedParams.add( "literal.extraMetadata2", "value2" );
-            expectedParams.add( "literal.extraMetadata3", "value3" );
-        }
-        expectedParams.add( "commitWithin", "true" );
-        return expectedParams;
-    }
-
-    /**
-     * return a list of example metadata fields present in a mock document
-     *
-     * @return
-     */
-    private List<String> getFields()
-    {
-        List<String> fields = new ArrayList<String>();
-        fields.add( "cm:description" );
-        fields.add( "cm:title" );
-        fields.add( "cm:name" );
-        fields.add( "extraMetadata1" );
-        fields.add( "extraMetadata2" );
-        fields.add( "extraMetadata3" );
-        return fields;
-    }
-
-    /**
-     * returns a testing mapping map
-     *
-     * @return
-     */
-    private Map<String, List<String>> getMappingsMap()
-    {
-        Map<String, List<String>> sourceTargets = new HashMap<String, List<String>>();
-        List<String> firstList = new ArrayList<String>();
-        firstList.add( "cm_description_s" );
-        List<String> secondList = new ArrayList<String>();
-        secondList.add( "cm_name_s" );
-        List<String> thirdList = new ArrayList<String>();
-        thirdList.add( "cm_title_s" );
-
-        sourceTargets.put( "cm:description", firstList );
-        sourceTargets.put( "cm:name", secondList );
-        sourceTargets.put( "cm:title", thirdList );
-        return sourceTargets;
-    }
-
-    /**
-     * returns a testing argument map
-     *
-     * @return
-     */
-    private Map<String, List<String>> getArgumentsMap()
-    {
-        Map<String, List<String>> sourceTargets = new HashMap<String, List<String>>();
-        List<String> firstList = new ArrayList<String>();
-        firstList.add( "text/plain" );
-        sourceTargets.put( "stream.type", firstList );
-        return sourceTargets;
-    }
+  @Override
+  public void setUp()
+    throws Exception
+  {
+
+    httpPosterToTest = spy(new HttpPoster( "zkHost", "collection1", 5000, 500, "update", "removePath", "statusPath",
+                 "allowAttributeName", "denyAttributeName", "idAttributeName",
+                 "modifiedDateAttributeName", "createdDateAttributeName", "indexedDateAttributeName",
+                 "fileNameAttributeName", "mimeTypeAttributeName", new Long( 5000 ), "true"));
+  }
+
+  /**
+   * Verify  the IndexPost Method create the correct IngestThread class
+   * @throws Exception
+   */
+  public void testIndexPost()
+    throws Exception
+  {
+    String[] shareAcls = new String[]{ "shareAcl1", "shareAcl2" };
+    String[] shareDenyAcls = new String[]{ "denyShareAcl1", "denyShareAcl2" };
+    String[] acls = new String[]{ "acl1", "acl2" };
+    String[] denyAcls = new String[]{ "denyAcl1", "denyAcl2" };
+
+    Logging.ingest = mock( Logger.class );
+    when( Logging.ingest.isDebugEnabled() ).thenReturn( false );
+    initRepositoryDocumentMock( shareAcls, shareDenyAcls, acls, denyAcls );
+
+    act = mock( IOutputAddActivity.class );
+    when(act.qualifyAccessToken( eq( "AuthorityString"), anyString() )).thenAnswer(new Answer<String>() {
+      @Override
+      public String answer(InvocationOnMock invocation) throws Throwable {
+        Object[] args = invocation.getArguments();
+        return (String) args[1];
+      }
+    });
+
+    Map<String, List<String>> sourceTargets = this.getMappingsMap();
+    Map<String, List<String>> streamParam = this.getArgumentsMap();
+
+    String commitWithin = "true";
+    HttpPoster.IngestThread mockIngestionThread=mock(HttpPoster.IngestThread.class);
+    Mockito.doThrow(new RuntimeException()).when( mockIngestionThread ).run();
+
+    whenNew( HttpPoster.IngestThread.class).withArguments("Document Id", document, streamParam, true, sourceTargets,shareAcls,
+                                shareDenyAcls, acls, denyAcls,commitWithin).thenReturn(mockIngestionThread);
+    httpPosterToTest.indexPost("Document Id", document, streamParam,
+                  sourceTargets,true, "AuthorityString",act);
+
+    verifyNew(HttpPoster.IngestThread.class).withArguments("Document Id", document, streamParam, true, sourceTargets, shareAcls,
+                                 shareDenyAcls, acls, denyAcls, commitWithin );
+  }
+
+  private void initRepositoryDocumentMock( String[] shareAcls, String[] shareDenyAcls, String[] acls,
+                       String[] denyAcls )
+    throws IOException
+  {
+    document = mock( RepositoryDocument.class );
+    List<String> fields = getFields();
+    Iterator<String> fieldsIterator = fields.iterator();
+    when( document.getFields() ).thenReturn( fieldsIterator );
+    when( document.getFieldAsStrings( "cm:description" ) ).thenReturn( new String[]{ "description" } );
+    when( document.getFieldAsStrings( "cm:name" ) ).thenReturn( new String[]{ "name" } );
+    when( document.getFieldAsStrings( "cm:title" ) ).thenReturn( new String[]{ "title" } );
+    when( document.getFieldAsStrings( "extraMetadata1" ) ).thenReturn( new String[]{ "value1" } );
+    when( document.getFieldAsStrings( "extraMetadata2" ) ).thenReturn( new String[]{ "value2" } );
+    when( document.getFieldAsStrings( "extraMetadata3" ) ).thenReturn( new String[]{ "value3" } );
+    when( document.getACL()).thenReturn(acls);
+    when( document.getShareACL()).thenReturn(shareAcls);
+    when( document.getShareDenyACL()).thenReturn( shareDenyAcls );
+    when( document.getDenyACL()).thenReturn(denyAcls);
+  }
+
+  /**
+   * inits the expected solr params for both the tests, in the first one we expect the extra params not to be present
+   * because they are not in the mappings
+   *
+   * @param test2
+   * @return
+   * @throws java.io.UnsupportedEncodingException
+   */
+  private ModifiableSolrParams initExpectedSolrParams( Boolean test2 )
+    throws UnsupportedEncodingException
+  {
+    ModifiableSolrParams expectedParams = new ModifiableSolrParams();
+    expectedParams.add( "literal.idAttributeName", "document id" );
+    expectedParams.add( "literal.allowAttributeNameshare", "shareAcl1" );
+    expectedParams.add( "literal.allowAttributeNameshare", "shareAcl2" );
+    expectedParams.add( "literal.denyAttributeNameshare", "denyShareAcl1" );
+    expectedParams.add( "literal.denyAttributeNameshare", "denyShareAcl2" );
+    expectedParams.add( "literal.allowAttributeNamedocument", "acl1" );
+    expectedParams.add( "literal.allowAttributeNamedocument", "acl2" );
+    expectedParams.add( "literal.denyAttributeNamedocument", "denyAcl1" );
+    expectedParams.add( "literal.denyAttributeNamedocument", "denyAcl2" );
+    expectedParams.add( "stream.type", "text/plain" );
+    expectedParams.add( "literal.cm_description_s", "description" );
+    expectedParams.add( "literal.cm_title_s", "title" );
+    expectedParams.add( "literal.cm_name_s", "name" );
+    if ( test2 )
+    {
+      expectedParams.add( "literal.extraMetadata1", "value1" );
+      expectedParams.add( "literal.extraMetadata2", "value2" );
+      expectedParams.add( "literal.extraMetadata3", "value3" );
+    }
+    expectedParams.add( "commitWithin", "true" );
+    return expectedParams;
+  }
+
+  /**
+   * return a list of example metadata fields present in a mock document
+   *
+   * @return
+   */
+  private List<String> getFields()
+  {
+    List<String> fields = new ArrayList<String>();
+    fields.add( "cm:description" );
+    fields.add( "cm:title" );
+    fields.add( "cm:name" );
+    fields.add( "extraMetadata1" );
+    fields.add( "extraMetadata2" );
+    fields.add( "extraMetadata3" );
+    return fields;
+  }
+
+  /**
+   * returns a testing mapping map
+   *
+   * @return
+   */
+  private Map<String, List<String>> getMappingsMap()
+  {
+    Map<String, List<String>> sourceTargets = new HashMap<String, List<String>>();
+    List<String> firstList = new ArrayList<String>();
+    firstList.add( "cm_description_s" );
+    List<String> secondList = new ArrayList<String>();
+    secondList.add( "cm_name_s" );
+    List<String> thirdList = new ArrayList<String>();
+    thirdList.add( "cm_title_s" );
+
+    sourceTargets.put( "cm:description", firstList );
+    sourceTargets.put( "cm:name", secondList );
+    sourceTargets.put( "cm:title", thirdList );
+    return sourceTargets;
+  }
+
+  /**
+   * returns a testing argument map
+   *
+   * @return
+   */
+  private Map<String, List<String>> getArgumentsMap()
+  {
+    Map<String, List<String>> sourceTargets = new HashMap<String, List<String>>();
+    List<String> firstList = new ArrayList<String>();
+    firstList.add( "text/plain" );
+    sourceTargets.put( "stream.type", firstList );
+    return sourceTargets;
+  }
 }

Modified: manifoldcf/branches/CONNECTORS-840/connectors/solr/connector/src/test/java/org/apache/manifoldcf/agents/output/solr/IngestThreadTest.java
URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-840/connectors/solr/connector/src/test/java/org/apache/manifoldcf/agents/output/solr/IngestThreadTest.java?rev=1556684&r1=1556683&r2=1556684&view=diff
==============================================================================
--- manifoldcf/branches/CONNECTORS-840/connectors/solr/connector/src/test/java/org/apache/manifoldcf/agents/output/solr/IngestThreadTest.java (original)
+++ manifoldcf/branches/CONNECTORS-840/connectors/solr/connector/src/test/java/org/apache/manifoldcf/agents/output/solr/IngestThreadTest.java Thu Jan  9 00:38:23 2014
@@ -52,196 +52,196 @@ import static org.powermock.api.mockito.
 @RunWith( PowerMockRunner.class )
 @PrepareForTest( { HttpPoster.IngestThread.class } )
 public class IngestThreadTest
-    extends TestCase
+  extends TestCase
 {
 
-    HttpPoster.IngestThread ingestThreadToTest;
+  HttpPoster.IngestThread ingestThreadToTest;
 
-    HttpPoster poster;
+  HttpPoster poster;
 
-    RepositoryDocument document;
+  RepositoryDocument document;
 
-    IOutputAddActivity act;
+  IOutputAddActivity act;
 
-    @Override
-    public void setUp()
-        throws Exception
-    {
-
-        poster =new HttpPoster( "zkHost", "collection1", 5000, 500, "update", "removePath", "statusPath",
-                                 "allowAttributeName", "denyAttributeName", "idAttributeName",
-                                 "modifiedDateAttributeName", "createdDateAttributeName", "indexedDateAttributeName",
-                                 "fileNameAttributeName", "mimeTypeAttributeName", new Long( 5000 ), "true" );
-
-        Logging.ingest = mock( Logger.class );
-        when( Logging.ingest.isDebugEnabled() ).thenReturn( false );
-        document = mock( RepositoryDocument.class );
-        List<String> fields = getFields();
-        Iterator<String> fieldsIterator = fields.iterator();
-        when( document.getFields() ).thenReturn( fieldsIterator );
-        when( document.getFieldAsStrings( "cm:description" ) ).thenReturn( new String[]{ "description" } );
-        when( document.getFieldAsStrings( "cm:name" ) ).thenReturn( new String[]{ "name" } );
-        when( document.getFieldAsStrings( "cm:title" ) ).thenReturn( new String[]{ "title" } );
-        when( document.getFieldAsStrings( "extraMetadata1" ) ).thenReturn( new String[]{ "value1" } );
-        when( document.getFieldAsStrings( "extraMetadata2" ) ).thenReturn( new String[]{ "value2" } );
-        when( document.getFieldAsStrings( "extraMetadata3" ) ).thenReturn( new String[]{ "value3" } );
-
-        act = mock( IOutputAddActivity.class );
-
-        Map<String, List<String>> sourceTargets = this.getMappingsMap();
-        Map<String, List<String>> streamParam = this.getArgumentsMap();
-        String[] shareAcls = new String[]{ "shareAcl1", "shareAcl2" };
-        String[] shareDenyAcls = new String[]{ "denyShareAcl1", "denyShareAcl2" };
-        String[] acls = new String[]{ "acl1", "acl2" };
-        String[] denyAcls = new String[]{ "denyAcl1", "denyAcl2" };
-        String commitWithin = "true";
-
-        ingestThreadToTest = spy(
-            poster.new IngestThread( "document id", document, streamParam, true, sourceTargets, shareAcls,
-                                     shareDenyAcls, acls, denyAcls, commitWithin ) );
-
-    }
-
-
-    public void testIndexPostNotKeepMetadata()
-        throws Exception
-    {
-        this.indexPostNotKeepMetadata( true );
-        this.indexPostNotKeepMetadata( false );
-
-    }
-
-    /**
-     * Verify the behaviour, when the keep variable is set to true, we want to send to Solr all the metadata fields
-     *
-     * @param keep
-     * @throws Exception
-     */
-    private void indexPostNotKeepMetadata( Boolean keep )
-        throws Exception
-    {
-        ingestThreadToTest.setKeepAllMetadata( keep );
-
-        ContentStreamUpdateRequest contentStreamUpdateRequest = mock( ContentStreamUpdateRequest.class );
-        whenNew( ContentStreamUpdateRequest.class ).withArguments( anyString() ).thenReturn(
-            contentStreamUpdateRequest );
-        UpdateResponse mockResponse = mock( UpdateResponse.class );
-        when( contentStreamUpdateRequest.process( any( SolrServer.class ) ) ).thenReturn( mockResponse );
-        doCallRealMethod().when( contentStreamUpdateRequest ).setParams( any( ModifiableSolrParams.class ) );
-        doCallRealMethod().when( contentStreamUpdateRequest ).getParams();
-        ingestThreadToTest.run();
-        verifyNew( ContentStreamUpdateRequest.class, atLeastOnce() ).withArguments( anyString() );
-
-        ModifiableSolrParams expectedParams = initExpectedSolrParams( keep );
-        assertEqualsModifiableSolrParams( expectedParams, contentStreamUpdateRequest.getParams() );
-        verify( contentStreamUpdateRequest ).process( any( SolrServer.class ) );
-
-    }
-
-    /**
-     * asserts that 2 ModifiableSolrParams are equals
-     *
-     * @param expected
-     * @param actual
-     * @return
-     */
-    private boolean assertEqualsModifiableSolrParams( ModifiableSolrParams expected, ModifiableSolrParams actual )
-    {
-        Set<String> expectedParameterNames = expected.getParameterNames();
-        Set<String> actualParameterNames = actual.getParameterNames();
-        int expectedSize = expectedParameterNames.size();
-        assertEquals( expectedSize, actualParameterNames.size() );
-        for ( String parameterName : expectedParameterNames )
-        {
-            assertEquals( expected.get( parameterName ), actual.get( parameterName ) );
-        }
-        return true;
-    }
-
-    /**
-     * inits the expected solr params for both the tests, in the first one we expect the extra params not to be present
-     * because they are not in the mappings
-     *
-     * @param test2
-     * @return
-     * @throws UnsupportedEncodingException
-     */
-    private ModifiableSolrParams initExpectedSolrParams( Boolean test2 )
-        throws UnsupportedEncodingException
-    {
-        ModifiableSolrParams expectedParams = new ModifiableSolrParams();
-        expectedParams.add( "literal.idAttributeName", "document id" );
-        expectedParams.add( "literal.allowAttributeNameshare", "shareAcl1" );
-        expectedParams.add( "literal.allowAttributeNameshare", "shareAcl2" );
-        expectedParams.add( "literal.denyAttributeNameshare", "denyShareAcl1" );
-        expectedParams.add( "literal.denyAttributeNameshare", "denyShareAcl2" );
-        expectedParams.add( "literal.allowAttributeNamedocument", "acl1" );
-        expectedParams.add( "literal.allowAttributeNamedocument", "acl2" );
-        expectedParams.add( "literal.denyAttributeNamedocument", "denyAcl1" );
-        expectedParams.add( "literal.denyAttributeNamedocument", "denyAcl2" );
-        expectedParams.add( "stream.type", "text/plain" );
-        expectedParams.add( "literal.cm_description_s", "description" );
-        expectedParams.add( "literal.cm_title_s", "title" );
-        expectedParams.add( "literal.cm_name_s", "name" );
-        if ( test2 )
-        {
-            expectedParams.add( "literal.extraMetadata1", "value1" );
-            expectedParams.add( "literal.extraMetadata2", "value2" );
-            expectedParams.add( "literal.extraMetadata3", "value3" );
-        }
-        expectedParams.add( "commitWithin", "true" );
-        return expectedParams;
-    }
-
-    /**
-     * return a list of example metadata fields present in a mock document
-     *
-     * @return
-     */
-    private List<String> getFields()
-    {
-        List<String> fields = new ArrayList<String>();
-        fields.add( "cm:description" );
-        fields.add( "cm:title" );
-        fields.add( "cm:name" );
-        fields.add( "extraMetadata1" );
-        fields.add( "extraMetadata2" );
-        fields.add( "extraMetadata3" );
-        return fields;
-    }
-
-    /**
-     * returns a testing mapping map
-     *
-     * @return
-     */
-    private Map<String, List<String>> getMappingsMap()
-    {
-        Map<String, List<String>> sourceTargets = new HashMap<String, List<String>>();
-        List<String> firstList = new ArrayList<String>();
-        firstList.add( "cm_description_s" );
-        List<String> secondList = new ArrayList<String>();
-        secondList.add( "cm_name_s" );
-        List<String> thirdList = new ArrayList<String>();
-        thirdList.add( "cm_title_s" );
-
-        sourceTargets.put( "cm:description", firstList );
-        sourceTargets.put( "cm:name", secondList );
-        sourceTargets.put( "cm:title", thirdList );
-        return sourceTargets;
-    }
-
-    /**
-     * returns a testing argument map
-     *
-     * @return
-     */
-    private Map<String, List<String>> getArgumentsMap()
-    {
-        Map<String, List<String>> sourceTargets = new HashMap<String, List<String>>();
-        List<String> firstList = new ArrayList<String>();
-        firstList.add( "text/plain" );
-        sourceTargets.put( "stream.type", firstList );
-        return sourceTargets;
-    }
+  @Override
+  public void setUp()
+    throws Exception
+  {
+
+    poster =new HttpPoster( "zkHost", "collection1", 5000, 500, "update", "removePath", "statusPath",
+                 "allowAttributeName", "denyAttributeName", "idAttributeName",
+                 "modifiedDateAttributeName", "createdDateAttributeName", "indexedDateAttributeName",
+                 "fileNameAttributeName", "mimeTypeAttributeName", new Long( 5000 ), "true" );
+
+    Logging.ingest = mock( Logger.class );
+    when( Logging.ingest.isDebugEnabled() ).thenReturn( false );
+    document = mock( RepositoryDocument.class );
+    List<String> fields = getFields();
+    Iterator<String> fieldsIterator = fields.iterator();
+    when( document.getFields() ).thenReturn( fieldsIterator );
+    when( document.getFieldAsStrings( "cm:description" ) ).thenReturn( new String[]{ "description" } );
+    when( document.getFieldAsStrings( "cm:name" ) ).thenReturn( new String[]{ "name" } );
+    when( document.getFieldAsStrings( "cm:title" ) ).thenReturn( new String[]{ "title" } );
+    when( document.getFieldAsStrings( "extraMetadata1" ) ).thenReturn( new String[]{ "value1" } );
+    when( document.getFieldAsStrings( "extraMetadata2" ) ).thenReturn( new String[]{ "value2" } );
+    when( document.getFieldAsStrings( "extraMetadata3" ) ).thenReturn( new String[]{ "value3" } );
+
+    act = mock( IOutputAddActivity.class );
+
+    Map<String, List<String>> sourceTargets = this.getMappingsMap();
+    Map<String, List<String>> streamParam = this.getArgumentsMap();
+    String[] shareAcls = new String[]{ "shareAcl1", "shareAcl2" };
+    String[] shareDenyAcls = new String[]{ "denyShareAcl1", "denyShareAcl2" };
+    String[] acls = new String[]{ "acl1", "acl2" };
+    String[] denyAcls = new String[]{ "denyAcl1", "denyAcl2" };
+    String commitWithin = "true";
+
+    ingestThreadToTest = spy(
+      poster.new IngestThread( "document id", document, streamParam, true, sourceTargets, shareAcls,
+                   shareDenyAcls, acls, denyAcls, commitWithin ) );
+
+  }
+
+
+  public void testIndexPostNotKeepMetadata()
+    throws Exception
+  {
+    this.indexPostNotKeepMetadata( true );
+    this.indexPostNotKeepMetadata( false );
+
+  }
+
+  /**
+   * Verify the behaviour, when the keep variable is set to true, we want to send to Solr all the metadata fields
+   *
+   * @param keep
+   * @throws Exception
+   */
+  private void indexPostNotKeepMetadata( Boolean keep )
+    throws Exception
+  {
+    ingestThreadToTest.setKeepAllMetadata( keep );
+
+    ContentStreamUpdateRequest contentStreamUpdateRequest = mock( ContentStreamUpdateRequest.class );
+    whenNew( ContentStreamUpdateRequest.class ).withArguments( anyString() ).thenReturn(
+      contentStreamUpdateRequest );
+    UpdateResponse mockResponse = mock( UpdateResponse.class );
+    when( contentStreamUpdateRequest.process( any( SolrServer.class ) ) ).thenReturn( mockResponse );
+    doCallRealMethod().when( contentStreamUpdateRequest ).setParams( any( ModifiableSolrParams.class ) );
+    doCallRealMethod().when( contentStreamUpdateRequest ).getParams();
+    ingestThreadToTest.run();
+    verifyNew( ContentStreamUpdateRequest.class, atLeastOnce() ).withArguments( anyString() );
+
+    ModifiableSolrParams expectedParams = initExpectedSolrParams( keep );
+    assertEqualsModifiableSolrParams( expectedParams, contentStreamUpdateRequest.getParams() );
+    verify( contentStreamUpdateRequest ).process( any( SolrServer.class ) );
+
+  }
+
+  /**
+   * asserts that 2 ModifiableSolrParams are equals
+   *
+   * @param expected
+   * @param actual
+   * @return
+   */
+  private boolean assertEqualsModifiableSolrParams( ModifiableSolrParams expected, ModifiableSolrParams actual )
+  {
+    Set<String> expectedParameterNames = expected.getParameterNames();
+    Set<String> actualParameterNames = actual.getParameterNames();
+    int expectedSize = expectedParameterNames.size();
+    assertEquals( expectedSize, actualParameterNames.size() );
+    for ( String parameterName : expectedParameterNames )
+    {
+      assertEquals( expected.get( parameterName ), actual.get( parameterName ) );
+    }
+    return true;
+  }
+
+  /**
+   * inits the expected solr params for both the tests, in the first one we expect the extra params not to be present
+   * because they are not in the mappings
+   *
+   * @param test2
+   * @return
+   * @throws UnsupportedEncodingException
+   */
+  private ModifiableSolrParams initExpectedSolrParams( Boolean test2 )
+    throws UnsupportedEncodingException
+  {
+    ModifiableSolrParams expectedParams = new ModifiableSolrParams();
+    expectedParams.add( "literal.idAttributeName", "document id" );
+    expectedParams.add( "literal.allowAttributeNameshare", "shareAcl1" );
+    expectedParams.add( "literal.allowAttributeNameshare", "shareAcl2" );
+    expectedParams.add( "literal.denyAttributeNameshare", "denyShareAcl1" );
+    expectedParams.add( "literal.denyAttributeNameshare", "denyShareAcl2" );
+    expectedParams.add( "literal.allowAttributeNamedocument", "acl1" );
+    expectedParams.add( "literal.allowAttributeNamedocument", "acl2" );
+    expectedParams.add( "literal.denyAttributeNamedocument", "denyAcl1" );
+    expectedParams.add( "literal.denyAttributeNamedocument", "denyAcl2" );
+    expectedParams.add( "stream.type", "text/plain" );
+    expectedParams.add( "literal.cm_description_s", "description" );
+    expectedParams.add( "literal.cm_title_s", "title" );
+    expectedParams.add( "literal.cm_name_s", "name" );
+    if ( test2 )
+    {
+      expectedParams.add( "literal.extraMetadata1", "value1" );
+      expectedParams.add( "literal.extraMetadata2", "value2" );
+      expectedParams.add( "literal.extraMetadata3", "value3" );
+    }
+    expectedParams.add( "commitWithin", "true" );
+    return expectedParams;
+  }
+
+  /**
+   * return a list of example metadata fields present in a mock document
+   *
+   * @return
+   */
+  private List<String> getFields()
+  {
+    List<String> fields = new ArrayList<String>();
+    fields.add( "cm:description" );
+    fields.add( "cm:title" );
+    fields.add( "cm:name" );
+    fields.add( "extraMetadata1" );
+    fields.add( "extraMetadata2" );
+    fields.add( "extraMetadata3" );
+    return fields;
+  }
+
+  /**
+   * returns a testing mapping map
+   *
+   * @return
+   */
+  private Map<String, List<String>> getMappingsMap()
+  {
+    Map<String, List<String>> sourceTargets = new HashMap<String, List<String>>();
+    List<String> firstList = new ArrayList<String>();
+    firstList.add( "cm_description_s" );
+    List<String> secondList = new ArrayList<String>();
+    secondList.add( "cm_name_s" );
+    List<String> thirdList = new ArrayList<String>();
+    thirdList.add( "cm_title_s" );
+
+    sourceTargets.put( "cm:description", firstList );
+    sourceTargets.put( "cm:name", secondList );
+    sourceTargets.put( "cm:title", thirdList );
+    return sourceTargets;
+  }
+
+  /**
+   * returns a testing argument map
+   *
+   * @return
+   */
+  private Map<String, List<String>> getArgumentsMap()
+  {
+    Map<String, List<String>> sourceTargets = new HashMap<String, List<String>>();
+    List<String> firstList = new ArrayList<String>();
+    firstList.add( "text/plain" );
+    sourceTargets.put( "stream.type", firstList );
+    return sourceTargets;
+  }
 }

Modified: manifoldcf/branches/CONNECTORS-840/connectors/solr/connector/src/test/java/org/apache/manifoldcf/agents/output/solr/SolrConnectorTest.java
URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-840/connectors/solr/connector/src/test/java/org/apache/manifoldcf/agents/output/solr/SolrConnectorTest.java?rev=1556684&r1=1556683&r2=1556684&view=diff
==============================================================================
--- manifoldcf/branches/CONNECTORS-840/connectors/solr/connector/src/test/java/org/apache/manifoldcf/agents/output/solr/SolrConnectorTest.java (original)
+++ manifoldcf/branches/CONNECTORS-840/connectors/solr/connector/src/test/java/org/apache/manifoldcf/agents/output/solr/SolrConnectorTest.java Thu Jan  9 00:38:23 2014
@@ -1,4 +1,19 @@
-
+/**
+ * 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.manifoldcf.agents.output.solr;
 
 import junit.framework.TestCase;
@@ -24,64 +39,64 @@ import static org.powermock.api.mockito.
  */
 public class SolrConnectorTest extends TestCase{
 
-    SolrConnector connectorToTest;
-    HttpPoster poster;
-    RepositoryDocument document;
-    IOutputAddActivity act;
-
-    @Override
-    public void setUp() throws Exception {
-        connectorToTest=spy(new SolrConnector());
-        poster=mock(HttpPoster.class);
-        document=mock(RepositoryDocument.class);
-        act=mock(IOutputAddActivity.class);
-        when(poster.indexPost(anyString(),eq(document),anyMap(),anyMap(),anyBoolean(),anyString(),eq(act))).thenReturn(true);
-
-    }
-
-    /**
-     * Test the AddOrReplaceDocument with an example test string in input
-     * @throws ManifoldCFException
-     * @throws ServiceInterruption
-     */
-    public void testAddOrReplaceDocument() throws ManifoldCFException, ServiceInterruption {
-        Map<String, List<String>> expectedSourceTargets = getMappingsMap();
-        Map<String,List<String>> expectedStreamParams = getStreamTypeMap();
-
-        connectorToTest.poster=poster;
-        String outputDescription = "1+stream.type=text/plain=+3+cm:description=cm_description_s=+cm:name=cm_name_s=+cm:title=cm_title_s=+1+keepAllMetadata=true=+";
-        connectorToTest.addOrReplaceDocument("Document Id", outputDescription,document,"",act);
-        verify(poster).indexPost(eq("Document Id"),eq(document),eq(expectedStreamParams),eq(expectedSourceTargets),eq(true),eq(""),eq(act));
-    }
-
-    /**
-     * returns the expected mappings map for the input string in test
-     * @return
-     */
-    private Map<String, List<String>> getMappingsMap() {
-        Map<String, List<String>> sourceTargets = new HashMap<String, List<String>>();
-        List<String> firstList=new ArrayList<String>();
-        firstList.add("cm_description_s");
-        List<String> secondList=new ArrayList<String>();
-        secondList.add("cm_name_s");
-        List<String> thirdList=new ArrayList<String>();
-        thirdList.add("cm_title_s");
-
-        sourceTargets.put("cm:description",firstList);
-        sourceTargets.put("cm:name",secondList);
-        sourceTargets.put("cm:title",thirdList);
-        return sourceTargets;
-    }
-
-    /**
-     * returns the expected mappings map for the input string in test
-     * @return
-     */
-    private Map<String, List<String>> getStreamTypeMap() {
-        Map<String, List<String>> sourceTargets = new HashMap<String, List<String>>();
-        List<String> firstList=new ArrayList<String>();
-        firstList.add("text/plain");
-        sourceTargets.put("stream.type",firstList);
-        return sourceTargets;
-    }
+  SolrConnector connectorToTest;
+  HttpPoster poster;
+  RepositoryDocument document;
+  IOutputAddActivity act;
+
+  @Override
+  public void setUp() throws Exception {
+    connectorToTest=spy(new SolrConnector());
+    poster=mock(HttpPoster.class);
+    document=mock(RepositoryDocument.class);
+    act=mock(IOutputAddActivity.class);
+    when(poster.indexPost(anyString(),eq(document),anyMap(),anyMap(),anyBoolean(),anyString(),eq(act))).thenReturn(true);
+
+  }
+
+  /**
+   * Test the AddOrReplaceDocument with an example test string in input
+   * @throws ManifoldCFException
+   * @throws ServiceInterruption
+   */
+  public void testAddOrReplaceDocument() throws ManifoldCFException, ServiceInterruption {
+    Map<String, List<String>> expectedSourceTargets = getMappingsMap();
+    Map<String,List<String>> expectedStreamParams = getStreamTypeMap();
+
+    connectorToTest.poster=poster;
+    String outputDescription = "1+stream.type=text/plain=+3+cm:description=cm_description_s=+cm:name=cm_name_s=+cm:title=cm_title_s=+1+keepAllMetadata=true=+";
+    connectorToTest.addOrReplaceDocument("Document Id", outputDescription,document,"",act);
+    verify(poster).indexPost(eq("Document Id"),eq(document),eq(expectedStreamParams),eq(expectedSourceTargets),eq(true),eq(""),eq(act));
+  }
+
+  /**
+   * returns the expected mappings map for the input string in test
+   * @return
+   */
+  private Map<String, List<String>> getMappingsMap() {
+    Map<String, List<String>> sourceTargets = new HashMap<String, List<String>>();
+    List<String> firstList=new ArrayList<String>();
+    firstList.add("cm_description_s");
+    List<String> secondList=new ArrayList<String>();
+    secondList.add("cm_name_s");
+    List<String> thirdList=new ArrayList<String>();
+    thirdList.add("cm_title_s");
+
+    sourceTargets.put("cm:description",firstList);
+    sourceTargets.put("cm:name",secondList);
+    sourceTargets.put("cm:title",thirdList);
+    return sourceTargets;
+  }
+
+  /**
+   * returns the expected mappings map for the input string in test
+   * @return
+   */
+  private Map<String, List<String>> getStreamTypeMap() {
+    Map<String, List<String>> sourceTargets = new HashMap<String, List<String>>();
+    List<String> firstList=new ArrayList<String>();
+    firstList.add("text/plain");
+    sourceTargets.put("stream.type",firstList);
+    return sourceTargets;
+  }
 }