@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 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 testGetScriptForLatestEndpointReturnsNullWhenNotFound() { ZuulFilterDAO dao = new ZuulFilterDAOCassandra(gateway); // setup empty response when(gateway.select(anyString())).thenReturn(response); when(response.isEmpty()).thenReturn(true); FilterInfo filterInfo = dao.getLatestFilterInfoForFilter("/unknown/filter"); assertNull(filterInfo); }
@Test public void testGetScriptForLatestEndpointReturnsNullWhenNotFound() { ZuulFilterDAO dao = new ZuulFilterDAOCassandra(gateway); // setup empty response when(gateway.select(anyString())).thenReturn(response); when(response.isEmpty()).thenReturn(true); FilterInfo filterInfo = dao.getLatestFilterInfoForFilter("/unknown/filter"); assertNull(filterInfo); }
if (revision == null) { script = scriptDAO.getLatestFilterInfoForFilter(filter_id); } else { int revisionNumber = -1;
FilterInfo filterInfo = dao.getLatestFilterInfoForFilter(filter);
FilterInfo filterInfo = dao.getLatestFilterInfoForFilter(filter);