Author: davsclaus
Date: Tue Feb 15 10:20:03 2011
New Revision: 1070829
URL: http://svn.apache.org/viewvc?rev=1070829&view=rev
Log:
CAMEL-2954: Added mybatis to distribution. Added osgi test.
Added:
camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/mybatis/
camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/mybatis/Account.java
camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/mybatis/MyBatisTest.java
camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/mybatis/
camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/mybatis/Account.xml
camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/mybatis/SqlMapConfig.xml
Modified:
camel/trunk/apache-camel/pom.xml
camel/trunk/apache-camel/src/main/descriptors/common-bin.xml
camel/trunk/parent/pom.xml
camel/trunk/tests/camel-itest-osgi/pom.xml
Modified: camel/trunk/apache-camel/pom.xml
URL:
http://svn.apache.org/viewvc/camel/trunk/apache-camel/pom.xml?rev=1070829&r1=1070828&r2=1070829&view=diff
==============================================================================
--- camel/trunk/apache-camel/pom.xml (original)
+++ camel/trunk/apache-camel/pom.xml Tue Feb 15 10:20:03 2011
@@ -275,6 +275,10 @@
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
+ <artifactId>camel-mybatis</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
<artifactId>camel-netty</artifactId>
</dependency>
<dependency>
Modified: camel/trunk/apache-camel/src/main/descriptors/common-bin.xml
URL:
http://svn.apache.org/viewvc/camel/trunk/apache-camel/src/main/descriptors/common-bin.xml?rev=1070829&r1=1070828&r2=1070829&view=diff
==============================================================================
--- camel/trunk/apache-camel/src/main/descriptors/common-bin.xml (original)
+++ camel/trunk/apache-camel/src/main/descriptors/common-bin.xml Tue Feb 15
10:20:03 2011
@@ -88,6 +88,7 @@
<include>org.apache.camel:camel-mina</include>
<include>org.apache.camel:camel-msv</include>
<include>org.apache.camel:camel-mvel</include>
+ <include>org.apache.camel:camel-mybatis</include>
<include>org.apache.camel:camel-nagios</include>
<include>org.apache.camel:camel-netty</include>
<include>org.apache.camel:camel-ognl</include>
Modified: camel/trunk/parent/pom.xml
URL:
http://svn.apache.org/viewvc/camel/trunk/parent/pom.xml?rev=1070829&r1=1070828&r2=1070829&view=diff
==============================================================================
--- camel/trunk/parent/pom.xml (original)
+++ camel/trunk/parent/pom.xml Tue Feb 15 10:20:03 2011
@@ -499,6 +499,11 @@
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
+ <artifactId>camel-mybatis</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
<artifactId>camel-nagios</artifactId>
<version>${project.version}</version>
</dependency>
Modified: camel/trunk/tests/camel-itest-osgi/pom.xml
URL:
http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/pom.xml?rev=1070829&r1=1070828&r2=1070829&view=diff
==============================================================================
--- camel/trunk/tests/camel-itest-osgi/pom.xml (original)
+++ camel/trunk/tests/camel-itest-osgi/pom.xml Tue Feb 15 10:20:03 2011
@@ -122,6 +122,11 @@
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-mybatis</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>ca.uhn.hapi</groupId>
<artifactId>hapi-structures-v24</artifactId>
<version>1.0</version>
@@ -359,7 +364,7 @@
<include>**/*Test.*</include>
</includes>
<excludes>
- <!-- TODO: temporary disable unit test to let TC
not hang -->
+ <!-- TODO: temporary disable unit test to
let TC not hang -->
<exclude>**/*Test.*</exclude>
<!--There are some conflicts of the JAXB OSGi
bundle and Hudson System jar
so I comment out these JAXB related tests -->
Added:
camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/mybatis/Account.java
URL:
http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/mybatis/Account.java?rev=1070829&view=auto
==============================================================================
---
camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/mybatis/Account.java
(added)
+++
camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/mybatis/Account.java
Tue Feb 15 10:20:03 2011
@@ -0,0 +1,65 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.itest.osgi.mybatis;
+
+/**
+ * @version $Revision$
+ */
+public class Account {
+ private int id;
+ private String firstName;
+ private String lastName;
+ private String emailAddress;
+
+ @Override
+ public String toString() {
+ return "Account[id: " + id + " name: " + firstName + " " + lastName +
" email: " + emailAddress + "]";
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public String getFirstName() {
+ return firstName;
+ }
+
+ public void setFirstName(String firstName) {
+ this.firstName = firstName;
+ }
+
+ public String getLastName() {
+ return lastName;
+ }
+
+ public void setLastName(String lastName) {
+ this.lastName = lastName;
+ }
+
+ public String getEmailAddress() {
+ return emailAddress;
+ }
+
+ public void setEmailAddress(String emailAddress) {
+ this.emailAddress = emailAddress;
+ }
+
+}
Added:
camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/mybatis/MyBatisTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/mybatis/MyBatisTest.java?rev=1070829&view=auto
==============================================================================
---
camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/mybatis/MyBatisTest.java
(added)
+++
camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/mybatis/MyBatisTest.java
Tue Feb 15 10:20:03 2011
@@ -0,0 +1,129 @@
+/**
+ * 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.mybatis;
+
+import java.sql.Connection;
+import java.sql.Statement;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mybatis.MyBatisComponent;
+import org.apache.camel.component.mybatis.MyBatisEndpoint;
+import org.apache.camel.itest.osgi.OSGiIntegrationTestSupport;
+import org.junit.Ignore;
+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 static org.ops4j.pax.exam.CoreOptions.equinox;
+import static org.ops4j.pax.exam.CoreOptions.felix;
+import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
+import static org.ops4j.pax.exam.CoreOptions.options;
+import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.profile;
+import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.scanFeatures;
+import static
org.ops4j.pax.exam.container.def.PaxRunnerOptions.workingDirectory;
+
+/**
+ * @version $Revision$
+ */
+@RunWith(JUnit4TestRunner.class)
+@Ignore("Loading OSGi driver in OSGi is ***** hard")
+public class MyBatisTest extends OSGiIntegrationTestSupport {
+
+ @Test
+ public void testMina() throws Exception {
+ getMockEndpoint("mock:result").expectedMessageCount(1);
+
+ Account account = new Account();
+ account.setId(444);
+ account.setFirstName("Willem");
+ account.setLastName("Jiang");
+ account.setEmailAddress("[email protected]");
+
+ template.sendBody("mybatis:insertAccount?statementType=Insert",
account);
+
+ assertMockEndpointsSatisfied();
+
+ dropTable();
+ }
+
+ @Override
+ protected CamelContext createCamelContext() throws Exception {
+ CamelContext context = super.createCamelContext();
+ context.disableJMX();
+ return context;
+ }
+
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ public void configure() throws Exception {
+ MyBatisComponent myBatis = context.getComponent("mybatis",
MyBatisComponent.class);
+
myBatis.setConfigurationUri("org/apache/camel/itest/osgi/mybatis/SqlMapConfig.xml");
+
+ // create table before we start using mybatis
+ createTable();
+
+ from("mybatis:selectAllAccounts").to("mock:result");
+ }
+ };
+ }
+
+ private void createTable() throws Exception {
+ // lets create the database...
+ Connection connection = createConnection();
+ Statement statement = connection.createStatement();
+ statement.execute("create table ACCOUNT ( ACC_ID INTEGER ,
ACC_FIRST_NAME VARCHAR(255), ACC_LAST_NAME VARCHAR(255), ACC_EMAIL VARCHAR(255)
)");
+ connection.close();
+ }
+
+ private void dropTable() throws Exception {
+ Connection connection = createConnection();
+ Statement statement = connection.createStatement();
+ statement.execute("drop table ACCOUNT");
+ connection.close();
+ }
+
+ private Connection createConnection() throws Exception {
+ MyBatisEndpoint endpoint = resolveMandatoryEndpoint("mybatis:Account",
MyBatisEndpoint.class);
+ return
endpoint.getSqlSessionFactory().getConfiguration().getEnvironment().getDataSource().getConnection();
+ }
+
+ @Configuration
+ public static Option[] configure() {
+ Option[] options = options(
+
+ // install the spring dm profile
+ profile("spring.dm").version("1.2.0"),
+ // this is how you set the default log level when using pax
logging (logProfile)
+
org.ops4j.pax.exam.CoreOptions.systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("INFO"),
+
+
mavenBundle().groupId("org.apache.derby").artifactId("derby").version("10.4.2.0"),
+
+ // using the features to install the camel components
+ scanFeatures(getCamelKarafFeatureUrl(),
+ "camel-core", "camel-test", "camel-mybatis"),
+
+ workingDirectory("target/paxrunner/"),
+
+ felix(), equinox());
+
+ return options;
+ }
+
+}
Added:
camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/mybatis/Account.xml
URL:
http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/mybatis/Account.xml?rev=1070829&view=auto
==============================================================================
---
camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/mybatis/Account.xml
(added)
+++
camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/mybatis/Account.xml
Tue Feb 15 10:20:03 2011
@@ -0,0 +1,100 @@
+<?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.
+-->
+<!DOCTYPE mapper
+ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+ "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+
+<mapper namespace="Account">
+
+ <!-- Result maps describe the mapping between the columns returned
+ from a query, and the class properties. A result map isn't
+ necessary if the columns (or aliases) match to the properties
+ exactly. -->
+ <resultMap id="AccountResult" type="Account">
+ <result property="id" column="ACC_ID"/>
+ <result property="firstName" column="ACC_FIRST_NAME"/>
+ <result property="lastName" column="ACC_LAST_NAME"/>
+ <result property="emailAddress" column="ACC_EMAIL"/>
+ </resultMap>
+
+ <!-- Select with no parameters using the result map for Account class. -->
+ <select id="selectAllAccounts" resultMap="AccountResult">
+ select * from ACCOUNT order by ACC_ID
+ </select>
+
+ <!-- A simpler select example without the result map. Note the
+aliases to match the properties of the target result class. -->
+ <select id="selectAccountById" parameterType="int" resultType="Account">
+ select
+ ACC_ID as id,
+ ACC_FIRST_NAME as firstName,
+ ACC_LAST_NAME as lastName,
+ ACC_EMAIL as emailAddress
+ from ACCOUNT
+ where ACC_ID = #{id}
+ </select>
+
+ <!-- Insert example, using the Account parameter class -->
+ <insert id="insertAccount" parameterType="Account">
+ insert into ACCOUNT (
+ ACC_ID,
+ ACC_FIRST_NAME,
+ ACC_LAST_NAME,
+ ACC_EMAIL
+ )
+ values (
+ #{id}, #{firstName}, #{lastName}, #{emailAddress}
+ )
+ </insert>
+
+ <!-- Update example, using the Account parameter class -->
+ <update id="updateAccount" parameterType="Account">
+ update ACCOUNT set
+ ACC_FIRST_NAME = #{firstName},
+ ACC_LAST_NAME = #{lastName},
+ ACC_EMAIL = #{emailAddress}
+ where
+ ACC_ID = #{id}
+ </update>
+
+ <!-- Delete example, using an integer as the parameter class -->
+ <delete id="deleteAccountById" parameterType="int">
+ delete from ACCOUNT where ACC_ID = #{id}
+ </delete>
+
+ <!-- START SNIPPET: e1 -->
+ <select id="selectUnprocessedAccounts" resultMap="AccountResult">
+ select * from ACCOUNT where PROCESSED = false
+ </select>
+ <!-- END SNIPPET: e1 -->
+
+ <select id="selectProcessedAccounts" resultMap="AccountResult">
+ select * from ACCOUNT where PROCESSED = true
+ </select>
+
+ <!-- START SNIPPET: e2 -->
+ <update id="consumeAccount" parameterType="Account">
+ update ACCOUNT set PROCESSED = true where ACC_ID = #{id}
+ </update>
+ <!-- END SNIPPET: e2 -->
+
+ <select id="count" resultType="int">
+ select count(*) from ACCOUNT
+ </select>
+
+</mapper>
\ No newline at end of file
Added:
camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/mybatis/SqlMapConfig.xml
URL:
http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/mybatis/SqlMapConfig.xml?rev=1070829&view=auto
==============================================================================
---
camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/mybatis/SqlMapConfig.xml
(added)
+++
camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/mybatis/SqlMapConfig.xml
Tue Feb 15 10:20:03 2011
@@ -0,0 +1,50 @@
+<?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.
+-->
+
+<!DOCTYPE configuration
+ PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
+ "http://mybatis.org/dtd/mybatis-3-config.dtd">
+
+<configuration>
+
+ <settings>
+ <setting name="useGeneratedKeys" value="false"/>
+ </settings>
+
+ <!-- Use type aliases to avoid typing the full classname every time. -->
+ <typeAliases>
+ <typeAlias alias="Account"
type="org.apache.camel.itest.osgi.mybatis.Account"/>
+ </typeAliases>
+
+ <!-- setup environment with JDBC data source -->
+ <environments default="development">
+ <environment id="development">
+ <transactionManager type="JDBC"/>
+ <dataSource type="POOLED">
+ <property name="driver"
value="org.apache.derby.jdbc.EmbeddedDriver"/>
+ <property name="url"
value="jdbc:derby:target/derby;create=true"/>
+ </dataSource>
+ </environment>
+ </environments>
+
+ <!-- mapping files -->
+ <mappers>
+ <mapper resource="org/apache/camel/itest/osgi/mybatis/Account.xml"/>
+ </mappers>
+
+</configuration>
\ No newline at end of file