1 /* GroupDAV connector for Funambol v6.5
2 * Copyright (C) 2007 Mathew McBride
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Affero General Public License as
6 * published by the Free Software Foundation, either version 3 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Affero General Public License for more details.
14 * You should have received a copy of the GNU Affero General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 package net
.bionicmessage
.funambol
.datakit
;
19 import com
.funambol
.common
.pim
.calendar
.Calendar
;
20 import com
.funambol
.common
.pim
.converter
.VCalendarConverter
;
21 import com
.funambol
.common
.pim
.model
.VCalendar
;
22 import com
.funambol
.common
.pim
.sif
.SIFCalendarParser
;
23 import com
.funambol
.common
.pim
.xvcalendar
.XVCalendarParser
;
24 import com
.funambol
.framework
.engine
.source
.SyncContext
;
25 import com
.funambol
.framework
.security
.Sync4jPrincipal
;
26 import java
.io
.ByteArrayInputStream
;
28 import java
.io
.FileInputStream
;
29 import java
.util
.Properties
;
30 import org
.apache
.commons
.codec
.binary
.Base64
;
31 import org
.junit
.After
;
32 import org
.junit
.AfterClass
;
33 import org
.junit
.Before
;
34 import org
.junit
.BeforeClass
;
35 import org
.junit
.Test
;
36 import static org
.junit
.Assert
.*;
42 public class funambol2ical4jTest
{
44 public funambol2ical4jTest() {
48 public static void setUpClass() throws Exception
{
52 public static void tearDownClass() throws Exception
{
60 public void tearDown() {
64 public void testNokiaMemo() throws Exception
{
66 File testFile
= new File("doc/problem-samples/nokia-memo.vcs");
67 FileInputStream fis
= new FileInputStream(testFile
);
68 XVCalendarParser vcp
= new XVCalendarParser(fis
);
69 VCalendar vc
= vcp
.XVCalendar();
70 VCalendarConverter vcf
= new VCalendarConverter(null, "UTF-8");
71 Calendar cal
= vcf
.vcalendar2calendar(vc
);
72 Properties fakeSyncSourceProps
= new Properties();
73 Sync4jPrincipal spp
= Sync4jPrincipal
.createPrincipal("user", "testid");
74 String passString
= "user:pass";
75 String encodedPassString
= new String(Base64
.encodeBase64(passString
.getBytes()));
76 spp
.setEncodedUserPwd(encodedPassString
);
77 SyncContext ctx
= new SyncContext(spp
, 0, null, null, 0);
78 net
.fortuna
.ical4j
.model
.Calendar ical4jcal
=
79 funambol2ical4j
.convertFunambolEvent2ical4jEvent(cal
, fakeSyncSourceProps
, ctx
);
80 String output
= ical4jcal
.toString();
81 System
.out
.print(output
);
85 public void testCategoryParse() throws Exception
{
87 File testFile
= new File("doc/problem-samples/category.vcs");
88 FileInputStream fis
= new FileInputStream(testFile
);
89 XVCalendarParser vcp
= new XVCalendarParser(fis
);
90 VCalendar vc
= vcp
.XVCalendar();
91 VCalendarConverter vcf
= new VCalendarConverter(null, "UTF-8");
92 Calendar cal
= vcf
.vcalendar2calendar(vc
);
93 Properties fakeSyncSourceProps
= new Properties();
94 Sync4jPrincipal spp
= Sync4jPrincipal
.createPrincipal("user", "testid");
95 String passString
= "user:pass";
96 String encodedPassString
= new String(Base64
.encodeBase64(passString
.getBytes()));
97 spp
.setEncodedUserPwd(encodedPassString
);
98 SyncContext ctx
= new SyncContext(spp
, 0, null, null, 0);
99 net
.fortuna
.ical4j
.model
.Calendar ical4jcal
=
100 funambol2ical4j
.convertFunambolEvent2ical4jEvent(cal
, fakeSyncSourceProps
, ctx
);
101 String output
= ical4jcal
.toString();
102 System
.out
.print(output
);
105 /** Prototype testcase used to test modifications needed to parse description
106 * text from Synthesis correctly
108 public void testX() throws Exception
{
110 File testFile
= new File("doc/problem-samples/complicated-comment.vcs");
111 FileInputStream fis
= new FileInputStream(testFile
);
112 byte[] data
= new byte[(int)testFile
.length()];
114 String dataString
= new String(data
, "UTF-8");
115 dataString
= dataString
.replace("=0D=0A=\r\n\r\nDTSTART", "\r\nDTSTART");
116 String debugString
= dataString
.replace("\r","xR").replace("\n","xN");
117 byte[] newData
= dataString
.getBytes("UTF-8");
118 ByteArrayInputStream bis
= new ByteArrayInputStream(newData
);
119 XVCalendarParser vcp
= new XVCalendarParser(bis
);
120 VCalendar vc
= vcp
.XVCalendar();
121 VCalendarConverter vcf
= new VCalendarConverter(null, "UTF-8");
122 Calendar cal
= vcf
.vcalendar2calendar(vc
);
123 Properties fakeSyncSourceProps
= new Properties();
124 Sync4jPrincipal spp
= Sync4jPrincipal
.createPrincipal("user", "testid");
125 String passString
= "user:pass";
126 String encodedPassString
= new String(Base64
.encodeBase64(passString
.getBytes()));
127 spp
.setEncodedUserPwd(encodedPassString
);
128 SyncContext ctx
= new SyncContext(spp
, 0, null, null, 0);
129 net
.fortuna
.ical4j
.model
.Calendar ical4jcal
=
130 funambol2ical4j
.convertFunambolEvent2ical4jEvent(cal
, fakeSyncSourceProps
, ctx
);
131 String output
= ical4jcal
.toString();
132 System
.out
.print(output
);
135 public void testSIFAllDay() throws Exception
{
137 File testFile
= new File("doc/problem-samples/SIFAllDay.xml");
138 FileInputStream fis
= new FileInputStream(testFile
);
139 SIFCalendarParser scp
= new SIFCalendarParser(fis
);
140 Calendar cal
= scp
.parse();
141 Properties fakeSyncSourceProps
= new Properties();
142 Sync4jPrincipal spp
= Sync4jPrincipal
.createPrincipal("user", "testid");
143 String passString
= "user:pass";
144 String encodedPassString
= new String(Base64
.encodeBase64(passString
.getBytes()));
145 spp
.setEncodedUserPwd(encodedPassString
);
146 SyncContext ctx
= new SyncContext(spp
, 0, null, null, 0);
147 net
.fortuna
.ical4j
.model
.Calendar ical4jcal
=
148 funambol2ical4j
.convertFunambolEvent2ical4jEvent(cal
, fakeSyncSourceProps
, ctx
);
149 String output
= ical4jcal
.toString();
150 System
.out
.print(output
);