Skip to content

Commit

Permalink
CamelTestSupport style of testing #3511
Browse files Browse the repository at this point in the history
  • Loading branch information
JiriOndrusek committed Jun 20, 2022
1 parent c764afc commit 393ee4d
Show file tree
Hide file tree
Showing 44 changed files with 2,697 additions and 90 deletions.
6 changes: 3 additions & 3 deletions docs/antora.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ asciidoc:

min-maven-version: 3.8.2 # replace ${min-maven-version}
target-maven-version: 3.8.4 # replace ${target-maven-version}
camel-version: 3.17.0 # replace ${camel.version}
camel-docs-version: 3.17.x # replace ${camel.docs.components.version}
camel-version: 3.18.0-SNAPSHOT # replace ${camel.version}
camel-docs-version: 3.18.x # replace ${camel.docs.components.version}
quarkus-version: 2.10.0.Final # replace ${quarkus.version}
graalvm-version: 22.1.0 # replace ${graalvm.version}
graalvm-docs-version: 22.1
# attributes used in xrefs to other Antora components
cq-camel-components: 3.17.x@components # replace ${camel.docs.components.xref}
cq-camel-components: 3.18.x@components # replace ${camel.docs.components.xref}
quarkus-examples-version: latest
4 changes: 4 additions & 0 deletions extensions-core/core/deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-arc-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus.arc</groupId>
<artifactId>arc-processor</artifactId>
</dependency>

<!-- camel -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* 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.deployment;

import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.builditem.TestAnnotationBuildItem;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class CamelTestProcessor {
private static final Logger LOGGER = LoggerFactory.getLogger(CamelTestProcessor.class);
static String TEST_ANNOTATION_CLASS_NAME = "org.apache.camel.quarkus.test.CamelQuarkusTest";

@BuildStep
void produceTestAnnotationBuildItem(BuildProducer<TestAnnotationBuildItem> testAnnotationBuildItems) {
testAnnotationBuildItems.produce(new TestAnnotationBuildItem(TEST_ANNOTATION_CLASS_NAME));
}

// @BuildStep
// void annotationTransformerBuildItem(BuildProducer<AnnotationsTransformerBuildItem> annotationsTransformerBuildItems) {
// annotationsTransformerBuildItems.produce(createAnnotationTransformer(null));
// }
//
// private AnnotationsTransformerBuildItem createAnnotationTransformer(DotName className) {
// return new AnnotationsTransformerBuildItem(new AnnotationsTransformer() {
// public boolean appliesTo(org.jboss.jandex.AnnotationTarget.Kind kind) {
// return kind == AnnotationTarget.Kind.CLASS;
// }
//
// public void transform(TransformationContext context) {
//
// if (context.getAnnotations().contains(
// AnnotationInstance.create(
// DotName.createSimple(CamelQuarkusTest.class.getName()),
// context.getTarget(),
// new AnnotationValue[] {}))) {
// context.transform().add(AnnotationInstance.create(
// DotName.createSimple(TestProfile.class.getName()),
// context.getTarget(),
// new AnnotationValue[] { AnnotationValue.createClassValue("value",
// Type.create(context.getTarget().asClass().name(), Type.Kind.CLASS)) }))
// .done();
// }
// }
// });
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
public class InjectionPointsProcessor {
private static final Logger LOGGER = Logger.getLogger(InjectionPointsProcessor.class);


private static final DotName ANNOTATION_NAME_NAMED = DotName.createSimple(
Named.class.getName());
private static final DotName INTERFACE_NAME_COMPONENT = DotName.createSimple(
Expand Down Expand Up @@ -226,12 +227,16 @@ void syntheticBeans(
BuildProducer<SyntheticBeanBuildItem> syntheticBeans,
BuildProducer<NativeImageProxyDefinitionBuildItem> proxyDefinitions) {

Set<String> alreadyCreated = new HashSet<>();

for (AnnotationInstance annot : index.getIndex().getAnnotations(ENDPOINT_INJECT_ANNOTATION)) {
final AnnotationTarget target = annot.target();
switch (target.kind()) {
case FIELD: {
final FieldInfo field = target.asField();
endpointInjectBeans(recorder, syntheticBeans, index.getIndex(), annot, field.type().name());
if (!excludeTestSyntheticBeanDuplicities(annot, alreadyCreated, field.declaringClass())) {
endpointInjectBeans(recorder, syntheticBeans, index.getIndex(), annot, field.type().name());
}
break;
}
case METHOD: {
Expand All @@ -251,8 +256,10 @@ void syntheticBeans(
switch (target.kind()) {
case FIELD: {
final FieldInfo field = target.asField();
produceBeans(recorder, capabilities, syntheticBeans, proxyDefinitions, beanCapabilityAvailable,
index.getIndex(), annot, field.type().name(), field.name(), field.declaringClass().name());
if (!excludeTestSyntheticBeanDuplicities(annot, alreadyCreated, field.declaringClass())) {
produceBeans(recorder, capabilities, syntheticBeans, proxyDefinitions, beanCapabilityAvailable,
index.getIndex(), annot, field.type().name(), field.name(), field.declaringClass().name());
}
break;
}
case METHOD: {
Expand All @@ -266,6 +273,33 @@ void syntheticBeans(
}
}

private boolean excludeTestSyntheticBeanDuplicities(AnnotationInstance annot, Set<String> alreadyCreated,
ClassInfo declaringClass) {
String identifier = annot.toString(false) + ":" + getTargetClass(annot).toString();

if (declaringClass.annotations().containsKey(DotName.createSimple(CamelTestProcessor.TEST_ANNOTATION_CLASS_NAME))) {
if (alreadyCreated.contains(identifier)) {
// System.out.println(">>>>>>>>>> already exists: " + identifier);
return true;
} else {
// System.out.println(">>>>>>>>>> creating: " + identifier);
alreadyCreated.add(identifier);
}
}
return false;
}

private DotName getTargetClass(AnnotationInstance annot) {
switch (annot.target().kind()) {
case FIELD:
return annot.target().asField().type().name();
case METHOD:
return annot.target().asMethod().returnType().name();
default:
return null;
}
}

void produceBeans(CamelRecorder recorder, List<CapabilityBuildItem> capabilities,
BuildProducer<SyntheticBeanBuildItem> syntheticBeans,
BuildProducer<NativeImageProxyDefinitionBuildItem> proxyDefinitions,
Expand Down
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@
<module>integration-test-groups</module>
<module>docs</module>
<module>integration-tests-jvm</module>
<module>test-framework</module>
</modules>

<developers>
Expand Down Expand Up @@ -586,6 +587,10 @@
<path>integration-tests-support</path>
<artifactIdPrefix>camel-quarkus-integration-test-support-</artifactIdPrefix>
</extensionDir>
<extensionDir>
<path>test-framework</path>
<artifactIdPrefix>camel-quarkus-test-framework</artifactIdPrefix>
</extensionDir>
</extensionDirs>
</configuration>
</plugin>
Expand Down
Loading

0 comments on commit 393ee4d

Please sign in to comment.