camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hadr...@apache.org
Subject svn commit: r600802 - in /activemq/camel/trunk/components: ./ camel-jcr/ camel-jcr/src/ camel-jcr/src/main/ camel-jcr/src/main/java/ camel-jcr/src/main/java/org/ camel-jcr/src/main/java/org/apache/ camel-jcr/src/main/java/org/apache/camel/ camel-jcr/sr...
Date Tue, 04 Dec 2007 06:32:18 GMT
Author: hadrian
Date: Mon Dec  3 22:32:16 2007
New Revision: 600802

URL: http://svn.apache.org/viewvc?rev=600802&view=rev
Log:
Patch for CAMEL-252.  Awsome, thanks!

Added:
    activemq/camel/trunk/components/camel-jcr/
    activemq/camel/trunk/components/camel-jcr/pom.xml   (with props)
    activemq/camel/trunk/components/camel-jcr/src/
    activemq/camel/trunk/components/camel-jcr/src/main/
    activemq/camel/trunk/components/camel-jcr/src/main/java/
    activemq/camel/trunk/components/camel-jcr/src/main/java/org/
    activemq/camel/trunk/components/camel-jcr/src/main/java/org/apache/
    activemq/camel/trunk/components/camel-jcr/src/main/java/org/apache/camel/
    activemq/camel/trunk/components/camel-jcr/src/main/java/org/apache/camel/component/
    activemq/camel/trunk/components/camel-jcr/src/main/java/org/apache/camel/component/jcr/
    activemq/camel/trunk/components/camel-jcr/src/main/java/org/apache/camel/component/jcr/JcrComponent.java
  (with props)
    activemq/camel/trunk/components/camel-jcr/src/main/java/org/apache/camel/component/jcr/JcrConverter.java
  (with props)
    activemq/camel/trunk/components/camel-jcr/src/main/java/org/apache/camel/component/jcr/JcrEndpoint.java
  (with props)
    activemq/camel/trunk/components/camel-jcr/src/main/java/org/apache/camel/component/jcr/JcrProducer.java
  (with props)
    activemq/camel/trunk/components/camel-jcr/src/main/resources/
    activemq/camel/trunk/components/camel-jcr/src/main/resources/META-INF/
    activemq/camel/trunk/components/camel-jcr/src/main/resources/META-INF/services/
    activemq/camel/trunk/components/camel-jcr/src/main/resources/META-INF/services/org/
    activemq/camel/trunk/components/camel-jcr/src/main/resources/META-INF/services/org/apache/
    activemq/camel/trunk/components/camel-jcr/src/main/resources/META-INF/services/org/apache/camel/
    activemq/camel/trunk/components/camel-jcr/src/main/resources/META-INF/services/org/apache/camel/TypeConverter
    activemq/camel/trunk/components/camel-jcr/src/main/resources/META-INF/services/org/apache/camel/component/
    activemq/camel/trunk/components/camel-jcr/src/main/resources/META-INF/services/org/apache/camel/component/jcr
    activemq/camel/trunk/components/camel-jcr/src/test/
    activemq/camel/trunk/components/camel-jcr/src/test/java/
    activemq/camel/trunk/components/camel-jcr/src/test/java/org/
    activemq/camel/trunk/components/camel-jcr/src/test/java/org/apache/
    activemq/camel/trunk/components/camel-jcr/src/test/java/org/apache/camel/
    activemq/camel/trunk/components/camel-jcr/src/test/java/org/apache/camel/component/
    activemq/camel/trunk/components/camel-jcr/src/test/java/org/apache/camel/component/jcr/
    activemq/camel/trunk/components/camel-jcr/src/test/java/org/apache/camel/component/jcr/JcrConverterTest.java
  (with props)
    activemq/camel/trunk/components/camel-jcr/src/test/java/org/apache/camel/component/jcr/JcrRouteTest.java
  (with props)
    activemq/camel/trunk/components/camel-jcr/src/test/resources/
    activemq/camel/trunk/components/camel-jcr/src/test/resources/log4j.properties   (with
props)
Modified:
    activemq/camel/trunk/components/pom.xml

