forked from apache/camel-quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CamelTestSupport style of testing apache#3511
- Loading branch information
1 parent
4c86d42
commit 42f0630
Showing
40 changed files
with
27,062 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
...deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelTestProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
// } | ||
// } | ||
// }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
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. | ||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<groupId>org.apache.camel.quarkus</groupId> | ||
<artifactId>camel-quarkus-integration-tests-support</artifactId> | ||
<version>2.10.0-SNAPSHOT</version> | ||
<relativePath>../pom.xml</relativePath> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>camel-quarkus-integration-test-support-jvm</artifactId> | ||
<name>Camel Quarkus :: Integration Tests :: Support</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-api</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-junit5</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.assertj</groupId> | ||
<artifactId>assertj-core</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-engine</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.camel.quarkus</groupId> | ||
<artifactId>camel-quarkus-integration-test-support</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.camel.quarkus</groupId> | ||
<artifactId>camel-quarkus-core</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.camel</groupId> | ||
<artifactId>camel-test-junit5</artifactId> | ||
</dependency> | ||
</dependencies> | ||
</project> |
31 changes: 31 additions & 0 deletions
31
...port/test-support-jvm/src/main/java/org/apache/camel/quarkus/test/BeforeEachCallback.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package org.apache.camel.quarkus.test; | ||
|
||
import java.lang.reflect.Method; | ||
import java.util.Arrays; | ||
import java.util.stream.Collectors; | ||
|
||
import io.quarkus.test.junit.callback.QuarkusTestBeforeEachCallback; | ||
import io.quarkus.test.junit.callback.QuarkusTestMethodContext; | ||
import org.junit.jupiter.api.extension.ExtensionContext; | ||
import org.junit.jupiter.engine.execution.ExtensionValuesStore; | ||
import org.junit.jupiter.engine.execution.NamespaceAwareStore; | ||
|
||
public class BeforeEachCallback implements QuarkusTestBeforeEachCallback { | ||
|
||
@Override | ||
public void beforeEach(QuarkusTestMethodContext context) { | ||
CamelQuarkusTestSupport testInstance = (CamelQuarkusTestSupport) context.getTestInstance(); | ||
|
||
testInstance.setCurrentTestName(getDisplayName(context.getTestMethod())); | ||
testInstance.setGlobalStore(new NamespaceAwareStore(new ExtensionValuesStore(null), ExtensionContext.Namespace.GLOBAL)); | ||
} | ||
|
||
private String getDisplayName(Method method) { | ||
StringBuilder sb = new StringBuilder(method.getName()); | ||
sb.append("("); | ||
sb.append(Arrays.stream(method.getParameterTypes()).map(c -> c.getSimpleName()).collect(Collectors.joining(", "))); | ||
sb.append(")"); | ||
|
||
return sb.toString(); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...upport/test-support-jvm/src/main/java/org/apache/camel/quarkus/test/CamelQuarkusTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.apache.camel.quarkus.test; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
import io.quarkus.test.junit.QuarkusTest; | ||
|
||
@Target({ ElementType.TYPE, ElementType.METHOD }) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@QuarkusTest | ||
public @interface CamelQuarkusTest { | ||
} |
82 changes: 82 additions & 0 deletions
82
...test-support-jvm/src/main/java/org/apache/camel/quarkus/test/CamelQuarkusTestSupport.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package org.apache.camel.quarkus.test; | ||
|
||
import javax.inject.Inject; | ||
|
||
import io.quarkus.test.junit.QuarkusTestProfile; | ||
import org.apache.camel.CamelContext; | ||
import org.apache.camel.test.junit5.CamelTestSupport; | ||
import org.junit.jupiter.api.extension.ExtensionContext; | ||
|
||
public class CamelQuarkusTestSupport extends CamelTestSupport | ||
implements QuarkusTestProfile { | ||
|
||
private boolean initialized = false; | ||
|
||
@Inject | ||
protected CamelContext context; | ||
|
||
@Override | ||
protected CamelContext createCamelContext() throws Exception { | ||
return this.context; | ||
} | ||
|
||
@Override | ||
public void beforeAll(ExtensionContext context) { | ||
//in camel-quarkus, junit5 uses different classloader, necessaryu code was moved into quarkus's callback | ||
} | ||
|
||
@Override | ||
public void beforeEach(ExtensionContext context) throws Exception { | ||
//in camel-quarkus, junit5 uses different classloader, necessaryu code was moved into quarkus's callback | ||
} | ||
|
||
@Override | ||
public void beforeTestExecution(ExtensionContext context) throws Exception { | ||
//in camel-quarkus, junit5 uses different classloader, necessaryu code was moved into quarkus's callback | ||
} | ||
|
||
@Override | ||
public void afterAll(ExtensionContext context) { | ||
//in camel-quarkus, junit5 uses different classloader, necessaryu code was moved into quarkus's callback | ||
} | ||
|
||
@Override | ||
public void afterEach(ExtensionContext context) throws Exception { | ||
//in camel-quarkus, junit5 uses different classloader, necessaryu code was moved into quarkus's callback | ||
} | ||
|
||
@Override | ||
public void afterTestExecution(ExtensionContext context) throws Exception { | ||
//in camel-quarkus, junit5 uses different classloader, necessaryu code was moved into quarkus's callback | ||
} | ||
|
||
@Override | ||
protected void stopCamelContext() throws Exception { | ||
//context is started and stopped via quarkus lifecycle | ||
} | ||
|
||
void setCurrentTestName(String currentTestName) { | ||
this.currentTestName = currentTestName; | ||
} | ||
|
||
void setGlobalStore(ExtensionContext.Store store) { | ||
this.globalStore = store; | ||
} | ||
|
||
@Override | ||
public boolean isUseRouteBuilder() { | ||
if (context.getRoutes().isEmpty()) { | ||
return super.isUseRouteBuilder(); | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
protected void doSetUp() throws Exception { | ||
if (!initialized) { | ||
super.doSetUp(); | ||
initialized = true; | ||
|
||
} | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
.../resources/META-INF/services/io.quarkus.test.junit.callback.QuarkusTestBeforeEachCallback
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
org.apache.camel.quarkus.test.BeforeEachCallback |
Oops, something went wrong.