01: /*
02: * Conditions Of Use
03: *
04: * This software was developed by employees of the National Institute of
05: * Standards and Technology (NIST), and others.
06: * This software is has been contributed to the public domain.
07: * As a result, a formal license is not needed to use the software.
08: *
09: * This software is provided "AS IS."
10: * NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED
11: * OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF
12: * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT
13: * AND DATA ACCURACY. NIST does not warrant or make any representations
14: * regarding the use of the software or the results thereof, including but
15: * not limited to the correctness, accuracy, reliability or usefulness of
16: * the software.
17: *
18: *
19: */
20: /*
21: * Created on Jul 27, 2004
22: *
23: *The Open SLEE project
24: */
25: package test.unit.gov.nist.javax.sip.parser;
26:
27: import gov.nist.javax.sip.parser.HeaderParser;
28: import gov.nist.javax.sip.header.ContactList;
29: import gov.nist.javax.sip.header.SIPHeader;
30: import junit.framework.*;
31: import java.lang.reflect.*;
32: import java.util.Iterator;
33:
34: import javax.sip.header.ContactHeader;
35:
36: /**
37: * Superclass for all test cases in this directory. The printlns will be
38: * replaced with logger calls.
39: *
40: */
41: public abstract class ParserTestCase extends TestCase {
42:
43: private HeaderParser createParser(Class parserClass, String header) {
44: try {
45: Constructor constructor = parserClass
46: .getConstructor(new Class[] { String.class });
47: return (HeaderParser) constructor
48: .newInstance(new String[] { header });
49: } catch (Exception ex) {
50: ex.printStackTrace();
51: System.out.println("fatal error");
52: }
53: return null;
54: }
55:
56: protected void setUp() throws Exception {
57: super .setUp();
58: System.out.println("start " + getClass().getName());
59: }
60:
61: protected void tearDown() throws Exception {
62: super .tearDown();
63: System.out.println("done " + getClass().getName());
64: }
65:
66: protected void testParser(Class parserClass, String[] headers) {
67: try {
68: for (int i = 0; i < headers.length; i++) {
69: System.out.print(headers[i]);
70: HeaderParser hp = createParser(parserClass, headers[i]);
71: SIPHeader hdr = (SIPHeader) hp.parse();
72:
73: hp = createParser(parserClass,
74: ((SIPHeader) hdr.clone()).encode().trim()
75: + "\n");
76: System.out.println(hdr.encode());
77: assertEquals(hdr, hp.parse());
78:
79: }
80: } catch (java.text.ParseException ex) {
81: ex.printStackTrace();
82: fail(getClass().getName());
83: } catch (Exception e) {
84: e.printStackTrace();
85: fail("Unexpected exception " + getClass().getName());
86: System.exit(0);
87: }
88: }
89:
90: public abstract void testParser();
91:
92: }
|