use of com.xpn.xwiki.web.XWikiURLFactoryService in project xwiki-platform by xwiki.
the class XWikiContextCopierTest method setup.
@Before
public void setup() throws Exception {
Utils.setComponentManager(mocker);
originalResponse = new XWikiServletResponseStub();
original = new XWikiContext();
// Set some values
original.setWikiId("wiki");
DocumentReference userReference = new DocumentReference("wiki", "Space", "Page");
EntityReferenceSerializer<String> serializer = mocker.registerMockComponent(EntityReferenceSerializer.TYPE_STRING, "compactwiki");
when(serializer.serialize(userReference)).thenReturn("wiki:Space.Page");
mocker.registerMockComponent(DocumentReferenceResolver.TYPE_STRING, "currentmixed");
original.setUserReference(userReference);
// Set the mock request
this.originalRequest = mock(XWikiRequest.class);
original.setRequest(this.originalRequest);
Copier<XWikiRequest> requestCopier = mocker.getInstance(new DefaultParameterizedType(null, Copier.class, XWikiRequest.class));
when(requestCopier.copy(this.originalRequest)).thenReturn(this.originalRequest);
// Set the stubbed response
original.setResponse(originalResponse);
// XWiki mock
XWiki xwiki = mock(XWiki.class);
original.setWiki(xwiki);
// Store mock
// Simulate the existence of a hibernate session in context
original.put(HIBSESSION, "opened session");
store = mock(XWikiStoreInterface.class);
// clean up will remove the session in the given context
doAnswer(new Answer<Void>() {
public Void answer(InvocationOnMock invocation) {
XWikiContext context = (XWikiContext) invocation.getArguments()[0];
context.put(HIBSESSION, null);
return null;
}
}).when(store).cleanUp(any(XWikiContext.class));
when(xwiki.getStore()).thenReturn(store);
// URL factory mock
XWikiURLFactory urlFactory = mock(XWikiURLFactory.class);
XWikiURLFactoryService urlFactoryService = mock(XWikiURLFactoryService.class);
when(urlFactoryService.createURLFactory(anyInt(), any(XWikiContext.class))).thenReturn(urlFactory);
when(xwiki.getURLFactoryService()).thenReturn(urlFactoryService);
}
use of com.xpn.xwiki.web.XWikiURLFactoryService in project xwiki-platform by xwiki.
the class XWiki method getURLFactoryService.
public XWikiURLFactoryService getURLFactoryService() {
if (this.urlFactoryService == null) {
synchronized (this.URLFACTORY_SERVICE_LOCK) {
if (this.urlFactoryService == null) {
LOGGER.info("Initializing URLFactory Service...");
XWikiURLFactoryService factoryService = null;
String urlFactoryServiceClass = getConfiguration().getProperty("xwiki.urlfactory.serviceclass");
if (urlFactoryServiceClass != null) {
try {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Using custom URLFactory Service Class [" + urlFactoryServiceClass + "]");
}
factoryService = (XWikiURLFactoryService) Class.forName(urlFactoryServiceClass).getConstructor(new Class<?>[] { XWiki.class }).newInstance(new Object[] { this });
} catch (Exception e) {
factoryService = null;
LOGGER.warn("Failed to initialize URLFactory Service [" + urlFactoryServiceClass + "]", e);
}
}
if (factoryService == null) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Using default URLFactory Service Class [" + urlFactoryServiceClass + "]");
}
factoryService = new XWikiURLFactoryServiceImpl(this);
}
// Set the urlFactoryService object in one assignment to prevent threading
// issues when checking for
// null above.
this.urlFactoryService = factoryService;
}
}
}
return this.urlFactoryService;
}
Aggregations