1 18 19 package cowsultants.itracker.ejb.test; 20 21 import java.rmi.*; 22 import java.sql.*; 23 import java.util.*; 24 import javax.rmi.*; 25 import javax.sql.*; 26 import javax.naming.*; 27 import javax.ejb.CreateException ; 28 29 import junit.framework.*; 30 31 import cowsultants.itracker.ejb.beans.entity.*; 32 import cowsultants.itracker.ejb.client.models.*; 33 import cowsultants.itracker.ejb.client.interfaces.*; 34 35 public class TestProjectHandler extends TestCase { 36 private InitialContext ic; 37 private Object phRef; 38 private ProjectHandlerHome phHome; 39 private ProjectHandler ph; 40 41 public TestProjectHandler(String name) { 42 super(name); 43 } 44 45 public void testCreateDeleteProject() { 46 try { 47 boolean status = false; 48 49 ProjectModel pModel = new ProjectModel(); 50 pModel.setName("Test Project"); 51 pModel.setDescription("Test Project Description"); 52 pModel = ph.createProject(pModel); 53 54 assertNotNull("Create project returned null model", pModel); 55 assertNotNull("Create project did not assign id", pModel.getId()); 56 57 ProjectModel pModel2 = ph.createProject(pModel); 58 59 ProjectModel[] projects = ph.getAllProjects(); 60 assertNotNull("All projects lookup returned null array", projects); 61 assertTrue("All projects lookup returned incorrect number or projects", projects.length == 2); 62 63 status = ph.deleteProject(pModel); 64 assertTrue("Delete project returned false for project 1", status); 65 status = ph.deleteProject(pModel2); 66 assertTrue("Delete project returned false for project 2", status); 67 68 projects = ph.getAllProjects(); 69 assertNotNull("Projects list was null", projects); 70 assertTrue("Project list did not contain 0 elements after removal", projects.length == 0); 71 } catch(Exception e) { 72 fail("Exception in test caught: " + e.toString()); 73 } 74 } 75 76 public void testProjectLookup() { 77 try { 78 ProjectModel pModel = new ProjectModel(); 79 pModel.setName("Test Project"); 80 pModel.setDescription("Test Project Description"); 81 pModel = ph.createProject(pModel); 82 83 ProjectModel testProjectModel = ph.getProject(pModel.getId()); 84 assertNotNull("Project lookup returned null value", testProjectModel); 85 assertTrue("Project lookup did not return correct test data", testProjectModel.getId().equals(pModel.getId())); 86 assertTrue("Project lookup did not return correct test data", testProjectModel.getName().equals(pModel.getName())); 87 88 ph.deleteProject(pModel); 89 } catch(Exception e) { 90 fail("Exception in test caught: " + e.toString()); 91 } 92 } 93 94 public void testManageComponents() { 95 try { 96 ProjectModel pModel = new ProjectModel(); 97 pModel.setName("Test Project"); 98 pModel.setDescription("Test Project Description"); 99 pModel = ph.createProject(pModel); 100 101 ComponentModel cModel = new ComponentModel(); 102 cModel.setName("Test Component"); 103 cModel.setDescription("Test Component Description"); 104 105 cModel = ph.addProjectComponent(pModel.getId(), cModel); 106 assertNotNull("Component addition returned null value", cModel); 107 assertNotNull("Component not assigned id on addition to project", cModel.getId()); 108 109 ProjectModel testProjectModel = ph.getProject(pModel.getId()); 110 assertNotNull("Project lookup returned null value", testProjectModel); 111 assertTrue("Project lookup did not return correct test data", testProjectModel.getId().equals(pModel.getId())); 112 assertTrue("Project lookup did not return correct test data", testProjectModel.getName().equals(pModel.getName())); 113 114 ComponentModel[] components = ph.getProjectComponents(testProjectModel.getId()); 115 assertNotNull("Project component list was null", components); 116 assertTrue("Project did not contain 1 component", components.length == 1); 117 assertTrue("Component data did not match test data", cModel.getName().equals(components[0].getName())); 118 119 boolean status = ph.removeProjectComponent(testProjectModel.getId(), cModel.getId()); 120 assertTrue("Remove component returned false", status); 121 components = ph.getProjectComponents(testProjectModel.getId()); 122 assertNotNull("Project component list was null", components); 123 assertTrue("Project did not contain 0 components after removal", components.length == 0); 124 125 ph.deleteProject(pModel); 126 } catch(Exception e) { 127 fail("Exception in test caught: " + e.toString()); 128 } 129 } 130 131 public void setUp() { 132 try { 133 ic = new InitialContext(); 134 135 phRef = ic.lookup(ProjectHandler.JNDI_NAME); 136 phHome = (ProjectHandlerHome) PortableRemoteObject.narrow(phRef, ProjectHandlerHome.class); 137 ph = phHome.create(); 138 } catch(Exception e) { 139 fail("Exception in setup caught: " + e.toString()); 140 } 141 } 142 143 public void tearDown() { 144 } 145 146 public static Test suite() { 147 return new TestSuite(TestProjectHandler.class); 148 } 149 150 } 151 | Popular Tags |