get TestSaveIarV0_1() uncommented but not running as a test yet since I didn't get the authentication server to work and my brain is about to fizzle out my ears

soprefactor
Justin Clark-Casey (justincc) 2010-05-28 23:14:24 +01:00
parent a60ca5236c
commit 191db0e6a4
4 changed files with 130 additions and 102 deletions

View File

@ -76,125 +76,118 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests
// Commenting for now! The mock inventory service needs more beef, at least for
// GetFolderForType
// REFACTORING PROBLEM. This needs to be rewritten.
//[Test]
public void TestSaveIarV0_1()
{
TestHelper.InMethod();
log4net.Config.XmlConfigurator.Configure();
// [Test]
// public void TestSaveIarV0_1()
// {
// TestHelper.InMethod();
// //log4net.Config.XmlConfigurator.Configure();
InventoryArchiverModule archiverModule = new InventoryArchiverModule(true);
// InventoryArchiverModule archiverModule = new InventoryArchiverModule(true);
Scene scene = SceneSetupHelpers.SetupScene("Inventory");
SceneSetupHelpers.SetupSceneModules(scene, archiverModule);
// Scene scene = SceneSetupHelpers.SetupScene("Inventory");
// SceneSetupHelpers.SetupSceneModules(scene, archiverModule);
// CommunicationsManager cm = scene.CommsManager;
// Create user
string userFirstName = "Jock";
string userLastName = "Stirrup";
string userPassword = "troll";
UUID userId = UUID.Parse("00000000-0000-0000-0000-000000000020");
UserProfileTestUtils.CreateUserWithInventory(scene, userFirstName, userLastName, userId, userPassword);
// // Create user
// string userFirstName = "Jock";
// string userLastName = "Stirrup";
// UUID userId = UUID.Parse("00000000-0000-0000-0000-000000000020");
// Create asset
SceneObjectGroup object1;
SceneObjectPart part1;
{
string partName = "My Little Dog Object";
UUID ownerId = UUID.Parse("00000000-0000-0000-0000-000000000040");
PrimitiveBaseShape shape = PrimitiveBaseShape.CreateSphere();
Vector3 groupPosition = new Vector3(10, 20, 30);
Quaternion rotationOffset = new Quaternion(20, 30, 40, 50);
Vector3 offsetPosition = new Vector3(5, 10, 15);
// lock (this)
// {
// UserProfileTestUtils.CreateUserWithInventory(
// cm, userFirstName, userLastName, userId, InventoryReceived);
// Monitor.Wait(this, 60000);
// }
part1
= new SceneObjectPart(
ownerId, shape, groupPosition, rotationOffset, offsetPosition);
part1.Name = partName;
// // Create asset
// SceneObjectGroup object1;
// SceneObjectPart part1;
// {
// string partName = "My Little Dog Object";
// UUID ownerId = UUID.Parse("00000000-0000-0000-0000-000000000040");
// PrimitiveBaseShape shape = PrimitiveBaseShape.CreateSphere();
// Vector3 groupPosition = new Vector3(10, 20, 30);
// Quaternion rotationOffset = new Quaternion(20, 30, 40, 50);
// Vector3 offsetPosition = new Vector3(5, 10, 15);
object1 = new SceneObjectGroup(part1);
scene.AddNewSceneObject(object1, false);
}
// part1
// = new SceneObjectPart(
// ownerId, shape, groupPosition, rotationOffset, offsetPosition);
// part1.Name = partName;
UUID asset1Id = UUID.Parse("00000000-0000-0000-0000-000000000060");
AssetBase asset1 = AssetHelpers.CreateAsset(asset1Id, object1);
scene.AssetService.Store(asset1);
// object1 = new SceneObjectGroup(part1);
// scene.AddNewSceneObject(object1, false);
// }
// Create item
UUID item1Id = UUID.Parse("00000000-0000-0000-0000-000000000080");
InventoryItemBase item1 = new InventoryItemBase();
item1.Name = "My Little Dog";
item1.AssetID = asset1.FullID;
item1.ID = item1Id;
InventoryFolderBase objsFolder
= InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, userId, "Objects");
item1.Folder = objsFolder.ID;
scene.AddInventoryItem(userId, item1);
// UUID asset1Id = UUID.Parse("00000000-0000-0000-0000-000000000060");
// AssetBase asset1 = AssetHelpers.CreateAsset(asset1Id, object1);
// scene.AssetService.Store(asset1);
MemoryStream archiveWriteStream = new MemoryStream();
archiverModule.OnInventoryArchiveSaved += SaveCompleted;
// // Create item
// UUID item1Id = UUID.Parse("00000000-0000-0000-0000-000000000080");
// InventoryItemBase item1 = new InventoryItemBase();
// item1.Name = "My Little Dog";
// item1.AssetID = asset1.FullID;
// item1.ID = item1Id;
// InventoryFolderBase objsFolder
// = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, userId, "Objects");
// item1.Folder = objsFolder.ID;
// scene.AddInventoryItem(userId, item1);
mre.Reset();
archiverModule.ArchiveInventory(
Guid.NewGuid(), userFirstName, userLastName, "Objects", userPassword, archiveWriteStream);
mre.WaitOne(60000, false);
// MemoryStream archiveWriteStream = new MemoryStream();
// archiverModule.OnInventoryArchiveSaved += SaveCompleted;
byte[] archive = archiveWriteStream.ToArray();
MemoryStream archiveReadStream = new MemoryStream(archive);
TarArchiveReader tar = new TarArchiveReader(archiveReadStream);
// mre.Reset();
// archiverModule.ArchiveInventory(
// Guid.NewGuid(), userFirstName, userLastName, "Objects", "troll", archiveWriteStream);
// mre.WaitOne(60000, false);
//bool gotControlFile = false;
bool gotObject1File = false;
//bool gotObject2File = false;
string expectedObject1FileName = InventoryArchiveWriteRequest.CreateArchiveItemName(item1);
string expectedObject1FilePath = string.Format(
"{0}{1}{2}",
ArchiveConstants.INVENTORY_PATH,
InventoryArchiveWriteRequest.CreateArchiveFolderName(objsFolder),
expectedObject1FileName);
// byte[] archive = archiveWriteStream.ToArray();
// MemoryStream archiveReadStream = new MemoryStream(archive);
// TarArchiveReader tar = new TarArchiveReader(archiveReadStream);
// //bool gotControlFile = false;
// bool gotObject1File = false;
// //bool gotObject2File = false;
// string expectedObject1FileName = InventoryArchiveWriteRequest.CreateArchiveItemName(item1);
// string expectedObject1FilePath = string.Format(
// "{0}{1}{2}",
// ArchiveConstants.INVENTORY_PATH,
// InventoryArchiveWriteRequest.CreateArchiveFolderName(objsFolder),
// expectedObject1FileName);
// string filePath;
// TarArchiveReader.TarEntryType tarEntryType;
string filePath;
TarArchiveReader.TarEntryType tarEntryType;
// Console.WriteLine("Reading archive");
// while (tar.ReadEntry(out filePath, out tarEntryType) != null)
// {
// Console.WriteLine("Got {0}", filePath);
while (tar.ReadEntry(out filePath, out tarEntryType) != null)
{
Console.WriteLine("Got {0}", filePath);
//// if (ArchiveConstants.CONTROL_FILE_PATH == filePath)
//// {
//// gotControlFile = true;
//// }
// if (filePath.StartsWith(ArchiveConstants.INVENTORY_PATH) && filePath.EndsWith(".xml"))
// if (ArchiveConstants.CONTROL_FILE_PATH == filePath)
// {
//// string fileName = filePath.Remove(0, "Objects/".Length);
////
//// if (fileName.StartsWith(part1.Name))
//// {
// Assert.That(expectedObject1FilePath, Is.EqualTo(filePath));
// gotObject1File = true;
//// }
//// else if (fileName.StartsWith(part2.Name))
//// {
//// Assert.That(fileName, Is.EqualTo(expectedObject2FileName));
//// gotObject2File = true;
//// }
// gotControlFile = true;
// }
// }
//// Assert.That(gotControlFile, Is.True, "No control file in archive");
// Assert.That(gotObject1File, Is.True, "No item1 file in archive");
//// Assert.That(gotObject2File, Is.True, "No object2 file in archive");
if (filePath.StartsWith(ArchiveConstants.INVENTORY_PATH) && filePath.EndsWith(".xml"))
{
// string fileName = filePath.Remove(0, "Objects/".Length);
//
// if (fileName.StartsWith(part1.Name))
// {
Assert.That(expectedObject1FilePath, Is.EqualTo(filePath));
gotObject1File = true;
// }
// else if (fileName.StartsWith(part2.Name))
// {
// Assert.That(fileName, Is.EqualTo(expectedObject2FileName));
// gotObject2File = true;
// }
}
}
// // TODO: Test presence of more files and contents of files.
// }
// Assert.That(gotControlFile, Is.True, "No control file in archive");
Assert.That(gotObject1File, Is.True, "No item1 file in archive");
// Assert.That(gotObject2File, Is.True, "No object2 file in archive");
// TODO: Test presence of more files and contents of files.
}
/// <summary>
/// Test loading a V0.1 OpenSim Inventory Archive (subject to change since there is no fixed format yet) where

