@Test
  public void testResetOriginalValues() throws Exception {
    CalendarResource newCalendarResource = addCalendarResource();

    _persistence.clearCache();

    CalendarResource existingCalendarResource =
        _persistence.findByPrimaryKey(newCalendarResource.getPrimaryKey());

    Assert.assertTrue(
        Validator.equals(
            existingCalendarResource.getUuid(),
            ReflectionTestUtil.invoke(
                existingCalendarResource, "getOriginalUuid", new Class<?>[0])));
    Assert.assertEquals(
        Long.valueOf(existingCalendarResource.getGroupId()),
        ReflectionTestUtil.<Long>invoke(
            existingCalendarResource, "getOriginalGroupId", new Class<?>[0]));

    Assert.assertEquals(
        Long.valueOf(existingCalendarResource.getClassNameId()),
        ReflectionTestUtil.<Long>invoke(
            existingCalendarResource, "getOriginalClassNameId", new Class<?>[0]));
    Assert.assertEquals(
        Long.valueOf(existingCalendarResource.getClassPK()),
        ReflectionTestUtil.<Long>invoke(
            existingCalendarResource, "getOriginalClassPK", new Class<?>[0]));
  }
  @Test
  public void testFetchByPrimaryKeyExisting() throws Exception {
    CalendarResource newCalendarResource = addCalendarResource();

    CalendarResource existingCalendarResource =
        _persistence.fetchByPrimaryKey(newCalendarResource.getPrimaryKey());

    Assert.assertEquals(existingCalendarResource, newCalendarResource);
  }
  @Test
  public void testCreate() throws Exception {
    long pk = RandomTestUtil.nextLong();

    CalendarResource calendarResource = _persistence.create(pk);

    Assert.assertNotNull(calendarResource);

    Assert.assertEquals(calendarResource.getPrimaryKey(), pk);
  }
  @Test
  public void testFetchByPrimaryKeysWithOnePrimaryKey() throws Exception {
    CalendarResource newCalendarResource = addCalendarResource();

    Set<Serializable> primaryKeys = new HashSet<Serializable>();

    primaryKeys.add(newCalendarResource.getPrimaryKey());

    Map<Serializable, CalendarResource> calendarResources =
        _persistence.fetchByPrimaryKeys(primaryKeys);

    Assert.assertEquals(1, calendarResources.size());
    Assert.assertEquals(
        newCalendarResource, calendarResources.get(newCalendarResource.getPrimaryKey()));
  }
  @Test
  public void testFetchByPrimaryKeysWithMultiplePrimaryKeysWhereSomePrimaryKeysExist()
      throws Exception {
    CalendarResource newCalendarResource = addCalendarResource();

    long pk = RandomTestUtil.nextLong();

    Set<Serializable> primaryKeys = new HashSet<Serializable>();

    primaryKeys.add(newCalendarResource.getPrimaryKey());
    primaryKeys.add(pk);

    Map<Serializable, CalendarResource> calendarResources =
        _persistence.fetchByPrimaryKeys(primaryKeys);

    Assert.assertEquals(1, calendarResources.size());
    Assert.assertEquals(
        newCalendarResource, calendarResources.get(newCalendarResource.getPrimaryKey()));
  }
  @Test
  public void testRemove() throws Exception {
    CalendarResource newCalendarResource = addCalendarResource();

    _persistence.remove(newCalendarResource);

    CalendarResource existingCalendarResource =
        _persistence.fetchByPrimaryKey(newCalendarResource.getPrimaryKey());

    Assert.assertNull(existingCalendarResource);
  }
  @Test
  public void testFetchByPrimaryKeysWithMultiplePrimaryKeysWhereAllPrimaryKeysExist()
      throws Exception {
    CalendarResource newCalendarResource1 = addCalendarResource();
    CalendarResource newCalendarResource2 = addCalendarResource();

    Set<Serializable> primaryKeys = new HashSet<Serializable>();

    primaryKeys.add(newCalendarResource1.getPrimaryKey());
    primaryKeys.add(newCalendarResource2.getPrimaryKey());

    Map<Serializable, CalendarResource> calendarResources =
        _persistence.fetchByPrimaryKeys(primaryKeys);

    Assert.assertEquals(2, calendarResources.size());
    Assert.assertEquals(
        newCalendarResource1, calendarResources.get(newCalendarResource1.getPrimaryKey()));
    Assert.assertEquals(
        newCalendarResource2, calendarResources.get(newCalendarResource2.getPrimaryKey()));
  }
