@@ -37,10 +37,7 @@ void fileIsAcceptedTrue() {
3737 @ Test
3838 @ DisplayName ("AsyncApi: Check if a contract is returned" )
3939 void convertFromTest () {
40- Collection <Contract > contracts ;
41- File file = new File (asyncApiContractConverterTestFixtures .EVENT_API_FILE );
42- contracts = multiApiContractConverter .convertFrom (file );
43- List <Contract > contractList = new ArrayList <>(contracts );
40+ List <Contract > contractList = getContracts (asyncApiContractConverterTestFixtures .EVENT_API_FILE );
4441
4542 assertThat (contractList ).hasSize (2 );
4643
@@ -60,9 +57,7 @@ void convertFromTest() {
6057 @ Test
6158 @ DisplayName ("AsyncApi: Check if Input is being processed okay" )
6259 void testInput () {
63- File file = new File (asyncApiContractConverterTestFixtures .EVENT_API_FILE );
64- Collection <Contract > contracts = multiApiContractConverter .convertFrom (file );
65- ArrayList <Contract > contractList = new ArrayList <>(contracts );
60+ List <Contract > contractList = getContracts (asyncApiContractConverterTestFixtures .EVENT_API_FILE );
6661 Map <String , Object > order = asyncApiContractConverterTestFixtures .createOrder ();
6762
6863 Contract publishContract = contractList .get (0 );
@@ -79,9 +74,7 @@ void testInput() {
7974 @ Test
8075 @ DisplayName ("AsyncApi: Check if OutputMessage is being processed okay" )
8176 void testOutputMessage () {
82- File file = new File (asyncApiContractConverterTestFixtures .EVENT_API_FILE );
83- Collection <Contract > contracts = multiApiContractConverter .convertFrom (file );
84- ArrayList <Contract > contractList = new ArrayList <>(contracts );
77+ List <Contract > contractList = getContracts (asyncApiContractConverterTestFixtures .EVENT_API_FILE );
8578 Map <String , Object > order = asyncApiContractConverterTestFixtures .createOrder ();
8679
8780 Contract publishContract = contractList .get (0 );
@@ -105,9 +98,7 @@ void testOutputMessage() {
10598 @ Test
10699 @ DisplayName ("AsyncApi: Check if the enum logic is being processed okay" )
107100 void testEnums () {
108- File file = new File (asyncApiContractConverterTestFixtures .TEST_ENUMS_FILE );
109- Collection <Contract > contracts = multiApiContractConverter .convertFrom (file );
110- ArrayList <Contract > contractList = new ArrayList <>(contracts );
101+ List <Contract > contractList = getContracts (asyncApiContractConverterTestFixtures .TEST_ENUMS_FILE );
111102
112103 for (int i = 0 ; i < contractList .size (); i ++) {
113104 Contract contract = contractList .get (i );
@@ -128,9 +119,7 @@ void testEnums() {
128119 @ Test
129120 @ DisplayName ("AsyncApi: Check if complex objects are being processed okay" )
130121 void testComplexObjects () {
131- File file = new File (asyncApiContractConverterTestFixtures .TEST_COMPLEX_OBJECTS_FILE );
132- Collection <Contract > contracts = multiApiContractConverter .convertFrom (file );
133- ArrayList <Contract > contractList = new ArrayList <>(contracts );
122+ List <Contract > contractList = getContracts (asyncApiContractConverterTestFixtures .TEST_COMPLEX_OBJECTS_FILE );
134123
135124 for (int i = 0 ; i < contractList .size (); i ++) {
136125 Contract contract = contractList .get (i );
@@ -150,17 +139,15 @@ void testComplexObjects() {
150139 } else {
151140 assertThat (nameValue ).containsEntry (asyncApiContractConverterTestFixtures .COMPANY_NAME , asyncApiContractConverterTestFixtures .CORUNET );
152141 assertThat (nameValue ).containsEntry (asyncApiContractConverterTestFixtures .REFERENCE_NAME , 3324 );
153- assertThat (addressValue ).containsEntry (asyncApiContractConverterTestFixtures .STREET , "Calle Sor Joaquina" );
142+ assertThat (addressValue ).containsEntry (asyncApiContractConverterTestFixtures .STREET , asyncApiContractConverterTestFixtures . STREET_VALUE );
154143 }
155144 }
156145 }
157146
158147 @ Test
159148 @ DisplayName ("AsyncApi: Check if arrays are being processed okay" )
160149 void testArrays () {
161- File file = new File (asyncApiContractConverterTestFixtures .TEST_ARRAYS_FILE );
162- Collection <Contract > contracts = multiApiContractConverter .convertFrom (file );
163- ArrayList <Contract > contractList = new ArrayList <>(contracts );
150+ List <Contract > contractList = getContracts (asyncApiContractConverterTestFixtures .TEST_ARRAYS_FILE );
164151
165152 for (int i = 0 ; i < contractList .size (); i ++) {
166153 Contract contract = contractList .get (i );
@@ -189,9 +176,7 @@ void testArrays() {
189176 @ Test
190177 @ DisplayName ("AsyncApi: Check if arrays with reference to an object are being processed okay" )
191178 void testArraysWithRef () {
192- File file = new File (asyncApiContractConverterTestFixtures .TEST_ARRAYS_REF_FILE );
193- Collection <Contract > contracts = multiApiContractConverter .convertFrom (file );
194- ArrayList <Contract > contractList = new ArrayList <>(contracts );
179+ List <Contract > contractList = getContracts (asyncApiContractConverterTestFixtures .TEST_ARRAYS_REF_FILE );
195180
196181 for (int i = 0 ; i < contractList .size (); i ++) {
197182 Contract contract = contractList .get (i );
@@ -215,9 +200,7 @@ void testArraysWithRef() {
215200 @ Test
216201 @ DisplayName ("AsyncApi: Check if basic types are being processed okay" )
217202 void testBasicTypes () {
218- File file = new File (asyncApiContractConverterTestFixtures .TEST_BASIC_TYPES_FILE );
219- Collection <Contract > contracts = multiApiContractConverter .convertFrom (file );
220- ArrayList <Contract > contractList = new ArrayList <>(contracts );
203+ List <Contract > contractList = getContracts (asyncApiContractConverterTestFixtures .TEST_BASIC_TYPES_FILE );
221204
222205 for (int i = 0 ; i < contractList .size (); i ++) {
223206 Contract contract = contractList .get (i );
@@ -244,7 +227,62 @@ void testBasicTypes() {
244227 assertThat (orderValue ).containsEntry (asyncApiContractConverterTestFixtures .BOOLEAN_TYPE , true );
245228 }
246229 }
230+ }
231+
232+ @ Test
233+ @ DisplayName ("AsyncApi: Check if references to external files work correctly" )
234+ void testExternalFiles () {
235+ List <Contract > contractList = getContracts (asyncApiContractConverterTestFixtures .TEST_EXTERNAL_FILE );
236+
237+ for (int i = 0 ; i < contractList .size (); i ++) {
238+ Contract contract = contractList .get (i );
239+
240+ Map <String , Object > bodyValue = (Map <String , Object >) contract .getOutputMessage ().getBody ().getClientValue ();
241+ assertThat (bodyValue .get (asyncApiContractConverterTestFixtures .ORDER )).isNotNull ();
242+ Map <String , Object > orderValue = (Map <String , Object >) bodyValue .get (asyncApiContractConverterTestFixtures .ORDER );
243+ List <Integer > amount = (ArrayList <Integer >) orderValue .get (asyncApiContractConverterTestFixtures .AMOUNT );
244+
245+ if (i == 0 ) {
246+ assertThat (orderValue .get (asyncApiContractConverterTestFixtures .COMPANY_NAME )).isNotNull ().isInstanceOf (String .class );
247+ assertThat (orderValue .get (asyncApiContractConverterTestFixtures .IS_SENT )).isNotNull ().isInstanceOf (Boolean .class );
248+ assertThat (amount ).isNotNull ().isInstanceOf (ArrayList .class );
249+ } else {
250+ assertThat (orderValue ).containsEntry (asyncApiContractConverterTestFixtures .COMPANY_NAME , asyncApiContractConverterTestFixtures .CORUNET );
251+ assertThat (orderValue ).containsEntry (asyncApiContractConverterTestFixtures .IS_SENT , true );
252+ assertThat (amount ).isEqualTo (asyncApiContractConverterTestFixtures .INT_ARRAY_VALUES );
253+ }
254+ }
255+ }
256+
257+ @ Test
258+ @ DisplayName ("AsyncApi: Check if references to external files work correctly with multiple schemas" )
259+ void testExternalFilesWithMultipleSchemas () {
260+ List <Contract > contractList = getContracts (asyncApiContractConverterTestFixtures .TEST_EXTERNAL_FILE_MULTIPLE_SCHEMAS );
261+
262+ for (int i = 0 ; i < contractList .size (); i ++) {
263+ Contract contract = contractList .get (i );
247264
265+ Map <String , Object > bodyValue = (Map <String , Object >) contract .getOutputMessage ().getBody ().getClientValue ();
266+ assertThat (bodyValue .get (asyncApiContractConverterTestFixtures .ORDERS )).isNotNull ();
267+ Map <String , Object > ordersValue = (Map <String , Object >) bodyValue .get (asyncApiContractConverterTestFixtures .ORDERS );
268+ assertThat (ordersValue .get (asyncApiContractConverterTestFixtures .ORDER_LINE )).isNotNull ();
269+ Map <String , Object > orderLineValue = (Map <String , Object >) ordersValue .get (asyncApiContractConverterTestFixtures .ORDER_LINE );
270+ assertThat (orderLineValue .get (asyncApiContractConverterTestFixtures .ORDER )).isNotNull ();
271+ Map <String , Object > orderValue = (Map <String , Object >) orderLineValue .get (asyncApiContractConverterTestFixtures .ORDER );
272+
273+ if (i == 0 ) {
274+ assertThat (orderValue .get (asyncApiContractConverterTestFixtures .COMPANY_NAME )).isNotNull ().isInstanceOf (String .class );
275+ } else {
276+ assertThat (orderValue ).containsEntry (asyncApiContractConverterTestFixtures .COMPANY_NAME , asyncApiContractConverterTestFixtures .CORUNET );
277+ }
278+ }
279+ }
280+
281+ private List <Contract > getContracts (String filePath ) {
282+ File file = new File (filePath );
283+ Collection <Contract > contracts = multiApiContractConverter .convertFrom (file );
284+ List <Contract > contractList = new ArrayList <>(contracts );
285+ return contractList ;
248286 }
249287
250288}
0 commit comments