TestJarSynchroUpdate.java

00001 /*
00002  * OpenMobileIS - a free Java(TM) Framework for mobile applications Java(TM)
00003  * Copyright (C) 2004-2009 Philippe Delrieu
00004  * All rights reserved.
00005  * Contact: pdelrieu@openmobileis.org
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this library; if not, write to the Free Software
00019  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00020  * USA
00021  *
00022  *  Author : Philippe Delrieu
00023  * 
00024  */
00025 
00026 package org.openmobileis.module.test;
00027 
00028 import java.io.File;
00029 import java.util.Enumeration;
00030 import java.util.Properties;
00031 
00032 import junit.framework.Assert;
00033 
00034 import org.openmobileis.bundle.update.server.FullAppUpdateSynchroTarget;
00035 import org.openmobileis.bundle.update.terminal.FullAppUpdateListener;
00036 import org.openmobileis.common.context.SessionContext;
00037 import org.openmobileis.common.context.SessionContextManager;
00038 import org.openmobileis.common.user.UserManager;
00039 import org.openmobileis.common.util.PropertiesManager;
00040 import org.openmobileis.common.util.log.LogManager;
00041 import org.openmobileis.synchro.client.SynchroDescriptor;
00042 import org.openmobileis.synchro.security.auth.Credential;
00043 import org.openmobileis.test.mock.common.MockUserManagerFactory;
00044 import org.openmobileis.test.mock.synchro.SimpleMockSynchroManager;
00045 
00050 public final class TestJarSynchroUpdate {
00051 
00055         public TestJarSynchroUpdate() {
00056                 // TODO Auto-generated constructor stub
00057         }
00058 
00062   public void testJarSynchro() {
00063     try {
00064 
00065         LogManager.registerLogManager(null);
00066         Properties props = System.getProperties();
00067         Enumeration enume = props.keys();
00068         while (enume.hasMoreElements()){
00069                 String key = (String) enume.nextElement();
00070                 String value = props.getProperty(key);
00071                 LogManager.traceDebug(0, "Key :"+key+" -> "+value);
00072         }
00073         
00074         //java.home, java.class.path
00075         
00076         File removeFile = new File(System.getProperty("user.dir") + "/WEB-INF/conf/misc.properties");
00077         if (removeFile.exists()) removeFile.delete();
00078         
00079       //init db properties.
00080       PropertiesManager.getManager().addProperty("fastobjectdb.database.path", System.getProperty("user.dir") + "/database");
00081       PropertiesManager.getManager().addProperty("fastobjectdb.database.name", "testdb");
00082 
00083       Credential cred = new Credential("test", "test");
00084       UserManager.getManager().registerUserManagerFactoryForGroup("defgroup", new MockUserManagerFactory("defgroup", "defname", cred));
00085 
00086       //manage session
00087       SessionContext context = SessionContextManager.getManager().createSessionContext("testsession");
00088       SessionContextManager.getManager().joinSessionContext("testsession");
00089       context.setUserGroup("defgroup");
00090       context.setUserId("defname");
00091 
00092       String synchroInstallPath = System.getProperty("user.dir") + "/synchro";
00093       SimpleMockSynchroManager synchromock = new SimpleMockSynchroManager(synchroInstallPath);
00094       FullAppUpdateListener listener = new FullAppUpdateListener();
00095       FullAppUpdateSynchroTarget target = new FullAppUpdateSynchroTarget(new File(System.getProperty("user.dir")+"/../server/updatefile.jar"));
00096       synchromock.registerTerminalSynchroListener(listener);
00097       synchromock.registerServerSynchroTarget(target);
00098       synchromock.synchronize("defgroup", cred, new SynchroDescriptor());
00099 
00100     } catch (Exception ex) {
00101       LogManager.traceError(0, ex);
00102       Assert.fail("Exception occurs during testXmlModuleParser :" + ex.getMessage());
00103     }
00104 
00105   }
00106 
00110         public static void main(String[] args) {
00111                 TestJarSynchroUpdate test = new TestJarSynchroUpdate();
00112                 test.testJarSynchro();
00113 
00114         }
00115 
00116 }

Generated on Mon Jan 11 21:19:17 2010 for OpenMobileIS by  doxygen 1.5.4