1
+ package io .swagger .codegen .v3 .generators .java ;
2
+
3
+ import java .io .File ;
4
+ import java .io .IOException ;
5
+
6
+ import org .apache .commons .io .FileUtils ;
7
+ import org .junit .rules .TemporaryFolder ;
8
+ import org .testng .Assert ;
9
+ import org .testng .annotations .Test ;
10
+ import org .testng .annotations .AfterClass ;
11
+ import org .testng .annotations .BeforeClass ;
12
+
13
+ import io .swagger .codegen .v3 .ClientOptInput ;
14
+ import io .swagger .codegen .v3 .DefaultGenerator ;
15
+ import io .swagger .codegen .v3 .config .CodegenConfigurator ;
16
+ import io .swagger .codegen .v3 .generators .AbstractCodegenTest ;
17
+
18
+ public class MicronautGeneratorCodegenTest extends AbstractCodegenTest {
19
+ private final TemporaryFolder folder = new TemporaryFolder ();
20
+ private File output = null ;
21
+
22
+ @ BeforeClass
23
+ public void generateCode () throws IOException {
24
+ this .folder .create ();
25
+ output = this .folder .getRoot ();
26
+
27
+ final CodegenConfigurator configurator = new CodegenConfigurator ()
28
+ .setLang ("micronaut" )
29
+ .setInputSpecURL ("src/test/resources/3_0_0/parameterOrder.yaml" )
30
+ .setOutputDir (output .getAbsolutePath ());
31
+
32
+ final ClientOptInput clientOptInput = configurator .toClientOptInput ();
33
+ new DefaultGenerator ().opts (clientOptInput ).generate ();
34
+ }
35
+
36
+ @ AfterClass
37
+ public void cleanUp () {
38
+ this .folder .delete ();
39
+ }
40
+
41
+ @ Test (description = "verify that model classes are generated" )
42
+ public void testModels () {
43
+ Assert .assertTrue (new File (output , "/src/main/java/io/swagger/model/LocalizedText.java" ).exists ());
44
+ }
45
+
46
+ @ Test (description = "verify that configuration classes are generated" )
47
+ public void testConfigurations () {
48
+ Assert .assertTrue (new File (output , "/src/main/java/io/swagger/configuration/UnsupportedOperationExceptionHandler.java" ).exists ());
49
+ }
50
+
51
+ @ Test (description = "verify interface api generated" )
52
+ public void testApiInterface () throws IOException {
53
+ final String expectedContent = "@Controller" + System .lineSeparator ()
54
+ + "public interface AdminApi {" ;
55
+ final File controllerFile = new File (output , "/src/main/java/io/swagger/api/AdminApi.java" );
56
+ final String content = FileUtils .readFileToString (controllerFile );
57
+ Assert .assertTrue (content .contains (expectedContent ));
58
+ }
59
+
60
+ @ Test (description = "verify that parameters are listed as follows: header, query, path, cookie, body" )
61
+ public void testApiParameters () throws IOException {
62
+ final String expectedContent = "default Single<HttpResponse<LocalizedText>> updateTest(@Parameter(description = \" Localized Text object containing updated data.\" ) @Valid @Body LocalizedText body" + System .lineSeparator ()
63
+ + ",@Parameter(description = \" description\" ) @PathVariable(\" id\" ) Long id" + System .lineSeparator ()
64
+ + ")" ;
65
+ final File controllerFile = new File (output , "/src/main/java/io/swagger/api/AdminApi.java" );
66
+ final String content = FileUtils .readFileToString (controllerFile );
67
+ Assert .assertTrue (content .contains (expectedContent ));
68
+ }
69
+ }
0 commit comments