diff options
Diffstat (limited to 'OpenSim/Tests/Common/Mock/TestXInventoryDataPlugin.cs')
-rw-r--r-- | OpenSim/Tests/Common/Mock/TestXInventoryDataPlugin.cs | 152 |
1 files changed, 152 insertions, 0 deletions
diff --git a/OpenSim/Tests/Common/Mock/TestXInventoryDataPlugin.cs b/OpenSim/Tests/Common/Mock/TestXInventoryDataPlugin.cs new file mode 100644 index 0000000..2b272e6 --- /dev/null +++ b/OpenSim/Tests/Common/Mock/TestXInventoryDataPlugin.cs | |||
@@ -0,0 +1,152 @@ | |||
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.Collections.Generic; | ||
30 | using System.Linq; | ||
31 | using System.Reflection; | ||
32 | using log4net; | ||
33 | using OpenMetaverse; | ||
34 | using OpenSim.Framework; | ||
35 | using OpenSim.Data; | ||
36 | using OpenSim.Data.Null; | ||
37 | |||
38 | namespace OpenSim.Tests.Common | ||
39 | { | ||
40 | public class TestXInventoryDataPlugin : NullGenericDataHandler, IXInventoryData | ||
41 | { | ||
42 | private Dictionary<UUID, XInventoryFolder> m_allFolders = new Dictionary<UUID, XInventoryFolder>(); | ||
43 | private Dictionary<UUID, XInventoryItem> m_allItems = new Dictionary<UUID, XInventoryItem>(); | ||
44 | |||
45 | public TestXInventoryDataPlugin(string conn, string realm) {} | ||
46 | |||
47 | public XInventoryItem[] GetItems(string[] fields, string[] vals) | ||
48 | { | ||
49 | // Console.WriteLine( | ||
50 | // "Requesting items, fields {0}, vals {1}", string.Join(", ", fields), string.Join(", ", vals)); | ||
51 | |||
52 | List<XInventoryItem> origItems = Get<XInventoryItem>(fields, vals, m_allItems.Values.ToList()); | ||
53 | |||
54 | XInventoryItem[] items = origItems.Select(i => i.Clone()).ToArray(); | ||
55 | |||
56 | // Console.WriteLine("Found {0} items", items.Length); | ||
57 | // Array.ForEach(items, i => Console.WriteLine("Found item {0} {1}", i.inventoryName, i.inventoryID)); | ||
58 | |||
59 | return items; | ||
60 | } | ||
61 | |||
62 | public XInventoryFolder[] GetFolders(string[] fields, string[] vals) | ||
63 | { | ||
64 | // Console.WriteLine( | ||
65 | // "Requesting folders, fields {0}, vals {1}", string.Join(", ", fields), string.Join(", ", vals)); | ||
66 | |||
67 | List<XInventoryFolder> origFolders | ||
68 | = Get<XInventoryFolder>(fields, vals, m_allFolders.Values.ToList()); | ||
69 | |||
70 | XInventoryFolder[] folders = origFolders.Select(f => f.Clone()).ToArray(); | ||
71 | |||
72 | // Console.WriteLine("Found {0} folders", folders.Length); | ||
73 | // Array.ForEach(folders, f => Console.WriteLine("Found folder {0} {1}", f.folderName, f.folderID)); | ||
74 | |||
75 | return folders; | ||
76 | } | ||
77 | |||
78 | public bool StoreFolder(XInventoryFolder folder) | ||
79 | { | ||
80 | m_allFolders[folder.folderID] = folder.Clone(); | ||
81 | |||
82 | // Console.WriteLine("Added folder {0} {1}", folder.folderName, folder.folderID); | ||
83 | |||
84 | return true; | ||
85 | } | ||
86 | |||
87 | public bool StoreItem(XInventoryItem item) | ||
88 | { | ||
89 | m_allItems[item.inventoryID] = item.Clone(); | ||
90 | |||
91 | // Console.WriteLine( | ||
92 | // "Added item {0} {1}, folder {2}, creator {3}, owner {4}", | ||
93 | // item.inventoryName, item.inventoryID, item.parentFolderID, item.creatorID, item.avatarID); | ||
94 | |||
95 | return true; | ||
96 | } | ||
97 | |||
98 | public bool DeleteFolders(string field, string val) | ||
99 | { | ||
100 | return DeleteFolders(new string[] { field }, new string[] { val }); | ||
101 | } | ||
102 | |||
103 | public bool DeleteFolders(string[] fields, string[] vals) | ||
104 | { | ||
105 | XInventoryFolder[] foldersToDelete = GetFolders(fields, vals); | ||
106 | Array.ForEach(foldersToDelete, f => m_allFolders.Remove(f.folderID)); | ||
107 | |||
108 | return true; | ||
109 | } | ||
110 | |||
111 | public bool DeleteItems(string field, string val) | ||
112 | { | ||
113 | return DeleteItems(new string[] { field }, new string[] { val }); | ||
114 | } | ||
115 | |||
116 | public bool DeleteItems(string[] fields, string[] vals) | ||
117 | { | ||
118 | XInventoryItem[] itemsToDelete = GetItems(fields, vals); | ||
119 | Array.ForEach(itemsToDelete, i => m_allItems.Remove(i.inventoryID)); | ||
120 | |||
121 | return true; | ||
122 | } | ||
123 | |||
124 | public bool MoveItem(string id, string newParent) { throw new NotImplementedException(); } | ||
125 | |||
126 | public bool MoveFolder(string id, string newParent) | ||
127 | { | ||
128 | // Don't use GetFolders() here - it takes a clone! | ||
129 | XInventoryFolder folder = m_allFolders[new UUID(id)]; | ||
130 | |||
131 | if (folder == null) | ||
132 | return false; | ||
133 | |||
134 | folder.parentFolderID = new UUID(newParent); | ||
135 | |||
136 | // XInventoryFolder[] newParentFolders | ||
137 | // = GetFolders(new string[] { "folderID" }, new string[] { folder.parentFolderID.ToString() }); | ||
138 | |||
139 | // Console.WriteLine( | ||
140 | // "Moved folder {0} {1}, to {2} {3}", | ||
141 | // folder.folderName, folder.folderID, newParentFolders[0].folderName, folder.parentFolderID); | ||
142 | |||
143 | // TODO: Really need to implement folder version incrementing, though this should be common code anyway, | ||
144 | // not reimplemented in each db plugin. | ||
145 | |||
146 | return true; | ||
147 | } | ||
148 | |||
149 | public XInventoryItem[] GetActiveGestures(UUID principalID) { throw new NotImplementedException(); } | ||
150 | public int GetAssetPermissions(UUID principalID, UUID assetID) { throw new NotImplementedException(); } | ||
151 | } | ||
152 | } \ No newline at end of file | ||