1 17 package org.alfresco.jcr.session; 18 19 import javax.jcr.Repository; 20 import javax.jcr.RepositoryException; 21 import javax.jcr.Session; 22 import javax.jcr.SimpleCredentials; 23 24 import org.alfresco.jcr.test.BaseJCRTest; 25 26 27 32 public class SessionImplTest extends BaseJCRTest 33 { 34 protected Session superuserSession; 35 36 @Override 37 protected void setUp() throws Exception 38 { 39 super.setUp(); 40 41 SimpleCredentials superuser = new SimpleCredentials("superuser", "".toCharArray()); 42 superuser.setAttribute("attr1", "superuserValue"); 43 superuser.setAttribute("attr2", new Integer (1)); 44 superuserSession = repository.login(superuser, getWorkspace()); 45 } 46 47 @Override 48 protected void tearDown() throws Exception 49 { 50 superuserSession.logout(); 51 super.tearDown(); 52 } 53 54 public void testRepository() 55 throws RepositoryException 56 { 57 Repository sessionRepository = superuserSession.getRepository(); 58 assertNotNull(sessionRepository); 59 assertEquals(repository, sessionRepository); 60 } 61 62 public void testUserId() 63 { 64 { 65 String userId = superuserSession.getUserID(); 66 assertNotNull(userId); 67 assertEquals("superuser", userId); 68 } 69 } 70 71 public void testAttributes() 72 { 73 { 74 String [] names = superuserSession.getAttributeNames(); 75 assertNotNull(names); 76 assertEquals(2, names.length); 77 String value1 = (String )superuserSession.getAttribute("attr1"); 78 assertNotNull(value1); 79 assertEquals("superuserValue", value1); 80 Integer value2 = (Integer )superuserSession.getAttribute("attr2"); 81 assertNotNull(value2); 82 assertEquals(new Integer (1), value2); 83 String value3 = (String )superuserSession.getAttribute("unknown"); 84 assertNull(value3); 85 } 86 } 87 88 public void testLogout() 89 { 90 boolean isLive = superuserSession.isLive(); 91 assertTrue(isLive); 92 superuserSession.logout(); 93 isLive = superuserSession.isLive(); 94 assertFalse(isLive); 95 } 96 97 } 98 99 | Popular Tags |