@Test public void testDownloadSingleScriptRevision() throws Exception { /* setup mock */ String filter_id = "name:type"; String action = "DOWNLOAD"; when(request.getPathInfo()).thenReturn("?action=" + action + "&filter_id=" + filter_id + "&revision=2"); when(request.getMethod()).thenReturn("GET"); when(request.getParameter("action")).thenReturn(action); when(request.getParameter("filter_id")).thenReturn(filter_id); when(request.getParameter("revision")).thenReturn("2"); /* setup mock DAO */ ZuulFilterDAO dao = mock(ZuulFilterDAOCassandra.class); FilterInfo script = mock(FilterInfo.class); when(dao.getFilterInfoForFilter(filter_id, 2)).thenReturn(script); String code = "code"; when(script.getFilterCode()).thenReturn(code); FilterScriptManagerServlet servlet = getEndpointScriptManagerImplementation(dao); servlet.service(request, response); /* verify the default status is used */ verify(response, never()).setStatus(anyInt()); // verify mime-type verify(response).setContentType("text/plain"); // verify the script is written to the response verify(responseWriter).write("code"); }
@Test public void testDownloadSingleScriptPlusErrorHandlerLatest() throws Exception { /* setup mock */ String filter_id = "name:type"; String action = "DOWNLOAD"; when(request.getPathInfo()).thenReturn("?action=" + action + "&filter_id=" + filter_id); when(request.getMethod()).thenReturn("GET"); when(request.getParameter("action")).thenReturn(action); when(request.getParameter("filter_id")).thenReturn(filter_id); /* setup mock DAO */ ZuulFilterDAO dao = mock(ZuulFilterDAOCassandra.class); FilterInfo script = mock(FilterInfo.class); when(dao.getLatestFilterInfoForFilter(filter_id)).thenReturn(script); when(dao.getFilterInfoForFilter(filter_id, 2)).thenReturn(script); when(script.getFilterCode()).thenReturn("code"); FilterScriptManagerServlet servlet = getEndpointScriptManagerImplementation(dao); servlet.service(request, response); /* verify the default status is used */ verify(response, never()).setStatus(anyInt()); // the writer should not be touched since we need binary, not text verify(responseWriter).write(anyString()); }
@Test public void testDownloadSingleScriptLatest() throws Exception { /* setup mock */ String filter_id = "name:type"; String action = "DOWNLOAD"; when(request.getPathInfo()).thenReturn("?action=" + action + "&filter_id=" + filter_id); when(request.getMethod()).thenReturn("GET"); when(request.getParameter("action")).thenReturn(action); when(request.getParameter("filter_id")).thenReturn(filter_id); /* setup mock DAO */ ZuulFilterDAO dao = mock(ZuulFilterDAOCassandra.class); FilterInfo script = mock(FilterInfo.class); when(dao.getLatestFilterInfoForFilter(filter_id)).thenReturn(script); when(dao.getFilterInfoForFilter(filter_id, 2)).thenReturn(script); when(script.getFilterCode()).thenReturn("code"); FilterScriptManagerServlet servlet = getEndpointScriptManagerImplementation(dao); servlet.service(request, response); /* verify the default status is used */ verify(response, never()).setStatus(anyInt()); // verify mime-type verify(response).setContentType("text/plain"); // verify the script is written to the response verify(responseWriter).write("code"); }
@Test public void testGetScriptForEndpointAndRevisionReturnsNullWhenNotFound() { ZuulFilterDAO dao = new ZuulFilterDAOCassandra(gateway); // setup empty response when(gateway.select(anyString())).thenReturn(response); when(response.isEmpty()).thenReturn(true); FilterInfo filterInfo = dao.getFilterInfoForFilter("/unknown/filter", 2); assertNull(filterInfo); }
@Test public void testGetScriptForEndpointAndRevisionReturnsNullWhenNotFound() { ZuulFilterDAO dao = new ZuulFilterDAOCassandra(gateway); // setup empty response when(gateway.select(anyString())).thenReturn(response); when(response.isEmpty()).thenReturn(true); FilterInfo filterInfo = dao.getFilterInfoForFilter("/unknown/filter", 2); assertNull(filterInfo); }
script = scriptDAO.getFilterInfoForFilter(filter_id, revisionNumber);
FilterInfo filterInfo = dao.getFilterInfoForFilter(filter, 3);
FilterInfo filterInfo = dao.getFilterInfoForFilter(filter, 3);