Example usage for org.apache.commons.lang3.time DateUtils addDays

List of usage examples for org.apache.commons.lang3.time DateUtils addDays

Introduction

In this page you can find the example usage for org.apache.commons.lang3.time DateUtils addDays.

Prototype

public static Date addDays(final Date date, final int amount) 

Source Link

Document

Adds a number of days to a date returning a new object.

Usage

From source file:org.silverpeas.components.gallery.dao.MediaDaoIT.java

@Test
public void getSocialInformationListOfMyContacts() throws Exception {
    Date beginDate = DateUtils.addDays(CREATE_DATE, +1);
    Date endDate = DateUtils.addDays(CREATE_DATE, +2);
    List<SocialInformation> socialInformationList = MediaDAO.getSocialInformationListOfMyContacts(
            Arrays.asList(writerUser.getId(), adminAccessUser.getId(), publisherUser.getId()),
            Arrays.asList(INSTANCE_A, "otherInstanceId"), Period.from(beginDate, endDate));
    assertThat(socialInformationList, hasSize(3));

    beginDate = DateUtils.addDays(CREATE_DATE, 0);
    endDate = DateUtils.addDays(CREATE_DATE, +2);
    socialInformationList = MediaDAO.getSocialInformationListOfMyContacts(
            Arrays.asList(writerUser.getId(), adminAccessUser.getId(), publisherUser.getId()),
            Arrays.asList(INSTANCE_A, "otherInstanceId"), Period.from(beginDate, endDate));
    assertThat(socialInformationList, hasSize(7));

    beginDate = DateUtils.addDays(LAST_UPDATE_DATE, -2);
    endDate = DateUtils.addDays(LAST_UPDATE_DATE, +2);
    socialInformationList = MediaDAO.getSocialInformationListOfMyContacts(
            Arrays.asList(writerUser.getId(), adminAccessUser.getId(), publisherUser.getId()),
            Arrays.asList(INSTANCE_A, "otherInstanceId"), Period.from(beginDate, endDate));
    assertThat(socialInformationList, hasSize(7));
}

From source file:org.silverpeas.components.gallery.dao.MediaDaoIT.java

