|
From: <tre...@us...> - 2007-09-02 20:04:50
|
Revision: 337
http://ogoglio.svn.sourceforge.net/ogoglio/?rev=337&view=rev
Author: trevorolio
Date: 2007-09-02 13:04:44 -0700 (Sun, 02 Sep 2007)
Log Message:
-----------
Added a basic sanity check with the viewer applet during the integration tests.
It doesn't do much more than load a space with a test cube for the moment.
This test does not check that the applet will load properly from the server, but simply that the java code will actually open a space client, load a thing via the web api, and render it once.
Modified Paths:
--------------
maven/trunk/ogoglio-integration-test/src/test/java/com/ogoglio/client/test/AppletTestWindow.java
maven/trunk/ogoglio-integration-test/src/test/java/com/ogoglio/client/test/ClientTest.java
Modified: maven/trunk/ogoglio-integration-test/src/test/java/com/ogoglio/client/test/AppletTestWindow.java
===================================================================
--- maven/trunk/ogoglio-integration-test/src/test/java/com/ogoglio/client/test/AppletTestWindow.java 2007-09-02 20:04:41 UTC (rev 336)
+++ maven/trunk/ogoglio-integration-test/src/test/java/com/ogoglio/client/test/AppletTestWindow.java 2007-09-02 20:04:44 UTC (rev 337)
@@ -14,7 +14,6 @@
package com.ogoglio.client.test;
-import java.applet.Applet;
import java.applet.AppletContext;
import java.applet.AppletStub;
import java.awt.BorderLayout;
@@ -24,70 +23,55 @@
import java.awt.GraphicsEnvironment;
import java.net.MalformedURLException;
import java.net.URI;
+import java.net.URISyntaxException;
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.ArgumentUtils;
import com.ogoglio.util.PropStorage;
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);
+ Dimension appDimension = new Dimension(500, 500);
- Applet applet = null;
+ public ViewerApplet applet = null;
EnvironmentStub clientStub1 = null;
- String host = "127.0.0.1:8080";
+ URI serviceURI = null;
- String serviceURI = "http://" + host + "/og/";
+ public AppletTestWindow(URI serviceURI, long spaceID, String authCookie, Dimension appDimension, boolean decorated) {
+ ArgumentUtils.assertNotNull(appDimension);
+ this.appDimension = appDimension;
+ ArgumentUtils.assertNotNull(serviceURI);
+ this.serviceURI = serviceURI;
- URL codeBase = getURL(serviceURI);
-
- static boolean fullScreen = false;
-
- public AppletTestWindow() {
setLayout(new BorderLayout());
setSize(appDimension);
setLocation(30, 50);
setResizable(false);
- if (fullScreen) {
+ if (!decorated) {
this.setUndecorated(true);
}
-
HashMap parameters1 = new HashMap();
- try {
- PropStorage ps=new PropStorage();
- ps.loadPropertySet(PropStorage.BOOTSTRAP_PROPS);
- 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("loginCookie", authenticator.getAuthCookie());
- } catch (Exception e) {
- e.printStackTrace();
- }
- //parameters1.put("loginCookie", "guestApplet_Test_Window2");
+ parameters1.put("loginCookie", authCookie);
+ parameters1.put("spaceID", "" + spaceID);
+ parameters1.put("serviceURI", serviceURI.toString());
- parameters1.put("spaceID", "" + System.getProperty("AppletTestWindow.space"));
- 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);
}
@@ -108,11 +92,19 @@
}
public URL getCodeBase() {
- return codeBase;
+ try {
+ return serviceURI.toURL();
+ } catch (MalformedURLException e) {
+ throw new IllegalStateException("Could not convert serviceURI to URL: " + serviceURI);
+ }
}
public URL getDocumentBase() {
- return codeBase;
+ try {
+ return serviceURI.toURL();
+ } catch (MalformedURLException e) {
+ throw new IllegalStateException("Could not convert serviceURI to URL: " + serviceURI);
+ }
}
public String getParameter(String name) {
@@ -130,26 +122,43 @@
applet.start();
}
- private static URL getURL(String url) {
- try {
- return new URL(url);
- } catch (MalformedURLException e) {
- throw new IllegalStateException("Bad url: " + url);
- }
+ public void cleanup(){
+ applet.destroy();
}
public static void main(String[] args) {
GraphicsEnvironment graphicsEnv = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice device = graphicsEnv.getDefaultScreenDevice();
+ Dimension dim = new Dimension(1024, 800);
+ boolean fullScreen = args.length > 0 && "fullscreen".equals(args[0]);
if (fullScreen) {
- appDimension = new Dimension(device.getDisplayMode().getWidth(), device.getDisplayMode().getWidth());
+ dim = new Dimension(device.getDisplayMode().getWidth(), device.getDisplayMode().getWidth());
}
- AppletTestWindow test = new AppletTestWindow();
- test.setVisible(true);
- if (fullScreen) {
- device.setFullScreenWindow(test);
+ String serviceURI = "http://127.0.0.1:8080/og/";
+ String loginCookie = null;
+ try {
+ PropStorage ps = new PropStorage();
+ ps.loadPropertySet(PropStorage.BOOTSTRAP_PROPS);
+ WebAPIAuthenticator authenticator = new WebAPIAuthenticator(new WebAPIClientWire(), new WebAPIDescriptor(new URI(serviceURI)), ps.getKeyFromSet(PropStorage.BOOTSTRAP_PROPS, "bootstrapUser"), ps.getKeyFromSet(PropStorage.BOOTSTRAP_PROPS, "bootstrapUserPW"));
+ loginCookie = authenticator.getAuthCookie();
+ } catch (Exception e) {
+ e.printStackTrace();
+ System.exit(1);
}
- test.start();
+
+ long spaceID = Long.parseLong(System.getProperty("AppletTestWindow.space"));
+
+ try {
+ AppletTestWindow test = new AppletTestWindow(new URI(serviceURI), spaceID, loginCookie, dim, fullScreen);
+ test.setVisible(true);
+ if (fullScreen) {
+ device.setFullScreenWindow(test);
+ }
+ test.start();
+ } catch (URISyntaxException e) {
+ e.printStackTrace();
+ System.exit(1);
+ }
}
}
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-09-02 20:04:41 UTC (rev 336)
+++ maven/trunk/ogoglio-integration-test/src/test/java/com/ogoglio/client/test/ClientTest.java 2007-09-02 20:04:44 UTC (rev 337)
@@ -13,6 +13,7 @@
limitations under the License. */
package com.ogoglio.client.test;
+import java.awt.Dimension;
import java.awt.Shape;
import java.io.FileNotFoundException;
import java.io.IOException;
@@ -28,6 +29,7 @@
import junit.framework.TestCase;
import nanoxml.XMLElement;
+import com.ogoglio.client.AuthenticationFailedException;
import com.ogoglio.client.SpaceClient;
import com.ogoglio.client.WebAPIAuthenticator;
import com.ogoglio.client.WebAPIAuthenticatorFactory;
@@ -97,88 +99,83 @@
}
- public void testWebAdmin() {
- try {
- PropStorage ps = new PropStorage();
- if (ps.loadPropertySet(PropStorage.BOOTSTRAP_PROPS) == false) {
- fail("unable to load properties bootstrap.properties!");
- }
+ public void testWebAdmin() throws AuthenticationFailedException, IOException {
+ 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"));
+ 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());
+ assertNotNull("got null auth cookie", adminAuthenticator.getAuthCookie());
- WebAPIClient adminWebClient = new WebAPIClient(descriptor1, adminAuthenticator, wire1);
- adminWebClient.createAccount(USERNAME1, AccountDocument.ACCOUNT_LEVEL_ADVANCED, "Susan", "Examplar", "http://example.com/susan/", "su...@ex...", PASSWORD1);
- adminWebClient.createAccount(USERNAME2, AccountDocument.ACCOUNT_LEVEL_ADVANCED, "Tina", "Examplar", "http://example.com/tina/", "ti...@ex...", PASSWORD1);
+ WebAPIClient adminWebClient = new WebAPIClient(descriptor1, adminAuthenticator, wire1);
+ adminWebClient.createAccount(USERNAME1, AccountDocument.ACCOUNT_LEVEL_ADVANCED, "Susan", "Examplar", "http://example.com/susan/", "su...@ex...", PASSWORD1);
+ adminWebClient.createAccount(USERNAME2, AccountDocument.ACCOUNT_LEVEL_ADVANCED, "Tina", "Examplar", "http://example.com/tina/", "ti...@ex...", PASSWORD1);
- assertNotNull(adminWebClient.getAccountDocument(USERNAME1));
- assertNotNull(adminWebClient.getAccountDocument(USERNAME2));
+ assertNotNull(adminWebClient.getAccountDocument(USERNAME1));
+ assertNotNull(adminWebClient.getAccountDocument(USERNAME2));
- WebAPIAuthenticator basicAuthenticator = new WebAPIAuthenticatorFactory().authenticate(wire1, descriptor1, USERNAME1, PASSWORD1);
- assertNotNull("got null auth cookie", basicAuthenticator.getAuthCookie());
- WebAPIClient basicWebClient = new WebAPIClient(descriptor1, basicAuthenticator, wire1);
- try {
- String failedUsername = "Bogosity" + System.currentTimeMillis();
- AccountDocument doc = basicWebClient.createAccount(failedUsername, AccountDocument.ACCOUNT_LEVEL_BASIC, "Shouldnt", "Exist", null, failedUsername + "@example.com", "1234");
- if (doc != null) {
- fail();
- }
- } catch (Exception e) {
- //this should happen, because basic accounts can't create new accounts
+ WebAPIAuthenticator basicAuthenticator = new WebAPIAuthenticatorFactory().authenticate(wire1, descriptor1, USERNAME1, PASSWORD1);
+ assertNotNull("got null auth cookie", basicAuthenticator.getAuthCookie());
+ WebAPIClient basicWebClient = new WebAPIClient(descriptor1, basicAuthenticator, wire1);
+ try {
+ String failedUsername = "Bogosity" + System.currentTimeMillis();
+ AccountDocument doc = basicWebClient.createAccount(failedUsername, AccountDocument.ACCOUNT_LEVEL_BASIC, "Shouldnt", "Exist", null, failedUsername + "@example.com", "1234");
+ if (doc != null) {
+ fail();
}
+ } catch (Exception e) {
+ //this should happen, because basic accounts can't create new accounts
+ }
- WebAPIGuestAuthenticator guestAuthenticator = new WebAPIAuthenticatorFactory().authenticate(descriptor1, WebConstants.GUEST_COOKIE_PREFIX + "Test_Suite_Guest1");
- WebAPIClient guestWebClient = new WebAPIClient(descriptor1, guestAuthenticator, wire1);
+ WebAPIGuestAuthenticator guestAuthenticator = new WebAPIAuthenticatorFactory().authenticate(descriptor1, WebConstants.GUEST_COOKIE_PREFIX + "Test_Suite_Guest1");
+ WebAPIClient guestWebClient = new WebAPIClient(descriptor1, guestAuthenticator, wire1);
- ServiceStateDocument serviceStateDoc = adminWebClient.setRegistrationState(ServiceStateDocument.REGISTRATION_STATE_CLOSED);
- assertEquals(ServiceStateDocument.REGISTRATION_STATE_CLOSED, serviceStateDoc.getRegistrationState());
- assertNull(adminWebClient.createAccount("shouldnotexist" + System.currentTimeMillis(), AccountDocument.ACCOUNT_LEVEL_BASIC, "Test", "Sims", null, System.currentTimeMillis() + "@example.com", "1234"));
- assertNull(basicWebClient.createAccount("shouldnotexist" + System.currentTimeMillis(), AccountDocument.ACCOUNT_LEVEL_BASIC, "Test", "Sims", null, System.currentTimeMillis() + "@example.com", "1234"));
- assertNull(guestWebClient.createAccount("shouldnotexist" + System.currentTimeMillis(), AccountDocument.ACCOUNT_LEVEL_BASIC, "Test", "Sims", null, System.currentTimeMillis() + "@example.com", "1234"));
+ ServiceStateDocument serviceStateDoc = adminWebClient.setRegistrationState(ServiceStateDocument.REGISTRATION_STATE_CLOSED);
+ assertEquals(ServiceStateDocument.REGISTRATION_STATE_CLOSED, serviceStateDoc.getRegistrationState());
+ assertNull(adminWebClient.createAccount("shouldnotexist" + System.currentTimeMillis(), AccountDocument.ACCOUNT_LEVEL_BASIC, "Test", "Sims", null, System.currentTimeMillis() + "@example.com", "1234"));
+ assertNull(basicWebClient.createAccount("shouldnotexist" + System.currentTimeMillis(), AccountDocument.ACCOUNT_LEVEL_BASIC, "Test", "Sims", null, System.currentTimeMillis() + "@example.com", "1234"));
+ assertNull(guestWebClient.createAccount("shouldnotexist" + System.currentTimeMillis(), AccountDocument.ACCOUNT_LEVEL_BASIC, "Test", "Sims", null, System.currentTimeMillis() + "@example.com", "1234"));
- serviceStateDoc = adminWebClient.setRegistrationState(ServiceStateDocument.REGISTRATION_STATE_OPEN);
- assertEquals(ServiceStateDocument.REGISTRATION_STATE_OPEN, serviceStateDoc.getRegistrationState());
- assertNotNull(adminWebClient.createAccount("shouldexist" + System.currentTimeMillis(), AccountDocument.ACCOUNT_LEVEL_BASIC, "Test", "Sims", null, System.currentTimeMillis() + "@example.com", "1234"));
- assertNotNull(basicWebClient.createAccount("shouldexist" + System.currentTimeMillis(), AccountDocument.ACCOUNT_LEVEL_BASIC, "Test", "Sims", null, System.currentTimeMillis() + "@example.com", "1234"));
- assertNotNull(guestWebClient.createAccount("shouldexist" + System.currentTimeMillis(), AccountDocument.ACCOUNT_LEVEL_BASIC, "Test", "Sims", null, System.currentTimeMillis() + "@example.com", "1234"));
+ serviceStateDoc = adminWebClient.setRegistrationState(ServiceStateDocument.REGISTRATION_STATE_OPEN);
+ assertEquals(ServiceStateDocument.REGISTRATION_STATE_OPEN, serviceStateDoc.getRegistrationState());
+ assertNotNull(adminWebClient.createAccount("shouldexist" + System.currentTimeMillis(), AccountDocument.ACCOUNT_LEVEL_BASIC, "Test", "Sims", null, System.currentTimeMillis() + "@example.com", "1234"));
+ assertNotNull(basicWebClient.createAccount("shouldexist" + System.currentTimeMillis(), AccountDocument.ACCOUNT_LEVEL_BASIC, "Test", "Sims", null, System.currentTimeMillis() + "@example.com", "1234"));
+ assertNotNull(guestWebClient.createAccount("shouldexist" + System.currentTimeMillis(), AccountDocument.ACCOUNT_LEVEL_BASIC, "Test", "Sims", null, System.currentTimeMillis() + "@example.com", "1234"));
- serviceStateDoc = adminWebClient.setRegistrationState(ServiceStateDocument.REGISTRATION_STATE_ADMIN_ONLY);
- assertEquals(ServiceStateDocument.REGISTRATION_STATE_ADMIN_ONLY, serviceStateDoc.getRegistrationState());
- assertNotNull(adminWebClient.createAccount("shouldexist" + System.currentTimeMillis(), AccountDocument.ACCOUNT_LEVEL_BASIC, "Test", "Sims", null, System.currentTimeMillis() + "@example.com", "1234"));
- assertNull(basicWebClient.createAccount("shouldnotexist" + System.currentTimeMillis(), AccountDocument.ACCOUNT_LEVEL_BASIC, "Test", "Sims", null, System.currentTimeMillis() + "@example.com", "1234"));
- assertNull(guestWebClient.createAccount("shouldnotexist" + System.currentTimeMillis(), AccountDocument.ACCOUNT_LEVEL_BASIC, "Test", "Sims", null, System.currentTimeMillis() + "@example.com", "1234"));
+ serviceStateDoc = adminWebClient.setRegistrationState(ServiceStateDocument.REGISTRATION_STATE_ADMIN_ONLY);
+ assertEquals(ServiceStateDocument.REGISTRATION_STATE_ADMIN_ONLY, serviceStateDoc.getRegistrationState());
+ assertNotNull(adminWebClient.createAccount("shouldexist" + System.currentTimeMillis(), AccountDocument.ACCOUNT_LEVEL_BASIC, "Test", "Sims", null, System.currentTimeMillis() + "@example.com", "1234"));
+ assertNull(basicWebClient.createAccount("shouldnotexist" + System.currentTimeMillis(), AccountDocument.ACCOUNT_LEVEL_BASIC, "Test", "Sims", null, System.currentTimeMillis() + "@example.com", "1234"));
+ assertNull(guestWebClient.createAccount("shouldnotexist" + System.currentTimeMillis(), AccountDocument.ACCOUNT_LEVEL_BASIC, "Test", "Sims", null, System.currentTimeMillis() + "@example.com", "1234"));
- String username = "testuser" + Math.abs(new Random().nextLong());
- adminWebClient.createAccount(username, AccountDocument.ACCOUNT_LEVEL_BASIC, "Test", "Sims", null, username + "@example.com", "1234");
+ String username = "testuser" + Math.abs(new Random().nextLong());
+ adminWebClient.createAccount(username, AccountDocument.ACCOUNT_LEVEL_BASIC, "Test", "Sims", null, username + "@example.com", "1234");
- AccountDocument accountDoc = adminWebClient.getAccountDocument(username);
- assertNotNull(accountDoc);
- assertEquals("Test", accountDoc.getFirstName());
- assertEquals("Sims", accountDoc.getLastName());
+ AccountDocument accountDoc = adminWebClient.getAccountDocument(username);
+ assertNotNull(accountDoc);
+ assertEquals("Test", accountDoc.getFirstName());
+ assertEquals("Sims", accountDoc.getLastName());
- Date frozenDate = new Date(System.currentTimeMillis() + 1000000);
- accountDoc.setFrozenUntil(frozenDate);
- accountDoc.setAccountLevel(AccountDocument.ACCOUNT_LEVEL_ADMIN);
- adminWebClient.updateAccount(accountDoc);
- accountDoc = adminWebClient.getAccountDocument(username);
- assertTrue(frozenDate.getTime() - accountDoc.getFrozenUntil().getTime() < 1000);
- assertEquals(AccountDocument.ACCOUNT_LEVEL_ADMIN, accountDoc.getAccountLevel());
- accountDoc.setFrozenUntil(new Date(1000));
- accountDoc.setAccountLevel(AccountDocument.ACCOUNT_LEVEL_BASIC);
- accountDoc = adminWebClient.updateAccount(accountDoc);
- AccountDocument ac2 = adminWebClient.getAccountDocument(username);
- assertNull(accountDoc.getFrozenUntil());
- assertNull(ac2.getFrozenUntil());
- assertEquals(AccountDocument.ACCOUNT_LEVEL_BASIC, accountDoc.getAccountLevel());
+ Date frozenDate = new Date(System.currentTimeMillis() + 1000000);
+ accountDoc.setFrozenUntil(frozenDate);
+ accountDoc.setAccountLevel(AccountDocument.ACCOUNT_LEVEL_ADMIN);
+ adminWebClient.updateAccount(accountDoc);
+ accountDoc = adminWebClient.getAccountDocument(username);
+ assertTrue(frozenDate.getTime() - accountDoc.getFrozenUntil().getTime() < 1000);
+ assertEquals(AccountDocument.ACCOUNT_LEVEL_ADMIN, accountDoc.getAccountLevel());
+ accountDoc.setFrozenUntil(new Date(1000));
+ accountDoc.setAccountLevel(AccountDocument.ACCOUNT_LEVEL_BASIC);
+ accountDoc = adminWebClient.updateAccount(accountDoc);
+ AccountDocument ac2 = adminWebClient.getAccountDocument(username);
+ assertNull(accountDoc.getFrozenUntil());
+ assertNull(ac2.getFrozenUntil());
+ assertEquals(AccountDocument.ACCOUNT_LEVEL_BASIC, accountDoc.getAccountLevel());
- } catch (Exception e) {
- e.printStackTrace();
- fail("Might want to check to make sure database exists and library account exists...");
- }
}
- public void testWebAPIClient() {
+ public void testWebAPIClient() throws IOException {
SpaceClient spaceClient1 = null;
SpaceClient guestSpaceClient1 = null;
@@ -214,7 +211,7 @@
assertEquals(1, thingDocs.length);
checkThingScripting(webClient1, thingDocs[0], spaceDocument);
-
+
checkPageManipulation(webClient1, thingDocs[0], spaceDocument);
//figure out the last template added
@@ -233,10 +230,6 @@
guestSpaceClient1 = checkGuestCookieOperation(spaceDocument.getSpaceID(), webClient1, WebConstants.GUEST_COOKIE_PREFIX + "Test_Suite_Guest");
checkDeletingSpaceDestroysThings(spaceDocument.getSpaceID(), webClient1, USERNAME1);
-
- } catch (IOException e) {
- e.printStackTrace();
- fail();
} finally {
if (spaceClient1 != null) {
spaceClient1.cleanup();
@@ -248,6 +241,58 @@
}
+ public void testApplet() throws AuthenticationFailedException, IOException {
+ WebAPIAuthenticator basicAuthenticator = new WebAPIAuthenticatorFactory().authenticate(wire1, descriptor1, USERNAME1, PASSWORD1);
+ assertNotNull("got null auth cookie", basicAuthenticator.getAuthCookie());
+ WebAPIClient basicWebClient = new WebAPIClient(descriptor1, basicAuthenticator, wire1);
+
+ TemplateDocument newTemplateDoc = basicWebClient.createTemplate("Viewed Test Template");
+ assertNotNull(newTemplateDoc);
+ basicWebClient.uploadTemplateGeometryStream(newTemplateDoc.getOwnerUsername(), newTemplateDoc.getTemplateID(), 0, UIConstants.getResource("sample-art3d/TestCube.obj"));
+ basicWebClient.uploadTemplateResourceStream(newTemplateDoc.getOwnerUsername(), newTemplateDoc.getTemplateID(), "TestCube.mtl", UIConstants.getResource("sample-art3d/TestCube.mtl"));
+ basicWebClient.uploadTemplateResourceStream(newTemplateDoc.getOwnerUsername(), newTemplateDoc.getTemplateID(), "TestCube.gif", UIConstants.getResource("sample-art3d/TestCube.gif"));
+ basicWebClient.updateTemplateScript(newTemplateDoc.getOwnerUsername(), newTemplateDoc.getTemplateID(), StreamUtils.readInput(UIConstants.getResource("sample-art3d/TestCube.js")));
+
+ TemplateDocument[] templateDocs = basicWebClient.getTemplateDocuments(basicAuthenticator.getUsername());
+ assertNotNull(templateDocs);
+ assertTrue(templateDocs.length > 0);
+
+ SpaceDocument spaceDocument = basicWebClient.createSpace("Applet Test Space");
+ assertNotNull(spaceDocument);
+ PossessionDocument possDoc = basicWebClient.createPossession(newTemplateDoc.getTemplateID());
+ assertNotNull(possDoc);
+ possDoc = basicWebClient.addPossessionToSpace(possDoc.getPossessionID(), spaceDocument.getSpaceID());
+ assertTrue(possDoc.getThingID() != -1);
+
+ ThingDocument thingDoc = basicWebClient.getThingDocument(spaceDocument.getSpaceID(), possDoc.getThingID());
+ thingDoc.setZ(-10);
+ basicWebClient.updateThing(spaceDocument.getSpaceID(), thingDoc);
+
+ AppletTestWindow testWindow = openAppletTestWindow(spaceDocument, basicAuthenticator);
+
+ testWindow.applet.sendChatMessage("Hey, this is a chat message");
+ assertEquals(basicAuthenticator.getAuthDocument(true).getUsername(), testWindow.applet.getUsername());
+ testWindow.cleanup();
+
+ basicWebClient.deleteSpace(spaceDocument.getSpaceID());
+ }
+
+ private AppletTestWindow openAppletTestWindow(SpaceDocument spaceDocument, WebAPIAuthenticator authenticator){
+ AppletTestWindow testWindow = new AppletTestWindow(descriptor1.getServiceURI(), spaceDocument.getSpaceID(), authenticator.getAuthCookie(), new Dimension(500, 500), true);
+ testWindow.setVisible(true);
+ testWindow.start();
+
+ long startTime = System.currentTimeMillis();
+ while(!testWindow.applet.completedInitialLoad() && System.currentTimeMillis() < startTime + 10000){
+ try {
+ Thread.sleep(500);
+ } catch (InterruptedException e) {
+ }
+ }
+ assertTrue(testWindow.applet.completedInitialLoad());
+ return testWindow;
+ }
+
private void checkThingScripting(WebAPIClient webClient, ThingDocument thingDocument, SpaceDocument spaceDocument) throws IOException {
//make sure script will return a value
String script = webClient.getTemplateScript(webClient.getAuthenticator().getUsername(), thingDocument.getTemplateID());
@@ -255,13 +300,13 @@
assertFalse(script.indexOf("onService(") == -1);
//look for the monkey
- String thingServiceResponse = webClient.getThingService(spaceDocument.getSpaceID(), thingDocument.getThingID());
+ String thingServiceResponse = webClient.getThingService(spaceDocument.getSpaceID(), thingDocument.getThingID());
assertEquals("monkey", thingServiceResponse);
//try with no script
webClient.updateTemplateScript(webClient.getAuthenticator().getUsername(), thingDocument.getTemplateID(), "");
webClient.reloadThing(spaceDocument.getSpaceID(), thingDocument.getThingID());
- thingServiceResponse = webClient.getThingService(spaceDocument.getSpaceID(), thingDocument.getThingID());
+ thingServiceResponse = webClient.getThingService(spaceDocument.getSpaceID(), thingDocument.getThingID());
assertEquals("", thingServiceResponse);
//reinstall script
@@ -278,7 +323,7 @@
return userDocs;
}
- private void checkAuthDoc(WebAPIAuthenticator auth1, WebAPIAuthenticator auth2) {
+ private void checkAuthDoc(WebAPIAuthenticator auth1, WebAPIAuthenticator auth2) throws IOException {
AuthDocument authDoc = getAuthDoc(null);
assertFalse(authDoc.isAuthenticated());
assertNull(authDoc.getUsername());
@@ -296,14 +341,9 @@
assertEquals(USERNAME2, authDoc.getUsername());
}
- private AuthDocument getAuthDoc(String authCookie) {
- try {
- XMLElement element = wire1.fetchAuthenticatedXML(descriptor1.getMeAuthURI(), authCookie);
- return new AuthDocument(element);
- } catch (IOException e) {
- fail("Error fetching auth document with no auth cookie: " + e);
- return null;
- }
+ private AuthDocument getAuthDoc(String authCookie) throws IOException {
+ XMLElement element = wire1.fetchAuthenticatedXML(descriptor1.getMeAuthURI(), authCookie);
+ return new AuthDocument(element);
}
private void checkSpaceAuthWithMembership(WebAPIAuthenticator memberAuth, WebAPIClient memberClient, WebAPIClient ownerClient, SpaceDocument spaceDocument) throws IOException {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|