use of org.pentaho.platform.api.engine.ISystemConfig in project pentaho-platform by pentaho.
the class PentahoSystemTest method initXMLFactories.
private void initXMLFactories(boolean factoriesInPentahoXML) throws Exception {
// mock pentaho.xml
final ISystemSettings settingsService = mock(ISystemSettings.class);
if (factoriesInPentahoXML) {
final Node testNode = mock(Node.class);
final Node testNodeName = mock(Node.class);
when(testNodeName.getText()).thenReturn(testSystemPropertyName);
when(testNode.selectSingleNode(eq("@name"))).thenReturn(testNodeName);
final Node testNodeImplementation = mock(Node.class);
when(testNodeImplementation.getText()).thenReturn(testXMLValue);
when(testNode.selectSingleNode(eq("@implementation"))).thenReturn(testNodeImplementation);
when(settingsService.getSystemSettings(eq("xml-factories/factory-impl"))).thenReturn(new LinkedList() {
{
add(testNode);
}
});
} else {
when(settingsService.getSystemSettings(eq("xml-factories/factory-impl"))).thenReturn(new LinkedList());
}
when(settingsService.getSystemSetting(anyString(), anyString())).thenReturn("");
PentahoSystem.setSystemSettingsService(settingsService);
// mock java-system-properties.properties
final IPentahoObjectFactory objectFactory = mock(IPentahoObjectFactory.class);
final ISystemConfig systemConfig = mock(ISystemConfig.class);
final IConfiguration configuration = mock(IConfiguration.class);
when(configuration.getProperties()).thenReturn(new Properties() {
{
setProperty(testSystemPropertyName, testPropertyValue);
}
});
when(systemConfig.getConfiguration(eq(PentahoSystem.JAVA_SYSTEM_PROPERTIES))).thenReturn(configuration);
when(objectFactory.objectDefined(eq(ISystemConfig.class))).thenReturn(true);
final IPentahoObjectReference pentahoObjectReference = mock(IPentahoObjectReference.class);
when(pentahoObjectReference.getObject()).thenReturn(systemConfig);
when(objectFactory.getObjectReferences(eq(ISystemConfig.class), any(IPentahoSession.class), any(Map.class))).thenReturn(new LinkedList() {
{
add(pentahoObjectReference);
}
});
PentahoSystem.registerObjectFactory(objectFactory);
PentahoSystem.init();
}
use of org.pentaho.platform.api.engine.ISystemConfig in project pentaho-platform by pentaho.
the class PentahoSystem method setSystemProperties.
private static void setSystemProperties() {
ISystemConfig systemConfig = PentahoSystem.get(ISystemConfig.class);
if (systemConfig == null) {
return;
}
final IConfiguration configuration = systemConfig.getConfiguration(JAVA_SYSTEM_PROPERTIES);
if (configuration != null) {
try {
final Properties systemSettingsProperties = configuration.getProperties();
for (String propName : systemSettingsProperties.stringPropertyNames()) {
System.setProperty(propName, systemSettingsProperties.getProperty(propName));
}
} catch (IOException e) {
Logger.warn(PentahoSystem.class.getName(), Messages.getInstance().getErrorString("PentahoSystem.WARN_SYSTEM_PROPERTIES_READ_FAIL", // $NON-NLS-1$
JAVA_SYSTEM_PROPERTIES));
}
}
}
Aggregations