15
15
using System . Collections . Generic ;
16
16
using System . Management . Automation ;
17
17
using System . Net ;
18
+ using System . Linq ;
18
19
using Microsoft . Azure . Commands . HDInsight . Models ;
19
20
using Microsoft . Azure . Management . HDInsight . Job . Models ;
20
21
using Microsoft . WindowsAzure . Commands . Common ;
21
22
using Microsoft . WindowsAzure . Commands . ScenarioTest ;
22
23
using Moq ;
23
24
using Xunit ;
25
+ using Microsoft . Azure . Management . HDInsight . Models ;
24
26
25
27
namespace Microsoft . Azure . Commands . HDInsight . Test
26
28
{
@@ -195,14 +197,93 @@ public void CreateStreamingJob()
195
197
job . Reducer == reducer && job . Defines . Count == defines . Count ) ) ) ;
196
198
}
197
199
198
- [ Fact ( Skip = "Test requires setting env variable, TODO remove that constraint" ) ]
200
+ [ Fact ]
201
+ [ Trait ( Category . AcceptanceType , Category . CheckIn ) ]
202
+ public void GetJobWithIdProvided ( )
203
+ {
204
+ // Update HDInsight Management properties for Job.
205
+ SetupManagementClientForJobTests ( ) ;
206
+
207
+ var jobId = "jobid_1984120_001" ;
208
+ var cmdlet = GetJobCommandDefinition ( ) ;
209
+ cmdlet . JobId = jobId ;
210
+
211
+ // Setup Job Management mocks
212
+ var jobResponse = new JobGetResponse
213
+ {
214
+ JobDetail = new JobDetailRootJsonObject { Id = jobId , Status = new Status ( ) , Userargs = new Userargs ( ) }
215
+ } ;
216
+
217
+ hdinsightJobManagementMock . Setup ( c => c . GetJob ( It . IsAny < string > ( ) ) )
218
+ . Returns ( jobResponse )
219
+ . Verifiable ( ) ;
220
+
221
+ cmdlet . ExecuteCmdlet ( ) ;
222
+ commandRuntimeMock . VerifyAll ( ) ;
223
+ commandRuntimeMock . Verify (
224
+ f =>
225
+ f . WriteObject ( It . Is < AzureHDInsightJob > ( job => job . JobId . Equals ( jobId ) ) ) ) ;
226
+ }
227
+
228
+ [ Fact ]
229
+ [ Trait ( Category . AcceptanceType , Category . CheckIn ) ]
230
+ public void ListJobs ( )
231
+ {
232
+ // Update HDInsight Management properties for Job.
233
+ SetupManagementClientForJobTests ( ) ;
234
+
235
+ var cmdlet = GetJobCommandDefinition ( ) ;
236
+
237
+ // Setup Job Management mocks
238
+ var jobListResponse = GetJobListResponse ( ) ;
239
+
240
+ hdinsightJobManagementMock . Setup ( c => c . ListJobs ( ) )
241
+ . Returns ( jobListResponse )
242
+ . Verifiable ( ) ;
243
+
244
+ cmdlet . ExecuteCmdlet ( ) ;
245
+ commandRuntimeMock . VerifyAll ( ) ;
246
+ commandRuntimeMock . Verify (
247
+ f =>
248
+ f . WriteObject ( It . Is < IEnumerable < string > > ( job => job . ElementAt ( 0 ) . Equals ( jobListResponse . ElementAt ( 0 ) . Detail . Id ) && job . ElementAt ( 1 ) . Equals ( jobListResponse . ElementAt ( 1 ) . Detail . Id ) ) , true ) ) ;
249
+ }
250
+
251
+ [ Fact ]
252
+ [ Trait ( Category . AcceptanceType , Category . CheckIn ) ]
253
+ public void ListJobsAfterJobId ( )
254
+ {
255
+ // Update HDInsight Management properties for Job.
256
+ SetupManagementClientForJobTests ( ) ;
257
+
258
+ var cmdlet = GetJobCommandDefinition ( ) ;
259
+ cmdlet . NumOfJobs = 2 ;
260
+
261
+ // Setup Job Management mocks
262
+ var jobListResponse = GetJobListResponse ( ) ;
263
+
264
+ hdinsightJobManagementMock . Setup ( c => c . ListJobsAfterJobId ( It . IsAny < string > ( ) , It . IsAny < int > ( ) ) )
265
+ . Returns ( jobListResponse )
266
+ . Verifiable ( ) ;
267
+
268
+ cmdlet . ExecuteCmdlet ( ) ;
269
+ commandRuntimeMock . VerifyAll ( ) ;
270
+ commandRuntimeMock . Verify (
271
+ f =>
272
+ f . WriteObject ( It . Is < IEnumerable < AzureHDInsightJob > > ( job => job . ElementAt ( 0 ) . JobId . Equals ( jobListResponse . ElementAt ( 0 ) . Detail . Id ) && job . ElementAt ( 1 ) . JobId . Equals ( jobListResponse . ElementAt ( 1 ) . Detail . Id ) ) , true ) ) ;
273
+ }
274
+
275
+ [ Fact ]
199
276
[ Trait ( Category . AcceptanceType , Category . CheckIn ) ]
200
277
public void StartJob ( )
201
278
{
279
+ // Update HDInsight Management properties for Job.
280
+ SetupManagementClientForJobTests ( ) ;
281
+
202
282
var cmdlet = new StartAzureHDInsightJobCommand
203
283
{
204
284
CommandRuntime = commandRuntimeMock . Object ,
205
285
HDInsightJobClient = hdinsightJobManagementMock . Object ,
286
+ HDInsightManagementClient = hdinsightManagementMock . Object ,
206
287
HttpCredential = new PSCredential ( "httpuser" , string . Format ( "Password1!" ) . ConvertToSecureString ( ) ) ,
207
288
ClusterName = ClusterName
208
289
} ;
@@ -246,7 +327,9 @@ public void StartJob()
246
327
{
247
328
Completed = "false" ,
248
329
User = cmdlet . HttpCredential . UserName ,
249
- Id = jobid
330
+ Id = jobid ,
331
+ Status = new Status ( ) ,
332
+ Userargs = new Userargs ( )
250
333
}
251
334
} ;
252
335
hdinsightJobManagementMock . Setup ( c => c . GetJob ( jobsub . JobSubmissionJsonResponse . Id ) ) . Returns ( getresponse ) . Verifiable ( ) ;
@@ -259,5 +342,42 @@ public void StartJob()
259
342
It . Is < AzureHDInsightJob > (
260
343
job => job . Cluster == ClusterName && job . JobId == jobid && job . Completed == "false" ) ) ) ;
261
344
}
345
+
346
+ public JobListResponse GetJobListResponse ( )
347
+ {
348
+ var jobListobject1 = new JobListJsonObject
349
+ {
350
+ Detail = new JobDetailRootJsonObject { Id = "jobid_1984120_001" , Status = new Status ( ) , Userargs = new Userargs ( ) } ,
351
+ Id = "jobid_1984120_001"
352
+ } ;
353
+
354
+ var jobListobject2 = new JobListJsonObject
355
+ {
356
+ Detail = new JobDetailRootJsonObject { Id = "jobid_1984120_002" , Status = new Status ( ) , Userargs = new Userargs ( ) } ,
357
+ Id = "jobid_1984120_002"
358
+ } ;
359
+
360
+ var jobListResponse = new JobListResponse
361
+ {
362
+ JobList = new List < JobListJsonObject > { jobListobject1 , jobListobject2 } ,
363
+ StatusCode = HttpStatusCode . OK
364
+ } ;
365
+
366
+ return jobListResponse ;
367
+ }
368
+
369
+ public GetAzureHDInsightJobCommand GetJobCommandDefinition ( )
370
+ {
371
+ var cmdlet = new GetAzureHDInsightJobCommand
372
+ {
373
+ CommandRuntime = commandRuntimeMock . Object ,
374
+ HDInsightJobClient = hdinsightJobManagementMock . Object ,
375
+ HDInsightManagementClient = hdinsightManagementMock . Object ,
376
+ HttpCredential = new PSCredential ( "httpuser" , string . Format ( "Password1!" ) . ConvertToSecureString ( ) ) ,
377
+ ClusterName = ClusterName
378
+ } ;
379
+
380
+ return cmdlet ;
381
+ }
262
382
}
263
383
}
0 commit comments