diff options
Diffstat (limited to 'OpenSim/Region/CoreModules/Framework/InventoryAccess/Tests/HGAssetMapperTests.cs')
-rw-r--r-- | OpenSim/Region/CoreModules/Framework/InventoryAccess/Tests/HGAssetMapperTests.cs | 146 |
1 files changed, 146 insertions, 0 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 | ||