From 8c21da3ceadf0abb80f3a284d05771a40671999b Mon Sep 17 00:00:00 2001 From: David Truong Date: Mon, 2 Dec 2024 13:00:25 -0600 Subject: [PATCH] LPD-43300 add test --- .../LayoutLocalizationUpgradeProcessTest.java | 144 ++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 modules/apps/layout/layout-test/src/testIntegration/java/com/liferay/layout/internal/upgrade/v1_3_1/test/LayoutLocalizationUpgradeProcessTest.java diff --git a/modules/apps/layout/layout-test/src/testIntegration/java/com/liferay/layout/internal/upgrade/v1_3_1/test/LayoutLocalizationUpgradeProcessTest.java b/modules/apps/layout/layout-test/src/testIntegration/java/com/liferay/layout/internal/upgrade/v1_3_1/test/LayoutLocalizationUpgradeProcessTest.java new file mode 100644 index 00000000000000..86070af70bccf1 --- /dev/null +++ b/modules/apps/layout/layout-test/src/testIntegration/java/com/liferay/layout/internal/upgrade/v1_3_1/test/LayoutLocalizationUpgradeProcessTest.java @@ -0,0 +1,144 @@ +/** + * SPDX-FileCopyrightText: (c) 2024 Liferay, Inc. https://liferay.com + * SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-Liferay-DXP-EULA-2.0.0-2023-06 + */ + +package com.liferay.layout.internal.upgrade.v1_3_1.test; + +import com.liferay.arquillian.extension.junit.bridge.junit.Arquillian; +import com.liferay.change.tracking.model.CTCollection; +import com.liferay.change.tracking.service.CTCollectionLocalService; +import com.liferay.change.tracking.service.CTEntryLocalService; +import com.liferay.change.tracking.service.CTProcessLocalService; +import com.liferay.layout.model.LayoutLocalization; +import com.liferay.layout.service.LayoutLocalizationLocalService; +import com.liferay.petra.lang.SafeCloseable; +import com.liferay.portal.kernel.cache.MultiVMPool; +import com.liferay.portal.kernel.change.tracking.CTCollectionThreadLocal; +import com.liferay.portal.kernel.model.Group; +import com.liferay.portal.kernel.model.Layout; +import com.liferay.portal.kernel.service.ClassNameLocalService; +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.util.GroupTestUtil; +import com.liferay.portal.kernel.test.util.RandomTestUtil; +import com.liferay.portal.kernel.test.util.TestPropsValues; +import com.liferay.portal.kernel.upgrade.UpgradeProcess; +import com.liferay.portal.test.log.LogCapture; +import com.liferay.portal.test.log.LoggerTestUtil; +import com.liferay.portal.test.rule.Inject; +import com.liferay.portal.test.rule.LiferayIntegrationTestRule; +import com.liferay.portal.test.rule.PermissionCheckerMethodTestRule; +import com.liferay.portal.upgrade.registry.UpgradeStepRegistrator; +import com.liferay.portal.upgrade.test.util.UpgradeTestUtil; + +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 David Truong + */ +@RunWith(Arquillian.class) +public class LayoutLocalizationUpgradeProcessTest { + + @ClassRule + @Rule + public static final AggregateTestRule aggregateTestRule = + new AggregateTestRule( + new LiferayIntegrationTestRule(), + PermissionCheckerMethodTestRule.INSTANCE); + + @Before + public void setUp() throws Exception { + _group = GroupTestUtil.addGroup(); + + _ctCollection1 = _ctCollectionLocalService.addCTCollection( + null, TestPropsValues.getCompanyId(), TestPropsValues.getUserId(), + 0, RandomTestUtil.randomString(), ""); + + _ctCollection2 = _ctCollectionLocalService.addCTCollection( + null, TestPropsValues.getCompanyId(), TestPropsValues.getUserId(), + 0, RandomTestUtil.randomString(), ""); + } + + @Test + public void testUpgrade() throws Exception { + LayoutLocalization layoutLocalization = null; + + try (SafeCloseable safeCloseable = + CTCollectionThreadLocal.setCTCollectionIdWithSafeCloseable( + _ctCollection1.getCtCollectionId())) { + + layoutLocalization = + _layoutLocalizationLocalService.addLayoutLocalization( + _group.getGroupId(), RandomTestUtil.randomString(), "en_US", + RandomTestUtil.randomLong(), new ServiceContext()); + } + + _runUpgrade(); + + Assert.assertNull( + _ctEntryLocalService.fetchCTEntry( + _ctCollection1.getCtCollectionId(), + _classNameLocalService.getClassNameId(LayoutLocalization.class), + layoutLocalization.getLayoutLocalizationId())); + } + + private void _runUpgrade() throws Exception { + try (LogCapture logCapture = LoggerTestUtil.configureLog4JLogger( + _CLASS_NAME, LoggerTestUtil.OFF)) { + + UpgradeProcess upgradeProcess = UpgradeTestUtil.getUpgradeStep( + _upgradeStepRegistrator, _CLASS_NAME); + + upgradeProcess.upgrade(); + + _multiVMPool.clear(); + } + } + + private static final String _CLASS_NAME = + "com.liferay.layout.internal.upgrade.v1_3_1." + + "LayoutLocalizationUpgradeProcess"; + + @Inject( + filter = "(&(component.name=com.liferay.layout.internal.upgrade.registry.LayoutServiceUpgradeStepRegistrator))" + ) + private static UpgradeStepRegistrator _upgradeStepRegistrator; + + @Inject + private ClassNameLocalService _classNameLocalService; + + @DeleteAfterTestRun + private CTCollection _ctCollection1; + + @DeleteAfterTestRun + private CTCollection _ctCollection2; + + @Inject + private CTCollectionLocalService _ctCollectionLocalService; + + @Inject + private CTEntryLocalService _ctEntryLocalService; + + @Inject + private CTProcessLocalService _ctProcessLocalService; + + @DeleteAfterTestRun + private Group _group; + + @DeleteAfterTestRun + private Layout _layout; + + @Inject + private LayoutLocalizationLocalService _layoutLocalizationLocalService; + + @Inject + private MultiVMPool _multiVMPool; + +} \ No newline at end of file