Skip to content

Commit

Permalink
#28214 : fixed test to add evaluate reason for dependency bundle test
Browse files Browse the repository at this point in the history
  • Loading branch information
dsolistorres committed Sep 18, 2024
1 parent d5f6ad0 commit 921c87d
Show file tree
Hide file tree
Showing 5 changed files with 194 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ public <T> boolean contains(final T asset, final PusheableAsset pusheableAsset)
return bundleAssets.isAdded(key, pusheableAsset);
}

public <T> boolean exclude(final T asset, final PusheableAsset pusheableAsset, String evaluateReason, final String excludeReason) {
public <T> boolean exclude(final T asset, final PusheableAsset pusheableAsset, final String evaluateReason, final String excludeReason) {
final String key = DependencyManager.getBundleKey(asset);

if(!excludes.contains(key)) {
Expand All @@ -325,7 +325,7 @@ public <T> void writeIncludeManifestItem(final T asset, final String evaluateRea
}
}

private <T> void writeExcludeManifestItem(final T asset, String evaluateReason, final String excludeReason) {
private <T> void writeExcludeManifestItem(final T asset, final String evaluateReason, final String excludeReason) {
if (ManifestItem.class.isAssignableFrom(asset.getClass())) {
if (UtilMethods.isSet(manifestBuilder)) {
manifestBuilder.exclude((ManifestItem) asset, evaluateReason, excludeReason);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ private String getManifestFileIncludeLine(final ManifestInfo manifestInfo,
}

private String getManifestFileExcludeLine(final ManifestInfo manifestInfo,
String evaluateReason, final String excludeReason) {
final String evaluateReason, final String excludeReason) {
return getManifestFileLine("EXCLUDED", manifestInfo, evaluateReason, excludeReason);
}

Expand All @@ -109,7 +109,7 @@ private String getManifestFileLine(
evaluateReason).stream().collect(Collectors.joining(","));
}

public <T> void exclude(final ManifestItem manifestItem, String evaluateReason, final String excludeReason){
public <T> void exclude(final ManifestItem manifestItem, final String evaluateReason, final String excludeReason){
final ManifestInfo manifestInfo = manifestItem.getManifestInfo();
final String line = getManifestFileExcludeLine(manifestInfo, evaluateReason, excludeReason);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.dotcms.enterprise.publishing.remote.bundler;

import com.dotcms.LicenseTestUtil;
import com.dotcms.contenttype.business.StoryBlockAPI;
import com.dotcms.contenttype.model.field.Field;
import com.dotcms.contenttype.model.field.ImageField;
Expand Down Expand Up @@ -126,6 +127,7 @@ public class DependencyBundlerTest {
public static void prepare() throws Exception {
//Setting web app environment
IntegrationTestInitService.getInstance().init();
LicenseTestUtil.getLicense();

final Map<String, List<ManifestItem>> excludeSystemFolderMap = new HashMap<>();
excludeSystemFolderMap.put(EXCLUDE_SYSTEM_FOLDER_HOST,
Expand Down Expand Up @@ -765,12 +767,19 @@ systemHostContentType, list(systemWorkflowScheme)

new TestData(contentletWithRelationship, contentletWithRelationshipIncludes, excludeSystemFolder,
filterDescriptorAllDependencies, "Contentlet with Relationship and filterDescriptorAllDependencies"),
new TestData(contentletWithRelationship, Map.of(contentTypeParent, list(relationship), contentletWithRelationship, list(relationship)), contentletWithRelationshipExcludes, filterDescriptorNotDependencies, "Contentlet with Relationship and filterDescriptorNotDependencies"),
new TestData(contentletWithRelationship, Map.of(contentTypeParent, list(relationship), contentletWithRelationship, list(relationship)), contentletWithRelationshipExcludes,
Map.of(contentTypeChild.getManifestInfo().id(),
list(getDependencyReason(relationship))),
filterDescriptorNotDependencies,
"Contentlet with Relationship and filterDescriptorNotDependencies"),
new TestData(contentletWithRelationship, Map.of(contentletWithRelationship, list(host, contentTypeParent, language, relationship), contentTypeParent, list(systemWorkflowScheme, relationship), relationship, list(contentTypeChild)),
Map.of(FILTER_EXCLUDE_REASON, list(), EXCLUDE_SYSTEM_FOLDER_HOST, list(systemFolder)),
filterDescriptorNotRelationship, "Contentlet with Relationship and filterDescriptorNotRelationship"),
new TestData(contentletWithRelationship, Map.of(contentletWithRelationship, list(relationship), contentTypeParent, list(relationship)), contentletWithRelationshipExcludes,
filterDescriptorNotDependenciesRelationship, "Contentlet with Relationship and filterDescriptorNotDependenciesRelationship"),
Map.of(contentTypeChild.getManifestInfo().id(),
list(getDependencyReason(relationship))),
filterDescriptorNotDependenciesRelationship,
"Contentlet with Relationship and filterDescriptorNotDependenciesRelationship"),

new TestData(contentWithCategory, contentWithCategoryIncludes, excludeSystemFolder,
filterDescriptorAllDependencies, "Contentlet with Category and filterDescriptorAllDependencies"),
Expand Down Expand Up @@ -817,9 +826,9 @@ private static Collection<TestData> createRuleTestCase() {
new TestData(rule, new HashMap<>(), Map.of(FILTER_EXCLUDE_REASON, list(host)), filterDescriptorNotDependenciesRelationship, "Page with filterDescriptorNotDependenciesRelationship"),

new TestData(ruleWithPage, Map.of(ruleWithPage, list(htmlPageAsset)), new HashMap<>(), filterDescriptorAllDependencies, "Rule with page and filterDescriptorAllDependencies"),
new TestData(ruleWithPage, new HashMap<>(), Map.of(FILTER_EXCLUDE_REASON, list(htmlPageAsset)), filterDescriptorNotDependencies, "Rule with page and filterDescriptorAllDependencies"),
new TestData(ruleWithPage, Map.of(ruleWithPage, list(htmlPageAsset)), new HashMap<>(), filterDescriptorNotRelationship, "Rule with page and filterDescriptorAllDependencies"),
new TestData(ruleWithPage, new HashMap<>(), Map.of(FILTER_EXCLUDE_REASON, list(htmlPageAsset)), filterDescriptorNotDependenciesRelationship, "Rule with page and filterDescriptorAllDependencies")
new TestData(ruleWithPage, new HashMap<>(), Map.of(FILTER_EXCLUDE_REASON, list(htmlPageAsset)), filterDescriptorNotDependencies, "Rule with page and filterDescriptorNotDependencies"),
new TestData(ruleWithPage, Map.of(ruleWithPage, list(htmlPageAsset)), new HashMap<>(), filterDescriptorNotRelationship, "Rule with page and filterDescriptorNotRelationship"),
new TestData(ruleWithPage, new HashMap<>(), Map.of(FILTER_EXCLUDE_REASON, list(htmlPageAsset)), filterDescriptorNotDependenciesRelationship, "Rule with page and filterDescriptorNotDependenciesRelationship")

);

Expand Down Expand Up @@ -1318,13 +1327,23 @@ EXCLUDE_SYSTEM_FOLDER_HOST, list(systemFolder)), filterDescriptorNotDependencies
EXCLUDE_SYSTEM_FOLDER_HOST, list(systemFolder)), filterDescriptorNotDependenciesRelationship, "Contentype with Category and filterDescriptorNotDependenciesRelationship"),

new TestData(contentTypeParent, contentTypeParentIncludes, excludeSystemFolder, filterDescriptorAllDependencies, "Contentype with Relationship and filterDescriptorAllDependencies"),
new TestData(contentTypeParent, Map.of(contentTypeParent, list(relationship)), Map.of(FILTER_EXCLUDE_REASON, list(host, systemWorkflowScheme, contentTypeChild),
EXCLUDE_SYSTEM_FOLDER_HOST, list(systemFolder)), filterDescriptorNotDependencies, "Contentype with Relationship and filterDescriptorNotDependencies"),
new TestData(contentTypeParent, Map.of(contentTypeParent, list(relationship)),
Map.of(FILTER_EXCLUDE_REASON, list(host, systemWorkflowScheme, contentTypeChild),
EXCLUDE_SYSTEM_FOLDER_HOST, list(systemFolder)),
Map.of(contentTypeChild.getManifestInfo().id(),
list(getDependencyReason(relationship))),
filterDescriptorNotDependencies,
"Contentype with Relationship and filterDescriptorNotDependencies"),
new TestData(contentTypeParent, Map.of(contentTypeParent, list(host, systemWorkflowScheme, relationship), relationship, list(contentTypeChild)),
Map.of(FILTER_EXCLUDE_REASON, list(), EXCLUDE_SYSTEM_FOLDER_HOST, list(systemFolder)),
filterDescriptorNotRelationship, "Contentype with Relationship and filterDescriptorNotRelationship"),
new TestData(contentTypeParent, Map.of(contentTypeParent, list(relationship)), Map.of(FILTER_EXCLUDE_REASON, list(host, systemWorkflowScheme, contentTypeChild),
EXCLUDE_SYSTEM_FOLDER_HOST, list(systemFolder)), filterDescriptorNotDependenciesRelationship, "Contentype with Relationship and filterDescriptorNotDependenciesRelationship")
new TestData(contentTypeParent, Map.of(contentTypeParent, list(relationship)),
Map.of(FILTER_EXCLUDE_REASON, list(host, systemWorkflowScheme, contentTypeChild),
EXCLUDE_SYSTEM_FOLDER_HOST, list(systemFolder)),
Map.of(contentTypeChild.getManifestInfo().id(),
list(getDependencyReason(relationship))),
filterDescriptorNotDependenciesRelationship,
"Contentype with Relationship and filterDescriptorNotDependenciesRelationship")
);
}

Expand Down Expand Up @@ -1436,6 +1455,12 @@ public void addLanguageVariableTestCaseInBundle()

}

private static String getDependencyReason(ManifestItem asset) {
return String.format(
"Dependency from: ID: %s Title: %s", asset.getManifestInfo().id(),
asset.getManifestInfo().title());
}

@DataProvider(format = "%m: %p[0]")
public static Object[] configs() throws Exception {
return new ModDateTestData[] {
Expand Down Expand Up @@ -1536,17 +1561,41 @@ contentTypeChild, list(APILocator.getWorkflowAPI().findSystemWorkflowScheme())

} else {
final String excludeByOperation = FILTER_EXCLUDE_BY_OPERATION + modDateTestData.operation;
manifestLines.addExcludes(Map.of(excludeByOperation,
list(host, language, contentTypeParent, contentTypeChild, relationship,
APILocator.getWorkflowAPI().findSystemWorkflowScheme())));
final List<ManifestItem> parentExcludeList = list(
host, language, contentTypeParent, relationship);
final List<ManifestItem> childExcludeList = list(
language, contentTypeChild);
manifestLines.addExcludes(
Map.of(excludeByOperation, parentExcludeList), contentParent);
manifestLines.addExcludes(
Map.of(excludeByOperation, childExcludeList), contentletChild);

final List<? extends Serializable> generalLangVarDependencies = list(
PublisherAPIImplTest.getLanguageVariablesContentType(),
APILocator.getWorkflowAPI().findSystemWorkflowScheme());

Stream.concat(PublisherAPIImplTest.getLanguagesVariableDependencies(),
languageVariables, generalLangVarDependencies).forEach(asset ->
manifestLines.addExclude((ManifestItem) asset, excludeByOperation));
languageVariables, generalLangVarDependencies).forEach(asset -> {
final String dependencyReason = asset instanceof Contentlet &&
!languageVariables.isEmpty() && languageVariables.contains((Contentlet) asset) ?
"Added Automatically by dotCMS" :
getDependencyReason(!languageVariables.isEmpty() ?
languageVariables.get(0) : (ManifestItem) asset);
manifestLines.addExclude((ManifestItem) asset, dependencyReason, excludeByOperation);
});

if (!languageVariables.isEmpty()) {
manifestLines.addExclude(APILocator.getFolderAPI().findSystemFolder(),
getDependencyReason(languageVariables.get(0)),
EXCLUDE_SYSTEM_FOLDER_HOST);
manifestLines.addExclude(APILocator.getHostAPI().findSystemHost(),
getDependencyReason(languageVariables.get(0).getContentType()),
EXCLUDE_SYSTEM_FOLDER_HOST);
manifestLines.addExclude(
APILocator.getWorkflowAPI().findSystemWorkflowScheme(),
getDependencyReason(languageVariables.get(0).getContentType()),
excludeByOperation);
}
}

dependencies.add(contentParent);
Expand All @@ -1559,11 +1608,14 @@ contentTypeChild, list(APILocator.getWorkflowAPI().findSystemWorkflowScheme())

manifestLines.addDependencies(Map.of(contentletChild, list(language, contentTypeChild)));
} else if (modDateTestData.operation == Operation.PUBLISH) {
manifestLines.addExclude(contentletChild, "Excluded by mod_date");
manifestLines.addExclude(contentletChild,
getDependencyReason(relationship),"Excluded by mod_date");

manifestLines.addDependencies(Map.of(contentletChild, list(language, contentTypeChild)));
} else {
manifestLines.addExclude(contentletChild, FILTER_EXCLUDE_BY_OPERATION + modDateTestData.operation);
manifestLines.addExclude(contentletChild,
getDependencyReason(relationship),
FILTER_EXCLUDE_BY_OPERATION + modDateTestData.operation);
}

manifestBuilder.close();
Expand Down Expand Up @@ -2358,6 +2410,7 @@ private static class TestData {
Map<ManifestItem, Collection<ManifestItem>> dependenciesToAssert;
FilterDescriptor filterDescriptor;
Map<String, List<ManifestItem>> excludes;
Map<String, List<String>> evaluateReasons;
String message;

public TestData(
Expand All @@ -2373,11 +2426,24 @@ public TestData(
final Map<ManifestItem, Collection<ManifestItem>> dependenciesToAssert,
final Map<String, List<ManifestItem>> excludes,
final FilterDescriptor filterDescriptor,
final String message) {
final String message) {
this(assetsToAddInBundle, dependenciesToAssert, excludes,
null, filterDescriptor, message);
}

public TestData(
final ManifestItem assetsToAddInBundle,
final Map<ManifestItem, Collection<ManifestItem>> dependenciesToAssert,
final Map<String, List<ManifestItem>> excludes,
final Map<String, List<String>> evaluateReasons,
final FilterDescriptor filterDescriptor,
final String message) {

this.assetsToAddInBundle = assetsToAddInBundle;
this.filterDescriptor = filterDescriptor;
this.dependenciesToAssert = dependenciesToAssert;
this.excludes = excludes;
this.evaluateReasons = evaluateReasons;
this.message = message;
}

Expand All @@ -2395,7 +2461,24 @@ public ManifestItemsMapTest manifestLines() {
manifestItemsMap.addDependencies(dependenciesToAssert);

if (excludes != null) {
manifestItemsMap.addExcludes(excludes);
if (evaluateReasons == null) {
manifestItemsMap.addExcludes(excludes, assetManifestItem);
} else {
for (final Map.Entry<String, List<ManifestItem>> excludeEntry : excludes.entrySet()) {
final String excludeReason = excludeEntry.getKey();
final List<ManifestItem> excludeList = excludeEntry.getValue();
for (final ManifestItem excludeItem : excludeList) {
final String itemId = excludeItem.getManifestInfo().id();
final List<String> evaluateReasonList = evaluateReasons
.getOrDefault(itemId,
list(getDependencyReason(assetManifestItem)));
for (final String evaluateReason : evaluateReasonList) {
manifestItemsMap.addExclude(excludeItem,
evaluateReason, excludeReason);
}
}
}
}
}

return manifestItemsMap;
Expand Down
Loading

0 comments on commit 921c87d

Please sign in to comment.