Java Code Examples for org.springframework.context.support.GenericApplicationContext#registerBeanDefinition()

The following examples show how to use org.springframework.context.support.GenericApplicationContext#registerBeanDefinition() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AsyncExecutionTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void asyncMethodsWithQualifier() throws Exception {
	originalThreadName = Thread.currentThread().getName();
	GenericApplicationContext context = new GenericApplicationContext();
	context.registerBeanDefinition("asyncTest", new RootBeanDefinition(AsyncMethodWithQualifierBean.class));
	context.registerBeanDefinition("autoProxyCreator", new RootBeanDefinition(DefaultAdvisorAutoProxyCreator.class));
	context.registerBeanDefinition("asyncAdvisor", new RootBeanDefinition(AsyncAnnotationAdvisor.class));
	context.registerBeanDefinition("e0", new RootBeanDefinition(ThreadPoolTaskExecutor.class));
	context.registerBeanDefinition("e1", new RootBeanDefinition(ThreadPoolTaskExecutor.class));
	context.registerBeanDefinition("e2", new RootBeanDefinition(ThreadPoolTaskExecutor.class));
	context.refresh();

	AsyncMethodWithQualifierBean asyncTest = context.getBean("asyncTest", AsyncMethodWithQualifierBean.class);
	asyncTest.doNothing(5);
	asyncTest.doSomething(10);
	Future<String> future = asyncTest.returnSomething(20);
	assertEquals("20", future.get());
	Future<String> future2 = asyncTest.returnSomething2(30);
	assertEquals("30", future2.get());
}
 
Example 2
Source File: QualifierAnnotationAutowireContextTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void autowiredFieldDoesNotResolveWithBaseQualifierAndNonDefaultValueAndMultipleMatchingCandidates() {
	GenericApplicationContext context = new GenericApplicationContext();
	ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
	cavs1.addGenericArgumentValue("the real juergen");
	RootBeanDefinition person1 = new RootBeanDefinition(Person.class, cavs1, null);
	person1.addQualifier(new AutowireCandidateQualifier(Qualifier.class, "juergen"));
	ConstructorArgumentValues cavs2 = new ConstructorArgumentValues();
	cavs2.addGenericArgumentValue("juergen imposter");
	RootBeanDefinition person2 = new RootBeanDefinition(Person.class, cavs2, null);
	person2.addQualifier(new AutowireCandidateQualifier(Qualifier.class, "juergen"));
	context.registerBeanDefinition("juergen1", person1);
	context.registerBeanDefinition("juergen2", person2);
	context.registerBeanDefinition("autowired",
			new RootBeanDefinition(QualifiedConstructorArgumentWithBaseQualifierNonDefaultValueTestBean.class));
	AnnotationConfigUtils.registerAnnotationConfigProcessors(context);
	try {
		context.refresh();
		fail("expected BeanCreationException");
	}
	catch (BeanCreationException e) {
		assertTrue(e instanceof UnsatisfiedDependencyException);
		assertEquals("autowired", e.getBeanName());
	}
}
 
Example 3
Source File: PersistenceInjectionTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void testPublicExtendedPersistenceContextSetter() throws Exception {
	EntityManager mockEm = mock(EntityManager.class);
	given(mockEmf.createEntityManager()).willReturn(mockEm);

	GenericApplicationContext gac = new GenericApplicationContext();
	gac.getDefaultListableBeanFactory().registerSingleton("entityManagerFactory", mockEmf);
	gac.registerBeanDefinition("annotationProcessor",
			new RootBeanDefinition(PersistenceAnnotationBeanPostProcessor.class));
	gac.registerBeanDefinition(DefaultPublicPersistenceContextSetter.class.getName(),
			new RootBeanDefinition(DefaultPublicPersistenceContextSetter.class));
	gac.refresh();

	DefaultPublicPersistenceContextSetter bean = (DefaultPublicPersistenceContextSetter) gac.getBean(
			DefaultPublicPersistenceContextSetter.class.getName());
	assertNotNull(bean.em);
}
 
