Skip to content

Commit

Permalink
#30457 include in 24.04.24 LTS
Browse files Browse the repository at this point in the history
  • Loading branch information
gortiz-dotcms committed Dec 5, 2024
1 parent 62d3f39 commit 9bf212a
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 18 deletions.
1 change: 1 addition & 0 deletions dotCMS/hotfix_tracking.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,4 @@ This maintenance release includes the following code fixes:
86. https://github.com/dotCMS/core/issues/28780 : Add Hint support for relationship fields #28780
87. https://github.com/dotCMS/core/issues/29501 : optimize sql query causing slowness on high-traffic sites #29501
88. https://github.com/dotCMS/core/issues/30053 : Overlay Misalignment in Content Type while relating content #30053
89. https://github.com/dotCMS/core/issues/30457 : FileAssetContainers not found when using case #30457
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ private Collection<? extends Permissionable> findFolderAssetContainers(final Use

for (final Object name : searchParams.filteringCriteria().values()) {

if (container.getName().toLowerCase().contains(name.toString())) {
if (container.getName().toLowerCase().contains(name.toString().toLowerCase())) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,42 +1,39 @@
package com.dotmarketing.portlets.containers.business;

import com.dotcms.JUnit4WeldRunner;
import com.dotcms.contenttype.model.type.ContentType;
import com.dotcms.datagen.ContainerAsFileDataGen;
import com.dotcms.datagen.ContainerDataGen;
import com.dotcms.datagen.ContentTypeDataGen;
import com.dotcms.datagen.SiteDataGen;
import com.dotcms.datagen.TestDataUtils;
import com.dotmarketing.beans.ContainerStructure;
import com.dotmarketing.beans.Host;
import com.dotmarketing.beans.Identifier;
import com.dotmarketing.beans.Inode;
import com.dotmarketing.business.APILocator;
import com.dotmarketing.db.HibernateUtil;
import com.dotmarketing.db.LocalTransaction;
import com.dotmarketing.exception.DotDataException;
import com.dotmarketing.exception.DotSecurityException;
import com.dotmarketing.portlets.AssetUtil;
import com.dotmarketing.portlets.ContentletBaseTest;
import com.dotmarketing.portlets.containers.model.Container;

import com.dotmarketing.util.UUIDGenerator;
import com.dotmarketing.util.UtilMethods;
import com.liferay.portal.model.User;
import com.liferay.portal.model.User;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.beanutils.BeanUtils;
import org.junit.Test;
import org.junit.runner.RunWith;

import javax.enterprise.context.Dependent;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Random;

import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

/**
* This class will test operations related with interacting with Containers.
*
* @author Jorge Urdaneta
* @since Aug 31st, 2012
*/
@Dependent
@RunWith(JUnit4WeldRunner.class)
public class ContainerAPITest extends ContentletBaseTest {

@Test
Expand Down Expand Up @@ -425,4 +422,61 @@ public void findContainerUsedBySpecificContentType() throws DotDataException, Do
}
}

/**
* Method to test: {@link ContainerAPI#findContainers(User, ContainerAPI.SearchParams)}
* Given Scenario: Searching for Containers with a given name.
* Expected Result: At least one Container must be returned.
*/
@Test
public void findFileContainerByName() throws DotDataException, DotSecurityException {
Host testSite = null;
try {
// Test data generation
testSite = new SiteDataGen().nextPersisted();
final String containerName = generateRandomName(10);
final String metadataCode = "$dotJSON.put(\"title\", \"Test "
+ containerName + " File Container\")\n"
+ "$dotJSON.put(\"max_contentlets\", 25)";
new ContainerAsFileDataGen()
.host(testSite)
.folderName("Test" + containerName + " File Container")
.metadataCode(metadataCode)
.nextPersisted();

// Find by name
final ContainerAPI.SearchParams searchParams = ContainerAPI.SearchParams.newBuilder()
.includeArchived(false)
.includeSystemContainer(false)
.siteId(testSite.getIdentifier())
.filteringCriterion(Map.of("title", containerName.toLowerCase())).build();
final List<Container> allContainers = containerAPI.findContainers(user, searchParams);

// Assertions
assertFalse("There must be at least one Container with the name 'File Container'", allContainers.isEmpty());
} finally {
// Clean up
if (null != testSite) {
APILocator.getHostAPI().archive(testSite, APILocator.systemUser(), false);
APILocator.getHostAPI().delete(testSite, APILocator.systemUser(), false);
}
}
}

private static final String ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
private static final Random RANDOM = new Random();

/**
* Generates a random name with the given length.
*
* @param length the length of the name to generate
* @return the generated name
*/
private static String generateRandomName(int length) {
StringBuilder name = new StringBuilder(length);
for (int i = 0; i < length; i++) {
name.append(ALPHABET.charAt(RANDOM.nextInt(ALPHABET.length())));
}
return name.toString();
}

}

0 comments on commit 9bf212a

Please sign in to comment.