Commit 0ddea3dd authored by Komal Makkar's avatar Komal Makkar
Browse files

Addressing comments.

parent df4bfe3e
Pipeline #22020 failed with stages
in 2 minutes and 11 seconds
...@@ -57,6 +57,7 @@ public class HandshakeFilter implements Filter { ...@@ -57,6 +57,7 @@ public class HandshakeFilter implements Filter {
String handshakeResponse = this.handshakeHandler.getHandshakeResponse(); String handshakeResponse = this.handshakeHandler.getHandshakeResponse();
PrintWriter out = httpServletResponse.getWriter(); PrintWriter out = httpServletResponse.getWriter();
out.flush();
out.print(handshakeResponse); out.print(handshakeResponse);
return; return;
} }
......
...@@ -20,13 +20,16 @@ import org.junit.runner.RunWith; ...@@ -20,13 +20,16 @@ import org.junit.runner.RunWith;
import org.mockito.InjectMocks; import org.mockito.InjectMocks;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner; import org.mockito.junit.MockitoJUnitRunner;
import org.opengroup.osdu.notification.provider.interfaces.IPubsubHandshakeHandler;
import org.opengroup.osdu.notification.provider.interfaces.IPubsubRequestBodyExtractor; import org.opengroup.osdu.notification.provider.interfaces.IPubsubRequestBodyExtractor;
import javax.servlet.FilterChain; import javax.servlet.FilterChain;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.ServletResponse; import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
...@@ -37,15 +40,24 @@ public class HandshakeFilterTest { ...@@ -37,15 +40,24 @@ public class HandshakeFilterTest {
@Mock @Mock
private IPubsubRequestBodyExtractor requestBodyExtractor; private IPubsubRequestBodyExtractor requestBodyExtractor;
@Mock
private IPubsubHandshakeHandler handshakeHandler;
@Mock @Mock
private HttpServletRequest httpServletRequest; private HttpServletRequest httpServletRequest;
@Mock
private HttpServletResponse httpServletResponse;
@Mock @Mock
private ServletResponse servletResponse; private ServletResponse servletResponse;
@Mock @Mock
private FilterChain filterChain; private FilterChain filterChain;
@Mock
private PrintWriter printWriter;
@InjectMocks @InjectMocks
private HandshakeFilter sut; private HandshakeFilter sut;
...@@ -58,4 +70,16 @@ public class HandshakeFilterTest { ...@@ -58,4 +70,16 @@ public class HandshakeFilterTest {
verify(this.filterChain, times(1)).doFilter(httpServletRequest, servletResponse); verify(this.filterChain, times(1)).doFilter(httpServletRequest, servletResponse);
} }
@Test
public void should_NotCallFiltersIfHandshake() throws IOException, ServletException {
doReturn("records-changed").when(httpServletRequest).getServletPath();
doReturn(true).when(this.requestBodyExtractor).isHandshakeRequest();
doReturn("handshake response").when(this.handshakeHandler).getHandshakeResponse();
doReturn(this.printWriter).when(this.httpServletResponse).getWriter();
this.sut.doFilter(this.httpServletRequest, this.httpServletResponse, this.filterChain);
verify(this.filterChain, times(0)).doFilter(httpServletRequest, servletResponse);
}
} }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment