KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > example > webservice > authoring > AuthoringServiceSystemTest


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.example.webservice.authoring;
18
19 import javax.xml.rpc.ServiceException JavaDoc;
20
21 import junit.framework.AssertionFailedError;
22
23 import org.alfresco.example.webservice.BaseWebServiceSystemTest;
24 import org.alfresco.example.webservice.content.ContentServiceLocator;
25 import org.alfresco.example.webservice.content.ContentServiceSoapBindingStub;
26 import org.alfresco.example.webservice.types.Content;
27 import org.alfresco.example.webservice.types.ContentFormat;
28 import org.alfresco.example.webservice.types.ParentReference;
29 import org.alfresco.example.webservice.types.Predicate;
30 import org.alfresco.example.webservice.types.Reference;
31 import org.apache.axis.EngineConfiguration;
32 import org.apache.axis.configuration.FileProvider;
33 import org.apache.commons.logging.Log;
34 import org.apache.commons.logging.LogFactory;
35
36 public class AuthoringServiceSystemTest extends BaseWebServiceSystemTest
37 {
38    private static Log logger = LogFactory.getLog(AuthoringServiceSystemTest.class);
39    
40    private static String JavaDoc versionedNodeId;
41    private static final String JavaDoc INITIAL_VERSION_CONTENT = "Content of the initial version";
42    private static final String JavaDoc FIRST_VERSION_CONTENT = "Content of the first version";
43    private static final String JavaDoc SECOND_VERSION_CONTENT = "The content for the second version is completely different";
44    private static final String JavaDoc THIRD_VERSION_CONTENT = "The third version is short!";
45    
46    private AuthoringServiceSoapBindingStub authoringService;
47
48    @Override JavaDoc
49    protected void setUp() throws Exception JavaDoc
50    {
51       super.setUp();
52
53       try
54       {
55          EngineConfiguration config = new FileProvider(getResourcesDir(), "client-deploy.wsdd");
56          this.authoringService = (AuthoringServiceSoapBindingStub)new AuthoringServiceLocator(config).getAuthoringService();
57       }
58       catch (ServiceException JavaDoc jre)
59       {
60          if (jre.getLinkedCause() != null)
61          {
62             jre.getLinkedCause().printStackTrace();
63          }
64          
65          throw new AssertionFailedError("JAX-RPC ServiceException caught: " + jre);
66       }
67       
68       assertNotNull("authoringService is null", this.authoringService);
69       
70       // Time out after a minute
71
this.authoringService.setTimeout(60000);
72    }
73    
74    public void testCreateNode() throws Exception JavaDoc
75    {
76       ContentServiceSoapBindingStub contentService = null;
77       try
78       {
79          EngineConfiguration config = new FileProvider(getResourcesDir(), "client-deploy.wsdd");
80          contentService = (ContentServiceSoapBindingStub)new ContentServiceLocator(config).getContentService();
81          assertNotNull("contentService is null", contentService);
82          contentService.setTimeout(60000);
83       }
84       catch (Exception JavaDoc e)
85       {
86          fail("Could not instantiate the content service" + e.toString());
87       }
88       
89       // get the root node (hard code for now until we have a way to query for the root node)
90
ParentReference root = new ParentReference();
91       root.setStore(STORE);
92       root.setUuid(companyHomeId);
93       
94       String JavaDoc mimetype = "text/plain";
95       Content content = contentService.create(root, "version-test.txt", new ContentFormat(mimetype, "UTF-8"),
96             INITIAL_VERSION_CONTENT.getBytes());
97       assertNotNull("returned content should not be null", content);
98       assertNotNull("format should not be null", content.getFormat());
99       assertEquals("Mimetype should match what was sent", mimetype, content.getFormat().getMimetype());
100       versionedNodeId = content.getReference().getUuid();
101       logger.debug("created new content with id: " + versionedNodeId);
102    }
103    
104    /**
105     * Tests the checkout service method
106     *
107     * @throws Exception
108     */

109    public void testCheckout() throws Exception JavaDoc
110    {
111       Reference ref = new Reference();
112       ref.setStore(STORE);
113       ref.setUuid(versionedNodeId);
114       Predicate predicate = new Predicate();
115       predicate.setNodes(new Reference[] {ref});
116       
117       // define the parent reference as a path based reference
118
// ParentReference checkoutLocation = new ParentReference();
119
// checkoutLocation.setStore(STORE);
120
// checkoutLocation.setPath("//*[@cm:name = 'Company Home']");
121

122       CheckoutResult result = this.authoringService.checkout(predicate, null);
123       assertNotNull("The result should not be null", result);
124       assertEquals("There should only be 1 original reference", 1, result.getOriginals().length);
125       assertEquals("There should only be 1 working copy reference", 1, result.getWorkingCopies().length);
126    }
127    
128    /**
129     * Tests the checkin service method
130     *
131     * @throws Exception
132     */

133    public void testCheckin() throws Exception JavaDoc
134    {
135       try
136       {
137          this.authoringService.checkin(null, null, false);
138          fail("This method should have thrown an authoring fault");
139       }
140       catch (AuthoringFault af)
141       {
142          // expected to get this
143
}
144    }
145
146    /**
147     * Tests the checkinExternal service method
148     *
149     * @throws Exception
150     */

151    public void testCheckinExternal() throws Exception JavaDoc
152    {
153       try
154       {
155          this.authoringService.checkinExternal(null, null, false, null, null);
156          fail("This method should have thrown an authoring fault");
157       }
158       catch (AuthoringFault af)
159       {
160          // expected to get this
161
}
162    }
163
164    /**
165     * Tests the cancelCheckout service method
166     *
167     * @throws Exception
168     */

169    public void testCancelCheckout() throws Exception JavaDoc
170    {
171       try
172       {
173          this.authoringService.cancelCheckout(null);
174          fail("This method should have thrown an authoring fault");
175       }
176       catch (AuthoringFault af)
177       {
178          // expected to get this
179
}
180    }
181
182    /**
183     * Tests the lock service method
184     *
185     * @throws Exception
186     */

187    public void testLock() throws Exception JavaDoc
188    {
189       try
190       {
191          this.authoringService.lock(null, false, null);
192          fail("This method should have thrown an authoring fault");
193       }
194       catch (AuthoringFault af)
195       {
196          // expected to get this
197
}
198    }
199
200    /**
201     * Tests the unlock service method
202     *
203     * @throws Exception
204     */

205    public void testUnlock() throws Exception JavaDoc
206    {
207       try
208       {
209          this.authoringService.unlock(null, false);
210          fail("This method should have thrown an authoring fault");
211       }
212       catch (AuthoringFault af)
213       {
214          // expected to get this
215
}
216    }
217
218    /**
219     * Tests the getLockStatus service method
220     *
221     * @throws Exception
222     */

223    public void testGetLockStatus() throws Exception JavaDoc
224    {
225       try
226       {
227          this.authoringService.getLockStatus(null);
228          fail("This method should have thrown an authoring fault");
229       }
230       catch (AuthoringFault af)
231       {
232          // expected to get this
233
}
234    }
235
236    /**
237     * Tests the createVersion service method
238     *
239     * @throws Exception
240     */

241    public void testCreateVersion() throws Exception JavaDoc
242    {
243       try
244       {
245          this.authoringService.createVersion(null, null, false);
246          fail("This method should have thrown an authoring fault");
247       }
248       catch (AuthoringFault af)
249       {
250          // expected to get this
251
}
252    }
253
254    /**
255     * Tests the getVersionHistory service method
256     *
257     * @throws Exception
258     */

259    public void testGetVersionHistory() throws Exception JavaDoc
260    {
261       try
262       {
263          this.authoringService.getVersionHistory(null);
264          fail("This method should have thrown an authoring fault");
265       }
266       catch (AuthoringFault af)
267       {
268          // expected to get this
269
}
270    }
271
272    /**
273     * Tests the revertVersion service method
274     *
275     * @throws Exception
276     */

277    public void testRevertVersion() throws Exception JavaDoc
278    {
279       try
280       {
281          this.authoringService.revertVersion(null, null);
282          fail("This method should have thrown an authoring fault");
283       }
284       catch (AuthoringFault af)
285       {
286          // expected to get this
287
}
288    }
289
290    /**
291     * Tests the deleteAllVersions service method
292     *
293     * @throws Exception
294     */

295    public void testDeleteAllVersions() throws Exception JavaDoc
296    {
297       try
298       {
299          this.authoringService.deleteAllVersions(null);
300          fail("This method should have thrown an authoring fault");
301       }
302       catch (AuthoringFault af)
303       {
304          // expected to get this
305
}
306    }
307 }
308
Popular Tags