forked from asyncapi/modelina
-
Notifications
You must be signed in to change notification settings - Fork 0
/
blackbox-java.spec.ts
84 lines (80 loc) · 2.67 KB
/
blackbox-java.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/**
* Blackbox tests are the final line of defense, that takes different real-life example documents and generate their corresponding models in all supported languages.
*
* For those languages where it is possible, the models are compiled/transpiled to ensure there are no syntax errors in generated models.
*
*/
import * as path from 'path';
import * as fs from 'fs';
import {
InputMetaModel,
InputProcessor,
JavaFileGenerator,
JAVA_COMMON_PRESET
} from '../../src';
import { execCommand } from './utils/Utils';
import filesToTest from './BlackBoxTestFiles';
describe.each(filesToTest)(
'Should be able to generate with inputs',
({ file, outputDirectory }) => {
jest.setTimeout(1000000);
const fileToGenerateFor = path.resolve(__dirname, file);
const outputDirectoryPath = path.resolve(
__dirname,
outputDirectory,
'java'
);
let models: InputMetaModel;
beforeAll(async () => {
if (fs.existsSync(outputDirectoryPath)) {
fs.rmSync(outputDirectoryPath, { recursive: true });
}
const inputFileContent = await fs.promises.readFile(fileToGenerateFor);
const processor = new InputProcessor();
const input = JSON.parse(String(inputFileContent));
models = await processor.process(input);
});
describe(file, () => {
const javaGeneratorOptions = [
{
generatorOption: {},
description: 'default generator',
renderOutputPath: path.resolve(outputDirectoryPath, './class/default')
},
{
generatorOption: {
presets: [JAVA_COMMON_PRESET]
},
description: 'all common presets',
renderOutputPath: path.resolve(
outputDirectoryPath,
'./class/commonpreset'
)
}
];
describe.each(javaGeneratorOptions)(
'should be able to generate and compile Java',
({ generatorOption, renderOutputPath, description }) => {
test(`class and enums ${description}`, async () => {
const generator = new JavaFileGenerator(generatorOption);
const dependencyPath = path.resolve(
__dirname,
'./dependencies/java/*'
);
const generatedModels = await generator.generateToFiles(
models,
renderOutputPath,
{ packageName: 'TestPackageName' }
);
expect(generatedModels).not.toHaveLength(0);
const compileCommand = `javac -cp ${dependencyPath} ${path.resolve(
renderOutputPath,
'*.java'
)}`;
await execCommand(compileCommand);
});
}
);
});
}
);