Search in sources :

Example 1 with ISystemConfig

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

the class StandaloneSpringPentahoObjectFactoryTest method testFallbackPenBean.

/**
 * Test <pen:bean> fallback behavior when no object is published matching the request. It should fall-back to
 * PentahoSystem.get() behavior where beans matching the simple-name of the queried class are returned.
 *
 * @throws Exception
 */
public void testFallbackPenBean() throws Exception {
    PentahoSystem.shutdown();
    ISystemConfig config = mock(ISystemConfig.class);
    when(config.getProperty("system.dampening-timeout")).thenReturn("3000");
    PentahoSystem.registerObject(config);
    StandaloneSession session = new StandaloneSession();
    PentahoSessionHolder.setSession(session);
    StandaloneSpringPentahoObjectFactory factory = new StandaloneSpringPentahoObjectFactory();
    factory.init("src/test/resources/solution/system/pentahoObjects.spring.xml", null);
    PentahoSystem.registerObjectFactory(factory);
    // fallback
    SimpleObjectHolder integerHolder = PentahoSystem.get(SimpleObjectHolder.class, "SimpleIntegerHolder", session);
    // to
    // simpleName
    assertNotNull(integerHolder);
    assertEquals(123, (int) integerHolder.getVal());
    // fallback
    SimpleObjectHolder stringHolder = PentahoSystem.get(SimpleObjectHolder.class, "SimpleStringHolder", session);
    // to
    // simpleName
    assertNotNull(stringHolder);
    assertEquals("testing_fallback_by_interface", stringHolder.getVal().toString());
    // checks
    SimpleObjectHolder integerHolder2 = PentahoSystem.get(SimpleObjectHolder.class, "SimpleIntegerHolder2", session);
    // ID
    assertNotNull(integerHolder2);
    assertEquals(456, (int) integerHolder2.getVal());
}
Also used : StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) ISystemConfig(org.pentaho.platform.api.engine.ISystemConfig) StandaloneSpringPentahoObjectFactory(org.pentaho.platform.engine.core.system.objfac.StandaloneSpringPentahoObjectFactory)

Example 2 with ISystemConfig

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

the class DefaultContentSystemListener method startup.

@Override
public boolean startup(IPentahoSession arg0) {
    // By default we'll run in a separate thread. This checks to see if someone has disabled this.
    ISystemConfig systemSettings = PentahoSystem.get(ISystemConfig.class);
    Boolean enableAsyncLoading = true;
    if (systemSettings != null) {
        String disableLoadAsyncStr = systemSettings.getProperty("system.enable-async-default-content-loading");
        enableAsyncLoading = Boolean.valueOf(disableLoadAsyncStr);
    }
    Runnable runnable = new Runnable() {

        @Override
        public void run() {
            try {
                SecurityHelper.getInstance().runAsSystem(new Callable<Void>() {

                    @Override
                    public Void call() throws Exception {
                        Logger.info(this.getClass().getName(), "Default content importer has started");
                        // get a File reference to the directory
                        String solutionPath = PentahoSystem.getApplicationContext().getSolutionPath(DEFAULT_CONTENT_FOLDER);
                        File directory = new File(solutionPath);
                        // Instantiate the importer
                        IPlatformImporter importer = PentahoSystem.get(IPlatformImporter.class);
                        ArchiveLoader archiveLoader = new ArchiveLoader(importer);
                        archiveLoader.loadAll(directory, ArchiveLoader.ZIPS_FILTER);
                        return null;
                    }
                });
            } catch (Exception e) {
                Logger.error(this.getClass().getName(), e.getMessage());
            }
        }
    };
    if (enableAsyncLoading) {
        Thread t = new Thread(runnable);
        t.setDaemon(true);
        t.setName("Default Content Loader Thread");
        t.start();
    } else {
        runnable.run();
    }
    return true;
}
Also used : ArchiveLoader(org.pentaho.platform.plugin.services.importer.ArchiveLoader) ISystemConfig(org.pentaho.platform.api.engine.ISystemConfig) IPlatformImporter(org.pentaho.platform.plugin.services.importer.IPlatformImporter) File(java.io.File)

Example 3 with ISystemConfig

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

the class PentahoWebContextFilterTest method setup.

