Author: solomax Date: Mon Feb 11 07:39:25 2013 New Revision: 1444670 URL: http://svn.apache.org/r1444670 Log: Import: test system properties are unified; Issue with importing room files is fixed; Basic checks are added to TestOldBackups
Modified: openmeetings/trunk/singlewebapp/build.xml openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/cli/Admin.java openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/servlet/outputhandler/BackupImportController.java openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/test/AbstractOpenmeetingsSpringTest.java openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/test/backup/TestOldBackups.java Modified: openmeetings/trunk/singlewebapp/build.xml URL: http://svn.apache.org/viewvc/openmeetings/trunk/singlewebapp/build.xml?rev=1444670&r1=1444669&r2=1444670&view=diff ============================================================================== --- openmeetings/trunk/singlewebapp/build.xml (original) +++ openmeetings/trunk/singlewebapp/build.xml Mon Feb 11 07:39:25 2013 @@ -792,11 +792,10 @@ <echo message="${myclsp}" /--> <junit maxmemory="1024m" printsummary="yes" dir="${junit.base.dir}" tempdir="${junit.base.dir}" fork="yes" forkmode="perBatch"> <classpath refid="junit.classpath" /> - <jvmarg value="-Dom.home=${om.home}" /> + <jvmarg value="-Dom.home=${basedir}/${om.dist.webapp}" /> <jvmarg value="-Dred5.root=${red5.root}" /> <jvmarg value="-Dbasedir=${basedir}" /> <jvmarg value="-Dred5.config_root=${red5.root}/conf" /> - <jvmarg value="-Dwebapps.root=${basedir}/${om.dist.webapp}" /> <jvmarg value="-Dbackups.dir=${junit.backups.dir}" /> <formatter type="${junit.test.formatter}" /> <batchtest todir="${junit.report.dir}"> Modified: openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/cli/Admin.java URL: http://svn.apache.org/viewvc/openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/cli/Admin.java?rev=1444670&r1=1444669&r2=1444670&view=diff ============================================================================== --- openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/cli/Admin.java (original) +++ openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/cli/Admin.java Mon Feb 11 07:39:25 2013 @@ -65,7 +65,8 @@ public class Admin { private InstallationConfig cfg = null; private Options opts = null; private CommandLine cmdl = null; - private ClassPathXmlApplicationContext ctx = null; + private ClassPathXmlApplicationContext ctx = null; + private final static String PERSISTENCE_NAME = "classes/META-INF/persistence.xml"; private Admin() { cfg = new InstallationConfig(); @@ -234,7 +235,7 @@ public class Admin { cfg.mailUseTls = "1"; } ConnectionProperties connectionProperties = new ConnectionProperties(); - File conf = new File(OmFileHelper.getWebinfDir(), "classes/META-INF/persistence.xml"); + File conf = new File(OmFileHelper.getWebinfDir(), PERSISTENCE_NAME); if (!conf.exists() || cmdl.hasOption("db-type") || cmdl.hasOption("db-host") || cmdl.hasOption("db-port") || cmdl.hasOption("db-name") || cmdl.hasOption("db-user") || cmdl.hasOption("db-pass")) { String dbType = cmdl.getOptionValue("db-type", "derby"); File srcConf = new File(OmFileHelper.getWebinfDir(), "classes/META-INF/" + dbType + "_persistence.xml"); @@ -574,20 +575,30 @@ public class Admin { return (pass == null || pass.length() < InstallationConfig.USER_PASSWORD_MINIMUM_LENGTH); } + public static void dropDB() throws Exception { + File conf = new File(OmFileHelper.getWebinfDir(), PERSISTENCE_NAME); + ConnectionProperties connectionProperties = ConnectionPropertiesPatcher.getConnectionProperties(conf); + immediateDropDB(connectionProperties); + } + private void dropDB(ConnectionProperties props) throws Exception { - if(cmdl.hasOption("drop")) { - String[] args = { - "-schemaAction", "retain,drop" - , "-properties", new File(OmFileHelper.getWebinfDir(), "classes/META-INF/persistence.xml").getCanonicalPath() - , "-connectionDriverName", props.getDriver() - , "-connectionURL", props.getURL() - , "-connectionUserName", props.getLogin() - , "-connectionPassword", props.getPassword() - , "-ignoreErrors", "true"}; - MappingTool.main(args); + if(cmdl.hasOption("drop")) { + immediateDropDB(props); } } + private static void immediateDropDB(ConnectionProperties props) throws Exception { + String[] args = { + "-schemaAction", "retain,drop" + , "-properties", new File(OmFileHelper.getWebinfDir(), PERSISTENCE_NAME).getCanonicalPath() + , "-connectionDriverName", props.getDriver() + , "-connectionURL", props.getURL() + , "-connectionUserName", props.getLogin() + , "-connectionPassword", props.getPassword() + , "-ignoreErrors", "true"}; + MappingTool.main(args); + } + private File checkRestoreFile(String file) { File backup = new File(file); if (!cmdl.hasOption("file") || !backup.exists() || !backup.isFile()) { Modified: openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/servlet/outputhandler/BackupImportController.java URL: http://svn.apache.org/viewvc/openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/servlet/outputhandler/BackupImportController.java?rev=1444670&r1=1444669&r2=1444670&view=diff ============================================================================== --- openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/servlet/outputhandler/BackupImportController.java (original) +++ openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/servlet/outputhandler/BackupImportController.java Mon Feb 11 07:39:25 2013 @@ -795,11 +795,13 @@ public class BackupImportController exte } private Long importLongType(String value) { - if (value.equals("null") || value.equals("")) { - return null; + Long val = null; + try { + val = Long.valueOf(value); + } catch (Exception e) { + // no-op } - - return Long.valueOf(value).longValue(); + return val; } private Long getNewId(Long oldId, Maps map) { Modified: openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/test/AbstractOpenmeetingsSpringTest.java URL: http://svn.apache.org/viewvc/openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/test/AbstractOpenmeetingsSpringTest.java?rev=1444670&r1=1444669&r2=1444670&view=diff ============================================================================== --- openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/test/AbstractOpenmeetingsSpringTest.java (original) +++ openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/test/AbstractOpenmeetingsSpringTest.java Mon Feb 11 07:39:25 2013 @@ -71,7 +71,8 @@ public abstract class AbstractOpenmeetin @Before public void setUp() throws Exception { - if (userManagement.getUserById(1L) == null) { + setOmHome(); + if (usersDao.count() < 1) { makeDefaultScheme(); log.info("Default scheme created successfully"); } else { @@ -126,7 +127,7 @@ public abstract class AbstractOpenmeetin } protected void setOmHome() { - String webappsDir = System.getProperty("webapps.root", "."); + String webappsDir = System.getProperty("om.home", "."); OmFileHelper.setOmHome(webappsDir); if (!OmFileHelper.getOmHome().exists() || !OmFileHelper.getOmHome().isDirectory()) { fail("Invalid directory is specified as OM HOME: " + webappsDir); @@ -134,7 +135,6 @@ public abstract class AbstractOpenmeetin } private void makeDefaultScheme() throws Exception { - setOmHome(); importInitvalues.loadAll(new InstallationConfig(), username, userpass, useremail, orgname, timeZone, false); } Modified: openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/test/backup/TestOldBackups.java URL: http://svn.apache.org/viewvc/openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/test/backup/TestOldBackups.java?rev=1444670&r1=1444669&r2=1444670&view=diff ============================================================================== --- openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/test/backup/TestOldBackups.java (original) +++ openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/test/backup/TestOldBackups.java Mon Feb 11 07:39:25 2013 @@ -1,10 +1,14 @@ package org.apache.openmeetings.test.backup; +import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import java.io.File; import java.io.FileInputStream; +import org.apache.openmeetings.data.file.dao.FileExplorerItemDao; +import org.apache.openmeetings.data.flvrecord.FlvRecordingDao; +import org.apache.openmeetings.data.user.dao.UsersDao; import org.apache.openmeetings.servlet.outputhandler.BackupImportController; import org.apache.openmeetings.test.AbstractOpenmeetingsSpringTest; import org.junit.Test; @@ -13,19 +17,37 @@ import org.springframework.beans.factory public class TestOldBackups extends AbstractOpenmeetingsSpringTest { @Autowired private BackupImportController backupController; - + @Autowired + private UsersDao usersDao; + @Autowired + private FlvRecordingDao recordingDao; + @Autowired + private FileExplorerItemDao fileExplorerItemDao; + @Test public void importOldVersions() { - setOmHome(); String backupsDir = System.getProperty("backups.dir", "."); File backupsHome = new File(backupsDir); if (!backupsHome.exists() || !backupsHome.isDirectory()) { fail("Invalid directory is specified for backup files: " + backupsDir); } + long userCount = 0; + long recCount = 0; + long fileCount = 0; for (File backup : backupsHome.listFiles()) { try { backupController.performImport(new FileInputStream(backup)); + long newUserCount = usersDao.count(); + long newRecCount = recordingDao.getFlvRecordings().size(); + long newFileCount = fileExplorerItemDao.getFileExplorerItems().size(); + assertTrue("Zero users were imported", newUserCount > userCount); + assertTrue("Zero recordings were imported", newRecCount > recCount); + assertTrue("Zero files were imported", newFileCount > fileCount); + + userCount = newUserCount; + recCount = newRecCount; + fileCount = newFileCount; } catch (Exception e) { throw new RuntimeException("Unexpected exception while importing backup: " + backup.getName(), e); }