@Test
public void saveNewPhoto() throws Exception {
    Date now = DateUtil.getNow();
    Date beginVisibilityDate = DateUtils.addMonths(now, -1);
    Date endVisibilityDate = DateUtils.addMonths(now, 4);
    Date beginDownloadDate = DateUtils.addDays(now, -10);
    Date endDownloadDate = DateUtils.addDays(now, 5);

    Photo newPhoto = new Photo();

    newPhoto.setComponentInstanceId(INSTANCE_A);
    newPhoto.setTitle("A title");
    newPhoto.setDescription("A description");
    newPhoto.setAuthor("An author");
    newPhoto.setKeyWord("keywords");
    newPhoto.setVisibilityPeriod(Period.from(beginVisibilityDate, endVisibilityDate));

    newPhoto.setFileName("new file name");
    newPhoto.setFileSize(2048);/*from ww  w.j a  v  a 2 s. co  m*/
    newPhoto.setFileMimeType(MediaMimeType.TIFF);
    newPhoto.setDownloadAuthorized(true);
    newPhoto.setDownloadPeriod(Period.from(beginDownloadDate, endDownloadDate));

    newPhoto.setDefinition(Definition.of(200, 100));

    assertThat(newPhoto.getId(), nullValue());
    String newId = Transaction
            .performInOne(() -> MediaDAO.saveMedia(OperationContext.fromUser(adminAccessUser), newPhoto));
    assertThat(newPhoto.getId(), notNullValue());
    assertThat(newPhoto.getId(), is(newId));

    try (Connection connection = getConnection()) {
        IDataSet actualDataSet = getActualDataSet(connection);
        ITable mediaTable = actualDataSet.getTable("SC_Gallery_Media");
        assertThat(mediaTable.getRowCount(), is(MEDIA_ROW_COUNT + 1));
        ITable internalTable = actualDataSet.getTable("SC_Gallery_Internal");
        assertThat(internalTable.getRowCount(), is(MEDIA_INTERNAL_ROW_COUNT + 1));
        ITable photoTable = actualDataSet.getTable("SC_Gallery_Photo");
        assertThat(photoTable.getRowCount(), is(MEDIA_PHOTO_ROW_COUNT + 1));
        ITable videoTable = actualDataSet.getTable("SC_Gallery_Video");
        assertThat(videoTable.getRowCount(), is(MEDIA_VIDEO_ROW_COUNT));
        ITable soundTable = actualDataSet.getTable("SC_Gallery_Sound");
        assertThat(soundTable.getRowCount(), is(MEDIA_SOUND_ROW_COUNT));
        ITable streamingTable = actualDataSet.getTable("SC_Gallery_Streaming");
        assertThat(streamingTable.getRowCount(), is(MEDIA_STREAMING_ROW_COUNT));
        ITable pathTable = actualDataSet.getTable("SC_Gallery_Path");
        assertThat(pathTable.getRowCount(), is(MEDIA_PATH_ROW_COUNT));

        TableRow mediaRow = getTableRowFor(mediaTable, "mediaId", newPhoto.getId());
        assertThat(mediaRow.getString("mediaId"), is(newId));
        assertThat(mediaRow.getString("mediaType"), is(MediaType.Photo.name()));
        assertThat(mediaRow.getString("instanceId"), is(INSTANCE_A));
        assertThat(mediaRow.getString("title"), is("A title"));
        assertThat(mediaRow.getString("description"), is("A description"));
        assertThat(mediaRow.getString("author"), is("An author"));
        assertThat(mediaRow.getString("keyword"), is("keywords"));
        assertThat(mediaRow.getLong("beginVisibilityDate"), is(beginVisibilityDate.getTime()));
        assertThat(mediaRow.getLong("endVisibilityDate"), is(endVisibilityDate.getTime()));
        assertThat(mediaRow.getDate("createDate"), greaterThanOrEqualTo(now));
        assertThat(mediaRow.getString("createdBy"), is(adminAccessUser.getId()));
        assertThat(mediaRow.getDate("lastUpdateDate"), is(mediaRow.getDate("createDate")));
        assertThat(mediaRow.getString("lastUpdatedBy"), is(adminAccessUser.getId()));

        TableRow iMediaRow = getTableRowFor(internalTable, "mediaId", newPhoto.getId());
        assertThat(iMediaRow.getString("mediaId"), is(newId));
        assertThat(iMediaRow.getString("fileName"), is("new file name"));
        assertThat(iMediaRow.getLong("fileSize"), is(2048L));
        assertThat(iMediaRow.getString("fileMimeType"), is("image/tiff"));
        assertThat(iMediaRow.getInteger("download"), is(1));
        assertThat(iMediaRow.getLong("beginDownloadDate"), is(beginDownloadDate.getTime()));
        assertThat(iMediaRow.getLong("endDownloadDate"), is(endDownloadDate.getTime()));

        TableRow photoRow = getTableRowFor(photoTable, "mediaId", newPhoto.getId());
        assertThat(photoRow.getString("mediaId"), is(newId));
        assertThat(photoRow.getInteger("resolutionH"), is(100));
        assertThat(photoRow.getInteger("resolutionW"), is(200));
    }
}

From source file:org.silverpeas.components.gallery.dao.MediaDaoIT.java

