@Test public void testIgnoringOfNumberFields() logon(TEST_ADMIN_USER); final String prefix = "GanttTest3"; final TaskTree taskTree = taskDao.getTaskTree(); final TaskDO rootTask = initTestDB.addTask(prefix, "root"); final Integer id1 = addTask(prefix + "1", null, null); final Integer id2 = addTask(prefix + "2", null, null); final Integer id3 = addTask(prefix + "3", BigDecimal.TEN, 10); final Integer id4 = addTask(prefix + "4", BigDecimal.TEN, 10); final Integer id5 = addTask(prefix + "5", BigDecimal.TEN, 10); findById(rootObject, id1).setDuration(new BigDecimal("10.000")).setProgress(10); // Modified. findById(rootObject, id3).setDuration(new BigDecimal("2")).setProgress(2); // Modified. findById(rootObject, id4).setDuration(new BigDecimal("10.000")).setProgress(10); // Unmodified findById(rootObject, id5).setDuration(null).setProgress(null); // Modified ganttChartDao.writeGanttObjects(ganttChartDO, rootObject); final String xml = transform(prefix, "<ganttObject id='{}'>" + "<children>" + "<ganttObject id='{1}' duration='10.000' progress='10'/>" assertEquals("check xml output.", xml, ganttChartDO.getGanttObjectsAsXml()); GanttTask ganttObject = ganttChartDao.readGanttObjects(ganttChartDO).getRootObject(); assertDurationAndProgress(ganttObject, id1, BigDecimal.TEN, 10); assertDurationAndProgress(ganttObject, id2, null, null); assertDurationAndProgress(ganttObject, id3, new BigDecimal("2"), 2); assertDurationAndProgress(ganttObject, id4, BigDecimal.TEN, 10); assertDurationAndProgress(ganttObject, id5, null, null);
private String transform(final String prefix, final String str) { final String text = str.replace('\'', '"'); final Pattern p = Pattern.compile("\\{([0-9\\.]*)\\}", Pattern.MULTILINE); final StringBuffer buf = new StringBuffer(); final Matcher m = p.matcher(text); while (m.find()) { if (m.group(1) != null) { final TaskDO task = getTask(prefix + m.group(1)); if (task != null) { m.appendReplacement(buf, String.valueOf(task.getId())); } else { m.appendReplacement(buf, "*** task " + m.group(1) + " not-found***"); } } } m.appendTail(buf); return buf.toString(); }
logon(TEST_ADMIN_USER); final String prefix = "GantChartTest"; final TaskTree taskTree = taskDao.getTaskTree(); taskDao.update(initTestDB.addTask(prefix + "1", prefix).setStartDate(dh.getDate()).setDuration(BigDecimal.TEN)); initTestDB.addTask(prefix + "1.1", prefix + "1"); taskDao.update(initTestDB.addTask(prefix + "2", prefix).setGanttPredecessor(getTask(prefix + "1")) .setDuration(BigDecimal.ONE)); taskDao.update(initTestDB.addTask(prefix + "3", prefix).setGanttPredecessor(getTask(prefix + "2")) .setGanttPredecessorOffset(10) .setDuration(BigDecimal.TEN)); assertEquals("No output because there is no further information in the GanttObject tree.", "", ganttChartDO.getGanttObjectsAsXml()); findById(rootObject, getTask(prefix + "2").getId()).setPredecessorOffset(5).setDuration(new BigDecimal("12")); findById(rootObject, getTask(prefix + "1.1").getId()).setDuration(new BigDecimal("2")); ganttChartDao.writeGanttObjects(ganttChartDO, rootObject); String xml = transform(prefix, "<ganttObject id='{}'>" + "<children>" + "<ganttObject id='{1}'>" ganttChartDao.writeGanttObjects(ganttChartDO, ganttObject); assertEquals(xml, ganttChartDO.getGanttObjectsAsXml()); assertEquals("duration", BigDecimal.TEN, findById(ganttObject, getTask(prefix + "1").getId()).getDuration()); assertEquals("startDate", dh.getDate(), findById(ganttObject, getTask(prefix + "1").getId()).getStartDate()); taskDao.update(getTask(prefix + "1.1").setParentTask(getTask(prefix))); // One level higher taskDao.update(getTask(prefix + "2").setParentTask(getTask(prefix + "II"))); // Moved anywhere. taskDao.update(getTask(prefix + "3").setParentTask(getTask(prefix + "II"))); // Moved anywhere.