manifoldcf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rh...@apache.org
Subject svn commit: r1770894 [3/3] - in /manifoldcf/branches/CONNECTORS-1290/connectors: ./ nuxeo/ nuxeo/connector/ nuxeo/connector/src/ nuxeo/connector/src/main/ nuxeo/connector/src/main/java/ nuxeo/connector/src/main/java/org/ nuxeo/connector/src/main/java/o...
Date Tue, 22 Nov 2016 23:11:09 GMT
Added: manifoldcf/branches/CONNECTORS-1290/connectors/nuxeo/connector/src/test/java/org/apache/manifoldcf/crawler/connectors/nuxeo/tests/NuxeoConnectorTest.java
URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-1290/connectors/nuxeo/connector/src/test/java/org/apache/manifoldcf/crawler/connectors/nuxeo/tests/NuxeoConnectorTest.java?rev=1770894&view=auto
==============================================================================
--- manifoldcf/branches/CONNECTORS-1290/connectors/nuxeo/connector/src/test/java/org/apache/manifoldcf/crawler/connectors/nuxeo/tests/NuxeoConnectorTest.java
(added)
+++ manifoldcf/branches/CONNECTORS-1290/connectors/nuxeo/connector/src/test/java/org/apache/manifoldcf/crawler/connectors/nuxeo/tests/NuxeoConnectorTest.java
Tue Nov 22 23:11:08 2016
@@ -0,0 +1,198 @@
+/**
+ * 
+ */
+package org.apache.manifoldcf.crawler.connectors.nuxeo.tests;
+
+import static org.junit.Assert.assertEquals;
+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.anyListOf;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
+import java.text.DateFormat;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+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.nuxeo.model.Document;
+import org.apache.manifoldcf.crawler.connectors.nuxeo.model.NuxeoResponse;
+import org.apache.manifoldcf.crawler.interfaces.IExistingVersions;
+import org.apache.manifoldcf.crawler.interfaces.IProcessActivity;
+import org.apache.manifoldcf.crawler.system.SeedingActivity;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+
+/**
+ * @author David Arroyo Escobar <arroyoescobardavid@gmail.com>
+ *
+ */
+@RunWith(MockitoJUnitRunner.class)
+public class NuxeoConnectorTest extends AbstractTest {
+
+	@Override
+	public void setup() throws Exception {
+		super.setup();
+
+		when(client.getDocuments(anyListOf(String.class), anyListOf(String.class), anyString(),
anyInt(), anyInt(),
+				anyObject())).thenReturn(new NuxeoResponse<Document>(Collections.<Document>
emptyList(), 0, 0, true));
+	};
+
+	@Test
+	public void checkMockInjection() throws Exception {
+		when(client.check()).thenReturn(true);
+		assertEquals(repositoryConnector.check(), "Connection working");
+	}
+
+	@Test
+	public void mockSeeding() throws Exception {
+		SeedingActivity activities = mock(SeedingActivity.class);
+		Specification spec = new Specification();
+		List<Document> documents = new ArrayList<Document>();
+		Document document = mock(Document.class);
+		long seedTime = 0;
+
+		documents.add(document);
+		documents.add(document);
+
+		when(client.getDocuments(anyListOf(String.class), anyListOf(String.class), anyString(),
anyInt(), anyInt(),
+				anyObject())).thenReturn(new NuxeoResponse<Document>(documents, 0, 0, true))
+						.thenReturn(new NuxeoResponse<Document>(Collections.<Document> emptyList(),
0, 0, true));
+
+		repositoryConnector.addSeedDocuments(activities, spec, "", seedTime,
+				BaseRepositoryConnector.JOBMODE_CONTINUOUS);
+
+		verify(activities, times(2)).addSeedDocument(anyString());
+		verify(client, times(1)).getDocuments(anyListOf(String.class), anyListOf(String.class),
anyString(), anyInt(),
+				anyInt(), anyObject());
+
+	}
+
+	@Test
+	public void mockEmptySeeding() throws Exception {
+		SeedingActivity activities = mock(SeedingActivity.class);
+		Specification spec = new Specification();
+		long seedTime = 0;
+
+		when(client.getDocuments(anyListOf(String.class), anyListOf(String.class), anyString(),
anyInt(), anyInt(),
+				anyObject())).thenReturn(new NuxeoResponse<Document>(Collections.<Document>
emptyList(), 0, 0, true));
+
+		repositoryConnector.addSeedDocuments(activities, spec, "", seedTime,
+				BaseRepositoryConnector.JOBMODE_CONTINUOUS);
+
+		verify(activities, times(0)).addSeedDocument(anyString());
+		verify(client, times(1)).getDocuments(anyListOf(String.class), anyListOf(String.class),
anyString(), anyInt(),
+				anyInt(), anyObject());
+
+	}
+
+	@Test
+	public void mockDeleteDocument() throws Exception {
+		Document doc = mock(Document.class);
+		String uid = "297529bf-191a-4c87-8259-28b692394229";
+		Specification spec = new Specification();
+		IProcessActivity activities = mock(IProcessActivity.class);
+		IExistingVersions statuses = mock(IExistingVersions.class);
+
+		when(doc.getState()).thenReturn("deleted");
+		when(client.getDocument(uid)).thenReturn(doc);
+
+		repositoryConnector.processDocuments(new String[] { uid }, statuses, spec, activities,
+				BaseRepositoryConnector.JOBMODE_CONTINUOUS, true);
+
+		verify(client, times(1)).getDocument(anyString());
+		verify(activities, times(1)).deleteDocument(uid);
+	}
+
+	@Test
+	public void mockSimpleIngestion() throws Exception {
+
+		Document doc = mock(Document.class);
+		Date date = new Date();
+		DateFormat df = DateFormat.getDateTimeInstance();
+		Long size = 0L;
+		String id;
+		String uri = "http://localhost:8080/nuxeo/site/api/v1/id/7995ff6d-1eda-41db-b9de-3ea4037fdb81";
+		Map<String, Object> metadata = new HashMap<String, Object>();
+		IProcessActivity activities = mock(IProcessActivity.class);
+		IExistingVersions statuses = mock(IExistingVersions.class);
+		Specification spec = new Specification();
+		String mediaType = "text/html; charset=utf-8";
+
+		metadata.put("key", "value");
+		id = df.format(date);
+
+		when(doc.getLenght()).thenReturn(size);
+		when(doc.getLastModified()).thenReturn(date);
+		when(doc.getMediatype()).thenReturn(mediaType);
+		when(doc.getMetadataAsMap()).thenReturn(metadata);
+		when(doc.getUid()).thenReturn(uri);
+
+		when(activities.checkDocumentNeedsReindexing(anyString(), anyString())).thenReturn(true);
+
+		when(statuses.getIndexedVersionString(id)).thenReturn(null);
+
+		when(client.getDocument(anyString())).thenReturn(doc);
+
+		when(client.getPathDocument(anyString())).thenReturn(uri);
+
+		repositoryConnector.processDocuments(new String[] { id }, statuses, spec, activities,
+				BaseRepositoryConnector.JOBMODE_CONTINUOUS, true);
+		ArgumentCaptor<RepositoryDocument> ac = ArgumentCaptor.forClass(RepositoryDocument.class);
+
+		verify(client, times(1)).getDocument(id);
+		verify(activities, times(1)).ingestDocumentWithException(eq(id), eq(df.format(date)), eq(uri),
ac.capture());
+		verify(activities, times(1)).recordActivity(anyLong(), eq("read document"), eq(size), eq(id),
eq("OK"),
+				anyString(), Mockito.isNull(String[].class));
+
+		RepositoryDocument rd = ac.getValue();
+		Long rdSize = rd.getBinaryLength();
+
+		String[] keyValue = rd.getFieldAsStrings("key");
+		assertEquals(size, rdSize);
+
+		assertEquals(keyValue.length, 1);
+		assertEquals(keyValue[0], "value");
+	}
+
+	@Test
+	public void mockNotNeedReindexing() throws Exception {
+		Document doc = mock(Document.class);
+		Date date = new Date();
+		DateFormat df = DateFormat.getDateTimeInstance();
+		String version = df.format(date);
+		String uid = "297529bf-191a-4c87-8259-28b692394229";
+
+		IProcessActivity activities = mock(IProcessActivity.class);
+		IExistingVersions statuses = mock(IExistingVersions.class);
+		Specification spec = new Specification();
+
+		when(doc.getLastModified()).thenReturn(df.parse(version));
+		when(statuses.getIndexedVersionString(uid)).thenReturn(version);
+		when(client.getDocument(anyString())).thenReturn(doc);
+
+		repositoryConnector.processDocuments(new String[] { uid }, statuses, spec, activities,
+				BaseRepositoryConnector.JOBMODE_CONTINUOUS, true);
+		ArgumentCaptor<RepositoryDocument> ac = ArgumentCaptor.forClass(RepositoryDocument.class);
+
+		verify(client, times(1)).getDocument(uid);
+		verify(activities, times(1)).checkDocumentNeedsReindexing(uid, version);
+		verify(activities, times(0)).ingestDocumentWithException(anyString(), anyString(), anyString(),
ac.capture());
+
+	}
+
+}

