Skip to content

Commit

Permalink
#28059 Updating integrations tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jgambarios committed Apr 23, 2024
1 parent fe6fec5 commit e4be04a
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public abstract class HostVariableFactory {
* @return The list of Site Variables
* @throws DotDataException
*/
protected abstract List<HostVariable> getVariablesForHost(String siteId)
public abstract List<HostVariable> getVariablesForHost(String siteId)
throws DotDataException;

protected abstract void updateUserReferences(String userToDelete, String userToReplace) throws DotDataException ;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.dotmarketing.portlets.hostvariable.bussiness;

import com.dotcms.repackage.com.google.common.annotations.VisibleForTesting;
import com.dotcms.util.transform.TransformerLocator;
import com.dotmarketing.business.CacheLocator;
import com.dotmarketing.common.db.DotConnect;
Expand Down Expand Up @@ -79,8 +80,8 @@ protected List <HostVariable> getAllVariables() throws DotDataException {
return hostVariables;
}


protected List<HostVariable> getVariablesForHost(final String siteId) throws DotDataException {
@VisibleForTesting
public List<HostVariable> getVariablesForHost(final String siteId) throws DotDataException {

List<HostVariable> siteVariables = CacheLocator.getHostVariablesCache()
.getVariablesForSite(siteId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.dotmarketing.beans.Permission;
import com.dotmarketing.business.APILocator;
import com.dotmarketing.business.CacheLocator;
import com.dotmarketing.business.FactoryLocator;
import com.dotmarketing.business.PermissionAPI;
import com.dotmarketing.business.Role;
import com.dotmarketing.business.RoleAPI;
Expand All @@ -36,6 +37,9 @@
import com.dotmarketing.portlets.contentlet.model.Contentlet;
import com.dotmarketing.portlets.contentlet.model.ContentletVersionInfo;
import com.dotmarketing.portlets.contentlet.model.IndexPolicy;
import com.dotmarketing.portlets.hostvariable.bussiness.HostVariableAPI;
import com.dotmarketing.portlets.hostvariable.bussiness.HostVariableFactory;
import com.dotmarketing.portlets.hostvariable.model.HostVariable;
import com.dotmarketing.portlets.languagesmanager.business.LanguageAPI;
import com.dotmarketing.portlets.languagesmanager.model.Language;
import com.dotmarketing.portlets.structure.model.Structure;
Expand All @@ -46,6 +50,7 @@
import com.dotmarketing.util.PaginatedArrayList;
import com.dotmarketing.util.UUIDGenerator;
import com.liferay.portal.model.User;
import java.util.Date;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
Expand Down Expand Up @@ -152,6 +157,44 @@ public void testDeleteHostCleanUpTemplates() throws Exception {

}

/**
* This test validates the site variables are deleted when the host is deleted
*/
@Test
public void testDeleteSiteCleanUpSiteVariables() throws Exception {

final HostVariableFactory hostVariableFactory = FactoryLocator.getHostVariableFactory();
final HostVariableAPI hostVariableAPI = APILocator.getHostVariableAPI();

final User user = APILocator.getUserAPI().getSystemUser();
final Host site = new SiteDataGen().nextPersisted();

// Check the current variables
var siteVariables = hostVariableFactory.getVariablesForHost(site.getIdentifier());
assertEquals(0, siteVariables.size());

// Save some variables to the site
hostVariableAPI.save(List.of(
createSiteVariable(site, user, 1),
createSiteVariable(site, user, 2),
createSiteVariable(site, user, 3),
createSiteVariable(site, user, 4),
createSiteVariable(site, user, 5)
), site.getIdentifier(), user, false);

// Make sure we properly saved the site variables
siteVariables = hostVariableFactory.getVariablesForHost(site.getIdentifier());
assertEquals(5, siteVariables.size());

// Delete the site
archiveHost(site, user);
deleteHost(site, user);

// And validate that the site variables were deleted
siteVariables = hostVariableFactory.getVariablesForHost(site.getIdentifier());
assertEquals(0, siteVariables.size());
}

@Test
public void testDeleteHost() throws Exception {

Expand Down Expand Up @@ -342,6 +385,28 @@ public void givenSearch_whenNewHost_thenFindsNewHost() throws Exception {
assertTrue(hosts.size() == 0 && hosts.getTotalResults() == 0);
}

/**
* Creates a site variable.
*
* @param host The host associated with the site variable.
* @param user The user who is creating the site variable.
* @param index The index used to generate unique names, keys, and values for the site
* variable.
* @return The created site variable.
*/
private HostVariable createSiteVariable(Host host, User user, int index) {

var siteVariable = new HostVariable();
siteVariable.setHostId(host.getIdentifier());
siteVariable.setName(String.format("var%dName", index));
siteVariable.setKey(String.format("var%dKey", index));
siteVariable.setValue(String.format("var%dValue", index));
siteVariable.setLastModifierId(user.getUserId());
siteVariable.setLastModDate(new Date());

return siteVariable;
}

/**
* Utility method to verify if Content Types under a just deleted host are also deleted or no,
* the idea is to validate that Content Types under the deleted host are deleted also EXCEPT for
Expand Down

0 comments on commit e4be04a

Please sign in to comment.