org.springframework.context.event.test.AnotherTestEvent Java Examples

The following examples show how to use org.springframework.context.event.test.AnotherTestEvent. 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: AnnotationDrivenEventListenerTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@EventListener
public Object handle(AnotherTestEvent event) {
	collectEvent(event);
	if (event.content == null) {
		return null;
	}
	else if (event.content instanceof String) {
		String s = (String) event.content;
		if (s.equals("String")) {
			return event.content;
		}
		else {
			return new TestEvent(this, event.getId(), s);
		}
	}
	return event.content;
}
 
Example #2
Source File: AnnotationDrivenEventListenerTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void collectionReply() {
	load(TestEventListener.class, ReplyEventListener.class);
	Set<Object> replies = new LinkedHashSet<>();
	replies.add("first");
	replies.add(4L);
	replies.add("third");
	AnotherTestEvent event = new AnotherTestEvent(this, replies);
	ReplyEventListener replyEventListener = this.context.getBean(ReplyEventListener.class);
	TestEventListener listener = this.context.getBean(TestEventListener.class);

	this.eventCollector.assertNoEventReceived(listener);
	this.eventCollector.assertNoEventReceived(replyEventListener);
	this.context.publishEvent(event);
	this.eventCollector.assertEvent(replyEventListener, event);
	this.eventCollector.assertEvent(listener, "first", "third"); // reply (no listener for 4L)
	this.eventCollector.assertTotalEventsCount(3);
}
 
Example #3
Source File: AnnotationDrivenEventListenerTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@EventListener
public Object handle(AnotherTestEvent event) {
	collectEvent(event);
	if (event.content == null) {
		return null;
	}
	else if (event.content instanceof String) {
		String s = (String) event.content;
		if (s.equals("String")) {
			return event.content;
		}
		else {
			return new TestEvent(this, event.getId(), s);
		}
	}
	return event.content;
}
 
Example #4
Source File: AnnotationDrivenEventListenerTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void collectionReply() {
	load(TestEventListener.class, ReplyEventListener.class);
	Set<Object> replies = new LinkedHashSet<>();
	replies.add("first");
	replies.add(4L);
	replies.add("third");
	AnotherTestEvent event = new AnotherTestEvent(this, replies);
	ReplyEventListener replyEventListener = this.context.getBean(ReplyEventListener.class);
	TestEventListener listener = this.context.getBean(TestEventListener.class);

	this.eventCollector.assertNoEventReceived(listener);
	this.eventCollector.assertNoEventReceived(replyEventListener);
	this.context.publishEvent(event);
	this.eventCollector.assertEvent(replyEventListener, event);
	this.eventCollector.assertEvent(listener, "first", "third"); // reply (no listener for 4L)
	this.eventCollector.assertTotalEventsCount(3);
}
 
Example #5
Source File: AnnotationDrivenEventListenerTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@EventListener
public Object handle(AnotherTestEvent event) {
	collectEvent(event);
	if (event.content == null) {
		return null;
	}
	else if (event.content instanceof String) {
		String s = (String) event.content;
		if (s.equals("String")) {
			return event.content;
		}
		else {
			return new TestEvent(this, event.getId(), s);
		}
	}
	return event.content;
}
 
Example #6
Source File: AnnotationDrivenEventListenerTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void collectionReply() {
	load(TestEventListener.class, ReplyEventListener.class);
	Set<Object> replies = new LinkedHashSet<>();
	replies.add("first");
	replies.add(4L);
	replies.add("third");
	AnotherTestEvent event = new AnotherTestEvent(this, replies);
	ReplyEventListener replyEventListener = this.context.getBean(ReplyEventListener.class);
	TestEventListener listener = this.context.getBean(TestEventListener.class);

	this.eventCollector.assertNoEventReceived(listener);
	this.eventCollector.assertNoEventReceived(replyEventListener);
	this.context.publishEvent(event);
	this.eventCollector.assertEvent(replyEventListener, event);
	this.eventCollector.assertEvent(listener, "first", "third"); // reply (no listener for 4L)
	this.eventCollector.assertTotalEventsCount(3);
}
 
Example #7
Source File: AnnotationDrivenEventListenerTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void asyncProcessingApplied() throws InterruptedException {
	loadAsync(AsyncEventListener.class);

	String threadName = Thread.currentThread().getName();
	AnotherTestEvent event = new AnotherTestEvent(this, threadName);
	AsyncEventListener listener = this.context.getBean(AsyncEventListener.class);
	this.eventCollector.assertNoEventReceived(listener);

	this.context.publishEvent(event);
	countDownLatch.await(2, TimeUnit.SECONDS);
	this.eventCollector.assertEvent(listener, event);
	this.eventCollector.assertTotalEventsCount(1);
}
 
