org.springframework.web.context.request.async.DeferredResult.DeferredResultHandler Java Examples

The following examples show how to use org.springframework.web.context.request.async.DeferredResult.DeferredResultHandler. 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 Project: spring-analysis-note   Author: Vip-Augus   File: DeferredResultTests.java    License: MIT License 6 votes vote down vote up
@Test
public void onTimeout() throws Exception {
	final StringBuilder sb = new StringBuilder();

	DeferredResultHandler handler = mock(DeferredResultHandler.class);

	DeferredResult<String> result = new DeferredResult<>(null, "timeout result");
	result.setResultHandler(handler);
	result.onTimeout(new Runnable() {
		@Override
		public void run() {
			sb.append("timeout event");
		}
	});

	result.getInterceptor().handleTimeout(null, null);

	assertEquals("timeout event", sb.toString());
	assertFalse("Should not be able to set result a second time", result.setResult("hello"));
	verify(handler).handleResult("timeout result");
}
 
Example #2
Source Project: spring-analysis-note   Author: Vip-Augus   File: DeferredResultTests.java    License: MIT License 6 votes vote down vote up
@Test
public void onError() throws Exception {
	final StringBuilder sb = new StringBuilder();

	DeferredResultHandler handler = mock(DeferredResultHandler.class);

	DeferredResult<String> result = new DeferredResult<>(null, "error result");
	result.setResultHandler(handler);
	Exception e = new Exception();
	result.onError(new Consumer<Throwable>() {
		@Override
		public void accept(Throwable t) {
			sb.append("error event");
		}
	});

	result.getInterceptor().handleError(null, null, e);

	assertEquals("error event", sb.toString());
	assertFalse("Should not be able to set result a second time", result.setResult("hello"));
	verify(handler).handleResult(e);
}
 
Example #3
Source Project: java-technology-stack   Author: codeEngraver   File: DeferredResultTests.java    License: MIT License 6 votes vote down vote up
@Test
public void onTimeout() throws Exception {
	final StringBuilder sb = new StringBuilder();

	DeferredResultHandler handler = mock(DeferredResultHandler.class);

	DeferredResult<String> result = new DeferredResult<>(null, "timeout result");
	result.setResultHandler(handler);
	result.onTimeout(new Runnable() {
		@Override
		public void run() {
			sb.append("timeout event");
		}
	});

	result.getInterceptor().handleTimeout(null, null);

	assertEquals("timeout event", sb.toString());
	assertFalse("Should not be able to set result a second time", result.setResult("hello"));
	verify(handler).handleResult("timeout result");
}
 
Example #4
Source Project: java-technology-stack   Author: codeEngraver   File: DeferredResultTests.java    License: MIT License 6 votes vote down vote up
@Test
public void onError() throws Exception {
	final StringBuilder sb = new StringBuilder();

	DeferredResultHandler handler = mock(DeferredResultHandler.class);

	DeferredResult<String> result = new DeferredResult<>(null, "error result");
	result.setResultHandler(handler);
	Exception e = new Exception();
	result.onError(new Consumer<Throwable>() {
		@Override
		public void accept(Throwable t) {
			sb.append("error event");
		}
	});

	result.getInterceptor().handleError(null, null, e);

	assertEquals("error event", sb.toString());
	assertFalse("Should not be able to set result a second time", result.setResult("hello"));
	verify(handler).handleResult(e);
}
 
Example #5
Source Project: spring4-understanding   Author: langtianya   File: DeferredResultTests.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void onTimeout() throws Exception {
	final StringBuilder sb = new StringBuilder();

	DeferredResultHandler handler = mock(DeferredResultHandler.class);

	DeferredResult<String> result = new DeferredResult<String>(null, "timeout result");
	result.setResultHandler(handler);
	result.onTimeout(new Runnable() {
		@Override
		public void run() {
			sb.append("timeout event");
		}
	});

	result.getInterceptor().handleTimeout(null, null);

	assertEquals("timeout event", sb.toString());
	assertFalse("Should not be able to set result a second time", result.setResult("hello"));
	verify(handler).handleResult("timeout result");
}
 
Example #6
Source Project: spring-analysis-note   Author: Vip-Augus   File: DeferredResultTests.java    License: MIT License 5 votes vote down vote up
@Test
public void setResult() {
	DeferredResultHandler handler = mock(DeferredResultHandler.class);

	DeferredResult<String> result = new DeferredResult<>();
	result.setResultHandler(handler);

	assertTrue(result.setResult("hello"));
	verify(handler).handleResult("hello");
}
 
Example #7
Source Project: spring-analysis-note   Author: Vip-Augus   File: DeferredResultTests.java    License: MIT License 5 votes vote down vote up
@Test
public void setResultTwice() {
	DeferredResultHandler handler = mock(DeferredResultHandler.class);

	DeferredResult<String> result = new DeferredResult<>();
	result.setResultHandler(handler);

	assertTrue(result.setResult("hello"));
	assertFalse(result.setResult("hi"));

	verify(handler).handleResult("hello");
}
 
