diff options
Diffstat (limited to 'OpenSim/Region/CoreModules/Framework/InventoryAccess/Tests')
-rw-r--r-- | OpenSim/Region/CoreModules/Framework/InventoryAccess/Tests/HGAssetMapperTests.cs | 146 | ||||
-rw-r--r-- | OpenSim/Region/CoreModules/Framework/InventoryAccess/Tests/InventoryAccessModuleTests.cs | 7 |
2 files changed, 149 insertions, 4 deletions
diff --git a/OpenSim/Region/CoreModules/Framework/InventoryAccess/Tests/HGAssetMapperTests.cs b/OpenSim/Region/CoreModules/Framework/InventoryAccess/Tests/HGAssetMapperTests.cs new file mode 100644 index 0000000..007ff63 --- /dev/null +++ b/OpenSim/Region/CoreModules/Framework/InventoryAccess/Tests/HGAssetMapperTests.cs | |||
@@ -0,0 +1,146 @@ | |||
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 System.Threading; | ||
30 | using System.Xml; | ||
31 | using Nini.Config; | ||
32 | using NUnit.Framework; | ||
33 | using OpenMetaverse; | ||
34 | using OpenSim.Framework; | ||
35 | using OpenSim.Region.CoreModules.Framework.InventoryAccess; | ||
36 | using OpenSim.Region.Framework.Scenes; | ||
37 | using OpenSim.Region.ScriptEngine.XEngine; | ||
38 | using OpenSim.Services.Interfaces; | ||
39 | using OpenSim.Tests.Common; | ||
40 | |||
41 | namespace OpenSim.Region.CoreModules.Framework.InventoryAccess.Tests | ||
42 | { | ||
43 | [TestFixture] | ||
44 | public class HGAssetMapperTests : OpenSimTestCase | ||
45 | { | ||
46 | [Test] | ||
47 | public void TestPostAssetRewrite() | ||
48 | { | ||
49 | TestHelpers.InMethod(); | ||
50 | // TestHelpers.EnableLogging(); | ||
51 | |||
52 | XEngine xengine = new OpenSim.Region.ScriptEngine.XEngine.XEngine(); | ||
53 | xengine.DebugLevel = 1; | ||
54 | |||
55 | IniConfigSource configSource = new IniConfigSource(); | ||
56 | |||
57 | IConfig startupConfig = configSource.AddConfig("Startup"); | ||
58 | startupConfig.Set("DefaultScriptEngine", "XEngine"); | ||
59 | |||
60 | IConfig xEngineConfig = configSource.AddConfig("XEngine"); | ||
61 | xEngineConfig.Set("Enabled", "true"); | ||
62 | xEngineConfig.Set("StartDelay", "0"); | ||
63 | xEngineConfig.Set("AppDomainLoading", "false"); | ||
64 | |||
65 | string homeUrl = "http://hg.HomeTestPostAssetRewriteGrid.com"; | ||
66 | string foreignUrl = "http://hg.ForeignTestPostAssetRewriteGrid.com"; | ||
67 | int soIdTail = 0x1; | ||
68 | UUID assetId = TestHelpers.ParseTail(0x10); | ||
69 | UUID userId = TestHelpers.ParseTail(0x100); | ||
70 | UUID sceneId = TestHelpers.ParseTail(0x1000); | ||
71 | string userFirstName = "TestPostAsset"; | ||
72 | string userLastName = "Rewrite"; | ||
73 | int soPartsCount = 3; | ||
74 | |||
75 | Scene scene = new SceneHelpers().SetupScene("TestPostAssetRewriteScene", sceneId, 1000, 1000, configSource); | ||
76 | SceneHelpers.SetupSceneModules(scene, configSource, xengine); | ||
77 | scene.StartScripts(); | ||
78 | |||
79 | HGAssetMapper hgam = new HGAssetMapper(scene, homeUrl); | ||
80 | UserAccount ua | ||
81 | = UserAccountHelpers.CreateUserWithInventory(scene, userFirstName, userLastName, userId, "password"); | ||
82 | |||
83 | SceneObjectGroup so = SceneHelpers.AddSceneObject(scene, soPartsCount, ua.PrincipalID, "part", soIdTail); | ||
84 | RezScript( | ||
85 | scene, so.UUID, "default { state_entry() { llSay(0, \"Hello World\"); } }", "item1", ua.PrincipalID); | ||
86 | |||
87 | AssetBase asset = AssetHelpers.CreateAsset(assetId, so); | ||
88 | asset.CreatorID = foreignUrl; | ||
89 | hgam.PostAsset(foreignUrl, asset); | ||
90 | |||
91 | // Check transformed asset. | ||
92 | AssetBase ncAssetGet = scene.AssetService.Get(assetId.ToString()); | ||
93 | Assert.AreEqual(foreignUrl, ncAssetGet.CreatorID); | ||
94 | string xmlData = Utils.BytesToString(ncAssetGet.Data); | ||
95 | XmlDocument ncAssetGetXmlDoc = new XmlDocument(); | ||
96 | ncAssetGetXmlDoc.LoadXml(xmlData); | ||
97 | |||
98 | // Console.WriteLine(ncAssetGetXmlDoc.OuterXml); | ||
99 | |||
100 | XmlNodeList creatorDataNodes = ncAssetGetXmlDoc.GetElementsByTagName("CreatorData"); | ||
101 | |||
102 | Assert.AreEqual(soPartsCount, creatorDataNodes.Count); | ||
103 | //Console.WriteLine("creatorDataNodes {0}", creatorDataNodes.Count); | ||
104 | |||
105 | foreach (XmlNode creatorDataNode in creatorDataNodes) | ||
106 | { | ||
107 | Assert.AreEqual( | ||
108 | string.Format("{0};{1} {2}", homeUrl, ua.FirstName, ua.LastName), creatorDataNode.InnerText); | ||
109 | } | ||
110 | |||
111 | // Check that saved script nodes have attributes | ||
112 | XmlNodeList savedScriptStateNodes = ncAssetGetXmlDoc.GetElementsByTagName("SavedScriptState"); | ||
113 | |||
114 | Assert.AreEqual(1, savedScriptStateNodes.Count); | ||
115 | Assert.AreEqual(1, savedScriptStateNodes[0].Attributes.Count); | ||
116 | XmlNode uuidAttribute = savedScriptStateNodes[0].Attributes.GetNamedItem("UUID"); | ||
117 | Assert.NotNull(uuidAttribute); | ||
118 | // XXX: To check the actual UUID attribute we would have to do some work to retreive the UUID of the task | ||
119 | // item created earlier. | ||
120 | } | ||
121 | |||
122 | private void RezScript(Scene scene, UUID soId, string script, string itemName, UUID userId) | ||
123 | { | ||
124 | InventoryItemBase itemTemplate = new InventoryItemBase(); | ||
125 | // itemTemplate.ID = itemId; | ||
126 | itemTemplate.Name = itemName; | ||
127 | itemTemplate.Folder = soId; | ||
128 | itemTemplate.InvType = (int)InventoryType.LSL; | ||
129 | |||
130 | // XXX: Ultimately it would be better to be able to directly manipulate the script engine to rez a script | ||
131 | // immediately for tests rather than chunter through it's threaded mechanisms. | ||
132 | AutoResetEvent chatEvent = new AutoResetEvent(false); | ||
133 | |||
134 | scene.EventManager.OnChatFromWorld += (s, c) => | ||
135 | { | ||
136 | // Console.WriteLine("Got chat [{0}]", c.Message); | ||
137 | chatEvent.Set(); | ||
138 | }; | ||
139 | |||
140 | scene.RezNewScript(userId, itemTemplate, script); | ||
141 | |||
142 | // Console.WriteLine("HERE"); | ||
143 | Assert.IsTrue(chatEvent.WaitOne(60000), "Chat event in HGAssetMapperTests.RezScript not received"); | ||
144 | } | ||
145 | } | ||
146 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/CoreModules/Framework/InventoryAccess/Tests/InventoryAccessModuleTests.cs b/OpenSim/Region/CoreModules/Framework/InventoryAccess/Tests/InventoryAccessModuleTests.cs index ac25a93..1d91165 100644 --- a/OpenSim/Region/CoreModules/Framework/InventoryAccess/Tests/InventoryAccessModuleTests.cs +++ b/OpenSim/Region/CoreModules/Framework/InventoryAccess/Tests/InventoryAccessModuleTests.cs | |||
@@ -37,14 +37,12 @@ using OpenSim.Data; | |||
37 | using OpenSim.Framework; | 37 | using OpenSim.Framework; |
38 | using OpenSim.Framework.Serialization; | 38 | using OpenSim.Framework.Serialization; |
39 | using OpenSim.Framework.Serialization.External; | 39 | using OpenSim.Framework.Serialization.External; |
40 | using OpenSim.Framework.Communications; | ||
41 | using OpenSim.Region.CoreModules.Avatar.Inventory.Archiver; | 40 | using OpenSim.Region.CoreModules.Avatar.Inventory.Archiver; |
42 | using OpenSim.Region.CoreModules.Framework.InventoryAccess; | 41 | using OpenSim.Region.CoreModules.Framework.InventoryAccess; |
43 | using OpenSim.Region.Framework.Scenes; | 42 | using OpenSim.Region.Framework.Scenes; |
44 | using OpenSim.Region.Framework.Scenes.Serialization; | 43 | using OpenSim.Region.Framework.Scenes.Serialization; |
45 | using OpenSim.Services.Interfaces; | 44 | using OpenSim.Services.Interfaces; |
46 | using OpenSim.Tests.Common; | 45 | using OpenSim.Tests.Common; |
47 | using OpenSim.Tests.Common.Mock; | ||
48 | 46 | ||
49 | namespace OpenSim.Region.CoreModules.Framework.InventoryAccess.Tests | 47 | namespace OpenSim.Region.CoreModules.Framework.InventoryAccess.Tests |
50 | { | 48 | { |
@@ -109,8 +107,9 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess.Tests | |||
109 | item1.AssetID = asset1.FullID; | 107 | item1.AssetID = asset1.FullID; |
110 | item1.ID = item1Id; | 108 | item1.ID = item1Id; |
111 | InventoryFolderBase objsFolder | 109 | InventoryFolderBase objsFolder |
112 | = InventoryArchiveUtils.FindFolderByPath(m_scene.InventoryService, m_userId, "Objects")[0]; | 110 | = InventoryArchiveUtils.FindFoldersByPath(m_scene.InventoryService, m_userId, "Objects")[0]; |
113 | item1.Folder = objsFolder.ID; | 111 | item1.Folder = objsFolder.ID; |
112 | item1.Flags |= (uint)InventoryItemFlags.ObjectHasMultipleItems; | ||
114 | m_scene.AddInventoryItem(item1); | 113 | m_scene.AddInventoryItem(item1); |
115 | 114 | ||
116 | SceneObjectGroup so | 115 | SceneObjectGroup so |
@@ -159,7 +158,7 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess.Tests | |||
159 | item1.AssetID = asset1.FullID; | 158 | item1.AssetID = asset1.FullID; |
160 | item1.ID = item1Id; | 159 | item1.ID = item1Id; |
161 | InventoryFolderBase objsFolder | 160 | InventoryFolderBase objsFolder |
162 | = InventoryArchiveUtils.FindFolderByPath(m_scene.InventoryService, m_userId, "Objects")[0]; | 161 | = InventoryArchiveUtils.FindFoldersByPath(m_scene.InventoryService, m_userId, "Objects")[0]; |
163 | item1.Folder = objsFolder.ID; | 162 | item1.Folder = objsFolder.ID; |
164 | m_scene.AddInventoryItem(item1); | 163 | m_scene.AddInventoryItem(item1); |
165 | 164 | ||