6
6
import assert , { fail } from 'assert'
7
7
import * as vscode from 'vscode'
8
8
import * as sinon from 'sinon'
9
- import { makeTemporaryToolkitFolder } from '../../../shared/filesystemUtilities'
10
9
import { DB , transformByQState , TransformByQStoppedError } from '../../../codewhisperer/models/model'
11
10
import {
11
+ finalizeTransformationJob ,
12
12
parseBuildFile ,
13
+ setMaven ,
13
14
stopTransformByQ ,
14
15
validateSQLMetadataFile ,
15
16
} from '../../../codewhisperer/commands/startTransformByQ'
@@ -40,14 +41,14 @@ import {
40
41
} from '../../../codewhisperer/service/transformByQ/transformProjectValidationHandler'
41
42
import { TransformationCandidateProject , ZipManifest } from '../../../codewhisperer/models/model'
42
43
import globals from '../../../shared/extensionGlobals'
43
- import { fs } from '../../../shared'
44
+ import { env , fs } from '../../../shared'
44
45
import { convertDateToTimestamp , convertToTimeString } from '../../../shared/datetime'
45
46
46
47
describe ( 'transformByQ' , function ( ) {
47
48
let tempDir : string
48
49
49
50
beforeEach ( async function ( ) {
50
- tempDir = await makeTemporaryToolkitFolder ( )
51
+ tempDir = ( await TestFolder . create ( ) ) . path
51
52
transformByQState . setToNotStarted ( )
52
53
} )
53
54
@@ -149,6 +150,22 @@ describe('transformByQ', function () {
149
150
sinon . assert . calledWithExactly ( stopJobStub , { transformationJobId : 'dummyId' } )
150
151
} )
151
152
153
+ it ( 'WHEN stopTransformByQ called with job that has already terminated THEN stop API not called' , async function ( ) {
154
+ const stopJobStub = sinon . stub ( codeWhisperer . codeWhispererClient , 'codeModernizerStopCodeTransformation' )
155
+ transformByQState . setToSucceeded ( )
156
+ await stopTransformByQ ( 'abc-123' )
157
+ sinon . assert . notCalled ( stopJobStub )
158
+ } )
159
+
160
+ it ( 'WHEN finalizeTransformationJob on failed job THEN error thrown and error message fields are set' , async function ( ) {
161
+ await assert . rejects ( async ( ) => {
162
+ await finalizeTransformationJob ( 'FAILED' )
163
+ } )
164
+ assert . notStrictEqual ( transformByQState . getJobFailureErrorChatMessage ( ) , undefined )
165
+ assert . notStrictEqual ( transformByQState . getJobFailureErrorNotification ( ) , undefined )
166
+ transformByQState . setJobDefaults ( ) // reset error messages to undefined
167
+ } )
168
+
152
169
it ( 'WHEN polling completed job THEN returns status as completed' , async function ( ) {
153
170
const mockJobResponse = {
154
171
$response : {
@@ -208,6 +225,16 @@ describe('transformByQ', function () {
208
225
assert . deepStrictEqual ( actual , expected )
209
226
} )
210
227
228
+ it ( `WHEN transforming a project with a Windows Maven executable THEN mavenName set correctly` , async function ( ) {
229
+ sinon . stub ( env , 'isWin' ) . returns ( true )
230
+ const tempFileName = 'mvnw.cmd'
231
+ const tempFilePath = path . join ( tempDir , tempFileName )
232
+ await toFile ( '' , tempFilePath )
233
+ transformByQState . setProjectPath ( tempDir )
234
+ await setMaven ( )
235
+ assert . strictEqual ( transformByQState . getMavenName ( ) , '.\\mvnw.cmd' )
236
+ } )
237
+
211
238
it ( `WHEN zip created THEN manifest.json contains test-compile custom build command` , async function ( ) {
212
239
const tempFileName = `testfile-${ globals . clock . Date . now ( ) } .zip`
213
240
transformByQState . setProjectPath ( tempDir )
@@ -234,6 +261,19 @@ describe('transformByQ', function () {
234
261
} )
235
262
} )
236
263
264
+ it ( 'WHEN zipCode THEN ZIP contains all expected files and no unexpected files' , async function ( ) {
265
+ const zipFilePath = path . join ( tempDir , 'test.zip' )
266
+ const zip = new AdmZip ( )
267
+ await fs . writeFile ( path . join ( tempDir , 'pom.xml' ) , 'dummy pom.xml' )
268
+ zip . addLocalFile ( path . join ( tempDir , 'pom.xml' ) )
269
+ zip . addFile ( 'manifest.json' , Buffer . from ( JSON . stringify ( { version : '1.0' } ) ) )
270
+ zip . writeZip ( zipFilePath )
271
+ const zipFiles = new AdmZip ( zipFilePath ) . getEntries ( )
272
+ const zipFileNames = zipFiles . map ( ( file ) => file . name )
273
+ assert . strictEqual ( zipFileNames . length , 2 ) // expecting only pom.xml and manifest.json
274
+ assert . strictEqual ( zipFileNames . includes ( 'pom.xml' ) && zipFileNames . includes ( 'manifest.json' ) , true )
275
+ } )
276
+
237
277
it ( `WHEN zip created THEN dependencies contains no .sha1 or .repositories files` , async function ( ) {
238
278
const m2Folders = [
239
279
'com/groupid1/artifactid1/version1' ,
0 commit comments