Example #8
Source Project: spring-analysis-note   Author: Vip-Augus   File: DeferredResultTests.java    License: MIT License 5 votes vote down vote up
@Test
public void hasResult() {
	DeferredResultHandler handler = mock(DeferredResultHandler.class);

	DeferredResult<String> result = new DeferredResult<>();
	result.setResultHandler(handler);

	assertFalse(result.hasResult());
	assertNull(result.getResult());

	result.setResult("hello");

	assertEquals("hello", result.getResult());
}
 
Example #9
Source Project: java-technology-stack   Author: codeEngraver   File: DeferredResultTests.java    License: MIT License 5 votes vote down vote up
@Test
public void setResult() {
	DeferredResultHandler handler = mock(DeferredResultHandler.class);

	DeferredResult<String> result = new DeferredResult<>();
	result.setResultHandler(handler);

	assertTrue(result.setResult("hello"));
	verify(handler).handleResult("hello");
}
 
Example #10
Source Project: java-technology-stack   Author: codeEngraver   File: DeferredResultTests.java    License: MIT License 5 votes vote down vote up
@Test
public void setResultTwice() {
	DeferredResultHandler handler = mock(DeferredResultHandler.class);

	DeferredResult<String> result = new DeferredResult<>();
	result.setResultHandler(handler);

	assertTrue(result.setResult("hello"));
	assertFalse(result.setResult("hi"));

	verify(handler).handleResult("hello");
}
 
Example #11
Source Project: java-technology-stack   Author: codeEngraver   File: DeferredResultTests.java    License: MIT License 5 votes vote down vote up
@Test
public void hasResult() {
	DeferredResultHandler handler = mock(DeferredResultHandler.class);

	DeferredResult<String> result = new DeferredResult<>();
	result.setResultHandler(handler);

	assertFalse(result.hasResult());
	assertNull(result.getResult());

	result.setResult("hello");

	assertEquals("hello", result.getResult());
}
 
Example #12
Source Project: spring4-understanding   Author: langtianya   File: DeferredResultTests.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void setResult() {
	DeferredResultHandler handler = mock(DeferredResultHandler.class);

	DeferredResult<String> result = new DeferredResult<String>();
	result.setResultHandler(handler);

	assertTrue(result.setResult("hello"));
	verify(handler).handleResult("hello");
}
 
Example #13
Source Project: spring4-understanding   Author: langtianya   File: DeferredResultTests.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void setResultTwice() {
	DeferredResultHandler handler = mock(DeferredResultHandler.class);

	DeferredResult<String> result = new DeferredResult<String>();
	result.setResultHandler(handler);

	assertTrue(result.setResult("hello"));
	assertFalse(result.setResult("hi"));

	verify(handler).handleResult("hello");
}
 
Example #14
Source Project: spring4-understanding   Author: langtianya   File: DeferredResultTests.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void hasResult() {
	DeferredResultHandler handler = mock(DeferredResultHandler.class);

	DeferredResult<String> result = new DeferredResult<String>();
	result.setResultHandler(handler);

	assertFalse(result.hasResult());
	assertNull(result.getResult());

	result.setResult("hello");

	assertEquals("hello", result.getResult());
}
 
Example #15
Source Project: spring-analysis-note   Author: Vip-Augus   File: DeferredResultTests.java    License: MIT License 3 votes vote down vote up
@Test
public void isSetOrExpired() {
	DeferredResultHandler handler = mock(DeferredResultHandler.class);

	DeferredResult<String> result = new DeferredResult<>();
	result.setResultHandler(handler);

	assertFalse(result.isSetOrExpired());

	result.setResult("hello");

	assertTrue(result.isSetOrExpired());

	verify(handler).handleResult("hello");
}
 
Example #16
Source Project: java-technology-stack   Author: codeEngraver   File: DeferredResultTests.java    License: MIT License 3 votes vote down vote up
@Test
public void isSetOrExpired() {
	DeferredResultHandler handler = mock(DeferredResultHandler.class);

	DeferredResult<String> result = new DeferredResult<>();
	result.setResultHandler(handler);

	assertFalse(result.isSetOrExpired());

	result.setResult("hello");

	assertTrue(result.isSetOrExpired());

	verify(handler).handleResult("hello");
}
 
Example #17
Source Project: spring4-understanding   Author: langtianya   File: DeferredResultTests.java    License: Apache License 2.0 3 votes vote down vote up
@Test
public void isSetOrExpired() {
	DeferredResultHandler handler = mock(DeferredResultHandler.class);

	DeferredResult<String> result = new DeferredResult<String>();
	result.setResultHandler(handler);

	assertFalse(result.isSetOrExpired());

	result.setResult("hello");

	assertTrue(result.isSetOrExpired());

	verify(handler).handleResult("hello");
}