@Before
public void setup() throws IOException, ServletException {
    this.serverScheme = "https";
    String serverName = "di.pentaho.local";
    int port = 9055;
    this.serverAddress = this.serverScheme + "://" + serverName + ":" + port;
    this.contextRoot = "/the/context/root/";
    this.fullyQualifiedServerURL = this.serverAddress + this.contextRoot;
    this.mockRequest = mock(HttpServletRequest.class);
    final ISystemSettings settingsService = mock(ISystemSettings.class);
    when(settingsService.getSystemSetting(eq("anonymous-authentication/anonymous-user"), eq("anonymousUser"))).thenReturn("anonymousUser");
    PentahoSystem.setSystemSettingsService(settingsService);
    final ISystemConfig systemConfig = mock(ISystemConfig.class);
    final IPentahoObjectFactory objectFactory = mock(IPentahoObjectFactory.class);
    when(objectFactory.objectDefined(eq(ISystemConfig.class))).thenReturn(true);
    final IPentahoObjectReference pentahoObjectReference = mock(IPentahoObjectReference.class);
    when(pentahoObjectReference.getObject()).thenReturn(systemConfig);
    try {
        when(objectFactory.getObjectReferences(eq(ISystemConfig.class), nullable(IPentahoSession.class), nullable(Map.class))).thenReturn(new LinkedList() {

            {
                add(pentahoObjectReference);
            }
        });
    } catch (ObjectFactoryException e) {
        e.printStackTrace();
    }
    when(settingsService.getSystemSetting(nullable(String.class), nullable(String.class))).thenReturn("");
    PentahoSystem.registerObjectFactory(objectFactory);
    PentahoSystem.init();
    ServletContext mockServletContext = mock(ServletContext.class);
    ServletRegistration mockServletRegistration = mock(ServletRegistration.class);
    Collection<String> mappings = new ArrayList<>(1);
    mappings.add(PentahoWebContextFilter.DEFAULT_OSGI_BRIDGE);
    when(mockServletRegistration.getMappings()).thenReturn(mappings);
    when(mockServletContext.getServletRegistration(PentahoWebContextFilter.PLATFORM_OSGI_BRIDGE_ID)).thenReturn(mockServletRegistration);
    when(this.mockRequest.getServletContext()).thenReturn(mockServletContext);
    when(this.mockRequest.getRequestURI()).thenReturn("/somewhere/" + PentahoWebContextFilter.WEB_CONTEXT_JS);
    when(this.mockRequest.getScheme()).thenReturn(this.serverScheme);
    when(this.mockRequest.getServerName()).thenReturn(serverName);
    when(this.mockRequest.getServerPort()).thenReturn(port);
    when(this.mockRequest.getHeader("referer")).thenReturn(this.serverAddress + "/some/app");
    this.mockResponse = mock(HttpServletResponse.class);
    this.mockResponseOutputStream = new java.io.ByteArrayOutputStream();
    when(this.mockResponse.getOutputStream()).thenReturn(new ServletOutputStream() {

        @Override
        public boolean isReady() {
            return true;
        }

        @Override
        public void setWriteListener(WriteListener writeListener) {
        }

        @Override
        public void write(int b) throws IOException {
            PentahoWebContextFilterTest.this.mockResponseOutputStream.write(b);
        }
    });
    FilterConfig mockFilterConfig = mock(FilterConfig.class);
    this.pentahoWebContextFilter = spy(new PentahoWebContextFilter());
    IApplicationContext mockApplicationContext = mock(IApplicationContext.class);
    when(mockApplicationContext.getFullyQualifiedServerURL()).thenReturn(this.fullyQualifiedServerURL);
    doReturn(mockApplicationContext).when(this.pentahoWebContextFilter).getApplicationContext();
    IPentahoRequestContext mockRequestContext = mock(IPentahoRequestContext.class);
    when(mockRequestContext.getContextPath()).thenReturn(this.contextRoot);
    doReturn(mockRequestContext).when(this.pentahoWebContextFilter).getRequestContext();
    this.activeTheme = "xptoTheme";
    IUserSetting mockUserSetting = mock(IUserSetting.class);
    when(mockUserSetting.getSettingValue()).thenReturn(this.activeTheme);
    IUserSettingService mockUserSettingsService = mock(IUserSettingService.class);
    when(mockUserSettingsService.getUserSetting("pentaho-user-theme", null)).thenReturn(mockUserSetting);
    doReturn(mockUserSettingsService).when(this.pentahoWebContextFilter).getUserSettingsService();
    this.sessionName = "testSession";
    IPentahoSession mockSession = mock(IPentahoSession.class);
    when(mockSession.getName()).thenReturn(this.sessionName);
    doReturn(mockSession).when(this.pentahoWebContextFilter).getSession();
    this.reservedChars = new ArrayList<>(2);
    this.reservedChars.add('r');
    this.reservedChars.add('c');
    doReturn(this.reservedChars).when(this.pentahoWebContextFilter).getRepositoryReservedChars();
    IPluginManager mockPluginManager = mock(IPluginManager.class);
    doReturn(mockPluginManager).when(this.pentahoWebContextFilter).getPluginManager();
    doReturn(PentahoWebContextFilter.DEFAULT_SERVICES_ROOT).when(this.pentahoWebContextFilter).initializeServicesPath();
    this.pentahoWebContextFilter.init(mockFilterConfig);
}
Also used : IPentahoObjectFactory(org.pentaho.platform.api.engine.IPentahoObjectFactory) ServletOutputStream(javax.servlet.ServletOutputStream) ArrayList(java.util.ArrayList) ISystemSettings(org.pentaho.platform.api.engine.ISystemSettings) IApplicationContext(org.pentaho.platform.api.engine.IApplicationContext) IUserSetting(org.pentaho.platform.api.usersettings.pojo.IUserSetting) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletRegistration(javax.servlet.ServletRegistration) ObjectFactoryException(org.pentaho.platform.api.engine.ObjectFactoryException) ServletContext(javax.servlet.ServletContext) FilterConfig(javax.servlet.FilterConfig) WriteListener(javax.servlet.WriteListener) IPentahoObjectReference(org.pentaho.platform.api.engine.IPentahoObjectReference) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) HttpServletResponse(javax.servlet.http.HttpServletResponse) ISystemConfig(org.pentaho.platform.api.engine.ISystemConfig) IOException(java.io.IOException) LinkedList(java.util.LinkedList) IPentahoRequestContext(org.pentaho.platform.api.engine.IPentahoRequestContext) IUserSettingService(org.pentaho.platform.api.usersettings.IUserSettingService) IPluginManager(org.pentaho.platform.api.engine.IPluginManager) Map(java.util.Map) Before(org.junit.Before)

