ExperimentUtil { public static Experiment toExperiment( CompanyLocalService companyLocalService, String dataSourceId, GroupLocalService groupLocalService, Layout layout, Locale locale, Portal portal, SegmentsEntryLocalService segmentsEntryLocalService, SegmentsExperienceLocalService segmentsExperienceLocalService, SegmentsExperiment segmentsExperiment) throws PortalException { return toExperiment( _getChannelId(groupLocalService, layout), dataSourceId, SegmentsEntryConstants.getDefaultSegmentsEntryName(locale), SegmentsExperienceConstants.getDefaultSegmentsExperienceName( locale), layout, locale, _getLayoutFullURL( portal, companyLocalService, groupLocalService, layout), segmentsEntryLocalService, segmentsExperienceLocalService, segmentsExperiment); }  static Experiment toExperiment(
			CompanyLocalService companyLocalService, String dataSourceId,
			GroupLocalService groupLocalService, Layout layout, Locale locale,
			Portal portal, SegmentsEntryLocalService segmentsEntryLocalService,
			SegmentsExperienceLocalService segmentsExperienceLocalService,
			SegmentsExperiment segmentsExperiment); static Experiment toExperiment(
			CompanyLocalService companyLocalService, String dataSourceId,
			GroupLocalService groupLocalService,
			LayoutLocalService layoutLocalService, Locale locale, Portal portal,
			SegmentsEntryLocalService segmentsEntryLocalService,
			SegmentsExperienceLocalService segmentsExperienceLocalService,
			SegmentsExperiment segmentsExperiment);  }
