/*
* $Header: /export/home/cvsroot/MyPersonalizerRepository/MyPersonalizer/Subsystems/Kernel/Sources/es/udc/mypersonalizer/kernel/model/repository/interfaces/WorkspaceDefinitionAccessorTest.java,v 1.1.1.1 2004/03/25 12:08:36 fbellas Exp $
* $Revision: 1.1.1.1 $
* $Date: 2004/03/25 12:08:36 $
*
* =============================================================================
*
* Copyright (c) 2003, The MyPersonalizer Development Group
* (http://www.tic.udc.es/~fbellas/mypersonalizer/index.html) at
* University Of A Coruna
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* - Neither the name of the University Of A Coruna nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
package es.udc.mypersonalizer.kernel.model.repository.interfaces;
import java.util.Collection;
import java.util.ArrayList;
import java.util.Iterator;
import es.udc.mypersonalizer.kernel.model.repository.interfaces.
WorkspaceDefinition;
import es.udc.mypersonalizer.kernel.model.repository.interfaces.
WorkspaceDefinitionAccessor;
import junit.framework.TestCase;
/**
* @author Abel Iago Toral Quiroga
*
* This class tests the <code>WorkspaceDefinitionAccessor</code> class.
* <p>
* The first argument is one of [add, update, remove, find, find_all]
* The second is the workspace type. (not for find_all)
* Third is the number of services to allow in thi workspace definition.
* Service identifiers will be generated in the form serviceIdentifier1, ...
* This parameter is only for add/update.
* Finally is a list of user group identifiers that can add/remove the
* workspace definition in the form : 45 37 12 ...
* This parameter is only for add/update.
* <p>
* Examples :
* remove workSpaceDef1
* Thi will remove workSpaceDef1 workspace definition.
* add workSpaceDef2 2 31 28
* This will add workSpaceDef2 with serviceIdentifier1 ans serviceIdentifier2
* available and with permissions for groups 31 and 28.
*/
public class WorkspaceDefinitionAccessorTest extends TestCase {
public static String testName = "";
public static WorkspaceDefinitionAccessor accessor;
public static String workspaceType = null;
public static int numberOfServices = 0;
public static Collection allowedGroups = null;
/**
* Constructor for WorkspaceDefinitionAccessorTest
* @param arg0
*/
public WorkspaceDefinitionAccessorTest(String arg0) {
super(arg0);
}
/**
* @see TestCase#setUp()
*/
protected void setUp() throws Exception {
super.setUp();
System.out.println("Setting up ...");
accessor = RepositoryAccessorFactory.getInstance().
createWorkspaceDefinitionAccessor();
}
public void testAdd() {
try {
System.out.println("Adding definition ...");
WorkspaceDefinition definition =
new WorkspaceDefinition(workspaceType);
Collection availableServices = new ArrayList();
for (int i = 0; i<numberOfServices; i++) {
availableServices.add("serviceIdentifier" + (i+1));
}
definition.setAvailableServiceIdentifiers(availableServices);
definition.setAllowedToAddUserGroupIdentifiers(allowedGroups);
definition.setAllowedToRemoveUserGroupIdentifiers(allowedGroups);
accessor.addWorkspaceDefinition(definition);
System.out.println("Definition added !!!");
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
assertEquals(true, true);
}
public void testRemove() {
try {
System.out.println("Removing definition ...");
accessor.removeWorkspaceDefinition(workspaceType);
System.out.println("Definition removed !!!");
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
assertEquals(true, true);
}
public void testFind() {
WorkspaceDefinition definition = null;
try {
System.out.println("Finding definition ...");
definition = accessor.findWorkspaceDefinition(workspaceType);
System.out.println("Definition finded !!!");
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
System.out.println("Available services : " +
definition.getAvailableServiceIdentifiers());
System.out.println("Allowed to add : " +
definition.getAllowedToAddUserGroupIdentifiers());
System.out.println("Allowed to remove : " +
definition.getAllowedToRemoveUserGroupIdentifiers());
assertEquals(true, true);
}
public void testFindAll() {
Iterator allDefinitions = null;
try {
System.out.println("Finding all definitions ...");
allDefinitions =
accessor.findAllWorkspaceDefinitions().iterator();
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
while (allDefinitions.hasNext()) {
WorkspaceDefinition definition =
(WorkspaceDefinition) allDefinitions.next();
System.out.println("----------------------------");
System.out.println("workspace : " + definition.getWorkspaceType());
System.out.println("Available services : " +
definition.getAvailableServiceIdentifiers());
System.out.println("Allowed to add : " +
definition.getAllowedToAddUserGroupIdentifiers());
System.out.println("Allowed to remove : " +
definition.getAllowedToRemoveUserGroupIdentifiers());
System.out.println("----------------------------");
}
assertEquals(true, true);
}
public void testUpdate() {
try {
System.out.println("Updating definition ...");
WorkspaceDefinition definition =
new WorkspaceDefinition(workspaceType);
Collection availableServices = new ArrayList();
for (int i = 0; i<numberOfServices; i++) {
availableServices.add("serviceIdentifier" + (i+1));
}
definition.setAvailableServiceIdentifiers(availableServices);
definition.setAllowedToAddUserGroupIdentifiers(allowedGroups);
definition.setAllowedToRemoveUserGroupIdentifiers(allowedGroups);
accessor.updateWorkspaceDefinition(definition);
System.out.println("Definition updated !!!");
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
assertEquals(true, true);
}
public static final void main(String args[])
throws Exception {
testName = args[0];
if (!testName.equals("find_all")) {
workspaceType = args[1];
}
if (testName.equals("add") || testName.equals("update")) {
numberOfServices = Integer.parseInt(args[2]);
allowedGroups = new ArrayList();
int i = 3;
while (i<args.length) {
Long l = new Long(args[i]);
allowedGroups.add(l);
i++;
}
}
TestCase test = null;
if (testName.equals("add")) {
test = new WorkspaceDefinitionAccessorTest("") {
public void runTest() {
testAdd();
}
};
}
if (testName.equals("remove")) {
test = new WorkspaceDefinitionAccessorTest("") {
public void runTest() {
testRemove();
}
};
}
if (testName.equals("find")) {
test = new WorkspaceDefinitionAccessorTest("") {
public void runTest() {
testFind();
}
};
}
if (testName.equals("find_all")) {
test = new WorkspaceDefinitionAccessorTest("") {
public void runTest() {
testFindAll();
}
};
}
if (testName.equals("update")) {
test = new WorkspaceDefinitionAccessorTest("") {
public void runTest() {
testUpdate();
}
};
}
test.run();
}
}
|