001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.trash;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.kernel.dao.orm.ActionableDynamicQuery;
019    import com.liferay.portal.kernel.dao.orm.DynamicQuery;
020    import com.liferay.portal.kernel.dao.orm.Property;
021    import com.liferay.portal.kernel.dao.orm.PropertyFactoryUtil;
022    import com.liferay.portal.kernel.dao.orm.QueryUtil;
023    import com.liferay.portal.kernel.search.Hits;
024    import com.liferay.portal.kernel.search.Indexer;
025    import com.liferay.portal.kernel.search.IndexerRegistryUtil;
026    import com.liferay.portal.kernel.search.SearchContext;
027    import com.liferay.portal.kernel.trash.TrashHandler;
028    import com.liferay.portal.kernel.trash.TrashHandlerRegistryUtil;
029    import com.liferay.portal.kernel.util.GetterUtil;
030    import com.liferay.portal.kernel.util.StringPool;
031    import com.liferay.portal.kernel.workflow.WorkflowConstants;
032    import com.liferay.portal.kernel.workflow.WorkflowThreadLocal;
033    import com.liferay.portal.model.BaseModel;
034    import com.liferay.portal.model.ClassedModel;
035    import com.liferay.portal.model.ContainerModel;
036    import com.liferay.portal.model.Group;
037    import com.liferay.portal.model.SystemEventConstants;
038    import com.liferay.portal.model.TrashedModel;
039    import com.liferay.portal.model.WorkflowedModel;
040    import com.liferay.portal.service.ServiceContext;
041    import com.liferay.portal.service.SystemEventLocalServiceUtil;
042    import com.liferay.portal.test.DeleteAfterTestRun;
043    import com.liferay.portal.util.PortalUtil;
044    import com.liferay.portal.util.test.GroupTestUtil;
045    import com.liferay.portal.util.test.SearchContextTestUtil;
046    import com.liferay.portal.util.test.ServiceContextTestUtil;
047    import com.liferay.portal.util.test.TestPropsValues;
048    import com.liferay.portlet.asset.model.AssetEntry;
049    import com.liferay.portlet.asset.service.AssetEntryLocalServiceUtil;
050    import com.liferay.portlet.trash.model.TrashEntry;
051    import com.liferay.portlet.trash.service.TrashEntryLocalServiceUtil;
052    import com.liferay.portlet.trash.service.TrashEntryServiceUtil;
053    import com.liferay.portlet.trash.service.TrashVersionLocalServiceUtil;
054    
055    import java.util.ArrayList;
056    import java.util.Collections;
057    import java.util.List;
058    
059    import org.junit.Assert;
060    import org.junit.Before;
061    import org.junit.Test;
062    
063    /**
064     * @author Brian Wing Shun Chan
065     * @author Eudaldo Alonso
066     * @author Manuel de la Pe??a
067     */
068    public abstract class BaseTrashHandlerTestCase {
069    
070            @Before
071            public void setUp() throws Exception {
072                    group = GroupTestUtil.addGroup();
073            }
074    
075            @Test
076            public void testDeleteTrashVersions() throws Exception {
077                    ServiceContext serviceContext =
078                            ServiceContextTestUtil.getServiceContext(group.getGroupId());
079    
080                    BaseModel<?> parentBaseModel = getParentBaseModel(
081                            group, serviceContext);
082    
083                    int initialTrashVersionsCount =
084                            TrashVersionLocalServiceUtil.getTrashVersionsCount();
085    
086                    baseModel = addBaseModel(parentBaseModel, true, serviceContext);
087    
088                    serviceContext.setWorkflowAction(WorkflowConstants.ACTION_SAVE_DRAFT);
089    
090                    baseModel = updateBaseModel(
091                            (Long)baseModel.getPrimaryKeyObj(), serviceContext);
092    
093                    moveParentBaseModelToTrash((Long)parentBaseModel.getPrimaryKeyObj());
094    
095                    TrashHandler trashHandler = TrashHandlerRegistryUtil.getTrashHandler(
096                            getBaseModelClassName());
097    
098                    trashHandler.deleteTrashEntry(getTrashEntryClassPK(baseModel));
099    
100                    Assert.assertEquals(
101                            initialTrashVersionsCount,
102                            TrashVersionLocalServiceUtil.getTrashVersionsCount());
103            }
104    
105            @Test
106            public void testTrashAndDeleteApproved() throws Exception {
107                    trashBaseModel(true, true);
108            }
109    
110            @Test
111            public void testTrashAndDeleteDraft() throws Exception {
112                    trashBaseModel(false, true);
113            }
114    
115            @Test
116            public void testTrashAndRestoreApproved() throws Exception {
117                    trashBaseModel(true, false);
118            }
119    
120            @Test
121            public void testTrashAndRestoreDraft() throws Exception {
122                    trashBaseModel(false, false);
123            }
124    
125            @Test
126            public void testTrashBaseModelAndParentAndDeleteGroupTrashEntries()
127                    throws Exception {
128    
129                    trashParentBaseModel(true, false, true);
130            }
131    
132            @Test
133            public void testTrashBaseModelAndParentAndDeleteParent() throws Exception {
134                    trashParentBaseModel(true, true, false);
135            }
136    
137            @Test
138            public void testTrashBaseModelAndParentAndRestoreModel() throws Exception {
139                    trashParentBaseModel(true, false, false);
140            }
141    
142            @Test
143            public void testTrashDuplicate() throws Exception {
144                    trashDuplicateBaseModel();
145            }
146    
147            @Test
148            public void testTrashGrandparentBaseModelAndRestoreParentModel()
149                    throws Exception {
150    
151                    trashGrandparentBaseModelAndRestoreParentModel();
152            }
153    
154            @Test
155            public void testTrashIsRestorableBaseModel() throws Exception {
156                    trashIsRestorableBaseModel();
157            }
158    
159            @Test
160            public void testTrashIsRestorableBaseModelWithParent1() throws Exception {
161                    trashIsRestorableBaseModelWithParent(false, false);
162            }
163    
164            @Test
165            public void testTrashIsRestorableBaseModelWithParent2() throws Exception {
166                    trashIsRestorableBaseModelWithParent(true, false);
167            }
168    
169            @Test
170            public void testTrashIsRestorableBaseModelWithParent3() throws Exception {
171                    trashIsRestorableBaseModelWithParent(false, true);
172            }
173    
174            @Test
175            public void testTrashIsRestorableBaseModelWithParent4() throws Exception {
176                    trashIsRestorableBaseModelWithParent(true, true);
177            }
178    
179            @Test
180            public void testTrashMoveBaseModel() throws Exception {
181                    trashMoveBaseModel();
182            }
183    
184            @Test
185            public void testTrashMyBaseModel() throws Exception {
186                    trashMyBaseModel();
187            }
188    
189            @Test
190            public void testTrashParentAndDeleteGroupTrashEntries() throws Exception {
191                    trashParentBaseModel(false, false, true);
192            }
193    
194            @Test
195            public void testTrashParentAndDeleteParent() throws Exception {
196                    trashParentBaseModel(false, true, false);
197            }
198    
199            @Test
200            public void testTrashRecentBaseModel() throws Exception {
201                    trashRecentBaseModel();
202            }
203    
204            @Test
205            public void testTrashVersionBaseModelAndDelete() throws Exception {
206                    trashVersionBaseModel(true);
207            }
208    
209            @Test
210            public void testTrashVersionBaseModelAndRestore() throws Exception {
211                    trashVersionBaseModel(false);
212            }
213    
214            @Test
215            public void testTrashVersionParentBaseModel() throws Exception {
216                    trashVersionParentBaseModel(false);
217            }
218    
219            @Test
220            public void testTrashVersionParentBaseModelAndRestore() throws Exception {
221                    trashVersionParentBaseModel(true);
222            }
223    
224            protected BaseModel<?> addBaseModel(
225                            BaseModel<?> parentBaseModel, boolean approved,
226                            ServiceContext serviceContext)
227                    throws Exception {
228    
229                    boolean workflowEnabled = WorkflowThreadLocal.isEnabled();
230    
231                    try {
232                            WorkflowThreadLocal.setEnabled(true);
233    
234                            BaseModel<?> baseModel = addBaseModelWithWorkflow(
235                                    parentBaseModel, approved, serviceContext);
236    
237                            return baseModel;
238                    }
239                    finally {
240                            WorkflowThreadLocal.setEnabled(workflowEnabled);
241                    }
242            }
243    
244            protected abstract BaseModel<?> addBaseModelWithWorkflow(
245                            BaseModel<?> parentBaseModel, boolean approved,
246                            ServiceContext serviceContext)
247                    throws Exception;
248    
249            protected BaseModel<?> addBaseModelWithWorkflow(
250                            boolean approved, ServiceContext serviceContext)
251                    throws Exception {
252    
253                    BaseModel<?> parentBaseModel = getParentBaseModel(
254                            group, serviceContext);
255    
256                    return addBaseModelWithWorkflow(
257                            parentBaseModel, approved, serviceContext);
258            }
259    
260            protected void deleteParentBaseModel(
261                            BaseModel<?> parentBaseModel, boolean includeTrashedEntries)
262                    throws Exception {
263            }
264    
265            protected BaseModel<?> expireBaseModel(
266                            BaseModel<?> baseModel, ServiceContext serviceContext)
267                    throws Exception {
268    
269                    return baseModel;
270            }
271    
272            protected AssetEntry fetchAssetEntry(Class<?> clazz, long classPK)
273                    throws Exception {
274    
275                    return AssetEntryLocalServiceUtil.fetchEntry(clazz.getName(), classPK);
276            }
277    
278            protected AssetEntry fetchAssetEntry(ClassedModel classedModel)
279                    throws Exception {
280    
281                    return fetchAssetEntry(
282                            classedModel.getModelClass(),
283                            (Long)classedModel.getPrimaryKeyObj());
284            }
285    
286            protected Long getAssetClassPK(ClassedModel classedModel) {
287                    return (Long)classedModel.getPrimaryKeyObj();
288            }
289    
290            protected abstract BaseModel<?> getBaseModel(long primaryKey)
291                    throws Exception;
292    
293            protected abstract Class<?> getBaseModelClass();
294    
295            protected String getBaseModelClassName() {
296                    Class<?> clazz = getBaseModelClass();
297    
298                    return clazz.getName();
299            }
300    
301            protected String getBaseModelName(ClassedModel classedModel) {
302                    return StringPool.BLANK;
303            }
304    
305            protected List<? extends WorkflowedModel> getChildrenWorkflowedModels(
306                            BaseModel<?> parentBaseModel)
307                    throws Exception {
308    
309                    return Collections.emptyList();
310            }
311    
312            protected long getDeletionSystemEventCount(
313                            TrashHandler trashHandler, final long systemEventSetKey)
314                    throws Exception {
315    
316                    final long systemEventClassNameId = PortalUtil.getClassNameId(
317                            trashHandler.getSystemEventClassName());
318    
319                    ActionableDynamicQuery actionableDynamicQuery =
320                            SystemEventLocalServiceUtil.getActionableDynamicQuery();
321    
322                    actionableDynamicQuery.setAddCriteriaMethod(
323                            new ActionableDynamicQuery.AddCriteriaMethod() {
324    
325                                    @Override
326                                    public void addCriteria(DynamicQuery dynamicQuery) {
327                                            Property classNameIdProperty = PropertyFactoryUtil.forName(
328                                                    "classNameId");
329    
330                                            dynamicQuery.add(
331                                                    classNameIdProperty.eq(systemEventClassNameId));
332    
333                                            if (systemEventSetKey > 0) {
334                                                    Property systemEventSetKeyProperty =
335                                                            PropertyFactoryUtil.forName("systemEventSetKey");
336    
337                                                    dynamicQuery.add(
338                                                            systemEventSetKeyProperty.eq(systemEventSetKey));
339                                            }
340    
341                                            Property typeProperty = PropertyFactoryUtil.forName("type");
342    
343                                            dynamicQuery.add(
344                                                    typeProperty.eq(SystemEventConstants.TYPE_DELETE));
345                                    }
346    
347                            });
348                    actionableDynamicQuery.setGroupId(group.getGroupId());
349    
350                    return actionableDynamicQuery.performCount();
351            }
352    
353            protected int getMineBaseModelsCount(long groupId, long userId)
354                    throws Exception {
355    
356                    return 0;
357            }
358    
359            protected abstract int getNotInTrashBaseModelsCount(
360                            BaseModel<?> parentBaseModel)
361                    throws Exception;
362    
363            protected BaseModel<?> getParentBaseModel(
364                            Group group, long parentBaseModelId, ServiceContext serviceContext)
365                    throws Exception {
366    
367                    return group;
368            }
369    
370            protected BaseModel<?> getParentBaseModel(
371                            Group group, ServiceContext serviceContext)
372                    throws Exception {
373    
374                    return group;
375            }
376    
377            protected Class<?> getParentBaseModelClass() {
378                    return getBaseModelClass();
379            }
380    
381            protected String getParentBaseModelClassName() {
382                    Class<?> clazz = getParentBaseModelClass();
383    
384                    return clazz.getName();
385            }
386    
387            protected int getRecentBaseModelsCount(long groupId) throws Exception {
388                    return 0;
389            }
390    
391            protected abstract String getSearchKeywords();
392    
393            protected int getTrashEntriesCount(long groupId) throws Exception {
394                    return TrashEntryLocalServiceUtil.getEntriesCount(groupId);
395            }
396    
397            protected long getTrashEntryClassPK(ClassedModel classedModel) {
398                    return (Long)classedModel.getPrimaryKeyObj();
399            }
400    
401            protected abstract String getUniqueTitle(BaseModel<?> baseModel);
402    
403            protected WorkflowedModel getWorkflowedModel(ClassedModel baseModel)
404                    throws Exception {
405    
406                    return (WorkflowedModel)baseModel;
407            }
408    
409            protected boolean isAssetableModel() {
410                    return true;
411            }
412    
413            protected boolean isAssetableParentModel() {
414                    return true;
415            }
416    
417            protected boolean isAssetEntryVisible(ClassedModel classedModel)
418                    throws Exception {
419    
420                    AssetEntry assetEntry = AssetEntryLocalServiceUtil.getEntry(
421                            classedModel.getModelClassName(), getAssetClassPK(classedModel));
422    
423                    return assetEntry.isVisible();
424            }
425    
426            protected boolean isBaseModelContainerModel() {
427                    if (baseModel instanceof ContainerModel) {
428                            return true;
429                    }
430    
431                    return false;
432            }
433    
434            protected boolean isBaseModelMoveableFromTrash() {
435                    return true;
436            }
437    
438            protected boolean isBaseModelTrashName(ClassedModel classedModel) {
439                    String baseModelName = getBaseModelName(classedModel);
440    
441                    if (baseModelName.startsWith(StringPool.SLASH)) {
442                            return true;
443                    }
444    
445                    return false;
446            }
447    
448            protected boolean isIndexableBaseModel() {
449                    return true;
450            }
451    
452            protected boolean isInTrashContainer(ClassedModel classedModel)
453                    throws Exception {
454    
455                    if (classedModel instanceof TrashedModel) {
456                            TrashedModel trashedModel = (TrashedModel)classedModel;
457    
458                            return trashedModel.isInTrashContainer();
459                    }
460    
461                    return false;
462            }
463    
464            protected BaseModel<?> moveBaseModelFromTrash(
465                            ClassedModel classedModel, Group group,
466                            ServiceContext serviceContext)
467                    throws Exception {
468    
469                    return getParentBaseModel(group, serviceContext);
470            }
471    
472            protected abstract void moveBaseModelToTrash(long primaryKey)
473                    throws Exception;
474    
475            protected void moveParentBaseModelToTrash(long primaryKey)
476                    throws Exception {
477            }
478    
479            protected void restoreParentBaseModelFromTrash(long primaryKey)
480                    throws Exception {
481            }
482    
483            protected int searchBaseModelsCount(Class<?> clazz, long groupId)
484                    throws Exception {
485    
486                    Indexer indexer = IndexerRegistryUtil.getIndexer(clazz);
487    
488                    SearchContext searchContext = SearchContextTestUtil.getSearchContext();
489    
490                    searchContext.setGroupIds(new long[] {groupId});
491    
492                    Hits results = indexer.search(searchContext);
493    
494                    return results.getLength();
495            }
496    
497            protected int searchTrashEntriesCount(
498                            String keywords, ServiceContext serviceContext)
499                    throws Exception {
500    
501                    Hits results = TrashEntryLocalServiceUtil.search(
502                            serviceContext.getCompanyId(), serviceContext.getScopeGroupId(),
503                            serviceContext.getUserId(), keywords, QueryUtil.ALL_POS,
504                            QueryUtil.ALL_POS, null);
505    
506                    return results.getLength();
507            }
508    
509            protected void trashBaseModel(boolean approved, boolean delete)
510                    throws Exception {
511    
512                    ServiceContext serviceContext =
513                            ServiceContextTestUtil.getServiceContext(group.getGroupId());
514    
515                    BaseModel<?> parentBaseModel = getParentBaseModel(
516                            group, serviceContext);
517    
518                    int initialBaseModelsCount = getNotInTrashBaseModelsCount(
519                            parentBaseModel);
520                    int initialBaseModelsSearchCount = 0;
521                    int initialTrashEntriesCount = getTrashEntriesCount(group.getGroupId());
522                    int initialTrashEntriesSearchCount = 0;
523    
524                    if (isIndexableBaseModel()) {
525                            initialBaseModelsSearchCount = searchBaseModelsCount(
526                                    getBaseModelClass(), group.getGroupId());
527                            initialTrashEntriesSearchCount = searchTrashEntriesCount(
528                                    getSearchKeywords(), serviceContext);
529                    }
530    
531                    baseModel = addBaseModel(parentBaseModel, approved, serviceContext);
532    
533                    String uniqueTitle = getUniqueTitle(baseModel);
534    
535                    Assert.assertEquals(
536                            initialBaseModelsCount + 1,
537                            getNotInTrashBaseModelsCount(parentBaseModel));
538    
539                    if (isIndexableBaseModel()) {
540                            if (approved) {
541                                    Assert.assertEquals(
542                                            initialBaseModelsSearchCount + 1,
543                                            searchBaseModelsCount(
544                                                    getBaseModelClass(), group.getGroupId()));
545                            }
546                            else {
547                                    Assert.assertEquals(
548                                            initialBaseModelsSearchCount,
549                                            searchBaseModelsCount(
550                                                    getBaseModelClass(), group.getGroupId()));
551                            }
552    
553                            Assert.assertEquals(
554                                    initialTrashEntriesSearchCount,
555                                    searchTrashEntriesCount(getSearchKeywords(), serviceContext));
556                    }
557    
558                    Assert.assertEquals(
559                            initialTrashEntriesCount, getTrashEntriesCount(group.getGroupId()));
560    
561                    baseModel = getBaseModel((Long)baseModel.getPrimaryKeyObj());
562    
563                    WorkflowedModel workflowedModel = getWorkflowedModel(baseModel);
564    
565                    int oldStatus = workflowedModel.getStatus();
566    
567                    if (isAssetableModel()) {
568                            Assert.assertEquals(approved, isAssetEntryVisible(baseModel));
569                    }
570    
571                    moveBaseModelToTrash((Long)baseModel.getPrimaryKeyObj());
572    
573                    Assert.assertEquals(
574                            initialBaseModelsCount,
575                            getNotInTrashBaseModelsCount(parentBaseModel));
576                    Assert.assertEquals(
577                            initialTrashEntriesCount + 1,
578                            getTrashEntriesCount(group.getGroupId()));
579    
580                    if (isIndexableBaseModel()) {
581                            Assert.assertEquals(
582                                    initialBaseModelsSearchCount,
583                                    searchBaseModelsCount(getBaseModelClass(), group.getGroupId()));
584                            Assert.assertEquals(
585                                    initialTrashEntriesSearchCount + 1,
586                                    searchTrashEntriesCount(getSearchKeywords(), serviceContext));
587                    }
588    
589                    if (uniqueTitle != null) {
590                            Assert.assertEquals(uniqueTitle, getUniqueTitle(baseModel));
591                    }
592    
593                    TrashEntry trashEntry = TrashEntryLocalServiceUtil.getEntry(
594                            getBaseModelClassName(), getTrashEntryClassPK(baseModel));
595    
596                    Assert.assertEquals(
597                            getTrashEntryClassPK(baseModel),
598                            GetterUtil.getLong(trashEntry.getClassPK()));
599    
600                    workflowedModel = getWorkflowedModel(
601                            getBaseModel((Long)baseModel.getPrimaryKeyObj()));
602    
603                    Assert.assertEquals(
604                            WorkflowConstants.STATUS_IN_TRASH, workflowedModel.getStatus());
605    
606                    if (isAssetableModel()) {
607                            Assert.assertFalse(isAssetEntryVisible(baseModel));
608                    }
609    
610                    TrashHandler trashHandler = TrashHandlerRegistryUtil.getTrashHandler(
611                            getBaseModelClassName());
612    
613                    Assert.assertEquals(
614                            1,
615                            getDeletionSystemEventCount(
616                                    trashHandler, trashEntry.getSystemEventSetKey()));
617    
618                    if (delete) {
619                            trashHandler.deleteTrashEntry(getTrashEntryClassPK(baseModel));
620    
621                            Assert.assertEquals(
622                                    initialBaseModelsCount,
623                                    getNotInTrashBaseModelsCount(parentBaseModel));
624    
625                            if (isIndexableBaseModel()) {
626                                    Assert.assertEquals(
627                                            initialBaseModelsSearchCount,
628                                            searchBaseModelsCount(
629                                                    getBaseModelClass(), group.getGroupId()));
630                                    Assert.assertEquals(
631                                            initialTrashEntriesSearchCount,
632                                            searchTrashEntriesCount(
633                                                    getSearchKeywords(), serviceContext));
634                            }
635    
636                            if (isAssetableModel()) {
637                                    Assert.assertNull(fetchAssetEntry(baseModel));
638                            }
639    
640                            Assert.assertEquals(
641                                    1, getDeletionSystemEventCount(trashHandler, -1));
642                    }
643                    else {
644                            trashHandler.restoreTrashEntry(
645                                    TestPropsValues.getUserId(), getTrashEntryClassPK(baseModel));
646    
647                            Assert.assertEquals(
648                                    initialBaseModelsCount + 1,
649                                    getNotInTrashBaseModelsCount(parentBaseModel));
650    
651                            if (isIndexableBaseModel()) {
652                                    if (approved) {
653                                            Assert.assertEquals(
654                                                    initialBaseModelsSearchCount + 1,
655                                                    searchBaseModelsCount(
656                                                            getBaseModelClass(), group.getGroupId()));
657                                    }
658                                    else {
659                                            Assert.assertEquals(
660                                                    initialBaseModelsSearchCount,
661                                                    searchBaseModelsCount(
662                                                            getBaseModelClass(), group.getGroupId()));
663                                    }
664    
665                                    Assert.assertEquals(
666                                            initialTrashEntriesSearchCount,
667                                            searchTrashEntriesCount(
668                                                    getSearchKeywords(), serviceContext));
669                            }
670    
671                            baseModel = getBaseModel((Long)baseModel.getPrimaryKeyObj());
672    
673                            workflowedModel = getWorkflowedModel(baseModel);
674    
675                            Assert.assertEquals(oldStatus, workflowedModel.getStatus());
676    
677                            if (isAssetableModel()) {
678                                    Assert.assertEquals(approved, isAssetEntryVisible(baseModel));
679                            }
680    
681                            if (uniqueTitle != null) {
682                                    Assert.assertEquals(uniqueTitle, getUniqueTitle(baseModel));
683                            }
684    
685                            Assert.assertEquals(
686                                    0, getDeletionSystemEventCount(trashHandler, -1));
687                    }
688            }
689    
690            protected void trashDuplicateBaseModel() throws Exception {
691                    ServiceContext serviceContext =
692                            ServiceContextTestUtil.getServiceContext(group.getGroupId());
693    
694                    BaseModel<?> parentBaseModel = getParentBaseModel(
695                            group, serviceContext);
696    
697                    int initialBaseModelsCount = getNotInTrashBaseModelsCount(
698                            parentBaseModel);
699                    int initialTrashEntriesCount = getTrashEntriesCount(group.getGroupId());
700    
701                    baseModel = addBaseModel(parentBaseModel, true, serviceContext);
702    
703                    moveBaseModelToTrash((Long)baseModel.getPrimaryKeyObj());
704    
705                    baseModel = getBaseModel((Long)baseModel.getPrimaryKeyObj());
706    
707                    Assert.assertEquals(
708                            initialBaseModelsCount,
709                            getNotInTrashBaseModelsCount(parentBaseModel));
710                    Assert.assertEquals(
711                            initialTrashEntriesCount + 1,
712                            getTrashEntriesCount(group.getGroupId()));
713    
714                    Assert.assertTrue(isBaseModelTrashName(baseModel));
715    
716                    BaseModel<?> duplicateBaseModel = addBaseModel(
717                            parentBaseModel, true, serviceContext);
718    
719                    moveBaseModelToTrash((Long)duplicateBaseModel.getPrimaryKeyObj());
720    
721                    duplicateBaseModel = getBaseModel(
722                            (Long)duplicateBaseModel.getPrimaryKeyObj());
723    
724                    Assert.assertEquals(
725                            initialBaseModelsCount,
726                            getNotInTrashBaseModelsCount(parentBaseModel));
727                    Assert.assertEquals(
728                            initialTrashEntriesCount + 2,
729                            getTrashEntriesCount(group.getGroupId()));
730    
731                    Assert.assertTrue(isBaseModelTrashName(duplicateBaseModel));
732            }
733    
734            protected void trashGrandparentBaseModelAndRestoreParentModel()
735                    throws Exception {
736    
737                    ServiceContext serviceContext =
738                            ServiceContextTestUtil.getServiceContext(group.getGroupId());
739    
740                    BaseModel<?> grandparentBaseModel = getParentBaseModel(
741                            group, serviceContext);
742    
743                    int initialBaseModelsCount = getNotInTrashBaseModelsCount(
744                            grandparentBaseModel);
745                    int initialTrashEntriesCount = getTrashEntriesCount(group.getGroupId());
746    
747                    BaseModel<?> parentBaseModel = getParentBaseModel(
748                            group, (Long)grandparentBaseModel.getPrimaryKeyObj(),
749                            serviceContext);
750    
751                    baseModel = addBaseModel(parentBaseModel, true, serviceContext);
752    
753                    if (getBaseModelClassName().equals(getParentBaseModelClassName())) {
754                            Assert.assertEquals(
755                                    initialBaseModelsCount + 1,
756                                    getNotInTrashBaseModelsCount(grandparentBaseModel));
757                    }
758                    else {
759                            Assert.assertEquals(
760                                    initialBaseModelsCount,
761                                    getNotInTrashBaseModelsCount(grandparentBaseModel));
762                    }
763    
764                    Assert.assertEquals(
765                            initialTrashEntriesCount, getTrashEntriesCount(group.getGroupId()));
766    
767                    moveParentBaseModelToTrash(
768                            (Long)grandparentBaseModel.getPrimaryKeyObj());
769    
770                    Assert.assertTrue(isInTrashContainer(baseModel));
771                    Assert.assertTrue(isInTrashContainer(parentBaseModel));
772                    Assert.assertEquals(
773                            initialBaseModelsCount,
774                            getNotInTrashBaseModelsCount(grandparentBaseModel));
775                    Assert.assertEquals(
776                            initialTrashEntriesCount + 1,
777                            getTrashEntriesCount(group.getGroupId()));
778    
779                    TrashHandler parentTrashHandler =
780                            TrashHandlerRegistryUtil.getTrashHandler(
781                                    getParentBaseModelClassName());
782    
783                    if (isAssetableModel()) {
784                            Assert.assertFalse(isAssetEntryVisible(baseModel));
785                    }
786    
787                    if (isAssetableParentModel()) {
788                            Assert.assertFalse(isAssetEntryVisible(parentBaseModel));
789                    }
790    
791                    parentTrashHandler.restoreTrashEntry(
792                            TestPropsValues.getUserId(),
793                            (Long)grandparentBaseModel.getPrimaryKeyObj());
794    
795                    Assert.assertEquals(
796                            initialTrashEntriesCount, getTrashEntriesCount(group.getGroupId()));
797    
798                    Assert.assertFalse(isInTrashContainer(baseModel));
799                    Assert.assertFalse(isInTrashContainer(parentBaseModel));
800    
801                    if (isAssetableModel()) {
802                            Assert.assertTrue(isAssetEntryVisible(baseModel));
803                    }
804    
805                    if (isAssetableParentModel()) {
806                            Assert.assertTrue(isAssetEntryVisible(parentBaseModel));
807                    }
808            }
809    
810            protected void trashIsRestorableBaseModel() throws Exception {
811                    ServiceContext serviceContext =
812                            ServiceContextTestUtil.getServiceContext(group.getGroupId());
813    
814                    baseModel = addBaseModelWithWorkflow(true, serviceContext);
815    
816                    moveBaseModelToTrash((Long)baseModel.getPrimaryKeyObj());
817    
818                    TrashHandler trashHandler = TrashHandlerRegistryUtil.getTrashHandler(
819                            getBaseModelClassName());
820    
821                    boolean restorable = trashHandler.isRestorable(
822                            getAssetClassPK(baseModel));
823    
824                    Assert.assertTrue(restorable);
825            }
826    
827            protected void trashIsRestorableBaseModelWithParent(
828                            boolean deleteParent, boolean moveParentToTrash)
829                    throws Exception {
830    
831                    ServiceContext serviceContext =
832                            ServiceContextTestUtil.getServiceContext(group.getGroupId());
833    
834                    BaseModel<?> parentBaseModel = getParentBaseModel(
835                            group, serviceContext);
836    
837                    baseModel = addBaseModel(parentBaseModel, true, serviceContext);
838    
839                    if (moveParentToTrash) {
840                            moveParentBaseModelToTrash(
841                                    (Long)parentBaseModel.getPrimaryKeyObj());
842                    }
843    
844                    moveBaseModelToTrash((Long)baseModel.getPrimaryKeyObj());
845    
846                    if (deleteParent) {
847                            if (moveParentToTrash) {
848                                    TrashHandler parentTrashHandler =
849                                            TrashHandlerRegistryUtil.getTrashHandler(
850                                                    getParentBaseModelClassName());
851    
852                                    parentTrashHandler.deleteTrashEntry(
853                                            (Long)parentBaseModel.getPrimaryKeyObj());
854                            }
855                            else {
856                                    deleteParentBaseModel(parentBaseModel, false);
857                            }
858                    }
859    
860                    TrashHandler trashHandler = TrashHandlerRegistryUtil.getTrashHandler(
861                            getBaseModelClassName());
862    
863                    boolean restorable = trashHandler.isRestorable(
864                            getAssetClassPK(baseModel));
865    
866                    if (moveParentToTrash || deleteParent) {
867                            Assert.assertFalse(restorable);
868                    }
869                    else {
870                            Assert.assertTrue(restorable);
871                    }
872            }
873    
874            protected void trashMoveBaseModel() throws Exception {
875                    ServiceContext serviceContext =
876                            ServiceContextTestUtil.getServiceContext(group.getGroupId());
877    
878                    int initialBaseModelsSearchCount = 0;
879    
880                    if (isIndexableBaseModel()) {
881                            initialBaseModelsSearchCount = searchBaseModelsCount(
882                                    getBaseModelClass(), group.getGroupId());
883                    }
884    
885                    BaseModel<?> parentBaseModel = getParentBaseModel(
886                            group, serviceContext);
887    
888                    baseModel = addBaseModel(parentBaseModel, true, serviceContext);
889    
890                    moveParentBaseModelToTrash((Long)parentBaseModel.getPrimaryKeyObj());
891    
892                    Assert.assertTrue(isInTrashContainer(baseModel));
893    
894                    if (isIndexableBaseModel()) {
895                            Assert.assertEquals(
896                                    initialBaseModelsSearchCount,
897                                    searchBaseModelsCount(getBaseModelClass(), group.getGroupId()));
898                    }
899    
900                    if (isAssetableModel()) {
901                            Assert.assertFalse(isAssetEntryVisible(baseModel));
902                    }
903    
904                    if (!isBaseModelMoveableFromTrash()) {
905                            return;
906                    }
907    
908                    moveBaseModelFromTrash(baseModel, group, serviceContext);
909    
910                    if (isIndexableBaseModel()) {
911                            if (isBaseModelContainerModel()) {
912                                    Assert.assertEquals(
913                                            initialBaseModelsSearchCount + 2,
914                                            searchBaseModelsCount(
915                                                    getBaseModelClass(), group.getGroupId()));
916                            }
917                            else {
918                                    Assert.assertEquals(
919                                            initialBaseModelsSearchCount + 1,
920                                            searchBaseModelsCount(
921                                                    getBaseModelClass(), group.getGroupId()));
922                            }
923                    }
924    
925                    if (isAssetableModel()) {
926                            Assert.assertTrue(isAssetEntryVisible(baseModel));
927                    }
928            }
929    
930            protected void trashMyBaseModel() throws Exception {
931                    ServiceContext serviceContext =
932                            ServiceContextTestUtil.getServiceContext(group.getGroupId());
933    
934                    BaseModel<?> parentBaseModel = getParentBaseModel(
935                            group, serviceContext);
936    
937                    int initialBaseModelsCount = getMineBaseModelsCount(
938                            group.getGroupId(), TestPropsValues.getUserId());
939    
940                    addBaseModel(parentBaseModel, true, serviceContext);
941    
942                    Assert.assertEquals(
943                            initialBaseModelsCount + 1,
944                            getMineBaseModelsCount(
945                                    group.getGroupId(), TestPropsValues.getUserId()));
946    
947                    moveParentBaseModelToTrash((Long)parentBaseModel.getPrimaryKeyObj());
948    
949                    Assert.assertEquals(
950                            initialBaseModelsCount,
951                            getMineBaseModelsCount(
952                                    group.getGroupId(), TestPropsValues.getUserId()));
953            }
954    
955            protected void trashParentBaseModel(
956                            boolean moveBaseModelToTrash, boolean deleteTrashEntries,
957                            boolean deleteGroupTrashEntries)
958                    throws Exception {
959    
960                    ServiceContext serviceContext =
961                            ServiceContextTestUtil.getServiceContext(group.getGroupId());
962    
963                    BaseModel<?> parentBaseModel = getParentBaseModel(
964                            group, serviceContext);
965    
966                    int initialBaseModelsCount = getNotInTrashBaseModelsCount(
967                            parentBaseModel);
968                    int initialTrashEntriesCount = getTrashEntriesCount(group.getGroupId());
969    
970                    baseModel = addBaseModel(parentBaseModel, true, serviceContext);
971    
972                    Assert.assertEquals(
973                            initialBaseModelsCount + 1,
974                            getNotInTrashBaseModelsCount(parentBaseModel));
975                    Assert.assertEquals(
976                            initialTrashEntriesCount, getTrashEntriesCount(group.getGroupId()));
977    
978                    if (moveBaseModelToTrash) {
979                            moveBaseModelToTrash((Long)baseModel.getPrimaryKeyObj());
980    
981                            Assert.assertEquals(
982                                    initialBaseModelsCount,
983                                    getNotInTrashBaseModelsCount(parentBaseModel));
984                            Assert.assertEquals(
985                                    initialTrashEntriesCount + 1,
986                                    getTrashEntriesCount(group.getGroupId()));
987    
988                            Assert.assertFalse(isInTrashContainer(baseModel));
989                    }
990    
991                    moveParentBaseModelToTrash((Long)parentBaseModel.getPrimaryKeyObj());
992    
993                    Assert.assertTrue(isInTrashContainer(baseModel));
994    
995                    if (moveBaseModelToTrash) {
996                            Assert.assertEquals(
997                                    initialTrashEntriesCount + 2,
998                                    getTrashEntriesCount(group.getGroupId()));
999                    }
1000                    else {
1001                            Assert.assertEquals(
1002                                    initialBaseModelsCount,
1003                                    getNotInTrashBaseModelsCount(parentBaseModel));
1004                            Assert.assertEquals(
1005                                    initialTrashEntriesCount + 1,
1006                                    getTrashEntriesCount(group.getGroupId()));
1007                    }
1008    
1009                    TrashHandler parentTrashHandler =
1010                            TrashHandlerRegistryUtil.getTrashHandler(
1011                                    getParentBaseModelClassName());
1012    
1013                    if (getBaseModelClassName().equals(getParentBaseModelClassName())) {
1014                            Assert.assertEquals(
1015                                    0,
1016                                    parentTrashHandler.getTrashContainedModelsCount(
1017                                            (Long)parentBaseModel.getPrimaryKeyObj()));
1018                            Assert.assertEquals(
1019                                    1,
1020                                    parentTrashHandler.getTrashContainerModelsCount(
1021                                            (Long)parentBaseModel.getPrimaryKeyObj()));
1022                    }
1023                    else {
1024                            Assert.assertEquals(
1025                                    1,
1026                                    parentTrashHandler.getTrashContainedModelsCount(
1027                                            (Long)parentBaseModel.getPrimaryKeyObj()));
1028                            Assert.assertEquals(
1029                                    0,
1030                                    parentTrashHandler.getTrashContainerModelsCount(
1031                                            (Long)parentBaseModel.getPrimaryKeyObj()));
1032                    }
1033    
1034                    if (isAssetableModel()) {
1035                            Assert.assertFalse(isAssetEntryVisible(baseModel));
1036                    }
1037    
1038                    if (deleteGroupTrashEntries) {
1039                            TrashEntryServiceUtil.deleteEntries(group.getGroupId());
1040    
1041                            Assert.assertEquals(0, getTrashEntriesCount(group.getGroupId()));
1042    
1043                            try {
1044                                    getBaseModel((Long)baseModel.getPrimaryKeyObj());
1045    
1046                                    Assert.fail();
1047                            }
1048                            catch (NoSuchModelException nsme) {
1049                            }
1050                    }
1051                    else if (deleteTrashEntries) {
1052                            parentTrashHandler.deleteTrashEntry(
1053                                    (Long)parentBaseModel.getPrimaryKeyObj());
1054    
1055                            Assert.assertEquals(
1056                                    initialBaseModelsCount,
1057                                    getNotInTrashBaseModelsCount(parentBaseModel));
1058    
1059                            if (isBaseModelMoveableFromTrash() && moveBaseModelToTrash) {
1060                                    Assert.assertEquals(
1061                                            initialTrashEntriesCount + 1,
1062                                            getTrashEntriesCount(group.getGroupId()));
1063    
1064                                    TrashHandler trashHandler =
1065                                            TrashHandlerRegistryUtil.getTrashHandler(
1066                                                    getBaseModelClassName());
1067    
1068                                    trashHandler.deleteTrashEntry(getTrashEntryClassPK(baseModel));
1069                            }
1070                            else {
1071                                    try {
1072                                            getBaseModel((Long)baseModel.getPrimaryKeyObj());
1073    
1074                                            Assert.fail();
1075                                    }
1076                                    catch (NoSuchModelException nsme) {
1077                                    }
1078                            }
1079    
1080                            Assert.assertEquals(
1081                                    initialTrashEntriesCount,
1082                                    getTrashEntriesCount(group.getGroupId()));
1083                    }
1084                    else if (isBaseModelMoveableFromTrash()) {
1085                            BaseModel<?> newParentBaseModel = moveBaseModelFromTrash(
1086                                    baseModel, group, serviceContext);
1087    
1088                            Assert.assertEquals(
1089                                    initialBaseModelsCount + 1,
1090                                    getNotInTrashBaseModelsCount(newParentBaseModel));
1091                            Assert.assertEquals(
1092                                    initialTrashEntriesCount + 1,
1093                                    getTrashEntriesCount(group.getGroupId()));
1094    
1095                            if (isAssetableModel()) {
1096                                    Assert.assertTrue(isAssetEntryVisible(baseModel));
1097                            }
1098                    }
1099            }
1100    
1101            protected void trashRecentBaseModel() throws Exception {
1102                    ServiceContext serviceContext =
1103                            ServiceContextTestUtil.getServiceContext(group.getGroupId());
1104    
1105                    BaseModel<?> parentBaseModel = getParentBaseModel(
1106                            group, serviceContext);
1107    
1108                    int initialBaseModelsCount = getRecentBaseModelsCount(
1109                            group.getGroupId());
1110    
1111                    addBaseModel(parentBaseModel, true, serviceContext);
1112    
1113                    Assert.assertEquals(
1114                            initialBaseModelsCount + 1,
1115                            getRecentBaseModelsCount(group.getGroupId()));
1116    
1117                    moveParentBaseModelToTrash((Long)parentBaseModel.getPrimaryKeyObj());
1118    
1119                    Assert.assertEquals(
1120                            initialBaseModelsCount,
1121                            getRecentBaseModelsCount(group.getGroupId()));
1122            }
1123    
1124            protected void trashVersionBaseModel(boolean delete) throws Exception {
1125                    ServiceContext serviceContext =
1126                            ServiceContextTestUtil.getServiceContext(group.getGroupId());
1127    
1128                    BaseModel<?> parentBaseModel = getParentBaseModel(
1129                            group, serviceContext);
1130    
1131                    int initialBaseModelsCount = getNotInTrashBaseModelsCount(
1132                            parentBaseModel);
1133                    int initialBaseModelsSearchCount = 0;
1134                    int initialTrashEntriesCount = getTrashEntriesCount(group.getGroupId());
1135                    int initialTrashEntriesSearchCount = 0;
1136    
1137                    if (isIndexableBaseModel()) {
1138                            initialBaseModelsSearchCount = searchBaseModelsCount(
1139                                    getBaseModelClass(), group.getGroupId());
1140                            initialTrashEntriesSearchCount = searchTrashEntriesCount(
1141                                    getSearchKeywords(), serviceContext);
1142                    }
1143    
1144                    baseModel = addBaseModel(parentBaseModel, true, serviceContext);
1145    
1146                    baseModel = updateBaseModel(
1147                            (Long)baseModel.getPrimaryKeyObj(), serviceContext);
1148    
1149                    Assert.assertEquals(
1150                            initialBaseModelsCount + 1,
1151                            getNotInTrashBaseModelsCount(parentBaseModel));
1152                    Assert.assertEquals(
1153                            initialTrashEntriesCount, getTrashEntriesCount(group.getGroupId()));
1154    
1155                    if (isIndexableBaseModel()) {
1156                            Assert.assertEquals(
1157                                    initialBaseModelsSearchCount + 1,
1158                                    searchBaseModelsCount(getBaseModelClass(), group.getGroupId()));
1159                            Assert.assertEquals(
1160                                    initialTrashEntriesSearchCount,
1161                                    searchTrashEntriesCount(getSearchKeywords(), serviceContext));
1162                    }
1163    
1164                    if (isAssetableModel()) {
1165                            Assert.assertTrue(isAssetEntryVisible(baseModel));
1166                    }
1167    
1168                    moveBaseModelToTrash((Long)baseModel.getPrimaryKeyObj());
1169    
1170                    Assert.assertEquals(
1171                            initialBaseModelsCount,
1172                            getNotInTrashBaseModelsCount(parentBaseModel));
1173                    Assert.assertEquals(
1174                            initialTrashEntriesCount + 1,
1175                            getTrashEntriesCount(group.getGroupId()));
1176    
1177                    if (isIndexableBaseModel()) {
1178                            Assert.assertEquals(
1179                                    initialBaseModelsSearchCount,
1180                                    searchBaseModelsCount(getBaseModelClass(), group.getGroupId()));
1181                            Assert.assertEquals(
1182                                    initialTrashEntriesSearchCount + 1,
1183                                    searchTrashEntriesCount(getSearchKeywords(), serviceContext));
1184                    }
1185    
1186                    if (isAssetableModel()) {
1187                            Assert.assertFalse(isAssetEntryVisible(baseModel));
1188                    }
1189    
1190                    TrashHandler trashHandler = TrashHandlerRegistryUtil.getTrashHandler(
1191                            getBaseModelClassName());
1192    
1193                    if (delete) {
1194                            trashHandler.deleteTrashEntry(getTrashEntryClassPK(baseModel));
1195    
1196                            Assert.assertEquals(
1197                                    initialBaseModelsCount,
1198                                    getNotInTrashBaseModelsCount(parentBaseModel));
1199                            Assert.assertEquals(
1200                                    initialTrashEntriesCount,
1201                                    getTrashEntriesCount(group.getGroupId()));
1202    
1203                            if (isIndexableBaseModel()) {
1204                                    Assert.assertEquals(
1205                                            initialBaseModelsSearchCount,
1206                                            searchBaseModelsCount(
1207                                                    getBaseModelClass(), group.getGroupId()));
1208                                    Assert.assertEquals(
1209                                            initialTrashEntriesSearchCount,
1210                                            searchTrashEntriesCount(
1211                                                    getSearchKeywords(), serviceContext));
1212                            }
1213    
1214                            if (isAssetableModel()) {
1215                                    Assert.assertNull(fetchAssetEntry(baseModel));
1216                            }
1217                    }
1218                    else {
1219                            trashHandler.restoreTrashEntry(
1220                                    TestPropsValues.getUserId(), getTrashEntryClassPK(baseModel));
1221    
1222                            Assert.assertEquals(
1223                                    initialBaseModelsCount + 1,
1224                                    getNotInTrashBaseModelsCount(parentBaseModel));
1225                            Assert.assertEquals(
1226                                    initialTrashEntriesCount,
1227                                    getTrashEntriesCount(group.getGroupId()));
1228    
1229                            if (isIndexableBaseModel()) {
1230                                    Assert.assertEquals(
1231                                            initialBaseModelsSearchCount + 1,
1232                                            searchBaseModelsCount(
1233                                                    getBaseModelClass(), group.getGroupId()));
1234                                    Assert.assertEquals(
1235                                            initialTrashEntriesSearchCount,
1236                                            searchTrashEntriesCount(
1237                                                    getSearchKeywords(), serviceContext));
1238                            }
1239    
1240                            if (isAssetableModel()) {
1241                                    Assert.assertTrue(isAssetEntryVisible(baseModel));
1242                            }
1243                    }
1244            }
1245    
1246            protected void trashVersionParentBaseModel(boolean moveBaseModel)
1247                    throws Exception {
1248    
1249                    ServiceContext serviceContext =
1250                            ServiceContextTestUtil.getServiceContext(group.getGroupId());
1251    
1252                    BaseModel<?> parentBaseModel = getParentBaseModel(
1253                            group, serviceContext);
1254    
1255                    int initialBaseModelsCount = getNotInTrashBaseModelsCount(
1256                            parentBaseModel);
1257                    int initialBaseModelsSearchCount = 0;
1258                    int initialTrashEntriesCount = getTrashEntriesCount(group.getGroupId());
1259                    int initialTrashEntriesSearchCount = 0;
1260    
1261                    if (isIndexableBaseModel()) {
1262                            initialBaseModelsSearchCount = searchBaseModelsCount(
1263                                    getBaseModelClass(), group.getGroupId());
1264                            initialTrashEntriesSearchCount = searchTrashEntriesCount(
1265                                    getSearchKeywords(), serviceContext);
1266                    }
1267    
1268                    List<Integer> originalStatuses = new ArrayList<Integer>();
1269    
1270                    baseModel = addBaseModel(parentBaseModel, true, serviceContext);
1271    
1272                    baseModel = expireBaseModel(baseModel, serviceContext);
1273    
1274                    WorkflowedModel workflowedModel = getWorkflowedModel(baseModel);
1275    
1276                    originalStatuses.add(workflowedModel.getStatus());
1277    
1278                    serviceContext.setWorkflowAction(WorkflowConstants.ACTION_PUBLISH);
1279    
1280                    baseModel = updateBaseModel(
1281                            (Long)baseModel.getPrimaryKeyObj(), serviceContext);
1282    
1283                    workflowedModel = getWorkflowedModel(baseModel);
1284    
1285                    originalStatuses.add(workflowedModel.getStatus());
1286    
1287                    serviceContext.setWorkflowAction(WorkflowConstants.ACTION_SAVE_DRAFT);
1288    
1289                    baseModel = updateBaseModel(
1290                            (Long)baseModel.getPrimaryKeyObj(), serviceContext);
1291    
1292                    workflowedModel = getWorkflowedModel(baseModel);
1293    
1294                    originalStatuses.add(workflowedModel.getStatus());
1295    
1296                    Assert.assertEquals(
1297                            initialBaseModelsCount + 1,
1298                            getNotInTrashBaseModelsCount(parentBaseModel));
1299                    Assert.assertEquals(
1300                            initialTrashEntriesCount, getTrashEntriesCount(group.getGroupId()));
1301    
1302                    if (isIndexableBaseModel()) {
1303                            Assert.assertEquals(
1304                                    initialBaseModelsSearchCount + 1,
1305                                    searchBaseModelsCount(getBaseModelClass(), group.getGroupId()));
1306                            Assert.assertEquals(
1307                                    initialTrashEntriesSearchCount,
1308                                    searchTrashEntriesCount(getSearchKeywords(), serviceContext));
1309                    }
1310    
1311                    if (isAssetableModel()) {
1312                            Assert.assertTrue(isAssetEntryVisible(baseModel));
1313                    }
1314    
1315                    moveParentBaseModelToTrash((Long)parentBaseModel.getPrimaryKeyObj());
1316    
1317                    Assert.assertEquals(
1318                            initialTrashEntriesCount + 1,
1319                            getTrashEntriesCount(group.getGroupId()));
1320                    Assert.assertTrue(isInTrashContainer(baseModel));
1321    
1322                    if (isAssetableModel()) {
1323                            Assert.assertFalse(isAssetEntryVisible(baseModel));
1324                    }
1325    
1326                    if (moveBaseModel && isBaseModelMoveableFromTrash()) {
1327                            BaseModel<?> newParentBaseModel = moveBaseModelFromTrash(
1328                                    baseModel, group, serviceContext);
1329    
1330                            baseModel = getBaseModel((Long)baseModel.getPrimaryKeyObj());
1331    
1332                            Assert.assertEquals(
1333                                    initialBaseModelsCount + 1,
1334                                    getNotInTrashBaseModelsCount(newParentBaseModel));
1335                            Assert.assertEquals(
1336                                    initialTrashEntriesCount + 1,
1337                                    getTrashEntriesCount(group.getGroupId()));
1338                            Assert.assertFalse(isInTrashContainer(baseModel));
1339    
1340                            if (isAssetableModel()) {
1341                                    Assert.assertTrue(isAssetEntryVisible(baseModel));
1342                            }
1343                    }
1344                    else {
1345                            restoreParentBaseModelFromTrash(
1346                                    (Long)parentBaseModel.getPrimaryKeyObj());
1347    
1348                            List<? extends WorkflowedModel> childrenWorkflowedModels =
1349                                    getChildrenWorkflowedModels(parentBaseModel);
1350    
1351                            for (int i = 1; i <= childrenWorkflowedModels.size(); i++) {
1352                                    WorkflowedModel childrenWorkflowedModel =
1353                                            childrenWorkflowedModels.get(i - 1);
1354    
1355                                    int originalStatus = originalStatuses.get(
1356                                            childrenWorkflowedModels.size() - i);
1357    
1358                                    Assert.assertEquals(
1359                                            originalStatus, childrenWorkflowedModel.getStatus());
1360                            }
1361                    }
1362            }
1363    
1364            protected BaseModel<?> updateBaseModel(
1365                            long primaryKey, ServiceContext serviceContext)
1366                    throws Exception {
1367    
1368                    return getBaseModel(primaryKey);
1369            }
1370    
1371            protected BaseModel<?> baseModel;
1372    
1373            @DeleteAfterTestRun
1374            protected Group group;
1375    
1376    }