Skip to content
Open
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 @@ -17,6 +17,7 @@
package org.apache.dubbo.common.extension;

import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.beans.factory.ScopeBeanFactory;
import org.apache.dubbo.common.convert.Converter;
import org.apache.dubbo.common.convert.StringToBooleanConverter;
import org.apache.dubbo.common.convert.StringToDoubleConverter;
Expand Down Expand Up @@ -666,10 +667,16 @@ void testLoadDefaultActivateExtension2() {

@Test
void testInjectExtension() {
// register bean for test ScopeBeanExtensionInjector
DemoImpl demoBean = new DemoImpl();
ApplicationModel.defaultModel().getBeanFactory().registerBean(demoBean);
// test default
// Work with the shared factory, but make registration idempotent.
ScopeBeanFactory beanFactory = ApplicationModel.defaultModel().getBeanFactory();
if (beanFactory.getBeansOfType(Demo.class).isEmpty()) {
beanFactory.registerBean("demo-test-singleton", new DemoImpl());
}
// After the (potential) registration, fetch the canonical DemoImpl(s).
List<DemoImpl> impls = beanFactory.getBeansOfType(DemoImpl.class);
DemoImpl demoBean = impls.get(0);

// Exercise injection path
InjectExt injectExt = getExtensionLoader(InjectExt.class).getExtension("injection");
InjectExtImpl injectExtImpl = (InjectExtImpl) injectExt;
Assertions.assertNotNull(injectExtImpl.getSimpleExt());
Expand All @@ -691,6 +698,13 @@ void testMultiNames() {

@Test
void testGetOrDefaultExtension() {
// Ensure there is exactly one DemoImpl available to satisfy injection paths.
ScopeBeanFactory beanFactory = ApplicationModel.defaultModel().getBeanFactory();
List<DemoImpl> demos = beanFactory.getBeansOfType(DemoImpl.class);
if (demos == null || demos.isEmpty()) {
beanFactory.registerBean("test-demo-bean", new DemoImpl());
}

ExtensionLoader<InjectExt> loader = getExtensionLoader(InjectExt.class);
InjectExt injectExt = loader.getOrDefaultExtension("non-exists");
assertEquals(InjectExtImpl.class, injectExt.getClass());
Expand Down
Loading