Java Code Examples for net.sf.mpxj.ProjectFile#addResource()
The following examples show how to use
net.sf.mpxj.ProjectFile#addResource() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BasicTest.java From mpxj with GNU Lesser General Public License v2.1 | 4 votes |
/** * This test exercises the automatic generation of WBS and outline levels. */ @Test public void testAutomaticGeneration() throws Exception { ProjectFile file = new ProjectFile(); Resource resource1 = file.addResource(); resource1.setName("R1"); assertEquals(1, resource1.getUniqueID().intValue()); assertEquals(1, resource1.getID().intValue()); Resource resource2 = file.addResource(); resource2.setName("R2"); assertEquals(2, resource2.getUniqueID().intValue()); assertEquals(2, resource2.getID().intValue()); Task task1 = file.addTask(); task1.setName("1.0"); assertEquals("1", task1.getWBS()); assertEquals(1, task1.getOutlineLevel().intValue()); assertEquals("1", task1.getOutlineNumber()); assertEquals(1, task1.getID().intValue()); assertEquals(1, task1.getUniqueID().intValue()); assertFalse(task1.getSummary()); task1 = file.addTask(); task1.setName("2.0"); assertEquals("2", task1.getWBS()); assertEquals(1, task1.getOutlineLevel().intValue()); assertEquals("2", task1.getOutlineNumber()); assertEquals(2, task1.getID().intValue()); assertEquals(2, task1.getUniqueID().intValue()); assertFalse(task1.getSummary()); task1 = file.addTask(); task1.setName("3.0"); assertEquals("3", task1.getWBS()); assertEquals(1, task1.getOutlineLevel().intValue()); assertEquals("3", task1.getOutlineNumber()); assertEquals(3, task1.getID().intValue()); assertEquals(3, task1.getUniqueID().intValue()); assertFalse(task1.getSummary()); Task task2 = task1.addTask(); task2.setName("3.1"); assertEquals("3.1", task2.getWBS()); assertEquals(2, task2.getOutlineLevel().intValue()); assertEquals("3.1", task2.getOutlineNumber()); assertEquals(4, task2.getID().intValue()); assertEquals(4, task2.getUniqueID().intValue()); assertTrue(task1.getSummary()); assertFalse(task2.getSummary()); task2 = task1.addTask(); task2.setName("3.2"); assertEquals("3.2", task2.getWBS()); assertEquals(2, task2.getOutlineLevel().intValue()); assertEquals("3.2", task2.getOutlineNumber()); assertEquals(5, task2.getID().intValue()); assertEquals(5, task2.getUniqueID().intValue()); assertTrue(task1.getSummary()); assertFalse(task2.getSummary()); Task task3 = task2.addTask(); task3.setName("3.2.1"); assertEquals("3.2.1", task3.getWBS()); assertEquals(3, task3.getOutlineLevel().intValue()); assertEquals("3.2.1", task3.getOutlineNumber()); assertEquals(6, task3.getID().intValue()); assertEquals(6, task3.getUniqueID().intValue()); assertTrue(task1.getSummary()); assertTrue(task2.getSummary()); assertFalse(task3.getSummary()); task3 = task2.addTask(); task3.setName("3.2.2"); assertEquals("3.2.2", task3.getWBS()); assertEquals(3, task3.getOutlineLevel().intValue()); assertEquals("3.2.2", task3.getOutlineNumber()); assertEquals(7, task3.getID().intValue()); assertEquals(7, task3.getUniqueID().intValue()); assertTrue(task1.getSummary()); assertTrue(task2.getSummary()); assertFalse(task3.getSummary()); }
Example 2
Source File: BasicTest.java From mpxj with GNU Lesser General Public License v2.1 | 4 votes |
/** * This method exercises resource notes, ensuring that * embedded commas and quotes are handled correctly. * * @throws Exception */ @Test public void testResourceNotes() throws Exception { String notes1 = "Notes, containing a comma. Done."; String notes2 = "Notes \"containing embedded quotes\" Done."; String notes3 = "Notes, \"containing embedded quotes, and comma's too.\" Done."; String notes4 = "\"Notes containing embedded quotes as first and last chars. Done.\""; String notes5 = "Normal unquoted notes. Done."; ProjectFile file1 = new ProjectFile(); Resource resource1 = file1.addResource(); resource1.setName("Test Resource 1"); resource1.setNotes(notes1); Resource resource2 = file1.addResource(); resource2.setName("Test Resource 2"); resource2.setNotes(notes2); Resource resource3 = file1.addResource(); resource3.setName("Test Resource 3"); resource3.setNotes(notes3); Resource resource4 = file1.addResource(); resource4.setName("Test Resource 4"); resource4.setNotes(notes4); Resource resource5 = file1.addResource(); resource5.setName("Test Resource 5"); resource5.setNotes(notes5); File out = File.createTempFile("junit", ".mpx"); new MPXWriter().write(file1, out); ProjectFile file2 = new MPXReader().read(out); String notes; Resource resource1a = file2.getResourceByUniqueID(resource1.getUniqueID()); notes = resource1a.getNotes(); assertEquals(notes1, notes); Resource resource2a = file2.getResourceByUniqueID(resource2.getUniqueID()); notes = resource2a.getNotes(); assertEquals(notes2, notes); Resource resource3a = file2.getResourceByUniqueID(resource3.getUniqueID()); notes = resource3a.getNotes(); assertEquals(notes3, notes); Resource resource4a = file2.getResourceByUniqueID(resource4.getUniqueID()); notes = resource4a.getNotes(); assertEquals(notes4, notes); Resource resource5a = file2.getResourceByUniqueID(resource5.getUniqueID()); notes = resource5a.getNotes(); assertEquals(notes5, notes); out.deleteOnExit(); }
Example 3
Source File: BasicTest.java From mpxj with GNU Lesser General Public License v2.1 | 4 votes |
/** * Write a file with embedded line break (\r and \n) characters in * various text fields. Ensure that a valid file is written, * and that it can be read successfully. * * @throws Exception */ @Test public void testEmbeddedLineBreaks() throws Exception { // // Create a simple MPX file // SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy"); ProjectFile file = new ProjectFile(); file.addDefaultBaseCalendar(); ProjectProperties properties = file.getProjectProperties(); properties.setComments("Project Header Comments: Some\rExample\nText\r\nWith\n\rBreaks"); properties.setStartDate(df.parse("01/01/2003")); Resource resource1 = file.addResource(); resource1.setName("Resource1: Some\rExample\nText\r\nWith\n\rBreaks"); resource1.setNotes("Resource1 Notes: Some\rExample\nText\r\nWith\n\rBreaks"); Task task1 = file.addTask(); task1.setName("Task1: Some\rExample\nText\r\nWith\n\rBreaks"); task1.setNotes("Task1 Notes: Some\rExample\nText\r\nWith\n\rBreaks"); // // Write the file // File out = File.createTempFile("junit", ".mpx"); new MPXWriter().write(file, out); // // Ensure we can read it successfully // file = new MPXReader().read(out); assertEquals(1, file.getTasks().size()); assertEquals(1, file.getResources().size()); properties = file.getProjectProperties(); assertEquals("Project Header Comments: Some\nExample\nText\nWith\nBreaks", properties.getComments()); task1 = file.getTaskByUniqueID(Integer.valueOf(1)); assertEquals("Task1: Some\nExample\nText\nWith\nBreaks", task1.getName()); assertEquals("Task1 Notes: Some\nExample\nText\nWith\nBreaks", task1.getNotes()); resource1 = file.getResourceByUniqueID(Integer.valueOf(1)); assertEquals("Resource1: Some\nExample\nText\nWith\nBreaks", resource1.getName()); assertEquals("Resource1 Notes: Some\nExample\nText\nWith\nBreaks", resource1.getNotes()); out.deleteOnExit(); }