Search in sources :

Example 46 with DefaultParameterizedType

use of org.xwiki.component.util.DefaultParameterizedType in project xwiki-platform by xwiki.

the class WikiCreationJobTest method setUp.

@Before
public void setUp() throws Exception {
    observationManager = mocker.getInstance(ObservationManager.class);
    loggerManager = mocker.getInstance(LoggerManager.class);
    store = mocker.getInstance(JobStatusStore.class);
    executionProvider = mock(Provider.class);
    mocker.registerComponent(new DefaultParameterizedType(null, Provider.class, Execution.class), executionProvider);
    when(executionProvider.get()).thenReturn(execution);
    executionContextManagerProvider = mock(Provider.class);
    mocker.registerComponent(new DefaultParameterizedType(null, Provider.class, ExecutionContextManager.class), executionContextManagerProvider);
    executionContextManager = mock(ExecutionContextManager.class);
    when(executionContextManagerProvider.get()).thenReturn(executionContextManager);
    jobContext = mocker.getInstance(JobContext.class);
    progressManager = mocker.getInstance(JobProgressManager.class);
    execution.pushContext(new ExecutionContext());
}
Also used : Execution(org.xwiki.context.Execution) DefaultExecution(org.xwiki.context.internal.DefaultExecution) ExecutionContext(org.xwiki.context.ExecutionContext) ExecutionContextManager(org.xwiki.context.ExecutionContextManager) LoggerManager(org.xwiki.logging.LoggerManager) ObservationManager(org.xwiki.observation.ObservationManager) JobContext(org.xwiki.job.JobContext) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) JobProgressManager(org.xwiki.job.event.status.JobProgressManager) JobStatusStore(org.xwiki.job.JobStatusStore) Provider(javax.inject.Provider) Before(org.junit.Before)

Example 47 with DefaultParameterizedType

use of org.xwiki.component.util.DefaultParameterizedType in project xwiki-platform by xwiki.

the class LiveNotificationEmailSenderTest method setUp.

@Before
public void setUp() throws Exception {
    this.mailSender = this.mocker.registerMockComponent(MailSender.class);
    this.sessionFactory = this.mocker.registerMockComponent(SessionFactory.class);
    this.mailListenerProvider = this.mocker.registerMockComponent(Provider.class, "database");
    this.notificationUserIteratorProvider = mock(Provider.class);
    this.mocker.registerComponent(new DefaultParameterizedType(null, Provider.class, NotificationUserIterator.class), this.notificationUserIteratorProvider);
    this.liveMimeMessageIteratorProvider = mock(Provider.class);
    this.mocker.registerComponent(new DefaultParameterizedType(null, Provider.class, LiveMimeMessageIterator.class), this.liveMimeMessageIteratorProvider);
    this.wikiDescriptorManager = this.mocker.registerMockComponent(WikiDescriptorManager.class);
}
Also used : SessionFactory(org.xwiki.mail.SessionFactory) NotificationUserIterator(org.xwiki.notifications.notifiers.internal.email.NotificationUserIterator) LiveMimeMessageIterator(org.xwiki.notifications.notifiers.internal.email.live.LiveMimeMessageIterator) WikiDescriptorManager(org.xwiki.wiki.descriptor.WikiDescriptorManager) MailSender(org.xwiki.mail.MailSender) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) Provider(javax.inject.Provider) Before(org.junit.Before)

Example 48 with DefaultParameterizedType

use of org.xwiki.component.util.DefaultParameterizedType in project xwiki-platform by xwiki.

the class XWikiDocumentFilterUtils method exportEntity.

/**
 * @param entity the entity to read
 * @param target the target where to write the result
 * @param xarProperties the configuration of the output filter
 * @param documentProperties the configuration of the input filter
 * @throws ComponentLookupException failed to find an event generator for passed entity
 * @throws FilterException when failing to generate export the passed entity
 * @throws IOException when failing to close the stream
 */
