Added: manifoldcf/branches/CONNECTORS-1490/connectors/mongodb/src/main/resources/org/apache/manifoldcf/agents/output/mongodboutput/viewConfiguration.html URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-1490/connectors/mongodb/src/main/resources/org/apache/manifoldcf/agents/output/mongodboutput/viewConfiguration.html?rev=1837604&view=auto ============================================================================== --- manifoldcf/branches/CONNECTORS-1490/connectors/mongodb/src/main/resources/org/apache/manifoldcf/agents/output/mongodboutput/viewConfiguration.html (added) +++ manifoldcf/branches/CONNECTORS-1490/connectors/mongodb/src/main/resources/org/apache/manifoldcf/agents/output/mongodboutput/viewConfiguration.html Tue Aug 7 15:07:07 2018 @@ -0,0 +1,65 @@ +<!-- + 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('MongodbConnector.hostNameColon'))</nobr> + </td> + <td class="value">$Encoder.bodyEscape($HOST)</td> + <tr> + <td class="description"> + <nobr>$Encoder.bodyEscape($ResourceBundle.getString('MongodbConnector.PortNumberColon'))</nobr> + <td class="value">$Encoder.bodyEscape($PORT)</td> + </tr> + </tr> + <tr> + <td class="description"> + <nobr>$Encoder.bodyEscape($ResourceBundle.getString('MongodbConnector.UserNameColon'))</nobr> + </td> + <td class="value">$Encoder.bodyEscape($USERNAME)</td> + </tr> + <tr> + <td class="description"> + <nobr>$Encoder.bodyEscape($ResourceBundle.getString('MongodbConnector.PasswordColon'))</nobr> + </td> + <td class="value"> + #if($Encoder.bodyEscape($PASSWORD) != "") + ******** + #else + + #end + </td> + </tr> + <tr> + <td class="description"> + <nobr>$Encoder.bodyEscape($ResourceBundle.getString('MongodbConnector.DatabaseColon'))</nobr> + </td> + <td class="value"> + <nobr>$Encoder.bodyEscape($DATABASE)</nobr> + </td> + </tr> + <tr> + <td class="description"> + <nobr>$Encoder.bodyEscape($ResourceBundle.getString('MongodbConnector.CollectionColon'))</nobr> + </td> + <td class="value"> + <nobr>$Encoder.bodyEscape($COLLECTION)</nobr> + </td> + </tr> + +</table> \ No newline at end of file
Added: manifoldcf/branches/CONNECTORS-1490/connectors/mongodb/src/test/java/org/apache/manifoldcf/agents/output/mongodboutput/tests/APISanityHSQLDBIT.java URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-1490/connectors/mongodb/src/test/java/org/apache/manifoldcf/agents/output/mongodboutput/tests/APISanityHSQLDBIT.java?rev=1837604&view=auto ============================================================================== --- manifoldcf/branches/CONNECTORS-1490/connectors/mongodb/src/test/java/org/apache/manifoldcf/agents/output/mongodboutput/tests/APISanityHSQLDBIT.java (added) +++ manifoldcf/branches/CONNECTORS-1490/connectors/mongodb/src/test/java/org/apache/manifoldcf/agents/output/mongodboutput/tests/APISanityHSQLDBIT.java Tue Aug 7 15:07:07 2018 @@ -0,0 +1,429 @@ +/* $Id$ */ + +/** + * 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 + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * 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.mongodboutput.tests; + +import com.mongodb.*; +import org.apache.manifoldcf.agents.output.mongodboutput.MongodbOutputConfig; +import org.apache.manifoldcf.core.interfaces.Configuration; +import org.apache.manifoldcf.core.interfaces.ConfigurationNode; +import org.apache.manifoldcf.core.interfaces.ManifoldCFException; +import org.apache.manifoldcf.crawler.system.ManifoldCF; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import java.net.UnknownHostException; +import java.util.Collections; + +/** + * @author Irindu Nugawela + */ +public class APISanityHSQLDBIT extends BaseITHSQLDB { + + private MongoClient client = null; + private DB mongoDatabase = null; + private DBCollection testCollection = null; + + private MongoClient getMongodbClientSession() throws Exception { + + MongoClient testClient = null; + + try { + testClient = new MongoClient(BaseITSanityTestUtils.TARGET_HOST_VALUE, Integer.parseInt(BaseITSanityTestUtils.TARGET_PORT_VALUE)); + mongoDatabase = testClient.getDB(BaseITSanityTestUtils.TARGET_DATABASE__VALUE); + } catch (UnknownHostException ex) { + throw new ManifoldCFException("Mongodb: Default host is not found. Is mongod process running?" + ex.getMessage(), ex); + } + + return testClient; + } + + private long queryTestContents(DBCollection testCollection) { + // deduct 1 for the document we created at the test area + return testCollection.count() - 1; + } + + @Before + public void createTestArea() + throws Exception { + try { + + client = getMongodbClientSession(); + + //creating a test database named testDatabase + mongoDatabase = client.getDB(BaseITSanityTestUtils.TARGET_DATABASE__VALUE); + + //creating a test collection named testCollection + testCollection = mongoDatabase.getCollection(BaseITSanityTestUtils.TARGET_COLLECTION_VALUE); + + //create credentials + final BasicDBObject createUserCommand = new BasicDBObject("createUser", BaseITSanityTestUtils.TARGET_USERNAME_VALUE).append("pwd", BaseITSanityTestUtils.TARGET_PASSWORD_VALUE).append("roles", + Collections.singletonList(new BasicDBObject("role", "readWrite").append("db", BaseITSanityTestUtils.TARGET_DATABASE__VALUE))); + + + CommandResult result = mongoDatabase.command(createUserCommand); + + //create a document to be inserted + BasicDBObject newDocument = new BasicDBObject(); + newDocument.append("fileName", "fileName") + .append("creationDate", "creationDate") + .append("lastModificationDate", "lastModificationDate") + .append("binaryLength", "binaryLength") + .append("documentURI", "documentURI") + .append("mimeType", "mimeType") + .append("lastModificationDate", "lastModificationDate") + .append("content", "content") + .append("sourcePath", "sourcePath"); + + //insert the test document so that the test collection and test Database are created + testCollection.insert(newDocument); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + + @After + public void removeTestArea() + throws Exception { + + // deleting the dummyuser + final BasicDBObject deleteUserCommand = new BasicDBObject("dropUser", BaseITSanityTestUtils.TARGET_USERNAME_VALUE); + CommandResult result = mongoDatabase.command(deleteUserCommand); + + // dropping the test Collection + testCollection.drop(); + + // dropping the test Database + mongoDatabase.dropDatabase(); + } + + @Test + public void sanityCheck() + throws Exception { + try { + + int i; + + // Create a basic file system connection, and save it. + ConfigurationNode connectionObject; + ConfigurationNode child; + Configuration requestObject; + Configuration result; + + connectionObject = new ConfigurationNode("repositoryconnection"); + + child = new ConfigurationNode("name"); + child.setValue("Test Connection"); + connectionObject.addChild(connectionObject.getChildCount(), child); + + child = new ConfigurationNode("class_name"); + child.setValue("org.apache.manifoldcf.crawler.tests.TestingRepositoryConnector"); + connectionObject.addChild(connectionObject.getChildCount(), child); + + child = new ConfigurationNode("description"); + child.setValue("Test Connection"); + connectionObject.addChild(connectionObject.getChildCount(), child); + + child = new ConfigurationNode("max_connections"); + child.setValue("10"); + connectionObject.addChild(connectionObject.getChildCount(), child); + + child = new ConfigurationNode("configuration"); + + //Testing Repository Connector parameters + + connectionObject.addChild(connectionObject.getChildCount(), child); + + requestObject = new Configuration(); + requestObject.addChild(0, connectionObject); + + result = performAPIPutOperationViaNodes("repositoryconnections/Test%20Connection", 201, requestObject); + + i = 0; + while (i < result.getChildCount()) { + ConfigurationNode resultNode = result.findChild(i++); + if (resultNode.getType().equals("error")) + throw new Exception(resultNode.getValue()); + } + + // Create a Mongodb output connection, and save it. + connectionObject = new ConfigurationNode("outputconnection"); + + child = new ConfigurationNode("name"); + child.setValue("MongoDB Output Connection"); + connectionObject.addChild(connectionObject.getChildCount(), child); + + child = new ConfigurationNode("class_name"); + child.setValue("org.apache.manifoldcf.agents.output.mongodboutput.MongodbOutputConnector"); + connectionObject.addChild(connectionObject.getChildCount(), child); + + child = new ConfigurationNode("description"); + child.setValue("MongoDB Output Connection - Target repo of the content migration"); + connectionObject.addChild(connectionObject.getChildCount(), child); + + child = new ConfigurationNode("max_connections"); + child.setValue("100"); + connectionObject.addChild(connectionObject.getChildCount(), child); + + child = new ConfigurationNode("configuration"); + + //Mongodb Output Connector parameters + + //host + ConfigurationNode host = new ConfigurationNode("_PARAMETER_"); + host.setAttribute("name", MongodbOutputConfig.HOST_PARAM); + host.setValue(BaseITSanityTestUtils.TARGET_HOST_VALUE); + child.addChild(child.getChildCount(), host); + + //port + ConfigurationNode port = new ConfigurationNode("_PARAMETER_"); + port.setAttribute("name", MongodbOutputConfig.PORT_PARAM); + port.setValue(BaseITSanityTestUtils.TARGET_PORT_VALUE); + child.addChild(child.getChildCount(), port); + + //database + ConfigurationNode database = new ConfigurationNode("_PARAMETER_"); + database.setAttribute("name", MongodbOutputConfig.DATABASE_PARAM); + database.setValue(BaseITSanityTestUtils.TARGET_DATABASE__VALUE); + child.addChild(child.getChildCount(), database); + + //collection + ConfigurationNode collection = new ConfigurationNode("_PARAMETER_"); + collection.setAttribute("name", MongodbOutputConfig.COLLECTION_PARAM); + collection.setValue(BaseITSanityTestUtils.TARGET_COLLECTION_VALUE); + child.addChild(child.getChildCount(), collection); + + //username + ConfigurationNode username = new ConfigurationNode("_PARAMETER_"); + username.setAttribute("name", MongodbOutputConfig.USERNAME_PARAM); + username.setValue(BaseITSanityTestUtils.TARGET_USERNAME_VALUE); + child.addChild(child.getChildCount(), username); + + //password + ConfigurationNode password = new ConfigurationNode("_PARAMETER_"); + password.setAttribute("name", MongodbOutputConfig.PASSWORD_PARAM); + password.setValue(BaseITSanityTestUtils.TARGET_PASSWORD_VALUE); + child.addChild(child.getChildCount(), password); + + + connectionObject.addChild(connectionObject.getChildCount(), child); + + requestObject = new Configuration(); + requestObject.addChild(0, connectionObject); + + result = performAPIPutOperationViaNodes("outputconnections/MongoDB%20Output%20Connection", 201, requestObject); + + i = 0; + while (i < result.getChildCount()) { + ConfigurationNode resultNode = result.findChild(i++); + if (resultNode.getType().equals("error")) + throw new Exception(resultNode.getValue()); + } + + // Create a job. + ConfigurationNode jobObject = new ConfigurationNode("job"); + + child = new ConfigurationNode("description"); + child.setValue("Test Job"); + jobObject.addChild(jobObject.getChildCount(), child); + + child = new ConfigurationNode("repository_connection"); + child.setValue("Test Connection"); + jobObject.addChild(jobObject.getChildCount(), child); + + // Revamped way of adding output connection + child = new ConfigurationNode("pipelinestage"); + ConfigurationNode pipelineChild = new ConfigurationNode("stage_id"); + pipelineChild.setValue("0"); + child.addChild(child.getChildCount(), pipelineChild); + pipelineChild = new ConfigurationNode("stage_isoutput"); + pipelineChild.setValue("true"); + child.addChild(child.getChildCount(), pipelineChild); + pipelineChild = new ConfigurationNode("stage_connectionname"); + pipelineChild.setValue("MongoDB Output Connection"); + child.addChild(child.getChildCount(), pipelineChild); + jobObject.addChild(jobObject.getChildCount(), child); + + child = new ConfigurationNode("run_mode"); + child.setValue("scan once"); + jobObject.addChild(jobObject.getChildCount(), child); + + child = new ConfigurationNode("start_mode"); + child.setValue("manual"); + jobObject.addChild(jobObject.getChildCount(), child); + + child = new ConfigurationNode("hopcount_mode"); + child.setValue("accurate"); + jobObject.addChild(jobObject.getChildCount(), child); + + child = new ConfigurationNode("document_specification"); + + jobObject.addChild(jobObject.getChildCount(), child); + + requestObject = new Configuration(); + requestObject.addChild(0, jobObject); + + result = performAPIPostOperationViaNodes("jobs", 201, requestObject); + + String jobIDString = null; + i = 0; + while (i < result.getChildCount()) { + ConfigurationNode resultNode = result.findChild(i++); + if (resultNode.getType().equals("error")) + throw new Exception(resultNode.getValue()); + else if (resultNode.getType().equals("job_id")) + jobIDString = resultNode.getValue(); + } + if (jobIDString == null) + throw new Exception("Missing job_id from return!"); + + // Now, start the job, and wait until it completes. + startJob(jobIDString); + waitJobInactive(jobIDString, 240000L); + + // Check to be sure we actually processed the right number of documents. + // The test data area has 3 documents and one directory, and we have to count the root directory too. + long count; + count = getJobDocumentsProcessed(jobIDString); + + if (count != 3) + throw new ManifoldCFException("Wrong number of documents processed - expected 3, saw " + new Long(count).toString()); + + //Tests if these three documents are stored in the target repo + long targetRepoNumberOfContents = queryTestContents(testCollection); + if (targetRepoNumberOfContents != 3) + throw new ManifoldCFException("Wrong number of documents stored in the MongoDB Target repo - expected 3, saw " + new Long(targetRepoNumberOfContents).toString()); + + // Now, delete the job. + deleteJob(jobIDString); + + waitJobDeleted(jobIDString, 240000L); + + // Cleanup is automatic by the base class, so we can feel free to leave jobs and connections lying around. + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + protected void startJob(String jobIDString) + throws Exception { + Configuration requestObject = new Configuration(); + + Configuration result = performAPIPutOperationViaNodes("start/" + jobIDString, 201, requestObject); + int i = 0; + while (i < result.getChildCount()) { + ConfigurationNode resultNode = result.findChild(i++); + if (resultNode.getType().equals("error")) + throw new Exception(resultNode.getValue()); + } + } + + protected void deleteJob(String jobIDString) + throws Exception { + Configuration result = performAPIDeleteOperationViaNodes("jobs/" + jobIDString, 200); + int i = 0; + while (i < result.getChildCount()) { + ConfigurationNode resultNode = result.findChild(i++); + if (resultNode.getType().equals("error")) + throw new Exception(resultNode.getValue()); + } + + } + + protected String getJobStatus(String jobIDString) + throws Exception { + Configuration result = performAPIGetOperationViaNodes("jobstatuses/" + jobIDString, 200); + String status = null; + int i = 0; + while (i < result.getChildCount()) { + ConfigurationNode resultNode = result.findChild(i++); + if (resultNode.getType().equals("error")) + throw new Exception(resultNode.getValue()); + else if (resultNode.getType().equals("jobstatus")) { + int j = 0; + while (j < resultNode.getChildCount()) { + ConfigurationNode childNode = resultNode.findChild(j++); + if (childNode.getType().equals("status")) + status = childNode.getValue(); + } + } + } + return status; + } + + protected long getJobDocumentsProcessed(String jobIDString) + throws Exception { + Configuration result = performAPIGetOperationViaNodes("jobstatuses/" + jobIDString, 200); + String documentsProcessed = null; + int i = 0; + while (i < result.getChildCount()) { + ConfigurationNode resultNode = result.findChild(i++); + if (resultNode.getType().equals("error")) + throw new Exception(resultNode.getValue()); + else if (resultNode.getType().equals("jobstatus")) { + int j = 0; + while (j < resultNode.getChildCount()) { + ConfigurationNode childNode = resultNode.findChild(j++); + if (childNode.getType().equals("documents_processed")) + documentsProcessed = childNode.getValue(); + } + } + } + if (documentsProcessed == null) + throw new Exception("Expected a documents_processed field, didn't find it"); + return new Long(documentsProcessed).longValue(); + } + + protected void waitJobInactive(String jobIDString, long maxTime) + throws Exception { + long startTime = System.currentTimeMillis(); + while (System.currentTimeMillis() < startTime + maxTime) { + String status = getJobStatus(jobIDString); + if (status == null) + throw new Exception("No such job: '" + jobIDString + "'"); + if (status.equals("not yet run")) + throw new Exception("Job was never started."); + if (status.equals("done")) + return; + if (status.equals("error")) + throw new Exception("Job reports error."); + ManifoldCF.sleep(1000L); + continue; + } + throw new ManifoldCFException("ManifoldCF did not terminate in the allotted time of " + new Long(maxTime).toString() + " milliseconds"); + } + + + protected void waitJobDeleted(String jobIDString, long maxTime) + throws Exception { + long startTime = System.currentTimeMillis(); + while (System.currentTimeMillis() < startTime + maxTime) { + String status = getJobStatus(jobIDString); + if (status == null) + return; + ManifoldCF.sleep(1000L); + } + throw new ManifoldCFException("ManifoldCF did not delete in the allotted time of " + new Long(maxTime).toString() + " milliseconds"); + } + + +} Added: manifoldcf/branches/CONNECTORS-1490/connectors/mongodb/src/test/java/org/apache/manifoldcf/agents/output/mongodboutput/tests/BaseHSQLDB.java URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-1490/connectors/mongodb/src/test/java/org/apache/manifoldcf/agents/output/mongodboutput/tests/BaseHSQLDB.java?rev=1837604&view=auto ============================================================================== --- manifoldcf/branches/CONNECTORS-1490/connectors/mongodb/src/test/java/org/apache/manifoldcf/agents/output/mongodboutput/tests/BaseHSQLDB.java (added) +++ manifoldcf/branches/CONNECTORS-1490/connectors/mongodb/src/test/java/org/apache/manifoldcf/agents/output/mongodboutput/tests/BaseHSQLDB.java Tue Aug 7 15:07:07 2018 @@ -0,0 +1,33 @@ +/* $Id$ */ + +/** + * 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 + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * 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.mongodboutput.tests; + + +/** This is a testing base class that is responsible for setting up/tearing down the agents framework. */ +public class BaseHSQLDB extends org.apache.manifoldcf.crawler.tests.BaseHSQLDB { + + protected String[] getOutputNames() { + return new String[]{"MongoDB"}; + } + + protected String[] getOutputClasses() { + return new String[]{"org.apache.manifoldcf.agents.output.mongodboutput.MongodbOutputConnector"}; + } + +} Added: manifoldcf/branches/CONNECTORS-1490/connectors/mongodb/src/test/java/org/apache/manifoldcf/agents/output/mongodboutput/tests/BaseITHSQLDB.java URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-1490/connectors/mongodb/src/test/java/org/apache/manifoldcf/agents/output/mongodboutput/tests/BaseITHSQLDB.java?rev=1837604&view=auto ============================================================================== --- manifoldcf/branches/CONNECTORS-1490/connectors/mongodb/src/test/java/org/apache/manifoldcf/agents/output/mongodboutput/tests/BaseITHSQLDB.java (added) +++ manifoldcf/branches/CONNECTORS-1490/connectors/mongodb/src/test/java/org/apache/manifoldcf/agents/output/mongodboutput/tests/BaseITHSQLDB.java Tue Aug 7 15:07:07 2018 @@ -0,0 +1,64 @@ +/* $Id$ */ + +/** + * 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 + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * 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.mongodboutput.tests; + +import org.junit.After; +import org.junit.Before; + +/** + * Base integration tests class for MongoDB tested against a CMIS repository + * + * @author Irindu Nugawela + */ +public class BaseITHSQLDB extends org.apache.manifoldcf.crawler.tests.BaseITHSQLDB { + + protected String[] getConnectorNames() { + return new String[]{"CMIS"}; + } + + protected String[] getConnectorClasses() { + return new String[]{"org.apache.manifoldcf.crawler.tests.TestingRepositoryConnector"}; + } + + protected String[] getOutputNames() { + return new String[]{"MongoDB"}; + } + + protected String[] getOutputClasses() { + return new String[]{"org.apache.manifoldcf.agents.output.mongodboutput.MongodbOutputConnector"}; + } + + // Setup/teardown + + @Before + public void setUpMongoDB() + throws Exception { + + //start mongod here + //we use maven docker plugin for this so no need to implement + } + + @After + public void cleanUpMongoDB() + throws Exception { + //stop mongod here + //we use maven docker plugin for this so no need to implement + } + +} Added: manifoldcf/branches/CONNECTORS-1490/connectors/mongodb/src/test/java/org/apache/manifoldcf/agents/output/mongodboutput/tests/BaseITSanityTestUtils.java URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-1490/connectors/mongodb/src/test/java/org/apache/manifoldcf/agents/output/mongodboutput/tests/BaseITSanityTestUtils.java?rev=1837604&view=auto ============================================================================== --- manifoldcf/branches/CONNECTORS-1490/connectors/mongodb/src/test/java/org/apache/manifoldcf/agents/output/mongodboutput/tests/BaseITSanityTestUtils.java (added) +++ manifoldcf/branches/CONNECTORS-1490/connectors/mongodb/src/test/java/org/apache/manifoldcf/agents/output/mongodboutput/tests/BaseITSanityTestUtils.java Tue Aug 7 15:07:07 2018 @@ -0,0 +1,38 @@ +/* $Id$ */ + +/** + * 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 + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * 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.mongodboutput.tests; + +/** + * Utility class dedicated to integration tests for the MongoDB Output Connector + * + * @author Irindu Nugawela + * + */ +public class BaseITSanityTestUtils { + + + //Test values for the source repository + public static final String TARGET_USERNAME_VALUE = "dummyuser"; + public static final String TARGET_PASSWORD_VALUE = "dummysecrect"; + public static final String TARGET_HOST_VALUE = "localhost"; + public static final String TARGET_PORT_VALUE = "27017"; + public static final String TARGET_DATABASE__VALUE = "testDatabase"; + public static final String TARGET_COLLECTION_VALUE = "testCollection"; + +} Added: manifoldcf/branches/CONNECTORS-1490/connectors/mongodb/src/test/java/org/apache/manifoldcf/agents/output/mongodboutput/tests/BasePostgresql.java URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-1490/connectors/mongodb/src/test/java/org/apache/manifoldcf/agents/output/mongodboutput/tests/BasePostgresql.java?rev=1837604&view=auto ============================================================================== --- manifoldcf/branches/CONNECTORS-1490/connectors/mongodb/src/test/java/org/apache/manifoldcf/agents/output/mongodboutput/tests/BasePostgresql.java (added) +++ manifoldcf/branches/CONNECTORS-1490/connectors/mongodb/src/test/java/org/apache/manifoldcf/agents/output/mongodboutput/tests/BasePostgresql.java Tue Aug 7 15:07:07 2018 @@ -0,0 +1,29 @@ +/** + * 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 + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * 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.mongodboutput.tests; + +/** This is a testing base class that is responsible for setting up/tearing down the agents framework. */ +public class BasePostgresql extends org.apache.manifoldcf.crawler.tests.ConnectorBasePostgresql { + protected String[] getOutputNames() { + return new String[]{"MongoDB"}; + } + + protected String[] getOutputClasses() { + return new String[]{"org.apache.manifoldcf.agents.output.mongodboutput.MongodbOutputConnector"}; + } + +} Added: manifoldcf/branches/CONNECTORS-1490/connectors/mongodb/src/test/java/org/apache/manifoldcf/agents/output/mongodboutput/tests/BaseUIHSQLDB.java URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-1490/connectors/mongodb/src/test/java/org/apache/manifoldcf/agents/output/mongodboutput/tests/BaseUIHSQLDB.java?rev=1837604&view=auto ============================================================================== --- manifoldcf/branches/CONNECTORS-1490/connectors/mongodb/src/test/java/org/apache/manifoldcf/agents/output/mongodboutput/tests/BaseUIHSQLDB.java (added) +++ manifoldcf/branches/CONNECTORS-1490/connectors/mongodb/src/test/java/org/apache/manifoldcf/agents/output/mongodboutput/tests/BaseUIHSQLDB.java Tue Aug 7 15:07:07 2018 @@ -0,0 +1,39 @@ +/* $Id$ */ + +/** + * 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 + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * 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.mongodboutput.tests; + +/** Tests that run the "agents daemon" should be derived from this */ +public class BaseUIHSQLDB extends org.apache.manifoldcf.crawler.tests.ConnectorBaseUIHSQLDB { + protected String[] getConnectorNames() { + return new String[]{"Test Connector"}; + } + + protected String[] getConnectorClasses() { + return new String[]{"org.apache.manifoldcf.crawler.tests.TestingRepositoryConnector"}; + } + + protected String[] getOutputNames() { + return new String[]{"Mongodb Output Connector"}; + } + + protected String[] getOutputClasses() { + return new String[]{"org.apache.manifoldcf.agents.output.mongodboutput.MongodbOutputConnector"}; + } + +} Added: manifoldcf/branches/CONNECTORS-1490/connectors/mongodb/src/test/java/org/apache/manifoldcf/agents/output/mongodboutput/tests/NavigationHSQLDBUI.java URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-1490/connectors/mongodb/src/test/java/org/apache/manifoldcf/agents/output/mongodboutput/tests/NavigationHSQLDBUI.java?rev=1837604&view=auto ============================================================================== --- manifoldcf/branches/CONNECTORS-1490/connectors/mongodb/src/test/java/org/apache/manifoldcf/agents/output/mongodboutput/tests/NavigationHSQLDBUI.java (added) +++ manifoldcf/branches/CONNECTORS-1490/connectors/mongodb/src/test/java/org/apache/manifoldcf/agents/output/mongodboutput/tests/NavigationHSQLDBUI.java Tue Aug 7 15:07:07 2018 @@ -0,0 +1,156 @@ +/* $Id$ */ + +/** + * 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 + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * 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.mongodboutput.tests; + +import org.apache.manifoldcf.core.tests.SeleniumTester; +import org.junit.Test; + +/** + * Basic UI navigation tests + */ +public class NavigationHSQLDBUI extends BaseUIHSQLDB { + + @Test + public void createConnectionsAndJob() + throws Exception { + testerInstance.start(SeleniumTester.BrowserType.CHROME, "en-US", "http://localhost:8346/mcf-crawler-ui/index.jsp"); + + //Login + testerInstance.waitForElementWithName("loginform"); + testerInstance.setValue("userID", "admin"); + testerInstance.setValue("password", "admin"); + testerInstance.clickButton("Login"); + testerInstance.verifyHeader("Welcome to Apache ManifoldCFâ¢"); + testerInstance.navigateTo("List output connections"); + testerInstance.clickButton("Add a new output connection"); + + // Fill in a name + testerInstance.waitForElementWithName("connname"); + testerInstance.setValue("connname", "MyOutputConnection"); + + //Goto to Type tab + testerInstance.clickTab("Type"); + + // Select a type + testerInstance.waitForElementWithName("classname"); + testerInstance.selectValue("classname", "org.apache.manifoldcf.agents.output.mongodboutput.MongodbOutputConnector"); + testerInstance.clickButton("Continue"); + + // Visit the Throttling tab + testerInstance.clickTab("Throttling"); + + // Parameters tab + testerInstance.clickTab("Parameters"); + testerInstance.setValue("host", "localhost"); + testerInstance.setValue("port", "27017"); + testerInstance.setValue("username", "mongoadmin"); + testerInstance.setValue("password", "secret"); + testerInstance.setValue("database", "testDatabase"); + testerInstance.setValue("collection", "testCollection"); + + // Go back to the Name tab + testerInstance.clickTab("Name"); + + // Now save the connection. + testerInstance.clickButton("Save"); + testerInstance.verifyThereIsNoError(); + + // Define a repository connection via the UI + testerInstance.navigateTo("List repository connections"); + testerInstance.clickButton("Add new connection"); + + testerInstance.waitForElementWithName("connname"); + testerInstance.setValue("connname", "MyRepositoryConnection"); + + // Select a type + testerInstance.clickTab("Type"); + testerInstance.selectValue("classname", "org.apache.manifoldcf.crawler.tests.TestingRepositoryConnector"); + testerInstance.clickButton("Continue"); + + // Visit the Throttling tab + testerInstance.clickTab("Throttling"); + + // Go back to the Name tab + testerInstance.clickTab("Name"); + + // Save + testerInstance.clickButton("Save"); + testerInstance.verifyThereIsNoError(); + + // Create a job + testerInstance.navigateTo("List jobs"); + //Add a job + testerInstance.clickButton("Add a new job"); + testerInstance.waitForElementWithName("description"); + //Fill in a name + testerInstance.setValue("description", "MyJob"); + testerInstance.clickTab("Connection"); + + // Select the connections + testerInstance.selectValue("output_connectionname", "MyOutputConnection"); + testerInstance.selectValue("output_precedent", "-1"); + testerInstance.clickButton("Add output", true); + testerInstance.waitForElementWithName("connectionname"); + testerInstance.selectValue("connectionname", "MyRepositoryConnection"); + + testerInstance.clickButton("Continue"); + + // Visit all the tabs. Scheduling tab first + testerInstance.clickTab("Scheduling"); + testerInstance.selectValue("dayofweek", "0"); + testerInstance.selectValue("hourofday", "1"); + testerInstance.selectValue("minutesofhour", "30"); + testerInstance.selectValue("monthofyear", "11"); + testerInstance.selectValue("dayofmonth", "none"); + testerInstance.setValue("duration", "120"); + testerInstance.clickButton("Add Scheduled Time", true); + testerInstance.waitForElementWithName("editjob"); + + // Save the job + testerInstance.clickButton("Save"); + testerInstance.verifyThereIsNoError(); + + testerInstance.waitForPresenceById("job"); + String jobID = testerInstance.getAttributeValueById("job", "jobid"); + + //Navigate to List Jobs + testerInstance.navigateTo("List jobs"); + testerInstance.waitForElementWithName("listjobs"); + + //Delete the job + testerInstance.clickButtonByTitle("Delete job " + jobID); + testerInstance.acceptAlert(); + testerInstance.verifyThereIsNoError(); + + //Wait for the job to go away + testerInstance.waitForJobDeleteEN(jobID, 120); + + // Delete the repository connection + testerInstance.navigateTo("List repository connections"); + testerInstance.clickButtonByTitle("Delete MyRepositoryConnection"); + testerInstance.acceptAlert(); + + // Delete the output connection + testerInstance.navigateTo("List output connections"); + testerInstance.clickButtonByTitle("Delete MyOutputConnection"); + testerInstance.acceptAlert(); + + } + +} Added: manifoldcf/branches/CONNECTORS-1490/connectors/mongodb/src/test/java/org/apache/manifoldcf/agents/output/mongodboutput/tests/SanityHSQLDBTest.java URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-1490/connectors/mongodb/src/test/java/org/apache/manifoldcf/agents/output/mongodboutput/tests/SanityHSQLDBTest.java?rev=1837604&view=auto ============================================================================== --- manifoldcf/branches/CONNECTORS-1490/connectors/mongodb/src/test/java/org/apache/manifoldcf/agents/output/mongodboutput/tests/SanityHSQLDBTest.java (added) +++ manifoldcf/branches/CONNECTORS-1490/connectors/mongodb/src/test/java/org/apache/manifoldcf/agents/output/mongodboutput/tests/SanityHSQLDBTest.java Tue Aug 7 15:07:07 2018 @@ -0,0 +1,33 @@ +/* $Id$ */ + +/** + * 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 + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * 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.mongodboutput.tests; + +import org.junit.Test; + +/** This is a very basic sanity check */ +public class SanityHSQLDBTest extends BaseHSQLDB { + + @Test + public void sanityCheck() + throws Exception { + // If we get this far, it must mean that the setup was successful, which is all that I'm shooting for in this test. + } + + +} Added: manifoldcf/branches/CONNECTORS-1490/connectors/mongodb/src/test/java/org/apache/manifoldcf/agents/output/mongodboutput/tests/SanityPostgresqlTest.java URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-1490/connectors/mongodb/src/test/java/org/apache/manifoldcf/agents/output/mongodboutput/tests/SanityPostgresqlTest.java?rev=1837604&view=auto ============================================================================== --- manifoldcf/branches/CONNECTORS-1490/connectors/mongodb/src/test/java/org/apache/manifoldcf/agents/output/mongodboutput/tests/SanityPostgresqlTest.java (added) +++ manifoldcf/branches/CONNECTORS-1490/connectors/mongodb/src/test/java/org/apache/manifoldcf/agents/output/mongodboutput/tests/SanityPostgresqlTest.java Tue Aug 7 15:07:07 2018 @@ -0,0 +1,33 @@ +/* $Id: SanityPostgresqlTest.java 1800083 2017-06-27 19:55:21Z piergiorgio $ */ + +/** + * 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 + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * 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.mongodboutput.tests; + +import org.junit.Test; + +/** This is a very basic sanity check */ +public class SanityPostgresqlTest extends BasePostgresql { + + @Test + public void sanityCheck() + throws Exception { + // If we get this far, it must mean that the setup was successful, which is all that I'm shooting for in this test. + } + + +} Modified: manifoldcf/branches/CONNECTORS-1490/connectors/pom.xml URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-1490/connectors/pom.xml?rev=1837604&r1=1837603&r2=1837604&view=diff ============================================================================== --- manifoldcf/branches/CONNECTORS-1490/connectors/pom.xml (original) +++ manifoldcf/branches/CONNECTORS-1490/connectors/pom.xml Tue Aug 7 15:07:07 2018 @@ -75,6 +75,7 @@ <module>slack</module> <module>rocketchat</module> <module>html-extractor</module> + <module>mongodb</module> </modules> </project>