Example 4
Source File: ScriptFactoryPostProcessorTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void testChangeScriptWithNoRefreshableBeanFunctionality() throws Exception {
	BeanDefinition processorBeanDefinition = createScriptFactoryPostProcessor(false);
	BeanDefinition scriptedBeanDefinition = createScriptedGroovyBean();

	GenericApplicationContext ctx = new GenericApplicationContext();
	ctx.registerBeanDefinition(PROCESSOR_BEAN_NAME, processorBeanDefinition);
	ctx.registerBeanDefinition(MESSENGER_BEAN_NAME, scriptedBeanDefinition);
	ctx.refresh();

	Messenger messenger = (Messenger) ctx.getBean(MESSENGER_BEAN_NAME);
	assertEquals(MESSAGE_TEXT, messenger.getMessage());
	// cool; now let's change the script and check the refresh behaviour...
	pauseToLetRefreshDelayKickIn(DEFAULT_SECONDS_TO_PAUSE);
	StaticScriptSource source = getScriptSource(ctx);
	source.setScript(CHANGED_SCRIPT);
	Messenger refreshedMessenger = (Messenger) ctx.getBean(MESSENGER_BEAN_NAME);
	assertEquals("Script seems to have been refreshed (must not be as no refreshCheckDelay set on ScriptFactoryPostProcessor)",
			MESSAGE_TEXT, refreshedMessenger.getMessage());
}
 
Example 5
Source File: PersistenceInjectionTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void testPrivatePersistenceContextField() throws Exception {
	mockEmf = mock(EntityManagerFactory.class, withSettings().serializable());
	GenericApplicationContext gac = new GenericApplicationContext();
	gac.getDefaultListableBeanFactory().registerSingleton("entityManagerFactory", mockEmf);
	gac.registerBeanDefinition("annotationProcessor",
			new RootBeanDefinition(PersistenceAnnotationBeanPostProcessor.class));
	gac.registerBeanDefinition(DefaultPrivatePersistenceContextField.class.getName(),
			new RootBeanDefinition(DefaultPrivatePersistenceContextField.class));
	gac.registerBeanDefinition(FactoryBeanWithPersistenceContextField.class.getName(),
			new RootBeanDefinition(FactoryBeanWithPersistenceContextField.class));
	gac.refresh();

	DefaultPrivatePersistenceContextField bean = (DefaultPrivatePersistenceContextField) gac.getBean(
			DefaultPrivatePersistenceContextField.class.getName());
	FactoryBeanWithPersistenceContextField bean2 = (FactoryBeanWithPersistenceContextField) gac.getBean(
			"&" + FactoryBeanWithPersistenceContextField.class.getName());
	assertNotNull(bean.em);
	assertNotNull(bean2.em);

	assertNotNull(SerializationTestUtils.serializeAndDeserialize(bean.em));
	assertNotNull(SerializationTestUtils.serializeAndDeserialize(bean2.em));
}
 
Example 6
Source File: QualifierAnnotationAutowireContextTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void autowiredFieldResolvesWithBaseQualifierAndNonDefaultValue() {
	GenericApplicationContext context = new GenericApplicationContext();
	ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
	cavs1.addGenericArgumentValue("the real juergen");
	RootBeanDefinition person1 = new RootBeanDefinition(Person.class, cavs1, null);
	person1.addQualifier(new AutowireCandidateQualifier(Qualifier.class, "juergen"));
	ConstructorArgumentValues cavs2 = new ConstructorArgumentValues();
	cavs2.addGenericArgumentValue("juergen imposter");
	RootBeanDefinition person2 = new RootBeanDefinition(Person.class, cavs2, null);
	person2.addQualifier(new AutowireCandidateQualifier(Qualifier.class, "not really juergen"));
	context.registerBeanDefinition("juergen1", person1);
	context.registerBeanDefinition("juergen2", person2);
	context.registerBeanDefinition("autowired",
			new RootBeanDefinition(QualifiedConstructorArgumentWithBaseQualifierNonDefaultValueTestBean.class));
	AnnotationConfigUtils.registerAnnotationConfigProcessors(context);
	context.refresh();
	QualifiedConstructorArgumentWithBaseQualifierNonDefaultValueTestBean bean =
			(QualifiedConstructorArgumentWithBaseQualifierNonDefaultValueTestBean) context.getBean("autowired");
	assertEquals("the real juergen", bean.getPerson().getName());
}
 
