KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > cowsultants > itracker > ejb > test > TestProjectHandler


1 /*
2  * This software was designed and created by Jason Carroll.
3  * Copyright (c) 2002, 2003, 2004 Jason Carroll.
4  * The author can be reached at jcarroll@cowsultants.com
5  * ITracker website: http://www.cowsultants.com
6  * ITracker forums: http://www.cowsultants.com/phpBB/index.php
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it only under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  */

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 JavaDoc;
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 JavaDoc phRef;
38     private ProjectHandlerHome phHome;
39     private ProjectHandler ph;
40
41     public TestProjectHandler(String JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc 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