1 23 package com.sun.enterprise.management.util.jmx; 24 25 26 import java.util.Set ; 27 import java.util.HashSet ; 28 import java.util.Collections ; 29 30 import javax.management.ObjectName ; 31 32 import com.sun.appserv.management.util.jmx.ObjectNameQuery; 33 import com.sun.appserv.management.util.jmx.ObjectNameQueryImpl; 34 35 36 37 public class ObjectNameQueryImplTest extends junit.framework.TestCase 38 { 39 40 public 41 ObjectNameQueryImplTest() 42 { 43 super( "ObjectNameQueryImplTest" ); 44 } 45 46 public 47 ObjectNameQueryImplTest( String name ) 48 { 49 super( name ); 50 } 51 public void 52 testCreation() 53 { 54 new ObjectNameQueryImpl(); 55 } 56 57 static final Set <ObjectName > EmptySet = Collections.unmodifiableSet( new HashSet <ObjectName >() ); 58 static final String [] EmptyStrings = new String [0]; 59 60 static Set <ObjectName > 61 createSet( ObjectName name ) 62 { 63 final Set <ObjectName > s = new HashSet <ObjectName >(); 64 65 s.add( name ); 66 67 return( s ); 68 } 69 70 static Set <ObjectName > 71 createSet( ObjectName [] names ) 72 { 73 final Set <ObjectName > s = new HashSet <ObjectName >(); 74 75 for( int i = 0; i < names.length; ++i ) 76 { 77 s.add( names[ i ] ); 78 } 79 80 return( s ); 81 } 82 83 84 static ObjectName 85 createName( String nameString ) 86 { 87 ObjectName name = null; 88 89 try 90 { 91 name = new ObjectName ( nameString ); 92 } 93 catch( Exception e ) 94 { 95 assert( false ); 96 } 97 return( name ); 98 } 99 100 public void 101 testEmptySet() 102 { 103 final ObjectNameQuery q = new ObjectNameQueryImpl(); 104 105 assertEquals( 0, q.matchAny( EmptySet, null, null ).size() ); 106 assertEquals( 0, q.matchAny( EmptySet, EmptyStrings, EmptyStrings ).size() ); 107 assertEquals( 0, q.matchAny( EmptySet, null, EmptyStrings ).size() ); 108 assertEquals( 0, q.matchAny( EmptySet, EmptyStrings, null ).size() ); 109 110 assertEquals( 0, q.matchAll( EmptySet, null, null ).size() ); 111 assertEquals( 0, q.matchAll( EmptySet, EmptyStrings, EmptyStrings ).size() ); 112 assertEquals( 0, q.matchAll( EmptySet, null, EmptyStrings ).size() ); 113 assertEquals( 0, q.matchAll( EmptySet, EmptyStrings, null ).size() ); 114 } 115 116 public void 117 testSingleItem() 118 { 119 final ObjectName name1 = createName( ":name=test,type=test" ); 120 final Set <ObjectName > testSet = createSet( name1 ); 121 122 final ObjectNameQuery q = new ObjectNameQueryImpl(); 123 124 assertEquals( 1, q.matchAny( testSet, 125 null, 126 null ).size() ); 127 128 assertEquals( 1, q.matchAny( testSet, 129 new String [] { "type" }, 130 new String [] { "test" } ).size() ); 131 132 assertEquals( 1, q.matchAny( testSet, 133 new String [] { "type" }, 134 null ).size() ); 135 136 assertEquals( 1, q.matchAny( testSet, 137 null, 138 new String [] { "test" } ).size() ); 139 140 141 assertEquals( 1, q.matchAny( testSet, 142 new String [] { "t.*" }, 143 new String [] { ".*e.*" } ).size() ); 144 145 146 assertEquals( 1, q.matchAny( testSet, 147 null, 148 new String [] { ".*e.*" } ).size() ); 149 150 151 assertEquals( 0, q.matchAny( testSet, EmptyStrings, EmptyStrings ).size() ); 152 assertEquals( 0, q.matchAny( testSet, null, EmptyStrings ).size() ); 153 assertEquals( 0, q.matchAny( testSet, EmptyStrings, null ).size() ); 154 } 155 } 156 157 158 159 160 161 162 | Popular Tags |