Search in sources :

Example 16 with ObjectReference

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

the class WikiObjectComponentManagerEventListenerProxyTest method testUnregisterObjectComponents.

@Test
public void testUnregisterObjectComponents() throws Exception {
    ObjectReference testReference = mock(ObjectReference.class);
    this.mocker.getComponentUnderTest().unregisterObjectComponents(testReference);
    verify(this.wikiComponentManagerEventListenerHelper, times(1)).unregisterComponents(testReference);
}
Also used : BaseObjectReference(com.xpn.xwiki.objects.BaseObjectReference) ObjectReference(org.xwiki.model.reference.ObjectReference) Test(org.junit.Test)

Example 17 with ObjectReference

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

the class LESSObjectPropertyResourceReferenceTest method getContent.

@Test
public void getContent() throws Exception {
    ObjectPropertyReference objectPropertyReference = new ObjectPropertyReference("property", new ObjectReference("class", new DocumentReference("wiki", "Space", "Document")));
    LESSObjectPropertyResourceReference lessObjectPropertyResourceReference = new LESSObjectPropertyResourceReference(objectPropertyReference, entityReferenceSerializer, bridge);
    // Mock
    when(bridge.getProperty(eq(objectPropertyReference))).thenReturn("content");
    // Test
    assertEquals("content", lessObjectPropertyResourceReference.getContent("skin"));
}
Also used : ObjectPropertyReference(org.xwiki.model.reference.ObjectPropertyReference) ObjectReference(org.xwiki.model.reference.ObjectReference) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 18 with ObjectReference

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

the class ModelFactory method toDocument.

public boolean toDocument(Document doc, org.xwiki.rest.model.jaxb.Page restPage) throws XWikiException {
    boolean modified = false;
    if (restPage.getContent() != null) {
        doc.setContent(restPage.getContent());
        modified = true;
    }
    if (restPage.getTitle() != null) {
        doc.setTitle(restPage.getTitle());
        modified = true;
    }
    if (restPage.getParent() != null) {
        doc.setParent(restPage.getParent());
        modified = true;
    }
    if (restPage.getSyntax() != null) {
        doc.setSyntaxId(restPage.getSyntax());
        modified = true;
    }
    doc.setHidden(restPage.isHidden());
    // Set objects
    if (restPage.getObjects() != null) {
        Set<ObjectReference> newReferences = new HashSet<>();
        // Add/update objects
        for (ObjectSummary restObjectSummary : restPage.getObjects().getObjectSummaries()) {
            if (restObjectSummary != null) {
                org.xwiki.rest.model.jaxb.Object restObject = (org.xwiki.rest.model.jaxb.Object) restObjectSummary;
                com.xpn.xwiki.api.Object xwikiObject = doc.getObject(restObject.getClassName(), restObject.getNumber());
                if (xwikiObject == null) {
                    xwikiObject = doc.newObject(restObject.getClassName());
                }
                toObject(xwikiObject, restObject);
                modified = true;
                newReferences.add(xwikiObject.getReference());
            }
        }
        // Remove objects
        List<com.xpn.xwiki.api.Object> toRemove = new ArrayList<>();
        for (Vector<com.xpn.xwiki.api.Object> objects : doc.getxWikiObjects().values()) {
            for (com.xpn.xwiki.api.Object object : objects) {
                if (!newReferences.contains(object.getReference())) {
                    toRemove.add(object);
                }
            }
        }
        for (com.xpn.xwiki.api.Object obj : toRemove) {
            doc.removeObject(obj);
            modified = true;
        }
    }
    return modified;
}
Also used : ArrayList(java.util.ArrayList) ObjectReference(org.xwiki.model.reference.ObjectReference) Object(org.xwiki.rest.model.jaxb.Object) BaseObject(com.xpn.xwiki.objects.BaseObject) Object(org.xwiki.rest.model.jaxb.Object) ObjectSummary(org.xwiki.rest.model.jaxb.ObjectSummary) HashSet(java.util.HashSet)

Aggregations

ObjectReference (org.xwiki.model.reference.ObjectReference)18 Test (org.junit.Test)8 DocumentReference (org.xwiki.model.reference.DocumentReference)8 BaseObject (com.xpn.xwiki.objects.BaseObject)6 BaseObjectReference (com.xpn.xwiki.objects.BaseObjectReference)5 ObjectPropertyReference (org.xwiki.model.reference.ObjectPropertyReference)5 Event (org.xwiki.eventstream.Event)4 ArrayList (java.util.ArrayList)2 DefaultEvent (org.xwiki.eventstream.internal.DefaultEvent)2 LocalDocumentReference (org.xwiki.model.reference.LocalDocumentReference)2 WikiReference (org.xwiki.model.reference.WikiReference)2 Property (org.xwiki.rest.model.jaxb.Property)2 ObjectPropertyResource (org.xwiki.rest.resources.objects.ObjectPropertyResource)2 XWikiContext (com.xpn.xwiki.XWikiContext)1 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)1 HashSet (java.util.HashSet)1 Mock (org.jmock.Mock)1 Invocation (org.jmock.core.Invocation)1 CustomStub (org.jmock.core.stub.CustomStub)1 EntityUnifiedDiff (org.xwiki.extension.xar.job.diff.EntityUnifiedDiff)1