Author: davsclaus
Date: Sun Jun 3 14:38:04 2012
New Revision: 1345680
URL: http://svn.apache.org/viewvc?rev=1345680&view=rev
Log:
CAMEL-52520: Added osgi unit test.
Added:
camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/bindy/
camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/bindy/BindyDataFormatCsvTest.java
- copied, changed from r1345637,
camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/beanio/BeanIODataFormatSimpleTest.java
camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/bindy/BindySpringDataFormatCsvTest.java
camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/bindy/Employee.java
- copied, changed from r1345637,
camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/beanio/Employee.java
camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/bindy/
camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/bindy/BindySpringDataFormatCsvTest.xml
- copied, changed from r1345637,
camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/spring/bean/CamelContext.xml
Modified:
camel/trunk/tests/camel-itest-osgi/pom.xml
Modified: camel/trunk/tests/camel-itest-osgi/pom.xml
URL:
http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/pom.xml?rev=1345680&r1=1345679&r2=1345680&view=diff
==============================================================================
--- camel/trunk/tests/camel-itest-osgi/pom.xml (original)
+++ camel/trunk/tests/camel-itest-osgi/pom.xml Sun Jun 3 14:38:04 2012
@@ -112,6 +112,11 @@
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
+ <artifactId>camel-bindy</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
<artifactId>camel-blueprint</artifactId>
<scope>test</scope>
</dependency>
Copied:
camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/bindy/BindyDataFormatCsvTest.java
(from r1345637,
camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/beanio/BeanIODataFormatSimpleTest.java)
URL:
http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/bindy/BindyDataFormatCsvTest.java?p2=camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/bindy/BindyDataFormatCsvTest.java&p1=camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/beanio/BeanIODataFormatSimpleTest.java&r1=1345637&r2=1345680&rev=1345680&view=diff
==============================================================================
---
camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/beanio/BeanIODataFormatSimpleTest.java
(original)
+++
camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/bindy/BindyDataFormatCsvTest.java
Sun Jun 3 14:38:04 2012
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.camel.itest.osgi.beanio;
+package org.apache.camel.itest.osgi.bindy;
import java.text.ParseException;
import java.text.SimpleDateFormat;
@@ -23,7 +23,7 @@ import java.util.List;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
-import org.apache.camel.dataformat.beanio.BeanIODataFormat;
+import org.apache.camel.dataformat.bindy.csv.BindyCsvDataFormat;
import org.apache.camel.itest.osgi.OSGiIntegrationTestSupport;
import org.apache.camel.spi.DataFormat;
import org.junit.Test;
@@ -38,17 +38,17 @@ import static org.ops4j.pax.exam.OptionU
*
*/
@RunWith(JUnit4TestRunner.class)
-public class BeanIODataFormatSimpleTest extends OSGiIntegrationTestSupport {
+public class BindyDataFormatCsvTest extends OSGiIntegrationTestSupport {
- private static final String FIXED_DATA =
"Joe,Smith,Developer,75000,10012009" + LS
- + "Jane,Doe,Architect,80000,01152008" + LS
- + "Jon,Anderson,Manager,85000,03182007" + LS;
+ private static final String FIXED_DATA =
"Joe,Smith,Developer,75000,10012009" + "\n"
+ + "Jane,Doe,Architect,80000,01152008" + "\n"
+ + "Jon,Anderson,Manager,85000,03182007" + "\n";
@Test
public void testMarshal() throws Exception {
List<Employee> employees = getEmployees();
- MockEndpoint mock = getMockEndpoint("mock:beanio-marshal");
+ MockEndpoint mock = getMockEndpoint("mock:bindy-marshal");
mock.expectedBodiesReceived(FIXED_DATA);
template.sendBody("direct:marshal", employees);
@@ -60,7 +60,7 @@ public class BeanIODataFormatSimpleTest
public void testUnmarshal() throws Exception {
List<Employee> employees = getEmployees();
- MockEndpoint mock = getMockEndpoint("mock:beanio-unmarshal");
+ MockEndpoint mock = getMockEndpoint("mock:bindy-unmarshal");
mock.expectedBodiesReceived(employees);
template.sendBody("direct:unmarshal", FIXED_DATA);
@@ -73,15 +73,13 @@ public class BeanIODataFormatSimpleTest
return new RouteBuilder() {
@Override
public void configure() throws Exception {
- DataFormat format = new BeanIODataFormat(
- "org/apache/camel/itest/osgi/beanio/mappings.xml",
- "employeeFile");
+ DataFormat format = new BindyCsvDataFormat(Employee.class);
from("direct:unmarshal").unmarshal(format)
- .split(simple("body")).to("mock:beanio-unmarshal");
+ .split(simple("body")).to("mock:bindy-unmarshal");
from("direct:marshal").marshal(format)
- .to("mock:beanio-marshal");
+ .to("mock:bindy-marshal");
}
};
}
@@ -119,7 +117,7 @@ public class BeanIODataFormatSimpleTest
Option[] options = combine(
getDefaultCamelKarafOptions(),
// using the features to install the other camel components
- loadCamelFeatures("camel-beanio"));
+ loadCamelFeatures("camel-bindy"));
return options;
}
Added:
camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/bindy/BindySpringDataFormatCsvTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/bindy/BindySpringDataFormatCsvTest.java?rev=1345680&view=auto
==============================================================================
---
camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/bindy/BindySpringDataFormatCsvTest.java
(added)
+++
camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/bindy/BindySpringDataFormatCsvTest.java
Sun Jun 3 14:38:04 2012
@@ -0,0 +1,112 @@
+/**
+ * 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.itest.osgi.bindy;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.itest.osgi.OSGiIntegrationSpringTestSupport;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.Configuration;
+import org.ops4j.pax.exam.junit.JUnit4TestRunner;
+import
org.springframework.osgi.context.support.OsgiBundleXmlApplicationContext;
+
+import static org.ops4j.pax.exam.OptionUtils.combine;
+
+/**
+ *
+ */
+@RunWith(JUnit4TestRunner.class)
+public class BindySpringDataFormatCsvTest extends
OSGiIntegrationSpringTestSupport {
+
+ private static final String FIXED_DATA =
"Joe,Smith,Developer,75000,10012009" + "\n"
+ + "Jane,Doe,Architect,80000,01152008" + "\n"
+ + "Jon,Anderson,Manager,85000,03182007" + "\n";
+
+ @Test
+ public void testMarshal() throws Exception {
+ List<Employee> employees = getEmployees();
+
+ MockEndpoint mock = getMockEndpoint("mock:bindy-marshal");
+ mock.expectedBodiesReceived(FIXED_DATA);
+
+ template.sendBody("direct:marshal", employees);
+
+ mock.assertIsSatisfied();
+ }
+
+ @Test
+ public void testUnmarshal() throws Exception {
+ List<Employee> employees = getEmployees();
+
+ MockEndpoint mock = getMockEndpoint("mock:bindy-unmarshal");
+ mock.expectedBodiesReceived(employees);
+
+ template.sendBody("direct:unmarshal", FIXED_DATA);
+
+ mock.assertIsSatisfied();
+ }
+
+ @Override
+ protected OsgiBundleXmlApplicationContext createApplicationContext() {
+ return new OsgiBundleXmlApplicationContext(new
String[]{"org/apache/camel/itest/osgi/bindy/BindySpringDataFormatCsvTest.xml"});
+ }
+
+ private List<Employee> getEmployees() throws ParseException {
+ List<Employee> employees = new ArrayList<Employee>();
+ Employee one = new Employee();
+ one.setFirstName("Joe");
+ one.setLastName("Smith");
+ one.setTitle("Developer");
+ one.setSalary(75000);
+ one.setHireDate(new SimpleDateFormat("MMddyyyy").parse("10012009"));
+ employees.add(one);
+
+ Employee two = new Employee();
+ two.setFirstName("Jane");
+ two.setLastName("Doe");
+ two.setTitle("Architect");
+ two.setSalary(80000);
+ two.setHireDate(new SimpleDateFormat("MMddyyyy").parse("01152008"));
+ employees.add(two);
+
+ Employee three = new Employee();
+ three.setFirstName("Jon");
+ three.setLastName("Anderson");
+ three.setTitle("Manager");
+ three.setSalary(85000);
+ three.setHireDate(new SimpleDateFormat("MMddyyyy").parse("03182007"));
+ employees.add(three);
+ return employees;
+ }
+
+ @Configuration
+ public static Option[] configure() {
+ Option[] options = combine(
+ getDefaultCamelKarafOptions(),
+ // using the features to install the other camel components
+ loadCamelFeatures("camel-bindy"));
+
+ return options;
+ }
+
+}
Copied:
camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/bindy/Employee.java
(from r1345637,
camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/beanio/Employee.java)
URL:
http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/bindy/Employee.java?p2=camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/bindy/Employee.java&p1=camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/beanio/Employee.java&r1=1345637&r2=1345680&rev=1345680&view=diff
==============================================================================
---
camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/beanio/Employee.java
(original)
+++
camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/bindy/Employee.java
Sun Jun 3 14:38:04 2012
@@ -14,19 +14,28 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.camel.itest.osgi.beanio;
+package org.apache.camel.itest.osgi.bindy;
import java.util.Date;
+import org.apache.camel.dataformat.bindy.annotation.CsvRecord;
+import org.apache.camel.dataformat.bindy.annotation.DataField;
+
/**
*
*/
+@CsvRecord(name = "Employee", crlf = "UNIX", separator = ",")
public class Employee {
+ @DataField(pos = 1)
private String firstName;
+ @DataField(pos = 2)
private String lastName;
+ @DataField(pos = 3)
private String title;
+ @DataField(pos = 4)
private int salary;
+ @DataField(pos = 5, pattern = "MMddyyyy")
private Date hireDate;
public Employee() {
Copied:
camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/bindy/BindySpringDataFormatCsvTest.xml
(from r1345637,
camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/spring/bean/CamelContext.xml)
URL:
http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/bindy/BindySpringDataFormatCsvTest.xml?p2=camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/bindy/BindySpringDataFormatCsvTest.xml&p1=camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/spring/bean/CamelContext.xml&r1=1345637&r2=1345680&rev=1345680&view=diff
==============================================================================
---
camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/spring/bean/CamelContext.xml
(original)
+++
camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/bindy/BindySpringDataFormatCsvTest.xml
Sun Jun 3 14:38:04 2012
@@ -23,14 +23,26 @@
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd">
- <bean id="foo" class="org.apache.camel.itest.osgi.core.bean.MyFooBean"/>
+ <camelContext xmlns="http://camel.apache.org/schema/spring">
- <camelContext xmlns="http://camel.apache.org/schema/spring">
- <camel:route>
- <camel:from uri="direct:start"/>
- <camel:to uri="bean:foo"/>
- <camel:to uri="mock:result"/>
- </camel:route>
- </camelContext>
+ <dataFormats>
+ <bindy id="myBindy" type="Csv"
classType="org.apache.camel.itest.osgi.bindy.Employee"/>
+ </dataFormats>
+
+ <route>
+ <from uri="direct:unmarshal"/>
+ <unmarshal ref="myBindy"/>
+ <split>
+ <simple>${body}</simple>
+ <to uri="mock:bindy-unmarshal"/>
+ </split>
+ </route>
+
+ <route>
+ <from uri="direct:marshal"/>
+ <marshal ref="myBindy"/>
+ <to uri="mock:bindy-marshal"/>
+ </route>
+ </camelContext>
</beans>