KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > jcr > repository > RepositoryImplTest


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.jcr.repository;
18
19 import javax.jcr.LoginException;
20 import javax.jcr.NoSuchWorkspaceException;
21 import javax.jcr.Repository;
22 import javax.jcr.RepositoryException;
23 import javax.jcr.Session;
24 import javax.jcr.SimpleCredentials;
25
26 import org.alfresco.jcr.test.BaseJCRTest;
27
28
29 /**
30  * Test JCR Repository Implementation
31  *
32  * @author David Caruana
33  */

34 public class RepositoryImplTest extends BaseJCRTest
35 {
36
37     public void testDescriptors()
38     {
39         String JavaDoc[] keys = repository.getDescriptorKeys();
40         assertEquals(11, keys.length);
41         for (String JavaDoc key : keys)
42         {
43             String JavaDoc value = repository.getDescriptor(key);
44             assertNotNull(value);
45         }
46         
47         assertNotNull(repository.getDescriptor(Repository.REP_NAME_DESC));
48         System.out.println(repository.getDescriptor(Repository.REP_NAME_DESC));
49         assertNotNull(repository.getDescriptor(Repository.REP_VENDOR_DESC));
50         assertNotNull(repository.getDescriptor(Repository.REP_VENDOR_URL_DESC));
51         assertNotNull(repository.getDescriptor(Repository.REP_VERSION_DESC));
52         System.out.println(repository.getDescriptor(Repository.REP_VERSION_DESC));
53         assertNotNull(repository.getDescriptor(Repository.SPEC_NAME_DESC));
54         assertNotNull(repository.getDescriptor(Repository.SPEC_VERSION_DESC));
55         assertEquals("true", repository.getDescriptor(Repository.LEVEL_1_SUPPORTED));
56         assertEquals("true", repository.getDescriptor(Repository.LEVEL_2_SUPPORTED));
57         assertEquals("true", repository.getDescriptor(Repository.OPTION_TRANSACTIONS_SUPPORTED));
58         assertEquals("true", repository.getDescriptor(Repository.QUERY_XPATH_DOC_ORDER));
59         assertEquals("true", repository.getDescriptor(Repository.QUERY_XPATH_POS_INDEX));
60     }
61     
62     public void testBadUsernameLogin() throws Exception JavaDoc
63     {
64         SimpleCredentials badUser = new SimpleCredentials("baduser", "".toCharArray());
65         try
66         {
67             repository.login(badUser);
68             fail("Failed to catch bad username - username should not exist.");
69         }
70         catch (LoginException e)
71         {
72         }
73     }
74     
75     public void testBadPwdLogin() throws Exception JavaDoc
76     {
77         SimpleCredentials badPwd = new SimpleCredentials("superuser", "badpwd".toCharArray());
78         try
79         {
80             repository.login(badPwd);
81             fail("Failed to catch bad password - password is invalid.");
82         }
83         catch (LoginException e)
84         {
85         }
86     }
87     
88     public void testNoCredentialsLogin() throws Exception JavaDoc
89     {
90         try
91         {
92             repository.login();
93             fail("Failed to catch no credentials.");
94         }
95         catch (LoginException e)
96         {
97         }
98     }
99
100     public void testLogin()
101         throws RepositoryException
102     {
103         SimpleCredentials good = new SimpleCredentials("superuser", "".toCharArray());
104         try
105         {
106             Session session = repository.login(good, getWorkspace());
107             assertNotNull(session);
108             session.logout();
109         }
110         catch (LoginException e)
111         {
112             fail("Failed to login.");
113         }
114
115         try
116         {
117             Session session = repository.login(good, null);
118             session.logout();
119         }
120         catch (NoSuchWorkspaceException e)
121         {
122             fail("Failed to detect default workspace");
123         }
124     }
125     
126 }
127
128
Popular Tags