ppalaga commented on a change in pull request #2525: URL: https://github.com/apache/camel-quarkus/pull/2525#discussion_r622174997
########## File path: docs/modules/ROOT/pages/reference/extensions/mybatis.adoc ########## @@ -34,3 +38,25 @@ Please refer to the above links for usage and configuration details. ---- Check the xref:user-guide/index.adoc[User guide] for more information about writing Camel Quarkus applications. + +== Additional Camel Quarkus configuration + +Please refer to https://quarkiverse.github.io/quarkiverse-docs/quarkus-mybatis/dev/index.html[Quarkus MyBatis] for configuration. It must enable the following options + +[source, properties] +---- +quarkus.mybatis.xmlconfig.enable=true +quarkus.mybatis.xmlconfig.path=SqlMapConfig.xml +---- +TIP: `quarkus.mybatis.xmlconfig.path` must be the same with `configurationUri` param in the mybatis endpoint. + +If you want to run in the native mode, you have to set these properties in pom.xml currently. + +[source, xml] +---- +<properties> + <quarkus.package.type>native</quarkus.package.type> Review comment: `<quarkus.package.type>native</quarkus.package.type>` is not MyBatis specific and it does not need to be documented here. ########## File path: integration-tests/mybatis/src/test/java/org/apache/camel/quarkus/component/mybatis/it/MyBatisTest.java ########## @@ -0,0 +1,99 @@ +/* + * 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.quarkus.component.mybatis.it; + +import io.quarkus.test.common.QuarkusTestResource; +import io.quarkus.test.h2.H2DatabaseTestResource; +import io.quarkus.test.junit.QuarkusTest; +import io.restassured.RestAssured; +import io.restassured.http.ContentType; +import org.apache.camel.quarkus.component.mybatis.it.entity.Account; +import org.junit.jupiter.api.Test; + +import static org.hamcrest.Matchers.equalTo; + +@QuarkusTest +@QuarkusTestResource(H2DatabaseTestResource.class) +public class MyBatisTest { + + @Test + public void loadComponentMybatis() { + /* A simple autogenerated test */ + RestAssured.get("/mybatis/load/component/mybatis") + .then() + .statusCode(200); + } + + @Test + public void loadComponentMybatisBean() { + /* A simple autogenerated test */ + RestAssured.get("/mybatis/load/component/mybatis-bean") + .then() + .statusCode(200); + } Review comment: ```suggestion ``` Please remove the auto-generated tests ########## File path: extensions/mybatis/deployment/src/main/java/org/apache/camel/quarkus/component/mybatis/deployment/MybatisProcessor.java ########## @@ -34,13 +39,19 @@ FeatureBuildItem feature() { return new FeatureBuildItem(FEATURE); } - /** - * Remove this once this extension starts supporting the native mode. - */ - @BuildStep(onlyIf = NativeBuild.class) - @Record(value = ExecutionTime.RUNTIME_INIT) - void warnJvmInNative(JvmOnlyRecorder recorder) { - JvmOnlyRecorder.warnJvmInNative(LOG, FEATURE); // warn at build time - recorder.warnJvmInNative(FEATURE); // warn at runtime + @Record(ExecutionTime.STATIC_INIT) + @BuildStep + CamelBeanBuildItem mybatisComponent( + List<SqlSessionFactoryBuildItem> sqlSessionFactoryBuildItem, CamelMyBatisRecorder recorder) { + return new CamelBeanBuildItem("mybatis", MyBatisComponent.class.getName(), + recorder.createMyBatisComponent(sqlSessionFactoryBuildItem.get(0).getSqlSessionFactory())); + } + + @Record(ExecutionTime.STATIC_INIT) + @BuildStep + CamelBeanBuildItem mybatisBeanComponent( + List<SqlSessionFactoryBuildItem> sqlSessionFactoryBuildItem, CamelMyBatisRecorder recorder) { + return new CamelBeanBuildItem("mybatis-bean", MyBatisBeanComponent.class.getName(), + recorder.createMyBatisBeanComponent(sqlSessionFactoryBuildItem.get(0).getSqlSessionFactory())); Review comment: Can we be sure that sqlSessionFactoryBuildItem is not empty? ########## File path: integration-tests/mybatis/src/test/java/org/apache/camel/quarkus/component/mybatis/it/MyBatisTest.java ########## @@ -0,0 +1,99 @@ +/* + * 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.quarkus.component.mybatis.it; + +import io.quarkus.test.common.QuarkusTestResource; +import io.quarkus.test.h2.H2DatabaseTestResource; +import io.quarkus.test.junit.QuarkusTest; +import io.restassured.RestAssured; +import io.restassured.http.ContentType; +import org.apache.camel.quarkus.component.mybatis.it.entity.Account; +import org.junit.jupiter.api.Test; + +import static org.hamcrest.Matchers.equalTo; + +@QuarkusTest +@QuarkusTestResource(H2DatabaseTestResource.class) +public class MyBatisTest { + + @Test + public void loadComponentMybatis() { + /* A simple autogenerated test */ + RestAssured.get("/mybatis/load/component/mybatis") + .then() + .statusCode(200); + } + + @Test + public void loadComponentMybatisBean() { + /* A simple autogenerated test */ + RestAssured.get("/mybatis/load/component/mybatis-bean") + .then() + .statusCode(200); + } + + @Test + public void testSelectOne() { + RestAssured.get("/mybatis/selectOne?id=456") + .then() + .statusCode(200) + .body("id", equalTo(456)) + .body("firstName", equalTo("Claus")) + .body("lastName", equalTo("Ibsen")) + .body("emailAddress", equalTo("non...@gmail.com")); + } + + @Test + public void testSelectOneNotFound() { + RestAssured.get("/mybatis/selectOne?id=999") + .then() + .statusCode(404); + } + + @Test + public void testInsert() { + Account account = new Account(); + account.setId(444); + account.setFirstName("Willem"); + account.setLastName("Jiang"); + account.setEmailAddress("fara...@gmail.com"); + + RestAssured.given() + .contentType(ContentType.JSON) + .body(account) + .post("/mybatis/insertOne") + .then() + .statusCode(200) + .body(equalTo("3")); + } + + @Test + public void testDelete() { + RestAssured.delete("/mybatis/deleteOne?id=456") + .then() + .statusCode(200) + .body(equalTo("1")); Review comment: Running `testDelete()` before `testSelectOne()` would make `testSelectOne()` fail. You should not assume any particular test method execution order. You may want to move this code to `testSelectOne()`. ########## File path: extensions/mybatis/deployment/src/main/java/org/apache/camel/quarkus/component/mybatis/deployment/MybatisProcessor.java ########## @@ -34,13 +39,19 @@ FeatureBuildItem feature() { return new FeatureBuildItem(FEATURE); } - /** - * Remove this once this extension starts supporting the native mode. - */ - @BuildStep(onlyIf = NativeBuild.class) - @Record(value = ExecutionTime.RUNTIME_INIT) - void warnJvmInNative(JvmOnlyRecorder recorder) { - JvmOnlyRecorder.warnJvmInNative(LOG, FEATURE); // warn at build time - recorder.warnJvmInNative(FEATURE); // warn at runtime + @Record(ExecutionTime.STATIC_INIT) + @BuildStep + CamelBeanBuildItem mybatisComponent( + List<SqlSessionFactoryBuildItem> sqlSessionFactoryBuildItem, CamelMyBatisRecorder recorder) { Review comment: Why `List<SqlSessionFactoryBuildItem>`? Can there be more than one `SqlSessionFactoryBuildItem`? ########## File path: docs/modules/ROOT/pages/reference/extensions/mybatis.adoc ########## @@ -34,3 +38,25 @@ Please refer to the above links for usage and configuration details. ---- Check the xref:user-guide/index.adoc[User guide] for more information about writing Camel Quarkus applications. + +== Additional Camel Quarkus configuration + +Please refer to https://quarkiverse.github.io/quarkiverse-docs/quarkus-mybatis/dev/index.html[Quarkus MyBatis] for configuration. It must enable the following options + +[source, properties] +---- +quarkus.mybatis.xmlconfig.enable=true +quarkus.mybatis.xmlconfig.path=SqlMapConfig.xml +---- +TIP: `quarkus.mybatis.xmlconfig.path` must be the same with `configurationUri` param in the mybatis endpoint. + +If you want to run in the native mode, you have to set these properties in pom.xml currently. + +[source, xml] +---- +<properties> + <quarkus.package.type>native</quarkus.package.type> + <quarkus.native.additional-build-args>--report-unsupported-elements-at-runtime</quarkus.native.additional-build-args> Review comment: OK, now I see there is https://github.com/quarkiverse/quarkus-mybatis/issues/10 . I'd prefer not merging this unless https://github.com/quarkiverse/quarkus-mybatis/issues/10 is fixed, or unless there is a clear idea how it can be fixed. ########## File path: docs/modules/ROOT/pages/reference/extensions/mybatis.adoc ########## @@ -34,3 +38,25 @@ Please refer to the above links for usage and configuration details. ---- Check the xref:user-guide/index.adoc[User guide] for more information about writing Camel Quarkus applications. + +== Additional Camel Quarkus configuration + +Please refer to https://quarkiverse.github.io/quarkiverse-docs/quarkus-mybatis/dev/index.html[Quarkus MyBatis] for configuration. It must enable the following options + +[source, properties] +---- +quarkus.mybatis.xmlconfig.enable=true +quarkus.mybatis.xmlconfig.path=SqlMapConfig.xml +---- +TIP: `quarkus.mybatis.xmlconfig.path` must be the same with `configurationUri` param in the mybatis endpoint. + +If you want to run in the native mode, you have to set these properties in pom.xml currently. + +[source, xml] +---- +<properties> + <quarkus.package.type>native</quarkus.package.type> + <quarkus.native.additional-build-args>--report-unsupported-elements-at-runtime</quarkus.native.additional-build-args> Review comment: Could you please explain why is this required? We generally do not want any `additional-build-args`. ########## File path: integration-tests/mybatis/src/main/java/org/apache/camel/quarkus/component/mybatis/it/MybatisResource.java ########## @@ -61,4 +77,44 @@ public Response loadComponentMybatisBean() throws Exception { LOG.warnf("Could not load [%s] from the Camel context", COMPONENT_MYBATIS_BEAN); return Response.status(500, COMPONENT_MYBATIS_BEAN + " could not be loaded from the Camel context").build(); } + Review comment: Could you please remove the original auto-generated test ensdpoints `loadComponentMybatis()` and `loadComponentMybatisBean()`? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org