コード例 #8
0
  protected void prepareLanguagesForImport(CalendarResource calendarResource)
      throws PortalException {

    Locale defaultLocale = LocaleUtil.fromLanguageId(calendarResource.getDefaultLanguageId());

    Locale[] availableLocales =
        LocaleUtil.fromLanguageIds(calendarResource.getAvailableLanguageIds());

    Locale defaultImportLocale =
        LocalizationUtil.getDefaultImportLocale(
            CalendarResource.class.getName(),
            calendarResource.getPrimaryKey(),
            defaultLocale,
            availableLocales);

    calendarResource.prepareLocalizedFieldsForImport(defaultImportLocale);
  }
コード例 #9
0
  @Override
  public boolean equals(Object obj) {
    if (obj == null) {
      return false;
    }

    CalendarResource calendarResource = null;

    try {
      calendarResource = (CalendarResource) obj;
    } catch (ClassCastException cce) {
      return false;
    }

    long primaryKey = calendarResource.getPrimaryKey();

    if (getPrimaryKey() == primaryKey) {
      return true;
    } else {
      return false;
    }
  }
コード例 #10
0
  @Test
  public void testUpdateExisting() throws Exception {
    long pk = RandomTestUtil.nextLong();

    CalendarResource newCalendarResource = _persistence.create(pk);

    newCalendarResource.setUuid(RandomTestUtil.randomString());

    newCalendarResource.setGroupId(RandomTestUtil.nextLong());

    newCalendarResource.setCompanyId(RandomTestUtil.nextLong());

    newCalendarResource.setUserId(RandomTestUtil.nextLong());

    newCalendarResource.setUserName(RandomTestUtil.randomString());

    newCalendarResource.setCreateDate(RandomTestUtil.nextDate());

    newCalendarResource.setModifiedDate(RandomTestUtil.nextDate());

    newCalendarResource.setResourceBlockId(RandomTestUtil.nextLong());

    newCalendarResource.setClassNameId(RandomTestUtil.nextLong());

    newCalendarResource.setClassPK(RandomTestUtil.nextLong());

    newCalendarResource.setClassUuid(RandomTestUtil.randomString());

    newCalendarResource.setCode(RandomTestUtil.randomString());

    newCalendarResource.setName(RandomTestUtil.randomString());

    newCalendarResource.setDescription(RandomTestUtil.randomString());

    newCalendarResource.setActive(RandomTestUtil.randomBoolean());

    newCalendarResource.setLastPublishDate(RandomTestUtil.nextDate());

    _calendarResources.add(_persistence.update(newCalendarResource));

    CalendarResource existingCalendarResource =
        _persistence.findByPrimaryKey(newCalendarResource.getPrimaryKey());

    Assert.assertEquals(existingCalendarResource.getUuid(), newCalendarResource.getUuid());
    Assert.assertEquals(
        existingCalendarResource.getCalendarResourceId(),
        newCalendarResource.getCalendarResourceId());
    Assert.assertEquals(existingCalendarResource.getGroupId(), newCalendarResource.getGroupId());
    Assert.assertEquals(
        existingCalendarResource.getCompanyId(), newCalendarResource.getCompanyId());
    Assert.assertEquals(existingCalendarResource.getUserId(), newCalendarResource.getUserId());
    Assert.assertEquals(existingCalendarResource.getUserName(), newCalendarResource.getUserName());
    Assert.assertEquals(
        Time.getShortTimestamp(existingCalendarResource.getCreateDate()),
        Time.getShortTimestamp(newCalendarResource.getCreateDate()));
    Assert.assertEquals(
        Time.getShortTimestamp(existingCalendarResource.getModifiedDate()),
        Time.getShortTimestamp(newCalendarResource.getModifiedDate()));
    Assert.assertEquals(
        existingCalendarResource.getResourceBlockId(), newCalendarResource.getResourceBlockId());
    Assert.assertEquals(
        existingCalendarResource.getClassNameId(), newCalendarResource.getClassNameId());
    Assert.assertEquals(existingCalendarResource.getClassPK(), newCalendarResource.getClassPK());
    Assert.assertEquals(
        existingCalendarResource.getClassUuid(), newCalendarResource.getClassUuid());
    Assert.assertEquals(existingCalendarResource.getCode(), newCalendarResource.getCode());
    Assert.assertEquals(existingCalendarResource.getName(), newCalendarResource.getName());
    Assert.assertEquals(
        existingCalendarResource.getDescription(), newCalendarResource.getDescription());
    Assert.assertEquals(existingCalendarResource.getActive(), newCalendarResource.getActive());
    Assert.assertEquals(
        Time.getShortTimestamp(existingCalendarResource.getLastPublishDate()),
        Time.getShortTimestamp(newCalendarResource.getLastPublishDate()));
  }