protected void assertEqualsAccount(HumanAccountData expected, AccountServiceData actual) { assertEquals(expected.getId().getAddress(), actual.id); }
public void testGetAccountNotLoggedUser() throws InvalidParticipantAddress, PersistenceException, IOException { // Mock data accountStore.putAccount(ACCOUNT_JOE); when(sessionManager.getLoggedInUser((HttpSession) anyObject())).thenReturn(ACCOUNT_MAT.getId()); when(sessionManager.getLoggedInUser((HttpServletRequest) anyObject())).thenReturn( ACCOUNT_MAT.getId()); // Test AccountServiceData requestData = new AccountServiceData(); ByteArrayOutputStream responseStream = new ByteArrayOutputStream(); executeService("/account/joe", "GET", requestData, responseStream, HttpServletResponse.SC_OK); AccountServiceData responseData = (AccountServiceData) ServiceData.fromJson(responseStream.toString("UTF-8"), AccountServiceData.class); assertNull(responseData.email); assertEquals(ACCOUNT_JOE.getLocale(), responseData.locale); assertTrue(responseData.avatarUrl.contains("image.png")); }
public void testGetAccount() throws InvalidParticipantAddress, PersistenceException, IOException { // Mock data accountStore.putAccount(ACCOUNT_JOE); when(sessionManager.getLoggedInUser((HttpSession) anyObject())).thenReturn(ACCOUNT_JOE.getId()); when(sessionManager.getLoggedInUser((HttpServletRequest) anyObject())).thenReturn( ACCOUNT_JOE.getId()); // Test AccountServiceData requestData = new AccountServiceData(); ByteArrayOutputStream responseStream = new ByteArrayOutputStream(); executeService("/account/joe", "GET", requestData, responseStream, HttpServletResponse.SC_OK); AccountServiceData responseData = (AccountServiceData) ServiceData.fromJson(responseStream.toString("UTF-8"), AccountServiceData.class); assertEquals(ACCOUNT_JOE.getEmail(), responseData.email); assertEquals(ACCOUNT_JOE.getLocale(), responseData.locale); assertTrue(responseData.avatarUrl.contains("image.png")); }
public void testUpdateAccount() throws PersistenceException, InvalidParticipantAddress, IOException { // Mock data accountStore.putAccount(ACCOUNT_JOE); when(sessionManager.getLoggedInUser((HttpSession) anyObject())).thenReturn(ACCOUNT_JOE.getId()); when(sessionManager.getLoggedInUser((HttpServletRequest) anyObject())).thenReturn( ACCOUNT_JOE.getId()); // Test AccountServiceData requestData = new AccountServiceData(); requestData.email = "joe@email.example.com"; requestData.locale = "es_ES"; requestData.password = "_password_"; requestData.avatarData = IMAGE_BASE64; ByteArrayOutputStream responseStream = new ByteArrayOutputStream(); executeService("/account/joe", "POST", requestData, responseStream, HttpServletResponse.SC_OK); AccountServiceData responseData = (AccountServiceData) ServiceData.fromJson(responseStream.toString("UTF-8"), AccountServiceData.class); assertEquals(requestData.email, responseData.email); assertEquals(requestData.locale, responseData.locale); assertTrue(responseData.avatarUrl.contains("image.png")); }
public void testQueryAccounts() throws PersistenceException, IOException { // Mock data accountStore.putAccount(ACCOUNT_JOE); accountStore.putAccount(ACCOUNT_TOM); accountStore.putAccount(ACCOUNT_MAT); when(sessionManager.getLoggedInUser((HttpSession) anyObject())).thenReturn(ACCOUNT_MAT.getId()); when(sessionManager.getLoggedInUser((HttpServletRequest) anyObject())).thenReturn( ACCOUNT_MAT.getId()); when(sessionManager.listLoggedInUsers((HttpServletRequest) anyObject())).thenReturn(CollectionUtils.immutableSet(ACCOUNT_MAT.getId())); // Test AccountServiceData requestData = new AccountServiceData(); ByteArrayOutputStream responseStream = new ByteArrayOutputStream(); executeService("/account", "GET", requestData, responseStream, HttpServletResponse.SC_OK, ImmutableMap.<String, String> of("p", "joe@example.com;tom@example.com;mike@example.com;mat@example.com")); AccountServiceData[] responseData = (AccountServiceData[]) ServiceData.arrayFromJson(responseStream.toString("UTF-8"), AccountServiceData[].class); assertEquals(4, responseData.length); // We expect results in the same order as query assertEqualsAccount(ACCOUNT_JOE, responseData[0]); assertEqualsAccount(ACCOUNT_TOM, responseData[1]); assertEqualsAccount(ACCOUNT_MIKE, responseData[2]); assertEqualsAccount(ACCOUNT_MAT, responseData[3]); }
public void testUserAddressReturnsCorrectResult() { ParticipantId id = ParticipantId.ofUnsafe("drhorrible@example.com"); HumanAccountData account = new HumanAccountDataImpl(id); assertEquals(account.getId(), id); assertTrue(account.isHuman()); assertFalse(account.isRobot()); }
public void testUserAddressReturnsCorrectResult() { ParticipantId id = ParticipantId.ofUnsafe("drhorrible@example.com"); HumanAccountData account = new HumanAccountDataImpl(id); assertEquals(account.getId(), id); assertTrue(account.isHuman()); assertFalse(account.isRobot()); }