1 22 package org.jboss.test.snmp; 23 24 import java.util.SortedSet ; 25 import java.util.TreeSet ; 26 27 import org.jboss.jmx.adaptor.snmp.agent.ComparableSnmpObjectId; 28 29 import junit.framework.TestCase; 30 31 37 public class ComparableSnmpOidTestCase extends TestCase 38 { 39 40 44 public void testIsNotLeaf() 45 { 46 ComparableSnmpObjectId coid = new ComparableSnmpObjectId(".1.2.3.4"); 47 boolean res = coid.isLeaf(); 48 assertFalse(res); 49 } 50 51 54 public void testIsLeaf() 55 { 56 ComparableSnmpObjectId coid = new ComparableSnmpObjectId(".1.2.3.4.0"); 57 boolean res = coid.isLeaf(); 58 assertTrue(res); 59 } 60 61 64 public void testIsLeaf2() 65 { 66 ComparableSnmpObjectId coid = new ComparableSnmpObjectId("1.2.3.4.0"); 67 boolean res = coid.isLeaf(); 68 assertTrue(res); 69 } 70 71 72 76 public void testRemoveLastPart() 77 { 78 ComparableSnmpObjectId coid = new ComparableSnmpObjectId("1.2.3.4.0"); 79 ComparableSnmpObjectId res = coid.removeLastPart(); 80 assertEquals(".1.2.3.4",res.toString()); 81 } 82 83 88 public void testCompareTo1() 89 { 90 ComparableSnmpObjectId coid = new ComparableSnmpObjectId("1.2.3.4.0"); 91 ComparableSnmpObjectId coid2 = new ComparableSnmpObjectId(".1.2.3.4.0"); 92 int res = coid.compareTo(coid2); 93 assertEquals(0,res); 94 } 95 96 101 public void testCompareTo2() 102 { 103 ComparableSnmpObjectId coid = new ComparableSnmpObjectId("1.2.3.4"); 104 ComparableSnmpObjectId coid2 = new ComparableSnmpObjectId("1.2.3.4.0"); 105 int res = coid.compareTo(coid2); 106 assertTrue(res!=0); 107 } 108 109 114 public void testCompareTo3() 115 { 116 ComparableSnmpObjectId coid = new ComparableSnmpObjectId("1.2.3.4.1"); 117 ComparableSnmpObjectId coid2 = new ComparableSnmpObjectId("1.2.3.4.2"); 118 int res = coid.compareTo(coid2); 119 assertTrue(res<0); 120 } 121 122 127 public void testCompareTo4() 128 { 129 ComparableSnmpObjectId coid = new ComparableSnmpObjectId("1.2.3.4.2"); 130 ComparableSnmpObjectId coid2 = new ComparableSnmpObjectId("1.2.3.4.1"); 131 int res = coid.compareTo(coid2); 132 assertTrue(res>0); 133 } 134 135 140 public void testCompareTo5() 141 { 142 ComparableSnmpObjectId coid = new ComparableSnmpObjectId("1.2.3.4.2"); 143 Object coid2 = new Object (); 144 int res = coid.compareTo(coid2); 145 assertTrue(res == -1); 146 } 147 148 149 public void testGetNextArc() 150 { 151 ComparableSnmpObjectId coid = new ComparableSnmpObjectId("1.2.3.4"); 152 ComparableSnmpObjectId res = coid.getNextArc(); 153 assertEquals(".1.2.4",res.toString()); 154 } 155 156 public void testGetNextArc2() 157 { 158 ComparableSnmpObjectId coid = new ComparableSnmpObjectId(".1.2.3.4.5"); 159 ComparableSnmpObjectId res = coid.getNextArc(); 160 assertEquals(".1.2.3.5",res.toString()); 161 } 162 163 public void testGetNextArc3() 164 { 165 ComparableSnmpObjectId coid = new ComparableSnmpObjectId(".1.2.3.4.0"); 166 ComparableSnmpObjectId res = coid.getNextArc(); 167 assertEquals(".1.2.4",res.toString()); 168 } 169 170 171 public void testGetSubtree() 172 { 173 SortedSet s = new TreeSet (); 174 ComparableSnmpObjectId coid = new ComparableSnmpObjectId("1.2.3.4.0"); 175 s.add(coid); 176 coid = new ComparableSnmpObjectId("1.2.3.5.0"); 177 s.add(coid); 178 coid = new ComparableSnmpObjectId("1.2.3.6.0"); 179 s.add(coid); 180 181 ComparableSnmpObjectId c2 = new ComparableSnmpObjectId("1.2.3.4.1"); 182 SortedSet subset = s.tailSet(c2); 183 assertEquals(2,subset.size()); 184 185 subset = s.headSet(c2); 186 assertEquals(1,subset.size()); 187 } 188 189 } | Popular Tags |