forked from helidon-io/helidon
-
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.
JAX-RS Support for Helidon 3 testing
Signed-off-by: Dmitry Aleksandrov <dmitry.aleksandrov@oracle.com>
- Loading branch information
1 parent
400954b
commit 6c2ea0d
Showing
28 changed files
with
797 additions
and
7 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
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,44 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright (c) 2023 Oracle and/or its affiliates. | ||
Licensed 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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>io.helidon.microprofile</groupId> | ||
<artifactId>helidon-microprofile-project</artifactId> | ||
<version>3.2.4-SNAPSHOT</version> | ||
<relativePath>../../pom.xml</relativePath> | ||
</parent> | ||
|
||
<groupId>io.helidon.microprofile.tests</groupId> | ||
<artifactId>helidon-microprofile-tests-common</artifactId> | ||
<name>Common testing support</name> | ||
|
||
<description> | ||
Common testing support | ||
</description> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>jakarta.enterprise</groupId> | ||
<artifactId>jakarta.enterprise.cdi-api</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
39 changes: 39 additions & 0 deletions
39
...rofile/tests/common/src/main/java/io/helidon/microprofile/tests/common/CommonAddBean.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,39 @@ | ||
/* | ||
* Copyright (c) 2023 Oracle and/or its affiliates. | ||
* | ||
* Licensed 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 io.helidon.microprofile.tests.common; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Repeatable; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* Add a bean to other annotations. | ||
* The class will be instantiated using CDI and will be available for injection into test classes and other beans. | ||
* This annotation can be repeated. | ||
*/ | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target({ElementType.TYPE, ElementType.METHOD}) | ||
@Repeatable(CommonAddBeans.class) | ||
public @interface CommonAddBean { | ||
|
||
/** | ||
* Class of the bean. | ||
* @return the class of a bean | ||
*/ | ||
Class<?> value(); | ||
} |
35 changes: 35 additions & 0 deletions
35
...ofile/tests/common/src/main/java/io/helidon/microprofile/tests/common/CommonAddBeans.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,35 @@ | ||
/* | ||
* Copyright (c) 2023 Oracle and/or its affiliates. | ||
* | ||
* Licensed 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 io.helidon.microprofile.tests.common; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* A repeatable container for {@link CommonAddBean}. | ||
* No need to use this annotation, just repeat {@link CommonAddBean} annotation. | ||
*/ | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target({ElementType.TYPE}) | ||
public @interface CommonAddBeans { | ||
/** | ||
* Beans to be added. | ||
* @return add bean annotations | ||
*/ | ||
CommonAddBean[] value(); | ||
} |
43 changes: 43 additions & 0 deletions
43
...e/tests/common/src/main/java/io/helidon/microprofile/tests/common/CommonCdiExtension.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,43 @@ | ||
/* | ||
* Copyright (c) 2023 Oracle and/or its affiliates. | ||
* | ||
* Licensed 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 io.helidon.microprofile.tests.common; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Inherited; | ||
import java.lang.annotation.Repeatable; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
import jakarta.enterprise.inject.spi.Extension; | ||
|
||
|
||
/** | ||
* Common CDI Extension. | ||
*/ | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target({ElementType.TYPE}) | ||
@Repeatable(CommonCdiExtensions.class) | ||
@Inherited | ||
public @interface CommonCdiExtension { | ||
|
||
/** | ||
* CDI Extension. | ||
* | ||
* @return The CDI Extension Class. | ||
*/ | ||
Class<? extends Extension> value(); | ||
} |
39 changes: 39 additions & 0 deletions
39
.../tests/common/src/main/java/io/helidon/microprofile/tests/common/CommonCdiExtensions.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,39 @@ | ||
/* | ||
* Copyright (c) 2023 Oracle and/or its affiliates. | ||
* | ||
* Licensed 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 io.helidon.microprofile.tests.common; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Inherited; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
|
||
/** | ||
* Common CDI Extensions for testing. | ||
*/ | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target({ElementType.TYPE}) | ||
@Inherited | ||
public @interface CommonCdiExtensions { | ||
|
||
/** | ||
* Return CDI Extension. | ||
* | ||
* @return CDIExtension[] | ||
*/ | ||
CommonCdiExtension[] value(); | ||
} |
83 changes: 83 additions & 0 deletions
83
...ofile/tests/common/src/main/java/io/helidon/microprofile/tests/common/CommonTestUtil.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,83 @@ | ||
/* | ||
* Copyright (c) 2023 Oracle and/or its affiliates. | ||
* | ||
* Licensed 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 io.helidon.microprofile.tests.common; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import jakarta.enterprise.inject.spi.Extension; | ||
|
||
/** | ||
* Common Utility class for tests. | ||
*/ | ||
public class CommonTestUtil { | ||
|
||
private CommonTestUtil() { | ||
} | ||
|
||
/** | ||
* Extract all Extensions from the given testClass. | ||
* | ||
* @param testClass Class | ||
* @return List with Extension classes | ||
*/ | ||
public static List<Class<? extends Extension>> getFeatureExtensions(Class<?> testClass) { | ||
|
||
List<Class<? extends Extension>> result = Arrays.stream(testClass.getDeclaredAnnotations()) | ||
.flatMap(a -> Arrays.stream(a.annotationType().getDeclaredAnnotations())) | ||
.filter(a -> a instanceof CommonCdiExtension) | ||
.map(CommonCdiExtension.class::cast) | ||
.map(CommonCdiExtension::value) | ||
.collect(Collectors.toList()); | ||
|
||
result.addAll(Arrays.stream(testClass.getDeclaredAnnotations()) | ||
.flatMap(a -> Arrays.stream(a.annotationType().getDeclaredAnnotations())) | ||
.filter(a -> a instanceof CommonCdiExtensions) | ||
.map(CommonCdiExtensions.class::cast) | ||
.flatMap(e -> Arrays.stream(e.value())) | ||
.map(CommonCdiExtension::value) | ||
.collect(Collectors.toList())); | ||
|
||
return result; | ||
} | ||
|
||
/** | ||
* Extract all Beans from the given testClass. | ||
* | ||
* @param testClass Class | ||
* @return List with Beans classes | ||
*/ | ||
public static List<Class<?>> getFeatureBeans(Class<?> testClass) { | ||
|
||
ArrayList<Class<?>> result = Arrays.stream(testClass.getDeclaredAnnotations()) | ||
.flatMap(a -> Arrays.stream(a.annotationType().getDeclaredAnnotations())) | ||
.filter(a -> a instanceof CommonAddBean) | ||
.map(CommonAddBean.class::cast) | ||
.map(CommonAddBean::value).collect(Collectors.toCollection(ArrayList::new)); | ||
|
||
result.addAll(Arrays.stream(testClass.getDeclaredAnnotations()) | ||
.flatMap(a -> Arrays.stream(a.annotationType().getDeclaredAnnotations())) | ||
.filter(a -> a instanceof CommonAddBeans) | ||
.map(CommonAddBeans.class::cast) | ||
.flatMap(e -> Arrays.stream(e.value())) | ||
.map(CommonAddBean::value) | ||
.collect(Collectors.toList())); | ||
return result; | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
...ofile/tests/common/src/main/java/io/helidon/microprofile/tests/common/JaxRsValidator.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,38 @@ | ||
/* | ||
* Copyright (c) 2023 Oracle and/or its affiliates. | ||
* | ||
* Licensed 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 io.helidon.microprofile.tests.common; | ||
|
||
|
||
import java.lang.annotation.Annotation; | ||
import java.util.Arrays; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
|
||
/** | ||
* Validator for JAX-RS annotation usage. | ||
*/ | ||
public abstract class JaxRsValidator implements TestValidator { | ||
|
||
protected boolean checkAddJaxRs(Class<?> testClass){ | ||
Set<String> testClassAnnotations = Arrays.stream(testClass.getDeclaredAnnotations()) | ||
.map(Annotation::annotationType) | ||
.map(Class::getName) | ||
.collect(Collectors.toSet()); | ||
return testClassAnnotations.stream().anyMatch(i -> i.contains("AddJaxRs")); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...rofile/tests/common/src/main/java/io/helidon/microprofile/tests/common/TestValidator.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,28 @@ | ||
/* | ||
* Copyright (c) 2023 Oracle and/or its affiliates. | ||
* | ||
* Licensed 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 io.helidon.microprofile.tests.common; | ||
|
||
/** | ||
* Validator for test class. | ||
*/ | ||
public interface TestValidator { | ||
|
||
/** | ||
* Perform Validation. | ||
* @param testClass for verification. | ||
*/ | ||
void validate(Class<?> testClass) throws RuntimeException; | ||
} |
20 changes: 20 additions & 0 deletions
20
...profile/tests/common/src/main/java/io/helidon/microprofile/tests/common/package-info.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,20 @@ | ||
/* | ||
* Copyright (c) 2023 Oracle and/or its affiliates. | ||
* | ||
* Licensed 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. | ||
*/ | ||
|
||
/** | ||
* Common Testing Extensions. | ||
*/ | ||
package io.helidon.microprofile.tests.common; |
Oops, something went wrong.