AssetConnectorTests.cs 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. using System;
  28. using System.Collections.Generic;
  29. using System.IO;
  30. using System.Reflection;
  31. using System.Threading;
  32. using log4net.Config;
  33. using Nini.Config;
  34. using NUnit.Framework;
  35. using OpenMetaverse;
  36. using OpenSim.Framework;
  37. using OpenSim.Region.Framework.Scenes;
  38. using OpenSim.Region.CoreModules.ServiceConnectorsOut.Asset;
  39. using OpenSim.Tests.Common;
  40. namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Asset.Tests
  41. {
  42. [TestFixture]
  43. public class AssetConnectorTests : OpenSimTestCase
  44. {
  45. [Test]
  46. public void TestAddAsset()
  47. {
  48. TestHelpers.InMethod();
  49. // TestHelpers.EnableLogging();
  50. IConfigSource config = new IniConfigSource();
  51. config.AddConfig("Modules");
  52. config.Configs["Modules"].Set("AssetServices", "LocalAssetServicesConnector");
  53. config.AddConfig("AssetService");
  54. config.Configs["AssetService"].Set("LocalServiceModule", "OpenSim.Services.AssetService.dll:AssetService");
  55. config.Configs["AssetService"].Set("StorageProvider", "OpenSim.Tests.Common.dll");
  56. LocalAssetServicesConnector lasc = new LocalAssetServicesConnector();
  57. lasc.Initialise(config);
  58. AssetBase a1 = AssetHelpers.CreateNotecardAsset();
  59. lasc.Store(a1);
  60. AssetBase retreivedA1 = lasc.Get(a1.ID);
  61. Assert.That(retreivedA1.ID, Is.EqualTo(a1.ID));
  62. Assert.That(retreivedA1.Metadata.ID, Is.EqualTo(a1.Metadata.ID));
  63. Assert.That(retreivedA1.Data.Length, Is.EqualTo(a1.Data.Length));
  64. AssetMetadata retrievedA1Metadata = lasc.GetMetadata(a1.ID);
  65. Assert.That(retrievedA1Metadata.ID, Is.EqualTo(a1.ID));
  66. byte[] retrievedA1Data = lasc.GetData(a1.ID);
  67. Assert.That(retrievedA1Data.Length, Is.EqualTo(a1.Data.Length));
  68. // TODO: Add cache and check that this does receive a copy of the asset
  69. }
  70. public void TestAddTemporaryAsset()
  71. {
  72. TestHelpers.InMethod();
  73. // TestHelpers.EnableLogging();
  74. IConfigSource config = new IniConfigSource();
  75. config.AddConfig("Modules");
  76. config.Configs["Modules"].Set("AssetServices", "LocalAssetServicesConnector");
  77. config.AddConfig("AssetService");
  78. config.Configs["AssetService"].Set("LocalServiceModule", "OpenSim.Services.AssetService.dll:AssetService");
  79. config.Configs["AssetService"].Set("StorageProvider", "OpenSim.Tests.Common.dll");
  80. LocalAssetServicesConnector lasc = new LocalAssetServicesConnector();
  81. lasc.Initialise(config);
  82. // If it is remote, it should be stored
  83. AssetBase a2 = AssetHelpers.CreateNotecardAsset();
  84. a2.Local = false;
  85. a2.Temporary = true;
  86. lasc.Store(a2);
  87. AssetBase retreivedA2 = lasc.Get(a2.ID);
  88. Assert.That(retreivedA2.ID, Is.EqualTo(a2.ID));
  89. Assert.That(retreivedA2.Metadata.ID, Is.EqualTo(a2.Metadata.ID));
  90. Assert.That(retreivedA2.Data.Length, Is.EqualTo(a2.Data.Length));
  91. AssetMetadata retrievedA2Metadata = lasc.GetMetadata(a2.ID);
  92. Assert.That(retrievedA2Metadata.ID, Is.EqualTo(a2.ID));
  93. byte[] retrievedA2Data = lasc.GetData(a2.ID);
  94. Assert.That(retrievedA2Data.Length, Is.EqualTo(a2.Data.Length));
  95. // TODO: Add cache and check that this does receive a copy of the asset
  96. }
  97. [Test]
  98. public void TestAddLocalAsset()
  99. {
  100. TestHelpers.InMethod();
  101. // TestHelpers.EnableLogging();
  102. IConfigSource config = new IniConfigSource();
  103. config.AddConfig("Modules");
  104. config.Configs["Modules"].Set("AssetServices", "LocalAssetServicesConnector");
  105. config.AddConfig("AssetService");
  106. config.Configs["AssetService"].Set("LocalServiceModule", "OpenSim.Services.AssetService.dll:AssetService");
  107. config.Configs["AssetService"].Set("StorageProvider", "OpenSim.Tests.Common.dll");
  108. LocalAssetServicesConnector lasc = new LocalAssetServicesConnector();
  109. lasc.Initialise(config);
  110. AssetBase a1 = AssetHelpers.CreateNotecardAsset();
  111. a1.Local = true;
  112. lasc.Store(a1);
  113. Assert.That(lasc.Get(a1.ID), Is.Null);
  114. Assert.That(lasc.GetData(a1.ID), Is.Null);
  115. Assert.That(lasc.GetMetadata(a1.ID), Is.Null);
  116. // TODO: Add cache and check that this does receive a copy of the asset
  117. }
  118. [Test]
  119. public void TestAddTemporaryLocalAsset()
  120. {
  121. TestHelpers.InMethod();
  122. // TestHelpers.EnableLogging();
  123. IConfigSource config = new IniConfigSource();
  124. config.AddConfig("Modules");
  125. config.Configs["Modules"].Set("AssetServices", "LocalAssetServicesConnector");
  126. config.AddConfig("AssetService");
  127. config.Configs["AssetService"].Set("LocalServiceModule", "OpenSim.Services.AssetService.dll:AssetService");
  128. config.Configs["AssetService"].Set("StorageProvider", "OpenSim.Tests.Common.dll");
  129. LocalAssetServicesConnector lasc = new LocalAssetServicesConnector();
  130. lasc.Initialise(config);
  131. // If it is local, it should not be stored
  132. AssetBase a1 = AssetHelpers.CreateNotecardAsset();
  133. a1.Local = true;
  134. a1.Temporary = true;
  135. lasc.Store(a1);
  136. Assert.That(lasc.Get(a1.ID), Is.Null);
  137. Assert.That(lasc.GetData(a1.ID), Is.Null);
  138. Assert.That(lasc.GetMetadata(a1.ID), Is.Null);
  139. // TODO: Add cache and check that this does receive a copy of the asset
  140. }
  141. }
  142. }