1515 */
1616package com .hubsante .hub .config ;
1717
18+ import static org .assertj .core .api .Assertions .assertThat ;
19+
1820import java .io .File ;
1921import java .io .FileWriter ;
2022import java .nio .charset .StandardCharsets ;
2123import java .util .List ;
22- import org .junit .jupiter .api .Assertions ;
2324import org .junit .jupiter .api .BeforeEach ;
2425import org .junit .jupiter .api .DisplayName ;
25- import org .junit .jupiter .api .Test ;
26+ import org .junit .jupiter .params .ParameterizedTest ;
27+ import org .junit .jupiter .params .provider .CsvSource ;
2628import org .springframework .test .util .ReflectionTestUtils ;
2729
2830public class HubConfigurationTest {
31+
2932 private HubConfiguration hubConfig ;
3033
3134 @ BeforeEach
@@ -43,37 +46,18 @@ void setUp() throws Exception {
4346 ReflectionTestUtils .setField (hubConfig , "supportedMessagesFile" , tempFile );
4447 }
4548
46- @ Test
47- @ DisplayName ("should load the common messages and the messages specific to the vhost" )
48- void shouldLoadCommonAndVhostSpecificMessages () throws Exception {
49- List <String > supportedMessages = hubConfig .loadSupportedMessages ("host_1" );
50-
51- Assertions .assertEquals (4 , supportedMessages .size ());
52- Assertions .assertTrue (supportedMessages .contains ("ReferenceWrapper" ));
53- Assertions .assertTrue (supportedMessages .contains ("ErrorWrapper" ));
54- Assertions .assertTrue (supportedMessages .contains ("type1" ));
55- Assertions .assertTrue (supportedMessages .contains ("type2" ));
56- }
57-
58- @ Test
59- @ DisplayName ("should load a different message list for a different vhost" )
60- void shouldLoadMessagesForAnotherVhost () throws Exception {
61- List <String > supportedMessages = hubConfig .loadSupportedMessages ("host_2" );
62-
63- Assertions .assertEquals (4 , supportedMessages .size ());
64- Assertions .assertTrue (supportedMessages .contains ("ReferenceWrapper" ));
65- Assertions .assertTrue (supportedMessages .contains ("ErrorWrapper" ));
66- Assertions .assertTrue (supportedMessages .contains ("type1" ));
67- Assertions .assertTrue (supportedMessages .contains ("type3" ));
68- }
69-
70- @ Test
71- @ DisplayName ("should fall back to the common messages only for an unknown vhost" )
72- void shouldLoadCommonMessagesOnlyForUnknownVhost () throws Exception {
73- List <String > supportedMessages = hubConfig .loadSupportedMessages ("unknown" );
74-
75- Assertions .assertEquals (2 , supportedMessages .size ());
76- Assertions .assertTrue (supportedMessages .contains ("ReferenceWrapper" ));
77- Assertions .assertTrue (supportedMessages .contains ("ErrorWrapper" ));
49+ @ ParameterizedTest (name = "vhost {0} supports {1}" )
50+ @ CsvSource ({
51+ "host_1, 'ReferenceWrapper,ErrorWrapper,type1,type2'" ,
52+ "host_2, 'ReferenceWrapper,ErrorWrapper,type1,type3'" ,
53+ "unknown, 'ReferenceWrapper,ErrorWrapper'" ,
54+ })
55+ @ DisplayName ("should load the common messages plus the ones specific to the vhost" )
56+ void shouldLoadSupportedMessages (String vhost , String expected ) throws Exception {
57+ List <String > supportedMessages = hubConfig .loadSupportedMessages (vhost );
58+
59+ assertThat (supportedMessages )
60+ .as ("messages supported on vhost %s" , vhost )
61+ .containsExactlyInAnyOrder (expected .split ("," ));
7862 }
7963}
0 commit comments