use of com.xpn.xwiki.objects.BaseObjectReference in project xwiki-platform by xwiki.
the class ObjectPropertySolrMetadataExtractor method setFieldsInternal.
@Override
public boolean setFieldsInternal(LengthSolrInputDocument solrDocument, EntityReference entityReference) throws Exception {
ObjectPropertyReference objectPropertyReference = new ObjectPropertyReference(entityReference);
BaseObjectReference objectReference = new BaseObjectReference(objectPropertyReference.getParent());
DocumentReference classReference = objectReference.getXClassReference();
DocumentReference documentReference = new DocumentReference(objectReference.getParent());
XWikiDocument originalDocument = getDocument(documentReference);
BaseProperty<ObjectPropertyReference> objectProperty = originalDocument.getXObjectProperty(objectPropertyReference);
if (objectProperty == null) {
return false;
}
// Object
solrDocument.setField(FieldUtils.CLASS, localSerializer.serialize(classReference));
solrDocument.setField(FieldUtils.NUMBER, objectReference.getObjectNumber());
// Property
solrDocument.setField(FieldUtils.PROPERTY_NAME, objectPropertyReference.getName());
setLocaleAndContentFields(documentReference, solrDocument, objectProperty);
return true;
}
use of com.xpn.xwiki.objects.BaseObjectReference in project xwiki-platform by xwiki.
the class WikiObjectComponentManagerEventListenerProxyTest method testWithWikiObjectComponentBuilder.
private void testWithWikiObjectComponentBuilder(WikiObjectComponentBuilder buider, BaseObjectReference objectReference, XWikiDocument source) throws Exception {
BaseObject baseObject = mock(BaseObject.class);
when(source.getXObject(any(ObjectReference.class))).thenReturn(baseObject);
this.mocker.getComponentUnderTest().registerObjectComponents(objectReference, baseObject, buider);
}
use of com.xpn.xwiki.objects.BaseObjectReference in project xwiki-platform by xwiki.
the class WikiObjectComponentManagerEventListenerProxyTest method testRegisterObjectComponentsWithBaseObjectComponentBuilder.
@Test
public void testRegisterObjectComponentsWithBaseObjectComponentBuilder() throws Exception {
BaseObjectReference objectReference = mock(BaseObjectReference.class);
XWikiDocument source = mock(XWikiDocument.class);
WikiBaseObjectComponentBuilder componentBuilder = mock(WikiBaseObjectComponentBuilder.class);
this.testWithWikiObjectComponentBuilder(componentBuilder, objectReference, source);
verify(componentBuilder, times(1)).buildComponents(any(BaseObject.class));
}
use of com.xpn.xwiki.objects.BaseObjectReference in project xwiki-platform by xwiki.
the class WikiObjectComponentManagerEventListenerProxyTest method testRegisterObjectComponentsWithStandardComponentBuilder.
@Test
public void testRegisterObjectComponentsWithStandardComponentBuilder() throws Exception {
BaseObjectReference objectReference = mock(BaseObjectReference.class);
XWikiDocument source = mock(XWikiDocument.class);
WikiObjectComponentBuilder componentBuilder = mock(WikiObjectComponentBuilder.class);
this.testWithWikiObjectComponentBuilder(componentBuilder, objectReference, source);
verify(componentBuilder, times(1)).buildComponents(objectReference);
}
use of com.xpn.xwiki.objects.BaseObjectReference in project xwiki-platform by xwiki.
the class SSXListenerTest method onEvent.
@Test
public void onEvent() throws Exception {
// Mocks
when(wikiDescriptorManager.getCurrentWikiId()).thenReturn("wiki");
XWikiDocument doc = mock(XWikiDocument.class);
BaseObject obj1 = mock(BaseObject.class);
BaseObject obj2 = mock(BaseObject.class);
List<BaseObject> objList = new ArrayList<>();
DocumentReference ssxDocRef = new DocumentReference("wiki", "XWiki", "StyleSheetExtension");
when(doc.getXObjects(eq(ssxDocRef))).thenReturn(objList);
objList.add(obj1);
objList.add(null);
objList.add(obj2);
when(obj1.getStringValue("contentType")).thenReturn("CSS");
when(obj2.getStringValue("contentType")).thenReturn("LESS");
when(obj2.getNumber()).thenReturn(2);
DocumentReference documentReference = new DocumentReference("wiki", "Space", "Doc");
when(doc.getDocumentReference()).thenReturn(documentReference);
// Because BaseObjectReference uses components from the Utils class, we need to set up the component manager
ComponentManager rootComponentManager = mock(ComponentManager.class);
Utils.setComponentManager(rootComponentManager);
ComponentManager contextComponentManager = mock(ComponentManager.class);
when(rootComponentManager.getInstance(ComponentManager.class, "context")).thenReturn(contextComponentManager);
// Mock to serialize the object
EntityReferenceSerializer entityReferenceSerializer = mock(EntityReferenceSerializer.class);
when(contextComponentManager.getInstance(EntityReferenceSerializer.TYPE_STRING, "compactwiki")).thenReturn(entityReferenceSerializer);
when(entityReferenceSerializer.serialize(any(EntityReference.class), any(EntityReference.class))).thenReturn("objName");
ObjectPropertyReference objPropertyReference = new ObjectPropertyReference("code", new BaseObjectReference(ssxDocRef, 2, documentReference));
LESSObjectPropertyResourceReference lessObjectPropertyResourceReference = new LESSObjectPropertyResourceReference(objPropertyReference, null, null);
when(lessResourceReferenceFactory.createReferenceForXObjectProperty(eq(objPropertyReference))).thenReturn(lessObjectPropertyResourceReference);
// Test
mocker.getComponentUnderTest().onEvent(new DocumentUpdatedEvent(), doc, new Object());
// Verify
verify(lessResourcesCache, atLeastOnce()).clearFromLESSResource(lessObjectPropertyResourceReference);
verify(colorThemeCache, atLeastOnce()).clearFromLESSResource(lessObjectPropertyResourceReference);
}
Aggregations