Search in sources :

Example 1 with IPentahoObjectFactory

use of org.pentaho.platform.api.engine.IPentahoObjectFactory in project data-access by pentaho.

the class DatasourceServiceTest method setUpClass.

@BeforeClass
public static void setUpClass() throws ObjectFactoryException {
    authorizationPolicy = mock(IAuthorizationPolicy.class);
    when(authorizationPolicy.isAllowed(RepositoryReadAction.NAME)).thenReturn(true);
    when(authorizationPolicy.isAllowed(RepositoryCreateAction.NAME)).thenReturn(true);
    IPentahoObjectFactory pentahoObjectFactory = mock(IPentahoObjectFactory.class);
    when(pentahoObjectFactory.objectDefined(anyString())).thenReturn(true);
    when(pentahoObjectFactory.get(anyClass(), anyString(), any(IPentahoSession.class))).thenAnswer((Answer<Object>) invocation -> {
        if (invocation.getArguments()[0].equals(IAuthorizationPolicy.class)) {
            return authorizationPolicy;
        }
        return null;
    });
    PentahoSystem.registerObjectFactory(pentahoObjectFactory);
}
Also used : RepositoryCreateAction(org.pentaho.platform.security.policy.rolebased.actions.RepositoryCreateAction) BeforeClass(org.junit.BeforeClass) PublishAction(org.pentaho.platform.security.policy.rolebased.actions.PublishAction) RepositoryReadAction(org.pentaho.platform.security.policy.rolebased.actions.RepositoryReadAction) LogicalModel(org.pentaho.metadata.model.LogicalModel) PentahoSystem(org.pentaho.platform.engine.core.system.PentahoSystem) Matchers.anyString(org.mockito.Matchers.anyString) Domain(org.pentaho.metadata.model.Domain) ArrayList(java.util.ArrayList) ArgumentMatcher(org.mockito.ArgumentMatcher) Answer(org.mockito.stubbing.Answer) IAuthorizationPolicy(org.pentaho.platform.api.engine.IAuthorizationPolicy) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) Assert.fail(org.junit.Assert.fail) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) ObjectFactoryException(org.pentaho.platform.api.engine.ObjectFactoryException) Matchers.any(org.mockito.Matchers.any) AdministerSecurityAction(org.pentaho.platform.security.policy.rolebased.actions.AdministerSecurityAction) List(java.util.List) Matchers.argThat(org.mockito.Matchers.argThat) Assert.assertFalse(org.junit.Assert.assertFalse) IPentahoObjectFactory(org.pentaho.platform.api.engine.IPentahoObjectFactory) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) Mockito.mock(org.mockito.Mockito.mock) IAuthorizationPolicy(org.pentaho.platform.api.engine.IAuthorizationPolicy) IPentahoObjectFactory(org.pentaho.platform.api.engine.IPentahoObjectFactory) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) BeforeClass(org.junit.BeforeClass)

Example 2 with IPentahoObjectFactory

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

the class IntegrationTestUtil method initializePentahoSystem.

public static synchronized void initializePentahoSystem(String solutionPath) throws Exception {
    // this setting is useful only for running the integration tests from within IntelliJ
    // this same property is set for integration tests via the pom when running with mvn
    String folderPaths = "target/spoon/plugins";
    File f = new File(folderPaths);
    System.setProperty("KETTLE_PLUGIN_BASE_FOLDERS", f.getAbsolutePath());
    StandaloneApplicationContext appContext = new StandaloneApplicationContext(solutionPath, "");
    PentahoSystem.setSystemSettingsService(new PathBasedSystemSettings());
    if (solutionPath == null) {
        throw new MetaverseException(Messages.getString("ERROR.MetaverseInit.BadConfigPath", solutionPath));
    }
    try {
        ClassLoader cl = Thread.currentThread().getContextClassLoader();
        Thread.currentThread().setContextClassLoader(MetaverseUtil.class.getClassLoader());
        IPentahoObjectFactory pentahoObjectFactory = new StandaloneSpringPentahoObjectFactory();
        pentahoObjectFactory.init(solutionPath, PentahoSystem.getApplicationContext());
        PentahoSystem.registerObjectFactory(pentahoObjectFactory);
        // Restore context classloader
        Thread.currentThread().setContextClassLoader(cl);
    } catch (Exception e) {
        throw new MetaverseException(Messages.getString("ERROR.MetaverseInit.CouldNotInit"), e);
    }
    PentahoSystem.init(appContext);
    PentahoSessionHolder.setSession(new StandaloneSession());
    registerKettlePlugins();
    try {
        KettleEnvironment.init();
    } catch (KettleException e) {
        e.printStackTrace();
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) MetaverseUtil(org.pentaho.metaverse.util.MetaverseUtil) IPentahoObjectFactory(org.pentaho.platform.api.engine.IPentahoObjectFactory) StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) StandaloneApplicationContext(org.pentaho.platform.engine.core.system.StandaloneApplicationContext) File(java.io.File) PathBasedSystemSettings(org.pentaho.platform.engine.core.system.PathBasedSystemSettings) MetaverseException(org.pentaho.metaverse.api.MetaverseException) KettleException(org.pentaho.di.core.exception.KettleException) MetaverseException(org.pentaho.metaverse.api.MetaverseException) KettlePluginException(org.pentaho.di.core.exception.KettlePluginException) StandaloneSpringPentahoObjectFactory(org.pentaho.platform.engine.core.system.objfac.StandaloneSpringPentahoObjectFactory)

