@Test
  public void testFetchByPrimaryKeyExisting() throws Exception {
    ServiceComponent newServiceComponent = addServiceComponent();

    ServiceComponent existingServiceComponent =
        _persistence.fetchByPrimaryKey(newServiceComponent.getPrimaryKey());

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

    ServiceComponent serviceComponent = _persistence.create(pk);

    Assert.assertNotNull(serviceComponent);

    Assert.assertEquals(serviceComponent.getPrimaryKey(), pk);
  }
  @Test
  public void testRemove() throws Exception {
    ServiceComponent newServiceComponent = addServiceComponent();

    _persistence.remove(newServiceComponent);

    ServiceComponent existingServiceComponent =
        _persistence.fetchByPrimaryKey(newServiceComponent.getPrimaryKey());

    Assert.assertNull(existingServiceComponent);
  }
  @Test
  public void testFetchByPrimaryKeysWithOnePrimaryKey() throws Exception {
    ServiceComponent newServiceComponent = addServiceComponent();

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

    primaryKeys.add(newServiceComponent.getPrimaryKey());

    Map<Serializable, ServiceComponent> serviceComponents =
        _persistence.fetchByPrimaryKeys(primaryKeys);

    Assert.assertEquals(1, serviceComponents.size());
    Assert.assertEquals(
        newServiceComponent, serviceComponents.get(newServiceComponent.getPrimaryKey()));
  }
  @Test
  public void testResetOriginalValues() throws Exception {
    ServiceComponent newServiceComponent = addServiceComponent();

    _persistence.clearCache();

    ServiceComponent existingServiceComponent =
        _persistence.findByPrimaryKey(newServiceComponent.getPrimaryKey());

    Assert.assertTrue(
        Validator.equals(
            existingServiceComponent.getBuildNamespace(),
            ReflectionTestUtil.invoke(
                existingServiceComponent, "getOriginalBuildNamespace", new Class<?>[0])));
    Assert.assertEquals(
        Long.valueOf(existingServiceComponent.getBuildNumber()),
        ReflectionTestUtil.<Long>invoke(
            existingServiceComponent, "getOriginalBuildNumber", new Class<?>[0]));
  }
  @Test
  public void testDynamicQueryByPrimaryKeyExisting() throws Exception {
    ServiceComponent newServiceComponent = addServiceComponent();

    DynamicQuery dynamicQuery =
        DynamicQueryFactoryUtil.forClass(ServiceComponent.class, _dynamicQueryClassLoader);

    dynamicQuery.add(
        RestrictionsFactoryUtil.eq(
            "serviceComponentId", newServiceComponent.getServiceComponentId()));

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

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

    ServiceComponent existingServiceComponent = result.get(0);

    Assert.assertEquals(existingServiceComponent, newServiceComponent);
  }
  @Test
  public void testFetchByPrimaryKeysWithMultiplePrimaryKeysWhereSomePrimaryKeysExist()
      throws Exception {
    ServiceComponent newServiceComponent = addServiceComponent();

    long pk = RandomTestUtil.nextLong();

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

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

    Map<Serializable, ServiceComponent> serviceComponents =
        _persistence.fetchByPrimaryKeys(primaryKeys);

    Assert.assertEquals(1, serviceComponents.size());
    Assert.assertEquals(
        newServiceComponent, serviceComponents.get(newServiceComponent.getPrimaryKey()));
  }
  @Test
  public void testDynamicQueryByProjectionExisting() throws Exception {
    ServiceComponent newServiceComponent = addServiceComponent();

    DynamicQuery dynamicQuery =
        DynamicQueryFactoryUtil.forClass(ServiceComponent.class, _dynamicQueryClassLoader);

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

    Object newServiceComponentId = newServiceComponent.getServiceComponentId();

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

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

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

    Object existingServiceComponentId = result.get(0);

    Assert.assertEquals(existingServiceComponentId, newServiceComponentId);
  }
  protected ServiceComponent addServiceComponent() throws Exception {
    long pk = RandomTestUtil.nextLong();

    ServiceComponent serviceComponent = _persistence.create(pk);

    serviceComponent.setMvccVersion(RandomTestUtil.nextLong());

    serviceComponent.setBuildNamespace(RandomTestUtil.randomString());

    serviceComponent.setBuildNumber(RandomTestUtil.nextLong());

    serviceComponent.setBuildDate(RandomTestUtil.nextLong());

    serviceComponent.setData(RandomTestUtil.randomString());

    _serviceComponents.add(_persistence.update(serviceComponent));

    return serviceComponent;
  }
  @Test
  public void testFetchByPrimaryKeysWithMultiplePrimaryKeysWhereAllPrimaryKeysExist()
      throws Exception {
    ServiceComponent newServiceComponent1 = addServiceComponent();
    ServiceComponent newServiceComponent2 = addServiceComponent();

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

    primaryKeys.add(newServiceComponent1.getPrimaryKey());
    primaryKeys.add(newServiceComponent2.getPrimaryKey());

    Map<Serializable, ServiceComponent> serviceComponents =
        _persistence.fetchByPrimaryKeys(primaryKeys);

    Assert.assertEquals(2, serviceComponents.size());
    Assert.assertEquals(
        newServiceComponent1, serviceComponents.get(newServiceComponent1.getPrimaryKey()));
    Assert.assertEquals(
        newServiceComponent2, serviceComponents.get(newServiceComponent2.getPrimaryKey()));
  }
  @Test
  public void testUpdateExisting() throws Exception {
    long pk = RandomTestUtil.nextLong();

    ServiceComponent newServiceComponent = _persistence.create(pk);

    newServiceComponent.setMvccVersion(RandomTestUtil.nextLong());

    newServiceComponent.setBuildNamespace(RandomTestUtil.randomString());

    newServiceComponent.setBuildNumber(RandomTestUtil.nextLong());

    newServiceComponent.setBuildDate(RandomTestUtil.nextLong());

    newServiceComponent.setData(RandomTestUtil.randomString());

    _serviceComponents.add(_persistence.update(newServiceComponent));

    ServiceComponent existingServiceComponent =
        _persistence.findByPrimaryKey(newServiceComponent.getPrimaryKey());

    Assert.assertEquals(
        existingServiceComponent.getMvccVersion(), newServiceComponent.getMvccVersion());
    Assert.assertEquals(
        existingServiceComponent.getServiceComponentId(),
        newServiceComponent.getServiceComponentId());
    Assert.assertEquals(
        existingServiceComponent.getBuildNamespace(), newServiceComponent.getBuildNamespace());
    Assert.assertEquals(
        existingServiceComponent.getBuildNumber(), newServiceComponent.getBuildNumber());
    Assert.assertEquals(
        existingServiceComponent.getBuildDate(), newServiceComponent.getBuildDate());
    Assert.assertEquals(existingServiceComponent.getData(), newServiceComponent.getData());
  }