Skip to content

Commit

Permalink
LRAC-14467 mock http in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosapmf authored and brianchandotcom committed Sep 13, 2023
1 parent 42f9ee3 commit 39ef61a
Showing 1 changed file with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* 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;
Expand All @@ -21,6 +21,7 @@
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;
Expand All @@ -40,6 +41,8 @@
import com.liferay.segments.service.SegmentsExperimentLocalService;
import com.liferay.segments.test.util.SegmentsTestUtil;

import java.util.Collections;

import javax.portlet.ActionRequest;

import org.junit.Assert;
Expand Down Expand Up @@ -128,6 +131,9 @@ public void testAddSegmentsExperiment() throws Exception {
TestPropsValues.getCompanyId(),
AnalyticsConfiguration.class.getName(),
HashMapDictionaryBuilder.<String, Object>put(
"liferayAnalyticsFaroBackendURL",
"http://localhost:8086"
).put(
"liferayAnalyticsURL", liferayAnalyticsURL
).build())) {

Expand Down Expand Up @@ -229,9 +235,25 @@ public void testAddSegmentsExperimentWithExistingTerminatedSegmentsExperiment()
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())));

ReflectionTestUtil.invoke(
_mvcActionCommand, "_addSegmentsExperiment",
new Class<?>[] {ActionRequest.class},
Expand Down

0 comments on commit 39ef61a

Please sign in to comment.