use of org.pentaho.platform.api.repository.IRuntimeRepository in project pentaho-platform by pentaho.
the class RuntimeRepositoryTest method doReadOnlyTest.
@SuppressWarnings("unused")
private void doReadOnlyTest(String elementId) {
// $NON-NLS-1$
info(Messages.getInstance().getString("RUNTIMEREPOTEST.USER_TESTINGREADONLY"));
HibernateUtil.beginTransaction();
try {
IRuntimeRepository repo = new RuntimeRepository();
repo.setSession(getPentahoSession());
RuntimeElement baseElement = (RuntimeElement) repo.loadElementById(elementId, null);
// $NON-NLS-1$
info(Messages.getInstance().getString("RUNTIMEREPOTEST.USER_SETTINGELEMENTTOREADONLY"));
baseElement.setReadOnly(true);
} finally {
HibernateUtil.commitTransaction();
}
// Now, the element is read-only.
// Flush the session and re-load the element to
// test the "loaded" methods.
HibernateUtil.flushSession();
HibernateUtil.clear();
// Now, reload the element.
HibernateUtil.beginTransaction();
try {
// $NON-NLS-1$
info(Messages.getInstance().getString("RUNTIMEREPOTEST.USER_LOADINGREADONLY"));
IRuntimeRepository repo = new RuntimeRepository();
repo.setSession(getPentahoSession());
RuntimeElement baseElement = (RuntimeElement) repo.loadElementById(elementId, null);
boolean caughtException = false;
try {
// $NON-NLS-1$
info(Messages.getInstance().getString("RUNTIMEREPOTEST.USER_TRYINGSETSTRINGPROPERTY"));
// $NON-NLS-1$
baseElement.setStringProperty(// $NON-NLS-1$
Messages.getInstance().getString("RUNTIMEREPOTEST.MODIFY_NEW_STRING_KEY"), // $NON-NLS-1$
Messages.getInstance().getString("RUNTIMEREPOTEST.MODIFY_STRING_VALUE"));
} catch (IllegalStateException ex) {
caughtException = true;
// $NON-NLS-1$
info(Messages.getInstance().getString("RUNTIMEREPOTEST.USER_EXCEPTIONTRIPPED"));
}
assertTrue(// $NON-NLS-1$
Messages.getInstance().getErrorString("RUNTIMEREPOTEST.ERROR_0001_EXCEPTIONNOTTRIPPED"), caughtException);
caughtException = false;
try {
// $NON-NLS-1$
info(Messages.getInstance().getString("RUNTIMEREPOTEST.USER_TRYINGSETPARENTTYPE"));
// $NON-NLS-1$
baseElement.setParentType(Messages.getInstance().getString("RUNTIMEREPOTEST.CREATE_PARENT_TYPE"));
} catch (IllegalStateException ex) {
caughtException = true;
// $NON-NLS-1$
info(Messages.getInstance().getString("RUNTIMEREPOTEST.USER_EXCEPTIONTRIPPED"));
}
assertTrue(// $NON-NLS-1$
Messages.getInstance().getErrorString("RUNTIMEREPOTEST.ERROR_0001_EXCEPTIONNOTTRIPPED"), caughtException);
} finally {
HibernateUtil.commitTransaction();
}
}
use of org.pentaho.platform.api.repository.IRuntimeRepository in project pentaho-platform by pentaho.
the class RuntimeRepositoryTest method createRuntimeElement.
@SuppressWarnings("unused")
private RuntimeElement createRuntimeElement() {
IRuntimeRepository repo = new RuntimeRepository();
repo.setSession(getPentahoSession());
RuntimeElement ele = null;
ele = (RuntimeElement) // $NON-NLS-1$
repo.newRuntimeElement(// $NON-NLS-1$
Messages.getInstance().getString("RUNTIMEREPOTEST.CREATE_PARENT"), Messages.getInstance().getString("RUNTIMEREPOTEST.CREATE_PARENT_TYPE"), // $NON-NLS-1$
false);
try {
assertNotNull(ele);
// $NON-NLS-1$
info(Messages.getInstance().getString("RUNTIMEREPOTEST.DEBUG_INSTANCE_ID") + ele.getInstanceId());
// $NON-NLS-1$
ele.setSolutionId(Messages.getInstance().getString("RUNTIMEREPOTEST.SALES_SOLUTION"));
ele.setStringProperty(Messages.getInstance().getString("RUNTIMEREPOTEST.SHORT_STRING_KEY"), // $NON-NLS-1$
Messages.getInstance().getString(// $NON-NLS-1$
"RUNTIMEREPOTEST.SHORT_STRING_VALUE"));
// Get a Long String to Store...
ele.setStringProperty(Messages.getInstance().getString("RUNTIMEREPOTEST.LONG_STRING_KEY"), // $NON-NLS-1$
longString.toString());
// $NON-NLS-1$
ele.setDateProperty(Messages.getInstance().getString("RUNTIMEREPOTEST.DATE_KEY"), new Date());
// $NON-NLS-1$
ele.setBigDecimalProperty(Messages.getInstance().getString("RUNTIMEREPOTEST.DECIMAL_KEY"), bdProperty);
List myList = new ArrayList();
// $NON-NLS-1$
myList.add(Messages.getInstance().getString("RUNTIMEREPOTEST.LIST_ELEMENT_STRING"));
// $NON-NLS-1$
myList.add(new BigDecimal("1283764.1294839483"));
myList.add(new Date());
// $NON-NLS-1$
ele.setListProperty(Messages.getInstance().getString("RUNTIMEREPOTEST.LIST_ELEMENT_KEY"), myList);
} finally {
HibernateUtil.commitTransaction();
}
return ele;
}
use of org.pentaho.platform.api.repository.IRuntimeRepository in project pentaho-platform by pentaho.
the class MultipleComponentIT method testSimpleRuntime.
/*
* public void testReportCharts() { startTest(); SimpleParameterProvider parameterProvider = new
* SimpleParameterProvider(); parameterProvider.setParameter("chart_type", "multipie"); //$NON-NLS-1$ //$NON-NLS-2$
* parameterProvider.setParameter("output-type", "html"); //$NON-NLS-1$ //$NON-NLS-2$ long curTime =
* System.currentTimeMillis(); String testName = RC_TEST_NAME + "multipie_" + curTime; //$NON-NLS-1$ IRuntimeContext
* context = run( "test", "reporting/JFreeReportChartTypes", "JFreeReport_Chart_ChartTypes.xaction",
* parameterProvider, testName, RC_TEST_EXTN); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ assertEquals(
* Messages.getInstance().getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"), IRuntimeContext.RUNTIME_STATUS_SUCCESS,
* context.getStatus()); //$NON-NLS-1$ InputStream is = this.getInputStreamFromOutput(testName, RC_TEST_EXTN);
* assertNotNull(is); try { is.close(); } catch (Exception ignored) { }
*
* parameterProvider.setParameter("chart_type", "line"); //$NON-NLS-1$ //$NON-NLS-2$ testName = RC_TEST_NAME + "line_"
* + curTime; //$NON-NLS-1$ context = run( "test", "reporting/JFreeReportChartTypes",
* "JFreeReport_Chart_ChartTypes.xaction", parameterProvider, testName, RC_TEST_EXTN); //$NON-NLS-1$ //$NON-NLS-2$
* //$NON-NLS-3$ assertEquals( Messages.getInstance().getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"),
* IRuntimeContext.RUNTIME_STATUS_SUCCESS, context.getStatus()); //$NON-NLS-1$ is =
* this.getInputStreamFromOutput(testName, RC_TEST_EXTN); assertNotNull(is); try { is.close(); } catch (Exception
* ignored) { }
*
* parameterProvider.setParameter("chart_type", "area"); //$NON-NLS-1$ //$NON-NLS-2$ testName = RC_TEST_NAME + "area_"
* + curTime; //$NON-NLS-1$ context = run( "test", "reporting/JFreeReportChartTypes",
* "JFreeReport_Chart_ChartTypes.xaction", parameterProvider, testName, RC_TEST_EXTN); //$NON-NLS-1$ //$NON-NLS-2$
* //$NON-NLS-3$ assertEquals( Messages.getInstance().getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"),
* IRuntimeContext.RUNTIME_STATUS_SUCCESS, context.getStatus()); //$NON-NLS-1$ is =
* this.getInputStreamFromOutput(testName, RC_TEST_EXTN); assertNotNull(is); try { is.close(); } catch (Exception
* ignored) { }
*
* parameterProvider.setParameter("chart_type", "stackedarea"); //$NON-NLS-1$ //$NON-NLS-2$ testName = RC_TEST_NAME +
* "stackedarea_" + curTime; //$NON-NLS-1$ context = run( "test", "reporting/JFreeReportChartTypes",
* "JFreeReport_Chart_ChartTypes.xaction", parameterProvider, testName, RC_TEST_EXTN); //$NON-NLS-1$ //$NON-NLS-2$
* //$NON-NLS-3$ assertEquals( Messages.getInstance().getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"),
* IRuntimeContext.RUNTIME_STATUS_SUCCESS, context.getStatus()); //$NON-NLS-1$ is =
* this.getInputStreamFromOutput(testName, RC_TEST_EXTN); assertNotNull(is); try { is.close(); } catch (Exception
* ignored) { }
*
* parameterProvider.setParameter("chart_type", "bar"); //$NON-NLS-1$ //$NON-NLS-2$ testName = RC_TEST_NAME + "bar_" +
* curTime; //$NON-NLS-1$ context = run( "test", "reporting/JFreeReportChartTypes",
* "JFreeReport_Chart_ChartTypes.xaction", parameterProvider, testName, RC_TEST_EXTN); //$NON-NLS-1$ //$NON-NLS-2$
* //$NON-NLS-3$ assertEquals( Messages.getInstance().getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"),
* IRuntimeContext.RUNTIME_STATUS_SUCCESS, context.getStatus()); //$NON-NLS-1$ is =
* this.getInputStreamFromOutput(testName, RC_TEST_EXTN); assertNotNull(is); try { is.close(); } catch (Exception
* ignored) { }
*
* parameterProvider.setParameter("chart_type", "stackedbar"); //$NON-NLS-1$ //$NON-NLS-2$ testName = RC_TEST_NAME +
* "stackedbar_" + curTime; //$NON-NLS-1$ context = run( "test", "reporting/JFreeReportChartTypes",
* "JFreeReport_Chart_ChartTypes.xaction", parameterProvider, testName, RC_TEST_EXTN); //$NON-NLS-1$ //$NON-NLS-2$
* //$NON-NLS-3$ assertEquals( Messages.getInstance().getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"),
* IRuntimeContext.RUNTIME_STATUS_SUCCESS, context.getStatus()); //$NON-NLS-1$ is =
* this.getInputStreamFromOutput(testName, RC_TEST_EXTN); assertNotNull(is); try { is.close(); } catch (Exception
* ignored) { }
*
* parameterProvider.setParameter("chart_type", "stackedbarpercentages"); //$NON-NLS-1$ //$NON-NLS-2$ testName =
* RC_TEST_NAME + "stackedbarpercentages_" + curTime; //$NON-NLS-1$ context = run( "test",
* "reporting/JFreeReportChartTypes", "JFreeReport_Chart_ChartTypes.xaction", parameterProvider, testName,
* RC_TEST_EXTN); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ assertEquals(
* Messages.getInstance().getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"), IRuntimeContext.RUNTIME_STATUS_SUCCESS,
* context.getStatus()); //$NON-NLS-1$ is = this.getInputStreamFromOutput(testName, RC_TEST_EXTN); assertNotNull(is);
* try { is.close(); } catch (Exception ignored) { }
*
* parameterProvider.setParameter("chart_type", "pie"); //$NON-NLS-1$ //$NON-NLS-2$ testName = RC_TEST_NAME + "pie_" +
* curTime; //$NON-NLS-1$ context = run( "test", "reporting/JFreeReportChartTypes",
* "JFreeReport_Chart_ChartTypes.xaction", parameterProvider, testName, RC_TEST_EXTN); //$NON-NLS-1$ //$NON-NLS-2$
* //$NON-NLS-3$ assertEquals( Messages.getInstance().getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"),
* IRuntimeContext.RUNTIME_STATUS_SUCCESS, context.getStatus()); //$NON-NLS-1$ is =
* this.getInputStreamFromOutput(testName, RC_TEST_EXTN); assertNotNull(is); try { is.close(); } catch (Exception
* ignored) { }
*
* finishTest(); }
*/
/*
* public void testDynamicSQLAndSecureFilter() { startTest(); SimpleParameterProvider parameterProvider = new
* SimpleParameterProvider(); // Add no parameters yet for first run String testName = DS_TEST_NAME +
* "parameterResponse_" + System.currentTimeMillis(); //$NON-NLS-1$ IRuntimeContext context = run( "test",
* "reporting", "DynamicSQLSample.xaction", parameterProvider, testName, DS_TEST_EXTN); //$NON-NLS-1$ //$NON-NLS-2$
* //$NON-NLS-3$ assertEquals( Messages.getInstance().getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"),
* IRuntimeContext.RUNTIME_STATUS_SUCCESS, context.getStatus()); //$NON-NLS-1$ // Should have created a Feedback html
* page in the output. InputStream is = this.getInputStreamFromOutput(testName, RC_TEST_EXTN); assertNotNull(is);
* String feedbackHTML = FileHelper.getStringFromInputStream(is); assertNotNull(feedbackHTML); // Make sure it's
* feedback HTML we have...
* assertTrue(feedbackHTML.indexOf("Use this form to supply the parameters required for this content") > 0);
* //$NON-NLS-1$ assertTrue(feedbackHTML.indexOf("Select: Department or Position") > 0); //$NON-NLS-1$ // OK - now,
* supply all the parameters and re-run. parameterProvider.setParameter("deptorposn", "department"); //$NON-NLS-1$
* //$NON-NLS-2$ parameterProvider.setParameter("type", "html"); //$NON-NLS-1$ //$NON-NLS-2$
* parameterProvider.setParameter("region", "Central"); //$NON-NLS-1$ //$NON-NLS-2$ testName = DS_TEST_NAME + "report_"
* + System.currentTimeMillis(); //$NON-NLS-1$ context = run("test", "reporting", "DynamicSQLSample.xaction",
* parameterProvider, testName, DS_TEST_EXTN); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
* assertEquals(context.getStatus(), IRuntimeContext.RUNTIME_STATUS_SUCCESS); // Should have created a report html
* page in the output. is = this.getInputStreamFromOutput(testName, RC_TEST_EXTN); assertNotNull(is); String
* reportHTML = FileHelper.getStringFromInputStream(is); assertNotNull(reportHTML); // Insure it has information
* assertTrue(reportHTML.indexOf("Professional Services") > 0); //$NON-NLS-1$
* assertTrue(reportHTML.indexOf("20,068,039") > 0); //$NON-NLS-1$ finishTest(); }
*/
public void testSimpleRuntime() {
// The simple runtime is used by the standalone distribution.
// This provides some simple tests to exercise the code...
startTest();
StandaloneSession session = // $NON-NLS-1$
new StandaloneSession(Messages.getInstance().getString("BaseTest.DEBUG_JUNIT_SESSION"));
IRuntimeRepository srr = new SimpleRuntimeRepository();
srr.setSession(session);
// $NON-NLS-1$
IRuntimeElement ele1 = srr.loadElementById("instanceid", null);
// $NON-NLS-1$ //$NON-NLS-2$
IRuntimeElement ele2 = srr.newRuntimeElement("parent", "parentType", true);
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
IRuntimeElement ele3 = srr.newRuntimeElement("parentid", "parentType", "solutionId", true);
// $NON-NLS-1$
SimpleRuntimeElement sre = (SimpleRuntimeElement) srr.loadElementById("instanceid", null);
List list = sre.getMessages();
if (list != null) {
for (int i = 0; i < list.size(); i++) {
// $NON-NLS-1$
System.out.println("Message " + (i + 1) + list.get(i));
}
// $NON-NLS-1$
sre.setParentId("parentid1");
// $NON-NLS-1$
sre.setParentType("parentidType1");
// $NON-NLS-1$
sre.setSolutionId("solutionId1");
sre.setReadOnly(true);
boolean isReadOnly = sre.getReadOnly();
String parentId = sre.getParentId();
String parentIdType = sre.getParentType();
String solutionId = sre.getSolutionId();
assertEquals(isReadOnly, true);
// $NON-NLS-1$
assertEquals(parentId, "parentid1");
// $NON-NLS-1$
assertEquals(parentIdType, "parentidType1");
// $NON-NLS-1$
assertEquals(solutionId, "solutionId1");
}
int revision = sre.getRevision();
// $NON-NLS-1$
System.out.println("Revision Value is" + revision);
// $NON-NLS-1$ //$NON-NLS-2$
sre.setStringProperty("parentId", "value");
// $NON-NLS-1$
BigDecimal tstBD = new BigDecimal("2.4");
// $NON-NLS-1$
ele2.setBigDecimalProperty("junkBD", tstBD);
// $NON-NLS-1$
BigDecimal bd = ele2.getBigDecimalProperty("junkBD");
assertEquals(bd, tstBD);
Date tstDT = new Date();
// $NON-NLS-1$
ele3.setDateProperty("junkDT", tstDT);
// $NON-NLS-1$
Date dt = ele3.getDateProperty("junkDT");
assertEquals(tstDT, dt);
List l = new ArrayList();
// $NON-NLS-1$
l.add("one");
// $NON-NLS-1$
l.add("two");
// $NON-NLS-1$
ele1.setListProperty("SOMELIST", l);
// $NON-NLS-1$
assertEquals(ele1.getListProperty("SOMELIST"), l);
Long aLong = new Long(5);
// $NON-NLS-1$
ele2.setLongProperty("SOMELONG", aLong);
// $NON-NLS-1$
assertEquals(ele2.getLongProperty("SOMELONG", null), aLong);
// $NON-NLS-1$
assertEquals(ele2.getLongProperty("SOMELONG", 5), 5);
Map mapProperty = new HashMap();
// $NON-NLS-1$ //$NON-NLS-2$
mapProperty.put("mapKey", "mapValue");
// $NON-NLS-1$
ele3.setMapProperty("SOMEMAP", mapProperty);
// $NON-NLS-1$
assertEquals(ele3.getMapProperty("SOMEMAP"), mapProperty);
// $NON-NLS-1$ //$NON-NLS-2$
ele1.setStringProperty("SOMESTRING", "SomeStringValue");
// $NON-NLS-1$ //$NON-NLS-2$
assertEquals(ele1.getStringProperty("SOMESTRING"), "SomeStringValue");
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
assertEquals(ele2.getStringProperty("DOESNTEXIST", "SomeDefault"), "SomeDefault");
// $NON-NLS-1$
assertNull(ele1.getStringProperty("DOESNTEXIST"));
// $NON-NLS-1$
assertNull(ele1.getBigDecimalProperty("DOESNTEXIST"));
// $NON-NLS-1$
assertNull(ele2.getDateProperty("DOESNTEXIST"));
// $NON-NLS-1$
assertNull(ele3.getListProperty("DOESNTEXIST"));
// $NON-NLS-1$
assertEquals(ele2.getLongProperty("DOESNTEXIST", 2), 2);
// $NON-NLS-1$
assertEquals(ele2.getLongProperty("DOESNTEXIST", new Long(2)), new Long(2));
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
assertEquals(ele1.getBigDecimalProperty("DOESNTEXIST", new BigDecimal("0.23")), new BigDecimal("0.23"));
Date tmpDate = new Date();
// $NON-NLS-1$
assertEquals(ele1.getDateProperty("DOESNTEXIST", tmpDate), tmpDate);
Set parmNames = ele1.getParameterNames();
assertNotNull(parmNames);
assertFalse(srr.usesHibernate());
// $NON-NLS-1$ //$NON-NLS-2$
assertEquals(ele2.getParameterType("SOMELONG"), "java.lang.Long");
// $NON-NLS-1$
assertEquals(ele2.getParentType(), "parentType");
// $NON-NLS-1$
assertEquals(ele3.getParentId(), "parentid");
// $NON-NLS-1$
assertEquals(ele1.getInstanceId(), "instanceid");
finishTest();
}
Aggregations