@@ -54,6 +54,18 @@ public void appIdUrlIsConstructedWithIkeyFromIngestionEndpoint() {
5454 assertEquals (URI .create (host +"/" +EndpointProvider .API_PROFILES_APP_ID_URI_PREFIX +ikey +EndpointProvider .API_PROFILES_APP_ID_URI_SUFFIX ), ep .getAppIdEndpointURL (ikey ));
5555 }
5656
57+ @ Test
58+ public void appIdUrlWithPathKeepsIt () {
59+ EndpointProvider ep = new EndpointProvider ();
60+ String ikey = "fake-ikey" ;
61+ String url = "http://123.com/path/321" ;
62+ ep .setIngestionEndpoint (URI .create (url ));
63+ assertEquals (URI .create (url +"/" +EndpointProvider .API_PROFILES_APP_ID_URI_PREFIX +ikey +EndpointProvider .API_PROFILES_APP_ID_URI_SUFFIX ), ep .getAppIdEndpointURL (ikey ));
64+
65+ ep .setIngestionEndpoint (URI .create (url +"/" ));
66+ assertEquals (URI .create (url +"/" +EndpointProvider .API_PROFILES_APP_ID_URI_PREFIX +ikey +EndpointProvider .API_PROFILES_APP_ID_URI_SUFFIX ), ep .getAppIdEndpointURL (ikey ));
67+ }
68+
5769 @ Test
5870 public void ikeyWithSuffix () throws Exception {
5971 final String ikey = "fake-ikey" ;
@@ -70,6 +82,38 @@ public void ikeyWithSuffix() throws Exception {
7082 assertEquals (expectedLiveEndpoint , config .getEndpointProvider ().getLiveEndpointURL ());
7183 }
7284
85+ @ Test
86+ public void suffixWithPathRetainsThePath () throws Exception {
87+ final String ikey = "fake-ikey" ;
88+ final String suffix = "ai.example.com/my-proxy-app/doProxy" ;
89+ final String cs = "InstrumentationKey=" +ikey +";EndpointSuffix=" +suffix ;
90+ final URI expectedIngestionEndpoint = URI .create ("https://" +EndpointPrefixes .INGESTION_ENDPOINT_PREFIX +"." +suffix );
91+ final URI expectedIngestionEndpointURL = URI .create ("https://" +EndpointPrefixes .INGESTION_ENDPOINT_PREFIX +"." +suffix + "/" + EndpointProvider .INGESTION_URI_PATH );
92+ final URI expectedLiveEndpoint = URI .create ("https://" +EndpointPrefixes .LIVE_ENDPOINT_PREFIX +"." +suffix + "/" + EndpointProvider .LIVE_URI_PATH );
93+
94+ ConnectionString .parseInto (cs , config );
95+ assertEquals (ikey , config .getInstrumentationKey ());
96+ assertEquals (expectedIngestionEndpoint , config .getEndpointProvider ().getIngestionEndpoint ());
97+ assertEquals (expectedIngestionEndpointURL , config .getEndpointProvider ().getIngestionEndpointURL ());
98+ assertEquals (expectedLiveEndpoint , config .getEndpointProvider ().getLiveEndpointURL ());
99+ }
100+
101+ @ Test
102+ public void suffixSupportsPort () throws Exception {
103+ final String ikey = "fake-ikey" ;
104+ final String suffix = "ai.example.com:9999" ;
105+ final String cs = "InstrumentationKey=" +ikey +";EndpointSuffix=" +suffix ;
106+ final URI expectedIngestionEndpoint = URI .create ("https://" +EndpointPrefixes .INGESTION_ENDPOINT_PREFIX +"." +suffix );
107+ final URI expectedIngestionEndpointURL = URI .create ("https://" +EndpointPrefixes .INGESTION_ENDPOINT_PREFIX +"." +suffix + "/" + EndpointProvider .INGESTION_URI_PATH );
108+ final URI expectedLiveEndpoint = URI .create ("https://" +EndpointPrefixes .LIVE_ENDPOINT_PREFIX +"." +suffix + "/" + EndpointProvider .LIVE_URI_PATH );
109+
110+ ConnectionString .parseInto (cs , config );
111+ assertEquals (ikey , config .getInstrumentationKey ());
112+ assertEquals (expectedIngestionEndpoint , config .getEndpointProvider ().getIngestionEndpoint ());
113+ assertEquals (expectedIngestionEndpointURL , config .getEndpointProvider ().getIngestionEndpointURL ());
114+ assertEquals (expectedLiveEndpoint , config .getEndpointProvider ().getLiveEndpointURL ());
115+ }
116+
73117 @ Test
74118 public void ikeyWithExplicitEndpoints () throws Exception {
75119 final String ikey = "fake-ikey" ;
@@ -197,15 +241,30 @@ public void orderDoesNotMatter() throws Exception {
197241 }
198242
199243 @ Test
200- public void endpointWithNoSchemeIsHttps () throws Exception {
244+ public void endpointWithNoSchemeIsInvalid () throws Exception {
245+ exception .expect (InvalidConnectionStringException .class );
246+ exception .expectMessage (containsString ("IngestionEndpoint" ));
201247 ConnectionString .parseInto ("InstrumentationKey=fake-ikey;IngestionEndpoint=my-ai.example.com" , config );
202- assertEquals ("https" , config .getEndpointProvider ().getIngestionEndpoint ().getScheme ());
248+ }
249+
250+ @ Test
251+ public void endpointWithPathMissingSchemeIsInvalid () throws Exception {
252+ exception .expect (InvalidConnectionStringException .class );
253+ exception .expectMessage (containsString ("IngestionEndpoint" ));
254+ ConnectionString .parseInto ("InstrumentationKey=fake-ikey;IngestionEndpoint=my-ai.example.com/path/prefix" , config );
255+ }
256+
257+ @ Test
258+ public void endpointWithPortMissingSchemeIsInvalid () throws Exception {
259+ exception .expect (InvalidConnectionStringException .class );
260+ exception .expectMessage (containsString ("IngestionEndpoint" ));
261+ ConnectionString .parseInto ("InstrumentationKey=fake-ikey;IngestionEndpoint=my-ai.example.com:9999" , config );
203262 }
204263
205264 @ Test
206265 public void httpEndpointKeepsScheme () throws Exception {
207266 ConnectionString .parseInto ("InstrumentationKey=fake-ikey;IngestionEndpoint=http://my-ai.example.com" , config );
208- assertEquals ("http" , config .getEndpointProvider ().getIngestionEndpoint (). getScheme ());
267+ assertEquals (URI . create ( "http://my-ai.example.com" ) , config .getEndpointProvider ().getIngestionEndpoint ());
209268 }
210269
211270 @ Test
0 commit comments