use of org.springframework.beans.factory.config.BeanDefinition in project spock by spockframework.
the class SpringMockTestExecutionListener method beforeTestMethod.
public void beforeTestMethod(TestContext testContext) throws Exception {
Object testInstance = testContext.getTestInstance();
if (testInstance instanceof Specification) {
Specification specification = (Specification) testInstance;
ScanScopedBeans scanScopedBeans = ReflectionUtil.getAnnotationRecursive(specification.getClass(), ScanScopedBeans.class);
Set<String> scopes = scanScopedBeans == null ? Collections.<String>emptySet() : new HashSet<String>(Arrays.asList(scanScopedBeans.value()));
ApplicationContext applicationContext = testContext.getApplicationContext();
String[] mockBeanNames = applicationContext.getBeanDefinitionNames();
List<Object> mockedBeans = new ArrayList<Object>();
for (String beanName : mockBeanNames) {
BeanDefinition beanDefinition = ((BeanDefinitionRegistry) applicationContext).getBeanDefinition(beanName);
if (beanDefinition.isAbstract()) {
continue;
}
if (beanDefinition.isSingleton() || scanScopedBean(scanScopedBeans, scopes, beanDefinition)) {
Object bean = applicationContext.getBean(beanName);
if (mockUtil.isMock(bean)) {
mockUtil.attachMock(bean, specification);
mockedBeans.add(bean);
}
}
}
testContext.setAttribute(MOCKED_BEANS_LIST, mockedBeans);
} else {
throw new IllegalArgumentException("SpringMockTestExecutionListener is only applicable for spock specifications.");
}
}
use of org.springframework.beans.factory.config.BeanDefinition in project spring-security by spring-projects.
the class ClearCredentialsMethodInvokingFactoryBean method createPortMapper.
private BeanReference createPortMapper(Element elt, ParserContext pc) {
// Register the portMapper. A default will always be created, even if no element
// exists.
BeanDefinition portMapper = new PortMappingsBeanDefinitionParser().parse(DomUtils.getChildElementByTagName(elt, Elements.PORT_MAPPINGS), pc);
String portMapperName = pc.getReaderContext().generateBeanName(portMapper);
pc.registerBeanComponent(new BeanComponentDefinition(portMapper, portMapperName));
return new RuntimeBeanReference(portMapperName);
}
use of org.springframework.beans.factory.config.BeanDefinition in project spring-security by spring-projects.
the class AuthenticationConfigBuilder method createOpenIDProvider.
private void createOpenIDProvider() {
Element openIDLoginElt = DomUtils.getChildElementByTagName(httpElt, Elements.OPENID_LOGIN);
BeanDefinitionBuilder openIDProviderBuilder = BeanDefinitionBuilder.rootBeanDefinition(OPEN_ID_AUTHENTICATION_PROVIDER_CLASS);
RootBeanDefinition uds = new RootBeanDefinition();
uds.setFactoryBeanName(BeanIds.USER_DETAILS_SERVICE_FACTORY);
uds.setFactoryMethodName("authenticationUserDetailsService");
uds.getConstructorArgumentValues().addGenericArgumentValue(openIDLoginElt.getAttribute(ATT_USER_SERVICE_REF));
openIDProviderBuilder.addPropertyValue("authenticationUserDetailsService", uds);
BeanDefinition openIDProvider = openIDProviderBuilder.getBeanDefinition();
openIDProviderRef = new RuntimeBeanReference(pc.getReaderContext().registerWithGeneratedName(openIDProvider));
}
use of org.springframework.beans.factory.config.BeanDefinition in project spring-boot by spring-projects.
the class AtomikosDependsOnBeanFactoryPostProcessorTests method assertDependsOn.
private void assertDependsOn(String bean, String... expected) {
BeanDefinition definition = this.context.getBeanDefinition(bean);
if (definition.getDependsOn() == null) {
assertThat(expected).as("No dependsOn expected for " + bean).isEmpty();
return;
}
HashSet<String> dependsOn = new HashSet<>(Arrays.asList(definition.getDependsOn()));
assertThat(dependsOn).isEqualTo(new HashSet<>(Arrays.asList(expected)));
}
use of org.springframework.beans.factory.config.BeanDefinition in project spring-framework by spring-projects.
the class RequiredAnnotationBeanPostProcessorTests method testWithRequiredPropertyOmitted.
@Test
public void testWithRequiredPropertyOmitted() {
try {
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
BeanDefinition beanDef = BeanDefinitionBuilder.genericBeanDefinition(RequiredTestBean.class).addPropertyValue("name", "Rob Harrop").addPropertyValue("favouriteColour", "Blue").addPropertyValue("jobTitle", "Grand Poobah").getBeanDefinition();
factory.registerBeanDefinition("testBean", beanDef);
factory.addBeanPostProcessor(new RequiredAnnotationBeanPostProcessor());
factory.preInstantiateSingletons();
fail("Should have thrown BeanCreationException");
} catch (BeanCreationException ex) {
String message = ex.getCause().getMessage();
assertTrue(message.contains("Property"));
assertTrue(message.contains("age"));
assertTrue(message.contains("testBean"));
}
}
Aggregations