Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, URL> beanDeploymentUrls = new HashMap<>();
protected final Map<String, URL> beanDeploymentUrls = new HashMap<>();

/**
* for having proper scan mode 'SCOPED' support we need to know which bean class
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}

}
}
Original file line number Diff line number Diff line change
@@ -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";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public Property[] properties()
@Override
public boolean disableDiscovery()
{
return false;
return true;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -217,4 +219,17 @@ public boolean accept(String name)
return accepts;
}
}

@Override
public Set<URL> getBeanXmls()
{
final Set<URL> result = new HashSet<>(super.getBeanXmls());
final URL embeddedUrl = beanDeploymentUrls.get(CDISeBeanArchiveService.EMBEDDED_URL);
if (embeddedUrl != null)
{
result.add(embeddedUrl);
}

return result;
}
}