use of org.xwiki.environment.Environment in project xwiki-platform by xwiki.
the class JGroupsNetworkAdapter method loadChannelConfiguration.
/**
* Load channel configuration.
*
* @param channelId the identifier of the channel
* @return the channel configuration
* @throws IOException failed to load configuration file
*/
private ProtocolStackConfigurator loadChannelConfiguration(String channelId) throws IOException {
String channelFile = channelId + ".xml";
String path = "/WEB-INF/" + CONFIGURATION_PATH + channelFile;
InputStream is = null;
try {
Environment environment = this.componentManager.getInstance(Environment.class);
is = environment.getResourceAsStream(path);
} catch (ComponentLookupException e) {
// Environment not found, continue by fallbacking on JGroups's standard configuration.
this.logger.debug("Failed to lookup the Environment component.", e);
}
if (is == null) {
// Fallback on JGroups standard configuration locations
is = ConfiguratorFactory.getConfigStream(channelFile);
if (is == null && !Global.DEFAULT_PROTOCOL_STACK.equals(channelFile)) {
// Fallback on default JGroups configuration
is = ConfiguratorFactory.getConfigStream(Global.DEFAULT_PROTOCOL_STACK);
}
}
return XmlConfigurator.getInstance(is);
}
use of org.xwiki.environment.Environment in project xwiki-platform by xwiki.
the class TempResourceActionTest method setUp.
@Before
public void setUp() throws Exception {
base = new File(getClass().getResource("/").toURI());
// Configure Servlet Environment defined in AbstractBridgedComponentTestCase so that it returns a good
// temporary directory
Environment environment = oldcore.getMocker().registerMockComponent(Environment.class);
when(environment.getTemporaryDirectory()).thenReturn(base);
action = new TempResourceAction();
}
use of org.xwiki.environment.Environment in project xwiki-platform by xwiki.
the class SerializedFilesMimeMessageIteratorTest method createMessageWhenFileNoLongerExists.
/**
* Error that can happen if the file has been locally deleted between the time the time the user executes a
* resend and the time the Mail Sender Thread reaches that file for processing (i.e. deserializing it).
*/
@Test
public void createMessageWhenFileNoLongerExists() throws Exception {
Environment environment = mock(Environment.class);
when(environment.getPermanentDirectory()).thenReturn(new File(TEMPORARY_DIRECTORY));
ComponentManager componentManager = mock(ComponentManager.class);
when(componentManager.getInstance(eq(Environment.class))).thenReturn(environment);
// Create a serialized file before the iterator is initialized
String mailID = "<1128820400.0.1419205781342.JavaMail.contact@xwiki.org>";
createSerializedMessage(mailID);
SerializedFilesMimeMessageIterator iterator = new SerializedFilesMimeMessageIterator(this.batchId, Collections.<String, Object>emptyMap(), componentManager);
// Remove the file before next() is called to generate the error
File messageFile = new File(this.batchDirectory, URLEncoder.encode(mailID, "UTF-8"));
messageFile.delete();
MimeMessage message = iterator.next();
// Verify that:
// 1) the returned message is null since there was an error
// 2) that the log contains the error
assertNull(message);
assertEquals("Failed to create Mime Message", this.logRule.getMessage(0));
}
use of org.xwiki.environment.Environment in project xwiki-platform by xwiki.
the class SerializedFilesMimeMessageIteratorTest method createMessage.
@Test
public void createMessage() throws Exception {
String mailID1 = "<1128820400.0.1419205781342.JavaMail.contact@xwiki.org>";
String mailID2 = "<1128820400.1.1419205781342.JavaMail.contact@xwiki.org>";
String mailID3 = "<1128820400.2.1419205781342.JavaMail.contact@xwiki.org>";
createSerializedMessage(mailID1);
createSerializedMessage(mailID2);
createSerializedMessage(mailID3);
Map<String, Object> parameters = new HashMap<>();
parameters.put("parameters", Collections.EMPTY_MAP);
Environment environment = mock(Environment.class);
when(environment.getPermanentDirectory()).thenReturn(new File(TEMPORARY_DIRECTORY));
ComponentManager componentManager = mock(ComponentManager.class);
when(componentManager.getInstance(eq(Environment.class))).thenReturn(environment);
SerializedFilesMimeMessageIterator iterator = new SerializedFilesMimeMessageIterator(this.batchId, parameters, componentManager);
ArrayList<String> listID = new ArrayList<>();
listID.add(mailID1);
listID.add(mailID2);
listID.add(mailID3);
assertTrue(iterator.hasNext());
MimeMessage message1 = iterator.next();
assertTrue(listID.contains(message1.getMessageID()));
listID.remove(message1.getMessageID());
assertTrue(iterator.hasNext());
MimeMessage message2 = iterator.next();
assertTrue(listID.contains(message2.getMessageID()));
listID.remove(message1.getMessageID());
assertTrue(iterator.hasNext());
MimeMessage message3 = iterator.next();
assertTrue(listID.contains(message2.getMessageID()));
listID.remove(message3.getMessageID());
assertFalse(iterator.hasNext());
}
use of org.xwiki.environment.Environment in project xwiki-platform by xwiki.
the class TemporaryChartImageWriterTest method getStorageLocation.
@Test
public void getStorageLocation() throws Exception {
WikiReference currentWikiReference = new WikiReference("wiki");
ModelContext modelContext = this.componentManager.getInstance(ModelContext.class);
when(modelContext.getCurrentEntityReference()).thenReturn(currentWikiReference);
Environment environment = this.componentManager.getInstance(Environment.class);
when(environment.getTemporaryDirectory()).thenReturn(new File("/tmpdir"));
File location = this.componentManager.getComponentUnderTest().getStorageLocation(new ImageId(new ChartMacroParameters()));
Assert.assertTrue("Got: " + location.toString(), location.toString().matches("/tmpdir/temp/chart/wiki/space/page/.*\\.png"));
}
Aggregations