BVB Source Codes

che Show DashboardRedirectionFilterTest.java Source code

Return Download che: download DashboardRedirectionFilterTest.java Source code - Download che Source code - Type:.java
  1. /*******************************************************************************
  2.  * Copyright (c) 2012-2017 Codenvy, S.A.
  3.  * All rights reserved. This program and the accompanying materials
  4.  * are made available under the terms of the Eclipse Public License v1.0
  5.  * which accompanies this distribution, and is available at
  6.  * http://www.eclipse.org/legal/epl-v10.html
  7.  *
  8.  * Contributors:
  9.  *   Codenvy, S.A. - initial API and implementation
  10.  *******************************************************************************/
  11. package org.eclipse.che;
  12.  
  13. import org.eclipse.che.api.core.rest.HttpJsonHelper;
  14. import org.eclipse.che.commons.env.EnvironmentContext;
  15. import org.eclipse.che.commons.subject.SubjectImpl;
  16. import org.mockito.InjectMocks;
  17. import org.mockito.Mock;
  18. import org.mockito.testng.MockitoTestNGListener;
  19. import org.omg.CORBA.ServerRequest;
  20. import org.testng.annotations.DataProvider;
  21. import org.testng.annotations.Listeners;
  22. import org.testng.annotations.Test;
  23.  
  24. import javax.servlet.FilterChain;
  25. import javax.servlet.ServletRequest;
  26. import javax.servlet.ServletResponse;
  27. import javax.servlet.http.HttpServletRequest;
  28. import javax.servlet.http.HttpServletResponse;
  29. import java.util.Arrays;
  30.  
  31. import static org.mockito.Matchers.any;
  32. import static org.mockito.Matchers.eq;
  33. import static org.mockito.Mockito.verify;
  34. import static org.mockito.Mockito.when;
  35.  
  36. @Listeners(value = {MockitoTestNGListener.class})
  37. public class DashboardRedirectionFilterTest {
  38.     @Mock
  39.     private FilterChain chain;
  40.  
  41.     @Mock
  42.     HttpJsonHelper helper;
  43.  
  44.     @Mock
  45.     private HttpServletRequest request;
  46.  
  47.     @Mock
  48.     private HttpServletResponse response;
  49.  
  50.     @InjectMocks
  51.     private DashboardRedirectionFilter filter;
  52.  
  53.     @Test
  54.     public void shouldSkipRequestToProject() throws Exception {
  55.         //given
  56.         when(request.getMethod()).thenReturn("GET");
  57.         when(request.getRequestURI()).thenReturn("/namespace/ws-id/project1");
  58.         when(request.getRequestURL()).thenReturn(new StringBuffer("http://localhost:8080/namespace/ws-id/project1"));
  59.  
  60.         //when
  61.         filter.doFilter(request, response, chain);
  62.  
  63.         //then
  64.         verify(chain).doFilter((ServletRequest)any(ServerRequest.class), any(ServletResponse.class));
  65.     }
  66.  
  67.     @Test(dataProvider = "nonNamespacePathProvider")
  68.     public void shouldRedirectIfRequestWithoutNamespace(String uri, String url) throws Exception {
  69.         //given
  70.         when(request.getMethod()).thenReturn("GET");
  71.         when(request.getRequestURI()).thenReturn(uri);
  72.         when(request.getRequestURL()).thenReturn(new StringBuffer(url));
  73.         EnvironmentContext context = new EnvironmentContext();
  74.         context.setSubject(new SubjectImpl("id123", "name", "token123", false));
  75.         EnvironmentContext.setCurrent(context);
  76.  
  77.         //when
  78.         filter.doFilter(request, response, chain);
  79.  
  80.         //then
  81.         verify(response).sendRedirect(eq("/dashboard/"));
  82.     }
  83.  
  84.     @DataProvider(name = "nonNamespacePathProvider")
  85.     public Object[][] nonProjectPathProvider() {
  86.         return new Object[][]{{"/ws-id/", "http://localhost:8080/ws-id123123/"},
  87.                               {"/wsname", "http://localhost:8080/wsname_only"},
  88.         };
  89.     }
  90.  
  91.     @Test(dataProvider = "notGETMethodProvider")
  92.     public void shouldSkipNotGETRequest(String method) throws Exception {
  93.         //given
  94.         when(request.getMethod()).thenReturn(method);
  95.         when(request.getRequestURI()).thenReturn("/ws-id/project1");
  96.         when(request.getRequestURL()).thenReturn(new StringBuffer("http://localhost:8080/ws-id/project1"));
  97.  
  98.         //when
  99.         filter.doFilter(request, response, chain);
  100.  
  101.         //then
  102.         verify(chain).doFilter((ServletRequest)any(ServerRequest.class), any(ServletResponse.class));
  103.     }
  104.  
  105.     @DataProvider(name = "notGETMethodProvider")
  106.     public Object[][] notGETMethodProvider() {
  107.         return new Object[][]{{"POST"},
  108.                               {"HEAD"},
  109.                               {"DELETE"},
  110.                               {"PUT"}
  111.         };
  112.     }
  113. }
  114.  
downloadDashboardRedirectionFilterTest.java Source code - Download che Source code
Related Source Codes/Software:
Gource - oftware version control visualization ... 2017-01-10
FDFullscreenPopGesture - A UINavigationController's category to enable full... 2017-01-10
node-style-guide - A guide for styling your node.js / JavaScript code... 2017-01-09
ImageOptim - GUI image optimizer for Mac htt... 2017-01-09
falcon - Falcon is a low-level, high-performance Python fra... 2017-01-09
notepad-plus-plus - Notepad++ official repository h... 2017-01-10
waterline - An adapter-based ORM for Node.js with support for ... 2017-01-10
Workerman - An asynchronous event driven PHP framework for eas... 2017-01-10
structor - An advanced visual editor for React components ... 2017-01-10
golearn - Machine Learning for Go 2017-01-10
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top