Example 7
Source File: AsyncExecutionTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void asyncMethodsWithQualifierThroughInterface() throws Exception {
	originalThreadName = Thread.currentThread().getName();
	GenericApplicationContext context = new GenericApplicationContext();
	context.registerBeanDefinition("asyncTest", new RootBeanDefinition(SimpleAsyncMethodWithQualifierBean.class));
	context.registerBeanDefinition("autoProxyCreator", new RootBeanDefinition(DefaultAdvisorAutoProxyCreator.class));
	context.registerBeanDefinition("asyncAdvisor", new RootBeanDefinition(AsyncAnnotationAdvisor.class));
	context.registerBeanDefinition("e0", new RootBeanDefinition(ThreadPoolTaskExecutor.class));
	context.registerBeanDefinition("e1", new RootBeanDefinition(ThreadPoolTaskExecutor.class));
	context.registerBeanDefinition("e2", new RootBeanDefinition(ThreadPoolTaskExecutor.class));
	context.refresh();

	SimpleInterface asyncTest = context.getBean("asyncTest", SimpleInterface.class);
	asyncTest.doNothing(5);
	asyncTest.doSomething(10);
	Future<String> future = asyncTest.returnSomething(20);
	assertEquals("20", future.get());
	Future<String> future2 = asyncTest.returnSomething2(30);
	assertEquals("30", future2.get());
}
 
Example 8
Source File: AsyncExecutionTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void asyncMethodsWithQualifierThroughInterface() throws Exception {
	originalThreadName = Thread.currentThread().getName();
	GenericApplicationContext context = new GenericApplicationContext();
	context.registerBeanDefinition("asyncTest", new RootBeanDefinition(SimpleAsyncMethodWithQualifierBean.class));
	context.registerBeanDefinition("autoProxyCreator", new RootBeanDefinition(DefaultAdvisorAutoProxyCreator.class));
	context.registerBeanDefinition("asyncAdvisor", new RootBeanDefinition(AsyncAnnotationAdvisor.class));
	context.registerBeanDefinition("e0", new RootBeanDefinition(ThreadPoolTaskExecutor.class));
	context.registerBeanDefinition("e1", new RootBeanDefinition(ThreadPoolTaskExecutor.class));
	context.registerBeanDefinition("e2", new RootBeanDefinition(ThreadPoolTaskExecutor.class));
	context.refresh();

	SimpleInterface asyncTest = context.getBean("asyncTest", SimpleInterface.class);
	asyncTest.doNothing(5);
	asyncTest.doSomething(10);
	Future<String> future = asyncTest.returnSomething(20);
	assertEquals("20", future.get());
	Future<String> future2 = asyncTest.returnSomething2(30);
	assertEquals("30", future2.get());
}
 
Example 9
Source File: InjectAnnotationAutowireContextTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void testAutowiredFieldResolvesWithMultipleQualifierValuesAndExplicitDefaultValue() {
	GenericApplicationContext context = new GenericApplicationContext();
	ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
	cavs1.addGenericArgumentValue(JUERGEN);
	RootBeanDefinition person1 = new RootBeanDefinition(Person.class, cavs1, null);
	AutowireCandidateQualifier qualifier = new AutowireCandidateQualifier(TestQualifierWithMultipleAttributes.class);
	qualifier.setAttribute("number", 456);
	person1.addQualifier(qualifier);
	ConstructorArgumentValues cavs2 = new ConstructorArgumentValues();
	cavs2.addGenericArgumentValue(MARK);
	RootBeanDefinition person2 = new RootBeanDefinition(Person.class, cavs2, null);
	AutowireCandidateQualifier qualifier2 = new AutowireCandidateQualifier(TestQualifierWithMultipleAttributes.class);
	qualifier2.setAttribute("number", 123);
	qualifier2.setAttribute("value", "default");
	person2.addQualifier(qualifier2);
	context.registerBeanDefinition(JUERGEN, person1);
	context.registerBeanDefinition(MARK, person2);
	context.registerBeanDefinition("autowired",
			new RootBeanDefinition(QualifiedFieldWithMultipleAttributesTestBean.class));
	AnnotationConfigUtils.registerAnnotationConfigProcessors(context);
	context.refresh();
	QualifiedFieldWithMultipleAttributesTestBean bean =
			(QualifiedFieldWithMultipleAttributesTestBean) context.getBean("autowired");
	assertEquals(MARK, bean.getPerson().getName());
}
 
