Skip to content

Commit 5f13daa

Browse files
committed
wip
1 parent 644a076 commit 5f13daa

File tree

3 files changed

+207
-0
lines changed

3 files changed

+207
-0
lines changed

pom.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,18 @@
273273
<groupId>com.github.elibracha</groupId>
274274
<artifactId>openapi-diff-commons</artifactId>
275275
<version>1.0.2</version>
276+
</dependency>
277+
<dependency>
278+
<groupId>com.github.elibracha</groupId>
279+
<artifactId>openapi-diff</artifactId>
280+
<version>2.2.8</version>
281+
<scope>test</scope>
282+
<exclusions>
283+
<exclusion>
284+
<groupId>org.slf4j</groupId>
285+
<artifactId>slf4j-log4j12</artifactId>
286+
</exclusion>
287+
</exclusions>
276288
</dependency>
277289
<!-- END OPENAPI-DIFF DEPENDENCIES-->
278290
</dependencies>
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.github.elibracha.ChangeTest;
2+
3+
import com.github.elibracha.OpenApiCompare;
4+
import com.github.elibracha.model.ChangedOpenApi;
5+
import com.github.elibracha.output.HtmlRender;
6+
import com.github.elibracha.exceptions.SpecificationSupportException;
7+
import com.github.elibracha.processors.ContextProcessor;
8+
9+
import java.io.FileWriter;
10+
import java.io.IOException;
11+
12+
import static org.junit.Assert.assertFalse;
13+
import static org.junit.Assert.assertTrue;
14+
15+
public abstract class AbstractChangeTest {
16+
17+
protected void executeChangeTest(String ignorePath, String originalPath, String generatedPath, String outputPath, boolean assertTrue) throws SpecificationSupportException{
18+
ContextProcessor contextProcessor = new ContextProcessor(
19+
getClass().getClassLoader().getResource(ignorePath).getFile()
20+
);
21+
22+
ChangedOpenApi changedOpenApi = OpenApiCompare.fromLocations(originalPath, generatedPath);
23+
24+
ChangedOpenApi changedOpenApiAfter = contextProcessor.process(changedOpenApi);
25+
26+
27+
String html =
28+
new HtmlRender("Changelog", "http://deepoove.com/swagger-diff/stylesheets/demo.css")
29+
.render(changedOpenApiAfter);
30+
try {
31+
FileWriter fw = new FileWriter(String.format("target/%s.html", outputPath));
32+
fw.write(html);
33+
fw.close();
34+
35+
} catch (IOException e) {
36+
e.printStackTrace();
37+
}
38+
if(assertTrue)
39+
assertTrue(changedOpenApi.isUnchanged());
40+
else{
41+
assertFalse(changedOpenApi.isUnchanged());
42+
}
43+
}
44+
45+
}
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
package com.github.elibracha.ChangeTest;
2+
3+
import org.junit.Test;
4+
import com.github.elibracha.exceptions.SpecificationSupportException;
5+
6+
public class ChangeTest extends AbstractChangeTest {
7+
8+
@Test
9+
public void testContextProcessorUnchanged() throws SpecificationSupportException {
10+
this.executeChangeTest(
11+
"changes/context/diffignore.yaml",
12+
"changes/context/original.yaml",
13+
"changes/context/generated.yaml",
14+
"contextDiff",
15+
true
16+
);
17+
}
18+
19+
@Test
20+
public void testParametersWildcardTrue() throws SpecificationSupportException {
21+
this.executeChangeTest(
22+
"changes/parameters/diffignore.yaml",
23+
"changes/parameters/original.yaml",
24+
"changes/parameters/generated.yaml",
25+
"parameterWildcardDiff",
26+
true
27+
);
28+
}
29+
30+
@Test
31+
public void testRequestContentMediaTypesWildcardTrue() throws SpecificationSupportException {
32+
this.executeChangeTest(
33+
"changes/request/request_content_media_types/diffignore.yaml",
34+
"changes/request/request_content_media_types/original.yaml",
35+
"changes/request/request_content_media_types/generated.yaml",
36+
"requestWildMediaTypecardDiff",
37+
true
38+
);
39+
}
40+
41+
@Test
42+
public void testRequestWildcardTrue() throws SpecificationSupportException {
43+
this.executeChangeTest(
44+
"changes/request/request_wildcard/diffignore.yaml",
45+
"changes/request/request_wildcard/original.yaml",
46+
"changes/request/request_wildcard/generated.yaml",
47+
"requestWildcardDiff",
48+
true
49+
);
50+
}
51+
52+
@Test
53+
public void testResponseWildcardTrue() throws SpecificationSupportException {
54+
this.executeChangeTest(
55+
"changes/response/response_wildcard/diffignore_true.yaml",
56+
"changes/response/response_wildcard/original.yaml",
57+
"changes/response/response_wildcard/generated.yaml",
58+
"responseWildcardDiff",
59+
true
60+
);
61+
}
62+
63+
@Test
64+
public void testResponseStatusWildcardTrue() throws SpecificationSupportException {
65+
this.executeChangeTest(
66+
"changes/response/response_status_wildcard/diffignore_true.yaml",
67+
"changes/response/response_wildcard/original.yaml",
68+
"changes/response/response_wildcard/generated.yaml",
69+
"responseStatusWildCardTrue",
70+
true
71+
);
72+
}
73+
74+
@Test
75+
public void testResponseStatusWildcardFalse() throws SpecificationSupportException {
76+
this.executeChangeTest(
77+
"changes/response/response_status_wildcard/diffignore_false.yaml",
78+
"changes/response/response_status_wildcard/original.yaml",
79+
"changes/response/response_status_wildcard/generated.yaml",
80+
"responseStatusWildCardFalseDiff",
81+
false
82+
);
83+
}
84+
85+
@Test
86+
public void testResponseStatusSchemaWildcardTrue() throws SpecificationSupportException {
87+
this.executeChangeTest(
88+
"changes/response/response_status_schema_wildcard/diffignore.yaml",
89+
"changes/response/response_status_schema_wildcard/original.yaml",
90+
"changes/response/response_status_schema_wildcard/generated.yaml",
91+
"responseStatusSchemaWildcardTrueDiff",
92+
true
93+
);
94+
}
95+
96+
@Test
97+
public void testSecurityWildcardTrue() throws SpecificationSupportException {
98+
this.executeChangeTest(
99+
"changes/security/diffignore.yaml",
100+
"changes/security/original.yaml",
101+
"changes/security/generated.yaml",
102+
"responseStatusSchemaWildcardTrueDiff",
103+
true
104+
);
105+
}
106+
107+
@Test
108+
public void testResponseIncreasedTrue() throws SpecificationSupportException {
109+
this.executeChangeTest(
110+
"changes/response/response_increased_true/diffignore.yaml",
111+
"changes/response/response_increased_true/original.yaml",
112+
"changes/response/response_increased_true/generated.yaml",
113+
"ResponseIncreasedTrue",
114+
true
115+
);
116+
}
117+
118+
@Test
119+
public void testResponseIncreasedFalse() throws SpecificationSupportException {
120+
this.executeChangeTest(
121+
"changes/response/response_increased_false/diffignore.yaml",
122+
"changes/response/response_increased_false/original.yaml",
123+
"changes/response/response_increased_false/generated.yaml",
124+
"ResponseIncreasedFalse",
125+
false
126+
);
127+
}
128+
129+
@Test
130+
public void testSecurityProcessorIncreasedTrue() throws SpecificationSupportException {
131+
this.executeChangeTest(
132+
"changes/security/increased_true/diffignore.yaml",
133+
"changes/security/increased_true/original.yaml",
134+
"changes/security/increased_true/generated.yaml",
135+
"securityIncreasedTrue",
136+
true
137+
);
138+
}
139+
140+
@Test
141+
public void testSecurityProcessorIncreasedFalse() throws SpecificationSupportException {
142+
this.executeChangeTest(
143+
"changes/security/increased_false/diffignore.yaml",
144+
"changes/security/increased_false/original.yaml",
145+
"changes/security/increased_false/generated.yaml",
146+
"securityIncreasedFalse",
147+
false
148+
);
149+
}
150+
}

0 commit comments

Comments
 (0)