Added: activemq/camel/trunk/components/camel-jcr/pom.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jcr/pom.xml?rev=600802&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-jcr/pom.xml (added)
+++ activemq/camel/trunk/components/camel-jcr/pom.xml Mon Dec  3 22:32:16 2007
@@ -0,0 +1,72 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+  
+  http://www.apache.org/licenses/LICENSE-2.0
+  
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<project
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xmlns="http://maven.apache.org/POM/4.0.0">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.apache.camel</groupId>
+    <artifactId>camel-parent</artifactId>
+    <version>1.3-SNAPSHOT</version>
+  </parent>
+  <artifactId>camel-jcr</artifactId>
+  <packaging>bundle</packaging>
+  <name>Camel :: JCR</name>
+  <description>Camel JCR support</description>
+
+  <properties>
+    <camel.osgi.export.pkg>
+      org.apache.camel.component.jcr*
+    </camel.osgi.export.pkg>
+  </properties>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.camel</groupId>
+      <artifactId>camel-core</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.jackrabbit</groupId>
+      <artifactId>jackrabbit-core</artifactId>
+      <version>1.3.3</version>
+    </dependency>
+    <dependency>
+      <groupId>javax.jcr</groupId>
+      <artifactId>jcr</artifactId>
+      <version>1.0</version>
+    </dependency>
+    <!-- test dependencies -->
+    <dependency>
+      <groupId>org.apache.camel</groupId>
+      <artifactId>camel-core</artifactId>
+      <type>test-jar</type>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-log4j12</artifactId>
+      <version>1.4.3</version>
+    </dependency>
+  </dependencies>
+</project>

Propchange: activemq/camel/trunk/components/camel-jcr/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/camel/trunk/components/camel-jcr/src/main/java/org/apache/camel/component/jcr/JcrComponent.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jcr/src/main/java/org/apache/camel/component/jcr/JcrComponent.java?rev=600802&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-jcr/src/main/java/org/apache/camel/component/jcr/JcrComponent.java
(added)
+++ activemq/camel/trunk/components/camel-jcr/src/main/java/org/apache/camel/component/jcr/JcrComponent.java
Mon Dec  3 22:32:16 2007
@@ -0,0 +1,40 @@
+/**
+ * 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.jcr;
+
+import java.util.Map;
+
+import org.apache.camel.Endpoint;
+import org.apache.camel.impl.DefaultComponent;
+import org.apache.camel.impl.DefaultExchange;
+
+/**
+ * A component for integrating with JSR-170 (JCR) compliant content repositories
+ */
+public class JcrComponent extends DefaultComponent<DefaultExchange> {
+
+    /**
+     * Property key for specifying the name of a node in the repository 
+     */
+    public static final String NODE_NAME = "org.apache.camel.component.jcr.node_name";
+
+    @Override @SuppressWarnings("unchecked")
+    protected Endpoint<DefaultExchange> createEndpoint(String uri, String remaining,
Map properties) throws Exception {
+        return new JcrEndpoint(uri, this);
+    }
+
+}

