Skip to content

Commit adc376b

Browse files
committed
Testing with Port Number.
1 parent 733a700 commit adc376b

File tree

2 files changed

+44
-7
lines changed

2 files changed

+44
-7
lines changed

src/main/java/com/microsoft/sqlserver/jdbc/StringUtils.java

+27
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,32 @@ private StringUtils() {
3838
public static boolean isEmpty(final CharSequence charSequence) {
3939
return charSequence == null || charSequence.length() == 0;
4040
}
41+
42+
/**
43+
* Check if String is numeric or not.
44+
* @param str {@link String}
45+
* @return {@link Boolean} if provided String is numeric or not.
46+
*/
47+
public static boolean isNumeric(final String str) {
48+
return !isEmpty(str) && str.matches("\\d+(\\.\\d+)?");
49+
}
50+
51+
/**
52+
* Check if string is integer or not
53+
* @param str {@link String}
54+
* @return {@link Boolean} if provided String is Integer or not.
55+
*/
56+
public static boolean isInteger(final String str) {
57+
boolean isInteger = false;
58+
59+
try {
60+
int i = Integer.parseInt(str);
61+
isInteger = true;
62+
}catch(NumberFormatException e) {
63+
//Nothing. this is not integer.
64+
}
65+
66+
return isInteger;
67+
}
4168

4269
}

src/test/java/com/microsoft/sqlserver/jdbc/fips/FipsTest.java

+17-7
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,14 @@ public void fipsDataSourceTrustServerCertificateTest() throws Exception {
201201
*/
202202
private void setDataSourceProperties(SQLServerDataSource ds) {
203203
ds.setServerName(dataSourceProps[0]);
204-
ds.setUser(dataSourceProps[1]);
205-
ds.setPassword(dataSourceProps[2]);
206-
ds.setDatabaseName(dataSourceProps[3]);
204+
205+
if (dataSourceProps[1] != null && StringUtils.isInteger(dataSourceProps[1])) {
206+
ds.setPortNumber(Integer.valueOf(dataSourceProps[1]));
207+
}
208+
209+
ds.setUser(dataSourceProps[2]);
210+
ds.setPassword(dataSourceProps[3]);
211+
ds.setDatabaseName(dataSourceProps[4]);
207212

208213
// Set all properties for FIPS
209214
ds.setFIPS(true);
@@ -247,20 +252,25 @@ private Properties buildConnectionProperties() {
247252
*/
248253
private static String[] getDataSourceProperties() {
249254
String[] params = connectionString.split(";");
250-
String[] dataSoureParam = new String[4];
255+
String[] dataSoureParam = new String[5];
251256

252257
for (String strParam : params) {
253258
if (strParam.startsWith("jdbc:sqlserver")) {
254259
dataSoureParam[0] = strParam.replace("jdbc:sqlserver://", "");
260+
String[] hostPort = dataSoureParam[0].split(":");
261+
dataSoureParam[0] = hostPort[0];
262+
if (hostPort.length > 1) {
263+
dataSoureParam[1] = hostPort[1];
264+
}
255265
}
256266
else if (strParam.startsWith("userName")) {
257-
dataSoureParam[1] = strParam.replace("userName=", "");
267+
dataSoureParam[2] = strParam.replace("userName=", "");
258268
}
259269
else if (strParam.startsWith("password")) {
260-
dataSoureParam[2] = strParam.replace("password=", "");
270+
dataSoureParam[3] = strParam.replace("password=", "");
261271
}
262272
else if (strParam.startsWith("database")) {
263-
dataSoureParam[3] = strParam.replace("database=", "");
273+
dataSoureParam[4] = strParam.replace("database=", "");
264274
}
265275

266276
}

0 commit comments

Comments
 (0)