1   /********************************************************************************
2    * InternetCafe is a software solution that helps the management of Cybercafes 
3    * according with the ITALIAN DECREE LAW ON ANTI-TERROR MEASURES, 27 JULY 2005.
4    * Copyright (C) 2006  Guido Angelo Ingenito
5   
6    * This program is free software; you can redistribute it and/or
7    * modify it under the terms of the GNU General Public License
8    * as published by the Free Software Foundation; either version 2
9    * of the License, or (at your option) any later version.
10  
11   * This program is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU General Public License for more details.
15   * 
16   * You should have received a copy of the GNU General Public License
17   * along with this program; if not, write to the Free Software
18   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19   *******************************************************************************/
20  
21  package test.base.user.JCard;
22  
23  import java.io.FileInputStream;
24  
25  import junit.framework.TestCase;
26  import base.user.jcard.Birthdate;
27  import base.user.jcard.ElectronicMail;
28  import base.user.jcard.JCard;
29  import base.user.jcard.Name;
30  
31  public class JCardTest extends TestCase {
32  
33  	public static void main(String[] args) {
34  		junit.textui.TestRunner.run(JCardTest.class);
35  	}
36  
37  	/*
38  	 * Tests end to end functionality of the JCard API
39  	 */
40  	public void testEnd2End() {
41  		try {
42  			// Create the card
43  			JCard jcard = new JCard();
44  			
45  			Name name = (Name) jcard.addProperty("NAME");
46  			name.setGivenName("Lokesh");
47  			System.out.println(name.toString());
48  			
49  			Birthdate birthday = (Birthdate) jcard.addProperty("BIRTHDATE");
50  			birthday.setBirthdate(1980, 12, 11);
51  			
52  			ElectronicMail email = (ElectronicMail) jcard.addProperty("EMAIL");
53  			email.setEmailAddress("lokeshrj@users.sourceforge.net");
54  			
55  			jcard.write("testcard.vcf");
56  			
57  			// Read the card from file system, and verify the contents
58  			FileInputStream fis = new FileInputStream("testcard.vcf");
59  			byte[] b = new byte[fis.available()];
60  			fis.read(b);
61  			String result = new String(b);
62  			
63  			String expected = new String("BEGIN:VCARD\r\nVERSION:2.1\r\nN:;Lokesh;;;\r\nBDAY:1980-12-11\r\nEMAIL;INTERNET:lokeshrj@users.sourceforge.net\r\nEND:VCARD");
64  			
65  			assertEquals(expected, result);
66  		}
67  		catch(Exception e) {
68  			e.printStackTrace();
69  			assertTrue(false);
70  		}
71  	}
72  	
73  	/*
74  	 * Test method for 'test.base.user.JCard.JCard.addProperty(String)'
75  	 */
76  	public void testAddProperty() {
77  		
78  	}
79  
80  	/*
81  	 * Test method for 'test.base.user.JCard.JCard.toString()'
82  	 */
83  	public void testToString() {
84  
85  	}
86  
87  }