Skip to content

Commit

Permalink
LPD-43300 add test
Browse files Browse the repository at this point in the history
  • Loading branch information
david-truong authored and brianchandotcom committed Dec 6, 2024
1 parent 3e0f96b commit 8c21da3
Showing 1 changed file with 144 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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;

}

0 comments on commit 8c21da3

Please sign in to comment.