@Override public void execute() { UserAccount result = _accountService.getUserByApiKey(getApiKey()); if (result != null) { UserResponse response = _responseGenerator.createUserResponse(result); response.setResponseName(getCommandName()); response.setResponseName(getCommandName()); this.setResponseObject(response); } else { throw new InvalidParameterValueException("User with specified API key does not exist"); } } }
@Test(expected = InvalidParameterValueException.class) public void testExecuteWithUnknownApikey() { userAccount = null; when(accountService.getUserByApiKey(null)).thenReturn(userAccount); getUserCmd.execute(); }
@Test public void testExecuteWithDefault() { final String secretKey = "Very secret key"; UserResponse response = new UserResponse(); response.setSecretKey(secretKey); when(accountService.getUserByApiKey(null)).thenReturn(userAccount); when(responseGenerator.createUserResponse(userAccount)).thenReturn(response); getUserCmd.execute(); response = (UserResponse) getUserCmd.getResponseObject(); assertFalse("SecretKey was revealed in ResponseObject, wasn't masked", secretKey.equals(response.getSecretKey())); } }
@Override public void execute() { final UserAccount result = _accountService.getUserByApiKey(getApiKey()); if (result != null) { final UserResponse response = _responseGenerator.createUserResponse(result); if (StringUtils.isNotBlank(response.getSecretKey())) { response.setSecretKey("SecretKey only visible when generating a new key"); } response.setResponseName(getCommandName()); this.setResponseObject(response); } else { throw new InvalidParameterValueException("User with specified API key does not exist"); } }