12
12
import org .openapitools .codegen .config .CodegenConfigurator ;
13
13
import org .openapitools .codegen .languages .AsciidocDocumentationCodegen ;
14
14
import org .testng .Assert ;
15
+ import org .testng .annotations .AfterClass ;
16
+ import org .testng .annotations .BeforeClass ;
15
17
import org .testng .annotations .Test ;
16
18
19
+ /** several asciidoc content checks with sample openapi v3. */
17
20
public class AsciidocSampleGeneratorTest {
18
21
19
- /**
20
- * ensure api-docs.json includes sample and spec files into markup.
21
- * @throws Exception generic exception
22
- */
23
- @ Test
24
- public void testSampleAsciidocMarkupGenerationFromJsonWithSpecsAndSamples () throws Exception {
22
+ public String markupContent = null ;
23
+ public String markupFileName = null ;
25
24
26
- File outputTempDirectory = Files .createTempDirectory ("test-asciidoc-sample-generator." ).toFile ();
25
+ File specDir = new File ("src/test/resources/3_0/asciidoc/specs/" );
26
+ File snippetDir = new File ("src/test/resources/3_0/asciidoc/generated-snippets/" );
27
27
28
- File specDir = new File ( "src/test/resources/3_0/asciidoc/specs/" );
29
- File snippetDir = new File ( "src/test/resources/3_0/asciidoc/generated-snippets/" );
28
+ @ BeforeClass
29
+ public void beforeClassGenerateTestMarkup () throws Exception {
30
30
31
- Assert .assertTrue (specDir .exists (), "test cancel, not specdDir found to use." + specDir .getPath ());
31
+ File outputTempDirectory = Files .createTempDirectory ("test-asciidoc-sample-generator." ).toFile ();
32
+
33
+ Assert .assertTrue (specDir .exists (), "test cancel, not specDir found to use." + specDir .getPath ());
32
34
Assert .assertTrue (snippetDir .exists (), "test cancel, not snippedDir found to use." + snippetDir .getPath ());
33
35
34
36
final CodegenConfigurator configurator = new CodegenConfigurator ().setGeneratorName ("asciidoc" )
@@ -40,46 +42,77 @@ public void testSampleAsciidocMarkupGenerationFromJsonWithSpecsAndSamples() thro
40
42
DefaultGenerator generator = new DefaultGenerator ();
41
43
List <File > files = generator .opts (configurator .toClientOptInput ()).generate ();
42
44
43
- boolean markupFileGenerated = false ;
44
-
45
45
for (File file : files ) {
46
46
if (file .getName ().equals ("index.adoc" )) {
47
- markupFileGenerated = true ;
48
- String markupContent = FileUtils .readFileToString (file , StandardCharsets .UTF_8 );
47
+ this .markupFileName = file .getAbsoluteFile ().toString ();
48
+ this .markupContent = FileUtils .readFileToString (file , StandardCharsets .UTF_8 );
49
+ }
50
+ }
51
+ }
49
52
50
- // include correct values from cli.
51
- Assert .assertTrue (markupContent .contains (":specDir: " + specDir .toString ()),
52
- "expected :specDir: in: " + markupContent .substring (0 , 350 ));
53
- Assert .assertTrue (markupContent .contains (":snippetDir: " + snippetDir .toString ()),
54
- "expected :snippetDir: in: " + markupContent .substring (0 , 350 ));
53
+ @ AfterClass
54
+ public void afterClassCleanUpTestMarkup () throws Exception {
55
+ if (this .markupFileName != null ) {
56
+ Files .deleteIfExists (Paths .get (this .markupFileName ));
57
+ }
58
+ }
55
59
56
- // include correct markup from separate directories, relative links
57
- Assert .assertTrue (markupContent .contains ("include::rest/project/GET/spec.adoc[]" ),
58
- "expected project spec.adoc to be included in " + file .getAbsolutePath ());
60
+ @ Test
61
+ public void testMarkupExistence () {
62
+ Assert .assertNotNull (this .markupContent , "asciidoc content index.adoc not created." );
63
+ }
59
64
60
- Assert .assertTrue (markupContent .contains ("include::rest/project/GET/implementation.adoc[]" ),
61
- "expected project implementation.adoc to be included in " + file .getAbsolutePath ());
65
+ /**
66
+ * ensure api-docs.json includes sample and spec files directory as attributes.
67
+ */
68
+ @ Test
69
+ public void testSampleAsciidocMarkupGenerationFromJsonWithAttributes () throws Exception {
70
+ Assert .assertTrue (markupContent .contains (":specDir: " + specDir .toString ()),
71
+ "expected :specDir: in: " + markupContent .substring (0 , 350 ));
72
+ Assert .assertTrue (markupContent .contains (":snippetDir: " + snippetDir .toString ()),
73
+ "expected :snippetDir: in: " + markupContent .substring (0 , 350 ));
74
+ }
75
+
76
+ /**
77
+ * ensure api-docs.json includes sample and spec files into markup.
78
+ */
79
+ @ Test
80
+ public void testSampleAsciidocMarkupGenerationFromJsonWithIncludes () throws Exception {
62
81
63
- Assert .assertTrue (markupContent .contains ("include::rest/project/GET/http-request.adoc[]" ),
64
- "expected project http-request.adoc to be included in " + file .getAbsolutePath ());
82
+ // include correct markup from separate directories, relative links
83
+ Assert .assertTrue (markupContent .contains ("include::rest/project/GET/spec.adoc[" ),
84
+ "expected project spec.adoc to be included in " + markupFileName );
65
85
66
- Assert .assertTrue (markupContent .contains ("include::rest/project/GET/http-response .adoc[] " ),
67
- "expected project http-response .adoc to be included in " + file . getAbsolutePath () );
86
+ Assert .assertTrue (markupContent .contains ("include::rest/project/GET/implementation .adoc[" ),
87
+ "expected project implementation .adoc to be included in " + markupFileName );
68
88
69
- Assert .assertTrue (markupContent .contains ("link: rest/project/GET/GET.json [" ),
70
- "expected link: not found in file: " + file . getAbsoluteFile () );
89
+ Assert .assertTrue (markupContent .contains ("include:: rest/project/GET/http-request.adoc [" ),
90
+ "expected project http-request.adoc to be included in " + markupFileName );
71
91
72
- // extract correct value from json
73
- Assert .assertTrue (markupContent .contains ("= time@work rest api" ),
74
- "missing main header for api spec from json: " + markupContent .substring (0 , 100 ));
75
- }
76
- Files .deleteIfExists (Paths .get (file .getAbsolutePath ()));
77
- }
92
+ Assert .assertTrue (markupContent .contains ("include::rest/project/GET/http-response.adoc[" ),
93
+ "expected project http-response.adoc to be included in " + markupFileName );
78
94
79
- Assert .assertTrue (markupFileGenerated , "index.adoc is not generated!" );
95
+ Assert .assertTrue (markupContent .contains ("link:rest/project/GET/GET.json[" ),
96
+ "expected link: not found in file: " + markupFileName );
97
+ }
80
98
81
- Files .deleteIfExists (Paths .get (outputTempDirectory .getAbsolutePath (), ".openapi-generator" ));
82
- Files .deleteIfExists (Paths .get (outputTempDirectory .getAbsolutePath ()));
99
+ /**
100
+ * markup doc header content.
101
+ */
102
+ @ Test
103
+ public void testSampleAsciidocMarkupGenerationFromJsonWithContent () throws Exception {
104
+ Assert .assertTrue (markupContent .contains ("= time@work rest api" ),
105
+ "missing main header for api spec from json: " + markupContent .substring (0 , 100 ));
106
+
107
+ }
108
+
109
+ /**
110
+ * fix: parameter name unchanged.
111
+ */
112
+ @ Test
113
+ public void testSampleAsciidocMarkupGenerationParameterNameUnchanged () throws Exception {
114
+ Assert .assertTrue (markupContent .contains ("from-iso-date-string" ),
115
+ "keep parameter name from-iso-date-string unchanged." );
83
116
}
84
117
85
118
}
0 commit comments