Search in sources :

Example 16 with Context

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);
    });
}
Also used : Context(com.enonic.xp.context.Context) ProcessUpdateParams(com.enonic.xp.content.processor.ProcessUpdateParams) ProcessUpdateResult(com.enonic.xp.content.processor.ProcessUpdateResult) Test(org.junit.jupiter.api.Test)

Example 17 with Context

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));
    });
}
Also used : Context(com.enonic.xp.context.Context) ProcessUpdateParams(com.enonic.xp.content.processor.ProcessUpdateParams) Test(org.junit.jupiter.api.Test)

Example 18 with Context

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));
}
Also used : BundleContext(org.osgi.framework.BundleContext) Context(com.enonic.xp.context.Context) InternalContext(com.enonic.xp.repo.impl.InternalContext) InternalContext(com.enonic.xp.repo.impl.InternalContext)

Example 19 with Context

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());
}
Also used : BundleContext(org.osgi.framework.BundleContext) Context(com.enonic.xp.context.Context) InternalContext(com.enonic.xp.repo.impl.InternalContext) Repository(com.enonic.xp.repository.Repository) SystemLoadResult(com.enonic.xp.dump.SystemLoadResult) Node(com.enonic.xp.node.Node) VersionsLoadResult(com.enonic.xp.dump.VersionsLoadResult) RepoLoadResult(com.enonic.xp.dump.RepoLoadResult) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Example 20 with Context

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;
    });
}
Also used : Context(com.enonic.xp.context.Context) NodeVersionQuery(com.enonic.xp.node.NodeVersionQuery) Instant(java.time.Instant) NodeVersionQueryResult(com.enonic.xp.node.NodeVersionQueryResult)

Aggregations

Context (com.enonic.xp.context.Context)101 Test (org.junit.jupiter.api.Test)35 AuthenticationInfo (com.enonic.xp.security.auth.AuthenticationInfo)21 Node (com.enonic.xp.node.Node)16 InternalContext (com.enonic.xp.repo.impl.InternalContext)16 User (com.enonic.xp.security.User)13 Content (com.enonic.xp.content.Content)11 PropertyTree (com.enonic.xp.data.PropertyTree)11 PrincipalKey (com.enonic.xp.security.PrincipalKey)10 Branch (com.enonic.xp.branch.Branch)9 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)9 ContextAccessor (com.enonic.xp.context.ContextAccessor)8 NodePath (com.enonic.xp.node.NodePath)8 ContextBuilder (com.enonic.xp.context.ContextBuilder)7 ContentId (com.enonic.xp.content.ContentId)6 CreateNodeParams (com.enonic.xp.node.CreateNodeParams)6 Repository (com.enonic.xp.repository.Repository)6 LogAuditLogParams (com.enonic.xp.audit.LogAuditLogParams)5 ProcessUpdateParams (com.enonic.xp.content.processor.ProcessUpdateParams)5 NodeComparison (com.enonic.xp.node.NodeComparison)5