Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ArC: fix BeanConfiguratorBase#read() #39181

Merged
merged 1 commit into from
Mar 5, 2024
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
@@ -1,10 +1,11 @@
package io.quarkus.arc.test.synthetic;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.lang.reflect.Method;
import java.util.List;
import java.util.function.Consumer;

import jakarta.enterprise.context.ApplicationScoped;
Expand All @@ -14,6 +15,7 @@
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.arc.Arc;
import io.quarkus.arc.InstanceHandle;
import io.quarkus.arc.deployment.SyntheticBeanBuildItem;
import io.quarkus.arc.deployment.SyntheticBeanBuildItem.ExtendedBeanConfigurator;
import io.quarkus.builder.BuildChainBuilder;
Expand Down Expand Up @@ -46,20 +48,31 @@ public void execute(BuildContext context) {
// We need to use reflection due to some class loading problems
Object recorderProxy = bytecodeRecorder.getRecordingProxy(TestRecorder.class);
try {
Method test = recorderProxy.getClass().getDeclaredMethod("test");
Object proxy = test.invoke(recorderProxy);
ExtendedBeanConfigurator configurator = SyntheticBeanBuildItem.configure(SynthBean.class)
Method test = recorderProxy.getClass().getDeclaredMethod("test", String.class);

Object proxy1 = test.invoke(recorderProxy, "ok");
ExtendedBeanConfigurator configurator1 = SyntheticBeanBuildItem.configure(SynthBean.class)
.scope(ApplicationScoped.class)
.identifier("ok")
.unremovable();
// No creator
assertThrows(IllegalStateException.class,
() -> configurator.done());
() -> configurator1.done());
// Not a returned proxy
assertThrows(IllegalArgumentException.class,
() -> configurator.runtimeProxy(new SynthBean()));
context.produce(configurator
.runtimeProxy(proxy)
() -> configurator1.runtimeProxy(new SynthBean()));
context.produce(configurator1
.runtimeProxy(proxy1)
.done());

// Register a synthetic bean with same types and qualifiers but different identifier
context.produce(SyntheticBeanBuildItem.configure(SynthBean.class)
.scope(ApplicationScoped.class)
.identifier("nok")
.unremovable()
.runtimeProxy(test.invoke(recorderProxy, "nok"))
.done());

} catch (Exception e) {
throw new RuntimeException(e);
}
Expand All @@ -73,19 +86,22 @@ public void execute(BuildContext context) {
@Recorder
public static class TestRecorder {

public SynthBean test() {
public SynthBean test(String val) {
SynthBean bean = new SynthBean();
bean.setValue("ok");
bean.setValue(val);
return bean;
}

}

@Test
public void testBeans() {
SynthBean bean = Arc.container().instance(SynthBean.class).get();
assertNotNull(bean);
assertEquals("ok", bean.getValue());
List<InstanceHandle<SynthBean>> beans = Arc.container().listAll(SynthBean.class);
assertEquals(2, beans.size());
for (InstanceHandle<SynthBean> handle : beans) {
String val = handle.get().getValue();
assertTrue("ok".equals(val) || "nok".equals(val));
}
}

@Vetoed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ protected BeanConfiguratorBase(DotName implClazz) {
*/
public THIS read(BeanConfiguratorBase<?, ?> base) {
super.read(base);
identifier = base.identifier;
types.clear();
types.addAll(base.types);
qualifiers.clear();
Expand Down
Loading