You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ja...@apache.org on 2023/10/18 06:28:11 UTC
[camel-quarkus] branch main updated: Support user TypeConverter as CDI beans
This is an automated email from the ASF dual-hosted git repository.
jamesnetherton pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
The following commit(s) were added to refs/heads/main by this push:
new e95d9ddfea Support user TypeConverter as CDI beans
e95d9ddfea is described below
commit e95d9ddfea848025e4799eea5277b5be02aae165
Author: James Netherton <ja...@gmail.com>
AuthorDate: Tue Oct 17 16:02:38 2023 +0100
Support user TypeConverter as CDI beans
Fixes #5429
---
.../quarkus/core/deployment/CamelProcessor.java | 13 +--
.../runtime/CamelTypeConverterCdiBeanTest.java | 98 ++++++++++++++++++++++
.../runtime/CamelTypeConverterSimpleBeanTest.java | 94 +++++++++++++++++++++
.../camel/quarkus/core/CamelContextRecorder.java | 6 +-
.../quarkus/core/FastTypeConverterInjector.java | 61 ++++++++++++++
.../core/converter/it/CdiBeanConverter.java | 35 ++++++++
.../core/converter/it/ConverterResource.java | 27 ++++--
.../core/converter/it/SimpleBeanConverter.java | 28 +++++++
...tConverters.java => StaticMethodConverter.java} | 2 +-
.../converter/it/model/MyTestPairResolver.java | 26 ++++++
.../quarkus/core/converter/it/ConverterTest.java | 20 +++--
11 files changed, 391 insertions(+), 19 deletions(-)
diff --git a/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelProcessor.java b/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelProcessor.java
index e354d2a428..d9901c29a1 100644
--- a/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelProcessor.java
+++ b/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelProcessor.java
@@ -42,11 +42,9 @@ import io.quarkus.deployment.annotations.Record;
import io.quarkus.deployment.builditem.ApplicationArchivesBuildItem;
import io.quarkus.deployment.builditem.CombinedIndexBuildItem;
import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem;
-import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import io.quarkus.maven.dependency.ArtifactKey;
import io.quarkus.runtime.RuntimeValue;
import io.smallrye.common.annotation.Identifier;
-import org.apache.camel.Converter;
import org.apache.camel.impl.converter.BaseTypeConverterRegistry;
import org.apache.camel.quarkus.core.CamelCapabilities;
import org.apache.camel.quarkus.core.CamelConfig;
@@ -107,6 +105,8 @@ class CamelProcessor {
"org.apache.camel.Producer");
private static final DotName PREDICATE_TYPE = DotName.createSimple(
"org.apache.camel.Predicate");
+ private static final DotName CONVERTER_TYPE = DotName.createSimple(
+ "org.apache.camel.Converter");
private static final Set<DotName> UNREMOVABLE_BEANS_TYPES = CamelSupport.setOf(
ROUTES_BUILDER_TYPE,
@@ -231,7 +231,7 @@ class CamelProcessor {
ApplicationArchivesBuildItem applicationArchives,
List<CamelTypeConverterLoaderBuildItem> additionalLoaders,
CombinedIndexBuildItem combinedIndex,
- BuildProducer<ReflectiveClassBuildItem> reflectiveClasses) {
+ BuildProducer<UnremovableBeanBuildItem> unremovableBean) {
IndexView index = combinedIndex.getIndex();
@@ -270,7 +270,7 @@ class CamelProcessor {
ArtifactKey artifactKey = archive.getKey();
if (artifactKey != null && "org.apache.camel".equals(artifactKey.getGroupId())
&& artifactKey.getArtifactId().startsWith("camel-")) {
- internalConverters.addAll(archive.getIndex().getAnnotations(DotName.createSimple(Converter.class.getName()))
+ internalConverters.addAll(archive.getIndex().getAnnotations(CONVERTER_TYPE)
.stream().filter(a -> a.target().kind() == AnnotationTarget.Kind.CLASS)
.map(a -> a.target().asClass().name().toString())
.collect(Collectors.toSet()));
@@ -278,7 +278,7 @@ class CamelProcessor {
}
Set<Class<?>> convertersClasses = index
- .getAnnotations(DotName.createSimple(Converter.class.getName()))
+ .getAnnotations(CONVERTER_TYPE)
.stream().filter(a -> a.target().kind() == AnnotationTarget.Kind.CLASS &&
(a.value("generateBulkLoader") == null || !a.value("generateBulkLoader").asBoolean()) &&
(a.value("generateLoader") == null || !a.value("generateLoader").asBoolean()))
@@ -289,6 +289,9 @@ class CamelProcessor {
recorder.loadAnnotatedConverters(typeConverterRegistry, convertersClasses);
+ // Enable @Converter annotated classes to be CDI beans
+ unremovableBean.produce(UnremovableBeanBuildItem.beanClassAnnotation(CONVERTER_TYPE));
+
//
// User can register loaders by providing a CamelTypeConverterLoaderBuildItem that can be used to
// provide additional TypeConverter or override default converters discovered by the previous step.
diff --git a/extensions-core/core/deployment/src/test/java/org/apache/camel/quarkus/core/runtime/CamelTypeConverterCdiBeanTest.java b/extensions-core/core/deployment/src/test/java/org/apache/camel/quarkus/core/runtime/CamelTypeConverterCdiBeanTest.java
new file mode 100644
index 0000000000..c61098d21b
--- /dev/null
+++ b/extensions-core/core/deployment/src/test/java/org/apache/camel/quarkus/core/runtime/CamelTypeConverterCdiBeanTest.java
@@ -0,0 +1,98 @@
+/*
+ * 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.core.runtime;
+
+import io.quarkus.test.QuarkusUnitTest;
+import jakarta.enterprise.context.ApplicationScoped;
+import jakarta.inject.Inject;
+import org.apache.camel.CamelContext;
+import org.apache.camel.Converter;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+public class CamelTypeConverterCdiBeanTest {
+
+ @RegisterExtension
+ static final QuarkusUnitTest CONFIG = new QuarkusUnitTest()
+ .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class)
+ .addClasses(Car.class, Bike.class, CarToBikeMapper.class));
+
+ @Inject
+ CamelContext context;
+
+ @Test
+ public void testTypeConverterAsCdiBean() {
+ String model = "Test";
+
+ Car car = new Car();
+ car.setModel(model);
+
+ Bike bike = context.getTypeConverter().tryConvertTo(Bike.class, car);
+ assertNotNull(bike);
+ assertEquals(model, bike.getMake());
+ }
+
+ @ApplicationScoped
+ @Converter
+ public static final class CarToBikeConverter {
+ @Inject
+ CarToBikeMapper mapper;
+
+ @Converter
+ public Bike carToBike(Car car) {
+ return mapper.mapCarToBike(car);
+ }
+ }
+
+ @ApplicationScoped
+ public static final class CarToBikeMapper {
+ public Bike mapCarToBike(Car car) {
+ Bike bike = new Bike();
+ bike.setMake(car.getModel());
+ return bike;
+ }
+ }
+
+ public static final class Car {
+ private String model;
+
+ public String getModel() {
+ return model;
+ }
+
+ public void setModel(String model) {
+ this.model = model;
+ }
+ }
+
+ static final class Bike {
+ private String make;
+
+ public String getMake() {
+ return make;
+ }
+
+ public void setMake(String make) {
+ this.make = make;
+ }
+ }
+}
diff --git a/extensions-core/core/deployment/src/test/java/org/apache/camel/quarkus/core/runtime/CamelTypeConverterSimpleBeanTest.java b/extensions-core/core/deployment/src/test/java/org/apache/camel/quarkus/core/runtime/CamelTypeConverterSimpleBeanTest.java
new file mode 100644
index 0000000000..ea40525cf2
--- /dev/null
+++ b/extensions-core/core/deployment/src/test/java/org/apache/camel/quarkus/core/runtime/CamelTypeConverterSimpleBeanTest.java
@@ -0,0 +1,94 @@
+/*
+ * 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.core.runtime;
+
+import io.quarkus.test.QuarkusUnitTest;
+import jakarta.inject.Inject;
+import org.apache.camel.CamelContext;
+import org.apache.camel.Converter;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+public class CamelTypeConverterSimpleBeanTest {
+
+ @RegisterExtension
+ static final QuarkusUnitTest CONFIG = new QuarkusUnitTest()
+ .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class)
+ .addClasses(Car.class, Bike.class, CarToBikeMapper.class));
+
+ @Inject
+ CamelContext context;
+
+ @Test
+ public void testTypeConverterAsSimpleBean() {
+ String model = "Test";
+
+ Car car = new Car();
+ car.setModel(model);
+
+ Bike bike = context.getTypeConverter().tryConvertTo(Bike.class, car);
+ assertNotNull(bike);
+ assertEquals(model, bike.getMake());
+ }
+
+ @Converter
+ public static final class CarToBikeConverter {
+ CarToBikeMapper mapper = new CarToBikeMapper();
+
+ @Converter
+ public Bike carToBike(Car car) {
+ return mapper.mapCarToBike(car);
+ }
+ }
+
+ public static final class CarToBikeMapper {
+ public Bike mapCarToBike(Car car) {
+ Bike bike = new Bike();
+ bike.setMake(car.getModel());
+ return bike;
+ }
+ }
+
+ public static final class Car {
+ private String model;
+
+ public String getModel() {
+ return model;
+ }
+
+ public void setModel(String model) {
+ this.model = model;
+ }
+ }
+
+ static final class Bike {
+ private String make;
+
+ public String getMake() {
+ return make;
+ }
+
+ public void setMake(String make) {
+ this.make = make;
+ }
+ }
+}
diff --git a/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelContextRecorder.java b/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelContextRecorder.java
index 78eb10685b..fd5ca69990 100644
--- a/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelContextRecorder.java
+++ b/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelContextRecorder.java
@@ -69,8 +69,12 @@ public class CamelContextRecorder {
extendedCamelContext.addContextPlugin(FactoryFinderResolver.class, factoryFinderResolver.getValue());
extendedCamelContext.addContextPlugin(RuntimeCamelCatalog.class, new CamelRuntimeCatalog(config.runtimeCatalog));
extendedCamelContext.setRegistry(registry.getValue());
- context.setTypeConverterRegistry(typeConverterRegistry.getValue());
+
+ TypeConverterRegistry typeConverterRegistryValue = typeConverterRegistry.getValue();
+ typeConverterRegistryValue.setInjector(new FastTypeConverterInjector(context));
+ context.setTypeConverterRegistry(typeConverterRegistryValue);
context.setLoadTypeConverters(false);
+
extendedCamelContext.addContextPlugin(ModelJAXBContextFactory.class, contextFactory.getValue());
extendedCamelContext.addContextPlugin(PackageScanClassResolver.class, packageScanClassResolver.getValue());
context.build();
diff --git a/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/FastTypeConverterInjector.java b/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/FastTypeConverterInjector.java
new file mode 100644
index 0000000000..b3412309f4
--- /dev/null
+++ b/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/FastTypeConverterInjector.java
@@ -0,0 +1,61 @@
+/*
+ * 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.core;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.CamelContextAware;
+import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.impl.engine.DefaultInjector;
+import org.apache.camel.spi.CamelBeanPostProcessor;
+import org.apache.camel.support.CamelContextHelper;
+import org.apache.camel.support.ObjectHelper;
+import org.apache.camel.support.PluginHelper;
+
+/**
+ * An {@link org.apache.camel.spi.Injector} that can delegate TypeConverter instance resolution to Arc.
+ */
+public class FastTypeConverterInjector extends DefaultInjector {
+ private final CamelContext context;
+ private final CamelBeanPostProcessor postProcessor;
+
+ public FastTypeConverterInjector(CamelContext context) {
+ super(context);
+ this.context = context;
+ this.postProcessor = PluginHelper.getBeanPostProcessor(context);
+ }
+
+ @Override
+ public <T> T newInstance(Class<T> type, boolean postProcessBean) {
+ // Try TypeConverter discovery from the Camel registry / Arc container
+ T typeConverter = CamelContextHelper.findSingleByType(context, type);
+ if (typeConverter == null) {
+ // Fallback to the default injector behavior
+ typeConverter = ObjectHelper.newInstance(type);
+ }
+
+ CamelContextAware.trySetCamelContext(typeConverter, context);
+ if (postProcessBean) {
+ try {
+ postProcessor.postProcessBeforeInitialization(typeConverter, typeConverter.getClass().getName());
+ postProcessor.postProcessAfterInitialization(typeConverter, typeConverter.getClass().getName());
+ } catch (Exception e) {
+ throw new RuntimeCamelException("Error during post processing of bean: " + typeConverter, e);
+ }
+ }
+ return typeConverter;
+ }
+}
diff --git a/integration-test-groups/foundation/type-converter/src/main/java/org/apache/camel/quarkus/core/converter/it/CdiBeanConverter.java b/integration-test-groups/foundation/type-converter/src/main/java/org/apache/camel/quarkus/core/converter/it/CdiBeanConverter.java
new file mode 100644
index 0000000000..10db63e785
--- /dev/null
+++ b/integration-test-groups/foundation/type-converter/src/main/java/org/apache/camel/quarkus/core/converter/it/CdiBeanConverter.java
@@ -0,0 +1,35 @@
+/*
+ * 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.core.converter.it;
+
+import jakarta.enterprise.context.ApplicationScoped;
+import jakarta.inject.Inject;
+import org.apache.camel.Converter;
+import org.apache.camel.quarkus.core.converter.it.model.MyTestPair;
+import org.apache.camel.quarkus.core.converter.it.model.MyTestPairResolver;
+
+@ApplicationScoped
+@Converter
+public class CdiBeanConverter {
+ @Inject
+ MyTestPairResolver resolver;
+
+ @Converter
+ public MyTestPair toMyPair(Integer i) {
+ return resolver.resolve(i);
+ }
+}
diff --git a/integration-test-groups/foundation/type-converter/src/main/java/org/apache/camel/quarkus/core/converter/it/ConverterResource.java b/integration-test-groups/foundation/type-converter/src/main/java/org/apache/camel/quarkus/core/converter/it/ConverterResource.java
index d6c19940eb..37f2bbe96e 100644
--- a/integration-test-groups/foundation/type-converter/src/main/java/org/apache/camel/quarkus/core/converter/it/ConverterResource.java
+++ b/integration-test-groups/foundation/type-converter/src/main/java/org/apache/camel/quarkus/core/converter/it/ConverterResource.java
@@ -36,32 +36,45 @@ import org.apache.camel.quarkus.it.support.typeconverter.pairs.MyBulk1Pair;
import org.apache.camel.quarkus.it.support.typeconverter.pairs.MyBulk2Pair;
import org.apache.camel.quarkus.it.support.typeconverter.pairs.MyLoaderPair;
import org.apache.camel.quarkus.it.support.typeconverter.pairs.MyRegistryPair;
-import org.apache.camel.spi.Registry;
import org.apache.camel.support.DefaultExchange;
import org.apache.camel.util.CollectionHelper;
@Path("/converter")
@ApplicationScoped
public class ConverterResource {
- @Inject
- Registry registry;
@Inject
CamelContext context;
@Path("/myRegistryPair")
@POST
@Produces(MediaType.APPLICATION_JSON)
- public MyRegistryPair converterMyRegistrPair(String input) {
+ public MyRegistryPair converterMyRegistryPair(String input) {
return context.getTypeConverter().convertTo(MyRegistryPair.class, input);
}
- @Path("/myTestPair")
+ @Path("/myTestPair/string")
@POST
@Produces(MediaType.APPLICATION_JSON)
public MyTestPair fromStringToMyTestPair(String input) {
return context.getTypeConverter().convertTo(MyTestPair.class, input);
}
+ @Path("/myTestPair/int")
+ @POST
+ @Produces(MediaType.APPLICATION_JSON)
+ public MyTestPair fromIntToMyTestPair(String input) {
+ Integer valueToConvert = Integer.valueOf(input);
+ return context.getTypeConverter().convertTo(MyTestPair.class, valueToConvert);
+ }
+
+ @Path("/myTestPair/float")
+ @POST
+ @Produces(MediaType.APPLICATION_JSON)
+ public MyTestPair fromFloatToMyTestPair(String input) {
+ Float valueToConvert = Float.valueOf(input);
+ return context.getTypeConverter().convertTo(MyTestPair.class, valueToConvert);
+ }
+
@Path("/myLoaderPair")
@POST
@Produces(MediaType.APPLICATION_JSON)
@@ -93,7 +106,7 @@ public class ConverterResource {
@Path("/setStatisticsEnabled")
@POST
@Produces(MediaType.TEXT_PLAIN)
- public void cnverterSetStatisticsEnabled(boolean value) {
+ public void converterSetStatisticsEnabled(boolean value) {
context.getTypeConverterRegistry().getStatistics().setStatisticsEnabled(value);
if (value) {
context.getTypeConverterRegistry().getStatistics().reset();
@@ -122,7 +135,7 @@ public class ConverterResource {
@Produces(MediaType.APPLICATION_JSON)
public MyExchangePair convertMyExchangePair(String input, @QueryParam("converterValue") String converterValue) {
Exchange e = new DefaultExchange(context);
- e.setProperty(TestConverters.CONVERTER_VALUE, converterValue);
+ e.setProperty(StaticMethodConverter.CONVERTER_VALUE, converterValue);
return context.getTypeConverter().convertTo(MyExchangePair.class, e, input);
}
diff --git a/integration-test-groups/foundation/type-converter/src/main/java/org/apache/camel/quarkus/core/converter/it/SimpleBeanConverter.java b/integration-test-groups/foundation/type-converter/src/main/java/org/apache/camel/quarkus/core/converter/it/SimpleBeanConverter.java
new file mode 100644
index 0000000000..5b436c7219
--- /dev/null
+++ b/integration-test-groups/foundation/type-converter/src/main/java/org/apache/camel/quarkus/core/converter/it/SimpleBeanConverter.java
@@ -0,0 +1,28 @@
+/*
+ * 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.core.converter.it;
+
+import org.apache.camel.Converter;
+import org.apache.camel.quarkus.core.converter.it.model.MyTestPair;
+
+@Converter
+public class SimpleBeanConverter {
+ @Converter
+ public MyTestPair toMyPair(Float f) {
+ return new MyTestPair(f + ":3.0");
+ }
+}
diff --git a/integration-test-groups/foundation/type-converter/src/main/java/org/apache/camel/quarkus/core/converter/it/TestConverters.java b/integration-test-groups/foundation/type-converter/src/main/java/org/apache/camel/quarkus/core/converter/it/StaticMethodConverter.java
similarity index 98%
rename from integration-test-groups/foundation/type-converter/src/main/java/org/apache/camel/quarkus/core/converter/it/TestConverters.java
rename to integration-test-groups/foundation/type-converter/src/main/java/org/apache/camel/quarkus/core/converter/it/StaticMethodConverter.java
index b477124b31..e03d2034a9 100644
--- a/integration-test-groups/foundation/type-converter/src/main/java/org/apache/camel/quarkus/core/converter/it/TestConverters.java
+++ b/integration-test-groups/foundation/type-converter/src/main/java/org/apache/camel/quarkus/core/converter/it/StaticMethodConverter.java
@@ -25,7 +25,7 @@ import org.apache.camel.quarkus.core.converter.it.model.MyTestPair;
import org.apache.camel.spi.TypeConverterRegistry;
@Converter
-public class TestConverters {
+public class StaticMethodConverter {
public static final String CONVERTER_VALUE = "converter_value";
diff --git a/integration-test-groups/foundation/type-converter/src/main/java/org/apache/camel/quarkus/core/converter/it/model/MyTestPairResolver.java b/integration-test-groups/foundation/type-converter/src/main/java/org/apache/camel/quarkus/core/converter/it/model/MyTestPairResolver.java
new file mode 100644
index 0000000000..edfc0727e3
--- /dev/null
+++ b/integration-test-groups/foundation/type-converter/src/main/java/org/apache/camel/quarkus/core/converter/it/model/MyTestPairResolver.java
@@ -0,0 +1,26 @@
+/*
+ * 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.core.converter.it.model;
+
+import jakarta.enterprise.context.ApplicationScoped;
+
+@ApplicationScoped
+public class MyTestPairResolver {
+ public MyTestPair resolve(Integer i) {
+ return new MyTestPair(i + ":2");
+ }
+}
diff --git a/integration-test-groups/foundation/type-converter/src/test/java/org/apache/camel/quarkus/core/converter/it/ConverterTest.java b/integration-test-groups/foundation/type-converter/src/test/java/org/apache/camel/quarkus/core/converter/it/ConverterTest.java
index d7d3c3edf1..7a77063504 100644
--- a/integration-test-groups/foundation/type-converter/src/test/java/org/apache/camel/quarkus/core/converter/it/ConverterTest.java
+++ b/integration-test-groups/foundation/type-converter/src/test/java/org/apache/camel/quarkus/core/converter/it/ConverterTest.java
@@ -35,9 +35,19 @@ public class ConverterTest {
}
@Test
- void testConverterFromAnnotation() {
+ void testConverterFromAnnotationWithStaticMethods() {
//converter with annotation present in this module
- testConverter("/converter/myTestPair", "a:b", "test_a", "b");
+ testConverter("/converter/myTestPair/string", "a:b", "test_a", "b");
+ }
+
+ @Test
+ void testConverterFromAnnotationWithNonStaticMethods() {
+ testConverter("/converter/myTestPair/int", "1", "test_1", "2");
+ }
+
+ @Test
+ void testConverterFromAnnotationAsCdiBean() {
+ testConverter("/converter/myTestPair/float", "2.0", "test_2.0", "3.0");
}
@Test
@@ -90,7 +100,7 @@ public class ConverterTest {
enableStatistics(true);
//cause 1 hit
- testConverterFromAnnotation();
+ testConverterFromAnnotationWithStaticMethods();
RestAssured.when().get("/converter/getStatisticsHit").then().body("hit", is(1), "miss", is(0));
@@ -113,13 +123,13 @@ public class ConverterTest {
testConverter(url, body, 200, expectedKey, expectedValue);
}
- private void testConverter(String url, String body, int expectedResutCode, String expectedKey, String expectedValue) {
+ private void testConverter(String url, String body, int expectedResultCode, String expectedKey, String expectedValue) {
ValidatableResponse response = RestAssured.given()
.contentType(ContentType.TEXT).body(body)
.accept(MediaType.APPLICATION_JSON)
.post(url)
.then()
- .statusCode(expectedResutCode);
+ .statusCode(expectedResultCode);
if (expectedKey != null) {
response.body("key", is(expectedKey), "val", is(expectedValue));