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());
}
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));
}
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"));
}
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));
}
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);
}
Aggregations