public void testToSqlDate() throws BirtException { java.sql.Date date = DataTypeUtil.toSqlDate("1999-2-11"); Calendar cal = Calendar.getInstance(); cal.clear(); cal.set(1999, 1, 11); cal.getTime(); assertEquals(cal.getTime(), date); try { java.sql.Date date1 = DataTypeUtil.toSqlDate("99-2-11"); cal.set(99, 1, 11); assertEquals(cal.getTime(), date1); } catch (BirtException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { java.sql.Date date1 = DataTypeUtil.toSqlDate("9921111"); assertEquals(cal.getTime(), date1); fail("Should not arrive here"); } catch (BirtException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
/** Test passing reportContext */ @SuppressWarnings("unchecked") @Test public void testExecute1() { try { final IReportEngine reportEngine = ReportEngine.getReportEngine(); final InputStream is = this.getClass().getResourceAsStream("/reports/test_display_parameters.rptdesign"); final IReportRunnable design = reportEngine.openReportDesign(is); final IGetParameterDefinitionTask paramTask = reportEngine.createGetParameterDefinitionTask(design); List<EngineException> errors = null; try { final IRunAndRenderTask rrTask = reportEngine.createRunAndRenderTask(design); final Map<String, Object> appContext = rrTask.getAppContext(); final ClassLoader classLoader = getClass().getClassLoader(); appContext.put(EngineConstants.APPCONTEXT_CLASSLOADER_KEY, classLoader); // rrTask.setAppContext(appContext); try { final ByteArrayOutputStream os = new ByteArrayOutputStream(); final RenderOption options = new HTMLRenderOption(); options.setOutputFormat("HTML"); options.setOutputStream(os); rrTask.setRenderOption(options); rrTask.run(); errors = rrTask.getErrors(); String output = os.toString("utf-8"); System.out.println(output); Assert.assertTrue(output.indexOf("Australian Collectors, Co.") >= 0); Assert.assertTrue(output.indexOf("NewParameter") >= 0); Assert.assertTrue(output.indexOf("abc") >= 0); } finally { rrTask.close(); } } finally { paramTask.close(); } if (errors != null) { Iterator<EngineException> iterator = errors.iterator(); if (iterator.hasNext()) { EngineException error = iterator.next(); Assert.fail("Engine exception: " + error.getMessage()); } } } catch (UnsupportedEncodingException e) { e.printStackTrace(); Assert.fail(e.toString()); } catch (BirtException e) { e.printStackTrace(); Assert.fail(e.toString()); } }
public void testToBoolean() { Boolean result; for (int i = 0; i < testObject.length; i++) { System.out.println(i); try { result = DataTypeUtil.toBoolean(testObject[i]); if (resultBoolean[i] instanceof Exception) fail("Should throw Exception."); assertEquals(result, resultBoolean[i]); } catch (BirtException dteEx) { if (!(resultBoolean[i] instanceof Exception)) fail("Should not throw Exception."); } } try { assertTrue(DataTypeUtil.toBoolean(new Double(0.1)).booleanValue()); assertTrue(DataTypeUtil.toBoolean(new Double(-0.1)).booleanValue()); assertTrue(DataTypeUtil.toBoolean(new Double(1)).booleanValue()); assertTrue(DataTypeUtil.toBoolean(new Double(1)).booleanValue()); assertFalse(DataTypeUtil.toBoolean(new Double(0)).booleanValue()); } catch (BirtException e) { // TODO Auto-generated catch block e.printStackTrace(); } }