2424import io .vertx .tests .ResourceHelper ;
2525import java .nio .file .Paths ;
2626import java .util .Map ;
27- import org .junit .jupiter .api .*;
27+ import org .junit .jupiter .api .BeforeEach ;
28+ import org .junit .jupiter .api .DisplayNameGeneration ;
29+ import org .junit .jupiter .api .DisplayNameGenerator ;
30+ import org .junit .jupiter .api .Nested ;
31+ import org .junit .jupiter .api .Test ;
2832import org .junit .jupiter .api .extension .ExtendWith ;
2933
3034/**
3438@ DisplayNameGeneration (DisplayNameGenerator .ReplaceUnderscores .class )
3539public class OpenAPIContractBuilderTest {
3640
41+ private static final String CONTRACT_PATH = "v3.1/petstore.json" ;
42+ private static final String SPLIT_CONTRACT_PATH =
43+ "io/vertx/tests/contract/from_with_path_and_additional_files/petstore.json" ;
44+ private static final String SPLIT_CONTRACT_REFERENCE_PATH =
45+ "io/vertx/tests/contract/from_with_path_and_additional_files/petstore.json" ;
46+ private static final String SPLIT_CONTRACT_REFERENCE_KEY = "htts://example.com/petstore" ;
47+
3748 @ Test
3849 void should_create_contract_when_valid_contract_path_is_provided (Vertx vertx , VertxTestContext ctx ) {
3950 OpenAPIContract .builder (vertx )
40- .setContractPath ("v3.1/petstore.json" )
51+ .setContractPath (CONTRACT_PATH )
4152 .build ()
4253 .onComplete (ctx .succeedingThenComplete ());
4354 }
4455
4556 @ Test
4657 void should_create_contract_when_valid_contract_is_provided (Vertx vertx , VertxTestContext ctx ) {
47- var contract = ResourceHelper .loadJson (vertx , Paths .get ("v3.1/petstore.json" ));
58+ var contract = ResourceHelper .loadJson (vertx , Paths .get (CONTRACT_PATH ));
4859 OpenAPIContract .builder (vertx )
4960 .setContract (contract )
5061 .build ()
@@ -55,36 +66,33 @@ void should_create_contract_when_valid_contract_is_provided(Vertx vertx, VertxTe
5566 void should_create_contract_when_valid_contract_path_and_additional_contract_paths_are_provided (Vertx vertx ,
5667 VertxTestContext ctx ) {
5768 OpenAPIContract .builder (vertx )
58- .setContractPath ("io/vertx/tests/contract/from_with_path_and_additional_files/petstore.json" )
59- .putAdditionalContractPartPath ("https://example.com/petstore" ,
60- "io/vertx/tests/contract/from_with_path_and_additional_files/components.json" )
69+ .setContractPath (SPLIT_CONTRACT_PATH )
70+ .putAdditionalContractPartPath (SPLIT_CONTRACT_REFERENCE_KEY , SPLIT_CONTRACT_REFERENCE_PATH )
6171 .build ()
6272 .onComplete (ctx .succeedingThenComplete ());
6373 }
6474
6575 @ Test
66-
6776 void should_create_contract_when_valid_contract_and_additional_contract_path_is_provided (Vertx vertx ,
6877 VertxTestContext ctx ) {
6978 var contract = ResourceHelper .loadJson (vertx ,
70- Paths .get ("io/vertx/tests/contract/from_with_path_and_additional_files/petstore.json" ));
79+ Paths .get (SPLIT_CONTRACT_PATH ));
7180 OpenAPIContract .builder (vertx )
7281 .setContract (contract )
73- .putAdditionalContractPartPath ("https://example.com/petstore" ,
74- "io/vertx/tests/contract/from_with_path_and_additional_files/components.json" )
82+ .putAdditionalContractPartPath (SPLIT_CONTRACT_REFERENCE_KEY ,
83+ SPLIT_CONTRACT_REFERENCE_PATH )
7584 .build ()
7685 .onComplete (ctx .succeedingThenComplete ());
7786 }
7887
7988 @ Test
80-
8189 void should_create_contract_when_valid_contract_path_and_additional_contract_part_is_provided (Vertx vertx ,
8290 VertxTestContext ctx ) {
8391 var components = ResourceHelper .loadJson (vertx ,
84- Paths .get ("io/vertx/tests/contract/from_with_path_and_additional_files/components.json" ));
92+ Paths .get (SPLIT_CONTRACT_REFERENCE_PATH ));
8593 OpenAPIContract .builder (vertx )
86- .setContractPath ("io/vertx/tests/contract/from_with_path_and_additional_files/petstore.json" )
87- .putAdditionalContractPart ("https://example.com/petstore" , components )
94+ .setContractPath (SPLIT_CONTRACT_PATH )
95+ .putAdditionalContractPart (SPLIT_CONTRACT_REFERENCE_KEY , components )
8896 .build ()
8997 .onComplete (ctx .succeedingThenComplete ());
9098 }
@@ -122,6 +130,7 @@ void should_fail_when_contract_is_invalid(Vertx vertx, VertxTestContext ctx) {
122130 @ ExtendWith (VertxExtension .class )
123131 class TestSetupOfAdditionalContractParts {
124132
133+ private static final String CONTRACT_FILE = "io/vertx/tests/builder/contract.yaml" ;
125134 private static final String REF1_ID = "http://example.com/ref1" ;
126135 private static final String REF2_ID = "http://example.com/ref2" ;
127136 private static final String REF1_1_FILE = "io/vertx/tests/builder/ref1.1.yaml" ;
@@ -144,7 +153,7 @@ private JsonObject content(String path) {
144153 @ Test
145154 void set_additional_contract_part_should_override_existing_path (Vertx vertx ) {
146155 var c = OpenAPIContract .builder (vertx )
147- .setContractPath ("io/vertx/tests/builder/contract.yaml" )
156+ .setContractPath (CONTRACT_FILE )
148157 .putAdditionalContractPartPath (REF1_ID , REF1_1_FILE )
149158 .putAdditionalContractPartPath (REF2_ID , REF2_1_FILE )
150159 .setAdditionalContractParts (Map .of (REF1_ID , content (REF1_2_FILE )))
@@ -156,7 +165,7 @@ void set_additional_contract_part_should_override_existing_path(Vertx vertx) {
156165 @ Test
157166 void put_additional_contract_part_should_override_existing_path (Vertx vertx ) {
158167 var c = OpenAPIContract .builder (vertx )
159- .setContractPath ("io/vertx/tests/builder/contract.yaml" )
168+ .setContractPath (CONTRACT_FILE )
160169 .putAdditionalContractPartPath (REF1_ID , REF1_1_FILE )
161170 .putAdditionalContractPartPath (REF2_ID , REF2_1_FILE )
162171 .putAdditionalContractPart (REF1_ID , content (REF1_2_FILE ))
@@ -168,7 +177,7 @@ void put_additional_contract_part_should_override_existing_path(Vertx vertx) {
168177 @ Test
169178 void set_additional_contract_path_should_override_existing_contract_part (Vertx vertx ) {
170179 var c = OpenAPIContract .builder (vertx )
171- .setContractPath ("io/vertx/tests/builder/contract.yaml" )
180+ .setContractPath (CONTRACT_FILE )
172181 .putAdditionalContractPart (REF1_ID , content (REF1_1_FILE ))
173182 .putAdditionalContractPart (REF2_ID , content (REF2_1_FILE ))
174183 .setAdditionalContractPartPaths (Map .of (REF2_ID , REF2_2_FILE ))
@@ -180,7 +189,7 @@ void set_additional_contract_path_should_override_existing_contract_part(Vertx v
180189 @ Test
181190 void put_additional_contract_path_should_override_existing_additional_contract_part (Vertx vertx ) {
182191 var c = OpenAPIContract .builder (vertx )
183- .setContractPath ("io/vertx/tests/builder/contract.yaml" )
192+ .setContractPath (CONTRACT_FILE )
184193 .putAdditionalContractPart (REF1_ID , content (REF1_1_FILE ))
185194 .putAdditionalContractPart (REF2_ID , content (REF2_1_FILE ))
186195 .putAdditionalContractPartPath (REF2_ID , REF2_2_FILE )
@@ -201,7 +210,7 @@ private void should_have(OpenAPIContract contract, String requestDescription, St
201210 @ Test
202211 void set_additional_contract_parts_should_replace_existing_contract_part (Vertx vertx ) {
203212 var c = OpenAPIContract .builder (vertx )
204- .setContractPath ("io/vertx/tests/builder/contract.yaml" )
213+ .setContractPath (CONTRACT_FILE )
205214 .putAdditionalContractPart (REF1_ID , content (REF1_1_FILE ))
206215 .putAdditionalContractPart (REF2_ID , content (REF2_1_FILE ))
207216 .setAdditionalContractParts (Map .of (REF2_ID , content (REF2_2_FILE )))
@@ -213,7 +222,7 @@ void set_additional_contract_parts_should_replace_existing_contract_part(Vertx v
213222 @ Test
214223 void set_additional_contract_paths_should_replace_existing_contract_paths (Vertx vertx ) {
215224 var c = OpenAPIContract .builder (vertx )
216- .setContractPath ("io/vertx/tests/builder/contract.yaml" )
225+ .setContractPath (CONTRACT_FILE )
217226 .putAdditionalContractPartPath (REF1_ID , REF1_1_FILE )
218227 .putAdditionalContractPartPath (REF2_ID , REF2_1_FILE )
219228 .setAdditionalContractPartPaths (Map .of (REF2_ID , REF2_2_FILE ))
0 commit comments