Propchange: activemq/camel/trunk/components/camel-jcr/src/main/java/org/apache/camel/component/jcr/JcrComponent.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/camel/trunk/components/camel-jcr/src/main/java/org/apache/camel/component/jcr/JcrConverter.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jcr/src/main/java/org/apache/camel/component/jcr/JcrConverter.java?rev=600802&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-jcr/src/main/java/org/apache/camel/component/jcr/JcrConverter.java
(added)
+++ activemq/camel/trunk/components/camel-jcr/src/main/java/org/apache/camel/component/jcr/JcrConverter.java
Mon Dec  3 22:32:16 2007
@@ -0,0 +1,76 @@
+/**
+ * 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.jcr;
+
+import java.io.InputStream;
+import java.util.Calendar;
+
+import javax.jcr.Value;
+
+import org.apache.camel.Converter;
+import org.apache.jackrabbit.value.BinaryValue;
+import org.apache.jackrabbit.value.BooleanValue;
+import org.apache.jackrabbit.value.DateValue;
+import org.apache.jackrabbit.value.StringValue;
+
+/**
+ * A helper class to transform Object into JCR {@link Value} implementations 
+ */
+@Converter
+public class JcrConverter {
+
+    /**
+     * Converts a {@link Boolean} into a {@link Value}
+     * @param bool the boolean
+     * @return the value
+     */
+    @Converter
+    public Value toValue(Boolean bool) {
+        return new BooleanValue(bool);
+    }
+
+    /**
+     * Converts an {@link InputStream} into a {@link Value}
+     * @param stream the input stream
+     * @return the value
+     */
+    @Converter
+    public Value toValue(InputStream stream) {
+        return new BinaryValue(stream);
+    }
+
+    /**
+     * Converts a {@link Calendar} into a {@link Value}
+     * @param calendar the calendar
+     * @return the value
+     */
+    @Converter
+    public Value toValue(Calendar calendar) {
+        return new DateValue(calendar);
+    }
+
+    /**
+     * Converts a {@link String} into a {@link Value}
+     * @param value the string
+     * @return the value
+     */
+    @Converter
+    public Value toValue(String value) {
+        return new StringValue(value);
+    }
+
+}

