@Test public void testFetchByPrimaryKeyExisting() throws Exception { Status newStatus = addStatus(); Status existingStatus = _persistence.fetchByPrimaryKey(newStatus.getPrimaryKey()); Assert.assertEquals(existingStatus, newStatus); }
@Test public void testRemove() throws Exception { Status newStatus = addStatus(); _persistence.remove(newStatus); Status existingStatus = _persistence.fetchByPrimaryKey(newStatus.getPrimaryKey()); Assert.assertNull(existingStatus); }
@Test public void testCreate() throws Exception { long pk = RandomTestUtil.nextLong(); Status status = _persistence.create(pk); Assert.assertNotNull(status); Assert.assertEquals(status.getPrimaryKey(), pk); }
@Test public void testResetOriginalValues() throws Exception { Status newStatus = addStatus(); _persistence.clearCache(); Status existingStatus = _persistence.findByPrimaryKey(newStatus.getPrimaryKey()); Assert.assertEquals( Long.valueOf(existingStatus.getUserId()), ReflectionTestUtil.<Long>invoke(existingStatus, "getOriginalUserId", new Class<?>[0])); }
@Test public void testFetchByPrimaryKeysWithOnePrimaryKey() throws Exception { Status newStatus = addStatus(); Set<Serializable> primaryKeys = new HashSet<Serializable>(); primaryKeys.add(newStatus.getPrimaryKey()); Map<Serializable, Status> statuses = _persistence.fetchByPrimaryKeys(primaryKeys); Assert.assertEquals(1, statuses.size()); Assert.assertEquals(newStatus, statuses.get(newStatus.getPrimaryKey())); }
/** * Adds the status to the database. Also notifies the appropriate model listeners. * * @param status the status * @return the status that was added */ @Indexable(type = IndexableType.REINDEX) @Override public Status addStatus(Status status) { status.setNew(true); return statusPersistence.update(status); }
@Test public void testDynamicQueryByPrimaryKeyExisting() throws Exception { Status newStatus = addStatus(); DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(Status.class, _dynamicQueryClassLoader); dynamicQuery.add(RestrictionsFactoryUtil.eq("statusId", newStatus.getStatusId())); List<Status> result = _persistence.findWithDynamicQuery(dynamicQuery); Assert.assertEquals(1, result.size()); Status existingStatus = result.get(0); Assert.assertEquals(existingStatus, newStatus); }
@Test public void testFetchByPrimaryKeysWithMultiplePrimaryKeysWhereSomePrimaryKeysExist() throws Exception { Status newStatus = addStatus(); long pk = RandomTestUtil.nextLong(); Set<Serializable> primaryKeys = new HashSet<Serializable>(); primaryKeys.add(newStatus.getPrimaryKey()); primaryKeys.add(pk); Map<Serializable, Status> statuses = _persistence.fetchByPrimaryKeys(primaryKeys); Assert.assertEquals(1, statuses.size()); Assert.assertEquals(newStatus, statuses.get(newStatus.getPrimaryKey())); }
@Test public void testDynamicQueryByProjectionExisting() throws Exception { Status newStatus = addStatus(); DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(Status.class, _dynamicQueryClassLoader); dynamicQuery.setProjection(ProjectionFactoryUtil.property("statusId")); Object newStatusId = newStatus.getStatusId(); dynamicQuery.add(RestrictionsFactoryUtil.in("statusId", new Object[] {newStatusId})); List<Object> result = _persistence.findWithDynamicQuery(dynamicQuery); Assert.assertEquals(1, result.size()); Object existingStatusId = result.get(0); Assert.assertEquals(existingStatusId, newStatusId); }
protected Status addStatus() throws Exception { long pk = RandomTestUtil.nextLong(); Status status = _persistence.create(pk); status.setUserId(RandomTestUtil.nextLong()); status.setModifiedDate(RandomTestUtil.nextLong()); status.setOnline(RandomTestUtil.randomBoolean()); status.setAwake(RandomTestUtil.randomBoolean()); status.setActivePanelIds(RandomTestUtil.randomString()); status.setMessage(RandomTestUtil.randomString()); status.setPlaySound(RandomTestUtil.randomBoolean()); _statuses.add(_persistence.update(status)); return status; }
@Test public void testFetchByPrimaryKeysWithMultiplePrimaryKeysWhereAllPrimaryKeysExist() throws Exception { Status newStatus1 = addStatus(); Status newStatus2 = addStatus(); Set<Serializable> primaryKeys = new HashSet<Serializable>(); primaryKeys.add(newStatus1.getPrimaryKey()); primaryKeys.add(newStatus2.getPrimaryKey()); Map<Serializable, Status> statuses = _persistence.fetchByPrimaryKeys(primaryKeys); Assert.assertEquals(2, statuses.size()); Assert.assertEquals(newStatus1, statuses.get(newStatus1.getPrimaryKey())); Assert.assertEquals(newStatus2, statuses.get(newStatus2.getPrimaryKey())); }
@Test public void testUpdateExisting() throws Exception { long pk = RandomTestUtil.nextLong(); Status newStatus = _persistence.create(pk); newStatus.setUserId(RandomTestUtil.nextLong()); newStatus.setModifiedDate(RandomTestUtil.nextLong()); newStatus.setOnline(RandomTestUtil.randomBoolean()); newStatus.setAwake(RandomTestUtil.randomBoolean()); newStatus.setActivePanelIds(RandomTestUtil.randomString()); newStatus.setMessage(RandomTestUtil.randomString()); newStatus.setPlaySound(RandomTestUtil.randomBoolean()); _statuses.add(_persistence.update(newStatus)); Status existingStatus = _persistence.findByPrimaryKey(newStatus.getPrimaryKey()); Assert.assertEquals(existingStatus.getStatusId(), newStatus.getStatusId()); Assert.assertEquals(existingStatus.getUserId(), newStatus.getUserId()); Assert.assertEquals(existingStatus.getModifiedDate(), newStatus.getModifiedDate()); Assert.assertEquals(existingStatus.getOnline(), newStatus.getOnline()); Assert.assertEquals(existingStatus.getAwake(), newStatus.getAwake()); Assert.assertEquals(existingStatus.getActivePanelIds(), newStatus.getActivePanelIds()); Assert.assertEquals(existingStatus.getMessage(), newStatus.getMessage()); Assert.assertEquals(existingStatus.getPlaySound(), newStatus.getPlaySound()); }