UpgradeRestService { @POST @Path( "/proxy/restart/{upgradeId}" ) public Response restartProxy( @PathParam( "upgradeId" ) String upgradeId ) throws HMSRestException { if ( StringUtils.isNotBlank( upgradeId ) ) { String upgradeBaseDir = HmsConfigHolder.getHMSConfigProperty( Constants.HMS_UPGRADE_DIR ); String scriptLocation = upgradeBaseDir + Constants.FILE_SEPERATOR + upgradeId + Constants.FILE_SEPERATOR + RESTART_PROXY_SCRIPT; logger.debug( "starts executing the script: {}", scriptLocation ); List<String> cmdWithArgs = new ArrayList<String>(); cmdWithArgs.add( 0, scriptLocation ); int exitCode = ProcessUtil.executeCommand( cmdWithArgs ); if ( exitCode != 0 ) { logger.error( "unsuccessful on executing the script, exit value {}", exitCode ); throw new HMSRestException( Status.INTERNAL_SERVER_ERROR.getStatusCode(), "unsuccessful on executing the script", "exit code: " + exitCode ); } logger.debug( "successfully completed executing the script: {}", scriptLocation ); } else { logger.error( "upgrade token can't be blank" ); throw new HMSRestException( Status.BAD_REQUEST.getStatusCode(), "upgrade token is blank", "Invalid input provided" ); } BaseResponse baseResponse = HmsGenericUtil.getBaseResponse( Status.ACCEPTED, "restart proxy initiated." ); return Response.accepted().entity( baseResponse ).build(); }  @POST Response upgrade( OobUpgradeSpec upgradeSpec ); @POST @Path( "/rollback" ) Response rollback( RollbackSpec rollbackSpec ); @POST @Path( "/upload" ) @Consumes( MediaType.MULTIPART_FORM_DATA ) Response uploadFile( MultipartFormDataInput multipartFormDataInput ); @GET @Path( "/monitor/{upgradeId}" ) Response getUpgradeStatus( @PathParam( "upgradeId" ) String upgradeId ); @DELETE @Path( "/backup/{upgradeId}" ) Response deleteBackup( @PathParam( "upgradeId" ) String upgradeId ); @POST @Path( "/proxy/restart/{upgradeId}" ) Response restartProxy( @PathParam( "upgradeId" ) String upgradeId ); @GET @Path( "/download/inventory/{upgradeId}" ) File downloadInventoryFile( @PathParam( "upgradeId" ) String upgradeId );  }
@SuppressWarnings( "unchecked" ) @Test public void testRestartProxyOnSuccessfulExecOfScript() throws HMSRestException { PowerMockito.mockStatic( ProcessUtil.class ); when( ProcessUtil.executeCommand( ( any( List.class ) ) ) ).thenReturn( 0 ); Response response = service.restartProxy( "100" ); assertNotNull( response ); assertTrue( response.getStatus() == Status.ACCEPTED.getStatusCode() ); }
@SuppressWarnings( "unchecked" ) @Test( expected = HMSRestException.class ) public void testRestartProxyOnUnsuccessfulExecOfScript() throws HMSRestException { PowerMockito.mockStatic( ProcessUtil.class ); when( ProcessUtil.executeCommand( ( any( List.class ) ) ) ).thenReturn( 1 ); service.restartProxy( "100" ); }