@Test public void testToExperimentWithSegmentsExperimentWithDefaultExperience() throws PortalException { Locale locale = LocaleUtil.ENGLISH; Layout layout = _createLayout(locale); SegmentsExperiment segmentsExperiment = _createSegmentsExperiment( SegmentsExperienceConstants.ID_DEFAULT, SegmentsExperimentConstants.Goal.BOUNCE_RATE.getLabel(), SegmentsExperimentConstants.STATUS_DRAFT); String channelId = RandomTestUtil.randomString(); String dataSourceId = RandomTestUtil.randomString(); String defaultSegmentsEntryName = RandomTestUtil.randomString(); String defaultSegmentsExperienceName = RandomTestUtil.randomString(); String pageURL = RandomTestUtil.randomString(); Experiment experiment = ExperimentUtil.toExperiment( channelId, dataSourceId, defaultSegmentsEntryName, defaultSegmentsExperienceName, layout, locale, pageURL, _segmentsEntryLocalService, _segmentsExperienceLocalService, segmentsExperiment); Assert.assertEquals(channelId, experiment.getChannelId()); Assert.assertEquals( segmentsExperiment.getCreateDate(), experiment.getCreateDate()); Assert.assertEquals(dataSourceId, experiment.getDataSourceId()); Assert.assertEquals( segmentsExperiment.getDescription(), experiment.getDescription()); Assert.assertEquals( SegmentsExperienceConstants.KEY_DEFAULT, experiment.getDXPExperienceId()); Assert.assertEquals( defaultSegmentsExperienceName, experiment.getDXPExperienceName()); Assert.assertEquals( (Long)layout.getGroupId(), experiment.getDXPGroupId()); Assert.assertEquals(layout.getUuid(), experiment.getDXPLayoutId()); Assert.assertEquals( SegmentsEntryConstants.KEY_DEFAULT, experiment.getDXPSegmentId()); Assert.assertEquals( defaultSegmentsEntryName, experiment.getDXPSegmentName()); Assert.assertEquals( ExperimentStatus.DRAFT, experiment.getExperimentStatus()); Assert.assertEquals(ExperimentType.AB, experiment.getExperimentType()); Goal goal = experiment.getGoal(); GoalMetric goalMetric = goal.getGoalMetric(); Assert.assertEquals( SegmentsExperimentConstants.Goal.BOUNCE_RATE.name(), goalMetric.name()); Assert.assertEquals( segmentsExperiment.getSegmentsExperimentKey(), experiment.getId()); Assert.assertEquals( segmentsExperiment.getModifiedDate(), experiment.getModifiedDate()); Assert.assertEquals(segmentsExperiment.getName(), experiment.getName()); Assert.assertEquals( layout.getFriendlyURL(), experiment.getPageRelativePath()); Assert.assertEquals(layout.getTitle(locale), experiment.getPageTitle()); Assert.assertEquals(pageURL, experiment.getPageURL()); Assert.assertNull(experiment.getPublishedDXPVariantId()); }
@Test public void testToExperimentWithSegmentsExperimentWithNondefaultExperience() throws PortalException { Locale locale = LocaleUtil.ENGLISH; Layout layout = _createLayout(locale); SegmentsEntry segmentsEntry = _createSegmentsEntry(locale); long segmentsEntryId = RandomTestUtil.randomLong(); Mockito.when( _segmentsEntryLocalService.getSegmentsEntry(segmentsEntryId) ).thenReturn( segmentsEntry ); SegmentsExperience segmentsExperience = _createSegmentsExperience( locale, segmentsEntryId); long segmentsExperienceId = RandomTestUtil.randomLong(); Mockito.when( _segmentsExperienceLocalService.getSegmentsExperience( segmentsExperienceId) ).thenReturn( segmentsExperience ); SegmentsExperiment segmentsExperiment = _createSegmentsExperiment( segmentsExperienceId, SegmentsExperimentConstants.Goal.BOUNCE_RATE.getLabel(), SegmentsExperimentConstants.STATUS_DRAFT); String channelId = RandomTestUtil.randomString(); String dataSourceId = RandomTestUtil.randomString(); String pageURL = RandomTestUtil.randomString(); Experiment experiment = ExperimentUtil.toExperiment( channelId, dataSourceId, RandomTestUtil.randomString(), RandomTestUtil.randomString(), layout, LocaleUtil.ENGLISH, pageURL, _segmentsEntryLocalService, _segmentsExperienceLocalService, segmentsExperiment); Assert.assertEquals(channelId, experiment.getChannelId()); Assert.assertEquals( segmentsExperiment.getCreateDate(), experiment.getCreateDate()); Assert.assertEquals(dataSourceId, experiment.getDataSourceId()); Assert.assertEquals( segmentsExperiment.getDescription(), experiment.getDescription()); Assert.assertEquals( segmentsExperience.getSegmentsExperienceKey(), experiment.getDXPExperienceId()); Assert.assertEquals( segmentsExperience.getName(locale), experiment.getDXPExperienceName()); Assert.assertEquals( (Long)layout.getGroupId(), experiment.getDXPGroupId()); Assert.assertEquals(layout.getUuid(), experiment.getDXPLayoutId()); Assert.assertEquals( segmentsEntry.getSegmentsEntryKey(), experiment.getDXPSegmentId()); Assert.assertEquals( segmentsEntry.getName(locale), experiment.getDXPSegmentName()); Assert.assertEquals( ExperimentStatus.DRAFT, experiment.getExperimentStatus()); Assert.assertEquals(ExperimentType.AB, experiment.getExperimentType()); Goal goal = experiment.getGoal(); GoalMetric goalMetric = goal.getGoalMetric(); Assert.assertEquals( SegmentsExperimentConstants.Goal.BOUNCE_RATE.name(), goalMetric.name()); Assert.assertEquals( segmentsExperiment.getSegmentsExperimentKey(), experiment.getId()); Assert.assertEquals( segmentsExperiment.getModifiedDate(), experiment.getModifiedDate()); Assert.assertEquals(segmentsExperiment.getName(), experiment.getName()); Assert.assertEquals( layout.getFriendlyURL(), experiment.getPageRelativePath()); Assert.assertEquals(layout.getTitle(locale), experiment.getPageTitle()); Assert.assertEquals(pageURL, experiment.getPageURL()); Assert.assertNull(experiment.getPublishedDXPVariantId()); }
@Test public void testToExperimentWithSegmentsExperimentWithStatusCompleted() throws PortalException { Locale locale = LocaleUtil.ENGLISH; Layout layout = _createLayout(locale); SegmentsEntry segmentsEntry = _createSegmentsEntry(locale); long segmentsEntryId = RandomTestUtil.randomLong(); Mockito.when( _segmentsEntryLocalService.getSegmentsEntry(segmentsEntryId) ).thenReturn( segmentsEntry ); SegmentsExperience segmentsExperience = _createSegmentsExperience( locale, segmentsEntryId); long segmentsExperienceId = RandomTestUtil.randomLong(); Mockito.when( _segmentsExperienceLocalService.getSegmentsExperience( segmentsExperienceId) ).thenReturn( segmentsExperience ); SegmentsExperiment segmentsExperiment = _createSegmentsExperiment( segmentsExperienceId, SegmentsExperimentConstants.Goal.BOUNCE_RATE.getLabel(), SegmentsExperimentConstants.STATUS_COMPLETED); String channelId = RandomTestUtil.randomString(); String dataSourceId = RandomTestUtil.randomString(); String pageURL = RandomTestUtil.randomString(); Experiment experiment = ExperimentUtil.toExperiment( channelId, dataSourceId, RandomTestUtil.randomString(), RandomTestUtil.randomString(), layout, LocaleUtil.ENGLISH, pageURL, _segmentsEntryLocalService, _segmentsExperienceLocalService, segmentsExperiment); Assert.assertEquals(channelId, experiment.getChannelId()); Assert.assertEquals( segmentsExperiment.getCreateDate(), experiment.getCreateDate()); Assert.assertEquals(dataSourceId, experiment.getDataSourceId()); Assert.assertEquals( segmentsExperiment.getDescription(), experiment.getDescription()); Assert.assertEquals( segmentsExperience.getSegmentsExperienceKey(), experiment.getDXPExperienceId()); Assert.assertEquals( segmentsExperience.getName(locale), experiment.getDXPExperienceName()); Assert.assertEquals( (Long)layout.getGroupId(), experiment.getDXPGroupId()); Assert.assertEquals(layout.getUuid(), experiment.getDXPLayoutId()); Assert.assertEquals( segmentsEntry.getSegmentsEntryKey(), experiment.getDXPSegmentId()); Assert.assertEquals( segmentsEntry.getName(locale), experiment.getDXPSegmentName()); Assert.assertEquals( ExperimentStatus.COMPLETED, experiment.getExperimentStatus()); Assert.assertEquals(ExperimentType.AB, experiment.getExperimentType()); Goal goal = experiment.getGoal(); GoalMetric goalMetric = goal.getGoalMetric(); Assert.assertEquals( SegmentsExperimentConstants.Goal.BOUNCE_RATE.name(), goalMetric.name()); Assert.assertEquals( segmentsExperiment.getSegmentsExperimentKey(), experiment.getId()); Assert.assertEquals( segmentsExperiment.getModifiedDate(), experiment.getModifiedDate()); Assert.assertEquals(segmentsExperiment.getName(), experiment.getName()); Assert.assertEquals( layout.getFriendlyURL(), experiment.getPageRelativePath()); Assert.assertEquals(layout.getTitle(locale), experiment.getPageTitle()); Assert.assertEquals(pageURL, experiment.getPageURL()); Assert.assertEquals( segmentsExperiment.getWinnerSegmentsExperienceKey(), experiment.getPublishedDXPVariantId()); }