OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
EstateTests.cs
Go to the documentation of this file.
1 /*
2  * Copyright (c) Contributors, http://opensimulator.org/
3  * See CONTRIBUTORS.TXT for a full list of copyright holders.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of the OpenSimulator Project nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 using System;
29 using log4net.Config;
30 using NUnit.Framework;
31 using OpenMetaverse;
32 using OpenSim.Framework;
33 using OpenSim.Region.Framework.Interfaces;
34 using OpenSim.Tests.Common;
35 using System.Text;
36 using log4net;
37 using System.Reflection;
38 using System.Data.Common;
39 
40 // DBMS-specific:
41 using MySql.Data.MySqlClient;
42 using OpenSim.Data.MySQL;
43 
44 using Mono.Data.Sqlite;
45 using OpenSim.Data.SQLite;
46 
47 namespace OpenSim.Data.Tests
48 {
49  [TestFixture(Description = "Estate store tests (SQLite)")]
50  public class SQLiteEstateTests : EstateTests<SqliteConnection, SQLiteEstateStore>
51  {
52  }
53 
54  [TestFixture(Description = "Estate store tests (MySQL)")]
55  public class MySqlEstateTests : EstateTests<MySqlConnection, MySQLEstateStore>
56  {
57  }
58 
59  public class EstateTests<TConn, TEstateStore> : BasicDataServiceTest<TConn, TEstateStore>
60  where TConn : DbConnection, new()
61  where TEstateStore : class, IEstateDataStore, new()
62  {
64 
65  public static UUID REGION_ID = new UUID("250d214e-1c7e-4f9b-a488-87c5e53feed7");
66 
67  public static UUID USER_ID_1 = new UUID("250d214e-1c7e-4f9b-a488-87c5e53feed1");
68  public static UUID USER_ID_2 = new UUID("250d214e-1c7e-4f9b-a488-87c5e53feed2");
69 
70  public static UUID MANAGER_ID_1 = new UUID("250d214e-1c7e-4f9b-a488-87c5e53feed3");
71  public static UUID MANAGER_ID_2 = new UUID("250d214e-1c7e-4f9b-a488-87c5e53feed4");
72 
73  public static UUID GROUP_ID_1 = new UUID("250d214e-1c7e-4f9b-a488-87c5e53feed5");
74  public static UUID GROUP_ID_2 = new UUID("250d214e-1c7e-4f9b-a488-87c5e53feed6");
75 
76  protected override void InitService(object service)
77  {
78  ClearDB();
79  db = (IEstateDataStore)service;
80  db.Initialise(m_connStr);
81  }
82 
83  private void ClearDB()
84  {
85  // if a new table is added, it has to be dropped here
86  DropTables(
87  "estate_managers",
88  "estate_groups",
89  "estate_users",
90  "estateban",
91  "estate_settings",
92  "estate_map"
93  );
94  ResetMigrations("EstateStore");
95  }
96 
97  #region 0Tests
98 
99  [Test]
101  {
102  TestHelpers.InMethod();
103 
104  EstateSettingsSimpleStorage(
105  REGION_ID,
129  );
130  }
131 
132  [Test]
134  {
135  TestHelpers.InMethod();
136 
137  EstateSettingsSimpleStorage(
138  REGION_ID,
140  DataTestUtil.UNSIGNED_INTEGER_MAX,
141  DataTestUtil.FLOAT_MAX,
142  DataTestUtil.INTEGER_MAX,
143  DataTestUtil.INTEGER_MAX,
144  DataTestUtil.INTEGER_MAX,
145  DataTestUtil.BOOLEAN_MAX,
146  DataTestUtil.BOOLEAN_MAX,
147  DataTestUtil.DOUBLE_MAX,
148  DataTestUtil.BOOLEAN_MAX,
149  DataTestUtil.BOOLEAN_MAX,
150  DataTestUtil.BOOLEAN_MAX,
151  DataTestUtil.BOOLEAN_MAX,
152  DataTestUtil.BOOLEAN_MAX,
153  DataTestUtil.BOOLEAN_MAX,
154  DataTestUtil.BOOLEAN_MAX,
155  DataTestUtil.BOOLEAN_MAX,
156  DataTestUtil.BOOLEAN_MAX,
157  DataTestUtil.BOOLEAN_MAX,
158  DataTestUtil.BOOLEAN_MAX,
159  DataTestUtil.BOOLEAN_MAX,
160  DataTestUtil.STRING_MAX(255),
162  );
163  }
164 
165  [Test]
167  {
168  TestHelpers.InMethod();
169 
170  EstateSettingsSimpleStorage(
171  REGION_ID,
173  DataTestUtil.UNSIGNED_INTEGER_MIN,
174  DataTestUtil.FLOAT_ACCURATE,
175  DataTestUtil.INTEGER_MIN,
176  DataTestUtil.INTEGER_MIN,
177  DataTestUtil.INTEGER_MIN,
178  DataTestUtil.BOOLEAN_MIN,
179  DataTestUtil.BOOLEAN_MIN,
180  DataTestUtil.DOUBLE_ACCURATE,
181  DataTestUtil.BOOLEAN_MIN,
182  DataTestUtil.BOOLEAN_MIN,
183  DataTestUtil.BOOLEAN_MIN,
184  DataTestUtil.BOOLEAN_MIN,
185  DataTestUtil.BOOLEAN_MIN,
186  DataTestUtil.BOOLEAN_MIN,
187  DataTestUtil.BOOLEAN_MIN,
188  DataTestUtil.BOOLEAN_MIN,
189  DataTestUtil.BOOLEAN_MIN,
190  DataTestUtil.BOOLEAN_MIN,
191  DataTestUtil.BOOLEAN_MIN,
192  DataTestUtil.BOOLEAN_MIN,
193  DataTestUtil.STRING_MAX(1),
195  );
196  }
197 
198  [Test]
200  {
201  TestHelpers.InMethod();
202 
203  // Letting estate store generate rows to database for us
204  EstateSettings originalSettings = db.LoadEstateSettings(REGION_ID, true);
205  new PropertyScrambler<EstateSettings>()
206  .DontScramble(x=>x.EstateID)
207  .Scramble(originalSettings);
208 
209  // Saving settings.
210  db.StoreEstateSettings(originalSettings);
211 
212  // Loading settings to another instance variable.
213  EstateSettings loadedSettings = db.LoadEstateSettings(REGION_ID, true);
214 
215  // Checking that loaded values are correct.
216  Assert.That(loadedSettings, Constraints.PropertyCompareConstraint(originalSettings));
217  }
218 
219  [Test]
221  {
222  TestHelpers.InMethod();
223 
224  // Letting estate store generate rows to database for us
225  EstateSettings originalSettings = db.LoadEstateSettings(REGION_ID, true);
226 
227  originalSettings.EstateManagers = new UUID[] { MANAGER_ID_1, MANAGER_ID_2 };
228 
229  // Saving settings.
230  db.StoreEstateSettings(originalSettings);
231 
232  // Loading settings to another instance variable.
233  EstateSettings loadedSettings = db.LoadEstateSettings(REGION_ID, true);
234 
235  Assert.AreEqual(2, loadedSettings.EstateManagers.Length);
236  Assert.AreEqual(MANAGER_ID_1, loadedSettings.EstateManagers[0]);
237  Assert.AreEqual(MANAGER_ID_2, loadedSettings.EstateManagers[1]);
238  }
239 
240  [Test]
242  {
243  TestHelpers.InMethod();
244 
245  // Letting estate store generate rows to database for us
246  EstateSettings originalSettings = db.LoadEstateSettings(REGION_ID, true);
247 
248  originalSettings.EstateAccess = new UUID[] { USER_ID_1, USER_ID_2 };
249 
250  // Saving settings.
251  db.StoreEstateSettings(originalSettings);
252 
253  // Loading settings to another instance variable.
254  EstateSettings loadedSettings = db.LoadEstateSettings(REGION_ID, true);
255 
256  Assert.AreEqual(2, loadedSettings.EstateAccess.Length);
257  Assert.AreEqual(USER_ID_1, loadedSettings.EstateAccess[0]);
258  Assert.AreEqual(USER_ID_2, loadedSettings.EstateAccess[1]);
259  }
260 
261  [Test]
263  {
264  TestHelpers.InMethod();
265 
266  // Letting estate store generate rows to database for us
267  EstateSettings originalSettings = db.LoadEstateSettings(REGION_ID, true);
268 
269  originalSettings.EstateGroups = new UUID[] { GROUP_ID_1, GROUP_ID_2 };
270 
271  // Saving settings.
272  db.StoreEstateSettings(originalSettings);
273 
274  // Loading settings to another instance variable.
275  EstateSettings loadedSettings = db.LoadEstateSettings(REGION_ID, true);
276 
277  Assert.AreEqual(2, loadedSettings.EstateAccess.Length);
278  Assert.AreEqual(GROUP_ID_1, loadedSettings.EstateGroups[0]);
279  Assert.AreEqual(GROUP_ID_2, loadedSettings.EstateGroups[1]);
280  }
281 
282  [Test]
284  {
285  TestHelpers.InMethod();
286 
287  // Letting estate store generate rows to database for us
288  EstateSettings originalSettings = db.LoadEstateSettings(REGION_ID, true);
289 
290  EstateBan estateBan1 = new EstateBan();
291  estateBan1.BannedUserID = DataTestUtil.UUID_MIN;
292 
293  EstateBan estateBan2 = new EstateBan();
294  estateBan2.BannedUserID = DataTestUtil.UUID_MAX;
295 
296  originalSettings.EstateBans = new EstateBan[] { estateBan1, estateBan2 };
297 
298  // Saving settings.
299  db.StoreEstateSettings(originalSettings);
300 
301  // Loading settings to another instance variable.
302  EstateSettings loadedSettings = db.LoadEstateSettings(REGION_ID, true);
303 
304  Assert.AreEqual(2, loadedSettings.EstateBans.Length);
305  Assert.AreEqual(DataTestUtil.UUID_MIN, loadedSettings.EstateBans[0].BannedUserID);
306 
307  Assert.AreEqual(DataTestUtil.UUID_MAX, loadedSettings.EstateBans[1].BannedUserID);
308 
309  }
310 
311  #endregion
312 
313  #region Parametrizable Test Implementations
314 
315  private void EstateSettingsSimpleStorage(
316  UUID regionId,
317  string estateName,
318  uint parentEstateID,
319  float billableFactor,
320  int pricePerMeter,
321  int redirectGridX,
322  int redirectGridY,
323  bool useGlobalTime,
324  bool fixedSun,
325  double sunPosition,
326  bool allowVoice,
327  bool allowDirectTeleport,
328  bool resetHomeOnTeleport,
329  bool denyAnonymous,
330  bool denyIdentified,
331  bool denyTransacted,
332  bool denyMinors,
333  bool abuseEmailToEstateOwner,
334  bool blockDwell,
335  bool estateSkipScripts,
336  bool taxFree,
337  bool publicAccess,
338  string abuseEmail,
339  UUID estateOwner
340  )
341  {
342 
343  // Letting estate store generate rows to database for us
344  EstateSettings originalSettings = db.LoadEstateSettings(regionId, true);
345 
346  SetEstateSettings(originalSettings,
347  estateName,
348  parentEstateID,
349  billableFactor,
350  pricePerMeter,
351  redirectGridX,
352  redirectGridY,
353  useGlobalTime,
354  fixedSun,
355  sunPosition,
356  allowVoice,
357  allowDirectTeleport,
358  resetHomeOnTeleport,
359  denyAnonymous,
360  denyIdentified,
361  denyTransacted,
362  denyMinors,
363  abuseEmailToEstateOwner,
364  blockDwell,
365  estateSkipScripts,
366  taxFree,
367  publicAccess,
368  abuseEmail,
369  estateOwner
370  );
371 
372  // Saving settings.
373  db.StoreEstateSettings(originalSettings);
374 
375  // Loading settings to another instance variable.
376  EstateSettings loadedSettings = db.LoadEstateSettings(regionId, true);
377 
378  // Checking that loaded values are correct.
379  ValidateEstateSettings(loadedSettings,
380  estateName,
381  parentEstateID,
382  billableFactor,
383  pricePerMeter,
384  redirectGridX,
385  redirectGridY,
386  useGlobalTime,
387  fixedSun,
388  sunPosition,
389  allowVoice,
390  allowDirectTeleport,
391  resetHomeOnTeleport,
392  denyAnonymous,
393  denyIdentified,
394  denyTransacted,
395  denyMinors,
396  abuseEmailToEstateOwner,
397  blockDwell,
398  estateSkipScripts,
399  taxFree,
400  publicAccess,
401  abuseEmail,
402  estateOwner
403  );
404 
405  }
406 
407  #endregion
408 
409  #region EstateSetting Initialization and Validation Methods
410 
411  private void SetEstateSettings(
412  EstateSettings estateSettings,
413  string estateName,
414  uint parentEstateID,
415  float billableFactor,
416  int pricePerMeter,
417  int redirectGridX,
418  int redirectGridY,
419  bool useGlobalTime,
420  bool fixedSun,
421  double sunPosition,
422  bool allowVoice,
423  bool allowDirectTeleport,
424  bool resetHomeOnTeleport,
425  bool denyAnonymous,
426  bool denyIdentified,
427  bool denyTransacted,
428  bool denyMinors,
429  bool abuseEmailToEstateOwner,
430  bool blockDwell,
431  bool estateSkipScripts,
432  bool taxFree,
433  bool publicAccess,
434  string abuseEmail,
435  UUID estateOwner
436  )
437  {
438  estateSettings.EstateName = estateName;
439  estateSettings.ParentEstateID = parentEstateID;
440  estateSettings.BillableFactor = billableFactor;
441  estateSettings.PricePerMeter = pricePerMeter;
442  estateSettings.RedirectGridX = redirectGridX;
443  estateSettings.RedirectGridY = redirectGridY;
444  estateSettings.UseGlobalTime = useGlobalTime;
445  estateSettings.FixedSun = fixedSun;
446  estateSettings.SunPosition = sunPosition;
447  estateSettings.AllowVoice = allowVoice;
448  estateSettings.AllowDirectTeleport = allowDirectTeleport;
449  estateSettings.ResetHomeOnTeleport = resetHomeOnTeleport;
450  estateSettings.DenyAnonymous = denyAnonymous;
451  estateSettings.DenyIdentified = denyIdentified;
452  estateSettings.DenyTransacted = denyTransacted;
453  estateSettings.DenyMinors = denyMinors;
454  estateSettings.AbuseEmailToEstateOwner = abuseEmailToEstateOwner;
455  estateSettings.BlockDwell = blockDwell;
456  estateSettings.EstateSkipScripts = estateSkipScripts;
457  estateSettings.TaxFree = taxFree;
458  estateSettings.PublicAccess = publicAccess;
459  estateSettings.AbuseEmail = abuseEmail;
460  estateSettings.EstateOwner = estateOwner;
461  }
462 
463  private void ValidateEstateSettings(
464  EstateSettings estateSettings,
465  string estateName,
466  uint parentEstateID,
467  float billableFactor,
468  int pricePerMeter,
469  int redirectGridX,
470  int redirectGridY,
471  bool useGlobalTime,
472  bool fixedSun,
473  double sunPosition,
474  bool allowVoice,
475  bool allowDirectTeleport,
476  bool resetHomeOnTeleport,
477  bool denyAnonymous,
478  bool denyIdentified,
479  bool denyTransacted,
480  bool denyMinors,
481  bool abuseEmailToEstateOwner,
482  bool blockDwell,
483  bool estateSkipScripts,
484  bool taxFree,
485  bool publicAccess,
486  string abuseEmail,
487  UUID estateOwner
488  )
489  {
490  Assert.AreEqual(estateName, estateSettings.EstateName);
491  Assert.AreEqual(parentEstateID, estateSettings.ParentEstateID);
492 
493  DataTestUtil.AssertFloatEqualsWithTolerance(billableFactor, estateSettings.BillableFactor);
494 
495  Assert.AreEqual(pricePerMeter, estateSettings.PricePerMeter);
496  Assert.AreEqual(redirectGridX, estateSettings.RedirectGridX);
497  Assert.AreEqual(redirectGridY, estateSettings.RedirectGridY);
498  Assert.AreEqual(useGlobalTime, estateSettings.UseGlobalTime);
499  Assert.AreEqual(fixedSun, estateSettings.FixedSun);
500 
501  DataTestUtil.AssertDoubleEqualsWithTolerance(sunPosition, estateSettings.SunPosition);
502 
503  Assert.AreEqual(allowVoice, estateSettings.AllowVoice);
504  Assert.AreEqual(allowDirectTeleport, estateSettings.AllowDirectTeleport);
505  Assert.AreEqual(resetHomeOnTeleport, estateSettings.ResetHomeOnTeleport);
506  Assert.AreEqual(denyAnonymous, estateSettings.DenyAnonymous);
507  Assert.AreEqual(denyIdentified, estateSettings.DenyIdentified);
508  Assert.AreEqual(denyTransacted, estateSettings.DenyTransacted);
509  Assert.AreEqual(denyMinors, estateSettings.DenyMinors);
510  Assert.AreEqual(abuseEmailToEstateOwner, estateSettings.AbuseEmailToEstateOwner);
511  Assert.AreEqual(blockDwell, estateSettings.BlockDwell);
512  Assert.AreEqual(estateSkipScripts, estateSettings.EstateSkipScripts);
513  Assert.AreEqual(taxFree, estateSettings.TaxFree);
514  Assert.AreEqual(publicAccess, estateSettings.PublicAccess);
515  Assert.AreEqual(abuseEmail, estateSettings.AbuseEmail);
516  Assert.AreEqual(estateOwner, estateSettings.EstateOwner);
517  }
518 
519  #endregion
520  }
521 }
override void InitService(object service)
To be overridden in derived classes. Do whatever init with the m_service, like setting the conn strin...
Definition: EstateTests.cs:76
static string STRING_MAX(int length)
Definition: DataTestUtil.cs:59
Shared constants and methods for database unit tests.
Definition: DataTestUtil.cs:39