@Test public void testCreateSuccess() { AccountService accountService = Mockito.mock(AccountService.class); Account account = Mockito.mock(Account.class); Mockito.when(accountService.getAccount(Matchers.anyLong())).thenReturn(account); addVpnUserCmd._accountService = accountService; RemoteAccessVpnService ravService = Mockito.mock(RemoteAccessVpnService.class); VpnUser vpnUser = Mockito.mock(VpnUser.class); Mockito.when(ravService.addVpnUser(Matchers.anyLong(), Matchers.anyString(), Matchers.anyString())).thenReturn(vpnUser); addVpnUserCmd._ravService = ravService; addVpnUserCmd.create(); }
@Test public void testCreateFailure() { AccountService accountService = Mockito.mock(AccountService.class); Account account = Mockito.mock(Account.class); Mockito.when(accountService.getAccount(Matchers.anyLong())).thenReturn(account); addVpnUserCmd._accountService = accountService; RemoteAccessVpnService ravService = Mockito.mock(RemoteAccessVpnService.class); Mockito.when(ravService.addVpnUser(Matchers.anyLong(), Matchers.anyString(), Matchers.anyString())).thenReturn(null); addVpnUserCmd._ravService = ravService; try { addVpnUserCmd.create(); } catch (ServerApiException exception) { Assert.assertEquals("Failed to add vpn user", exception.getDescription()); } }
@Override public void create() { Account owner = _accountService.getAccount(getEntityOwnerId()); VpnUser vpnUser = _ravService.addVpnUser(owner.getId(), userName, password); if (vpnUser == null) { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add vpn user"); } setEntityId(vpnUser.getId()); setEntityUuid(vpnUser.getUuid()); } }
@Test public void testCreateSuccess() { final AccountService accountService = Mockito.mock(AccountService.class); final Account account = Mockito.mock(Account.class); Mockito.when(accountService.getAccount(Matchers.anyLong())).thenReturn(account); addVpnUserCmd._accountService = accountService; final RemoteAccessVpnService ravService = Mockito.mock(RemoteAccessVpnService.class); final VpnUser vpnUser = Mockito.mock(VpnUser.class); Mockito.when(ravService.addVpnUser(Matchers.anyLong(), Matchers.anyString(), Matchers.anyString())).thenReturn(vpnUser); addVpnUserCmd._ravService = ravService; addVpnUserCmd.create(); }
@Test public void testCreateFailure() { final AccountService accountService = Mockito.mock(AccountService.class); final Account account = Mockito.mock(Account.class); Mockito.when(accountService.getAccount(Matchers.anyLong())).thenReturn(account); addVpnUserCmd._accountService = accountService; final RemoteAccessVpnService ravService = Mockito.mock(RemoteAccessVpnService.class); Mockito.when(ravService.addVpnUser(Matchers.anyLong(), Matchers.anyString(), Matchers.anyString())).thenReturn(null); addVpnUserCmd._ravService = ravService; try { addVpnUserCmd.create(); } catch (final ServerApiException exception) { Assert.assertEquals("Failed to add vpn user", exception.getDescription()); } } }
@Override public void create() { final Account owner = _accountService.getAccount(getEntityOwnerId()); final VpnUser vpnUser = _ravService.addVpnUser(owner.getId(), userName, password); if (vpnUser == null) { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add vpn user"); } setEntityId(vpnUser.getId()); setEntityUuid(vpnUser.getUuid()); } }