Skip to content

Commit

Permalink
refactoring, improved tests
Browse files Browse the repository at this point in the history
issue #347
  • Loading branch information
rsoika committed Feb 19, 2018
1 parent 9d59901 commit 1c720fe
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -708,23 +708,13 @@ private void setItemValue(String itemName, Object itemValue, boolean append) {
@SuppressWarnings("rawtypes")
private boolean validateItemValue(Object itemValue) {

if (itemValue==null) {
return true;
}

// convert Calendar instance into Date! issue #52
if (itemValue instanceof Calendar) {
itemValue=((Calendar)itemValue).getTime();
itemValue = ((Calendar) itemValue).getTime();
}

// array?
if (itemValue != null && itemValue.getClass().isArray()) {
for (int i = 0; i < Array.getLength(itemValue); i++) {
Object singleValue = Array.get(itemValue, i);
if (!validateItemValue(singleValue)) {
return false;
}
}
// first we test if basic type?
if (isBasicType(itemValue)) {
return true;
}

Expand All @@ -738,7 +728,18 @@ private boolean validateItemValue(Object itemValue) {
return true;
} else

// map
// array?
if (itemValue != null && itemValue.getClass().isArray()) {
for (int i = 0; i < Array.getLength(itemValue); i++) {
Object singleValue = Array.get(itemValue, i);
if (!validateItemValue(singleValue)) {
return false;
}
}
return true;
} else

// map?
if ((itemValue instanceof Map)) {
Map map = (Map) itemValue;
for (Object value : map.values()) {
Expand All @@ -747,9 +748,10 @@ private boolean validateItemValue(Object itemValue) {
}
}
return true;
} else {
return (isBasicType(itemValue));
}

// unknown type
return false;
}

/**
Expand All @@ -776,13 +778,14 @@ private static boolean isBasicType(java.lang.Object o) {
// test package name
Class c = o.getClass();
String name = c.getName();
if (!name.startsWith("java.lang.") && !name.startsWith("java.math.") && !"java.util.Date".equals(name)
&& !"org.imixs.workflow.xml.XMLItem".equals(name)
&& !"org.imixs.workflow.xml.XMLItemCollection".equals(name)) {
return false;
if (name.startsWith("java.lang.") || name.startsWith("java.math.") || "java.util.Date".equals(name)
|| "org.imixs.workflow.xml.XMLItem".equals(name)
|| "org.imixs.workflow.xml.XMLItemCollection".equals(name)) {
return true;
}

return true;
// no basic type
return false;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -679,4 +679,21 @@ public void testItemCollectionNoBasictype() {

}

/**
* Test raw type int, double, boolean
*/
@Test
@Category(org.imixs.workflow.ItemCollection.class)
public void testItemCollectionRawtype() {
ItemCollection itemCollection = new ItemCollection();
itemCollection.replaceItemValue("txtTitel", "Hello");
double d=5.20;
itemCollection.replaceItemValue("price", d);

byte[] bytes="Some Data".getBytes();
itemCollection.replaceItemValue("data", bytes);

Assert.assertNotNull(itemCollection);

}
}

0 comments on commit 1c720fe

Please sign in to comment.