/** * 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.DLFileEntryMetadata; import com.liferay.document.library.kernel.model.DLFileEntryType; import com.liferay.document.library.kernel.service.DLFileEntryTypeLocalServiceUtil; import com.liferay.document.library.kernel.util.DLUtil; import com.liferay.dynamic.data.mapping.kernel.DDMStructureManagerUtil; import com.liferay.dynamic.data.mapping.model.DDMStructure; import com.liferay.dynamic.data.mapping.test.util.DDMStructureTestUtil; import com.liferay.portal.kernel.model.Group; import com.liferay.portal.kernel.model.StagedModel; 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.lar.test.BaseStagedModelDataHandlerTestCase; 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 DLFileEntryTypeStagedModelDataHandlerTest 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<>(); DDMStructure ddmStructure = DDMStructureTestUtil.addStructure( group.getGroupId(), DLFileEntryMetadata.class.getName()); addDependentStagedModel( dependentStagedModelsMap, DDMStructureManagerUtil.getDDMStructureModelClass(), ddmStructure); return dependentStagedModelsMap; } @Override protected StagedModel addStagedModel( Group group, Map<String, List<StagedModel>> dependentStagedModelsMap) throws Exception { Class<?> ddmStructureClass = DDMStructureManagerUtil.getDDMStructureModelClass(); List<StagedModel> dependentStagedModels = dependentStagedModelsMap.get( ddmStructureClass.getSimpleName()); DDMStructure ddmStructure = (DDMStructure)dependentStagedModels.get(0); ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext( group.getGroupId(), TestPropsValues.getUserId()); DLFileEntryType dlFileEntryType = DLFileEntryTypeLocalServiceUtil.addFileEntryType( TestPropsValues.getUserId(), group.getGroupId(), RandomTestUtil.randomString(), RandomTestUtil.randomString(), new long[] {ddmStructure.getStructureId()}, serviceContext); DDMStructureManagerUtil.updateStructureKey( ddmStructure.getStructureId(), DLUtil.getDDMStructureKey(dlFileEntryType)); return dlFileEntryType; } @Override protected StagedModel getStagedModel(String uuid, Group group) { try { return DLFileEntryTypeLocalServiceUtil. getDLFileEntryTypeByUuidAndGroupId(uuid, group.getGroupId()); } catch (Exception e) { return null; } } @Override protected Class<? extends StagedModel> getStagedModelClass() { return DLFileEntryType.class; } @Override protected void validateImport( Map<String, List<StagedModel>> dependentStagedModelsMap, Group group) throws Exception { Class<?> ddmStructureClass = DDMStructureManagerUtil.getDDMStructureModelClass(); List<StagedModel> dependentStagedModels = dependentStagedModelsMap.get( ddmStructureClass.getSimpleName()); Assert.assertEquals( dependentStagedModels.toString(), 1, dependentStagedModels.size()); DDMStructure ddmStructure = (DDMStructure)dependentStagedModels.get(0); DDMStructureManagerUtil.getStructureByUuidAndGroupId( ddmStructure.getUuid(), group.getGroupId()); } @Override protected void validateImportedStagedModel( StagedModel stagedModel, StagedModel importedStagedModel) throws Exception { super.validateImportedStagedModel(stagedModel, importedStagedModel); DLFileEntryType dlFileEntryType = (DLFileEntryType)stagedModel; DLFileEntryType importedDLFileEntryType = (DLFileEntryType)importedStagedModel; Assert.assertEquals( dlFileEntryType.getName(), importedDLFileEntryType.getName()); Assert.assertEquals( dlFileEntryType.getDescription(), importedDLFileEntryType.getDescription()); } }