Skip to content

Commit 2234a3c

Browse files
author
Bilal Al
committed
polish
1 parent fa8de3f commit 2234a3c

File tree

3 files changed

+32
-12
lines changed

3 files changed

+32
-12
lines changed

client/src/main/java/io/split/client/SplitClientConfig.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@
1010
import pluggable.CustomStorageWrapper;
1111

1212
import java.io.IOException;
13-
import java.util.*;
13+
import java.util.HashSet;
14+
import java.util.LinkedHashSet;
15+
import java.util.List;
16+
import java.util.Properties;
1417
import java.util.concurrent.ThreadFactory;
18+
import java.util.Locale;
1519
import java.io.InputStream;
1620

1721
import static io.split.inputValidation.FlagSetsValidator.cleanup;

client/src/main/java/io/split/service/SplitHttpClientKerberosImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public synchronized SplitHttpResponse post(URI uri, HttpEntity entity, Map<Strin
123123
postHttpURLConnection = (HttpURLConnection) uri.toURL().openConnection();
124124
return _post(postHttpURLConnection, entity, additionalHeaders);
125125
} catch (Exception e) {
126-
throw new IOException(String.format("Problem in http post operation: %s", e), e);
126+
throw new IllegalStateException(String.format("Problem in http post operation: %s", e), e);
127127
} finally {
128128
try {
129129
postHttpURLConnection.disconnect();
@@ -165,7 +165,7 @@ public SplitHttpResponse _post(HttpURLConnection postHttpURLConnection,
165165
}
166166
return new SplitHttpResponse(responseCode, statusMessage, "", getResponseHeaders(postHttpURLConnection));
167167
} catch (Exception e) {
168-
throw new IOException(String.format("Problem in http post operation: %s", e), e);
168+
throw new IllegalStateException(String.format("Problem in http post operation: %s", e), e);
169169
}
170170
}
171171

@@ -209,6 +209,6 @@ private Header[] getResponseHeaders(HttpURLConnection urlConnection) {
209209
}
210210
@Override
211211
public void close() throws IOException {
212-
// _client.close();
212+
213213
}
214214
}

client/src/test/java/io/split/service/HttpSplitClientKerberosTest.java

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public void testGetError() throws URISyntaxException, IOException {
9999

100100
Mockito.when(mockHttpURLConnection.getResponseCode()).thenReturn(HttpURLConnection.HTTP_INTERNAL_ERROR);
101101
ByteArrayInputStream stubInputStream = new ByteArrayInputStream(Files.asCharSource(
102-
new File("/Users/bilalal-shahwany/repos/java/kerberos/java-client/client/src/test/resources/split-change-special-characters.json"), Charsets.UTF_8).read().getBytes(Charsets.UTF_8));
102+
new File("src/test/resources/split-change-special-characters.json"), Charsets.UTF_8).read().getBytes(Charsets.UTF_8));
103103
when(mockHttpURLConnection.getInputStream()).thenReturn(stubInputStream);
104104

105105
SplitHttpClientKerberosImpl splitHtpClientKerberos = SplitHttpClientKerberosImpl.create(decorator, "qwerty", metadata());
@@ -111,13 +111,16 @@ public void testGetError() throws URISyntaxException, IOException {
111111
@Test(expected = IllegalStateException.class)
112112
public void testException() throws URISyntaxException, InvocationTargetException, NoSuchMethodException,
113113
IllegalAccessException, IOException {
114-
URI rootTarget = URI.create("https://api.split.io/splitChanges?since=1234567");
115-
CloseableHttpClient httpClientMock = TestHelper.mockHttpClient("split-change-special-characters.json",
116-
HttpStatus.SC_INTERNAL_SERVER_ERROR);
114+
HttpURLConnection mockHttpURLConnection = Mockito.mock(HttpURLConnection.class);
117115
RequestDecorator decorator = null;
118116

119-
SplitHttpClient splitHtpClient = SplitHttpClientImpl.create(httpClientMock, decorator, "qwerty", metadata());
120-
splitHtpClient.get(rootTarget,
117+
Mockito.when(mockHttpURLConnection.getResponseCode()).thenReturn(HttpURLConnection.HTTP_INTERNAL_ERROR);
118+
ByteArrayInputStream stubInputStream = new ByteArrayInputStream(Files.asCharSource(
119+
new File("src/test/resources/split-change-special-characters.json"), Charsets.UTF_8).read().getBytes(Charsets.UTF_8));
120+
when(mockHttpURLConnection.getInputStream()).thenReturn(stubInputStream);
121+
122+
SplitHttpClientKerberosImpl splitHtpClientKerberos = SplitHttpClientKerberosImpl.create(decorator, "qwerty", metadata());
123+
SplitHttpResponse splitHttpResponse = splitHtpClientKerberos._get(mockHttpURLConnection,
121124
new FetchOptions.Builder().cacheControlHeaders(true).build(), null);
122125
}
123126

@@ -178,11 +181,13 @@ public void testPotParameters() throws URISyntaxException, IOException {
178181
assertThat(connectionCaptor.getValue().getURL().toString(), is(equalTo(new URL("https://kubernetesturl.com/split/api/testImpressions/bulk").toString())));
179182
}
180183

181-
@Test(expected = IOException.class)
182-
public void testPosttException() throws URISyntaxException, IOException {
184+
@Test
185+
public void testPosttError() throws URISyntaxException, IOException {
183186
HttpURLConnection mockHttpURLConnection = Mockito.mock(HttpURLConnection.class);
184187
RequestDecorator decorator = new RequestDecorator(null);
188+
ByteArrayOutputStream mockOs = Mockito.mock( ByteArrayOutputStream.class);
185189
Mockito.when(mockHttpURLConnection.getResponseCode()).thenReturn(HttpURLConnection.HTTP_INTERNAL_ERROR);
190+
when(mockHttpURLConnection.getOutputStream()).thenReturn(mockOs);
186191

187192
SplitHttpClientKerberosImpl splitHtpClientKerberos = SplitHttpClientKerberosImpl.create(decorator, "qwerty", metadata());
188193
SplitHttpResponse splitHttpResponse = splitHtpClientKerberos._post(mockHttpURLConnection,
@@ -191,6 +196,17 @@ public void testPosttException() throws URISyntaxException, IOException {
191196
Assert.assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, (long) splitHttpResponse.statusCode());
192197
}
193198

199+
@Test(expected = IllegalStateException.class)
200+
public void testPosttException() throws URISyntaxException, IOException {
201+
HttpURLConnection mockHttpURLConnection = Mockito.mock(HttpURLConnection.class);
202+
RequestDecorator decorator = null;
203+
Mockito.when(mockHttpURLConnection.getResponseCode()).thenReturn(HttpURLConnection.HTTP_OK);
204+
205+
SplitHttpClientKerberosImpl splitHtpClientKerberos = SplitHttpClientKerberosImpl.create(decorator, "qwerty", metadata());
206+
SplitHttpResponse splitHttpResponse = splitHtpClientKerberos._post(mockHttpURLConnection,
207+
Utils.toJsonEntity(Arrays.asList(new String[] { "A", "B", "C", "D" })), null);
208+
}
209+
194210
private SDKMetadata metadata() {
195211
return new SDKMetadata("java-1.2.3", "1.2.3.4", "someIP");
196212
}

0 commit comments

Comments
 (0)