TestBaseProfil.java

00001 
00025 package org.openmobileis.test.bundle.profil;
00026 
00027 import java.io.File;
00028 import java.io.FileReader;
00029 import java.io.InputStreamReader;
00030 import java.io.Reader;
00031 
00032 import org.openmobileis.bundle.coldupdate.server.ColdUpdateModuleLoader;
00033 import org.openmobileis.common.context.SessionContext;
00034 import org.openmobileis.common.context.SessionContextManager;
00035 import org.openmobileis.common.user.UserManager;
00036 import org.openmobileis.common.user.profile.Profile;
00037 import org.openmobileis.common.user.profile.ProfileDataManager;
00038 import org.openmobileis.common.user.profile.ProfileProperty;
00039 import org.openmobileis.common.user.profile.ProfileService;
00040 import org.openmobileis.common.util.PropertiesManager;
00041 import org.openmobileis.common.util.collection.Array;
00042 import org.openmobileis.common.util.file.FileUtilities;
00043 import org.openmobileis.common.util.log.LogManager;
00044 import org.openmobileis.module.core.DependProfileModule;
00045 import org.openmobileis.module.core.ProfileModule;
00046 import org.openmobileis.module.core.ProfileModuleSynchroListener;
00047 import org.openmobileis.module.core.XmlModuleParser;
00048 import org.openmobileis.module.profiles.server.ProfilManagerSyncTarget;
00049 import org.openmobileis.module.profiles.terminal.OpenMSPProfileSyncListener;
00050 import org.openmobileis.module.profiles.terminal.TerminalXmlProfilParser;
00051 import org.openmobileis.module.server.ModuleJarSynchroTarget;
00052 import org.openmobileis.module.terminal.ModuleJarSyncListener;
00053 import org.openmobileis.module.terminal.ModuleManager;
00054 import org.openmobileis.synchro.client.SynchroDescriptor;
00055 import org.openmobileis.synchro.client.SynchroManager;
00056 import org.openmobileis.synchro.openmsp.client.OpenMSPSynchroManager;
00057 import org.openmobileis.synchro.openmsp.client.conduit.HttpOpenMSPSynchroConduit;
00058 import org.openmobileis.synchro.openmsp.client.conduit.LocalOpenMSPSynchroConduit;
00059 import org.openmobileis.synchro.openmsp.server.synctarget.SynchroTargerManager;
00060 import org.openmobileis.synchro.openmsp.server.synctarget.proxy.GenericProxySynchroTarget;
00061 import org.openmobileis.synchro.security.auth.Credential;
00062 import org.openmobileis.test.mock.common.MockUserManagerFactory;
00063 import org.openmobileis.test.mock.synchro.SimpleMockSynchroManager;
00064 
00065 import junit.framework.Assert;
00066 import junit.framework.TestCase;
00067 
00068 /*
00069  * Title:        OpenMobileIS project source <BR>
00070  * Description:
00071  * @author      Philippe Delrieu
00072  * @since       JDK 1.1
00073  * @version 1.0.
00074  */
00075 
00076 public class TestBaseProfil extends TestCase {
00077 
00081   public TestBaseProfil(String name) {
00082     super(name);
00083   }
00084 
00085   /* (non-Javadoc)
00086    * @see junit.framework.TestCase#setUp()
00087    */
00088   protected void setUp() throws Exception {
00089     super.setUp();
00090     LogManager.registerLogManager(null);
00091   }
00092 
00093   /* (non-Javadoc)
00094    * @see junit.framework.TestCase#tearDown()
00095    */
00096   protected void tearDown() throws Exception {
00097     super.tearDown();
00098   }
00099 
00103   public void testXmlModuleParser() {
00104     try {
00105       Reader reader = new InputStreamReader(PropertiesManager.getManager().getRessourceAsStream("/org/openmobileis/test/bundle/profil/testmodule.xml"));
00106       XmlModuleParser parser = new XmlModuleParser(reader);
00107       parser.parse();
00108       //validate parsing
00109       ProfileModule module = parser.getModuletoload();
00110       Assert.assertEquals("TEST", module.getName());
00111       Assert.assertEquals("1.0.0", module.getVersion());
00112       Assert.assertEquals("testsnchro.jar", module.getServerjar());
00113       Assert.assertEquals("testterminal.jar", module.getTerminaljar());
00114       Array deplist = module.getDependModuleList();
00115       Assert.assertTrue(deplist.contains(new DependProfileModule("openMobileIS", "1.0.0")));
00116 
00117       Array rubriclist = module.getModuleRubrics();
00118 
00119       //testrub1
00120       ProfileModuleRubric rub1 = (ProfileModuleRubric) rubriclist.get(0);
00121       Assert.assertEquals("testrub1", rub1.getName());
00122       Assert.assertEquals("testloader1", rub1.getLoaderClass());
00123       Assert.assertTrue(rub1.getDependsList().length == 0);
00124       Array synclist = rub1.getSynchroListenerList();
00125       ProfileModuleSynchroListener sync = (ProfileModuleSynchroListener) synclist.get(0);
00126       Assert.assertEquals("listerner1", sync.name);
00127       Assert.assertNull(sync.dependsList);
00128       sync = (ProfileModuleSynchroListener) synclist.get(1);
00129       Assert.assertEquals("listerner3", sync.name);
00130       Assert.assertNull(sync.dependsList);
00131       sync = (ProfileModuleSynchroListener) synclist.get(2);
00132       Assert.assertEquals("listerner2", sync.name);
00133       Assert.assertNotNull(sync.dependsList);
00134       Assert.assertEquals("listerner1", sync.dependsList[0]);
00135       Assert.assertEquals("listerner3", sync.dependsList[1]);
00136       Assert.assertNotNull(rub1.getProperty("description"));
00137       Assert.assertEquals("Test rubric loader", rub1.getProperty("description"));
00138 
00139       //testrub2
00140       rub1 = (ProfileModuleRubric) rubriclist.get(1);
00141       Assert.assertEquals("testrub2", rub1.getName());
00142       String[] deprublist = rub1.getDependsList();
00143       Assert.assertEquals("testrub1", deprublist[0]);
00144       Assert.assertEquals("testloader21", rub1.getLoaderClass());
00145       synclist = rub1.getSynchroListenerList();
00146       sync = (ProfileModuleSynchroListener) synclist.get(0);
00147       Assert.assertEquals("listerner1", sync.name);
00148       Assert.assertNull(sync.dependsList);
00149 
00150       //testrub3
00151       rub1 = (ProfileModuleRubric) rubriclist.get(2);
00152       Assert.assertEquals("testrub3", rub1.getName());
00153       deprublist = rub1.getDependsList();
00154       Assert.assertEquals("testrub1", deprublist[0]);
00155       Assert.assertEquals("testrub2", deprublist[1]);
00156       Assert.assertEquals("testloader3", rub1.getLoaderClass());
00157       synclist = rub1.getSynchroListenerList();
00158       sync = (ProfileModuleSynchroListener) synclist.get(0);
00159       Assert.assertEquals("listerner31", sync.name);
00160       Assert.assertNull(sync.dependsList);
00161 
00162     } catch (Exception ex) {
00163       Assert.fail("Exception occurs during testXmlModuleParser :" + ex.getMessage());
00164     }
00165   }
00166 
00170   public void testTerminalProfilParser() {
00171     try {
00172       Reader reader = new InputStreamReader(PropertiesManager.getManager().getRessourceAsStream("/org/openmobileis/test/bundle/profil/testprofils.xml"));
00173       TerminalXmlProfilParser parser = new TerminalXmlProfilParser(reader);
00174       Profile profil = parser.getParsedProfil();
00175       Assert.assertEquals("defname", profil.profilName);
00176       //validate ribric
00177       Assert.assertEquals(profil.ProfileServices.length, 4);
00178 
00179       Assert.assertEquals("openMobileIS", profil.ProfileServices[0].moduleName);
00180       Assert.assertEquals("Core OpenMobileIS", profil.ProfileServices[0].serviceName);
00181       Assert.assertEquals("1.0.0", profil.ProfileServices[0].version);
00182       Assert.assertNull(profil.ProfileServices[0].description);
00183 
00184       Assert.assertEquals("TEST", profil.ProfileServices[1].moduleName);
00185       Assert.assertEquals("testrub1", profil.ProfileServices[1].serviceName);
00186       Assert.assertEquals("1.0.0", profil.ProfileServices[1].version);
00187       Assert.assertEquals("test desc", profil.ProfileServices[1].description);
00188 
00189       Assert.assertEquals("TEST", profil.ProfileServices[2].moduleName);
00190       Assert.assertEquals("testrub2", profil.ProfileServices[2].serviceName);
00191       Assert.assertEquals("test desc2", profil.ProfileServices[2].description);
00192       Assert.assertNull(profil.ProfileServices[2].version);
00193 
00194       Assert.assertEquals("TEST", profil.ProfileServices[3].moduleName);
00195       Assert.assertEquals("testrub3", profil.ProfileServices[3].serviceName);
00196       Assert.assertNull(profil.ProfileServices[3].version);
00197       Assert.assertNull(profil.ProfileServices[3].description);
00198 
00199       //validate property
00200       Assert.assertEquals(profil.profilProperties.length, 2);
00201       Assert.assertEquals("testkey1", profil.profilProperties[0].key);
00202       Assert.assertEquals("value1", profil.profilProperties[0].value);
00203       Assert.assertNull(profil.profilProperties[0].moduleName);
00204 
00205       Assert.assertEquals("testkey2", profil.profilProperties[1].key);
00206       Assert.assertEquals("value2", profil.profilProperties[1].value);
00207       Assert.assertEquals("TEST", profil.profilProperties[1].moduleName);
00208 
00209     } catch (Exception ex) {
00210       Assert.fail("Exception occurs during testXmlModuleParser :" + ex.getMessage());
00211     }
00212 
00213   }
00214 
00218   public void testProfilEquals() {
00219     try {
00220       Reader reader = new InputStreamReader(PropertiesManager.getManager().getRessourceAsStream("/org/openmobileis/test/bundle/profil/testprofils.xml"));
00221       TerminalXmlProfilParser parser = new TerminalXmlProfilParser(reader);
00222       Profile profil1 = parser.getParsedProfil();
00223 
00224       reader = new InputStreamReader(PropertiesManager.getManager().getRessourceAsStream("/org/openmobileis/test/bundle/profil/testprofils.xml"));
00225       parser = new TerminalXmlProfilParser(reader);
00226       Profile profil2 = parser.getParsedProfil();
00227 
00228       Assert.assertEquals(profil1, profil2);
00229 
00230       //test modif name
00231       profil2.profilName = "toto";
00232       Assert.assertNotSame(profil1, profil2);
00233       profil2.profilName = profil1.profilName;
00234       Assert.assertEquals(profil1, profil2);
00235 
00236       profil2.ProfileServices = new ProfileService[] { profil1.ProfileServices[0], profil1.ProfileServices[1], profil1.ProfileServices[2] };
00237       Assert.assertNotSame(profil1, profil2);
00238       profil2.ProfileServices = profil1.ProfileServices;
00239       Assert.assertEquals(profil1, profil2);
00240       profil2.ProfileServices[0].moduleName = "toto";
00241       Assert.assertNotSame(profil1, profil2);
00242       profil2.ProfileServices = profil1.ProfileServices;
00243       Assert.assertEquals(profil1, profil2);
00244       profil2.ProfileServices[0].serviceName = "toto";
00245       Assert.assertNotSame(profil1, profil2);
00246       profil2.ProfileServices = profil1.ProfileServices;
00247       Assert.assertEquals(profil1, profil2);
00248       profil2.ProfileServices[0].version = "toto";
00249       Assert.assertNotSame(profil1, profil2);
00250       profil2.ProfileServices = profil1.ProfileServices;
00251       Assert.assertEquals(profil1, profil2);
00252       profil2.ProfileServices[0].description = "toto";
00253       Assert.assertNotSame(profil1, profil2);
00254       profil2.ProfileServices = profil1.ProfileServices;
00255       Assert.assertEquals(profil1, profil2);
00256       profil2.ProfileServices[1].description = "toto";
00257       Assert.assertNotSame(profil1, profil2);
00258       profil2.ProfileServices = profil1.ProfileServices;
00259       Assert.assertEquals(profil1, profil2);
00260       profil2.ProfileServices[3].version = "toto";
00261       Assert.assertNotSame(profil1, profil2);
00262       profil2.ProfileServices = profil1.ProfileServices;
00263       Assert.assertEquals(profil1, profil2);
00264       profil2.ProfileServices[1].version = null;
00265       Assert.assertNotSame(profil1, profil2);
00266       profil2.ProfileServices = profil1.ProfileServices;
00267       Assert.assertEquals(profil1, profil2);
00268       profil2.ProfileServices[1].description = null;
00269       Assert.assertNotSame(profil1, profil2);
00270       profil2.ProfileServices = profil1.ProfileServices;
00271       Assert.assertEquals(profil1, profil2);
00272 
00273       profil2.profilProperties = new ProfileProperty[] { profil1.profilProperties[0] };
00274       Assert.assertNotSame(profil1, profil2);
00275       profil2.profilProperties = profil1.profilProperties;
00276       Assert.assertEquals(profil1, profil2);
00277       profil2.profilProperties[0].key = "toto";
00278       Assert.assertNotSame(profil1, profil2);
00279       profil2.profilProperties = profil1.profilProperties;
00280       Assert.assertEquals(profil1, profil2);
00281       profil2.profilProperties[0].value = "toto";
00282       Assert.assertNotSame(profil1, profil2);
00283       profil2.profilProperties = profil1.profilProperties;
00284       Assert.assertEquals(profil1, profil2);
00285       profil2.profilProperties[0].moduleName = "toto";
00286       Assert.assertNotSame(profil1, profil2);
00287       profil2.profilProperties = profil1.profilProperties;
00288       Assert.assertEquals(profil1, profil2);
00289       profil2.profilProperties[1].moduleName = "toto";
00290       Assert.assertNotSame(profil1, profil2);
00291       profil2.profilProperties = profil1.profilProperties;
00292       Assert.assertEquals(profil1, profil2);
00293       profil2.profilProperties[1].moduleName = null;
00294       Assert.assertNotSame(profil1, profil2);
00295       profil2.profilProperties = profil1.profilProperties;
00296       Assert.assertEquals(profil1, profil2);
00297 
00298     } catch (Exception ex) {
00299       Assert.fail("Exception occurs during testXmlModuleParser :" + ex.getMessage());
00300     }
00301 
00302   }
00303 
00307   public void testProfilSynchro() {
00308     try {
00309 
00310       String synchronizedProfilFile = System.getProperty("user.dir") + "/WEB-INF/conf/userprofil.xml";
00311       PropertiesManager.getManager().addProperty("org.openmobileis.profil.file", synchronizedProfilFile);
00312 
00313       //remove terminal files
00314       File file = new File(synchronizedProfilFile);
00315       if (file.exists())
00316         file.delete();
00317 
00318       //init db properties.
00319       PropertiesManager.getManager().addProperty("fastobjectdb.database.path", System.getProperty("user.dir") + "/database");
00320       PropertiesManager.getManager().addProperty("fastobjectdb.database.name", "testdb");
00321 
00322       Credential cred = new Credential("test", "test");
00323       UserManager.getManager().registerUserManagerFactoryForGroup("defgroup", new MockUserManagerFactory("defgroup", "defname", cred));
00324 
00325       Reader reader = new InputStreamReader(PropertiesManager.getManager().getRessourceAsStream("/org/openmobileis/test/bundle/profil/testprofils.xml"));
00326       TerminalXmlProfilParser serverprofilmanager = new TerminalXmlProfilParser(reader);
00327       ProfileDataManager.getManager().registerProfilDataFactoryForGroup("defgroup", serverprofilmanager);
00328 
00329       //manage session
00330       SessionContext context = SessionContextManager.getManager().createSessionContext("testsession");
00331       SessionContextManager.getManager().joinSessionContext("testsession");
00332       context.setUserGroup("defgroup");
00333       context.setUserId("defname");
00334 
00335       String synchroInstallPath = System.getProperty("user.dir") + "/synchro";
00336       SimpleMockSynchroManager synchromock = new SimpleMockSynchroManager(synchroInstallPath);
00337       OpenMSPProfileSyncListener listener = new OpenMSPProfileSyncListener();
00338       ProfilManagerSyncTarget target = new ProfilManagerSyncTarget();
00339       synchromock.registerTerminalSynchroListener(listener);
00340       synchromock.registerServerSynchroTarget(target);
00341       synchromock.synchronize("defgroup", cred, new SynchroDescriptor());
00342 
00343       //validate the created profil is the same as the server one.
00344       Profile serverprofil = serverprofilmanager.getParsedProfil();
00345       Reader termreader = new FileReader(synchronizedProfilFile);
00346       TerminalXmlProfilParser parser = new TerminalXmlProfilParser(termreader);
00347       Profile tremprofil = parser.getParsedProfil();
00348       Assert.assertEquals(serverprofil, tremprofil);
00349 
00350     } catch (Exception ex) {
00351       LogManager.traceError(0, ex);
00352       Assert.fail("Exception occurs during testXmlModuleParser :" + ex.getMessage());
00353     }
00354 
00355   }
00356 
00357   public void testJarSynchro() {
00358     try {
00359       //copy files needed for the test
00360       String basepath = System.getProperty("user.dir") + "/testfiles/testprofile/testjarsynchro/";
00361       String destPath = System.getProperty("user.dir") + "/repository/";
00362       FileUtilities.copyFile(basepath+"openmobileis.xml", destPath+"openmobileis.xml");
00363       FileUtilities.copyFile(basepath+"openmisclient.jar", destPath+"openmisclient.jar");
00364       FileUtilities.copyFile(basepath+"openmobileis.xml", System.getProperty("user.dir")+"/WEB-INF/conf/xml/openMobileIS.xml");
00365       
00366       //init server parameters.
00367       String xmlservermodulefile = System.getProperty("user.dir") + "/repository/openmobileis.xml";
00368       PropertiesManager.getManager().addProperty("org.openmobileis.bundle.module.repositorypath", System.getProperty("user.dir") + "/repository");
00369 
00370       //init terminal parameter
00371       PropertiesManager.getManager().addProperty("org.openmobileis.module.repository.jar", System.getProperty("user.dir") + "/WEB-INF/lib");
00372       PropertiesManager.getManager().addProperty("org.openmobileis.module.repository.xml", System.getProperty("user.dir") + "/WEB-INF/conf/xml");
00373       
00374       //test if the terminal jar and xml file exist. If yes delete them.
00375       File jarfile = new File(PropertiesManager.getManager().getProperty("org.openmobileis.module.repository.jar") + "/openmisclient.jar");
00376       if (jarfile.exists())
00377         jarfile.delete();
00378       File xmlffile = new File(PropertiesManager.getManager().getProperty("org.openmobileis.module.repository.xml") + "/openMobileIS.xml");
00379  //     if (xmlffile.exists())
00380  //       xmlffile.delete();
00381 
00382       //init context data
00383       Credential cred = new Credential("test", "test");
00384       UserManager.getManager().registerUserManagerFactoryForGroup("defgroup", new MockUserManagerFactory("defgroup", "defname", cred));
00385 
00386       Reader reader = new InputStreamReader(PropertiesManager.getManager().getRessourceAsStream("/org/openmobileis/test/bundle/profil/testprofils.xml"));
00387       TerminalXmlProfilParser serverprofilmanager = new TerminalXmlProfilParser(reader);
00388       ProfileDataManager.getManager().registerProfilDataFactoryForGroup("defgroup", serverprofilmanager);
00389 
00390       //manage session
00391       SessionContext context = SessionContextManager.getManager().createSessionContext("testsession");
00392       SessionContextManager.getManager().joinSessionContext("testsession");
00393       context.setUserGroup("defgroup");
00394       context.setUserId("defname");
00395       
00396       ProfileModule module = ModuleManager.getManager().readModuleXmlFiles("openMobileIS");
00397       ModuleJarSyncListener listener = new ModuleJarSyncListener();
00398       listener.setModule(module);
00399       ModuleJarSynchroTarget target = new ModuleJarSynchroTarget(new File(xmlservermodulefile));
00400 
00401       //init synchro path.
00402       String synchroInstallPath = System.getProperty("user.dir") + "/synchro";
00403       PropertiesManager.getManager().addProperty("org.openmobileis.synchro.direct.installpath", synchroInstallPath);
00404       SynchroDescriptor descriptor = new SynchroDescriptor();
00405         HttpOpenMSPSynchroConduit conduit = new HttpOpenMSPSynchroConduit();
00406         conduit.setSynchroPath(synchroInstallPath);
00407         conduit.setSynchroUserAgent("OpenMSPPlug-WI-V[1.0]-WINCE[DR-FR-WINCE/04-02-00-00]");
00408       descriptor.setSynchroConduit(conduit);
00409       SimpleMockSynchroManager synchromock = new SimpleMockSynchroManager(synchroInstallPath);
00410 
00411       synchromock.registerTerminalSynchroListener(listener);
00412       synchromock.registerServerSynchroTarget(target);
00413       synchromock.synchronize("defgroup", cred, descriptor);
00414 
00415       //validate synchronisation first synchro
00416       Assert.assertTrue(jarfile.exists());
00417       Assert.assertTrue(xmlffile.exists());
00418 
00419       //delete terminal xml and jar. do synchro  Test nothing synchronized.
00420       jarfile.delete();
00421       xmlffile.delete();
00422       synchromock.synchronize("defgroup", cred, descriptor);
00423       Assert.assertTrue(!jarfile.exists());
00424       Assert.assertTrue(!xmlffile.exists());
00425 
00426       //modif server xml date test file synchronized
00427       jarfile.delete();
00428       xmlffile.delete();
00429 
00430       File sxmlfile = new File(xmlservermodulefile);
00431       sxmlfile.setLastModified(new java.util.Date().getTime());
00432 
00433       //way 1 second
00434       Thread.currentThread().sleep(1000);
00435 
00436       synchromock.synchronize("defgroup", cred, descriptor);
00437       Assert.assertTrue(jarfile.exists());
00438       Assert.assertTrue(xmlffile.exists());
00439 
00440       //delete terminal xml and jar. Modif server jar . test file synchronized.
00441       jarfile.delete();
00442       xmlffile.delete();
00443       File sjarfile = new File(PropertiesManager.getManager().getProperty("org.openmobileis.bundle.module.repositorypath") + "/"
00444           + target.getProfilModule().getTerminaljar());
00445       sjarfile.setLastModified(new java.util.Date().getTime());
00446 
00447       //way 1 second
00448       Thread.currentThread().sleep(1000);
00449       synchromock.synchronize("defgroup", cred, descriptor);
00450       Assert.assertTrue(jarfile.exists());
00451       Assert.assertTrue(xmlffile.exists());
00452 
00453       // delete terminal jar Test noting synchronized.
00454       jarfile.delete();
00455       xmlffile.delete();
00456       synchromock.synchronize("defgroup", cred, descriptor);
00457       Assert.assertTrue(!jarfile.exists());
00458       Assert.assertTrue(!xmlffile.exists());
00459 
00460     } catch (Exception ex) {
00461       LogManager.traceError(0, ex);
00462       Assert.fail("Exception occurs during testXmlModuleParser :" + ex.getMessage());
00463     }
00464 
00465   }
00466 
00467   public void testCompleteProfilJarSynchro() {
00468     try {
00469       //copy files needed for the test
00470       String basepath = System.getProperty("user.dir") + "/testfiles/testprofile/testCompleteProfilJarSynchro/";
00471       String destPath = System.getProperty("user.dir");
00472       FileUtilities.copyFile(basepath+"openmobileis.xml", destPath+"/repository/openmobileis.xml");
00473       FileUtilities.copyFile(basepath+"openmisclient.jar", destPath+"/repository/openmisclient.jar");
00474       FileUtilities.copyFile(basepath+"mycrm.xml", destPath+"/repository/mycrm.xml");
00475       FileUtilities.copyFile(basepath+"mycrm.jar", destPath+"/repository/mycrm.jar");
00476       FileUtilities.copyFile(basepath+"initprofil.xml", destPath+"/WEB-INF/conf/userprofil.xml");
00477       FileUtilities.copyFile(basepath+"baseprofil.xml", destPath+"/server_conf/baseprofil.xml");
00478       //put base file to load openmis module.
00479       FileUtilities.copyFile(basepath+"openmobileis.xml", destPath+"/WEB-INF/module/xml/openMobileIS.xml");
00480 
00481       
00482       //DO ALL INIT
00483       //init profil path. Done because modified by other test, otherwise done by module manager
00484       String synchronizedProfilFile = System.getProperty("user.dir") + "/WEB-INF/conf/userprofil.xml";
00485       PropertiesManager.getManager().addProperty("org.openmobileis.profil.file", synchronizedProfilFile);
00486       //init db properties.
00487       PropertiesManager.getManager().addProperty("fastobjectdb.database.path", System.getProperty("user.dir") + "/database");
00488       PropertiesManager.getManager().addProperty("fastobjectdb.database.name", "testdb");
00489       //init server parameters.
00490  //     String xmlservermodulefile = System.getProperty("user.dir") + "/repository/openmobileis.xml";
00491       PropertiesManager.getManager().addProperty("org.openmobileis.bundle.module.repositorypath", System.getProperty("user.dir") + "/repository");
00492 
00493       //init terminal parameter
00494       //done by module manager
00495   //    PropertiesManager.getManager().addProperty("org.openmobileis.module.repository.jar", System.getProperty("user.dir") + "/WEB-INF/lib");
00496   //    PropertiesManager.getManager().addProperty("org.openmobileis.module.repository.xml", System.getProperty("user.dir") + "/WEB-INF/conf/xml");
00497 
00498       //test if the terminal jar and xml file exist. If yes delete them.
00499 
00500       //init context data
00501       Credential cred = new Credential("test", "test");
00502       UserManager.getManager().registerUserManagerFactoryForGroup("defgroup", new MockUserManagerFactory("defgroup", "defname", cred));
00503 
00504       Reader reader = new FileReader(System.getProperty("user.dir") + "/server_conf/baseprofil.xml");
00505       TerminalXmlProfilParser serverprofilmanager = new TerminalXmlProfilParser(reader);
00506       ProfileDataManager.getManager().registerProfilDataFactoryForGroup("defgroup", serverprofilmanager);
00507 
00508       //manage session
00509       SessionContext context = SessionContextManager.getManager().createSessionContext("testsession");
00510       SessionContextManager.getManager().joinSessionContext("testsession");
00511       context.setUserGroup("defgroup");
00512       context.setUserId("defname");
00513       
00514       //init module management
00515       TestModuleManagerListener moduleManagerListenernew  = new TestModuleManagerListener();
00516       //delete synchro files
00517       PropertiesManager.getManager().addProperty("org.openmobileis.module.repository.jar", moduleManagerListenernew.getJarInstallPath());
00518       PropertiesManager.getManager().addProperty("org.openmobileis.module.repository.xml", moduleManagerListenernew.getXMLInstallPath());
00519       File todeletefile = new File(PropertiesManager.getManager().getProperty("org.openmobileis.module.repository.jar")+"/openmisclient.jar");
00520       todeletefile.delete();
00521       todeletefile = new File(PropertiesManager.getManager().getProperty("org.openmobileis.module.repository.xml")+"/openMobileIS.xml");
00522       todeletefile.delete();
00523       todeletefile = new File(PropertiesManager.getManager().getProperty("org.openmobileis.module.repository.jar")+"/mycrm.jar");
00524       todeletefile.delete();
00525       todeletefile = new File(PropertiesManager.getManager().getProperty("org.openmobileis.module.repository.xml")+"/MyCRM.xml");
00526       todeletefile.delete();
00527       ModuleManager.getManager().registerModuleManagerListener(moduleManagerListenernew);
00528       ModuleManager.getManager().initModule();
00529       Assert.assertNotNull(moduleManagerListenernew.loadedModuleNames[0]);
00530       Assert.assertEquals("openMobileIS", moduleManagerListenernew.loadedModuleNames[0].getName());
00531       
00532       //init synchro
00533       String synchroInstallPath = System.getProperty("user.dir") + "/synchro";
00534       PropertiesManager.getManager().addProperty("org.openmobileis.synchro.direct.installpath", synchroInstallPath);
00535       SynchroDescriptor descriptor = new SynchroDescriptor();
00536       descriptor.setSynchroGroup("defgroup");
00537       String useragent = OpenMSPSynchroManager.getManager().getSynchroUserAgent(descriptor);
00538       
00539       LocalOpenMSPSynchroConduit conduit = new LocalOpenMSPSynchroConduit();
00540         conduit.setSynchroPath(synchroInstallPath);
00541         conduit.setSynchroUserAgent(useragent);
00542       descriptor.setSynchroConduit(conduit);
00543       
00544       //server configuration. Add profil target and module target
00545       PropertiesManager.getManager().addProperty("org.openmobileis.bundle.module.repositorypath", System.getProperty("user.dir") + "/repository");
00546       ColdUpdateModuleLoader.getManager();
00547       ProfilManagerSyncTarget target = new ProfilManagerSyncTarget();
00548       SynchroTargerManager.getManager().addSynchroTargetListener(target, null, null);
00549       SynchroTargerManager.getManager().registerProxyTargetForTerminal(new GenericProxySynchroTarget(), null);      
00550       //start globale synchro
00551       SynchroManager.getManager().registerSynchroProcessor(OpenMSPSynchroManager.getManager());
00552       SynchroManager.getManager().doSynchro(cred, descriptor);
00553       
00554   //    validate XML and JAR files has been synchronized
00555       File jarfile = new File(PropertiesManager.getManager().getProperty("org.openmobileis.module.repository.jar")+"/openmisclient.jar");
00556       Assert.assertTrue(jarfile.exists());
00557       jarfile = new File(PropertiesManager.getManager().getProperty("org.openmobileis.module.repository.jar")+"/mycrm.jar");
00558       Assert.assertTrue(jarfile.exists());
00559       
00560       File xmlfile = new File(PropertiesManager.getManager().getProperty("org.openmobileis.module.repository.xml")+"/openMobileIS.xml");
00561       Assert.assertTrue(xmlfile.exists());
00562       xmlfile = new File(PropertiesManager.getManager().getProperty("org.openmobileis.module.repository.xml")+"/MyCRM.xml");
00563       Assert.assertTrue(xmlfile.exists());
00564       
00565       //mise en place de la partie static synchro. Module initiale. demarrage et rechargement.
00566      
00567     } catch (Exception ex) {
00568       LogManager.traceError(0, ex);
00569       Assert.fail("Exception occurs during testXmlModuleParser :" + ex.getMessage());
00570     }
00571 
00572   }
00573 
00574 }

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