-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
181 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
141 changes: 141 additions & 0 deletions
141
imixs-workflow-core/src/test/java/org/imixs/workflow/xml/TestXMLItemCollectionAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
package org.imixs.workflow.xml; | ||
|
||
import java.util.Date; | ||
import java.util.GregorianCalendar; | ||
import java.util.List; | ||
|
||
import javax.xml.datatype.DatatypeConfigurationException; | ||
import javax.xml.datatype.DatatypeFactory; | ||
import javax.xml.datatype.XMLGregorianCalendar; | ||
|
||
import org.imixs.workflow.ItemCollection; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
/** | ||
* Test class for xmlItemCollection object | ||
* | ||
* @author rsoika | ||
* | ||
*/ | ||
public class TestXMLItemCollectionAdapter { | ||
|
||
@Test | ||
public void testItemCollection() { | ||
ItemCollection itemCollection = new ItemCollection(); | ||
itemCollection.replaceItemValue("txtTitel", "Hello"); | ||
XMLItemCollection xmlItemCollection = null; | ||
try { | ||
xmlItemCollection = XMLItemCollectionAdapter | ||
.putItemCollection(itemCollection); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
Assert.fail(); | ||
} | ||
|
||
ItemCollection col2 = XMLItemCollectionAdapter | ||
.getItemCollection(xmlItemCollection); | ||
|
||
Assert.assertEquals(itemCollection.getItemValueString("txttitel"), | ||
"Hello"); | ||
|
||
Assert.assertEquals(col2.getItemValueString("txttitel"), "Hello"); | ||
} | ||
|
||
/** | ||
* test convertion of date values | ||
*/ | ||
@Test | ||
public void testDateValue() { | ||
ItemCollection itemCollection = new ItemCollection(); | ||
|
||
Date datTest = new Date(); | ||
itemCollection.replaceItemValue("datDate", datTest); | ||
|
||
XMLItemCollection xmlItemCollection = null; | ||
try { | ||
xmlItemCollection = XMLItemCollectionAdapter | ||
.putItemCollection(itemCollection); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
Assert.fail(); | ||
} | ||
|
||
ItemCollection col2 = XMLItemCollectionAdapter | ||
.getItemCollection(xmlItemCollection); | ||
|
||
// test if date is equals | ||
Assert.assertEquals(col2.getItemValueDate("datDate"), | ||
itemCollection.getItemValueDate("datDate")); | ||
|
||
Assert.assertEquals(col2.getItemValueDate("datDate"), datTest); | ||
|
||
} | ||
|
||
/** | ||
* Issue #52 | ||
* | ||
* Test conversion of XMLGregorianCalener Instances | ||
* | ||
* @see http://stackoverflow.com/questions/835889/java-util-date-to- | ||
* xmlgregoriancalendar | ||
*/ | ||
@SuppressWarnings({ "rawtypes" }) | ||
@Test | ||
public void testXMLGregrianCalendar() { | ||
|
||
// first we test normal date objects | ||
|
||
Date datTest = new Date(); | ||
|
||
XMLItemCollection xmlItemCollection = new XMLItemCollection(); | ||
XMLItem xmlItem = new XMLItem(); | ||
xmlItem.setName("datdate"); | ||
xmlItem.setValue(new Object[] { datTest }); | ||
XMLItem[] xmlItemList = new XMLItem[] { xmlItem }; | ||
xmlItemCollection.setItem(xmlItemList); | ||
|
||
ItemCollection itemCollection = XMLItemCollectionAdapter | ||
.getItemCollection(xmlItemCollection); | ||
Assert.assertEquals(itemCollection.getItemValueDate("datdate"), datTest); | ||
|
||
/* | ||
* Test phase II. | ||
*/ | ||
|
||
// now we repeat the test with an XMLGregorianCalneder Object... | ||
XMLGregorianCalendar xmlDate = null; | ||
try { | ||
GregorianCalendar c = new GregorianCalendar(); | ||
c.setTime(datTest); | ||
xmlDate = DatatypeFactory.newInstance().newXMLGregorianCalendar(c); | ||
} catch (DatatypeConfigurationException e) { | ||
|
||
e.printStackTrace(); | ||
Assert.fail(); | ||
} | ||
xmlItemCollection = new XMLItemCollection(); | ||
xmlItem = new XMLItem(); | ||
xmlItem.setName("datdate"); | ||
xmlItem.setValue(new Object[] { xmlDate }); | ||
xmlItemList = new XMLItem[] { xmlItem }; | ||
xmlItemCollection.setItem(xmlItemList); | ||
|
||
itemCollection = XMLItemCollectionAdapter | ||
.getItemCollection(xmlItemCollection); | ||
|
||
// now we expect that the XMLItemCollectionAdapter has converted | ||
// the XMLGregorianCalendar impl into a java.util.Date object | ||
|
||
List resultDate = itemCollection.getItemValue("datdate"); | ||
Assert.assertNotNull(resultDate); | ||
Assert.assertEquals(1, resultDate.size()); | ||
|
||
Assert.assertFalse(resultDate.get(0) instanceof XMLGregorianCalendar); | ||
Assert.assertTrue(resultDate.get(0) instanceof java.util.Date); | ||
|
||
Assert.assertEquals(itemCollection.getItemValueDate("datdate"), datTest); | ||
|
||
} | ||
|
||
} |