diff --git a/test/Common.test.js b/test/Common.test.js index 3afabf4..901c43c 100644 --- a/test/Common.test.js +++ b/test/Common.test.js @@ -17,6 +17,7 @@ const generateFolderName = () => { return path.resolve(MAIN_TEST_RESULT_PATH, crypto.randomBytes(4).toString('hex')); }; +jest.setTimeout(30000); // Test class Function test('Creates Class from parameters', () => { @@ -146,8 +147,6 @@ test('invalid port', () => { // Test EnvJson Function test('EnvJson extracts correct values', async () => { - jest.setTimeout(30000); - const OUTPUT_DIR = generateFolderName(); const generator = new Generator(path.normalize('./'), OUTPUT_DIR, { forceWrite: true, templateParams: params }); @@ -171,8 +170,6 @@ test('EnvJson extracts correct values', async () => { // Test ImportModels test('ImportModels are generated', async () => { - jest.setTimeout(30000); - const OUTPUT_DIR = generateFolderName(); const generator = new Generator(path.normalize('./'), OUTPUT_DIR, { forceWrite: true, templateParams: params }); diff --git a/test/Consumer.test.js b/test/Consumer.test.js index d244ab8..dcf1295 100644 --- a/test/Consumer.test.js +++ b/test/Consumer.test.js @@ -6,22 +6,22 @@ const crypto = require('crypto'); const MAIN_TEST_RESULT_PATH = path.join('test', 'temp', 'integrationTestResult'); +jest.setTimeout(30000); + // Test Imports function test('Generates all imports from path', async() => { const generateFolderName = () => { return path.resolve(MAIN_TEST_RESULT_PATH, crypto.randomBytes(4).toString('hex')); }; - - jest.setTimeout(30000); - + const OUTPUT_DIR = generateFolderName(); const params = { server: 'production' }; - + const generator = new Generator(path.normalize('./'), OUTPUT_DIR, { forceWrite: true, templateParams: params }); await generator.generateFromFile(path.resolve('test', 'mocks/single-channel.yml')); - + expect(testConsumer.ConsumerImports({asyncapi: generator.asyncapi, params: generator.templateParams, message: { name: 'Song', id: () => { return 'Song'; }}})).toBe(` import java.util.logging.*; import java.io.Serializable; diff --git a/test/integration.test.js b/test/integration.test.js index 0255708..cfd14f4 100644 --- a/test/integration.test.js +++ b/test/integration.test.js @@ -5,8 +5,8 @@ const crypto = require('crypto'); const MAIN_TEST_RESULT_PATH = path.join('test', 'temp', 'integrationTestResult'); -/* - * Please note: This test file was adapted from +/* + * Please note: This test file was adapted from * https://github.com/asyncapi/java-spring-cloud-stream-template/blob/master/test/integration.test.js */ @@ -19,15 +19,13 @@ describe('template integration tests using the generator', () => { jest.setTimeout(30000); it('should generate static application files', async () => { - jest.setTimeout(30000); - const OUTPUT_DIR = generateFolderName(); const PACKAGE = 'com.asyncapi'; const PACKAGE_PATH = path.join(...PACKAGE.split('.')); const params = { server: 'production' }; - + const generator = new Generator(path.normalize('./'), OUTPUT_DIR, { forceWrite: true, templateParams: params }); await generator.generateFromFile(path.resolve('test', 'mocks/single-channel.yml')); @@ -47,15 +45,13 @@ describe('template integration tests using the generator', () => { }); it('should generate dynamic producer subscriber files', async () => { - jest.setTimeout(30000); - const OUTPUT_DIR = generateFolderName(); const PACKAGE = 'com.asyncapi'; const PACKAGE_PATH = path.join(...PACKAGE.split('.')); const params = { server: 'production' }; - + const generator = new Generator(path.normalize('./'), OUTPUT_DIR, { forceWrite: true, templateParams: params }); await generator.generateFromFile(path.resolve('test', 'mocks/single-channel.yml')); @@ -66,22 +62,20 @@ describe('template integration tests using the generator', () => { `${PACKAGE_PATH}/${channelName}Producer.java`, `${PACKAGE_PATH}/${channelName}Subscriber.java` ]; - + for (const index in expectedFiles) { expect(existsSync(path.join(OUTPUT_DIR, expectedFiles[index]))).toBe(true); } }); it('should generate dynamic model files', async () => { - jest.setTimeout(30000); - const OUTPUT_DIR = generateFolderName(); const PACKAGE = 'com.asyncapi'; const PACKAGE_PATH = path.join(...PACKAGE.split('.')); const params = { server: 'production' }; - + const generator = new Generator(path.normalize('./'), OUTPUT_DIR, { forceWrite: true, templateParams: params }); await generator.generateFromFile(path.resolve('test', 'mocks/many-messages.yml')); @@ -91,15 +85,13 @@ describe('template integration tests using the generator', () => { `${PACKAGE_PATH}/models/Album.java`, `${PACKAGE_PATH}/models/Artist.java` ]; - + for (const index in expectedFiles) { expect(existsSync(path.join(OUTPUT_DIR, expectedFiles[index]))).toBe(true); } }); it('file structure should depend on package', async () => { - jest.setTimeout(30000); - const OUTPUT_DIR = generateFolderName(); const PACKAGE = 'com.ibm.mq.different.jms'; const PACKAGE_PATH = path.join(...PACKAGE.split('.')); @@ -107,32 +99,30 @@ describe('template integration tests using the generator', () => { server: 'production', package: PACKAGE }; - + const generator = new Generator(path.normalize('./'), OUTPUT_DIR, { forceWrite: true, templateParams: params }); await generator.generateFromFile(path.resolve('test', 'mocks/many-messages.yml')); const expectedFiles = [ `${PACKAGE_PATH}/Connection.java` ]; - + for (const index in expectedFiles) { expect(existsSync(path.join(OUTPUT_DIR, expectedFiles[index]))).toBe(true); } }); it('default env password is passw0rd', async () => { - jest.setTimeout(30000); - const OUTPUT_DIR = generateFolderName(); const PACKAGE = 'com.ibm.mq.different.jms'; const params = { server: 'production', package: PACKAGE }; - + const generator = new Generator(path.normalize('./'), OUTPUT_DIR, { forceWrite: true, templateParams: params }); await generator.generateFromFile(path.resolve('test', 'mocks/many-messages.yml')); - + // Read in JSON file const exportedEnv = JSON.parse(readFileSync(path.join(OUTPUT_DIR, 'env.json'))); const password = exportedEnv.MQ_ENDPOINTS[0].APP_PASSWORD; @@ -142,8 +132,6 @@ describe('template integration tests using the generator', () => { }); it('default password overwritten on param provide', async () => { - jest.setTimeout(30000); - const OUTPUT_DIR = generateFolderName(); const PACKAGE = 'com.ibm.mq.different.jms'; const params = { @@ -151,10 +139,10 @@ describe('template integration tests using the generator', () => { package: PACKAGE, password: 'paramProvidedPassword' }; - + const generator = new Generator(path.normalize('./'), OUTPUT_DIR, { forceWrite: true, templateParams: params }); await generator.generateFromFile(path.resolve('test', 'mocks/many-messages.yml')); - + // Read in JSON file const exportedEnv = JSON.parse(readFileSync(path.join(OUTPUT_DIR, 'env.json'))); const password = exportedEnv.MQ_ENDPOINTS[0].APP_PASSWORD; @@ -164,15 +152,13 @@ describe('template integration tests using the generator', () => { }); it('default password overwritten by system env', async () => { - jest.setTimeout(30000); - const OUTPUT_DIR = generateFolderName(); const PACKAGE = 'com.ibm.mq.different.jms'; const params = { server: 'production', package: PACKAGE }; - + // Set app_password env variable process.env.APP_PASSWORD = 'envAppPassword'; @@ -191,8 +177,6 @@ describe('template integration tests using the generator', () => { }); it('password parameter overwrites environment variable', async () => { - jest.setTimeout(30000); - const OUTPUT_DIR = generateFolderName(); const PACKAGE = 'com.ibm.mq.different.jms'; const params = { @@ -200,7 +184,7 @@ describe('template integration tests using the generator', () => { package: PACKAGE, password: 'paramProvidedPassword' }; - + // Set app_password env variable process.env.APP_PASSWORD = 'envAppPassword'; @@ -219,18 +203,16 @@ describe('template integration tests using the generator', () => { }); it('default env username is app', async () => { - jest.setTimeout(30000); - const OUTPUT_DIR = generateFolderName(); const PACKAGE = 'com.ibm.mq.different.jms'; const params = { server: 'production', package: PACKAGE }; - + const generator = new Generator(path.normalize('./'), OUTPUT_DIR, { forceWrite: true, templateParams: params }); await generator.generateFromFile(path.resolve('test', 'mocks/many-messages.yml')); - + // Read in JSON file const exportedEnv = JSON.parse(readFileSync(path.join(OUTPUT_DIR, 'env.json'))); const username = exportedEnv.MQ_ENDPOINTS[0].APP_USER; @@ -240,8 +222,6 @@ describe('template integration tests using the generator', () => { }); it('default username overwritten on param provide', async () => { - jest.setTimeout(30000); - const OUTPUT_DIR = generateFolderName(); const PACKAGE = 'com.ibm.mq.different.jms'; const params = { @@ -249,10 +229,10 @@ describe('template integration tests using the generator', () => { package: PACKAGE, user: 'paramUsername' }; - + const generator = new Generator(path.normalize('./'), OUTPUT_DIR, { forceWrite: true, templateParams: params }); await generator.generateFromFile(path.resolve('test', 'mocks/many-messages.yml')); - + // Read in JSON file const exportedEnv = JSON.parse(readFileSync(path.join(OUTPUT_DIR, 'env.json'))); const username = exportedEnv.MQ_ENDPOINTS[0].APP_USER; @@ -262,15 +242,13 @@ describe('template integration tests using the generator', () => { }); it('default username overwritten by system env', async () => { - jest.setTimeout(30000); - const OUTPUT_DIR = generateFolderName(); const PACKAGE = 'com.ibm.mq.different.jms'; const params = { server: 'production', package: PACKAGE }; - + // Set app_user env variable process.env.APP_USER = 'envAppUsername'; @@ -289,8 +267,6 @@ describe('template integration tests using the generator', () => { }); it('username parameter overwrites environment variable', async () => { - jest.setTimeout(30000); - const OUTPUT_DIR = generateFolderName(); const PACKAGE = 'com.ibm.mq.different.jms'; const params = { @@ -298,7 +274,7 @@ describe('template integration tests using the generator', () => { package: PACKAGE, user: 'paramProvidedUsername' }; - + // Set app_user env variable process.env.APP_USER = 'envAppUsername';