|
|
@ -1,5 +1,5 @@
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* Copyright 2012-2019 the original author or authors.
|
|
|
|
* Copyright 2012-2020 the original author or authors.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
@ -51,7 +51,7 @@ class BeanDefinitionLoaderTests {
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
void loadClass() {
|
|
|
|
void loadClass() {
|
|
|
|
BeanDefinitionLoader loader = new BeanDefinitionLoader(this.registry, MyComponent.class);
|
|
|
|
BeanDefinitionLoader loader = new BeanDefinitionLoader(this.registry, MyComponent.class);
|
|
|
|
assertThat(loader.load()).isEqualTo(1);
|
|
|
|
assertThat(load(loader)).isEqualTo(1);
|
|
|
|
assertThat(this.registry.containsBean("myComponent")).isTrue();
|
|
|
|
assertThat(this.registry.containsBean("myComponent")).isTrue();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -61,13 +61,13 @@ class BeanDefinitionLoaderTests {
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
BeanDefinitionLoader loader = new BeanDefinitionLoader(this.registry, myComponent.getClass());
|
|
|
|
BeanDefinitionLoader loader = new BeanDefinitionLoader(this.registry, myComponent.getClass());
|
|
|
|
assertThat(loader.load()).isEqualTo(0);
|
|
|
|
assertThat(load(loader)).isEqualTo(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
void loadJsr330Class() {
|
|
|
|
void loadJsr330Class() {
|
|
|
|
BeanDefinitionLoader loader = new BeanDefinitionLoader(this.registry, MyNamedComponent.class);
|
|
|
|
BeanDefinitionLoader loader = new BeanDefinitionLoader(this.registry, MyNamedComponent.class);
|
|
|
|
assertThat(loader.load()).isEqualTo(1);
|
|
|
|
assertThat(load(loader)).isEqualTo(1);
|
|
|
|
assertThat(this.registry.containsBean("myNamedComponent")).isTrue();
|
|
|
|
assertThat(this.registry.containsBean("myNamedComponent")).isTrue();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -75,7 +75,7 @@ class BeanDefinitionLoaderTests {
|
|
|
|
void loadXmlResource() {
|
|
|
|
void loadXmlResource() {
|
|
|
|
ClassPathResource resource = new ClassPathResource("sample-beans.xml", getClass());
|
|
|
|
ClassPathResource resource = new ClassPathResource("sample-beans.xml", getClass());
|
|
|
|
BeanDefinitionLoader loader = new BeanDefinitionLoader(this.registry, resource);
|
|
|
|
BeanDefinitionLoader loader = new BeanDefinitionLoader(this.registry, resource);
|
|
|
|
assertThat(loader.load()).isEqualTo(1);
|
|
|
|
assertThat(load(loader)).isEqualTo(1);
|
|
|
|
assertThat(this.registry.containsBean("myXmlComponent")).isTrue();
|
|
|
|
assertThat(this.registry.containsBean("myXmlComponent")).isTrue();
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -84,7 +84,7 @@ class BeanDefinitionLoaderTests {
|
|
|
|
void loadGroovyResource() {
|
|
|
|
void loadGroovyResource() {
|
|
|
|
ClassPathResource resource = new ClassPathResource("sample-beans.groovy", getClass());
|
|
|
|
ClassPathResource resource = new ClassPathResource("sample-beans.groovy", getClass());
|
|
|
|
BeanDefinitionLoader loader = new BeanDefinitionLoader(this.registry, resource);
|
|
|
|
BeanDefinitionLoader loader = new BeanDefinitionLoader(this.registry, resource);
|
|
|
|
assertThat(loader.load()).isEqualTo(1);
|
|
|
|
assertThat(load(loader)).isEqualTo(1);
|
|
|
|
assertThat(this.registry.containsBean("myGroovyComponent")).isTrue();
|
|
|
|
assertThat(this.registry.containsBean("myGroovyComponent")).isTrue();
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -93,7 +93,7 @@ class BeanDefinitionLoaderTests {
|
|
|
|
void loadGroovyResourceWithNamespace() {
|
|
|
|
void loadGroovyResourceWithNamespace() {
|
|
|
|
ClassPathResource resource = new ClassPathResource("sample-namespace.groovy", getClass());
|
|
|
|
ClassPathResource resource = new ClassPathResource("sample-namespace.groovy", getClass());
|
|
|
|
BeanDefinitionLoader loader = new BeanDefinitionLoader(this.registry, resource);
|
|
|
|
BeanDefinitionLoader loader = new BeanDefinitionLoader(this.registry, resource);
|
|
|
|
assertThat(loader.load()).isEqualTo(1);
|
|
|
|
assertThat(load(loader)).isEqualTo(1);
|
|
|
|
assertThat(this.registry.containsBean("myGroovyComponent")).isTrue();
|
|
|
|
assertThat(this.registry.containsBean("myGroovyComponent")).isTrue();
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -101,7 +101,7 @@ class BeanDefinitionLoaderTests {
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
void loadPackage() {
|
|
|
|
void loadPackage() {
|
|
|
|
BeanDefinitionLoader loader = new BeanDefinitionLoader(this.registry, MyComponent.class.getPackage());
|
|
|
|
BeanDefinitionLoader loader = new BeanDefinitionLoader(this.registry, MyComponent.class.getPackage());
|
|
|
|
assertThat(loader.load()).isEqualTo(2);
|
|
|
|
assertThat(load(loader)).isEqualTo(2);
|
|
|
|
assertThat(this.registry.containsBean("myComponent")).isTrue();
|
|
|
|
assertThat(this.registry.containsBean("myComponent")).isTrue();
|
|
|
|
assertThat(this.registry.containsBean("myNamedComponent")).isTrue();
|
|
|
|
assertThat(this.registry.containsBean("myNamedComponent")).isTrue();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -109,7 +109,7 @@ class BeanDefinitionLoaderTests {
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
void loadClassName() {
|
|
|
|
void loadClassName() {
|
|
|
|
BeanDefinitionLoader loader = new BeanDefinitionLoader(this.registry, MyComponent.class.getName());
|
|
|
|
BeanDefinitionLoader loader = new BeanDefinitionLoader(this.registry, MyComponent.class.getName());
|
|
|
|
assertThat(loader.load()).isEqualTo(1);
|
|
|
|
assertThat(load(loader)).isEqualTo(1);
|
|
|
|
assertThat(this.registry.containsBean("myComponent")).isTrue();
|
|
|
|
assertThat(this.registry.containsBean("myComponent")).isTrue();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -117,7 +117,7 @@ class BeanDefinitionLoaderTests {
|
|
|
|
void loadResourceName() {
|
|
|
|
void loadResourceName() {
|
|
|
|
BeanDefinitionLoader loader = new BeanDefinitionLoader(this.registry,
|
|
|
|
BeanDefinitionLoader loader = new BeanDefinitionLoader(this.registry,
|
|
|
|
"classpath:org/springframework/boot/sample-beans.xml");
|
|
|
|
"classpath:org/springframework/boot/sample-beans.xml");
|
|
|
|
assertThat(loader.load()).isEqualTo(1);
|
|
|
|
assertThat(load(loader)).isEqualTo(1);
|
|
|
|
assertThat(this.registry.containsBean("myXmlComponent")).isTrue();
|
|
|
|
assertThat(this.registry.containsBean("myXmlComponent")).isTrue();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -125,14 +125,14 @@ class BeanDefinitionLoaderTests {
|
|
|
|
void loadGroovyName() {
|
|
|
|
void loadGroovyName() {
|
|
|
|
BeanDefinitionLoader loader = new BeanDefinitionLoader(this.registry,
|
|
|
|
BeanDefinitionLoader loader = new BeanDefinitionLoader(this.registry,
|
|
|
|
"classpath:org/springframework/boot/sample-beans.groovy");
|
|
|
|
"classpath:org/springframework/boot/sample-beans.groovy");
|
|
|
|
assertThat(loader.load()).isEqualTo(1);
|
|
|
|
assertThat(load(loader)).isEqualTo(1);
|
|
|
|
assertThat(this.registry.containsBean("myGroovyComponent")).isTrue();
|
|
|
|
assertThat(this.registry.containsBean("myGroovyComponent")).isTrue();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
void loadPackageName() {
|
|
|
|
void loadPackageName() {
|
|
|
|
BeanDefinitionLoader loader = new BeanDefinitionLoader(this.registry, MyComponent.class.getPackage().getName());
|
|
|
|
BeanDefinitionLoader loader = new BeanDefinitionLoader(this.registry, MyComponent.class.getPackage().getName());
|
|
|
|
assertThat(loader.load()).isEqualTo(2);
|
|
|
|
assertThat(load(loader)).isEqualTo(2);
|
|
|
|
assertThat(this.registry.containsBean("myComponent")).isTrue();
|
|
|
|
assertThat(this.registry.containsBean("myComponent")).isTrue();
|
|
|
|
assertThat(this.registry.containsBean("myNamedComponent")).isTrue();
|
|
|
|
assertThat(this.registry.containsBean("myNamedComponent")).isTrue();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -142,7 +142,7 @@ class BeanDefinitionLoaderTests {
|
|
|
|
// See gh-6126
|
|
|
|
// See gh-6126
|
|
|
|
BeanDefinitionLoader loader = new BeanDefinitionLoader(this.registry,
|
|
|
|
BeanDefinitionLoader loader = new BeanDefinitionLoader(this.registry,
|
|
|
|
MyComponentInPackageWithoutDot.class.getPackage().getName());
|
|
|
|
MyComponentInPackageWithoutDot.class.getPackage().getName());
|
|
|
|
int loaded = loader.load();
|
|
|
|
int loaded = load(loader);
|
|
|
|
assertThat(loaded).isEqualTo(1);
|
|
|
|
assertThat(loaded).isEqualTo(1);
|
|
|
|
assertThat(this.registry.containsBean("myComponentInPackageWithoutDot")).isTrue();
|
|
|
|
assertThat(this.registry.containsBean("myComponentInPackageWithoutDot")).isTrue();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -151,9 +151,15 @@ class BeanDefinitionLoaderTests {
|
|
|
|
void loadPackageAndClassDoesNotDoubleAdd() {
|
|
|
|
void loadPackageAndClassDoesNotDoubleAdd() {
|
|
|
|
BeanDefinitionLoader loader = new BeanDefinitionLoader(this.registry, MyComponent.class.getPackage(),
|
|
|
|
BeanDefinitionLoader loader = new BeanDefinitionLoader(this.registry, MyComponent.class.getPackage(),
|
|
|
|
MyComponent.class);
|
|
|
|
MyComponent.class);
|
|
|
|
assertThat(loader.load()).isEqualTo(2);
|
|
|
|
assertThat(load(loader)).isEqualTo(2);
|
|
|
|
assertThat(this.registry.containsBean("myComponent")).isTrue();
|
|
|
|
assertThat(this.registry.containsBean("myComponent")).isTrue();
|
|
|
|
assertThat(this.registry.containsBean("myNamedComponent")).isTrue();
|
|
|
|
assertThat(this.registry.containsBean("myNamedComponent")).isTrue();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private int load(BeanDefinitionLoader loader) {
|
|
|
|
|
|
|
|
int beans = this.registry.getBeanDefinitionCount();
|
|
|
|
|
|
|
|
loader.load();
|
|
|
|
|
|
|
|
return this.registry.getBeanDefinitionCount() - beans;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|