use of com.enonic.xp.context.Context in project xp by enonic.
the class ProjectAccessSiteProcessorTest method testProcessUpdateWithNoChanges.
@Test
public void testProcessUpdateWithNoChanges() {
final Context context = ContextBuilder.from(ContextAccessor.current()).authInfo(AuthenticationInfo.create().user(TEST_USER).principals(RoleKeys.ADMIN).build()).build();
context.runWith(() -> {
final ProcessUpdateParams params = createProcessUpdateParams("white", "white");
final ProcessUpdateResult result = this.projectAccessSiteProcessor.processUpdate(params);
assertNull(result);
});
}
use of com.enonic.xp.context.Context in project xp by enonic.
the class ProjectAccessSiteProcessorTest method testProcessUpdateWithNoRights.
@Test
public void testProcessUpdateWithNoRights() throws ProjectAccessRequiredException {
final Context context = ContextBuilder.from(ContextAccessor.current()).authInfo(AuthenticationInfo.create().user(TEST_USER).build()).build();
context.runWith(() -> {
final ProcessUpdateParams params = createProcessUpdateParams("white", "blue");
assertThrows(ProjectAccessRequiredException.class, () -> this.projectAccessSiteProcessor.processUpdate(params));
});
}
use of com.enonic.xp.context.Context in project xp by enonic.
the class DumpServiceImplTest method createRootNode.
private void createRootNode(final RepositoryId repositoryId, final AccessControlList permissions, final ChildOrder childOrder) {
final Context rootNodeContext = ContextBuilder.from(ContextAccessor.current()).repositoryId(repositoryId).branch(RepositoryConstants.MASTER_BRANCH).build();
final InternalContext rootNodeInternalContext = InternalContext.create(rootNodeContext).build();
this.storageService.store(Node.createRoot().permissions(permissions != null ? permissions : RepositoryConstants.DEFAULT_REPO_PERMISSIONS).inheritPermissions(false).childOrder(childOrder != null ? childOrder : RepositoryConstants.DEFAULT_CHILD_ORDER).build(), rootNodeInternalContext);
rootNodeContext.runWith(() -> nodeService.refresh(RefreshMode.ALL));
}
use of com.enonic.xp.context.Context in project xp by enonic.
the class DumpServiceImplTest method number_of_versions_in_other_repo.
@Test
public void number_of_versions_in_other_repo() {
final Repository myRepo = NodeHelper.runAsAdmin(() -> doCreateRepository(RepositoryId.from("myrepo"), AccessControlList.create().add(AccessControlEntry.create().principal(ctxDefault().getAuthInfo().getUser().getKey()).allowAll().build()).build(), null));
final Context myRepoContext = ContextBuilder.from(ContextAccessor.current()).repositoryId(myRepo.getId()).branch(RepositoryConstants.MASTER_BRANCH).build();
final Node myNode = myRepoContext.callWith(() -> createNode(NodePath.ROOT, "myNode"));
myRepoContext.runWith(() -> updateNode(myNode));
myRepoContext.runWith(() -> updateNode(myNode));
myRepoContext.runWith(() -> updateNode(myNode));
final SystemLoadResult dumpResult = NodeHelper.runAsAdmin(() -> dumpDeleteAndLoad(true, SystemDumpParams.create().dumpName("myTestDump").build()));
final RepoLoadResult repoLoadResult = getRepoLoadResult(dumpResult, myRepo.getId());
final VersionsLoadResult versionsLoadResult = repoLoadResult.getVersionsLoadResult();
assertNotNull(versionsLoadResult);
// One for root, 4 for myNode
assertEquals(5, versionsLoadResult.getSuccessful());
}
use of com.enonic.xp.context.Context in project xp by enonic.
the class SegmentVacuumCommand method isRepositoryToKeep.
private boolean isRepositoryToKeep(final RepositoryId repositoryId) {
return repositoryPresenceMap.computeIfAbsent(repositoryId, key -> {
if (LOG.isDebugEnabled()) {
LOG.debug("Repository [" + repositoryId + "] not found in the list of current repository");
}
// If repository is not present, find if there is an old version more recent than the threshold
final Context systemContext = ContextBuilder.from(ContextAccessor.current()).repositoryId(SystemConstants.SYSTEM_REPO_ID).branch(SystemConstants.BRANCH_SYSTEM).build();
final Instant since = Instant.now().minusMillis(params.getAgeThreshold());
final NodeVersionQuery findRecentVersionsQuery = NodeVersionQuery.create().nodeId(NodeId.from(repositoryId.toString())).addQueryFilter(RangeFilter.create().fieldName(VersionIndexPath.TIMESTAMP.getPath()).from(ValueFactory.newDateTime(since)).build()).size(0).addOrderBy(FieldOrderExpr.create(VersionIndexPath.TIMESTAMP, OrderExpr.Direction.DESC)).build();
final NodeVersionQueryResult result = systemContext.callWith(() -> nodeService.findVersions(findRecentVersionsQuery));
if (result.getTotalHits() > 0 && LOG.isDebugEnabled()) {
LOG.debug("Recent versions of the repository entry found");
}
return result.getTotalHits() > 0;
});
}
Aggregations