00001
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 package gov.lanl.isr.sensix.test;
00036
00037 import junit.framework.*;
00038 import gov.lanl.isr.sensix.*;
00039 import gov.lanl.isr.sensix.discovery.*;
00040 import gov.lanl.isr.sensix.sensing.*;
00041
00042
00043 public class DiscoveryTest extends TestCase
00044 {
00045 public void testEndian() {
00046 int test = 5;
00047 assertEquals(test, DiscoveryService.b2i(DiscoveryService.i2b(test)));
00048 test = 83886080;
00049 assertEquals(test, DiscoveryService.b2i(DiscoveryService.i2b(test)));
00050 if (test == DiscoveryService.b2i_le(DiscoveryService.i2b(test)))
00051 fail("LittleEndian conversion should not equal a BigEndian value");
00052 }
00053
00054 public void testAnnounce() {
00055 int hdr_size = DiscoveryService.HEADER_SIZE;
00056 byte[] hdr, body;
00057 DiscoverMessage dm = null;
00058
00059 Announce a = new Announce(11, (byte)3);
00060 hdr = DiscoveryService.announceHeader();
00061 body = DiscoveryService.loadAnnounce(a);
00062 try {
00063 DiscoverMessageHeader dh = new DiscoverMessageHeader(hdr);
00064 dm = new DiscoverMessage(dh, body);
00065 } catch (DiscoverMessageException dme) {
00066 fail("Discover Message exception: " + dme.toString());
00067 }
00068 assertEquals(a.nodeIdent, dm.nodeIdent);
00069 assertEquals(a.hLevel, dm.hLevel);
00070 }
00071
00072 public void testReport() {
00073 int hdr_size = DiscoveryService.HEADER_SIZE;
00074 byte[] hdr, body;
00075 DiscoverMessage dm = null;
00076
00077 Report r = new Report(1928, (byte)7, (byte)0x23);
00078 hdr = DiscoveryService.reportHeader();
00079 body = DiscoveryService.loadReport(r);
00080 try {
00081 DiscoverMessageHeader dh = new DiscoverMessageHeader(hdr);
00082 dm = new DiscoverMessage(dh, body);
00083 } catch (DiscoverMessageException dme) {
00084 fail("Discover Message exception: " + dme.toString());
00085 }
00086 assertEquals(r.nodeIdent, dm.nodeIdent);
00087 assertEquals(r.hLevel, dm.hLevel);
00088 assertEquals(r.cType, dm.cType);
00089 }
00090
00091 public void testRequire() {
00092 int hdr_size = DiscoveryService.HEADER_SIZE;
00093 byte[] hdr, body;
00094 DiscoverMessage dm = null;
00095
00096 Require r = new Require(1546, (byte)7, (byte)0x23, 922);
00097 hdr = DiscoveryService.requireHeader();
00098 body = DiscoveryService.loadRequire(r);
00099 try {
00100 DiscoverMessageHeader dh = new DiscoverMessageHeader(hdr);
00101 dm = new DiscoverMessage(dh, body);
00102 } catch (DiscoverMessageException dme) {
00103 fail("Discover Message exception: " + dme.toString());
00104 }
00105 assertEquals(r.nodeIdent, dm.nodeIdent);
00106 assertEquals(r.hLevel, dm.hLevel);
00107 assertEquals(r.cType, dm.cType);
00108 assertEquals(r.targetIdent, dm.targetIdent);
00109 }
00110
00111 public void testShare() {
00112 int hdr_size = DiscoveryService.HEADER_SIZE;
00113 byte[] hdr, body;
00114 DiscoverMessage dm = null;
00115
00116 Share s = new Share(2038461, (byte)10, (byte)0x02, "dummy_ior");
00117 hdr = DiscoveryService.shareHeader(s);
00118 body = DiscoveryService.loadShare(s);
00119 try {
00120 DiscoverMessageHeader dh = new DiscoverMessageHeader(hdr);
00121 dm = new DiscoverMessage(dh, body);
00122 } catch (DiscoverMessageException dme) {
00123 fail("Discover Message exception: " + dme.toString());
00124 }
00125 assertEquals(s.nodeIdent, dm.nodeIdent);
00126 assertEquals(s.hLevel, dm.hLevel);
00127 assertEquals(s.cType, dm.cType);
00128 assertEquals(s.ior, dm.ior);
00129 }
00130 }