KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > snmp > ComparableSnmpOidTestCase


1 /*
2  * JBoss, Home of Professional Open Source
3  * Copyright 2005, JBoss Inc., and individual contributors as indicated
4  * by the @authors tag. See the copyright.txt in the distribution for a
5  * full listing of individual contributors.
6  *
7  * This is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as
9  * published by the Free Software Foundation; either version 2.1 of
10  * the License, or (at your option) any later version.
11  *
12  * This software is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this software; if not, write to the Free
19  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21  */

22 package org.jboss.test.snmp;
23
24 import java.util.SortedSet JavaDoc;
25 import java.util.TreeSet JavaDoc;
26
27 import org.jboss.jmx.adaptor.snmp.agent.ComparableSnmpObjectId;
28
29 import junit.framework.TestCase;
30
31 /**
32  * Tests for the ComparableSnmpObjectId, a Subclass of SnmpObjectId from
33  * the joesnmp package. Most tests are trivial.
34  * @author <a HREF="mailto:hwr@pilhuhn.de">Heiko W. Rupp</a>
35  * @version $Revision: 46154 $
36  */

37 public class ComparableSnmpOidTestCase extends TestCase
38 {
39     
40     /**
41      * Make sure, that the passed oid which does not end in .0
42      * is not detected as leaf.
43      */

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     /**
52      * Make sure that the passed oid ending in .0 is detected as leaf.
53      */

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     /**
62      * Make sure that the passed oid ending in .0 is detected as leaf.
63      */

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     /**
73      * See if the last part of an oid is correctly chopped of.
74      *
75      */

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     /**
84      * See if compareTo from Comparable works as expected.
85      * This is needed for use of the ComparableSnmpObjectId in SortedSets etc.
86      * @see java.lang.Comparable
87      */

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     /**
97      * See if compareTo from Comparable works as expected.
98      * This is needed for use of the ComparableSnmpObjectId in SortedSets etc.
99      * @see java.lang.Comparable
100      */

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     /**
110      * See if compareTo from Comparable works as expected.
111      * This is needed for use of the ComparableSnmpObjectId in SortedSets etc.
112      * @see java.lang.Comparable
113      */

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     /**
123      * See if compareTo from Comparable works as expected.
124      * This is needed for use of the ComparableSnmpObjectId in SortedSets etc.
125      * @see java.lang.Comparable
126      */

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     /**
136      * See if compareTo from Comparable works as expected.
137      * This is needed for use of the ComparableSnmpObjectId in SortedSets etc.
138      * @see java.lang.Comparable
139      */

140     public void testCompareTo5()
141     {
142         ComparableSnmpObjectId coid = new ComparableSnmpObjectId("1.2.3.4.2");
143         Object JavaDoc coid2 = new Object JavaDoc();
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 JavaDoc s = new TreeSet JavaDoc();
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 JavaDoc 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