use of org.pentaho.platform.engine.core.system.StandaloneSession in project pentaho-platform by pentaho.
the class DefaultBackingRepositoryLifecycleManager method loginAsRepositoryAdmin.
protected void loginAsRepositoryAdmin() {
StandaloneSession pentahoSession = new StandaloneSession(repositoryAdminUsername);
pentahoSession.setAuthenticated(repositoryAdminUsername);
final List<GrantedAuthority> repositoryAdminAuthorities = new ArrayList<GrantedAuthority>();
final String password = "ignored";
UserDetails repositoryAdminUserDetails = new User(repositoryAdminUsername, password, true, true, true, true, repositoryAdminAuthorities);
Authentication repositoryAdminAuthentication = new UsernamePasswordAuthenticationToken(repositoryAdminUserDetails, password, repositoryAdminAuthorities);
PentahoSessionHolder.setSession(pentahoSession);
// this line necessary for Spring Security's MethodSecurityInterceptor
SecurityContextHolder.getContext().setAuthentication(repositoryAdminAuthentication);
}
use of org.pentaho.platform.engine.core.system.StandaloneSession in project pentaho-platform by pentaho.
the class MondrianCatalogHelperIT method testAddCatalog.
@Test
public void testAddCatalog() throws Exception {
final String mondrianFolderPath = ClientRepositoryPaths.getEtcFolderPath() + RepositoryFile.SEPARATOR + "mondrian";
UnifiedRepositoryTestUtils.stubGetFolder(repo, mondrianFolderPath);
// return no children
UnifiedRepositoryTestUtils.stubGetChildren(repo, mondrianFolderPath);
final String steelWheelsFolderPath = mondrianFolderPath + RepositoryFile.SEPARATOR + CATALOG_NAME;
UnifiedRepositoryTestUtils.stubGetFileDoesNotExist(repo, steelWheelsFolderPath);
UnifiedRepositoryTestUtils.stubCreateFolder(repo, steelWheelsFolderPath);
final String metadataPath = steelWheelsFolderPath + RepositoryFile.SEPARATOR + "metadata";
UnifiedRepositoryTestUtils.stubCreateFile(repo, metadataPath);
final String olapFolderPath = ClientRepositoryPaths.getEtcFolderPath() + RepositoryFile.SEPARATOR + "olap-servers";
UnifiedRepositoryTestUtils.stubGetFolder(repo, olapFolderPath);
// return no children
UnifiedRepositoryTestUtils.stubGetChildren(repo, olapFolderPath);
IPentahoSession session = new StandaloneSession("admin");
MondrianCatalog cat = createTestCatalog();
File file = new File(TestResourceLocation.TEST_RESOURCES + "/solution/test/charts/steelwheels.mondrian.xml");
String mondrianSchema = IOUtils.toString(new FileInputStream(file));
session.setAttribute("MONDRIAN_SCHEMA_XML_CONTENT", mondrianSchema);
MondrianCatalogHelper helperSpy = spy(helper);
IAclNodeHelper aclNodeHelper = mock(IAclNodeHelper.class);
doNothing().when(aclNodeHelper).setAclFor(any(RepositoryFile.class), any(RepositoryFileAcl.class));
doReturn(aclNodeHelper).when(helperSpy).getAclHelper();
doReturn(true).when(helperSpy).catalogExists(any(MondrianCatalog.class), eq(session));
helperSpy.addCatalog(cat, true, session);
verify(repo).createFile(eq(UnifiedRepositoryTestUtils.makeIdObject(steelWheelsFolderPath)), argThat(UnifiedRepositoryTestUtils.isLikeFile(UnifiedRepositoryTestUtils.makeFileObject(metadataPath))), argThat(UnifiedRepositoryTestUtils.hasData(UnifiedRepositoryTestUtils.pathPropertyPair("/catalog/definition", "mondrian:/" + cat.getName()), UnifiedRepositoryTestUtils.pathPropertyPair("/catalog/datasourceInfo", cat.getDataSourceInfo()))), anyString());
verify(repo).createFile(eq(UnifiedRepositoryTestUtils.makeIdObject(steelWheelsFolderPath)), argThat(UnifiedRepositoryTestUtils.isLikeFile(UnifiedRepositoryTestUtils.makeFileObject(steelWheelsFolderPath + RepositoryFile.SEPARATOR + "schema.xml"))), any(IRepositoryFileData.class), anyString());
// cache should be cleared for this schema only
verify(olapService, times(1)).getConnection(CATALOG_NAME, session);
verify(mondrianCacheControl, times(1)).flushSchema(this.mondrianSchema);
}
use of org.pentaho.platform.engine.core.system.StandaloneSession in project pentaho-platform by pentaho.
the class MondrianCatalogHelperIT method testNoDspApplied_WhenNoDynamicSchemaProcessorParameterInDataSourceInfo.
@Test
public void testNoDspApplied_WhenNoDynamicSchemaProcessorParameterInDataSourceInfo() throws Exception {
final String replaceTemplate = "REPLACE_TEMPLATE";
final String DATA_SOURCE_INFO_WITHOUT_DSP = "DataSource=TestDataSource";
final String SCHEMA_MOCK = "Test Schema Mock " + replaceTemplate;
MondrianCatalogHelper helperSpy = spy(helper);
doReturn(SCHEMA_MOCK).when(helperSpy).docAtUrlToString(anyString(), any(IPentahoSession.class));
IPentahoSession session = new StandaloneSession("admin");
String schema = helperSpy.applyDSP(session, DATA_SOURCE_INFO_WITHOUT_DSP, SCHEMA_MOCK);
assertNotNull(schema);
verify(helperSpy).docAtUrlToString(anyString(), any(IPentahoSession.class));
assertFalse(schema.contains("REPLACE_TOKEN"));
}
use of org.pentaho.platform.engine.core.system.StandaloneSession in project pentaho-platform by pentaho.
the class ChartIT method testChartHelper_Null.
/*
* public void testCategoryAreaChart() { runCategoryChartTest(JFreeChartEngine.AREA_CHART_TYPE,
* "test/charts/areaChart.xml", "testAreaChart"); //$NON-NLS-1$ //$NON-NLS-2$ }
*
* public void testCategoryBarChart() { runCategoryChartTest(JFreeChartEngine.BAR_CHART_TYPE,
* "test/charts/barChart.xml", "testBarChart"); //$NON-NLS-1$ //$NON-NLS-2$ }
*
* public void testCategoryLineChart() { runCategoryChartTest(JFreeChartEngine.LINE_CHART_TYPE,
* "test/charts/lineChart.xml", "testLineChart"); //$NON-NLS-1$ //$NON-NLS-2$ }
*
* public void testPieChart() { runPieChartTest(JFreeChartEngine.PIE_CHART_TYPE, "test/charts/pieChart.xml",
* "testPieChart"); //$NON-NLS-1$ //$NON-NLS-2$ }
*/
/*
* public void testChartHelper_DialChart() { String region = "Central"; //$NON-NLS-1$ ArrayList messages = new
* ArrayList(); SimpleParameterProvider parameters = new SimpleParameterProvider();
* parameters.setParameter("image-width", "450"); //$NON-NLS-1$ //$NON-NLS-2$ parameters.setParameter("image-height",
* "300"); //$NON-NLS-1$ //$NON-NLS-2$ parameters.setParameter("REGION", region); //$NON-NLS-1$
* parameters.setParameter("outer-params", "REGION"); //$NON-NLS-1$ //$NON-NLS-2$
* parameters.setParameter("inner-param", "DEPARTMENT"); //$NON-NLS-1$ //$NON-NLS-2$ parameters.setParameter(
* "drill-url", "SampleDashboard.jsp?region=" + region + "&department={DEPARTMENT}&measure={measure}");
* //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ parameters.setParameter("series-name", "measure"); //$NON-NLS-1$
* //$NON-NLS-2$ parameters.setParameter("chart-type", "DialChart"); //$NON-NLS-1$ //$NON-NLS-2$
* parameters.setParameter("value", "550"); //$NON-NLS-1$ //$NON-NLS-2$ StringBuffer content = new StringBuffer();
* StandaloneSession session = new StandaloneSession(Messages.getString("BaseTest.DEBUG_JUNIT_SESSION"));
* //$NON-NLS-1$ ChartHelper.doChart("/test-src/solutions/samples/dashboard/departments.widget.xml", parameters,
* content, session, messages, null); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ try { OutputStream os =
* getOutputStream(SOLUTION_PATH, "ChartTest.testChartHelper_DialChart", ".html"); //$NON-NLS-1$ //$NON-NLS-2$
* os.write(content.toString().getBytes()); } catch (Exception e) {
*
* } }
*
* public void testChartHelper_PieChart() { String region = "Central"; //$NON-NLS-1$ ArrayList messages = new
* ArrayList(); SimpleParameterProvider parameters = new SimpleParameterProvider();
* parameters.setParameter("image-width", "450"); //$NON-NLS-1$ //$NON-NLS-2$ parameters.setParameter("image-height",
* "300"); //$NON-NLS-1$ //$NON-NLS-2$ parameters.setParameter("REGION", region); //$NON-NLS-1$
* parameters.setParameter("outer-params", "REGION"); //$NON-NLS-1$ //$NON-NLS-2$
* parameters.setParameter("inner-param", "DEPARTMENT"); //$NON-NLS-1$ //$NON-NLS-2$ parameters.setParameter(
* "drill-url", "SampleDashboard.jsp?region=" + region + "&department={DEPARTMENT}&measure={measure}");
* //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ parameters.setParameter("series-name", "measure"); //$NON-NLS-1$
* //$NON-NLS-2$ parameters.setParameter("chart-type", "PieChart"); //$NON-NLS-1$ //$NON-NLS-2$ StringBuffer content =
* new StringBuffer(); StandaloneSession session = new
* StandaloneSession(Messages.getString("BaseTest.DEBUG_JUNIT_SESSION")); //$NON-NLS-1$
* ChartHelper.doChart("/test-src/solutions/samples/dashboard/departments.widget.xml", parameters, content, session,
* messages, null); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ try { OutputStream os = getOutputStream(SOLUTION_PATH,
* "ChartTest.testChartHelper_PieChart", ".html"); //$NON-NLS-1$ //$NON-NLS-2$
* os.write(content.toString().getBytes()); } catch (Exception e) {
*
* } }
*
* public void testChartHelper_PieGrid() { String region = "Central"; //$NON-NLS-1$ ArrayList messages = new
* ArrayList(); SimpleParameterProvider parameters = new SimpleParameterProvider();
* parameters.setParameter("image-width", "450"); //$NON-NLS-1$ //$NON-NLS-2$ parameters.setParameter("image-height",
* "300"); //$NON-NLS-1$ //$NON-NLS-2$ parameters.setParameter("REGION", region); //$NON-NLS-1$
* parameters.setParameter("outer-params", "REGION"); //$NON-NLS-1$ //$NON-NLS-2$
* parameters.setParameter("inner-param", "DEPARTMENT"); //$NON-NLS-1$ //$NON-NLS-2$ parameters.setParameter(
* "drill-url", "SampleDashboard.jsp?region=" + region + "&department={DEPARTMENT}&measure={measure}");
* //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ parameters.setParameter("series-name", "measure"); //$NON-NLS-1$
* //$NON-NLS-2$ parameters.setParameter("chart-type", "PieGrid"); //$NON-NLS-1$ //$NON-NLS-2$ StringBuffer content =
* new StringBuffer(); StandaloneSession session = new
* StandaloneSession(Messages.getString("BaseTest.DEBUG_JUNIT_SESSION")); //$NON-NLS-1$
* ChartHelper.doChart(/test-src/solutions/samples/dashboard/departments.widget.xml", parameters, content, session,
* messages, null); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ try { OutputStream os = getOutputStream(SOLUTION_PATH,
* "ChartTest.testChartHelper_PieGrid", ".html"); //$NON-NLS-1$ //$NON-NLS-2$ os.write(content.toString().getBytes());
* } catch (Exception e) {
*
* } }
*
* public void testChartHelper_BarChart() { String region = "Central"; //$NON-NLS-1$ ArrayList messages = new
* ArrayList(); SimpleParameterProvider parameters = new SimpleParameterProvider();
* parameters.setParameter("image-width", "450"); //$NON-NLS-1$ //$NON-NLS-2$ parameters.setParameter("image-height",
* "300"); //$NON-NLS-1$ //$NON-NLS-2$ parameters.setParameter("REGION", region); //$NON-NLS-1$
* parameters.setParameter("outer-params", "REGION"); //$NON-NLS-1$ //$NON-NLS-2$
* parameters.setParameter("inner-param", "DEPARTMENT"); //$NON-NLS-1$ //$NON-NLS-2$ parameters.setParameter(
* "drill-url", "SampleDashboard.jsp?region=" + region + "&department={DEPARTMENT}&measure={measure}");
* //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ parameters.setParameter("series-name", "measure"); //$NON-NLS-1$
* //$NON-NLS-2$ parameters.setParameter("chart-type", "BarChart"); //$NON-NLS-1$ //$NON-NLS-2$ StringBuffer content =
* new StringBuffer(); StandaloneSession session = new
* StandaloneSession(Messages.getString("BaseTest.DEBUG_JUNIT_SESSION")); //$NON-NLS-1$
* ChartHelper.doChart("/test-src/solutions/samples/dashboard/departments.widget.xml", parameters, content, session,
* messages, null); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ try { OutputStream os = getOutputStream(SOLUTION_PATH,
* "ChartTest.testChartHelper_BarChart", ".html"); //$NON-NLS-1$ //$NON-NLS-2$
* os.write(content.toString().getBytes()); } catch (Exception e) {
*
* } }
*/
/*
* public void testChartHelper_LineChart() { String region = "Central"; //$NON-NLS-1$ ArrayList messages = new
* ArrayList(); SimpleParameterProvider parameters = new SimpleParameterProvider();
* parameters.setParameter("image-width", "450"); //$NON-NLS-1$ //$NON-NLS-2$ parameters.setParameter("image-height",
* "300"); //$NON-NLS-1$ //$NON-NLS-2$ parameters.setParameter("REGION", region); //$NON-NLS-1$
* parameters.setParameter("outer-params", "REGION"); //$NON-NLS-1$ //$NON-NLS-2$
* parameters.setParameter("inner-param", "DEPARTMENT"); //$NON-NLS-1$ //$NON-NLS-2$ parameters.setParameter(
* "drill-url", "SampleDashboard.jsp?region=" + region + "&department={DEPARTMENT}&measure={measure}");
* //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ parameters.setParameter("series-name", "measure"); //$NON-NLS-1$
* //$NON-NLS-2$ parameters.setParameter("chart-type", "LineChart"); //$NON-NLS-1$ //$NON-NLS-2$ StringBuffer content
* = new StringBuffer(); StandaloneSession session = new
* StandaloneSession(Messages.getString("BaseTest.DEBUG_JUNIT_SESSION")); //$NON-NLS-1$
* ChartHelper.doChart("/test-src/solutions/samples/dashboard/departments.widget.xml", parameters, content, session,
* messages, null); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ try { OutputStream os = getOutputStream(SOLUTION_PATH,
* "ChartTest.testChartHelper_LineChart", ".html"); //$NON-NLS-1$ //$NON-NLS-2$
* os.write(content.toString().getBytes()); } catch (Exception e) {
*
* } }
*/
/*
* public void testChartHelper_AreaChart() { String region = "Central"; //$NON-NLS-1$ ArrayList messages = new
* ArrayList(); SimpleParameterProvider parameters = new SimpleParameterProvider();
* parameters.setParameter("image-width", "450"); //$NON-NLS-1$ //$NON-NLS-2$ parameters.setParameter("image-height",
* "300"); //$NON-NLS-1$ //$NON-NLS-2$ parameters.setParameter("REGION", region); //$NON-NLS-1$
* parameters.setParameter("outer-params", "REGION"); //$NON-NLS-1$ //$NON-NLS-2$
* parameters.setParameter("inner-param", "DEPARTMENT"); //$NON-NLS-1$ //$NON-NLS-2$
* parameters.setParameter("connection", "SampleData"); //$NON-NLS-1$ //$NON-NLS-2$ parameters.setParameter("query",
* "select REGION, DEPARTMENT, MANAGER_NAME, EMAIL from DEPARTMENT_MANAGERS"); //$NON-NLS-1$ //$NON-NLS-2$
* parameters.setParameter( "drill-url", "SampleDashboard.jsp?region=" + region +
* "&department={DEPARTMENT}&measure={measure}"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
* parameters.setParameter("series-name", "measure"); //$NON-NLS-1$ //$NON-NLS-2$
* parameters.setParameter("chart-type", "AreaChart"); //$NON-NLS-1$ //$NON-NLS-2$ StringBuffer content = new
* StringBuffer(); StandaloneSession session = new
* StandaloneSession(Messages.getString("BaseTest.DEBUG_JUNIT_SESSION")); //$NON-NLS-1$
* ChartHelper.doChart("/test-src/solutions/samples/dashboard/departments.widget.xml", parameters, content, session,
* messages, null); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ try { OutputStream os = getOutputStream(SOLUTION_PATH,
* "ChartTest.testChartHelper_AreaChart", ".html"); //$NON-NLS-1$ //$NON-NLS-2$
* os.write(content.toString().getBytes()); } catch (Exception e) {
*
* } }
*/
public void testChartHelper_Null() {
// $NON-NLS-1$
String region = "Central";
ArrayList messages = new ArrayList();
SimpleParameterProvider parameters = new SimpleParameterProvider();
// $NON-NLS-1$ //$NON-NLS-2$
parameters.setParameter("image-width", "450");
// $NON-NLS-1$ //$NON-NLS-2$
parameters.setParameter("image-height", "300");
// $NON-NLS-1$
parameters.setParameter("REGION", region);
// $NON-NLS-1$ //$NON-NLS-2$
parameters.setParameter("outer-params", "REGION");
// $NON-NLS-1$ //$NON-NLS-2$
parameters.setParameter("inner-param", "DEPARTMENT");
parameters.setParameter("drill-url", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
"SampleDashboard.jsp?region=" + region + "&department={DEPARTMENT}&measure={measure}");
// $NON-NLS-1$ //$NON-NLS-2$
parameters.setParameter("series-name", "measure");
// $NON-NLS-1$ //$NON-NLS-2$
parameters.setParameter("chart-type", "");
StringBuffer content = new StringBuffer();
StandaloneSession session = // $NON-NLS-1$
new StandaloneSession(Messages.getInstance().getString("BaseTest.DEBUG_JUNIT_SESSION"));
PentahoSessionHolder.setSession(session);
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
ChartHelper.doChart("/samples/dashboard/departments.widget.xml", parameters, content, session, messages, null);
try {
// $NON-NLS-1$ //$NON-NLS-2$
OutputStream os = getOutputStream("ChartTest.testChartHelper_Null", ".html");
os.write(content.toString().getBytes());
} catch (Exception e) {
// ignore
}
}
use of org.pentaho.platform.engine.core.system.StandaloneSession in project pentaho-platform by pentaho.
the class ChartbeansIT method init0.
@Before
public void init0() {
microPlatform = new MicroPlatform(TestResourceLocation.TEST_RESOURCES + "/solution/");
microPlatform.define(ISolutionEngine.class, SolutionEngine.class);
microPlatform.define(IChartBeansGenerator.class, DefaultChartBeansGenerator.class);
microPlatform.define(IUnifiedRepository.class, FileSystemBackedUnifiedRepository.class, Scope.GLOBAL);
FileSystemBackedUnifiedRepository repo = (FileSystemBackedUnifiedRepository) PentahoSystem.get(IUnifiedRepository.class);
repo.setRootDir(new File(TestResourceLocation.TEST_RESOURCES + "/solution"));
session = new StandaloneSession();
}
Aggregations