From 2f98c996ee6c84c0c83b9d68741aeee8ecdf75c7 Mon Sep 17 00:00:00 2001 From: Mathew McBride Date: Mon, 3 Dec 2007 12:42:11 +1100 Subject: [PATCH] Test for Calendar Sync Source --- .../groupdav/calendar/CalendarSyncSourceTest.java | 165 +++++++++++++++++++++ 1 file changed, 165 insertions(+) create mode 100644 test_src/net/bionicmessage/funambol/groupdav/calendar/CalendarSyncSourceTest.java diff --git a/test_src/net/bionicmessage/funambol/groupdav/calendar/CalendarSyncSourceTest.java b/test_src/net/bionicmessage/funambol/groupdav/calendar/CalendarSyncSourceTest.java new file mode 100644 index 0000000..ea9a27e --- /dev/null +++ b/test_src/net/bionicmessage/funambol/groupdav/calendar/CalendarSyncSourceTest.java @@ -0,0 +1,165 @@ +/* + * CalendarSyncSourceTest.java + * JUnit 4.x based test + * + * Created on July 26, 2007, 5:44 PM + */ +package net.bionicmessage.funambol.groupdav.calendar; + +import com.funambol.framework.engine.SyncItem; +import com.funambol.framework.engine.SyncItemImpl; +import com.funambol.framework.engine.SyncItemKey; +import com.funambol.framework.engine.source.ContentType; +import com.funambol.framework.engine.source.SyncContext; +import com.funambol.framework.engine.source.SyncSourceInfo; +import com.funambol.framework.security.Sync4jPrincipal; +import java.io.File; +import java.io.FileInputStream; +import java.util.Properties; +import junit.framework.JUnit4TestAdapter; +import net.bionicmessage.funambol.framework.Constants; +import net.bionicmessage.funambol.groupdav.calendar.CalendarSyncSource; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import static org.junit.Assert.*; +import org.apache.commons.codec.binary.Base64; +/** + * + * @author matt + */ + +public class CalendarSyncSourceTest { + + private String clientId = "STATIC-TEST"; + private String testPropertiesFile = ".groupdavconnector_test_properties"; + private CalendarSyncSource css = null; + private SyncContext ctx = null; + private Sync4jPrincipal spp = null; + private Properties testProps = null; + + public CalendarSyncSourceTest() { + } + + @BeforeClass + public static void setUpClass() throws Exception { + } + + @AfterClass + public static void tearDownClass() throws Exception { + } + + @Before + public void setUp() throws Exception { + // Load a properties file from the local user dir + String testPropsPath = System.getProperty("user.home") + System.getProperty("file.separator") + testPropertiesFile; + testProps = new Properties(); + testProps.load(new FileInputStream(new File(testPropsPath))); + css = new CalendarSyncSource(); + String storePath = System.getProperty("java.io.tmpdir") + System.getProperty("file.separator") + "calendarsyncsource-test"; + Properties props = new Properties(); + props.setProperty(Constants.STOREDIR_PATH, storePath); + props.setProperty(Constants.SOURCE_LOCATION_BASE + "default", testProps.getProperty("connector.sources.default")); + props.setProperty(Constants.SERVER_HOST, testProps.getProperty("connector.serverhost")); + css.setConnectorProperties(props); + spp = Sync4jPrincipal.createPrincipal(props.getProperty("test.user"), "testid"); + String passString = String.format("%s:%s", testProps.getProperty("test.user"), + testProps.getProperty("test.password")); + String encodedPassString = new String(Base64.encodeBase64(passString.getBytes())); + spp.setEncodedUserPwd(encodedPassString); + ctx = new SyncContext(spp, 0, null, null, 0); + SyncSourceInfo ssInfo = new SyncSourceInfo(); + ContentType vcard = new ContentType(); + vcard.setType("text/x-vcalendar"); + vcard.setVersion("1.0"); + ContentType[] supported = new ContentType[1]; + supported[0] = vcard; + ssInfo.setSupportedTypes(supported); + ssInfo.setPreferred(0); + css.setInfo(ssInfo); + } + + @After + public void tearDown() throws Exception { + } + + /** The tests below are in a series of 'easiest' to 'i can't believe its not + * a human' */ + @Test + public void beginSlowAndEnd() throws Exception { + ctx = new SyncContext(spp, 201, null, null, 0); + css.beginSync(ctx); + css.endSync(); + } + + @Test + public void beginSlowGetAllSyncItemKeysEnd() throws Exception { + ctx = new SyncContext(spp, 201, null, null, 0); + css.beginSync(ctx); + SyncItemKey[] all = css.getAllSyncItemKeys(); + for (int i = 0; i < all.length; i++) { + SyncItemKey syncItemKey = all[i]; + SyncItemKey[] indiv = new SyncItemKey[1]; + indiv[0] = syncItemKey; + System.out.printf("New/updated Key: %s\n", syncItemKey.getKeyAsString()).flush(); + css.setOperationStatus("Add", 201, indiv); + } + css.endSync(); + } + + @Test + public void beginSlowGetAllSyncItemKeysGetItemsVcalEnd() throws Exception { + ctx = new SyncContext(spp, 201, null, null, 0); + css.setType("text/x-vcalendar"); // to fix later + css.beginSync(ctx); + SyncItemKey[] all = css.getAllSyncItemKeys(); + for (int i = 0; i < all.length; i++) { + SyncItemKey syncItemKey = all[i]; + System.out.printf("New/updated Key: %s\n", syncItemKey.getKeyAsString()).flush(); + SyncItem si = css.getSyncItemFromId(syncItemKey); + String contents = new String(si.getContent()); + System.out.printf("Contents: %s\n------\n", contents).flush(); + } + css.endSync(); + } + + @Test + public void beginNormalAddItem() throws Exception { + ctx = new SyncContext(spp, 200, null, null, 0); + css.setType("text/x-vcalendar"); + css.beginSync(ctx); + File problemSample = new File("doc/problem-samples/synthesis-quoted-printable-example.txt"); + FileInputStream fis = new FileInputStream(problemSample); + byte[] data = new byte[fis.available()]; + fis.read(data); + fis.close(); + SyncItemImpl sync = new SyncItemImpl(css, "testitem-calsourcetest"); + sync.setContent(data); + sync.setType("text/x-vcalendar"); + SyncItem result = css.addSyncItem(sync); + byte[] newdata = result.getContent(); + String resdata = new String(newdata); + String resuid = result.getKey().getKeyAsString(); + System.out.printf("Returned from addSyncItem: %s\n, UID: %s\n", resdata, resuid).flush(); + // Write a temp file + System.setProperty("calsyncsourcetest.beginslowadditem.resuid", resuid); + css.endSync(); + } + + @Test + public void beginNormalDeleteItem() throws Exception { + ctx = new SyncContext(spp, 200, null, null, 0); + css.setType("text/x-vcalendar"); + css.beginSync(ctx); + String uid = System.getProperty("calsyncsourcetest.beginslowadditem.resuid"); + css.removeSyncItem(new SyncItemKey(uid), null, false); + System.out.printf("Removed item %s from server\n", uid); + css.endSync(); + } + + public static junit.framework.Test suite() { + return new JUnit4TestAdapter(CalendarSyncSourceTest.class); + } +} \ No newline at end of file -- 2.11.4.GIT