protected VirtualHost addVirtualHost() throws Exception {
    long pk = ServiceTestUtil.nextLong();

    VirtualHost virtualHost = _persistence.create(pk);

    virtualHost.setMvccVersion(ServiceTestUtil.nextLong());

    virtualHost.setCompanyId(ServiceTestUtil.nextLong());

    virtualHost.setLayoutSetId(ServiceTestUtil.nextLong());

    virtualHost.setHostname(ServiceTestUtil.randomString());

    _persistence.update(virtualHost);

    return virtualHost;
  }
  public VirtualHost updateVirtualHost(long companyId, long layoutSetId, String hostname)
      throws SystemException {

    VirtualHost virtualHost = virtualHostPersistence.fetchByC_L(companyId, layoutSetId);

    if (virtualHost == null) {
      long virtualHostId = counterLocalService.increment();

      virtualHost = virtualHostPersistence.create(virtualHostId);

      virtualHost.setCompanyId(companyId);
      virtualHost.setLayoutSetId(layoutSetId);
    }

    virtualHost.setHostname(hostname);

    virtualHostPersistence.update(virtualHost, false);

    return virtualHost;
  }
  @Test
  public void testUpdateExisting() throws Exception {
    long pk = ServiceTestUtil.nextLong();

    VirtualHost newVirtualHost = _persistence.create(pk);

    newVirtualHost.setMvccVersion(ServiceTestUtil.nextLong());

    newVirtualHost.setCompanyId(ServiceTestUtil.nextLong());

    newVirtualHost.setLayoutSetId(ServiceTestUtil.nextLong());

    newVirtualHost.setHostname(ServiceTestUtil.randomString());

    _persistence.update(newVirtualHost);

    VirtualHost existingVirtualHost = _persistence.findByPrimaryKey(newVirtualHost.getPrimaryKey());

    Assert.assertEquals(existingVirtualHost.getMvccVersion(), newVirtualHost.getMvccVersion());
    Assert.assertEquals(existingVirtualHost.getVirtualHostId(), newVirtualHost.getVirtualHostId());
    Assert.assertEquals(existingVirtualHost.getCompanyId(), newVirtualHost.getCompanyId());
    Assert.assertEquals(existingVirtualHost.getLayoutSetId(), newVirtualHost.getLayoutSetId());
    Assert.assertEquals(existingVirtualHost.getHostname(), newVirtualHost.getHostname());
  }