@Test(dataProvider = "invalidRegisterTestData") public void register_withInvalidArguments_shouldThrowClientException( String login, String password, ExceptionBody exceptionBody) throws GeneralSecurityException { UserResource sut = createSystemUnderTest(null, null, null, null); try { sut.register(login, password); } catch (ClientException ex) { assertEquals(ex.getResponse().getEntity(), exceptionBody); return; } fail(); }
@Override public void init(Context context, Request request, Response response) { super.init(context, request, response); getVariants().add(new Variant(TEXT_XML)); getVariants().add(new Variant(APPLICATION_JSON)); m_entryId = (String) getRequest().getAttributes().get("entryId"); }
@Override public void init(Context context, Request request, Response response) { super.init(context, request, response); String domain = m_domainManager.getDomain().getName(); String to = (String) getRequest().getAttributes().get("to"); m_from = getUser().getAddrSpec(domain); m_to = SipUri.fix(to, domain); }
@Override public void init(Context context, Request request, Response response) { super.init(context, request, response); getVariants().add(new Variant(TEXT_XML)); getVariants().add(new Variant(APPLICATION_JSON)); // pull parameters from url m_form = getRequest().getResourceRef().getQueryAsForm(); }
@Test public void register_ifLoginIsAlreadyTaken_shouldThrowClientException() throws GeneralSecurityException { UserRepository userRepository = mock(UserRepository.class); UserResource sut = createSystemUnderTest(userRepository, null, null, null); String login = "******"; String password = "******"; User user = new UserFactory(mock(StringGenerator.class), mock(PasswordEncrypter.class)) .create(login, password); when(userRepository.getByLogin(login)).thenReturn(user); try { sut.register(login, password); } catch (ClientException ex) { assertEquals(ex.getResponse().getEntity(), new ExceptionBody("Login is already taken")); return; } fail(); }
@Test public void login_ifPasswordIsNotCorrect_shouldThrowClientException() throws GeneralSecurityException { final String password = "******"; final String login = "******"; UserFactory userFactoryStub = mock(UserFactory.class); when(userFactoryStub.create(any(String.class), any(String.class))).thenReturn(new User(login)); User user = userFactoryStub.create(login, password); user.setPasswordHash(password); UserRepository repositoryStub = mock(UserRepository.class); when(repositoryStub.getByLogin(login)).thenReturn(user); UserResource sut = createSystemUnderTest(repositoryStub, null, userFactoryStub, null); try { sut.login("foo", "bzr"); } catch (ClientException e) { assertEquals(e.getResponse().getEntity(), new ExceptionBody("Password is not correct")); return; } fail(); }
@Test public void register_thisTestWorksWell() throws GeneralSecurityException { UserResource sut = createSystemUnderTest(null, null, null, null); Response resp = sut.register("foo", "bar"); assertEquals(resp.getStatus(), Response.Status.OK.getStatusCode()); }
public void login(String username, String password) { user.login(username, password); }