Added: manifoldcf/branches/CONNECTORS-1637/connectors/confluence-v6/src/main/resources/org/apache/manifoldcf/crawler/connectors/confluence/v6/editSpecification_confSecurity.html URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-1637/connectors/confluence-v6/src/main/resources/org/apache/manifoldcf/crawler/connectors/confluence/v6/editSpecification_confSecurity.html?rev=1874903&view=auto ============================================================================== --- manifoldcf/branches/CONNECTORS-1637/connectors/confluence-v6/src/main/resources/org/apache/manifoldcf/crawler/connectors/confluence/v6/editSpecification_confSecurity.html (added) +++ manifoldcf/branches/CONNECTORS-1637/connectors/confluence-v6/src/main/resources/org/apache/manifoldcf/crawler/connectors/confluence/v6/editSpecification_confSecurity.html Fri Mar 6 15:29:45 2020 @@ -0,0 +1,42 @@ +<!-- + 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. +--> + + +#if($TabName == $ResourceBundle.getString('ConfluenceRepositoryConnector.Security') && ${SeqNum} == ${SelectedNum}) + +<table class="displaytable"> + <tr><td class="separator" colspan="2"><hr/></td></tr> + + <tr> + <td class="description" colspan="2"> + $Encoder.bodyEscape($ResourceBundle.getString('ConfluenceRepositoryConnector.ActivateSecurity')) + </td> + <td class="value"> + <input type="checkbox" name="s${SeqNum}_activate_security" value="true" + #if($ACTIVATE_SECURITY == 'true') checked + #end + /> + </td> + </tr> + +</table> + +#else + +<input type="hidden" name="s${SeqNum}_activate_security" value="$ACTIVATE_SECURITY"/> + +#end
Added: manifoldcf/branches/CONNECTORS-1637/connectors/confluence-v6/src/main/resources/org/apache/manifoldcf/crawler/connectors/confluence/v6/editSpecification_confSpaces.html URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-1637/connectors/confluence-v6/src/main/resources/org/apache/manifoldcf/crawler/connectors/confluence/v6/editSpecification_confSpaces.html?rev=1874903&view=auto ============================================================================== --- manifoldcf/branches/CONNECTORS-1637/connectors/confluence-v6/src/main/resources/org/apache/manifoldcf/crawler/connectors/confluence/v6/editSpecification_confSpaces.html (added) +++ manifoldcf/branches/CONNECTORS-1637/connectors/confluence-v6/src/main/resources/org/apache/manifoldcf/crawler/connectors/confluence/v6/editSpecification_confSpaces.html Fri Mar 6 15:29:45 2020 @@ -0,0 +1,74 @@ +<!-- + 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. +--> + + +#if($TabName == $ResourceBundle.getString('ConfluenceRepositoryConnector.Spaces') && ${SeqNum} == ${SelectedNum}) + +<table class="displaytable"> + <tr><td class="separator" colspan="2"><hr/></td></tr> + + #set($spacecounter = 0) + #foreach($space in $SPACES) + + <tr> + <td class="description"> + <input type="hidden" name="s${SeqNum}_spaceop_$spacecounter" value=""/> + <input type="hidden" name="s${SeqNum}_space_$spacecounter" value="$Encoder.attributeEscape($space)"/> + <a name="s${SeqNum}_tokenspace_$spacecounter"> + <input type="button" value="$Encoder.attributeEscape($ResourceBundle.getString('ConfluenceRepositoryConnector.Delete'))" onClick='Javascript:s${SeqNum}_SpecDeleteSpace($spacecounter)' alt="$Encoder.attributeEscape($ResourceBundle.getString('ConfluenceRepositoryConnector.DeleteSpace'))$spacecounter"/> + </a> + </td> + <td class="value">$Encoder.bodyEscape($space)</td> + </tr> + + #set($spacecounter = $spacecounter + 1) + #end + + #set($nextspace = $spacecounter + 1) + + #if($spacecounter == 0) + <tr> + <td class="message" colspan="2">$Encoder.bodyEscape($ResourceBundle.getString('ConfluenceRepositoryConnector.NoSpacesConfigured'))</td> + </tr> + #end + + <tr><td class="lightseparator" colspan="2"><hr/></td></tr> + + <tr> + <td class="description"> + <input type="hidden" name="s${SeqNum}_spacescount" value="$spacecounter"/> + <input type="hidden" name="s${SeqNum}_spaceop" value=""/> + <a name="space_$spacecounter"> + <input type="button" value="$Encoder.attributeEscape($ResourceBundle.getString('ConfluenceRepositoryConnector.Add'))" onClick='Javascript:s${SeqNum}_SpecAddSpace($nextspace)' alt="$Encoder.attributeEscape($ResourceBundle.getString('ConfluenceRepositoryConnector.AddSpace'))"/> + </a> + </td> + <td class="value"> + <input type="text" size="30" name="s${SeqNum}_space" value=""/> + </td> + </tr> +</table> + +#else + + #set($spacecounter = 0) + #foreach($space in $SPACES) +<input type="hidden" name="s${SeqNum}_space_$spacecounter" value="$Encoder.attributeEscape($space)"/> + #set($spacecounter = $spacecounter + 1) + #end +<input type="hidden" name="s${SeqNum}_spacescount" value="$spacecounter"/> + +#end Added: manifoldcf/branches/CONNECTORS-1637/connectors/confluence-v6/src/main/resources/org/apache/manifoldcf/crawler/connectors/confluence/v6/viewConfiguration_conf.html URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-1637/connectors/confluence-v6/src/main/resources/org/apache/manifoldcf/crawler/connectors/confluence/v6/viewConfiguration_conf.html?rev=1874903&view=auto ============================================================================== --- manifoldcf/branches/CONNECTORS-1637/connectors/confluence-v6/src/main/resources/org/apache/manifoldcf/crawler/connectors/confluence/v6/viewConfiguration_conf.html (added) +++ manifoldcf/branches/CONNECTORS-1637/connectors/confluence-v6/src/main/resources/org/apache/manifoldcf/crawler/connectors/confluence/v6/viewConfiguration_conf.html Fri Mar 6 15:29:45 2020 @@ -0,0 +1,95 @@ +<!-- + 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. +--> + +<table class="displaytable"> + + <tr> + <td class="description"> + <nobr>$Encoder.bodyEscape($ResourceBundle.getString('ConfluenceRepositoryConnector.ProtocolColon'))</nobr> + </td> + <td class="value"> + <nobr>$Encoder.bodyEscape($CONFLUENCE_PROTOCOL)</nobr> + </td> + </tr> + + <tr> + <td class="description"> + <nobr>$Encoder.bodyEscape($ResourceBundle.getString('ConfluenceRepositoryConnector.HostColon'))</nobr> + </td> + <td class="value"> + <nobr>$Encoder.bodyEscape($CONFLUENCE_HOST)</nobr> + </td> + </tr> + + <tr> + <td class="description"> + <nobr>$Encoder.bodyEscape($ResourceBundle.getString('ConfluenceRepositoryConnector.PortColon'))</nobr> + </td> + <td class="value"> + <nobr>$Encoder.bodyEscape($CONFLUENCE_PORT)</nobr> + </td> + </tr> + + <tr> + <td class="description"> + <nobr>$Encoder.bodyEscape($ResourceBundle.getString('ConfluenceRepositoryConnector.PathColon'))</nobr> + </td> + <td class="value"> + <nobr>$Encoder.bodyEscape($CONFLUENCE_PATH)</nobr> + </td> + </tr> + + <tr> + <td class="description"> + <nobr>$Encoder.bodyEscape($ResourceBundle.getString('ConfluenceRepositoryConnector.SocketTimeoutColon'))</nobr> + </td> + <td class="value"> + <nobr>$Encoder.bodyEscape($CONFLUENCE_SOCKET_TIMEOUT)</nobr> + </td> + </tr> + + <tr> + <td class="description"> + <nobr>$Encoder.bodyEscape($ResourceBundle.getString('ConfluenceRepositoryConnector.ConnectionTimeoutColon'))</nobr> + </td> + <td class="value"> + <nobr>$Encoder.bodyEscape($CONFLUENCE_CONNECTION_TIMEOUT)</nobr> + </td> + </tr> + + <tr><td class="separator" colspan="2"><hr/></td></tr> + + <tr> + <td class="description"> + <nobr>$Encoder.bodyEscape($ResourceBundle.getString('ConfluenceRepositoryConnector.UsernameColon'))</nobr> + </td> + <td class="value"> + <nobr>$Encoder.bodyEscape($CONFLUENCE_USERNAME)</nobr> + </td> + </tr> + + <tr> + <td class="description"> + <nobr>$Encoder.bodyEscape($ResourceBundle.getString('ConfluenceRepositoryConnector.PasswordColon'))</nobr> + </td> + <td class="value"> + <nobr>********</nobr> + </td> + </tr> + +</table> + Added: manifoldcf/branches/CONNECTORS-1637/connectors/confluence-v6/src/main/resources/org/apache/manifoldcf/crawler/connectors/confluence/v6/viewSpecification_conf.html URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-1637/connectors/confluence-v6/src/main/resources/org/apache/manifoldcf/crawler/connectors/confluence/v6/viewSpecification_conf.html?rev=1874903&view=auto ============================================================================== --- manifoldcf/branches/CONNECTORS-1637/connectors/confluence-v6/src/main/resources/org/apache/manifoldcf/crawler/connectors/confluence/v6/viewSpecification_conf.html (added) +++ manifoldcf/branches/CONNECTORS-1637/connectors/confluence-v6/src/main/resources/org/apache/manifoldcf/crawler/connectors/confluence/v6/viewSpecification_conf.html Fri Mar 6 15:29:45 2020 @@ -0,0 +1,68 @@ +<!-- + 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. +--> + +<table class="displaytable"> + <tr> + <td class="message" colspan="2"> + $Encoder.bodyEscape($ResourceBundle.getString('ConfluenceRepositoryConnector.ActivateSecurity')) + </td> + <td class="description"> + <nobr>$Encoder.bodyEscape($ACTIVATE_SECURITY)</nobr> + </td> + </tr> + + <tr> +#if($SPACES.size() == 0) + <td class="message" colspan="2"> + $Encoder.bodyEscape($ResourceBundle.getString('ConfluenceRepositoryConnector.NoSpacesConfigured')) + </td> +#else + <td class="description"> + <nobr>$Encoder.bodyEscape($ResourceBundle.getString('ConfluenceRepositoryConnector.Spaces'))</nobr> + </td> + <td class="value"> + #set($spacecounter = 0) + #foreach($space in $SPACES) + <nobr>$Encoder.bodyEscape($space)</nobr><br/> + #set($spacecounter = $spacecounter + 1) + #end + </td> +#end + </tr> + + <tr> + <td class="message" colspan="2"> + $Encoder.bodyEscape($ResourceBundle.getString('ConfluenceRepositoryConnector.ProcessAttachments')) + </td> + <td class="description"> + <nobr>$Encoder.bodyEscape($PROCESS_ATTACHMENTS)</nobr> + </td> + </tr> + + <tr> + <td class="message" colspan="2"> + $Encoder.bodyEscape($ResourceBundle.getString('ConfluenceRepositoryConnector.TypeSpec')) + </td> + <td class="description"> +#if($PAGETYPE == 'blogpost') + <nobr>$Encoder.bodyEscape($ResourceBundle.getString('ConfluenceRepositoryConnector.TypeBlog'))</nobr> +#else + <nobr>$Encoder.bodyEscape($ResourceBundle.getString('ConfluenceRepositoryConnector.TypePage'))</nobr> +#end + </td> + </tr> +</table> \ No newline at end of file Added: manifoldcf/branches/CONNECTORS-1637/connectors/confluence-v6/src/test/java/org/apache/manifoldcf/authorities/confluence/tests/ConfluenceAuthorityTest.java URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-1637/connectors/confluence-v6/src/test/java/org/apache/manifoldcf/authorities/confluence/tests/ConfluenceAuthorityTest.java?rev=1874903&view=auto ============================================================================== --- manifoldcf/branches/CONNECTORS-1637/connectors/confluence-v6/src/test/java/org/apache/manifoldcf/authorities/confluence/tests/ConfluenceAuthorityTest.java (added) +++ manifoldcf/branches/CONNECTORS-1637/connectors/confluence-v6/src/test/java/org/apache/manifoldcf/authorities/confluence/tests/ConfluenceAuthorityTest.java Fri Mar 6 15:29:45 2020 @@ -0,0 +1,88 @@ +/** +* 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.authorities.confluence.tests; + +import static org.mockito.Matchers.anyString; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.manifoldcf.authorities.authorities.confluence.v6.ConfluenceAuthorityConnector; +import org.apache.manifoldcf.authorities.interfaces.AuthorizationResponse; +import org.apache.manifoldcf.authorities.interfaces.IAuthorityConnector; +import org.apache.manifoldcf.core.interfaces.ICacheManager; +import org.apache.manifoldcf.crawler.connectors.confluence.v6.client.ConfluenceClient; +import org.apache.manifoldcf.crawler.connectors.confluence.v6.model.ConfluenceUser; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; + +@RunWith(MockitoJUnitRunner.class) +public class ConfluenceAuthorityTest { + + @Mock + private ConfluenceClient client; + + private ConfluenceAuthorityConnector connector; + + @Before + public void setup() throws Exception{ + connector = new ConfluenceAuthorityConnector(); + connector.setConfluenceClient(client); +// ICacheManager cacheManager = mock(ICacheManager.class); +// connector.setCacheManager(cacheManager); + } + + @Test + public void checkMockInjection() throws Exception{ + when(client.checkAuth()).thenReturn(true); + Assert.assertEquals(connector.check(), "Connection working"); + } + + @Test + public void checkUserNotFound() throws Exception{ + ConfluenceUser user = mock(ConfluenceUser.class); + when(user.getUsername()).thenReturn(null); + when(client.getUserAuthorities(anyString())).thenReturn(user); + AuthorizationResponse response = connector.getAuthorizationResponse(anyString()); + String[] tokens = response.getAccessTokens(); + Assert.assertEquals(tokens.length, 1); + Assert.assertEquals(tokens[0], IAuthorityConnector.GLOBAL_DENY_TOKEN); + Assert.assertEquals(response.getResponseStatus(), AuthorizationResponse.RESPONSE_USERNOTFOUND); + } + + @Test + public void checkUserFound() throws Exception{ + ConfluenceUser user = mock(ConfluenceUser.class); + when(user.getUsername()).thenReturn("A"); + List<String> tokens = new ArrayList<String>(); + tokens.add("B"); + when(user.getAuthorities()).thenReturn(tokens); + when(client.getUserAuthorities(anyString())).thenReturn(user); + AuthorizationResponse response = connector.getAuthorizationResponse(anyString()); + String[] tokens_aux = response.getAccessTokens(); + Assert.assertEquals(tokens_aux.length, 1); + Assert.assertEquals(tokens_aux[0], tokens.get(0)); + Assert.assertEquals(response.getResponseStatus(), AuthorizationResponse.RESPONSE_OK); + } + +} Added: manifoldcf/branches/CONNECTORS-1637/connectors/confluence-v6/src/test/java/org/apache/manifoldcf/crawler/connectors/confluence/tests/ConfluenceConnectorTest.java URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-1637/connectors/confluence-v6/src/test/java/org/apache/manifoldcf/crawler/connectors/confluence/tests/ConfluenceConnectorTest.java?rev=1874903&view=auto ============================================================================== --- manifoldcf/branches/CONNECTORS-1637/connectors/confluence-v6/src/test/java/org/apache/manifoldcf/crawler/connectors/confluence/tests/ConfluenceConnectorTest.java (added) +++ manifoldcf/branches/CONNECTORS-1637/connectors/confluence-v6/src/test/java/org/apache/manifoldcf/crawler/connectors/confluence/tests/ConfluenceConnectorTest.java Fri Mar 6 15:29:45 2020 @@ -0,0 +1,241 @@ +/** +* 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.crawler.connectors.confluence.tests; + +import static org.mockito.Matchers.anyInt; +import static org.mockito.Matchers.anyLong; +import static org.mockito.Matchers.anyObject; +import static org.mockito.Matchers.anyString; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.nio.charset.StandardCharsets; +import java.text.DateFormat; +import java.util.*; + +import org.apache.manifoldcf.agents.interfaces.RepositoryDocument; +import org.apache.manifoldcf.core.interfaces.Specification; +import org.apache.manifoldcf.crawler.connectors.BaseRepositoryConnector; +import org.apache.manifoldcf.crawler.connectors.confluence.v6.ConfluenceRepositoryConnector; +import org.apache.manifoldcf.crawler.connectors.confluence.v6.client.ConfluenceClient; +import org.apache.manifoldcf.crawler.connectors.confluence.v6.model.ConfluenceResponse; +import org.apache.manifoldcf.crawler.connectors.confluence.v6.model.ConfluenceRestrictionsResponse; +import org.apache.manifoldcf.crawler.connectors.confluence.v6.model.Group; +import org.apache.manifoldcf.crawler.connectors.confluence.v6.model.Page; +import org.apache.manifoldcf.crawler.connectors.confluence.v6.model.Restrictions; +import org.apache.manifoldcf.crawler.connectors.confluence.v6.model.Space; +import org.apache.manifoldcf.crawler.connectors.confluence.v6.model.User; +import org.apache.manifoldcf.crawler.connectors.confluence.v6.model.Restrictions.ReadRestrictions; +import org.apache.manifoldcf.crawler.interfaces.IExistingVersions; +import org.apache.manifoldcf.crawler.interfaces.IProcessActivity; +import org.apache.manifoldcf.crawler.system.SeedingActivity; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.ArgumentCaptor; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.runners.MockitoJUnitRunner; + +import com.google.common.base.Optional; + +@RunWith(MockitoJUnitRunner.class) +public class ConfluenceConnectorTest { + + @Mock + private ConfluenceClient client; + + private ConfluenceRepositoryConnector connector; + + @SuppressWarnings("unchecked") + @Before + public void setup() throws Exception{ + connector = new ConfluenceRepositoryConnector(); + connector.setConfluenceClient(client); + when(client.getSpaces(anyInt(), anyInt(), Mockito.any(Optional.class), Mockito.any(Optional.class))). + thenReturn(new ConfluenceResponse<Space>(Collections.<Space>emptyList(), 0, 0, true)); + } + + @SuppressWarnings("unchecked") + @Test + public void mockEmptySeeding() throws Exception { + + SeedingActivity activities = mock(SeedingActivity.class); + Specification spec = new Specification(); + long seedTime = 0; + + connector.addSeedDocuments(activities, spec, "", seedTime, BaseRepositoryConnector.JOBMODE_ONCEONLY); + // Verify it starts always at 0. Pagination configurable so anyInt(). Only one call because isLast must be false + verify(client, times(1)).getSpaces(eq(0), anyInt(), Mockito.any(Optional.class), Mockito.any(Optional.class)); + } + + @SuppressWarnings("unchecked") + @Test + public void mockSeeding() throws Exception { + + SeedingActivity activities = mock(SeedingActivity.class); + Specification spec = new Specification(); + long seedTime = 0; + + // Mock spaces + List<Space> spaces = new ArrayList<Space>(); + Space space = new Space(); + space.setKey("test"); + spaces.add(space); + when(client.getSpaces(anyInt(), anyInt(), Mockito.any(Optional.class), Mockito.any(Optional.class))). + thenReturn(new ConfluenceResponse<Space>(spaces, 0, 0, false)). + thenReturn(new ConfluenceResponse<Space>(Collections.<Space>emptyList(), 0, 0, true)); + + // Mock pages + List<Page> pages = new ArrayList<Page>(); + Page page = mock(Page.class); + pages.add(page); + when(client.getSpaceRootPages(anyInt(), anyInt(), anyString(), Mockito.any(Optional.class))). + thenReturn(new ConfluenceResponse<Page>(pages, 0, 0, false)). + thenReturn(new ConfluenceResponse<Page>(Collections.<Page>emptyList(), 0, 0, true)); + connector.addSeedDocuments(activities, spec, "", seedTime, BaseRepositoryConnector.JOBMODE_ONCEONLY); + verify(activities, times(1)).addSeedDocument(Mockito.anyString()); + verify(client, times(1)).getSpaces(eq(0), anyInt(), Mockito.any(Optional.class), Mockito.any(Optional.class)); + verify(client, times(1)).getSpaces(eq(1), anyInt(), Mockito.any(Optional.class), Mockito.any(Optional.class)); + verify(client, times(1)).getSpaceRootPages(eq(0), anyInt(), anyString(), Mockito.any(Optional.class)); + verify(client, times(1)).getSpaceRootPages(eq(1), anyInt(), anyString(), Mockito.any(Optional.class)); + } + + @Test + public void mockSimpleIngestion() throws Exception{ + + Page fakePage = mock(Page.class); + + Date date = new Date(); + DateFormat df = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, Locale.ROOT); + String content = "A"; + String uri = "http://test"; + byte[] documentBytes = content + .getBytes(StandardCharsets.UTF_8); + long size = (long) documentBytes.length; + + when(fakePage.hasContent()).thenReturn(true); + when(fakePage.getContent()).thenReturn(content); + when(fakePage.getLength()).thenReturn(size); + when(fakePage.getLastModifiedDate()).thenReturn(date); + when(fakePage.getMediaType()).thenReturn("text/plain"); + when(fakePage.getCreatedDate()).thenReturn(date); + when(fakePage.getWebUrl()).thenReturn(uri); + Map<String, Object> metadata = new HashMap<String, Object>(); + metadata.put("x", "y"); + when(fakePage.getMetadataAsMap()).thenReturn(metadata); + + IProcessActivity activities = mock(IProcessActivity.class); + when(activities.checkLengthIndexable(anyLong())) + .thenReturn(true); + when(activities.checkMimeTypeIndexable(anyString())) + .thenReturn(true); + when(activities.checkDateIndexable((Date)anyObject())) + .thenReturn(true); + when(activities.checkURLIndexable(anyString())) + .thenReturn(true); + when(activities.checkDocumentNeedsReindexing(anyString(), anyString())) + .thenReturn(true); + IExistingVersions statuses = mock(IExistingVersions.class); + + String ID = df.format(date); + when(statuses.getIndexedVersionString(ID)). + thenReturn(null); + + when(client.getPage(Mockito.anyString())). + thenReturn(fakePage); + + Restrictions restrictions = mock(Restrictions.class); + ReadRestrictions readRestrictions = mock(ReadRestrictions.class); + when(readRestrictions.getUsers()).thenReturn(new ArrayList<User>()); + when(readRestrictions.getGroups()).thenReturn(new ArrayList<Group>()); + when(restrictions.getReadRestrictions()).thenReturn(readRestrictions); + when(client.getPageReadRestrictions(anyInt(), anyInt(), anyString())). + thenReturn(new ConfluenceRestrictionsResponse<Restrictions>(restrictions, 0, 200, true)); + + connector.processDocuments(new String[]{ID}, statuses, new Specification(), activities, 0, true); + ArgumentCaptor<RepositoryDocument> rd = ArgumentCaptor.forClass(RepositoryDocument.class); + + verify(client, times(1)).getPage(ID); + verify(client, times(1)).getPageReadRestrictions(anyInt(), anyInt(), anyString()); + verify(activities, times(1)).ingestDocumentWithException(eq(ID), + eq(df.format(date) + "+0++0+"), eq(uri), rd.capture()); + verify(activities, times(1)).recordActivity(anyLong(), + eq("read document"), eq(size), eq(ID), eq("OK"), + anyString(), Mockito.isNull(String[].class)); + + RepositoryDocument doc = rd.getValue(); + Assert.assertEquals(size, doc.getBinaryLength()); + String[] values = doc.getFieldAsStrings("x"); + Assert.assertEquals(values.length, 1); + Assert.assertEquals(values[0], "y"); + + } + + @Test + public void mockNeedsReindexing() throws Exception{ + Restrictions restrictions = mock(Restrictions.class); + ReadRestrictions readRestrictions = mock(ReadRestrictions.class); + when(readRestrictions.getUsers()).thenReturn(new ArrayList<User>()); + when(readRestrictions.getGroups()).thenReturn(new ArrayList<Group>()); + when(restrictions.getReadRestrictions()).thenReturn(readRestrictions); + when(client.getPageReadRestrictions(anyInt(), anyInt(), anyString())). + thenReturn(new ConfluenceRestrictionsResponse<Restrictions>(restrictions, 0, 0, true)); + + Page fakePage = mock(Page.class); + when(fakePage.hasContent()).thenReturn(true); + Date date = new Date(); + DateFormat df = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, Locale.ROOT); + String version = df.format(date) + "+0++0+"; + when(fakePage.getLastModifiedDate()).thenReturn(df.parse(version)); + + String id = "1"; + IProcessActivity activities = mock(IProcessActivity.class); + IExistingVersions statuses = mock(IExistingVersions.class); + when(statuses.getIndexedVersionString(id)). + thenReturn(version); + + when(client.getPage(Mockito.anyString())). + thenReturn(fakePage); + + connector.processDocuments(new String[]{id}, statuses, new Specification(), activities, 0, true); + verify(client, times(1)).getPage(id); + verify(activities, times(1)).checkDocumentNeedsReindexing(id, version); + } + + @Test + public void mockDeleteDocument() throws Exception{ + Page fakePage = mock(Page.class); + when(fakePage.hasContent()).thenReturn(false); + String id = "A"; + when(fakePage.hasContent()).thenReturn(false); + when(client.getPage(Mockito.anyString())). + thenReturn(fakePage); + + IExistingVersions statuses = mock(IExistingVersions.class); + IProcessActivity activities = mock(IProcessActivity.class); + connector.processDocuments(new String[]{id}, statuses, new Specification(), activities, 0, true); + verify(client, times(1)).getPage(id); + verify(activities, times(1)).deleteDocument(id); + + } + +} Modified: manifoldcf/branches/CONNECTORS-1637/connectors/pom.xml URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-1637/connectors/pom.xml?rev=1874903&r1=1874902&r2=1874903&view=diff ============================================================================== --- manifoldcf/branches/CONNECTORS-1637/connectors/pom.xml (original) +++ manifoldcf/branches/CONNECTORS-1637/connectors/pom.xml Fri Mar 6 15:29:45 2020 @@ -67,6 +67,7 @@ <module>documentfilter</module> <module>searchblox</module> <module>confluence</module> + <module>confluence-v6</module> <module>amazons3</module> <module>kafka</module> <module>opennlp</module>
