Author: jstrachan
Date: Tue May 13 06:59:37 2008
New Revision: 655868
URL: http://svn.apache.org/viewvc?rev=655868&view=rev
Log:
made it easier to instantiate a FileEndpoint directly and added a test case for
https://issues.apache.org/activemq/browse/CAMEL-505
Added:
activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/file/
activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/file/SpringFileRouteTest.java
(with props)
activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/file/
activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/file/SpringFileRouteTest-context.xml
(with props)
Modified:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileEndpoint.java
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultEndpoint.java
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ScheduledPollEndpoint.java
activemq/camel/trunk/components/camel-spring/pom.xml
Modified:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileEndpoint.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileEndpoint.java?rev=655868&r1=655867&r2=655868&view=diff
==============================================================================
---
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileEndpoint.java
(original)
+++
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileEndpoint.java
Tue May 13 06:59:37 2008
@@ -23,6 +23,7 @@
import org.apache.camel.Message;
import org.apache.camel.Processor;
import org.apache.camel.Producer;
+import org.apache.camel.util.ObjectHelper;
import org.apache.camel.component.file.strategy.FileProcessStrategyFactory;
import org.apache.camel.component.file.strategy.FileProcessStrategySupport;
import org.apache.camel.component.file.strategy.NoOpFileProcessStrategy;
@@ -62,6 +63,13 @@
this.file = file;
}
+ public FileEndpoint(File file) {
+ this.file = file;
+ }
+
+ public FileEndpoint() {
+ }
+
public Producer<FileExchange> createProducer() throws Exception {
Producer<FileExchange> result = new FileProducer(this);
return result;
@@ -105,12 +113,17 @@
}
public File getFile() {
+ ObjectHelper.notNull(file, "file");
if (autoCreate && !file.exists()) {
file.mkdirs();
}
return file;
}
+ public void setFile(File file) {
+ this.file = file;
+ }
+
public boolean isSingleton() {
return true;
}
@@ -260,4 +273,8 @@
return FileProcessStrategyFactory.createFileProcessStrategy(isNoop(),
isDelete(), isLock(), moveNamePrefix, moveNamePostfix);
}
+ @Override
+ protected String createEndpointUri() {
+ return "file://" + getFile().getAbsolutePath();
+ }
}
Modified:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultEndpoint.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultEndpoint.java?rev=655868&r1=655867&r2=655868&view=diff
==============================================================================
---
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultEndpoint.java
(original)
+++
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultEndpoint.java
Tue May 13 06:59:37 2008
@@ -54,28 +54,38 @@
}
protected DefaultEndpoint(String endpointUri) {
- this.endpointUri = endpointUri;
+ this.setEndpointUri(endpointUri);
+ }
+
+ protected DefaultEndpoint() {
}
public int hashCode() {
- return endpointUri.hashCode() * 37 + 1;
+ return getEndpointUri().hashCode() * 37 + 1;
}
@Override
public boolean equals(Object object) {
if (object instanceof DefaultEndpoint) {
DefaultEndpoint that = (DefaultEndpoint) object;
- return ObjectHelper.equal(this.endpointUri, that.endpointUri);
+ return ObjectHelper.equal(this.getEndpointUri(),
that.getEndpointUri());
}
return false;
}
@Override
public String toString() {
- return "Endpoint[" + endpointUri + "]";
+ return "Endpoint[" + getEndpointUri() + "]";
}
public String getEndpointUri() {
+ if (endpointUri == null) {
+ endpointUri = createEndpointUri();
+ if (endpointUri == null) {
+ throw new IllegalArgumentException("endpointUri is not specified
and " + getClass().getName()
+ + " does not implement createEndpointUri() to create a
default value");
+ }
+ }
return endpointUri;
}
@@ -182,4 +192,17 @@
public void configureProperties(Map options) {
}
+
+ /**
+ * A factory method to lazily create the endpointUri if none is specified
+ * @return
+ */
+ protected String createEndpointUri() {
+ return null;
+ }
+
+ protected void setEndpointUri(String endpointUri) {
+ this.endpointUri = endpointUri;
+ }
+
}
Modified:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ScheduledPollEndpoint.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ScheduledPollEndpoint.java?rev=655868&r1=655867&r2=655868&view=diff
==============================================================================
---
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ScheduledPollEndpoint.java
(original)
+++
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ScheduledPollEndpoint.java
Tue May 13 06:59:37 2008
@@ -45,6 +45,9 @@
super(endpointUri);
}
+ protected ScheduledPollEndpoint() {
+ }
+
public Map getConsumerProperties() {
return consumerProperties;
}
Modified: activemq/camel/trunk/components/camel-spring/pom.xml
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/pom.xml?rev=655868&r1=655867&r2=655868&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-spring/pom.xml (original)
+++ activemq/camel/trunk/components/camel-spring/pom.xml Tue May 13 06:59:37
2008
@@ -73,6 +73,11 @@
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-hamcrest</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<scope>test</scope>
@@ -80,7 +85,7 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
- <version>${spring-version}</version>
+ <version>${spring-version}</version>
<scope>test</scope>
</dependency>
<dependency>
Added:
activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/file/SpringFileRouteTest.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/file/SpringFileRouteTest.java?rev=655868&view=auto
==============================================================================
---
activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/file/SpringFileRouteTest.java
(added)
+++
activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/file/SpringFileRouteTest.java
Tue May 13 06:59:37 2008
@@ -0,0 +1,63 @@
+/**
+ *
+ * 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.file;
+
+import java.io.File;
+
+import org.apache.camel.CamelTemplate;
+import org.apache.camel.Endpoint;
+import org.apache.camel.EndpointInject;
+import org.apache.camel.TestSupport;
+import org.apache.camel.Assertions;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.ContextConfiguration;
+import
org.springframework.test.context.junit38.AbstractJUnit38SpringContextTests;
+
+/**
+ * @version $Revision: 1.1 $
+ */
[EMAIL PROTECTED]
+public class SpringFileRouteTest extends AbstractJUnit38SpringContextTests {
+ protected String expectedBody = "Hello World!";
+ @Autowired
+ protected CamelTemplate template;
+ @Autowired
+ protected Endpoint inputFile;
+ @EndpointInject(uri = "mock:result")
+ protected MockEndpoint result;
+
+ public void testMocksAreValid() throws Exception {
+ // lets check that our injected endpoint is valid
+ FileEndpoint fileEndpoint = Assertions.assertIsInstanceOf(FileEndpoint.class, inputFile);
+ assertEquals("File", new File("target/test-default-inbox"),
fileEndpoint.getFile());
+
+ result.expectedBodiesReceived(expectedBody);
+ result.setResultWaitTime(5000);
+
+ template.sendBodyAndHeader(inputFile, expectedBody, "cheese", 123);
+
+ result.assertIsSatisfied();
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ TestSupport.deleteDirectory("target/test-default-inbox");
+ super.setUp();
+ }
+}
Propchange:
activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/file/SpringFileRouteTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/file/SpringFileRouteTest-context.xml
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/file/SpringFileRouteTest-context.xml?rev=655868&view=auto
==============================================================================
---
activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/file/SpringFileRouteTest-context.xml
(added)
+++
activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/file/SpringFileRouteTest-context.xml
Tue May 13 06:59:37 2008
@@ -0,0 +1,40 @@
+<?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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
+ http://activemq.apache.org/camel/schema/spring
http://activemq.apache.org/camel/schema/spring/camel-spring.xsd
+ ">
+
+ <!-- START SNIPPET: example -->
+ <camelContext xmlns="http://activemq.apache.org/camel/schema/spring">
+ <template id="camelTemplate"/>
+
+ <route>
+ <from ref="inputFile"/>
+ <to uri="mock:result"/>
+ </route>
+ </camelContext>
+
+ <bean id="inputFile" class="org.apache.camel.component.file.FileEndpoint">
+ <property name="file" value="target/test-default-inbox"/>
+ </bean>
+ <!-- END SNIPPET: example -->
+
+</beans>
Propchange:
activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/file/SpringFileRouteTest-context.xml
------------------------------------------------------------------------------
svn:eol-style = native