UpgradeRestService { @POST @Path( "/rollback" ) public Response rollback( RollbackSpec rollbackSpec ) throws HMSRestException { UpgradeUtil.validateRollbackRequest( rollbackSpec ); boolean rollbackInitiated = UpgradeUtil.rollbackUpgrade( rollbackSpec ); if ( rollbackInitiated ) { BaseResponse response = new BaseResponse( Status.ACCEPTED.getStatusCode(), Status.ACCEPTED.getReasonPhrase(), "Rollback of upgrade initiated." ); return Response.accepted().entity( response ).build(); } else { throw new HMSRestException( Status.INTERNAL_SERVER_ERROR.getStatusCode(), Status.INTERNAL_SERVER_ERROR.getReasonPhrase(), "Initiating rollback of upgrade failed." ); } }  @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 );  }
@Test public void testRollbackWithNullSpec() { HMSRestException e = rollback( null ); message = "HMS rollback upgrade request should have the mandatory parameters - [ id ]."; assertEquals( e.getResponseErrorCode(), Status.BAD_REQUEST.getStatusCode() ); assertEquals( message, e.getReason() ); }
@Test public void testRollbackWithNullHmsToken() { rollbackSpec.setId( null ); HMSRestException e = rollback( rollbackSpec ); assertNotNull( e ); assertEquals( e.getResponseErrorCode(), Status.BAD_REQUEST.getStatusCode() ); message = "'id' is a mandatory parameter for HMS Upgrade rollback."; assertEquals( message, e.getReason() ); }
@Test public void testRollbackWithBlankHmsToken() { rollbackSpec.setId( " " ); HMSRestException e = rollback( rollbackSpec ); assertNotNull( e ); assertEquals( e.getResponseErrorCode(), Status.BAD_REQUEST.getStatusCode() ); message = "'id' is a mandatory parameter for HMS Upgrade rollback."; assertEquals( message, e.getReason() ); }