Search in sources :

Example 41 with EntityReference

use of org.xwiki.model.reference.EntityReference in project xwiki-platform by xwiki.

the class DocumentsDeletingListenerTest method testCancel.

@Test
public void testCancel() throws Exception {
    Request request = mock(Request.class);
    Job job = mock(Job.class);
    JobStatus status = mock(JobStatus.class);
    when(job.getRequest()).thenReturn(request);
    when(request.isInteractive()).thenReturn(true);
    when(job.getStatus()).thenReturn(status);
    Map<EntityReference, EntitySelection> concernedEntities = new HashMap<>();
    DocumentReference doc1 = new DocumentReference("a", "b", "c1");
    concernedEntities.put(doc1, new EntitySelection(doc1));
    XarInstalledExtension ext1 = mock(XarInstalledExtension.class);
    when(ext1.getId()).thenReturn(new ExtensionId("ext1"));
    when(repository.getXarInstalledExtensions(doc1)).thenReturn(Arrays.asList(ext1));
    InterruptedException e = new InterruptedException();
    doThrow(e).when(status).ask(any(), anyLong(), any());
    // Test
    DocumentsDeletingEvent event = mock(DocumentsDeletingEvent.class);
    mocker.getComponentUnderTest().onEvent(event, job, concernedEntities);
    // Check
    verify(status, times(1)).ask(any(), eq(5L), eq(TimeUnit.MINUTES));
    verify(event).cancel(eq("Question has been interrupted."));
    verify(mocker.getMockedLogger()).warn("Confirm question has been interrupted.");
}
Also used : JobStatus(org.xwiki.job.event.status.JobStatus) HashMap(java.util.HashMap) XarInstalledExtension(org.xwiki.extension.xar.internal.repository.XarInstalledExtension) EntitySelection(org.xwiki.refactoring.job.question.EntitySelection) Request(org.xwiki.job.Request) EntityReference(org.xwiki.model.reference.EntityReference) ExtensionId(org.xwiki.extension.ExtensionId) Job(org.xwiki.job.Job) DocumentReference(org.xwiki.model.reference.DocumentReference) DocumentsDeletingEvent(org.xwiki.bridge.event.DocumentsDeletingEvent) Test(org.junit.Test)

Example 42 with EntityReference

use of org.xwiki.model.reference.EntityReference in project xwiki-platform by xwiki.

the class DefaultReferenceEntityReferenceResolverTest method resolveObjectPropertyReferenceWhenMissingParents.

/**
 * Tests that a relative object property is resolved correctly and completed with the default object parent.
 */
@Test
public void resolveObjectPropertyReferenceWhenMissingParents() {
    EntityReference reference = resolver.resolve(new EntityReference("property", EntityType.OBJECT_PROPERTY), EntityType.OBJECT_PROPERTY);
    assertEquals(EntityType.OBJECT_PROPERTY, reference.getType());
    assertEquals("property", reference.getName());
    assertEquals(EntityType.OBJECT, reference.getParent().getType());
    assertEquals(DEFAULT_OBJECT, reference.getParent().getName());
    assertEquals(EntityType.DOCUMENT, reference.getParent().getParent().getType());
    assertEquals(DEFAULT_PAGE, reference.getParent().getParent().getName());
    assertEquals(EntityType.SPACE, reference.getParent().getParent().getParent().getType());
    assertEquals(DEFAULT_SPACE, reference.getParent().getParent().getParent().getName());
    assertEquals(EntityType.WIKI, reference.getParent().getParent().getParent().getParent().getType());
    assertEquals(DEFAULT_WIKI, reference.getParent().getParent().getParent().getParent().getName());
}
Also used : EntityReference(org.xwiki.model.reference.EntityReference) Test(org.junit.Test)

Example 43 with EntityReference

use of org.xwiki.model.reference.EntityReference in project xwiki-platform by xwiki.

the class DefaultReferenceEntityReferenceResolverTest method resolveSpaceReferenceWhenTypeIsDocument.

@Test
public void resolveSpaceReferenceWhenTypeIsDocument() {
    EntityReference reference = this.resolver.resolve(new EntityReference("page", EntityType.DOCUMENT), EntityType.SPACE);
    assertEquals(EntityType.SPACE, reference.getType());
    assertEquals(DEFAULT_SPACE, reference.getName());
    assertEquals(EntityType.WIKI, reference.getParent().getType());
    assertEquals(DEFAULT_WIKI, reference.getParent().getName());
}
Also used : EntityReference(org.xwiki.model.reference.EntityReference) Test(org.junit.Test)

Example 44 with EntityReference

use of org.xwiki.model.reference.EntityReference in project xwiki-platform by xwiki.

the class DefaultReferenceEntityReferenceResolverTest method resolveDocumentReferenceWhenMissingParents.

@Test
public void resolveDocumentReferenceWhenMissingParents() {
    EntityReference partialReference = new EntityReference("page", EntityType.DOCUMENT);
    EntityReference reference = this.resolver.resolve(partialReference, EntityType.DOCUMENT);
    assertNotSame(partialReference, reference);
    assertEquals(DEFAULT_SPACE, reference.getParent().getName());
    assertEquals(EntityType.SPACE, reference.getParent().getType());
    assertEquals(DEFAULT_WIKI, reference.getParent().getParent().getName());
    assertEquals(EntityType.WIKI, reference.getParent().getParent().getType());
}
Also used : EntityReference(org.xwiki.model.reference.EntityReference) Test(org.junit.Test)

Example 45 with EntityReference

use of org.xwiki.model.reference.EntityReference in project xwiki-platform by xwiki.

the class DefaultReferenceEntityReferenceResolverTest method resolveAttachmentReferenceWhenMissingParents.

@Test
public void resolveAttachmentReferenceWhenMissingParents() {
    EntityReference reference = this.resolver.resolve(new EntityReference("filename", EntityType.ATTACHMENT), EntityType.ATTACHMENT);
    assertEquals(DEFAULT_PAGE, reference.getParent().getName());
    assertEquals(EntityType.DOCUMENT, reference.getParent().getType());
    assertEquals(DEFAULT_SPACE, reference.getParent().getParent().getName());
    assertEquals(EntityType.SPACE, reference.getParent().getParent().getType());
    assertEquals(DEFAULT_WIKI, reference.getParent().getParent().getParent().getName());
    assertEquals(EntityType.WIKI, reference.getParent().getParent().getParent().getType());
}
Also used : EntityReference(org.xwiki.model.reference.EntityReference) Test(org.junit.Test)

Aggregations

EntityReference (org.xwiki.model.reference.EntityReference)338 Test (org.junit.Test)157 DocumentReference (org.xwiki.model.reference.DocumentReference)107 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)39 BaseObject (com.xpn.xwiki.objects.BaseObject)38 ArrayList (java.util.ArrayList)27 XWikiContext (com.xpn.xwiki.XWikiContext)24 WikiReference (org.xwiki.model.reference.WikiReference)24 SpaceReference (org.xwiki.model.reference.SpaceReference)23 LocalDocumentReference (org.xwiki.model.reference.LocalDocumentReference)18 XWikiException (com.xpn.xwiki.XWikiException)17 EntityType (org.xwiki.model.EntityType)11 BaseClass (com.xpn.xwiki.objects.classes.BaseClass)10 EntityReferenceProvider (org.xwiki.model.reference.EntityReferenceProvider)9 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)8 XDOM (org.xwiki.rendering.block.XDOM)8 URL (java.net.URL)7 AttachmentReference (org.xwiki.model.reference.AttachmentReference)7 HashMap (java.util.HashMap)6 Before (org.junit.Before)6