Skip to content

Commit

Permalink
NXP-32775: Align on 2025 and start test without errors + cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
guirenard committed Jan 8, 2025
1 parent a691c33 commit 1724a54
Show file tree
Hide file tree
Showing 14 changed files with 101 additions and 65 deletions.
3 changes: 1 addition & 2 deletions ci/Jenkinsfiles/build.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ Closure buildUnitTestStage(env) {
sh """
mvn -B -nsu -pl :nuxeo-retention \
-Dcustom.environment=${env} \
-Dcustom.environment.log.dir=target-${env} \
-Dnuxeo.test.core=${env == 'mongodb' ? 'mongodb' : 'vcs'} \
test
"""
}
Expand All @@ -61,6 +59,7 @@ pipeline {
}
environment {
CURRENT_NAMESPACE = nxK8s.getCurrentNamespace()
TEST_SERVICE_DOMAIN_SUFFIX = 'svc.cluster.local'
MAVEN_OPTS = "$MAVEN_OPTS -Xms512m -Xmx3072m"
VERSION = nxUtils.getVersion()
NUXEO_RETENTION_PACKAGE_PATH = "nuxeo-retention-package/target/nuxeo-retention-package-${VERSION}.zip"
Expand Down
3 changes: 2 additions & 1 deletion ci/mvn/nuxeo-test-mongodb.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
nuxeo.test.core=mongodb
nuxeo.test.mongodb.dbname=nuxeo
nuxeo.test.mongodb.server=mongodb://mongodb.$NAMESPACE.svc.cluster.local
nuxeo.test.mongodb.server=mongodb://mongodb.$NAMESPACE.$TEST_SERVICE_DOMAIN_SUFFIX
7 changes: 4 additions & 3 deletions ci/mvn/nuxeo-test-postgresql.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
nuxeo.test.vcs.db=PostgreSQL
nuxeo.test.vcs.server=postgresql.$NAMESPACE.svc.cluster.local
nuxeo.test.vcs.database=nuxeo
nuxeo.test.core=sql
nuxeo.test.sql.db=PostgreSQL
nuxeo.test.sql.server=postgresql.$NAMESPACE.$TEST_SERVICE_DOMAIN_SUFFIX
nuxeo.test.sql.database=nuxeo
10 changes: 10 additions & 0 deletions nuxeo-retention/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,15 @@
<artifactId>nuxeo-platform-default-config</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.nuxeo.ecm.platform</groupId>
<artifactId>nuxeo-search-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.nuxeo.ecm.platform</groupId>
<artifactId>nuxeo-platform-tag</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
import java.util.List;
import java.util.Map;

import org.nuxeo.audit.service.AuditComponent;
import org.nuxeo.ecm.core.api.CoreSession;
import org.nuxeo.ecm.core.api.DocumentModel;
import org.nuxeo.ecm.core.api.IdRef;
import org.nuxeo.ecm.core.bulk.action.computation.AbstractBulkComputation;
import org.nuxeo.ecm.core.bulk.message.BulkCommand;
import org.nuxeo.ecm.platform.audit.service.NXAuditEventsService;
import org.nuxeo.lib.stream.computation.Topology;
import org.nuxeo.retention.adapters.RetentionRule;
import org.nuxeo.retention.service.RetentionManager;
Expand Down Expand Up @@ -74,7 +74,7 @@ public EvaluateRuleComputation() {
@Override
public void startBucket(String bucketKey) {
BulkCommand command = getCurrentCommand();
Serializable auditParam = command.getParam(NXAuditEventsService.DISABLE_AUDIT_LOGGER);
Serializable auditParam = command.getParam(AuditComponent.DISABLE_AUDIT_LOGGER);
disableAudit = auditParam != null && Boolean.parseBoolean(auditParam.toString());
retentionManager = Framework.getService(RetentionManager.class);
ruleId = command.getParam(PARAM_RULE_ID);
Expand All @@ -90,7 +90,7 @@ protected void compute(CoreSession session, List<String> ids, Map<String, Serial
continue;
}
if (disableAudit) {
doc.putContextData(NXAuditEventsService.DISABLE_AUDIT_LOGGER, Boolean.TRUE);
doc.putContextData(AuditComponent.DISABLE_AUDIT_LOGGER, Boolean.TRUE);
}
retentionManager.attachRule(doc, rule, session);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.nuxeo.audit.service.AuditComponent;
import org.nuxeo.ecm.core.api.CoreSession;
import org.nuxeo.ecm.core.api.DocumentModel;
import org.nuxeo.ecm.core.bulk.action.computation.AbstractBulkComputation;
import org.nuxeo.ecm.core.bulk.message.BulkCommand;
import org.nuxeo.ecm.platform.audit.service.NXAuditEventsService;
import org.nuxeo.lib.stream.computation.Topology;
import org.nuxeo.retention.RetentionConstants;
import org.nuxeo.retention.adapters.Record;
Expand Down Expand Up @@ -85,7 +85,7 @@ public EvalInputEventBasedRuleComputation() {
@Override
public void startBucket(String bucketKey) {
BulkCommand command = getCurrentCommand();
Serializable auditParam = command.getParam(NXAuditEventsService.DISABLE_AUDIT_LOGGER);
Serializable auditParam = command.getParam(AuditComponent.DISABLE_AUDIT_LOGGER);
disableAudit = auditParam != null && Boolean.parseBoolean(auditParam.toString());
retentionManager = Framework.getService(RetentionManager.class);
eventInput = command.getParam(ACTION_EVENT_INPUT_PARAM);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.nuxeo.audit.service.AuditComponent;
import org.nuxeo.ecm.core.api.CoreSession;
import org.nuxeo.ecm.core.api.DocumentModel;
import org.nuxeo.ecm.core.api.IdRef;
import org.nuxeo.ecm.core.api.versioning.VersioningService;
import org.nuxeo.ecm.platform.audit.service.NXAuditEventsService;
import org.nuxeo.ecm.platform.dublincore.listener.DublinCoreListener;
import org.nuxeo.ecm.platform.ec.notification.NotificationConstants;
import org.nuxeo.retention.RetentionConstants;
Expand Down Expand Up @@ -115,14 +115,14 @@ protected void save(CoreSession session) {
document.putContextData(VersioningService.DISABLE_AUTOMATIC_VERSIONING, true);
document.putContextData(DublinCoreListener.DISABLE_DUBLINCORE_LISTENER, true);
document.putContextData(NotificationConstants.DISABLE_NOTIFICATION_SERVICE, true);
document.putContextData(NXAuditEventsService.DISABLE_AUDIT_LOGGER, true);
document.putContextData(AuditComponent.DISABLE_AUDIT_LOGGER, true);
document.putContextData(VersioningService.DISABLE_AUTO_CHECKOUT, true);
document.putContextData(RetentionConstants.RETENTION_CHECKER_LISTENER_IGNORE, true);
session.saveDocument(document);
document.putContextData(VersioningService.DISABLE_AUTOMATIC_VERSIONING, null);
document.putContextData(DublinCoreListener.DISABLE_DUBLINCORE_LISTENER, null);
document.putContextData(NotificationConstants.DISABLE_NOTIFICATION_SERVICE, null);
document.putContextData(NXAuditEventsService.DISABLE_AUDIT_LOGGER, null);
document.putContextData(AuditComponent.DISABLE_AUDIT_LOGGER, null);
document.putContextData(VersioningService.DISABLE_AUTO_CHECKOUT, null);
document.getContextData().remove(RetentionConstants.RETENTION_CHECKER_LISTENER_IGNORE);
}
Expand All @@ -132,7 +132,7 @@ public void saveRetainUntil(Calendar retainUntil) {
}

public void setRule(RetentionRule rule, CoreSession session) {
setRuleIds(Arrays.asList(rule.getDocument().getId()));
setRuleIds(Collections.singletonList(rule.getDocument().getId()));
save(session);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
package org.nuxeo.retention.listeners;

import static org.nuxeo.ecm.core.api.security.SecurityConstants.SYSTEM_USERNAME;
import static org.nuxeo.ecm.core.query.sql.NXQL.ECM_UUID;
import static org.nuxeo.retention.RetentionConstants.ACTIVE_EVENT_BASED_RETENTION_RULES_QUERY;
import static org.nuxeo.retention.RetentionConstants.RECORD_RULE_IDS_PROP;
import static org.nuxeo.retention.RetentionConstants.RULE_RECORD_DOCUMENT_QUERY;
Expand Down Expand Up @@ -55,7 +54,7 @@
*
* @since 11.1
*/
public class RetentionBusinessEventListener implements EventListener {
public class RetentionBusinessEventqListener implements EventListener {

private static final Logger log = LogManager.getLogger(RetentionBusinessEventListener.class);

Expand All @@ -73,7 +72,7 @@ public void handleEvent(Event event) {
var rulesIds = getEventBasedRuleIdsForEvent(eventName, repositoryName);
query.append(" AND ") //
.append(RECORD_RULE_IDS_PROP) //
.append(String.format(" IN ('%s')", rulesIds.stream().collect(Collectors.joining("', '"))));
.append(String.format(" IN ('%s')", String.join("', '", rulesIds)));
BulkCommand command = new BulkCommand.Builder(EvalInputEventBasedRuleAction.ACTION_NAME,
query.toString(), SYSTEM_USERNAME).param(ACTION_EVENT_ID_PARAM, eventName)
.param(ACTION_EVENT_INPUT_PARAM, eventInput)
Expand All @@ -92,7 +91,7 @@ protected List<String> getEventBasedRuleIdsForEvent(String eventName, String rep
.append(NXQL.escapeString(eventName));
CoreSession session = CoreInstance.getCoreSession(repository);
PartialList<Map<String, Serializable>> results = session.queryProjection(query.toString(), 0, 0);
return results.stream().map(m -> (String) m.get(ECM_UUID)).collect(Collectors.toList());
return results.stream().map(m -> (String) m.get(NXQL.ECM_UUID)).collect(Collectors.toList());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public interface RetentionManager {
* @param document the document
* @param rule the rule
* @param session the session
* @return
* @return true if rule can be attached to the document
* @since 11.1
*/
boolean canAttachRule(DocumentModel document, RetentionRule rule, CoreSession session);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
import org.apache.el.ExpressionFactoryImpl;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.nuxeo.audit.api.LogEntry;
import org.nuxeo.audit.service.AuditBackend;
import org.nuxeo.audit.service.AuditComponent;
import org.nuxeo.ecm.automation.AutomationService;
import org.nuxeo.ecm.automation.OperationContext;
import org.nuxeo.ecm.automation.OperationException;
Expand Down Expand Up @@ -65,9 +68,6 @@
import org.nuxeo.ecm.directory.Session;
import org.nuxeo.ecm.directory.api.DirectoryService;
import org.nuxeo.ecm.platform.actions.ELActionContext;
import org.nuxeo.ecm.platform.audit.api.AuditLogger;
import org.nuxeo.ecm.platform.audit.api.LogEntry;
import org.nuxeo.ecm.platform.audit.service.NXAuditEventsService;
import org.nuxeo.ecm.platform.dublincore.listener.DublinCoreListener;
import org.nuxeo.ecm.platform.ec.notification.NotificationConstants;
import org.nuxeo.ecm.platform.el.ExpressionContext;
Expand All @@ -78,6 +78,7 @@
import org.nuxeo.retention.event.RetentionEventContext;
import org.nuxeo.retention.workers.RuleEvaluationWorker;
import org.nuxeo.runtime.api.Framework;
import org.nuxeo.runtime.model.Component;
import org.nuxeo.runtime.model.ComponentContext;
import org.nuxeo.runtime.model.DefaultComponent;

Expand Down Expand Up @@ -160,7 +161,7 @@ public DocumentModel unattachRule(DocumentModel document, CoreSession session) {
document.putContextData(VersioningService.DISABLE_AUTOMATIC_VERSIONING, true);
document.putContextData(DublinCoreListener.DISABLE_DUBLINCORE_LISTENER, true);
document.putContextData(NotificationConstants.DISABLE_NOTIFICATION_SERVICE, true);
document.putContextData(NXAuditEventsService.DISABLE_AUDIT_LOGGER, true);
document.putContextData(AuditComponent.DISABLE_AUDIT_LOGGER, true);
document.putContextData(VersioningService.DISABLE_AUTO_CHECKOUT, true);
document.putContextData(RetentionConstants.RETENTION_CHECKER_LISTENER_IGNORE, true);
return session.saveDocument(document);
Expand Down Expand Up @@ -215,14 +216,12 @@ public void fireRetentionEvent(String eventName, String eventInput, boolean audi
Event event = evctx.newEvent(eventName);
Framework.getService(EventProducer.class).fireEvent(event);
if (audit) {
AuditLogger logger = Framework.getService(AuditLogger.class);
LogEntry entry = logger.newLogEntry();
entry.setEventId(name);
entry.setEventDate(new Date());
entry.setCategory(RetentionConstants.EVENT_CATEGORY);
entry.setPrincipalName(session.getPrincipal().getName());
entry.setComment(evctx.getInput());
logger.addLogEntries(Collections.singletonList(entry));
LogEntry entry = LogEntry.builder(name, new Date())
.category(RetentionConstants.EVENT_CATEGORY)
.principalName(session.getPrincipal().getName())
.comment(evctx.getInput())
.build();
Framework.getService(AuditBackend.class).addLogEntries(Collections.singletonList(entry));
}
}

Expand Down Expand Up @@ -427,8 +426,11 @@ public void invalidate() {

@Override
public int getApplicationStartedOrder() {
// after directories
return 98;
Component component = (Component) Framework.getRuntime()
.getComponentInstance(
"org.nuxeo.ecm.core.operation.OperationServiceComponent")
.getInstance();
return component.getApplicationStartedOrder() + 1;
}

@Override
Expand All @@ -449,4 +451,5 @@ public void start(ComponentContext context) {
});
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<component name="org.nuxeo.retention.RetentionService">
<require>org.nuxeo.ecm.platform.usermanager.UserService</require>
<require>org.nuxeo.ecm.platform.usermanager.UserManagerImpl</require>
<require>org.nuxeo.ecm.core.operation.OperationServiceComponent</require>
<require>org.nuxeo.retention.vocabularies</require>

<implementation
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* (C) Copyright 2025 Nuxeo (http://nuxeo.com/) and others.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Contributors:
* Guillaume Renard
*/

package org.nuxeo.retention.test;

import org.nuxeo.ecm.automation.test.EmbeddedAutomationServerFeature;
import org.nuxeo.ecm.core.test.CoreSearchFeature;
import org.nuxeo.ecm.core.test.DefaultRepositoryInit;
import org.nuxeo.ecm.core.test.annotations.Granularity;
import org.nuxeo.ecm.core.test.annotations.RepositoryConfig;
import org.nuxeo.runtime.test.runner.Deploy;
import org.nuxeo.runtime.test.runner.Features;
import org.nuxeo.runtime.test.runner.RunnerFeature;

@Features({EmbeddedAutomationServerFeature.class, CoreSearchFeature.class})
@RepositoryConfig(init = DefaultRepositoryInit.class, cleanup = Granularity.METHOD)
@Deploy("org.nuxeo.ecm.platform.types")
@Deploy("org.nuxeo.ecm.platform.webapp.types")
//@Deploy("org.nuxeo.ecm.core.management")
@Deploy("org.nuxeo.ecm.default.config")
@Deploy("org.nuxeo.ecm.platform.search.core")
@Deploy("org.nuxeo.ecm.platform.tag")
@Deploy("org.nuxeo.retention.core:OSGI-INF/retention-core-types.xml")
@Deploy("org.nuxeo.retention.core:OSGI-INF/retention-adapters.xml")
@Deploy("org.nuxeo.retention.core:OSGI-INF/retention-vocabularies.xml")
@Deploy("org.nuxeo.retention.core:OSGI-INF/retention-content-template.xml")
@Deploy("org.nuxeo.retention.core:OSGI-INF/retention-service-framework.xml")
@Deploy("org.nuxeo.retention.core:OSGI-INF/retention-listeners.xml")
@Deploy("org.nuxeo.retention.core:OSGI-INF/retention-operations.xml")
@Deploy("org.nuxeo.retention.core:OSGI-INF/retention-actions.xml")
public class RetentionFeature implements RunnerFeature {
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,46 +22,28 @@
import static org.junit.Assert.assertTrue;

import java.time.Duration;
import java.util.Arrays;
import java.util.List;

import jakarta.inject.Inject;

import org.junit.Before;
import org.junit.runner.RunWith;
import org.nuxeo.ecm.automation.test.EmbeddedAutomationServerFeature;
import org.nuxeo.ecm.core.api.CoreSession;
import org.nuxeo.ecm.core.api.DocumentModel;
import org.nuxeo.ecm.core.bulk.BulkService;
import org.nuxeo.ecm.core.security.RetentionExpiredFinderListener;
import org.nuxeo.ecm.core.test.CoreFeature;
import org.nuxeo.ecm.core.test.DefaultRepositoryInit;
import org.nuxeo.ecm.core.test.annotations.Granularity;
import org.nuxeo.ecm.core.test.annotations.RepositoryConfig;
import org.nuxeo.retention.adapters.RetentionRule;
import org.nuxeo.retention.adapters.RetentionRule.StartingPointPolicy;
import org.nuxeo.retention.service.RetentionManager;
import org.nuxeo.runtime.test.runner.Deploy;
import org.nuxeo.runtime.test.runner.Features;
import org.nuxeo.runtime.test.runner.FeaturesRunner;

/**
* @since 11.1
*/
@RunWith(FeaturesRunner.class)
@Features(EmbeddedAutomationServerFeature.class)
@RepositoryConfig(init = DefaultRepositoryInit.class, cleanup = Granularity.METHOD)
@Deploy("org.nuxeo.ecm.platform.types")
@Deploy("org.nuxeo.ecm.core.management")
@Deploy("org.nuxeo.ecm.default.config")
@Deploy("org.nuxeo.retention.core:OSGI-INF/retention-core-types.xml")
@Deploy("org.nuxeo.retention.core:OSGI-INF/retention-adapters.xml")
@Deploy("org.nuxeo.retention.core:OSGI-INF/retention-vocabularies.xml")
@Deploy("org.nuxeo.retention.core:OSGI-INF/retention-content-template.xml")
@Deploy("org.nuxeo.retention.core:OSGI-INF/retention-service-framework.xml")
@Deploy("org.nuxeo.retention.core:OSGI-INF/retention-listeners.xml")
@Deploy("org.nuxeo.retention.core:OSGI-INF/retention-operations.xml")
@Deploy("org.nuxeo.retention.core:OSGI-INF/retention-actions.xml")
@Features(RetentionFeature.class)
public abstract class RetentionTestCase {

@Inject
Expand Down Expand Up @@ -143,8 +125,8 @@ protected RetentionRule createRuleWithActions(RetentionRule.ApplicationPolicy po
} else {
rule.makeEnforcedRecord();
}
session.createDocument(doc);
return session.saveDocument(rule.getDocument()).getAdapter(RetentionRule.class);
doc = session.createDocument(doc);
return session.saveDocument(doc).getAdapter(RetentionRule.class);
}

protected RetentionRule createImmediateRuleMillis(RetentionRule.ApplicationPolicy policy, long durationMillis,
Expand All @@ -154,7 +136,7 @@ protected RetentionRule createImmediateRuleMillis(RetentionRule.ApplicationPolic

protected RetentionRule createImmediateRuleMillis(RetentionRule.ApplicationPolicy policy, long durationMillis,
List<String> beginActions, List<String> endActions, boolean flexible) {
return createRuleWithActions(policy, RetentionRule.StartingPointPolicy.IMMEDIATE, Arrays.asList("File"), null,
return createRuleWithActions(policy, RetentionRule.StartingPointPolicy.IMMEDIATE, List.of("File"), null,
null, null, null, 0L, 0L, 0L, durationMillis, beginActions, endActions, flexible);
}

Expand Down
Loading

0 comments on commit 1724a54

Please sign in to comment.