/** * 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.message.boards.lar.test; import com.liferay.arquillian.extension.junit.bridge.junit.Arquillian; import com.liferay.exportimport.kernel.lar.ManifestSummary; import com.liferay.exportimport.kernel.lar.StagedModelType; import com.liferay.message.boards.kernel.model.MBCategory; import com.liferay.message.boards.kernel.model.MBCategoryConstants; import com.liferay.message.boards.kernel.model.MBMessage; import com.liferay.message.boards.kernel.model.MBThread; import com.liferay.message.boards.kernel.service.MBBanLocalServiceUtil; import com.liferay.message.boards.kernel.service.MBCategoryLocalServiceUtil; import com.liferay.message.boards.kernel.service.MBCategoryServiceUtil; import com.liferay.message.boards.kernel.service.MBMessageLocalServiceUtil; import com.liferay.message.boards.kernel.service.MBThreadFlagLocalServiceUtil; import com.liferay.message.boards.web.constants.MBPortletKeys; import com.liferay.message.boards.web.exportimport.data.handler.MBPortletDataHandler; import com.liferay.portal.kernel.model.Group; import com.liferay.portal.kernel.model.User; import com.liferay.portal.kernel.service.GroupLocalServiceUtil; import com.liferay.portal.kernel.service.ServiceContext; import com.liferay.portal.kernel.test.rule.AggregateTestRule; 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.kernel.test.util.UserTestUtil; import com.liferay.portal.kernel.util.LongWrapper; import com.liferay.portal.kernel.util.StringPool; import com.liferay.portal.kernel.workflow.WorkflowConstants; import com.liferay.portal.lar.test.BasePortletDataHandlerTestCase; import com.liferay.portal.service.test.ServiceTestUtil; import com.liferay.portal.test.rule.LiferayIntegrationTestRule; import java.util.Collection; import java.util.List; import java.util.Map; import org.junit.Assert; import org.junit.Before; import org.junit.ClassRule; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; /** * @author Zsolt Berentey */ @RunWith(Arquillian.class) public class MBPortletDataHandlerTest extends BasePortletDataHandlerTestCase { @ClassRule @Rule public static final AggregateTestRule aggregateTestRule = new LiferayIntegrationTestRule(); @Before @Override public void setUp() throws Exception { super.setUp(); ServiceTestUtil.setUser(TestPropsValues.getUser()); } @Test public void testDeleteAllFolders() throws Exception { Group group = GroupTestUtil.addGroup(); ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext( group.getGroupId(), TestPropsValues.getUserId()); MBCategory parentCategory = MBCategoryServiceUtil.addCategory( TestPropsValues.getUserId(), MBCategoryConstants.DEFAULT_PARENT_CATEGORY_ID, RandomTestUtil.randomString(), StringPool.BLANK, serviceContext); MBCategory childCategory = MBCategoryServiceUtil.addCategory( TestPropsValues.getUserId(), parentCategory.getCategoryId(), RandomTestUtil.randomString(), StringPool.BLANK, serviceContext); MBCategoryLocalServiceUtil.moveCategoryToTrash( TestPropsValues.getUserId(), childCategory.getCategoryId()); MBCategoryLocalServiceUtil.moveCategoryToTrash( TestPropsValues.getUserId(), parentCategory.getCategoryId()); MBCategoryLocalServiceUtil.deleteCategory(parentCategory, false); GroupLocalServiceUtil.deleteGroup(group); List<MBCategory> categories = MBCategoryLocalServiceUtil.getCategories( group.getGroupId()); Assert.assertEquals(categories.toString(), 0, categories.size()); } @Override protected void addParameters(Map<String, String[]> parameterMap) { addBooleanParameter( parameterMap, MBPortletDataHandler.NAMESPACE, "messages", true); addBooleanParameter( parameterMap, MBPortletDataHandler.NAMESPACE, "thread-flags", true); addBooleanParameter( parameterMap, MBPortletDataHandler.NAMESPACE, "user-bans", true); } @Override protected void addStagedModels() throws Exception { ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext( stagingGroup.getGroupId(), TestPropsValues.getUserId()); MBCategory category = MBCategoryServiceUtil.addCategory( TestPropsValues.getUserId(), MBCategoryConstants.DEFAULT_PARENT_CATEGORY_ID, RandomTestUtil.randomString(), StringPool.BLANK, serviceContext); serviceContext.setWorkflowAction(WorkflowConstants.ACTION_PUBLISH); MBMessage message = MBMessageLocalServiceUtil.addMessage( TestPropsValues.getUserId(), RandomTestUtil.randomString(), stagingGroup.getGroupId(), category.getCategoryId(), RandomTestUtil.randomString(), RandomTestUtil.randomString(), serviceContext); MBThreadFlagLocalServiceUtil.addThreadFlag( TestPropsValues.getUserId(), message.getThread(), serviceContext); User user = UserTestUtil.addUser(TestPropsValues.getGroupId()); MBBanLocalServiceUtil.addBan( TestPropsValues.getUserId(), user.getUserId(), serviceContext); } @Override protected void checkManifestSummary( ManifestSummary expectedManifestSummary) { String manifestSummaryKey = ManifestSummary.getManifestSummaryKey( new StagedModelType(MBThread.class.getName())); Collection<String> manifestSummaryKeys = expectedManifestSummary.getManifestSummaryKeys(); manifestSummaryKeys.remove(manifestSummaryKey); Map<String, LongWrapper> modelAdditionCounters = expectedManifestSummary.getModelAdditionCounters(); modelAdditionCounters.remove(manifestSummaryKey); Map<String, LongWrapper> modelDeletionCounters = expectedManifestSummary.getModelDeletionCounters(); modelDeletionCounters.remove(manifestSummaryKey); super.checkManifestSummary(expectedManifestSummary); } @Override protected String getPortletId() { return MBPortletKeys.MESSAGE_BOARDS; } }