From 2c13f3ce6bdf7600a5e0a54597287919af200817 Mon Sep 17 00:00:00 2001 From: freddyDOTCMS <147462678+freddyDOTCMS@users.noreply.github.com> Date: Mon, 13 Nov 2023 11:54:37 -0600 Subject: [PATCH] #25478 Filtering by DEFAULT Variant (#26653) * #25478 Filtering by DEFAULT Variant * #25478 Including Test --- .../com/dotcms/browser/BrowserAPITest.java | 84 ++++++++++++++++--- .../com/dotcms/browser/BrowserAPIImpl.java | 4 + 2 files changed, 76 insertions(+), 12 deletions(-) diff --git a/dotCMS/src/integration-test/java/com/dotcms/browser/BrowserAPITest.java b/dotCMS/src/integration-test/java/com/dotcms/browser/BrowserAPITest.java index a4a3d37a3b73..a08c012d70d6 100644 --- a/dotCMS/src/integration-test/java/com/dotcms/browser/BrowserAPITest.java +++ b/dotCMS/src/integration-test/java/com/dotcms/browser/BrowserAPITest.java @@ -1,14 +1,9 @@ package com.dotcms.browser; import com.dotcms.IntegrationTestBase; -import com.dotcms.datagen.FileAssetDataGen; -import com.dotcms.datagen.FolderDataGen; -import com.dotcms.datagen.HTMLPageDataGen; -import com.dotcms.datagen.LanguageDataGen; -import com.dotcms.datagen.LinkDataGen; -import com.dotcms.datagen.SiteDataGen; -import com.dotcms.datagen.TestDataUtils; +import com.dotcms.datagen.*; import com.dotcms.util.IntegrationTestInitService; +import com.dotcms.variant.model.Variant; import com.dotmarketing.beans.Host; import com.dotmarketing.business.APILocator; import com.dotmarketing.business.Treeable; @@ -43,11 +38,7 @@ import java.io.File; import java.io.IOException; import java.net.URL; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; import java.util.stream.Collectors; import static org.junit.Assert.assertEquals; @@ -609,6 +600,75 @@ public void test_getFolderContent_folderOrderedByName() throws Exception{ } + /** + * Method to test: {@link BrowserAPIImpl#getFolderContent(BrowserQuery)} + * When: A Contentlet has Version in DEFAULT Variant and also in a specific Variant + * Should: Return just the DEFAULT Version + * + * @throws DotDataException + * @throws DotSecurityException + * @throws IOException + */ + @Test + public void getJustDEFAULTVariantVersion() throws DotDataException, DotSecurityException, IOException { + final Host host = new SiteDataGen().nextPersisted(); + final Folder folder = new FolderDataGen().site(host).nextPersisted(); + + final Contentlet file = new FileAssetDataGen(folder, "This is a File") + .folder(folder) + .host(host) + .nextPersisted(); + + final Variant variant = new VariantDataGen().nextPersisted(); + ContentletDataGen.createNewVersion(file, variant, Collections.EMPTY_MAP); + + final Map files = browserAPI.getFolderContent(BrowserQuery.builder() + .withHostOrFolderId(folder.getIdentifier()) + .build()); + + assertEquals(1, Integer.parseInt(files.get("total").toString())); + + final List list = (List) files.get("list"); + assertEquals(1, list.size()); + assertEquals(file.getIdentifier(), ((Contentlet.ContentletHashMap) list.get(0)).get("identifier")); + assertEquals(file.getInode(), ((Contentlet.ContentletHashMap) list.get(0)).get("inode")); + + } + + /** + * Method to test: {@link BrowserAPIImpl#getFolderContent(BrowserQuery)} + * When: A Contentlet has Version in a specific Variant + * Should: Not return this Contentlet + * + * @throws DotDataException + * @throws DotSecurityException + * @throws IOException + */ + @Test + public void notGetSpecificVariantVersion() throws DotDataException, DotSecurityException, IOException { + final Host host = new SiteDataGen().nextPersisted(); + final Folder folder = new FolderDataGen().site(host).nextPersisted(); + + final Variant variant = new VariantDataGen().nextPersisted(); + + final Contentlet file = new FileAssetDataGen(folder, "This is a File") + .folder(folder) + .host(host) + .variant(variant) + .nextPersisted(); + + + final Map files = browserAPI.getFolderContent(BrowserQuery.builder() + .withHostOrFolderId(folder.getIdentifier()) + .build()); + + assertEquals(0, Integer.parseInt(files.get("total").toString())); + + final List list = (List) files.get("list"); + assertTrue(list.isEmpty()); + + } + /** *