public void exportEntity(Object entity, OutputTarget target, XAROutputProperties xarProperties, DocumentInstanceInputProperties documentProperties) throws ComponentLookupException, FilterException, IOException {
    // Input
    documentProperties.setVerbose(false);
    // Output
    xarProperties.setForceDocument(true);
    if (target != null) {
        xarProperties.setTarget(target);
    }
    xarProperties.setVerbose(false);
    BeanOutputFilterStream<XAROutputProperties> xarFilter = ((BeanOutputFilterStreamFactory<XAROutputProperties>) this.xarOutputFilterStreamFactory).createOutputFilterStream(xarProperties);
    XARFilter filter = (XARFilter) xarFilter.getFilter();
    BeanEntityEventGenerator<Object, DocumentInstanceInputProperties> generator = this.componentManager.getInstance(new DefaultParameterizedType(null, EntityEventGenerator.class, getClass(entity)));
    // Spaces and document events
    FilterEventParameters documentParameters = null;
    DocumentReference documentReference = null;
    if (entity instanceof XWikiDocument) {
        documentReference = ((XWikiDocument) entity).getDocumentReference();
        for (SpaceReference spaceReference : documentReference.getSpaceReferences()) {
            filter.beginWikiSpace(spaceReference.getName(), FilterEventParameters.EMPTY);
        }
        documentParameters = new FilterEventParameters();
        documentParameters.put(WikiDocumentFilter.PARAMETER_LOCALE, ((XWikiDocument) entity).getDefaultLocale());
        filter.beginWikiDocument(documentReference.getName(), documentParameters);
    }
    // Document Locale events
    generator.write(entity, xarFilter, documentProperties);
    // Document and spaces events
    if (documentParameters != null) {
        filter.endWikiDocument(documentReference.getName(), documentParameters);
        documentReference = ((XWikiDocument) entity).getDocumentReference();
        for (EntityReference reference = documentReference.getParent(); reference instanceof SpaceReference; reference = reference.getParent()) {
            filter.beginWikiSpace(reference.getName(), FilterEventParameters.EMPTY);
        }
    }
    xarFilter.close();
}
Also used : BeanOutputFilterStreamFactory(org.xwiki.filter.output.BeanOutputFilterStreamFactory) SpaceReference(org.xwiki.model.reference.SpaceReference) XAROutputProperties(org.xwiki.filter.xar.output.XAROutputProperties) DocumentInstanceInputProperties(org.xwiki.filter.instance.input.DocumentInstanceInputProperties) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) FilterEventParameters(org.xwiki.filter.FilterEventParameters) BeanEntityEventGenerator(org.xwiki.filter.instance.input.BeanEntityEventGenerator) EntityEventGenerator(org.xwiki.filter.instance.input.EntityEventGenerator) EntityReference(org.xwiki.model.reference.EntityReference) BaseObject(com.xpn.xwiki.objects.BaseObject) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) XARFilter(org.xwiki.filter.xar.internal.XARFilter) DocumentReference(org.xwiki.model.reference.DocumentReference)

Example 49 with DefaultParameterizedType

use of org.xwiki.component.util.DefaultParameterizedType in project xwiki-platform by xwiki.

the class XWikiDocumentFilterUtils method importEntity.

/**
 * @param entityClass to class used to find the {@link EntityOutputFilterStream} component
 * @param entity the entity to write to or null to create a new entity of the passed class
 * @param source the stream to read
 * @param xarProperties the configuration of the input filter
 * @param documentProperties the configuration of the output filter
 * @return the imported entity, same as {@code entity} if not null
 * @throws FilterException when failing to import
 * @throws IOException when failing to import
 * @throws ComponentLookupException when failing to find a EntityOutputFilterStream corresponding to passed class
 */
