/** * Copyright (c) 2000-present Liferay, Inc. All rights reserved. * * This library is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the Free * Software Foundation; either version 2.1 of the License, or (at your option) * any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. */ package com.liferay.bookmarks.verify.test; import com.liferay.arquillian.extension.junit.bridge.junit.Arquillian; import com.liferay.bookmarks.model.BookmarksEntry; import com.liferay.bookmarks.model.BookmarksFolder; import com.liferay.bookmarks.service.BookmarksEntryLocalServiceUtil; import com.liferay.bookmarks.service.BookmarksFolderLocalServiceUtil; import com.liferay.bookmarks.util.test.BookmarksTestUtil; import com.liferay.portal.kernel.model.Group; import com.liferay.portal.kernel.service.ServiceContext; import com.liferay.portal.kernel.test.rule.AggregateTestRule; import com.liferay.portal.kernel.test.rule.DeleteAfterTestRun; import com.liferay.portal.kernel.test.rule.Sync; import com.liferay.portal.kernel.test.rule.SynchronousDestinationTestRule; import com.liferay.portal.kernel.test.util.GroupTestUtil; import com.liferay.portal.kernel.test.util.RandomTestUtil; import com.liferay.portal.kernel.test.util.ServiceContextTestUtil; import com.liferay.portal.kernel.test.util.TestPropsValues; import com.liferay.portal.service.test.ServiceTestUtil; import com.liferay.portal.test.rule.LiferayIntegrationTestRule; import com.liferay.portal.verify.VerifyProcess; import com.liferay.portal.verify.test.BaseVerifyProcessTestCase; import com.liferay.registry.Filter; import com.liferay.registry.Registry; import com.liferay.registry.RegistryUtil; import com.liferay.registry.ServiceTracker; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.ClassRule; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; /** * @author Manuel de la Peña * @author Eudaldo Alonso * @author Sergio González */ @RunWith(Arquillian.class) @Sync public class BookmarksServiceVerifyProcessTest extends BaseVerifyProcessTestCase { @ClassRule @Rule public static final AggregateTestRule aggregateTestRule = new AggregateTestRule( new LiferayIntegrationTestRule(), SynchronousDestinationTestRule.INSTANCE); @BeforeClass public static void setUpClass() { Registry registry = RegistryUtil.getRegistry(); Filter filter = registry.getFilter( "(&(objectClass=" + VerifyProcess.class.getName() + ")(verify.process.name=com.liferay.bookmarks.service))"); _serviceTracker = registry.trackServices(filter); _serviceTracker.open(); } @AfterClass public static void tearDownClass() { _serviceTracker.close(); } @Before @Override public void setUp() throws Exception { super.setUp(); ServiceTestUtil.setUser(TestPropsValues.getUser()); _group = GroupTestUtil.addGroup(); } @Test public void testBookmarksEntryTreePathWithBookmarksEntryInTrash() throws Exception { BookmarksFolder parentFolder = BookmarksTestUtil.addFolder( _group.getGroupId(), RandomTestUtil.randomString()); ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group.getGroupId()); BookmarksEntry entry = BookmarksTestUtil.addEntry( parentFolder.getFolderId(), true, serviceContext); BookmarksEntryLocalServiceUtil.moveEntryToTrash( TestPropsValues.getUserId(), entry.getEntryId()); BookmarksFolderLocalServiceUtil.deleteFolder( parentFolder.getFolderId(), false); doVerify(); } @Test public void testBookmarksEntryTreePathWithBookmarksParentFolderInTrash() throws Exception { BookmarksFolder grandparentFolder = BookmarksTestUtil.addFolder( _group.getGroupId(), RandomTestUtil.randomString()); BookmarksFolder parentFolder = BookmarksTestUtil.addFolder( _group.getGroupId(), grandparentFolder.getFolderId(), RandomTestUtil.randomString()); ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group.getGroupId()); BookmarksTestUtil.addEntry( parentFolder.getFolderId(), true, serviceContext); BookmarksFolderLocalServiceUtil.moveFolderToTrash( TestPropsValues.getUserId(), parentFolder.getFolderId()); BookmarksFolderLocalServiceUtil.deleteFolder( grandparentFolder.getFolderId(), false); doVerify(); } @Test public void testBookmarksFolderTreePathWithBookmarksFolderInTrash() throws Exception { BookmarksFolder parentFolder = BookmarksTestUtil.addFolder( _group.getGroupId(), RandomTestUtil.randomString()); BookmarksFolder folder = BookmarksTestUtil.addFolder( _group.getGroupId(), parentFolder.getFolderId(), RandomTestUtil.randomString()); BookmarksFolderLocalServiceUtil.moveFolderToTrash( TestPropsValues.getUserId(), folder.getFolderId()); BookmarksFolderLocalServiceUtil.deleteFolder( parentFolder.getFolderId(), false); doVerify(); } @Test public void testBookmarksFolderTreePathWithBookmarksParentFolderInTrash() throws Exception { BookmarksFolder grandparentFolder = BookmarksTestUtil.addFolder( _group.getGroupId(), RandomTestUtil.randomString()); BookmarksFolder parentFolder = BookmarksTestUtil.addFolder( _group.getGroupId(), grandparentFolder.getFolderId(), RandomTestUtil.randomString()); BookmarksTestUtil.addFolder( _group.getGroupId(), parentFolder.getFolderId(), RandomTestUtil.randomString()); BookmarksFolderLocalServiceUtil.moveFolderToTrash( TestPropsValues.getUserId(), parentFolder.getFolderId()); BookmarksFolderLocalServiceUtil.deleteFolder( grandparentFolder.getFolderId(), false); doVerify(); } @Override protected VerifyProcess getVerifyProcess() { return _serviceTracker.getService(); } private static ServiceTracker<VerifyProcess, VerifyProcess> _serviceTracker; @DeleteAfterTestRun private Group _group; }