2023-01-24 15:29:31 +01:00
|
|
|
/* Copyright (c) Cloud Software Group, Inc.
|
2013-06-24 13:41:48 +02:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms,
|
|
|
|
* with or without modification, are permitted provided
|
|
|
|
* that the following conditions are met:
|
|
|
|
*
|
|
|
|
* * Redistributions of source code must retain the above
|
|
|
|
* copyright notice, this list of conditions and the
|
|
|
|
* following disclaimer.
|
|
|
|
* * Redistributions in binary form must reproduce the above
|
|
|
|
* copyright notice, this list of conditions and the
|
|
|
|
* following disclaimer in the documentation and/or other
|
|
|
|
* materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
|
|
|
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
|
|
|
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
|
|
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
|
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
|
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using Moq;
|
|
|
|
using NUnit.Framework;
|
|
|
|
using XenAdmin.Alerts;
|
|
|
|
using XenAdmin.Core;
|
|
|
|
using XenAdmin.Network;
|
|
|
|
using XenAPI;
|
|
|
|
|
|
|
|
namespace XenAdminTests.UnitTests.AlertTests
|
|
|
|
{
|
2019-06-03 19:04:52 +02:00
|
|
|
[TestFixture, Category(TestCategories.Unit)]
|
2013-06-24 13:41:48 +02:00
|
|
|
public class XenServerPatchAlertTests
|
|
|
|
{
|
|
|
|
private Mock<IXenConnection> connA;
|
|
|
|
private Mock<IXenConnection> connB;
|
|
|
|
private Mock<Host> hostA;
|
|
|
|
private Mock<Host> hostB;
|
|
|
|
|
2015-07-27 19:06:34 +02:00
|
|
|
protected Cache cacheA;
|
|
|
|
protected Cache cacheB;
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
[Test]
|
|
|
|
public void TestAlertWithConnectionAndHosts()
|
|
|
|
{
|
2018-06-15 17:05:37 +02:00
|
|
|
XenServerPatch p = new XenServerPatch("uuid", "name", "My description", "guidance", string.Empty, "6.0.1", "http://url", "http://patchUrl", new DateTime(2011, 4, 1).ToString(), "", "", "");
|
2013-06-24 13:41:48 +02:00
|
|
|
XenServerPatchAlert alert = new XenServerPatchAlert(p);
|
|
|
|
alert.IncludeConnection(connA.Object);
|
|
|
|
alert.IncludeConnection(connB.Object);
|
2014-04-29 15:23:53 +02:00
|
|
|
alert.IncludeHosts(new List<Host> { hostA.Object, hostB.Object });
|
2013-06-24 13:41:48 +02:00
|
|
|
|
2019-06-03 19:04:52 +02:00
|
|
|
ClassVerifiers.VerifyGetters(alert, new AlertClassUnitTestData
|
2013-06-24 13:41:48 +02:00
|
|
|
{
|
|
|
|
AppliesTo = "HostAName, HostBName, ConnAName, ConnBName",
|
2013-07-18 16:04:47 +02:00
|
|
|
FixLinkText = "Go to Web Page",
|
2013-06-24 13:41:48 +02:00
|
|
|
HelpID = "XenServerPatchAlert",
|
2013-07-03 18:53:40 +02:00
|
|
|
Description = "My description",
|
2013-07-18 16:04:47 +02:00
|
|
|
HelpLinkText = "Help",
|
2013-06-24 13:41:48 +02:00
|
|
|
Title = "New Update Available - name",
|
|
|
|
Priority = "Priority2"
|
|
|
|
});
|
|
|
|
|
|
|
|
Assert.IsFalse(alert.CanIgnore);
|
|
|
|
|
|
|
|
VerifyConnExpectations(Times.Once);
|
|
|
|
VerifyHostsExpectations(Times.Once);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestAlertWithHostsAndNoConnection()
|
|
|
|
{
|
2018-06-15 17:05:37 +02:00
|
|
|
XenServerPatch p = new XenServerPatch("uuid", "name", "My description", "guidance", string.Empty, "6.0.1", "http://url", "http://patchUrl", new DateTime(2011, 4, 1).ToString(), "1", "", "");
|
2013-06-24 13:41:48 +02:00
|
|
|
XenServerPatchAlert alert = new XenServerPatchAlert(p);
|
|
|
|
alert.IncludeHosts(new List<Host>() { hostA.Object, hostB.Object });
|
|
|
|
|
2019-06-03 19:04:52 +02:00
|
|
|
ClassVerifiers.VerifyGetters(alert, new AlertClassUnitTestData
|
2013-06-24 13:41:48 +02:00
|
|
|
{
|
|
|
|
AppliesTo = "HostAName, HostBName",
|
2013-07-18 16:04:47 +02:00
|
|
|
FixLinkText = "Go to Web Page",
|
2013-06-24 13:41:48 +02:00
|
|
|
HelpID = "XenServerPatchAlert",
|
2013-07-03 18:53:40 +02:00
|
|
|
Description = "My description",
|
2013-07-18 16:04:47 +02:00
|
|
|
HelpLinkText = "Help",
|
2013-06-24 13:41:48 +02:00
|
|
|
Title = "New Update Available - name",
|
|
|
|
Priority = "Priority1"
|
|
|
|
});
|
|
|
|
|
|
|
|
Assert.IsFalse(alert.CanIgnore);
|
|
|
|
|
|
|
|
VerifyConnExpectations(Times.Never);
|
|
|
|
VerifyHostsExpectations(Times.Once);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestAlertWithConnectionAndNoHosts()
|
|
|
|
{
|
2018-06-15 17:05:37 +02:00
|
|
|
XenServerPatch p = new XenServerPatch("uuid", "name", "My description", "guidance", string.Empty, "6.0.1", "http://url", "http://patchUrl", new DateTime(2011, 4, 1).ToString(), "0", "", "");
|
2013-06-24 13:41:48 +02:00
|
|
|
XenServerPatchAlert alert = new XenServerPatchAlert(p);
|
|
|
|
alert.IncludeConnection(connA.Object);
|
|
|
|
alert.IncludeConnection(connB.Object);
|
|
|
|
|
2019-06-03 19:04:52 +02:00
|
|
|
ClassVerifiers.VerifyGetters(alert, new AlertClassUnitTestData
|
2013-06-24 13:41:48 +02:00
|
|
|
{
|
|
|
|
AppliesTo = "ConnAName, ConnBName",
|
2013-07-18 16:04:47 +02:00
|
|
|
FixLinkText = "Go to Web Page",
|
2013-06-24 13:41:48 +02:00
|
|
|
HelpID = "XenServerPatchAlert",
|
2013-07-03 18:53:40 +02:00
|
|
|
Description = "My description",
|
2013-07-18 16:04:47 +02:00
|
|
|
HelpLinkText = "Help",
|
2013-06-24 13:41:48 +02:00
|
|
|
Title = "New Update Available - name",
|
|
|
|
Priority = "Unknown"
|
|
|
|
});
|
|
|
|
|
|
|
|
Assert.IsFalse(alert.CanIgnore);
|
|
|
|
|
|
|
|
VerifyConnExpectations(Times.Once);
|
|
|
|
VerifyHostsExpectations(Times.Never);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestAlertWithNoConnectionAndNoHosts()
|
|
|
|
{
|
2018-06-15 17:05:37 +02:00
|
|
|
XenServerPatch p = new XenServerPatch("uuid", "name", "My description", "guidance", string.Empty, "6.0.1", "http://url", "http://patchUrl", new DateTime(2011, 4, 1).ToString(), "5", "", "");
|
2013-06-24 13:41:48 +02:00
|
|
|
XenServerPatchAlert alert = new XenServerPatchAlert(p);
|
|
|
|
|
2019-06-03 19:04:52 +02:00
|
|
|
ClassVerifiers.VerifyGetters(alert, new AlertClassUnitTestData
|
2013-06-24 13:41:48 +02:00
|
|
|
{
|
|
|
|
AppliesTo = string.Empty,
|
2013-07-18 16:04:47 +02:00
|
|
|
FixLinkText = "Go to Web Page",
|
2013-06-24 13:41:48 +02:00
|
|
|
HelpID = "XenServerPatchAlert",
|
2013-07-03 18:53:40 +02:00
|
|
|
Description = "My description",
|
2013-07-18 16:04:47 +02:00
|
|
|
HelpLinkText = "Help",
|
2013-06-24 13:41:48 +02:00
|
|
|
Title = "New Update Available - name",
|
|
|
|
Priority = "Priority5"
|
|
|
|
});
|
|
|
|
|
|
|
|
Assert.IsTrue(alert.CanIgnore);
|
|
|
|
|
|
|
|
VerifyConnExpectations(Times.Never);
|
|
|
|
VerifyHostsExpectations(Times.Never);
|
|
|
|
}
|
|
|
|
|
2019-06-03 19:04:52 +02:00
|
|
|
[Test]
|
2013-06-24 13:41:48 +02:00
|
|
|
public void TestAlertWithNullPatch()
|
|
|
|
{
|
2019-06-03 19:04:52 +02:00
|
|
|
Assert.Throws(typeof(NullReferenceException), () => new XenServerPatchAlert(null));
|
2013-06-24 13:41:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void VerifyConnExpectations(Func<Times> times)
|
|
|
|
{
|
2017-09-13 15:46:58 +02:00
|
|
|
connA.Verify(n => n.Name, times());
|
|
|
|
connB.Verify(n => n.Name, times());
|
2013-06-24 13:41:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void VerifyHostsExpectations(Func<Times> times)
|
|
|
|
{
|
2017-09-13 15:46:58 +02:00
|
|
|
hostA.Verify(n => n.Name(), times());
|
|
|
|
hostB.Verify(n => n.Name(), times());
|
2013-06-24 13:41:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
public void TestSetUp()
|
|
|
|
{
|
|
|
|
connA = new Mock<IXenConnection>(MockBehavior.Strict);
|
|
|
|
connA.Setup(n => n.Name).Returns("ConnAName");
|
2015-07-27 19:06:34 +02:00
|
|
|
cacheA = new Cache();
|
|
|
|
connA.Setup(x => x.Cache).Returns(cacheA);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
connB = new Mock<IXenConnection>(MockBehavior.Strict);
|
|
|
|
connB.Setup(n => n.Name).Returns("ConnBName");
|
2015-07-27 19:06:34 +02:00
|
|
|
cacheB = new Cache();
|
|
|
|
connB.Setup(x => x.Cache).Returns(cacheB);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
hostA = new Mock<Host>(MockBehavior.Strict);
|
2017-09-03 04:33:29 +02:00
|
|
|
hostA.Setup(n => n.Name()).Returns("HostAName");
|
2020-06-30 10:57:32 +02:00
|
|
|
hostA.Setup(n => n.Equals(It.IsAny<Host>())).Returns((Host o) => ReferenceEquals(o, hostA.Object));
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
hostB = new Mock<Host>(MockBehavior.Strict);
|
2017-09-03 04:33:29 +02:00
|
|
|
hostB.Setup(n => n.Name()).Returns("HostBName");
|
2020-06-30 10:57:32 +02:00
|
|
|
hostB.Setup(n => n.Equals(It.IsAny<Host>())).Returns((Host o) => ReferenceEquals(o, hostB.Object));
|
2013-06-24 13:41:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
[TearDown]
|
|
|
|
public void TestTearDown()
|
|
|
|
{
|
2015-07-27 19:06:34 +02:00
|
|
|
cacheA = null;
|
|
|
|
cacheB = null;
|
2013-06-24 13:41:48 +02:00
|
|
|
connA = null;
|
|
|
|
connB = null;
|
|
|
|
hostA = null;
|
|
|
|
hostB = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|