Propchange: activemq/camel/trunk/components/camel-jcr/src/main/java/org/apache/camel/component/jcr/JcrConverter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/camel/trunk/components/camel-jcr/src/main/java/org/apache/camel/component/jcr/JcrEndpoint.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jcr/src/main/java/org/apache/camel/component/jcr/JcrEndpoint.java?rev=600802&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-jcr/src/main/java/org/apache/camel/component/jcr/JcrEndpoint.java
(added)
+++ activemq/camel/trunk/components/camel-jcr/src/main/java/org/apache/camel/component/jcr/JcrEndpoint.java
Mon Dec  3 22:32:16 2007
@@ -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.jcr;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import javax.jcr.Credentials;
+import javax.jcr.Repository;
+import javax.jcr.SimpleCredentials;
+
+import org.apache.camel.Consumer;
+import org.apache.camel.Processor;
+import org.apache.camel.Producer;
+import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.impl.DefaultEndpoint;
+import org.apache.camel.impl.DefaultExchange;
+
+/**
+ * A JCR endpoint
+ */
+public class JcrEndpoint extends DefaultEndpoint<DefaultExchange> {
+
+    private Credentials credentials;
+    private Repository repository;
+    private String base;
+
+    @SuppressWarnings("unchecked")
+    protected JcrEndpoint(String endpointUri, JcrComponent component) {
+        super(endpointUri, component);
+        try {
+            URI uri = new URI(endpointUri);
+            if (uri.getUserInfo() != null && uri.getAuthority() != null) {
+                this.credentials = new SimpleCredentials(uri.getUserInfo(), uri.getAuthority().toCharArray());
+            }
+            this.repository = (Repository) component.getCamelContext().getRegistry().lookup(uri.getHost());
+            if (repository == null) {
+                throw new RuntimeCamelException("No JCR repository defined under '" + uri.getHost()
+ "'");
+            }
+            this.base = uri.getPath().replaceAll("^/", "");
+        } catch (URISyntaxException e) {
+            throw new IllegalArgumentException("Invalid URI: " + endpointUri, e);
+        }
+    }
+
+    /**
+     * Currently unsupported
+     * @throws RuntimeCamelException
+     */
+    public Consumer<DefaultExchange> createConsumer(Processor processor) throws Exception
{
+        throw new RuntimeCamelException("No consumer endpoint support for JCR available");
+    }
+
+    /**
+     * Creates a new {@link Producer} 
+     */
+    public Producer<DefaultExchange> createProducer() throws Exception {
+        return new JcrProducer(this);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isSingleton() {
+        return false;
+    }
+
+    /**
+     * Get the {@link Repository}
+     * 
+     * @return the repository
+     */
+    protected Repository getRepository() {
+        return repository;
+    }
+
+    /**
+     * Get the {@link Credentials} for establishing the JCR repository connection
+     * 
+     * @return the credentials
+     */
+    protected Credentials getCredentials() {
+        return credentials;
+    }
+
+    /**
+     * Get the base node when accessing the reposititory
+     * 
+     * @return the base node
+     */
+    protected String getBase() {
+        return base;
+    }
+
+}

Propchange: activemq/camel/trunk/components/camel-jcr/src/main/java/org/apache/camel/component/jcr/JcrEndpoint.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/camel/trunk/components/camel-jcr/src/main/java/org/apache/camel/component/jcr/JcrProducer.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jcr/src/main/java/org/apache/camel/component/jcr/JcrProducer.java?rev=600802&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-jcr/src/main/java/org/apache/camel/component/jcr/JcrProducer.java
(added)
+++ activemq/camel/trunk/components/camel-jcr/src/main/java/org/apache/camel/component/jcr/JcrProducer.java
Mon Dec  3 22:32:16 2007
@@ -0,0 +1,82 @@
+/**
+ * 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.jcr;
+
+import javax.jcr.LoginException;
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.Value;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.TypeConverter;
+import org.apache.camel.impl.DefaultExchange;
+import org.apache.camel.impl.DefaultProducer;
+
+public class JcrProducer extends DefaultProducer<DefaultExchange> {
+
+    public JcrProducer(JcrEndpoint jcrEndpoint) throws LoginException,
+            RepositoryException {
+        super(jcrEndpoint);
+    }
+
+    public void process(Exchange exchange) throws Exception {
+        Session session = openSession();
+        try {
+            Node base = getBaseNode(session);
+            Node node = base.addNode(getNodeName(exchange));
+            TypeConverter converter = exchange.getContext().getTypeConverter();
+            for (String key : exchange.getProperties().keySet()) {
+                Value value = converter.convertTo(Value.class, exchange
+                        .getProperty(key));
+                node.setProperty(key, value);
+            }
+            node.addMixin("mix:referenceable");
+            session.save();
+            exchange.getOut().setBody(node.getUUID());
+        } finally {
+            if (session != null &&
+                session.isLive() ) {
+                session.logout();
+            }
+        }
+    }
+
+    private String getNodeName(Exchange exchange) {
+        if (exchange.getProperty(JcrComponent.NODE_NAME) != null) {
+            return exchange.getProperty(JcrComponent.NODE_NAME).toString();
+        }
+        return exchange.getExchangeId();
+    }
+
+    private Node getBaseNode(Session session) throws Exception {
+        Node baseNode = session.getRootNode();
+        for (String node : getJcrEndpoint().getBase().split("/")) {
+            baseNode = baseNode.addNode(node);
+        }
+        return baseNode;
+    }
+
+    protected Session openSession() throws LoginException, RepositoryException {
+        return getJcrEndpoint().getRepository().login(getJcrEndpoint().getCredentials());
+    }
+
+    private JcrEndpoint getJcrEndpoint() {
+        JcrEndpoint endpoint = (JcrEndpoint) getEndpoint();
+        return endpoint;
+    }
+}

Propchange: activemq/camel/trunk/components/camel-jcr/src/main/java/org/apache/camel/component/jcr/JcrProducer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/camel/trunk/components/camel-jcr/src/main/resources/META-INF/services/org/apache/camel/TypeConverter
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jcr/src/main/resources/META-INF/services/org/apache/camel/TypeConverter?rev=600802&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-jcr/src/main/resources/META-INF/services/org/apache/camel/TypeConverter
(added)
+++ activemq/camel/trunk/components/camel-jcr/src/main/resources/META-INF/services/org/apache/camel/TypeConverter
Mon Dec  3 22:32:16 2007
@@ -0,0 +1,18 @@
+#
+# 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.
+#
+
+org.apache.camel.component.jcr
\ No newline at end of file

Added: activemq/camel/trunk/components/camel-jcr/src/main/resources/META-INF/services/org/apache/camel/component/jcr
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jcr/src/main/resources/META-INF/services/org/apache/camel/component/jcr?rev=600802&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-jcr/src/main/resources/META-INF/services/org/apache/camel/component/jcr
(added)
+++ activemq/camel/trunk/components/camel-jcr/src/main/resources/META-INF/services/org/apache/camel/component/jcr
Mon Dec  3 22:32:16 2007
@@ -0,0 +1,18 @@
+#
+# 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.
+#
+
+class=org.apache.camel.component.jcr.JcrComponent
\ No newline at end of file

Added: activemq/camel/trunk/components/camel-jcr/src/test/java/org/apache/camel/component/jcr/JcrConverterTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jcr/src/test/java/org/apache/camel/component/jcr/JcrConverterTest.java?rev=600802&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-jcr/src/test/java/org/apache/camel/component/jcr/JcrConverterTest.java
(added)
+++ activemq/camel/trunk/components/camel-jcr/src/test/java/org/apache/camel/component/jcr/JcrConverterTest.java
Mon Dec  3 22:32:16 2007
@@ -0,0 +1,64 @@
+/**
+ * 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.jcr;
+
+import java.io.ByteArrayInputStream;
+import java.util.Calendar;
+
+import javax.jcr.Value;
+
+import junit.framework.TestCase;
+
+import org.apache.camel.TypeConverter;
+import org.apache.camel.impl.ReflectionInjector;
+import org.apache.camel.impl.converter.DefaultTypeConverter;
+import org.apache.jackrabbit.value.BinaryValue;
+import org.apache.jackrabbit.value.BooleanValue;
+import org.apache.jackrabbit.value.DateValue;
+import org.apache.jackrabbit.value.StringValue;
+
+/**
+ * Tests for JCR type conversions ({@link JcrConverter})
+ */
+public class JcrConverterTest extends TestCase {
+
+    protected TypeConverter converter = new DefaultTypeConverter(new ReflectionInjector());
+
+    public void testBooleanValueConverter() throws Exception {
+        assertJcrConverterAvailable(BooleanValue.class, Boolean.TRUE);
+    }
+
+    public void testBinaryValueConverter() throws Exception {
+        assertJcrConverterAvailable(BinaryValue.class, new ByteArrayInputStream("test".getBytes()));
+    }
+
+    public void testDateValueConverter() throws Exception {
+        assertJcrConverterAvailable(DateValue.class, Calendar.getInstance());
+    }
+
+    public void testStringValueConverter() throws Exception {
+        assertJcrConverterAvailable(StringValue.class, "plain text");
+    }
+
+    @SuppressWarnings("unchecked")
+    private void assertJcrConverterAvailable(Class expected, Object object) {
+        Value value = converter.convertTo(Value.class, object);
+        assertNotNull(value);
+        assertTrue(expected.isAssignableFrom(value.getClass()));
+    }
+
+}

Propchange: activemq/camel/trunk/components/camel-jcr/src/test/java/org/apache/camel/component/jcr/JcrConverterTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/camel/trunk/components/camel-jcr/src/test/java/org/apache/camel/component/jcr/JcrRouteTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jcr/src/test/java/org/apache/camel/component/jcr/JcrRouteTest.java?rev=600802&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-jcr/src/test/java/org/apache/camel/component/jcr/JcrRouteTest.java
(added)
+++ activemq/camel/trunk/components/camel-jcr/src/test/java/org/apache/camel/component/jcr/JcrRouteTest.java
Mon Dec  3 22:32:16 2007
@@ -0,0 +1,92 @@
+/**
+ * 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.jcr;
+
+import java.io.File;
+import java.io.IOException;
+
+import javax.jcr.Node;
+import javax.jcr.Repository;
+import javax.jcr.Session;
+import javax.jcr.SimpleCredentials;
+import javax.naming.Context;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.jackrabbit.core.TransientRepository;
+import org.apache.jackrabbit.core.fs.local.FileUtil;
+
+public class JcrRouteTest extends ContextTestSupport {
+
+    private Repository repository;
+
+    @Override
+    protected void setUp() throws Exception {
+        clean();
+        super.setUp();
+        template.setDefaultEndpointUri("direct:a");
+    }
+
+    private void clean() throws IOException {
+        File[] files = { new File("repository"), new File("repository.xml"), new File("derby.log")
};
+        for (File file : files) {
+            if (file.exists()) {
+                FileUtil.delete(file);
+            }
+        }
+    }
+
+    public void testJcrRoute() throws Exception {
+        Exchange exchange = createExchangeWithBody("<hello>world!</hello>");
+        Exchange out = template.send(exchange);
+        assertNotNull(out);
+        String uuid = out.getOut().getBody(String.class);
+        Session session = repository.login(new SimpleCredentials("user", "pass".toCharArray()));
+        try {
+            Node node = session.getNodeByUUID(uuid);
+            assertNotNull(node);
+            assertEquals("/home/test/node", node.getPath());
+            assertEquals("<hello>world!</hello>", node.getProperty("my.contents.property").getString());
+        } finally {
+            if (session != null && session.isLive()) {
+                session.logout();
+            }
+        }
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:a")
+                    .setProperty(JcrComponent.NODE_NAME, constant("node"))
+                    .setProperty("my.contents.property", body())
+                    .to("jcr://user:pass@repository/home/test");
+            }
+        };
+    }
+
+    @Override
+    protected Context createJndiContext() throws Exception {
+        Context context = super.createJndiContext();
+        repository = new TransientRepository();
+        context.bind("repository", repository);
+        return context;
+    }
+}

Propchange: activemq/camel/trunk/components/camel-jcr/src/test/java/org/apache/camel/component/jcr/JcrRouteTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/camel/trunk/components/camel-jcr/src/test/resources/log4j.properties
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jcr/src/test/resources/log4j.properties?rev=600802&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-jcr/src/test/resources/log4j.properties (added)
+++ activemq/camel/trunk/components/camel-jcr/src/test/resources/log4j.properties Mon Dec
 3 22:32:16 2007
@@ -0,0 +1,34 @@
+## ------------------------------------------------------------------------
+## 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.
+## ------------------------------------------------------------------------
+
+#
+# The logging properties used for testing
+#
+log4j.rootLogger=INFO, out
+
+# uncomment the following to enable camel debugging
+#log4j.logger.org.apache.camel=DEBUG
+
+log4j.logger.org.apache.activemq=WARN
+log4j.logger.org.apache.mina=WARN
+log4j.logger.org.apache.ftpserver=WARN
+
+# CONSOLE appender not used by default
+log4j.appender.out=org.apache.log4j.ConsoleAppender
+log4j.appender.out.layout=org.apache.log4j.PatternLayout
+log4j.appender.out.layout.ConversionPattern=[%30.30t] %-30.30c{1} %-5p %m%n
+#log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n

Propchange: activemq/camel/trunk/components/camel-jcr/src/test/resources/log4j.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: activemq/camel/trunk/components/pom.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/pom.xml?rev=600802&r1=600801&r2=600802&view=diff
==============================================================================
--- activemq/camel/trunk/components/pom.xml (original)
+++ activemq/camel/trunk/components/pom.xml Mon Dec  3 22:32:16 2007
@@ -51,6 +51,7 @@
     <module>camel-jing</module>
     <module>camel-jms</module>
     <module>camel-josql</module>
+    <module>camel-jcr</module>
     <module>camel-jpa</module>
     <module>camel-juel</module>
     <module>camel-mail</module>



Mime
View raw message