Skip to content

Commit af8551e

Browse files
rakillenddsharpe
authored andcommitted
Issue #490 - Remove trailing L from long property values (#491)
1 parent 5ea1ee4 commit af8551e

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

core/src/main/java/oracle/weblogic/deploy/aliases/TypeUtils.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.python.core.Py;
2323
import org.python.core.PyDictionary;
2424
import org.python.core.PyException;
25+
import org.python.core.PyLong;
2526
import org.python.core.PyObject;
2627
import org.python.core.PyTuple;
2728

@@ -323,7 +324,7 @@ private static Properties convertToProperties(Object value, String delimiter) th
323324
properties = new Properties();
324325
for (Object obj : dict.items()) {
325326
PyTuple po = (PyTuple) obj;
326-
properties.put( po.__finditem__(0).toString(), po.__finditem__(1).toString() );
327+
properties.put( po.__finditem__(0).toString(), getPropertyText(po.__finditem__(1)) );
327328
}
328329
} else {
329330
AliasException ae = new AliasException("WLSDPLY-08503", value.getClass().getName());
@@ -332,6 +333,20 @@ private static Properties convertToProperties(Object value, String delimiter) th
332333
}
333334
return properties.isEmpty() ? null : properties;
334335
}
336+
337+
/**
338+
* Returns text for the specified value, for use with property type.
339+
* @param value the value to be examined
340+
* @return text for the value
341+
*/
342+
private static String getPropertyText(Object value) {
343+
// toString() for PyLong includes trailing L, such as 25L
344+
if(value instanceof PyLong) {
345+
return ((PyLong) value).getValue().toString();
346+
}
347+
return value.toString();
348+
}
349+
335350
private static PyDictionary convertToDictionary(Object value, String delimiter, boolean useOrderedDict)
336351
throws AliasException {
337352
final String METHOD = "convertToDictionary";

core/src/test/java/oracle/weblogic/deploy/aliases/TypeUtilsTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
import org.junit.Test;
1515
import org.python.core.PyDictionary;
16+
import org.python.core.PyLong;
1617
import org.python.core.PyObject;
1718
import org.python.core.PyString;
1819
import org.python.core.PyTuple;
@@ -134,4 +135,20 @@ public void convertToProperties() throws Exception {
134135
assertEquals("Properties from Map failed", expected, TypeUtils.convertToType(Properties.class, map, ";"));
135136

136137
}
138+
139+
@Test
140+
public void convertDictToProperties() throws Exception {
141+
PyDictionary dict = new PyDictionary();
142+
// test special processing to remove trailing L from PyLong, such as 25L
143+
dict.__setitem__("mail.smtp.port", new PyLong(25));
144+
dict.__setitem__("mail.smtp.host", new PyString("192.168.56.1"));
145+
146+
Properties result = (Properties) TypeUtils.convertToType(Properties.class, dict);
147+
148+
Properties expected = new Properties();
149+
expected.put("mail.smtp.port", "25");
150+
expected.put("mail.smtp.host", "192.168.56.1");
151+
152+
assertEquals("Properties from dict failed", expected, result);
153+
}
137154
}

0 commit comments

Comments
 (0)