More Lambdas
Also, make inner ctors package rather than private to avoid the synthetic class and method the compiler has to create. See: http://stackoverflow.com/questions/921025/eclipse-warning-about-synthetic-accessor-for-private-static-nested-classes-in-jav JMX Lambdas Polishing - clean up More
This commit is contained in:
committed by
Artem Bilan
parent
7b1d43a6dc
commit
c865d38576
@@ -32,8 +32,6 @@ import java.util.TimeZone;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.beans.PropertyAccessor;
|
||||
@@ -121,24 +119,19 @@ public class HttpProxyScenarioTests {
|
||||
|
||||
final String contentDispositionValue = "attachment; filename=\"test.txt\"";
|
||||
|
||||
Mockito.doAnswer(new Answer<ResponseEntity<?>>() {
|
||||
|
||||
@Override
|
||||
public ResponseEntity<?> answer(InvocationOnMock invocation) throws Throwable {
|
||||
URI uri = (URI) invocation.getArguments()[0];
|
||||
assertEquals(new URI("http://testServer/test?foo=bar&FOO=BAR"), uri);
|
||||
HttpEntity<?> httpEntity = (HttpEntity<?>) invocation.getArguments()[2];
|
||||
HttpHeaders httpHeaders = httpEntity.getHeaders();
|
||||
assertEquals(ifModifiedSince, httpHeaders.getIfModifiedSince());
|
||||
assertEquals(ifUnmodifiedSinceValue, httpHeaders.getFirst("If-Unmodified-Since"));
|
||||
assertEquals("Keep-Alive", httpHeaders.getFirst("Connection"));
|
||||
|
||||
MultiValueMap<String, String> responseHeaders = new LinkedMultiValueMap<String, String>(httpHeaders);
|
||||
responseHeaders.set("Connection", "close");
|
||||
responseHeaders.set("Content-Disposition", contentDispositionValue);
|
||||
return new ResponseEntity<Object>(responseHeaders, HttpStatus.OK);
|
||||
}
|
||||
Mockito.doAnswer(invocation -> {
|
||||
URI uri = (URI) invocation.getArguments()[0];
|
||||
assertEquals(new URI("http://testServer/test?foo=bar&FOO=BAR"), uri);
|
||||
HttpEntity<?> httpEntity = (HttpEntity<?>) invocation.getArguments()[2];
|
||||
HttpHeaders httpHeaders = httpEntity.getHeaders();
|
||||
assertEquals(ifModifiedSince, httpHeaders.getIfModifiedSince());
|
||||
assertEquals(ifUnmodifiedSinceValue, httpHeaders.getFirst("If-Unmodified-Since"));
|
||||
assertEquals("Keep-Alive", httpHeaders.getFirst("Connection"));
|
||||
|
||||
MultiValueMap<String, String> responseHeaders = new LinkedMultiValueMap<String, String>(httpHeaders);
|
||||
responseHeaders.set("Connection", "close");
|
||||
responseHeaders.set("Content-Disposition", contentDispositionValue);
|
||||
return new ResponseEntity<Object>(responseHeaders, HttpStatus.OK);
|
||||
}).when(template).exchange(Mockito.any(URI.class), Mockito.any(HttpMethod.class),
|
||||
Mockito.any(HttpEntity.class), (Class<?>) Mockito.any(Class.class));
|
||||
|
||||
@@ -179,28 +172,23 @@ public class HttpProxyScenarioTests {
|
||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
|
||||
RestTemplate template = Mockito.spy(new RestTemplate());
|
||||
Mockito.doAnswer(new Answer<ResponseEntity<?>>() {
|
||||
Mockito.doAnswer(invocation -> {
|
||||
URI uri = (URI) invocation.getArguments()[0];
|
||||
assertEquals(new URI("http://testServer/testmp"), uri);
|
||||
HttpEntity<?> httpEntity = (HttpEntity<?>) invocation.getArguments()[2];
|
||||
HttpHeaders httpHeaders = httpEntity.getHeaders();
|
||||
assertEquals("Keep-Alive", httpHeaders.getFirst("Connection"));
|
||||
assertEquals("multipart/form-data;boundary=----WebKitFormBoundarywABD2xqC1FLBijlQ",
|
||||
httpHeaders.getContentType().toString());
|
||||
|
||||
@Override
|
||||
public ResponseEntity<?> answer(InvocationOnMock invocation) throws Throwable {
|
||||
URI uri = (URI) invocation.getArguments()[0];
|
||||
assertEquals(new URI("http://testServer/testmp"), uri);
|
||||
HttpEntity<?> httpEntity = (HttpEntity<?>) invocation.getArguments()[2];
|
||||
HttpHeaders httpHeaders = httpEntity.getHeaders();
|
||||
assertEquals("Keep-Alive", httpHeaders.getFirst("Connection"));
|
||||
assertEquals("multipart/form-data;boundary=----WebKitFormBoundarywABD2xqC1FLBijlQ",
|
||||
httpHeaders.getContentType().toString());
|
||||
|
||||
HttpEntity<?> entity = (HttpEntity<?>) invocation.getArguments()[2];
|
||||
assertThat(entity.getBody(), instanceOf(byte[].class));
|
||||
assertEquals("foo", new String((byte[]) entity.getBody()));
|
||||
|
||||
MultiValueMap<String, String> responseHeaders = new LinkedMultiValueMap<String, String>(httpHeaders);
|
||||
responseHeaders.set("Connection", "close");
|
||||
responseHeaders.set("Content-Type", "text/plain");
|
||||
return new ResponseEntity<Object>(responseHeaders, HttpStatus.OK);
|
||||
}
|
||||
HttpEntity<?> entity = (HttpEntity<?>) invocation.getArguments()[2];
|
||||
assertThat(entity.getBody(), instanceOf(byte[].class));
|
||||
assertEquals("foo", new String((byte[]) entity.getBody()));
|
||||
|
||||
MultiValueMap<String, String> responseHeaders = new LinkedMultiValueMap<String, String>(httpHeaders);
|
||||
responseHeaders.set("Connection", "close");
|
||||
responseHeaders.set("Content-Type", "text/plain");
|
||||
return new ResponseEntity<Object>(responseHeaders, HttpStatus.OK);
|
||||
}).when(template).exchange(Mockito.any(URI.class), Mockito.any(HttpMethod.class),
|
||||
Mockito.any(HttpEntity.class), (Class<?>) Mockito.any(Class.class));
|
||||
|
||||
|
||||
@@ -46,7 +46,6 @@ import org.springframework.expression.common.LiteralExpression;
|
||||
import org.springframework.expression.spel.standard.SpelExpression;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.converter.HttpMessageConverter;
|
||||
import org.springframework.integration.MessageRejectedException;
|
||||
import org.springframework.integration.core.MessagingTemplate;
|
||||
import org.springframework.integration.http.converter.SerializingHttpMessageConverter;
|
||||
import org.springframework.integration.http.inbound.HttpRequestHandlingController;
|
||||
@@ -54,9 +53,7 @@ import org.springframework.integration.http.inbound.HttpRequestHandlingMessaging
|
||||
import org.springframework.integration.http.support.DefaultHttpHeaderMapper;
|
||||
import org.springframework.integration.test.util.TestUtils;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageDeliveryException;
|
||||
import org.springframework.messaging.MessageHandler;
|
||||
import org.springframework.messaging.MessageHandlingException;
|
||||
import org.springframework.messaging.MessageHeaders;
|
||||
import org.springframework.messaging.PollableChannel;
|
||||
import org.springframework.messaging.SubscribableChannel;
|
||||
@@ -273,12 +270,7 @@ public class HttpInboundGatewayParserTests {
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private MessageHandler handlerExpecting(final Matcher<Message> messageMatcher) {
|
||||
return new MessageHandler() {
|
||||
@Override
|
||||
public void handleMessage(Message<?> message) throws MessageRejectedException, MessageHandlingException, MessageDeliveryException {
|
||||
assertThat(message, is(messageMatcher));
|
||||
}
|
||||
};
|
||||
return message -> assertThat(message, is(messageMatcher));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -29,18 +29,19 @@ import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.expression.Expression;
|
||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.integration.channel.DirectChannel;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.handler.AbstractReplyProducingMessageHandler;
|
||||
import org.springframework.integration.http.AbstractHttpInboundTests;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
import org.springframework.validation.Errors;
|
||||
@@ -349,26 +350,24 @@ public class HttpRequestHandlingControllerTests extends AbstractHttpInboundTests
|
||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
final AtomicInteger active = new AtomicInteger();
|
||||
final AtomicBoolean expected503 = new AtomicBoolean();
|
||||
Executors.newSingleThreadExecutor().execute(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
// wait for the active thread
|
||||
latch2.await(10, TimeUnit.SECONDS);
|
||||
}
|
||||
catch (InterruptedException e1) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
// start the shutdown
|
||||
active.set(controller.beforeShutdown());
|
||||
try {
|
||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
controller.handleRequest(request, response);
|
||||
expected503.set(response.getStatus() == HttpStatus.SERVICE_UNAVAILABLE.value());
|
||||
latch1.countDown();
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Executors.newSingleThreadExecutor().execute(() -> {
|
||||
try {
|
||||
// wait for the active thread
|
||||
latch2.await(10, TimeUnit.SECONDS);
|
||||
}
|
||||
catch (InterruptedException e1) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
// start the shutdown
|
||||
active.set(controller.beforeShutdown());
|
||||
try {
|
||||
MockHttpServletResponse response1 = new MockHttpServletResponse();
|
||||
controller.handleRequest(request, response1);
|
||||
expected503.set(response1.getStatus() == HttpStatus.SERVICE_UNAVAILABLE.value());
|
||||
latch1.countDown();
|
||||
}
|
||||
catch (Exception e) {
|
||||
LogFactory.getLog(getClass()).error("Async handleRequest failed", e);
|
||||
}
|
||||
});
|
||||
ModelAndView modelAndView = controller.handleRequest(request, response);
|
||||
|
||||
@@ -36,10 +36,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.integration.http.AbstractHttpInboundTests;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageHandler;
|
||||
import org.springframework.messaging.MessageHeaders;
|
||||
import org.springframework.messaging.MessagingException;
|
||||
import org.springframework.messaging.SubscribableChannel;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
@@ -118,35 +115,31 @@ public class Int2312RequestMappingIntegrationTests extends AbstractHttpInboundTe
|
||||
final RequestAttributes attributes = new ServletRequestAttributes(request);
|
||||
RequestContextHolder.setRequestAttributes(attributes);
|
||||
|
||||
this.toLowerCaseChannel.subscribe(new MessageHandler() {
|
||||
this.toLowerCaseChannel.subscribe(message -> {
|
||||
MessageHeaders headers = message.getHeaders();
|
||||
|
||||
@Override
|
||||
public void handleMessage(Message<?> message) throws MessagingException {
|
||||
MessageHeaders headers = message.getHeaders();
|
||||
assertEquals(attributes, headers.get("requestAttributes"));
|
||||
|
||||
assertEquals(attributes, headers.get("requestAttributes"));
|
||||
Object requestParams = headers.get("requestParams");
|
||||
assertNotNull(requestParams);
|
||||
assertEquals(params, ((MultiValueMap<String, String>) requestParams).toSingleValueMap());
|
||||
|
||||
Object requestParams = headers.get("requestParams");
|
||||
assertNotNull(requestParams);
|
||||
assertEquals(params, ((MultiValueMap<String, String>) requestParams).toSingleValueMap());
|
||||
Object matrixVariables = headers.get("matrixVariables");
|
||||
assertThat(matrixVariables, Matchers.instanceOf(Map.class));
|
||||
Object value = ((Map<?, ?>) matrixVariables).get("value");
|
||||
assertThat(value, Matchers.instanceOf(MultiValueMap.class));
|
||||
assertEquals("1", ((MultiValueMap<String, ?>) value).getFirst("q1"));
|
||||
assertEquals("2", ((MultiValueMap<String, ?>) value).getFirst("q2"));
|
||||
|
||||
Object matrixVariables = headers.get("matrixVariables");
|
||||
assertThat(matrixVariables, Matchers.instanceOf(Map.class));
|
||||
Object value = ((Map<?, ?>) matrixVariables).get("value");
|
||||
assertThat(value, Matchers.instanceOf(MultiValueMap.class));
|
||||
assertEquals("1", ((MultiValueMap<String, ?>) value).getFirst("q1"));
|
||||
assertEquals("2", ((MultiValueMap<String, ?>) value).getFirst("q2"));
|
||||
Object requestHeaders = headers.get("requestHeaders");
|
||||
assertNotNull(requestParams);
|
||||
assertEquals(MediaType.TEXT_PLAIN, ((HttpHeaders) requestHeaders).getContentType());
|
||||
|
||||
Object requestHeaders = headers.get("requestHeaders");
|
||||
assertNotNull(requestParams);
|
||||
assertEquals(MediaType.TEXT_PLAIN, ((HttpHeaders) requestHeaders).getContentType());
|
||||
|
||||
Map<String, Cookie> cookies = (Map<String, Cookie>) headers.get("cookies");
|
||||
assertEquals(1, cookies.size());
|
||||
Cookie foo = cookies.get("foo");
|
||||
assertNotNull(foo);
|
||||
assertEquals(cookie, foo);
|
||||
}
|
||||
Map<String, Cookie> cookies = (Map<String, Cookie>) headers.get("cookies");
|
||||
assertEquals(1, cookies.size());
|
||||
Cookie foo = cookies.get("foo");
|
||||
assertNotNull(foo);
|
||||
assertEquals(cookie, foo);
|
||||
});
|
||||
|
||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
|
||||
Reference in New Issue
Block a user