KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > cowsultants > itracker > web > test > TestIssueService


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.web.test;
20
21 import java.io.*;
22 import java.util.*;
23 import java.net.*;
24
25 import org.apache.axis.*;
26 import org.apache.axis.attachments.*;
27 import org.apache.axis.client.*;
28 import org.apache.axis.encoding.*;
29 import org.apache.axis.utils.*;
30
31 import javax.activation.*;
32 import javax.xml.namespace.QName JavaDoc;
33 import javax.xml.rpc.ParameterMode JavaDoc;
34
35 import cowsultants.itracker.ejb.client.models.*;
36 import cowsultants.itracker.ejb.client.util.*;
37
38 public class TestIssueService {
39
40     public static void main(String JavaDoc[] args) throws Exception JavaDoc {
41         if(args == null || args.length != 3) {
42             System.out.println("Usage: java TestIssueService <wsurl> <userid> <password>");
43             return;
44         }
45
46         try {
47             Service service = new Service();
48             Call call = (Call) service.createCall();
49
50             QName JavaDoc qnGeneric = new QName JavaDoc("urn:itracker", "genericmodel");
51             call.registerTypeMapping(GenericModel.class, qnGeneric,
52                           new org.apache.axis.encoding.ser.BeanSerializerFactory(GenericModel.class, qnGeneric),
53                           new org.apache.axis.encoding.ser.BeanDeserializerFactory(GenericModel.class, qnGeneric));
54
55             QName JavaDoc qnIssue = new QName JavaDoc("urn:itracker", "issue");
56             call.registerTypeMapping(IssueModel.class, qnIssue,
57                           new org.apache.axis.encoding.ser.BeanSerializerFactory(IssueModel.class, qnIssue),
58                           new org.apache.axis.encoding.ser.BeanDeserializerFactory(IssueModel.class, qnIssue));
59
60             QName JavaDoc qnIssueField = new QName JavaDoc("urn:itracker", "issuefield");
61             call.registerTypeMapping(IssueFieldModel.class, qnIssueField,
62                           new org.apache.axis.encoding.ser.BeanSerializerFactory(IssueFieldModel.class, qnIssueField),
63                           new org.apache.axis.encoding.ser.BeanDeserializerFactory(IssueFieldModel.class, qnIssueField));
64
65             QName JavaDoc qnIssueHistory = new QName JavaDoc("urn:itracker", "issuehistory");
66             call.registerTypeMapping(IssueHistoryModel.class, qnIssueHistory,
67                           new org.apache.axis.encoding.ser.BeanSerializerFactory(IssueHistoryModel.class, qnIssueHistory),
68                           new org.apache.axis.encoding.ser.BeanDeserializerFactory(IssueHistoryModel.class, qnIssueHistory));
69
70             QName JavaDoc qnIssueAttachment = new QName JavaDoc("urn:itracker", "issueattachment");
71             call.registerTypeMapping(IssueAttachmentModel.class, qnIssueAttachment,
72                           new org.apache.axis.encoding.ser.BeanSerializerFactory(IssueAttachmentModel.class, qnIssueAttachment),
73                           new org.apache.axis.encoding.ser.BeanDeserializerFactory(IssueAttachmentModel.class, qnIssueAttachment));
74
75             QName JavaDoc qnComponent = new QName JavaDoc("urn:itracker", "component");
76             call.registerTypeMapping(ComponentModel.class, qnComponent,
77                           new org.apache.axis.encoding.ser.BeanSerializerFactory(ComponentModel.class, qnComponent),
78                           new org.apache.axis.encoding.ser.BeanDeserializerFactory(ComponentModel.class, qnComponent));
79
80             QName JavaDoc qnVersion = new QName JavaDoc("urn:itracker", "version");
81             call.registerTypeMapping(VersionModel.class, qnVersion,
82                           new org.apache.axis.encoding.ser.BeanSerializerFactory(VersionModel.class, qnVersion),
83                           new org.apache.axis.encoding.ser.BeanDeserializerFactory(VersionModel.class, qnVersion));
84
85             QName JavaDoc qnNotification = new QName JavaDoc("urn:itracker", "notification");
86             call.registerTypeMapping(NotificationModel.class, qnNotification,
87                           new org.apache.axis.encoding.ser.BeanSerializerFactory(NotificationModel.class, qnNotification),
88                           new org.apache.axis.encoding.ser.BeanDeserializerFactory(NotificationModel.class, qnNotification));
89
90             QName JavaDoc qnProject = new QName JavaDoc("urn:itracker", "project");
91             call.registerTypeMapping(ProjectModel.class, qnProject,
92                           new org.apache.axis.encoding.ser.BeanSerializerFactory(ProjectModel.class, qnProject),
93                           new org.apache.axis.encoding.ser.BeanDeserializerFactory(ProjectModel.class, qnProject));
94
95             QName JavaDoc qnCustomField = new QName JavaDoc("urn:itracker", "customfield");
96             call.registerTypeMapping(CustomFieldModel.class, qnCustomField,
97                           new org.apache.axis.encoding.ser.BeanSerializerFactory(CustomFieldModel.class, qnCustomField),
98                           new org.apache.axis.encoding.ser.BeanDeserializerFactory(CustomFieldModel.class, qnCustomField));
99             QName JavaDoc qnCustomFieldValue = new QName JavaDoc("urn:itracker", "customfieldvalue");
100             call.registerTypeMapping(CustomFieldValueModel.class, qnCustomFieldValue,
101                           new org.apache.axis.encoding.ser.BeanSerializerFactory(CustomFieldValueModel.class, qnCustomFieldValue),
102                           new org.apache.axis.encoding.ser.BeanDeserializerFactory(CustomFieldValueModel.class, qnCustomFieldValue));
103
104             QName JavaDoc qnUser = new QName JavaDoc("urn:itracker", "user");
105             call.registerTypeMapping(UserModel.class, qnUser,
106                           new org.apache.axis.encoding.ser.BeanSerializerFactory(UserModel.class, qnUser),
107                           new org.apache.axis.encoding.ser.BeanDeserializerFactory(UserModel.class, qnUser));
108
109             QName JavaDoc qnPermission = new QName JavaDoc("urn:itracker", "permission");
110             call.registerTypeMapping(PermissionModel.class, qnPermission,
111                           new org.apache.axis.encoding.ser.BeanSerializerFactory(PermissionModel.class, qnPermission),
112                           new org.apache.axis.encoding.ser.BeanDeserializerFactory(PermissionModel.class, qnPermission));
113
114             QName JavaDoc qnPreferences = new QName JavaDoc("urn:itracker", "preferences");
115             call.registerTypeMapping(UserPreferencesModel.class, qnPreferences,
116                           new org.apache.axis.encoding.ser.BeanSerializerFactory(UserPreferencesModel.class, qnPreferences),
117                           new org.apache.axis.encoding.ser.BeanDeserializerFactory(UserPreferencesModel.class, qnPreferences));
118
119             System.out.println("Setting service to " + args[0] + "/ITrackerIssueService");
120             call.setTargetEndpointAddress(new java.net.URL JavaDoc(args[0] + "/ITrackerIssueService"));
121             call.setOperationName("getAllIssues");
122             call.addParameter("login", XMLType.XSD_STRING, ParameterMode.IN );
123             call.addParameter("authentication", XMLType.XSD_STRING, ParameterMode.IN );
124             call.addParameter("authType", XMLType.XSD_INTEGER, ParameterMode.IN );
125             call.setReturnType(XMLType.SOAP_ARRAY);
126
127             IssueModel[] values = (IssueModel[]) call.invoke( new Object JavaDoc[] { args[1], args[2], new Integer JavaDoc(AuthenticationConstants.AUTH_TYPE_PASSWORD_PLAIN) });
128
129             if(values != null) {
130                 for(int i = 0; i < values.length; i++) {
131                     System.out.println("Issue " + values[i].getId() + ":");
132                     System.out.println(" Project: " + values[i].getProjectName());
133                     System.out.println(" Description: " + values[i].getDescription());
134                     System.out.println(" Severity: " + IssueUtilities.getSeverityName(values[i].getSeverity()));
135                     System.out.println(" Status: " + IssueUtilities.getStatusName(values[i].getStatus()));
136                     if(values[i].getStatus() >= IssueUtilities.STATUS_RESOLVED) {
137                         System.out.println(" Resolution: " + values[i].getResolution());
138                     }
139                     System.out.println(" Created: " + values[i].getCreateDate());
140                     System.out.println(" Last Modified: " + values[i].getLastModifiedDate());
141                     System.out.println("");
142                 }
143                 if(values.length > 0) {
144                     call.setOperationName("getIssue");
145                     call.removeAllParameters();
146                     call.addParameter("issueId", XMLType.XSD_INTEGER, ParameterMode.IN );
147                     call.addParameter("login", XMLType.XSD_STRING, ParameterMode.IN );
148                     call.addParameter("password", XMLType.XSD_STRING, ParameterMode.IN );
149                     call.addParameter("passwordEnc", XMLType.XSD_BOOLEAN, ParameterMode.IN );
150                     call.setReturnType(qnIssue);
151
152                     IssueModel issue = (IssueModel) call.invoke( new Object JavaDoc[] { values[0].getId(), args[1], args[2], new Integer JavaDoc(AuthenticationConstants.AUTH_TYPE_PASSWORD_PLAIN) });
153                     System.out.println("\n");
154                     System.out.println("Issue " + issue.getId() + ":");
155                     System.out.println(" Project: " + issue.getProjectName());
156                     System.out.println(" Description: " + issue.getDescription());
157                     System.out.println(" Severity: " + IssueUtilities.getSeverityName(issue.getSeverity()));
158                     System.out.println(" Status: " + IssueUtilities.getStatusName(issue.getStatus()));
159                     if(values[0].getStatus() >= IssueUtilities.STATUS_RESOLVED) {
160                         System.out.println(" Resolution: " + issue.getResolution());
161                     }
162                     System.out.println(" Created: " + issue.getCreateDate());
163                     System.out.println(" Last Modified: " + issue.getLastModifiedDate());
164                     System.out.println(" Components: ");
165                     for(int i = 0; i < issue.getComponents().length; i++) {
166                         System.out.println(" " + issue.getComponents()[i].getName() + " [" + issue.getComponents()[i].getId() + "]");
167                     }
168                     System.out.println(" Versions: ");
169                     for(int i = 0; i < issue.getVersions().length; i++) {
170                         System.out.println(" " + issue.getVersions()[i].getNumber() + " [" + issue.getVersions()[i].getId() + "]");
171                     }
172                     System.out.println(" History: ");
173                     for(int i = 0; i < issue.getHistory().length; i++) {
174                         System.out.println(" " + i + ") " + issue.getHistory()[i].getDescription());
175                     }
176                 }
177             }
178
179             call.setTargetEndpointAddress(new java.net.URL JavaDoc(args[0] + "/ITrackerProjectService"));
180             call.setOperationName("getAllProjects");
181             call.removeAllParameters();
182             call.addParameter("login", XMLType.XSD_STRING, ParameterMode.IN );
183             call.addParameter("password", XMLType.XSD_STRING, ParameterMode.IN );
184             call.addParameter("passwordEnc", XMLType.XSD_BOOLEAN, ParameterMode.IN );
185             call.setReturnType(XMLType.SOAP_ARRAY);
186
187
188             System.out.println("\n\nTesting create issue...");
189             ProjectModel[] projects = (ProjectModel[]) call.invoke( new Object JavaDoc[] { args[1], args[2], new Integer JavaDoc(AuthenticationConstants.AUTH_TYPE_PASSWORD_PLAIN) });
190             if(projects != null && projects.length > 0) {
191                 IssueModel newIssue = new IssueModel();
192                 newIssue.setProject(projects[0]);
193                 newIssue.setStatus(IssueUtilities.STATUS_NEW);
194                 newIssue.setSeverity(1);
195                 newIssue.setDescription("New web services test issue.");
196                 newIssue.setHistory(new IssueHistoryModel[] { new IssueHistoryModel("Test issue history entry.") });
197
198                 File fileAttachment = new File("C:\\Books.doc");
199                 String JavaDoc contentType = "UNKNOWN";
200                 try {
201                     contentType = fileAttachment.toURL().openConnection().getContentType();
202                 } catch(Exception JavaDoc e) {
203                     e.printStackTrace();
204                 }
205                 newIssue.setAttachments(new IssueAttachmentModel[] { new IssueAttachmentModel("Books.doc", contentType, "Test word doc attachment", fileAttachment.length()) });
206
207                 call.setTargetEndpointAddress(new java.net.URL JavaDoc(args[0] + "/ITrackerIssueService"));
208                 call.setOperationName("createIssue");
209                 call.removeAllParameters();
210                 AttachmentPart attachment = new AttachmentPart(new DataHandler(new FileDataSource("C:\\Books.doc")));
211                 attachment.setContentId("Books.doc");
212                 call.addAttachmentPart(attachment);
213                 call.addParameter("issue", XMLType.XSD_QNAME, newIssue.getClass(), ParameterMode.IN );
214                 call.addParameter("login", XMLType.XSD_STRING, ParameterMode.IN );
215                 call.addParameter("password", XMLType.XSD_STRING, ParameterMode.IN );
216                 call.addParameter("passwordEnc", XMLType.XSD_BOOLEAN, ParameterMode.IN );
217                 call.setReturnType(qnIssue);
218                 IssueModel createdIssue = (IssueModel) call.invoke( new Object JavaDoc[] { newIssue, args[1], args[2], new Integer JavaDoc(AuthenticationConstants.AUTH_TYPE_PASSWORD_PLAIN) });
219
220                 System.out.println("Created Issue " + createdIssue.getId() + ":");
221                 System.out.println(" Project: " + createdIssue.getProjectName());
222                 System.out.println(" Description: " + createdIssue.getDescription());
223                 System.out.println(" Severity: " + IssueUtilities.getSeverityName(createdIssue.getSeverity()));
224                 System.out.println(" Status: " + IssueUtilities.getStatusName(createdIssue.getStatus()));
225                 System.out.println(" Created: " + createdIssue.getCreateDate());
226                 System.out.println(" Last Modified: " + createdIssue.getLastModifiedDate());
227                 System.out.println(" Components: ");
228                 for(int i = 0; i < createdIssue.getComponents().length; i++) {
229                     System.out.println(" " + createdIssue.getComponents()[i].getName() + " [" + createdIssue.getComponents()[i].getId() + "]");
230                 }
231                 System.out.println(" Versions: ");
232                 for(int i = 0; i < createdIssue.getVersions().length; i++) {
233                     System.out.println(" " + createdIssue.getVersions()[i].getNumber() + " [" + createdIssue.getVersions()[i].getId() + "]");
234                 }
235                 System.out.println(" History: ");
236                 for(int i = 0; i < createdIssue.getHistory().length; i++) {
237                     System.out.println(" " + i + ") " + createdIssue.getHistory()[i].getDescription());
238                 }
239             }
240
241         } catch (AxisFault fault) {
242             System.out.println("Error : " + fault.toString());
243             return;
244         }
245     }
246 }
Popular Tags