PhoneRecordAPIResource { @POST @Path("register/{user}/{phoneNumber}") @Produces(MediaType.APPLICATION_JSON) @OAuthSecurity(enabled = true) @ApiOperation(value = "Start user-phone bind process", notes = "Saves the user's data in a database and than send an SMS message with a code for a user to punch in and return", httpMethod = "POST", response = Void.class ) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK"), @ApiResponse(code = 400, message = "Invalid parameter", response = Void.class), @ApiResponse(code = 500, message = "Failed to access the registration database", response = Void.class) }) public Map<String, Object> registerPhone(@PathParam("user") String userName, @PathParam("phoneNumber") String phoneNumber) { userName = userName == null ? "" : userName.trim(); phoneNumber = phoneNumber == null ? "" : phoneNumber.trim(); if (userName.isEmpty() || phoneNumber.isEmpty()) { logger.fine(String.format("Parameter error user [%s] or phone [%s] are empty", userName, phoneNumber)); throw new BadRequestException(String.format("Parameter error user [%s] or phone [%s] are empty", userName, phoneNumber)); } final String validationRecord = getValidationRecord(6); try { final RegistrationRecord s = data.fetchByUserName(userName, false); if (s != null) { data.update(new RegistrationRecord(s.getKey(), userName, phoneNumber, validationRecord, true)); } else { data.update(new RegistrationRecord(-1, userName, phoneNumber, validationRecord, true)); } } catch (Throwable t) { logger.log(Level.SEVERE, "Failed to update the database", t); throw new InternalServerErrorException("Failed to update"); } final String prefix = getValidationRecord(3); final Map<String, Object> rc = new HashMap<>(); rc.put("status", true); rc.put("prefix", prefix); return rc; }  @POST @Path("/{to}") @Consumes(value = MediaType.APPLICATION_FORM_URLENCODED) @OAuthSecurity(enabled = true) @ApiOperation(value = "Send an SMS message", notes = "Send an SMS message using the configured Twilio servoce", httpMethod = "POST", response = Void.class ) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK", response = Void.class), @ApiResponse(code = 400, message = "Invalid parameter", response = Void.class), @ApiResponse(code = 500, message = "Failed to access the Twilio service", response = Void.class) }) void sendSMS(@PathParam("to") String to, @QueryParam("body") String body); @POST @Path("register/{user}/{phoneNumber}") @Produces(MediaType.APPLICATION_JSON) @OAuthSecurity(enabled = true) @ApiOperation(value = "Start user-phone bind process", notes = "Saves the user's data in a database and than send an SMS message with a code for a user to punch in and return", httpMethod = "POST", response = Void.class ) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK"), @ApiResponse(code = 400, message = "Invalid parameter", response = Void.class), @ApiResponse(code = 500, message = "Failed to access the registration database", response = Void.class) }) Map<String, Object> registerPhone(@PathParam("user") String userName, @PathParam("phoneNumber") String phoneNumber); @POST @Path("validate/{user}/{code}") @Consumes(value = MediaType.APPLICATION_FORM_URLENCODED) @OAuthSecurity(enabled = true) @ApiOperation(value = "Start user-phone bind process", notes = "Saves the user's data in a database and than send an SMS message with a code for a user to punch in and return", httpMethod = "POST", response = Void.class ) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK", response = Void.class), @ApiResponse(code = 400, message = "Invalid parameter", response = Void.class), @ApiResponse(code = 500, message = "Failed to access the registration database", response = Void.class) }) void validateUserPhone(@PathParam("user") String userName, @PathParam("code") String validationCode);  }
@Test public void testEmptyParams() { try { res.registerPhone("", "12345678"); fail("Should throw an exception"); } catch(Exception e) { e.printStackTrace(); } }