1 29 30 package nextapp.echo2.webrender.test; 31 32 import org.w3c.dom.Element ; 33 import org.w3c.dom.NodeList ; 34 35 import nextapp.echo2.webrender.ServerMessage; 36 import junit.framework.TestCase; 37 38 41 public class ServerMessageTest extends TestCase { 42 43 46 public void testAddLibrary() { 47 NodeList libraryNodeList; 48 ServerMessage message = new ServerMessage(); 49 50 message.addLibrary("service1"); 51 libraryNodeList = message.getDocument().getElementsByTagName("library"); 52 assertEquals(1, libraryNodeList.getLength()); 53 54 message.addLibrary("service2"); 55 libraryNodeList = message.getDocument().getElementsByTagName("library"); 56 assertEquals(2, libraryNodeList.getLength()); 57 58 message.addLibrary("service1"); 59 libraryNodeList = message.getDocument().getElementsByTagName("library"); 60 assertEquals(2, libraryNodeList.getLength()); 61 } 62 63 66 public void testAppendPartDirective() { 67 ServerMessage message = new ServerMessage(); 68 message.appendPartDirective(ServerMessage.GROUP_ID_UPDATE, "DomUpdate", "dom-add"); 69 message.appendPartDirective(ServerMessage.GROUP_ID_UPDATE, "DomUpdate", "dom-remove"); 70 message.appendPartDirective(ServerMessage.GROUP_ID_UPDATE, "DomUpdate", "dom-add"); 71 message.appendPartDirective(ServerMessage.GROUP_ID_UPDATE, "SomethingElse", "thing"); 72 message.appendPartDirective(ServerMessage.GROUP_ID_UPDATE, "DomUpdate", "dom-remove"); 73 message.appendPartDirective(ServerMessage.GROUP_ID_UPDATE, "DomUpdate", "dom-add"); 74 assertEquals(3, message.getDocument().getElementsByTagName("message-part").getLength()); 75 } 76 77 80 public void testItemizedDirective() { 81 ServerMessage message = new ServerMessage(); 82 String [] keyAttributeNames = new String []{"alpha", "bravo"}; 83 84 Element directiveElement1 = message.getItemizedDirective(ServerMessage.GROUP_ID_POSTUPDATE, "Processor", "Directive", 85 keyAttributeNames, new String []{"alpha1", "bravo1"}); 86 assertEquals("Directive", directiveElement1.getNodeName()); 87 assertEquals("alpha1", directiveElement1.getAttribute("alpha")); 88 assertEquals("bravo1", directiveElement1.getAttribute("bravo")); 89 90 Element directiveElement2 = message.getItemizedDirective(ServerMessage.GROUP_ID_POSTUPDATE, "Processor", "Directive", 91 keyAttributeNames, new String []{"alpha1", "bravo1"}); 92 assertEquals("Directive", directiveElement2.getNodeName()); 93 assertEquals("alpha1", directiveElement2.getAttribute("alpha")); 94 assertEquals("bravo1", directiveElement2.getAttribute("bravo")); 95 96 assertTrue(directiveElement1.equals(directiveElement2)); 97 98 Element directiveElement3 = message.getItemizedDirective(ServerMessage.GROUP_ID_POSTUPDATE, "Processor", "Directive", 99 keyAttributeNames, new String []{"alpha2", "bravo2"}); 100 assertEquals("Directive", directiveElement3.getNodeName()); 101 assertEquals("alpha2", directiveElement3.getAttribute("alpha")); 102 assertEquals("bravo2", directiveElement3.getAttribute("bravo")); 103 104 assertFalse(directiveElement1.equals(directiveElement3)); 105 assertFalse(directiveElement2.equals(directiveElement3)); 106 } 107 108 111 public void testGroupIds() { 112 ServerMessage message = new ServerMessage(); 113 Element directiveElement, messagePartGroupElement; 114 115 directiveElement = message.appendPartDirective(ServerMessage.GROUP_ID_UPDATE, "Something", "do-something"); 116 messagePartGroupElement = (Element ) directiveElement.getParentNode().getParentNode(); 117 assertEquals("message-part-group", messagePartGroupElement.getNodeName()); 118 assertEquals(ServerMessage.GROUP_ID_UPDATE, messagePartGroupElement.getAttribute("id")); 119 120 directiveElement = message.appendPartDirective(ServerMessage.GROUP_ID_POSTUPDATE, "Something", "do-something"); 121 messagePartGroupElement = (Element ) directiveElement.getParentNode().getParentNode(); 122 assertEquals("message-part-group", messagePartGroupElement.getNodeName()); 123 assertEquals(ServerMessage.GROUP_ID_POSTUPDATE, messagePartGroupElement.getAttribute("id")); 124 } 125 } 126 | Popular Tags |