Search in sources :

Example 31 with ComponentManager

use of org.xwiki.component.manager.ComponentManager in project xwiki-platform by xwiki.

the class DefaultLinkRefactoringTest method configure.

@Before
public void configure() throws Exception {
    XWiki xwiki = mock(XWiki.class);
    when(this.xcontext.getWiki()).thenReturn(xwiki);
    Provider<XWikiContext> xcontextProvider = this.mocker.getInstance(XWikiContext.TYPE_PROVIDER);
    when(xcontextProvider.get()).thenReturn(this.xcontext);
    this.resourceReferenceResolver = this.mocker.getInstance(DefaultResourceReferenceEntityReferenceResolver.TYPE_RESOURCEREFERENCE);
    this.defaultReferenceDocumentReferenceResolver = this.mocker.getInstance(DocumentReferenceResolver.TYPE_REFERENCE);
    this.compactEntityReferenceSerializer = this.mocker.getInstance(EntityReferenceSerializer.TYPE_STRING, "compact");
    Provider<ComponentManager> contextComponentManagerProvider = this.mocker.registerMockComponent(new DefaultParameterizedType(null, Provider.class, ComponentManager.class), "context");
    when(contextComponentManagerProvider.get()).thenReturn(this.mocker);
}
Also used : ComponentManager(org.xwiki.component.manager.ComponentManager) XWiki(com.xpn.xwiki.XWiki) XWikiContext(com.xpn.xwiki.XWikiContext) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) Provider(javax.inject.Provider) Before(org.junit.Before)

Example 32 with ComponentManager

use of org.xwiki.component.manager.ComponentManager in project xwiki-platform by xwiki.

the class ClassPropertyValuesResourceImplTest method configure.

@Before
public void configure() throws Exception {
    this.resolver = this.mocker.getInstance(DocumentReferenceResolver.TYPE_STRING);
    this.authorization = this.mocker.getInstance(ContextualAuthorizationManager.class);
    when(this.resolver.resolve("Path.To.Class", propertyReference.extractReference(EntityType.WIKI))).thenReturn((DocumentReference) propertyReference.getParent());
    XWikiContext xcontext = mock(XWikiContext.class);
    XWiki xwiki = mock(XWiki.class);
    XWikiDocument classDocument = mock(XWikiDocument.class);
    when(xcontext.getWiki()).thenReturn(xwiki);
    when(xwiki.getDocument(propertyReference, xcontext)).thenReturn(classDocument);
    when(classDocument.getXClass()).thenReturn(this.xclass);
    ExecutionContext executionContext = new ExecutionContext();
    executionContext.setProperty("xwikicontext", xcontext);
    Execution execution = mock(Execution.class);
    ComponentManager componentManager = this.mocker.getInstance(ComponentManager.class, "context");
    when(componentManager.getInstance(Execution.class)).thenReturn(execution);
    when(execution.getContext()).thenReturn(executionContext);
    Provider<XWikiContext> xcontextProvider = this.mocker.getInstance(XWikiContext.TYPE_PROVIDER);
    when(xcontextProvider.get()).thenReturn(xcontext);
    UriInfo uriInfo = mock(UriInfo.class);
    when(uriInfo.getBaseUri()).thenReturn(new URI("/xwiki/rest"));
    this.resource = this.mocker.getComponentUnderTest();
    ReflectionUtils.setFieldValue(resource, "uriInfo", uriInfo);
}
Also used : ContextualAuthorizationManager(org.xwiki.security.authorization.ContextualAuthorizationManager) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) ExecutionContext(org.xwiki.context.ExecutionContext) Execution(org.xwiki.context.Execution) ComponentManager(org.xwiki.component.manager.ComponentManager) XWikiContext(com.xpn.xwiki.XWikiContext) XWiki(com.xpn.xwiki.XWiki) URI(java.net.URI) UriInfo(javax.ws.rs.core.UriInfo) Before(org.junit.Before)

Example 33 with ComponentManager

use of org.xwiki.component.manager.ComponentManager in project xwiki-platform by xwiki.

the class DefaultClassPropertyValuesProviderTest method getValues.

@Test
public void getValues() throws Exception {
    ClassPropertyReference propertyReference = new ClassPropertyReference("category", this.classReference);
    ClassPropertyValuesProvider dbListValuesProvider = mock(ClassPropertyValuesProvider.class);
    ComponentManager contextComponentManager = this.mocker.getInstance(ComponentManager.class, "context");
    PropertyValues values = new PropertyValues();
    when(contextComponentManager.getInstance(ClassPropertyValuesProvider.class, "DBList")).thenReturn(dbListValuesProvider);
    when(dbListValuesProvider.getValues(propertyReference, 13, "one", "two")).thenReturn(values);
    assertSame(values, this.mocker.getComponentUnderTest().getValues(propertyReference, 13, "one", "two"));
}
Also used : ClassPropertyValuesProvider(org.xwiki.rest.resources.classes.ClassPropertyValuesProvider) PropertyValues(org.xwiki.rest.model.jaxb.PropertyValues) ComponentManager(org.xwiki.component.manager.ComponentManager) ClassPropertyReference(org.xwiki.model.reference.ClassPropertyReference) Test(org.junit.Test)

