Skip to content

Commit

Permalink
LRAC-14467 update test to be accorded to the new behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosapmf authored and brianchandotcom committed Sep 13, 2023
1 parent 23d884c commit 0ba470e
Showing 1 changed file with 49 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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.<String, Object>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;
Expand All @@ -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;
Expand Down

0 comments on commit 0ba470e

Please sign in to comment.