Created
April 20, 2017 19:14
-
-
Save mizanRahman/552cf9a46e590fad44139854ce389ca4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @RunWith(MockitoJUnitRunner.class) | |
| public class TokenAuthenticationFilterTest { | |
| private static final String token = "260bce87-6be9-4897-add7-b3b675952538"; | |
| private static final String testUri = "/testUri"; | |
| @Mock | |
| private SecurityService securityService; | |
| @InjectMocks | |
| private TokenAuthenticationFilter tokenAuthenticationFilter = new TokenAuthenticationFilter(); | |
| @Test | |
| public void testDoFilterInternalPositiveScenarioWhenTokenIsInHeader() throws ServletException, IOException { | |
| MockHttpServletRequest request = new MockHttpServletRequest(); | |
| request.addHeader(TOKEN, token); | |
| request.setRequestURI(testUri); | |
| MockHttpServletResponse response = new MockHttpServletResponse(); | |
| MockFilterChain filterChain = new MockFilterChain(); | |
| when(securityService.doesExistToken(token)).thenReturn(true); | |
| tokenAuthenticationFilter.doFilterInternal(request, response, filterChain); | |
| assertThat(response.getStatus()).isEqualTo(HttpStatus.OK.value()); | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
package org.hexagon.hmac;
import org.haxagon.hmac.web.LogFilter;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.runners.MockitoJUnitRunner;
import org.springframework.mock.web.MockFilterChain;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import javax.servlet.ServletException;
import java.io.IOException;
/**
Created by mizan on 4/21/17.
*/
@RunWith(MockitoJUnitRunner.class)
public class HmacAccessFilterTest {
@test
public void testHello() throws ServletException, IOException {
MockHttpServletRequest r = new MockHttpServletRequest();
r.setRequestURI("/api/hello/world");
r.addHeader("NAME", "MIZAN");
r.setContent("{"mizan": "name"}".getBytes());
}
}