1+ // Comments are in English as requested
12package es .in2 .vcverifier .oid4vp .controller ;
23
34import es .in2 .vcverifier .config .FrontendConfig ;
910import org .mockito .junit .jupiter .MockitoExtension ;
1011import org .springframework .ui .Model ;
1112
13+ import java .util .Locale ;
14+
1215import static org .junit .jupiter .api .Assertions .assertEquals ;
1316import static org .mockito .Mockito .*;
1417
@@ -31,86 +34,95 @@ class ClientErrorControllerTest {
3134 private static final String FAVICON_SRC = "faviconSrcValue" ;
3235 private static final String DEFAULT_LANG = "en" ;
3336
34- //todo
35- // @Test
36- // void showErrorPage_withValidParameters_shouldReturnViewNameAndAddAttributesToModel() {
37- // // Arrange
38- // String errorCode = "ERROR_CODE_123";
39- // String errorMessage = "An error occurred during client authentication.";
40- // String clientUrl = "https://client.example.com";
41- // String supportUri = "https://support.example.com";
42- // String originalRequestURL = "https://original.example.com";
43- //
44- //
45- // when(frontendConfig.getSupportUrl()).thenReturn(supportUri);
46- // when(frontendConfig.getPrimaryColor()).thenReturn(PRIMARY_COLOR);
47- // when(frontendConfig.getPrimaryContrastColor()).thenReturn(PRIMARY_CONTRAST_COLOR);
48- // when(frontendConfig.getSecondaryColor()).thenReturn(SECONDARY_COLOR);
49- // when(frontendConfig.getSecondaryContrastColor()).thenReturn(SECONDARY_CONTRAST_COLOR);
50- // when(frontendConfig.getFaviconSrc()).thenReturn(FAVICON_SRC);
51- // when(frontendConfig.getDefaultLang()).thenReturn(DEFAULT_LANG);
52- //
53- // // Act
54- // String viewName = clientErrorController.showErrorPage(errorCode, errorMessage, clientUrl, originalRequestURL ,model);
55- //
56- // // Assert
57- // assertEquals("client-authentication-error-en", viewName);
58- //
59- // verify(model).addAttribute("errorCode", errorCode);
60- // verify(model).addAttribute("errorMessage", errorMessage);
61- // verify(model).addAttribute("clientUrl", clientUrl);
62- // verify(model).addAttribute("supportUri", supportUri);
63- // verify(model).addAttribute("originalRequestURL", originalRequestURL);
64- // verify(model).addAttribute("primary", PRIMARY_COLOR);
65- // verify(model).addAttribute("primaryContrast", PRIMARY_CONTRAST_COLOR);
66- // verify(model).addAttribute("secondary", SECONDARY_COLOR);
67- // verify(model).addAttribute("secondaryContrast", SECONDARY_CONTRAST_COLOR);
68- // verify(model).addAttribute("faviconSrc", FAVICON_SRC);
69- //
70- // }
71- //
72- // @Test
73- // void showErrorPage_withNullSupportUri_shouldAddNullSupportUriToModel() {
74- // // Arrange
75- // String errorCode = "ERROR_CODE_456";
76- // String errorMessage = "Another error occurred.";
77- // String clientUrl = "https://client.example.com";
78- // String originalRequestURL = "https://original.example.com";
79- // when(frontendConfig.getSupportUrl()).thenReturn(null);
80- // when(frontendConfig.getDefaultLang()).thenReturn(DEFAULT_LANG);
81- //
82- // // Act
83- // String viewName = clientErrorController.showErrorPage(errorCode, errorMessage, clientUrl, originalRequestURL, model);
84- //
85- // // Assert
86- // assertEquals("client-authentication-error-en", viewName);
87- //
88- // verify(model).addAttribute("errorCode", errorCode);
89- // verify(model).addAttribute("errorMessage", errorMessage);
90- // verify(model).addAttribute("clientUrl", clientUrl);
91- // verify(model).addAttribute("supportUri", null);
92- // verify(model).addAttribute("originalRequestURL", originalRequestURL);
93- // }
94- //
95- // @Test
96- // void showErrorPage_withNullParameters_shouldAddNullValuesToModel() {
97- // // Arrange
98- // String supportUri = "https://support.example.com";
99- //
100- // when(frontendConfig.getSupportUrl()).thenReturn(supportUri);
101- // when(frontendConfig.getDefaultLang()).thenReturn(DEFAULT_LANG);
102- //
103- // // Act
104- // String viewName = clientErrorController.showErrorPage(null, null, null, null,model);
105- //
106- // // Assert
107- // assertEquals("client-authentication-error-en", viewName);
108- //
109- // verify(model).addAttribute("errorCode", null);
110- // verify(model).addAttribute("errorMessage", null);
111- // verify(model).addAttribute("clientUrl", null);
112- // verify(model).addAttribute("originalRequestURL", null);
113- // verify(model).addAttribute("supportUri", supportUri);
114- // }
115- }
37+ @ Test
38+ void showErrorPage_withValidParameters_shouldReturnViewNameAndAddAttributesToModel () {
39+ // Arrange
40+ String errorCode = "ERROR_CODE_123" ;
41+ String errorMessage = "An error occurred during client authentication." ;
42+ String clientUrl = "https://client.example.com" ;
43+ String supportUri = "https://support.example.com" ;
44+ String originalRequestURL = "https://original.example.com" ;
45+ Locale locale = Locale .forLanguageTag ("es" ); // not used by controller, fallback uses defaultLang
46+
47+ when (frontendConfig .getSupportUrl ()).thenReturn (supportUri );
48+ when (frontendConfig .getPrimaryColor ()).thenReturn (PRIMARY_COLOR );
49+ when (frontendConfig .getPrimaryContrastColor ()).thenReturn (PRIMARY_CONTRAST_COLOR );
50+ when (frontendConfig .getSecondaryColor ()).thenReturn (SECONDARY_COLOR );
51+ when (frontendConfig .getSecondaryContrastColor ()).thenReturn (SECONDARY_CONTRAST_COLOR );
52+ when (frontendConfig .getFaviconSrc ()).thenReturn (FAVICON_SRC );
53+ when (frontendConfig .getDefaultLang ()).thenReturn (DEFAULT_LANG );
54+
55+ // Act
56+ String viewName = clientErrorController .showErrorPage (
57+ errorCode , errorMessage , clientUrl , originalRequestURL , locale , model
58+ );
59+
60+ // Assert
61+ assertEquals ("client-authentication-error-en" , viewName );
62+
63+ verify (model ).addAttribute ("errorCode" , errorCode );
64+ verify (model ).addAttribute ("errorMessage" , errorMessage );
65+ verify (model ).addAttribute ("clientUrl" , clientUrl );
66+ verify (model ).addAttribute ("supportUri" , supportUri );
67+ verify (model ).addAttribute ("originalRequestURL" , originalRequestURL );
68+
69+ verify (model ).addAttribute ("primary" , PRIMARY_COLOR );
70+ verify (model ).addAttribute ("primaryContrast" , PRIMARY_CONTRAST_COLOR );
71+ verify (model ).addAttribute ("secondary" , SECONDARY_COLOR );
72+ verify (model ).addAttribute ("secondaryContrast" , SECONDARY_CONTRAST_COLOR );
73+ verify (model ).addAttribute ("faviconSrc" , FAVICON_SRC );
74+
75+ verifyNoMoreInteractions (model );
76+ }
77+
78+ @ Test
79+ void showErrorPage_withNullSupportUri_shouldAddNullSupportUriToModel () {
80+ // Arrange
81+ String errorCode = "ERROR_CODE_456" ;
82+ String errorMessage = "Another error occurred." ;
83+ String clientUrl = "https://client.example.com" ;
84+ String originalRequestURL = "https://original.example.com" ;
85+ Locale locale = Locale .forLanguageTag ("en" );
11686
87+ when (frontendConfig .getSupportUrl ()).thenReturn (null );
88+ when (frontendConfig .getDefaultLang ()).thenReturn (DEFAULT_LANG );
89+
90+ // Act
91+ String viewName = clientErrorController .showErrorPage (
92+ errorCode , errorMessage , clientUrl , originalRequestURL , locale , model
93+ );
94+
95+ // Assert
96+ assertEquals ("client-authentication-error-en" , viewName );
97+
98+ verify (model ).addAttribute ("errorCode" , errorCode );
99+ verify (model ).addAttribute ("errorMessage" , errorMessage );
100+ verify (model ).addAttribute ("clientUrl" , clientUrl );
101+ verify (model ).addAttribute ("supportUri" , null );
102+ verify (model ).addAttribute ("originalRequestURL" , originalRequestURL );
103+ }
104+
105+ @ Test
106+ void showErrorPage_withNullParameters_shouldAddNullValuesToModel () {
107+ // Arrange
108+ String supportUri = "https://support.example.com" ;
109+ Locale locale = Locale .forLanguageTag ("fr" );
110+
111+ when (frontendConfig .getSupportUrl ()).thenReturn (supportUri );
112+ when (frontendConfig .getDefaultLang ()).thenReturn (DEFAULT_LANG );
113+
114+ // Act
115+ String viewName = clientErrorController .showErrorPage (
116+ null , null , null , null , locale , model
117+ );
118+
119+ // Assert
120+ assertEquals ("client-authentication-error-en" , viewName );
121+
122+ verify (model ).addAttribute ("errorCode" , null );
123+ verify (model ).addAttribute ("errorMessage" , null );
124+ verify (model ).addAttribute ("clientUrl" , null );
125+ verify (model ).addAttribute ("originalRequestURL" , null );
126+ verify (model ).addAttribute ("supportUri" , supportUri );
127+ }
128+ }
0 commit comments