diff --git a/webbeans-impl/src/main/java/org/apache/webbeans/corespi/scanner/AbstractMetaDataDiscovery.java b/webbeans-impl/src/main/java/org/apache/webbeans/corespi/scanner/AbstractMetaDataDiscovery.java index 3080013a5..13fe0fa9a 100644 --- a/webbeans-impl/src/main/java/org/apache/webbeans/corespi/scanner/AbstractMetaDataDiscovery.java +++ b/webbeans-impl/src/main/java/org/apache/webbeans/corespi/scanner/AbstractMetaDataDiscovery.java @@ -90,7 +90,7 @@ public abstract class AbstractMetaDataDiscovery implements BdaScannerService * We store this information since not all containers and storages do support * new URL(...). */ - private final Map beanDeploymentUrls = new HashMap<>(); + protected final Map beanDeploymentUrls = new HashMap<>(); /** * for having proper scan mode 'SCOPED' support we need to know which bean class diff --git a/webbeans-junit5/src/test/java/org/apache/openwebbeans/junit5/features/AlternativeTest.java b/webbeans-junit5/src/test/java/org/apache/openwebbeans/junit5/features/AlternativeTest.java new file mode 100644 index 000000000..f979aab56 --- /dev/null +++ b/webbeans-junit5/src/test/java/org/apache/openwebbeans/junit5/features/AlternativeTest.java @@ -0,0 +1,82 @@ +/* + * 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.openwebbeans.junit5.features; + +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.enterprise.inject.Alternative; +import jakarta.enterprise.inject.Default; +import jakarta.inject.Inject; +import org.apache.openwebbeans.junit5.Cdi; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +@Cdi(disableDiscovery = true, classes = { + AlternativeTest.Service.class, AlternativeTest.Provider.class, AlternativeTest.DefaultProvider.class, AlternativeTest.AlternativeProvider.class +}, alternatives = AlternativeTest.AlternativeProvider.class) +public class AlternativeTest +{ + @Inject + private Service service; + + @Test + void test1() + { + assertEquals("alternative", service.run()); + } + + public interface Provider + { + String provide(); + } + + @Alternative + public static class AlternativeProvider implements Provider + { + @Override + public String provide() + { + return "alternative"; + } + } + + @Default + public static class DefaultProvider implements Provider + { + @Override + public String provide() + { + return "default"; + } + } + + @ApplicationScoped + public static class Service + { + + @Inject + private Provider provider; + + public String run() + { + return provider.provide(); + } + + } +} diff --git a/webbeans-junit5/src/test/java/org/apache/openwebbeans/junit5/features/InterceptorTest.java b/webbeans-junit5/src/test/java/org/apache/openwebbeans/junit5/features/InterceptorTest.java new file mode 100644 index 000000000..0ad51310a --- /dev/null +++ b/webbeans-junit5/src/test/java/org/apache/openwebbeans/junit5/features/InterceptorTest.java @@ -0,0 +1,84 @@ +/* + * 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.openwebbeans.junit5.features; + +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.enterprise.context.NormalScope; +import jakarta.enterprise.inject.Alternative; +import jakarta.enterprise.inject.Default; +import jakarta.inject.Inject; +import jakarta.interceptor.AroundInvoke; +import jakarta.interceptor.Interceptor; +import jakarta.interceptor.InterceptorBinding; +import jakarta.interceptor.InvocationContext; +import org.apache.openwebbeans.junit5.Cdi; +import org.junit.jupiter.api.Test; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +@Cdi(disableDiscovery = true, classes = { + InterceptorTest.Service.class, InterceptorTest.MyInterceptor.class, InterceptorTest.Wrap.class +}, interceptors = InterceptorTest.MyInterceptor.class) +public class InterceptorTest +{ + @Inject + private Service service; + + @Test + void test1() + { + assertEquals("Intercepted Hello World", service.run()); + } + + @Target({ElementType.TYPE, ElementType.METHOD}) + @Retention(RetentionPolicy.RUNTIME) + @InterceptorBinding + public @interface Wrap { + + } + + @Interceptor + @Wrap + public static class MyInterceptor { + @AroundInvoke + public Object restrictAccessBasedOnTime(InvocationContext ctx) throws Exception { + final Object result = ctx.proceed(); + if (result instanceof String) { + return "Intercepted " + result; + } else { + return result; + } + } + } + + @ApplicationScoped + public static class Service + { + @Wrap + public String run() + { + return "Hello World"; + } + } +} diff --git a/webbeans-junit5/src/test/java/org/apache/openwebbeans/junit5/parameter/ParameterResolutionTest.java b/webbeans-junit5/src/test/java/org/apache/openwebbeans/junit5/parameter/ParameterResolutionTest.java index 228d91be7..fd5f01aa0 100644 --- a/webbeans-junit5/src/test/java/org/apache/openwebbeans/junit5/parameter/ParameterResolutionTest.java +++ b/webbeans-junit5/src/test/java/org/apache/openwebbeans/junit5/parameter/ParameterResolutionTest.java @@ -34,7 +34,7 @@ import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertSame; -@Cdi(classes = MyService.class) +@Cdi(classes = MyService.class, disableDiscovery = true) class ParameterResolutionTest { @Inject MyService service; diff --git a/webbeans-junit5/src/test/java/org/apache/openwebbeans/junit5/perclass/PerMethodTest.java b/webbeans-junit5/src/test/java/org/apache/openwebbeans/junit5/perclass/PerMethodTest.java index a1344917a..f38fb4cdb 100644 --- a/webbeans-junit5/src/test/java/org/apache/openwebbeans/junit5/perclass/PerMethodTest.java +++ b/webbeans-junit5/src/test/java/org/apache/openwebbeans/junit5/perclass/PerMethodTest.java @@ -184,7 +184,7 @@ public Property[] properties() @Override public boolean disableDiscovery() { - return false; + return true; } @Override diff --git a/webbeans-se/src/main/java/org/apache/openwebbeans/se/CDISeScannerService.java b/webbeans-se/src/main/java/org/apache/openwebbeans/se/CDISeScannerService.java index 9780a7820..84a95c439 100644 --- a/webbeans-se/src/main/java/org/apache/openwebbeans/se/CDISeScannerService.java +++ b/webbeans-se/src/main/java/org/apache/openwebbeans/se/CDISeScannerService.java @@ -37,6 +37,8 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Enumeration; +import java.util.HashSet; +import java.util.Set; import java.util.stream.Stream; import java.util.stream.StreamSupport; @@ -217,4 +219,17 @@ public boolean accept(String name) return accepts; } } + + @Override + public Set getBeanXmls() + { + final Set result = new HashSet<>(super.getBeanXmls()); + final URL embeddedUrl = beanDeploymentUrls.get(CDISeBeanArchiveService.EMBEDDED_URL); + if (embeddedUrl != null) + { + result.add(embeddedUrl); + } + + return result; + } }