1616
1717package de .codecentric .boot .admin .server .domain .values ;
1818
19+ import org .assertj .core .api .WithAssertions ;
1920import org .junit .jupiter .api .Test ;
2021
2122import static org .assertj .core .api .Assertions .assertThatThrownBy ;
2223
23- class RegistrationTest {
24+ class RegistrationTest implements WithAssertions {
2425
2526 @ Test
2627 void invariants () {
@@ -43,4 +44,57 @@ void invariants() {
4344 .hasMessage ("'serviceUrl' is not valid: invalid" );
4445 }
4546
47+ @ Test
48+ void returnsNull_whenServiceUrlIsNull_evenIfMetadataHasOverride () {
49+ Registration reg = Registration .builder ()
50+ .name ("app" )
51+ .healthUrl ("https://example.com/actuator/health" )
52+ .metadata ("service-url" , "https://override.example.com" )
53+ .build ();
54+
55+ assertThat (reg .getServiceUrl ()).isNull ();
56+ }
57+
58+ @ Test
59+ void usesMetadataOverride_whenValidAbsoluteUrlProvided () {
60+ Registration reg = Registration .create ("app" , "https://example.com/actuator/health" )
61+ .serviceUrl ("https://base.example.com" )
62+ .metadata ("service-url" , "https://override.example.com" )
63+ .build ();
64+
65+ assertThat (reg .getServiceUrl ()).isEqualTo ("https://override.example.com" );
66+ }
67+
68+ @ Test
69+ void fallsBackToOriginal_whenMetadataOverrideIsInvalidSyntax () {
70+ Registration reg = Registration .create ("app" , "https://example.com/actuator/health" )
71+ .serviceUrl ("https://base.example.com" )
72+ .metadata ("service-url" , "http://exa mple.com" ) // invalide URI (Leerzeichen)
73+ .build ();
74+
75+ assertThat (reg .getServiceUrl ()).isEqualTo ("https://base.example.com" );
76+ }
77+
78+ @ Test
79+ void keepsOriginal_whenNoMetadataOverridePresent () {
80+ Registration reg = Registration .create ("app" , "https://example.com/actuator/health" )
81+ .serviceUrl ("https://base.example.com" )
82+ .metadata ("other" , "value" )
83+ .build ();
84+
85+ assertThat (reg .getServiceUrl ()).isEqualTo ("https://base.example.com" );
86+ }
87+
88+ @ Test
89+ void acceptsEmptyStringFromMetadata_evenThoughItIsRelative () {
90+ Registration reg = Registration .create ("app" , "https://example.com/actuator/health" )
91+ .serviceUrl ("https://base.example.com" )
92+ .metadata ("service-url" , "" )
93+ .build ();
94+
95+ // new URI("") erzeugt eine relative, aber syntaktisch valide URI -> Methode gibt
96+ // "" zurück
97+ assertThat (reg .getServiceUrl ()).isEqualTo ("" );
98+ }
99+
46100}
0 commit comments