You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2013/08/01 05:48:39 UTC
[1/2] git commit: CAMEL-6595 fixed the test packages name issue of
camel-cmis with thanks to Maurizio
Updated Branches:
refs/heads/camel-2.11.x 929609587 -> c90c9dc99
refs/heads/master 7f3907db6 -> f336cb311
CAMEL-6595 fixed the test packages name issue of camel-cmis with thanks to Maurizio
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/f336cb31
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/f336cb31
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/f336cb31
Branch: refs/heads/master
Commit: f336cb311a623fb098509baebcb2001126e7073b
Parents: 7f3907d
Author: Willem Jiang <ni...@apache.org>
Authored: Thu Aug 1 11:43:51 2013 +0800
Committer: Willem Jiang <ni...@apache.org>
Committed: Thu Aug 1 11:44:31 2013 +0800
----------------------------------------------------------------------
.../camel/componenet/cmis/CMISConsumerTest.java | 104 -----------
.../camel/componenet/cmis/CMISProducerTest.java | 181 -------------------
.../componenet/cmis/CMISQueryProducerTest.java | 109 -----------
.../camel/componenet/cmis/CMISTestSupport.java | 163 -----------------
.../camel/component/cmis/CMISConsumerTest.java | 104 +++++++++++
.../camel/component/cmis/CMISProducerTest.java | 180 ++++++++++++++++++
.../component/cmis/CMISQueryProducerTest.java | 109 +++++++++++
.../camel/component/cmis/CMISTestSupport.java | 163 +++++++++++++++++
8 files changed, 556 insertions(+), 557 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/f336cb31/components/camel-cmis/src/test/java/org/apache/camel/componenet/cmis/CMISConsumerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-cmis/src/test/java/org/apache/camel/componenet/cmis/CMISConsumerTest.java b/components/camel-cmis/src/test/java/org/apache/camel/componenet/cmis/CMISConsumerTest.java
deleted file mode 100644
index ff2a695..0000000
--- a/components/camel-cmis/src/test/java/org/apache/camel/componenet/cmis/CMISConsumerTest.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/**
- * 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.camel.componenet.cmis;
-
-import java.io.UnsupportedEncodingException;
-import java.util.List;
-
-import org.apache.camel.Consumer;
-import org.apache.camel.Endpoint;
-import org.apache.camel.EndpointInject;
-import org.apache.camel.Exchange;
-import org.apache.camel.Processor;
-import org.apache.camel.component.mock.MockEndpoint;
-import org.apache.chemistry.opencmis.client.api.Folder;
-import org.junit.Before;
-import org.junit.Test;
-
-public class CMISConsumerTest extends CMISTestSupport {
-
- @EndpointInject(uri = "mock:result")
- protected MockEndpoint resultEndpoint;
-
- @Test
- public void getAllContentFromServerOrderedFromRootToLeaves() throws Exception {
- resultEndpoint.expectedMessageCount(5);
-
- Consumer treeBasedConsumer = createConsumerFor(CMIS_ENDPOINT_TEST_SERVER);
- treeBasedConsumer.start();
-
- resultEndpoint.assertIsSatisfied();
- treeBasedConsumer.stop();
-
- List<Exchange> exchanges = resultEndpoint.getExchanges();
- assertTrue(getNodeNameForIndex(exchanges, 0).equals("RootFolder"));
- assertTrue(getNodeNameForIndex(exchanges, 1).equals("Folder1"));
- assertTrue(getNodeNameForIndex(exchanges, 2).equals("Folder2"));
- assertTrue(getNodeNameForIndex(exchanges, 3).contains(".txt"));
- assertTrue(getNodeNameForIndex(exchanges, 4).contains(".txt"));
- }
-
- @Test
- public void consumeDocumentsWithQuery() throws Exception {
- resultEndpoint.expectedMessageCount(2);
-
- Consumer queryBasedConsumer = createConsumerFor(
- CMIS_ENDPOINT_TEST_SERVER + "?query=SELECT * FROM cmis:document");
- queryBasedConsumer.start();
- resultEndpoint.assertIsSatisfied();
- queryBasedConsumer.stop();
- }
-
- private Consumer createConsumerFor(String path) throws Exception {
- Endpoint endpoint = context.getEndpoint("cmis://" + path);
- return endpoint.createConsumer(new Processor() {
- public void process(Exchange exchange) throws Exception {
- template.send("mock:result", exchange);
- }
- });
- }
-
- private String getNodeNameForIndex(List<Exchange> exchanges, int index) {
- return exchanges.get(index).getIn().getHeader("cmis:name", String.class);
- }
-
- private void populateRepositoryRootFolderWithTwoFoldersAndTwoDocuments()
- throws UnsupportedEncodingException {
- Folder folder1 = createFolderWithName("Folder1");
- Folder folder2 = createChildFolderWithName(folder1, "Folder2");
- createTextDocument(folder2, "Document2.1", "2.1.txt");
- createTextDocument(folder2, "Document2.2", "2.2.txt");
- //L0 ROOT
- // |
- //L1 Folder1
- //L2 |_____Folder2
- // ||
- //L3 Doc2.1___||___Doc2.2
- }
-
- @Override
- public boolean isUseRouteBuilder() {
- return false;
- }
-
- @Override
- @Before
- public void setUp() throws Exception {
- super.setUp();
- populateRepositoryRootFolderWithTwoFoldersAndTwoDocuments();
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/f336cb31/components/camel-cmis/src/test/java/org/apache/camel/componenet/cmis/CMISProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-cmis/src/test/java/org/apache/camel/componenet/cmis/CMISProducerTest.java b/components/camel-cmis/src/test/java/org/apache/camel/componenet/cmis/CMISProducerTest.java
deleted file mode 100644
index a972e61..0000000
--- a/components/camel-cmis/src/test/java/org/apache/camel/componenet/cmis/CMISProducerTest.java
+++ /dev/null
@@ -1,181 +0,0 @@
-/**
- * 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.camel.componenet.cmis;
-
-import org.apache.camel.Endpoint;
-import org.apache.camel.Exchange;
-import org.apache.camel.NoSuchHeaderException;
-import org.apache.camel.Produce;
-import org.apache.camel.Producer;
-import org.apache.camel.ProducerTemplate;
-import org.apache.camel.ResolveEndpointFailedException;
-import org.apache.camel.RuntimeExchangeException;
-import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.cmis.CamelCMISConstants;
-import org.apache.chemistry.opencmis.client.api.CmisObject;
-import org.apache.chemistry.opencmis.client.api.Document;
-import org.apache.chemistry.opencmis.client.api.Folder;
-import org.apache.chemistry.opencmis.commons.PropertyIds;
-import org.junit.Test;
-
-public class CMISProducerTest extends CMISTestSupport {
-
- @Produce(uri = "direct:start")
- protected ProducerTemplate template;
-
- @Test
- public void storeMessageBodyAsTextDocument() throws Exception {
- String content = "Some content to be store";
- Exchange exchange = createExchangeWithInBody(content);
- exchange.getIn().getHeaders().put(PropertyIds.CONTENT_STREAM_MIME_TYPE, "text/plain; charset=UTF-8");
- exchange.getIn().getHeaders().put(PropertyIds.NAME, "test.file");
-
- template.send(exchange);
-
- String newNodeId = exchange.getOut().getBody(String.class);
- assertNotNull(newNodeId);
-
- String newNodeContent = getDocumentContentAsString(newNodeId);
- assertEquals(content, newNodeContent);
- }
-
- @Test
- public void getDocumentMimeTypeFromMessageContentType() throws Exception {
- Exchange exchange = createExchangeWithInBody("Some content to be store");
- exchange.getIn().getHeaders().put(Exchange.CONTENT_TYPE, "text/plain");
- exchange.getIn().getHeaders().put(PropertyIds.NAME, "test.file");
-
- template.send(exchange);
- String newNodeId = exchange.getOut().getBody(String.class);
-
- CmisObject cmisObject = retrieveCMISObjectByIdFromServer(newNodeId);
- Document doc = (Document)cmisObject;
- assertEquals("text/plain", doc.getPropertyValue(PropertyIds.CONTENT_STREAM_MIME_TYPE));
- }
-
- @Test
- public void namePropertyIsAlwaysRequired() {
- Exchange exchange = createExchangeWithInBody("Some content that will fail to be stored");
- exchange.getIn().getHeaders().put(PropertyIds.CONTENT_STREAM_MIME_TYPE, "text/plain; charset=UTF-8");
-
- template.send(exchange);
- Exception exception = exchange.getException();
- Object body = exchange.getOut().getBody();
-
- assertNull(body);
- assertTrue(exception instanceof NoSuchHeaderException);
- }
-
- @Test
- public void createDocumentWithoutContentByExplicitlySpecifyingObjectTypeHeader() throws Exception {
- Exchange exchange = createExchangeWithInBody(null);
- exchange.getIn().getHeaders().put(PropertyIds.CONTENT_STREAM_MIME_TYPE, "text/plain; charset=UTF-8");
- exchange.getIn().getHeaders().put(PropertyIds.OBJECT_TYPE_ID, "cmis:document");
- exchange.getIn().getHeaders().put(PropertyIds.NAME, "test.file");
-
- template.send(exchange);
- String newNodeId = exchange.getOut().getBody(String.class);
- assertNotNull(newNodeId);
-
- CmisObject cmisObject = retrieveCMISObjectByIdFromServer(newNodeId);
- Document doc = (Document)cmisObject;
- assertEquals("cmis:document", doc.getPropertyValue(PropertyIds.OBJECT_TYPE_ID));
- }
-
- @Test
- public void emptyBodyAndMissingObjectTypeHeaderCreatesFolderNode() throws Exception {
- Exchange exchange = createExchangeWithInBody(null);
- exchange.getIn().getHeaders().put(PropertyIds.NAME, "testFolder");
-
- template.send(exchange);
- String newNodeId = exchange.getOut().getBody(String.class);
- assertNotNull(newNodeId);
-
- CmisObject newNode = retrieveCMISObjectByIdFromServer(newNodeId);
- assertEquals("cmis:folder", newNode.getType().getId());
- assertTrue(newNode instanceof Folder);
- }
-
- @Test
- public void cmisPropertiesAreStored() throws Exception {
- Exchange exchange = createExchangeWithInBody("Some content to be store");
- exchange.getIn().getHeaders().put(PropertyIds.CONTENT_STREAM_MIME_TYPE, "text/plain; charset=UTF-8");
- exchange.getIn().getHeaders().put(PropertyIds.NAME, "test.txt");
-
- template.send(exchange);
- String newNodeId = exchange.getOut().getBody(String.class);
- CmisObject newNode = retrieveCMISObjectByIdFromServer(newNodeId);
-
- assertEquals("test.txt", newNode.getPropertyValue(PropertyIds.NAME));
- assertEquals("text/plain; charset=UTF-8",
- newNode.getPropertyValue(PropertyIds.CONTENT_STREAM_MIME_TYPE));
- }
-
- @Test(expected = ResolveEndpointFailedException.class)
- public void failConnectingToNonExistingRepository() throws Exception {
- Endpoint endpoint = context.getEndpoint("cmis://" + CMIS_ENDPOINT_TEST_SERVER
- + "?username=admin&password=admin&repositoryId=NON_EXISTING_ID");
- Producer producer = endpoint.createProducer();
-
- Exchange exchange = createExchangeWithInBody("Some content to be store");
- exchange.getIn().getHeaders().put(PropertyIds.NAME, "test.txt");
- producer.process(exchange);
- }
-
- @Test
- public void createDocumentAtSpecificPath() throws Exception {
- Folder folder1 = createFolderWithName("Folder1");
- createChildFolderWithName(folder1, "Folder2");
- String existingFolderStructure = "/Folder1/Folder2";
-
- Exchange exchange = createExchangeWithInBody("Some content to be stored");
- exchange.getIn().getHeaders().put(PropertyIds.CONTENT_STREAM_MIME_TYPE, "text/plain; charset=UTF-8");
- exchange.getIn().getHeaders().put(PropertyIds.NAME, "test.file");
- exchange.getIn().getHeaders().put(CamelCMISConstants.CMIS_FOLDER_PATH, existingFolderStructure);
-
- template.send(exchange);
- String newNodeId = exchange.getOut().getBody(String.class);
-
- Document document = (Document)retrieveCMISObjectByIdFromServer(newNodeId);
- String documentFullPath = document.getPaths().get(0);
- assertEquals(existingFolderStructure + "/test.file", documentFullPath);
- }
-
- @Test
- public void failCreatingFolderAtNonExistingPath() throws Exception {
- String existingFolderStructure = "/No/Path/Here";
-
- Exchange exchange = createExchangeWithInBody(null);
- exchange.getIn().getHeaders().put(PropertyIds.NAME, "folder1");
- exchange.getIn().getHeaders().put(PropertyIds.OBJECT_TYPE_ID, "cmis:folder");
- exchange.getIn().getHeaders().put(CamelCMISConstants.CMIS_FOLDER_PATH, existingFolderStructure);
-
- template.send(exchange);
- assertTrue(exchange.getException() instanceof RuntimeExchangeException);
- }
-
- @Override
- protected RouteBuilder createRouteBuilder() throws Exception {
- return new RouteBuilder() {
- public void configure() {
- from("direct:start")
- .to("cmis://" + CMIS_ENDPOINT_TEST_SERVER);
- }
- };
- }
-
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/f336cb31/components/camel-cmis/src/test/java/org/apache/camel/componenet/cmis/CMISQueryProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-cmis/src/test/java/org/apache/camel/componenet/cmis/CMISQueryProducerTest.java b/components/camel-cmis/src/test/java/org/apache/camel/componenet/cmis/CMISQueryProducerTest.java
deleted file mode 100644
index d81eca0..0000000
--- a/components/camel-cmis/src/test/java/org/apache/camel/componenet/cmis/CMISQueryProducerTest.java
+++ /dev/null
@@ -1,109 +0,0 @@
-/**
- * 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.camel.componenet.cmis;
-
-import java.io.InputStream;
-import java.io.UnsupportedEncodingException;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.camel.Endpoint;
-import org.apache.camel.Exchange;
-import org.apache.camel.Producer;
-import org.apache.chemistry.opencmis.client.api.Folder;
-import org.junit.Before;
-import org.junit.Test;
-
-public class CMISQueryProducerTest extends CMISTestSupport {
-
- @Override
- @Before
- public void setUp() throws Exception {
- super.setUp();
- populateServerWithContent();
- }
-
- @Test
- public void queryServerForDocumentWithSpecificName() throws Exception {
- Endpoint endpoint = context.getEndpoint("cmis://" + CMIS_ENDPOINT_TEST_SERVER + "?queryMode=true");
- Producer producer = endpoint.createProducer();
-
- Exchange exchange = createExchangeWithInBody(
- "SELECT * FROM cmis:document WHERE cmis:name = 'test1.txt'");
- producer.process(exchange);
-
- @SuppressWarnings("unchecked")
- List<Map<String, Object>> documents = exchange.getOut().getBody(List.class);
- assertEquals(1, documents.size());
- assertEquals("test1.txt", documents.get(0).get("cmis:name"));
- }
-
- @Test
- public void getResultCountFromHeader() throws Exception {
- Endpoint endpoint = context.getEndpoint("cmis://" + CMIS_ENDPOINT_TEST_SERVER + "?queryMode=true");
- Producer producer = endpoint.createProducer();
-
- Exchange exchange = createExchangeWithInBody(
- "SELECT * FROM cmis:document WHERE CONTAINS('Camel test content.')");
- producer.process(exchange);
-
- @SuppressWarnings("unchecked")
- List<Map<String, Object>> documents = exchange.getOut().getBody(List.class);
- assertEquals(2, documents.size());
- assertEquals(2, exchange.getOut().getHeader("CamelCMISResultCount"));
- }
-
- @Test
- public void limitNumberOfResultsWithReadSizeHeader() throws Exception {
- Endpoint endpoint = context.getEndpoint("cmis://" + CMIS_ENDPOINT_TEST_SERVER + "?queryMode=true");
- Producer producer = endpoint.createProducer();
-
- Exchange exchange = createExchangeWithInBody(
- "SELECT * FROM cmis:document WHERE CONTAINS('Camel test content.')");
- exchange.getIn().getHeaders().put("CamelCMISReadSize", 1);
-
- producer.process(exchange);
-
- @SuppressWarnings("unchecked")
- List<Map<String, Object>> documents = exchange.getOut().getBody(List.class);
- assertEquals(1, documents.size());
- }
-
- @Test
- public void retrieveAlsoDocumentContent() throws Exception {
- Endpoint endpoint = context.getEndpoint("cmis://" + CMIS_ENDPOINT_TEST_SERVER + "?queryMode=true");
- Producer producer = endpoint.createProducer();
-
- Exchange exchange = createExchangeWithInBody(
- "SELECT * FROM cmis:document WHERE cmis:name='test1.txt'");
- exchange.getIn().getHeaders().put("CamelCMISRetrieveContent", true);
-
- producer.process(exchange);
-
- @SuppressWarnings("unchecked")
- List<Map<String, Object>> documents = exchange.getOut().getBody(List.class);
- InputStream content = (InputStream)documents.get(0).get("CamelCMISContent");
- assertEquals("This is the first Camel test content.", readFromStream(content));
- }
-
- private void populateServerWithContent() throws UnsupportedEncodingException {
- Folder newFolder = createFolderWithName("CamelCmisTestFolder");
- createTextDocument(newFolder, "This is the first Camel test content.", "test1.txt");
- createTextDocument(newFolder, "This is the second Camel test content.", "test2.txt");
- }
-
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/f336cb31/components/camel-cmis/src/test/java/org/apache/camel/componenet/cmis/CMISTestSupport.java
----------------------------------------------------------------------
diff --git a/components/camel-cmis/src/test/java/org/apache/camel/componenet/cmis/CMISTestSupport.java b/components/camel-cmis/src/test/java/org/apache/camel/componenet/cmis/CMISTestSupport.java
deleted file mode 100644
index 138f219..0000000
--- a/components/camel-cmis/src/test/java/org/apache/camel/componenet/cmis/CMISTestSupport.java
+++ /dev/null
@@ -1,163 +0,0 @@
-/**
- * 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.camel.componenet.cmis;
-
-import java.io.BufferedReader;
-import java.io.ByteArrayInputStream;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.UnsupportedEncodingException;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.camel.Exchange;
-import org.apache.camel.impl.DefaultExchange;
-import org.apache.camel.test.junit4.CamelTestSupport;
-import org.apache.chemistry.opencmis.client.api.CmisObject;
-import org.apache.chemistry.opencmis.client.api.Document;
-import org.apache.chemistry.opencmis.client.api.Folder;
-import org.apache.chemistry.opencmis.client.api.ItemIterable;
-import org.apache.chemistry.opencmis.client.api.Repository;
-import org.apache.chemistry.opencmis.client.api.Session;
-import org.apache.chemistry.opencmis.client.api.SessionFactory;
-import org.apache.chemistry.opencmis.client.runtime.SessionFactoryImpl;
-import org.apache.chemistry.opencmis.commons.PropertyIds;
-import org.apache.chemistry.opencmis.commons.SessionParameter;
-import org.apache.chemistry.opencmis.commons.data.ContentStream;
-import org.apache.chemistry.opencmis.commons.enums.BindingType;
-import org.apache.chemistry.opencmis.commons.enums.UnfileObject;
-import org.apache.chemistry.opencmis.commons.enums.VersioningState;
-import org.eclipse.jetty.server.Server;
-import org.eclipse.jetty.webapp.WebAppContext;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-
-public class CMISTestSupport extends CamelTestSupport {
- protected static final String CMIS_ENDPOINT_TEST_SERVER
- = "http://localhost:9090/chemistry-opencmis-server-inmemory/atom";
- protected static final String OPEN_CMIS_SERVER_WAR_PATH
- = "target/dependency/chemistry-opencmis-server-inmemory-0.8.0.war";
-
- protected static Server cmisServer;
-
- protected Exchange createExchangeWithInBody(String body) {
- DefaultExchange exchange = new DefaultExchange(context);
- if (body != null) {
- exchange.getIn().setBody(body);
- }
- return exchange;
- }
-
- protected CmisObject retrieveCMISObjectByIdFromServer(String nodeId) throws Exception {
- Session session = createSession();
- return session.getObject(nodeId);
- }
-
- protected void deleteAllContent() {
- Session session = createSession();
- Folder rootFolder = session.getRootFolder();
- ItemIterable<CmisObject> children = rootFolder.getChildren();
- for (CmisObject cmisObject : children) {
- if ("cmis:folder".equals(cmisObject.getPropertyValue(PropertyIds.OBJECT_TYPE_ID))) {
- List<String> notDeltedIdList = ((Folder)cmisObject)
- .deleteTree(true, UnfileObject.DELETE, true);
- if (notDeltedIdList != null && notDeltedIdList.size() > 0) {
- throw new RuntimeException("Cannot empty repo");
- }
- } else {
- cmisObject.delete(true);
- }
- }
- session.getBinding().close();
- }
-
- protected Session createSession() {
- SessionFactory sessionFactory = SessionFactoryImpl.newInstance();
- Map<String, String> parameter = new HashMap<String, String>();
- parameter.put(SessionParameter.ATOMPUB_URL, CMIS_ENDPOINT_TEST_SERVER);
- parameter.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());
-
- Repository repository = sessionFactory.getRepositories(parameter).get(0);
- return repository.createSession();
- }
-
- protected String getDocumentContentAsString(String nodeId) throws Exception {
- CmisObject cmisObject = retrieveCMISObjectByIdFromServer(nodeId);
- Document doc = (Document)cmisObject;
- InputStream inputStream = doc.getContentStream().getStream();
- return readFromStream(inputStream);
- }
-
- protected String readFromStream(InputStream in) throws Exception {
- StringBuilder result = new StringBuilder();
- BufferedReader br = new BufferedReader(new InputStreamReader(in));
-
- String strLine;
- while ((strLine = br.readLine()) != null) {
- result.append(strLine);
- }
- in.close();
- return result.toString();
- }
-
- protected Folder createFolderWithName(String folderName) {
- Folder rootFolder = createSession().getRootFolder();
- return createChildFolderWithName(rootFolder, folderName);
- }
-
- protected Folder createChildFolderWithName(Folder parent, String childName) {
- Map<String, String> newFolderProps = new HashMap<String, String>();
- newFolderProps.put(PropertyIds.OBJECT_TYPE_ID, "cmis:folder");
- newFolderProps.put(PropertyIds.NAME, childName);
- return parent.createFolder(newFolderProps);
- }
-
- protected void createTextDocument(Folder newFolder, String content, String fileName)
- throws UnsupportedEncodingException {
- byte[] buf = content.getBytes("UTF-8");
- ByteArrayInputStream input = new ByteArrayInputStream(buf);
- ContentStream contentStream = createSession().getObjectFactory()
- .createContentStream(fileName, buf.length, "text/plain; charset=UTF-8", input);
-
- Map<String, Object> properties = new HashMap<String, Object>();
- properties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document");
- properties.put(PropertyIds.NAME, fileName);
- newFolder.createDocument(properties, contentStream, VersioningState.NONE);
- }
-
- @BeforeClass
- public static void startServer() throws Exception {
- cmisServer = new Server(9090);
- cmisServer.setHandler(new WebAppContext(OPEN_CMIS_SERVER_WAR_PATH, "/chemistry-opencmis-server-inmemory"));
- cmisServer.start();
- }
-
- @AfterClass
- public static void stopServer() throws Exception {
- cmisServer.stop();
- }
-
- @Override
- @Before
- public void setUp() throws Exception {
- deleteAllContent();
- super.setUp();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/f336cb31/components/camel-cmis/src/test/java/org/apache/camel/component/cmis/CMISConsumerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-cmis/src/test/java/org/apache/camel/component/cmis/CMISConsumerTest.java b/components/camel-cmis/src/test/java/org/apache/camel/component/cmis/CMISConsumerTest.java
new file mode 100644
index 0000000..007822a
--- /dev/null
+++ b/components/camel-cmis/src/test/java/org/apache/camel/component/cmis/CMISConsumerTest.java
@@ -0,0 +1,104 @@
+/**
+ * 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.camel.component.cmis;
+
+import java.io.UnsupportedEncodingException;
+import java.util.List;
+
+import org.apache.camel.Consumer;
+import org.apache.camel.Endpoint;
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.chemistry.opencmis.client.api.Folder;
+import org.junit.Before;
+import org.junit.Test;
+
+public class CMISConsumerTest extends CMISTestSupport {
+
+ @EndpointInject(uri = "mock:result")
+ protected MockEndpoint resultEndpoint;
+
+ @Test
+ public void getAllContentFromServerOrderedFromRootToLeaves() throws Exception {
+ resultEndpoint.expectedMessageCount(5);
+
+ Consumer treeBasedConsumer = createConsumerFor(CMIS_ENDPOINT_TEST_SERVER);
+ treeBasedConsumer.start();
+
+ resultEndpoint.assertIsSatisfied();
+ treeBasedConsumer.stop();
+
+ List<Exchange> exchanges = resultEndpoint.getExchanges();
+ assertTrue(getNodeNameForIndex(exchanges, 0).equals("RootFolder"));
+ assertTrue(getNodeNameForIndex(exchanges, 1).equals("Folder1"));
+ assertTrue(getNodeNameForIndex(exchanges, 2).equals("Folder2"));
+ assertTrue(getNodeNameForIndex(exchanges, 3).contains(".txt"));
+ assertTrue(getNodeNameForIndex(exchanges, 4).contains(".txt"));
+ }
+
+ @Test
+ public void consumeDocumentsWithQuery() throws Exception {
+ resultEndpoint.expectedMessageCount(2);
+
+ Consumer queryBasedConsumer = createConsumerFor(
+ CMIS_ENDPOINT_TEST_SERVER + "?query=SELECT * FROM cmis:document");
+ queryBasedConsumer.start();
+ resultEndpoint.assertIsSatisfied();
+ queryBasedConsumer.stop();
+ }
+
+ private Consumer createConsumerFor(String path) throws Exception {
+ Endpoint endpoint = context.getEndpoint("cmis://" + path);
+ return endpoint.createConsumer(new Processor() {
+ public void process(Exchange exchange) throws Exception {
+ template.send("mock:result", exchange);
+ }
+ });
+ }
+
+ private String getNodeNameForIndex(List<Exchange> exchanges, int index) {
+ return exchanges.get(index).getIn().getHeader("cmis:name", String.class);
+ }
+
+ private void populateRepositoryRootFolderWithTwoFoldersAndTwoDocuments()
+ throws UnsupportedEncodingException {
+ Folder folder1 = createFolderWithName("Folder1");
+ Folder folder2 = createChildFolderWithName(folder1, "Folder2");
+ createTextDocument(folder2, "Document2.1", "2.1.txt");
+ createTextDocument(folder2, "Document2.2", "2.2.txt");
+ //L0 ROOT
+ // |
+ //L1 Folder1
+ //L2 |_____Folder2
+ // ||
+ //L3 Doc2.1___||___Doc2.2
+ }
+
+ @Override
+ public boolean isUseRouteBuilder() {
+ return false;
+ }
+
+ @Override
+ @Before
+ public void setUp() throws Exception {
+ super.setUp();
+ populateRepositoryRootFolderWithTwoFoldersAndTwoDocuments();
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/f336cb31/components/camel-cmis/src/test/java/org/apache/camel/component/cmis/CMISProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-cmis/src/test/java/org/apache/camel/component/cmis/CMISProducerTest.java b/components/camel-cmis/src/test/java/org/apache/camel/component/cmis/CMISProducerTest.java
new file mode 100644
index 0000000..b8d5d78
--- /dev/null
+++ b/components/camel-cmis/src/test/java/org/apache/camel/component/cmis/CMISProducerTest.java
@@ -0,0 +1,180 @@
+/**
+ * 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.camel.component.cmis;
+
+import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
+import org.apache.camel.NoSuchHeaderException;
+import org.apache.camel.Produce;
+import org.apache.camel.Producer;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.ResolveEndpointFailedException;
+import org.apache.camel.RuntimeExchangeException;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.chemistry.opencmis.client.api.CmisObject;
+import org.apache.chemistry.opencmis.client.api.Document;
+import org.apache.chemistry.opencmis.client.api.Folder;
+import org.apache.chemistry.opencmis.commons.PropertyIds;
+import org.junit.Test;
+
+public class CMISProducerTest extends CMISTestSupport {
+
+ @Produce(uri = "direct:start")
+ protected ProducerTemplate template;
+
+ @Test
+ public void storeMessageBodyAsTextDocument() throws Exception {
+ String content = "Some content to be store";
+ Exchange exchange = createExchangeWithInBody(content);
+ exchange.getIn().getHeaders().put(PropertyIds.CONTENT_STREAM_MIME_TYPE, "text/plain; charset=UTF-8");
+ exchange.getIn().getHeaders().put(PropertyIds.NAME, "test.file");
+
+ template.send(exchange);
+
+ String newNodeId = exchange.getOut().getBody(String.class);
+ assertNotNull(newNodeId);
+
+ String newNodeContent = getDocumentContentAsString(newNodeId);
+ assertEquals(content, newNodeContent);
+ }
+
+ @Test
+ public void getDocumentMimeTypeFromMessageContentType() throws Exception {
+ Exchange exchange = createExchangeWithInBody("Some content to be store");
+ exchange.getIn().getHeaders().put(Exchange.CONTENT_TYPE, "text/plain");
+ exchange.getIn().getHeaders().put(PropertyIds.NAME, "test.file");
+
+ template.send(exchange);
+ String newNodeId = exchange.getOut().getBody(String.class);
+
+ CmisObject cmisObject = retrieveCMISObjectByIdFromServer(newNodeId);
+ Document doc = (Document)cmisObject;
+ assertEquals("text/plain", doc.getPropertyValue(PropertyIds.CONTENT_STREAM_MIME_TYPE));
+ }
+
+ @Test
+ public void namePropertyIsAlwaysRequired() {
+ Exchange exchange = createExchangeWithInBody("Some content that will fail to be stored");
+ exchange.getIn().getHeaders().put(PropertyIds.CONTENT_STREAM_MIME_TYPE, "text/plain; charset=UTF-8");
+
+ template.send(exchange);
+ Exception exception = exchange.getException();
+ Object body = exchange.getOut().getBody();
+
+ assertNull(body);
+ assertTrue(exception instanceof NoSuchHeaderException);
+ }
+
+ @Test
+ public void createDocumentWithoutContentByExplicitlySpecifyingObjectTypeHeader() throws Exception {
+ Exchange exchange = createExchangeWithInBody(null);
+ exchange.getIn().getHeaders().put(PropertyIds.CONTENT_STREAM_MIME_TYPE, "text/plain; charset=UTF-8");
+ exchange.getIn().getHeaders().put(PropertyIds.OBJECT_TYPE_ID, "cmis:document");
+ exchange.getIn().getHeaders().put(PropertyIds.NAME, "test.file");
+
+ template.send(exchange);
+ String newNodeId = exchange.getOut().getBody(String.class);
+ assertNotNull(newNodeId);
+
+ CmisObject cmisObject = retrieveCMISObjectByIdFromServer(newNodeId);
+ Document doc = (Document)cmisObject;
+ assertEquals("cmis:document", doc.getPropertyValue(PropertyIds.OBJECT_TYPE_ID));
+ }
+
+ @Test
+ public void emptyBodyAndMissingObjectTypeHeaderCreatesFolderNode() throws Exception {
+ Exchange exchange = createExchangeWithInBody(null);
+ exchange.getIn().getHeaders().put(PropertyIds.NAME, "testFolder");
+
+ template.send(exchange);
+ String newNodeId = exchange.getOut().getBody(String.class);
+ assertNotNull(newNodeId);
+
+ CmisObject newNode = retrieveCMISObjectByIdFromServer(newNodeId);
+ assertEquals("cmis:folder", newNode.getType().getId());
+ assertTrue(newNode instanceof Folder);
+ }
+
+ @Test
+ public void cmisPropertiesAreStored() throws Exception {
+ Exchange exchange = createExchangeWithInBody("Some content to be store");
+ exchange.getIn().getHeaders().put(PropertyIds.CONTENT_STREAM_MIME_TYPE, "text/plain; charset=UTF-8");
+ exchange.getIn().getHeaders().put(PropertyIds.NAME, "test.txt");
+
+ template.send(exchange);
+ String newNodeId = exchange.getOut().getBody(String.class);
+ CmisObject newNode = retrieveCMISObjectByIdFromServer(newNodeId);
+
+ assertEquals("test.txt", newNode.getPropertyValue(PropertyIds.NAME));
+ assertEquals("text/plain; charset=UTF-8",
+ newNode.getPropertyValue(PropertyIds.CONTENT_STREAM_MIME_TYPE));
+ }
+
+ @Test(expected = ResolveEndpointFailedException.class)
+ public void failConnectingToNonExistingRepository() throws Exception {
+ Endpoint endpoint = context.getEndpoint("cmis://" + CMIS_ENDPOINT_TEST_SERVER
+ + "?username=admin&password=admin&repositoryId=NON_EXISTING_ID");
+ Producer producer = endpoint.createProducer();
+
+ Exchange exchange = createExchangeWithInBody("Some content to be store");
+ exchange.getIn().getHeaders().put(PropertyIds.NAME, "test.txt");
+ producer.process(exchange);
+ }
+
+ @Test
+ public void createDocumentAtSpecificPath() throws Exception {
+ Folder folder1 = createFolderWithName("Folder1");
+ createChildFolderWithName(folder1, "Folder2");
+ String existingFolderStructure = "/Folder1/Folder2";
+
+ Exchange exchange = createExchangeWithInBody("Some content to be stored");
+ exchange.getIn().getHeaders().put(PropertyIds.CONTENT_STREAM_MIME_TYPE, "text/plain; charset=UTF-8");
+ exchange.getIn().getHeaders().put(PropertyIds.NAME, "test.file");
+ exchange.getIn().getHeaders().put(CamelCMISConstants.CMIS_FOLDER_PATH, existingFolderStructure);
+
+ template.send(exchange);
+ String newNodeId = exchange.getOut().getBody(String.class);
+
+ Document document = (Document)retrieveCMISObjectByIdFromServer(newNodeId);
+ String documentFullPath = document.getPaths().get(0);
+ assertEquals(existingFolderStructure + "/test.file", documentFullPath);
+ }
+
+ @Test
+ public void failCreatingFolderAtNonExistingPath() throws Exception {
+ String existingFolderStructure = "/No/Path/Here";
+
+ Exchange exchange = createExchangeWithInBody(null);
+ exchange.getIn().getHeaders().put(PropertyIds.NAME, "folder1");
+ exchange.getIn().getHeaders().put(PropertyIds.OBJECT_TYPE_ID, "cmis:folder");
+ exchange.getIn().getHeaders().put(CamelCMISConstants.CMIS_FOLDER_PATH, existingFolderStructure);
+
+ template.send(exchange);
+ assertTrue(exchange.getException() instanceof RuntimeExchangeException);
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ public void configure() {
+ from("direct:start")
+ .to("cmis://" + CMIS_ENDPOINT_TEST_SERVER);
+ }
+ };
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/f336cb31/components/camel-cmis/src/test/java/org/apache/camel/component/cmis/CMISQueryProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-cmis/src/test/java/org/apache/camel/component/cmis/CMISQueryProducerTest.java b/components/camel-cmis/src/test/java/org/apache/camel/component/cmis/CMISQueryProducerTest.java
new file mode 100644
index 0000000..db6af6a
--- /dev/null
+++ b/components/camel-cmis/src/test/java/org/apache/camel/component/cmis/CMISQueryProducerTest.java
@@ -0,0 +1,109 @@
+/**
+ * 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.camel.component.cmis;
+
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
+import org.apache.camel.Producer;
+import org.apache.chemistry.opencmis.client.api.Folder;
+import org.junit.Before;
+import org.junit.Test;
+
+public class CMISQueryProducerTest extends CMISTestSupport {
+
+ @Override
+ @Before
+ public void setUp() throws Exception {
+ super.setUp();
+ populateServerWithContent();
+ }
+
+ @Test
+ public void queryServerForDocumentWithSpecificName() throws Exception {
+ Endpoint endpoint = context.getEndpoint("cmis://" + CMIS_ENDPOINT_TEST_SERVER + "?queryMode=true");
+ Producer producer = endpoint.createProducer();
+
+ Exchange exchange = createExchangeWithInBody(
+ "SELECT * FROM cmis:document WHERE cmis:name = 'test1.txt'");
+ producer.process(exchange);
+
+ @SuppressWarnings("unchecked")
+ List<Map<String, Object>> documents = exchange.getOut().getBody(List.class);
+ assertEquals(1, documents.size());
+ assertEquals("test1.txt", documents.get(0).get("cmis:name"));
+ }
+
+ @Test
+ public void getResultCountFromHeader() throws Exception {
+ Endpoint endpoint = context.getEndpoint("cmis://" + CMIS_ENDPOINT_TEST_SERVER + "?queryMode=true");
+ Producer producer = endpoint.createProducer();
+
+ Exchange exchange = createExchangeWithInBody(
+ "SELECT * FROM cmis:document WHERE CONTAINS('Camel test content.')");
+ producer.process(exchange);
+
+ @SuppressWarnings("unchecked")
+ List<Map<String, Object>> documents = exchange.getOut().getBody(List.class);
+ assertEquals(2, documents.size());
+ assertEquals(2, exchange.getOut().getHeader("CamelCMISResultCount"));
+ }
+
+ @Test
+ public void limitNumberOfResultsWithReadSizeHeader() throws Exception {
+ Endpoint endpoint = context.getEndpoint("cmis://" + CMIS_ENDPOINT_TEST_SERVER + "?queryMode=true");
+ Producer producer = endpoint.createProducer();
+
+ Exchange exchange = createExchangeWithInBody(
+ "SELECT * FROM cmis:document WHERE CONTAINS('Camel test content.')");
+ exchange.getIn().getHeaders().put("CamelCMISReadSize", 1);
+
+ producer.process(exchange);
+
+ @SuppressWarnings("unchecked")
+ List<Map<String, Object>> documents = exchange.getOut().getBody(List.class);
+ assertEquals(1, documents.size());
+ }
+
+ @Test
+ public void retrieveAlsoDocumentContent() throws Exception {
+ Endpoint endpoint = context.getEndpoint("cmis://" + CMIS_ENDPOINT_TEST_SERVER + "?queryMode=true");
+ Producer producer = endpoint.createProducer();
+
+ Exchange exchange = createExchangeWithInBody(
+ "SELECT * FROM cmis:document WHERE cmis:name='test1.txt'");
+ exchange.getIn().getHeaders().put("CamelCMISRetrieveContent", true);
+
+ producer.process(exchange);
+
+ @SuppressWarnings("unchecked")
+ List<Map<String, Object>> documents = exchange.getOut().getBody(List.class);
+ InputStream content = (InputStream)documents.get(0).get("CamelCMISContent");
+ assertEquals("This is the first Camel test content.", readFromStream(content));
+ }
+
+ private void populateServerWithContent() throws UnsupportedEncodingException {
+ Folder newFolder = createFolderWithName("CamelCmisTestFolder");
+ createTextDocument(newFolder, "This is the first Camel test content.", "test1.txt");
+ createTextDocument(newFolder, "This is the second Camel test content.", "test2.txt");
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/f336cb31/components/camel-cmis/src/test/java/org/apache/camel/component/cmis/CMISTestSupport.java
----------------------------------------------------------------------
diff --git a/components/camel-cmis/src/test/java/org/apache/camel/component/cmis/CMISTestSupport.java b/components/camel-cmis/src/test/java/org/apache/camel/component/cmis/CMISTestSupport.java
new file mode 100644
index 0000000..a466a01
--- /dev/null
+++ b/components/camel-cmis/src/test/java/org/apache/camel/component/cmis/CMISTestSupport.java
@@ -0,0 +1,163 @@
+/**
+ * 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.camel.component.cmis;
+
+import java.io.BufferedReader;
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.UnsupportedEncodingException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.impl.DefaultExchange;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.apache.chemistry.opencmis.client.api.CmisObject;
+import org.apache.chemistry.opencmis.client.api.Document;
+import org.apache.chemistry.opencmis.client.api.Folder;
+import org.apache.chemistry.opencmis.client.api.ItemIterable;
+import org.apache.chemistry.opencmis.client.api.Repository;
+import org.apache.chemistry.opencmis.client.api.Session;
+import org.apache.chemistry.opencmis.client.api.SessionFactory;
+import org.apache.chemistry.opencmis.client.runtime.SessionFactoryImpl;
+import org.apache.chemistry.opencmis.commons.PropertyIds;
+import org.apache.chemistry.opencmis.commons.SessionParameter;
+import org.apache.chemistry.opencmis.commons.data.ContentStream;
+import org.apache.chemistry.opencmis.commons.enums.BindingType;
+import org.apache.chemistry.opencmis.commons.enums.UnfileObject;
+import org.apache.chemistry.opencmis.commons.enums.VersioningState;
+import org.eclipse.jetty.server.Server;
+import org.eclipse.jetty.webapp.WebAppContext;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+
+public class CMISTestSupport extends CamelTestSupport {
+ protected static final String CMIS_ENDPOINT_TEST_SERVER
+ = "http://localhost:9090/chemistry-opencmis-server-inmemory/atom";
+ protected static final String OPEN_CMIS_SERVER_WAR_PATH
+ = "target/dependency/chemistry-opencmis-server-inmemory-0.8.0.war";
+
+ protected static Server cmisServer;
+
+ protected Exchange createExchangeWithInBody(String body) {
+ DefaultExchange exchange = new DefaultExchange(context);
+ if (body != null) {
+ exchange.getIn().setBody(body);
+ }
+ return exchange;
+ }
+
+ protected CmisObject retrieveCMISObjectByIdFromServer(String nodeId) throws Exception {
+ Session session = createSession();
+ return session.getObject(nodeId);
+ }
+
+ protected void deleteAllContent() {
+ Session session = createSession();
+ Folder rootFolder = session.getRootFolder();
+ ItemIterable<CmisObject> children = rootFolder.getChildren();
+ for (CmisObject cmisObject : children) {
+ if ("cmis:folder".equals(cmisObject.getPropertyValue(PropertyIds.OBJECT_TYPE_ID))) {
+ List<String> notDeltedIdList = ((Folder)cmisObject)
+ .deleteTree(true, UnfileObject.DELETE, true);
+ if (notDeltedIdList != null && notDeltedIdList.size() > 0) {
+ throw new RuntimeException("Cannot empty repo");
+ }
+ } else {
+ cmisObject.delete(true);
+ }
+ }
+ session.getBinding().close();
+ }
+
+ protected Session createSession() {
+ SessionFactory sessionFactory = SessionFactoryImpl.newInstance();
+ Map<String, String> parameter = new HashMap<String, String>();
+ parameter.put(SessionParameter.ATOMPUB_URL, CMIS_ENDPOINT_TEST_SERVER);
+ parameter.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());
+
+ Repository repository = sessionFactory.getRepositories(parameter).get(0);
+ return repository.createSession();
+ }
+
+ protected String getDocumentContentAsString(String nodeId) throws Exception {
+ CmisObject cmisObject = retrieveCMISObjectByIdFromServer(nodeId);
+ Document doc = (Document)cmisObject;
+ InputStream inputStream = doc.getContentStream().getStream();
+ return readFromStream(inputStream);
+ }
+
+ protected String readFromStream(InputStream in) throws Exception {
+ StringBuilder result = new StringBuilder();
+ BufferedReader br = new BufferedReader(new InputStreamReader(in));
+
+ String strLine;
+ while ((strLine = br.readLine()) != null) {
+ result.append(strLine);
+ }
+ in.close();
+ return result.toString();
+ }
+
+ protected Folder createFolderWithName(String folderName) {
+ Folder rootFolder = createSession().getRootFolder();
+ return createChildFolderWithName(rootFolder, folderName);
+ }
+
+ protected Folder createChildFolderWithName(Folder parent, String childName) {
+ Map<String, String> newFolderProps = new HashMap<String, String>();
+ newFolderProps.put(PropertyIds.OBJECT_TYPE_ID, "cmis:folder");
+ newFolderProps.put(PropertyIds.NAME, childName);
+ return parent.createFolder(newFolderProps);
+ }
+
+ protected void createTextDocument(Folder newFolder, String content, String fileName)
+ throws UnsupportedEncodingException {
+ byte[] buf = content.getBytes("UTF-8");
+ ByteArrayInputStream input = new ByteArrayInputStream(buf);
+ ContentStream contentStream = createSession().getObjectFactory()
+ .createContentStream(fileName, buf.length, "text/plain; charset=UTF-8", input);
+
+ Map<String, Object> properties = new HashMap<String, Object>();
+ properties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document");
+ properties.put(PropertyIds.NAME, fileName);
+ newFolder.createDocument(properties, contentStream, VersioningState.NONE);
+ }
+
+ @BeforeClass
+ public static void startServer() throws Exception {
+ cmisServer = new Server(9090);
+ cmisServer.setHandler(new WebAppContext(OPEN_CMIS_SERVER_WAR_PATH, "/chemistry-opencmis-server-inmemory"));
+ cmisServer.start();
+ }
+
+ @AfterClass
+ public static void stopServer() throws Exception {
+ cmisServer.stop();
+ }
+
+ @Override
+ @Before
+ public void setUp() throws Exception {
+ deleteAllContent();
+ super.setUp();
+ }
+
+}
[2/2] git commit: CAMEL-6595 fixed the test packages name issue of
camel-cmis with thanks to Maurizio
Posted by ni...@apache.org.
CAMEL-6595 fixed the test packages name issue of camel-cmis with thanks to Maurizio
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/c90c9dc9
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/c90c9dc9
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/c90c9dc9
Branch: refs/heads/camel-2.11.x
Commit: c90c9dc99a6db71107cc1e3d52f2237f4417c975
Parents: 9296095
Author: Willem Jiang <ni...@apache.org>
Authored: Thu Aug 1 11:43:51 2013 +0800
Committer: Willem Jiang <ni...@apache.org>
Committed: Thu Aug 1 11:45:21 2013 +0800
----------------------------------------------------------------------
.../camel/componenet/cmis/CMISConsumerTest.java | 104 -----------
.../camel/componenet/cmis/CMISProducerTest.java | 181 -------------------
.../componenet/cmis/CMISQueryProducerTest.java | 109 -----------
.../camel/componenet/cmis/CMISTestSupport.java | 163 -----------------
.../camel/component/cmis/CMISConsumerTest.java | 104 +++++++++++
.../camel/component/cmis/CMISProducerTest.java | 180 ++++++++++++++++++
.../component/cmis/CMISQueryProducerTest.java | 109 +++++++++++
.../camel/component/cmis/CMISTestSupport.java | 163 +++++++++++++++++
8 files changed, 556 insertions(+), 557 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/c90c9dc9/components/camel-cmis/src/test/java/org/apache/camel/componenet/cmis/CMISConsumerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-cmis/src/test/java/org/apache/camel/componenet/cmis/CMISConsumerTest.java b/components/camel-cmis/src/test/java/org/apache/camel/componenet/cmis/CMISConsumerTest.java
deleted file mode 100644
index ff2a695..0000000
--- a/components/camel-cmis/src/test/java/org/apache/camel/componenet/cmis/CMISConsumerTest.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/**
- * 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.camel.componenet.cmis;
-
-import java.io.UnsupportedEncodingException;
-import java.util.List;
-
-import org.apache.camel.Consumer;
-import org.apache.camel.Endpoint;
-import org.apache.camel.EndpointInject;
-import org.apache.camel.Exchange;
-import org.apache.camel.Processor;
-import org.apache.camel.component.mock.MockEndpoint;
-import org.apache.chemistry.opencmis.client.api.Folder;
-import org.junit.Before;
-import org.junit.Test;
-
-public class CMISConsumerTest extends CMISTestSupport {
-
- @EndpointInject(uri = "mock:result")
- protected MockEndpoint resultEndpoint;
-
- @Test
- public void getAllContentFromServerOrderedFromRootToLeaves() throws Exception {
- resultEndpoint.expectedMessageCount(5);
-
- Consumer treeBasedConsumer = createConsumerFor(CMIS_ENDPOINT_TEST_SERVER);
- treeBasedConsumer.start();
-
- resultEndpoint.assertIsSatisfied();
- treeBasedConsumer.stop();
-
- List<Exchange> exchanges = resultEndpoint.getExchanges();
- assertTrue(getNodeNameForIndex(exchanges, 0).equals("RootFolder"));
- assertTrue(getNodeNameForIndex(exchanges, 1).equals("Folder1"));
- assertTrue(getNodeNameForIndex(exchanges, 2).equals("Folder2"));
- assertTrue(getNodeNameForIndex(exchanges, 3).contains(".txt"));
- assertTrue(getNodeNameForIndex(exchanges, 4).contains(".txt"));
- }
-
- @Test
- public void consumeDocumentsWithQuery() throws Exception {
- resultEndpoint.expectedMessageCount(2);
-
- Consumer queryBasedConsumer = createConsumerFor(
- CMIS_ENDPOINT_TEST_SERVER + "?query=SELECT * FROM cmis:document");
- queryBasedConsumer.start();
- resultEndpoint.assertIsSatisfied();
- queryBasedConsumer.stop();
- }
-
- private Consumer createConsumerFor(String path) throws Exception {
- Endpoint endpoint = context.getEndpoint("cmis://" + path);
- return endpoint.createConsumer(new Processor() {
- public void process(Exchange exchange) throws Exception {
- template.send("mock:result", exchange);
- }
- });
- }
-
- private String getNodeNameForIndex(List<Exchange> exchanges, int index) {
- return exchanges.get(index).getIn().getHeader("cmis:name", String.class);
- }
-
- private void populateRepositoryRootFolderWithTwoFoldersAndTwoDocuments()
- throws UnsupportedEncodingException {
- Folder folder1 = createFolderWithName("Folder1");
- Folder folder2 = createChildFolderWithName(folder1, "Folder2");
- createTextDocument(folder2, "Document2.1", "2.1.txt");
- createTextDocument(folder2, "Document2.2", "2.2.txt");
- //L0 ROOT
- // |
- //L1 Folder1
- //L2 |_____Folder2
- // ||
- //L3 Doc2.1___||___Doc2.2
- }
-
- @Override
- public boolean isUseRouteBuilder() {
- return false;
- }
-
- @Override
- @Before
- public void setUp() throws Exception {
- super.setUp();
- populateRepositoryRootFolderWithTwoFoldersAndTwoDocuments();
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/c90c9dc9/components/camel-cmis/src/test/java/org/apache/camel/componenet/cmis/CMISProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-cmis/src/test/java/org/apache/camel/componenet/cmis/CMISProducerTest.java b/components/camel-cmis/src/test/java/org/apache/camel/componenet/cmis/CMISProducerTest.java
deleted file mode 100644
index a972e61..0000000
--- a/components/camel-cmis/src/test/java/org/apache/camel/componenet/cmis/CMISProducerTest.java
+++ /dev/null
@@ -1,181 +0,0 @@
-/**
- * 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.camel.componenet.cmis;
-
-import org.apache.camel.Endpoint;
-import org.apache.camel.Exchange;
-import org.apache.camel.NoSuchHeaderException;
-import org.apache.camel.Produce;
-import org.apache.camel.Producer;
-import org.apache.camel.ProducerTemplate;
-import org.apache.camel.ResolveEndpointFailedException;
-import org.apache.camel.RuntimeExchangeException;
-import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.cmis.CamelCMISConstants;
-import org.apache.chemistry.opencmis.client.api.CmisObject;
-import org.apache.chemistry.opencmis.client.api.Document;
-import org.apache.chemistry.opencmis.client.api.Folder;
-import org.apache.chemistry.opencmis.commons.PropertyIds;
-import org.junit.Test;
-
-public class CMISProducerTest extends CMISTestSupport {
-
- @Produce(uri = "direct:start")
- protected ProducerTemplate template;
-
- @Test
- public void storeMessageBodyAsTextDocument() throws Exception {
- String content = "Some content to be store";
- Exchange exchange = createExchangeWithInBody(content);
- exchange.getIn().getHeaders().put(PropertyIds.CONTENT_STREAM_MIME_TYPE, "text/plain; charset=UTF-8");
- exchange.getIn().getHeaders().put(PropertyIds.NAME, "test.file");
-
- template.send(exchange);
-
- String newNodeId = exchange.getOut().getBody(String.class);
- assertNotNull(newNodeId);
-
- String newNodeContent = getDocumentContentAsString(newNodeId);
- assertEquals(content, newNodeContent);
- }
-
- @Test
- public void getDocumentMimeTypeFromMessageContentType() throws Exception {
- Exchange exchange = createExchangeWithInBody("Some content to be store");
- exchange.getIn().getHeaders().put(Exchange.CONTENT_TYPE, "text/plain");
- exchange.getIn().getHeaders().put(PropertyIds.NAME, "test.file");
-
- template.send(exchange);
- String newNodeId = exchange.getOut().getBody(String.class);
-
- CmisObject cmisObject = retrieveCMISObjectByIdFromServer(newNodeId);
- Document doc = (Document)cmisObject;
- assertEquals("text/plain", doc.getPropertyValue(PropertyIds.CONTENT_STREAM_MIME_TYPE));
- }
-
- @Test
- public void namePropertyIsAlwaysRequired() {
- Exchange exchange = createExchangeWithInBody("Some content that will fail to be stored");
- exchange.getIn().getHeaders().put(PropertyIds.CONTENT_STREAM_MIME_TYPE, "text/plain; charset=UTF-8");
-
- template.send(exchange);
- Exception exception = exchange.getException();
- Object body = exchange.getOut().getBody();
-
- assertNull(body);
- assertTrue(exception instanceof NoSuchHeaderException);
- }
-
- @Test
- public void createDocumentWithoutContentByExplicitlySpecifyingObjectTypeHeader() throws Exception {
- Exchange exchange = createExchangeWithInBody(null);
- exchange.getIn().getHeaders().put(PropertyIds.CONTENT_STREAM_MIME_TYPE, "text/plain; charset=UTF-8");
- exchange.getIn().getHeaders().put(PropertyIds.OBJECT_TYPE_ID, "cmis:document");
- exchange.getIn().getHeaders().put(PropertyIds.NAME, "test.file");
-
- template.send(exchange);
- String newNodeId = exchange.getOut().getBody(String.class);
- assertNotNull(newNodeId);
-
- CmisObject cmisObject = retrieveCMISObjectByIdFromServer(newNodeId);
- Document doc = (Document)cmisObject;
- assertEquals("cmis:document", doc.getPropertyValue(PropertyIds.OBJECT_TYPE_ID));
- }
-
- @Test
- public void emptyBodyAndMissingObjectTypeHeaderCreatesFolderNode() throws Exception {
- Exchange exchange = createExchangeWithInBody(null);
- exchange.getIn().getHeaders().put(PropertyIds.NAME, "testFolder");
-
- template.send(exchange);
- String newNodeId = exchange.getOut().getBody(String.class);
- assertNotNull(newNodeId);
-
- CmisObject newNode = retrieveCMISObjectByIdFromServer(newNodeId);
- assertEquals("cmis:folder", newNode.getType().getId());
- assertTrue(newNode instanceof Folder);
- }
-
- @Test
- public void cmisPropertiesAreStored() throws Exception {
- Exchange exchange = createExchangeWithInBody("Some content to be store");
- exchange.getIn().getHeaders().put(PropertyIds.CONTENT_STREAM_MIME_TYPE, "text/plain; charset=UTF-8");
- exchange.getIn().getHeaders().put(PropertyIds.NAME, "test.txt");
-
- template.send(exchange);
- String newNodeId = exchange.getOut().getBody(String.class);
- CmisObject newNode = retrieveCMISObjectByIdFromServer(newNodeId);
-
- assertEquals("test.txt", newNode.getPropertyValue(PropertyIds.NAME));
- assertEquals("text/plain; charset=UTF-8",
- newNode.getPropertyValue(PropertyIds.CONTENT_STREAM_MIME_TYPE));
- }
-
- @Test(expected = ResolveEndpointFailedException.class)
- public void failConnectingToNonExistingRepository() throws Exception {
- Endpoint endpoint = context.getEndpoint("cmis://" + CMIS_ENDPOINT_TEST_SERVER
- + "?username=admin&password=admin&repositoryId=NON_EXISTING_ID");
- Producer producer = endpoint.createProducer();
-
- Exchange exchange = createExchangeWithInBody("Some content to be store");
- exchange.getIn().getHeaders().put(PropertyIds.NAME, "test.txt");
- producer.process(exchange);
- }
-
- @Test
- public void createDocumentAtSpecificPath() throws Exception {
- Folder folder1 = createFolderWithName("Folder1");
- createChildFolderWithName(folder1, "Folder2");
- String existingFolderStructure = "/Folder1/Folder2";
-
- Exchange exchange = createExchangeWithInBody("Some content to be stored");
- exchange.getIn().getHeaders().put(PropertyIds.CONTENT_STREAM_MIME_TYPE, "text/plain; charset=UTF-8");
- exchange.getIn().getHeaders().put(PropertyIds.NAME, "test.file");
- exchange.getIn().getHeaders().put(CamelCMISConstants.CMIS_FOLDER_PATH, existingFolderStructure);
-
- template.send(exchange);
- String newNodeId = exchange.getOut().getBody(String.class);
-
- Document document = (Document)retrieveCMISObjectByIdFromServer(newNodeId);
- String documentFullPath = document.getPaths().get(0);
- assertEquals(existingFolderStructure + "/test.file", documentFullPath);
- }
-
- @Test
- public void failCreatingFolderAtNonExistingPath() throws Exception {
- String existingFolderStructure = "/No/Path/Here";
-
- Exchange exchange = createExchangeWithInBody(null);
- exchange.getIn().getHeaders().put(PropertyIds.NAME, "folder1");
- exchange.getIn().getHeaders().put(PropertyIds.OBJECT_TYPE_ID, "cmis:folder");
- exchange.getIn().getHeaders().put(CamelCMISConstants.CMIS_FOLDER_PATH, existingFolderStructure);
-
- template.send(exchange);
- assertTrue(exchange.getException() instanceof RuntimeExchangeException);
- }
-
- @Override
- protected RouteBuilder createRouteBuilder() throws Exception {
- return new RouteBuilder() {
- public void configure() {
- from("direct:start")
- .to("cmis://" + CMIS_ENDPOINT_TEST_SERVER);
- }
- };
- }
-
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/c90c9dc9/components/camel-cmis/src/test/java/org/apache/camel/componenet/cmis/CMISQueryProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-cmis/src/test/java/org/apache/camel/componenet/cmis/CMISQueryProducerTest.java b/components/camel-cmis/src/test/java/org/apache/camel/componenet/cmis/CMISQueryProducerTest.java
deleted file mode 100644
index d81eca0..0000000
--- a/components/camel-cmis/src/test/java/org/apache/camel/componenet/cmis/CMISQueryProducerTest.java
+++ /dev/null
@@ -1,109 +0,0 @@
-/**
- * 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.camel.componenet.cmis;
-
-import java.io.InputStream;
-import java.io.UnsupportedEncodingException;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.camel.Endpoint;
-import org.apache.camel.Exchange;
-import org.apache.camel.Producer;
-import org.apache.chemistry.opencmis.client.api.Folder;
-import org.junit.Before;
-import org.junit.Test;
-
-public class CMISQueryProducerTest extends CMISTestSupport {
-
- @Override
- @Before
- public void setUp() throws Exception {
- super.setUp();
- populateServerWithContent();
- }
-
- @Test
- public void queryServerForDocumentWithSpecificName() throws Exception {
- Endpoint endpoint = context.getEndpoint("cmis://" + CMIS_ENDPOINT_TEST_SERVER + "?queryMode=true");
- Producer producer = endpoint.createProducer();
-
- Exchange exchange = createExchangeWithInBody(
- "SELECT * FROM cmis:document WHERE cmis:name = 'test1.txt'");
- producer.process(exchange);
-
- @SuppressWarnings("unchecked")
- List<Map<String, Object>> documents = exchange.getOut().getBody(List.class);
- assertEquals(1, documents.size());
- assertEquals("test1.txt", documents.get(0).get("cmis:name"));
- }
-
- @Test
- public void getResultCountFromHeader() throws Exception {
- Endpoint endpoint = context.getEndpoint("cmis://" + CMIS_ENDPOINT_TEST_SERVER + "?queryMode=true");
- Producer producer = endpoint.createProducer();
-
- Exchange exchange = createExchangeWithInBody(
- "SELECT * FROM cmis:document WHERE CONTAINS('Camel test content.')");
- producer.process(exchange);
-
- @SuppressWarnings("unchecked")
- List<Map<String, Object>> documents = exchange.getOut().getBody(List.class);
- assertEquals(2, documents.size());
- assertEquals(2, exchange.getOut().getHeader("CamelCMISResultCount"));
- }
-
- @Test
- public void limitNumberOfResultsWithReadSizeHeader() throws Exception {
- Endpoint endpoint = context.getEndpoint("cmis://" + CMIS_ENDPOINT_TEST_SERVER + "?queryMode=true");
- Producer producer = endpoint.createProducer();
-
- Exchange exchange = createExchangeWithInBody(
- "SELECT * FROM cmis:document WHERE CONTAINS('Camel test content.')");
- exchange.getIn().getHeaders().put("CamelCMISReadSize", 1);
-
- producer.process(exchange);
-
- @SuppressWarnings("unchecked")
- List<Map<String, Object>> documents = exchange.getOut().getBody(List.class);
- assertEquals(1, documents.size());
- }
-
- @Test
- public void retrieveAlsoDocumentContent() throws Exception {
- Endpoint endpoint = context.getEndpoint("cmis://" + CMIS_ENDPOINT_TEST_SERVER + "?queryMode=true");
- Producer producer = endpoint.createProducer();
-
- Exchange exchange = createExchangeWithInBody(
- "SELECT * FROM cmis:document WHERE cmis:name='test1.txt'");
- exchange.getIn().getHeaders().put("CamelCMISRetrieveContent", true);
-
- producer.process(exchange);
-
- @SuppressWarnings("unchecked")
- List<Map<String, Object>> documents = exchange.getOut().getBody(List.class);
- InputStream content = (InputStream)documents.get(0).get("CamelCMISContent");
- assertEquals("This is the first Camel test content.", readFromStream(content));
- }
-
- private void populateServerWithContent() throws UnsupportedEncodingException {
- Folder newFolder = createFolderWithName("CamelCmisTestFolder");
- createTextDocument(newFolder, "This is the first Camel test content.", "test1.txt");
- createTextDocument(newFolder, "This is the second Camel test content.", "test2.txt");
- }
-
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/c90c9dc9/components/camel-cmis/src/test/java/org/apache/camel/componenet/cmis/CMISTestSupport.java
----------------------------------------------------------------------
diff --git a/components/camel-cmis/src/test/java/org/apache/camel/componenet/cmis/CMISTestSupport.java b/components/camel-cmis/src/test/java/org/apache/camel/componenet/cmis/CMISTestSupport.java
deleted file mode 100644
index 138f219..0000000
--- a/components/camel-cmis/src/test/java/org/apache/camel/componenet/cmis/CMISTestSupport.java
+++ /dev/null
@@ -1,163 +0,0 @@
-/**
- * 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.camel.componenet.cmis;
-
-import java.io.BufferedReader;
-import java.io.ByteArrayInputStream;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.UnsupportedEncodingException;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.camel.Exchange;
-import org.apache.camel.impl.DefaultExchange;
-import org.apache.camel.test.junit4.CamelTestSupport;
-import org.apache.chemistry.opencmis.client.api.CmisObject;
-import org.apache.chemistry.opencmis.client.api.Document;
-import org.apache.chemistry.opencmis.client.api.Folder;
-import org.apache.chemistry.opencmis.client.api.ItemIterable;
-import org.apache.chemistry.opencmis.client.api.Repository;
-import org.apache.chemistry.opencmis.client.api.Session;
-import org.apache.chemistry.opencmis.client.api.SessionFactory;
-import org.apache.chemistry.opencmis.client.runtime.SessionFactoryImpl;
-import org.apache.chemistry.opencmis.commons.PropertyIds;
-import org.apache.chemistry.opencmis.commons.SessionParameter;
-import org.apache.chemistry.opencmis.commons.data.ContentStream;
-import org.apache.chemistry.opencmis.commons.enums.BindingType;
-import org.apache.chemistry.opencmis.commons.enums.UnfileObject;
-import org.apache.chemistry.opencmis.commons.enums.VersioningState;
-import org.eclipse.jetty.server.Server;
-import org.eclipse.jetty.webapp.WebAppContext;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-
-public class CMISTestSupport extends CamelTestSupport {
- protected static final String CMIS_ENDPOINT_TEST_SERVER
- = "http://localhost:9090/chemistry-opencmis-server-inmemory/atom";
- protected static final String OPEN_CMIS_SERVER_WAR_PATH
- = "target/dependency/chemistry-opencmis-server-inmemory-0.8.0.war";
-
- protected static Server cmisServer;
-
- protected Exchange createExchangeWithInBody(String body) {
- DefaultExchange exchange = new DefaultExchange(context);
- if (body != null) {
- exchange.getIn().setBody(body);
- }
- return exchange;
- }
-
- protected CmisObject retrieveCMISObjectByIdFromServer(String nodeId) throws Exception {
- Session session = createSession();
- return session.getObject(nodeId);
- }
-
- protected void deleteAllContent() {
- Session session = createSession();
- Folder rootFolder = session.getRootFolder();
- ItemIterable<CmisObject> children = rootFolder.getChildren();
- for (CmisObject cmisObject : children) {
- if ("cmis:folder".equals(cmisObject.getPropertyValue(PropertyIds.OBJECT_TYPE_ID))) {
- List<String> notDeltedIdList = ((Folder)cmisObject)
- .deleteTree(true, UnfileObject.DELETE, true);
- if (notDeltedIdList != null && notDeltedIdList.size() > 0) {
- throw new RuntimeException("Cannot empty repo");
- }
- } else {
- cmisObject.delete(true);
- }
- }
- session.getBinding().close();
- }
-
- protected Session createSession() {
- SessionFactory sessionFactory = SessionFactoryImpl.newInstance();
- Map<String, String> parameter = new HashMap<String, String>();
- parameter.put(SessionParameter.ATOMPUB_URL, CMIS_ENDPOINT_TEST_SERVER);
- parameter.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());
-
- Repository repository = sessionFactory.getRepositories(parameter).get(0);
- return repository.createSession();
- }
-
- protected String getDocumentContentAsString(String nodeId) throws Exception {
- CmisObject cmisObject = retrieveCMISObjectByIdFromServer(nodeId);
- Document doc = (Document)cmisObject;
- InputStream inputStream = doc.getContentStream().getStream();
- return readFromStream(inputStream);
- }
-
- protected String readFromStream(InputStream in) throws Exception {
- StringBuilder result = new StringBuilder();
- BufferedReader br = new BufferedReader(new InputStreamReader(in));
-
- String strLine;
- while ((strLine = br.readLine()) != null) {
- result.append(strLine);
- }
- in.close();
- return result.toString();
- }
-
- protected Folder createFolderWithName(String folderName) {
- Folder rootFolder = createSession().getRootFolder();
- return createChildFolderWithName(rootFolder, folderName);
- }
-
- protected Folder createChildFolderWithName(Folder parent, String childName) {
- Map<String, String> newFolderProps = new HashMap<String, String>();
- newFolderProps.put(PropertyIds.OBJECT_TYPE_ID, "cmis:folder");
- newFolderProps.put(PropertyIds.NAME, childName);
- return parent.createFolder(newFolderProps);
- }
-
- protected void createTextDocument(Folder newFolder, String content, String fileName)
- throws UnsupportedEncodingException {
- byte[] buf = content.getBytes("UTF-8");
- ByteArrayInputStream input = new ByteArrayInputStream(buf);
- ContentStream contentStream = createSession().getObjectFactory()
- .createContentStream(fileName, buf.length, "text/plain; charset=UTF-8", input);
-
- Map<String, Object> properties = new HashMap<String, Object>();
- properties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document");
- properties.put(PropertyIds.NAME, fileName);
- newFolder.createDocument(properties, contentStream, VersioningState.NONE);
- }
-
- @BeforeClass
- public static void startServer() throws Exception {
- cmisServer = new Server(9090);
- cmisServer.setHandler(new WebAppContext(OPEN_CMIS_SERVER_WAR_PATH, "/chemistry-opencmis-server-inmemory"));
- cmisServer.start();
- }
-
- @AfterClass
- public static void stopServer() throws Exception {
- cmisServer.stop();
- }
-
- @Override
- @Before
- public void setUp() throws Exception {
- deleteAllContent();
- super.setUp();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/c90c9dc9/components/camel-cmis/src/test/java/org/apache/camel/component/cmis/CMISConsumerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-cmis/src/test/java/org/apache/camel/component/cmis/CMISConsumerTest.java b/components/camel-cmis/src/test/java/org/apache/camel/component/cmis/CMISConsumerTest.java
new file mode 100644
index 0000000..007822a
--- /dev/null
+++ b/components/camel-cmis/src/test/java/org/apache/camel/component/cmis/CMISConsumerTest.java
@@ -0,0 +1,104 @@
+/**
+ * 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.camel.component.cmis;
+
+import java.io.UnsupportedEncodingException;
+import java.util.List;
+
+import org.apache.camel.Consumer;
+import org.apache.camel.Endpoint;
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.chemistry.opencmis.client.api.Folder;
+import org.junit.Before;
+import org.junit.Test;
+
+public class CMISConsumerTest extends CMISTestSupport {
+
+ @EndpointInject(uri = "mock:result")
+ protected MockEndpoint resultEndpoint;
+
+ @Test
+ public void getAllContentFromServerOrderedFromRootToLeaves() throws Exception {
+ resultEndpoint.expectedMessageCount(5);
+
+ Consumer treeBasedConsumer = createConsumerFor(CMIS_ENDPOINT_TEST_SERVER);
+ treeBasedConsumer.start();
+
+ resultEndpoint.assertIsSatisfied();
+ treeBasedConsumer.stop();
+
+ List<Exchange> exchanges = resultEndpoint.getExchanges();
+ assertTrue(getNodeNameForIndex(exchanges, 0).equals("RootFolder"));
+ assertTrue(getNodeNameForIndex(exchanges, 1).equals("Folder1"));
+ assertTrue(getNodeNameForIndex(exchanges, 2).equals("Folder2"));
+ assertTrue(getNodeNameForIndex(exchanges, 3).contains(".txt"));
+ assertTrue(getNodeNameForIndex(exchanges, 4).contains(".txt"));
+ }
+
+ @Test
+ public void consumeDocumentsWithQuery() throws Exception {
+ resultEndpoint.expectedMessageCount(2);
+
+ Consumer queryBasedConsumer = createConsumerFor(
+ CMIS_ENDPOINT_TEST_SERVER + "?query=SELECT * FROM cmis:document");
+ queryBasedConsumer.start();
+ resultEndpoint.assertIsSatisfied();
+ queryBasedConsumer.stop();
+ }
+
+ private Consumer createConsumerFor(String path) throws Exception {
+ Endpoint endpoint = context.getEndpoint("cmis://" + path);
+ return endpoint.createConsumer(new Processor() {
+ public void process(Exchange exchange) throws Exception {
+ template.send("mock:result", exchange);
+ }
+ });
+ }
+
+ private String getNodeNameForIndex(List<Exchange> exchanges, int index) {
+ return exchanges.get(index).getIn().getHeader("cmis:name", String.class);
+ }
+
+ private void populateRepositoryRootFolderWithTwoFoldersAndTwoDocuments()
+ throws UnsupportedEncodingException {
+ Folder folder1 = createFolderWithName("Folder1");
+ Folder folder2 = createChildFolderWithName(folder1, "Folder2");
+ createTextDocument(folder2, "Document2.1", "2.1.txt");
+ createTextDocument(folder2, "Document2.2", "2.2.txt");
+ //L0 ROOT
+ // |
+ //L1 Folder1
+ //L2 |_____Folder2
+ // ||
+ //L3 Doc2.1___||___Doc2.2
+ }
+
+ @Override
+ public boolean isUseRouteBuilder() {
+ return false;
+ }
+
+ @Override
+ @Before
+ public void setUp() throws Exception {
+ super.setUp();
+ populateRepositoryRootFolderWithTwoFoldersAndTwoDocuments();
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/c90c9dc9/components/camel-cmis/src/test/java/org/apache/camel/component/cmis/CMISProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-cmis/src/test/java/org/apache/camel/component/cmis/CMISProducerTest.java b/components/camel-cmis/src/test/java/org/apache/camel/component/cmis/CMISProducerTest.java
new file mode 100644
index 0000000..b8d5d78
--- /dev/null
+++ b/components/camel-cmis/src/test/java/org/apache/camel/component/cmis/CMISProducerTest.java
@@ -0,0 +1,180 @@
+/**
+ * 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.camel.component.cmis;
+
+import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
+import org.apache.camel.NoSuchHeaderException;
+import org.apache.camel.Produce;
+import org.apache.camel.Producer;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.ResolveEndpointFailedException;
+import org.apache.camel.RuntimeExchangeException;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.chemistry.opencmis.client.api.CmisObject;
+import org.apache.chemistry.opencmis.client.api.Document;
+import org.apache.chemistry.opencmis.client.api.Folder;
+import org.apache.chemistry.opencmis.commons.PropertyIds;
+import org.junit.Test;
+
+public class CMISProducerTest extends CMISTestSupport {
+
+ @Produce(uri = "direct:start")
+ protected ProducerTemplate template;
+
+ @Test
+ public void storeMessageBodyAsTextDocument() throws Exception {
+ String content = "Some content to be store";
+ Exchange exchange = createExchangeWithInBody(content);
+ exchange.getIn().getHeaders().put(PropertyIds.CONTENT_STREAM_MIME_TYPE, "text/plain; charset=UTF-8");
+ exchange.getIn().getHeaders().put(PropertyIds.NAME, "test.file");
+
+ template.send(exchange);
+
+ String newNodeId = exchange.getOut().getBody(String.class);
+ assertNotNull(newNodeId);
+
+ String newNodeContent = getDocumentContentAsString(newNodeId);
+ assertEquals(content, newNodeContent);
+ }
+
+ @Test
+ public void getDocumentMimeTypeFromMessageContentType() throws Exception {
+ Exchange exchange = createExchangeWithInBody("Some content to be store");
+ exchange.getIn().getHeaders().put(Exchange.CONTENT_TYPE, "text/plain");
+ exchange.getIn().getHeaders().put(PropertyIds.NAME, "test.file");
+
+ template.send(exchange);
+ String newNodeId = exchange.getOut().getBody(String.class);
+
+ CmisObject cmisObject = retrieveCMISObjectByIdFromServer(newNodeId);
+ Document doc = (Document)cmisObject;
+ assertEquals("text/plain", doc.getPropertyValue(PropertyIds.CONTENT_STREAM_MIME_TYPE));
+ }
+
+ @Test
+ public void namePropertyIsAlwaysRequired() {
+ Exchange exchange = createExchangeWithInBody("Some content that will fail to be stored");
+ exchange.getIn().getHeaders().put(PropertyIds.CONTENT_STREAM_MIME_TYPE, "text/plain; charset=UTF-8");
+
+ template.send(exchange);
+ Exception exception = exchange.getException();
+ Object body = exchange.getOut().getBody();
+
+ assertNull(body);
+ assertTrue(exception instanceof NoSuchHeaderException);
+ }
+
+ @Test
+ public void createDocumentWithoutContentByExplicitlySpecifyingObjectTypeHeader() throws Exception {
+ Exchange exchange = createExchangeWithInBody(null);
+ exchange.getIn().getHeaders().put(PropertyIds.CONTENT_STREAM_MIME_TYPE, "text/plain; charset=UTF-8");
+ exchange.getIn().getHeaders().put(PropertyIds.OBJECT_TYPE_ID, "cmis:document");
+ exchange.getIn().getHeaders().put(PropertyIds.NAME, "test.file");
+
+ template.send(exchange);
+ String newNodeId = exchange.getOut().getBody(String.class);
+ assertNotNull(newNodeId);
+
+ CmisObject cmisObject = retrieveCMISObjectByIdFromServer(newNodeId);
+ Document doc = (Document)cmisObject;
+ assertEquals("cmis:document", doc.getPropertyValue(PropertyIds.OBJECT_TYPE_ID));
+ }
+
+ @Test
+ public void emptyBodyAndMissingObjectTypeHeaderCreatesFolderNode() throws Exception {
+ Exchange exchange = createExchangeWithInBody(null);
+ exchange.getIn().getHeaders().put(PropertyIds.NAME, "testFolder");
+
+ template.send(exchange);
+ String newNodeId = exchange.getOut().getBody(String.class);
+ assertNotNull(newNodeId);
+
+ CmisObject newNode = retrieveCMISObjectByIdFromServer(newNodeId);
+ assertEquals("cmis:folder", newNode.getType().getId());
+ assertTrue(newNode instanceof Folder);
+ }
+
+ @Test
+ public void cmisPropertiesAreStored() throws Exception {
+ Exchange exchange = createExchangeWithInBody("Some content to be store");
+ exchange.getIn().getHeaders().put(PropertyIds.CONTENT_STREAM_MIME_TYPE, "text/plain; charset=UTF-8");
+ exchange.getIn().getHeaders().put(PropertyIds.NAME, "test.txt");
+
+ template.send(exchange);
+ String newNodeId = exchange.getOut().getBody(String.class);
+ CmisObject newNode = retrieveCMISObjectByIdFromServer(newNodeId);
+
+ assertEquals("test.txt", newNode.getPropertyValue(PropertyIds.NAME));
+ assertEquals("text/plain; charset=UTF-8",
+ newNode.getPropertyValue(PropertyIds.CONTENT_STREAM_MIME_TYPE));
+ }
+
+ @Test(expected = ResolveEndpointFailedException.class)
+ public void failConnectingToNonExistingRepository() throws Exception {
+ Endpoint endpoint = context.getEndpoint("cmis://" + CMIS_ENDPOINT_TEST_SERVER
+ + "?username=admin&password=admin&repositoryId=NON_EXISTING_ID");
+ Producer producer = endpoint.createProducer();
+
+ Exchange exchange = createExchangeWithInBody("Some content to be store");
+ exchange.getIn().getHeaders().put(PropertyIds.NAME, "test.txt");
+ producer.process(exchange);
+ }
+
+ @Test
+ public void createDocumentAtSpecificPath() throws Exception {
+ Folder folder1 = createFolderWithName("Folder1");
+ createChildFolderWithName(folder1, "Folder2");
+ String existingFolderStructure = "/Folder1/Folder2";
+
+ Exchange exchange = createExchangeWithInBody("Some content to be stored");
+ exchange.getIn().getHeaders().put(PropertyIds.CONTENT_STREAM_MIME_TYPE, "text/plain; charset=UTF-8");
+ exchange.getIn().getHeaders().put(PropertyIds.NAME, "test.file");
+ exchange.getIn().getHeaders().put(CamelCMISConstants.CMIS_FOLDER_PATH, existingFolderStructure);
+
+ template.send(exchange);
+ String newNodeId = exchange.getOut().getBody(String.class);
+
+ Document document = (Document)retrieveCMISObjectByIdFromServer(newNodeId);
+ String documentFullPath = document.getPaths().get(0);
+ assertEquals(existingFolderStructure + "/test.file", documentFullPath);
+ }
+
+ @Test
+ public void failCreatingFolderAtNonExistingPath() throws Exception {
+ String existingFolderStructure = "/No/Path/Here";
+
+ Exchange exchange = createExchangeWithInBody(null);
+ exchange.getIn().getHeaders().put(PropertyIds.NAME, "folder1");
+ exchange.getIn().getHeaders().put(PropertyIds.OBJECT_TYPE_ID, "cmis:folder");
+ exchange.getIn().getHeaders().put(CamelCMISConstants.CMIS_FOLDER_PATH, existingFolderStructure);
+
+ template.send(exchange);
+ assertTrue(exchange.getException() instanceof RuntimeExchangeException);
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ public void configure() {
+ from("direct:start")
+ .to("cmis://" + CMIS_ENDPOINT_TEST_SERVER);
+ }
+ };
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/c90c9dc9/components/camel-cmis/src/test/java/org/apache/camel/component/cmis/CMISQueryProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-cmis/src/test/java/org/apache/camel/component/cmis/CMISQueryProducerTest.java b/components/camel-cmis/src/test/java/org/apache/camel/component/cmis/CMISQueryProducerTest.java
new file mode 100644
index 0000000..db6af6a
--- /dev/null
+++ b/components/camel-cmis/src/test/java/org/apache/camel/component/cmis/CMISQueryProducerTest.java
@@ -0,0 +1,109 @@
+/**
+ * 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.camel.component.cmis;
+
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
+import org.apache.camel.Producer;
+import org.apache.chemistry.opencmis.client.api.Folder;
+import org.junit.Before;
+import org.junit.Test;
+
+public class CMISQueryProducerTest extends CMISTestSupport {
+
+ @Override
+ @Before
+ public void setUp() throws Exception {
+ super.setUp();
+ populateServerWithContent();
+ }
+
+ @Test
+ public void queryServerForDocumentWithSpecificName() throws Exception {
+ Endpoint endpoint = context.getEndpoint("cmis://" + CMIS_ENDPOINT_TEST_SERVER + "?queryMode=true");
+ Producer producer = endpoint.createProducer();
+
+ Exchange exchange = createExchangeWithInBody(
+ "SELECT * FROM cmis:document WHERE cmis:name = 'test1.txt'");
+ producer.process(exchange);
+
+ @SuppressWarnings("unchecked")
+ List<Map<String, Object>> documents = exchange.getOut().getBody(List.class);
+ assertEquals(1, documents.size());
+ assertEquals("test1.txt", documents.get(0).get("cmis:name"));
+ }
+
+ @Test
+ public void getResultCountFromHeader() throws Exception {
+ Endpoint endpoint = context.getEndpoint("cmis://" + CMIS_ENDPOINT_TEST_SERVER + "?queryMode=true");
+ Producer producer = endpoint.createProducer();
+
+ Exchange exchange = createExchangeWithInBody(
+ "SELECT * FROM cmis:document WHERE CONTAINS('Camel test content.')");
+ producer.process(exchange);
+
+ @SuppressWarnings("unchecked")
+ List<Map<String, Object>> documents = exchange.getOut().getBody(List.class);
+ assertEquals(2, documents.size());
+ assertEquals(2, exchange.getOut().getHeader("CamelCMISResultCount"));
+ }
+
+ @Test
+ public void limitNumberOfResultsWithReadSizeHeader() throws Exception {
+ Endpoint endpoint = context.getEndpoint("cmis://" + CMIS_ENDPOINT_TEST_SERVER + "?queryMode=true");
+ Producer producer = endpoint.createProducer();
+
+ Exchange exchange = createExchangeWithInBody(
+ "SELECT * FROM cmis:document WHERE CONTAINS('Camel test content.')");
+ exchange.getIn().getHeaders().put("CamelCMISReadSize", 1);
+
+ producer.process(exchange);
+
+ @SuppressWarnings("unchecked")
+ List<Map<String, Object>> documents = exchange.getOut().getBody(List.class);
+ assertEquals(1, documents.size());
+ }
+
+ @Test
+ public void retrieveAlsoDocumentContent() throws Exception {
+ Endpoint endpoint = context.getEndpoint("cmis://" + CMIS_ENDPOINT_TEST_SERVER + "?queryMode=true");
+ Producer producer = endpoint.createProducer();
+
+ Exchange exchange = createExchangeWithInBody(
+ "SELECT * FROM cmis:document WHERE cmis:name='test1.txt'");
+ exchange.getIn().getHeaders().put("CamelCMISRetrieveContent", true);
+
+ producer.process(exchange);
+
+ @SuppressWarnings("unchecked")
+ List<Map<String, Object>> documents = exchange.getOut().getBody(List.class);
+ InputStream content = (InputStream)documents.get(0).get("CamelCMISContent");
+ assertEquals("This is the first Camel test content.", readFromStream(content));
+ }
+
+ private void populateServerWithContent() throws UnsupportedEncodingException {
+ Folder newFolder = createFolderWithName("CamelCmisTestFolder");
+ createTextDocument(newFolder, "This is the first Camel test content.", "test1.txt");
+ createTextDocument(newFolder, "This is the second Camel test content.", "test2.txt");
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/c90c9dc9/components/camel-cmis/src/test/java/org/apache/camel/component/cmis/CMISTestSupport.java
----------------------------------------------------------------------
diff --git a/components/camel-cmis/src/test/java/org/apache/camel/component/cmis/CMISTestSupport.java b/components/camel-cmis/src/test/java/org/apache/camel/component/cmis/CMISTestSupport.java
new file mode 100644
index 0000000..a466a01
--- /dev/null
+++ b/components/camel-cmis/src/test/java/org/apache/camel/component/cmis/CMISTestSupport.java
@@ -0,0 +1,163 @@
+/**
+ * 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.camel.component.cmis;
+
+import java.io.BufferedReader;
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.UnsupportedEncodingException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.impl.DefaultExchange;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.apache.chemistry.opencmis.client.api.CmisObject;
+import org.apache.chemistry.opencmis.client.api.Document;
+import org.apache.chemistry.opencmis.client.api.Folder;
+import org.apache.chemistry.opencmis.client.api.ItemIterable;
+import org.apache.chemistry.opencmis.client.api.Repository;
+import org.apache.chemistry.opencmis.client.api.Session;
+import org.apache.chemistry.opencmis.client.api.SessionFactory;
+import org.apache.chemistry.opencmis.client.runtime.SessionFactoryImpl;
+import org.apache.chemistry.opencmis.commons.PropertyIds;
+import org.apache.chemistry.opencmis.commons.SessionParameter;
+import org.apache.chemistry.opencmis.commons.data.ContentStream;
+import org.apache.chemistry.opencmis.commons.enums.BindingType;
+import org.apache.chemistry.opencmis.commons.enums.UnfileObject;
+import org.apache.chemistry.opencmis.commons.enums.VersioningState;
+import org.eclipse.jetty.server.Server;
+import org.eclipse.jetty.webapp.WebAppContext;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+
+public class CMISTestSupport extends CamelTestSupport {
+ protected static final String CMIS_ENDPOINT_TEST_SERVER
+ = "http://localhost:9090/chemistry-opencmis-server-inmemory/atom";
+ protected static final String OPEN_CMIS_SERVER_WAR_PATH
+ = "target/dependency/chemistry-opencmis-server-inmemory-0.8.0.war";
+
+ protected static Server cmisServer;
+
+ protected Exchange createExchangeWithInBody(String body) {
+ DefaultExchange exchange = new DefaultExchange(context);
+ if (body != null) {
+ exchange.getIn().setBody(body);
+ }
+ return exchange;
+ }
+
+ protected CmisObject retrieveCMISObjectByIdFromServer(String nodeId) throws Exception {
+ Session session = createSession();
+ return session.getObject(nodeId);
+ }
+
+ protected void deleteAllContent() {
+ Session session = createSession();
+ Folder rootFolder = session.getRootFolder();
+ ItemIterable<CmisObject> children = rootFolder.getChildren();
+ for (CmisObject cmisObject : children) {
+ if ("cmis:folder".equals(cmisObject.getPropertyValue(PropertyIds.OBJECT_TYPE_ID))) {
+ List<String> notDeltedIdList = ((Folder)cmisObject)
+ .deleteTree(true, UnfileObject.DELETE, true);
+ if (notDeltedIdList != null && notDeltedIdList.size() > 0) {
+ throw new RuntimeException("Cannot empty repo");
+ }
+ } else {
+ cmisObject.delete(true);
+ }
+ }
+ session.getBinding().close();
+ }
+
+ protected Session createSession() {
+ SessionFactory sessionFactory = SessionFactoryImpl.newInstance();
+ Map<String, String> parameter = new HashMap<String, String>();
+ parameter.put(SessionParameter.ATOMPUB_URL, CMIS_ENDPOINT_TEST_SERVER);
+ parameter.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());
+
+ Repository repository = sessionFactory.getRepositories(parameter).get(0);
+ return repository.createSession();
+ }
+
+ protected String getDocumentContentAsString(String nodeId) throws Exception {
+ CmisObject cmisObject = retrieveCMISObjectByIdFromServer(nodeId);
+ Document doc = (Document)cmisObject;
+ InputStream inputStream = doc.getContentStream().getStream();
+ return readFromStream(inputStream);
+ }
+
+ protected String readFromStream(InputStream in) throws Exception {
+ StringBuilder result = new StringBuilder();
+ BufferedReader br = new BufferedReader(new InputStreamReader(in));
+
+ String strLine;
+ while ((strLine = br.readLine()) != null) {
+ result.append(strLine);
+ }
+ in.close();
+ return result.toString();
+ }
+
+ protected Folder createFolderWithName(String folderName) {
+ Folder rootFolder = createSession().getRootFolder();
+ return createChildFolderWithName(rootFolder, folderName);
+ }
+
+ protected Folder createChildFolderWithName(Folder parent, String childName) {
+ Map<String, String> newFolderProps = new HashMap<String, String>();
+ newFolderProps.put(PropertyIds.OBJECT_TYPE_ID, "cmis:folder");
+ newFolderProps.put(PropertyIds.NAME, childName);
+ return parent.createFolder(newFolderProps);
+ }
+
+ protected void createTextDocument(Folder newFolder, String content, String fileName)
+ throws UnsupportedEncodingException {
+ byte[] buf = content.getBytes("UTF-8");
+ ByteArrayInputStream input = new ByteArrayInputStream(buf);
+ ContentStream contentStream = createSession().getObjectFactory()
+ .createContentStream(fileName, buf.length, "text/plain; charset=UTF-8", input);
+
+ Map<String, Object> properties = new HashMap<String, Object>();
+ properties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document");
+ properties.put(PropertyIds.NAME, fileName);
+ newFolder.createDocument(properties, contentStream, VersioningState.NONE);
+ }
+
+ @BeforeClass
+ public static void startServer() throws Exception {
+ cmisServer = new Server(9090);
+ cmisServer.setHandler(new WebAppContext(OPEN_CMIS_SERVER_WAR_PATH, "/chemistry-opencmis-server-inmemory"));
+ cmisServer.start();
+ }
+
+ @AfterClass
+ public static void stopServer() throws Exception {
+ cmisServer.stop();
+ }
+
+ @Override
+ @Before
+ public void setUp() throws Exception {
+ deleteAllContent();
+ super.setUp();
+ }
+
+}