Example 10
Source File: PersistenceInjectionTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void testPublicSpecificExtendedPersistenceContextSetter() throws Exception {
	EntityManagerFactory mockEmf2 = mock(EntityManagerFactory.class);
	EntityManager mockEm2 = mock(EntityManager.class);
	given(mockEmf2.createEntityManager()).willReturn(mockEm2);

	GenericApplicationContext gac = new GenericApplicationContext();
	gac.getDefaultListableBeanFactory().registerSingleton("entityManagerFactory", mockEmf);
	gac.getDefaultListableBeanFactory().registerSingleton("unit2", mockEmf2);
	gac.registerBeanDefinition("annotationProcessor",
			new RootBeanDefinition(PersistenceAnnotationBeanPostProcessor.class));
	gac.registerBeanDefinition(SpecificPublicPersistenceContextSetter.class.getName(),
			new RootBeanDefinition(SpecificPublicPersistenceContextSetter.class));
	gac.refresh();

	SpecificPublicPersistenceContextSetter bean = (SpecificPublicPersistenceContextSetter) gac.getBean(
			SpecificPublicPersistenceContextSetter.class.getName());
	assertNotNull(bean.getEntityManager());
	bean.getEntityManager().flush();
	verify(mockEm2).getTransaction();
	verify(mockEm2).flush();
}
 
Example 11
Source File: PersistenceInjectionTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void testPublicPersistenceUnitSetterWithOverriding() {
	EntityManagerFactory mockEmf2 = mock(EntityManagerFactory.class);

	GenericApplicationContext gac = new GenericApplicationContext();
	gac.getDefaultListableBeanFactory().registerSingleton("entityManagerFactory", mockEmf);
	gac.registerBeanDefinition("annotationProcessor",
			new RootBeanDefinition(PersistenceAnnotationBeanPostProcessor.class));
	RootBeanDefinition bd = new RootBeanDefinition(DefaultPublicPersistenceUnitSetter.class);
	bd.getPropertyValues().add("emf", mockEmf2);
	gac.registerBeanDefinition(DefaultPublicPersistenceUnitSetter.class.getName(), bd);
	gac.refresh();

	DefaultPublicPersistenceUnitSetter bean = (DefaultPublicPersistenceUnitSetter) gac.getBean(
			DefaultPublicPersistenceUnitSetter.class.getName());
	assertSame(mockEmf2, bean.emf);
}
 
Example 12
Source File: InjectAnnotationAutowireContextTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void testAutowiredConstructorArgumentWithMultipleNonQualifiedCandidates() {
	GenericApplicationContext context = new GenericApplicationContext();
	ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
	cavs1.addGenericArgumentValue(JUERGEN);
	RootBeanDefinition person1 = new RootBeanDefinition(Person.class, cavs1, null);
	ConstructorArgumentValues cavs2 = new ConstructorArgumentValues();
	cavs2.addGenericArgumentValue(MARK);
	RootBeanDefinition person2 = new RootBeanDefinition(Person.class, cavs2, null);
	context.registerBeanDefinition(JUERGEN, person1);
	context.registerBeanDefinition(MARK, person2);
	context.registerBeanDefinition("autowired",
			new RootBeanDefinition(QualifiedConstructorArgumentTestBean.class));
	AnnotationConfigUtils.registerAnnotationConfigProcessors(context);
	try {
		context.refresh();
		fail("expected BeanCreationException");
	}
	catch (BeanCreationException e) {
		assertTrue(e instanceof UnsatisfiedDependencyException);
		assertEquals("autowired", e.getBeanName());
	}
}
 
