1 16 package org.outerj.daisy.repository.test; 17 18 import org.outerj.daisy.repository.testsupport.AbstractDaisyTestCase; 19 import org.outerj.daisy.repository.*; 20 import org.outerj.daisy.repository.user.Role; 21 22 public abstract class AbstractCollectionTest extends AbstractDaisyTestCase { 23 protected boolean resetDataStores() { 24 return true; 25 } 26 27 protected abstract RepositoryManager getRepositoryManager() throws Exception ; 28 29 public void testCollections() throws Exception { 30 RepositoryManager repositoryManager = getRepositoryManager(); 31 Repository repository = repositoryManager.getRepository(new Credentials("testuser", "testuser")); 32 repository.switchRole(Role.ADMINISTRATOR); 33 34 CollectionManager collectionManager = repository.getCollectionManager(); 35 36 DocumentCollection collection1 = collectionManager.createCollection("collection1"); 37 collection1.save(); 38 39 DocumentCollection fetchedCollection1 = collectionManager.getCollection(collection1.getId(), true); 40 assertEquals("collection name is stored correctly", collection1.getName(), fetchedCollection1.getName()); 41 42 assertTrue("data store id of stored collection is -1 or less", fetchedCollection1.getId() > -1); 44 assertNotNull("last modified date of stored collection is null", fetchedCollection1.getLastModified()); 45 assertTrue("last modifier of stored collection is invalid", fetchedCollection1.getLastModifier() >= -1); 46 assertNotNull("xml object returned by stored collection is null", fetchedCollection1.getXml()); 47 48 collection1.setName(collection1.getName() + "x"); 50 collection1.save(); 51 assertEquals("collection name change correctly saved", collection1.getName(), 52 collectionManager.getCollection(collection1.getId(), true).getName()); 53 54 assertEquals("retrieving collection by name should give collection with correct id", 56 collection1.getId(), collectionManager.getCollectionByName(collection1.getName(), true).getId()); 57 58 61 DocumentCollections collections = collectionManager.getCollections(true); 62 assertNotNull(collections); 63 DocumentCollection[] collArray = collections.getArray(); 64 assertNotNull(collArray); 65 66 for (int i = 0; i < collArray.length; i++) { 67 DocumentCollection collection = collArray[i]; 68 assertNotNull(collection); 69 } 70 71 DocumentCollection collection2 = collectionManager.createCollection("collection2"); 75 collection2.save(); 76 77 collectionManager.getCollection(collection2.getId(), false); 79 80 collection2.setName("collection2-modified"); 81 collection2.save(); 82 83 DocumentCollection collection2Refetched = collectionManager.getCollection(collection2.getId(), false); 84 assertEquals(collection2.getName(), collection2Refetched.getName()); 85 86 collectionManager.deleteCollection(collection2.getId()); 87 try { 88 collectionManager.getCollection(collection2.getId(), false); 89 fail("Getting a deleted exception should throw an exception."); 90 } catch (CollectionNotFoundException e) {} 91 92 DocumentCollection collection3 = collectionManager.createCollection("a b"); 93 collection3.save(); 94 assertEquals(collection3.getId(), collectionManager.getCollectionByName("a b", true).getId()); 95 assertEquals(collection3.getId(), collectionManager.getCollectionByName("a b", false).getId()); 96 97 } 99 } 100 | Popular Tags |