Example 3 with IPentahoObjectFactory

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

the class BootTest method testBootSettings.

@Test
public void testBootSettings() throws Exception {
    PentahoSystemBoot boot = new PentahoSystemBoot();
    boot.setFilePath("src/test/resources/solution");
    IPentahoObjectFactory factory = boot.getFactory();
    assertNotNull("object factory is null", factory);
    SystemSettings settings = new SystemSettings();
    boot.setSettingsProvider(settings);
    assertEquals(settings, boot.getSettingsProvider());
}
Also used : PentahoSystemBoot(org.pentaho.platform.engine.core.system.boot.PentahoSystemBoot) IPentahoObjectFactory(org.pentaho.platform.api.engine.IPentahoObjectFactory) SystemSettings(org.pentaho.platform.engine.core.system.SystemSettings) Test(org.junit.Test)

Example 4 with IPentahoObjectFactory

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

the class BootTest method testBootListeners.

@Test
public void testBootListeners() throws Exception {
    PentahoSystemBoot boot = new PentahoSystemBoot();
    boot.setFilePath("src/test/resources/solution");
    boot.define(ISolutionEngine.class.getSimpleName(), Object1.class.getName(), IPentahoDefinableObjectFactory.Scope.GLOBAL);
    TestLifecycleListener lifecycleListener1 = new TestLifecycleListener();
    TestLifecycleListener lifecycleListener2 = new TestLifecycleListener();
    boot.addLifecycleListener(lifecycleListener1);
    List<IPentahoSystemListener> lifecycleListeners1 = boot.getLifecycleListeners();
    assertEquals(1, lifecycleListeners1.size());
    assertEquals(lifecycleListener1, lifecycleListeners1.get(0));
    assertFalse(TestLifecycleListener.startupCalled);
    assertFalse(TestLifecycleListener.shutdownCalled);
    List<IPentahoSystemListener> lifecycleListeners2 = new ArrayList<IPentahoSystemListener>();
    lifecycleListeners2.add(lifecycleListener2);
    boot.setLifecycleListeners(lifecycleListeners2);
    List<IPentahoSystemListener> lifecycleListeners3 = boot.getLifecycleListeners();
    assertEquals(1, lifecycleListeners3.size());
    assertEquals(lifecycleListener2, lifecycleListeners3.get(0));
    assertEquals(lifecycleListeners2, lifecycleListeners3);
    IPentahoObjectFactory factory = boot.getFactory();
    assertNotNull("object factory is null", factory);
    assertTrue("object factory not definable", factory instanceof IPentahoDefinableObjectFactory);
    assertFalse(boot.isInitialized());
    boolean ok = boot.start();
    assertNull(boot.getSettingsProvider());
    assertTrue(boot.isInitialized());
    assertTrue(ok);
    assertTrue(TestLifecycleListener.startupCalled);
    assertFalse(TestLifecycleListener.shutdownCalled);
    boot.stop();
    assertFalse(boot.isInitialized());
    assertTrue(TestLifecycleListener.startupCalled);
    assertTrue(TestLifecycleListener.shutdownCalled);
}
Also used : PentahoSystemBoot(org.pentaho.platform.engine.core.system.boot.PentahoSystemBoot) IPentahoDefinableObjectFactory(org.pentaho.platform.api.engine.IPentahoDefinableObjectFactory) ISolutionEngine(org.pentaho.platform.api.engine.ISolutionEngine) IPentahoSystemListener(org.pentaho.platform.api.engine.IPentahoSystemListener) IPentahoObjectFactory(org.pentaho.platform.api.engine.IPentahoObjectFactory) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 5 with IPentahoObjectFactory

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

Aggregations

IPentahoObjectFactory (org.pentaho.platform.api.engine.IPentahoObjectFactory)32 StandaloneSpringPentahoObjectFactory (org.pentaho.platform.engine.core.system.objfac.StandaloneSpringPentahoObjectFactory)9 IPentahoObjectReference (org.pentaho.platform.api.engine.IPentahoObjectReference)8 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)8 Test (org.junit.Test)7 ObjectFactoryException (org.pentaho.platform.api.engine.ObjectFactoryException)7 StandaloneApplicationContext (org.pentaho.platform.engine.core.system.StandaloneApplicationContext)7 ArrayList (java.util.ArrayList)6 IPentahoDefinableObjectFactory (org.pentaho.platform.api.engine.IPentahoDefinableObjectFactory)6 PathBasedSystemSettings (org.pentaho.platform.engine.core.system.PathBasedSystemSettings)6 PentahoSystemBoot (org.pentaho.platform.engine.core.system.boot.PentahoSystemBoot)5 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)5 Map (java.util.Map)4 ISystemConfig (org.pentaho.platform.api.engine.ISystemConfig)4 HashSet (java.util.HashSet)3 LinkedList (java.util.LinkedList)3 Before (org.junit.Before)3 ApplicationContext (org.springframework.context.ApplicationContext)3 File (java.io.File)2 IOException (java.io.IOException)2