KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > example > webservice > BaseWebServiceSystemTest


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;
18
19 import javax.xml.rpc.ServiceException JavaDoc;
20
21 import junit.framework.AssertionFailedError;
22
23 import org.alfresco.example.webservice.authentication.AuthenticationResult;
24 import org.alfresco.example.webservice.authentication.AuthenticationServiceLocator;
25 import org.alfresco.example.webservice.authentication.AuthenticationServiceSoapBindingStub;
26 import org.alfresco.example.webservice.types.Store;
27 import org.alfresco.example.webservice.types.StoreEnum;
28 import org.alfresco.service.cmr.repository.StoreRef;
29 import org.alfresco.util.BaseTest;
30 import org.apache.commons.logging.Log;
31 import org.apache.commons.logging.LogFactory;
32
33 /**
34  * Base class for all web service system tests that need to authenticate.
35  * The setUp method calls the AuthenticationService and authenticates as admin/admin,
36  * the returned ticket is then stored in <code>TicketHolder.ticket</code> so that
37  * all subclass implementations can use it to call other services.
38  *
39  * @see junit.framework.TestCase#setUp()
40  * @author gavinc
41  */

42 public abstract class BaseWebServiceSystemTest extends BaseTest
43 {
44    private static Log logger = LogFactory.getLog(BaseWebServiceSystemTest.class);
45    
46    private static final String JavaDoc USERNAME = "admin";
47    private static final String JavaDoc PASSWORD = "admin";
48    
49    // ********************************************************************
50
//
51
// NOTE: The rootId and companyHomeId variables have to be set for your
52
// database for the tests to run successfully, once there is a way
53
// to query for the root node this can be removed.
54
// Perform a MySQL query to get the ids for the rootId execute:
55
// "select * from node where type_local_name = 'store_root';" and
56
// pick the row with an identifier of 'SpacesStore'.
57
// For the company home id execute the following query:
58
// "select * from child_assoc where parent_guid = '<your-root-id>' and local_name = 'Company_Home';"
59
//
60
// ********************************************************************
61

62    protected static String JavaDoc rootId = "fddc4ffb-1ace-11da-b3ba-e981aa43b126";
63    protected static String JavaDoc companyHomeId = "fe289b3d-1ace-11da-b3ba-e981aa43b126";
64    protected Store STORE = new Store(StoreEnum.workspace, "SpacesStore");
65    protected StoreRef STORE_REF = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore");
66    
67    /**
68     * Calls the AuthenticationService to retrieve a ticket for all tests to use.
69     */

70    @Override JavaDoc
71    protected void setUp() throws Exception JavaDoc
72    {
73       super.setUp();
74       AuthenticationServiceSoapBindingStub authSvc = null;
75       try
76       {
77          authSvc = (AuthenticationServiceSoapBindingStub)new AuthenticationServiceLocator().getAuthenticationService();
78       }
79       catch (ServiceException JavaDoc jre)
80       {
81          if (jre.getLinkedCause() != null)
82          {
83             jre.getLinkedCause().printStackTrace();
84          }
85          
86          throw new AssertionFailedError("JAX-RPC ServiceException caught: " + jre);
87       }
88       
89       assertNotNull("authSvc is null", authSvc);
90       
91       // Time out after a minute
92
authSvc.setTimeout(60000);
93       
94       // call the authenticate method and retrieve the ticket
95
AuthenticationResult result = authSvc.authenticate(USERNAME, PASSWORD);
96       assertNotNull("result is null", result);
97       String JavaDoc ticket = result.getTicket();
98       assertNotNull("ticket is null", ticket);
99       TicketHolder.ticket = ticket;
100       if (logger.isDebugEnabled())
101          logger.debug("Retrieved and stored ticket: " + TicketHolder.ticket);
102    }
103 }
104
Popular Tags