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

fix(containers) : change search functionality to case insensitive for file containers #30543

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,6 +1,8 @@
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;
Expand All @@ -20,23 +22,30 @@
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 +434,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();
}

}