001: /*
002: * Copyright 2004 Outerthought bvba and Schaubroeck nv
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.outerj.daisy.repository.test;
017:
018: import org.outerj.daisy.repository.testsupport.AbstractDaisyTestCase;
019: import org.outerj.daisy.repository.*;
020: import org.outerj.daisy.repository.user.Role;
021:
022: public abstract class AbstractCollectionTest extends
023: AbstractDaisyTestCase {
024: protected boolean resetDataStores() {
025: return true;
026: }
027:
028: protected abstract RepositoryManager getRepositoryManager()
029: throws Exception;
030:
031: public void testCollections() throws Exception {
032: RepositoryManager repositoryManager = getRepositoryManager();
033: Repository repository = repositoryManager
034: .getRepository(new Credentials("testuser", "testuser"));
035: repository.switchRole(Role.ADMINISTRATOR);
036:
037: CollectionManager collectionManager = repository
038: .getCollectionManager();
039:
040: DocumentCollection collection1 = collectionManager
041: .createCollection("collection1");
042: collection1.save();
043:
044: DocumentCollection fetchedCollection1 = collectionManager
045: .getCollection(collection1.getId(), true);
046: assertEquals("collection name is stored correctly", collection1
047: .getName(), fetchedCollection1.getName());
048:
049: //some extra tests on the object we just fetched
050: assertTrue("data store id of stored collection is -1 or less",
051: fetchedCollection1.getId() > -1);
052: assertNotNull(
053: "last modified date of stored collection is null",
054: fetchedCollection1.getLastModified());
055: assertTrue("last modifier of stored collection is invalid",
056: fetchedCollection1.getLastModifier() >= -1);
057: assertNotNull(
058: "xml object returned by stored collection is null",
059: fetchedCollection1.getXml());
060:
061: // try to modify the collection
062: collection1.setName(collection1.getName() + "x");
063: collection1.save();
064: assertEquals("collection name change correctly saved",
065: collection1.getName(), collectionManager.getCollection(
066: collection1.getId(), true).getName());
067:
068: // try to retrieve the collection by name
069: assertEquals(
070: "retrieving collection by name should give collection with correct id",
071: collection1.getId(), collectionManager
072: .getCollectionByName(collection1.getName(),
073: true).getId());
074:
075: /* at this point there should be at least one collection in the list of all collections,
076: * so the collection list can easily be loaded here.
077: */
078: DocumentCollections collections = collectionManager
079: .getCollections(true);
080: assertNotNull(collections);
081: DocumentCollection[] collArray = collections.getArray();
082: assertNotNull(collArray);
083:
084: for (int i = 0; i < collArray.length; i++) {
085: DocumentCollection collection = collArray[i];
086: assertNotNull(collection);
087: }
088:
089: //
090: // test proper invalidation of collection caches (if any)
091: //
092: DocumentCollection collection2 = collectionManager
093: .createCollection("collection2");
094: collection2.save();
095:
096: // line below should NOT throw an CollectionNotFoundException
097: collectionManager.getCollection(collection2.getId(), false);
098:
099: collection2.setName("collection2-modified");
100: collection2.save();
101:
102: DocumentCollection collection2Refetched = collectionManager
103: .getCollection(collection2.getId(), false);
104: assertEquals(collection2.getName(), collection2Refetched
105: .getName());
106:
107: collectionManager.deleteCollection(collection2.getId());
108: try {
109: collectionManager.getCollection(collection2.getId(), false);
110: fail("Getting a deleted exception should throw an exception.");
111: } catch (CollectionNotFoundException e) {
112: }
113:
114: DocumentCollection collection3 = collectionManager
115: .createCollection("a b");
116: collection3.save();
117: assertEquals(collection3.getId(), collectionManager
118: .getCollectionByName("a b", true).getId());
119: assertEquals(collection3.getId(), collectionManager
120: .getCollectionByName("a b", false).getId());
121:
122: // NOTE: test of assigning collections to documents are part of the AbstractDocumentTest
123: }
124: }
|