Search in sources :

Example 11 with Context

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

the class IndexServiceImplTest method reindex_cms_repo.

@Test
public void reindex_cms_repo() throws Exception {
    final Context cmsRepoContext = ContextBuilder.from(ContextAccessor.current()).repositoryId(TEST_REPO_ID).branch(ContentConstants.BRANCH_DRAFT).build();
    cmsRepoContext.callWith(this::createDefaultRootNode);
    cmsRepoContext.callWith(() -> createNode(CreateNodeParams.create().setNodeId(NodeId.from("su")).name("su").parent(NodePath.ROOT).build()));
    refresh();
    assertEquals(2, cmsRepoContext.callWith(this::findAllNodes).getHits());
    this.indexService.purgeSearchIndex(new PurgeIndexParams(cmsRepoContext.getRepositoryId()));
    assertEquals(0, cmsRepoContext.callWith(this::findAllNodes).getHits());
    this.indexService.reindex(ReindexParams.create().addBranch(cmsRepoContext.getBranch()).repositoryId(cmsRepoContext.getRepositoryId()).initialize(true).build());
    refresh();
    assertEquals(2, cmsRepoContext.callWith(this::findAllNodes).getHits());
}
Also used : Context(com.enonic.xp.context.Context) PurgeIndexParams(com.enonic.xp.index.PurgeIndexParams) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Example 12 with Context

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

the class ScheduleAuditLogSupportImpl method delete.

@Override
public void delete(final ScheduledJobName name, final boolean result) {
    final Context context = scheduleContext();
    executor.execute(() -> doDelete(name, result, context));
}
Also used : Context(com.enonic.xp.context.Context)

Example 13 with Context

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

the class RepositoryServiceImplTest method update_data.

@Test
void update_data() {
    final String repoId = "repo-with-data";
    doCreateRepo(repoId);
    Context mockCurrentContext = ContextBuilder.create().branch("master").repositoryId(repoId).authInfo(REPO_TEST_DEFAULT_USER_AUTHINFO).build();
    PropertyTree data = new PropertyTree();
    data.setString("myProp", "b");
    mockCurrentContext.callWith(() -> repositoryService.updateRepository(UpdateRepositoryParams.create().repositoryId(RepositoryId.from(repoId)).editor(edit -> edit.data = data).build()));
    final Repository persistedRepo = getPersistedRepoWithoutCache(repoId);
    assertEquals("b", persistedRepo.getData().getString("myProp"));
}
Also used : Context(com.enonic.xp.context.Context) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) IdProviderKey(com.enonic.xp.security.IdProviderKey) CreateNodeParams(com.enonic.xp.node.CreateNodeParams) DeleteRepositoryParams(com.enonic.xp.repository.DeleteRepositoryParams) Node(com.enonic.xp.node.Node) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) Branch(com.enonic.xp.branch.Branch) NodeHelper(com.enonic.xp.repo.impl.node.NodeHelper) RepositoryId(com.enonic.xp.repository.RepositoryId) ImmutableList(com.google.common.collect.ImmutableList) CreateBranchParams(com.enonic.xp.repository.CreateBranchParams) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ContextAccessor(com.enonic.xp.context.ContextAccessor) ContextBuilder(com.enonic.xp.context.ContextBuilder) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ByteSource(com.google.common.io.ByteSource) SystemConstants(com.enonic.xp.security.SystemConstants) PropertyTree(com.enonic.xp.data.PropertyTree) BinaryReference(com.enonic.xp.util.BinaryReference) DeleteBranchParams(com.enonic.xp.repository.DeleteBranchParams) User(com.enonic.xp.security.User) BinaryAttachment(com.enonic.xp.node.BinaryAttachment) NodePath(com.enonic.xp.node.NodePath) AuthenticationInfo(com.enonic.xp.security.auth.AuthenticationInfo) AccessControlList(com.enonic.xp.security.acl.AccessControlList) CreateRepositoryParams(com.enonic.xp.repository.CreateRepositoryParams) UpdateRepositoryParams(com.enonic.xp.repository.UpdateRepositoryParams) Test(org.junit.jupiter.api.Test) PrincipalKey(com.enonic.xp.security.PrincipalKey) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) RoleKeys(com.enonic.xp.security.RoleKeys) Context(com.enonic.xp.context.Context) Assertions.assertDoesNotThrow(org.junit.jupiter.api.Assertions.assertDoesNotThrow) AccessControlEntry(com.enonic.xp.security.acl.AccessControlEntry) Repository(com.enonic.xp.repository.Repository) Repository(com.enonic.xp.repository.Repository) PropertyTree(com.enonic.xp.data.PropertyTree) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Example 14 with Context

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

the class ScheduleAuditLogSupportImpl method modify.

@Override
public void modify(ModifyScheduledJobParams params, ScheduledJob job) {
    final Context context = scheduleContext();
    executor.execute(() -> doUpdate(params, job, context));
}
Also used : Context(com.enonic.xp.context.Context)

Example 15 with Context

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

the class IdProviderRequestWrapperTest method isUserInRole.

@Test
void isUserInRole() {
    final User user = User.create().key(PrincipalKey.ofUser(IdProviderKey.createDefault(), "userId")).login("usr").build();
    final AuthenticationInfo authenticationInfo = AuthenticationInfo.create().user(user).principals(RoleKeys.ADMIN).build();
    final Context context = ContextBuilder.create().build();
    final Session session = new SessionMock();
    context.getLocalScope().setSession(session);
    session.setAttribute(authenticationInfo);
    final Boolean isAdmin = context.callWith(() -> new IdProviderRequestWrapper(request).isUserInRole(RoleKeys.ADMIN.getId()));
    assertTrue(isAdmin);
    verifyNoInteractions(request);
}
Also used : Context(com.enonic.xp.context.Context) User(com.enonic.xp.security.User) AuthenticationInfo(com.enonic.xp.security.auth.AuthenticationInfo) Session(com.enonic.xp.session.Session) SessionMock(com.enonic.xp.session.SessionMock) Test(org.junit.jupiter.api.Test)

Aggregations

Context (com.enonic.xp.context.Context)99 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 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 PrincipalKey (com.enonic.xp.security.PrincipalKey)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