-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Improved the XML-based serialization that got introduced as a fix for #120/#170 Dropped Externalization (supposed to be replaced with XML-based serialization) to reduce complexity. Added unit tests to verify XML-based serialization functionality.
- Loading branch information
Showing
5 changed files
with
112 additions
and
64 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
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
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
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
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 |
---|---|---|
|
@@ -19,6 +19,8 @@ | |
import org.xmpp.packet.JID; | ||
|
||
import java.util.Date; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertTrue; | ||
|
@@ -30,6 +32,74 @@ | |
*/ | ||
public class XmlSerializerTest { | ||
|
||
/** | ||
* Checks that an instance of {@link Conversation} can be marshalled to XML, and back to an object again, | ||
* verifying that the resulting object is equal to the original input. | ||
*/ | ||
@Test | ||
public void testXmlMarshallingConversationTest() throws Exception { | ||
// Setup test fixture. | ||
final Map<String, UserParticipations> participations = new HashMap<>(); | ||
final UserParticipations userParticipations = new UserParticipations(true); | ||
userParticipations.addParticipation(new ConversationParticipation(new Date(2), "unittest")); | ||
userParticipations.addParticipation(new ConversationParticipation(new Date(3))); | ||
final ConversationParticipation participation = new ConversationParticipation(new Date(4), "unittest"); | ||
participation.participationEnded(new Date(5)); | ||
userParticipations.addParticipation(participation); | ||
participations.put("g@d", userParticipations); | ||
participations.put("a@s/f", userParticipations); | ||
final Conversation input = new Conversation(new JID("[email protected]"), true, new Date(1), new Date(2), 8, participations); | ||
|
||
// Execute system under test. | ||
final String xml = XmlSerializer.getInstance().marshall(input); | ||
final Object result = XmlSerializer.getInstance().unmarshall(xml); | ||
|
||
// Verify result. | ||
assertTrue(result instanceof Conversation); | ||
assertEquals("Marshalled content didn't unmarshall as equal object. Marshalled content: " + xml, input, result); | ||
} | ||
|
||
/** | ||
* Checks that an instance of {@link UserParticipations} can be marshalled to XML, and back to an object again, | ||
* verifying that the resulting object is equal to the original input. | ||
*/ | ||
@Test | ||
public void testXmlMarshallingUserParticipationsTest() throws Exception { | ||
// Setup test fixture. | ||
final UserParticipations input = new UserParticipations(true); | ||
input.addParticipation(new ConversationParticipation(new Date(2), "unittest")); | ||
input.addParticipation(new ConversationParticipation(new Date(3))); | ||
final ConversationParticipation participation = new ConversationParticipation(new Date(4), "unittest"); | ||
participation.participationEnded(new Date(5)); | ||
input.addParticipation(participation); | ||
|
||
// Execute system under test. | ||
final String xml = XmlSerializer.getInstance().marshall(input); | ||
final Object result = XmlSerializer.getInstance().unmarshall(xml); | ||
|
||
// Verify result. | ||
assertTrue(result instanceof UserParticipations); | ||
assertEquals("Marshalled content didn't unmarshall as equal object. Marshalled content: " + xml, input, result); | ||
} | ||
|
||
/** | ||
* Checks that an instance of {@link ConversationParticipation} can be marshalled to XML, and back to an object again, | ||
* verifying that the resulting object is equal to the original input. | ||
*/ | ||
@Test | ||
public void testXmlMarshallingConversationParticipationTest() throws Exception { | ||
// Setup test fixture. | ||
final ConversationParticipation input = new ConversationParticipation(new Date(2), "unittest"); | ||
|
||
// Execute system under test. | ||
final String xml = XmlSerializer.getInstance().marshall(input); | ||
final Object result = XmlSerializer.getInstance().unmarshall(xml); | ||
|
||
// Verify result. | ||
assertTrue(result instanceof ConversationParticipation); | ||
assertEquals("Marshalled content didn't unmarshall as equal object. Marshalled content: " + xml, input, result); | ||
} | ||
|
||
/** | ||
* Checks that an instance of {@link ConversationEvent} can be marshalled to XML, and back to an object again, | ||
* verifying that the resulting object is equal to the original input. | ||
|