@Test
public void saveExistingPhoto() throws Exception {
    Date now = DateUtil.getNow();
    Date endVisibilityDate = DateUtils.addMonths(now, 4);
    Date beginDownloadDate = DateUtils.addDays(now, -10);

    String mediaIdToUpdate = "2";

    try (Connection connection = getConnection()) {
        IDataSet actualDataSet = getActualDataSet(connection);
        ITable mediaTable = actualDataSet.getTable("SC_Gallery_Media");
        assertThat(mediaTable.getRowCount(), is(MEDIA_ROW_COUNT));
        ITable internalTable = actualDataSet.getTable("SC_Gallery_Internal");
        assertThat(internalTable.getRowCount(), is(MEDIA_INTERNAL_ROW_COUNT));
        ITable photoTable = actualDataSet.getTable("SC_Gallery_Photo");
        assertThat(photoTable.getRowCount(), is(MEDIA_PHOTO_ROW_COUNT));
        ITable videoTable = actualDataSet.getTable("SC_Gallery_Video");
        assertThat(videoTable.getRowCount(), is(MEDIA_VIDEO_ROW_COUNT));
        ITable soundTable = actualDataSet.getTable("SC_Gallery_Sound");
        assertThat(soundTable.getRowCount(), is(MEDIA_SOUND_ROW_COUNT));
        ITable streamingTable = actualDataSet.getTable("SC_Gallery_Streaming");
        assertThat(streamingTable.getRowCount(), is(MEDIA_STREAMING_ROW_COUNT));
        ITable pathTable = actualDataSet.getTable("SC_Gallery_Path");
        assertThat(pathTable.getRowCount(), is(MEDIA_PATH_ROW_COUNT));

        TableRow mediaRow = getTableRowFor(mediaTable, "mediaId", mediaIdToUpdate);
        assertThat(mediaRow.getString("mediaId"), is(mediaIdToUpdate));
        assertThat(mediaRow.getString("mediaType"), is(MediaType.Photo.name()));
        assertThat(mediaRow.getString("instanceId"), is(INSTANCE_A));
        assertThat(mediaRow.getString("title"), is("title 2"));
        assertThat(mediaRow.getValue("description"), nullValue());
        assertThat(mediaRow.getValue("author"), nullValue());
        assertThat(mediaRow.getValue("keyword"), nullValue());
        assertThat(mediaRow.getLong("beginVisibilityDate"), is(DateUtil.MINIMUM_DATE.getTime()));
        assertThat(mediaRow.getLong("endVisibilityDate"), is(DateUtil.MAXIMUM_DATE.getTime()));
        assertThat(mediaRow.getDate("createDate"), is(CREATE_DATE));
        assertThat(mediaRow.getString("createdBy"), is("0"));
        assertThat(mediaRow.getDate("lastUpdateDate"), is(CREATE_DATE));
        assertThat(mediaRow.getString("lastUpdatedBy"), is("0"));

        TableRow iMediaRow = getTableRowFor(internalTable, "mediaId", mediaIdToUpdate);
        assertThat(iMediaRow.getString("mediaId"), is(mediaIdToUpdate));
        assertThat(iMediaRow.getString("fileName"), is("fileName_2"));
        assertThat(iMediaRow.getLong("fileSize"), is(102L));
        assertThat(iMediaRow.getString("fileMimeType"), is("image/png"));
        assertThat(iMediaRow.getInteger("download"), is(0));
        assertThat(iMediaRow.getValue("beginDownloadDate"), nullValue());
        assertThat(iMediaRow.getValue("endDownloadDate"), nullValue());

        TableRow photoRow = getTableRowFor(photoTable, "mediaId", mediaIdToUpdate);
        assertThat(photoRow.getString("mediaId"), is(mediaIdToUpdate));
        assertThat(photoRow.getInteger("resolutionH"), is(600));
        assertThat(photoRow.getInteger("resolutionW"), is(800));
    }/*from w ww. jav a 2  s . c  o  m*/

    Photo photoToUpdate = Transaction
            .performInOne(
                    () -> MediaDAO.getByCriteria(defaultMediaCriteria().identifierIsOneOf(mediaIdToUpdate)))
            .getPhoto();

    photoToUpdate.setTitle(photoToUpdate.getTitle() + "_updated");
    photoToUpdate.setKeyWord("keywords_updated");
    photoToUpdate.setVisibilityPeriod(Period.from(DateUtil.MINIMUM_DATE, endVisibilityDate));

    photoToUpdate.setFileName(photoToUpdate.getFileName() + "_updated");
    photoToUpdate.setFileSize(2048);
    photoToUpdate.setFileMimeType(MediaMimeType.TIFF);
    photoToUpdate.setDownloadAuthorized(true);
    photoToUpdate.setDownloadPeriod(Period.from(beginDownloadDate, DateUtil.MAXIMUM_DATE));

    photoToUpdate.setDefinition(Definition.of(200, 100));

    String savedMediaId = photoToUpdate.getId();
    String mediaId = Transaction
            .performInOne(() -> MediaDAO.saveMedia(OperationContext.fromUser(publisherUser), photoToUpdate));
    assertThat(mediaId, is(savedMediaId));
    assertThat(mediaId, is(photoToUpdate.getId()));

    try (Connection connection = getConnection()) {
        IDataSet actualDataSet = getActualDataSet(connection);
        ITable mediaTable = actualDataSet.getTable("SC_Gallery_Media");
        assertThat(mediaTable.getRowCount(), is(MEDIA_ROW_COUNT));
        ITable internalTable = actualDataSet.getTable("SC_Gallery_Internal");
        assertThat(internalTable.getRowCount(), is(MEDIA_INTERNAL_ROW_COUNT));
        ITable photoTable = actualDataSet.getTable("SC_Gallery_Photo");
        assertThat(photoTable.getRowCount(), is(MEDIA_PHOTO_ROW_COUNT));
        ITable videoTable = actualDataSet.getTable("SC_Gallery_Video");
        assertThat(videoTable.getRowCount(), is(MEDIA_VIDEO_ROW_COUNT));
        ITable soundTable = actualDataSet.getTable("SC_Gallery_Sound");
        assertThat(soundTable.getRowCount(), is(MEDIA_SOUND_ROW_COUNT));
        ITable streamingTable = actualDataSet.getTable("SC_Gallery_Streaming");
        assertThat(streamingTable.getRowCount(), is(MEDIA_STREAMING_ROW_COUNT));
        ITable pathTable = actualDataSet.getTable("SC_Gallery_Path");
        assertThat(pathTable.getRowCount(), is(MEDIA_PATH_ROW_COUNT));

        TableRow mediaRow = getTableRowFor(mediaTable, "mediaId", mediaIdToUpdate);
        assertThat(mediaRow.getString("mediaId"), is(mediaIdToUpdate));
        assertThat(mediaRow.getString("mediaType"), is(MediaType.Photo.name()));
        assertThat(mediaRow.getString("instanceId"), is(INSTANCE_A));
        assertThat(mediaRow.getString("title"), is("title 2_updated"));
        assertThat(mediaRow.getString("description"), isEmptyString());
        assertThat(mediaRow.getString("author"), isEmptyString());
        assertThat(mediaRow.getString("keyword"), is("keywords_updated"));
        assertThat(mediaRow.getLong("beginVisibilityDate"), is(DateUtil.MINIMUM_DATE.getTime()));
        assertThat(mediaRow.getLong("endVisibilityDate"), is(endVisibilityDate.getTime()));
        assertThat(mediaRow.getDate("createDate"), is(CREATE_DATE));
        assertThat(mediaRow.getString("createdBy"), is("0"));
        assertThat(mediaRow.getDate("lastUpdateDate"), greaterThanOrEqualTo(now));
        assertThat(mediaRow.getString("lastUpdatedBy"), is(publisherUser.getId()));

        TableRow iMediaRow = getTableRowFor(internalTable, "mediaId", mediaIdToUpdate);
        assertThat(iMediaRow.getString("mediaId"), is(mediaIdToUpdate));
        assertThat(iMediaRow.getString("fileName"), is("fileName_2_updated"));
        assertThat(iMediaRow.getLong("fileSize"), is(2048L));
        assertThat(iMediaRow.getString("fileMimeType"), is("image/tiff"));
        assertThat(iMediaRow.getInteger("download"), is(1));
        assertThat(iMediaRow.getLong("beginDownloadDate"), is(beginDownloadDate.getTime()));
        assertThat(iMediaRow.getValue("endDownloadDate"), nullValue());

        TableRow photoRow = getTableRowFor(photoTable, "mediaId", mediaIdToUpdate);
        assertThat(photoRow.getString("mediaId"), is(mediaIdToUpdate));
        assertThat(photoRow.getInteger("resolutionH"), is(100));
        assertThat(photoRow.getInteger("resolutionW"), is(200));
    }
}

