use of org.xwiki.model.reference.WikiReference in project xwiki-platform by xwiki.
the class ContextComponentManagerTest method testRegisterComponentInUserComponentManager.
@Test
public void testRegisterComponentInUserComponentManager() throws Exception {
final States state = getMockery().states("test");
getMockery().checking(new Expectations() {
{
allowing(mockDocumentAccessBridge).getCurrentUserReference();
when(state.isNot("otheruser"));
will(returnValue(new DocumentReference("wiki", "XWiki", "user1")));
allowing(mockWikiDescriptorManager).getCurrentWikiId();
will(returnValue("wiki"));
allowing(mockCurrentSpaceReferenceProvider).get();
will(returnValue(new SpaceReference("space", new WikiReference("wiki"))));
allowing(mockCurrentDocumentReferenceProvider).get();
will(returnValue(new DocumentReference("wiki", "space", "document")));
}
});
ComponentManager contextCM = getComponentManager().getInstance(ComponentManager.class, "context");
try {
contextCM.getInstance(Role.class);
Assert.fail("Should have raised an exception");
} catch (ComponentLookupException expected) {
// No need to assert the message, we just want to ensure an exception is raised.
}
// Register component for the current user
ComponentManager userCM = getComponentManager().getInstance(ComponentManager.class, "user");
DefaultComponentDescriptor<Role> cd = new DefaultComponentDescriptor<Role>();
cd.setRoleType(Role.class);
cd.setImplementation(RoleImpl.class);
userCM.registerComponent(cd);
// Verify we can lookup the component from the Context CM
Assert.assertNotNull(contextCM.getInstance(Role.class));
// Now verify that we cannot look it up anymore if there's another user in the context
state.become("otheruser");
getMockery().checking(new Expectations() {
{
allowing(mockDocumentAccessBridge).getCurrentUserReference();
will(returnValue(new DocumentReference("wiki", "XWiki", "user2")));
allowing(mockWikiDescriptorManager).getCurrentWikiId();
will(returnValue("wiki"));
allowing(mockCurrentSpaceReferenceProvider).get();
will(returnValue(new SpaceReference("space", new WikiReference("wiki"))));
allowing(mockCurrentDocumentReferenceProvider).get();
will(returnValue(new DocumentReference("wiki", "space", "document")));
}
});
try {
contextCM.getInstance(Role.class);
Assert.fail("Should have raised an exception");
} catch (ComponentLookupException expected) {
// No need to assert the message, we just want to ensure an exception is raised.
}
}
use of org.xwiki.model.reference.WikiReference in project xwiki-platform by xwiki.
the class XarInstalledExtensionRepository method pagesUpdated.
private void pagesUpdated(XarInstalledExtension installedExtension, String namespace, boolean add) throws UnsupportedNamespaceException {
if (installedExtension != null) {
for (XarEntry xarEntry : installedExtension.getXarPackage().getEntries()) {
if (namespace != null) {
DocumentReference reference = new DocumentReference(xarEntry, new WikiReference(XarHandlerUtils.getWikiFromNamespace(namespace)));
synchronized (this.documents) {
Collection<XarInstalledExtension> referenceExtensions = this.documents.get(reference);
if (referenceExtensions != null || add) {
Set<XarInstalledExtension> newSet = referenceExtensions != null ? new LinkedHashSet<>(referenceExtensions) : new LinkedHashSet<>();
if (add) {
newSet.add(installedExtension);
} else {
newSet.remove(installedExtension);
}
this.documents.put(reference, newSet);
}
}
} else {
synchronized (this.rootDocuments) {
Collection<XarInstalledExtension> referenceExtensions = this.rootDocuments.get(xarEntry);
if (referenceExtensions != null || add) {
Set<XarInstalledExtension> newSet = referenceExtensions != null ? new LinkedHashSet<>(referenceExtensions) : new LinkedHashSet<>();
if (add) {
newSet.add(installedExtension);
} else {
newSet.remove(installedExtension);
}
this.rootDocuments.put(xarEntry, newSet);
}
}
}
}
}
}
use of org.xwiki.model.reference.WikiReference in project xwiki-platform by xwiki.
the class ExtensionHistoryScriptServiceTest method replayWithoutAdmin.
@Test
public void replayWithoutAdmin() throws Exception {
InstallRequest installRequest = new InstallRequest();
installRequest.addNamespace("wiki:dev");
ExtensionJobHistoryRecord install = new ExtensionJobHistoryRecord("install", installRequest, null, null, null);
List<ExtensionJobHistoryRecord> records = Arrays.asList(install);
when(this.xcontext.getWikiId()).thenReturn("dev");
when(this.authorization.hasAccess(Right.ADMIN, new WikiReference("dev"))).thenReturn(false);
Job replayJob = mock(Job.class);
ArgumentCaptor<ReplayRequest> requestCaptor = ArgumentCaptor.forClass(ReplayRequest.class);
when(jobExecutor.execute(eq(ReplayJob.JOB_TYPE), requestCaptor.capture())).thenReturn(replayJob);
assertSame(replayJob, this.mocker.getComponentUnderTest().replay(records));
ReplayRequest request = requestCaptor.getValue();
assertTrue(request.getRecords().isEmpty());
}
use of org.xwiki.model.reference.WikiReference in project xwiki-platform by xwiki.
the class ExtensionHistoryScriptServiceTest method replayWithAdminButNoPR.
@Test
public void replayWithAdminButNoPR() throws Exception {
InstallRequest installRequest = new InstallRequest();
installRequest.addNamespace("wiki:drafts");
installRequest.setProperty("user.reference", new DocumentReference("drafts", "Users", "Alice"));
ExtensionJobHistoryRecord install = new ExtensionJobHistoryRecord("install", installRequest, null, null, null);
List<ExtensionJobHistoryRecord> records = Arrays.asList(install);
when(this.xcontext.getWikiId()).thenReturn("dev");
when(this.documentAccessBridge.getCurrentUserReference()).thenReturn(new DocumentReference("dev", "Users", "Bob"));
when(this.authorization.hasAccess(Right.ADMIN, new WikiReference("dev"))).thenReturn(true);
when(this.authorization.hasAccess(Right.PROGRAM)).thenReturn(false);
Job replayJob = mock(Job.class);
ArgumentCaptor<ReplayRequest> requestCaptor = ArgumentCaptor.forClass(ReplayRequest.class);
when(jobExecutor.execute(eq(ReplayJob.JOB_TYPE), requestCaptor.capture())).thenReturn(replayJob);
assertSame(replayJob, this.mocker.getComponentUnderTest().replay(records));
ReplayRequest request = requestCaptor.getValue();
assertEquals(Arrays.asList(install), request.getRecords());
assertEquals(Arrays.asList("wiki:dev"), install.getRequest().getNamespaces());
assertEquals(this.documentAccessBridge.getCurrentUserReference(), install.getRequest().getProperty("user.reference"));
}
use of org.xwiki.model.reference.WikiReference in project xwiki-platform by xwiki.
the class DefaultStringSpaceReferenceResolverTest method resolveWithExplicitSpaceReference.
@Test
public void resolveWithExplicitSpaceReference() {
SpaceReference reference = this.resolver.resolve("", new SpaceReference("space", new WikiReference("wiki")));
Assert.assertEquals("space", reference.getName());
Assert.assertEquals("wiki", reference.getWikiReference().getName());
}
Aggregations