@Test @SuppressWarnings( "ResultOfMethodCallIgnored" ) public void testUpdateActivityStatusInDoGet() throws Exception { LogChannelInterface log = mock( LogChannelInterface.class ); ServletOutputStream outputStream = mock( ServletOutputStream.class ); SlaveServerDetection activeServerDetection = mock( SlaveServerDetection.class ); SlaveServerDetection inactiveServerDetection = mock( SlaveServerDetection.class ); SlaveServer activeSlaveServer = mock( SlaveServer.class ); SlaveServer inactiveSlaveServer = mock( SlaveServer.class ); servlet.log = log; List<SlaveServerDetection> detections = new ArrayList<>(); detections.add( activeServerDetection ); detections.add( inactiveServerDetection ); doReturn( false ).when( log ).isDebug(); doReturn( outputStream ).when( response ).getOutputStream(); doReturn( detections ).when( servlet ).getDetections(); doReturn( activeSlaveServer ).when( activeServerDetection ).getSlaveServer(); doReturn( inactiveSlaveServer ).when( inactiveServerDetection ).getSlaveServer(); doThrow( new Exception() ).when( inactiveSlaveServer ).getStatus(); doCallRealMethod().when( servlet ).doGet( request, response ); servlet.doGet( request, response ); verify( activeSlaveServer ).getStatus(); verify( activeServerDetection, never() ).setActive( false ); verify( activeServerDetection, never() ).setLastInactiveDate( anyObject() ); verify( activeServerDetection ).getXML(); verify( inactiveSlaveServer ).getStatus(); verify( inactiveServerDetection ).setActive( false ); verify( inactiveServerDetection ).setLastInactiveDate( anyObject() ); verify( inactiveServerDetection ).getXML(); }
public void doGet( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException { if ( isJettyMode() && !request.getContextPath().startsWith( CONTEXT_PATH ) ) { return; } if ( log.isDebug() ) { logDebug( BaseMessages.getString( PKG, "GetStatusServlet.StatusRequested" ) ); } response.setStatus( HttpServletResponse.SC_OK ); response.setContentType( "text/xml" ); response.setCharacterEncoding( Const.XML_ENCODING ); PrintStream out = new PrintStream( response.getOutputStream() ); out.print( XMLHandler.getXMLHeader( Const.XML_ENCODING ) ); out.println( XMLHandler.openTag( XML_TAG_SLAVESERVER_DETECTIONS ) ); if ( getDetections() != null ) { for ( SlaveServerDetection slaveServer : getDetections() ) { try { slaveServer.getSlaveServer().getStatus(); } catch ( Exception e ) { slaveServer.setActive( false ); slaveServer.setLastInactiveDate( new Date() ); } out.println( slaveServer.getXML() ); } } out.println( XMLHandler.closeTag( XML_TAG_SLAVESERVER_DETECTIONS ) ); }
GetSlavesServlet extends BaseHttpServlet implements CartePluginInterface { public void doGet( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException { if ( isJettyMode() && !request.getContextPath().startsWith( CONTEXT_PATH ) ) { return; } if ( log.isDebug() ) { logDebug( BaseMessages.getString( PKG, "GetStatusServlet.StatusRequested" ) ); } response.setStatus( HttpServletResponse.SC_OK ); response.setContentType( "text/xml" ); response.setCharacterEncoding( Const.XML_ENCODING ); PrintStream out = new PrintStream( response.getOutputStream() ); out.print( XMLHandler.getXMLHeader( Const.XML_ENCODING ) ); out.println( XMLHandler.openTag( XML_TAG_SLAVESERVER_DETECTIONS ) ); if ( getDetections() != null ) { for ( SlaveServerDetection slaveServer : getDetections() ) { try { slaveServer.getSlaveServer().getStatus(); } catch ( Exception e ) { slaveServer.setActive( false ); slaveServer.setLastInactiveDate( new Date() ); } out.println( slaveServer.getXML() ); } } out.println( XMLHandler.closeTag( XML_TAG_SLAVESERVER_DETECTIONS ) ); } }
GetSlavesServlet extends BaseHttpServlet implements CartePluginInterface { public void doGet( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException { if ( isJettyMode() && !request.getContextPath().startsWith( CONTEXT_PATH ) ) { return; } if ( log.isDebug() ) { logDebug( BaseMessages.getString( PKG, "GetStatusServlet.StatusRequested" ) ); } response.setStatus( HttpServletResponse.SC_OK ); response.setContentType( "text/xml" ); response.setCharacterEncoding( Const.XML_ENCODING ); PrintStream out = new PrintStream( response.getOutputStream() ); out.print( XMLHandler.getXMLHeader( Const.XML_ENCODING ) ); out.println( XMLHandler.openTag( XML_TAG_SLAVESERVER_DETECTIONS ) ); if ( getDetections() != null ) { for ( SlaveServerDetection slaveServer : getDetections() ) { try { slaveServer.getSlaveServer().getStatus(); } catch ( Exception e ) { slaveServer.setActive( false ); slaveServer.setLastInactiveDate( new Date() ); } out.println( slaveServer.getXML() ); } } out.println( XMLHandler.closeTag( XML_TAG_SLAVESERVER_DETECTIONS ) ); } GetSlavesServlet();  GetSlavesServlet( List<SlaveServerDetection> slaveServers );  GetSlavesServlet( List<SlaveServerDetection> slaveServers, boolean isJetty ); }
GetSlavesServlet extends BaseHttpServlet implements CartePluginInterface { public void doGet( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException { if ( isJettyMode() && !request.getContextPath().startsWith( CONTEXT_PATH ) ) { return; } if ( log.isDebug() ) { logDebug( BaseMessages.getString( PKG, "GetStatusServlet.StatusRequested" ) ); } response.setStatus( HttpServletResponse.SC_OK ); response.setContentType( "text/xml" ); response.setCharacterEncoding( Const.XML_ENCODING ); PrintStream out = new PrintStream( response.getOutputStream() ); out.print( XMLHandler.getXMLHeader( Const.XML_ENCODING ) ); out.println( XMLHandler.openTag( XML_TAG_SLAVESERVER_DETECTIONS ) ); if ( getDetections() != null ) { for ( SlaveServerDetection slaveServer : getDetections() ) { try { slaveServer.getSlaveServer().getStatus(); } catch ( Exception e ) { slaveServer.setActive( false ); slaveServer.setLastInactiveDate( new Date() ); } out.println( slaveServer.getXML() ); } } out.println( XMLHandler.closeTag( XML_TAG_SLAVESERVER_DETECTIONS ) ); } GetSlavesServlet();  GetSlavesServlet( List<SlaveServerDetection> slaveServers );  GetSlavesServlet( List<SlaveServerDetection> slaveServers, boolean isJetty ); void doGet( HttpServletRequest request, HttpServletResponse response ); String toString(); String getService(); String getContextPath(); }
GetSlavesServlet extends BaseHttpServlet implements CartePluginInterface { public void doGet( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException { if ( isJettyMode() && !request.getContextPath().startsWith( CONTEXT_PATH ) ) { return; } if ( log.isDebug() ) { logDebug( BaseMessages.getString( PKG, "GetStatusServlet.StatusRequested" ) ); } response.setStatus( HttpServletResponse.SC_OK ); response.setContentType( "text/xml" ); response.setCharacterEncoding( Const.XML_ENCODING ); PrintStream out = new PrintStream( response.getOutputStream() ); out.print( XMLHandler.getXMLHeader( Const.XML_ENCODING ) ); out.println( XMLHandler.openTag( XML_TAG_SLAVESERVER_DETECTIONS ) ); if ( getDetections() != null ) { for ( SlaveServerDetection slaveServer : getDetections() ) { try { slaveServer.getSlaveServer().getStatus(); } catch ( Exception e ) { slaveServer.setActive( false ); slaveServer.setLastInactiveDate( new Date() ); } out.println( slaveServer.getXML() ); } } out.println( XMLHandler.closeTag( XML_TAG_SLAVESERVER_DETECTIONS ) ); } GetSlavesServlet();  GetSlavesServlet( List<SlaveServerDetection> slaveServers );  GetSlavesServlet( List<SlaveServerDetection> slaveServers, boolean isJetty ); void doGet( HttpServletRequest request, HttpServletResponse response ); String toString(); String getService(); String getContextPath(); static final String XML_TAG_SLAVESERVER_DETECTIONS; static final String CONTEXT_PATH; }