use of org.xwiki.environment.Environment in project xwiki-platform by xwiki.
the class EmbeddedSolrInstanceInitializationTest method setup.
@Before
public void setup() throws Exception {
Environment mockEnvironment = this.mocker.registerMockComponent(Environment.class);
when(mockEnvironment.getPermanentDirectory()).thenReturn(PERMANENT_DIRECTORY);
FileUtils.deleteDirectory(PERMANENT_DIRECTORY);
PERMANENT_DIRECTORY.mkdirs();
this.mockXWikiProperties = this.mocker.registerMockComponent(ConfigurationSource.class, "xwikiproperties");
}
use of org.xwiki.environment.Environment in project xwiki-platform by xwiki.
the class AbstractBridgedComponentTestCase method setUp.
@Override
@Before
public 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");
// 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);
execution.getContext().setProperty(XWikiContext.EXECUTIONCONTEXT_KEY, this.context);
XWikiStubContextProvider stubContextProvider = getComponentManager().getInstance(XWikiStubContextProvider.class);
stubContextProvider.initialize(this.context);
// 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 = (ServletEnvironment) getComponentManager().getInstance(Environment.class);
final ServletContext mockServletContext = getMockery().mock(ServletContext.class);
environment.setServletContext(mockServletContext);
getMockery().checking(new Expectations() {
{
allowing(mockServletContext).getResourceAsStream("/WEB-INF/cache/infinispan/config.xml");
will(returnValue(null));
allowing(mockServletContext).getResourceAsStream("/WEB-INF/xwiki.cfg");
will(returnValue(null));
allowing(mockServletContext).getAttribute("javax.servlet.context.tempdir");
will(returnValue(new File(System.getProperty("java.io.tmpdir"))));
}
});
final CoreConfiguration mockCoreConfiguration = registerMockComponent(CoreConfiguration.class);
getMockery().checking(new Expectations() {
{
allowing(mockCoreConfiguration).getDefaultDocumentSyntax();
will(returnValue(Syntax.XWIKI_1_0));
}
});
}
use of org.xwiki.environment.Environment in project xwiki-platform by xwiki.
the class LocalizationScriptServiceTest method setUp.
@Before
public void setUp() throws Exception {
componentManager = mock(ComponentManager.class);
Provider<ComponentManager> componentManagerProvider = mocker.registerMockComponent(new DefaultParameterizedType(null, Provider.class, ComponentManager.class), "context");
when(componentManagerProvider.get()).thenReturn(componentManager);
renderer = mock(BlockRenderer.class, Syntax.PLAIN_1_0.toIdString());
when(componentManager.getInstance(BlockRenderer.class, Syntax.PLAIN_1_0.toIdString())).thenReturn(renderer);
localizationContext = mocker.getInstance(LocalizationContext.class);
localizationManager = mocker.getInstance(LocalizationManager.class);
localizationScriptService = (LocalizationScriptService) mocker.getComponentUnderTest();
translation = mock(Translation.class);
doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
WikiPrinter printer = (WikiPrinter) invocation.getArguments()[1];
printer.print("print result");
return null;
}
}).when(renderer).render(eq(new WordBlock("message")), any(WikiPrinter.class));
when(translation.render(Locale.ROOT, ArrayUtils.EMPTY_OBJECT_ARRAY)).thenReturn(new WordBlock("message"));
when(localizationManager.getTranslation("key", Locale.ROOT)).thenReturn(translation);
when(localizationContext.getCurrentLocale()).thenReturn(Locale.ROOT);
environment = mocker.getInstance(Environment.class);
}
use of org.xwiki.environment.Environment in project xwiki-platform by xwiki.
the class XWikiAttachmentContent method getNewFileItem.
/**
* @return a new FileItem for temporarily storing attachment content.
* @since 4.2M3
*/
private static FileItem getNewFileItem() {
final Environment env = Utils.getComponent(Environment.class);
final File dir = new File(env.getTemporaryDirectory(), "attachment-cache");
try {
if (!dir.mkdirs() && !dir.exists()) {
throw new UnexpectedException("Failed to create directory for attachments " + dir);
}
final DiskFileItem dfi = new DiskFileItem(null, null, false, null, 10000, dir);
// This causes the temp file to be created.
dfi.getOutputStream().close();
return dfi;
} catch (IOException e) {
throw new UnexpectedException("Failed to create new attachment temporary file.", e);
}
}
use of org.xwiki.environment.Environment in project xwiki-platform by xwiki.
the class DefaultEntityResourceActionListerTest method listActions.
@Test
public void listActions() throws Exception {
Environment environment = this.mocker.getInstance(Environment.class);
when(environment.getResourceAsStream("/WEB-INF/struts-config.xml")).thenReturn(getClass().getClassLoader().getResourceAsStream("WEB-INF/struts-config.xml"));
this.mocker.registerMockComponent(new DefaultParameterizedType(null, ResourceReferenceHandler.class, EntityResourceAction.class), "testaction");
assertThat(this.mocker.getComponentUnderTest().listActions(), hasItems("view", "edit", "get", "testaction"));
}
Aggregations