Example 4 with ISystemConfig

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

the class UserRoleDaoServiceTest method setUp.

@Before
public void setUp() throws Exception {
    PentahoSystem.init();
    SecurityHelper.setMockInstance(mock(ISecurityHelper.class));
    Properties props = mock(Properties.class);
    when(props.getProperty(UserRoleDaoService.PUC_USER_PASSWORD_LENGTH)).thenReturn("0");
    when(props.getProperty(UserRoleDaoService.PUC_USER_PASSWORD_REQUIRE_SPECIAL_CHARACTER)).thenReturn("false");
    IConfiguration config = mock(IConfiguration.class);
    when(config.getProperties()).thenReturn(props);
    ISystemConfig sysConfig = mock(ISystemConfig.class);
    when(sysConfig.getConfiguration("security")).thenReturn(config);
    userRoleService = new UserRoleDaoService();
    userRoleService.setSystemConfig(sysConfig);
}
Also used : ISecurityHelper(org.pentaho.platform.api.engine.ISecurityHelper) ISystemConfig(org.pentaho.platform.api.engine.ISystemConfig) Properties(java.util.Properties) IConfiguration(org.pentaho.platform.api.engine.IConfiguration) Before(org.junit.Before)

Example 5 with ISystemConfig

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

the class RequestParameterAuthenticationFilterTest method beforeTest.

@Before
public void beforeTest() throws KettleException, IOException {
    KettleClientEnvironment.init();
    filter = new RequestParameterAuthenticationFilter();
    authManagerMock = mock(AuthenticationManager.class);
    filter.setAuthenticationManager(authManagerMock);
    final Properties properties = new Properties();
    properties.setProperty("requestParameterAuthenticationEnabled", "true");
    IConfiguration config = mock(IConfiguration.class);
    ISystemConfig mockISystemConfig = mock(ISystemConfig.class);
    mockISystemConfig.registerConfiguration(config);
    filter.setSystemConfig(mockISystemConfig);
    doReturn(config).when(mockISystemConfig).getConfiguration("security");
    doReturn(properties).when(config).getProperties();
}
Also used : AuthenticationManager(org.springframework.security.authentication.AuthenticationManager) ISystemConfig(org.pentaho.platform.api.engine.ISystemConfig) Properties(java.util.Properties) IConfiguration(org.pentaho.platform.api.engine.IConfiguration) RequestParameterAuthenticationFilter(org.pentaho.platform.web.http.security.RequestParameterAuthenticationFilter) Before(org.junit.Before)

Aggregations

ISystemConfig (org.pentaho.platform.api.engine.ISystemConfig)20 IConfiguration (org.pentaho.platform.api.engine.IConfiguration)11 Properties (java.util.Properties)9 Test (org.junit.Test)7 Before (org.junit.Before)5 IPentahoObjectFactory (org.pentaho.platform.api.engine.IPentahoObjectFactory)5 IOException (java.io.IOException)4 Map (java.util.Map)4 IPentahoObjectReference (org.pentaho.platform.api.engine.IPentahoObjectReference)4 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)4 LinkedList (java.util.LinkedList)3 ISystemSettings (org.pentaho.platform.api.engine.ISystemSettings)3 IApplicationContext (org.pentaho.platform.api.engine.IApplicationContext)2 ObjectFactoryException (org.pentaho.platform.api.engine.ObjectFactoryException)2 StandaloneSpringPentahoObjectFactory (org.pentaho.platform.engine.core.system.objfac.StandaloneSpringPentahoObjectFactory)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Locale (java.util.Locale)1 FilterConfig (javax.servlet.FilterConfig)1