Skip to content

Commit f9c7c52

Browse files
committed
tests for PHP generator gitRepoBaseURL Option, in readme
1 parent 03533cf commit f9c7c52

File tree

1 file changed

+113
-0
lines changed

1 file changed

+113
-0
lines changed

modules/swagger-codegen/src/test/java/io/swagger/codegen/v3/service/GeneratorServiceTest.java

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,119 @@
1818
import java.util.List;
1919

2020
public class GeneratorServiceTest {
21+
22+
@Test(description = "readme reference url")
23+
public void testGeneratorService_readmeV2() throws IOException {
24+
25+
String path = getTmpFolder().getAbsolutePath();
26+
GenerationRequest request = new GenerationRequest();
27+
request
28+
.codegenVersion(GenerationRequest.CodegenVersion.V2)
29+
.type(GenerationRequest.Type.CLIENT)
30+
.lang("php")
31+
.spec(loadSpecAsNode("2_0/readme149.yaml", true, true))
32+
.options(
33+
new Options()
34+
.outputDir(path)
35+
.gitRepoId("TestRepo")
36+
.gitUserId("testuser")
37+
.gitRepoBaseURL("gitlab")
38+
);
39+
List<File> files = new GeneratorService().generationRequest(request).generate();
40+
Assert.assertFalse(files.isEmpty());
41+
for (File f: files) {
42+
String relPath = f.getAbsolutePath().substring(path.length());
43+
if ("/SwaggerClient-php/README.md".equals(relPath)) {
44+
Assert.assertTrue(FileUtils.readFileToString(f).contains("gitlab"));
45+
}
46+
if ("/SwaggerClient-php/git_push.sh".equals(relPath)) {
47+
Assert.assertFalse(FileUtils.readFileToString(f).contains("https://github.com"));
48+
}
49+
}
50+
}
51+
52+
@Test(description = "readme reference url")
53+
public void testGeneratorService_readmeV2_NoOption() throws IOException {
54+
55+
String path = getTmpFolder().getAbsolutePath();
56+
GenerationRequest request = new GenerationRequest();
57+
request
58+
.codegenVersion(GenerationRequest.CodegenVersion.V2)
59+
.type(GenerationRequest.Type.CLIENT)
60+
.lang("php")
61+
.spec(loadSpecAsNode("2_0/readme149.yaml", true, true))
62+
.options(
63+
new Options()
64+
.outputDir(path)
65+
.gitRepoId("TestRepo")
66+
.gitUserId("testuser")
67+
);
68+
List<File> files = new GeneratorService().generationRequest(request).generate();
69+
Assert.assertFalse(files.isEmpty());
70+
for (File f: files) {
71+
String relPath = f.getAbsolutePath().substring(path.length());
72+
if ("/SwaggerClient-php/README.md".equals(relPath)) {
73+
Assert.assertTrue(FileUtils.readFileToString(f).contains("https://github.com/testuser"));
74+
}
75+
}
76+
}
77+
78+
@Test(description = "readme reference url")
79+
public void testGeneratorService_readmeV3() throws IOException {
80+
81+
String path = getTmpFolder().getAbsolutePath();
82+
GenerationRequest request = new GenerationRequest();
83+
request
84+
.codegenVersion(GenerationRequest.CodegenVersion.V3)
85+
.type(GenerationRequest.Type.CLIENT)
86+
.lang("php")
87+
.spec(loadSpecAsNode("3_0_0/readme149_v3.yaml", true, false))
88+
.options(
89+
new Options()
90+
.outputDir(path)
91+
.gitRepoId("TestRepo")
92+
.gitUserId("testuser")
93+
.gitRepoBaseURL("gitlab")
94+
);
95+
List<File> files = new GeneratorService().generationRequest(request).generate();
96+
Assert.assertFalse(files.isEmpty());
97+
for (File f: files) {
98+
String relPath = f.getAbsolutePath().substring(path.length());
99+
if ("/SwaggerClient-php/README.md".equals(relPath)) {
100+
Assert.assertTrue(FileUtils.readFileToString(f).contains("gitlab"));
101+
}
102+
if ("/SwaggerClient-php/git_push.sh".equals(relPath)) {
103+
Assert.assertFalse(FileUtils.readFileToString(f).contains("https://github.com"));
104+
}
105+
}
106+
}
107+
108+
@Test(description = "readme reference url")
109+
public void testGeneratorService_readmeV3_NoOption() throws IOException {
110+
111+
String path = getTmpFolder().getAbsolutePath();
112+
GenerationRequest request = new GenerationRequest();
113+
request
114+
.codegenVersion(GenerationRequest.CodegenVersion.V3)
115+
.type(GenerationRequest.Type.CLIENT)
116+
.lang("php")
117+
.spec(loadSpecAsNode("3_0_0/readme149_v3.yaml", true, false))
118+
.options(
119+
new Options()
120+
.outputDir(path)
121+
.gitRepoId("TestRepo")
122+
.gitUserId("testuser")
123+
124+
);
125+
List<File> files = new GeneratorService().generationRequest(request).generate();
126+
Assert.assertFalse(files.isEmpty());
127+
for (File f: files) {
128+
String relPath = f.getAbsolutePath().substring(path.length());
129+
if ("/SwaggerClient-php/README.md".equals(relPath)) {
130+
Assert.assertTrue(FileUtils.readFileToString(f).contains("http://github.com/testuser"));
131+
}
132+
}
133+
}
21134

22135
@Test(description = "test generator service with html2")
23136
public void testGeneratorService_HTML2_Bearer() throws IOException {

0 commit comments

Comments
 (0)