001: /*
002: * $Header: /export/home/cvsroot/MyPersonalizerRepository/MyPersonalizer/Subsystems/Portal/Sources/es/udc/mypersonalizer/portal/model/wizards/RemovePropertyStructureUpdaterTest.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.wizards;
042:
043: import es.udc.mypersonalizer.kernel.conventions.ServiceConventions;
044: import es.udc.mypersonalizer.kernel.model.editors.UserRegistrationInformationEditor;
045: import es.udc.mypersonalizer.kernel.model.properties.CompoundProperty;
046: import es.udc.mypersonalizer.kernel.model.properties.Property;
047: import es.udc.mypersonalizer.kernel.model.properties.PropertyStructure;
048: import es.udc.mypersonalizer.kernel.model.properties.SimpleProperty;
049: import es.udc.mypersonalizer.portal.model.permissions.UserCredentials;
050: import es.udc.mypersonalizer.portal.model.types.WizardEvent;
051: import java.util.*;
052: import junit.framework.Assert;
053: import junit.framework.TestCase;
054:
055: /**
056: * Test suite for the "removePropertyStructure" property updater.
057: *
058: * @author Daniel Fernandez
059: * @since 1.0
060: */
061: public class RemovePropertyStructureUpdaterTest extends TestCase {
062:
063: private WizardEvent firstRemoveEvent;
064: private WizardEvent secondRemoveEvent;
065:
066: private Property property;
067:
068: private Property desiredPropertyAfterFirstRemove;
069: private Property desiredPropertyAfterSecondRemove;
070:
071: /**
072: * @param arg0
073: */
074: public RemovePropertyStructureUpdaterTest(String arg0) {
075: super (arg0);
076: }
077:
078: /**
079: * @see TestCase#setUp()
080: */
081: protected void setUp() throws Exception {
082: super .setUp();
083: removeFirstPropertyStructureSetUp();
084: removeSecondPropertyStructureSetUp();
085: }
086:
087: public void testInOrder() {
088: removeFirstPropertyStructure();
089: removeSecondPropertyStructure();
090: }
091:
092: public void removeFirstPropertyStructure() {
093: try {
094: PropertyUpdater propertyUpdater = new RemovePropertyStructureUpdater();
095: propertyUpdater.update(property, firstRemoveEvent);
096: Assert.assertEquals(property,
097: desiredPropertyAfterFirstRemove);
098: } catch (Exception e) {
099: fail("removeFirstPropertyStructure: "
100: + "Unexpected exception\n***********\n" + e);
101: }
102: }
103:
104: public void removeSecondPropertyStructure() {
105: try {
106: PropertyUpdater propertyUpdater = new RemovePropertyStructureUpdater();
107: propertyUpdater.update(property, secondRemoveEvent);
108: Assert.assertEquals(property,
109: desiredPropertyAfterSecondRemove);
110: } catch (Exception e) {
111: fail("removeSecondPropertyStructure: "
112: + "Unexpected exception\n***********\n" + e);
113: }
114: }
115:
116: private void removeFirstPropertyStructureSetUp() {
117:
118: /* Desired Property stuff */
119: String desiredName = "property";
120: List desiredContentsList = new ArrayList();
121:
122: /* Desired Property stuff, 1st PropertyStructure*/
123: Map desiredContents1 = new HashMap();
124: desiredContents1.put(
125: UserRegistrationInformationEditor.LOGIN_NAME,
126: new String[] { "pepe" });
127: desiredContents1.put("name", new String[] { "Jose Gonzalez" });
128: desiredContents1.put("address", new String[] { "Gran Via, 4" });
129: desiredContents1.put("hobbies", new String[] { "Fishing",
130: "Swimming", "Golf" });
131: desiredContents1.put("age", new String[0]);
132:
133: desiredContentsList.add(desiredContents1);
134:
135: /* Desired Property stuff, 2nd PropertyStructure*/
136: Map desiredContents2 = new HashMap();
137: desiredContents2.put(
138: UserRegistrationInformationEditor.LOGIN_NAME,
139: new String[] { "luis" });
140: desiredContents2
141: .put("name", new String[] { "Luis Garcigomez" });
142: desiredContents2.put("address",
143: new String[] { "Felipe II, 12" });
144: desiredContents2.put("hobbies", new String[] { "Bullfighting",
145: "Football" });
146: desiredContents2.put("age", new String[0]);
147:
148: desiredContentsList.add(desiredContents2);
149:
150: /* Finally, create the whole thing */
151: firstRemoveEvent = createRemoveWizardEvent("1");
152:
153: property = createProperty(desiredName, desiredContentsList);
154:
155: List desiredPropertyAfterFirstRemoveContents = new ArrayList();
156: desiredPropertyAfterFirstRemoveContents.add(desiredContents1);
157: desiredPropertyAfterFirstRemove = createProperty(desiredName,
158: desiredPropertyAfterFirstRemoveContents);
159: }
160:
161: private void removeSecondPropertyStructureSetUp() {
162:
163: /* Property stuff */
164: String desiredName = "property";
165:
166: secondRemoveEvent = createRemoveWizardEvent("0");
167:
168: List desiredPropertyAfterSecondRemoveContents = new ArrayList();
169: desiredPropertyAfterSecondRemove = createProperty(desiredName,
170: desiredPropertyAfterSecondRemoveContents);
171: }
172:
173: /*
174: * +-------------------------+
175: * | UTILITY METHODS |
176: * +-------------------------+
177: */
178:
179: private Property createProperty(String name, List contents) {
180:
181: List propertyStructures = new ArrayList();
182: Iterator contentsIterator = contents.iterator();
183: while (contentsIterator.hasNext()) {
184: Map contentsMap = (Map) contentsIterator.next();
185: PropertyStructure propertyStructure = new PropertyStructure();
186: Iterator contentIterator = contentsMap.entrySet()
187: .iterator();
188: while (contentIterator.hasNext()) {
189: Map.Entry entry = (Map.Entry) contentIterator.next();
190: String propertyName = (String) entry.getKey();
191: String[] propertyValues = (String[]) entry.getValue();
192:
193: try {
194: SimpleProperty simpleProperty = new SimpleProperty(
195: propertyName, propertyValues, Class
196: .forName("java.lang.String"));
197: propertyStructure.put(simpleProperty);
198:
199: } catch (Exception e) {
200: fail("createProperty: "
201: + "Unexpected exception\n***********\n" + e);
202: }
203:
204: }
205:
206: propertyStructures.add(propertyStructure);
207: }
208:
209: PropertyStructure[] propertyStructureArray = (PropertyStructure[]) propertyStructures
210: .toArray(new PropertyStructure[0]);
211: Property result = new CompoundProperty(name,
212: propertyStructureArray);
213: return result;
214:
215: }
216:
217: private WizardEvent createRemoveWizardEvent(
218: String propertyStructureName) {
219:
220: UserCredentials userCredentials = new UserCredentials(
221: "whatever", null);
222:
223: String serviceIdentifier = ServiceConventions.USER_REGISTRATION_INFORMATION_SERVICE_IDENTIFIER;
224: String propertySetterCommand = "removePropertyStructure";
225:
226: Long propertyIdentifier = new Long(0L);
227:
228: Map properties = new HashMap();
229:
230: return new WizardEvent(userCredentials, properties,
231: serviceIdentifier, propertySetterCommand,
232: propertyStructureName, propertyIdentifier);
233:
234: }
235:
236: }
|