1   /*
2    *   Copyright 2004 The Apache Software Foundation
3    *
4    *   Licensed under the Apache License, Version 2.0 (the "License");
5    *   you may not use this file except in compliance with the License.
6    *   You may obtain a copy of the License at
7    *
8    *       http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *   Unless required by applicable law or agreed to in writing, software
11   *   distributed under the License is distributed on an "AS IS" BASIS,
12   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *   See the License for the specific language governing permissions and
14   *   limitations under the License.
15   *
16   */
17  package org.apache.asn1.ber ;
18  
19  
20  import junit.framework.TestCase ;
21  
22  
23  /***
24   * Tests TypeClass class.
25   *
26   * @author <a href="mailto:dev@directory.apache.org">
27   * Apache Directory Project</a>
28   * @version $Rev: 289141 $
29   */
30  public class TypeClassTest extends TestCase
31  {
32  
33      public static void main(String[] args)
34      {
35          junit.textui.TestRunner.run(TypeClassTest.class);
36      }
37  
38      /*
39       * @see TestCase#setUp()
40       */
41      protected void setUp() throws Exception
42      {
43          super.setUp();
44      }
45  
46      /*
47       * @see TestCase#tearDown()
48       */
49      protected void tearDown() throws Exception
50      {
51          super.tearDown();
52      }
53  
54      /***
55       * Constructor for TypeClassTest.
56       * @param arg0
57       */
58      public TypeClassTest(String arg0)
59      {
60          super(arg0);
61      }
62  
63      /*
64       * Class to test for TypeClass getTypeClass(String)
65       */
66      public void testGetTypeClassString()
67      {
68          assertEquals( TypeClass.APPLICATION, TypeClass.getTypeClass(
69                          TypeClass.APPLICATION.getName() ) ) ;
70          assertEquals( TypeClass.UNIVERSAL, TypeClass.getTypeClass( 
71                          TypeClass.UNIVERSAL.getName() ) ) ;
72          assertEquals( TypeClass.PRIVATE, TypeClass.getTypeClass( 
73                          TypeClass.PRIVATE.getName() ) ) ;
74          assertEquals( TypeClass.CONTEXT_SPECIFIC, TypeClass.getTypeClass( 
75                          TypeClass.CONTEXT_SPECIFIC.getName() ) ) ;
76  
77          assertEquals( TypeClass.APPLICATION, TypeClass.getTypeClass( 
78                          "application") ) ;
79          assertEquals( TypeClass.UNIVERSAL, TypeClass.getTypeClass( 
80                          "Universal" ) ) ;
81          assertEquals( TypeClass.PRIVATE, TypeClass.getTypeClass( 
82                          "PRivatE" ) ) ;
83          assertEquals( TypeClass.CONTEXT_SPECIFIC, TypeClass.getTypeClass( 
84                          "context_specific" ) ) ;
85          
86          try
87          {
88              TypeClass.getTypeClass( "asdf" ) ;
89              fail( "exception should prevent this failure" ) ;
90          }
91          catch ( Throwable t )
92          { 
93              assertNotNull( t ) ;
94          }
95      }
96  
97      /*
98       * Class to test for TypeClass getTypeClass(int)
99       */
100     public void testGetTypeClassint()
101     {
102         assertEquals( TypeClass.APPLICATION, TypeClass.getTypeClass( 
103                         TypeClass.APPLICATION_VAL ) ) ;
104         assertEquals( TypeClass.PRIVATE, TypeClass.getTypeClass( 
105                         TypeClass.PRIVATE_VAL ) ) ;
106         assertEquals( TypeClass.UNIVERSAL, TypeClass.getTypeClass( 
107                         TypeClass.UNIVERSAL_VAL ) ) ;
108         assertEquals( TypeClass.CONTEXT_SPECIFIC, TypeClass.getTypeClass( 
109                         TypeClass.CONTEXT_SPECIFIC_VAL ) ) ;
110         
111         try
112         {
113             TypeClass.getTypeClass( 35 ) ;
114             fail( "exception should prevent this failure" ) ;
115         }
116         catch( Throwable t )
117         {
118             assertNotNull( t ) ;
119         }
120     }
121 }