Skip to content

Commit

Permalink
Add validation support. First iteration.
Browse files Browse the repository at this point in the history
Signed-off-by: Dmitry Aleksandrov <[email protected]>
  • Loading branch information
dalexandrov committed Nov 15, 2023
1 parent d8a7f18 commit 38c50db
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 9 deletions.
10 changes: 10 additions & 0 deletions bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -978,6 +978,16 @@
<artifactId>helidon-microprofile-testing-testng</artifactId>
<version>${helidon.version}</version>
</dependency>
<dependency>
<groupId>io.helidon.microprofile.testing</groupId>
<artifactId>helidon-microprofile-testing-common</artifactId>
<version>${helidon.version}</version>
</dependency>
<dependency>
<groupId>io.helidon.microprofile.testing</groupId>
<artifactId>helidon-microprofile-testing-jaxrs</artifactId>
<version>${helidon.version}</version>
</dependency>
<dependency>
<groupId>io.helidon.messaging.mock</groupId>
<artifactId>helidon-messaging-mock</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* 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.testing.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 class JaxRsValidator {

private JaxRsValidator() {
}

/**
* Perform validation. Runtime exception is thrown if something is wrong.
* @param testClass the annotated test class
*/
public static void validate(Class<?> testClass){
Set<String> testClassAnnotations = Arrays.stream(testClass.getDeclaredAnnotations())
.map(Annotation::annotationType)
.map(Class::getName)
.collect(Collectors.toSet());
if (testClassAnnotations.stream().anyMatch(i -> i.contains("AddJaxRs"))
&& testClassAnnotations.stream().noneMatch(i -> i.contains("DisableDiscovery"))){
throw new RuntimeException("@AddJaxRs annotation should be used only with @DisableDiscovery annotation.");
}
}
}
2 changes: 0 additions & 2 deletions microprofile/testing/jaxrs/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@
<dependency>
<groupId>io.helidon.microprofile.testing</groupId>
<artifactId>helidon-microprofile-testing-common</artifactId>
<version>4.0.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>

Expand Down
2 changes: 1 addition & 1 deletion microprofile/testing/jaxrs/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
requires io.helidon.microprofile.testing.common;
requires jakarta.inject;
requires jersey.cdi1x;
requires jersey.weld2.se;
requires org.junit.jupiter.api;

requires transitive jakarta.cdi;
requires transitive jakarta.ws.rs;
requires jersey.weld2.se;

exports io.helidon.microprofile.testing.jaxrs;

Expand Down
2 changes: 0 additions & 2 deletions microprofile/testing/junit5/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@
<dependency>
<groupId>io.helidon.microprofile.testing</groupId>
<artifactId>helidon-microprofile-testing-common</artifactId>
<version>4.0.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

import io.helidon.config.mp.MpConfigSources;
import io.helidon.config.yaml.mp.YamlMpConfigSource;
import io.helidon.microprofile.testing.common.JaxRsValidator;

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.context.Dependent;
Expand Down Expand Up @@ -134,11 +135,12 @@ public void beforeAll(ExtensionContext context) {

if (resetPerTest) {
validatePerTest();

return;
}
validatePerClass();

JaxRsValidator.validate(testClass);

configure(classLevelConfigMeta);

if (!classLevelConfigMeta.useExisting) {
Expand Down
2 changes: 0 additions & 2 deletions microprofile/testing/testng/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@
<dependency>
<groupId>io.helidon.microprofile.testing</groupId>
<artifactId>helidon-microprofile-testing-jaxrs</artifactId>
<version>4.0.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

import io.helidon.config.mp.MpConfigSources;
import io.helidon.config.yaml.mp.YamlMpConfigSource;
import io.helidon.microprofile.testing.common.JaxRsValidator;

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.context.Dependent;
Expand Down Expand Up @@ -129,6 +130,8 @@ public void onBeforeClass(ITestClass iTestClass) {
}
validatePerClass();

JaxRsValidator.validate(testClass);

configure(classLevelConfigMeta);

if (!classLevelConfigMeta.useExisting) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;

@HelidonTest
//@DisableDiscovery
@DisableDiscovery

@AddBean(TestReqScopeDisabledDiscovery.MyController.class)
@AddJaxRs
Expand Down

0 comments on commit 38c50db

Please sign in to comment.