1717 */
1818public class CustomURLPathTest {
1919
20- @ Test (groups = {"unit" })
21- public void testCustomURLPathConfiguration () {
22- String customPath = "/sales/db" ;
23-
24- // Simulate the URL building logic from HttpAPIClientHelper
25- String baseURL = "http://localhost:8123" ;
20+ /**
21+ * Helper method to build URI with custom path, simulating the logic from HttpAPIClientHelper.
22+ */
23+ private URI buildURIWithCustomPath (String baseURL , String customPath ) throws URISyntaxException {
2624 Map <String , Object > requestConfig = new HashMap <>();
27- requestConfig .put (ClientConfigProperties .CUSTOM_URL_PATH .getKey (), customPath );
25+ if (customPath != null ) {
26+ requestConfig .put (ClientConfigProperties .CUSTOM_URL_PATH .getKey (), customPath );
27+ }
2828
29- try {
30- URIBuilder uriBuilder = new URIBuilder (baseURL );
31-
32- // Add custom URL path if configured
33- String configuredPath = (String ) requestConfig .get (ClientConfigProperties .CUSTOM_URL_PATH .getKey ());
34- if (configuredPath != null && !configuredPath .isEmpty ()) {
35- String existingPath = uriBuilder .getPath ();
36- if (existingPath == null || existingPath .isEmpty () || existingPath .equals ("/" )) {
37- uriBuilder .setPath (configuredPath );
38- } else {
39- uriBuilder .setPath (existingPath + configuredPath );
40- }
29+ URIBuilder uriBuilder = new URIBuilder (baseURL );
30+
31+ // Add custom URL path if configured
32+ String configuredPath = (String ) requestConfig .get (ClientConfigProperties .CUSTOM_URL_PATH .getKey ());
33+ if (configuredPath != null && !configuredPath .isEmpty ()) {
34+ String existingPath = uriBuilder .getPath ();
35+ if (existingPath == null || existingPath .isEmpty () || existingPath .equals ("/" )) {
36+ uriBuilder .setPath (configuredPath );
37+ } else {
38+ uriBuilder .setPath (existingPath + configuredPath );
4139 }
42-
43- URI uri = uriBuilder .normalizeSyntax ().build ();
40+ }
41+
42+ return uriBuilder .normalizeSyntax ().build ();
43+ }
44+
45+ @ Test (groups = {"unit" })
46+ public void testCustomURLPathConfiguration () {
47+ try {
48+ URI uri = buildURIWithCustomPath ("http://localhost:8123" , "/sales/db" );
4449
4550 assertEquals (uri .toString (), "http://localhost:8123/sales/db" );
4651 assertEquals (uri .getPath (), "/sales/db" );
@@ -51,28 +56,8 @@ public void testCustomURLPathConfiguration() {
5156
5257 @ Test (groups = {"unit" })
5358 public void testCustomURLPathWithExistingPath () {
54- String customPath = "/app/db" ;
55-
56- // Test with base URL that already has a path
57- String baseURL = "http://localhost:8123/api" ;
58- Map <String , Object > requestConfig = new HashMap <>();
59- requestConfig .put (ClientConfigProperties .CUSTOM_URL_PATH .getKey (), customPath );
60-
6159 try {
62- URIBuilder uriBuilder = new URIBuilder (baseURL );
63-
64- // Add custom URL path if configured
65- String configuredPath = (String ) requestConfig .get (ClientConfigProperties .CUSTOM_URL_PATH .getKey ());
66- if (configuredPath != null && !configuredPath .isEmpty ()) {
67- String existingPath = uriBuilder .getPath ();
68- if (existingPath == null || existingPath .isEmpty () || existingPath .equals ("/" )) {
69- uriBuilder .setPath (configuredPath );
70- } else {
71- uriBuilder .setPath (existingPath + configuredPath );
72- }
73- }
74-
75- URI uri = uriBuilder .normalizeSyntax ().build ();
60+ URI uri = buildURIWithCustomPath ("http://localhost:8123/api" , "/app/db" );
7661
7762 assertEquals (uri .toString (), "http://localhost:8123/api/app/db" );
7863 assertEquals (uri .getPath (), "/api/app/db" );
@@ -83,26 +68,8 @@ public void testCustomURLPathWithExistingPath() {
8368
8469 @ Test (groups = {"unit" })
8570 public void testEmptyCustomURLPath () {
86- // Test with empty custom path
87- String baseURL = "http://localhost:8123" ;
88- Map <String , Object > requestConfig = new HashMap <>();
89- requestConfig .put (ClientConfigProperties .CUSTOM_URL_PATH .getKey (), "" );
90-
9171 try {
92- URIBuilder uriBuilder = new URIBuilder (baseURL );
93-
94- // Add custom URL path if configured
95- String configuredPath = (String ) requestConfig .get (ClientConfigProperties .CUSTOM_URL_PATH .getKey ());
96- if (configuredPath != null && !configuredPath .isEmpty ()) {
97- String existingPath = uriBuilder .getPath ();
98- if (existingPath == null || existingPath .isEmpty () || existingPath .equals ("/" )) {
99- uriBuilder .setPath (configuredPath );
100- } else {
101- uriBuilder .setPath (existingPath + configuredPath );
102- }
103- }
104-
105- URI uri = uriBuilder .normalizeSyntax ().build ();
72+ URI uri = buildURIWithCustomPath ("http://localhost:8123" , "" );
10673
10774 // Empty path should not modify the URL
10875 assertEquals (uri .toString (), "http://localhost:8123" );
@@ -113,25 +80,8 @@ public void testEmptyCustomURLPath() {
11380
11481 @ Test (groups = {"unit" })
11582 public void testNoCustomURLPath () {
116- // Test without custom path configured
117- String baseURL = "http://localhost:8123" ;
118- Map <String , Object > requestConfig = new HashMap <>();
119-
12083 try {
121- URIBuilder uriBuilder = new URIBuilder (baseURL );
122-
123- // Add custom URL path if configured
124- String configuredPath = (String ) requestConfig .get (ClientConfigProperties .CUSTOM_URL_PATH .getKey ());
125- if (configuredPath != null && !configuredPath .isEmpty ()) {
126- String existingPath = uriBuilder .getPath ();
127- if (existingPath == null || existingPath .isEmpty () || existingPath .equals ("/" )) {
128- uriBuilder .setPath (configuredPath );
129- } else {
130- uriBuilder .setPath (existingPath + configuredPath );
131- }
132- }
133-
134- URI uri = uriBuilder .normalizeSyntax ().build ();
84+ URI uri = buildURIWithCustomPath ("http://localhost:8123" , null );
13585
13686 // No custom path should keep URL unchanged
13787 assertEquals (uri .toString (), "http://localhost:8123" );
0 commit comments