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());
}
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);
}
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();
}
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();
}
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);
}
Aggregations