From 92d280487fd38c17d2400d1db454b70bbae6bdd4 Mon Sep 17 00:00:00 2001 From: "daniel.solis" Date: Mon, 4 Nov 2024 18:24:50 -0600 Subject: [PATCH] #28362 : changed HostSearchOptions class to Search Type enum for clarity --- ...ocalSystemEventSubscribersInitializer.java | 8 +- .../vanityurl/business/VanityUrlAPIImpl.java | 5 +- .../dotmarketing/business/ajax/HostAjax.java | 10 +- .../portlets/contentlet/business/HostAPI.java | 20 ++-- .../contentlet/business/HostAPIImpl.java | 105 +++++++----------- .../business/HostSearchOptions.java | 68 ------------ .../remote/HostBundlerHandlerTest.java | 13 +-- .../contentlet/business/HostAPITest.java | 17 +-- 8 files changed, 74 insertions(+), 172 deletions(-) delete mode 100644 dotCMS/src/main/java/com/dotmarketing/portlets/contentlet/business/HostSearchOptions.java diff --git a/dotCMS/src/main/java/com/dotcms/system/event/local/business/LocalSystemEventSubscribersInitializer.java b/dotCMS/src/main/java/com/dotcms/system/event/local/business/LocalSystemEventSubscribersInitializer.java index 01195629cbe3..1e27f3f8436a 100644 --- a/dotCMS/src/main/java/com/dotcms/system/event/local/business/LocalSystemEventSubscribersInitializer.java +++ b/dotCMS/src/main/java/com/dotcms/system/event/local/business/LocalSystemEventSubscribersInitializer.java @@ -17,7 +17,7 @@ import com.dotmarketing.exception.DotDataException; import com.dotmarketing.exception.DotSecurityException; import com.dotmarketing.portlets.containers.business.ContainerStructureFinderStrategyResolver; -import com.dotmarketing.portlets.contentlet.business.HostSearchOptions; +import com.dotmarketing.portlets.contentlet.business.HostAPI; import com.dotmarketing.portlets.folders.business.ApplicationContainerFolderListener; import com.dotmarketing.portlets.folders.business.ApplicationTemplateFolderListener; import com.dotmarketing.portlets.folders.model.Folder; @@ -87,8 +87,7 @@ public void initApplicationContainerFolderListener() { final User user = APILocator.systemUser(); final List hosts = APILocator.getHostAPI().findAllFromDB(user, - new HostSearchOptions().withIncludeSystemHost(true) - .withRespectFrontendRoles(false)); + HostAPI.SearchType.INCLUDE_SYSTEM_HOST); final ApplicationContainerFolderListener listener = new ApplicationContainerFolderListener(); for (final Host host : hosts) { @@ -111,8 +110,7 @@ public void initApplicationTemplateFolderListener() { final User user = APILocator.systemUser(); final List hosts = APILocator.getHostAPI().findAllFromDB(user, - new HostSearchOptions().withIncludeSystemHost(true) - .withRespectFrontendRoles(false)); + HostAPI.SearchType.INCLUDE_SYSTEM_HOST); final ApplicationTemplateFolderListener listener = new ApplicationTemplateFolderListener(); for (final Host host : hosts) { diff --git a/dotCMS/src/main/java/com/dotcms/vanityurl/business/VanityUrlAPIImpl.java b/dotCMS/src/main/java/com/dotcms/vanityurl/business/VanityUrlAPIImpl.java index b0c9844273f4..48c7f0f42a1b 100644 --- a/dotCMS/src/main/java/com/dotcms/vanityurl/business/VanityUrlAPIImpl.java +++ b/dotCMS/src/main/java/com/dotcms/vanityurl/business/VanityUrlAPIImpl.java @@ -24,7 +24,7 @@ import com.dotmarketing.exception.DotRuntimeException; import com.dotmarketing.portlets.contentlet.business.ContentletAPI; import com.dotmarketing.portlets.contentlet.business.DotContentletValidationException; -import com.dotmarketing.portlets.contentlet.business.HostSearchOptions; +import com.dotmarketing.portlets.contentlet.business.HostAPI; import com.dotmarketing.portlets.contentlet.model.Contentlet; import com.dotmarketing.portlets.languagesmanager.business.LanguageAPI; import com.dotmarketing.portlets.languagesmanager.model.Language; @@ -117,8 +117,7 @@ private void populateVanityURLsCacheBySite(final Host site) { @Override public void populateAllVanityURLsCache() throws DotDataException { for (final Host site : Try.of(() -> APILocator.getHostAPI().findAllFromDB(APILocator.systemUser(), - new HostSearchOptions().withIncludeSystemHost(true) - .withRespectFrontendRoles(false))).getOrElse(List.of())) { + HostAPI.SearchType.INCLUDE_SYSTEM_HOST)).getOrElse(List.of())) { populateVanityURLsCacheBySite(site); } populateVanityURLsCacheBySite(APILocator.getHostAPI().findSystemHost()); diff --git a/dotCMS/src/main/java/com/dotmarketing/business/ajax/HostAjax.java b/dotCMS/src/main/java/com/dotmarketing/business/ajax/HostAjax.java index 6e2dea0ef121..37d52d25eb1d 100644 --- a/dotCMS/src/main/java/com/dotmarketing/business/ajax/HostAjax.java +++ b/dotCMS/src/main/java/com/dotmarketing/business/ajax/HostAjax.java @@ -2,13 +2,11 @@ import com.dotcms.repackage.org.directwebremoting.WebContext; import com.dotcms.repackage.org.directwebremoting.WebContextFactory; -import com.dotcms.util.CollectionsUtils; import com.dotmarketing.beans.Host; import com.dotmarketing.business.APILocator; import com.dotmarketing.business.CacheLocator; import com.dotmarketing.business.DotStateException; import com.dotmarketing.business.PermissionAPI; -import com.dotmarketing.business.Versionable; import com.dotmarketing.business.util.HostNameComparator; import com.dotmarketing.business.web.UserWebAPI; import com.dotmarketing.business.web.WebAPILocator; @@ -17,7 +15,6 @@ import com.dotmarketing.exception.DotSecurityException; import com.dotmarketing.portlets.contentlet.business.ContentletAPI; import com.dotmarketing.portlets.contentlet.business.HostAPI; -import com.dotmarketing.portlets.contentlet.business.HostSearchOptions; import com.dotmarketing.portlets.contentlet.model.ContentletVersionInfo; import com.dotmarketing.portlets.structure.model.Field; import com.dotmarketing.portlets.structure.model.Structure; @@ -127,10 +124,11 @@ public Map findHostsForDataStore(String filter, boolean showArch public Map findHostsPaginated(final String filter, final boolean showArchived, int offset, int count) throws DotDataException, DotSecurityException, PortalException, SystemException { final User user = this.getLoggedInUser(); final boolean respectFrontend = !this.userWebAPI.isLoggedToBackend(this.getHttpRequest()); + final List searchTypes = respectFrontend ? + List.of(HostAPI.SearchType.RESPECT_FRONT_END_ROLES, HostAPI.SearchType.LIVE_ONLY) : + List.of(HostAPI.SearchType.LIVE_ONLY); final List sitesFromDb = this.hostAPI.findAllFromDB(user, - new HostSearchOptions().withIncludeSystemHost(false) - .withRetrieveLiveVersion(true) - .withRespectFrontendRoles(respectFrontend)); + searchTypes.toArray(new HostAPI.SearchType[0])); final List fields = FieldsCache.getFieldsByStructureVariableName(Host.HOST_VELOCITY_VAR_NAME); final List searchableFields = fields.stream().filter(field -> field.isListed() && field .getFieldType().startsWith("text")).collect(Collectors.toList()); diff --git a/dotCMS/src/main/java/com/dotmarketing/portlets/contentlet/business/HostAPI.java b/dotCMS/src/main/java/com/dotmarketing/portlets/contentlet/business/HostAPI.java index fd2fe28ea5bc..b3197794750a 100644 --- a/dotCMS/src/main/java/com/dotmarketing/portlets/contentlet/business/HostAPI.java +++ b/dotCMS/src/main/java/com/dotmarketing/portlets/contentlet/business/HostAPI.java @@ -23,10 +23,11 @@ public interface HostAPI { /** - * Will return a List of a host's aliases If no host aliases will return empty list - * @param host Host - * @return List + * This class is used to define the options for the search of a host. */ + enum SearchType { + LIVE_ONLY, RESPECT_FRONT_END_ROLES, INCLUDE_SYSTEM_HOST + } /** * Returns the aliases of a given Site in the form of a list. In the Site's properties, aliases can be separated by: @@ -184,7 +185,7 @@ Host find(Contentlet contentlet, /** * @deprecated This method is basically duplicated code. Use one of the following methods instead: *
    - *
  • {@link #findAllFromDB(User, HostSearchOptions)}
  • + *
  • {@link #findAllFromDB(User, SearchType...)}
  • *
  • {@link #findAllFromCache(User, boolean)}
  • *
  • {@link #search(String, boolean, boolean, int, int, User, boolean)}
  • *
@@ -223,15 +224,14 @@ Host find(Contentlet contentlet, * method allows you to EXCLUDE the System Host from the result list. Additionally, you can specify whether * you want to retrieve the live version of the Site over its working version if available. * - * @param user The {@link User} that is calling this method. - * @param searchOptions The search options to be used when retrieving the list of Sites. - * + * @param user The {@link User} that is calling this method. + * @param searchTypes The search options to be used when retrieving the list of Sites. * @return The list of {@link Host} objects. - * @throws DotDataException An error occurred when accessing the data source. + * @throws DotDataException An error occurred when accessing the data source. * @throws DotSecurityException The specified User does not have the required permissions to perform this - * operation. + * operation. */ - List findAllFromDB(final User user, final HostSearchOptions searchOptions) throws DotDataException, DotSecurityException; + List findAllFromDB(final User user, final SearchType... searchTypes) throws DotDataException, DotSecurityException; /** * Returns the complete list of Sites in your dotCMS repository retrieved from the cache. If no data is currently diff --git a/dotCMS/src/main/java/com/dotmarketing/portlets/contentlet/business/HostAPIImpl.java b/dotCMS/src/main/java/com/dotmarketing/portlets/contentlet/business/HostAPIImpl.java index ab15f99c22c9..42e04de866b0 100644 --- a/dotCMS/src/main/java/com/dotmarketing/portlets/contentlet/business/HostAPIImpl.java +++ b/dotCMS/src/main/java/com/dotmarketing/portlets/contentlet/business/HostAPIImpl.java @@ -42,6 +42,7 @@ import io.vavr.control.Try; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Optional; @@ -340,77 +341,58 @@ public Host find(final Contentlet contentlet, @Override @Deprecated public List findAll(final User user, final boolean respectFrontendRoles) throws DotDataException, DotSecurityException { - return this.findAllFromDB(user, - new HostSearchOptions().withIncludeSystemHost(true) - .withRespectFrontendRoles(respectFrontendRoles)); + final List searchTypes = respectFrontendRoles ? + List.of(SearchType.INCLUDE_SYSTEM_HOST, SearchType.RESPECT_FRONT_END_ROLES) : + List.of(SearchType.INCLUDE_SYSTEM_HOST); + return this.findAllFromDB(user, searchTypes.toArray(new SearchType[0])); } @Override public List findAll(final User user, final int limit, final int offset, final String sortBy, final boolean respectFrontendRoles) throws DotDataException, DotSecurityException { - return this.findPaginatedSitesFromDB(user, limit, offset, sortBy, respectFrontendRoles); + final List searchTypes = respectFrontendRoles ? + List.of(SearchType.INCLUDE_SYSTEM_HOST, SearchType.RESPECT_FRONT_END_ROLES) : + List.of(SearchType.INCLUDE_SYSTEM_HOST); + return this.findPaginatedSitesFromDB(user, limit, offset, sortBy, + searchTypes.toArray(new SearchType[0])); } @Override @CloseDBIfOpened - public List findAllFromDB(final User user, final HostSearchOptions searchOptions) throws DotDataException, DotSecurityException { - return this.findPaginatedSitesFromDB(user, 0, 0, null, - searchOptions.isIncludeSystemHost(), - searchOptions.isRetrieveLiveVersion(), - searchOptions.isRespectFrontendRoles()); + public List findAllFromDB(final User user, final SearchType... searchTypes) throws DotDataException, DotSecurityException { + return this.findPaginatedSitesFromDB(user, 0, 0, null, searchTypes); } /** - * Returns an optionally paginated list of all Sites in your dotCMS content repository, including the System Host. - * - * @param user The {@link User} performing this action. - * @param limit Limit of results returned in the response, for pagination purposes. If set equal or - * lower than zero, this parameter will be ignored. - * @param offset Expected offset of results in the response, for pagination purposes. If set equal or - * lower than zero, this parameter will be ignored. - * @param sortBy Optional sorting criterion, as specified by the available columns in: {@link - * com.dotmarketing.common.util.SQLUtil#ORDERBY_WHITELIST} - * @param respectFrontendRoles If the User's front-end roles need to be taken into account in order to perform this - * operation, set to {@code true}. Otherwise, set to {@code false}. + * Returns an optionally paginated list of all Sites in your dotCMS content repository. This method allows you to + * * EXCLUDE the System Host from the result list. It also allows you to get live versions of the sites + * when they are available. * + * @param user The {@link User} performing this action. + * @param limit Limit of results returned in the response, for pagination purposes. If set equal or + * lower than zero, this parameter will be ignored. + * @param offset Expected offset of results in the response, for pagination purposes. If set equal or + * lower than zero, this parameter will be ignored. + * @param sortBy Optional sorting criterion, as specified by the available columns in: {@link + * com.dotmarketing.common.util.SQLUtil#ORDERBY_WHITELIST} + * @param searchTypes The search types to be used in the query. * @return The list of {@link Host} objects. - * * @throws DotDataException An error occurred when accessing the data source. * @throws DotSecurityException The specified User does not have the required permissions to perform this * operation. */ @CloseDBIfOpened private List findPaginatedSitesFromDB(final User user, final int limit, final int offset, final String - sortBy, final boolean respectFrontendRoles) throws DotDataException, DotSecurityException { - return this.findPaginatedSitesFromDB(user, limit, offset, sortBy, true, false, respectFrontendRoles); - } + sortBy, final SearchType... searchTypes) throws DotDataException, DotSecurityException { + + final boolean respectFrontEndRoles = Arrays.stream(searchTypes).anyMatch(t -> t == SearchType.RESPECT_FRONT_END_ROLES); + final boolean includeSystemHost = Arrays.stream(searchTypes).anyMatch(t -> t == SearchType.INCLUDE_SYSTEM_HOST); + final boolean liveOnly = Arrays.stream(searchTypes).anyMatch(t -> t == SearchType.LIVE_ONLY); - /** - * Returns an optionally paginated list of all Sites in your dotCMS content repository. This method allows you to - * EXCLUDE the System Host from the result list. - * - * @param user The {@link User} performing this action. - * @param limit Limit of results returned in the response, for pagination purposes. If set equal or - * lower than zero, this parameter will be ignored. - * @param offset Expected offset of results in the response, for pagination purposes. If set equal or - * lower than zero, this parameter will be ignored. - * @param sortBy Optional sorting criterion, as specified by the available columns in: {@link - * com.dotmarketing.common.util.SQLUtil#ORDERBY_WHITELIST} - * @param includeSystemHost If the System Host should be included in the result list, set to {@code true}. - * @param retrieveLiveVersion If the live version of the Site should be retrieved, set to {@code true}. - * @param respectFrontendRoles If the User's front-end roles need to be taken into account in order to perform this - * operation, set to {@code true}. Otherwise, set to {@code false}. - * @return The list of {@link Host} objects. - * @throws DotDataException An error occurred when accessing the data source. - * @throws DotSecurityException The specified User does not have the required permissions to perform this - * operation. - */ - private List findPaginatedSitesFromDB(final User user, final int limit, final int offset, - final String sortBy, final boolean includeSystemHost, - final boolean retrieveLiveVersion, final boolean respectFrontendRoles) throws DotDataException, DotSecurityException { final List siteList = this.getHostFactory().findAll( - limit, offset, sortBy, includeSystemHost, retrieveLiveVersion); - return filterHostsByPermissions(user, includeSystemHost, respectFrontendRoles, siteList); + limit, offset, sortBy, includeSystemHost, liveOnly); + + return filterHostsByPermissions(user, includeSystemHost, respectFrontEndRoles, siteList); } /** @@ -451,14 +433,10 @@ public List findAllFromCache(final User user, final boolean respectFrontendRoles) throws DotDataException, DotSecurityException { Set cachedSites = hostCache.getAllSites(respectFrontendRoles); if(null == cachedSites){ - final List allFromDB = findAllFromDB(APILocator.systemUser(), - new HostSearchOptions().withIncludeSystemHost(true) - .withRetrieveLiveVersion(false) - .withRespectFrontendRoles(false)); - final List allFromDBLive = findAllFromDB(APILocator.systemUser(), - new HostSearchOptions().withIncludeSystemHost(true) - .withRetrieveLiveVersion(true) - .withRespectFrontendRoles(false)); + final List allFromDB = findAllFromDB( + APILocator.systemUser(), SearchType.INCLUDE_SYSTEM_HOST); + final List allFromDBLive = findAllFromDB( + APILocator.systemUser(), SearchType.INCLUDE_SYSTEM_HOST, SearchType.LIVE_ONLY); hostCache.addAll(allFromDB, allFromDBLive); final List filteredSiteList = filterHostsByPermissions( user, true, respectFrontendRoles, @@ -527,10 +505,11 @@ public Host save(final Host hostToBeSaved, User user, boolean respectFrontendRol public void updateDefaultHost(Host host, User user, boolean respectFrontendRoles) throws DotDataException, DotSecurityException{ // If host is marked as default make sure that no other host is already set to be the default if(host.isDefault()) { - ContentletAPI conAPI = APILocator.getContentletAPI(); - List hosts= findAllFromDB(user, - new HostSearchOptions().withIncludeSystemHost(true) - .withRespectFrontendRoles(respectFrontendRoles)); + final ContentletAPI conAPI = APILocator.getContentletAPI(); + final List searchTypes = respectFrontendRoles ? + List.of(SearchType.INCLUDE_SYSTEM_HOST, SearchType.RESPECT_FRONT_END_ROLES) : + List.of(SearchType.INCLUDE_SYSTEM_HOST); + final List hosts= findAllFromDB(user, searchTypes.toArray(new SearchType[0])); Host otherHost; Contentlet otherHostContentlet; for(Host h : hosts){ @@ -539,7 +518,7 @@ public void updateDefaultHost(Host host, User user, boolean respectFrontendRoles } // if this host is the default as well then ours should become the only one if(h.isDefault()){ - boolean isHostRunning = h.isLive(); + final boolean isHostRunning = h.isLive(); otherHostContentlet = APILocator.getContentletAPI().checkout(h.getInode(), user, respectFrontendRoles); otherHost = new Host(otherHostContentlet); hostCache.remove(otherHost); @@ -549,7 +528,7 @@ public void updateDefaultHost(Host host, User user, boolean respectFrontendRoles if(host.getMap().containsKey(Contentlet.DISABLE_WORKFLOW)) otherHost.setProperty(Contentlet.DISABLE_WORKFLOW,true); - Contentlet cont = conAPI.checkin(otherHost, user, respectFrontendRoles); + final Contentlet cont = conAPI.checkin(otherHost, user, respectFrontendRoles); if(isHostRunning) { otherHost = new Host(cont); publish(otherHost, user, respectFrontendRoles); diff --git a/dotCMS/src/main/java/com/dotmarketing/portlets/contentlet/business/HostSearchOptions.java b/dotCMS/src/main/java/com/dotmarketing/portlets/contentlet/business/HostSearchOptions.java deleted file mode 100644 index d43e6321f37e..000000000000 --- a/dotCMS/src/main/java/com/dotmarketing/portlets/contentlet/business/HostSearchOptions.java +++ /dev/null @@ -1,68 +0,0 @@ -package com.dotmarketing.portlets.contentlet.business; - -/** - * This class is used to define the options for the search of a host. - * The options are: - * - includeSystemHost: if true, the system host will be included in the search - * - retrieveLiveVersion: if true, the live version of the host will be retrieved if available - * - respectFrontendRoles: if true, the search will respect the user frontend roles - */ -public class HostSearchOptions { - private boolean includeSystemHost = false; - private boolean retrieveLiveVersion = false; - private boolean respectFrontendRoles = false; - - /** - * Returns if the system host is included in the search - * @return true if the system host is included in the search, false otherwise - */ - public boolean isIncludeSystemHost() { - return includeSystemHost; - } - - /** - * Returns if the live version of the host is retrieved if available - * @return true if the live version of the host is retrieved, false otherwise - */ - public boolean isRetrieveLiveVersion() { - return retrieveLiveVersion; - } - - /** - * Returns if the search respects the user frontend roles - * @return true if the search respects the user frontend roles, false otherwise - */ - public boolean isRespectFrontendRoles() { - return respectFrontendRoles; - } - - /** - * Sets if the system host is included in the search - * @param includeSystemHost true if the system host is included in the search, false otherwise - * @return this object - */ - public HostSearchOptions withIncludeSystemHost(boolean includeSystemHost) { - this.includeSystemHost = includeSystemHost; - return this; - } - - /** - * Sets if the live version of the host is retrieved if available - * @param retrieveLiveVersion true if the live version of the host is retrieved, false otherwise - * @return this object - */ - public HostSearchOptions withRetrieveLiveVersion(boolean retrieveLiveVersion) { - this.retrieveLiveVersion = retrieveLiveVersion; - return this; - } - - /** - * Sets if the search respects the user frontend roles - * @param respectFrontendRoles true if the search respects the user frontend roles, false otherwise - * @return this object - */ - public HostSearchOptions withRespectFrontendRoles(boolean respectFrontendRoles) { - this.respectFrontendRoles = respectFrontendRoles; - return this; - } -} diff --git a/dotcms-integration/src/test/java/com/dotcms/enterprise/publishing/remote/HostBundlerHandlerTest.java b/dotcms-integration/src/test/java/com/dotcms/enterprise/publishing/remote/HostBundlerHandlerTest.java index 9bfcdf62862b..4bbb38aac0e0 100644 --- a/dotcms-integration/src/test/java/com/dotcms/enterprise/publishing/remote/HostBundlerHandlerTest.java +++ b/dotcms-integration/src/test/java/com/dotcms/enterprise/publishing/remote/HostBundlerHandlerTest.java @@ -15,7 +15,6 @@ import com.dotmarketing.db.HibernateUtil; import com.dotmarketing.db.LocalTransaction; import com.dotmarketing.portlets.contentlet.business.HostAPI; -import com.dotmarketing.portlets.contentlet.business.HostSearchOptions; import com.dotmarketing.portlets.contentlet.model.IndexPolicy; import com.dotmarketing.util.Config; import com.dotmarketing.util.UUIDGenerator; @@ -45,8 +44,7 @@ public static void prepare() throws Exception { hostAPI = APILocator.getHostAPI(); user = APILocator.getUserAPI().getSystemUser(); originalHostSize = APILocator.getHostAPI().findAllFromDB(user, - new HostSearchOptions().withIncludeSystemHost(true) - .withRespectFrontendRoles(false)).size(); + HostAPI.SearchType.INCLUDE_SYSTEM_HOST).size(); } /** @@ -80,8 +78,7 @@ public void testBundlerHandler_UnpublishHost_Success() throws Exception { Assert.assertEquals(originalHostSize + 1, APILocator.getHostAPI().findAllFromDB(user, - new HostSearchOptions().withIncludeSystemHost(true) - .withRespectFrontendRoles(false)).size()); + HostAPI.SearchType.INCLUDE_SYSTEM_HOST).size()); contentSet.add(host2.getIdentifier()); @@ -113,8 +110,7 @@ public void testBundlerHandler_UnpublishHost_Success() throws Exception { Assert.assertEquals(originalHostSize, APILocator.getHostAPI().findAllFromDB(user, - new HostSearchOptions().withIncludeSystemHost(true) - .withRespectFrontendRoles(false)).size()); + HostAPI.SearchType.INCLUDE_SYSTEM_HOST).size()); TestDataUtils.assertEmptyQueue(); } finally { @@ -156,8 +152,7 @@ public void testGenerate_success_when_liveContentletIsNotFound() Assert.assertEquals(originalHostSize + 1, APILocator.getHostAPI().findAllFromDB(user, - new HostSearchOptions().withIncludeSystemHost(true) - .withRespectFrontendRoles(false)).size()); + HostAPI.SearchType.INCLUDE_SYSTEM_HOST).size()); contentSet.add(host.getIdentifier()); diff --git a/dotcms-integration/src/test/java/com/dotmarketing/portlets/contentlet/business/HostAPITest.java b/dotcms-integration/src/test/java/com/dotmarketing/portlets/contentlet/business/HostAPITest.java index 9c5a708a4601..b99c936b1ec5 100644 --- a/dotcms-integration/src/test/java/com/dotmarketing/portlets/contentlet/business/HostAPITest.java +++ b/dotcms-integration/src/test/java/com/dotmarketing/portlets/contentlet/business/HostAPITest.java @@ -1,6 +1,7 @@ package com.dotmarketing.portlets.contentlet.business; import com.dotcms.IntegrationTestBase; +import com.dotcms.JUnit4WeldRunner; import com.dotcms.LicenseTestUtil; import com.dotcms.contenttype.exception.NotFoundInDbException; import com.dotcms.contenttype.model.type.BaseContentType; @@ -51,11 +52,13 @@ import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; +import org.junit.runner.RunWith; import org.mockito.Mockito; import org.quartz.JobDetail; import org.quartz.JobExecutionContext; import org.quartz.Trigger; +import javax.enterprise.context.Dependent; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -81,6 +84,8 @@ * @author Jorge Urdaneta * @since Sep 5, 2013 */ +@Dependent +@RunWith(JUnit4WeldRunner.class) public class HostAPITest extends IntegrationTestBase { @BeforeClass @@ -1010,8 +1015,7 @@ public void Test_findAllCache() throws DotSecurityException, DotDataException { final User systemUser = APILocator.systemUser(); final HostAPI hostAPI = APILocator.getHostAPI(); final List allFromDB1 = hostAPI.findAllFromDB(systemUser, - new HostSearchOptions().withIncludeSystemHost(true) - .withRespectFrontendRoles(false)); + HostAPI.SearchType.INCLUDE_SYSTEM_HOST); final List allFromCache1 = hostAPI.findAllFromCache(systemUser, false); Assert.assertTrue( allFromDB1.size() == allFromCache1.size() && allFromDB1.containsAll(allFromCache1) && allFromCache1.containsAll(allFromDB1)); @@ -1832,7 +1836,7 @@ public void count() throws DotHibernateException, ExecutionException, Interrupte /** *
    - *
  • Method to test: {@link HostAPI#findAllFromDB(User, HostSearchOptions)}
  • + *
  • Method to test: {@link HostAPI#findAllFromDB(User, HostAPI.SearchType...)}
  • *
  • Given Scenario: Create a test Site and call the {@findAllFromDB} method that allows you to include * or exclude the System Host.
  • *
  • Expected Result: When calling the method with the {@code includeSystemHost} parameter as @@ -1846,12 +1850,9 @@ public void findAllFromDB() throws DotDataException, DotSecurityException { final User systemUser = APILocator.systemUser(); // Test data generation - final List siteList = hostAPI.findAllFromDB(systemUser, - new HostSearchOptions().withIncludeSystemHost(false) - .withRespectFrontendRoles(false)); + final List siteList = hostAPI.findAllFromDB(systemUser); final List siteListWithSystemHost = hostAPI.findAllFromDB(systemUser, - new HostSearchOptions().withIncludeSystemHost(true) - .withRespectFrontendRoles(false)); + HostAPI.SearchType.INCLUDE_SYSTEM_HOST); // Assertions assertEquals("The size difference between both Site lists MUST be 1", 1,