Propchange: manifoldcf/branches/CONNECTORS-1290/connectors/nuxeo/connector/src/test/java/org/apache/manifoldcf/crawler/connectors/nuxeo/tests/NuxeoConnectorTest.java
------------------------------------------------------------------------------
    svn:executable = *

Added: manifoldcf/branches/CONNECTORS-1290/connectors/nuxeo/pom.xml
URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-1290/connectors/nuxeo/pom.xml?rev=1770894&view=auto
==============================================================================
--- manifoldcf/branches/CONNECTORS-1290/connectors/nuxeo/pom.xml (added)
+++ manifoldcf/branches/CONNECTORS-1290/connectors/nuxeo/pom.xml Tue Nov 22 23:11:08 2016
@@ -0,0 +1,372 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <parent>
+    <groupId>org.apache.manifoldcf</groupId>
+    <artifactId>mcf-connectors</artifactId>
+    <version>2.6-SNAPSHOT</version>
+  </parent>
+
+  <name>ManifoldCF - Connectors - Nuxeo Connector</name>
+  <modelVersion>4.0.0</modelVersion>
+  <artifactId>mcf-nuxeo-connector</artifactId>
+  <packaging>jar</packaging>
+
+  <url>http://maven.apache.org</url>
+
+  <developers>
+    <developer>
+      <name>David Arroyo Escobar</name>
+      <email>arroyoescobardavid@gmail.com</email>
+    </developer>
+  </developers>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
+  </properties>
+
+  <build>
+    <defaultGoal>integration-test</defaultGoal>
+    <sourceDirectory>${basedir}/connector/src/main/java</sourceDirectory>
+    <testSourceDirectory>${basedir}/connector/src/test/java</testSourceDirectory>
+    <resources>
+      <resource>
+        <directory>${basedir}/connector/src/main/native2ascii</directory>
+        <includes>
+          <include>**/*.properties</include>
+        </includes>
+      </resource>
+      <resource>
+        <directory>${basedir}/connector/src/main/resources</directory>
+        <includes>
+          <include>**/*.html</include>
+          <include>**/*.js</include>
+        </includes>
+      </resource>
+    </resources>
+    <testResources>
+      <testResource>
+        <directory>${basedir}/connector/src/test/resources</directory>
+      </testResource>
+    </testResources>
+
+
+    <plugins>
+      <plugin>
+        <groupId>org.codehaus.mojo</groupId>
+        <artifactId>native2ascii-maven-plugin</artifactId>
+        <version>1.0-beta-1</version>
+        <configuration>
+          <workDir>target/classes</workDir>
+        </configuration>
+        <executions>
+          <execution>
+            <id>native2ascii-utf8</id>
+            <goals>
+              <goal>native2ascii</goal>
+            </goals>
+            <configuration>
+              <encoding>UTF8</encoding>
+              <includes>
+                <include>**/*.properties</include>
+              </includes>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+
+      <!-- Test plugin configuration -->
+      <plugin>
+        <artifactId>maven-dependency-plugin</artifactId>
+        <executions>
+          <execution>
+            <id>copy-war</id>
+            <phase>generate-resources</phase>
+            <goals>
+              <goal>copy</goal>
+            </goals>
+            <configuration>
+              <outputDirectory>target/dependency</outputDirectory>
+              <artifactItems>
+                <artifactItem>
+                  <groupId>${project.groupId}</groupId>
+                  <artifactId>mcf-api-service</artifactId>
+                  <version>${project.version}</version>
+                  <type>war</type>
+                  <overWrite>false</overWrite>
+                  <destFileName>mcf-api-service.war</destFileName>
+                </artifactItem>
+                <artifactItem>
+                  <groupId>${project.groupId}</groupId>
+                  <artifactId>mcf-authority-service</artifactId>
+                  <version>${project.version}</version>
+                  <type>war</type>
+                  <overWrite>false</overWrite>
+                  <destFileName>mcf-authority-service.war</destFileName>
+                </artifactItem>
+                <artifactItem>
+                  <groupId>${project.groupId}</groupId>
+                  <artifactId>mcf-crawler-ui</artifactId>
+                  <version>${project.version}</version>
+                  <type>war</type>
+                  <overWrite>false</overWrite>
+                  <destFileName>mcf-crawler-ui.war</destFileName>
+                </artifactItem>
+              </artifactItems>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+
+
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <configuration>
+          <excludes>
+            <exclude>**/*Postgresql*.java</exclude>
+            <exclude>**/*MySQL*.java</exclude>
+          </excludes>
+          <forkCount>1</forkCount>
+          <reuseForks>false</reuseForks>
+          <workingDirectory>target/test-output</workingDirectory>
+        </configuration>
+      </plugin>
+
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-failsafe-plugin</artifactId>
+        <version>2.18.1</version>
+        <configuration>
+          <skipTests>${skipITs}</skipTests>
+          <systemPropertyVariables>
+            <crawlerWarPath>../dependency/mcf-crawler-ui.war</crawlerWarPath>
+            <authorityserviceWarPath>../dependency/mcf-authority-service.war</authorityserviceWarPath>
+            <apiWarPath>../dependency/mcf-api-service.war</apiWarPath>
+          </systemPropertyVariables>
+          <excludes>
+            <exclude>**/*Postgresql*.java</exclude>
+            <exclude>**/*MySQL*.java</exclude>
+          </excludes>
+          <forkCount>1</forkCount>
+          <reuseForks>false</reuseForks>
+          <workingDirectory>target/test-output</workingDirectory>
+        </configuration>
+        <executions>
+          <execution>
+            <id>integration-test</id>
+            <goals>
+              <goal>integration-test</goal>
+            </goals>
+          </execution>
+          <execution>
+            <id>verify</id>
+            <goals>
+              <goal>verify</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+
+    </plugins>
+    <pluginManagement>
+      <plugins>
+        <!--This plugin's configuration is used to store Eclipse m2e settings 
+          only. It has no influence on the Maven build itself. -->
+        <plugin>
+          <groupId>org.eclipse.m2e</groupId>
+          <artifactId>lifecycle-mapping</artifactId>
+          <version>1.0.0</version>
+          <configuration>
+            <lifecycleMappingMetadata>
+              <pluginExecutions>
+                <pluginExecution>
+                  <pluginExecutionFilter>
+                    <groupId>
+                      org.apache.maven.plugins
+                    </groupId>
+                    <artifactId>
+                      maven-dependency-plugin
+                    </artifactId>
+                    <versionRange>
+                      [2.8,)
+                    </versionRange>
+                    <goals>
+                      <goal>copy</goal>
+                    </goals>
+                  </pluginExecutionFilter>
+                  <action>
+                    <ignore></ignore>
+                  </action>
+                </pluginExecution>
+                <pluginExecution>
+                  <pluginExecutionFilter>
+                    <groupId>
+                      org.codehaus.mojo
+                    </groupId>
+                    <artifactId>
+                      native2ascii-maven-plugin
+                    </artifactId>
+                    <versionRange>
+                      [1.0-beta-1,)
+                    </versionRange>
+                    <goals>
+                      <goal>native2ascii</goal>
+                    </goals>
+                  </pluginExecutionFilter>
+                  <action>
+                    <ignore></ignore>
+                  </action>
+                </pluginExecution>
+                <pluginExecution>
+                  <pluginExecutionFilter>
+                    <groupId>
+                      org.apache.maven.plugins
+                    </groupId>
+                    <artifactId>
+                      maven-remote-resources-plugin
+                    </artifactId>
+                    <versionRange>
+                      [1.5,)
+                    </versionRange>
+                    <goals>
+                      <goal>process</goal>
+                    </goals>
+                  </pluginExecutionFilter>
+                  <action>
+                    <ignore></ignore>
+                  </action>
+                </pluginExecution>
+              </pluginExecutions>
+            </lifecycleMappingMetadata>
+          </configuration>
+        </plugin>
+      </plugins>
+    </pluginManagement>
+  </build>
+
+
+
+  <dependencies>
+    <dependency>
+      <groupId>${project.groupId}</groupId>
+      <artifactId>mcf-core</artifactId>
+      <version>${project.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>${project.groupId}</groupId>
+      <artifactId>mcf-connector-common</artifactId>
+      <version>${project.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>${project.groupId}</groupId>
+      <artifactId>mcf-pull-agent</artifactId>
+      <version>${project.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>${project.groupId}</groupId>
+      <artifactId>mcf-agents</artifactId>
+      <version>${project.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>${project.groupId}</groupId>
+      <artifactId>mcf-ui-core</artifactId>
+      <version>${project.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>commons-lang</groupId>
+      <artifactId>commons-lang</artifactId>
+      <version>${commons-lang.version}</version>
+      <type>jar</type>
+    </dependency>
+
+    <dependency>
+      <groupId>com.google.guava</groupId>
+      <artifactId>guava</artifactId>
+      <version>15.0</version>
+    </dependency>
+    
+    <!-- Testing dependencies -->
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>${junit.version}</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.mockito</groupId>
+      <artifactId>mockito-core</artifactId>
+      <version>${mockito.version}</version>
+      <scope>test</scope>
+    </dependency>
+
+    <dependency>
+      <groupId>com.github.tomakehurst</groupId>
+      <artifactId>wiremock</artifactId>
+      <version>${wiremock.version}</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>${project.groupId}</groupId>
+      <artifactId>mcf-core</artifactId>
+      <version>${project.version}</version>
+      <type>test-jar</type>
+      <scope>test</scope>
+    </dependency>
+
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-api</artifactId>
+      <version>${slf4j.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-simple</artifactId>
+      <version>${slf4j.version}</version>
+    </dependency>
+
+    <dependency>
+      <groupId>commons-logging</groupId>
+      <artifactId>commons-logging</artifactId>
+      <version>1.1.1</version>
+      <scope>test</scope>
+    </dependency>
+
+    <dependency>
+      <groupId>log4j</groupId>
+      <artifactId>log4j</artifactId>
+      <version>1.2.16</version>
+      <scope>provided</scope>
+      <type>jar</type>
+    </dependency>
+    <dependency>
+      <groupId>com.googlecode.json-simple</groupId>
+      <artifactId>json-simple</artifactId>
+      <version>1.1</version>
+    </dependency>
+    <dependency>
+      <groupId>commons-codec</groupId>
+      <artifactId>commons-codec</artifactId>
+      <version>1.8</version>
+    </dependency>
+  </dependencies>
+
+</project>

Propchange: manifoldcf/branches/CONNECTORS-1290/connectors/nuxeo/pom.xml
------------------------------------------------------------------------------
    svn:executable = *

Modified: manifoldcf/branches/CONNECTORS-1290/connectors/pom.xml
URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-1290/connectors/pom.xml?rev=1770894&r1=1770893&r2=1770894&view=diff
==============================================================================
--- manifoldcf/branches/CONNECTORS-1290/connectors/pom.xml (original)
+++ manifoldcf/branches/CONNECTORS-1290/connectors/pom.xml Tue Nov 22 23:11:08 2016
@@ -69,6 +69,7 @@
     <module>amazons3</module>
     <module>kafka</module>
     <module>opennlp</module>
+    <module>nuxeo</module>
   </modules>
 
 </project>



Mime
View raw message