001: /*
002: * $Header: /export/home/cvsroot/MyPersonalizerRepository/MyPersonalizer/Subsystems/Portal/Sources/es/udc/mypersonalizer/portal/model/wizards/UpdateSimplePropertiesUpdaterTest.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 "updateSimpleProperties" property updater.
057: *
058: * @author Daniel Fernandez
059: * @since 1.0
060: */
061: public class UpdateSimplePropertiesUpdaterTest extends TestCase {
062:
063: private WizardEvent newPropertyCreationEvent;
064: private WizardEvent propertyUpdateEvent;
065:
066: private Property newPropertyCreationProperty;
067: private Property propertyUpdateProperty;
068:
069: private Property newPropertyCreationDesiredProperty;
070: private Property propertyUpdateDesiredProperty;
071:
072: /**
073: * @param arg0
074: */
075: public UpdateSimplePropertiesUpdaterTest(String arg0) {
076: super (arg0);
077: }
078:
079: /**
080: * @see TestCase#setUp()
081: */
082: protected void setUp() throws Exception {
083: super .setUp();
084: createNewPropertySetUp();
085: updatePropertySetUp();
086: }
087:
088: public void testInOrder() {
089: createNewProperty();
090: updateProperty();
091: }
092:
093: public void createNewProperty() {
094: try {
095: PropertyUpdater propertyUpdater = new UpdateSimplePropertiesUpdater();
096: propertyUpdater.update(newPropertyCreationProperty,
097: newPropertyCreationEvent);
098: Assert.assertEquals(newPropertyCreationProperty,
099: newPropertyCreationDesiredProperty);
100: } catch (Exception e) {
101: fail("createNewProperty: Unexpected exception\n***********\n"
102: + e);
103: }
104: }
105:
106: public void updateProperty() {
107: try {
108: PropertyUpdater propertyUpdater = new UpdateSimplePropertiesUpdater();
109: propertyUpdater.update(propertyUpdateProperty,
110: propertyUpdateEvent);
111: Assert.assertEquals(propertyUpdateProperty,
112: propertyUpdateDesiredProperty);
113: } catch (Exception e) {
114: fail("testPropertyUpdate: Unexpected exception\n***********\n"
115: + e);
116: }
117: }
118:
119: private void createNewPropertySetUp() {
120:
121: /* WizardEvent stuff */
122: String loginName = "pepe";
123: Map properties = new HashMap();
124: properties.put("name", new String[] { "Jose Gonzalez" });
125: properties.put("address", new String[] { "Gran Via, 4" });
126: properties.put("hobbies", new String[] { "Fishing", "Swimming",
127: "Golf" });
128: properties.put("age", new String[0]);
129:
130: /* Property stuff */
131: String name = "userStuffForCreation";
132: Map contents = new HashMap();
133: contents.put(UserRegistrationInformationEditor.LOGIN_NAME,
134: new String[] { "pepe" });
135: contents.put("name", new String[0]);
136: contents.put("address", new String[0]);
137: contents.put("hobbies", new String[0]);
138: contents.put("age", new String[0]);
139:
140: /* Desired Property stuff */
141: String desiredName = "userStuffForCreation";
142: Map desiredContents = new HashMap();
143: desiredContents.put(
144: UserRegistrationInformationEditor.LOGIN_NAME,
145: new String[] { "pepe" });
146: desiredContents.put("name", new String[] { "Jose Gonzalez" });
147: desiredContents.put("address", new String[] { "Gran Via, 4" });
148: desiredContents.put("hobbies", new String[] { "Fishing",
149: "Swimming", "Golf" });
150: desiredContents.put("age", new String[0]);
151:
152: /* Finally, create the whole thing */
153: newPropertyCreationEvent = createWizardEvent(loginName,
154: properties);
155: newPropertyCreationProperty = createProperty(name, contents);
156: newPropertyCreationDesiredProperty = createProperty(
157: desiredName, desiredContents);
158: }
159:
160: private void updatePropertySetUp() {
161:
162: /* WizardEvent stuff */
163: String loginName = "luis";
164: Map properties = new HashMap();
165: properties.put("name", new String[] { "Luis Garcigomez" });
166: properties.put("address", new String[] { "Felipe II, 12" });
167: properties.put("hobbies", new String[] { "Bullfighting",
168: "Football" });
169: properties.put("age", new String[0]);
170:
171: /* Property stuff */
172: String name = "userStuffForUpdate";
173: Map contents = new HashMap();
174: contents.put(UserRegistrationInformationEditor.LOGIN_NAME,
175: new String[] { "luis" });
176: contents.put("name",
177: new String[] { "Luis Garcigomez Villuela" });
178: contents.put("address", new String[] { "Felipe II, 12" });
179: contents.put("hobbies", new String[] { "Bullfighting" });
180: contents.put("age", new String[] { "25" });
181:
182: /* Desired Property stuff */
183: String desiredName = "userStuffForUpdate";
184: Map desiredContents = new HashMap();
185: desiredContents.put(
186: UserRegistrationInformationEditor.LOGIN_NAME,
187: new String[] { "luis" });
188: desiredContents.put("name", new String[] { "Luis Garcigomez" });
189: desiredContents
190: .put("address", new String[] { "Felipe II, 12" });
191: desiredContents.put("hobbies", new String[] { "Bullfighting",
192: "Football" });
193: desiredContents.put("age", new String[0]);
194:
195: /* Finally, create the whole thing */
196: propertyUpdateEvent = createWizardEvent(loginName, properties);
197: propertyUpdateProperty = createProperty(name, contents);
198: propertyUpdateDesiredProperty = createProperty(desiredName,
199: desiredContents);
200: }
201:
202: /*
203: * +-------------------------+
204: * | UTILITY METHODS |
205: * +-------------------------+
206: */
207:
208: private Property createProperty(String name, Map contents) {
209:
210: PropertyStructure propertyStructure = new PropertyStructure();
211: Iterator contentIterator = contents.entrySet().iterator();
212: while (contentIterator.hasNext()) {
213: Map.Entry entry = (Map.Entry) contentIterator.next();
214: String propertyName = (String) entry.getKey();
215: String[] propertyValues = (String[]) entry.getValue();
216:
217: try {
218: SimpleProperty simpleProperty = new SimpleProperty(
219: propertyName, propertyValues, Class
220: .forName("java.lang.String"));
221: propertyStructure.put(simpleProperty);
222:
223: } catch (Exception e) {
224: fail("createProperty: Unexpected exception\n***********\n"
225: + e);
226: }
227:
228: }
229:
230: Property result = new CompoundProperty(name,
231: new PropertyStructure[] { propertyStructure });
232:
233: return result;
234:
235: }
236:
237: private WizardEvent createWizardEvent(String loginName,
238: Map properties) {
239:
240: UserCredentials userCredentials = new UserCredentials(
241: loginName, null);
242:
243: String serviceIdentifier = ServiceConventions.USER_REGISTRATION_INFORMATION_SERVICE_IDENTIFIER;
244: String propertySetterCommand = "updateSimpleProperties";
245:
246: String propertyStructureName = "0";
247:
248: Long propertyIdentifier = new Long(0L);
249:
250: return new WizardEvent(userCredentials, properties,
251: serviceIdentifier, propertySetterCommand,
252: propertyStructureName, propertyIdentifier);
253:
254: }
255:
256: }
|