From source file:org.silverpeas.components.gallery.dao.MediaDaoIT.java

@Test
public void saveNewVideo() throws Exception {
    Date now = DateUtil.getNow();
    Date beginVisibilityDate = DateUtils.addMonths(now, -1);
    Date endDownloadDate = DateUtils.addDays(now, 5);

    Video newVideo = new Video();

    newVideo.setComponentInstanceId(INSTANCE_A);
    newVideo.setTitle("A video title");
    newVideo.setAuthor("A video author");
    newVideo.setKeyWord("video keywords");
    newVideo.setVisibilityPeriod(Period.from(beginVisibilityDate, DateUtil.MAXIMUM_DATE));

    newVideo.setFileName("new video file name");
    newVideo.setFileSize(2048);/*from w w  w.  j  a v  a2  s  .c o  m*/
    newVideo.setFileMimeType(MediaMimeType.MP4);
    newVideo.setDownloadAuthorized(false);
    newVideo.setDownloadPeriod(Period.from(DateUtil.MINIMUM_DATE, endDownloadDate));

    newVideo.setDefinition(Definition.of(1920, 1080));

    assertThat(newVideo.getId(), nullValue());
    String newId = Transaction
            .performInOne(() -> MediaDAO.saveMedia(OperationContext.fromUser(writerUser), newVideo));
    assertThat(newVideo.getId(), notNullValue());
    assertThat(newVideo.getId(), is(newId));

    try (Connection connection = getConnection()) {
        IDataSet actualDataSet = getActualDataSet(connection);
        ITable mediaTable = actualDataSet.getTable("SC_Gallery_Media");
        assertThat(mediaTable.getRowCount(), is(MEDIA_ROW_COUNT + 1));
        ITable internalTable = actualDataSet.getTable("SC_Gallery_Internal");
        assertThat(internalTable.getRowCount(), is(MEDIA_INTERNAL_ROW_COUNT + 1));
        ITable photoTable = actualDataSet.getTable("SC_Gallery_Photo");
        assertThat(photoTable.getRowCount(), is(MEDIA_PHOTO_ROW_COUNT));
        ITable videoTable = actualDataSet.getTable("SC_Gallery_Video");
        assertThat(videoTable.getRowCount(), is(MEDIA_VIDEO_ROW_COUNT + 1));
        ITable soundTable = actualDataSet.getTable("SC_Gallery_Sound");
        assertThat(soundTable.getRowCount(), is(MEDIA_SOUND_ROW_COUNT));
        ITable streamingTable = actualDataSet.getTable("SC_Gallery_Streaming");
        assertThat(streamingTable.getRowCount(), is(MEDIA_STREAMING_ROW_COUNT));
        ITable pathTable = actualDataSet.getTable("SC_Gallery_Path");
        assertThat(pathTable.getRowCount(), is(MEDIA_PATH_ROW_COUNT));

        TableRow mediaRow = getTableRowFor(mediaTable, "mediaId", newVideo.getId());
        assertThat(mediaRow.getString("mediaId"), is(newId));
        assertThat(mediaRow.getString("mediaType"), is(MediaType.Video.name()));
        assertThat(mediaRow.getString("instanceId"), is(INSTANCE_A));
        assertThat(mediaRow.getString("title"), is("A video title"));
        assertThat(mediaRow.getString("description"), isEmptyString());
        assertThat(mediaRow.getString("author"), is("A video author"));
        assertThat(mediaRow.getString("keyword"), is("video keywords"));
        assertThat(mediaRow.getLong("beginVisibilityDate"), is(beginVisibilityDate.getTime()));
        assertThat(mediaRow.getLong("endVisibilityDate"), is(DateUtil.MAXIMUM_DATE.getTime()));
        assertThat(mediaRow.getDate("createDate"), greaterThanOrEqualTo(now));
        assertThat(mediaRow.getString("createdBy"), is(writerUser.getId()));
        assertThat(mediaRow.getDate("lastUpdateDate"), is(mediaRow.getDate("createDate")));
        assertThat(mediaRow.getString("lastUpdatedBy"), is(writerUser.getId()));

        TableRow iMediaRow = getTableRowFor(internalTable, "mediaId", newVideo.getId());
        assertThat(iMediaRow.getString("mediaId"), is(newId));
        assertThat(iMediaRow.getString("fileName"), is("new video file name"));
        assertThat(iMediaRow.getLong("fileSize"), is(2048L));
        assertThat(iMediaRow.getString("fileMimeType"), is("video/mp4"));
        assertThat(iMediaRow.getInteger("download"), is(0));
        assertThat(iMediaRow.getLong("beginDownloadDate"), nullValue());
        assertThat(iMediaRow.getLong("endDownloadDate"), is(endDownloadDate.getTime()));

        TableRow videoRow = getTableRowFor(videoTable, "mediaId", newVideo.getId());
        assertThat(videoRow.getString("mediaId"), is(newId));
        assertThat(videoRow.getInteger("resolutionH"), is(1080));
        assertThat(videoRow.getInteger("resolutionW"), is(1920));
        assertThat(videoRow.getLong("bitrate"), is(0L));
        assertThat(videoRow.getLong("duration"), is(0L));
    }
}

