/src/HDInsight/HDInsight.Test/UnitTests/DataLakeStoreTests.cs

https://github.com/Azure/azure-powershell · C# · 151 lines · 126 code · 12 blank · 13 comment · 10 complexity · f51544d04d208e7e3b1be3660194bebe MD5 · raw file

  1. // ----------------------------------------------------------------------------------
  2. //
  3. // Copyright Microsoft Corporation
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. // ----------------------------------------------------------------------------------
  14. using Microsoft.Azure.Commands.HDInsight;
  15. using Microsoft.Azure.Commands.HDInsight.ManagementCommands;
  16. using Microsoft.Azure.Commands.HDInsight.Models;
  17. using Microsoft.Azure.Commands.HDInsight.Test;
  18. using Microsoft.Azure.ServiceManagement.Common.Models;
  19. using Microsoft.WindowsAzure.Commands.Common;
  20. using Microsoft.WindowsAzure.Commands.ScenarioTest;
  21. using Moq;
  22. using System;
  23. using System.Management.Automation;
  24. using Xunit;
  25. namespace Commands.HDInsight.Test.UnitTests
  26. {
  27. public class DataLakeStoreTests : HDInsightTestBase
  28. {
  29. private NewAzureHDInsightClusterCommand cmdlet;
  30. private Guid ObjectId = new Guid("11111111-1111-1111-1111-111111111111");
  31. private Guid ApplicationId = new Guid("11111111-1111-1111-1111-111111111111");
  32. private Guid AadTenantId = new Guid("11111111-1111-1111-1111-111111111111");
  33. private string Certificate = "";
  34. private string CertificatePassword = "";
  35. private byte[] CertificateFileContents = { };
  36. private readonly PSCredential _httpCred;
  37. private Mock<AzureHDInsightConfig> AzureHDInsightconfigMock;
  38. public DataLakeStoreTests(Xunit.Abstractions.ITestOutputHelper output)
  39. {
  40. XunitTracingInterceptor.AddToContext(new XunitTracingInterceptor(output));
  41. base.SetupTestsForManagement();
  42. _httpCred = new PSCredential("hadoopuser", string.Format("Password1!").ConvertToSecureString());
  43. cmdlet = new NewAzureHDInsightClusterCommand
  44. {
  45. CommandRuntime = commandRuntimeMock.Object,
  46. HDInsightManagementClient = hdinsightManagementMock.Object
  47. };
  48. AzureHDInsightconfigMock = new Mock<AzureHDInsightConfig>();
  49. }
  50. [Fact]
  51. [Trait(Category.AcceptanceType, Category.CheckIn)]
  52. public void CanCreateClusterConfigWithDataLakeStoreParameters()
  53. {
  54. var newclusteridentitycmdlet = new NewAzureHDInsightClusterConfigCommand()
  55. {
  56. CommandRuntime = commandRuntimeMock.Object,
  57. HDInsightManagementClient = hdinsightManagementMock.Object,
  58. ObjectId = ObjectId,
  59. ApplicationId = ApplicationId,
  60. CertificateFilePath = Certificate,
  61. AadTenantId = AadTenantId,
  62. CertificatePassword = CertificatePassword
  63. };
  64. newclusteridentitycmdlet.ExecuteCmdlet();
  65. commandRuntimeMock.Verify(
  66. f =>
  67. f.WriteObject(
  68. It.Is<AzureHDInsightConfig>(
  69. c =>
  70. c.AADTenantId == AadTenantId &&
  71. c.CertificatePassword == CertificatePassword &&
  72. c.ObjectId == ObjectId &&
  73. c.ApplicationId == ApplicationId &&
  74. c.CertificateFilePath == Certificate
  75. )),
  76. Times.Once);
  77. }
  78. [Fact]
  79. [Trait(Category.AcceptanceType, Category.CheckIn)]
  80. public void CanCreateDataLakeClusterWithCertificationFileContents()
  81. {
  82. var clusterIdentityCmdlet = new NewAzureHDInsightClusterConfigCommand()
  83. {
  84. CommandRuntime = commandRuntimeMock.Object,
  85. HDInsightManagementClient = hdinsightManagementMock.Object,
  86. ObjectId = ObjectId,
  87. ApplicationId = ApplicationId,
  88. CertificateFileContents = CertificateFileContents,
  89. AadTenantId = AadTenantId,
  90. CertificatePassword = CertificatePassword
  91. };
  92. clusterIdentityCmdlet.ExecuteCmdlet();
  93. commandRuntimeMock.Verify(
  94. f =>
  95. f.WriteObject(
  96. It.Is<AzureHDInsightConfig>(
  97. c =>
  98. c.AADTenantId == AadTenantId &&
  99. c.CertificatePassword == CertificatePassword &&
  100. c.ObjectId == ObjectId &&
  101. c.ApplicationId == ApplicationId &&
  102. c.CertificateFileContents == CertificateFileContents
  103. )),
  104. Times.Once);
  105. }
  106. [Fact]
  107. [Trait(Category.AcceptanceType, Category.CheckIn)]
  108. public void ShouldThrowIfCertificateOptionsAreNotPassed()
  109. {
  110. var clusterIdentityCmdlet = new AddAzureHDInsightClusterIdentity()
  111. {
  112. CommandRuntime = commandRuntimeMock.Object,
  113. HDInsightManagementClient = hdinsightManagementMock.Object,
  114. ObjectId = ObjectId,
  115. ApplicationId = ApplicationId,
  116. AadTenantId = AadTenantId,
  117. CertificatePassword = CertificatePassword
  118. };
  119. Assert.Throws<ArgumentException>(() => clusterIdentityCmdlet.ExecuteCmdlet());
  120. }
  121. [Fact]
  122. [Trait(Category.AcceptanceType, Category.CheckIn)]
  123. public void ShouldThrowIfBothCertificateOptionsArePassed()
  124. {
  125. var clusterIdentityCmdlet = new AddAzureHDInsightClusterIdentity()
  126. {
  127. CommandRuntime = commandRuntimeMock.Object,
  128. HDInsightManagementClient = hdinsightManagementMock.Object,
  129. ObjectId = ObjectId,
  130. ApplicationId = ApplicationId,
  131. AadTenantId = AadTenantId,
  132. CertificatePassword = CertificatePassword,
  133. CertificateFileContents = CertificateFileContents,
  134. CertificateFilePath = Certificate
  135. };
  136. Assert.Throws<ArgumentException>(() => clusterIdentityCmdlet.ExecuteCmdlet());
  137. }
  138. }
  139. }