PresenceConnectorsTests.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. using System;
  28. using System.Collections.Generic;
  29. using System.IO;
  30. using System.Reflection;
  31. using System.Threading;
  32. using log4net.Config;
  33. using NUnit.Framework;
  34. using OpenMetaverse;
  35. using OpenSim.Framework;
  36. using Nini.Config;
  37. using OpenSim.Region.CoreModules.ServiceConnectorsOut.Presence;
  38. using OpenSim.Region.Framework.Scenes;
  39. using PresenceInfo = OpenSim.Services.Interfaces.PresenceInfo;
  40. using OpenSim.Tests.Common;
  41. namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Presence.Tests
  42. {
  43. [TestFixture]
  44. public class PresenceConnectorsTests : OpenSimTestCase
  45. {
  46. LocalPresenceServicesConnector m_LocalConnector;
  47. public override void SetUp()
  48. {
  49. base.SetUp();
  50. IConfigSource config = new IniConfigSource();
  51. config.AddConfig("Modules");
  52. config.AddConfig("PresenceService");
  53. config.Configs["Modules"].Set("PresenceServices", "LocalPresenceServicesConnector");
  54. config.Configs["PresenceService"].Set("LocalServiceModule", "OpenSim.Services.PresenceService.dll:PresenceService");
  55. config.Configs["PresenceService"].Set("StorageProvider", "OpenSim.Data.Null.dll");
  56. m_LocalConnector = new LocalPresenceServicesConnector();
  57. m_LocalConnector.Initialise(config);
  58. // Let's stick in a test presence
  59. m_LocalConnector.m_PresenceService.LoginAgent(UUID.Zero.ToString(), UUID.Zero, UUID.Zero);
  60. }
  61. /// <summary>
  62. /// Test OpenSim Presence.
  63. /// </summary>
  64. [Test]
  65. public void TestPresenceV0_1()
  66. {
  67. SetUp();
  68. // Let's stick in a test presence
  69. /*
  70. PresenceData p = new PresenceData();
  71. p.SessionID = UUID.Zero;
  72. p.UserID = UUID.Zero.ToString();
  73. p.Data = new Dictionary<string, string>();
  74. p.Data["Online"] = true.ToString();
  75. m_presenceData.Add(UUID.Zero, p);
  76. */
  77. string user1 = UUID.Zero.ToString();
  78. UUID session1 = UUID.Zero;
  79. // this is not implemented by this connector
  80. //m_LocalConnector.LoginAgent(user1, session1, UUID.Zero);
  81. PresenceInfo result = m_LocalConnector.GetAgent(session1);
  82. Assert.IsNotNull(result, "Retrieved GetAgent is null");
  83. Assert.That(result.UserID, Is.EqualTo(user1), "Retrieved userID does not match");
  84. UUID region1 = UUID.Random();
  85. bool r = m_LocalConnector.ReportAgent(session1, region1);
  86. Assert.IsTrue(r, "First ReportAgent returned false");
  87. result = m_LocalConnector.GetAgent(session1);
  88. Assert.That(result.RegionID, Is.EqualTo(region1), "Agent is not in the right region (region1)");
  89. UUID region2 = UUID.Random();
  90. r = m_LocalConnector.ReportAgent(session1, region2);
  91. Assert.IsTrue(r, "Second ReportAgent returned false");
  92. result = m_LocalConnector.GetAgent(session1);
  93. Assert.That(result.RegionID, Is.EqualTo(region2), "Agent is not in the right region (region2)");
  94. r = m_LocalConnector.LogoutAgent(session1);
  95. Assert.IsTrue(r, "LogoutAgent returned false");
  96. result = m_LocalConnector.GetAgent(session1);
  97. Assert.IsNull(result, "Agent session is still stored after logout");
  98. r = m_LocalConnector.ReportAgent(session1, region1);
  99. Assert.IsFalse(r, "ReportAgent of non-logged in user returned true");
  100. }
  101. }
  102. }