Example #8
Source File: AnnotationDrivenEventListenerTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void replyWithPayload() {
	load(TestEventListener.class, ReplyEventListener.class);
	AnotherTestEvent event = new AnotherTestEvent(this, "String");
	ReplyEventListener replyEventListener = this.context.getBean(ReplyEventListener.class);
	TestEventListener listener = this.context.getBean(TestEventListener.class);


	this.eventCollector.assertNoEventReceived(listener);
	this.eventCollector.assertNoEventReceived(replyEventListener);
	this.context.publishEvent(event);
	this.eventCollector.assertEvent(replyEventListener, event);
	this.eventCollector.assertEvent(listener, "String"); // reply
	this.eventCollector.assertTotalEventsCount(2);
}
 
Example #9
Source File: AnnotationDrivenEventListenerTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@EventListener
@Async
public void handleAsync(AnotherTestEvent event) {
	collectEvent(event);
	if ("fail".equals(event.content)) {
		this.countDownLatch.countDown();
		throw new IllegalStateException("Test exception");
	}
}
 
Example #10
Source File: AnnotationDrivenEventListenerTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@EventListener
@Async
public void handleAsync(AnotherTestEvent event) {
	assertTrue(!Thread.currentThread().getName().equals(event.content));
	collectEvent(event);
	this.countDownLatch.countDown();
}
 
Example #11
Source File: AnnotationDrivenEventListenerTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@EventListener
@Async
public void handleAsync(AnotherTestEvent event) {
	assertTrue(!Thread.currentThread().getName().equals(event.content));
	this.eventCollector.addEvent(this, event);
	this.countDownLatch.countDown();
}
 
Example #12
Source File: AnnotationDrivenEventListenerTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@EventListener
@Async
public void handleAsync(AnotherTestEvent event) {
	assertTrue(!Thread.currentThread().getName().equals(event.content));
	this.eventCollector.addEvent(this, event);
	this.countDownLatch.countDown();
}
 
Example #13
Source File: AnnotationDrivenEventListenerTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void simpleReply() {
	load(TestEventListener.class, ReplyEventListener.class);
	AnotherTestEvent event = new AnotherTestEvent(this, "dummy");
	ReplyEventListener replyEventListener = this.context.getBean(ReplyEventListener.class);
	TestEventListener listener = this.context.getBean(TestEventListener.class);


	this.eventCollector.assertNoEventReceived(listener);
	this.eventCollector.assertNoEventReceived(replyEventListener);
	this.context.publishEvent(event);
	this.eventCollector.assertEvent(replyEventListener, event);
	this.eventCollector.assertEvent(listener, new TestEvent(replyEventListener, event.getId(), "dummy")); // reply
	this.eventCollector.assertTotalEventsCount(2);
}
 
Example #14
Source File: AnnotationDrivenEventListenerTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void nullReplyIgnored() {
	load(TestEventListener.class, ReplyEventListener.class);
	AnotherTestEvent event = new AnotherTestEvent(this, null); // No response
	ReplyEventListener replyEventListener = this.context.getBean(ReplyEventListener.class);
	TestEventListener listener = this.context.getBean(TestEventListener.class);

	this.eventCollector.assertNoEventReceived(listener);
	this.eventCollector.assertNoEventReceived(replyEventListener);
	this.context.publishEvent(event);
	this.eventCollector.assertEvent(replyEventListener, event);
	this.eventCollector.assertNoEventReceived(listener);
	this.eventCollector.assertTotalEventsCount(1);
}
 
Example #15
Source File: AnnotationDrivenEventListenerTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void arrayReply() {
	load(TestEventListener.class, ReplyEventListener.class);
	AnotherTestEvent event = new AnotherTestEvent(this, new String[]{"first", "second"});
	ReplyEventListener replyEventListener = this.context.getBean(ReplyEventListener.class);
	TestEventListener listener = this.context.getBean(TestEventListener.class);

	this.eventCollector.assertNoEventReceived(listener);
	this.eventCollector.assertNoEventReceived(replyEventListener);
	this.context.publishEvent(event);
	this.eventCollector.assertEvent(replyEventListener, event);
	this.eventCollector.assertEvent(listener, "first", "second"); // reply
	this.eventCollector.assertTotalEventsCount(3);
}
 
