|
From: <ian...@us...> - 2007-08-29 20:55:22
|
Revision: 290
http://ogoglio.svn.sourceforge.net/ogoglio/?rev=290&view=rev
Author: iansmith
Date: 2007-08-29 13:55:24 -0700 (Wed, 29 Aug 2007)
Log Message:
-----------
New support for migrations and better support for test resources.
Modified Paths:
--------------
maven/trunk/ogoglio-appdev/src/main/java/com/ogoglio/appdev/migrate/Migration.java
maven/trunk/ogoglio-appdev/src/main/java/com/ogoglio/appdev/migrate/MigrationSupport.java
maven/trunk/ogoglio-appdev/src/main/java/com/ogoglio/appdev/migrate/test/DBZapTest.java
maven/trunk/ogoglio-common/.classpath
maven/trunk/ogoglio-common/pom.xml
maven/trunk/ogoglio-common/src/main/java/com/ogoglio/util/WebConstants.java
maven/trunk/ogoglio-integration-test/pom.xml
maven/trunk/ogoglio-integration-test/src/test/java/com/ogoglio/client/test/ClientTest.java
maven/trunk/ogoglio-server/.classpath
maven/trunk/ogoglio-server/pom.xml
maven/trunk/ogoglio-server/src/main/java/com/ogoglio/migrate/AccountsForTesting.java
maven/trunk/ogoglio-server/src/main/java/com/ogoglio/site/AuthServlet.java
maven/trunk/ogoglio-server/src/main/java/com/ogoglio/site/MessageProxy.java
maven/trunk/ogoglio-server/src/test/java/com/ogoglio/persist/test/PersistTest.java
Added Paths:
-----------
maven/trunk/ogoglio-appdev/src/test/resources/basic.properties
maven/trunk/ogoglio-common/src/main/java/com/ogoglio/util/PropStorage.java
maven/trunk/ogoglio-integration-test/src/test/resources/basic-config.properties
maven/trunk/ogoglio-integration-test/src/test/resources/bootstrap.properties
maven/trunk/ogoglio-integration-test/src/test/resources/test-config.properties
maven/trunk/ogoglio-server/src/test/resources/basic-config.properties
maven/trunk/ogoglio-server/src/test/resources/bootstrap.properties
maven/trunk/ogoglio-viewer-applet/src/test/java/com/ogoglio/viewer/test/
maven/trunk/ogoglio-viewer-applet/src/test/java/com/ogoglio/viewer/test/AppletTestWindow.java
Modified: maven/trunk/ogoglio-appdev/src/main/java/com/ogoglio/appdev/migrate/Migration.java
===================================================================
--- maven/trunk/ogoglio-appdev/src/main/java/com/ogoglio/appdev/migrate/Migration.java 2007-08-29 00:48:02 UTC (rev 289)
+++ maven/trunk/ogoglio-appdev/src/main/java/com/ogoglio/appdev/migrate/Migration.java 2007-08-29 20:55:24 UTC (rev 290)
@@ -9,6 +9,21 @@
public interface Migration {
- public boolean migrate(SessionFactory sessionFactory, ServletConfig servletConfig, Context ctx, Properties testConfig, int from, int to);
+ /*
+ * Called to move a running database from one version to another. The receiver should
+ * take actions that are required to make the new schema work properly, such as fixing
+ * pointers that may have been put out-of-date.
+ *
+ * Return false if things went wrong.
+ */
+ public boolean patch(SessionFactory sessionFactory, ServletConfig servletConfig, Context ctx, int from, int to);
+ /*O
+ * The receiver should use this call to populate the database with data that would be useful
+ * to sample programs or a user such as example user accounts, etc.
+ *
+ * Return false if things went wrong.
+ */
+ public boolean populate(SessionFactory sessionFactory, int from, int to);
+
}
Modified: maven/trunk/ogoglio-appdev/src/main/java/com/ogoglio/appdev/migrate/MigrationSupport.java
===================================================================
--- maven/trunk/ogoglio-appdev/src/main/java/com/ogoglio/appdev/migrate/MigrationSupport.java 2007-08-29 00:48:02 UTC (rev 289)
+++ maven/trunk/ogoglio-appdev/src/main/java/com/ogoglio/appdev/migrate/MigrationSupport.java 2007-08-29 20:55:24 UTC (rev 290)
@@ -1,9 +1,5 @@
package com.ogoglio.appdev.migrate;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Properties;
-
import javax.naming.Context;
import javax.naming.NamingException;
import javax.servlet.ServletConfig;
@@ -12,13 +8,19 @@
import org.hibernate.cfg.Configuration;
import com.ogoglio.appdev.persist.PersistException;
+import com.ogoglio.util.PropStorage;
import com.ogoglio.viewer.render.UIConstants;
+
+
public abstract class MigrationSupport {
//check on migration okayness
public static final String MIGRATION_KEY = "ogoglio/okToMigrateDB";
+ public static final boolean DDL_MODE_UPDATE=true;
+ public static final boolean DDL_MODE_CREATE=false;
+
public MigrationSupport() {
}
@@ -32,7 +34,8 @@
if (version != versionNumber()) {
System.err.println("DB Version Mismatch! Expected (" + versionNumber() + ") but got " + version + "!");
sessionFactory.close();
- return tryUpgrade(servletConf, ctx, version, versionNumber(), "update", true);
+ return tryUpgrade(servletConf, ctx, version, versionNumber(),
+ DDL_MODE_UPDATE, true, null);
}
sessionFactory.close();
return true; // we are at the expected version
@@ -42,12 +45,12 @@
return false;
}
System.err.println("Unable to figure out DB version number. Likely this is a fresh database....(" + e.innerThrowable.getClass().getName() + ")");
- return initialize_version(servletConf, ctx, true);
+ return initVersionAndUpgrade(servletConf, ctx);
}
}
- public boolean initialize_version(ServletConfig conf, Context ctx, boolean useJNDI) {
- Configuration configuration = createConfigurationForHibernate(0, "create", useJNDI);
+ public boolean initVersionOnly(boolean useJNDI, PropStorage propStore) {
+ Configuration configuration = createConfigurationForHibernate(0, "create", useJNDI, propStore);
try {
SessionFactory factory = configuration.buildSessionFactory();
if (setVersionNumberOfDbViaQuery(factory, 0, 0) == false) {
@@ -55,19 +58,25 @@
return false;
}
factory.close();
- return tryUpgrade(conf, ctx, 0, versionNumber(), "create", useJNDI);
- } catch (Throwable e) {
- System.err.println("Error trying initialized DB:" + e.getMessage());
+ return true;
+ } catch (Throwable t) {
+ System.err.println("Error trying initialized DB:" + t.getMessage());
return false;
}
-
}
+
+ public boolean initVersionAndUpgrade(ServletConfig conf, Context ctx) {
+ if (!initVersionOnly(true,null)) {
+ return false;
+ }
+ return tryUpgrade(conf, ctx, 0, versionNumber(), DDL_MODE_UPDATE, true,null);
+ }
public Configuration getCurrentConfiguration() {
- return createConfigurationForHibernate(versionNumber(), null, true);
+ return createConfigurationForHibernate(versionNumber(), null, true, null);
}
- public Configuration createConfigurationForHibernate(int num, String autoSetting, boolean useJNDI) {
+ public Configuration createConfigurationForHibernate(int num, String autoSetting, boolean useJNDI, PropStorage ps) {
Configuration configuration = new Configuration();
if (autoSetting != null) {
configuration.setProperty("hibernate.hbm2ddl.auto", autoSetting);
@@ -75,14 +84,7 @@
if (useJNDI) {
configuration.setProperty("hibernate.connection.datasource", "java:comp/env/jdbc/space");
} else {
- Properties p = new Properties();
- try {
- p.load(getClass().getResourceAsStream("/test-config.properties"));
- configuration.addProperties(p);
- } catch (IOException e) {
- System.err.println("Unable to find the test configuration file!" + e.getMessage());
- return configuration.configure();
- }
+ configuration.addProperties(ps.getAllProps(PropStorage.TEST_CONFIG_PROPS));
}
configuration.addInputStream(UIConstants.getResource("com/ogoglio/migrate/migration-" + num + ".xml"));
return configuration.configure();
@@ -97,35 +99,39 @@
}
}
- public boolean tryUpgrade(ServletConfig servletConfig, Context ctx, int db_is, int db_wants_to_be, String ddlMode, boolean useJNDI) {
+ public boolean tryUpgrade(ServletConfig servletConfig, Context ctx, int db_is,
+ int db_wants_to_be, boolean isUpdate, boolean useJNDI, PropStorage propStore) {
if (migrationList().length != versionNumber()) {
System.out.println("Internal error! Migration list length should be " + versionNumber() + " but is " + migrationList().length + "!");
return false;
}
- Properties testConfig = new Properties();
boolean canMigrate = false;
- if (ctx == null) {
- //in test mode
- testConfig = getTestConfig();
- if ("true".equals(testConfig.getProperty("ogoglio.okToMigrateDB"))) {
- canMigrate = true;
- }
- } else {
- //not testing, but might be integration testing
- try {
- String migrate = (String) ctx.lookup(MIGRATION_KEY);
- if ("true".equals(migrate)) {
- canMigrate = true;
- }
- } catch (NamingException e) {
- System.err.println("Naming exception trying to access " + MIGRATION_KEY + " from naming context!");
- }
+
+ //check the flags
+ try {
+ String migrate;
+ if (useJNDI) {
+ migrate = (String) ctx.lookup(MIGRATION_KEY);
+ } else {
+ migrate= propStore.getKeyFromSet(PropStorage.TEST_CONFIG_PROPS, "ogoglio.okToMigrateDB");
+ }
+ if ("true".equals(migrate)) {
+ canMigrate = true;
+ }
+ } catch (NamingException e) {
+ System.err.println("Naming exception trying to access " + MIGRATION_KEY + " from naming context!");
+ canMigrate=false;
}
if (!canMigrate) {
System.err.println("Cannot migrate data! Property ogoglio.okToMigrateDB is false or non-existent!");
return false;
}
+ String hbm_auto_flag="update";
+ if (!isUpdate) {
+ hbm_auto_flag="create";
+ }
+
for (int i = db_is; i < db_wants_to_be; ++i) {
Migration current = migrationList()[i];
@@ -133,38 +139,47 @@
System.out.println("DB: Attempting migration from " + i + " to " + (i + 1) + "...");
//try to get hibernate to do the work
- Configuration config = createConfigurationForHibernate(i + 1, ddlMode, useJNDI);
+ Configuration config = createConfigurationForHibernate(i + 1, hbm_auto_flag, useJNDI, propStore);
SessionFactory factory = config.buildSessionFactory();
//subtle: if the ddlMode is create, hibernate blows away all the data (including our version number record)
int expectedRecords = 1;
- if ("create".equals(ddlMode)) {
+ if (!isUpdate) {
expectedRecords = 0;
}
setVersionNumberOfDbViaQuery(factory, i + 1, expectedRecords);
- if (!current.migrate(factory, servletConfig, ctx, testConfig, i, i + 1)) {
+ if (!current.patch(factory, servletConfig, ctx, i, i + 1)) {
factory.close();
return false;
}
+
+ if (!isUpdate) {
+ //we need to go ahead and create the data
+ if (!current.populate(factory, i, i+1)) {
+ System.out.println("FART: Whoa! Populate failed!"+i);
+ factory.close();
+ return false;
+ }
+ System.out.println("FART: Populate ok!"+i);
+ }
+
factory.close();
System.out.println("------------------------------------------------\n");
}
return true;
}
- public Properties getTestConfig() {
- Properties testConfig = new Properties();
- InputStream is = getClass().getResourceAsStream("/test-config.properties");
- if (is == null) {
- System.err.println("Warning! Unable to find test-config.properties! Probably something is broken!");
- } else {
- try {
- testConfig.load(is);
- } catch (IOException e) {
- System.err.println("Warning! Error reading test-config.properties! " + e.getMessage());
- }
- }
- return testConfig;
- }
+ public boolean destroyAllData() {
+ PropStorage ps =new PropStorage();
+ if (ps.loadPropertySet(PropStorage.TEST_CONFIG_PROPS)==false) {
+ return false;
+ }
+
+ if (initVersionOnly(false, ps)==false) {
+ return false;
+ }
+
+ return tryUpgrade(null, null, 0, versionNumber(), DDL_MODE_CREATE, false, ps);
+ }
}
Modified: maven/trunk/ogoglio-appdev/src/main/java/com/ogoglio/appdev/migrate/test/DBZapTest.java
===================================================================
--- maven/trunk/ogoglio-appdev/src/main/java/com/ogoglio/appdev/migrate/test/DBZapTest.java 2007-08-29 00:48:02 UTC (rev 289)
+++ maven/trunk/ogoglio-appdev/src/main/java/com/ogoglio/appdev/migrate/test/DBZapTest.java 2007-08-29 20:55:24 UTC (rev 290)
@@ -5,6 +5,7 @@
import org.hibernate.SessionFactory;
import com.ogoglio.appdev.migrate.MigrationSupport;
+import com.ogoglio.util.PropStorage;
public abstract class DBZapTest extends TestCase {
@@ -15,15 +16,19 @@
public void setUp() {
try {
MigrationSupport support = getMigrationSupport();
- if (!("true".equals(support.getTestConfig().getProperty("ogoglio.okToZapDB")))) {
+ PropStorage ps=new PropStorage();
+ if (ps.loadPropertySet(PropStorage.TEST_CONFIG_PROPS)==false) {
+ fail("Can't load test configuration for hibernate properties!");
+ }
+ if (!("true".equals(ps.getKeyFromSet(PropStorage.TEST_CONFIG_PROPS,"ogoglio.okToZapDB")))) {
fail("Whoa! Shouldn't be running tests without setting the ogoglio.okToZapDB property!");
}
- if (support.initialize_version(null, null, false) == false) {
+ if (support.destroyAllData() == false) {
fail("can't get DB set up: trying to initialize it in the test code");
}
//if we are here, db stuff worked, but we still need to avoid all the jndi stuff
- sessionFactory = support.createConfigurationForHibernate(getMigrationSupport().versionNumber(), null, false).buildSessionFactory();
+ sessionFactory = support.createConfigurationForHibernate(getMigrationSupport().versionNumber(), null, false, ps).buildSessionFactory();
} catch (Exception e) {
System.out.println("-------");
e.printStackTrace(System.out);
Added: maven/trunk/ogoglio-appdev/src/test/resources/basic.properties
===================================================================
--- maven/trunk/ogoglio-appdev/src/test/resources/basic.properties (rev 0)
+++ maven/trunk/ogoglio-appdev/src/test/resources/basic.properties 2007-08-29 20:55:24 UTC (rev 290)
@@ -0,0 +1,4 @@
+# basic info needed for some tests
+ogoglio.testSpaceNumber = ${ogoglio.testSpaceNumber}
+ogoglio.baseUrl = ${ogoglio.baseURL}
+
Modified: maven/trunk/ogoglio-common/.classpath
===================================================================
--- maven/trunk/ogoglio-common/.classpath 2007-08-29 00:48:02 UTC (rev 289)
+++ maven/trunk/ogoglio-common/.classpath 2007-08-29 20:55:24 UTC (rev 290)
@@ -2,9 +2,7 @@
<classpath>
<classpathentry kind="src" path="src/main/java"/>
<classpathentry kind="src" path="src/test/java"/>
- <classpathentry excluding="**" output="src/main/resources/avatar" kind="src" path="src/main/resources/avatar"/>
- <classpathentry excluding="**" output="src/main/resources/templates" kind="src" path="src/main/resources/templates"/>
- <classpathentry excluding="**" output="src/test/resources" kind="src" path="src/test/resources"/>
+ <classpathentry excluding="**" kind="src" output="src/main/resources/templates" path="src/main/resources/templates"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
<classpathentry kind="output" path="target/classes"/>
Modified: maven/trunk/ogoglio-common/pom.xml
===================================================================
--- maven/trunk/ogoglio-common/pom.xml 2007-08-29 00:48:02 UTC (rev 289)
+++ maven/trunk/ogoglio-common/pom.xml 2007-08-29 20:55:24 UTC (rev 290)
@@ -13,14 +13,7 @@
<build>
<resources>
<!-- FILTER RESOURCES FOR SOME CONSTANTS-->
- <!--
<resource>
- <directory>src/main/resources/testing_constants</directory>
- <filtering>true</filtering>
- </resource>
- -->
-
- <resource>
<targetPath>avatar</targetPath>
<directory>src/main/resources/avatar</directory>
</resource>
Added: maven/trunk/ogoglio-common/src/main/java/com/ogoglio/util/PropStorage.java
===================================================================
--- maven/trunk/ogoglio-common/src/main/java/com/ogoglio/util/PropStorage.java (rev 0)
+++ maven/trunk/ogoglio-common/src/main/java/com/ogoglio/util/PropStorage.java 2007-08-29 20:55:24 UTC (rev 290)
@@ -0,0 +1,55 @@
+package com.ogoglio.util;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+/*
+ * This is used by test and utility code to manipulate the DB and avoid having production
+ * jars that contain property files that have private information.
+ */
+public class PropStorage {
+
+ public static final String TEST_CONFIG_PROPS="test-config.properties";
+ public static final String BOOTSTRAP_PROPS="bootstrap.properties";
+ public static final String BASIC_PROPS = "basic-config.properties";
+
+
+
+ private Map propMap = new HashMap();
+
+ public PropStorage() {}
+
+ public boolean loadPropertySet(String propsetNameAndPath) {
+ if (!propMap.containsKey(propsetNameAndPath)) {
+ InputStream is;
+ is = UIConstants.class.getClassLoader().getResourceAsStream(propsetNameAndPath);
+ if (is== null) {
+ is= UIConstants.class.getResourceAsStream(propsetNameAndPath);
+ }
+ if (is==null) {
+ return false;
+ }
+ Properties props=new Properties();
+ try {
+ props.load(is);
+ propMap.put(propsetNameAndPath,props);
+ } catch (IOException e) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ public String getKeyFromSet(String propSetName, String key) {
+ Properties props=(Properties)propMap.get(propSetName);
+ return props.getProperty(key);
+ }
+
+ public Properties getAllProps(String propsetNameAndPath) {
+ return (Properties)propMap.get(propsetNameAndPath);
+ }
+
+}
Modified: maven/trunk/ogoglio-common/src/main/java/com/ogoglio/util/WebConstants.java
===================================================================
--- maven/trunk/ogoglio-common/src/main/java/com/ogoglio/util/WebConstants.java 2007-08-29 00:48:02 UTC (rev 289)
+++ maven/trunk/ogoglio-common/src/main/java/com/ogoglio/util/WebConstants.java 2007-08-29 20:55:24 UTC (rev 290)
@@ -1,8 +1,5 @@
package com.ogoglio.util;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Properties;
public class WebConstants {
public static final String AUTH_USERNAME_PARAM = "username";
Modified: maven/trunk/ogoglio-integration-test/pom.xml
===================================================================
--- maven/trunk/ogoglio-integration-test/pom.xml 2007-08-29 00:48:02 UTC (rev 289)
+++ maven/trunk/ogoglio-integration-test/pom.xml 2007-08-29 20:55:24 UTC (rev 290)
@@ -9,13 +9,23 @@
<packaging>pom</packaging>
<build>
+ <!-- -->
+ <!-- TEST RESOURCES -->
+ <!-- -->
<testResources>
<testResource>
- <targetPath></targetPath>
- <directory>src/test/resources/</directory>
+ <directory>src/test/resources</directory>
<filtering>true</filtering>
+ <includes>
+ <include>test-config.properties</include>
+ <include>basic-config.properties</include>
+ <include>bootstrap.properties</include>
+ <include>mail/*</include>
+ <include>sample-art3d/*</include>
+ </includes>
</testResource>
</testResources>
+
<plugins>
<!-- COMPILER needed b/c POM packaging by default doesn't build the tests -->
<plugin>
@@ -99,8 +109,10 @@
<goals>
<goal>stop</goal>
</goals>
+
<configuration>
<wait>true</wait>
+ <type>runtime</type>
</configuration>
</execution>
<execution>
@@ -110,7 +122,8 @@
<goals>
<goal>stop</goal>
</goals>
- <configuration>
+ <configuration>
+ <type>runtime</type>
<wait>false</wait>
</configuration>
</execution>
Modified: maven/trunk/ogoglio-integration-test/src/test/java/com/ogoglio/client/test/ClientTest.java
===================================================================
--- maven/trunk/ogoglio-integration-test/src/test/java/com/ogoglio/client/test/ClientTest.java 2007-08-29 00:48:02 UTC (rev 289)
+++ maven/trunk/ogoglio-integration-test/src/test/java/com/ogoglio/client/test/ClientTest.java 2007-08-29 20:55:24 UTC (rev 290)
@@ -41,8 +41,10 @@
import com.ogoglio.client.model.SplinePath;
import com.ogoglio.client.model.Thing;
import com.ogoglio.client.model.User;
+import com.ogoglio.util.PropStorage;
import com.ogoglio.util.StreamUtils;
import com.ogoglio.util.WebConstants;
+import com.ogoglio.viewer.render.UIConstants;
import com.ogoglio.xml.AccountDocument;
import com.ogoglio.xml.AuthDocument;
import com.ogoglio.xml.BodyDocument;
@@ -97,7 +99,15 @@
public void testWebAdmin() {
try {
- WebAPIAuthenticator adminAuthenticator = new WebAPIAuthenticatorFactory().authenticate(wire1, descriptor1, BootstrapInfo.getBootstrapUsername(), BootstrapInfo.getBootstrapUserPW());
+ PropStorage ps=new PropStorage();
+ if (ps.loadPropertySet(PropStorage.BOOTSTRAP_PROPS)==false) {
+ fail("unable to load properties bootstrap.properties!");
+ }
+
+ WebAPIAuthenticator adminAuthenticator = new WebAPIAuthenticatorFactory().authenticate(wire1, descriptor1,
+ ps.getKeyFromSet(PropStorage.BOOTSTRAP_PROPS, "bootstrapUser"),
+ ps.getKeyFromSet(PropStorage.BOOTSTRAP_PROPS, "bootstrapUserPW"));
+
assertNotNull("got null auth cookie", adminAuthenticator.getAuthCookie());
WebAPIClient adminWebClient = new WebAPIClient(descriptor1, adminAuthenticator, wire1);
@@ -240,7 +250,7 @@
private UserDocument[] verifyUserDocsBySize(WebAPIClient webClient1, long spaceID, int expectedLen, String expectedUsername) throws IOException {
UserDocument[] userDocs = webClient1.getUserDocuments(spaceID);
- assertTrue(userDocs.length == expectedLen);
+ assertEquals(expectedLen,userDocs.length);
if (expectedUsername != null) {
assertEquals(expectedUsername, userDocs[0].getUsername());
}
@@ -422,6 +432,7 @@
SpaceClient guestSpaceClient1 = new SpaceClient(spaceID, serviceURI1, guestCookie1, new TestSpaceClientListener());
try {
Thread.sleep(1000);
+ Thread.yield();
} catch (InterruptedException e) {
e.printStackTrace();
}
@@ -533,11 +544,10 @@
String CUBE_GIF = "TestCube.gif";
String CUBE_MATERIAL = "TestCube.mtl";
- Class clazz = getClass();
- webClient1.uploadTemplateGeometryStream(newTemplateDoc.getOwnerUsername(), newTemplateDoc.getTemplateID(), 0, clazz.getResourceAsStream("/sample-art3d/TestCube.obj"));
- webClient1.uploadTemplateResourceStream(newTemplateDoc.getOwnerUsername(), newTemplateDoc.getTemplateID(), CUBE_MATERIAL, clazz.getResourceAsStream("/sample-art3d/TestCube.mtl"));
- webClient1.uploadTemplateResourceStream(newTemplateDoc.getOwnerUsername(), newTemplateDoc.getTemplateID(), CUBE_GIF, clazz.getResourceAsStream("/sample-art3d/TestCube.gif"));
- webClient1.updateTemplateScript(newTemplateDoc.getOwnerUsername(), newTemplateDoc.getTemplateID(), StreamUtils.readInput(clazz.getResourceAsStream("/sample-art3d/TestCube.js")));
+ webClient1.uploadTemplateGeometryStream(newTemplateDoc.getOwnerUsername(), newTemplateDoc.getTemplateID(), 0, UIConstants.getResource("sample-art3d/TestCube.obj"));
+ webClient1.uploadTemplateResourceStream(newTemplateDoc.getOwnerUsername(), newTemplateDoc.getTemplateID(), CUBE_MATERIAL, UIConstants.getResource("sample-art3d/TestCube.mtl"));
+ webClient1.uploadTemplateResourceStream(newTemplateDoc.getOwnerUsername(), newTemplateDoc.getTemplateID(), CUBE_GIF, UIConstants.getResource("sample-art3d/TestCube.gif"));
+ webClient1.updateTemplateScript(newTemplateDoc.getOwnerUsername(), newTemplateDoc.getTemplateID(), StreamUtils.readInput(UIConstants.getResource("sample-art3d/TestCube.js")));
baseDoc = webClient1.getTemplateDocument(newTemplateDoc.getOwnerUsername(), newTemplateDoc.getTemplateID());
//make sure the sequence right above didn't take more than 1 sec
Added: maven/trunk/ogoglio-integration-test/src/test/resources/basic-config.properties
===================================================================
--- maven/trunk/ogoglio-integration-test/src/test/resources/basic-config.properties (rev 0)
+++ maven/trunk/ogoglio-integration-test/src/test/resources/basic-config.properties 2007-08-29 20:55:24 UTC (rev 290)
@@ -0,0 +1,4 @@
+# basic info needed for some tests
+ogoglio.testSpaceNumber = ${ogoglio.testSpaceNumber}
+ogoglio.baseUrl = ${ogoglio.baseURL}
+
Added: maven/trunk/ogoglio-integration-test/src/test/resources/bootstrap.properties
===================================================================
--- maven/trunk/ogoglio-integration-test/src/test/resources/bootstrap.properties (rev 0)
+++ maven/trunk/ogoglio-integration-test/src/test/resources/bootstrap.properties 2007-08-29 20:55:24 UTC (rev 290)
@@ -0,0 +1,2 @@
+bootstrapUser=${ogoglio.bootstrapUser}
+bootstrapUserPW=${ogoglio.bootstrapUserPW}
Added: maven/trunk/ogoglio-integration-test/src/test/resources/test-config.properties
===================================================================
--- maven/trunk/ogoglio-integration-test/src/test/resources/test-config.properties (rev 0)
+++ maven/trunk/ogoglio-integration-test/src/test/resources/test-config.properties 2007-08-29 20:55:24 UTC (rev 290)
@@ -0,0 +1,28 @@
+# this is needed for running tests because tomcat isn't
+# actually around when these tests get run so we need
+# to use the DB via the simple c3po connection manager
+# (supplied with hibernate)
+
+hibernate.connection.driver_class = com.mysql.jdbc.Driver
+hibernate.connection.url = ${ogoglio.mysql.url}
+hibernate.connection.username = ${ogoglio.mysql.user}
+hibernate.connection.password = ${ogoglio.mysql.password}
+hibernate.show_sql=false
+hibernate.dialect=org.hibernate.dialect.MySQLDialect
+
+#copied from the web
+#hibernate.c3p0.min_size=5
+#hibernate.c3p0.max_size=20
+#hibernate.c3p0.timeout=1800
+#hibernate.c3p0.max_statements=50
+
+#for doing tests that need bootstrap
+ogoglio.baseURL=${ogoglio.baseURL}
+ogoglio.bootstrapUser=${ogoglio.bootstrapUser}
+ogoglio.bootstrapUserPW=${ogoglio.bootstrapUserPW}
+
+#can destroy the db?
+ogoglio.okToZapDB=${ogoglio.okToZapDB}
+#can migrate data?
+ogoglio.okToMigrateDB=${ogoglio.okToMigrateDB}
+
Modified: maven/trunk/ogoglio-server/.classpath
===================================================================
--- maven/trunk/ogoglio-server/.classpath 2007-08-29 00:48:02 UTC (rev 289)
+++ maven/trunk/ogoglio-server/.classpath 2007-08-29 20:55:24 UTC (rev 290)
@@ -1,9 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
+ <classpathentry kind="src" path="src/main/java"/>
+ <classpathentry kind="src" path="src/test/java"/>
+ <classpathentry excluding="**" kind="src" output="src/main/resources/hibernate" path="src/main/resources/hibernate"/>
+ <classpathentry excluding="**" kind="src" output="src/main/resources/log4j" path="src/main/resources/log4j"/>
+ <classpathentry excluding="**" kind="src" output="src/test/resources" path="src/test/resources"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
- <attribute value="/usr/local/jdk1.5.0_12/jre/lib/i386" name="org.eclipse.jdt.launching.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY"/>
+ <attribute name="org.eclipse.jdt.launching.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY" value="/usr/local/jdk1.5.0_12/jre/lib/i386"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
Modified: maven/trunk/ogoglio-server/pom.xml
===================================================================
--- maven/trunk/ogoglio-server/pom.xml 2007-08-29 00:48:02 UTC (rev 289)
+++ maven/trunk/ogoglio-server/pom.xml 2007-08-29 20:55:24 UTC (rev 290)
@@ -65,6 +65,8 @@
<filtering>true</filtering>
<includes>
<include>test-config.properties</include>
+ <include>basic-config.properties</include>
+ <include>bootstrap.properties</include>
<include>mail/*</include>
<include>templates/*</include>
</includes>
Modified: maven/trunk/ogoglio-server/src/main/java/com/ogoglio/migrate/AccountsForTesting.java
===================================================================
--- maven/trunk/ogoglio-server/src/main/java/com/ogoglio/migrate/AccountsForTesting.java 2007-08-29 00:48:02 UTC (rev 289)
+++ maven/trunk/ogoglio-server/src/main/java/com/ogoglio/migrate/AccountsForTesting.java 2007-08-29 20:55:24 UTC (rev 290)
@@ -1,7 +1,6 @@
package com.ogoglio.migrate;
import java.net.URI;
-import java.util.Properties;
import javax.naming.Context;
import javax.servlet.ServletConfig;
@@ -9,35 +8,49 @@
import org.hibernate.SessionFactory;
import com.ogoglio.appdev.migrate.Migration;
-import com.ogoglio.appdev.servlet.AbstractResourceServlet;
import com.ogoglio.persist.ServiceInitializationPersistTasks;
+import com.ogoglio.util.PropStorage;
+
public class AccountsForTesting implements Migration {
- private static final String BOOTSTRAP_ACCT_USER_KEY = "ogoglio/bootstrapUser";
+ public boolean patch(SessionFactory sessionFactory, ServletConfig config, Context ctx, int from, int to) {
+ return true;
+ }
+ public boolean populate(SessionFactory sessionFactory, int from, int to) {
- private static final String BOOTSTRAP_ACCT_PW_KEY = "ogoglio/bootstrapUserPW";
-
- public boolean migrate(SessionFactory sessionFactory, ServletConfig NOTUSED, Context ctx, Properties testConfig, int from, int to) {
-
if ((from != 0) || (to != 1)) {
System.out.println("Migration called in the wrong place! Expected 0->1 but was:" + from + "->" + to + "!");
System.out.println("Migration called in the wrong place! Check the ordering of migration array!");
return false;
}
try {
+
String uriString, user, pw;
- //if null, we are test mode
- if (ctx == null) {
- uriString = testConfig.getProperty(AbstractResourceServlet.OGOGLIO_BASE_URL_KEY.replace('/', '.'));
- user = testConfig.getProperty(BOOTSTRAP_ACCT_USER_KEY.replace('/', '.'));
- pw = testConfig.getProperty(BOOTSTRAP_ACCT_PW_KEY.replace('/', '.'));
- } else {
- uriString = (String) ctx.lookup(AbstractResourceServlet.OGOGLIO_BASE_URL_KEY);
- user = (String) ctx.lookup(BOOTSTRAP_ACCT_USER_KEY);
- pw = (String) ctx.lookup(BOOTSTRAP_ACCT_PW_KEY);
+ PropStorage zap=new PropStorage();
+ System.out.println("FART1--->populate:"+(zap.loadPropertySet(PropStorage.BOOTSTRAP_PROPS))+","+
+ zap.loadPropertySet(PropStorage.BASIC_PROPS));
+
+ if (zap.loadPropertySet(PropStorage.BOOTSTRAP_PROPS)==false) {
+ return false;
}
+ if (zap.loadPropertySet(PropStorage.BASIC_PROPS)==false) {
+ return false;
+ }
+ System.out.println("FART2--->populate:");
+ uriString = zap.getKeyFromSet(PropStorage.BASIC_PROPS, "ogoglio.baseUrl");
+ user=zap.getKeyFromSet(PropStorage.BOOTSTRAP_PROPS, "bootstrapUser");
+ pw=zap.getKeyFromSet(PropStorage.BOOTSTRAP_PROPS, "bootstrapUserPW");
+
+ if ((uriString==null) || (user==null) || (pw==null)) {
+ System.out.println("URI FART:"+(uriString==null));
+ System.out.println("USER FART:"+(user==null));
+ System.out.println("PW FART:"+(pw==null));
+ return false;
+ }
+
+ System.out.println("FART3--->uriString:"+uriString);
URI uri = new URI(uriString);
//actual work
ServiceInitializationPersistTasks.initializeLocalSim(uri, sessionFactory);
Modified: maven/trunk/ogoglio-server/src/main/java/com/ogoglio/site/AuthServlet.java
===================================================================
--- maven/trunk/ogoglio-server/src/main/java/com/ogoglio/site/AuthServlet.java 2007-08-29 00:48:02 UTC (rev 289)
+++ maven/trunk/ogoglio-server/src/main/java/com/ogoglio/site/AuthServlet.java 2007-08-29 20:55:24 UTC (rev 290)
@@ -50,7 +50,7 @@
if (cookie == null) {
return false;
}
- return cookie.startsWith(GUEST_COOKIE_PREFIX);
+ return cookie.startsWith(WebConstants.GUEST_COOKIE_PREFIX);
}
public static AccountRecord getAuthedAccountRecord(HttpServletRequest request, SessionFactory hibernateSessionFactory) throws PersistException {
@@ -238,13 +238,11 @@
public static final String COOKIE_CHARS = "abcdefghijklmnopqrstuvwxyz1234567890";
- public static final String GUEST_COOKIE_PREFIX = "guest";
-
public static final String[] GUEST_NAMES = { "Moon", "Spoon", "Plume", "Bloom", "Thyme", "Rhyme", "Steel", "Boat", "Vase", "Book", "Screen", "Fenestra", "Farmer", "Door", "Squid", "Rocket", "Picker", "Page", "Lawn", "Food", "Plate", "Bean", "Horse", "Cat", "Fireplace", "Frame", "Chair", "Table", "Sofa", "Stair", "Counter", "Shelf", "Phone", "Robot", "Tree", "Key" };
private String generateGuestCookie() {
StringBuffer result = new StringBuffer();
- result.append(GUEST_COOKIE_PREFIX);
+ result.append(WebConstants.GUEST_COOKIE_PREFIX);
for (int i = 0; i < 3; i++) {
result.append("_" + GUEST_NAMES[Math.abs(random.nextInt()) % GUEST_NAMES.length]);
}
@@ -254,7 +252,7 @@
private String generateAuthCookie(boolean guest) {
StringBuffer result = new StringBuffer(14);
if (guest) {
- result.append(GUEST_COOKIE_PREFIX);
+ result.append(WebConstants.GUEST_COOKIE_PREFIX);
} else {
result.append("tr");
}
Modified: maven/trunk/ogoglio-server/src/main/java/com/ogoglio/site/MessageProxy.java
===================================================================
--- maven/trunk/ogoglio-server/src/main/java/com/ogoglio/site/MessageProxy.java 2007-08-29 00:48:02 UTC (rev 289)
+++ maven/trunk/ogoglio-server/src/main/java/com/ogoglio/site/MessageProxy.java 2007-08-29 20:55:24 UTC (rev 290)
@@ -40,6 +40,7 @@
import com.ogoglio.persist.SpaceRecord;
import com.ogoglio.util.ArgumentUtils;
import com.ogoglio.util.TwoWayMap;
+import com.ogoglio.util.WebConstants;
import com.ogoglio.xml.SpaceEvent;
import com.ogoglio.xml.UserDocument;
@@ -124,7 +125,7 @@
String username = null;
long bodyID = -1;
- if (payload.getLoginCookie().startsWith(AuthServlet.GUEST_COOKIE_PREFIX)) {
+ if (payload.getLoginCookie().startsWith(WebConstants.GUEST_COOKIE_PREFIX)) {
if (!SpacePersistTasks.canReadSpace(null, payload.getSpaceID(), sessionFactory)) {
Message failureMessage = new Message(channelServer.getLocator(), request.getOrigin(), payload.getSpaceID(), new PayloadFactory.AuthenticationFailurePayload("Guests are not allowed in this space."));
sourceChannel.sendMessage(failureMessage);
@@ -161,7 +162,7 @@
return;
}
- if(username.startsWith(AuthServlet.GUEST_COOKIE_PREFIX)) {
+ if(username.startsWith(WebConstants.GUEST_COOKIE_PREFIX)) {
URI userListURI = WebAPIUtil.appendToURI(simRecord.getSimURI(), "space/" + spaceRecord.getSpaceID() + "/user/");
XMLElement element = new WebAPIClientWire().fetchAuthenticatedXML(userListURI, null);
if(element == null) {
Modified: maven/trunk/ogoglio-server/src/test/java/com/ogoglio/persist/test/PersistTest.java
===================================================================
--- maven/trunk/ogoglio-server/src/test/java/com/ogoglio/persist/test/PersistTest.java 2007-08-29 00:48:02 UTC (rev 289)
+++ maven/trunk/ogoglio-server/src/test/java/com/ogoglio/persist/test/PersistTest.java 2007-08-29 20:55:24 UTC (rev 290)
@@ -68,6 +68,7 @@
}
}
public void setUp() {
+
super.setUp();
username1 = AccountRecord.cleanUsername("MoonUnitZappa");
email1 = AccountRecord.cleanEmail("mu...@ex...");
Added: maven/trunk/ogoglio-server/src/test/resources/basic-config.properties
===================================================================
--- maven/trunk/ogoglio-server/src/test/resources/basic-config.properties (rev 0)
+++ maven/trunk/ogoglio-server/src/test/resources/basic-config.properties 2007-08-29 20:55:24 UTC (rev 290)
@@ -0,0 +1,4 @@
+# basic info needed for some tests
+ogoglio.testSpaceNumber = ${ogoglio.testSpaceNumber}
+ogoglio.baseUrl = ${ogoglio.baseURL}
+
Added: maven/trunk/ogoglio-server/src/test/resources/bootstrap.properties
===================================================================
--- maven/trunk/ogoglio-server/src/test/resources/bootstrap.properties (rev 0)
+++ maven/trunk/ogoglio-server/src/test/resources/bootstrap.properties 2007-08-29 20:55:24 UTC (rev 290)
@@ -0,0 +1,2 @@
+bootstrapUser=${ogoglio.bootstrapUser}
+bootstrapUserPW=${ogoglio.bootstrapUserPW}
Copied: maven/trunk/ogoglio-viewer-applet/src/test/java/com/ogoglio/viewer/test/AppletTestWindow.java (from rev 277, maven/trunk/ogoglio-viewer-applet/src/main/java/com/ogoglio/viewer/applet/AppletTestWindow.java)
===================================================================
--- maven/trunk/ogoglio-viewer-applet/src/test/java/com/ogoglio/viewer/test/AppletTestWindow.java (rev 0)
+++ maven/trunk/ogoglio-viewer-applet/src/test/java/com/ogoglio/viewer/test/AppletTestWindow.java 2007-08-29 20:55:24 UTC (rev 290)
@@ -0,0 +1,162 @@
+/* Copyright 2007 Transmutable (http://transmutable.com/)
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License. */
+
+package com.ogoglio.viewer.test;
+
+import java.applet.Applet;
+import java.applet.AppletContext;
+import java.applet.AppletStub;
+import java.awt.BorderLayout;
+import java.awt.Dimension;
+import java.awt.Frame;
+import java.awt.GraphicsDevice;
+import java.awt.GraphicsEnvironment;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URL;
+import java.util.HashMap;
+
+import com.ogoglio.client.WebAPIAuthenticator;
+import com.ogoglio.client.WebAPIClientWire;
+import com.ogoglio.client.WebAPIDescriptor;
+import com.ogoglio.util.PropStorage;
+import com.ogoglio.util.WebConstants;
+import com.ogoglio.viewer.applet.ViewerApplet;
+
+public class AppletTestWindow extends Frame {
+
+ //static Dimension appDimension = new Dimension(640, 500);
+ //static Dimension appDimension = new Dimension(500, 522);
+ static Dimension appDimension = new Dimension(1000, 640);
+
+ Applet applet = null;
+
+ EnvironmentStub clientStub1 = null;
+
+ String host = "127.0.0.1:8080";
+
+ String serviceURI = "http://" + host + "/og/";
+
+ URL codeBase = getURL(serviceURI);
+
+ static boolean fullScreen = false;
+
+ public AppletTestWindow() {
+ setLayout(new BorderLayout());
+ setSize(appDimension);
+ setLocation(30, 50);
+ setResizable(false);
+ if (fullScreen) {
+ this.setUndecorated(true);
+ }
+ PropStorage ps=new PropStorage();
+ if (!ps.loadPropertySet(PropStorage.BOOTSTRAP_PROPS)) {
+ System.out.println("Can't find bootstrap properties!");
+ System.exit(1);
+ }
+ if (!ps.loadPropertySet(PropStorage.BASIC_PROPS)) {
+ System.out.println("Can't find basic properties!");
+ System.exit(1);
+ }
+ HashMap parameters1 = new HashMap();
+ try {
+ WebAPIAuthenticator authenticator = new WebAPIAuthenticator(new WebAPIClientWire(), new WebAPIDescriptor(new URI(serviceURI)),
+ ps.getKeyFromSet(PropStorage.BOOTSTRAP_PROPS, "bootstrapUser"),
+ ps.getKeyFromSet(PropStorage.BOOTSTRAP_PROPS, "bootstrapUserPW"));
+ parameters1.put(WebConstants.AUTH_COOKIE, authenticator.getAuthCookie());
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ //parameters1.put("loginCookie", "guestApplet_Test_Window2");
+
+ parameters1.put("spaceID", "" + ps.getKeyFromSet(PropStorage.BASIC_PROPS, "testSpaceNumber"));
+ parameters1.put("serviceURI", serviceURI);
+
+ //parameters1.put("x", "0");
+ //parameters1.put("y", "1000");
+ //parameters1.put("z", "0");
+ //parameters1.put("rx", "-1.6");
+ //parameters1.put("ry", "0");
+ //parameters1.put("rz", "0");
+
+ //parameters1.put("movable", "false");
+
+ clientStub1 = new EnvironmentStub(parameters1);
+ applet = new ViewerApplet();
+ //applet = new BodyEditorApplet();
+ applet.setStub(clientStub1);
+ add(applet, BorderLayout.CENTER);
+ }
+
+ private class EnvironmentStub implements AppletStub {
+
+ HashMap parameters = null;
+
+ public EnvironmentStub(HashMap parameters) {
+ this.parameters = parameters;
+ }
+
+ public void appletResize(int width, int height) {
+ }
+
+ public AppletContext getAppletContext() {
+ return null;
+ }
+
+ public URL getCodeBase() {
+ return codeBase;
+ }
+
+ public URL getDocumentBase() {
+ return codeBase;
+ }
+
+ public String getParameter(String name) {
+ return (String) parameters.get(name);
+ }
+
+ public boolean isActive() {
+ return true;
+ }
+
+ }
+
+ public void start() {
+ applet.init();
+ applet.start();
+ }
+
+ private static URL getURL(String url) {
+ try {
+ return new URL(url);
+ } catch (MalformedURLException e) {
+ throw new IllegalStateException("Bad url: " + url);
+ }
+ }
+
+ public static void main(String[] args) {
+ GraphicsEnvironment graphicsEnv = GraphicsEnvironment.getLocalGraphicsEnvironment();
+ GraphicsDevice device = graphicsEnv.getDefaultScreenDevice();
+ if (fullScreen) {
+ appDimension = new Dimension(device.getDisplayMode().getWidth(), device.getDisplayMode().getWidth());
+ }
+ AppletTestWindow test = new AppletTestWindow();
+ test.setVisible(true);
+ if (fullScreen) {
+ device.setFullScreenWindow(test);
+ }
+ test.start();
+ }
+
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|