Skip to content

Commit

Permalink
#27748 include in 23.10.24 LTS
Browse files Browse the repository at this point in the history
  • Loading branch information
erickgonzalez committed Nov 4, 2024
1 parent 5f2a7db commit 85244a0
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 4 deletions.
1 change: 1 addition & 0 deletions dotCMS/hotfix_tracking.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,4 @@ This maintenance release includes the following code fixes:
168. https://github.com/dotCMS/core/issues/27141 : Responsive Design Issue with Experiment Results Chart Not Resizing Properly #27141
169. https://github.com/dotCMS/core/issues/27451 : Registering page events after the Experiment ended #27451
170. https://github.com/dotCMS/core/issues/27584 : Edit mode navigation render is broken #27584
171. https://github.com/dotCMS/core/issues/27748 : Render Page on Ended Experiment Variant #27748
Original file line number Diff line number Diff line change
Expand Up @@ -4227,4 +4227,50 @@ public void removeAllVariants_ShouldResetSplitTypeToSplitEvenly()

assertEquals(Type.SPLIT_EVENLY, experimentAfterDelete.trafficProportion().type());
}

/**
* Method to test: {@link ExperimentsAPIImpl#end(String, User)}
* WHen: End An Experiment
* Should: Archive the Variants
*
* @throws DotDataException
* @throws DotSecurityException
*/
@Test
public void archiveVariantAfterStopExperiment() throws DotDataException, DotSecurityException {

final Host host = new SiteDataGen().nextPersisted();
final Template template = new TemplateDataGen().host(host).nextPersisted();

final HTMLPageAsset pageA = new HTMLPageDataGen(host, template).nextPersisted();

Experiment experiment = new ExperimentDataGen()
.page(pageA).nextPersisted();

experiment = APILocator.getExperimentsAPI()
.addVariant(experiment.id().orElseThrow(), "v1", APILocator.systemUser());


experiment = APILocator.getExperimentsAPI()
.addVariant(experiment.id().orElseThrow(), "v2", APILocator.systemUser());

final ExperimentVariant v1 = experiment.trafficProportion().variants().stream()
.filter((variant)->variant.description().equals("v1"))
.collect(Collectors.toList()).get(0);

final ExperimentVariant v2 = experiment.trafficProportion().variants().stream()
.filter((variant)->variant.description().equals("v2"))
.collect(Collectors.toList()).get(0);

APILocator.getExperimentsAPI().start(experiment.id().get(), APILocator.systemUser());
APILocator.getExperimentsAPI().end(experiment.id().get(), APILocator.systemUser());

final Variant variant1FromDataBase = APILocator.getVariantAPI().get(v1.id()).orElseThrow();
assertTrue("The Variant must be archived", variant1FromDataBase.archived());


final Variant variant2FromDataBase = APILocator.getVariantAPI().get(v2.id()).orElseThrow();
assertTrue("The Variant must be archived", variant2FromDataBase.archived());

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2754,4 +2754,51 @@ public void usingViewToolToInjectExperimentCode() throws IOException {
private String getNotExperimentJsCode(){
return "<SCRIPT>localStorage.removeItem('experiment_data');</SCRIPT>\n";
}

/**
* Method to test: {@link HTMLPageAssetRenderedAPI#getPageHtml(PageContext, HttpServletRequest, HttpServletResponse)}
* When: Try to render a page with a specific Archived {@link Variant}} and a specific {@link Language}
* and the page had a contentlet that:
* - had version in that language and that variant.
* - had version in that language and DEFAULT variant.
* - The page just have version in that specific language.
* Should: render the page for DEFAULT {@link Variant}} and {@link Language} {@link Contentlet} version
*
* @throws WebAssetException
* @throws DotDataException
* @throws DotSecurityException
*/
@Test
public void renderPageWithSpecificArchivedVariant() throws WebAssetException, DotDataException, DotSecurityException {
final Language language = new LanguageDataGen().nextPersisted();
final Host host = new SiteDataGen().nextPersisted();
final Variant variant = new VariantDataGen().nextPersisted();

final ContentType contentType = createContentType();
final Container container = createAndPublishContainer(host, contentType);
final HTMLPageAsset page = createHtmlPageAsset(language, host, container);
final Contentlet contentlet = createContentlet(language, host, contentType);

createNewVersion(contentlet, language, variant);

addToPage(container, page, contentlet);

APILocator.getVariantAPI().archive(variant.name());

final HttpServletRequest mockRequest = createHttpServletRequest(language, host,
variant, page);

final HttpServletResponse mockResponse = mock(HttpServletResponse.class);
final HttpSession session = createHttpSession(mockRequest);
when(session.getAttribute(WebKeys.VISITOR)).thenReturn(null);

String html = APILocator.getHTMLPageAssetRenderedAPI().getPageHtml(
PageContextBuilder.builder()
.setUser(APILocator.systemUser())
.setPageUri(page.getURI())
.setPageMode(PageMode.LIVE)
.build(),
mockRequest, mockResponse);
Assert.assertEquals("<div>DEFAULT content-default-" + language.getId() + "</div>", html);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,8 @@ public Experiment end(String experimentId, User user)
.withScheduling(endedScheduling);
final Experiment saved = save(ended, user);

archivedAllVariants(saved);

cacheRunningExperiments();

SecurityLogger.logInfo(this.getClass(), () -> String.format("Experiment '%s' [%s] has been ended by User" +
Expand All @@ -852,6 +854,15 @@ public Experiment end(String experimentId, User user)
}
}

private void archivedAllVariants(Experiment saved) throws DotDataException {
for (ExperimentVariant variant : saved.trafficProportion().variants()) {

if (!variant.id().equals(DEFAULT_VARIANT.name())) {
variantAPI.archive(variant.id());
}
}
}

@WrapInTransaction
@Override
public Experiment addVariant(final String experimentId, final String variantDescription,
Expand Down Expand Up @@ -1611,4 +1622,4 @@ private void checkAndDeleteExperiment(final Contentlet contentlet, final User us
throw new DotRuntimeException(message, e);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,11 @@ public String currentVariantId() {
currentVariantName = VariantAPI.DEFAULT_VARIANT.name();
} else {
try {
final Optional<Variant> byName = APILocator.getVariantAPI()
.get(currentVariantName);
currentVariantName = byName.isPresent() ? byName.get().name() : VariantAPI.DEFAULT_VARIANT.name();
return APILocator.getVariantAPI()
.get(currentVariantName)
.filter((variant -> !variant.archived()))
.orElse(VariantAPI.DEFAULT_VARIANT)
.name();
} catch (DotDataException e) {
Logger.error(VariantWebAPIImpl.class,
String.format("It is not possible get variant y name %s: %s",
Expand Down

0 comments on commit 85244a0

Please sign in to comment.