コード例 #1
0
  @Test
  public void testFetchByPrimaryKeyExisting() throws Exception {
    Region newRegion = addRegion();

    Region existingRegion = _persistence.fetchByPrimaryKey(newRegion.getPrimaryKey());

    Assert.assertEquals(existingRegion, newRegion);
  }
コード例 #2
0
  @Test
  public void testCreate() throws Exception {
    long pk = RandomTestUtil.nextLong();

    Region region = _persistence.create(pk);

    Assert.assertNotNull(region);

    Assert.assertEquals(region.getPrimaryKey(), pk);
  }
コード例 #3
0
  @Test
  public void testRemove() throws Exception {
    Region newRegion = addRegion();

    _persistence.remove(newRegion);

    Region existingRegion = _persistence.fetchByPrimaryKey(newRegion.getPrimaryKey());

    Assert.assertNull(existingRegion);
  }
コード例 #4
0
  @Test
  public void testDynamicQueryByPrimaryKeyExisting() throws Exception {
    Region newRegion = addRegion();

    DynamicQuery dynamicQuery =
        DynamicQueryFactoryUtil.forClass(Region.class, Region.class.getClassLoader());

    dynamicQuery.add(RestrictionsFactoryUtil.eq("regionId", newRegion.getRegionId()));

    List<Region> result = _persistence.findWithDynamicQuery(dynamicQuery);

    Assert.assertEquals(1, result.size());

    Region existingRegion = result.get(0);

    Assert.assertEquals(existingRegion, newRegion);
  }
コード例 #5
0
  public String getRegionName() throws PortalException, SystemException {
    String regionName = null;

    if (regionId != 0) {
      try {
        Region region = RegionServiceUtil.getRegion(regionId);

        regionName = region.getName().toLowerCase();
      } catch (NoSuchRegionException nsre) {
        if (_log.isWarnEnabled()) {
          _log.warn(nsre.getMessage());
        }
      }
    }

    return regionName;
  }
コード例 #6
0
  @Test
  public void testResetOriginalValues() throws Exception {
    if (!PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
      return;
    }

    Region newRegion = addRegion();

    _persistence.clearCache();

    RegionModelImpl existingRegionModelImpl =
        (RegionModelImpl) _persistence.findByPrimaryKey(newRegion.getPrimaryKey());

    Assert.assertEquals(
        existingRegionModelImpl.getCountryId(), existingRegionModelImpl.getOriginalCountryId());
    Assert.assertTrue(
        Validator.equals(
            existingRegionModelImpl.getRegionCode(),
            existingRegionModelImpl.getOriginalRegionCode()));
  }
コード例 #7
0
  @Test
  public void testDynamicQueryByProjectionExisting() throws Exception {
    Region newRegion = addRegion();

    DynamicQuery dynamicQuery =
        DynamicQueryFactoryUtil.forClass(Region.class, Region.class.getClassLoader());

    dynamicQuery.setProjection(ProjectionFactoryUtil.property("regionId"));

    Object newRegionId = newRegion.getRegionId();

    dynamicQuery.add(RestrictionsFactoryUtil.in("regionId", new Object[] {newRegionId}));

    List<Object> result = _persistence.findWithDynamicQuery(dynamicQuery);

    Assert.assertEquals(1, result.size());

    Object existingRegionId = result.get(0);

    Assert.assertEquals(existingRegionId, newRegionId);
  }
コード例 #8
0
  protected Region addRegion() throws Exception {
    long pk = RandomTestUtil.nextLong();

    Region region = _persistence.create(pk);

    region.setMvccVersion(RandomTestUtil.nextLong());

    region.setCountryId(RandomTestUtil.nextLong());

    region.setRegionCode(RandomTestUtil.randomString());

    region.setName(RandomTestUtil.randomString());

    region.setActive(RandomTestUtil.randomBoolean());

    _persistence.update(region);

    return region;
  }
コード例 #9
0
  @Test
  public void testUpdateExisting() throws Exception {
    long pk = RandomTestUtil.nextLong();

    Region newRegion = _persistence.create(pk);

    newRegion.setMvccVersion(RandomTestUtil.nextLong());

    newRegion.setCountryId(RandomTestUtil.nextLong());

    newRegion.setRegionCode(RandomTestUtil.randomString());

    newRegion.setName(RandomTestUtil.randomString());

    newRegion.setActive(RandomTestUtil.randomBoolean());

    _persistence.update(newRegion);

    Region existingRegion = _persistence.findByPrimaryKey(newRegion.getPrimaryKey());

    Assert.assertEquals(existingRegion.getMvccVersion(), newRegion.getMvccVersion());
    Assert.assertEquals(existingRegion.getRegionId(), newRegion.getRegionId());
    Assert.assertEquals(existingRegion.getCountryId(), newRegion.getCountryId());
    Assert.assertEquals(existingRegion.getRegionCode(), newRegion.getRegionCode());
    Assert.assertEquals(existingRegion.getName(), newRegion.getName());
    Assert.assertEquals(existingRegion.getActive(), newRegion.getActive());
  }