From source file:org.silverpeas.components.gallery.dao.MediaOrderSQLQueryBuilder.java

@Override
public MediaOrderCriteriaProcessor processNbDaysAfterThatDeleteAnOrder(final Date referenceDate,
        final int nbDaysAfterThatDeleteAnOrder) {
    if (!done) {//from   w  ww  .  j  av a 2 s  .  c o m
        where(conjunction).append("O.createDate < ?");
        parameters.add(DateUtils.addDays(referenceDate, -nbDaysAfterThatDeleteAnOrder));
        conjunction = "";
    }
    return this;
}

From source file:org.silverpeas.components.gallery.dao.MediaSQLQueryBuilder.java

@Override
public MediaCriteriaProcessor processNbDaysBeforeThatMediaIsNotVisible(final Date referenceDate,
        final int nbDaysBeforeThatMediaIsNotVisible) {
    if (!done) {//from www  .j  av  a 2s .  c  o  m
        where(conjunction).append("M.endVisibilityDate between ? and ?");
        DateTime date = new DateTime(DateUtils.addDays(referenceDate, nbDaysBeforeThatMediaIsNotVisible));
        parameters.add(date.getBeginOfDay().getTime());
        parameters.add(date.getEndOfDay().getTime());
        conjunction = "";
    }
    return this;
}

