1
1
package io .swagger .generator .online ;
2
2
3
3
import com .fasterxml .jackson .databind .JsonNode ;
4
+ import io .swagger .generator .model .GenerationRequest ;
5
+ import io .swagger .generator .model .Options ;
4
6
import io .swagger .v3 .core .util .Json ;
7
+ import org .apache .commons .io .FileUtils ;
5
8
import org .apache .commons .io .IOUtils ;
9
+ import org .apache .http .HttpEntity ;
6
10
import org .apache .http .HttpResponse ;
7
11
import org .apache .http .client .HttpClient ;
8
12
import org .apache .http .client .methods .HttpGet ;
13
+ import org .apache .http .client .methods .HttpPost ;
14
+ import org .apache .http .entity .StringEntity ;
9
15
import org .apache .http .impl .client .HttpClientBuilder ;
10
16
import org .testng .Assert ;
11
17
import org .testng .annotations .Test ;
12
18
19
+ import java .io .File ;
20
+ import java .util .LinkedHashMap ;
21
+ import java .util .Map ;
22
+
13
23
public class GeneratorControllerIT {
14
24
15
25
static final String DEFAULT_HOST = "http://localhost:8080/v2" ;
16
26
private HttpClient client = HttpClientBuilder .create ().build ();
17
27
18
- @ Test
28
+ @ Test ( enabled = false )
19
29
public void getClients () throws Exception {
20
30
final HttpResponse response = client .execute (new HttpGet (DEFAULT_HOST + "/clients" ));
21
31
int responseCode = response .getStatusLine ().getStatusCode ();
@@ -27,7 +37,7 @@ public void getClients() throws Exception {
27
37
Assert .assertTrue (jsonNode .toString ().contains ("java" ));
28
38
}
29
39
30
- @ Test
40
+ @ Test ( enabled = false )
31
41
public void getServers () throws Exception {
32
42
final HttpResponse response = client .execute (new HttpGet (DEFAULT_HOST + "/servers" ));
33
43
int responseCode = response .getStatusLine ().getStatusCode ();
@@ -38,4 +48,30 @@ public void getServers() throws Exception {
38
48
Assert .assertTrue (jsonNode .isArray ());
39
49
Assert .assertTrue (jsonNode .toString ().contains ("inflector" ));
40
50
}
51
+
52
+ @ Test (enabled = false )
53
+ public void generateJava () throws Exception {
54
+ String json = FileUtils .readFileToString (new File ("src/test/resources/petstore-oas3.json" ));
55
+ JsonNode node = Json .mapper ().readTree (json );
56
+ Map <String , Object > spec = Json .mapper ().convertValue (node , LinkedHashMap .class );
57
+
58
+
59
+ GenerationRequest generationRequest = new GenerationRequest ()
60
+ .spec (spec )
61
+ .options (new Options ()
62
+ .lang ("java" ));
63
+ HttpEntity entity = new StringEntity (Json .pretty (generationRequest ), "UTF-8" );
64
+
65
+ HttpPost post = new HttpPost (DEFAULT_HOST + "/generate" );
66
+ post .setHeader ("Content-Type" , "application/json" );
67
+ post .setEntity (entity );
68
+
69
+ final HttpResponse response = client .execute (post );
70
+ int responseCode = response .getStatusLine ().getStatusCode ();
71
+ Assert .assertEquals (responseCode , 200 );
72
+ Assert .assertEquals (response .getFirstHeader ("Content-Type" ).getValue (), "application/octet-stream" );
73
+ Assert .assertTrue (response .getFirstHeader ("Content-Disposition" ).getValue ().contains (" filename=\" generated-java-bundle.zip\" " ));
74
+ }
75
+
76
+
41
77
}
0 commit comments