Example 13
Source File: InjectAnnotationAutowireContextTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void testAutowiredFieldResolvesQualifiedCandidate() {
	GenericApplicationContext context = new GenericApplicationContext();
	ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
	cavs1.addGenericArgumentValue(JUERGEN);
	RootBeanDefinition person1 = new RootBeanDefinition(Person.class, cavs1, null);
	person1.addQualifier(new AutowireCandidateQualifier(TestQualifier.class));
	ConstructorArgumentValues cavs2 = new ConstructorArgumentValues();
	cavs2.addGenericArgumentValue(MARK);
	RootBeanDefinition person2 = new RootBeanDefinition(Person.class, cavs2, null);
	context.registerBeanDefinition(JUERGEN, person1);
	context.registerBeanDefinition(MARK, person2);
	context.registerBeanDefinition("autowired",
			new RootBeanDefinition(QualifiedFieldTestBean.class));
	AnnotationConfigUtils.registerAnnotationConfigProcessors(context);
	context.refresh();
	QualifiedFieldTestBean bean = (QualifiedFieldTestBean) context.getBean("autowired");
	assertEquals(JUERGEN, bean.getPerson().getName());
}
 
Example 14
Source File: InjectAnnotationAutowireContextTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void testAutowiredFieldDoesNotResolveCandidateWithDefaultValueAndConflictingValueOnBeanDefinition() {
	GenericApplicationContext context = new GenericApplicationContext();
	ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
	cavs1.addGenericArgumentValue(JUERGEN);
	RootBeanDefinition person1 = new RootBeanDefinition(Person.class, cavs1, null);
	// qualifier added, and non-default value specified
	person1.addQualifier(new AutowireCandidateQualifier(TestQualifierWithDefaultValue.class, "not the default"));
	ConstructorArgumentValues cavs2 = new ConstructorArgumentValues();
	cavs2.addGenericArgumentValue(MARK);
	RootBeanDefinition person2 = new RootBeanDefinition(Person.class, cavs2, null);
	context.registerBeanDefinition(JUERGEN, person1);
	context.registerBeanDefinition(MARK, person2);
	context.registerBeanDefinition("autowired",
			new RootBeanDefinition(QualifiedFieldWithDefaultValueTestBean.class));
	AnnotationConfigUtils.registerAnnotationConfigProcessors(context);
	try {
		context.refresh();
		fail("expected BeanCreationException");
	}
	catch (BeanCreationException e) {
		assertTrue(e.getRootCause() instanceof NoSuchBeanDefinitionException);
		assertEquals("autowired", e.getBeanName());
	}
}
 
Example 15
Source File: QualifierAnnotationAutowireContextTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void autowiredFieldDoesNotResolveCandidateWithDefaultValueAndConflictingValueOnBeanDefinition() {
	GenericApplicationContext context = new GenericApplicationContext();
	ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
	cavs1.addGenericArgumentValue(JUERGEN);
	RootBeanDefinition person1 = new RootBeanDefinition(Person.class, cavs1, null);
	// qualifier added, and non-default value specified
	person1.addQualifier(new AutowireCandidateQualifier(TestQualifierWithDefaultValue.class, "not the default"));
	ConstructorArgumentValues cavs2 = new ConstructorArgumentValues();
	cavs2.addGenericArgumentValue(MARK);
	RootBeanDefinition person2 = new RootBeanDefinition(Person.class, cavs2, null);
	context.registerBeanDefinition(JUERGEN, person1);
	context.registerBeanDefinition(MARK, person2);
	context.registerBeanDefinition("autowired",
			new RootBeanDefinition(QualifiedFieldWithDefaultValueTestBean.class));
	AnnotationConfigUtils.registerAnnotationConfigProcessors(context);
	try {
		context.refresh();
		fail("expected BeanCreationException");
	}
	catch (BeanCreationException e) {
		assertTrue(e.getRootCause() instanceof NoSuchBeanDefinitionException);
		assertEquals("autowired", e.getBeanName());
	}
}
 
