KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > example > webservice > authentication > AuthenticationServiceSystemTest


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.authentication;
18
19 import javax.xml.rpc.ServiceException JavaDoc;
20
21 import junit.framework.AssertionFailedError;
22
23 import org.alfresco.util.BaseTest;
24
25 /**
26  * Tests the AuthenticationService by trying to login as admin/admin and
27  * attempting to login with incorrect credentials.
28  *
29  * @author gavinc
30  */

31 public class AuthenticationServiceSystemTest extends BaseTest
32 {
33    private AuthenticationServiceSoapBindingStub binding;
34    
35    /**
36     * @see junit.framework.TestCase#setUp()
37     */

38    @Override JavaDoc
39    protected void setUp() throws Exception JavaDoc
40    {
41       super.setUp();
42       try
43       {
44          this.binding = (AuthenticationServiceSoapBindingStub)new AuthenticationServiceLocator().getAuthenticationService();
45       }
46       catch (ServiceException JavaDoc jre)
47       {
48          if (jre.getLinkedCause() != null)
49          {
50             jre.getLinkedCause().printStackTrace();
51          }
52          
53          throw new AssertionFailedError("JAX-RPC ServiceException caught: " + jre);
54       }
55       
56       assertNotNull("binding is null", this.binding);
57       
58       // Time out after a minute
59
binding.setTimeout(60000);
60    }
61
62    /**
63     * Tests whether the authentication service is working correctly
64     *
65     * @throws Exception
66     */

67    public void testSuccessfulLogin() throws Exception JavaDoc
68    {
69       try
70       {
71          AuthenticationResult value = this.binding.authenticate("admin", "admin");
72          assertNotNull("result must not be null", value);
73          System.out.println("ticket = " + value.getTicket());
74       }
75       catch (AuthenticationFault error)
76       {
77          throw new AssertionFailedError("AuthenticationFault Exception caught: " + error);
78       }
79    }
80    
81    /**
82     * Tests that a failed authentication attempt fails as expected
83     *
84     * @throws Exception
85     */

86    public void testFailedLogin() throws Exception JavaDoc
87    {
88       try
89       {
90          AuthenticationResult result = this.binding.authenticate("wrong", "credentials");
91          fail("The credentials are incorrect so an AuthenticationFault should have been thrown");
92       }
93       catch (AuthenticationFault error)
94       {
95          // we expected this
96
}
97    }
98 }
99
Popular Tags