1 45 package org.exolab.jms.net.socket; 46 47 import junit.framework.TestCase; 48 49 import org.exolab.jms.net.uri.URI; 50 import org.exolab.jms.net.util.Properties; 51 52 53 59 public class SocketRequestInfoTest extends TestCase { 60 61 66 public SocketRequestInfoTest(String name) { 67 super(name); 68 } 69 70 75 public void testAccessors() throws Exception { 76 final String uri = "tcp://localhost:8050"; 77 final String alternativeURI = "tcp://foo.org:9090"; 78 final boolean bindAll = true; 79 final boolean bindOne = false; 80 final int maxThreads = 21; 81 82 SocketRequestInfo info = populate(uri, alternativeURI, bindAll, 83 maxThreads); 84 85 assertEquals(uri, info.getURI().toString()); 86 assertEquals(alternativeURI, info.getAlternativeURI().toString()); 87 assertEquals(bindAll, info.getBindAll()); 88 info.setBindAll(bindOne); 89 assertEquals(bindOne, info.getBindAll()); 90 assertEquals(maxThreads, info.getMaxThreads()); 91 } 92 93 98 public void testEquals() throws Exception { 99 final String uri = "tcp://localhost:8050"; 100 final String alternativeURI = "tcp://foo.org:9090"; 101 final boolean bindAll = true; 102 final int maxThreads = 23; 103 104 SocketRequestInfo info1 = populate(uri, alternativeURI, bindAll, 105 maxThreads); 106 SocketRequestInfo info2 = populate(uri, alternativeURI, bindAll, 107 maxThreads); 108 assertEquals(info1, info2); 109 110 SocketRequestInfo info3 = populate(uri, null, bindAll, maxThreads); 111 assertFalse(info1.equals(info3)); 112 113 SocketRequestInfo info4 = populate(uri, alternativeURI, !bindAll, 114 maxThreads); 115 assertFalse(info1.equals(info4)); 116 117 SocketRequestInfo info5 = populate(uri, alternativeURI, bindAll, 118 maxThreads + 1); 119 assertFalse(info1.equals(info5)); 120 } 121 122 127 public void testProperties() throws Exception { 128 final String prefix = "org.exolab.jms.net.tcps."; 129 final String uri = "tcps://exolab.org:4040/"; 130 final String alternativeURI = "tcps://localhost:4040/"; 131 final boolean bindAll = false; 132 final int maxThreads = 24; 133 134 Properties properties = new Properties(prefix); 135 SocketRequestInfo info1 = populate(uri, alternativeURI, bindAll, 136 maxThreads); 137 info1.export(properties); 138 139 SocketRequestInfo info2 = new SocketRequestInfo(new URI(uri), 140 properties); 141 assertEquals(info1, info2); 142 143 assertEquals(uri, info2.getURI().toString()); 144 assertEquals(alternativeURI, info2.getAlternativeURI().toString()); 145 assertEquals(bindAll, info2.getBindAll()); 146 assertEquals(maxThreads, info2.getMaxThreads()); 147 } 148 149 161 private SocketRequestInfo populate(String uri, String alternativeURI, 162 boolean bindAll, int maxThreads) 163 throws Exception { 164 SocketRequestInfo info = new SocketRequestInfo(new URI(uri)); 165 if (alternativeURI != null) { 166 info.setAlternativeURI(new URI(alternativeURI)); 167 } 168 info.setBindAll(bindAll); 169 info.setMaxThreads(maxThreads); 170 return info; 171 } 172 173 } 174 | Popular Tags |