Example 16
Source File: QualifierAnnotationAutowireContextTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void autowiredFieldDoesNotResolveCandidateWithDefaultValueAndConflictingValueOnBeanDefinition() {
	GenericApplicationContext context = new GenericApplicationContext();
	ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
	cavs1.addGenericArgumentValue(JUERGEN);
	RootBeanDefinition person1 = new RootBeanDefinition(Person.class, cavs1, null);
	// qualifier added, and non-default value specified
	person1.addQualifier(new AutowireCandidateQualifier(TestQualifierWithDefaultValue.class, "not the default"));
	ConstructorArgumentValues cavs2 = new ConstructorArgumentValues();
	cavs2.addGenericArgumentValue(MARK);
	RootBeanDefinition person2 = new RootBeanDefinition(Person.class, cavs2, null);
	context.registerBeanDefinition(JUERGEN, person1);
	context.registerBeanDefinition(MARK, person2);
	context.registerBeanDefinition("autowired",
			new RootBeanDefinition(QualifiedFieldWithDefaultValueTestBean.class));
	AnnotationConfigUtils.registerAnnotationConfigProcessors(context);
	try {
		context.refresh();
		fail("expected BeanCreationException");
	}
	catch (BeanCreationException e) {
		assertTrue(e.getRootCause() instanceof NoSuchBeanDefinitionException);
		assertEquals("autowired", e.getBeanName());
	}
}
 
Example 17
Source File: PersistenceInjectionTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testPrivatePersistenceUnitField() {
	GenericApplicationContext gac = new GenericApplicationContext();
	gac.getDefaultListableBeanFactory().registerSingleton("entityManagerFactory", mockEmf);
	gac.registerBeanDefinition("annotationProcessor",
			new RootBeanDefinition(PersistenceAnnotationBeanPostProcessor.class));
	gac.registerBeanDefinition(DefaultPrivatePersistenceUnitField.class.getName(),
			new RootBeanDefinition(DefaultPrivatePersistenceUnitField.class));
	gac.refresh();

	DefaultPrivatePersistenceUnitField bean = (DefaultPrivatePersistenceUnitField) gac.getBean(
			DefaultPrivatePersistenceUnitField.class.getName());
	assertSame(mockEmf, bean.emf);
}
 
Example 18
Source File: AsyncExecutionTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void asyncMethodsInInterface() throws Exception {
	originalThreadName = Thread.currentThread().getName();
	GenericApplicationContext context = new GenericApplicationContext();
	context.registerBeanDefinition("asyncTest", new RootBeanDefinition(AsyncMethodsInterfaceBean.class));
	context.registerBeanDefinition("autoProxyCreator", new RootBeanDefinition(DefaultAdvisorAutoProxyCreator.class));
	context.registerBeanDefinition("asyncAdvisor", new RootBeanDefinition(AsyncAnnotationAdvisor.class));
	context.refresh();

	AsyncMethodsInterface asyncTest = context.getBean("asyncTest", AsyncMethodsInterface.class);
	asyncTest.doNothing(5);
	asyncTest.doSomething(10);
	Future<String> future = asyncTest.returnSomething(20);
	assertEquals("20", future.get());
}
 
Example 19
Source File: LoggerBeanNamesResolverTest.java    From eclair with Apache License 2.0 5 votes vote down vote up
@Test
public void resolve() {
    // given
    String beanName = "simpleLogger";
    String emptyLoggerName = "";
    String alias = "logger";
    GenericApplicationContext applicationContext = new StaticApplicationContext();
    applicationContext.registerBeanDefinition(beanName, givenLoggerBeanDefinition());
    applicationContext.getBeanFactory().registerAlias(beanName, alias);
    // when
    Set<String> namesByBeanName = loggerBeanNamesResolver.resolve(applicationContext, beanName);
    // then
    assertThat(namesByBeanName, hasSize(3));
    assertThat(namesByBeanName, containsInAnyOrder(beanName, emptyLoggerName, alias));
}
 
Example 20
Source File: AsyncExecutionTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void asyncMethodsThroughInterface() throws Exception {
	originalThreadName = Thread.currentThread().getName();
	GenericApplicationContext context = new GenericApplicationContext();
	context.registerBeanDefinition("asyncTest", new RootBeanDefinition(SimpleAsyncMethodBean.class));
	context.registerBeanDefinition("autoProxyCreator", new RootBeanDefinition(DefaultAdvisorAutoProxyCreator.class));
	context.registerBeanDefinition("asyncAdvisor", new RootBeanDefinition(AsyncAnnotationAdvisor.class));
	context.refresh();

	SimpleInterface asyncTest = context.getBean("asyncTest", SimpleInterface.class);
	asyncTest.doNothing(5);
	asyncTest.doSomething(10);
	Future<String> future = asyncTest.returnSomething(20);
	assertEquals("20", future.get());
}