Example #16
Source File: AnnotationDrivenEventListenerTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void collectionReplyNullValue() {
	load(TestEventListener.class, ReplyEventListener.class);
	AnotherTestEvent event = new AnotherTestEvent(this, Arrays.asList(null, "test"));
	ReplyEventListener replyEventListener = this.context.getBean(ReplyEventListener.class);
	TestEventListener listener = this.context.getBean(TestEventListener.class);

	this.eventCollector.assertNoEventReceived(listener);
	this.eventCollector.assertNoEventReceived(replyEventListener);
	this.context.publishEvent(event);
	this.eventCollector.assertEvent(replyEventListener, event);
	this.eventCollector.assertEvent(listener, "test");
	this.eventCollector.assertTotalEventsCount(2);
}
 
Example #17
Source File: AnnotationDrivenEventListenerTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void exceptionNotPropagatedWithAsync() throws InterruptedException {
	loadAsync(ExceptionEventListener.class);
	AnotherTestEvent event = new AnotherTestEvent(this, "fail");
	ExceptionEventListener listener = this.context.getBean(ExceptionEventListener.class);
	this.eventCollector.assertNoEventReceived(listener);

	this.context.publishEvent(event);
	this.countDownLatch.await(2, TimeUnit.SECONDS);

	this.eventCollector.assertEvent(listener, event);
	this.eventCollector.assertTotalEventsCount(1);
}
 
Example #18
Source File: AnnotationDrivenEventListenerTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void asyncProcessingAppliedWithInterfaceProxy() throws InterruptedException {
	doLoad(AsyncConfigurationWithInterfaces.class, SimpleProxyTestBean.class);

	String threadName = Thread.currentThread().getName();
	AnotherTestEvent event = new AnotherTestEvent(this, threadName);
	SimpleService listener = this.context.getBean(SimpleService.class);
	this.eventCollector.assertNoEventReceived(listener);

	this.context.publishEvent(event);
	countDownLatch.await(2, TimeUnit.SECONDS);
	this.eventCollector.assertEvent(listener, event);
	this.eventCollector.assertTotalEventsCount(1);
}
 
Example #19
Source File: AnnotationDrivenEventListenerTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void asyncProcessingAppliedWithScopedProxy() throws InterruptedException {
	doLoad(AsyncConfigurationWithInterfaces.class, ScopedProxyTestBean.class);

	String threadName = Thread.currentThread().getName();
	AnotherTestEvent event = new AnotherTestEvent(this, threadName);
	SimpleService listener = this.context.getBean(SimpleService.class);
	this.eventCollector.assertNoEventReceived(listener);

	this.context.publishEvent(event);
	countDownLatch.await(2, TimeUnit.SECONDS);
	this.eventCollector.assertEvent(listener, event);
	this.eventCollector.assertTotalEventsCount(1);
}
 
Example #20
Source File: AnnotationDrivenEventListenerTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void exceptionNotPropagatedWithAsync() throws InterruptedException {
	loadAsync(ExceptionEventListener.class);
	AnotherTestEvent event = new AnotherTestEvent(this, "fail");
	ExceptionEventListener listener = this.context.getBean(ExceptionEventListener.class);
	this.eventCollector.assertNoEventReceived(listener);

	this.context.publishEvent(event);
	countDownLatch.await(2, TimeUnit.SECONDS);

	this.eventCollector.assertEvent(listener, event);
	this.eventCollector.assertTotalEventsCount(1);
}
 
Example #21
Source File: AnnotationDrivenEventListenerTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void replyWithPayload() {
	load(TestEventListener.class, ReplyEventListener.class);
	AnotherTestEvent event = new AnotherTestEvent(this, "String");
	ReplyEventListener replyEventListener = this.context.getBean(ReplyEventListener.class);
	TestEventListener listener = this.context.getBean(TestEventListener.class);


	this.eventCollector.assertNoEventReceived(listener);
	this.eventCollector.assertNoEventReceived(replyEventListener);
	this.context.publishEvent(event);
	this.eventCollector.assertEvent(replyEventListener, event);
	this.eventCollector.assertEvent(listener, "String"); // reply
	this.eventCollector.assertTotalEventsCount(2);
}
 
Example #22
Source File: AnnotationDrivenEventListenerTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@EventListener
@Async
public void handleAsync(AnotherTestEvent event) {
	collectEvent(event);
	if ("fail".equals(event.content)) {
		countDownLatch.countDown();
		throw new IllegalStateException("Test exception");
	}
}
 
