RequestIdentityInterceptor extends HandlerInterceptorAdapter { @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) { String requestIdentity = request.getHeader(ServiceBrokerRequest.REQUEST_IDENTITY_HEADER); if (StringUtils.hasLength(requestIdentity)) { response.addHeader(ServiceBrokerRequest.REQUEST_IDENTITY_HEADER, requestIdentity); } return true; }  @Override boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler);  }
@Test void defaultBehaviorReturnsTrue() { RequestIdentityInterceptor interceptor = new RequestIdentityInterceptor(); assertThat(interceptor.preHandle(request, response, null)).isTrue(); }
@Test void requestIdentityHeader() { given(request.getHeader(ServiceBrokerRequest.REQUEST_IDENTITY_HEADER)).willReturn("request-id"); RequestIdentityInterceptor interceptor = new RequestIdentityInterceptor(); assertThat(interceptor.preHandle(request, response, null)).isTrue(); verify(response, times(1)).addHeader(ServiceBrokerRequest.REQUEST_IDENTITY_HEADER, "request-id"); }
@Test void requestIdentityHeaderIsMissing() { given(request.getHeader(ServiceBrokerRequest.REQUEST_IDENTITY_HEADER)).willReturn(null); RequestIdentityInterceptor interceptor = new RequestIdentityInterceptor(); assertThat(interceptor.preHandle(request, response, null)).isTrue(); assertThat(response.getHeader(ServiceBrokerRequest.REQUEST_IDENTITY_HEADER)).isNull(); }