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);
}
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();
}
}
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());
}
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);
}
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);
}
Aggregations