/**
* 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.message.boards.kernel.model.MBBan;
import com.liferay.message.boards.kernel.service.MBBanLocalServiceUtil;
import com.liferay.portal.kernel.model.Group;
import com.liferay.portal.kernel.model.StagedModel;
import com.liferay.portal.kernel.model.User;
import com.liferay.portal.kernel.service.ServiceContext;
import com.liferay.portal.kernel.test.rule.AggregateTestRule;
import com.liferay.portal.kernel.test.rule.Sync;
import com.liferay.portal.kernel.test.rule.SynchronousDestinationTestRule;
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.lar.test.BaseStagedModelDataHandlerTestCase;
import com.liferay.portal.test.rule.LiferayIntegrationTestRule;
import java.util.List;
import java.util.Map;
import org.junit.Assert;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.runner.RunWith;
/**
* @author Daniel Kocsis
*/
@RunWith(Arquillian.class)
@Sync
public class MBBanStagedModelDataHandlerTest
extends BaseStagedModelDataHandlerTestCase {
@ClassRule
@Rule
public static final AggregateTestRule aggregateTestRule =
new AggregateTestRule(
new LiferayIntegrationTestRule(),
SynchronousDestinationTestRule.INSTANCE);
@Override
protected StagedModel addStagedModel(
Group group,
Map<String, List<StagedModel>> dependentStagedModelsMap)
throws Exception {
ServiceContext serviceContext =
ServiceContextTestUtil.getServiceContext(
group.getGroupId(), TestPropsValues.getUserId());
User user = UserTestUtil.addUser(TestPropsValues.getGroupId());
return MBBanLocalServiceUtil.addBan(
TestPropsValues.getUserId(), user.getUserId(), serviceContext);
}
@Override
protected StagedModel getStagedModel(String uuid, Group group) {
List<MBBan> bans = null;
try {
bans = MBBanLocalServiceUtil.getBans(group.getGroupId(), 0, 1);
if (!bans.isEmpty()) {
return bans.get(0);
}
}
catch (Exception e) {
}
return null;
}
@Override
protected Class<? extends StagedModel> getStagedModelClass() {
return MBBan.class;
}
@Override
protected void validateImport(
StagedModel stagedModel, StagedModelAssets stagedModelAssets,
Map<String, List<StagedModel>> dependentStagedModelsMap,
Group group)
throws Exception {
super.validateImport(
stagedModel, stagedModelAssets, dependentStagedModelsMap, group);
MBBan ban = (MBBan)stagedModel;
MBBan importedBan = (MBBan)getStagedModel(stagedModel.getUuid(), group);
Assert.assertEquals(ban.getBanUserUuid(), importedBan.getBanUserUuid());
}
}