001: /*
002: * $Header: /export/home/cvsroot/MyPersonalizerRepository/MyPersonalizer/Subsystems/Portal/Sources/es/udc/mypersonalizer/portal/model/actions/personalization/FindServicePropertyActionTest.java,v 1.1.1.1 2004/03/25 12:08:40 fbellas Exp $
003: * $Revision: 1.1.1.1 $
004: * $Date: 2004/03/25 12:08:40 $
005: *
006: * =============================================================================
007: *
008: * Copyright (c) 2003, The MyPersonalizer Development Group
009: * (http://www.tic.udc.es/~fbellas/mypersonalizer/index.html) at
010: * University Of A Coruna
011: * All rights reserved.
012: *
013: * Redistribution and use in source and binary forms, with or without
014: * modification, are permitted provided that the following conditions are met:
015: *
016: * - Redistributions of source code must retain the above copyright notice,
017: * this list of conditions and the following disclaimer.
018: *
019: * - Redistributions in binary form must reproduce the above copyright notice,
020: * this list of conditions and the following disclaimer in the documentation
021: * and/or other materials provided with the distribution.
022: *
023: * - Neither the name of the University Of A Coruna nor the names of its
024: * contributors may be used to endorse or promote products derived from
025: * this software without specific prior written permission.
026: *
027: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
028: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
029: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
030: * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
031: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
032: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
033: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
034: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
035: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
036: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
037: * POSSIBILITY OF SUCH DAMAGE.
038: *
039: */
040:
041: package es.udc.mypersonalizer.portal.model.actions.personalization;
042:
043: import java.util.ArrayList;
044: import java.util.Collection;
045: import java.util.Iterator;
046: import java.util.List;
047: import java.util.Map;
048:
049: import junit.framework.Assert;
050: import junit.framework.TestCase;
051: import es.udc.mypersonalizer.kernel.model.actions.ActionProcessorSingleton;
052: import es.udc.mypersonalizer.kernel.model.editors.DesktopLayoutEditor;
053: import es.udc.mypersonalizer.kernel.model.editors.EditorFactory;
054: import es.udc.mypersonalizer.kernel.model.editors.ServiceKeys;
055: import es.udc.mypersonalizer.kernel.model.editors.UserRegistrationInformationEditor;
056: import es.udc.mypersonalizer.kernel.model.editors.WorkspaceLayoutEditor;
057: import es.udc.mypersonalizer.kernel.model.repository.interfaces.DesktopLayout;
058: import es.udc.mypersonalizer.kernel.model.repository.interfaces.DesktopLayoutAccessor;
059: import es.udc.mypersonalizer.kernel.model.repository.interfaces.RepositoryAccessorFactory;
060: import es.udc.mypersonalizer.kernel.model.repository.interfaces.ServiceProperty;
061: import es.udc.mypersonalizer.kernel.model.repository.interfaces.ServicePropertyKey;
062: import es.udc.mypersonalizer.kernel.model.repository.interfaces.UserGroup;
063: import es.udc.mypersonalizer.kernel.model.repository.interfaces.UserGroupAccessor;
064: import es.udc.mypersonalizer.kernel.model.repository.interfaces.UserRegistrationInformation;
065: import es.udc.mypersonalizer.kernel.model.repository.interfaces.UserRegistrationInformationAccessor;
066: import es.udc.mypersonalizer.kernel.model.repository.interfaces.WorkspaceLayout;
067: import es.udc.mypersonalizer.kernel.model.repository.interfaces.WorkspaceLayoutAccessor;
068: import es.udc.mypersonalizer.kernel.util.exceptions.InternalErrorException;
069: import es.udc.mypersonalizer.kernel.util.exceptions.ModelException;
070: import es.udc.mypersonalizer.portal.model.permissions.UserCredentials;
071: import es.udc.mypersonalizer.portal.model.types.personalization.FindServicePropertyEvent;
072:
073: /**
074: * Test suite for {@link FindServicePropertyAction}.
075: *
076: * @author Daniel Fernandez
077: * @since 1.0
078: */
079: public class FindServicePropertyActionTest extends TestCase {
080:
081: private static final String FIND_SERVICE_PROPERTY_ACTION = "FindServicePropertyAction";
082:
083: private static final String EDIT_USER_REGISTRATION_INFORMATION_ACTION = "FindUserRegistrationInformationAction";
084:
085: private static final String TEST_LOGIN_NAME = "scott";
086:
087: private FindServicePropertyEvent servicePropertyEvent;
088:
089: public FindServicePropertyActionTest(String testName) {
090: super (testName);
091: }
092:
093: protected void setUp() throws Exception {
094: super .setUp();
095:
096: }
097:
098: public void testFindUserInfo() {
099: try {
100: servicePropertyEvent = createServicePropertyEvent();
101: if (servicePropertyEvent.getServicePropertyKey() != null) {
102: findServiceProperty();
103: }
104: } catch (RuntimeException e) {
105: fail(e.getMessage());
106: }
107: Assert.assertEquals(true, true);
108: }
109:
110: public void findServiceProperty() throws RuntimeException {
111:
112: try {
113: ActionProcessorSingleton actionProcessorSingleton = ActionProcessorSingleton
114: .getInstance();
115:
116: ServiceProperty serviceProperty = (ServiceProperty) actionProcessorSingleton
117: .execute(FIND_SERVICE_PROPERTY_ACTION,
118: servicePropertyEvent);
119:
120: System.out
121: .println("Property correctly read from repository");
122: } catch (InternalErrorException e) {
123: throw new RuntimeException(e.getMessage());
124: } catch (ModelException e) {
125: throw new RuntimeException(e.getMessage());
126: }
127:
128: }
129:
130: private FindServicePropertyEvent createServicePropertyEvent()
131: throws RuntimeException {
132:
133: try {
134:
135: RepositoryAccessorFactory repositoryAccessorFactory = RepositoryAccessorFactory
136: .getInstance();
137:
138: UserRegistrationInformationAccessor userRegInfoAccessor = repositoryAccessorFactory
139: .createUserRegistrationInformationAccessor();
140:
141: UserRegistrationInformation userRegistrationInformation = userRegInfoAccessor
142: .findUserRegistrationInformation(TEST_LOGIN_NAME);
143:
144: EditorFactory editorFactory = EditorFactory.getInstance();
145: UserRegistrationInformationEditor userRegInfoEditor = editorFactory
146: .createUserRegistrationInformationEditor(userRegistrationInformation
147: .getProperty());
148:
149: DesktopLayoutAccessor desktopLayoutAccessor = repositoryAccessorFactory
150: .createDesktopLayoutAccessor();
151:
152: DesktopLayout desktopLayout = desktopLayoutAccessor
153: .findDesktopLayout(userRegInfoEditor
154: .getDesktopLayoutPropertyIdentifier());
155:
156: DesktopLayoutEditor desktopLayoutEditor = editorFactory
157: .createDesktopLayoutEditor(desktopLayout
158: .getProperty());
159:
160: WorkspaceLayoutAccessor workspaceLayoutAccessor = repositoryAccessorFactory
161: .createWorkspaceLayoutAccessor();
162:
163: WorkspaceLayout workspaceLayout = workspaceLayoutAccessor
164: .findWorkspaceLayout(desktopLayoutEditor
165: .getDefaultWorkspaceLayoutIdentifier());
166:
167: WorkspaceLayoutEditor workspaceLayoutEditor = editorFactory
168: .createWorkspaceLayoutEditor(workspaceLayout
169: .getProperty());
170:
171: Iterator serviceKeysIter = workspaceLayoutEditor
172: .getServiceKeys().entrySet().iterator();
173: ServicePropertyKey servicePropertyKey = null;
174:
175: while ((serviceKeysIter.hasNext())
176: && (servicePropertyKey == null)) {
177: Map.Entry entry = (Map.Entry) serviceKeysIter.next();
178: List servicePropertyList = (List) entry.getValue();
179: if (!servicePropertyList.isEmpty()) {
180: ServiceKeys serviceKeys = (ServiceKeys) servicePropertyList
181: .get(0);
182: servicePropertyKey = serviceKeys
183: .getServicePropertyKey();
184: }
185: }
186:
187: UserGroupAccessor userGroupAccessor = repositoryAccessorFactory
188: .createUserGroupAccessor();
189: Collection userGroupIdentifiers = new ArrayList();
190: Collection userGroups = userGroupAccessor
191: .findAllGroupsAssignedToUser(TEST_LOGIN_NAME);
192: Iterator userGroupsIterator = userGroups.iterator();
193: while (userGroupsIterator.hasNext()) {
194: UserGroup userGroup = (UserGroup) userGroupsIterator
195: .next();
196: userGroupIdentifiers.add(userGroup
197: .getUserGroupIdentifier());
198: }
199:
200: FindServicePropertyEvent event = new FindServicePropertyEvent(
201: new UserCredentials(TEST_LOGIN_NAME,
202: userGroupIdentifiers), servicePropertyKey);
203:
204: return event;
205:
206: } catch (Exception e) {
207: throw new RuntimeException(e.getMessage());
208: }
209: }
210:
211: }
|