Search in sources :

Example 11 with IConfiguration

use of org.pentaho.platform.api.engine.IConfiguration in project pentaho-platform by pentaho.

the class SqlMetadataQueryExecTest method testDriverClassesToForceMetaNoEntries.

@Test
public void testDriverClassesToForceMetaNoEntries() throws IOException {
    ISystemConfig sysConfig = mock(ISystemConfig.class);
    IConfiguration config = mock(IConfiguration.class);
    when(sysConfig.getConfiguration(SqlMetadataQueryExec.CONFIG_ID)).thenReturn(config);
    Properties props = mock(Properties.class);
    when(config.getProperties()).thenReturn(props);
    final ArgumentCaptor<String> defaultValue = ArgumentCaptor.forClass(String.class);
    when(props.getProperty(eq(SqlMetadataQueryExec.FORCE_DB_META_CLASSES_PROP), defaultValue.capture())).thenAnswer(new Answer<String>() {

        @Override
        public String answer(InvocationOnMock invocation) throws Throwable {
            return defaultValue.getValue();
        }
    });
    SqlMetadataQueryExec sqlMetadataQueryExec = new SqlMetadataQueryExec(sysConfig);
    assertEquals(0, sqlMetadataQueryExec.driverClassesToForceMeta.size());
}
Also used : InvocationOnMock(org.mockito.invocation.InvocationOnMock) ISystemConfig(org.pentaho.platform.api.engine.ISystemConfig) Matchers.anyString(org.mockito.Matchers.anyString) IConfiguration(org.pentaho.platform.api.engine.IConfiguration) Properties(java.util.Properties) Test(org.junit.Test)

Example 12 with IConfiguration

use of org.pentaho.platform.api.engine.IConfiguration in project pentaho-platform by pentaho.

the class SystemResourceIT method setUp.

@Before
public void setUp() throws Exception {
    mp = new MicroPlatform();
    mp.defineInstance(IAuthorizationPolicy.class, new TestAuthorizationPolicy());
    mp.start();
    ISystemConfig systemConfig = new SystemConfig();
    IConfiguration securityConfig = mock(IConfiguration.class);
    Properties props = new Properties();
    props.setProperty("provider", "jackrabbit");
    when(securityConfig.getProperties()).thenReturn(props);
    when(securityConfig.getId()).thenReturn("security");
    systemConfig.registerConfiguration(securityConfig);
    systemResource = new SystemResource(systemConfig);
    // $NON-NLS-1$
    StandaloneApplicationContext applicationContext = new StandaloneApplicationContext(getSolutionPath(), "");
    ApplicationContext springApplicationContext = getSpringApplicationContext();
    IPentahoObjectFactory pentahoObjectFactory = new StandaloneSpringPentahoObjectFactory();
    pentahoObjectFactory.init(null, springApplicationContext);
    PentahoSystem.registerObjectFactory(pentahoObjectFactory);
    // force Spring to populate PentahoSystem
    boolean initOk = PentahoSystem.init(applicationContext);
/*
     * StandaloneSession session = new StandaloneSession();
     * 
     * StandaloneSpringPentahoObjectFactory factory = new StandaloneSpringPentahoObjectFactory( );
     * 
     * File f = new File(TestResourceLocation.TEST_RESOURCES + "/solution/system/pentahoObjects.spring.xml"); FileSystemResource fsr = new
     * FileSystemResource(f); GenericApplicationContext appCtx = new GenericApplicationContext();
     * XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(appCtx); xmlReader.loadBeanDefinitions(fsr);
     * 
     * factory.init(TestResourceLocation.TEST_RESOURCES + "/solution/system/pentahoObjects.spring.xml", appCtx );
     */
}
Also used : ISystemConfig(org.pentaho.platform.api.engine.ISystemConfig) SystemConfig(org.pentaho.platform.config.SystemConfig) StandaloneApplicationContext(org.pentaho.platform.engine.core.system.StandaloneApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) IPentahoObjectFactory(org.pentaho.platform.api.engine.IPentahoObjectFactory) MicroPlatform(org.pentaho.test.platform.engine.core.MicroPlatform) ISystemConfig(org.pentaho.platform.api.engine.ISystemConfig) FileSystemResource(org.springframework.core.io.FileSystemResource) StandaloneApplicationContext(org.pentaho.platform.engine.core.system.StandaloneApplicationContext) IConfiguration(org.pentaho.platform.api.engine.IConfiguration) Properties(java.util.Properties) StandaloneSpringPentahoObjectFactory(org.pentaho.platform.engine.core.system.objfac.StandaloneSpringPentahoObjectFactory) Before(org.junit.Before)

Example 13 with IConfiguration

use of org.pentaho.platform.api.engine.IConfiguration in project pentaho-platform by pentaho.

the class SystemConfigIT method testListConfigurations.

@Test
public void testListConfigurations() throws Exception {
    IConfiguration c = new PropertiesFileConfiguration("test", new File(TestResourceLocation.TEST_RESOURCES + "/SystemConfig/system/test.properties"));
    systemConfig.registerConfiguration(c);
    assertEquals(1, systemConfig.listConfigurations().length);
    c = new PropertiesFileConfiguration("test", new File(TestResourceLocation.TEST_RESOURCES + "/SystemConfig/system/test.properties"));
    systemConfig.registerConfiguration(c);
    assertEquals(1, systemConfig.listConfigurations().length);
    c = new PropertiesFileConfiguration("test2", new File(TestResourceLocation.TEST_RESOURCES + "/SystemConfig/system/test.properties"));
    systemConfig.registerConfiguration(c);
    assertEquals(2, systemConfig.listConfigurations().length);
}
Also used : IConfiguration(org.pentaho.platform.api.engine.IConfiguration) File(java.io.File) Test(org.junit.Test)

Example 14 with IConfiguration

use of org.pentaho.platform.api.engine.IConfiguration in project pentaho-platform by pentaho.

the class SystemConfigIT method testSetConfiguration.

@Test
public void testSetConfiguration() throws Exception {
    IConfiguration c = new PropertiesFileConfiguration("test", new File(TestResourceLocation.TEST_RESOURCES + "/SystemConfig/system/test.properties"));
    systemConfig.registerConfiguration(c);
    assertNotNull(systemConfig.getConfiguration("test"));
}
Also used : IConfiguration(org.pentaho.platform.api.engine.IConfiguration) File(java.io.File) Test(org.junit.Test)

Example 15 with IConfiguration

use of org.pentaho.platform.api.engine.IConfiguration 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)

Aggregations

IConfiguration (org.pentaho.platform.api.engine.IConfiguration)17 ISystemConfig (org.pentaho.platform.api.engine.ISystemConfig)10 Properties (java.util.Properties)9 Test (org.junit.Test)9 File (java.io.File)4 IOException (java.io.IOException)4 Matchers.anyString (org.mockito.Matchers.anyString)3 Before (org.junit.Before)2 IPentahoObjectFactory (org.pentaho.platform.api.engine.IPentahoObjectFactory)2 LinkedList (java.util.LinkedList)1 Locale (java.util.Locale)1 Map (java.util.Map)1 Matcher (java.util.regex.Matcher)1 ServletException (javax.servlet.ServletException)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 WebApplicationException (javax.ws.rs.WebApplicationException)1