Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LPS-104573 SF #80953

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,39 @@
/**
* Copyright (c) 2000-present Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/

package com.liferay.segments.exception;

import com.liferay.portal.kernel.exception.PortalException;

/**
* @author Eduardo García
*/
public class RunSegmentsExperimentException extends PortalException {

public RunSegmentsExperimentException() {
}

public RunSegmentsExperimentException(String msg) {
super(msg);
}

public RunSegmentsExperimentException(String msg, Throwable cause) {
super(msg, cause);
}

public RunSegmentsExperimentException(Throwable cause) {
super(cause);
}

}
1 change: 1 addition & 0 deletions modules/apps/segments/segments-service/service.xml
Expand Up @@ -345,6 +345,7 @@
<exception>LockedSegmentsExperiment</exception>
<exception>RequiredSegmentsEntry</exception>
<exception>RequiredSegmentsExperience</exception>
<exception>RunSegmentsExperiment</exception>
<exception>SegmentsEntryCriteria</exception>
<exception>SegmentsEntryKey</exception>
<exception>SegmentsEntryName</exception>
Expand Down
Expand Up @@ -42,6 +42,7 @@
import com.liferay.segments.constants.SegmentsPortletKeys;
import com.liferay.segments.exception.LockedSegmentsExperimentException;
import com.liferay.segments.exception.NoSuchExperimentException;
import com.liferay.segments.exception.RunSegmentsExperimentException;
import com.liferay.segments.exception.SegmentsExperimentConfidenceLevelException;
import com.liferay.segments.exception.SegmentsExperimentGoalException;
import com.liferay.segments.exception.SegmentsExperimentNameException;
Expand Down Expand Up @@ -320,11 +321,16 @@ public SegmentsExperiment runSegmentsExperiment(
_validateEditableStatus(segmentsExperiment.getStatus());

_validateConfidenceLevel(confidenceLevel);
_validateSegmentsExperimentRels(segmentsExperienceIdSplitMap);
_validateSplit(segmentsExperienceIdSplitMap);

UnicodeProperties typeSettingsProperties =
segmentsExperiment.getTypeSettingsProperties();

_validateGoalTarget(
typeSettingsProperties.get("goal"),
typeSettingsProperties.get("goalTarget"));

typeSettingsProperties.setProperty(
"confidenceLevel", String.valueOf(confidenceLevel));

Expand Down Expand Up @@ -565,12 +571,35 @@ private void _validateGoal(String goal) throws PortalException {
}
}

private void _validateGoalTarget(String goal, String goalTarget)
throws PortalException {

if (goal.equals(
SegmentsExperimentConstants.Goal.CLICK_RATE.getLabel()) &&
Validator.isNull(goalTarget)) {

throw new RunSegmentsExperimentException(
"Target element needs to be set in click goal");
}
}

private void _validateName(String name) throws PortalException {
if (Validator.isNull(name)) {
throw new SegmentsExperimentNameException();
}
}

private void _validateSegmentsExperimentRels(
Map<Long, Double> segmentsExperienceIdSplitMap)
throws PortalException {

if (segmentsExperienceIdSplitMap.size() <= 1) {
throw new RunSegmentsExperimentException(
"Segments experiment rels must be more than 1 to test " +
"against Control");
}
}

private void _validateSplit(Map<Long, Double> segmentsExperienceIdSplitMap)
throws PortalException {

Expand Down
Expand Up @@ -37,6 +37,7 @@
import com.liferay.segments.constants.SegmentsExperienceConstants;
import com.liferay.segments.constants.SegmentsExperimentConstants;
import com.liferay.segments.exception.LockedSegmentsExperimentException;
import com.liferay.segments.exception.RunSegmentsExperimentException;
import com.liferay.segments.exception.SegmentsExperimentConfidenceLevelException;
import com.liferay.segments.exception.SegmentsExperimentGoalException;
import com.liferay.segments.exception.SegmentsExperimentNameException;
Expand Down Expand Up @@ -534,6 +535,48 @@ public void testRunSegmentsExperiment() throws Exception {
variantSegmentsExperimentRel.getSplit(), 0.001);
}

@Test(expected = RunSegmentsExperimentException.class)
public void testRunSegmentsExperimentWithClickGoalAndEmptyTarget()
throws Exception {

SegmentsExperiment segmentsExperiment = _addSegmentsExperiment();

_segmentsExperimentLocalService.updateSegmentsExperiment(
segmentsExperiment.getSegmentsExperimentId(),
RandomTestUtil.randomString(), RandomTestUtil.randomString(),
SegmentsExperimentConstants.Goal.CLICK_RATE.getLabel(),
StringPool.BLANK);

SegmentsExperience variantSegmentsExperience =
SegmentsTestUtil.addSegmentsExperience(
segmentsExperiment.getGroupId(),
segmentsExperiment.getClassNameId(),
segmentsExperiment.getClassPK());

Map<Long, Double> segmentsExperienceIdSplitMap = HashMapBuilder.put(
segmentsExperiment.getSegmentsExperienceId(), 0.70
).put(
variantSegmentsExperience.getSegmentsExperienceId(), 0.30
).build();

_segmentsExperimentLocalService.runSegmentsExperiment(
segmentsExperiment.getSegmentsExperimentId(), 0.95,
segmentsExperienceIdSplitMap);
}

@Test(expected = RunSegmentsExperimentException.class)
public void testRunSegmentsExperimentWithControlVariant() throws Exception {
SegmentsExperiment segmentsExperiment = _addSegmentsExperiment();

Map<Long, Double> segmentsExperienceIdSplitMap = HashMapBuilder.put(
segmentsExperiment.getSegmentsExperienceId(), 1.00
).build();

_segmentsExperimentLocalService.runSegmentsExperiment(
segmentsExperiment.getSegmentsExperimentId(), 0.95,
segmentsExperienceIdSplitMap);
}

@Test(expected = SegmentsExperimentConfidenceLevelException.class)
public void testRunSegmentsExperimentWithInvalidConfidenceLevel()
throws Exception {
Expand All @@ -551,16 +594,14 @@ public void testRunSegmentsExperimentWithInvalidConfidenceLevel()
variantSegmentsExperience.getSegmentsExperienceId(),
ServiceContextTestUtil.getServiceContext(_group.getGroupId()));

double confidenceLevel = 1.2;

Map<Long, Double> segmentsExperienceIdSplitMap = HashMapBuilder.put(
segmentsExperiment.getSegmentsExperienceId(), 0.70
).put(
variantSegmentsExperience.getSegmentsExperienceId(), 0.30
).build();

_segmentsExperimentLocalService.runSegmentsExperiment(
segmentsExperiment.getSegmentsExperimentId(), confidenceLevel,
segmentsExperiment.getSegmentsExperimentId(), 1.2,
segmentsExperienceIdSplitMap);
}

Expand Down