/**
* 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.document.library.internal.exportimport.data.handler.test;
import com.liferay.arquillian.extension.junit.bridge.junit.Arquillian;
import com.liferay.document.library.kernel.model.DLFolderConstants;
import com.liferay.document.library.kernel.service.DLAppServiceUtil;
import com.liferay.portal.kernel.model.Group;
import com.liferay.portal.kernel.model.Repository;
import com.liferay.portal.kernel.model.RepositoryEntry;
import com.liferay.portal.kernel.model.StagedModel;
import com.liferay.portal.kernel.repository.model.Folder;
import com.liferay.portal.kernel.service.RepositoryEntryLocalServiceUtil;
import com.liferay.portal.kernel.service.RepositoryLocalServiceUtil;
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.RandomTestUtil;
import com.liferay.portal.kernel.test.util.ServiceContextTestUtil;
import com.liferay.portal.kernel.test.util.TestPropsValues;
import com.liferay.portal.kernel.util.PortalUtil;
import com.liferay.portal.kernel.util.UnicodeProperties;
import com.liferay.portal.lar.test.BaseStagedModelDataHandlerTestCase;
import com.liferay.portal.repository.liferayrepository.LiferayRepository;
import com.liferay.portal.test.rule.LiferayIntegrationTestRule;
import java.util.HashMap;
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 Mate Thurzo
*/
@RunWith(Arquillian.class)
@Sync
public class RepositoryStagedModelDataHandlerTest
extends BaseStagedModelDataHandlerTestCase {
@ClassRule
@Rule
public static final AggregateTestRule aggregateTestRule =
new AggregateTestRule(
new LiferayIntegrationTestRule(),
SynchronousDestinationTestRule.INSTANCE);
@Override
protected Map<String, List<StagedModel>> addDependentStagedModelsMap(
Group group)
throws Exception {
Map<String, List<StagedModel>> dependentStagedModelsMap =
new HashMap<>();
long classNameId = PortalUtil.getClassNameId(
LiferayRepository.class.getName());
ServiceContext serviceContext =
ServiceContextTestUtil.getServiceContext(
group.getGroupId(), TestPropsValues.getUserId());
Folder mountFolder = DLAppServiceUtil.addFolder(
group.getGroupId(), DLFolderConstants.DEFAULT_PARENT_FOLDER_ID,
RandomTestUtil.randomString(), RandomTestUtil.randomString(),
serviceContext);
_repository = RepositoryLocalServiceUtil.addRepository(
TestPropsValues.getUserId(), group.getGroupId(), classNameId,
mountFolder.getFolderId(), RandomTestUtil.randomString(),
RandomTestUtil.randomString(), RandomTestUtil.randomString(),
new UnicodeProperties(), false, serviceContext);
RepositoryEntry repositoryEntry =
RepositoryEntryLocalServiceUtil.addRepositoryEntry(
TestPropsValues.getUserId(), group.getGroupId(),
_repository.getRepositoryId(), RandomTestUtil.randomString(),
serviceContext);
addDependentStagedModel(
dependentStagedModelsMap, RepositoryEntry.class, repositoryEntry);
return dependentStagedModelsMap;
}
@Override
protected StagedModel addStagedModel(
Group group,
Map<String, List<StagedModel>> dependentStagedModelsMap)
throws Exception {
return _repository;
}
@Override
protected StagedModel getStagedModel(String uuid, Group group) {
try {
return RepositoryLocalServiceUtil.getRepositoryByUuidAndGroupId(
uuid, group.getGroupId());
}
catch (Exception e) {
return null;
}
}
@Override
protected Class<? extends StagedModel> getStagedModelClass() {
return Repository.class;
}
@Override
protected void validateImport(
Map<String, List<StagedModel>> dependentStagedModelsMap,
Group group)
throws Exception {
List<StagedModel> dependentStagedModels = dependentStagedModelsMap.get(
RepositoryEntry.class.getSimpleName());
Assert.assertEquals(
dependentStagedModels.toString(), 1, dependentStagedModels.size());
RepositoryEntry repositoryEntry =
(RepositoryEntry)dependentStagedModels.get(0);
RepositoryEntryLocalServiceUtil.getRepositoryEntryByUuidAndGroupId(
repositoryEntry.getUuid(), group.getGroupId());
}
@Override
protected void validateImportedStagedModel(
StagedModel stagedModel, StagedModel importedStagedModel)
throws Exception {
super.validateImportedStagedModel(stagedModel, importedStagedModel);
Repository repository = (Repository)stagedModel;
Repository importedRepository = (Repository)importedStagedModel;
Assert.assertEquals(repository.getName(), importedRepository.getName());
Assert.assertEquals(
repository.getDescription(), importedRepository.getDescription());
}
private Repository _repository;
}