View File

@ -376,6 +376,8 @@ namespace OpenSim.Region.Framework.Scenes
/// <param name="mod"></param>
public void RegisterModuleInterface<M>(M mod)
{
m_log.DebugFormat("[SCENE BASE]: Registering interface {0}", typeof(M));
List<Object> l = null;
if (!ModuleInterfaces.TryGetValue(typeof(M), out l))
{

View File

@ -42,6 +42,7 @@ using OpenSim.Region.Framework.Scenes;
using OpenSim.Region.CoreModules.Agent.Capabilities;
using OpenSim.Region.CoreModules.Avatar.Gods;
using OpenSim.Region.CoreModules.ServiceConnectorsOut.Asset;
using OpenSim.Region.CoreModules.ServiceConnectorsOut.Authentication;
using OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory;
using OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid;
using OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts;
@ -58,6 +59,7 @@ namespace OpenSim.Tests.Common.Setup
// These static variables in order to allow regions to be linked by shared modules and same
// CommunicationsManager.
private static ISharedRegionModule m_assetService = null;
// private static ISharedRegionModule m_authenticationService = null;
private static ISharedRegionModule m_inventoryService = null;
private static ISharedRegionModule m_gridService = null;
private static ISharedRegionModule m_userAccountService = null;
@ -178,6 +180,9 @@ namespace OpenSim.Tests.Common.Setup
else
StartAssetService(testScene, false);
// For now, always started a 'real' authenication service
StartAuthenticationService(testScene, true);
if (realServices.Contains("inventory"))
StartInventoryService(testScene, true);
else
@ -243,6 +248,27 @@ namespace OpenSim.Tests.Common.Setup
m_assetService = assetService;
}
private static void StartAuthenticationService(Scene testScene, bool real)
{
ISharedRegionModule service = new LocalAuthenticationServicesConnector();
IConfigSource config = new IniConfigSource();
config.AddConfig("Modules");
config.AddConfig("AuthenticationService");
config.Configs["Modules"].Set("AuthenticationServices", "LocalAuthenticationServicesConnector");
if (real)
config.Configs["AuthenticationService"].Set(
"LocalServiceModule", "OpenSim.Services.AuthenticationService.dll:PasswordAuthenticationService");
else
config.Configs["AuthenticationService"].Set(
"LocalServiceModule", "OpenSim.Tests.Common.dll:MockuthenticationService");
config.Configs["AuthenticationService"].Set("StorageProvider", "OpenSim.Data.Null.dll");
service.Initialise(config);
service.AddRegion(testScene);
service.RegionLoaded(testScene);
testScene.AddRegionModule(service.Name, service);
//m_authenticationService = service;
}
private static void StartInventoryService(Scene testScene, bool real)
{
ISharedRegionModule inventoryService = new LocalInventoryServicesConnector();

View File

@ -117,10 +117,17 @@ namespace OpenSim.Tests.Common.Setup
public static UserAccount CreateUserWithInventory(Scene scene)
{
UUID userId = UUID.Parse("00000000-0000-0000-0000-000000000099");
UserAccount ua = new UserAccount(userId) { FirstName = "Bill", LastName = "Bailey" };
return CreateUserWithInventory(
scene, "Bill", "Bailey", UUID.Parse("00000000-0000-0000-0000-000000000099"), "troll");
}
public static UserAccount CreateUserWithInventory(
Scene scene, string firstName, string lastName, UUID userId, string pw)
{
UserAccount ua = new UserAccount(userId) { FirstName = firstName, LastName = lastName };
scene.UserAccountService.StoreUserAccount(ua);
scene.InventoryService.CreateUserInventory(ua.PrincipalID);
scene.AuthenticationService.SetPassword(ua.PrincipalID, pw);
return ua;
}