public <T> T importEntity(Class<T> entityClass, T entity, InputSource source, XARInputProperties xarProperties, DocumentInstanceOutputProperties documentProperties) throws FilterException, IOException, ComponentLookupException {
    // Output
    EntityOutputFilterStream<T> filterStream = this.componentManager.getInstance(new DefaultParameterizedType(null, EntityOutputFilterStream.class, entityClass));
    filterStream.setProperties(documentProperties);
    filterStream.setEntity(entity);
    if (filterStream instanceof XWikiDocumentOutputFilterStream) {
        ((XWikiDocumentOutputFilterStream) filterStream).disableRenderingEvents();
    }
    // Input
    xarProperties.setSourceType(getSourceType(entityClass));
    xarProperties.setSource(source);
    BeanInputFilterStream<XARInputProperties> xarReader = ((BeanInputFilterStreamFactory<XARInputProperties>) this.xarInputFilterStreamFactory).createInputFilterStream(xarProperties);
    // Convert
    xarReader.read(filterStream.getFilter());
    xarReader.close();
    return filterStream.getEntity();
}
Also used : EntityOutputFilterStream(com.xpn.xwiki.internal.filter.output.EntityOutputFilterStream) XWikiDocumentOutputFilterStream(com.xpn.xwiki.internal.filter.output.XWikiDocumentOutputFilterStream) BeanInputFilterStreamFactory(org.xwiki.filter.input.BeanInputFilterStreamFactory) XARInputProperties(org.xwiki.filter.xar.input.XARInputProperties) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType)

Example 50 with DefaultParameterizedType

use of org.xwiki.component.util.DefaultParameterizedType in project xwiki-platform by xwiki.

