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 15, 2022
1 parent 4c86d42 commit 6a0a509
Show file tree
Hide file tree
Showing 40 changed files with 2,506 additions and 87 deletions.
8 changes: 8 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 All @@ -59,6 +63,10 @@
<groupId>org.jboss.spec.javax.xml.bind</groupId>
<artifactId>jboss-jaxb-api_2.3_spec</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-junit5</artifactId>
</dependency>

<!-- test dependencies -->
<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.apache.camel.quarkus.test.CamelQuarkusTest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class CamelTestProcessor {
private static final Logger LOGGER = LoggerFactory.getLogger(CamelTestProcessor.class);

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

// @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 @@ -56,6 +56,7 @@
import org.apache.camel.quarkus.core.CamelRecorder;
import org.apache.camel.quarkus.core.InjectionPointsRecorder;
import org.apache.camel.quarkus.core.deployment.spi.CamelRuntimeTaskBuildItem;
import org.apache.camel.quarkus.test.CamelQuarkusTest;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.AnnotationTarget;
import org.jboss.jandex.AnnotationTarget.Kind;
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(CamelQuarkusTest.class.getName()))) {
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
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@
<module>integration-test-groups</module>
<module>docs</module>
<module>integration-tests-jvm</module>
<module>test-framework</module>
</modules>

<developers>
Expand Down
Loading

0 comments on commit 6a0a509

Please sign in to comment.