From source file:org.silverpeas.core.admin.UsersAndGroupsIT.java

@Test
public void shouldAddNewUser() throws Exception {
    Date now = new Date();
    Date tosAcceptanceDate = DateUtils.addDays(now, 1);
    Date lastLoginDate = DateUtils.addDays(now, 2);
    Date lastLoginCredentialUpdateDate = DateUtils.addDays(now, 3);
    Date expirationDate = DateUtils.addDays(now, 4);
    Date stateSaveDate = DateUtils.addDays(now, 5);

    UserDetail user = new UserDetail();
    user.setAccessLevel(UserAccessLevel.ADMINISTRATOR);
    user.setDomainId("0");
    user.seteMail("nicolas.eysseric@silverpeas.com");
    user.setFirstName("Nicolas");
    user.setLastName("EYSSERIC");
    user.setLogin("neysseri");
    user.setTosAcceptanceDate(tosAcceptanceDate);
    user.setLastLoginDate(lastLoginDate);
    user.setNbSuccessfulLoginAttempts(7);
    user.setLastLoginCredentialUpdateDate(lastLoginCredentialUpdateDate);
    user.setExpirationDate(expirationDate);
    user.setState(UserState.EXPIRED);// ww  w. ja v  a  2s .  c o m
    user.setStateSaveDate(stateSaveDate);

    String newUserId = "5";
    String userId = admin.addUser(user);
    assertThat(userId, is(newUserId));

    user = admin.getUserDetail(newUserId);
    assertThat(user.getAccessLevel(), is(UserAccessLevel.ADMINISTRATOR));
    assertThat(user.getSaveDate(), greaterThan(now));
    assertThat(user.getVersion(), is(0));
    assertThat(user.getTosAcceptanceDate().getTime(), is(tosAcceptanceDate.getTime()));
    assertThat(user.getLastLoginDate().getTime(), is(lastLoginDate.getTime()));
    assertThat(user.getNbSuccessfulLoginAttempts(), is(7));
    assertThat(user.getLastLoginCredentialUpdateDate().getTime(), is(lastLoginCredentialUpdateDate.getTime()));
    assertThat(user.getExpirationDate().getTime(), is(expirationDate.getTime()));
    assertThat(user.getState(), is(UserState.EXPIRED));
    assertThat(user.getStateSaveDate(), greaterThan(now));
}

From source file:org.silverpeas.core.admin.UsersAndGroupsIT.java

