Source code: com/obs/commandline/test/ContactTestClient.java
1 package com.obs.commandline.test;
2 import java.util.Calendar;
3 import java.util.Properties;
4
5 import javax.naming.InitialContext;
6 import javax.rmi.PortableRemoteObject;
7
8 import com.obs.common.contact.views.*;
9
10 import com.obs.ejb.contact.interfaces.ContactController;
11 import com.obs.ejb.contact.interfaces.ContactControllerHome;
12
13 public class ContactTestClient {
14
15 InitialContext jndiContext;
16 ContactControllerHome cchome;
17 ContactController cc;
18
19 public ContactTestClient(boolean runtest) {
20 try
21 {
22 String cid, pid, aid, eid, fid, wid;
23
24 Properties props = new Properties();
25
26 props.setProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
27 props.setProperty("java.naming.provider.url", "localhost:1099");
28 jndiContext = new InitialContext(props);
29
30 Object ref = jndiContext.lookup("com/obs/ejb/contact/ContactControllerEJB");
31
32 cchome = (ContactControllerHome)
33 PortableRemoteObject.narrow (ref, ContactControllerHome.class);
34
35
36 cc = cchome.create();
37 if(runtest){
38
39 cid = this.createContact();
40 pid = this.createPersonInContact(cid);
41 aid = this.createAddressInContact(cid);
42 eid = this.createEMailInContact(cid);
43 fid = this.createPhoneInContact(cid);
44 wid = this.createWebSiteInContact(cid);
45
46 this.dropPersonFromContact(pid,cid);
47 this.dropAddressFromContact(aid,cid);
48 this.dropEMailFromContact(eid,cid);
49 this.dropPhoneFromContact(fid,cid);
50 this.dropWebSiteFromContact(wid,cid);
51
52 this.removeAddress(aid);
53 this.removePerson(pid);
54 this.removeEMail(eid);
55 this.removePhone(fid);
56 this.removeWebSite(wid);
57 this.removeContact(cid);
58 }
59 }
60 catch(Exception e) { e.printStackTrace(); }
61 }
62
63 public void removeContact(String id) throws Exception {
64 System.out.println("Removing Contact");
65 cc.removeContact(id);
66
67 }
68 public void removePerson(String id) throws Exception {
69
70 System.out.println("Removing Person");
71 cc.removePerson(id);
72 }
73 public void removeAddress(String id) throws Exception {
74 System.out.println("Removing Address");
75 cc.removeAddress(id);
76
77 }
78 public void removeEMail(String id) throws Exception {
79 System.out.println("Removing EMail");
80 cc.removeEMail(id);
81
82 }
83 public void removePhone(String id) throws Exception {
84 System.out.println("Removing Phone Number");
85 cc.removePhone(id);
86
87 }
88 public void removeWebSite(String id) throws Exception {
89 System.out.println("Removing Web Site");
90 cc.removeWebSite(id);
91
92 }
93 public void dropPersonFromContact(String pid, String cid) throws Exception {
94 System.out.println("Dropping Person: "+pid+" from Contact: "+cid);
95 cc.dropPerson(pid,cid);
96 }
97 public void dropAddressFromContact(String aid,String cid) throws Exception {
98 System.out.println("Dropping Address: "+aid+" from Contact: "+cid);
99 cc.dropAddress(aid,cid);
100 }
101 public void dropEMailFromContact(String eid, String cid) throws Exception {
102 System.out.println("Dropping EMail: "+eid+" from Contact: "+cid);
103 cc.dropEMail(eid,cid);
104 }
105 public void dropPhoneFromContact(String pid, String cid) throws Exception {
106 System.out.println("Dropping Phone Number: "+pid+" from Contact: "+cid);
107 cc.dropPhone(pid,cid);
108 }
109 public void dropWebSiteFromContact(String wid, String cid) throws Exception {
110 System.out.println("Dropping Web Site: "+wid+" from Contact: "+cid);
111 cc.dropWebSite(wid,cid);
112 }
113
114 public String createContact() throws Exception {
115 return cc.createContact("Test Contact","This is a testing contact");
116 }
117
118 public String createPersonInContact(String contactid) throws Exception {
119 System.out.println("Creating Person");
120 PersonView pv = new PersonView();
121 pv.setFirstName("David");
122 pv.setLastName("Durst");
123 pv.setJobTitle("OBS Project Lead");
124 pv.setSocSecNo("000-00-0000");
125 pv.setNote("Really Tierd");
126 pv.setDateOfBirth(Calendar.getInstance());
127 return cc.createPersonInContact(pv,contactid);
128 }
129 public String createAddressInContact(String contactid) throws Exception {
130 System.out.println("Creating Address");
131
132 AddressView av = new AddressView();
133 System.out.println("Creating Address");
134 av.setStreetLineOne("1234 Somewhere Ave.");
135 av.setStreetLineTwo("Apt. #1111");
136 av.setCity("Los Angeles");
137 av.setState("CA");
138 av.setZipCode("99999");
139 av.setCountry("Unitied States");
140 av.setName("Work Address");
141
142 return cc.createAddressInContact(av,contactid);
143 }
144 public String createEMailInContact(String contactid) throws Exception {
145 System.out.println("Creating EMail");
146
147 EMailView ev = new EMailView();
148 ev.setName("Work E-Mail");
149 ev.setEMail("ddurst@larubber.com");
150
151 return cc.createEMailInContact(ev,contactid);
152 }
153
154 public String createPhoneInContact(String contactid) throws Exception {
155 System.out.println("Creating Phone Number");
156 PhoneView pv = new PhoneView();
157 pv.setName("Work Phone Number");
158 pv.setPhoneNo("555-555-1212");
159
160 return cc.createPhoneInContact(pv,contactid);
161
162 }
163 public String createWebSiteInContact(String contactid) throws Exception {
164 System.out.println("Creating Web Site");
165 WebSiteView wv = new WebSiteView();
166 wv.setWebSite("www.sf.net/projects/obserpcrm");
167 return cc.createWebSiteInContact(wv,contactid);
168 }
169 public static void main(String[] args) {
170 new ContactTestClient(true);
171 }
172 }
173