From 0ba470eabb07c3a49b7960de69f1dc6f7251789f Mon Sep 17 00:00:00 2001 From: Marcos Martins Date: Mon, 4 Sep 2023 16:30:27 -0300 Subject: [PATCH] LRAC-14467 update test to be accorded to the new behavior --- ...sExperimentStatusMVCActionCommandTest.java | 66 ++++++++++++++----- 1 file changed, 49 insertions(+), 17 deletions(-) rename modules/dxp/apps/segments/{segments-experiment-test/src/testIntegration/java/com/liferay/segments/experiment/web => segments-asah-connector-test/src/testIntegration/java/com/liferay/segments/asah/connector}/internal/portlet/action/test/EditSegmentsExperimentStatusMVCActionCommandTest.java (74%) diff --git a/modules/dxp/apps/segments/segments-experiment-test/src/testIntegration/java/com/liferay/segments/experiment/web/internal/portlet/action/test/EditSegmentsExperimentStatusMVCActionCommandTest.java b/modules/dxp/apps/segments/segments-asah-connector-test/src/testIntegration/java/com/liferay/segments/asah/connector/internal/portlet/action/test/EditSegmentsExperimentStatusMVCActionCommandTest.java similarity index 74% rename from modules/dxp/apps/segments/segments-experiment-test/src/testIntegration/java/com/liferay/segments/experiment/web/internal/portlet/action/test/EditSegmentsExperimentStatusMVCActionCommandTest.java rename to modules/dxp/apps/segments/segments-asah-connector-test/src/testIntegration/java/com/liferay/segments/asah/connector/internal/portlet/action/test/EditSegmentsExperimentStatusMVCActionCommandTest.java index adebc167e71b8e..3592f5ed492ee2 100644 --- a/modules/dxp/apps/segments/segments-experiment-test/src/testIntegration/java/com/liferay/segments/experiment/web/internal/portlet/action/test/EditSegmentsExperimentStatusMVCActionCommandTest.java +++ b/modules/dxp/apps/segments/segments-asah-connector-test/src/testIntegration/java/com/liferay/segments/asah/connector/internal/portlet/action/test/EditSegmentsExperimentStatusMVCActionCommandTest.java @@ -3,25 +3,31 @@ * SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-Liferay-DXP-EULA-2.0.0-2023-06 */ -package com.liferay.segments.experiment.web.internal.portlet.action.test; +package com.liferay.segments.asah.connector.internal.portlet.action.test; +import com.liferay.analytics.settings.configuration.AnalyticsConfiguration; import com.liferay.arquillian.extension.junit.bridge.junit.Arquillian; import com.liferay.layout.test.util.LayoutTestUtil; import com.liferay.petra.string.StringPool; +import com.liferay.portal.configuration.test.util.CompanyConfigurationTemporarySwapper; +import com.liferay.portal.kernel.json.JSONUtil; import com.liferay.portal.kernel.model.Company; import com.liferay.portal.kernel.model.Group; import com.liferay.portal.kernel.model.Layout; import com.liferay.portal.kernel.portlet.bridges.mvc.MVCActionCommand; import com.liferay.portal.kernel.service.CompanyLocalService; +import com.liferay.portal.kernel.test.ReflectionTestUtil; import com.liferay.portal.kernel.test.portlet.MockLiferayPortletActionRequest; import com.liferay.portal.kernel.test.portlet.MockLiferayPortletActionResponse; 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.MockHttp; 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.theme.ThemeDisplay; +import com.liferay.portal.kernel.util.HashMapDictionaryBuilder; import com.liferay.portal.kernel.util.LocaleUtil; import com.liferay.portal.kernel.util.WebKeys; import com.liferay.portal.test.rule.Inject; @@ -37,6 +43,8 @@ import com.liferay.segments.service.SegmentsExperimentRelLocalService; import com.liferay.segments.test.util.SegmentsTestUtil; +import java.util.Collections; + import org.junit.Assert; import org.junit.Before; import org.junit.BeforeClass; @@ -126,21 +134,45 @@ public void testEditSegmentsExperimentStatusWithWinnerSegmentsExperienceId() String.valueOf( variantSegmentsExperience.getSegmentsExperienceId())); - _mvcResourceCommand.processAction( - mockLiferayPortletActionRequest, - new MockLiferayPortletActionResponse()); - - defaultSegmentsExperience = - _segmentsExperienceRelLocalService.getSegmentsExperience( - defaultSegmentsExperience.getSegmentsExperienceId()); - - Assert.assertFalse(defaultSegmentsExperience.isActive()); - - variantSegmentsExperience = - _segmentsExperienceRelLocalService.getSegmentsExperience( - variantSegmentsExperience.getSegmentsExperienceId()); - - Assert.assertTrue(variantSegmentsExperience.isActive()); + try (CompanyConfigurationTemporarySwapper + companyConfigurationTemporarySwapper = + new CompanyConfigurationTemporarySwapper( + TestPropsValues.getCompanyId(), + AnalyticsConfiguration.class.getName(), + HashMapDictionaryBuilder.put( + "liferayAnalyticsFaroBackendURL", + "http://localhost:8086" + ).put( + "liferayAnalyticsURL", "http://localhost:8080/" + ).build())) { + + Object asahFaroBackendClient = ReflectionTestUtil.getFieldValue( + _mvcActionCommand, "_asahFaroBackendClient"); + + ReflectionTestUtil.setFieldValue( + asahFaroBackendClient, "_http", + new MockHttp( + Collections.singletonMap( + "/api/1.0/experiments/" + + segmentsExperiment.getSegmentsExperimentKey(), + () -> JSONUtil.put( + "id", "123456" + ).toString()))); + + _mvcActionCommand.processAction( + mockLiferayPortletActionRequest, + new MockLiferayPortletActionResponse()); + + Assert.assertNull( + _segmentsExperienceRelLocalService.fetchSegmentsExperience( + defaultSegmentsExperience.getSegmentsExperienceId())); + + variantSegmentsExperience = + _segmentsExperienceRelLocalService.getSegmentsExperience( + variantSegmentsExperience.getSegmentsExperienceId()); + + Assert.assertTrue(variantSegmentsExperience.isActive()); + } } private static Company _company; @@ -154,7 +186,7 @@ public void testEditSegmentsExperimentStatusWithWinnerSegmentsExperienceId() @Inject( filter = "mvc.command.name=/segments_experiment/edit_segments_experiment_status" ) - private MVCActionCommand _mvcResourceCommand; + private MVCActionCommand _mvcActionCommand; @Inject private SegmentsExperienceLocalService _segmentsExperienceRelLocalService;