@Test
public void shouldUpdateUser() throws Exception {
    Date now = new Date();
    Date tosAcceptanceDate = DateUtils.addDays(now, 1);
    Date lastLoginDate = DateUtils.addDays(now, 2);
    Date lastLoginCredentialUpdateDate = DateUtils.addDays(now, 3);
    Date expirationDate = DateUtils.addDays(now, 4);
    Date stateSaveDate = DateUtils.addDays(now, 5);

    String updatedUserId = "1";
    UserDetail user = admin.getUserDetail(updatedUserId);

    assertThat(user.getAccessLevel(), is(UserAccessLevel.ADMINISTRATOR));
    assertThat(user.isAccessAdmin(), is(true));
    assertThat(user.isAccessDomainManager(), is(false));
    assertThat(user.isAccessSpaceManager(), is(false));
    assertThat(user.isAccessPdcManager(), is(false));
    assertThat(user.isAccessUser(), is(false));
    assertThat(user.isAccessGuest(), is(false));
    assertThat(user.getSaveDate(), nullValue());
    assertThat(user.getVersion(), is(0));
    assertThat(user.getTosAcceptanceDate(), nullValue());
    assertThat(user.getLastLoginDate(), nullValue());
    assertThat(user.getNbSuccessfulLoginAttempts(), is(0));
    assertThat(user.getLastLoginCredentialUpdateDate(), nullValue());
    assertThat(user.getExpirationDate(), nullValue());
    assertThat(user.getState(), is(UserState.VALID));
    assertThat(user.isExpiredState(), is(false));
    assertThat(user.getStateSaveDate(), lessThan(now));

    String newEmail = "ney@silverpeas.com";
    user.seteMail(newEmail);/*from www . j  a  va 2s. c om*/
    user.setAccessLevel(UserAccessLevel.USER);
    user.setTosAcceptanceDate(tosAcceptanceDate);
    user.setLastLoginDate(lastLoginDate);
    user.setNbSuccessfulLoginAttempts(7);
    user.setLastLoginCredentialUpdateDate(lastLoginCredentialUpdateDate);
    user.setExpirationDate(expirationDate);
    admin.updateUser(user);

    user = admin.getUserDetail(updatedUserId);
    assertThat(user.geteMail(), is(newEmail));
    assertThat(user.getAccessLevel(), is(UserAccessLevel.USER));
    assertThat(user.isAccessAdmin(), is(false));
    assertThat(user.isAccessDomainManager(), is(false));
    assertThat(user.isAccessSpaceManager(), is(false));
    assertThat(user.isAccessPdcManager(), is(false));
    assertThat(user.isAccessUser(), is(true));
    assertThat(user.isAccessGuest(), is(false));
    assertThat(user.getSaveDate(), greaterThan(now));
    assertThat(user.getVersion(), is(1));
    assertThat(user.getTosAcceptanceDate().getTime(), is(tosAcceptanceDate.getTime()));
    assertThat(user.getLastLoginDate().getTime(), is(lastLoginDate.getTime()));
    assertThat(user.getNbSuccessfulLoginAttempts(), is(7));
    assertThat(user.getLastLoginCredentialUpdateDate().getTime(), is(lastLoginCredentialUpdateDate.getTime()));
    assertThat(user.getExpirationDate().getTime(), is(expirationDate.getTime()));
    assertThat(user.getState(), is(UserState.VALID));
    assertThat(user.isExpiredState(), is(false));
    assertThat(user.isDeletedState(), is(false));
    assertThat(user.getStateSaveDate(), lessThan(now));

    expirationDate = DateUtils.addDays(now, -4);
    user.setExpirationDate(expirationDate);
    admin.updateUser(user);

    user = admin.getUserDetail(updatedUserId);
    assertThat(user.getVersion(), is(2));
    assertThat(user.isExpiredState(), is(true));

    user.setAccessLevel(UserAccessLevel.GUEST);
    user.setExpirationDate(null);
    user.setState(UserState.EXPIRED);
    user.setStateSaveDate(stateSaveDate);
    admin.updateUser(user);

    user = admin.getUserDetail(updatedUserId);
    assertThat(user.getAccessLevel(), is(UserAccessLevel.GUEST));
    assertThat(user.isAccessAdmin(), is(false));
    assertThat(user.isAccessDomainManager(), is(false));
    assertThat(user.isAccessSpaceManager(), is(false));
    assertThat(user.isAccessPdcManager(), is(false));
    assertThat(user.isAccessUser(), is(false));
    assertThat(user.isAccessGuest(), is(true));
    assertThat(user.getSaveDate(), greaterThan(now));
    assertThat(user.getVersion(), is(3));
    assertThat(user.getExpirationDate(), nullValue());
    assertThat(user.getState(), is(UserState.EXPIRED));
    assertThat(user.isExpiredState(), is(true));
    assertThat(user.isDeletedState(), is(false));
    assertThat(user.getStateSaveDate().getTime(), is(stateSaveDate.getTime()));

    user.setAccessLevel(UserAccessLevel.DOMAIN_ADMINISTRATOR);
    admin.updateUser(user);

    user = admin.getUserDetail(updatedUserId);
    assertThat(user.getVersion(), is(4));
    assertThat(user.getAccessLevel(), is(UserAccessLevel.DOMAIN_ADMINISTRATOR));
    assertThat(user.isAccessAdmin(), is(false));
    assertThat(user.isAccessDomainManager(), is(true));
    assertThat(user.isAccessSpaceManager(), is(false));
    assertThat(user.isAccessPdcManager(), is(false));
    assertThat(user.isAccessUser(), is(false));
    assertThat(user.isAccessGuest(), is(false));

    user.setAccessLevel(UserAccessLevel.PDC_MANAGER);
    admin.updateUser(user);

    user = admin.getUserDetail(updatedUserId);
    assertThat(user.getVersion(), is(5));
    assertThat(user.getAccessLevel(), is(UserAccessLevel.PDC_MANAGER));
    assertThat(user.isAccessAdmin(), is(false));
    assertThat(user.isAccessDomainManager(), is(false));
    assertThat(user.isAccessSpaceManager(), is(false));
    assertThat(user.isAccessPdcManager(), is(true));
    assertThat(user.isAccessUser(), is(false));
    assertThat(user.isAccessGuest(), is(false));
}

