@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 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()); }
@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 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 testRemove() throws Exception { ServiceComponent newServiceComponent = addServiceComponent(); _persistence.remove(newServiceComponent); ServiceComponent existingServiceComponent = _persistence.fetchByPrimaryKey(newServiceComponent.getPrimaryKey()); Assert.assertNull(existingServiceComponent); }
@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 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])); }