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