Search in sources :

Example 51 with Context

use of com.enonic.xp.context.Context in project xp by enonic.

the class ProjectAccessSiteProcessorTest method testProcessUpdateByContentAdmin.

@Test
public void testProcessUpdateByContentAdmin() {
    final Context context = ContextBuilder.from(ContextAccessor.current()).authInfo(AuthenticationInfo.create().user(TEST_USER).principals(RoleKeys.CONTENT_MANAGER_ADMIN).build()).build();
    context.runWith(() -> {
        final ProcessUpdateParams params = createProcessUpdateParams("white", "blue");
        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 52 with Context

use of com.enonic.xp.context.Context in project xp by enonic.

the class ProjectAccessSiteProcessorTest method testProcessUpdateByAdmin.

@Test
public void testProcessUpdateByAdmin() {
    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", "blue");
        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 53 with Context

use of com.enonic.xp.context.Context in project xp by enonic.

the class GetBranchDataCommand method doExecute.

private SearchResult doExecute() {
    final CompareExpr compareExpr = CompareExpr.create(FieldExpr.from(BranchIndexPath.BRANCH_NAME.getPath()), CompareExpr.Operator.EQ, ValueExpr.string(branch.getValue()));
    final Context reindexContext = ContextBuilder.from(ContextAccessor.current()).repositoryId(this.repositoryId).branch(branch).build();
    return this.nodeSearchService.query(NodeBranchQuery.create().query(QueryExpr.from(compareExpr)).size(NodeSearchService.GET_ALL_SIZE_FLAG).build(), SingleRepoStorageSource.create(reindexContext.getRepositoryId(), SingleRepoStorageSource.Type.BRANCH));
}
Also used : Context(com.enonic.xp.context.Context) CompareExpr(com.enonic.xp.query.expr.CompareExpr)

Example 54 with Context

use of com.enonic.xp.context.Context in project xp by enonic.

the class DumpServiceImplTest method root_node_gets_correct_properties.

@Test
public void root_node_gets_correct_properties() throws Exception {
    final AccessControlList newRepoACL = AccessControlList.create().add(AccessControlEntry.create().principal(RoleKeys.EVERYONE).allowAll().build()).build();
    final Repository newRepo = NodeHelper.runAsAdmin(() -> doCreateRepository(RepositoryId.from("my-new-repo"), newRepoACL, ChildOrder.manualOrder()));
    final Context newContext = ContextBuilder.from(ContextAccessor.current()).repositoryId(newRepo.getId()).branch(RepositoryConstants.MASTER_BRANCH).build();
    newContext.runWith(() -> createNode(NodePath.ROOT, "myNode"));
    NodeHelper.runAsAdmin(() -> dumpDeleteAndLoad(true));
    final Node loadedRootNode = newContext.callWith(() -> this.nodeService.getRoot());
    assertEquals(newRepoACL, loadedRootNode.getPermissions());
}
Also used : AccessControlList(com.enonic.xp.security.acl.AccessControlList) BundleContext(org.osgi.framework.BundleContext) Context(com.enonic.xp.context.Context) InternalContext(com.enonic.xp.repo.impl.InternalContext) Repository(com.enonic.xp.repository.Repository) Node(com.enonic.xp.node.Node) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Example 55 with Context

use of com.enonic.xp.context.Context in project xp by enonic.

the class NodeServiceImplTest method createRootNode.

@Test
public void createRootNode() {
    final User user = User.create().key(PrincipalKey.ofUser(IdProviderKey.system(), "user1")).displayName("User 1").modifiedTime(Instant.now()).email("user1@enonic.com").login("user1").build();
    this.nodeService.createRootNode(CreateRootNodeParams.create().childOrder(ChildOrder.from("_name ASC")).permissions(AccessControlList.of(AccessControlEntry.create().allowAll().principal(user.getKey()).build())).build());
    printContentRepoIndex();
    final Context context = ContextBuilder.create().authInfo(AuthenticationInfo.create().user(user).principals(RoleKeys.CONTENT_MANAGER_ADMIN).build()).branch(WS_DEFAULT).repositoryId(TEST_REPO_ID).build();
    context.runWith(() -> assertNotNull(this.nodeService.getByPath(NodePath.ROOT)));
    context.runWith(() -> assertNotNull(this.nodeService.getRoot()));
}
Also used : Context(com.enonic.xp.context.Context) User(com.enonic.xp.security.User) Test(org.junit.jupiter.api.Test)

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