Example 34 with ComponentManager

use of org.xwiki.component.manager.ComponentManager in project xwiki-platform by xwiki.

the class DefaultWikiComponentBridgeTest method getHandledMethods.

@Test
public void getHandledMethods() throws Exception {
    final ComponentManager componentManager = getComponentManager().getInstance(ComponentManager.class);
    final ContentParser contentParser = getComponentManager().getInstance(ContentParser.class);
    final Parser parser = getMockery().mock(Parser.class);
    final XDOM xdom = new XDOM(new ArrayList<Block>());
    final BaseObject methodObject = getMockery().mock(BaseObject.class, "method");
    final Vector<BaseObject> methodObjects = new Vector<BaseObject>();
    methodObjects.add(methodObject);
    getMockery().checking(new Expectations() {

        {
            oneOf(componentDoc).getObjectNumbers(METHOD_CLASS);
            will(returnValue(1));
            oneOf(componentDoc).getObjects(METHOD_CLASS);
            will(returnValue(methodObjects));
            allowing(methodObject).getStringValue(METHOD_NAME_FIELD);
            will(returnValue("test"));
            allowing(methodObject).getStringValue(METHOD_CODE_FIELD);
            will(returnValue("test"));
            oneOf(componentDoc).getSyntax();
            will(returnValue(Syntax.XWIKI_2_1));
            oneOf(contentParser).parse("test", Syntax.XWIKI_2_1, DOC_REFERENCE);
            will(returnValue(xdom));
        }
    });
    Assert.assertEquals(1, bridge.getHandledMethods(DOC_REFERENCE).size());
}
Also used : Expectations(org.jmock.Expectations) XDOM(org.xwiki.rendering.block.XDOM) ComponentManager(org.xwiki.component.manager.ComponentManager) ContentParser(org.xwiki.component.wiki.internal.bridge.ContentParser) Block(org.xwiki.rendering.block.Block) Vector(java.util.Vector) ContentParser(org.xwiki.component.wiki.internal.bridge.ContentParser) Parser(org.xwiki.rendering.parser.Parser) BaseObject(com.xpn.xwiki.objects.BaseObject) Test(org.junit.Test)

Example 35 with ComponentManager

use of org.xwiki.component.manager.ComponentManager 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);
}
Also used : ObjectPropertyReference(org.xwiki.model.reference.ObjectPropertyReference) LESSObjectPropertyResourceReference(org.xwiki.lesscss.internal.resources.LESSObjectPropertyResourceReference) ArrayList(java.util.ArrayList) DocumentUpdatedEvent(org.xwiki.bridge.event.DocumentUpdatedEvent) BaseObject(com.xpn.xwiki.objects.BaseObject) EntityReferenceSerializer(org.xwiki.model.reference.EntityReferenceSerializer) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) BaseObjectReference(com.xpn.xwiki.objects.BaseObjectReference) ComponentManager(org.xwiki.component.manager.ComponentManager) EntityReference(org.xwiki.model.reference.EntityReference) BaseObject(com.xpn.xwiki.objects.BaseObject) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Aggregations

ComponentManager (org.xwiki.component.manager.ComponentManager)76 Test (org.junit.Test)34 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)23 DefaultParameterizedType (org.xwiki.component.util.DefaultParameterizedType)18 DocumentReference (org.xwiki.model.reference.DocumentReference)17 Provider (javax.inject.Provider)14 NamespacedComponentManager (org.xwiki.component.manager.NamespacedComponentManager)12 Before (org.junit.Before)11 DefaultComponentDescriptor (org.xwiki.component.descriptor.DefaultComponentDescriptor)11 XWikiContext (com.xpn.xwiki.XWikiContext)9 Expectations (org.jmock.Expectations)9 WikiReference (org.xwiki.model.reference.WikiReference)9 HashMap (java.util.HashMap)7 Execution (org.xwiki.context.Execution)7 SpaceReference (org.xwiki.model.reference.SpaceReference)7 XWiki (com.xpn.xwiki.XWiki)6 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)6 ArrayList (java.util.ArrayList)6 ExecutionContext (org.xwiki.context.ExecutionContext)6 MimeMessage (javax.mail.internet.MimeMessage)5