Example #23
Source File: AnnotationDrivenEventListenerTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@EventListener
@Async
public void handleAsync(AnotherTestEvent event) {
	assertTrue(!Thread.currentThread().getName().equals(event.content));
	collectEvent(event);
	countDownLatch.countDown();
}
 
Example #24
Source File: AnnotationDrivenEventListenerTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@EventListener
@Async
public void handleAsync(AnotherTestEvent event) {
	assertTrue(!Thread.currentThread().getName().equals(event.content));
	eventCollector.addEvent(this, event);
	countDownLatch.countDown();
}
 
Example #25
Source File: AnnotationDrivenEventListenerTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@EventListener
@Async
public void handleAsync(AnotherTestEvent event) {
	assertTrue(!Thread.currentThread().getName().equals(event.content));
	eventCollector.addEvent(this, event);
	countDownLatch.countDown();
}
 
Example #26
Source File: AnnotationDrivenEventListenerTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void asyncProcessingAppliedWithScopedProxy() throws InterruptedException {
	doLoad(AsyncConfigurationWithInterfaces.class, ScopedProxyTestBean.class);

	String threadName = Thread.currentThread().getName();
	AnotherTestEvent event = new AnotherTestEvent(this, threadName);
	SimpleService listener = this.context.getBean(SimpleService.class);
	this.eventCollector.assertNoEventReceived(listener);

	this.context.publishEvent(event);
	this.countDownLatch.await(2, TimeUnit.SECONDS);
	this.eventCollector.assertEvent(listener, event);
	this.eventCollector.assertTotalEventsCount(1);
}
 
Example #27
Source File: AnnotationDrivenEventListenerTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void nullReplyIgnored() {
	load(TestEventListener.class, ReplyEventListener.class);
	AnotherTestEvent event = new AnotherTestEvent(this, null); // No response
	ReplyEventListener replyEventListener = this.context.getBean(ReplyEventListener.class);
	TestEventListener listener = this.context.getBean(TestEventListener.class);

	this.eventCollector.assertNoEventReceived(listener);
	this.eventCollector.assertNoEventReceived(replyEventListener);
	this.context.publishEvent(event);
	this.eventCollector.assertEvent(replyEventListener, event);
	this.eventCollector.assertNoEventReceived(listener);
	this.eventCollector.assertTotalEventsCount(1);
}
 
Example #28
Source File: AnnotationDrivenEventListenerTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void arrayReply() {
	load(TestEventListener.class, ReplyEventListener.class);
	AnotherTestEvent event = new AnotherTestEvent(this, new String[]{"first", "second"});
	ReplyEventListener replyEventListener = this.context.getBean(ReplyEventListener.class);
	TestEventListener listener = this.context.getBean(TestEventListener.class);

	this.eventCollector.assertNoEventReceived(listener);
	this.eventCollector.assertNoEventReceived(replyEventListener);
	this.context.publishEvent(event);
	this.eventCollector.assertEvent(replyEventListener, event);
	this.eventCollector.assertEvent(listener, "first", "second"); // reply
	this.eventCollector.assertTotalEventsCount(3);
}
 
Example #29
Source File: AnnotationDrivenEventListenerTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void collectionReplyNullValue() {
	load(TestEventListener.class, ReplyEventListener.class);
	AnotherTestEvent event = new AnotherTestEvent(this, Arrays.asList(null, "test"));
	ReplyEventListener replyEventListener = this.context.getBean(ReplyEventListener.class);
	TestEventListener listener = this.context.getBean(TestEventListener.class);

	this.eventCollector.assertNoEventReceived(listener);
	this.eventCollector.assertNoEventReceived(replyEventListener);
	this.context.publishEvent(event);
	this.eventCollector.assertEvent(replyEventListener, event);
	this.eventCollector.assertEvent(listener, "test");
	this.eventCollector.assertTotalEventsCount(2);
}
 
Example #30
Source File: AnnotationDrivenEventListenerTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void asyncProcessingApplied() throws InterruptedException {
	loadAsync(AsyncEventListener.class);

	String threadName = Thread.currentThread().getName();
	AnotherTestEvent event = new AnotherTestEvent(this, threadName);
	AsyncEventListener listener = this.context.getBean(AsyncEventListener.class);
	this.eventCollector.assertNoEventReceived(listener);

	this.context.publishEvent(event);
	this.countDownLatch.await(2, TimeUnit.SECONDS);
	this.eventCollector.assertEvent(listener, event);
	this.eventCollector.assertTotalEventsCount(1);
}