Search in sources :

Example 16 with ISystemConfig

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();
}
Also used : IPentahoObjectReference(org.pentaho.platform.api.engine.IPentahoObjectReference) IPentahoObjectFactory(org.pentaho.platform.api.engine.IPentahoObjectFactory) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) Node(org.dom4j.Node) ISystemConfig(org.pentaho.platform.api.engine.ISystemConfig) ISystemSettings(org.pentaho.platform.api.engine.ISystemSettings) IConfiguration(org.pentaho.platform.api.engine.IConfiguration) Properties(java.util.Properties) Map(java.util.Map) LinkedList(java.util.LinkedList)

Example 17 with ISystemConfig

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));
        }
    }
}
Also used : ISystemConfig(org.pentaho.platform.api.engine.ISystemConfig) IOException(java.io.IOException) IConfiguration(org.pentaho.platform.api.engine.IConfiguration) Properties(java.util.Properties)

Aggregations

ISystemConfig (org.pentaho.platform.api.engine.ISystemConfig)17 IConfiguration (org.pentaho.platform.api.engine.IConfiguration)10 Properties (java.util.Properties)8 Test (org.junit.Test)7 IOException (java.io.IOException)3 Matchers.anyString (org.mockito.Matchers.anyString)3 IPentahoObjectFactory (org.pentaho.platform.api.engine.IPentahoObjectFactory)3 Map (java.util.Map)2 Before (org.junit.Before)2 IPentahoObjectReference (org.pentaho.platform.api.engine.IPentahoObjectReference)2 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)2 StandaloneSpringPentahoObjectFactory (org.pentaho.platform.engine.core.system.objfac.StandaloneSpringPentahoObjectFactory)2 File (java.io.File)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 Locale (java.util.Locale)1 Node (org.dom4j.Node)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 IApplicationContext (org.pentaho.platform.api.engine.IApplicationContext)1 ISystemSettings (org.pentaho.platform.api.engine.ISystemSettings)1