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 21, 2022
1 parent 1dea37e commit c0828a0
Show file tree
Hide file tree
Showing 44 changed files with 2,779 additions and 87 deletions.
6 changes: 6 additions & 0 deletions docs/modules/ROOT/pages/reference/extensions/yaml-dsl.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@

An YAML stack for parsing YAML route definitions

== What's inside

* xref:{cq-camel-components}:others:yaml-dsl.adoc[YAML DSL]

Please refer to the above link for usage and configuration details.

== Maven coordinates

https://code.quarkus.io/?extension-search=camel-quarkus-yaml-dsl[Create a new project with this extension on code.quarkus.io, window="_blank"]
Expand Down
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 @@ -226,12 +226,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 +255,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 +272,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 c0828a0

Please sign in to comment.