This is an automated email from the ASF dual-hosted git repository.
solomax pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/openmeetings.git
The following commit(s) were added to refs/heads/master by this push:
new 4095b8e [OPENMEETINGS-1856] admin tests should be fixed
4095b8e is described below
commit 4095b8e389cce6988b4f31c3d9230975d6d2fe93
Author: Maxim Solodovnik <[email protected]>
AuthorDate: Wed Oct 31 15:05:22 2018 +0700
[OPENMEETINGS-1856] admin tests should be fixed
---
.../openmeetings/db/util/ApplicationHelper.java | 4 ++-
.../java/org/apache/openmeetings/cli/Admin.java | 4 ++-
.../org/apache/openmeetings/cli/TestAdmin.java | 42 +++++++++++-----------
.../web/pages/install/TestInstall.java | 16 +++++++++
4 files changed, 43 insertions(+), 23 deletions(-)
diff --git
a/openmeetings-db/src/main/java/org/apache/openmeetings/db/util/ApplicationHelper.java
b/openmeetings-db/src/main/java/org/apache/openmeetings/db/util/ApplicationHelper.java
index e2b6cb8..cb84a4f 100644
---
a/openmeetings-db/src/main/java/org/apache/openmeetings/db/util/ApplicationHelper.java
+++
b/openmeetings-db/src/main/java/org/apache/openmeetings/db/util/ApplicationHelper.java
@@ -23,6 +23,8 @@ import static
org.apache.openmeetings.util.OpenmeetingsVariables.isInitComplete;
import static
org.springframework.web.context.WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE;
import static
org.springframework.web.context.support.WebApplicationContextUtils.getWebApplicationContext;
+import java.util.UUID;
+
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
@@ -60,7 +62,7 @@ public class ApplicationHelper {
// This is the case for non-web-app applications
(command line admin)
try {
app =
(WebApplication)OpenmeetingsVariables.getAppClass().newInstance();
- app.setName("--dumb--"); //temporary name for
temporary application
+ app.setName(String.format("--%s--",
UUID.randomUUID())); //temporary name for temporary application
ServletContext sc = new MockServletContext(app,
null);
XmlWebApplicationContext xmlContext = new
XmlWebApplicationContext();
xmlContext.setConfigLocation("classpath:applicationContext.xml");
diff --git
a/openmeetings-install/src/main/java/org/apache/openmeetings/cli/Admin.java
b/openmeetings-install/src/main/java/org/apache/openmeetings/cli/Admin.java
index dc7398f..f173e2c 100644
--- a/openmeetings-install/src/main/java/org/apache/openmeetings/cli/Admin.java
+++ b/openmeetings-install/src/main/java/org/apache/openmeetings/cli/Admin.java
@@ -111,7 +111,9 @@ public class Admin {
String ctxName = System.getProperty("context",
DEFAULT_CONTEXT_NAME);
setWicketApplicationName(ctxName);
home = new File(System.getProperty(RED5_HOME));
- OmFileHelper.setOmHome(new File(new File(home, "webapps"),
ctxName));
+ if (OmFileHelper.getOmHome() == null) {
+ OmFileHelper.setOmHome(new File(new File(home,
"webapps"), ctxName));
+ }
}
private static void log(CharSequence msg) {
diff --git
a/openmeetings-web/src/test/java/org/apache/openmeetings/cli/TestAdmin.java
b/openmeetings-web/src/test/java/org/apache/openmeetings/cli/TestAdmin.java
index d854cf7..d6e0395 100644
--- a/openmeetings-web/src/test/java/org/apache/openmeetings/cli/TestAdmin.java
+++ b/openmeetings-web/src/test/java/org/apache/openmeetings/cli/TestAdmin.java
@@ -25,6 +25,10 @@ import static
org.apache.openmeetings.AbstractJUnitDefaults.group;
import static org.apache.openmeetings.AbstractJUnitDefaults.userpass;
import static org.apache.openmeetings.AbstractSpringTest.setOmHome;
import static org.apache.openmeetings.cli.Admin.RED5_HOME;
+import static
org.apache.openmeetings.db.util.ApplicationHelper.destroyApplication;
+import static org.apache.openmeetings.util.OmFileHelper.getOmHome;
+import static
org.apache.openmeetings.util.OpenmeetingsVariables.getWicketApplicationName;
+import static
org.apache.openmeetings.util.OpenmeetingsVariables.setInitComplete;
import static
org.apache.openmeetings.web.pages.install.TestInstall.resetDerbyHome;
import static
org.apache.openmeetings.web.pages.install.TestInstall.setDerbyHome;
import static org.junit.Assert.fail;
@@ -34,7 +38,10 @@ import java.io.IOException;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.List;
+import java.util.UUID;
+import org.apache.wicket.Application;
+import org.apache.wicket.protocol.http.WebApplication;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
@@ -48,7 +55,7 @@ public class TestAdmin {
setOmHome();
tempFolder = Files.createTempDirectory("omtempdb").toFile();
System.setProperty("user.dir", tempFolder.getCanonicalPath());
- System.setProperty(RED5_HOME, tempFolder.getCanonicalPath());
+ System.setProperty(RED5_HOME, getOmHome().getCanonicalPath());
setDerbyHome(tempFolder);
}
@@ -57,6 +64,11 @@ public class TestAdmin {
resetDerbyHome();
System.getProperties().remove(RED5_HOME);
deleteDirectory(tempFolder);
+ WebApplication app =
(WebApplication)Application.get(getWicketApplicationName());
+ if (app != null) {
+ destroyApplication();
+ setInitComplete(false);
+ }
}
private static void checkError(String... args) throws Exception {
@@ -86,37 +98,28 @@ public class TestAdmin {
@Test
public void testInstallParamConflict() throws Exception {
- checkError("-i", "-file", "aaa", "-user", "bbb");
+ checkError("-v", "-i", "-file", "aaa", "-user", "bbb");
checkError("-i", "-file", "aaa", "-email", "bbb");
checkError("-i", "-file", "aaa", "-group", "bbb");
}
- private static Admin getAdmin(Admin _a) {
- if (_a == null) {
- Admin a = new Admin();
- setOmHome();
- return a;
- }
- return _a;
- }
-
- private static void performInstall(Admin _a, String... args) throws
Exception {
+ private static void performInstall(Admin admin, String... args) throws
Exception {
List<String> params = Arrays.asList("-i"
, "-tz", "Europe/Berlin"
, "-email", email
, "-group", group
, "-user", adminUsername
- , "--password", userpass);
+ , "--password", userpass
+ , "--db-name",
UUID.randomUUID().toString().replaceAll("-", ""));
for (String a : args) {
params.add(a);
}
- Admin a = getAdmin(_a);
- a.process(params.toArray(new String[] {}));
+ admin.process(params.toArray(new String[] {}));
}
@Test
public void testInstallBackup() throws Exception {
- Admin a = getAdmin(null);
+ Admin a = new Admin();
performInstall(a);
//backup
a.process("-b");
@@ -124,12 +127,9 @@ public class TestAdmin {
a.process("-b", Files.createTempFile("omtempbackup",
null).toFile().getCanonicalPath());
}
-
@Test
- public void testFiles() throws Exception {
- Admin a = getAdmin(null);
- performInstall(a);
+ public void testFilesNoDb() throws Exception {
//clean-up report
- a.process("-f");
+ new Admin().process("-f");
}
}
diff --git
a/openmeetings-web/src/test/java/org/apache/openmeetings/web/pages/install/TestInstall.java
b/openmeetings-web/src/test/java/org/apache/openmeetings/web/pages/install/TestInstall.java
index 5fefda3..d3e6363 100644
---
a/openmeetings-web/src/test/java/org/apache/openmeetings/web/pages/install/TestInstall.java
+++
b/openmeetings-web/src/test/java/org/apache/openmeetings/web/pages/install/TestInstall.java
@@ -38,6 +38,8 @@ import static org.junit.Assert.assertNull;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
+import java.sql.DriverManager;
+import java.sql.SQLException;
import java.util.Locale;
import java.util.Random;
import java.util.TimeZone;
@@ -68,9 +70,23 @@ public class TestInstall {
public static void setDerbyHome(File f) throws IOException {
System.setProperty(DERBY_HOME, f.getCanonicalPath());
+ try {
+
Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();
+ } catch (InstantiationException | IllegalAccessException |
ClassNotFoundException e) {
+ log.error("Fail to re-init Derby", e);
+ }
}
public static void resetDerbyHome() {
+ try {
+
DriverManager.getConnection("jdbc:derby:;shutdown=true");
+ } catch (SQLException e) {
+ if ("XJ015".equals(e.getSQLState()) && 50000 ==
e.getErrorCode()) {
+ log.info("Derby shutdown successfully");
+ } else {
+ log.error("Fail to shutdown Derby", e);
+ }
+ }
System.getProperties().remove(DERBY_HOME);
}