@Test public void testInsertPersonalizeDetail() throws Exception { String userId = "1020"; // Verifying that the user does not exist assertThat(dao.getById(userId), nullValue()); final UserPreferences expectedDetail_1020 = new UserPreferences( userId, "fr", "Test", "WA500", false, false, false, UserMenuDisplay.BOOKMARKS); Transaction.performInOne(() -> dao.save(expectedDetail_1020)); UserPreferences detail = dao.getById(userId); assertThat(detail, notNullValue()); assertThat(detail, PersonalizationMatcher.matches(expectedDetail_1020)); assertThat(detail, PersonalizationMatcher.matches(actualUserPreferencesForUserId(userId))); userId = "1030"; final UserPreferences expectedDetail_1030 = new UserPreferences( userId, "en", "Silverpeas", "WA26", true, false, false, UserMenuDisplay.DISABLE); Transaction.performInOne(() -> dao.save(expectedDetail_1030)); detail = dao.getById(userId); assertThat(detail, notNullValue()); assertThat(detail, PersonalizationMatcher.matches(expectedDetail_1030)); assertThat(detail, PersonalizationMatcher.matches(actualUserPreferencesForUserId(userId))); userId = "1040"; final UserPreferences expectedDetail_1040 = new UserPreferences( userId, "de", "Silverpeas_V", "WA38", false, true, false, UserMenuDisplay.ALL); Transaction.performInOne(() -> dao.save(expectedDetail_1040)); detail = dao.getById(userId); assertThat(detail, notNullValue()); assertThat(detail, PersonalizationMatcher.matches(expectedDetail_1040)); assertThat(detail, PersonalizationMatcher.matches(actualUserPreferencesForUserId(userId))); userId = "1050"; final UserPreferences expectedDetail_1050 = new UserPreferences( userId, "dl", "Silverpeas_V6", "WA38", false, false, true, UserMenuDisplay.DEFAULT); Transaction.performInOne(() -> dao.save(expectedDetail_1050)); detail = dao.getById(userId); assertThat(detail, notNullValue()); assertThat(detail, PersonalizationMatcher.matches(expectedDetail_1050)); assertThat(detail, PersonalizationMatcher.matches(actualUserPreferencesForUserId(userId))); }
@Test public void testReadByPrimaryKeyUnexistingUser() throws Exception { Transaction.performInOne( () -> { ExternalAccount account = service.getExternalAccount(SocialNetworkID.LINKEDIN, "1233"); assertThat(account, nullValue()); return null; }); }
@Test @Transactional public void testCreateExternalAccount() throws Exception { Transaction.performInOne( () -> { service.createExternalAccount(SocialNetworkID.FACEBOOK, "13", "1345"); return null; }); ExternalAccount account = service.getExternalAccount(SocialNetworkID.FACEBOOK, "1345"); assertThat(account, is(notNullValue())); assertThat(account.getSilverpeasUserId(), is("13")); }
@Test public void testDeletePersonalizeDetail() throws Exception { String userId = "1000"; final UserPreferences expectedDetail = actualUserPreferencesForUserId(userId); UserPreferences detail = dao.getById(userId); assertThat(detail, notNullValue()); assertThat(detail, PersonalizationMatcher.matches(expectedDetail)); Transaction.performInOne( () -> { dao.delete(expectedDetail); return null; }); assertThat(dao.getById(userId), nullValue()); assertThat(actualUserPreferencesForUserId(userId), nullValue()); }
@Test public void testUpdatePersonalizeDetail() throws Exception { String userId = "1000"; final UserPreferences expectedDetail = actualUserPreferencesForUserId(userId); UserPreferences detail = dao.getById(userId); assertThat(detail, notNullValue()); assertThat(detail, PersonalizationMatcher.matches(expectedDetail)); assertThat(expectedDetail.getLanguage(), is(not("DUMMY"))); expectedDetail.setLanguage("DUMMY"); Transaction.performInOne(() -> dao.save(expectedDetail)); UserPreferences actual = actualUserPreferencesForUserId(userId); assertThat(actual, notNullValue()); assertThat(actual, PersonalizationMatcher.matches(expectedDetail)); assertThat(actual.getLanguage(), is("DUMMY")); }