001: /*
002: * Copyright 2007 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.RepositoryManager;
020: import org.outerj.daisy.repository.Repository;
021: import org.outerj.daisy.repository.Credentials;
022: import org.outerj.daisy.repository.user.Role;
023: import org.outerj.daisy.workflow.WorkflowManager;
024: import org.outerj.daisy.workflow.WfPoolManager;
025: import org.outerj.daisy.workflow.WfPool;
026: import org.outerj.daisy.workflow.WorkflowException;
027:
028: import java.util.List;
029: import java.util.ArrayList;
030: import java.util.Set;
031: import java.util.Collections;
032:
033: public abstract class AbstractPoolTest extends AbstractDaisyTestCase {
034: protected boolean resetDataStores() {
035: return true;
036: }
037:
038: protected Set<String> getDisabledContainerIds() {
039: return Collections.emptySet();
040: }
041:
042: protected abstract RepositoryManager getRepositoryManager()
043: throws Exception;
044:
045: public void testPoolManagement() throws Exception {
046: RepositoryManager repositoryManager = getRepositoryManager();
047:
048: Repository repository = repositoryManager
049: .getRepository(new Credentials("testuser", "testuser"));
050: repository.switchRole(Role.ADMINISTRATOR);
051:
052: WorkflowManager workflowManager = (WorkflowManager) repository
053: .getExtension("WorkflowManager");
054: WfPoolManager poolManager = workflowManager.getPoolManager();
055:
056: WfPool pool = poolManager.createPool("My first pool");
057: pool.save();
058: assertNotNull(pool.getLastModified());
059: assertEquals(repository.getUserId(), pool.getLastModifier());
060:
061: WfPool refetchedPool = poolManager.getPool(pool.getId());
062: assertNotNull(refetchedPool);
063: refetchedPool.setDescription("This is my first pool.");
064: refetchedPool.save();
065:
066: pool = poolManager.getPoolByName("My first pool");
067: assertEquals("My first pool", pool.getName());
068: assertEquals("This is my first pool.", pool.getDescription());
069:
070: WfPool pool2 = poolManager.createPool("My second pool");
071: pool2.save();
072:
073: assertEquals(2, poolManager.getPools().size());
074:
075: poolManager.addUsersToPool(pool.getId(), idList(1, 2, 3));
076: poolManager.addUsersToPool(pool2.getId(), idList(2));
077: // adding user again to same pool should not give an exception
078: poolManager.addUsersToPool(pool2.getId(), idList(2));
079: poolManager.addUsersToPool(pool2.getId(), idList());
080:
081: try {
082: poolManager.addUsersToPool(23232, idList(1, 2, 3));
083: fail("Adding users to non-existing pool should give an exception.");
084: } catch (WorkflowException e) {
085: }
086:
087: List<WfPool> userPools = poolManager.getPoolsForUser(2);
088: assertEquals(2, userPools.size());
089:
090: assertEquals(3, poolManager.getUsersForPool(pool.getId())
091: .size());
092: assertEquals(1, poolManager.getUsersForPool(pool2.getId())
093: .size());
094:
095: poolManager.clearPool(pool2.getId());
096: assertEquals(0, poolManager.getUsersForPool(pool2.getId())
097: .size());
098:
099: poolManager.removeUsersFromPool(pool.getId(), idList(3, 4, 5));
100: assertEquals(2, poolManager.getUsersForPool(pool.getId())
101: .size());
102:
103: // TODO test nonadmin users cannot update/create pools
104:
105: }
106:
107: private List<Long> idList(long... ids) {
108: List<Long> list = new ArrayList<Long>(ids.length);
109: for (long id : ids) {
110: list.add(id);
111: }
112: return list;
113: }
114: }
|