the class AbstractBridgedXWikiComponentTestCase method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    // Statically store the component manager in {@link Utils} to be able to access it without
    // the context.
    Utils.setComponentManager(getComponentManager());
    this.context = new XWikiContext();
    this.context.setWikiId("xwiki");
    this.context.setMainXWiki("xwiki");
    // Make sure response.encodeURL() calls don't fail
    Mock xwikiResponse = mock(XWikiResponse.class);
    xwikiResponse.stubs().method("setLocale");
    xwikiResponse.stubs().method("encodeURL").will(new CustomStub("Implements XWikiResponse.encodeURL") {

        @Override
        public Object invoke(Invocation invocation) throws Throwable {
            return invocation.parameterValues.get(0);
        }
    });
    this.context.setResponse((XWikiResponse) xwikiResponse.proxy());
    // We need to initialize the Component Manager so that the components can be looked up
    getContext().put(ComponentManager.class.getName(), getComponentManager());
    // Bridge with old XWiki Context, required for old code.
    Execution execution = getComponentManager().getInstance(Execution.class);
    this.context.declareInExecutionContext(execution.getContext());
    XWikiStubContextProvider stubContextProvider = getComponentManager().getInstance(XWikiStubContextProvider.class);
    stubContextProvider.initialize(this.context);
    // Bridge with XWiki Context Provider, required by newer code.
    Mock mockContextProvider = mock(Provider.class);
    mockContextProvider.stubs().method("get").will(returnValue(this.context));
    DefaultComponentDescriptor<Provider<XWikiContext>> contextProviderDescriptor = new DefaultComponentDescriptor<Provider<XWikiContext>>();
    contextProviderDescriptor.setRoleType(new DefaultParameterizedType(null, Provider.class, XWikiContext.class));
    contextProviderDescriptor.setRoleHint("default");
    getComponentManager().registerComponent(contextProviderDescriptor, (Provider<XWikiContext>) mockContextProvider.proxy());
    // Since the oldcore module draws the Servlet Environment in its dependencies we need to ensure it's set up
    // correctly with a Servlet Context.
    ServletEnvironment environment = getComponentManager().getInstance(Environment.class);
    Mock mockServletContext = mock(ServletContext.class);
    environment.setServletContext((ServletContext) mockServletContext.proxy());
    mockServletContext.stubs().method("getResourceAsStream").will(returnValue(null));
    mockServletContext.stubs().method("getResource").will(returnValue(null));
    mockServletContext.stubs().method("getAttribute").with(eq("javax.servlet.context.tempdir")).will(returnValue(new File(System.getProperty("java.io.tmpdir"))));
    File testDirectory = new File("target/test-" + new Date().getTime());
    this.temporaryDirectory = new File(testDirectory, "temporary-dir");
    this.permanentDirectory = new File(testDirectory, "permanent-dir");
    environment.setTemporaryDirectory(this.temporaryDirectory);
    environment.setPermanentDirectory(this.permanentDirectory);
    Mock mockCoreConfiguration = registerMockComponent(CoreConfiguration.class);
    mockCoreConfiguration.stubs().method("getDefaultDocumentSyntax").will(returnValue(Syntax.XWIKI_1_0));
    this.mockWikiDescriptorManager = registerMockComponent(WikiDescriptorManager.class);
    this.mockWikiDescriptorManager.stubs().method("getCurrentWikiId").will(new CustomStub("Implements WikiDescriptorManager.getCurrentWikiId") {

        @Override
        public String invoke(Invocation invocation) throws Throwable {
            return getContext().getWikiId();
        }
    });
    this.mockWikiDescriptorManager.stubs().method("getMainWikiId").will(new CustomStub("Implements WikiDescriptorManager.getMainWikiId") {

        @Override
        public String invoke(Invocation invocation) throws Throwable {
            return getContext().getMainXWiki();
        }
    });
    // In order not to create a cyclic dependency we have the platform-rendering-xwiki module (which contains
    // XWikiWikiModel requires for oldcore testing) not depend on platform-rendering-configuration-default. As a
    // consequence we need to provide a mock ExtendedRenderingConfiguration component as otherwise injecting
    // WikiModel would fail (since XWikiWikiModel depends on ExtendedRenderingConfiguration).
    registerMockComponent(ExtendedRenderingConfiguration.class);
}
Also used : XWikiStubContextProvider(com.xpn.xwiki.util.XWikiStubContextProvider) Invocation(org.jmock.core.Invocation) WikiDescriptorManager(org.xwiki.wiki.descriptor.WikiDescriptorManager) XWikiContext(com.xpn.xwiki.XWikiContext) Mock(org.jmock.Mock) Date(java.util.Date) Provider(javax.inject.Provider) XWikiStubContextProvider(com.xpn.xwiki.util.XWikiStubContextProvider) Execution(org.xwiki.context.Execution) DefaultComponentDescriptor(org.xwiki.component.descriptor.DefaultComponentDescriptor) CustomStub(org.jmock.core.stub.CustomStub) ComponentManager(org.xwiki.component.manager.ComponentManager) ServletEnvironment(org.xwiki.environment.internal.ServletEnvironment) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) File(java.io.File)

Aggregations

DefaultParameterizedType (org.xwiki.component.util.DefaultParameterizedType)104 Test (org.junit.Test)44 Before (org.junit.Before)32 Provider (javax.inject.Provider)27 DocumentReference (org.xwiki.model.reference.DocumentReference)24 XWikiContext (com.xpn.xwiki.XWikiContext)19 ComponentManager (org.xwiki.component.manager.ComponentManager)19 ExecutionContext (org.xwiki.context.ExecutionContext)17 ExtendedURL (org.xwiki.url.ExtendedURL)15 Execution (org.xwiki.context.Execution)14 HashMap (java.util.HashMap)13 DocumentAccessBridge (org.xwiki.bridge.DocumentAccessBridge)13 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)12 ResourceReferenceSerializer (org.xwiki.resource.ResourceReferenceSerializer)10 VfsResourceReference (org.xwiki.vfs.VfsResourceReference)10 Properties (java.util.Properties)9 MimeBodyPartFactory (org.xwiki.mail.MimeBodyPartFactory)9 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)8 XWiki (com.xpn.xwiki.XWiki)7 File (java.io.File)7