diff options
Diffstat (limited to 'OpenSim/Services/InventoryService')
-rw-r--r-- | OpenSim/Services/InventoryService/Tests/XInventoryServiceTests.cs | 110 | ||||
-rw-r--r-- | OpenSim/Services/InventoryService/XInventoryService.cs | 40 |
2 files changed, 140 insertions, 10 deletions
diff --git a/OpenSim/Services/InventoryService/Tests/XInventoryServiceTests.cs b/OpenSim/Services/InventoryService/Tests/XInventoryServiceTests.cs index d2356c5..9e3fa69 100644 --- a/OpenSim/Services/InventoryService/Tests/XInventoryServiceTests.cs +++ b/OpenSim/Services/InventoryService/Tests/XInventoryServiceTests.cs | |||
@@ -43,8 +43,18 @@ namespace OpenSim.Services.InventoryService.Tests | |||
43 | /// TODO: Fill out more tests. | 43 | /// TODO: Fill out more tests. |
44 | /// </remarks> | 44 | /// </remarks> |
45 | [TestFixture] | 45 | [TestFixture] |
46 | public class XInventoryServiceTests | 46 | public class XInventoryServiceTests : OpenSimTestCase |
47 | { | 47 | { |
48 | private IInventoryService CreateXInventoryService() | ||
49 | { | ||
50 | IConfigSource config = new IniConfigSource(); | ||
51 | config.AddConfig("InventoryService"); | ||
52 | config.Configs["InventoryService"].Set("StorageProvider", "OpenSim.Tests.Common.dll"); | ||
53 | |||
54 | return ServerUtils.LoadPlugin<IInventoryService>( | ||
55 | "OpenSim.Services.InventoryService.dll:XInventoryService", new Object[] { config }); | ||
56 | } | ||
57 | |||
48 | /// <summary> | 58 | /// <summary> |
49 | /// Tests add item operation. | 59 | /// Tests add item operation. |
50 | /// </summary> | 60 | /// </summary> |
@@ -54,25 +64,31 @@ namespace OpenSim.Services.InventoryService.Tests | |||
54 | [Test] | 64 | [Test] |
55 | public void TestAddItem() | 65 | public void TestAddItem() |
56 | { | 66 | { |
67 | TestHelpers.InMethod(); | ||
68 | |||
57 | string creatorId = TestHelpers.ParseTail(0x1).ToString(); | 69 | string creatorId = TestHelpers.ParseTail(0x1).ToString(); |
58 | UUID ownerId = TestHelpers.ParseTail(0x2); | 70 | UUID ownerId = TestHelpers.ParseTail(0x2); |
59 | UUID itemId = TestHelpers.ParseTail(0x10); | 71 | UUID itemId = TestHelpers.ParseTail(0x10); |
60 | UUID assetId = TestHelpers.ParseTail(0x20); | 72 | UUID assetId = TestHelpers.ParseTail(0x20); |
73 | UUID folderId = TestHelpers.ParseTail(0x30); | ||
74 | int invType = (int)InventoryType.Animation; | ||
75 | int assetType = (int)AssetType.Animation; | ||
61 | string itemName = "item1"; | 76 | string itemName = "item1"; |
62 | 77 | ||
63 | IConfigSource config = new IniConfigSource(); | 78 | IInventoryService xis = CreateXInventoryService(); |
64 | config.AddConfig("InventoryService"); | ||
65 | config.Configs["InventoryService"].Set("StorageProvider", "OpenSim.Tests.Common.dll"); | ||
66 | |||
67 | IInventoryService xis | ||
68 | = ServerUtils.LoadPlugin<IInventoryService>( | ||
69 | "OpenSim.Services.InventoryService.dll:XInventoryService", new Object[] { config }); | ||
70 | 79 | ||
71 | InventoryItemBase itemToStore | 80 | InventoryItemBase itemToStore |
72 | = new InventoryItemBase(itemId, ownerId) | 81 | = new InventoryItemBase(itemId, ownerId) |
73 | { CreatorId = creatorId.ToString(), AssetID = assetId, Name = itemName }; | 82 | { |
83 | CreatorIdentification = creatorId.ToString(), | ||
84 | AssetID = assetId, | ||
85 | Name = itemName, | ||
86 | Folder = folderId, | ||
87 | InvType = invType, | ||
88 | AssetType = assetType | ||
89 | }; | ||
74 | 90 | ||
75 | xis.AddItem(itemToStore); | 91 | Assert.That(xis.AddItem(itemToStore), Is.True); |
76 | 92 | ||
77 | InventoryItemBase itemRetrieved = new InventoryItemBase(itemId); | 93 | InventoryItemBase itemRetrieved = new InventoryItemBase(itemId); |
78 | itemRetrieved = xis.GetItem(itemRetrieved); | 94 | itemRetrieved = xis.GetItem(itemRetrieved); |
@@ -81,7 +97,81 @@ namespace OpenSim.Services.InventoryService.Tests | |||
81 | Assert.That(itemRetrieved.CreatorId, Is.EqualTo(creatorId)); | 97 | Assert.That(itemRetrieved.CreatorId, Is.EqualTo(creatorId)); |
82 | Assert.That(itemRetrieved.Owner, Is.EqualTo(ownerId)); | 98 | Assert.That(itemRetrieved.Owner, Is.EqualTo(ownerId)); |
83 | Assert.That(itemRetrieved.AssetID, Is.EqualTo(assetId)); | 99 | Assert.That(itemRetrieved.AssetID, Is.EqualTo(assetId)); |
100 | Assert.That(itemRetrieved.Folder, Is.EqualTo(folderId)); | ||
101 | Assert.That(itemRetrieved.InvType, Is.EqualTo(invType)); | ||
102 | Assert.That(itemRetrieved.AssetType, Is.EqualTo(assetType)); | ||
84 | Assert.That(itemRetrieved.Name, Is.EqualTo(itemName)); | 103 | Assert.That(itemRetrieved.Name, Is.EqualTo(itemName)); |
85 | } | 104 | } |
105 | |||
106 | [Test] | ||
107 | public void TestUpdateItem() | ||
108 | { | ||
109 | TestHelpers.InMethod(); | ||
110 | // TestHelpers.EnableLogging(); | ||
111 | |||
112 | string creatorId = TestHelpers.ParseTail(0x1).ToString(); | ||
113 | UUID ownerId = TestHelpers.ParseTail(0x2); | ||
114 | UUID itemId = TestHelpers.ParseTail(0x10); | ||
115 | UUID assetId = TestHelpers.ParseTail(0x20); | ||
116 | UUID folderId = TestHelpers.ParseTail(0x30); | ||
117 | int invType = (int)InventoryType.Animation; | ||
118 | int assetType = (int)AssetType.Animation; | ||
119 | string itemName = "item1"; | ||
120 | string itemName2 = "item2"; | ||
121 | |||
122 | IInventoryService xis = CreateXInventoryService(); | ||
123 | |||
124 | InventoryItemBase itemToStore | ||
125 | = new InventoryItemBase(itemId, ownerId) | ||
126 | { | ||
127 | CreatorIdentification = creatorId.ToString(), | ||
128 | AssetID = assetId, | ||
129 | Name = itemName, | ||
130 | Folder = folderId, | ||
131 | InvType = invType, | ||
132 | AssetType = assetType | ||
133 | }; | ||
134 | |||
135 | Assert.That(xis.AddItem(itemToStore), Is.True); | ||
136 | |||
137 | // Normal update | ||
138 | itemToStore.Name = itemName2; | ||
139 | |||
140 | Assert.That(xis.UpdateItem(itemToStore), Is.True); | ||
141 | |||
142 | InventoryItemBase itemRetrieved = new InventoryItemBase(itemId); | ||
143 | itemRetrieved = xis.GetItem(itemRetrieved); | ||
144 | |||
145 | Assert.That(itemRetrieved, Is.Not.Null); | ||
146 | Assert.That(itemRetrieved.Name, Is.EqualTo(itemName2)); | ||
147 | |||
148 | // Attempt to update properties that should never change | ||
149 | string creatorId2 = TestHelpers.ParseTail(0x7).ToString(); | ||
150 | UUID ownerId2 = TestHelpers.ParseTail(0x8); | ||
151 | UUID folderId2 = TestHelpers.ParseTail(0x70); | ||
152 | int invType2 = (int)InventoryType.CallingCard; | ||
153 | int assetType2 = (int)AssetType.CallingCard; | ||
154 | string itemName3 = "item3"; | ||
155 | |||
156 | itemToStore.CreatorIdentification = creatorId2.ToString(); | ||
157 | itemToStore.Owner = ownerId2; | ||
158 | itemToStore.Folder = folderId2; | ||
159 | itemToStore.InvType = invType2; | ||
160 | itemToStore.AssetType = assetType2; | ||
161 | itemToStore.Name = itemName3; | ||
162 | |||
163 | Assert.That(xis.UpdateItem(itemToStore), Is.True); | ||
164 | |||
165 | itemRetrieved = xis.GetItem(itemRetrieved); | ||
166 | |||
167 | Assert.That(itemRetrieved, Is.Not.Null); | ||
168 | Assert.That(itemRetrieved.CreatorId, Is.EqualTo(creatorId)); | ||
169 | Assert.That(itemRetrieved.Owner, Is.EqualTo(ownerId)); | ||
170 | Assert.That(itemRetrieved.AssetID, Is.EqualTo(assetId)); | ||
171 | Assert.That(itemRetrieved.Folder, Is.EqualTo(folderId)); | ||
172 | Assert.That(itemRetrieved.InvType, Is.EqualTo(invType)); | ||
173 | Assert.That(itemRetrieved.AssetType, Is.EqualTo(assetType)); | ||
174 | Assert.That(itemRetrieved.Name, Is.EqualTo(itemName3)); | ||
175 | } | ||
86 | } | 176 | } |
87 | } \ No newline at end of file | 177 | } \ No newline at end of file |
diff --git a/OpenSim/Services/InventoryService/XInventoryService.cs b/OpenSim/Services/InventoryService/XInventoryService.cs index 9abc5e4..00faa44 100644 --- a/OpenSim/Services/InventoryService/XInventoryService.cs +++ b/OpenSim/Services/InventoryService/XInventoryService.cs | |||
@@ -476,6 +476,46 @@ namespace OpenSim.Services.InventoryService | |||
476 | // m_log.InfoFormat( | 476 | // m_log.InfoFormat( |
477 | // "[XINVENTORY SERVICE]: Updating item {0} {1} in folder {2}", item.Name, item.ID, item.Folder); | 477 | // "[XINVENTORY SERVICE]: Updating item {0} {1} in folder {2}", item.Name, item.ID, item.Folder); |
478 | 478 | ||
479 | InventoryItemBase retrievedItem = GetItem(item); | ||
480 | |||
481 | if (retrievedItem == null) | ||
482 | { | ||
483 | m_log.WarnFormat( | ||
484 | "[XINVENTORY SERVICE]: Tried to update item {0} {1}, owner {2} but no existing item found.", | ||
485 | item.Name, item.ID, item.Owner); | ||
486 | |||
487 | return false; | ||
488 | } | ||
489 | |||
490 | // Do not allow invariants to change. Changes to folder ID occur in MoveItems() | ||
491 | if (retrievedItem.InvType != item.InvType | ||
492 | || retrievedItem.AssetType != item.AssetType | ||
493 | || retrievedItem.Folder != item.Folder | ||
494 | || retrievedItem.CreatorIdentification != item.CreatorIdentification | ||
495 | || retrievedItem.Owner != item.Owner) | ||
496 | { | ||
497 | m_log.WarnFormat( | ||
498 | "[XINVENTORY SERVICE]: Caller to UpdateItem() for {0} {1} tried to alter property(s) that should be invariant, (InvType, AssetType, Folder, CreatorIdentification, Owner), existing ({2}, {3}, {4}, {5}, {6}), update ({7}, {8}, {9}, {10}, {11})", | ||
499 | retrievedItem.Name, | ||
500 | retrievedItem.ID, | ||
501 | retrievedItem.InvType, | ||
502 | retrievedItem.AssetType, | ||
503 | retrievedItem.Folder, | ||
504 | retrievedItem.CreatorIdentification, | ||
505 | retrievedItem.Owner, | ||
506 | item.InvType, | ||
507 | item.AssetType, | ||
508 | item.Folder, | ||
509 | item.CreatorIdentification, | ||
510 | item.Owner); | ||
511 | |||
512 | item.InvType = retrievedItem.InvType; | ||
513 | item.AssetType = retrievedItem.AssetType; | ||
514 | item.Folder = retrievedItem.Folder; | ||
515 | item.CreatorIdentification = retrievedItem.CreatorIdentification; | ||
516 | item.Owner = retrievedItem.Owner; | ||
517 | } | ||
518 | |||
479 | return m_Database.StoreItem(ConvertFromOpenSim(item)); | 519 | return m_Database.StoreItem(ConvertFromOpenSim(item)); |
480 | } | 520 | } |
481 | 521 | ||