001: /*
002: * $Header: /export/home/cvsroot/MyPersonalizerRepository/MyPersonalizer/Subsystems/Portal/Sources/es/udc/mypersonalizer/portal/model/actions/mainpage/MainPageActionTest.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.mainpage;
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.UserGroup;
061: import es.udc.mypersonalizer.kernel.model.repository.interfaces.UserGroupAccessor;
062: import es.udc.mypersonalizer.kernel.model.repository.interfaces.UserRegistrationInformation;
063: import es.udc.mypersonalizer.kernel.model.repository.interfaces.UserRegistrationInformationAccessor;
064: import es.udc.mypersonalizer.kernel.model.repository.interfaces.WorkspaceLayout;
065: import es.udc.mypersonalizer.kernel.model.repository.interfaces.WorkspaceLayoutAccessor;
066: import es.udc.mypersonalizer.kernel.util.exceptions.InternalErrorException;
067: import es.udc.mypersonalizer.kernel.util.exceptions.ModelException;
068: import es.udc.mypersonalizer.portal.model.permissions.UserCredentials;
069: import es.udc.mypersonalizer.portal.model.types.mainpage.MainPageEvent;
070: import es.udc.mypersonalizer.portal.model.types.mainpage.MainPageResult;
071:
072: /**
073: * Test suite for {@link MainPageAction}.
074: *
075: * @author Daniel Fernandez
076: * @since 1.0
077: */
078: public class MainPageActionTest extends TestCase {
079:
080: private static final String MAIN_PAGE_ACTION = "MainPageAction";
081:
082: private static final String EDIT_USER_REGISTRATION_INFORMATION_ACTION = "FindUserRegistrationInformationAction";
083:
084: private static final String TEST_LOGIN_NAME = "scott";
085:
086: private MainPageEvent mainPageEvent;
087:
088: public MainPageActionTest(String testName) {
089: super (testName);
090: }
091:
092: protected void setUp() throws Exception {
093: super .setUp();
094:
095: }
096:
097: public void testFindMainPageContents() {
098: try {
099: mainPageEvent = createMainPageEvent();
100: findMainPageContents();
101: } catch (RuntimeException e) {
102: fail(e.getMessage());
103: }
104: Assert.assertEquals(true, true);
105: }
106:
107: public void findMainPageContents() throws RuntimeException {
108:
109: try {
110: ActionProcessorSingleton actionProcessorSingleton = ActionProcessorSingleton
111: .getInstance();
112:
113: System.out.println("About to read "
114: + mainPageEvent.getServicePropertyKeys().size()
115: + " service properties from repository");
116: MainPageResult mainPageResult = (MainPageResult) actionProcessorSingleton
117: .execute(MAIN_PAGE_ACTION, mainPageEvent);
118:
119: System.out
120: .println("Service Properties correctly read "
121: + "from repository: "
122: + mainPageResult
123: .getServicePropertiesByKey().size());
124: } catch (InternalErrorException e) {
125: throw new RuntimeException(e.getMessage());
126: } catch (ModelException e) {
127: throw new RuntimeException(e.getMessage());
128: }
129:
130: }
131:
132: private MainPageEvent createMainPageEvent() throws RuntimeException {
133:
134: try {
135:
136: RepositoryAccessorFactory repositoryAccessorFactory = RepositoryAccessorFactory
137: .getInstance();
138:
139: UserRegistrationInformationAccessor userRegInfoAccessor = repositoryAccessorFactory
140: .createUserRegistrationInformationAccessor();
141:
142: UserRegistrationInformation userRegistrationInformation = userRegInfoAccessor
143: .findUserRegistrationInformation(TEST_LOGIN_NAME);
144:
145: EditorFactory editorFactory = EditorFactory.getInstance();
146: UserRegistrationInformationEditor userRegInfoEditor = editorFactory
147: .createUserRegistrationInformationEditor(userRegistrationInformation
148: .getProperty());
149:
150: DesktopLayoutAccessor desktopLayoutAccessor = repositoryAccessorFactory
151: .createDesktopLayoutAccessor();
152:
153: DesktopLayout desktopLayout = desktopLayoutAccessor
154: .findDesktopLayout(userRegInfoEditor
155: .getDesktopLayoutPropertyIdentifier());
156:
157: DesktopLayoutEditor desktopLayoutEditor = editorFactory
158: .createDesktopLayoutEditor(desktopLayout
159: .getProperty());
160:
161: WorkspaceLayoutAccessor workspaceLayoutAccessor = repositoryAccessorFactory
162: .createWorkspaceLayoutAccessor();
163:
164: WorkspaceLayout workspaceLayout = workspaceLayoutAccessor
165: .findWorkspaceLayout(desktopLayoutEditor
166: .getDefaultWorkspaceLayoutIdentifier());
167:
168: WorkspaceLayoutEditor workspaceLayoutEditor = editorFactory
169: .createWorkspaceLayoutEditor(workspaceLayout
170: .getProperty());
171:
172: Map currentWorkspaceServiceKeys = workspaceLayoutEditor
173: .getServiceKeys();
174:
175: List servicePropertyKeysList = getServicePropertyKeysAsList(currentWorkspaceServiceKeys);
176:
177: UserGroupAccessor userGroupAccessor = repositoryAccessorFactory
178: .createUserGroupAccessor();
179: Collection userGroupIdentifiers = new ArrayList();
180: Collection userGroups = userGroupAccessor
181: .findAllGroupsAssignedToUser(TEST_LOGIN_NAME);
182: Iterator userGroupsIterator = userGroups.iterator();
183: while (userGroupsIterator.hasNext()) {
184: UserGroup userGroup = (UserGroup) userGroupsIterator
185: .next();
186: userGroupIdentifiers.add(userGroup
187: .getUserGroupIdentifier());
188: }
189:
190: MainPageEvent event = new MainPageEvent(
191: new UserCredentials(TEST_LOGIN_NAME,
192: userGroupIdentifiers),
193: servicePropertyKeysList);
194:
195: return event;
196:
197: } catch (Exception e) {
198: throw new RuntimeException(e.getMessage());
199: }
200: }
201:
202: private List getServicePropertyKeysAsList(Map serviceKeysAsMap) {
203: List servicePropertyKeysAsList = new ArrayList();
204: Iterator entryIter = serviceKeysAsMap.entrySet().iterator();
205: while (entryIter.hasNext()) {
206: Map.Entry entry = (Map.Entry) entryIter.next();
207: List currentServiceKeys = (List) entry.getValue();
208: Iterator serviceKeysIter = currentServiceKeys.iterator();
209: while (serviceKeysIter.hasNext()) {
210: ServiceKeys serviceKeys = (ServiceKeys) serviceKeysIter
211: .next();
212: servicePropertyKeysAsList.add(serviceKeys
213: .getServicePropertyKey());
214: }
215: }
216: return servicePropertyKeysAsList;
217: }
218:
219: }
|