From source file:org.silverpeas.core.date.AbstractDateDatable.java

@Override
public T addDays(final int amount) {
    return newInstanceFrom(DateUtils.addDays(this, amount));
}

From source file:org.silverpeas.core.util.DateUtilTest.java

@Test
public void testGetOutputDateAndHour() {
    Date date = DateUtil.resetHour(java.sql.Date.valueOf("2013-05-21"));
    assertThat(DateUtil.getOutputDateAndHour(date, LANGUAGE), is("05/21/2013"));

    Date year = DateUtils.addYears(date, 1);
    assertThat(DateUtil.getOutputDateAndHour(year, LANGUAGE), is("05/21/2014"));

    Date month = DateUtils.addMonths(date, 1);
    assertThat(DateUtil.getOutputDateAndHour(month, LANGUAGE), is("06/21/2013"));

    Date day = DateUtils.addDays(date, 1);
    assertThat(DateUtil.getOutputDateAndHour(day, LANGUAGE), is("05/22/2013"));

    Date hour = DateUtils.addHours(date, 1);
    assertThat(DateUtil.getOutputDateAndHour(hour, LANGUAGE), is("05/21/2013 01:00"));
    hour = DateUtils.addHours(date, 12);
    assertThat(DateUtil.getOutputDateAndHour(hour, LANGUAGE), is("05/21/2013 12:00"));
    hour = DateUtils.addHours(date, 22);
    assertThat(DateUtil.getOutputDateAndHour(hour, LANGUAGE), is("05/21/2013 22:00"));

    Date minute = DateUtils.addMinutes(date, 1);
    assertThat(DateUtil.getOutputDateAndHour(minute, LANGUAGE), is("05/21/2013 00:01"));
    minute = DateUtils.addMinutes(date, 59);
    assertThat(DateUtil.getOutputDateAndHour(minute, LANGUAGE), is("05/21/2013 00:59"));
    minute = DateUtils.addMinutes(date, 60);
    assertThat(DateUtil.getOutputDateAndHour(minute, LANGUAGE), is("05/21/2013 01:00"));
    minute = DateUtils.addMinutes(date, 61);
    assertThat(DateUtil.getOutputDateAndHour(minute, LANGUAGE), is("05/21/2013 01:01"));

    Date second = DateUtils.addSeconds(date, 1);
    assertThat(DateUtil.getOutputDateAndHour(second, LANGUAGE), is("05/21/2013 00:00"));
    second = DateUtils.addSeconds(date, 59);
    assertThat(DateUtil.getOutputDateAndHour(second, LANGUAGE), is("05/21/2013 00:00"));
    second = DateUtils.addSeconds(date, 60);
    assertThat(DateUtil.getOutputDateAndHour(second, LANGUAGE), is("05/21/2013 00:01"));
    second = DateUtils.addSeconds(date, 61);
    assertThat(DateUtil.getOutputDateAndHour(second, LANGUAGE), is("05/21/2013 00:01"));

    Date millisecond = DateUtils.addMilliseconds(date, 1);
    assertThat(DateUtil.getOutputDateAndHour(millisecond, LANGUAGE), is("05/21/2013 00:00"));
    millisecond = DateUtils.addMilliseconds(date, 999);
    assertThat(DateUtil.getOutputDateAndHour(millisecond, LANGUAGE), is("05/21/2013 00:00"));
    millisecond = DateUtils.addMilliseconds(date, 1000);
    assertThat(DateUtil.getOutputDateAndHour(millisecond, LANGUAGE), is("05/21/2013 00:00"));
    millisecond = DateUtils.addMilliseconds(date, 1001);
    assertThat(DateUtil.getOutputDateAndHour(millisecond, LANGUAGE), is("05/21/2013 00:00"));

    // 2013-05-21 23:59:59.999
    date = DateUtils.addHours(//ww  w . j  ava 2s  . com
            DateUtils.addMinutes(DateUtils.addSeconds(DateUtils.addMilliseconds(date, 999), 59), 59), 23);
    assertThat(DateUtil.getOutputDateAndHour(date, LANGUAGE), is("05/21/2013 23:59"));

    // 2013-05-22 00:00:00.000
    date = DateUtils.addMilliseconds(date, 1);
    assertThat(DateUtil.getOutputDateAndHour(date, LANGUAGE), is("05/22/2013"));

    // 2013-05-22 00:00:00.001
    date = DateUtils.addMilliseconds(date, 1);
    assertThat(DateUtil.getOutputDateAndHour(date, LANGUAGE), is("05/22/2013 00:00"));
}