Uploaded image for project: 'PUBLIC - Liferay Portal Community Edition'
  1. PUBLIC - Liferay Portal Community Edition
  2. LPS-56124

Default createDate and modifiedDate cannot be overridden in new entities using serviceContext

    Details

    • Type: Regression Bug
    • Status: Closed
    • Resolution: Fixed
    • Affects Version/s: 7.0.0 M6
    • Fix Version/s: 7.0.0 M6
    • Component/s: Portal Services
    • Labels:
      None

      Description

      Steps to reproduce:

      1. Create a test file on the following location: modules/apps/bookmarks/bookmarks-test/test/integration/com/liferay/bookmarks/BookmarksEntryCreateDateTest.java
      package com.liferay.bookmarks;
      
      import com.liferay.arquillian.extension.junit.bridge.junit.Arquillian;
      import com.liferay.bookmarks.model.BookmarksEntry;
      import com.liferay.bookmarks.service.BookmarksEntryLocalServiceUtil;
      import com.liferay.portal.kernel.test.rule.AggregateTestRule;
      import com.liferay.portal.kernel.test.rule.TransactionalTestRule;
      import com.liferay.portal.kernel.test.util.TestPropsValues;
      import com.liferay.portal.model.Group;
      import com.liferay.portal.model.User;
      import com.liferay.portal.service.GroupLocalServiceUtil;
      import com.liferay.portal.service.ServiceContext;
      import com.liferay.portal.service.UserLocalServiceUtil;
      import com.liferay.portal.test.rule.LiferayIntegrationTestRule;
      import com.liferay.portal.util.PortalUtil;
      import java.util.Date;
      import org.junit.Assert;
      import org.junit.ClassRule;
      import org.junit.Rule;
      import org.junit.Test;
      import org.junit.runner.RunWith;
      
      /**
       * Created by akos on 2015.06.04..
       */
      @RunWith(Arquillian.class)
      public class BookmarksEntryCreateDateTest {
      
      	@ClassRule
      	@Rule
      	public static final AggregateTestRule aggregateTestRule =
      		new AggregateTestRule(
      			new LiferayIntegrationTestRule(), TransactionalTestRule.INSTANCE);
      
      	@Test
      	public void addBookmark() throws Exception {
      		long companyId = PortalUtil.getDefaultCompanyId();
      
      		User user = UserLocalServiceUtil.getDefaultUser(companyId);
      
      		Group group = GroupLocalServiceUtil.getGroup(companyId, "Guest");
      
      		ServiceContext serviceContext = new ServiceContext();
      
      		Date date = new Date(0);
      
      		serviceContext.setCreateDate(date);
      
      		BookmarksEntry entry = BookmarksEntryLocalServiceUtil.addEntry(
      			user.getUserId(), group.getGroupId(), 0, "name",
      			"http://google.com", null, serviceContext);
      
      		Assert.assertEquals(date, entry.getCreateDate());
      	}
      }
      
      1. Go to modules/apps/bookmarks/bookmarks-test/ and run
        ant deploy
      2. Start portal
      3. Run the test using
        ant test-class -Dtest.class=BookmarksEntryCreateDateTest
        

      Result: the test fails with

      expected:<Thu Jan 01 00:00:00 GMT 1970> but was:<Thu Jun 04 12:40:37 GMT 2015>

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Days since last comment:
                  4 years, 19 weeks, 3 days ago

                  Packages

                  Version Package
                  7.0.0 M6